]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/attsub.c
subs: Factor lnd_insque() out of lnd_sel(), ask_olist(), ...
[empserver] / src / lib / subs / attsub.c
index 93438edf3c3ebee5be82550d9f5400d3eec2c0bc..34f664cc8cc7804f7665379bcb5619dfe0f72bb8 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1996-2000
- *     Markus Armbruster, 2006-2013
+ *     Markus Armbruster, 2006-2014
  */
 
 #include <config.h>
@@ -1068,18 +1068,11 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
                land_answer[(int)land.lnd_army] != 'Y')
                continue;
        }
-       if (!(llp = malloc(sizeof(struct ulist)))) {
-           logerror("Malloc failed in attack!\n");
-           abort_attack();
-           return;
-       }
-       memset(llp, 0, sizeof(struct ulist));
-       emp_insque(&llp->queue, olist);
+       llp = lnd_insque(&land, olist);
+       llp->supplied = 1;
        llp->mobil = mobcost;
-       llp->unit.land = land;
        llp->x = llp->unit.land.lnd_x;
        llp->y = llp->unit.land.lnd_y;
-       llp->chrp = (struct empobj_chr *)&lchr[(int)llp->unit.land.lnd_type];
        llp->eff = llp->unit.land.lnd_effic;
        if (lnd_spyval(&land) > *a_spyp)
            *a_spyp = lnd_spyval(&land);
@@ -1198,18 +1191,11 @@ get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
            continue;
        intelligence_report(player->cnum, &land, a_spy,
                            "Scouts report defending unit:");
-       if (!(llp = malloc(sizeof(struct ulist)))) {
-           logerror("Malloc failed in attack!\n");
-           abort_attack();
-           return;
-       }
-       memset(llp, 0, sizeof(struct ulist));
-       emp_insque(&llp->queue, list);
+       llp = lnd_insque(&land, list);
        llp->supplied = lnd_supply_all(&land);
-       llp->unit.land = land;
+       llp->mobil = 0.0;
        llp->x = llp->unit.land.lnd_x;
        llp->y = llp->unit.land.lnd_y;
-       llp->chrp = (struct empobj_chr *)&lchr[(int)llp->unit.land.lnd_type];
        llp->eff = llp->unit.land.lnd_effic;
        if (lnd_spyval(&land) > *d_spyp)
            *d_spyp = lnd_spyval(&land);
@@ -1507,16 +1493,12 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
        wu(0, land.lnd_own, "%s reacts to %s.\n",
           prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
 
-       llp = malloc(sizeof(struct ulist));
-
-       memset(llp, 0, sizeof(struct ulist));
+       llp = lnd_insque(&land, list);
        llp->supplied = 1;
+       llp->mobil = 0.0;
        llp->x = origx;
        llp->y = origy;
-       llp->chrp = (struct empobj_chr *)&lchr[(int)land.lnd_type];
-       llp->unit.land = land;
        llp->eff = land.lnd_effic;
-       emp_insque(&llp->queue, list);
        if (lnd_spyval(&land) > *d_spyp)
            *d_spyp = lnd_spyval(&land);
 
@@ -2037,8 +2019,8 @@ take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist)
     int to_take = CASUALTY_LUMP;
     int biggest_troops = 0, index = -1;
     int n, tot_troops = 0, biggest_mil, cas;
-    struct emp_qelem *qp, *biggest;
-    struct ulist *llp;
+    struct emp_qelem *qp;
+    struct ulist *llp, *biggest;
 
     for (n = 0; n <= off->last; ++n) {
        if (off[n].type != EF_BAD) {
@@ -2099,14 +2081,13 @@ take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist)
 
        if (llp->unit.land.lnd_item[I_MILIT] > biggest_mil) {
            biggest_mil = llp->unit.land.lnd_item[I_MILIT];
-           biggest = qp;
+           biggest = llp;
        }
     }
     if (biggest == NULL)
        return CASUALTY_LUMP - to_take;
 
-    llp = (struct ulist *)biggest;
-    cas = lnd_take_casualty(combat_mode, llp, to_take);
+    cas = lnd_take_casualty(combat_mode, biggest, to_take);
     return CASUALTY_LUMP - (to_take - cas);
 }