Skip to content

Commit

Permalink
Protect can_step_taken_wrt_to_zoc against null terrain
Browse files Browse the repository at this point in the history
Using can_step_taken_wrt_to_zoc in the path finding code (through
unit_can_move_to_tile) makes it possible that unseen tiles are passed to it. We
should therefore not assume that the terrain of the tile is known.

Closes longturn#1315.
  • Loading branch information
lmoureaux committed Aug 24, 2022
1 parent 687289b commit 52e3388
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions common/movement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,10 @@ bool can_step_taken_wrt_to_zoc(const struct unit_type *punittype,
if (tile_city(src_tile) || tile_city(dst_tile)) {
return true;
}
if (terrain_has_flag(tile_terrain(src_tile), TER_NO_ZOC)
|| terrain_has_flag(tile_terrain(dst_tile), TER_NO_ZOC)) {
const auto src_terrain = tile_terrain(src_tile);
const auto dst_terrain = tile_terrain(dst_tile);
if ((src_terrain && terrain_has_flag(src_terrain, TER_NO_ZOC))
|| (dst_terrain && terrain_has_flag(dst_terrain, TER_NO_ZOC))) {
return true;
}

Expand Down

0 comments on commit 52e3388

Please sign in to comment.