2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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.
28 * improve.c: Improve the infrastructure of a sector
30 * Known contributors to this file:
31 * Steve McClure, 1996-2000
47 "Improve what ('road' or 'rail')? ",
48 "Improve what ('road', 'rail' or 'defense')? "
56 struct nstr_sect nstr;
71 if (!(p = getstarg(player->argp[1],
72 prompt[opt_DEFENSE_INFRA], buf)) || !*p)
74 if (!strncmp(p, "ro", 2))
76 else if (!strncmp(p, "ra", 2))
78 else if (!strncmp(p, "de", 2)) {
79 if (!opt_DEFENSE_INFRA) {
80 pr("Defense infrastructure is disabled.\n");
86 if (!snxtsct(&nstr, player->argp[2]))
90 while (nxtsct(&nstr, §)) {
94 value = sect.sct_road;
95 else if (type == INT_RAIL)
96 value = sect.sct_rail;
97 else /* type == INT_DEF */
98 value = sect.sct_defense;
99 sprintf(inbuf, "Sector %s has a %s of %d%%. Improve how much? ",
100 xyas(sect.sct_x, sect.sct_y, player->cnum),
101 intrchr[type].in_name, value);
102 if (!(p = getstarg(player->argp[3], inbuf, buf)) || !*p)
104 if (!check_sect_ok(§))
114 lneeded = intrchr[type].in_lcms * maxup;
117 if (sect.sct_item[I_LCM] < lneeded) {
118 lneeded = sect.sct_item[I_LCM];
119 maxup = lneeded / intrchr[type].in_lcms;
121 pr("Not enough lcms in %s\n",
122 xyas(sect.sct_x, sect.sct_y, player->cnum));
126 hneeded = intrchr[type].in_hcms * maxup;
129 if (sect.sct_item[I_HCM] < hneeded) {
130 hneeded = sect.sct_item[I_HCM];
131 maxup = hneeded / intrchr[type].in_hcms;
133 pr("Not enough hcms in %s\n",
134 xyas(sect.sct_x, sect.sct_y, player->cnum));
138 mneeded = intrchr[type].in_mcost * maxup;
139 if ((sect.sct_mobil - 1) < mneeded) {
140 mneeded = sect.sct_mobil - 1;
143 maxup = mneeded / intrchr[type].in_mcost;
145 pr("Not enough mobility in %s\n",
146 xyas(sect.sct_x, sect.sct_y, player->cnum));
150 dneeded = intrchr[type].in_dcost * maxup;
151 natp = getnatp(player->cnum);
152 if ((natp->nat_money - 1) < dneeded) {
153 /* Nasty - leave 'em with a buck. :) */
154 dneeded = natp->nat_money - 1;
157 maxup = dneeded / intrchr[type].in_dcost;
159 pr("Not enough money left to improve %s\n",
160 xyas(sect.sct_x, sect.sct_y, player->cnum));
166 lneeded = intrchr[type].in_lcms * maxup;
167 hneeded = intrchr[type].in_hcms * maxup;
168 mneeded = intrchr[type].in_mcost * maxup;
169 dneeded = intrchr[type].in_dcost * maxup;
170 player->dolcost += dneeded;
172 sect.sct_item[I_LCM] -= lneeded;
174 sect.sct_item[I_HCM] -= hneeded;
175 sect.sct_mobil -= mneeded;
178 if (CANT_HAPPEN(value > 100))
180 pr("Sector %s %s increased from %d%% to %d%%\n",
181 xyas(sect.sct_x, sect.sct_y, player->cnum),
182 intrchr[type].in_name, ovalue, value);
183 if (type == INT_ROAD)
184 sect.sct_road = value;
185 else if (type == INT_RAIL)
186 sect.sct_rail = value;
187 else if (type == INT_DEF)
188 sect.sct_defense = value;
194 pr("%s: No sector(s)\n", player->argp[1]);
196 pr("%s: No sector(s)\n", "");
199 pr("%d sector%s\n", nsect, splur(nsect));