]> 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 10a38a4a77bf18f26a054c67b041deb311767822..4b0cec14b330edc234044f3a8d421a298b393b06 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, 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
@@ -30,7 +30,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2004-2008
+ *     Markus Armbruster, 2004-2009
  */
 
 #include <config.h>
@@ -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;
@@ -553,10 +552,10 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
                    prland(&llp->unit.land));
            continue;
        }
-       if (sect.sct_type == SCT_BSPAN) {
+       if (SCT_MINES_ARE_SEAMINES(&sect)) {
            if (verbose)
-               mpr(actor, "%s is on a bridge.  No mines there!\n",
-                   prland(&llp->unit.land));
+               mpr(actor, "%s is in a %s sector.  No landmines there!\n",
+                   prland(&llp->unit.land), dchr[sect.sct_type].d_name);
            continue;
        }
        if (takemob) {
@@ -620,12 +619,10 @@ lnd_check_mines(struct emp_qelem *land_list)
        getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &sect);
        if (sect.sct_oldown == llp->unit.land.lnd_own)
            continue;
-       if (sect.sct_type == SCT_BSPAN)
-           continue;
-       if (!sect.sct_mines)
+       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);
@@ -683,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);
@@ -720,27 +717,47 @@ static int
 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
                         natid victim)
 {
-    int dam;
+    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;
 
     msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
 
-    dam = msl_launch_mindam(&msl_list, newx, newy,
-                           lnd_easiest_target(list), EF_LAND,
-                           lnd_count(list) * 20, "troops", victim,
-                           MI_INTERDICT);
+    dam = 0;
+    for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
+       newqp = qp->q_back;
+       plp = (struct plist *)qp;
+
+       if (dam < mindam && mission_pln_equip(plp, NULL, 'p') >= 0) {
+           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);
+               dam += newdam;
+           } else {
+               newdam = pln_damage(&plp->plane, 'p', 0);
+               collateral_damage(newx, newy, newdam);
+           }
+       use_up_msl:
+           plp->plane.pln_effic = 0;
+           putplane(plp->plane.pln_uid, &plp->plane);
+       }
+       emp_remque(qp);
+       free(qp);
+    }
+
     if (dam) {
        mpr(victim, "missile interdiction mission does %d damage!\n", dam);
        collateral_damage(newx, newy, dam);
+       lnd_damage(list, dam);
     }
-    qp = msl_list.q_forw;
-    while (qp != msl_list.q_forw) {
-       newqp = qp->q_forw;
-       emp_remque(qp);
-       free(qp);
-       qp = newqp;
-    }
-    return dam;
+    return stopping;
 }
 
 #if 0
@@ -756,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;
 
@@ -775,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,
@@ -785,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)
 {
@@ -801,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;
 }
 
@@ -825,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;
 
@@ -835,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);
@@ -989,7 +1016,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
                    pr("%s was shot and killed.\n", prland(&llp->unit.land));
                    llp->unit.land.lnd_effic = 0;
                    putland(llp->unit.land.lnd_uid, &llp->unit.land);
-                   lnd_delete(llp, 0);
+                   lnd_delete(llp, NULL);
                }
            }
        }
@@ -1026,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);
        }