Skip to content

Commit

Permalink
bug 2710 ships moving in circles break guard
Browse files Browse the repository at this point in the history
  • Loading branch information
ennorehling committed Dec 6, 2020
1 parent fe463a9 commit e4e06df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
2 changes: 0 additions & 2 deletions scripts/tests/e2/ships.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 25 additions & 15 deletions src/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
}
}

Expand Down

0 comments on commit e4e06df

Please sign in to comment.