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
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.
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.
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/>.
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.
27 * improve.c: Improve the infrastructure of a sector
29 * Known contributors to this file:
30 * Steve McClure, 1996-2000
42 struct nstr_sect nstr;
57 p = getstarg(player->argp[1],
58 "Improve what ('road', 'rail' or 'defense')? ",
62 if (!strncmp(p, "ro", 2))
64 else if (!strncmp(p, "ra", 2))
66 else if (!strncmp(p, "de", 2)) {
71 if (!intrchr[type].in_enable) {
72 pr("%s improvement is disabled.\n", intrchr[type].in_name);
76 if (!snxtsct(&nstr, player->argp[2]))
80 while (nxtsct(&nstr, §)) {
84 value = sect.sct_road;
85 else if (type == INT_RAIL)
86 value = sect.sct_rail;
87 else /* type == INT_DEF */
88 value = sect.sct_defense;
89 sprintf(prompt, "Sector %s has a %s of %d%%. Improve how much? ",
90 xyas(sect.sct_x, sect.sct_y, player->cnum),
91 intrchr[type].in_name, value);
92 p = getstarg(player->argp[3], prompt, buf);
95 if (!check_sect_ok(§))
105 lneeded = intrchr[type].in_lcms * maxup;
106 if (sect.sct_item[I_LCM] < lneeded) {
107 lneeded = sect.sct_item[I_LCM];
108 maxup = lneeded / intrchr[type].in_lcms;
110 pr("Not enough lcms in %s\n",
111 xyas(sect.sct_x, sect.sct_y, player->cnum));
115 hneeded = intrchr[type].in_hcms * maxup;
116 if (sect.sct_item[I_HCM] < hneeded) {
117 hneeded = sect.sct_item[I_HCM];
118 maxup = hneeded / intrchr[type].in_hcms;
120 pr("Not enough hcms in %s\n",
121 xyas(sect.sct_x, sect.sct_y, player->cnum));
125 mneeded = intrchr[type].in_mcost * maxup;
126 if ((sect.sct_mobil - 1) < mneeded) {
127 mneeded = sect.sct_mobil - 1;
130 maxup = mneeded / intrchr[type].in_mcost;
132 pr("Not enough mobility in %s\n",
133 xyas(sect.sct_x, sect.sct_y, player->cnum));
137 dneeded = intrchr[type].in_dcost * maxup;
138 natp = getnatp(player->cnum);
139 if (player->dolcost + dneeded > natp->nat_money) {
140 pr("Not enough money left to improve %s by %d%%\n",
141 xyas(sect.sct_x, sect.sct_y, player->cnum), maxup);
144 lneeded = intrchr[type].in_lcms * maxup;
145 hneeded = intrchr[type].in_hcms * maxup;
146 mneeded = intrchr[type].in_mcost * maxup;
147 dneeded = intrchr[type].in_dcost * maxup;
148 player->dolcost += dneeded;
149 sect.sct_item[I_LCM] -= lneeded;
150 sect.sct_item[I_HCM] -= hneeded;
151 sect.sct_mobil -= mneeded;
154 if (CANT_HAPPEN(value > 100))
156 pr("Sector %s %s increased from %d%% to %d%%\n",
157 xyas(sect.sct_x, sect.sct_y, player->cnum),
158 intrchr[type].in_name, ovalue, value);
159 if (type == INT_ROAD)
160 sect.sct_road = value;
161 else if (type == INT_RAIL)
162 sect.sct_rail = value;
163 else if (type == INT_DEF)
164 sect.sct_defense = value;
170 pr("%s: No sector(s)\n", player->argp[1]);
172 pr("%s: No sector(s)\n", "");
175 pr("%d sector%s\n", nsect, splur(nsect));