]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/buil.c
Update copyright notice.
[empserver] / src / lib / commands / buil.c
index de142330341b6a7d25cde4fe574f407c641cfdd7..93200a033d56f62a6e6e4b0b6a023e530c92e4bf 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *      Steve McClure, 1998-2000
  */
 
-#ifdef Rel4
+#include <limits.h>
 #include <string.h>
-#endif /* Rel4 */
 #include "misc.h"
 #include "player.h"
 #include "var.h"
 #include "sect.h"
 #include "nat.h"
-#include "retreat.h"
 #include "ship.h"
 #include "land.h"
 #include "nuke.h"
 #include "xy.h"
 #include "nsc.h"
 #include "treaty.h"
-#include "deity.h"
 #include "file.h"
 #include "path.h"
 #include "optlist.h"
 #include "commands.h"
 
 static int build_nuke(register struct sctstr *sp,
-                     register struct nchrstr *np, register int *vec);
+                     register struct nchrstr *np, short *vec);
 static int build_ship(register struct sctstr *sp,
-                     register struct mchrstr *mp, register int *vec,
+                     register struct mchrstr *mp, short *vec,
                      int tlev);
 static int build_land(register struct sctstr *sp,
-                     register struct lchrstr *lp, register int *vec,
+                     register struct lchrstr *lp, short *vec,
                      int tlev);
-static int build_bridge(register struct sctstr *sp, register int *vec);
-static int build_tower(register struct sctstr *sp, register int *vec);
+static int build_bridge(register struct sctstr *sp, short *vec);
+static int build_tower(register struct sctstr *sp, short *vec);
 static int build_plane(register struct sctstr *sp,
-                      register struct plchrstr *pp, register int *vec,
+                      register struct plchrstr *pp, short *vec,
                       int tlev);
 
 static int cash;               /* static ok */
 
-double sqrt(double);
-double logx();
-
-extern int morale_base;
-extern int sect_mob_neg_factor;
-extern int etu_per_update;
-
 /*
  * build <WHAT> <SECTS> <TYPE|DIR|MEG> [NUMBER]
  */
 int
 buil(void)
 {
-    extern double buil_bt;
-    extern double buil_tower_bt;
     struct sctstr sect;
     struct nstr_sect nstr;
     struct natstr *natp;
@@ -98,11 +86,9 @@ buil(void)
     struct plchrstr *pp;
     struct nchrstr *np;
     s_char *p;
-    int vec[I_MAX + 1];
     int gotsect = 0;
     int built;
     int hold, found, number = 1, x;
-    extern float drnuke_const;
     int asked = 0;
     s_char buf[1024];
 
@@ -319,32 +305,30 @@ buil(void)
            gotsect++;
            if (!player->owner)
                continue;
-           getvec(VT_ITEM, vec, (s_char *)&sect, EF_SECTOR);
            switch (what) {
            case 'l':
-               built = build_land(&sect, lp, vec, tlev);
+               built = build_land(&sect, lp, sect.sct_item, tlev);
                break;
            case 's':
-               built = build_ship(&sect, mp, vec, tlev);
+               built = build_ship(&sect, mp, sect.sct_item, tlev);
                break;
            case 'b':
-               built = build_bridge(&sect, vec);
+               built = build_bridge(&sect, sect.sct_item);
                break;
            case 't':
-               built = build_tower(&sect, vec);
+               built = build_tower(&sect, sect.sct_item);
                break;
            case 'n':
-               built = build_nuke(&sect, np, vec);
+               built = build_nuke(&sect, np, sect.sct_item);
                break;
            case 'p':
-               built = build_plane(&sect, pp, vec, tlev);
+               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) {
-               putvec(VT_ITEM, vec, (s_char *)&sect, EF_SECTOR);
                putsect(&sect);
            }
        }
@@ -357,19 +341,17 @@ buil(void)
 
 static int
 build_ship(register struct sctstr *sp, register struct mchrstr *mp,
-          register int *vec, int tlev)
+          short *vec, int tlev)
 {
     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");
@@ -385,16 +367,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;
@@ -403,7 +383,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);
@@ -426,8 +406,8 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp,
     ship.shp_autonav = 0;
     /* new code for autonav, Chad Zabel 1-15-94 */
     for (i = 0; i < TMAX; ++i) {
-       ship.shp_tstart[i] = ' ';
-       ship.shp_tend[i] = ' ';
+       ship.shp_tstart[i] = I_NONE;
+       ship.shp_tend[i] = I_NONE;
        ship.shp_lstart[i] = 0;
        ship.shp_lend[i] = 0;
     }
@@ -447,17 +427,9 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp,
     ship.shp_nxlight = 0;
     ship.shp_nchoppers = 0;
     ship.shp_fleet = ' ';
-    ship.shp_nv = 0;
-    ship.shp_sell = 0;
-    ship.shp_tech = tlev;
-
-    techdiff = (int)(tlev - mp->m_tech);
-    ship.shp_armor = (short)SHP_DEF(mp->m_armor, techdiff);
-    ship.shp_speed = (short)SHP_SPD(mp->m_speed, techdiff);
-    ship.shp_visib = (short)SHP_VIS(mp->m_visib, techdiff);
-    ship.shp_frnge = (short)SHP_RNG(mp->m_frnge, techdiff);
-    ship.shp_glim = (short)SHP_FIR(mp->m_glim, techdiff);
-
+    memset(ship.shp_item, 0, sizeof(ship.shp_item));
+    ship.shp_pstage = PLG_HEALTHY;
+    ship.shp_ptime = 0;
     ship.shp_mobquota = 0;
     *ship.shp_path = 0;
     ship.shp_follow = nstr.cur;
@@ -467,14 +439,14 @@ 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));
+    shp_set_tech(&ship, tlev);
 
     vec[I_LCM] -= lcm;
     vec[I_HCM] -= hcm;
 
-    if (getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_INFECT)
-       putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP);
+    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);
     putship(ship.shp_uid, &ship);
@@ -485,29 +457,24 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp,
 
 static int
 build_land(register struct sctstr *sp, register struct lchrstr *lp,
-          register int *vec, int tlev)
+          short *vec, int tlev)
 {
     struct lndstr land;
     struct nstr_item nstr;
-    int cost;
-    int w_p_eff;
-    int points;
-    struct natstr *natp;
-    float eff = ((float)LAND_MINEFF / 100.0);
-    double techfact(int, double);
+    int avail, cost;
+    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));
-
-    natp = getnatp(player->cnum);
+#endif
+    hcm = roundavg(((double)lp->l_hcm * eff));
+    lcm = roundavg(((double)lp->l_lcm * eff));
 
     if (sp->sct_type != SCT_HEADQ) {
        pr("Land Units must be built in headquarters.\n");
@@ -544,22 +511,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);
@@ -585,8 +549,6 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp,
     } else {
        land.lnd_mobil = 0;
     }
-    land.lnd_sell = 0;
-    land.lnd_tech = tlev;
     land.lnd_uid = nstr.cur;
     land.lnd_army = ' ';
     land.lnd_flags = 0;
@@ -600,23 +562,10 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp,
     land.lnd_rflags = 0;
     memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
     land.lnd_rad_max = 0;
-    land.lnd_nv = 0;
-    land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech);
-    land.lnd_def = (float)LND_ATTDEF(lp->l_def, tlev - lp->l_tech);
-    land.lnd_vul = (int)LND_VUL(lp->l_vul, tlev - lp->l_tech);
-    land.lnd_spd = (int)LND_SPD(lp->l_spd, tlev - lp->l_tech);
-    land.lnd_vis = (int)LND_VIS(lp->l_vis, tlev - lp->l_tech);
-    land.lnd_spy = (int)LND_SPY(lp->l_spy, tlev - lp->l_tech);
-    land.lnd_rad = (int)LND_RAD(lp->l_rad, tlev - lp->l_tech);
-    land.lnd_frg = (int)LND_FRG(lp->l_frg, tlev - lp->l_tech);
-    land.lnd_acc = (int)LND_ACC(lp->l_acc, tlev - lp->l_tech);
-    land.lnd_dam = (int)LND_DAM(lp->l_dam, tlev - lp->l_tech);
-    land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, tlev - lp->l_tech);
-    land.lnd_aaf = (int)LND_AAF(lp->l_aaf, tlev - lp->l_tech);
-    land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, tlev - lp->l_tech);
-    land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech);
-    land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech);
-    land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech);
+    memset(land.lnd_item, 0, sizeof(land.lnd_item));
+    land.lnd_pstage = PLG_HEALTHY;
+    land.lnd_ptime = 0;
+    lnd_set_tech(&land, tlev);
 
     vec[I_LCM] -= lcm;
     vec[I_HCM] -= hcm;
@@ -624,26 +573,8 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp,
     vec[I_GUN] -= gun;
     vec[I_SHELL] -= shell;
 
-/* Disabled autoloading of food onto units
-    max_amt = vl_find(V_FOOD, lp->l_vtype, lp->l_vamt, (int) lp->l_nv);
-    food_needed = (etu_per_update * eatrate) *
-       (vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW])+1;
-    if ((vec[I_FOOD]-max_amt) < food_needed)
-       max_amt = (vec[I_FOOD]-food_needed);
-    
-    if (max_amt < 0)
-       max_amt = 0;
-    
-    vec[I_FOOD] -= max_amt;
-    
-    memset(lvec, 0, sizeof(lvec));
-    getvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
-    lvec[I_FOOD] += max_amt;
-    putvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
-*/
-
-    if (getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_INFECT)
-       putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND);
+    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);
@@ -652,17 +583,13 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp,
     return 1;
 }
 
-static
-    int
-build_bridge(register struct sctstr *sp, register int *vec)
+static int
+build_bridge(register struct sctstr *sp, short *vec)
 {
-    extern int buil_bh;
-    extern double buil_bc;
     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];
@@ -730,12 +657,11 @@ build_bridge(register struct sctstr *sp, register int *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]) {
@@ -779,12 +705,12 @@ build_bridge(register struct sctstr *sp, register int *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;
@@ -796,7 +722,7 @@ build_bridge(register struct sctstr *sp, register int *vec)
     } else {
        sect.sct_mobil = 0;
     }
-    putvar(V_MINE, 0, (s_char *)&sect, EF_SECTOR);
+    sect.sct_mines = 0;
     putsect(&sect);
     pr("Bridge span built over %s\n",
        xyas(sect.sct_x, sect.sct_y, player->cnum));
@@ -807,13 +733,11 @@ build_bridge(register struct sctstr *sp, register int *vec)
     return 1;
 }
 
-static
-    int
+static int
 build_nuke(register struct sctstr *sp, register struct nchrstr *np,
-          register int *vec)
+          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");
@@ -836,24 +760,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);
@@ -866,26 +789,23 @@ build_nuke(register struct sctstr *sp, register struct nchrstr *np,
     return 1;
 }
 
-static
-    int
+static int
 build_plane(register struct sctstr *sp, register struct plchrstr *pp,
-           register int *vec, int tlev)
+           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;
@@ -900,16 +820,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;
@@ -923,7 +841,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);
@@ -953,70 +871,37 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp,
     plane.pln_opx = 0;
     plane.pln_opy = 0;
     plane.pln_radius = 0;
-
-    /* Note that this next block of variables can be changed so that individual
-     * 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));
-    plane.pln_range = PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech));
+    plane.pln_range = UCHAR_MAX; /* will be adjusted by pln_set_tech() */
     plane.pln_range_max = plane.pln_range;
-    plane.pln_load = PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech));
     plane.pln_fuel = pp->pl_fuel;
-
     plane.pln_wing = ' ';
-    plane.pln_tech = tlev;
     plane.pln_ship = -1;
     plane.pln_land = -1;
     plane.pln_uid = nstr.cur;
     plane.pln_nuketype = -1;
     plane.pln_harden = 0;
-    plane.pln_sell = 0;
     plane.pln_flags = 0;
+    pln_set_tech(&plane, tlev);
+
+    vec[I_LCM] -= lcm;
+    vec[I_HCM] -= hcm;
+    vec[I_MILIT] -= mil;
+
     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));
-    vec[I_LCM] -= lcm;
-    vec[I_HCM] -= hcm;
-    vec[I_MILIT] -= mil;
     return 1;
 }
 
-static
-    int
-build_tower(register struct sctstr *sp, register int *vec)
+static int
+build_tower(register struct sctstr *sp, short *vec)
 {
-    extern int buil_tower_bh;
-    extern double buil_tower_bc;
     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;
@@ -1057,12 +942,11 @@ build_tower(register struct sctstr *sp, register int *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]) {
@@ -1109,12 +993,12 @@ build_tower(register struct sctstr *sp, register int *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;
@@ -1126,7 +1010,7 @@ build_tower(register struct sctstr *sp, register int *vec)
     }
     if (!opt_DEFENSE_INFRA)
        sect.sct_defense = sect.sct_effic;
-    putvar(V_MINE, 0, (s_char *)&sect, EF_SECTOR);
+    sect.sct_mines = 0;
     putsect(&sect);
     pr("Bridge tower built in %s\n",
        xyas(sect.sct_x, sect.sct_y, player->cnum));