]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/buil.c
Remove unused members of struct lndstr, lonstr, nukstr, trtstr
[empserver] / src / lib / commands / buil.c
index 9d1c0ede60cc9b641e55b735f441f936fe655e04..9ebe6f6ee3ea6adc146f67809e9882838da3df76 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  buil.c: Build ships, nukes, bridges, planes, land units, bridge towers
- * 
+ *
  *  Known contributors to this file:
  *      Steve McClure, 1998-2000
- *      Markus Armbruster, 2004-2006
+ *      Markus Armbruster, 2004-2009
  */
 
 #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 "game.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"
+#include "unit.h"
 
 static int build_nuke(struct sctstr *sp,
                      struct nchrstr *np, short *vec, int tlev);
@@ -90,10 +86,10 @@ buil(void)
     char buf[1024];
 
     natp = getnatp(player->cnum);
-    if ((p =
-        getstarg(player->argp[1],
-                 "Build (ship, nuke, bridge, plane, land unit, tower)? ",
-                 buf)) == 0)
+    p = getstarg(player->argp[1],
+                "Build (ship, nuke, bridge, plane, land unit, tower)? ",
+                buf);
+    if (!p)
        return RET_SYN;
     what = *p;
 
@@ -107,7 +103,7 @@ buil(void)
     switch (what) {
     case 'p':
        p = getstarg(player->argp[3], "Plane type? ", buf);
-       if (p == 0 || *p == 0)
+       if (!p || !*p)
            return RET_SYN;
        type = ef_elt_byname(EF_PLANE_CHR, p);
        if (type >= 0) {
@@ -125,7 +121,7 @@ buil(void)
        break;
     case 's':
        p = getstarg(player->argp[3], "Ship type? ", buf);
-       if (p == 0 || *p == 0)
+       if (!p || !*p)
            return RET_SYN;
        type = ef_elt_byname(EF_SHIP_CHR, p);
        if (type >= 0) {
@@ -145,7 +141,7 @@ buil(void)
        break;
     case 'l':
        p = getstarg(player->argp[3], "Land unit type? ", buf);
-       if (p == 0 || *p == 0)
+       if (!p || !*p)
            return RET_SYN;
        type = ef_elt_byname(EF_LAND_CHR, p);
        if (type >= 0) {
@@ -186,7 +182,7 @@ buil(void)
            return RET_FAIL;
        }
        p = getstarg(player->argp[3], "Nuke type? ", buf);
-       if (p == 0 || *p == 0)
+       if (!p || !*p)
            return RET_SYN;
        type = ef_elt_byname(EF_NUKE_CHR, p);
        if (type >= 0) {
@@ -223,7 +219,7 @@ buil(void)
                        "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')
+               if (!p || *p != 'y')
                    return RET_SYN;
            }
        }
@@ -290,7 +286,7 @@ build_ship(struct sctstr *sp, struct mchrstr *mp, short *vec, int tlev)
 {
     struct shpstr ship;
     struct nstr_item nstr;
-    int avail, i;
+    int avail;
     double cost;
     double eff = SHIP_MINEFF / 100.0;
     int lcm, hcm;
@@ -339,59 +335,33 @@ build_ship(struct sctstr *sp, struct mchrstr *mp, short *vec, int tlev)
     if (freeship == 0) {
        ef_extend(EF_SHIP, 50);
     }
-    memset(&ship, 0, sizeof(struct shpstr));
+    ef_blank(EF_SHIP, nstr.cur, &ship);
     ship.shp_x = sp->sct_x;
     ship.shp_y = sp->sct_y;
-    ship.shp_destx[0] = sp->sct_x;
-    ship.shp_desty[0] = sp->sct_y;
-    ship.shp_destx[1] = sp->sct_x;
-    ship.shp_desty[1] = sp->sct_y;
-    ship.shp_autonav = 0;
-    /* new code for autonav, Chad Zabel 1-15-94 */
-    for (i = 0; i < TMAX; ++i) {
-       ship.shp_tstart[i] = I_NONE;
-       ship.shp_tend[i] = I_NONE;
-       ship.shp_lstart[i] = 0;
-       ship.shp_lend[i] = 0;
-    }
-    ship.shp_mission = 0;
     ship.shp_own = player->cnum;
     ship.shp_type = mp - mchr;
     ship.shp_effic = SHIP_MINEFF;
     if (opt_MOB_ACCESS) {
-       time(&ship.shp_access);
+       game_tick_to_now(&ship.shp_access);
        ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
     } else {
        ship.shp_mobil = 0;
     }
-    ship.shp_uid = nstr.cur;
-    ship.shp_nplane = 0;
-    ship.shp_nland = 0;
-    ship.shp_nxlight = 0;
-    ship.shp_nchoppers = 0;
-    ship.shp_fleet = 0;
     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;
     ship.shp_name[0] = 0;
     ship.shp_orig_own = player->cnum;
     ship.shp_orig_x = sp->sct_x;
     ship.shp_orig_y = sp->sct_y;
-    ship.shp_fuel = mchr[(int)ship.shp_type].m_fuelc;
-    ship.shp_rflags = 0;
-    memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
     shp_set_tech(&ship, tlev);
+    unit_wipe_orders((struct empobj *)&ship);
 
     vec[I_LCM] -= lcm;
     vec[I_HCM] -= hcm;
 
     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);
     pr("%s", prship(&ship));
     pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
@@ -476,36 +446,26 @@ build_land(struct sctstr *sp, struct lchrstr *lp, short *vec, int tlev)
     if (freeland == 0) {
        ef_extend(EF_LAND, 50);
     }
-    memset(&land, 0, sizeof(struct lndstr));
+    ef_blank(EF_LAND, nstr.cur, &land);
     land.lnd_x = sp->sct_x;
     land.lnd_y = sp->sct_y;
     land.lnd_own = player->cnum;
-    land.lnd_mission = 0;
     land.lnd_type = lp - lchr;
     land.lnd_effic = LAND_MINEFF;
     if (opt_MOB_ACCESS) {
-       time(&land.lnd_access);
+       game_tick_to_now(&land.lnd_access);
        land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
     } else {
        land.lnd_mobil = 0;
     }
-    land.lnd_uid = nstr.cur;
-    land.lnd_army = 0;
-    land.lnd_flags = 0;
     land.lnd_ship = -1;
     land.lnd_land = -1;
-    land.lnd_nland = 0;
     land.lnd_harden = 0;
-    land.lnd_retreat = morale_base;
-    land.lnd_fuel = lp->l_fuelc;
-    land.lnd_nxlight = 0;
-    land.lnd_rflags = 0;
-    memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
-    land.lnd_rad_max = 0;
     memset(land.lnd_item, 0, sizeof(land.lnd_item));
     land.lnd_pstage = PLG_HEALTHY;
     land.lnd_ptime = 0;
     lnd_set_tech(&land, tlev);
+    unit_wipe_orders((struct empobj *)&land);
 
     vec[I_LCM] -= lcm;
     vec[I_HCM] -= hcm;
@@ -516,8 +476,6 @@ build_land(struct sctstr *sp, struct lchrstr *lp, short *vec, int tlev)
     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);
     pr("%s", prland(&land));
     pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
     return 1;
@@ -581,7 +539,7 @@ build_bridge(struct sctstr *sp, short *vec)
 
     if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
        pr("'%c' is not a valid direction...\n", *p);
-       direrr(0, 0, 0);
+       direrr(NULL, NULL, NULL);
        return 0;
     }
     newx = sp->sct_x + diroff[val][0];
@@ -616,7 +574,7 @@ build_bridge(struct sctstr *sp, short *vec)
     sect.sct_rail = 0;
     sect.sct_defense = 0;
     if (opt_MOB_ACCESS) {
-       time(&sect.sct_access);
+       game_tick_to_now(&sect.sct_access);
        sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
     } else {
        sect.sct_mobil = 0;
@@ -687,24 +645,21 @@ build_nuke(struct sctstr *sp, struct nchrstr *np, short *vec, int tlev)
     if (freenuke == 0) {
        ef_extend(EF_NUKE, 50);
     }
-    memset(&nuke, 0, sizeof(struct nukstr));
+    ef_blank(EF_NUKE, nstr.cur, &nuke);
     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_plane = -1;
     nuke.nuk_tech = tlev;
+    unit_wipe_orders((struct empobj *)&nuke);
 
     vec[I_HCM] -= np->n_hcm;
     vec[I_LCM] -= np->n_lcm;
     vec[I_OIL] -= np->n_oil;
     vec[I_RAD] -= np->n_rad;
 
-    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));
@@ -774,39 +729,30 @@ build_plane(struct sctstr *sp, struct plchrstr *pp, short *vec, int tlev)
     if (freeplane == 0) {
        ef_extend(EF_PLANE, 50);
     }
-    memset(&plane, 0, sizeof(struct plnstr));
+    ef_blank(EF_PLANE, nstr.cur, &plane);
     plane.pln_x = sp->sct_x;
     plane.pln_y = sp->sct_y;
     plane.pln_own = sp->sct_own;
     plane.pln_type = pp - plchr;
     plane.pln_effic = PLANE_MINEFF;
     if (opt_MOB_ACCESS) {
-       time(&plane.pln_access);
+       game_tick_to_now(&plane.pln_access);
        plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
     } else {
        plane.pln_mobil = 0;
     }
-    plane.pln_mission = 0;
-    plane.pln_opx = 0;
-    plane.pln_opy = 0;
-    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 = 0;
     plane.pln_ship = -1;
     plane.pln_land = -1;
-    plane.pln_uid = nstr.cur;
-    plane.pln_nuketype = -1;
     plane.pln_harden = 0;
     plane.pln_flags = 0;
     pln_set_tech(&plane, tlev);
+    unit_wipe_orders((struct empobj *)&plane);
 
     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));
@@ -822,7 +768,6 @@ build_tower(struct sctstr *sp, short *vec)
     int avail;
     char *p;
     char buf[1024];
-    int good;
     int i;
     int nx;
     int ny;
@@ -869,7 +814,7 @@ build_tower(struct sctstr *sp, short *vec)
 
     if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
        pr("'%c' is not a valid direction...\n", *p);
-       direrr(0, 0, 0);
+       direrr(NULL, NULL, NULL);
        return 0;
     }
     newx = sp->sct_x + diroff[val][0];
@@ -881,7 +826,6 @@ build_tower(struct sctstr *sp, short *vec)
 
     /* Now, check.  You aren't allowed to build bridge towers
        next to land. */
-    good = 0;
     for (i = 1; i <= 6; i++) {
        struct sctstr s2;
        nx = sect.sct_x + diroff[i][0];
@@ -889,15 +833,11 @@ build_tower(struct sctstr *sp, short *vec)
        getsect(nx, ny, &s2);
        if ((s2.sct_type != SCT_WATER) &&
            (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) {
-           good = 1;
-           break;
+           pr("Bridge towers cannot be built adjacent to land.\n");
+           pr("That sector is adjacent to land.\n");
+           return 0;
        }
     }
-    if (good) {
-       pr("Bridge towers cannot be built adjacent to land.\n");
-       pr("That sector is adjacent to land.\n");
-       return 0;
-    }
 
     sp->sct_avail -= avail;
     player->dolcost += buil_tower_bc;
@@ -908,7 +848,7 @@ build_tower(struct sctstr *sp, short *vec)
     sect.sct_rail = 0;
     sect.sct_defense = 0;
     if (opt_MOB_ACCESS) {
-       time(&sect.sct_access);
+       game_tick_to_now(&sect.sct_access);
        sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
     } else {
        sect.sct_mobil = 0;