Skip to content

Commit

Permalink
Make map.set_terrain actually work in the game
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 15, 2021
1 parent a3be2df commit 48cb020
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/game_board.cpp
Expand Up @@ -337,7 +337,11 @@ bool game_board::change_terrain(
} else if(mode_str == "overlay") {
mode = terrain_type_data::OVERLAY;
}

return change_terrain(loc, terrain, mode, replace_if_failed);
}

bool game_board::change_terrain(const map_location &loc, const t_translation::terrain_code &terrain, terrain_type_data::merge_mode& mode, bool replace_if_failed) {
/*
* When a hex changes from a village terrain to a non-village terrain, and
* a team owned that village it loses that village. When a hex changes from
Expand Down
6 changes: 4 additions & 2 deletions src/game_board.hpp
Expand Up @@ -16,6 +16,8 @@

#include "display_context.hpp"
#include "team.hpp"
#include "terrain/translation.hpp"
#include "terrain/type_data.hpp"
#include "units/map.hpp"
#include "units/id.hpp"
#include <optional>
Expand Down Expand Up @@ -157,8 +159,8 @@ class game_board : public display_context
bool try_add_unit_to_recall_list(const map_location& loc, const unit_ptr u);
std::optional<std::string> replace_map(const gamemap & r);

bool change_terrain(const map_location &loc, const std::string &t,
const std::string & mode, bool replace_if_failed); //used only by lua and debug commands
bool change_terrain(const map_location &loc, const std::string &t, const std::string & mode, bool replace_if_failed); //used only by lua and debug commands
bool change_terrain(const map_location &loc, const t_translation::terrain_code &t, terrain_type_data::merge_mode& mode, bool replace_if_failed); //used only by lua and debug commands

// Global accessor from unit.hpp

Expand Down
20 changes: 18 additions & 2 deletions src/scripting/lua_terrainmap.cpp
Expand Up @@ -259,7 +259,15 @@ static void impl_merge_terrain(lua_State* L, int idx, gamemap_base& map, map_loc
auto ter = t_translation::read_terrain_code(t_str);
if(ter.base == t_translation::NO_LAYER && ter.overlay != t_translation::NO_LAYER)
mode = terrain_type_data::OVERLAY;
map.set_terrain(loc, ter, mode);
if(auto gm = dynamic_cast<gamemap*>(&map)) {
if(resources::gameboard) {
bool result = resources::gameboard->change_terrain(loc, ter, mode, true);

if(resources::controller) {
resources::controller->get_display().needs_rebuild(result);
}
}
} else map.set_terrain(loc, ter, mode);
}

static int impl_terrainmap_colget(lua_State* L)
Expand Down Expand Up @@ -375,7 +383,15 @@ static int intf_set_terrain(lua_State *L)
}
}

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

if(resources::controller) {
resources::controller->get_display().needs_rebuild(result);
}
}
} else tm.set_terrain(loc, terrain, mode);
return 0;
}

Expand Down

0 comments on commit 48cb020

Please sign in to comment.