Fix cargo giveaway in scrap and scuttle

When giving away cargo by scrapping or scuttling its carrier, the
cargo's cargo wasn't given away.  Happened for instance when a ship
carrying a land unit carrying a SAM got scrapped.

Also, wing, army and mission weren't cleared.

To fix, create unit_give_away() and use it in unit_drop_cargo().
This commit is contained in:
Markus Armbruster 2008-09-13 22:06:44 -04:00
parent f3651f17e5
commit d2b1bef0f5
2 changed files with 39 additions and 7 deletions

View file

@ -58,3 +58,4 @@ extern char *unit_path(int, struct empobj *, char *);
extern void unit_view(struct emp_qelem *);
extern void unit_update_cargo(struct empobj *);
extern void unit_drop_cargo(struct empobj *, natid);
extern void unit_give_away(struct empobj *, natid, natid);

View file

@ -268,13 +268,44 @@ unit_drop_cargo(struct empobj *unit, natid newown)
obj_nameof(&cargo.gen),
ef_nameof(unit->ef_type), unit->uid,
xyas(cargo.gen.x, cargo.gen.y, cargo.gen.own));
if (newown) {
mpr(cargo.gen.own, "%s given to %s\n",
obj_nameof(&cargo.gen), cname(newown));
mpr(newown, "%s given to you by %s\n",
obj_nameof(&cargo.gen), cname(cargo.gen.own));
cargo.gen.own = newown;
}
if (newown)
unit_give_away(&cargo.gen, newown, cargo.gen.own);
put_empobj(type, cargo.gen.uid, &cargo.gen);
}
}
}
/*
* Give UNIT and its cargo to RECIPIENT.
* No action if RECIPIENT already owns UNIT.
* If GIVER is non-zero, inform RECIPIENT and GIVER of the transaction.
* Clears mission and group on the units given away.
*/
void
unit_give_away(struct empobj *unit, natid recipient, natid giver)
{
int type;
struct nstr_item ni;
union empobj_storage cargo;
if (unit->own == recipient)
return;
if (giver) {
mpr(unit->own, "%s given to %s\n",
obj_nameof(unit), cname(recipient));
mpr(recipient, "%s given to you by %s\n",
obj_nameof(unit), cname(giver));
}
unit->own = recipient;
unit->mission = 0;
unit->group = 0;
for (type = EF_PLANE; type <= EF_NUKE; type++) {
snxtitem_cargo(&ni, type, unit->ef_type, unit->uid);
while (nxtitem(&ni, &cargo)) {
unit_give_away(&cargo.gen, recipient, giver);
put_empobj(type, cargo.gen.uid, &cargo.gen);
}
}