]> git.pond.sub.org Git - empserver/blob - src/lib/commands/terr.c
(sctstr): New member sct_dterr.
[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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future 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     char *p;
50     int terr_n;
51     int field;
52     struct nstr_sect nstr;
53     char prompt[128];
54     char buf[1024];
55
56     if (!snxtsct(&nstr, player->argp[1]))
57         return RET_SYN;
58     if (player->argp[3]) {
59         field = atoi(player->argp[3]);
60     } else {
61         field = player->god ? -1 : 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 (*p == 0)
72             continue;
73         terr_n = atoi(p);
74         if (terr_n < 0 || terr_n > TERR_MAX) {
75             pr("Territory number must be between 0 and %d\n", TERR_MAX);
76             return RET_FAIL;
77         }
78         if (!check_sect_ok(&sect))
79             return RET_FAIL;
80         switch (field) {
81         case 1:
82             sect.sct_terr1 = terr_n;
83             break;
84         case 2:
85             sect.sct_terr2 = terr_n;
86             break;
87         case 3:
88             sect.sct_terr3 = terr_n;
89             break;
90         case -1:
91             if (player->god) {
92                 sect.sct_dterr = terr_n;
93                 break;
94             }
95             /* fall through */
96         default:
97             sect.sct_terr = terr_n;
98         }
99         putsect(&sect);
100     }
101     return RET_OK;
102 }