diff --git a/src/editor/map/context_manager.cpp b/src/editor/map/context_manager.cpp index f682c8f88b8c..1e8aa125b201 100644 --- a/src/editor/map/context_manager.cpp +++ b/src/editor/map/context_manager.cpp @@ -718,7 +718,7 @@ void context_manager::generate_map_dialog() if(map_string.empty()) { gui2::show_transient_message("", _("Map creation failed.")); } else { - editor_map new_map(game_config_, map_string); + editor_map new_map(map_string); editor_action_whole_map a(new_map); get_map_context().set_needs_labels_reset(); // Ensure Player Start labels are updated together with newly generated map perform_refresh(a); @@ -951,7 +951,7 @@ void context_manager::revert_map() void context_manager::new_map(int width, int height, const t_translation::terrain_code& fill, bool new_context) { const config& default_schedule = game_config_.find_child("editor_times", "id", "empty"); - editor_map m(game_config_, width, height, fill); + editor_map m(width, height, fill); if(new_context) { int new_id = add_map_context(m, true, default_schedule); @@ -964,7 +964,7 @@ void context_manager::new_map(int width, int height, const t_translation::terrai void context_manager::new_scenario(int width, int height, const t_translation::terrain_code& fill, bool new_context) { const config& default_schedule = game_config_.find_child("editor_times", "id", "empty"); - editor_map m(game_config_, width, height, fill); + editor_map m(width, height, fill); if(new_context) { int new_id = add_map_context(m, false, default_schedule); @@ -1017,7 +1017,7 @@ void context_manager::create_default_context() t_translation::read_terrain_code(game_config::default_terrain); const config& default_schedule = game_config_.find_child("editor_times", "id", "empty"); - add_map_context(editor_map(game_config_, 44, 33, default_terrain), true, default_schedule); + add_map_context(editor_map(44, 33, default_terrain), true, default_schedule); } else { for(const std::string& filename : saved_windows_) { add_map_context(game_config_, filename); diff --git a/src/editor/map/editor_map.cpp b/src/editor/map/editor_map.cpp index de27de618cf4..4c5643c4b2e2 100644 --- a/src/editor/map/editor_map.cpp +++ b/src/editor/map/editor_map.cpp @@ -39,23 +39,23 @@ editor_map_load_exception wrap_exc(const char* type, const std::string& e_msg, c return editor_map_load_exception(filename, msg); } -editor_map::editor_map(const game_config_view& terrain_cfg) - : gamemap(std::make_shared(terrain_cfg), "") +editor_map::editor_map() + : gamemap("") , selection_() { } -editor_map::editor_map(const game_config_view& terrain_cfg, const std::string& data) - : gamemap(std::make_shared(terrain_cfg), data) +editor_map::editor_map(const std::string& data) + : gamemap(data) , selection_() { sanity_check(); } -editor_map editor_map::from_string(const game_config_view& terrain_cfg, const std::string& data) +editor_map editor_map::from_string(const std::string& data) { try { - return editor_map(terrain_cfg, data); + return editor_map(data); } catch (const incorrect_map_format_error& e) { throw wrap_exc("format", e.message, ""); } catch (const wml_exception& e) { @@ -65,8 +65,8 @@ editor_map editor_map::from_string(const game_config_view& terrain_cfg, const s } } -editor_map::editor_map(const game_config_view& terrain_cfg, std::size_t width, std::size_t height, const t_translation::terrain_code & filler) - : gamemap(std::make_shared(terrain_cfg), t_translation::write_game_map(t_translation::ter_map(width + 2, height + 2, filler))) +editor_map::editor_map(std::size_t width, std::size_t height, const t_translation::terrain_code & filler) + : gamemap(t_translation::write_game_map(t_translation::ter_map(width + 2, height + 2, filler))) , selection_() { sanity_check(); diff --git a/src/editor/map/editor_map.hpp b/src/editor/map/editor_map.hpp index 3f9a31fd6eac..8f827a5c8267 100644 --- a/src/editor/map/editor_map.hpp +++ b/src/editor/map/editor_map.hpp @@ -69,27 +69,26 @@ editor_map_load_exception wrap_exc(const char* type, const std::string& e_msg, c class editor_map : public gamemap { public: - /** * Empty map constructor */ - explicit editor_map(const game_config_view& terrain_cfg); + editor_map(); /** * Create an editor map from a map data string */ - editor_map(const game_config_view& terrain_cfg, const std::string& data); + editor_map(const std::string& data); /** * Wrapper around editor_map(cfg, data) that catches possible exceptions * and wraps them in a editor_map_load_exception */ - static editor_map from_string(const game_config_view& terrain_cfg, const std::string& data); + static editor_map from_string(const std::string& data); /** * Create an editor map with the given dimensions and filler terrain */ - editor_map(const game_config_view& terrain_cfg, std::size_t width, std::size_t height, const t_translation::terrain_code & filler); + editor_map(std::size_t width, std::size_t height, const t_translation::terrain_code & filler); /** * Create an editor_map by upgrading an existing gamemap. The map data is diff --git a/src/editor/map/map_context.cpp b/src/editor/map/map_context.cpp index a4dc7eb12109..e281dde2084e 100644 --- a/src/editor/map/map_context.cpp +++ b/src/editor/map/map_context.cpp @@ -91,7 +91,7 @@ map_context::map_context(const game_config_view& game_config, const std::string& , map_data_key_() , embedded_(false) , pure_map_(false) - , map_(game_config) + , map_() , undo_stack_() , redo_stack_() , actions_since_save_(0) @@ -161,7 +161,7 @@ map_context::map_context(const game_config_view& game_config, const std::string& if(!boost::regex_search( file_string, matched_map_data, rexpression_map_data, boost::regex_constants::match_not_dot_null) ) { - map_ = editor_map::from_string(game_config, file_string); // throws on error + map_ = editor_map::from_string(file_string); // throws on error pure_map_ = true; add_to_recent_files(); @@ -191,7 +191,7 @@ map_context::map_context(const game_config_view& game_config, const std::string& LOG_ED << "Loading embedded map file" << std::endl; embedded_ = true; pure_map_ = true; - map_ = editor_map::from_string(game_config, map_data); + map_ = editor_map::from_string(map_data); } add_to_recent_files(); @@ -216,7 +216,7 @@ map_context::map_context(const game_config_view& game_config, const std::string& filename_ = new_filename; file_string = filesystem::read_file(filename_); - map_ = editor_map::from_string(game_config, file_string); + map_ = editor_map::from_string(file_string); pure_map_ = true; add_to_recent_files(); @@ -334,7 +334,7 @@ void map_context::load_scenario(const game_config_view& game_config) victory_defeated_ = scenario["victory_when_enemies_defeated"].to_bool(true); random_time_ = scenario["random_start_time"].to_bool(false); - map_ = editor_map::from_string(game_config, scenario["map_data"]); // throws on error + map_ = editor_map::from_string(scenario["map_data"]); // throws on error labels_.read(scenario); diff --git a/src/game_board.cpp b/src/game_board.cpp index f7e37051f923..20ea59e7fcda 100644 --- a/src/game_board.cpp +++ b/src/game_board.cpp @@ -14,7 +14,6 @@ #include "config.hpp" #include "game_board.hpp" -#include "game_config_manager.hpp" #include "preferences/game.hpp" #include "log.hpp" #include "map/map.hpp" @@ -36,7 +35,7 @@ static lg::log_domain log_engine_enemies("engine/enemies"); game_board::game_board(const config& level) : teams_() - , map_(new gamemap(game_config_manager::get()->terrain_types(), level["map_data"])) + , map_(std::make_unique(level["map_data"])) , unit_id_manager_(level["next_underlying_unit_id"]) , units_() { @@ -47,7 +46,9 @@ game_board::game_board(const game_board & other) , labels_(other.labels_) , map_(new gamemap(*(other.map_))) , unit_id_manager_(other.unit_id_manager_) - , units_(other.units_) {} + , units_(other.units_) +{ +} game_board::~game_board() {} diff --git a/src/game_initialization/create_engine.cpp b/src/game_initialization/create_engine.cpp index f880343b251c..dff8a12b06e9 100644 --- a/src/game_initialization/create_engine.cpp +++ b/src/game_initialization/create_engine.cpp @@ -67,8 +67,7 @@ void scenario::set_metadata() const std::string& map_data = data_["map_data"]; try { - map_.reset(new gamemap(game_config_manager::get()->terrain_types(), - map_data)); + map_.reset(new gamemap(map_data)); } catch(const incorrect_map_format_error& e) { data_["description"] = _("Map could not be loaded: ") + e.message; @@ -658,7 +657,7 @@ void create_engine::init_all_levels() bool add_map = true; std::unique_ptr map; try { - map.reset(new gamemap(game_config_manager::get()->terrain_types(), user_map_data["map_data"])); + map.reset(new gamemap(user_map_data["map_data"])); } catch (const incorrect_map_format_error& e) { user_map_data["description"] = _("Map could not be loaded: ") + e.message; diff --git a/src/game_initialization/lobby_data.cpp b/src/game_initialization/lobby_data.cpp index b9cd719a2ab4..facd9bdb5d90 100644 --- a/src/game_initialization/lobby_data.cpp +++ b/src/game_initialization/lobby_data.cpp @@ -32,7 +32,6 @@ #include "mp_game_settings.hpp" #include "preferences/credentials.hpp" #include "preferences/game.hpp" -#include "terrain/type_data.hpp" #include "wml_exception.hpp" #include @@ -297,7 +296,7 @@ game_info::game_info(const config& game, const std::vector& install info_stream << " — ??×??"; } else { try { - gamemap map(std::make_shared(game_config), map_data); + gamemap map(map_data); std::ostringstream msi; msi << map.w() << font::unicode_multiplication_sign << map.h(); map_size_info = msi.str(); diff --git a/src/gui/widgets/minimap.cpp b/src/gui/widgets/minimap.cpp index 088301e7477d..2fd51a0141c7 100644 --- a/src/gui/widgets/minimap.cpp +++ b/src/gui/widgets/minimap.cpp @@ -210,7 +210,7 @@ const surface minimap::get_image(const int w, const int h) const try { - const gamemap map(std::make_shared(*terrain_), map_data_); + const gamemap map(map_data_); const surface surf = image::getMinimap(w, h, map, nullptr, nullptr, true); cache.emplace(key, value_type(surf)); #ifdef DEBUG_MINIMAP_CACHE diff --git a/src/map/map.cpp b/src/map/map.cpp index 85f47798271f..92b9213e0641 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -21,6 +21,7 @@ #include "config.hpp" #include "formula/string_utils.hpp" +#include "game_config_manager.hpp" #include "log.hpp" #include "map/exception.hpp" #include "serialization/parser.hpp" @@ -100,15 +101,21 @@ void gamemap::write_terrain(const map_location &loc, config& cfg) const cfg["terrain"] = t_translation::write_terrain_code(get_terrain(loc)); } -gamemap::gamemap(const std::shared_ptr& tdata, const std::string& data) +gamemap::gamemap(const std::string& data) : tiles_(1, 1) - , tdata_(tdata) + , tdata_() , villages_() , w_(-1) , h_(-1) { - DBG_G << "loading map: '" << data << "'\n"; + if(const auto* gcm = game_config_manager::get()) { + tdata_ = gcm->terrain_types(); + } else { + // Should only be encountered in unit tests + tdata_ = std::make_shared(game_config_view::wrap({})); + } + DBG_G << "loading map: '" << data << "'\n"; read(data); } diff --git a/src/map/map.hpp b/src/map/map.hpp index e43b807e61c6..8d1af75ef59b 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -68,15 +68,14 @@ class gamemap const std::shared_ptr& tdata() const { return tdata_; } /** - * Loads a map, with the given terrain configuration. + * Loads a map. * * Data should be a series of lines, with each character representing one * hex on the map. Starting locations are represented by numbers. * - * @param tdata the terrain data * @param data the map data to load. */ - gamemap(const std::shared_ptr& tdata, const std::string& data); // throw(incorrect_map_format_error) + gamemap(const std::string& data); // throw(incorrect_map_format_error) virtual ~gamemap(); diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index 61a64bc4663f..68c0f0a76450 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -1069,7 +1069,7 @@ int game_lua_kernel::intf_terrain_mask(lua_State *L) } - gamemap mask_map(board().map().tdata(), ""); + gamemap mask_map(""); mask_map.read(t_str, false); board().map_->overlay(mask_map, loc, rules, is_odd, ignore_special_locations);