From e4c170f2490ffee3fd5bb6bd9ab3f82748e5f164 Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Mon, 13 Aug 2018 02:22:40 +0200 Subject: [PATCH] fix villages after terrain_mask (cherry-picked from commit 6cd9de1202d1f4f90d56ba9b7950aecfc1e5f3f4) --- src/scripting/game_lua_kernel.cpp | 6 +++++- src/team.cpp | 12 ++++++++++++ src/team.hpp | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index d3dffdc81f4c..3526a7967d64 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -1110,10 +1110,14 @@ int game_lua_kernel::intf_terrain_mask(lua_State *L) } - gamemap mask_map(resources::gameboard->map().tdata(), ""); + gamemap mask_map(board().map().tdata(), ""); mask_map.read(t_str, false); board().map_->overlay(mask_map, loc, rules, is_odd, ignore_special_locations); + for(team& t : board().teams()) { + t.fix_villages(board().map()); + } + if (game_display_) { game_display_->needs_rebuild(true); } diff --git a/src/team.cpp b/src/team.cpp index c5491d7c7b73..f38b4e1d1475 100644 --- a/src/team.cpp +++ b/src/team.cpp @@ -422,6 +422,18 @@ void team::write(config& cfg) const cfg["action_bonus_count"] = action_bonus_count_; } +void team::fix_villages(const gamemap &map) +{ + for (auto it = villages_.begin(); it != villages_.end(); ) { + if (map.is_village(*it)) { + ++it; + } + else { + it = villages_.erase(it); + } + } +} + game_events::pump_result_t team::get_village(const map_location& loc, const int owner_side, game_data* gamedata) { villages_.insert(loc); diff --git a/src/team.hpp b/src/team.hpp index c1273f401c0c..caaf97009354 100644 --- a/src/team.hpp +++ b/src/team.hpp @@ -177,6 +177,7 @@ class team void write(config& cfg) const; + void fix_villages(const gamemap &map); game_events::pump_result_t get_village(const map_location&, const int owner_side, game_data * fire_event); //!< Acquires a village from owner_side. Pointer fire_event should be the game_data for the game if it is desired to fire an event -- a "capture" event with owner_side variable scoped in will be fired. For no event, pass it nullptr. Default is the resources::gamedata pointer void lose_village(const map_location&); void clear_villages() { villages_.clear(); }