Skip to content

Commit

Permalink
Restore the optional replace_if_failed argument on set_terrain
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 17, 2021
1 parent 51abfbe commit 46a7a1f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/scripting/lua_terrainmap.cpp
Expand Up @@ -371,6 +371,7 @@ static int impl_terrainmap_set(lua_State *L)
* - Arg 1: map location.
* - Arg 2: terrain code string.
* - Arg 3: layer: (overlay|base|both, default=both)
* - Arg 4: replace_if_failed, default = no
*/
static int intf_set_terrain(lua_State *L)
{
Expand All @@ -380,6 +381,7 @@ static int intf_set_terrain(lua_State *L)

auto terrain = t_translation::read_terrain_code(t_str);
auto mode = terrain_type_data::BOTH;
bool replace_if_failed = false;

if(!lua_isnoneornil(L, 4)) {
string_view mode_str = luaL_checkstring(L, 4);
Expand All @@ -389,11 +391,15 @@ static int intf_set_terrain(lua_State *L)
else if(mode_str == "overlay") {
mode = terrain_type_data::OVERLAY;
}

if(!lua_isnoneornil(L, 5)) {
replace_if_failed = luaW_toboolean(L, 5);
}
}

if(auto gm = dynamic_cast<gamemap*>(&tm)) {
if(resources::gameboard) {
bool result = resources::gameboard->change_terrain(loc, terrain, mode, true);
bool result = resources::gameboard->change_terrain(loc, terrain, mode, replace_if_failed);

for(team& t : resources::gameboard->teams()) {
t.fix_villages(*gm);
Expand Down

0 comments on commit 46a7a1f

Please sign in to comment.