From 6fb5caf633ffb4c1b021ce2fe6d4c36a59b6a5ad Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 5 Jul 2011 21:06:40 +0200 Subject: [PATCH] Oops when stuck cargo snaps to new ship, plane or land unit 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 | 4 ++-- src/lib/subs/land.c | 7 +++++-- src/lib/subs/plane.c | 7 +++++-- src/lib/subs/ship.c | 7 +++++-- src/lib/subs/unitsub.c | 6 +++++- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/unit.h b/include/unit.h index 1eb5df243..08ceeb5be 100644 --- a/include/unit.h +++ b/include/unit.h @@ -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 *); diff --git a/src/lib/subs/land.c b/src/lib/subs/land.c index 0ef301a02..5a7ae3e63 100644 --- a/src/lib/subs/land.c +++ b/src/lib/subs/land.c @@ -28,7 +28,7 @@ * * Known contributors to this file: * Steve McClure, 1996 - * Markus Armbruster, 2004-2008 + * Markus Armbruster, 2004-2011 */ #include @@ -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) diff --git a/src/lib/subs/plane.c b/src/lib/subs/plane.c index 29cb65237..7b1c89ae8 100644 --- a/src/lib/subs/plane.c +++ b/src/lib/subs/plane.c @@ -29,7 +29,7 @@ * Known contributors to this file: * Dave Pare, 1989 * Steve McClure, 1996 - * Markus Armbruster, 2006-2008 + * Markus Armbruster, 2006-2011 */ #include @@ -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) diff --git a/src/lib/subs/ship.c b/src/lib/subs/ship.c index 119648ca6..dadee5fca 100644 --- a/src/lib/subs/ship.c +++ b/src/lib/subs/ship.c @@ -29,7 +29,7 @@ * Known contributors to this file: * Dave Pare, 1989 * Steve McClure, 1996 - * Markus Armbruster, 2004-2008 + * Markus Armbruster, 2004-2011 */ #include @@ -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) diff --git a/src/lib/subs/unitsub.c b/src/lib/subs/unitsub.c index 4e8e6c23c..283425a93 100644 --- a/src/lib/subs/unitsub.c +++ b/src/lib/subs/unitsub.c @@ -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; } /* -- 2.43.0