diff --git a/scripts/tests/e2/ships.lua b/scripts/tests/e2/ships.lua index 202c74b6a..c9f3272ea 100644 --- a/scripts/tests/e2/ships.lua +++ b/scripts/tests/e2/ships.lua @@ -529,8 +529,6 @@ function test_ship_crew_stops_guarding() local sh = ship.create(r1, "longboat") u1.ship = sh u2.ship = sh - u1.name = 'Bolgrim' - u1.name = 'Bolle' u1:clear_orders() u1:add_order("NACH O W") u1:set_skill("sailing", 1) -- cptskill = 1 diff --git a/src/move.c b/src/move.c index e9bbea9a0..c33067098 100644 --- a/src/move.c +++ b/src/move.c @@ -624,9 +624,6 @@ mark_travelthru(unit * u, region * r, const region_list * route, void move_ship(ship * sh, region * from, region * to, region_list * route) { - unit **iunit = &from->units; - unit **ulist = &to->units; - assert(sh); if (from != to) { translist(&from->ships, &to->ships, sh); @@ -636,25 +633,38 @@ void move_ship(ship * sh, region * from, region * to, region_list * route) leave_trail(sh, from, route); } - while (*iunit != NULL) { - unit *u = *iunit; - assert(u->region == from); + if (route != NULL) { + unit** iunit = &from->units; + unit** ulist = &to->units; + unit* ufirst = NULL; - if (u->ship == sh) { - if (route != NULL) + do { + unit *u = *iunit; + + if (u->ship == sh) { + *iunit = u->next; + if (!ufirst) { + ufirst = u; + } mark_travelthru(u, from, route, NULL); - if (from != to) { - u->ship = 0; /* temporary trick -- do not use u_set_ship here */ + u->ship = NULL; /* temporary trick -- do not use u_set_ship here */ + leave_region(u); + u->region = NULL; + u->next = NULL; move_unit(u, to, ulist); ulist = &u->next; u->ship = sh; /* undo the trick -- do not use u_set_ship here */ + if (effskill(u, SK_SAILING, from) >= 1) { + produceexp(u, SK_SAILING, u->number); + } } - if (route && effskill(u, SK_SAILING, from) >= 1) { - produceexp(u, SK_SAILING, u->number); + else if (ufirst) { + break; } - } - if (*iunit == u) - iunit = &u->next; + else { + iunit = &u->next; + } + } while (*iunit && (ufirst == NULL || ufirst != *iunit)); } }