Make unit_give_away() immune to infinite recursion
Put the unit before recursing into its cargo. This breaks cycles in the "is loaded on" relations. Such cycles exist only in a corrupt game state. Mildly inefficient, because callers typically put the unit again.
This commit is contained in:
parent
5820e12504
commit
6589601e56
1 changed files with 2 additions and 3 deletions
|
@ -301,13 +301,12 @@ unit_give_away(struct empobj *unit, natid recipient, natid giver)
|
||||||
|
|
||||||
unit->own = recipient;
|
unit->own = recipient;
|
||||||
unit_wipe_orders(unit);
|
unit_wipe_orders(unit);
|
||||||
|
put_empobj(unit->ef_type, unit->uid, unit);
|
||||||
|
|
||||||
for (type = EF_PLANE; type <= EF_NUKE; type++) {
|
for (type = EF_PLANE; type <= EF_NUKE; type++) {
|
||||||
snxtitem_cargo(&ni, type, unit->ef_type, unit->uid);
|
snxtitem_cargo(&ni, type, unit->ef_type, unit->uid);
|
||||||
while (nxtitem(&ni, &cargo)) {
|
while (nxtitem(&ni, &cargo))
|
||||||
unit_give_away(&cargo.gen, recipient, giver);
|
unit_give_away(&cargo.gen, recipient, giver);
|
||||||
put_empobj(type, cargo.gen.uid, &cargo.gen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue