]> git.pond.sub.org Git - empserver/blob - src/lib/commands/terr.c
Update copyright notice
[empserver] / src / lib / commands / terr.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2008, 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 "commands.h"
37
38 int
39 terr(void)
40 {
41     struct sctstr sect;
42     char *p;
43     int terr_n;
44     int field;
45     struct nstr_sect nstr;
46     char prompt[128];
47     char buf[1024];
48
49     if (!snxtsct(&nstr, player->argp[1]))
50         return RET_SYN;
51     if (player->argp[3]) {
52         field = atoi(player->argp[3]);
53     } else {
54         field = player->god ? -1 : 0;
55     }
56     while (nxtsct(&nstr, &sect)) {
57         if (!player->owner)
58             continue;
59         sprintf(prompt, "%s %d%% %s  territory? ",
60                 xyas(nstr.x, nstr.y, player->cnum),
61                 sect.sct_effic, dchr[sect.sct_type].d_name);
62         if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
63             return RET_FAIL;
64         if (*p == 0)
65             continue;
66         terr_n = atoi(p);
67         if (terr_n < 0 || terr_n > TERR_MAX) {
68             pr("Territory number must be between 0 and %d\n", TERR_MAX);
69             return RET_FAIL;
70         }
71         if (!check_sect_ok(&sect))
72             return RET_FAIL;
73         switch (field) {
74         case 1:
75             sect.sct_terr1 = terr_n;
76             break;
77         case 2:
78             sect.sct_terr2 = terr_n;
79             break;
80         case 3:
81             sect.sct_terr3 = terr_n;
82             break;
83         case -1:
84             if (player->god) {
85                 sect.sct_dterr = terr_n;
86                 break;
87             }
88             /* fall through */
89         default:
90             sect.sct_terr = terr_n;
91         }
92         putsect(&sect);
93     }
94     return RET_OK;
95 }