]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/lndsub.c
Fix test for capability engineer in lnd_hit_mine()
[empserver] / src / lib / subs / lndsub.c
index 8d82b6097d2fb3c75a06a15cdb630f1e00bbdf6b..4b0cec14b330edc234044f3a8d421a298b393b06 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -52,7 +52,7 @@
 #include "unit.h"
 
 static void lnd_mess(char *, struct ulist *);
-static int lnd_hit_mine(struct lndstr *, struct lchrstr *);
+static int lnd_hit_mine(struct lndstr *);
 static int has_helpful_engineer(coord, coord, natid);
 
 double
@@ -178,10 +178,9 @@ 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) {
-       eff_eq = 100;
+    if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY)
        llp->unit.land.lnd_effic = 0;
-    else {
+    else {
        eff_eq = ldround(cas * 100.0 /
            ((struct lchrstr *)llp->chrp)->l_item[I_MILIT], 1);
        llp->unit.land.lnd_effic -= eff_eq;
@@ -623,7 +622,7 @@ lnd_check_mines(struct emp_qelem *land_list)
        if (SCT_LANDMINES(&sect) == 0)
            continue;
        if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
-           lnd_hit_mine(&llp->unit.land, ((struct lchrstr *)llp->chrp));
+           lnd_hit_mine(&llp->unit.land);
            sect.sct_mines--;
            putsect(&sect);
            putland(llp->unit.land.lnd_uid, &llp->unit.land);
@@ -681,7 +680,7 @@ lnd_damage(struct emp_qelem *list, int totdam)
     for (qp = list->q_back; qp != list; qp = next) {
        next = qp->q_back;
        llp = (struct ulist *)qp;
-       /* have to get it again because of collateral damage */
+       /* land unit might have changed (launched SAMs, collateral dmg) */
        getland(llp->unit.land.lnd_uid, &llp->unit.land);
        landdamage(&llp->unit.land, dam);
        putland(llp->unit.land.lnd_uid, &llp->unit.land);
@@ -721,6 +720,7 @@ lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
     int mindam = lnd_count(list) * 20;
     int hardtarget = lnd_easiest_target(list);
     int dam, newdam, sublaunch;
+    int stopping = 0;
     struct plist *plp;
     struct emp_qelem msl_list, *qp, *newqp;
 
@@ -735,6 +735,7 @@ lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
            if (msl_launch(&plp->plane, EF_LAND, "troops",
                           newx, newy, victim, &sublaunch) < 0)
                goto use_up_msl;
+           stopping = 1;
            if (msl_hit(&plp->plane, hardtarget, EF_LAND,
                        N_LND_MISS, N_LND_SMISS, sublaunch, victim)) {
                newdam = pln_damage(&plp->plane, 'p', 1);
@@ -754,8 +755,9 @@ lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
     if (dam) {
        mpr(victim, "missile interdiction mission does %d damage!\n", dam);
        collateral_damage(newx, newy, dam);
+       lnd_damage(list, dam);
     }
-    return dam;
+    return stopping;
 }
 
 #if 0
@@ -771,6 +773,7 @@ lnd_fort_interdiction(struct emp_qelem *list,
     double guneff;
     int shell, gun;
     int dam;
+    int stopping = 0;
     int totdam = 0;
     int i;
 
@@ -790,6 +793,7 @@ lnd_fort_interdiction(struct emp_qelem *list,
        putsect(&fsect);
        if (dam < 0)
            continue;
+       stopping = 1;
        totdam += dam;
        mpr(victim, "Incoming fire does %d damage!\n", dam);
        wu(0, fsect.sct_own,
@@ -800,11 +804,25 @@ lnd_fort_interdiction(struct emp_qelem *list,
        nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
     }
     if (totdam > 0)
-       return lnd_damage(list, totdam);
-    return 0;
+       lnd_damage(list, totdam);
+    return stopping;
 }
 #endif
 
+static int
+lnd_mission_interdiction(struct emp_qelem *list, coord x, coord y,
+                        natid victim)
+{
+    int dam;
+
+    dam = unit_interdict(x, y, victim, "land units",
+                        lnd_easiest_target(list),
+                        MI_INTERDICT);
+    if (dam >= 0)
+       lnd_damage(list, dam);
+    return dam >= 0;
+}
+
 int
 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
 {
@@ -816,14 +834,8 @@ lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
        stopping |= lnd_fort_interdiction(list, newx, newy, victim);
 #endif
 
-    stopping |=
-       lnd_damage(list,
-                  unit_interdict(newx, newy, victim, "land units",
-                                 lnd_easiest_target(list), MI_INTERDICT));
-
-    stopping |=
-       lnd_damage(list,
-                  lnd_missile_interdiction(list, newx, newy, victim));
+    stopping |= lnd_mission_interdiction(list, newx, newy, victim);
+    stopping |= lnd_missile_interdiction(list, newx, newy, victim);
     return stopping;
 }
 
@@ -840,7 +852,7 @@ lnd_hardtarget(struct lndstr *lp)
 }
 
 static int
-lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
+lnd_hit_mine(struct lndstr *lp)
 {
     int m;
 
@@ -850,7 +862,7 @@ lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
     nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
 
     m = MINE_LDAMAGE();
-    if (lcp->l_flags & L_ENGINEER)
+    if (lchr[lp->lnd_type].l_flags & L_ENGINEER)
        m /= 2;
 
     landdamage(lp, m);
@@ -1041,7 +1053,6 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
        /* move survivors to done */
        for (qp = cur.q_back; qp != &cur; qp = next) {
            next = qp->q_back;
-           llp = (struct ulist *)qp;
            emp_remque(qp);
            emp_insque(qp, &done);
        }