]> git.pond.sub.org Git - empserver/commitdiff
unit: Drop ulist member chrp
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 29 Dec 2014 07:41:23 +0000 (08:41 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 28 Feb 2015 15:13:15 +0000 (16:13 +0100)
Commit cd8d742 mechanically combined struct mlist's mcp and struct
llist's llp into struct ulist's chrp, adding type casts to every use.
Not necessary, simply use mchr[] and lchr[] directly.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/empobj.h
include/unit.h
src/lib/subs/attsub.c
src/lib/subs/lndsub.c
src/lib/subs/shpsub.c
src/lib/subs/unitsub.c

index 30462698cb35126ac232b696f7aad6a0100596db..d02c4d566d648c1543c1811ab76974404289d5f1 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2006
- *     Markus Armbruster, 2006-2011
+ *     Markus Armbruster, 2006-2014
  */
 
 #ifndef EMPOBJ_H
@@ -90,8 +90,6 @@ union empobj_storage {
     struct trdstr trade;
 };
 
-struct empobj_chr;
-
 #define get_empobj(type, n, p) ef_read((type), (n), (p))
 #define put_empobj(type, n, p) ef_write((type), (n), (p))
 #define get_empobjp(type, n) ((struct empobj *)ef_ptr((type), (n)))
index b544d7f91214c264e914df5ff17ac0700f330354..0bf896c134495a363790b355376309322b5fc817 100644 (file)
@@ -40,7 +40,6 @@ struct ulist {
     struct emp_qelem queue;    /* list of units */
     double mobil;              /* moving: how much the unit has left
                                   ground combat: how much to charge */
-    struct empobj_chr *chrp;   /* pointer to characteristics unit */
     union empobj_storage unit; /* unit */
     /* Rest used only by ground combat (attsub.c) */
     coord x, y;                        /* x,y it came from */
index 9640f10ee766ba4023ad5b77413cff35b494d36b..cfe291a2833489087ec49823f7d05eee1508cffb 100644 (file)
@@ -1076,7 +1076,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
        llp->eff = llp->unit.land.lnd_effic;
        if (lnd_spyval(&land) > *a_spyp)
            *a_spyp = lnd_spyval(&land);
-       if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
+       if (lchr[land.lnd_type].l_flags & L_ENGINEER)
            ++*a_engineerp;
        if (def->type == EF_SHIP && ++count >= maxland)
            break;
@@ -2488,7 +2488,7 @@ take_move_in_mob(int combat_mode, struct ulist *llp, struct combat *off,
         * Set mobcost to basic assault cost, moblim to maximum
         * mobility to keep when assaulting from non-landing ship
         */
-       if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE) {
+       if (lchr[llp->unit.land.lnd_type].l_flags & L_MARINE) {
            mobcost = gain / 2.0;
            moblim = 0;
        } else {
@@ -2500,7 +2500,7 @@ take_move_in_mob(int combat_mode, struct ulist *llp, struct combat *off,
            mobcost = MAX(mobcost, mob - moblim);
        break;
     case A_BOARD:
-       if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE)
+       if (lchr[llp->unit.land.lnd_type].l_flags & L_MARINE)
            mobcost = 10;
        else
            mobcost = 40;
index 2aa99d748e75a0c9e0fae45bd4c375f44b8e2815..0d49b0164e5eca691480be43d2ec99ef94217f42 100644 (file)
@@ -167,11 +167,11 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
 
     taken = llp->unit.land.lnd_item[I_MILIT];
     /* Spies always die */
-    if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY)
+    if (lchr[llp->unit.land.lnd_type].l_flags & L_SPY)
        llp->unit.land.lnd_effic = 0;
     else {
        eff_eq = ldround(cas * 100.0 /
-           ((struct lchrstr *)llp->chrp)->l_item[I_MILIT], 1);
+           lchr[llp->unit.land.lnd_type].l_item[I_MILIT], 1);
        llp->unit.land.lnd_effic -= eff_eq;
        lnd_submil(&llp->unit.land, cas);
     }
@@ -274,7 +274,7 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
        /* nowhere to go.. take more casualties */
        llp->unit.land.lnd_effic -= 10;
        lnd_submil(&llp->unit.land,
-                  ((struct lchrstr *)llp->chrp)->l_item[I_MILIT] / 10);
+                  lchr[llp->unit.land.lnd_type].l_item[I_MILIT] / 10);
        if (llp->unit.land.lnd_effic < LAND_MINEFF) {
            lnd_print(llp->unit.land.lnd_own, llp,
                      "has nowhere to retreat, and dies!");
@@ -444,7 +444,6 @@ lnd_insque(struct lndstr *lp, struct emp_qelem *list)
 {
     struct ulist *mlp = malloc(sizeof(struct ulist));
 
-    mlp->chrp = (struct empobj_chr *)&lchr[lp->lnd_type];
     mlp->unit.land = *lp;
     mlp->mobil = lp->lnd_mobil;
     emp_insque(&mlp->queue, list);
@@ -595,7 +594,7 @@ lnd_sweep(struct emp_qelem *land_list, int explicit, int takemob,
     for (qp = land_list->q_back; qp != land_list; qp = next) {
        next = qp->q_back;
        llp = (struct ulist *)qp;
-       if (!(((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)) {
+       if (!(lchr[llp->unit.land.lnd_type].l_flags & L_ENGINEER)) {
            if (explicit)
                mpr(actor, "%s is not an engineer!\n",
                    prland(&llp->unit.land));
@@ -623,11 +622,11 @@ lnd_sweep(struct emp_qelem *land_list, int explicit, int takemob,
        putland(llp->unit.land.lnd_uid, &llp->unit.land);
        if (!(mines = sect.sct_mines))
            continue;
-       max = ((struct lchrstr *)llp->chrp)->l_item[I_SHELL];
+       max = lchr[llp->unit.land.lnd_type].l_item[I_SHELL];
        lshells = llp->unit.land.lnd_item[I_SHELL];
        sshells = sect.sct_item[I_SHELL];
        for (m = 0; mines > 0 && m < max * 2; m++) {
-           if (chance(0.5 * ((struct lchrstr *)llp->chrp)->l_att)) {
+           if (chance(0.5 * lchr[llp->unit.land.lnd_type].l_att)) {
                mpr(actor, "Sweep...\n");
                mines--;
                if (lshells < max)
@@ -654,7 +653,7 @@ contains_engineer(struct emp_qelem *list)
     for (qp = list->q_back; qp != list; qp = next) {
        next = qp->q_back;
        llp = (struct ulist *)qp;
-       if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
+       if (lchr[llp->unit.land.lnd_type].l_flags & L_ENGINEER)
            return 1;
     }
     return 0;
index 8291c46dadf7e75905527516e841cf665a4c2731..9692e8e44d7b7e6399df9ce05fd91d9e46635b32 100644 (file)
@@ -96,7 +96,6 @@ shp_insque(struct shpstr *sp, struct emp_qelem *list)
 {
     struct ulist *mlp = malloc(sizeof(struct ulist));
 
-    mlp->chrp = (struct empobj_chr *)&mchr[sp->shp_type];
     mlp->unit.ship = *sp;
     mlp->mobil = sp->shp_mobil;
     emp_insque(&mlp->queue, list);
@@ -207,7 +206,7 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
     for (qp = ship_list->q_back; qp != ship_list; qp = next) {
        next = qp->q_back;
        mlp = (struct ulist *)qp;
-       if (!(((struct mchrstr *)mlp->chrp)->m_flags & M_SWEEP)) {
+       if (!(mchr[mlp->unit.ship.shp_type].m_flags & M_SWEEP)) {
            if (verbose)
                mpr(actor, "%s doesn't have minesweeping capability!\n",
                    prship(&mlp->unit.ship));
@@ -233,7 +232,7 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
        putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
        if (!(mines = sect.sct_mines))
            continue;
-       max = ((struct mchrstr *)mlp->chrp)->m_item[I_SHELL];
+       max = mchr[mlp->unit.ship.shp_type].m_item[I_SHELL];
        shells = mlp->unit.ship.shp_item[I_SHELL];
        for (m = 0; mines > 0 && m < 5; m++) {
            if (chance(0.66)) {
@@ -371,10 +370,10 @@ shp_count(struct emp_qelem *list, int wantflags, int nowantflags,
        if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
            continue;
        if (wantflags &&
-           (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+           (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
            continue;
        if (nowantflags &&
-           ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+           mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
            continue;
        ++count;
     }
@@ -414,10 +413,10 @@ shp_damage(struct emp_qelem *list, int totdam, int wantflags,
        if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
            continue;
        if (wantflags &&
-           (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+           (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
            continue;
        if (nowantflags &&
-           ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+           mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
            continue;
        shp_damage_one(mlp, dam);
     }
@@ -439,10 +438,10 @@ shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
        if (newx != mlp->unit.ship.shp_x || newy != mlp->unit.ship.shp_y)
            continue;
        if (wantflags &&
-           (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+           (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
            continue;
        if (nowantflags &&
-           ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+           mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
            continue;
        return 1;
     }
@@ -462,20 +461,20 @@ most_valuable_ship(struct emp_qelem *list, coord x, coord y)
        mlp = (struct ulist *)qp;
        if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
            continue;
-       if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
+       if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
            continue;
-       if (!((struct mchrstr *)mlp->chrp)->m_nxlight &&
-           !((struct mchrstr *)mlp->chrp)->m_nchoppers &&
-           ((struct mchrstr *)mlp->chrp)->m_cost < 1000 &&
-           !((struct mchrstr *)mlp->chrp)->m_nplanes &&
-           !((struct mchrstr *)mlp->chrp)->m_nland)
+       if (!mchr[mlp->unit.ship.shp_type].m_nxlight &&
+           !mchr[mlp->unit.ship.shp_type].m_nchoppers &&
+           mchr[mlp->unit.ship.shp_type].m_cost < 1000 &&
+           !mchr[mlp->unit.ship.shp_type].m_nplanes &&
+           !mchr[mlp->unit.ship.shp_type].m_nland)
            continue;
        if (!mvs) {
            mvs = mlp;
            continue;
        }
-       if (((struct mchrstr *)mlp->chrp)->m_cost * mlp->unit.ship.shp_effic >
-           ((struct mchrstr *)mvs->chrp)->m_cost * mvs->unit.ship.shp_effic)
+       if (mchr[mlp->unit.ship.shp_type].m_cost * mlp->unit.ship.shp_effic >
+           mchr[mvs->unit.ship.shp_type].m_cost * mvs->unit.ship.shp_effic)
            mvs = mlp;
     }
     return mvs;
@@ -495,10 +494,10 @@ shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags)
        next = qp->q_back;
        mlp = (struct ulist *)qp;
        if (wantflags &&
-           (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+           (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
            continue;
        if (nowantflags &&
-           ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+           mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
            continue;
        hard = shp_hardtarget(&mlp->unit.ship);
        if (hard < easiest)
@@ -584,7 +583,7 @@ notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
     for (qp = list->q_back; qp != list; qp = next) {
        next = qp->q_back;
        mlp = (struct ulist *)qp;
-       if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
+       if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
            continue;
        if (natp->nat_flags & NF_COASTWATCH)
            wu(0, sectp->sct_own,
@@ -840,7 +839,7 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor)
        rad_map_set(mlp->unit.ship.shp_own,
                    mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
                    mlp->unit.ship.shp_effic, mlp->unit.ship.shp_tech,
-                   ((struct mchrstr *)mlp->chrp)->m_vrnge);
+                   mchr[mlp->unit.ship.shp_type].m_vrnge);
     }
     if (QEMPTY(list))
        return stopping;
index 8dfac456182c85150b6362eee4d246eee49985a1..76121736d82f25cacec324305c2a97175ac6ac48 100644 (file)
@@ -188,9 +188,9 @@ unit_view(struct emp_qelem *list)
            continue;
        getsect(ulp->unit.gen.x, ulp->unit.gen.y, &sect);
        if (ulp->unit.gen.ef_type == EF_SHIP) {
-           if (((struct mchrstr *)ulp->chrp)->m_flags & M_FOOD)
+           if (mchr[ulp->unit.ship.shp_type].m_flags & M_FOOD)
                pr("[fert:%d] ", sect.sct_fertil);
-           if (((struct mchrstr *)ulp->chrp)->m_flags & M_OIL)
+           if (mchr[ulp->unit.ship.shp_type].m_flags & M_OIL)
                pr("[oil:%d] ", sect.sct_oil);
        }
        pr("%s @ %s %d%% %s\n", unit_nameof(&ulp->unit.gen),