]> git.pond.sub.org Git - empserver/blob - src/lib/commands/setres.c
afe069458d3529ca7e3c296fcc9b9cacbc3d7569
[empserver] / src / lib / commands / setres.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  *  setres.c: Set resources of a sector
29  * 
30  *  Known contributors to this file:
31  *     David Muir Sharnoff
32  *     Karl Hagen
33  *     Steve McClure, 1998
34  */
35
36 #include <config.h>
37
38 #include <stdio.h>
39 #include <ctype.h>
40 #include "misc.h"
41 #include "player.h"
42 #include "xy.h"
43 #include "sect.h"
44 #include "nat.h"
45 #include "nsc.h"
46 #include "file.h"
47 #include "commands.h"
48
49 /*
50  * format: setres resource <amt>  <sect>
51  */
52 int
53 setres(void)
54 {
55     struct sctstr sect;
56     s_char *what;
57     int amt;
58     s_char *p;
59     struct nstr_sect nstr;
60     s_char buf[1024];
61
62     if ((what = getstarg(player->argp[1],
63                          "Set What (iron, gold, oil, uranium, fertility)? ",
64                          buf)) == 0)
65         return RET_SYN;
66     switch (what[0]) {
67     case 'i':
68         if (!snxtsct(&nstr, player->argp[2]))
69             return RET_SYN;
70         while (nxtsct(&nstr, &sect) > 0) {
71             if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
72                 (*p == '\0'))
73                 return RET_SYN;
74             amt = atoi(p);
75             if (amt > 100)
76                 amt = 100;
77             if (amt < 0)
78                 amt = 0;
79             if (sect.sct_own != 0)
80                 resnoise(&sect, 1, "Iron ore content",
81                          (int)sect.sct_min, amt);
82             sect.sct_min = (u_char)amt;
83             putsect(&sect);
84         }
85         break;
86     case 'g':
87         if (!snxtsct(&nstr, player->argp[2]))
88             return RET_SYN;
89         while (nxtsct(&nstr, &sect) > 0) {
90             if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
91                 (*p == '\0'))
92                 return RET_SYN;
93             amt = atoi(p);
94             if (amt > 100)
95                 amt = 100;
96             if (amt < 0)
97                 amt = 0;
98             if (sect.sct_own != 0)
99                 resnoise(&sect, 1, "Gold content",
100                          (int)sect.sct_gmin, amt);
101             sect.sct_gmin = (u_char)amt;
102             putsect(&sect);
103         }
104         break;
105     case 'o':
106         if (!snxtsct(&nstr, player->argp[2]))
107             return RET_SYN;
108         while (nxtsct(&nstr, &sect) > 0) {
109             if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
110                 (*p == '\0'))
111                 return RET_SYN;
112             amt = atoi(p);
113             if (amt > 100)
114                 amt = 100;
115             if (amt < 0)
116                 amt = 0;
117             if (sect.sct_own != 0)
118                 resnoise(&sect, 1, "Oil content", (int)sect.sct_oil, amt);
119             sect.sct_oil = (u_char)amt;
120             putsect(&sect);
121         }
122         break;
123     case 'f':
124         if (!snxtsct(&nstr, player->argp[2]))
125             return RET_SYN;
126         while (nxtsct(&nstr, &sect) > 0) {
127             if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
128                 (*p == '\0'))
129                 return RET_SYN;
130             amt = atoi(p);
131             if (amt > 100)
132                 amt = 100;
133             if (amt < 0)
134                 amt = 0;
135             if (sect.sct_own != 0)
136                 resnoise(&sect, 1, "Fertility content",
137                          (int)sect.sct_fertil, amt);
138             sect.sct_fertil = (u_char)amt;
139             putsect(&sect);
140         }
141         break;
142     case 'u':
143         if (!snxtsct(&nstr, player->argp[2]))
144             return RET_SYN;
145         while (nxtsct(&nstr, &sect) > 0) {
146             if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
147                 (*p == '\0'))
148                 return RET_SYN;
149             amt = atoi(p);
150             if (amt > 100)
151                 amt = 100;
152             if (amt < 0)
153                 amt = 0;
154             if (sect.sct_own != 0)
155                 resnoise(&sect, 1, "Uranium content",
156                          (int)sect.sct_uran, amt);
157             sect.sct_uran = (u_char)amt;
158             putsect(&sect);
159         }
160         break;
161     default:
162         pr("huh?\n");
163         return RET_SYN;
164     }
165     return RET_OK;
166 }