From 17494e74d1a703c65d2feacbeb695c02ce4e6bd7 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 15 May 2004 13:23:39 +0000 Subject: [PATCH] (SCT_BLD_WORK, SHP_BLD_WORK, PLN_BLD_WORK, LND_BLD_WORK, NUK_BLD_WORK): New, to encapsulate the formula in one place. (SCT_MINEFF): New. Use it instead of literal 20. (buil): Use CANT_HAPPEN() for internal error. (build_ship, build_land, build_bridge, build_nuke, build_plane, build_tower): Simplify avail calculation. (lupgr, supgr, pupgr): Charge 15% of total build avail instead of an undocumented amount computed from build lcm and hcm. (build_ship, build_land, build_bridge, build_nuke, build_plane, build_tower, lupgr, supgr, pupgr): Fix reporting of required avail when there's not enough. Closes #942823. (lupgr, supgr, pupgr): Code printed cost rounded down, but required and charged unrounded cost. Confusing. Round cost down, like the build command. Closes #942811. (UPGR_COST, UPGR_EFF, lupgr, supgr, pupgr): New UPGR_COST, UPGR_COST replace literal values. (show_bridge, show_tower): Don't claim bridge building requires `workers' (whatever that is), since it doesn't. --- include/land.h | 4 +- include/nuke.h | 4 + include/plane.h | 2 + include/sect.h | 6 ++ include/ship.h | 9 +-- src/lib/commands/bomb.c | 2 +- src/lib/commands/buil.c | 148 ++++++++++++++---------------------- src/lib/commands/upgr.c | 77 +++++++++---------- src/lib/common/sectdamage.c | 4 +- src/lib/subs/sect.c | 2 +- src/lib/subs/show.c | 19 ++--- src/lib/update/land.c | 2 +- src/lib/update/plane.c | 2 +- src/lib/update/ship.c | 2 +- 14 files changed, 128 insertions(+), 155 deletions(-) diff --git a/include/land.h b/include/land.h index 7ee2e2583..92cfe449e 100644 --- a/include/land.h +++ b/include/land.h @@ -169,7 +169,9 @@ struct lchrstr { #define LND_FU(b, t) (b) #define LND_XPL(b, t) (b) #define LND_MXL(b, t) (b) -#define LND_COST(b, t) ((b) * (1.0 + (sqrt((double)(t)) / 100.0))) + +/* Work required for building 100% */ +#define LND_BLD_WORK(lcm, hcm) (20 + (lcm) + 2 * (hcm)) /* Chance to detect L_SPY unit (percent) */ #define LND_SPY_DETECT_CHANCE(eff) ((110-(eff))/100.0) diff --git a/include/nuke.h b/include/nuke.h index bd05fbbc4..9cbb5257f 100644 --- a/include/nuke.h +++ b/include/nuke.h @@ -72,6 +72,10 @@ struct nchrstr { #define getnukep(n) \ (struct nukstr *) ef_ptr(EF_NUKE, n) +/* Work required for building */ +#define NUK_BLD_WORK(lcm, hcm, oil, rad) \ + (((lcm) + 2 * (hcm) + (oil) + (rad) + 4) / 5) + extern struct nchrstr nchr[]; extern int nuk_maxno; diff --git a/include/plane.h b/include/plane.h index 90533b17a..25e5f4f9b 100644 --- a/include/plane.h +++ b/include/plane.h @@ -164,6 +164,8 @@ struct shiplook { #define PLN_LOAD(b, t) (t ? (b * (logx((double)t, (double)50.0) < 1.0 ? 1.0 : \ logx((double)t, (double)50.0))) : b) +/* Work required for building 100% */ +#define PLN_BLD_WORK(lcm, hcm) (20 + (lcm) + 2 * (hcm)) /* src/lib/subs/aircombat.c */ extern void ac_planedamage(struct plist *, natid, int, natid, int, diff --git a/include/sect.h b/include/sect.h index 4f9e03d3f..6a40eff0e 100644 --- a/include/sect.h +++ b/include/sect.h @@ -166,6 +166,12 @@ extern int sct_maxno; extern struct dchrstr dchr[]; extern struct dchrstr bigcity_dchr; +/* Minimal efficiency of sectors that can be knocked down (bridges) */ +#define SCT_MINEFF 20 + +/* Work required for building */ +#define SCT_BLD_WORK(lcm, hcm) ((lcm) + 2 * (hcm)) + #define MIN_MOBCOST 0.001 /* lowest cost a sector can have to move into */ #define FORTEFF 5 /* forts must be 5% efficient to fire. */ diff --git a/include/ship.h b/include/ship.h index 9887beb2e..d6d56fcc6 100644 --- a/include/ship.h +++ b/include/ship.h @@ -46,12 +46,6 @@ /* bit masks for the autonav mode flags */ -/* -#define AN_SAILDIR 1 -#define AN_AUTONAV 2 -#define AN_STANDBY 4 -#define AN_LOADING 8 - */ #define AN_SAILDIR bit(1) #define AN_AUTONAV bit(2) #define AN_STANDBY bit(3) @@ -212,6 +206,9 @@ struct mlist { #define SHP_FIR(b, t) (t ? (b * (logx((double)t, (double)60.0) < 1.0 ? 1.0 : \ logx((double)t, (double)60.0))) : b) +/* Work required for building 100% */ +#define SHP_BLD_WORK(lcm, hcm) (20 + (lcm) + 2 * (hcm)) + /* return codes from shp_check_nav */ #define CN_NAVIGABLE (0) #define CN_LANDLOCKED (1) diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index 206ef4b9d..549e5f19f 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -404,7 +404,7 @@ eff_bomb(struct emp_qelem *list, struct sctstr *target) "%s bombing raid did %d%% damage in %s\n", cname(player->cnum), oldeff - target->sct_effic, xyas(target->sct_x, target->sct_y, target->sct_own)); - if (target->sct_effic < 20) { + if (target->sct_effic < SCT_MINEFF) { if (target->sct_type == SCT_BSPAN) knockdown(target, list); else if (target->sct_type == SCT_BTOWER) { diff --git a/src/lib/commands/buil.c b/src/lib/commands/buil.c index b6b05ba3a..8a5d091e5 100644 --- a/src/lib/commands/buil.c +++ b/src/lib/commands/buil.c @@ -326,7 +326,7 @@ buil(void) built = build_plane(§, pp, sect.sct_item, tlev); break; default: - pr("internal error in build (%d)\n", what); + CANT_HAPPEN("Bad WHAT"); return RET_FAIL; } if (built) { @@ -346,15 +346,14 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp, { struct shpstr ship; struct nstr_item nstr; - int cost, i; - int w_p_eff, x; - float eff = ((float)SHIP_MINEFF / 100.0); - int points, lcm, hcm; + int avail, cost, i; + float eff = SHIP_MINEFF / 100.0; + int lcm, hcm; int freeship = 0; int techdiff; - hcm = roundavg(((double)mp->m_hcm * (double)eff)); - lcm = roundavg(((double)mp->m_lcm * (double)eff)); + hcm = roundavg((double)mp->m_hcm * eff); + lcm = roundavg((double)mp->m_lcm * eff); if (sp->sct_type != SCT_HARBR) { pr("Ships must be built in harbours.\n"); @@ -370,16 +369,14 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp, xyas(sp->sct_x, sp->sct_y, player->cnum)); return 0; } - w_p_eff = (20 + mp->m_lcm + (mp->m_hcm * 2)); - points = sp->sct_avail * 100 / w_p_eff; - if (points < SHIP_MINEFF) { + avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * SHIP_MINEFF + 99) / 100; + if (sp->sct_avail < avail) { pr("Not enough available work in %s to build a %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum), mp->m_name); - pr(" (%d available work required)\n", - 1 + (w_p_eff * SHIP_MINEFF) / 100); + pr(" (%d available work required)\n", avail); return 0; } - cost = mp->m_cost * eff; + cost = mp->m_cost * SHIP_MINEFF / 100; if (cash < cost) { pr("Not enough money left to build a %s\n", mp->m_name); return 0; @@ -388,7 +385,7 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp, return 0; if (!check_sect_ok(sp)) return 0; - sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * SHIP_MINEFF) / 100; + sp->sct_avail -= avail; player->dolcost += cost; cash -= cost; snxtitem_all(&nstr, EF_SHIP); @@ -453,8 +450,7 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp, ship.shp_orig_y = sp->sct_y; ship.shp_fuel = mchr[(int)ship.shp_type].m_fuelc; ship.shp_rflags = 0; - for (x = 0; x < 10; x++) - ship.shp_rpath[x] = 0; + memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath)); vec[I_LCM] -= lcm; vec[I_HCM] -= hcm; @@ -475,22 +471,21 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp, { struct lndstr land; struct nstr_item nstr; - int cost; - int w_p_eff; - int points; + int avail, cost; struct natstr *natp; - float eff = ((float)LAND_MINEFF / 100.0); + float eff = LAND_MINEFF / 100.0; int mil, lcm, hcm, gun, shell; int freeland = 0; - /* - mil = roundavg(((double)lp->l_mil * (double)eff)); - shell = roundavg(((double)lp->l_shell * (double)eff)); - gun = roundavg(((double)lp->l_gun * (double)eff)); - */ +#if 0 + mil = roundavg(((double)lp->l_mil * eff)); + shell = roundavg(((double)lp->l_shell * eff)); + gun = roundavg(((double)lp->l_gun * eff)); +#else mil = shell = gun = 0; - hcm = roundavg(((double)lp->l_hcm * (double)eff)); - lcm = roundavg(((double)lp->l_lcm * (double)eff)); +#endif + hcm = roundavg(((double)lp->l_hcm * eff)); + lcm = roundavg(((double)lp->l_lcm * eff)); natp = getnatp(player->cnum); @@ -529,22 +524,19 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp, return 0; if (!check_sect_ok(sp)) return 0; - w_p_eff = (20 + lp->l_lcm + (lp->l_hcm * 2)); - points = sp->sct_avail * 100 / w_p_eff; - if (points < LAND_MINEFF) { + avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * LAND_MINEFF + 99) / 100; + if (sp->sct_avail < avail) { pr("Not enough available work in %s to build a %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name); - pr(" (%d available work required)\n", - 1 + (w_p_eff * LAND_MINEFF) / 100); + pr(" (%d available work required)\n", avail); return 0; } - cost = ((float)lp->l_cost * eff); - /* cost = (int)LND_COST(cost, tlev - lp->l_tech); */ + cost = lp->l_cost * LAND_MINEFF / 100; if (cash < cost) { pr("Not enough money left to build a %s\n", lp->l_name); return 0; } - sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * LAND_MINEFF) / 100; + sp->sct_avail -= avail; player->dolcost += cost; cash -= cost; snxtitem_all(&nstr, EF_LAND); @@ -626,8 +618,7 @@ build_bridge(register struct sctstr *sp, short *vec) struct sctstr sect; int val; int newx, newy; - int w_p_eff; - int points; + int avail; int nx, ny, i, good = 0; s_char *p; s_char buf[1024]; @@ -695,12 +686,11 @@ build_bridge(register struct sctstr *sp, short *vec) pr("you only have %d.\n", cash); return 0; } - w_p_eff = buil_bh * 2; - points = sp->sct_avail * 100 / w_p_eff; - if (points < 20) { + 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)); - pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100); + pr(" (%d available work required)\n", avail); return 0; } if (!player->argp[3]) { @@ -744,12 +734,12 @@ build_bridge(register struct sctstr *sp, short *vec) return 0; } } /* end EASY_BRIDGES */ - sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100; + sp->sct_avail -= avail; player->dolcost += buil_bc; cash -= buil_bc; sect.sct_type = SCT_BSPAN; sect.sct_newtype = SCT_BSPAN; - sect.sct_effic = 20; + sect.sct_effic = SCT_MINEFF; sect.sct_road = 0; sect.sct_rail = 0; sect.sct_defense = 0; @@ -776,8 +766,7 @@ static int build_nuke(register struct sctstr *sp, register struct nchrstr *np, short *vec) { - int w_p_eff; - int points; + int avail; if (sp->sct_type != SCT_NUKE && !player->god) { pr("Nuclear weapons must be built in nuclear plants.\n"); @@ -800,24 +789,23 @@ build_nuke(register struct sctstr *sp, register struct nchrstr *np, pr("You need $%d, you only have %d.\n", np->n_cost, cash); return 0; } - w_p_eff = np->n_rad + np->n_oil + np->n_lcm + np->n_hcm * 2; - points = sp->sct_avail * 100 / w_p_eff; + 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 * make them start at 20%. Since they don't have efficiency - * now, we choose 20% as a "big" number. + * now, we charge all the work right away. */ - if (points < 20) { + if (sp->sct_avail < avail) { pr("Not enough available work in %s to build a %s;\n", xyas(sp->sct_x, sp->sct_y, player->cnum), np->n_name); - pr(" (%d available work required)\n", 1 + w_p_eff * 20 / 100); + pr(" (%d available work required)\n", avail); return 0; } if (!trechk(player->cnum, 0, NEWNUK)) return 0; if (!check_sect_ok(sp)) return 0; - sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100; + sp->sct_avail -= avail; player->dolcost += np->n_cost; cash -= np->n_cost; nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1); @@ -835,20 +823,18 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp, short *vec, int tlev) { struct plnstr plane; - int cost; + int avail, cost; struct nstr_item nstr; - float eff = ((float)PLANE_MINEFF / 100.0); - int points; - int w_p_eff; + float eff = PLANE_MINEFF / 100.0; int hcm, lcm, mil; int freeplane = 0; - mil = roundavg(((double)pp->pl_crew * (double)eff)); + mil = roundavg(((double)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 * (double)eff)); - lcm = roundavg(((double)pp->pl_lcm * (double)eff)); + hcm = roundavg(((double)pp->pl_hcm * eff)); + lcm = roundavg(((double)pp->pl_lcm * eff)); if (sp->sct_type != SCT_AIRPT && !player->god) { pr("Planes must be built in airports.\n"); return 0; @@ -863,16 +849,14 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp, xyas(sp->sct_x, sp->sct_y, player->cnum)); return 0; } - w_p_eff = (20 + pp->pl_lcm + (pp->pl_hcm * 2)); - points = sp->sct_avail * 100 / w_p_eff; - if (points < PLANE_MINEFF) { + avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * PLANE_MINEFF + 99) / 100; + if (sp->sct_avail < avail) { pr("Not enough available work in %s to build a %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name); - pr(" (%d available work required)\n", - 1 + PLANE_MINEFF * w_p_eff / 100); + pr(" (%d available work required)\n", avail); return 0; } - cost = pp->pl_cost * eff; + cost = pp->pl_cost * PLANE_MINEFF / 100; if (cash < cost) { pr("Not enough money left to build a %s\n", pp->pl_name); return 0; @@ -886,7 +870,7 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp, return 0; if (!check_sect_ok(sp)) return 0; - sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * PLANE_MINEFF) / 100; + sp->sct_avail -= avail; player->dolcost += cost; cash -= cost; snxtitem_all(&nstr, EF_PLANE); @@ -921,26 +905,6 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp, * planes may have their own stats (like based on tech maybe? :) ) Thus, * the code now checks the pln_acc, pln_load and pln_fuel instead of using * the static definitions of them. */ -/* - n = (int) (pp->pl_range * (0.75 + techfact(tlev - pp->pl_tech, 2.0))); - if (n > 127) - n = 127; - plane.pln_range = n; - plane.pln_range_max = n; - n = (int) (pp->pl_att * (0.75 + techfact(tlev - pp->pl_tech, 2.0))); - if (n > 127) - n = 127; - plane.pln_att = n; - n = (int) (pp->pl_def * (0.75 + techfact(tlev - pp->pl_tech, 2.0))); - if (n > 127) - n = 127; - if (n < pp->pl_def) - n = pp->pl_def; - plane.pln_def = n; - plane.pln_acc = pp->pl_acc; - plane.pln_load = pp->pl_load; - plane.pln_fuel = pp->pl_fuel; -*/ plane.pln_att = PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)); plane.pln_def = PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)); plane.pln_acc = PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)); @@ -974,8 +938,7 @@ build_tower(register struct sctstr *sp, short *vec) struct sctstr sect; int val; int newx, newy; - int w_p_eff; - int points; + int avail; s_char *p; s_char buf[1024]; int good; @@ -1016,12 +979,11 @@ build_tower(register struct sctstr *sp, short *vec) pr("you only have %d.\n", cash); return 0; } - w_p_eff = buil_tower_bh * 2; - points = sp->sct_avail * 100 / w_p_eff; - if (points < 20) { + 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", xyas(sp->sct_x, sp->sct_y, player->cnum)); - pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100); + pr(" (%d available work required)\n", avail); return 0; } if (!player->argp[3]) { @@ -1068,12 +1030,12 @@ build_tower(register struct sctstr *sp, short *vec) return 0; } - sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100; + 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 = 20; + sect.sct_effic = SCT_MINEFF; sect.sct_road = 0; sect.sct_rail = 0; sect.sct_defense = 0; diff --git a/src/lib/commands/upgr.c b/src/lib/commands/upgr.c index c84191392..6fa951ea8 100644 --- a/src/lib/commands/upgr.c +++ b/src/lib/commands/upgr.c @@ -47,6 +47,11 @@ #include "file.h" #include "commands.h" +enum { + UPGR_COST = 15, /* how much avail and money to charge */ + UPGR_EFF = 35 /* efficiency reduction */ +}; + static int lupgr(void); static int pupgr(void); static int supgr(void); @@ -86,8 +91,7 @@ lupgr(void) struct lchrstr *lp; int n; int tlev; - int w_p_eff; - int points; + int avail, cost; int rel; int techdiff; long cash; @@ -114,13 +118,11 @@ lupgr(void) } n++; lp = &lchr[(int)land.lnd_type]; - w_p_eff = ((lp->l_lcm / 2) + lp->l_hcm); - points = sect.sct_avail * 100 / w_p_eff; - if (points < 20) { + avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * UPGR_COST + 99) / 100; + if (sect.sct_avail < avail) { pr("Not enough available work in %s to upgrade a %s\n", xyas(sect.sct_x, sect.sct_y, player->cnum), lp->l_name); - pr(" (%d available work required)\n", - 1 + (w_p_eff * 20) / 100); + pr(" (%d available work required)\n", avail); continue; } if (land.lnd_effic < 60) { @@ -132,14 +134,15 @@ lupgr(void) land.lnd_tech, tlev); continue; } - if (lp->l_cost * .15 + player->dolcost > cash) { + cost = lp->l_cost * UPGR_COST / 100; + if (cost + player->dolcost > cash) { pr("You don't have enough money to upgrade %s!\n", prland(&land)); continue; } - sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100; - land.lnd_effic -= 35; + sect.sct_avail -= avail; + land.lnd_effic -= UPGR_EFF; land.lnd_tech = tlev; techdiff = (int)(tlev - lp->l_tech); @@ -168,14 +171,14 @@ lupgr(void) putland(land.lnd_uid, &land); putsect(§); - player->dolcost += (double)lp->l_cost * .15; + player->dolcost += cost; pr("%s upgraded to tech %d, at a cost of %d\n", prland(&land), - land.lnd_tech, (int)(lp->l_cost * .15)); + land.lnd_tech, cost); if (land.lnd_own != player->cnum) wu(0, land.lnd_own, "%s upgraded by %s to tech %d, at a cost of %d\n", prland(&land), cname(player->cnum), land.lnd_tech, - (int)(lp->l_cost * .15)); + cost); } if (n == 0) { pr("No land units\n"); @@ -194,8 +197,7 @@ supgr(void) struct mchrstr *mp; int n; int tlev; - int w_p_eff; - int points; + int avail, cost; int rel; int techdiff; long cash; @@ -222,13 +224,11 @@ supgr(void) } n++; mp = &mchr[(int)ship.shp_type]; - w_p_eff = ((mp->m_lcm / 2) + mp->m_hcm); - points = sect.sct_avail * 100 / w_p_eff; - if (points < 20) { + avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * UPGR_COST + 99) / 100; + if (sect.sct_avail < avail) { pr("Not enough available work in %s to upgrade a %s\n", xyas(sect.sct_x, sect.sct_y, player->cnum), mp->m_name); - pr(" (%d available work required)\n", - 1 + (w_p_eff * 20) / 100); + pr(" (%d available work required)\n", avail); continue; } if (ship.shp_effic < 60) { @@ -240,14 +240,15 @@ supgr(void) ship.shp_tech, tlev); continue; } - if (mp->m_cost * .15 + player->dolcost > cash) { + cost = mp->m_cost * UPGR_COST / 100; + if (cost + player->dolcost > cash) { pr("You don't have enough money to upgrade %s!\n", prship(&ship)); continue; } - sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100; - ship.shp_effic -= 35; + sect.sct_avail -= avail; + ship.shp_effic -= UPGR_EFF; ship.shp_tech = tlev; techdiff = (int)(tlev - mp->m_tech); @@ -262,14 +263,14 @@ supgr(void) putship(ship.shp_uid, &ship); putsect(§); - player->dolcost += (double)mp->m_cost * .15; + player->dolcost += cost; pr("%s upgraded to tech %d, at a cost of %d\n", prship(&ship), - ship.shp_tech, (int)(mp->m_cost * .15)); + ship.shp_tech, cost); if (ship.shp_own != player->cnum) wu(0, ship.shp_own, "%s upgraded by %s to tech %d, at a cost of %d\n", prship(&ship), cname(player->cnum), ship.shp_tech, - (int)(mp->m_cost * .15)); + cost); } if (n == 0) { pr("No ships\n"); @@ -288,8 +289,7 @@ pupgr(void) struct plchrstr *pp; int n; int tlev; - int w_p_eff; - int points; + int avail, cost; int rel; int techdiff; long cash; @@ -316,13 +316,11 @@ pupgr(void) } n++; pp = &plchr[(int)plane.pln_type]; - w_p_eff = ((pp->pl_lcm / 2) + pp->pl_hcm); - points = sect.sct_avail * 100 / w_p_eff; - if (points < 20) { + avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * UPGR_COST + 99) / 100; + if (sect.sct_avail < avail) { pr("Not enough available work in %s to upgrade a %s\n", xyas(sect.sct_x, sect.sct_y, player->cnum), pp->pl_name); - pr(" (%d available work required)\n", - 1 + (w_p_eff * 20) / 100); + pr(" (%d available work required)\n", avail); continue; } if (plane.pln_effic < 60) { @@ -334,7 +332,8 @@ pupgr(void) plane.pln_tech, tlev); continue; } - if (pp->pl_cost * .15 + player->dolcost > cash) { + cost = pp->pl_cost * UPGR_COST / 100; + if (cost + player->dolcost > cash) { pr("You don't have enough money to upgrade %s!\n", prplane(&plane)); continue; @@ -344,8 +343,8 @@ pupgr(void) continue; } - sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100; - plane.pln_effic -= 35; + sect.sct_avail -= avail; + plane.pln_effic -= UPGR_EFF; plane.pln_tech = tlev; techdiff = (int)(tlev - pp->pl_tech); @@ -368,14 +367,14 @@ pupgr(void) putplane(plane.pln_uid, &plane); putsect(§); - player->dolcost += (double)pp->pl_cost * .15; + player->dolcost += cost; pr("%s upgraded to tech %d, at a cost of %d\n", prplane(&plane), - plane.pln_tech, (int)(pp->pl_cost * .15)); + plane.pln_tech, cost); if (plane.pln_own != player->cnum) wu(0, plane.pln_own, "%s upgraded by %s to tech %d, at a cost of %d\n", prplane(&plane), cname(player->cnum), plane.pln_tech, - (int)(pp->pl_cost * .15)); + cost); } if (n == 0) { pr("No planes.\n"); diff --git a/src/lib/common/sectdamage.c b/src/lib/common/sectdamage.c index 85e660258..c92ab33b6 100644 --- a/src/lib/common/sectdamage.c +++ b/src/lib/common/sectdamage.c @@ -75,10 +75,10 @@ sect_damage(struct sctstr *sp, int dam, struct emp_qelem *list) sp->sct_mobil = damage(sp->sct_mobil, dam); item_damage(dam, sp->sct_item); if (opt_EASY_BRIDGES == 0) { - if (sp->sct_effic < 20 && sp->sct_type == SCT_BHEAD) + if (sp->sct_effic < SCT_MINEFF && sp->sct_type == SCT_BHEAD) bridgefall(sp, list); } else { - if (sp->sct_effic < 20 && sp->sct_type == SCT_BSPAN) + if (sp->sct_effic < SCT_MINEFF && sp->sct_type == SCT_BSPAN) knockdown(sp, list); } putsect(sp); diff --git a/src/lib/subs/sect.c b/src/lib/subs/sect.c index b5a1a6f84..c84c4a1b1 100644 --- a/src/lib/subs/sect.c +++ b/src/lib/subs/sect.c @@ -91,7 +91,7 @@ checksect(struct sctstr *sp) else loyalcivs = 0; - if (sp->sct_effic < 20) { + if (sp->sct_effic < SCT_MINEFF) { if (sp->sct_type == SCT_BSPAN) knockdown(sp, 0); else if (sp->sct_type == SCT_BTOWER) { diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c index c24bb83cb..402a65423 100644 --- a/src/lib/subs/show.c +++ b/src/lib/subs/show.c @@ -234,9 +234,10 @@ show_bridge(int tlev) pr(" %d hcm,", buil_bh); else if (!opt_NO_LCMS) pr(" %d lcm,", buil_bh); - pr(" %d workers,\n", buil_bh * 2); + pr(" %d workers,\n", 0); pr("%d available workforce, and cost $%g\n", - 1 + (buil_bh * 40 / 100), buil_bc); + (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100, + buil_bc); } void @@ -249,9 +250,10 @@ show_tower(int tlev) pr(" %d hcm,", buil_tower_bh); else if (!opt_NO_LCMS) pr(" %d lcm,", buil_tower_bh); - pr(" %d workers,\n", buil_tower_bh * 2); + pr(" %d workers,\n", 0); pr("%d available workforce, and cost $%g\n", - 1 + (buil_tower_bh * 40 / 100), buil_tower_bc); + (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100, + buil_tower_bc); } void @@ -275,8 +277,7 @@ show_nuke_build(int tlev) if (opt_NONUKES) return; for (np = nchr, n = 0; n < N_MAXNUKE; np++, n++) { - avail = - (4 + np->n_rad + np->n_oil + np->n_lcm + np->n_hcm * 2) / 5; + avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad); if (np->n_tech > tlev) continue; if (np->n_name == 0 || np->n_name[0] == '\0') @@ -355,7 +356,7 @@ show_ship_build(int tlev) pr("%-25.25s %3d %3d %5d %4d $%d\n", mp->m_name, mp->m_lcm, mp->m_hcm, - 20 + mp->m_lcm + mp->m_hcm * 2, mp->m_tech, mp->m_cost); + SHP_BLD_WORK(mp->m_lcm, mp->m_hcm), mp->m_tech, mp->m_cost); } } @@ -529,7 +530,7 @@ show_plane_build(int tlev) pr("%-25.25s %3d %3d %3d %5d %4d $%d\n", pp->pl_name, pp->pl_lcm, pp->pl_hcm, pp->pl_crew, - 20 + 2 * pp->pl_hcm + pp->pl_lcm, pp->pl_tech, pp->pl_cost); + PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm), pp->pl_tech, pp->pl_cost); } } @@ -549,7 +550,7 @@ show_land_build(int tlev) lp->l_name, lp->l_lcm, lp->l_hcm, lp->l_gun, - 20 + lp->l_lcm + (lp->l_hcm * 2), lp->l_tech, lp->l_cost); + LND_BLD_WORK(lp->l_lcm, lp->l_hcm), lp->l_tech, lp->l_cost); } } diff --git a/src/lib/update/land.c b/src/lib/update/land.c index 453bc8f41..9c1e878e4 100644 --- a/src/lib/update/land.c +++ b/src/lib/update/land.c @@ -267,7 +267,7 @@ landrepair(register struct lndstr *land, struct natstr *np, else avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100; - w_p_eff = 20 + (lp->l_lcm + 2 * lp->l_hcm); + w_p_eff = LND_BLD_WORK(lp->l_lcm, lp->l_hcm); delta = roundavg((double)avail / w_p_eff); if (delta <= 0) return 1; diff --git a/src/lib/update/plane.c b/src/lib/update/plane.c index 8fb773d31..4cf30898b 100644 --- a/src/lib/update/plane.c +++ b/src/lib/update/plane.c @@ -179,7 +179,7 @@ prod_plane(int etus, int natnum, int *bp, int buildem) shp = getshipp(pp->pln_ship); avail += (etus * shp->shp_item[I_MILIT] / 2); } - w_p_eff = 20 + (desc->pl_lcm + 2 * desc->pl_hcm); + w_p_eff = PLN_BLD_WORK(desc->pl_lcm, desc->pl_hcm); delta = roundavg((double)avail / w_p_eff); if (delta <= 0) continue; diff --git a/src/lib/update/ship.c b/src/lib/update/ship.c index f8686ac86..77abc4afc 100644 --- a/src/lib/update/ship.c +++ b/src/lib/update/ship.c @@ -299,7 +299,7 @@ shiprepair(register struct shpstr *ship, struct natstr *np, avail = wf + gt_bg_nmbr(bp, sp, I_MAX + 1) * 100; } - w_p_eff = 20 + (mp->m_lcm + 2 * mp->m_hcm); + w_p_eff = SHP_BLD_WORK(mp->m_lcm, mp->m_hcm); if ((sp->sct_off) && (sp->sct_own == ship->shp_own)) return 1; -- 2.43.0