]> git.pond.sub.org Git - empserver/blob - src/lib/commands/terr.c
d15003de3c78b505692ac08466927cc7dc509423
[empserver] / src / lib / commands / terr.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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 <config.h>
35
36 #include "misc.h"
37 #include "player.h"
38 #include "sect.h"
39 #include "xy.h"
40 #include "nsc.h"
41 #include "nat.h"
42 #include "file.h"
43 #include "commands.h"
44
45 int
46 terr(void)
47 {
48     struct sctstr sect;
49     s_char *p;
50     int terr_n;
51     int field;
52     struct nstr_sect nstr;
53     s_char prompt[128];
54     s_char buf[1024];
55
56     if (!snxtsct(&nstr, player->argp[1]))
57         return RET_SYN;
58     if (player->argp[3] && isdigit(*(player->argp[3]))) {
59         field = atoi(player->argp[3]);
60     } else {
61         field = 0;
62     }
63     while (nxtsct(&nstr, &sect)) {
64         if (!player->owner)
65             continue;
66         sprintf(prompt, "%s %d%% %s  territory? ",
67                 xyas(nstr.x, nstr.y, player->cnum),
68                 sect.sct_effic, dchr[sect.sct_type].d_name);
69         if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
70             return RET_FAIL;
71         if (!check_sect_ok(&sect))
72             return RET_FAIL;
73         if (*p == 0)
74             continue;
75         terr_n = atoi(p);
76         while (terr_n < 0 || terr_n > 99 || *p < '0' || *p > '9') {
77             pr("Enter a number between 0 and 99!\n");
78             sprintf(prompt, "%s %d%% %s  territory? ",
79                     xyas(nstr.x, nstr.y, player->cnum),
80                     sect.sct_effic, dchr[sect.sct_type].d_name);
81             if ((p = getstarg((s_char *)0, prompt, buf)) == 0)
82                 return RET_FAIL;
83             if (!check_sect_ok(&sect))
84                 return RET_FAIL;
85             if (*p == 0)
86                 break;
87             terr_n = atoi(p);
88         }
89         if (*p == 0)
90             continue;
91         switch (field) {
92         case 1:
93             sect.sct_terr1 = terr_n;
94             break;
95         case 2:
96             sect.sct_terr2 = terr_n;
97             break;
98         case 3:
99             sect.sct_terr3 = terr_n;
100             break;
101         default:
102             sect.sct_terr = terr_n;
103         }
104         putsect(&sect);
105     }
106     return RET_OK;
107 }