Skip to content

Commit

Permalink
Force units to load after unloading to a sea tile
Browse files Browse the repository at this point in the history
Say we have two transports A and B next to the coast C, with a land
unit in A. Consider the following orders for the land unit:

1. Unload from A to B->tile
2. Move from B->tile to C

This sequence should not succeed because the unit should still be loaded
after the first step. However, in practice the unit was not loaded after
step 1, resulting in an invalid state that confused ORDER_MOVED. Do the
same when bumping units after a transport is killed.

The fix to that is obviously to load the unit after step 1. There is a
catch though: this is (and has always been) done without considering
action enablers. It might be possible to exploit this to bypass loading
rules.

Spotted by mu in LT78.
  • Loading branch information
lmoureaux committed Aug 30, 2023
1 parent f105cd4 commit 0cab365
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/unithand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ static bool do_disembark(struct player *act_player, struct unit *act_unit,
fc_assert_ret_val(tgt_tile, false);
fc_assert_ret_val(paction, false);

unit_move(act_unit, tgt_tile, move_cost, nullptr, false, false);
unit_move(act_unit, tgt_tile, move_cost, nullptr, true, false);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion server/unittools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet)
/* FIXME: Shouldn't unit_move_handling() be used here? This is
* the unit escaping by moving itself. It should therefore
* respect movement rules. */
unit_move(vunit, dsttile, move_cost, nullptr, false, false);
unit_move(vunit, dsttile, move_cost, nullptr, true, false);
num_escaped[player_index(vplayer)]++;
escaped = true;
unitcount--;
Expand Down

0 comments on commit 0cab365

Please sign in to comment.