]> git.pond.sub.org Git - empserver/commitdiff
Factor out a single plane's end of sortie into new pln_put1()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 22 Mar 2008 13:55:30 +0000 (14:55 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 26 Mar 2008 21:09:09 +0000 (22:09 +0100)
Use it in pln_put() and ac_planedamage().

This changes ac_planedamage() to deal with a destroyed airbase.
Before, aborted planes happily landed there.  This bug could not
actually bite, because the code neither yields nor does damage to
potential airbases between checking the landing airbase before takeoff
and aborting planes in ac_planedamage().

It changes pln_put() to cope with dead planes.  Before, it made them
land as if they lived, fortunately without ill effects (complaints
about not being able to land were suppressed for dead planes).
ac_planedamage() removes dead planes, but pinflak_planedamage()
doesn't, and these end up in pln_put().  pinflak_planedamage() no
longer has to take shot down planes off their carriers, because
pln_put() now takes care of that.

include/prototypes.h
src/lib/commands/bomb.c
src/lib/subs/aircombat.c
src/lib/subs/plnsub.c

index 42ac4464e105f68c7b851467b0af0ccf4aa082fa..4950e4a8d5cbd1ebebd1b0a7dcbe80a589142089 100644 (file)
@@ -558,6 +558,7 @@ extern int pln_arm(struct emp_qelem *, int, char, struct ichrstr *,
                   int, int);
 extern int pln_mobcost(int, struct plnstr *, int);
 extern void pln_put(struct emp_qelem *);
+extern void pln_put1(struct plist *);
 extern void pln_removedupes(struct emp_qelem *, struct emp_qelem *);
 extern void take_plane_off_ship(struct plnstr *, struct shpstr *);
 extern void take_plane_off_land(struct plnstr *, struct lndstr *);
index b791b7b8d1b0442f7f5d24e83c45b5f1debffbe2..f475d47df4b9eb9cb43abfa3fa4b3d6abb251768 100644 (file)
@@ -844,8 +844,6 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
     int disp;
     char dmess[255];
     int eff;
-    struct shpstr ship;
-    struct lndstr land;
     natid plane_owner;
     int dam;
 
@@ -873,14 +871,6 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
     if (disp == 1) {
        if (from != 0)
            nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
-       if (pp->pln_ship >= 0) {
-           getship(pp->pln_ship, &ship);
-           take_plane_off_ship(pp, &ship);
-       }
-       if (pp->pln_land >= 0) {
-           getland(pp->pln_land, &land);
-           take_plane_off_land(pp, &land);
-       }
     }
     putplane(pp->pln_uid, pp);
 
index 644fe78b8618337c3d5f7e3bbd72028719430eb1..9c833d9b71182553a7049ec49c2802ca503ab0b9 100644 (file)
@@ -708,8 +708,6 @@ ac_planedamage(struct plist *plp, natid from, int dam, natid other,
     int disp;
     char dmess[255];
     int eff;
-    struct shpstr ship;
-    struct lndstr land;
     natid plane_owner;
 
     disp = 0;
@@ -752,25 +750,10 @@ ac_planedamage(struct plist *plp, natid from, int dam, natid other,
 
     pp->pln_effic = eff;
     pp->pln_mobil -= MIN(32 + pp->pln_mobil, dam / 2);
-    if (disp == 1) {
-       if (from != 0 && (plp->pcp->pl_flags & P_M) == 0)
+    if (disp) {
+       if (disp == 1 && from != 0 && (plp->pcp->pl_flags & P_M) == 0)
            nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
-       if (pp->pln_ship >= 0) {
-           getship(pp->pln_ship, &ship);
-           take_plane_off_ship(pp, &ship);
-       }
-       if (pp->pln_land >= 0) {
-           getland(pp->pln_land, &land);
-           take_plane_off_land(pp, &land);
-       }
-       pp->pln_effic = 0;
-       putplane(pp->pln_uid, pp);
-       emp_remque(&plp->queue);
-       free(plp);
-    } else if (disp == 2) {
-       putplane(pp->pln_uid, pp);
-       emp_remque(&plp->queue);
-       free(plp);
+       pln_put1(plp);
     } else
        putplane(pp->pln_uid, pp);
     strcpy(mesg, dmess);
index 7ce0783f1c7355f687d9c9be6cf9fe325f935831..2eddb817829eda51002d7ad50b46058b4860748b 100644 (file)
@@ -725,50 +725,59 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission)
 void
 pln_put(struct emp_qelem *list)
 {
-    struct emp_qelem *qp;
-    struct emp_qelem *newqp;
-    struct plist *plp;
+    struct emp_qelem *qp, *next;
+
+    for (qp = list->q_forw; qp != list; qp = next) {
+       next = qp->q_forw;
+       pln_put1((struct plist *)qp);
+    }
+}
+
+void
+pln_put1(struct plist *plp)
+{
     struct plnstr *pp;
     struct shpstr ship;
+    struct lndstr land;
     struct sctstr sect;
 
-    /* Here is where planes return home from bombing runs.
-       We need to make sure they still have somewhere to return
-       home to! */
-    qp = list->q_forw;
-    while (qp != list) {
-       plp = (struct plist *)qp;
-       pp = &plp->plane;
-       /* Ok, check out where it wants to land */
+    pp = &plp->plane;
+    if (!pp->pln_own) {
+       /* crashed */
        if (pp->pln_ship >= 0) {
-           /* It is landing on a carrier */
            getship(pp->pln_ship, &ship);
-           /* We should do more, like make sure it's really
-              a carrier, etc. but for now just make sure it's
-              not sunk. */
-           if (ship.shp_effic < SHIP_MINEFF) {
-               mpr(pp->pln_own,
-                   "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
-                   "splashes into the sea.\n",
-                   pp->pln_ship, pp->pln_uid);
-               pp->pln_effic = 0;
-           }
-       } else {
-           /* Presume we are landing back in a sector. */
-           getsect(pp->pln_x, pp->pln_y, &sect);
-           if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
-               mpr(pp->pln_own,
-                   "Nowhere to land at %s, plane #%d crashes and burns...\n",
-                   xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
-               pp->pln_effic = 0;
-           }
+           take_plane_off_ship(pp, &ship);
+       }
+       if (pp->pln_land >= 0) {
+           getland(pp->pln_land, &land);
+           take_plane_off_land(pp, &land);
+       }
+    } else if (pp->pln_ship >= 0) {
+       /* It is landing on a carrier */
+       getship(pp->pln_ship, &ship);
+       /* We should do more, like make sure it's really
+          a carrier, etc. but for now just make sure it's
+          not sunk. */
+       if (ship.shp_effic < SHIP_MINEFF) {
+           mpr(pp->pln_own,
+               "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
+               "splashes into the sea.\n",
+               pp->pln_ship, pp->pln_uid);
+           pp->pln_effic = 0;
+       }
+    } else {
+       /* Presume we are landing back in a sector. */
+       getsect(pp->pln_x, pp->pln_y, &sect);
+       if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
+           mpr(pp->pln_own,
+               "Nowhere to land at %s, plane #%d crashes and burns...\n",
+               xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
+           pp->pln_effic = 0;
        }
-       putplane(pp->pln_uid, pp);
-       newqp = qp->q_forw;
-       emp_remque(qp);
-       free(qp);
-       qp = newqp;
     }
+    putplane(pp->pln_uid, pp);
+    emp_remque(&plp->queue);
+    free(plp);
 }
 
 void