/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
* improve.c: Improve the infrastructure of a sector
- *
+ *
* Known contributors to this file:
* Steve McClure, 1996-2000
*/
-#include <string.h>
-#include "misc.h"
-#include "player.h"
-#include "var.h"
-#include "xy.h"
-#include "sect.h"
-#include "nsc.h"
-#include "nat.h"
-#include "path.h"
-#include "file.h"
-#include "optlist.h"
-#include "commands.h"
+#include <config.h>
-char *prompt[] = {
- "Improve what ('road' or 'rail')? ",
- "Improve what ('road', 'rail' or 'defense')? "
-};
+#include "commands.h"
int
improve(void)
struct sctstr sect;
int nsect;
struct nstr_sect nstr;
- s_char *p;
- s_char buf[1024];
- s_char inbuf[128];
+ char *p;
+ char buf[1024];
+ char prompt[128];
int type;
int value;
int ovalue;
int dneeded;
int wanted;
- if (!(p = getstarg(player->argp[1],
- prompt[opt_DEFENSE_INFRA], buf)) || !*p)
+ p = getstarg(player->argp[1],
+ "Improve what ('road', 'rail' or 'defense')? ",
+ buf);
+ if (!p || !*p)
return RET_SYN;
if (!strncmp(p, "ro", 2))
type = INT_ROAD;
else if (!strncmp(p, "ra", 2))
type = INT_RAIL;
else if (!strncmp(p, "de", 2)) {
- if (!opt_DEFENSE_INFRA) {
- pr("Defense infrastructure is disabled.\n");
- return RET_FAIL;
- }
type = INT_DEF;
} else
return RET_SYN;
+
+ if (!intrchr[type].in_enable) {
+ pr("%s improvement is disabled.\n", intrchr[type].in_name);
+ return RET_FAIL;
+ }
+
if (!snxtsct(&nstr, player->argp[2]))
return RET_SYN;
prdate();
value = sect.sct_rail;
else /* type == INT_DEF */
value = sect.sct_defense;
- sprintf(inbuf, "Sector %s has a %s of %d%%. Improve how much? ",
+ sprintf(prompt, "Sector %s has a %s of %d%%. Improve how much? ",
xyas(sect.sct_x, sect.sct_y, player->cnum),
intrchr[type].in_name, value);
- if (!(p = getstarg(player->argp[3], inbuf, buf)) || !*p)
+ p = getstarg(player->argp[3], prompt, buf);
+ if (!p || !*p)
continue;
if (!check_sect_ok(§))
continue;
if (!maxup)
continue;
lneeded = intrchr[type].in_lcms * maxup;
- if (opt_NO_LCMS)
- lneeded = 0;
if (sect.sct_item[I_LCM] < lneeded) {
lneeded = sect.sct_item[I_LCM];
maxup = lneeded / intrchr[type].in_lcms;
}
}
hneeded = intrchr[type].in_hcms * maxup;
- if (opt_NO_HCMS)
- hneeded = 0;
if (sect.sct_item[I_HCM] < hneeded) {
hneeded = sect.sct_item[I_HCM];
maxup = hneeded / intrchr[type].in_hcms;
}
dneeded = intrchr[type].in_dcost * maxup;
natp = getnatp(player->cnum);
- if ((natp->nat_money - 1) < dneeded) {
-/* Nasty - leave 'em with a buck. :) */
- dneeded = natp->nat_money - 1;
- if (dneeded < 0)
- dneeded = 0;
- maxup = dneeded / intrchr[type].in_dcost;
- if (maxup <= 0) {
- pr("Not enough money left to improve %s\n",
- xyas(sect.sct_x, sect.sct_y, player->cnum));
- continue;
- }
+ if (player->dolcost + dneeded > natp->nat_money) {
+ pr("Not enough money left to improve %s by %d%%\n",
+ xyas(sect.sct_x, sect.sct_y, player->cnum), maxup);
+ break;
}
- if (maxup <= 0)
- continue;
lneeded = intrchr[type].in_lcms * maxup;
hneeded = intrchr[type].in_hcms * maxup;
mneeded = intrchr[type].in_mcost * maxup;
dneeded = intrchr[type].in_dcost * maxup;
player->dolcost += dneeded;
- if (!opt_NO_LCMS)
- sect.sct_item[I_LCM] -= lneeded;
- if (!opt_NO_HCMS)
- sect.sct_item[I_HCM] -= hneeded;
+ sect.sct_item[I_LCM] -= lneeded;
+ sect.sct_item[I_HCM] -= hneeded;
sect.sct_mobil -= mneeded;
ovalue = value;
value += maxup;