]> git.pond.sub.org Git - empserver/blob - src/lib/commands/terr.c
Do not include var.h where no longer needed. Clean up register keywords in these...
[empserver] / src / lib / commands / terr.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  terr.c: Designate territory of sectors
29  * 
30  *  Known contributors to this file:
31  *     Edward M. Rynes Esq.
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "sect.h"
37 #include "xy.h"
38 #include "nsc.h"
39 #include "nat.h"
40 #include "file.h"
41 #include "commands.h"
42
43 int
44 terr(void)
45 {
46     struct sctstr sect;
47     s_char *p;
48     int terr_n;
49     int field;
50     struct nstr_sect nstr;
51     s_char prompt[128];
52     s_char buf[1024];
53
54     if (!snxtsct(&nstr, player->argp[1]))
55         return RET_SYN;
56     if (player->argp[3] && isdigit(*(player->argp[3]))) {
57         field = atoi(player->argp[3]);
58     } else {
59         field = 0;
60     }
61     while (nxtsct(&nstr, &sect)) {
62         if (!player->owner)
63             continue;
64         sprintf(prompt, "%s %d%% %s  territory? ",
65                 xyas(nstr.x, nstr.y, player->cnum),
66                 sect.sct_effic, dchr[sect.sct_type].d_name);
67         if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
68             return RET_FAIL;
69         if (!check_sect_ok(&sect))
70             return RET_FAIL;
71         if (*p == 0)
72             continue;
73         terr_n = atoi(p);
74         while (terr_n < 0 || terr_n > 99 || *p < '0' || *p > '9') {
75             pr("Enter a number between 0 and 99!\n");
76             sprintf(prompt, "%s %d%% %s  territory? ",
77                     xyas(nstr.x, nstr.y, player->cnum),
78                     sect.sct_effic, dchr[sect.sct_type].d_name);
79             if ((p = getstarg((s_char *)0, prompt, buf)) == 0)
80                 return RET_FAIL;
81             if (!check_sect_ok(&sect))
82                 return RET_FAIL;
83             if (*p == 0)
84                 break;
85             terr_n = atoi(p);
86         }
87         if (*p == 0)
88             continue;
89         switch (field) {
90         case 1:
91             sect.sct_terr1 = terr_n;
92             break;
93         case 2:
94             sect.sct_terr2 = terr_n;
95             break;
96         case 3:
97             sect.sct_terr3 = terr_n;
98             break;
99         default:
100             sect.sct_terr = terr_n;
101         }
102         putsect(&sect);
103     }
104     return RET_OK;
105 }