]> git.pond.sub.org Git - empserver/blob - src/lib/commands/setsect.c
6e91ec558123c35f6fbe447bff6d44386ebd1239
[empserver] / src / lib / commands / setsect.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  setsect.c: Give resources to a country
28  *
29  *  Known contributors to this file:
30  *     David Muir Sharnoff
31  *     Steve McClure, 1998
32  *     Markus Armbruster, 2004-2013
33  */
34
35 #include <config.h>
36
37 #include "commands.h"
38
39 /*
40  * format: setres thing <sect> <#>
41  */
42 int
43 setsector(void)
44 {
45     struct sctstr sect;
46     char *what;
47     int amt, ret;
48     char *p;
49     struct nstr_sect nstr;
50     char buf[1024];
51     char char0, char1;
52
53     what = getstarg(player->argp[1],
54                     "Give what (iron, gold, oil, uranium, fertility, owner, eff., mob., work, avail., oldown, mines)? ",
55                     buf);
56     if (!what || !*what)
57         return RET_SYN;
58     char0 = what[0];
59     char1 = what[1];
60
61     if (!snxtsct(&nstr, player->argp[2]))
62         return RET_SYN;
63     while (nxtsct(&nstr, &sect) > 0) {
64         p = getstarg(player->argp[3], "What value : ", buf);
65         if (!p || !*p)
66             return RET_SYN;
67         amt = atoi(p);
68         if (!check_sect_ok(&sect))
69             return RET_FAIL;
70         switch (char0) {
71         case 'i':
72             ret = edit_sect_i(&sect, "i", sect.sct_min + amt);
73             break;
74         case 'g':
75             ret = edit_sect_i(&sect, "g", sect.sct_gmin + amt);
76             break;
77         case 'o':
78             switch (char1) {
79             case 'i':
80                 ret = edit_sect_i(&sect, "c", sect.sct_oil + amt);
81                 break;
82                 break;
83             case 'w':
84                 ret = edit_sect(&sect, "o", p);
85                 break;
86             case 'l':
87                 ret = edit_sect(&sect, "O", p);
88                 break;
89             default:
90                 pr("huh?\n");
91                 return RET_SYN;
92             }
93             break;
94         case 'e':
95             ret = edit_sect_i(&sect, "e", sect.sct_effic + amt);
96             break;
97         case 'm':
98             switch (char1) {
99             case 'i':
100                 ret = edit_sect_i(&sect, "M", sect.sct_mines + amt);
101                 break;
102             case 'o':
103                 ret = edit_sect_i(&sect, "m", sect.sct_mobil + amt);
104                 break;
105             default:
106                 pr("huh?\n");
107                 return RET_SYN;
108             }
109             break;
110         case 'a':
111             ret = edit_sect_i(&sect, "a", sect.sct_avail + amt);
112             break;
113         case 'w':
114             ret = edit_sect_i(&sect, "w", sect.sct_work + amt);
115             break;
116         case 'f':
117             ret = edit_sect_i(&sect, "f", sect.sct_fertil + amt);
118             break;
119         case 'u':
120             ret = edit_sect_i(&sect, "u", sect.sct_uran + amt);
121             break;
122         default:
123             pr("huh?\n");
124             ret = RET_SYN;
125         }
126         if (ret != RET_OK)
127             return ret;
128         putsect(&sect);
129     }
130     return RET_OK;
131 }