diff --git a/include/unit.h b/include/unit.h index 34b9c99b..df31adca 100644 --- a/include/unit.h +++ b/include/unit.h @@ -59,3 +59,4 @@ 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); +extern void unit_wipe_orders(struct empobj *); diff --git a/src/lib/commands/trad.c b/src/lib/commands/trad.c index d5aea270..c61c9c3a 100644 --- a/src/lib/commands/trad.c +++ b/src/lib/commands/trad.c @@ -372,8 +372,6 @@ check_trade(void) tg.plane.pln_land = -1; break; case EF_SHIP: - tg.ship.shp_rflags = 0; - memset(tg.ship.shp_rpath, 0, sizeof(tg.ship.shp_rpath)); break; case EF_LAND: tg.land.lnd_x = trade.trd_x; diff --git a/src/lib/subs/takeover.c b/src/lib/subs/takeover.c index 6037e4bf..43ffdded 100644 --- a/src/lib/subs/takeover.c +++ b/src/lib/subs/takeover.c @@ -47,6 +47,7 @@ #include "prototypes.h" #include "sect.h" #include "ship.h" +#include "unit.h" #include "xy.h" static void takeover_unit(struct empobj *, natid); @@ -231,14 +232,11 @@ takeover_unit(struct empobj *unit, natid newown) unit->own = newown; if (opt_MARKET) trdswitchown(unit->ef_type, unit, newown); - unit->group = 0; - unit->mission = 0; + unit_wipe_orders(unit); switch (unit->ef_type) { case EF_SHIP: sp = (struct shpstr *)unit; - sp->shp_rflags = 0; - memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath)); break; case EF_PLANE: pp = (struct plnstr *)unit; diff --git a/src/lib/subs/unitsub.c b/src/lib/subs/unitsub.c index ebd4d5e1..dff5ecbb 100644 --- a/src/lib/subs/unitsub.c +++ b/src/lib/subs/unitsub.c @@ -37,6 +37,7 @@ #include "empobj.h" #include "file.h" #include "player.h" +#include "optlist.h" #include "prototypes.h" #include "unit.h" @@ -299,8 +300,7 @@ unit_give_away(struct empobj *unit, natid recipient, natid giver) } unit->own = recipient; - unit->mission = 0; - unit->group = 0; + unit_wipe_orders(unit); for (type = EF_PLANE; type <= EF_NUKE; type++) { snxtitem_cargo(&ni, type, unit->ef_type, unit->uid); @@ -310,3 +310,55 @@ unit_give_away(struct empobj *unit, natid recipient, natid giver) } } } + +/* + * Wipe orders and such from UNIT. + */ +void +unit_wipe_orders(struct empobj *unit) +{ + struct shpstr *sp; + struct plnstr *pp; + struct lndstr *lp; + int i; + + unit->group = 0; + unit->opx = unit->opy = 0; + unit->mission = 0; + unit->radius = 0; + + switch (unit->ef_type) { + case EF_SHIP: + sp = (struct shpstr *)unit; + sp->shp_destx[0] = sp->shp_desty[0] = 0; + sp->shp_destx[1] = sp->shp_desty[1] = 0; + for (i = 0; i < TMAX; ++i) { + sp->shp_tstart[i] = I_NONE; + sp->shp_tend[i] = I_NONE; + sp->shp_lstart[i] = 0; + sp->shp_lend[i] = 0; + } + sp->shp_autonav = 0; + sp->shp_mobquota = 0; + sp->shp_path[0] = 0; + sp->shp_follow = sp->shp_uid; + sp->shp_rflags = 0; + sp->shp_rpath[0] = 0; + break; + case EF_PLANE: + pp = (struct plnstr *)unit; + pp->pln_range = pln_range_max(pp); + break; + case EF_LAND: + lp = (struct lndstr *)unit; + lp->lnd_retreat = morale_base; + lp->lnd_rflags = 0; + lp->lnd_rpath[0] = 0; + lp->lnd_rad_max = 0; + break; + case EF_NUKE: + break; + default: + CANT_REACH(); + } +}