]> git.pond.sub.org Git - empserver/commitdiff
Fix update to take dead units off carriers
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 15 Apr 2009 21:06:54 +0000 (23:06 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 15 Apr 2009 21:06:54 +0000 (23:06 +0200)
upd_plane() upd_land() and left planes and land units lost to lack of
maintenance on their carriers.  Cargo lists were fine anyway, because
unit_cargo_init() ignored dead units.  But when the dead unit got
reused for building a new one, pln_prewrite() / lnd_prewrite() got
confused and attempted to take it off its carrier, which made
clink_rem() oops, because the unit wasn't on the cargo list.  No real
harm done, as oops recovery was fine.

Fix upd_plane() and upd_land() to clear the carrier.  Make
unit_cargo_init() oops when it finds dead units on carriers.

src/lib/common/cargo.c
src/lib/update/land.c
src/lib/update/plane.c

index 59ccf84b02abbd1ab8e50664bd83cea9201fcf40..d0c84d72e102ce3516957bfa050d48b5689320ad 100644 (file)
@@ -241,24 +241,33 @@ unit_cargo_init(void)
        unit_onresize(i);
 
     for (i = 0; (pp = getplanep(i)); i++) {
-       if (!pp->pln_own)
+       if (!pp->pln_own) {
+           if (CANT_HAPPEN(pp->pln_ship >= 0 || pp->pln_land >= 0))
+               pp->pln_ship = pp->pln_land = -1;
            continue;
+       }
        if (CANT_HAPPEN(pp->pln_ship >= 0 && pp->pln_land >= 0))
            pp->pln_land = -1;
        pln_carrier_change(pp, EF_SHIP, -1, pp->pln_ship);
        pln_carrier_change(pp, EF_LAND, -1, pp->pln_land);
     }
     for (i = 0; (lp = getlandp(i)); i++) {
-       if (!lp->lnd_own)
+       if (!lp->lnd_own) {
+           if (CANT_HAPPEN(lp->lnd_ship >= 0 || lp->lnd_land >= 0))
+               lp->lnd_ship = lp->lnd_land = -1;
            continue;
+       }
        if (CANT_HAPPEN(lp->lnd_ship >= 0 && lp->lnd_land >= 0))
            lp->lnd_land = -1;
        lnd_carrier_change(lp, EF_SHIP, -1, lp->lnd_ship);
        lnd_carrier_change(lp, EF_LAND, -1, lp->lnd_land);
     }
     for (i = 0; (np = getnukep(i)); i++) {
-       if (!np->nuk_own)
+       if (!np->nuk_own) {
+           if (CANT_HAPPEN(np->nuk_plane >= 0))
+               np->nuk_plane = -1;
            continue;
+       }
        nuk_carrier_change(np, EF_PLANE, -1, np->nuk_plane);
     }
 }
index 81ca77d34ccb2159377164e618e7985dee26fe50..41cc568231285b3d2d64e276b4e2076e5ad4b2c2 100644 (file)
@@ -125,6 +125,7 @@ upd_land(struct lndstr *lp, int etus,
                makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
                         lp->lnd_x, lp->lnd_y);
                lp->lnd_own = 0;
+               lp->lnd_ship = lp->lnd_land = -1;
                return;
            }
            wu(0, lp->lnd_own,
index f764f17ca9c0811aedca8740ead7ad5fd64e85ad..dea614c05d74456857ee7ce2a1d2199c29716c3c 100644 (file)
@@ -110,6 +110,7 @@ upd_plane(struct plnstr *pp, int etus,
                makelost(EF_PLANE, pp->pln_own, pp->pln_uid,
                         pp->pln_x, pp->pln_y);
                pp->pln_own = 0;
+               pp->pln_ship = pp->pln_land = -1;
                return;
            }
            wu(0, pp->pln_own,