diff --git a/src/give.c b/src/give.c index 8f352ccbb..e1a3cec66 100644 --- a/src/give.c +++ b/src/give.c @@ -385,6 +385,9 @@ message * give_ship(unit *u1, unit *u2, int n, order *ord) } } else { + if (u2->building) { + leave_building(u2); + } if (n < u1->ship->number) { ship * sh = new_ship(u1->ship->type, u1->region, u1->faction->locale); scale_ship(sh, 0); diff --git a/src/kernel/save.c b/src/kernel/save.c index a65dda7e1..66eb22471 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -376,7 +376,7 @@ unit *read_unit(gamedata *data) { unit *u; const race *rc; - int number, n, p; + int number, n, p, bn, sn; order **orderp; char obuf[DISPLAYSIZE]; faction *f; @@ -443,9 +443,10 @@ unit *read_unit(gamedata *data) else u->irace = NULL; - READ_INT(data->store, &n); - if (n > 0) { - building * b = findbuilding(n); + READ_INT(data->store, &bn); + READ_INT(data->store, &sn); + if (sn <= 0 && bn > 0) { + building * b = findbuilding(bn); if (b) { u_set_building(u, b); if (fval(u, UFL_OWNER)) { @@ -453,13 +454,12 @@ unit *read_unit(gamedata *data) } } else { - log_error("read_unit: unit in unkown building '%s'", itoa36(n)); + log_error("read_unit: unit in unkown building '%s'", itoa36(bn)); } } - READ_INT(data->store, &n); - if (n > 0) { - ship * sh = findship(n); + if (sn > 0) { + ship * sh = findship(sn); if (sh) { u_set_ship(u, sh); if (fval(u, UFL_OWNER)) { @@ -467,7 +467,7 @@ unit *read_unit(gamedata *data) } } else { - log_error("read_unit: unit in unkown ship '%s'", itoa36(n)); + log_error("read_unit: unit in unkown ship '%s'", itoa36(sn)); } } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 0e22e8d2d..6b4cbe2b0 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -635,7 +635,7 @@ void leave_ship(unit * u) { struct ship *sh = u->ship; - u->ship = 0; + u->ship = NULL; if (sh->_owner == u) { ship_update_owner(sh); sh->_owner = ship_owner(sh);