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 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
97 if (!check_sect_ok(§))
107 lneeded = intrchr[type].in_lcms * maxup;
108 if (sect.sct_item[I_LCM] < lneeded) {
109 lneeded = sect.sct_item[I_LCM];
110 maxup = lneeded / intrchr[type].in_lcms;
112 pr("Not enough lcms in %s\n",
113 xyas(sect.sct_x, sect.sct_y, player->cnum));
117 hneeded = intrchr[type].in_hcms * maxup;
118 if (sect.sct_item[I_HCM] < hneeded) {
119 hneeded = sect.sct_item[I_HCM];
120 maxup = hneeded / intrchr[type].in_hcms;
122 pr("Not enough hcms in %s\n",
123 xyas(sect.sct_x, sect.sct_y, player->cnum));
127 mneeded = intrchr[type].in_mcost * maxup;
128 if ((sect.sct_mobil - 1) < mneeded) {
129 mneeded = sect.sct_mobil - 1;
132 maxup = mneeded / intrchr[type].in_mcost;
134 pr("Not enough mobility in %s\n",
135 xyas(sect.sct_x, sect.sct_y, player->cnum));
139 dneeded = intrchr[type].in_dcost * maxup;
140 natp = getnatp(player->cnum);
141 if (player->dolcost + dneeded > natp->nat_money) {
142 pr("Not enough money left to improve %s by %d%%\n",
143 xyas(sect.sct_x, sect.sct_y, player->cnum), maxup);
146 lneeded = intrchr[type].in_lcms * maxup;
147 hneeded = intrchr[type].in_hcms * maxup;
148 mneeded = intrchr[type].in_mcost * maxup;
149 dneeded = intrchr[type].in_dcost * maxup;
150 player->dolcost += dneeded;
151 sect.sct_item[I_LCM] -= lneeded;
152 sect.sct_item[I_HCM] -= hneeded;
153 sect.sct_mobil -= mneeded;
156 if (CANT_HAPPEN(value > 100))
158 pr("Sector %s %s increased from %d%% to %d%%\n",
159 xyas(sect.sct_x, sect.sct_y, player->cnum),
160 intrchr[type].in_name, ovalue, value);
161 if (type == INT_ROAD)
162 sect.sct_road = value;
163 else if (type == INT_RAIL)
164 sect.sct_rail = value;
165 else if (type == INT_DEF)
166 sect.sct_defense = value;
172 pr("%s: No sector(s)\n", player->argp[1]);
174 pr("%s: No sector(s)\n", "");
177 pr("%d sector%s\n", nsect, splur(nsect));