]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/aircombat.c
Update copyright notice
[empserver] / src / lib / subs / aircombat.c
index 4ae807c6ecdee78b4c8894c571e8c974b64af682..7d4773190b6fa341140246049200ff4448370369 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -30,7 +30,7 @@
  *     Dave Pare, 1986
  *     Thomas Ruschak, 1992
  *     Steve McClure, 1996
- *     Markus Armbruster, 2006-2010
+ *     Markus Armbruster, 2006-2012
  */
 
 #include <config.h>
@@ -45,6 +45,7 @@
 #include "nsc.h"
 #include "optlist.h"
 #include "path.h"
+#include "plague.h"
 #include "plane.h"
 #include "player.h"
 #include "prototypes.h"
@@ -61,7 +62,7 @@ static void ac_intercept(struct emp_qelem *, struct emp_qelem *,
 static void ac_combat_headers(natid, natid);
 static void ac_airtoair(struct emp_qelem *, struct emp_qelem *);
 static void ac_dog(struct plist *, struct plist *);
-static void ac_planedamage(struct plist *, natid, int, int, char *);
+static void ac_putplane(struct plist *, int);
 static void ac_doflak(struct emp_qelem *, struct sctstr *);
 static void ac_landflak(struct emp_qelem *, coord, coord);
 static void ac_shipflak(struct emp_qelem *, coord, coord);
@@ -449,7 +450,7 @@ ac_dog(struct plist *ap, struct plist *dp)
     double odds;
     int intensity, i;
     natid att_own, def_own;
-    int adam, ddam;
+    int adam, ddam, adisp, ddisp;
     char adam_mesg[14], ddam_mesg[14];
 
     att_own = ap->plane.pln_own;
@@ -500,14 +501,16 @@ ac_dog(struct plist *ap, struct plist *dp)
     if (dp->pcp->pl_flags & P_M)
        ddam = 100;
 
-    ac_planedamage(ap, def_own, adam, 0, adam_mesg);
-    ac_planedamage(dp, att_own, ddam, 0, ddam_mesg);
+    adisp = ac_damage_plane(&ap->plane, def_own, adam, 0, adam_mesg);
+    ddisp = ac_damage_plane(&dp->plane, att_own, ddam, 0, ddam_mesg);
     ac_dog_report(att_own, intensity, odds,
                  ap, att, adam, adam_mesg,
                  dp, def, ddam, ddam_mesg);
     ac_dog_report(def_own, intensity, odds,
                  dp, def, ddam, ddam_mesg,
                  ap, att, adam, adam_mesg);
+    ac_putplane(ap, adisp);
+    ac_putplane(dp, ddisp);
 
     if (opt_HIDDEN) {
        setcont(att_own, def_own, FOUND_FLY);
@@ -515,27 +518,6 @@ ac_dog(struct plist *ap, struct plist *dp)
     }
 }
 
-/*
- * zap plane associated with plp.
- * Damaging country is "from", damage is "dam".
- *
- * NOTE: This routine removes the appropriate plane element from the
- * queue if it gets destroyed.  That means that the caller must assume
- * that the current queue pointer is invalid on return from the ac_planedamage
- * call.  (this has caused bugs in the past)
- */
-static void
-ac_planedamage(struct plist *plp, natid from, int dam, int flak,
-              char *mesg)
-{
-    int disp = ac_damage_plane(&plp->plane, from, dam, flak, mesg);
-
-    if (disp) {
-       pln_put1(plp);
-    } else
-       putplane(plp->plane.pln_uid, &plp->plane);
-}
-
 int
 ac_damage_plane(struct plnstr *pp, natid from, int dam, int flak,
                char *mesg)
@@ -571,6 +553,21 @@ ac_damage_plane(struct plnstr *pp, natid from, int dam, int flak,
     return disp;
 }
 
+/*
+ * NOTE: This routine may remove the appropriate plane element from the
+ * queue if it gets destroyed.  That means that the caller must assume
+ * that the current queue pointer is invalid on return from the
+ * call.  (this has caused bugs in the past)
+ */
+static void
+ac_putplane(struct plist *plp, int disp)
+{
+    if (disp)
+       pln_put1(plp);
+    else
+       putplane(plp->plane.pln_uid, &plp->plane);
+}
+
 static void
 ac_doflak(struct emp_qelem *list, struct sctstr *from)
 {
@@ -695,7 +692,7 @@ static void
 ac_fireflak(struct emp_qelem *list, natid from, int guns)
 {
     struct plist *plp;
-    int n;
+    int n, disp;
     struct emp_qelem *qp;
     struct emp_qelem *next;
     char msg[14];
@@ -704,9 +701,10 @@ ac_fireflak(struct emp_qelem *list, natid from, int guns)
        next = qp->q_forw;
        plp = (struct plist *)qp;
        n = ac_flak_dam(guns, pln_def(&plp->plane), plp->pcp->pl_flags);
-       ac_planedamage(plp, from, n, 1, msg);
+       disp = ac_damage_plane(&plp->plane, from, n, 1, msg);
        mpr(plp->plane.pln_own, "    %s takes %d%s%s.\n",
            prplane(&plp->plane), n, *msg ? " --" : "", msg);
+       ac_putplane(plp, disp);
     }
 }
 
@@ -787,6 +785,7 @@ getilists(struct emp_qelem *list, unsigned char *rel, natid intruder)
        /* got one! */
        ip = malloc(sizeof(*ip));
        ip->load = 0;
+       ip->pstage = PLG_HEALTHY;
        ip->pcp = &plchr[(int)plane.pln_type];
        ip->plane = plane;
        emp_insque(&ip->queue, &list[plane.pln_own]);