/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
*
* Known contributors to this file:
* Steve McClure, 1998-2000
- * Markus Armbruster, 2004-2005
+ * Markus Armbruster, 2004-2006
*/
#include <config.h>
#include <limits.h>
-#include <string.h>
-#include "misc.h"
-#include "player.h"
-#include "plague.h"
-#include "sect.h"
-#include "nat.h"
-#include "ship.h"
+#include "commands.h"
#include "land.h"
+#include "lost.h"
+#include "map.h"
#include "nuke.h"
+#include "optlist.h"
+#include "path.h"
+#include "plague.h"
#include "plane.h"
-#include "xy.h"
-#include "nsc.h"
+#include "ship.h"
#include "treaty.h"
-#include "file.h"
-#include "path.h"
-#include "optlist.h"
-#include "commands.h"
static int build_nuke(struct sctstr *sp,
- struct nchrstr *np, short *vec);
+ struct nchrstr *np, short *vec, int tlev);
static int build_ship(struct sctstr *sp,
- struct mchrstr *mp, short *vec,
- int tlev);
+ struct mchrstr *mp, short *vec, int tlev);
static int build_land(struct sctstr *sp,
- struct lchrstr *lp, short *vec,
- int tlev);
+ struct lchrstr *lp, short *vec, int tlev);
static int build_bridge(struct sctstr *sp, short *vec);
static int build_tower(struct sctstr *sp, short *vec);
static int build_plane(struct sctstr *sp,
- struct plchrstr *pp, short *vec,
- int tlev);
-
-static int cash; /* static ok */
+ struct plchrstr *pp, short *vec, int tlev);
+static int build_can_afford(double, char *);
/*
* build <WHAT> <SECTS> <TYPE|DIR|MEG> [NUMBER]
int tlev;
int rlev;
int type;
- int what;
+ char what;
struct lchrstr *lp;
struct mchrstr *mp;
struct plchrstr *pp;
struct nchrstr *np;
- s_char *p;
+ char *p;
int gotsect = 0;
int built;
- int number = 1, x;
- int asked = 0;
- s_char buf[1024];
+ int number;
+ char buf[1024];
natp = getnatp(player->cnum);
if ((p =
return RET_SYN;
what = *p;
- for (x = 0; x < number; x++) {
- if (!snxtsct(&nstr, player->argp[2])) {
- pr("Bad sector specification.\n");
+ if (!snxtsct(&nstr, player->argp[2])) {
+ pr("Bad sector specification.\n");
+ return RET_SYN;
+ }
+ tlev = (int)natp->nat_level[NAT_TLEV];
+ rlev = (int)natp->nat_level[NAT_RLEV];
+
+ switch (what) {
+ case 'p':
+ p = getstarg(player->argp[3], "Plane type? ", buf);
+ if (p == 0 || *p == 0)
return RET_SYN;
+ type = ef_elt_byname(EF_PLANE_CHR, p);
+ if (type >= 0) {
+ pp = &plchr[type];
+ rqtech = pp->pl_tech;
+ if (rqtech > tlev)
+ type = -1;
}
- tlev = (int)natp->nat_level[NAT_TLEV];
- rlev = (int)natp->nat_level[NAT_RLEV];
-
- switch (what) {
- case 'p':
- p = getstarg(player->argp[3], "Plane type? ", buf);
- if (p == 0 || *p == 0)
- return RET_SYN;
- type = typematch(p, EF_PLANE);
- if (type >= 0) {
- pp = &plchr[type];
- rqtech = pp->pl_tech;
- if (rqtech > tlev)
- type = -1;
- }
- if (type < 0) {
- pr("You can't build that!\n");
- pr("Use `show plane build %d' to show types you can build.\n", tlev);
- return RET_FAIL;
- }
- break;
- case 's':
- p = getstarg(player->argp[3], "Ship type? ", buf);
- if (p == 0 || *p == 0)
- return RET_SYN;
- type = typematch(p, EF_SHIP);
- if (type >= 0) {
- mp = &mchr[type];
- rqtech = mp->m_tech;
- if (rqtech > tlev)
- type = -1;
- if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
- type = -1;
- }
- if (type < 0) {
- pr("You can't build that!\n");
- pr("Use `show ship build %d' to show types you can build.\n", tlev);
- return RET_FAIL;
- }
- break;
- case 'l':
- p = getstarg(player->argp[3], "Land unit type? ", buf);
- if (p == 0 || *p == 0)
- return RET_SYN;
- type = typematch(p, EF_LAND);
- if (type >= 0) {
- lp = &lchr[type];
- rqtech = lp->l_tech;
- if (rqtech > tlev)
- type = -1;
- if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
- type = -1;
- }
- if (type < 0) {
- pr("You can't build that!\n");
- pr("Use `show land build %d' to show types you can build.\n", tlev);
- return RET_FAIL;
- }
- break;
- case 'b':
- if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) {
- pr("Building a span requires a tech of %.0f\n", buil_bt);
- return 2;
- }
- break;
- case 't':
- if (!opt_BRIDGETOWERS) {
- pr("Bridge tower building is disabled.\n");
- return RET_FAIL;
- }
- if (natp->nat_level[NAT_TLEV] + 0.005 < buil_tower_bt) {
- pr("Building a tower requires a tech of %.0f\n",
- buil_tower_bt);
- return 2;
- }
- break;
- case 'n':
- if (!ef_nelem(EF_NUKE_CHR)) {
- pr("There are no nukes in this game.\n");
- return RET_FAIL;
- }
- p = getstarg(player->argp[3], "Nuke type? ", buf);
- if (p == 0 || *p == 0)
- return RET_SYN;
- type = typematch(p, EF_NUKE);
- if (type >= 0) {
- np = &nchr[type];
- rqtech = np->n_tech;
- if (rqtech > tlev
- || (drnuke_const > MIN_DRNUKE_CONST &&
- np->n_tech * drnuke_const > rlev))
- type = -1;
- }
- if (type < 0) {
- int tt = tlev;
- if (drnuke_const > MIN_DRNUKE_CONST)
- tt = (tlev < (rlev / drnuke_const) ? (int)tlev :
- (int)(rlev / drnuke_const));
- pr("You can't build that!\n");
- pr("Use `show nuke build %d' to show types you can build.\n", tt);
- return RET_FAIL;
- }
- break;
- default:
+ if (type < 0) {
+ pr("You can't build that!\n");
+ pr("Use `show plane build %d' to show types you can build.\n",
+ tlev);
+ return RET_FAIL;
+ }
+ break;
+ case 's':
+ p = getstarg(player->argp[3], "Ship type? ", buf);
+ if (p == 0 || *p == 0)
+ return RET_SYN;
+ type = ef_elt_byname(EF_SHIP_CHR, p);
+ if (type >= 0) {
+ mp = &mchr[type];
+ rqtech = mp->m_tech;
+ if (rqtech > tlev)
+ type = -1;
+ if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
+ type = -1;
+ }
+ if (type < 0) {
pr("You can't build that!\n");
+ pr("Use `show ship build %d' to show types you can build.\n",
+ tlev);
return RET_FAIL;
}
- if (what != 'b' && what != 't') {
- if (player->argp[4]) {
- if (atoi(player->argp[4]) > 20 && !asked) {
- s_char bstr[80];
- asked = 1;
- (void)sprintf(bstr,
- "Are you sure that you want to build %s of them? ",
- player->argp[4]);
- p = getstarg(player->argp[6], bstr, buf);
- if (p == 0 || *p != 'y')
- return RET_SYN;
- }
- number = atoi(player->argp[4]);
+ break;
+ case 'l':
+ p = getstarg(player->argp[3], "Land unit type? ", buf);
+ if (p == 0 || *p == 0)
+ return RET_SYN;
+ type = ef_elt_byname(EF_LAND_CHR, p);
+ if (type >= 0) {
+ lp = &lchr[type];
+ rqtech = lp->l_tech;
+ if (rqtech > tlev)
+ type = -1;
+ if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
+ type = -1;
+ }
+ if (type < 0) {
+ pr("You can't build that!\n");
+ pr("Use `show land build %d' to show types you can build.\n",
+ tlev);
+ return RET_FAIL;
+ }
+ break;
+ case 'b':
+ if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) {
+ pr("Building a span requires a tech of %.0f\n", buil_bt);
+ return RET_FAIL;
+ }
+ break;
+ case 't':
+ if (!opt_BRIDGETOWERS) {
+ pr("Bridge tower building is disabled.\n");
+ return RET_FAIL;
+ }
+ if (natp->nat_level[NAT_TLEV] + 0.005 < buil_tower_bt) {
+ pr("Building a tower requires a tech of %.0f\n",
+ buil_tower_bt);
+ return RET_FAIL;
+ }
+ break;
+ case 'n':
+ if (!ef_nelem(EF_NUKE_CHR)) {
+ pr("There are no nukes in this game.\n");
+ return RET_FAIL;
+ }
+ p = getstarg(player->argp[3], "Nuke type? ", buf);
+ if (p == 0 || *p == 0)
+ return RET_SYN;
+ type = ef_elt_byname(EF_NUKE_CHR, p);
+ if (type >= 0) {
+ np = &nchr[type];
+ rqtech = np->n_tech;
+ if (rqtech > tlev
+ || (drnuke_const > MIN_DRNUKE_CONST &&
+ np->n_tech * drnuke_const > rlev))
+ type = -1;
+ }
+ if (type < 0) {
+ int tt = tlev;
+ if (drnuke_const > MIN_DRNUKE_CONST)
+ tt = (tlev < (rlev / drnuke_const) ? (int)tlev :
+ (int)(rlev / drnuke_const));
+ pr("You can't build that!\n");
+ pr("Use `show nuke build %d' to show types you can build.\n",
+ tt);
+ return RET_FAIL;
+ }
+ break;
+ default:
+ pr("You can't build that!\n");
+ return RET_SYN;
+ }
+
+ number = 1;
+ if (what != 'b' && what != 't') {
+ if (player->argp[4]) {
+ number = atoi(player->argp[4]);
+ if (number > 20) {
+ char bstr[80];
+ sprintf(bstr,
+ "Are you sure that you want to build %s of them? ",
+ player->argp[4]);
+ p = getstarg(player->argp[6], bstr, buf);
+ if (p == 0 || *p != 'y')
+ return RET_SYN;
}
}
- if (what != 'b' && what != 'n' && what != 't') {
- if (player->argp[5]) {
- tlev = atoi(player->argp[5]);
- if (tlev > natp->nat_level[NAT_TLEV] && !player->god) {
- pr("Your tech level is only %d.\n",
- (int)natp->nat_level[NAT_TLEV]);
- return RET_FAIL;
- }
- if (rqtech > tlev) {
- pr("Required tech is %d.\n", rqtech);
- return RET_FAIL;
- }
- pr("building with tech level %d.\n", tlev);
- } else
- tlev = (int)natp->nat_level[NAT_TLEV];
+ }
+
+ if (what != 'b' && what != 'n' && what != 't') {
+ if (player->argp[5]) {
+ tlev = atoi(player->argp[5]);
+ if (tlev > natp->nat_level[NAT_TLEV] && !player->god) {
+ pr("Your tech level is only %d.\n",
+ (int)natp->nat_level[NAT_TLEV]);
+ return RET_FAIL;
+ }
+ if (rqtech > tlev) {
+ pr("Required tech is %d.\n", rqtech);
+ return RET_FAIL;
+ }
+ pr("building with tech level %d.\n", tlev);
}
- cash = natp->nat_money;
+ }
+
+ while (number-- > 0) {
while (nxtsct(&nstr, §)) {
gotsect++;
if (!player->owner)
built = build_tower(§, sect.sct_item);
break;
case 'n':
- built = build_nuke(§, np, sect.sct_item);
+ built = build_nuke(§, np, sect.sct_item, tlev);
break;
case 'p':
built = build_plane(§, pp, sect.sct_item, tlev);
break;
default:
- CANT_HAPPEN("Bad WHAT");
+ CANT_REACH();
return RET_FAIL;
}
if (built) {
putsect(§);
}
}
+ snxtsct_rewind(&nstr);
}
if (!gotsect) {
pr("Bad sector specification.\n");
}
static int
-build_ship(struct sctstr *sp, struct mchrstr *mp,
- short *vec, int tlev)
+build_ship(struct sctstr *sp, struct mchrstr *mp, short *vec, int tlev)
{
struct shpstr ship;
struct nstr_item nstr;
- int avail, cost, i;
- float eff = SHIP_MINEFF / 100.0;
+ int avail, i;
+ double cost;
+ double eff = SHIP_MINEFF / 100.0;
int lcm, hcm;
int freeship = 0;
- hcm = roundavg((double)mp->m_hcm * eff);
- lcm = roundavg((double)mp->m_lcm * eff);
+ hcm = roundavg(mp->m_hcm * eff);
+ lcm = roundavg(mp->m_lcm * eff);
if (sp->sct_type != SCT_HARBR) {
pr("Ships must be built in harbours.\n");
pr(" (%d available work required)\n", avail);
return 0;
}
- cost = mp->m_cost * SHIP_MINEFF / 100;
- if (cash < cost) {
- pr("Not enough money left to build a %s\n", mp->m_name);
+ cost = mp->m_cost * SHIP_MINEFF / 100.0;
+ if (!build_can_afford(cost, mp->m_name))
return 0;
- }
if (!trechk(player->cnum, 0, NEWSHP))
return 0;
if (!check_sect_ok(sp))
return 0;
sp->sct_avail -= avail;
player->dolcost += cost;
- cash -= cost;
snxtitem_all(&nstr, EF_SHIP);
while (nxtitem(&nstr, &ship)) {
if (ship.shp_own == 0) {
ship.shp_nland = 0;
ship.shp_nxlight = 0;
ship.shp_nchoppers = 0;
- ship.shp_fleet = ' ';
+ ship.shp_fleet = 0;
memset(ship.shp_item, 0, sizeof(ship.shp_item));
ship.shp_pstage = PLG_HEALTHY;
ship.shp_ptime = 0;
if (sp->sct_pstage == PLG_INFECT)
ship.shp_pstage = PLG_EXPOSED;
- makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x,
- ship.shp_y);
+ makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid,
+ ship.shp_x, ship.shp_y);
putship(ship.shp_uid, &ship);
pr("%s", prship(&ship));
pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
}
static int
-build_land(struct sctstr *sp, struct lchrstr *lp,
- short *vec, int tlev)
+build_land(struct sctstr *sp, struct lchrstr *lp, short *vec, int tlev)
{
struct lndstr land;
struct nstr_item nstr;
- int avail, cost;
- float eff = LAND_MINEFF / 100.0;
+ int avail;
+ double cost;
+ double eff = LAND_MINEFF / 100.0;
int mil, lcm, hcm, gun, shell;
int freeland = 0;
#if 0
- mil = roundavg(((double)lp->l_mil * eff));
- shell = roundavg(((double)lp->l_shell * eff));
- gun = roundavg(((double)lp->l_gun * eff));
+ mil = roundavg(lp->l_mil * eff);
+ shell = roundavg(lp->l_shell * eff);
+ gun = roundavg(lp->l_gun * eff);
#else
mil = shell = gun = 0;
#endif
- hcm = roundavg(((double)lp->l_hcm * eff));
- lcm = roundavg(((double)lp->l_lcm * eff));
+ hcm = roundavg(lp->l_hcm * eff);
+ lcm = roundavg(lp->l_lcm * eff);
if (sp->sct_type != SCT_HEADQ) {
pr("Land Units must be built in headquarters.\n");
pr(" (%d available work required)\n", avail);
return 0;
}
- cost = lp->l_cost * LAND_MINEFF / 100;
- if (cash < cost) {
- pr("Not enough money left to build a %s\n", lp->l_name);
+ cost = lp->l_cost * LAND_MINEFF / 100.0;
+ if (!build_can_afford(cost, lp->l_name))
return 0;
- }
sp->sct_avail -= avail;
player->dolcost += cost;
- cash -= cost;
snxtitem_all(&nstr, EF_LAND);
while (nxtitem(&nstr, &land)) {
if (land.lnd_own == 0) {
land.lnd_mobil = 0;
}
land.lnd_uid = nstr.cur;
- land.lnd_army = ' ';
+ land.lnd_army = 0;
land.lnd_flags = 0;
land.lnd_ship = -1;
land.lnd_land = -1;
if (sp->sct_pstage == PLG_INFECT)
land.lnd_pstage = PLG_EXPOSED;
putland(nstr.cur, &land);
- makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
- land.lnd_y);
+ makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
+ land.lnd_x, land.lnd_y);
pr("%s", prland(&land));
pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
return 1;
int newx, newy;
int avail;
int nx, ny, i, good = 0;
- s_char *p;
- s_char buf[1024];
+ char *p;
+ char buf[1024];
if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */
if (sp->sct_type != SCT_BTOWER) {
return 0;
}
- if (cash < buil_bc) {
- pr("A span costs $%.2f to build; ", buil_bc);
- pr("you only have %d.\n", cash);
+ if (!build_can_afford(buil_bc, dchr[SCT_BSPAN].d_name))
return 0;
- }
avail = (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100;
if (sp->sct_avail < avail) {
pr("Not enough available work in %s to build a bridge\n",
xyas(sp->sct_x, sp->sct_y, player->cnum));
nav_map(sp->sct_x, sp->sct_y, 1);
}
- if (!(p = getstarg(player->argp[3], "build span in what direction? ", buf))
- || !*p) {
+ p = getstarg(player->argp[3], "build span in what direction? ", buf);
+ if (!p || !*p) {
return 0;
}
/* Sanity check time */
} /* end EASY_BRIDGES */
sp->sct_avail -= avail;
player->dolcost += buil_bc;
- cash -= buil_bc;
sect.sct_type = SCT_BSPAN;
sect.sct_newtype = SCT_BSPAN;
sect.sct_effic = SCT_MINEFF;
sect.sct_road = 0;
sect.sct_rail = 0;
sect.sct_defense = 0;
- if (!opt_DEFENSE_INFRA)
- sect.sct_defense = sect.sct_effic;
if (opt_MOB_ACCESS) {
time(§.sct_access);
sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
}
static int
-build_nuke(struct sctstr *sp, struct nchrstr *np,
- short *vec)
+build_nuke(struct sctstr *sp, struct nchrstr *np, short *vec, int tlev)
{
+ struct nukstr nuke;
+ struct nstr_item nstr;
int avail;
+ int freenuke;
if (sp->sct_type != SCT_NUKE && !player->god) {
pr("Nuclear weapons must be built in nuclear plants.\n");
np->n_hcm, np->n_lcm, np->n_oil, np->n_rad);
return 0;
}
- if (cash < np->n_cost) {
- pr("You need $%d, you only have %d.\n", np->n_cost, cash);
+ if (!build_can_afford(np->n_cost, np->n_name))
return 0;
- }
avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
/*
* XXX when nukes turn into units (or whatever), then
return 0;
sp->sct_avail -= avail;
player->dolcost += np->n_cost;
- cash -= np->n_cost;
- nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1);
+ snxtitem_all(&nstr, EF_NUKE);
+ freenuke = 0;
+ while (nxtitem(&nstr, &nuke)) {
+ if (nuke.nuk_own == 0) {
+ freenuke++;
+ break;
+ }
+ }
+ if (freenuke == 0) {
+ ef_extend(EF_NUKE, 50);
+ }
+ memset(&nuke, 0, sizeof(struct nukstr));
+ nuke.nuk_x = sp->sct_x;
+ nuke.nuk_y = sp->sct_y;
+ nuke.nuk_own = sp->sct_own;
+ nuke.nuk_type = np - nchr;
+ nuke.nuk_effic = 100;
+ nuke.nuk_stockpile = 0;
+ nuke.nuk_ship = nuke.nuk_plane = nuke.nuk_land = -1;
+ nuke.nuk_uid = nstr.cur;
+ nuke.nuk_tech = tlev;
+
vec[I_HCM] -= np->n_hcm;
vec[I_LCM] -= np->n_lcm;
vec[I_OIL] -= np->n_oil;
vec[I_RAD] -= np->n_rad;
- pr("%s warhead created in %s\n", np->n_name,
+
+ makenotlost(EF_NUKE, nuke.nuk_own, nuke.nuk_uid,
+ nuke.nuk_x, nuke.nuk_y);
+ putnuke(nuke.nuk_uid, &nuke);
+ pr("%s created in %s\n", prnuke(&nuke),
xyas(sp->sct_x, sp->sct_y, player->cnum));
return 1;
}
static int
-build_plane(struct sctstr *sp, struct plchrstr *pp,
- short *vec, int tlev)
+build_plane(struct sctstr *sp, struct plchrstr *pp, short *vec, int tlev)
{
struct plnstr plane;
- int avail, cost;
struct nstr_item nstr;
- float eff = PLANE_MINEFF / 100.0;
+ int avail;
+ double cost;
+ double eff = PLANE_MINEFF / 100.0;
int hcm, lcm, mil;
- int freeplane = 0;
+ int freeplane;
- mil = roundavg(((double)pp->pl_crew * eff));
+ mil = roundavg(pp->pl_crew * eff);
/* Always use at least 1 mil to build a plane */
if (mil == 0 && pp->pl_crew > 0)
mil = 1;
- hcm = roundavg(((double)pp->pl_hcm * eff));
- lcm = roundavg(((double)pp->pl_lcm * eff));
+ hcm = roundavg(pp->pl_hcm * eff);
+ lcm = roundavg(pp->pl_lcm * eff);
if (sp->sct_type != SCT_AIRPT && !player->god) {
pr("Planes must be built in airports.\n");
return 0;
pr(" (%d available work required)\n", avail);
return 0;
}
- cost = pp->pl_cost * PLANE_MINEFF / 100;
- if (cash < cost) {
- pr("Not enough money left to build a %s\n", pp->pl_name);
+ cost = pp->pl_cost * PLANE_MINEFF / 100.0;
+ if (!build_can_afford(cost, pp->pl_name))
return 0;
- }
if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) {
pr("Not enough military for crew in %s\n",
xyas(sp->sct_x, sp->sct_y, player->cnum));
return 0;
sp->sct_avail -= avail;
player->dolcost += cost;
- cash -= cost;
snxtitem_all(&nstr, EF_PLANE);
freeplane = 0;
while (nxtitem(&nstr, &plane)) {
plane.pln_radius = 0;
plane.pln_range = UCHAR_MAX; /* will be adjusted by pln_set_tech() */
plane.pln_range_max = plane.pln_range;
- plane.pln_wing = ' ';
+ plane.pln_wing = 0;
plane.pln_ship = -1;
plane.pln_land = -1;
plane.pln_uid = nstr.cur;
vec[I_HCM] -= hcm;
vec[I_MILIT] -= mil;
- makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
- plane.pln_y);
+ makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
+ plane.pln_x, plane.pln_y);
putplane(plane.pln_uid, &plane);
pr("%s built in sector %s\n", prplane(&plane),
xyas(sp->sct_x, sp->sct_y, player->cnum));
int val;
int newx, newy;
int avail;
- s_char *p;
- s_char buf[1024];
+ char *p;
+ char buf[1024];
int good;
int i;
int nx;
return 0;
}
- if (cash < buil_tower_bc) {
- pr("A bridge tower costs $%.2f to build; ", buil_tower_bc);
- pr("you only have %d.\n", cash);
+ if (!build_can_afford(buil_tower_bc, dchr[SCT_BTOWER].d_name))
return 0;
- }
avail = (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100;
if (sp->sct_avail < avail) {
pr("Not enough available work in %s to build a bridge tower\n",
pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
nav_map(sp->sct_x, sp->sct_y, 1);
}
- if (!(p = getstarg(player->argp[3], "build tower in what direction? ", buf))
- || !*p) {
+ p = getstarg(player->argp[3], "build tower in what direction? ", buf);
+ if (!p || !*p) {
return 0;
}
/* Sanity check time */
sp->sct_avail -= avail;
player->dolcost += buil_tower_bc;
- cash -= buil_tower_bc;
sect.sct_type = SCT_BTOWER;
sect.sct_newtype = SCT_BTOWER;
sect.sct_effic = SCT_MINEFF;
} else {
sect.sct_mobil = 0;
}
- if (!opt_DEFENSE_INFRA)
- sect.sct_defense = sect.sct_effic;
sect.sct_mines = 0;
map_set(player->cnum, sect.sct_x, sect.sct_y, dchr[SCT_BTOWER].d_mnem, 2);
writemap(player->cnum);
vec[I_HCM] -= buil_tower_bh;
return 1;
}
+
+static int
+build_can_afford(double cost, char *what)
+{
+ struct natstr *natp = getnatp(player->cnum);
+ if (natp->nat_money < player->dolcost + cost) {
+ pr("Not enough money left to build a %s\n", what);
+ return 0;
+ }
+ return 1;
+}