2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, 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 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.
28 * improve.c: Improve the infrastructure of a sector
30 * Known contributors to this file:
31 * Steve McClure, 1996-2000
45 struct nstr_sect nstr;
60 p = getstarg(player->argp[1],
61 "Improve what ('road', 'rail' or 'defense')? ",
65 if (!strncmp(p, "ro", 2))
67 else if (!strncmp(p, "ra", 2))
69 else if (!strncmp(p, "de", 2)) {
74 if (!intrchr[type].in_enable) {
75 pr("%s improvement is disabled.\n", intrchr[type].in_name);
79 if (!snxtsct(&nstr, player->argp[2]))
83 while (nxtsct(&nstr, §)) {
87 value = sect.sct_road;
88 else if (type == INT_RAIL)
89 value = sect.sct_rail;
90 else /* type == INT_DEF */
91 value = sect.sct_defense;
92 sprintf(prompt, "Sector %s has a %s of %d%%. Improve how much? ",
93 xyas(sect.sct_x, sect.sct_y, player->cnum),
94 intrchr[type].in_name, value);
95 p = getstarg(player->argp[3], prompt, buf);
98 if (!check_sect_ok(§))
108 lneeded = intrchr[type].in_lcms * maxup;
109 if (sect.sct_item[I_LCM] < lneeded) {
110 lneeded = sect.sct_item[I_LCM];
111 maxup = lneeded / intrchr[type].in_lcms;
113 pr("Not enough lcms in %s\n",
114 xyas(sect.sct_x, sect.sct_y, player->cnum));
118 hneeded = intrchr[type].in_hcms * maxup;
119 if (sect.sct_item[I_HCM] < hneeded) {
120 hneeded = sect.sct_item[I_HCM];
121 maxup = hneeded / intrchr[type].in_hcms;
123 pr("Not enough hcms in %s\n",
124 xyas(sect.sct_x, sect.sct_y, player->cnum));
128 mneeded = intrchr[type].in_mcost * maxup;
129 if ((sect.sct_mobil - 1) < mneeded) {
130 mneeded = sect.sct_mobil - 1;
133 maxup = mneeded / intrchr[type].in_mcost;
135 pr("Not enough mobility in %s\n",
136 xyas(sect.sct_x, sect.sct_y, player->cnum));
140 dneeded = intrchr[type].in_dcost * maxup;
141 natp = getnatp(player->cnum);
142 if (player->dolcost + dneeded > natp->nat_money) {
143 pr("Not enough money left to improve %s by %d%%\n",
144 xyas(sect.sct_x, sect.sct_y, player->cnum), maxup);
147 lneeded = intrchr[type].in_lcms * maxup;
148 hneeded = intrchr[type].in_hcms * maxup;
149 mneeded = intrchr[type].in_mcost * maxup;
150 dneeded = intrchr[type].in_dcost * maxup;
151 player->dolcost += dneeded;
152 sect.sct_item[I_LCM] -= lneeded;
153 sect.sct_item[I_HCM] -= hneeded;
154 sect.sct_mobil -= mneeded;
157 if (CANT_HAPPEN(value > 100))
159 pr("Sector %s %s increased from %d%% to %d%%\n",
160 xyas(sect.sct_x, sect.sct_y, player->cnum),
161 intrchr[type].in_name, ovalue, value);
162 if (type == INT_ROAD)
163 sect.sct_road = value;
164 else if (type == INT_RAIL)
165 sect.sct_rail = value;
166 else if (type == INT_DEF)
167 sect.sct_defense = value;
173 pr("%s: No sector(s)\n", player->argp[1]);
175 pr("%s: No sector(s)\n", "");
178 pr("%d sector%s\n", nsect, splur(nsect));