Skip to content

Commit

Permalink
sync create unit debug command
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Jun 7, 2015
1 parent b7d6cc9 commit b9bbbde
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/menu_events.cpp
Expand Up @@ -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<unit_map::iterator, bool> 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
Expand Down
40 changes: 40 additions & 0 deletions src/synced_commands.cpp
Expand Up @@ -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 <boost/foreach.hpp>

Expand Down Expand Up @@ -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<unit_map::iterator, bool> 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;
}

0 comments on commit b9bbbde

Please sign in to comment.