Rewrite the broken code to move cargo with its carrier

The old code did not move a carrier's cargo (planes, land units,
nukes) when the carrier moved.  Instead, it fixed up the location in
the postread callback.  Anything not going through ef_read(), in
particular the update, saw it in its old, incorrect location, until a
fixed up copy got written back.

Moreover, the timestamp did not change when cargo moved, so
incremental dumps did not pick up the movement.

The new code moves the cargo along with the carrier.

New unit_update_cargo() moves or destroys a carrier's cargo (planes,
land units, nukes) along with the carrier.  Call it from
shp_prewrite(), pln_prewrite() and lnd_prewrite() when the carrier
moves or gets destroyed.

Remove the code to destroy cargo from shp_prewrite(), pln_prewrite(),
lnd_prewrite().

Remove the code to fix up cargo location from pln_postread(),
lnd_postread(), nuk_postread().

This changes the message for ship and land unit cargo getting
destroyed from "sunk" and "MIA" to "lost".
This commit is contained in:
Markus Armbruster 2008-09-12 19:31:48 -04:00
parent e7f5b517a0
commit 3cf29456fe
6 changed files with 45 additions and 181 deletions

View file

@ -204,3 +204,37 @@ unit_view(struct emp_qelem *list)
sect.sct_effic, dchr[sect.sct_type].d_name);
}
}
/*
* Update cargo of CARRIER for movement or destruction.
* If the carrier is destroyed, destroy its cargo (planes, land units,
* nukes).
* Else update their location to the carrier's. Any op sectors equal
* to location get updated, too.
*/
void
unit_update_cargo(struct empobj *carrier)
{
int cargo_type;
struct nstr_item ni;
union empobj_storage obj;
for (cargo_type = EF_PLANE; cargo_type <= EF_NUKE; cargo_type++) {
snxtitem_cargo(&ni, cargo_type, carrier->ef_type, carrier->uid);
while (nxtitem(&ni, &obj)) {
if (!carrier->own) {
mpr(obj.gen.own, "%s lost!\n", obj_nameof(&obj.gen));
obj.gen.effic = 0;
} else {
/* mission op-area centered on the obj travels with it */
if (obj.gen.opx == obj.gen.x && obj.gen.opy == obj.gen.y) {
obj.gen.opx = carrier->x;
obj.gen.opy = carrier->y;
}
obj.gen.x = carrier->x;
obj.gen.y = carrier->y;
}
put_empobj(cargo_type, obj.gen.uid, &obj);
}
}
}