Fix crash when removing drifted ships.

This commit is contained in:
Enno Rehling 2018-09-16 10:02:09 +02:00
parent 419ff9b514
commit 65675d1947
2 changed files with 24 additions and 31 deletions

View File

@ -630,7 +630,7 @@ mark_travelthru(unit * u, region * r, const region_list * route,
}
}
ship *move_ship(ship * sh, region * from, region * to, region_list * route)
void move_ship(ship * sh, region * from, region * to, region_list * route)
{
unit **iunit = &from->units;
unit **ulist = &to->units;
@ -663,8 +663,6 @@ ship *move_ship(ship * sh, region * from, region * to, region_list * route)
if (*iunit == u)
iunit = &u->next;
}
return sh;
}
static bool is_freezing(const unit * u)
@ -857,39 +855,34 @@ static void drifting_ships(region * r)
}
}
if (rnext != NULL) {
if (firstu != NULL) {
message *msg = msg_message("ship_drift", "ship dir", sh, dir);
msg_to_ship_inmates(sh, &firstu, &lastu, msg);
}
fset(sh, SF_DRIFTED);
if (ovl >= overload_start()) {
damage_ship(sh, damage_overload(ovl));
msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("massive_overload", "ship", sh));
}
else {
damage_ship(sh, damage_drift);
}
if (sh->damage >= sh->size * DAMAGE_SCALE) {
msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("shipsink", "ship", sh));
sink_ship(sh);
remove_ship(shp, sh);
}
else if (rnext != NULL) {
/* Das Schiff und alle Einheiten darin werden nun von r
* nach rnext verschoben. Danach eine Meldung. */
* nach rnext verschoben. Danach eine Meldung. */
add_regionlist(&route, rnext);
set_coast(sh, r, rnext);
sh = move_ship(sh, r, rnext, route);
move_ship(sh, r, rnext, route);
free_regionlist(route);
if (firstu != NULL) {
message *msg = msg_message("ship_drift", "ship dir", sh, dir);
msg_to_ship_inmates(sh, &firstu, &lastu, msg);
}
}
if (sh != NULL) {
fset(sh, SF_DRIFTED);
if (ovl >= overload_start()) {
damage_ship(sh, damage_overload(ovl));
msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("massive_overload", "ship", sh));
}
else {
damage_ship(sh, damage_drift);
}
if (sh->damage >= sh->size * DAMAGE_SCALE) {
msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("shipsink", "ship", sh));
sink_ship(sh);
remove_ship(shp, sh);
}
}
if (*shp == sh) {
else {
shp = &sh->next;
}
}
@ -1970,7 +1963,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting)
if (fval(u, UFL_FOLLOWING))
caught_target(current_point, u);
sh = move_ship(sh, starting_point, current_point, *routep);
move_ship(sh, starting_point, current_point, *routep);
/* Hafengebühren ? */

View File

@ -77,7 +77,7 @@ extern "C" {
bool canfly(struct unit *u);
void leave_trail(struct ship *sh, struct region *from,
struct region_list *route);
struct ship *move_ship(struct ship *sh, struct region *from,
void move_ship(struct ship *sh, struct region *from,
struct region *to, struct region_list *route);
int walkingcapacity(const struct unit *u);
int movement_speed(const struct unit * u);