2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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
51 "Improve what ('road' or 'rail')? ",
52 "Improve what ('road', 'rail' or 'defense')? "
60 struct nstr_sect nstr;
76 if (!(p = getstarg(player->argp[1],
77 prompt[opt_DEFENSE_INFRA], buf)) || !*p)
79 if (!strncmp(p, "ro", 2))
81 else if (!strncmp(p, "ra", 2))
83 else if (!strncmp(p, "de", 2) && opt_DEFENSE_INFRA)
87 if (!snxtsct(&nstr, player->argp[2]))
91 while (nxtsct(&nstr, §)) {
95 value = sect.sct_road;
96 else if (type == INT_RAIL)
97 value = sect.sct_rail;
98 else if (type == INT_DEF)
99 value = sect.sct_defense;
100 sprintf(inbuf, "Sector %s has a %s of %d%%. Improve how much? ",
101 xyas(sect.sct_x, sect.sct_y, player->cnum),
102 intrchr[type].in_name, value);
103 if (!(p = getstarg(player->argp[3], inbuf, buf)) || !*p)
105 if (!check_sect_ok(§))
107 getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
116 lneeded = intrchr[type].in_lcms * maxup;
119 if (vec[I_LCM] < lneeded) {
120 lneeded = vec[I_LCM];
121 maxup = lneeded / intrchr[type].in_lcms;
123 pr("Not enough lcms in %s\n",
124 xyas(sect.sct_x, sect.sct_y, player->cnum));
128 hneeded = intrchr[type].in_hcms * maxup;
131 if (vec[I_HCM] < hneeded) {
132 hneeded = vec[I_HCM];
133 maxup = hneeded / intrchr[type].in_hcms;
135 pr("Not enough hcms in %s\n",
136 xyas(sect.sct_x, sect.sct_y, player->cnum));
140 mneeded = intrchr[type].in_mcost * maxup;
141 if ((sect.sct_mobil - 1) < mneeded) {
142 mneeded = sect.sct_mobil - 1;
145 maxup = mneeded / intrchr[type].in_mcost;
147 pr("Not enough mobility in %s\n",
148 xyas(sect.sct_x, sect.sct_y, player->cnum));
152 dneeded = intrchr[type].in_dcost * maxup;
153 natp = getnatp(player->cnum);
154 if ((natp->nat_money - 1) < dneeded) {
155 /* Nasty - leave 'em with a buck. :) */
156 dneeded = natp->nat_money - 1;
159 maxup = dneeded / intrchr[type].in_dcost;
161 pr("Not enough money left to improve %s\n",
162 xyas(sect.sct_x, sect.sct_y, player->cnum));
168 lneeded = intrchr[type].in_lcms * maxup;
169 hneeded = intrchr[type].in_hcms * maxup;
170 mneeded = intrchr[type].in_mcost * maxup;
171 dneeded = intrchr[type].in_dcost * maxup;
172 player->dolcost += dneeded;
174 vec[I_LCM] -= lneeded;
176 vec[I_HCM] -= hneeded;
177 sect.sct_mobil -= mneeded;
178 putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
183 pr("Sector %s %s increased from %d%% to %d%%\n",
184 xyas(sect.sct_x, sect.sct_y, player->cnum),
185 intrchr[type].in_name, ovalue, value);
186 if (type == INT_ROAD)
187 sect.sct_road = value;
188 else if (type == INT_RAIL)
189 sect.sct_rail = value;
190 else if (type == INT_DEF)
191 sect.sct_defense = value;
197 pr("%s: No sector(s)\n", player->argp[1]);
199 pr("%s: No sector(s)\n", "");
202 pr("%d sector%s\n", nsect, splur(nsect));