diff --git a/src/menu_events.cpp b/src/menu_events.cpp index 6b247b8746f7..ec98d84fc641 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -1082,30 +1082,11 @@ namespace { // Helpers for create_unit() * Creates a unit and places it on the board. * (Intended for use with any units created via debug mode.) */ - void create_and_place(game_display& gui, const gamemap & map, unit_map & units, + void create_and_place(game_display& , const gamemap & , unit_map & , const map_location & loc, const unit_type & u_type, unit_race::GENDER gender = unit_race::NUM_GENDERS) { - // Create the unit. - unit created(u_type, 1, true, gender); - created.new_turn(); - - // Add the unit to the board. - std::pair add_result = - units.replace(loc, created); - gui.invalidate_unit(); - unit_display::unit_recruited(loc); - - // Village capture? - if ( map.is_village(loc) ) - actions::get_village(loc, created.side()); - - // Update fog/shroud. - actions::shroud_clearer clearer; - clearer.clear_unit(loc, created); - clearer.fire_events(); - if ( add_result.first.valid() ) // In case sighted events messed with the unit. - actions::actor_sighted(*add_result.first); + synced_context::run_and_throw("debug_create_unit", config_of("x", loc.x + 1)("y", loc.y + 1)("type", u_type.id())("gender", gender_string(gender))); } }// Anonymous namespace diff --git a/src/synced_commands.cpp b/src/synced_commands.cpp index 43c2e18f7d80..01ec73d64b41 100644 --- a/src/synced_commands.cpp +++ b/src/synced_commands.cpp @@ -36,6 +36,8 @@ #include "resources.hpp" #include "scripting/game_lua_kernel.hpp" #include "formula_string_utils.hpp" +#include "unit_types.hpp" +#include "unit_display.hpp" #include @@ -442,3 +444,41 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_unit, child, use_undo, /*show*/, error_ha return true; } +SYNCED_COMMAND_HANDLER_FUNCTION(debug_create_unit, child, use_undo, /*show*/, error_handler) +{ + if(use_undo) { + resources::undo_stack->clear(); + } + + utils::string_map symbols; + symbols["player"] = resources::controller->current_team().current_player(); + resources::screen->announce(vgettext("A unit was created using debug command during turn of $player", symbols), font::NORMAL_COLOR); + map_location loc(child); + const unit_race::GENDER gender = string_gender(child["gender"], unit_race::NUM_GENDERS); + const unit_type *u_type = unit_types.find(child["type"]); + if (!u_type) { + error_handler("Invalid unit type", true); + return false; + } + // Create the unit. + unit created(*u_type, 1, true, gender); + created.new_turn(); + + // Add the unit to the board. + std::pair add_result = resources::units->replace(loc, created); + resources::screen->invalidate_unit(); + unit_display::unit_recruited(loc); + + // Village capture? + if ( resources::gameboard->map().is_village(loc) ) + actions::get_village(loc, created.side()); + + // Update fog/shroud. + actions::shroud_clearer clearer; + clearer.clear_unit(loc, created); + clearer.fire_events(); + if ( add_result.first.valid() ) // In case sighted events messed with the unit. + actions::actor_sighted(*add_result.first); + + return true; +}