]> git.pond.sub.org Git - empserver/commitdiff
(SCT_BLD_WORK, SHP_BLD_WORK, PLN_BLD_WORK, LND_BLD_WORK,
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 15 May 2004 13:23:39 +0000 (13:23 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 15 May 2004 13:23:39 +0000 (13:23 +0000)
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.

14 files changed:
include/land.h
include/nuke.h
include/plane.h
include/sect.h
include/ship.h
src/lib/commands/bomb.c
src/lib/commands/buil.c
src/lib/commands/upgr.c
src/lib/common/sectdamage.c
src/lib/subs/sect.c
src/lib/subs/show.c
src/lib/update/land.c
src/lib/update/plane.c
src/lib/update/ship.c

index 7ee2e2583b5386ad9a12418d8760801e3e5cf958..92cfe449ebd1f4d3d5056dde002ca8d69cab0ba3 100644 (file)
@@ -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)
index bd05fbbc4d487009922023db29cc73b6b678fa86..9cbb5257f0b34019b37b143089c45ee01de63250 100644 (file)
@@ -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;
index 90533b17a6ef7ee87c0b61316d339e0bb0340864..25e5f4f9befdaedc89bf4d1ae2d93c217f0eed9c 100644 (file)
@@ -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,
index 4f9e03d3f47d01a06cd7bec4a03d08aa36a55b10..6a40eff0e53dde630b3c2c9f9d5c293a364de5d7 100644 (file)
@@ -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. */
 
index 9887beb2eec4a729d60794f0bcb79d69ff05b56d..d6d56fcc6a4fd3b736c698001e0284474a6fcd20 100644 (file)
 
 /* 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)
index 206ef4b9d3d1a07350685ac1d2426b877bae634f..549e5f19f1e2aea7a746081f0bb94d71a2224668 100644 (file)
@@ -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) {
index b6b05ba3afeaece7c167efdcbffd07218579cdf8..8a5d091e57d3d682e287b7a03aca6374c0a1ef87 100644 (file)
@@ -326,7 +326,7 @@ buil(void)
                built = build_plane(&sect, 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;
index c841913927730bca01a3e6b2bd8c6679135e6b72..6fa951ea865885e2041f46bcced3a5390e645256 100644 (file)
 #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(&sect);
-       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(&sect);
-       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(&sect);
-       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");
index 85e6602587d98fc529214b29d9a056126ec6ab67..c92ab33b62cf31439179827e30e2009c39fc3613 100644 (file)
@@ -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);
index b5a1a6f84532b985487828a9bb2357baa01c2aae..c84c4a1b1ccfa1d0944b115de2cfc36b422cb0a8 100644 (file)
@@ -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) {
index c24bb83cb7f1397482f7c917125de21a2b8d0e56..402a6542369461dab9f3e38a718ae5f38603fec5 100644 (file)
@@ -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);
     }
 }
 
index 453bc8f41718f46c6c66fb9152814cb325d4601b..9c1e878e4d6e3337a9419bf96418c3b4f3cf3890 100644 (file)
@@ -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;
index 8fb773d31a19561191721f8cf97efc6e324e5b25..4cf30898b9695b2eb0ed642e778d01a783c69f50 100644 (file)
@@ -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;
index f8686ac86eac02260efef9d90f3e35f4b1174ce4..77abc4afc8bd00208fbad10bed5bac73fc527fe0 100644 (file)
@@ -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;