]> git.pond.sub.org Git - empserver/commitdiff
Oops when stuck cargo snaps to new ship, plane or land unit
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 5 Jul 2011 19:06:40 +0000 (21:06 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 10 Jul 2011 09:43:44 +0000 (11:43 +0200)
When units somehow get stuck on a dead carrier, a new build reusing
the dead carrier's UID picks up its cargo.  The cargo gets teleported
to its new carrier when the carrier moves.

Oops when a ship, plane or land unit is created with cargo.  To
recover, destroy the cargo.

include/unit.h
src/lib/subs/land.c
src/lib/subs/plane.c
src/lib/subs/ship.c
src/lib/subs/unitsub.c

index 1eb5df24383cbc29b62132c90821d5a5dfb30e8d..08ceeb5be689a4c2bc029e3a812220f232781fd8 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2006-2007
- *     Markus Armbruster, 2006
+ *     Markus Armbruster, 2006-2011
  */
 
 #ifndef UNIT_H
@@ -59,7 +59,7 @@ extern void unit_list(struct emp_qelem *);
 extern void unit_put(struct emp_qelem *list, natid actor);
 extern char *unit_path(int, struct empobj *, char *);
 extern void unit_view(struct emp_qelem *);
-extern void unit_update_cargo(struct empobj *);
+extern int unit_update_cargo(struct empobj *);
 extern void unit_drop_cargo(struct empobj *, natid);
 extern void unit_give_away(struct empobj *, natid, natid);
 extern void unit_wipe_orders(struct empobj *);
index 0ef301a0282b0bc49f5cf38af354e683057e6636..5a7ae3e63655179b485d45b79385494f0ba1d694 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Steve McClure, 1996
- *     Markus Armbruster, 2004-2008
+ *     Markus Armbruster, 2004-2011
  */
 
 #include <config.h>
@@ -79,9 +79,12 @@ lnd_prewrite(int n, void *old, void *new)
        lnd_carrier_change(lp, EF_LAND, oldlp->lnd_land, lp->lnd_land);
 
     /* We've avoided assigning to lp->lnd_own, in case oldlp == lp */
-    if (oldlp->lnd_own != own)
+    if (oldlp->lnd_own != own) {
        lost_and_found(EF_LAND, oldlp->lnd_own, own,
                       lp->lnd_uid, lp->lnd_x, lp->lnd_y);
+       CANT_HAPPEN(!oldlp->lnd_own
+                   && unit_update_cargo((struct empobj *)oldlp));
+    }
 
     lp->lnd_own = own;
     if (!own || lp->lnd_x != oldlp->lnd_x || lp->lnd_y != oldlp->lnd_y)
index 29cb6523760c99603511634663b32e2863aa508e..7b1c89ae8673f5b1a8e33c84f3e2ad9123175508 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Dave Pare, 1989
  *     Steve McClure, 1996
- *     Markus Armbruster, 2006-2008
+ *     Markus Armbruster, 2006-2011
  */
 
 #include <config.h>
@@ -78,9 +78,12 @@ pln_prewrite(int n, void *old, void *new)
        pln_carrier_change(pp, EF_LAND, oldpp->pln_land, pp->pln_land);
 
     /* We've avoided assigning to pp->pln_own, in case oldpp == pp */
-    if (oldpp->pln_own != own)
+    if (oldpp->pln_own != own) {
        lost_and_found(EF_PLANE, oldpp->pln_own, own,
                       pp->pln_uid, pp->pln_x, pp->pln_y);
+       CANT_HAPPEN(!oldpp->pln_own
+                   && unit_update_cargo((struct empobj *)oldpp));
+    }
 
     pp->pln_own = own;
     if (!own || pp->pln_x != oldpp->pln_x || pp->pln_y != oldpp->pln_y)
index 119648ca67aa22a9a415c5ed06afda78a14df273..dadee5fca383bfe9e0d157e73805eef9ae403fde 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Dave Pare, 1989
  *     Steve McClure, 1996
- *     Markus Armbruster, 2004-2008
+ *     Markus Armbruster, 2004-2011
  */
 
 #include <config.h>
@@ -74,9 +74,12 @@ shp_prewrite(int n, void *old, void *new)
     item_prewrite(sp->shp_item);
 
     /* We've avoided assigning to sp->shp_own, in case oldsp == sp */
-    if (oldsp->shp_own != own)
+    if (oldsp->shp_own != own) {
        lost_and_found(EF_SHIP, oldsp->shp_own, own,
                       sp->shp_uid, sp->shp_x, sp->shp_y);
+       CANT_HAPPEN(!oldsp->shp_own
+                   && unit_update_cargo((struct empobj *)oldsp));
+    }
 
     sp->shp_own = own;
     if (!own || sp->shp_x != oldsp->shp_x || sp->shp_y != oldsp->shp_y)
index 4e8e6c23c1346e991422082c7a023ce7ff26e486..283425a93d4d93d70f6fe63170633a2fed11bda4 100644 (file)
@@ -243,13 +243,15 @@ unit_view(struct emp_qelem *list)
  * nukes).
  * Else update their location to the carrier's.  Any op sectors equal
  * to location get updated, too.
+ * Return number of units updated.
  */
-void
+int
 unit_update_cargo(struct empobj *carrier)
 {
     int cargo_type;
     struct nstr_item ni;
     union empobj_storage obj;
+    int n = 0;
 
     for (cargo_type = EF_PLANE; cargo_type <= EF_NUKE; cargo_type++) {
        snxtitem_cargo(&ni, cargo_type, carrier->ef_type, carrier->uid);
@@ -267,8 +269,10 @@ unit_update_cargo(struct empobj *carrier)
                obj.gen.y = carrier->y;
            }
            put_empobj(cargo_type, obj.gen.uid, &obj);
+           n++;
        }
     }
+    return n;
 }
 
 /*