Skip to content

Commit

Permalink
Merge pull request #563 from ln-zookeeper/unit_placed_event
Browse files Browse the repository at this point in the history
Added event type "unit placed"
  • Loading branch information
ln-zookeeper committed Jan 12, 2016
2 parents cf8ff90 + 956e86f commit 80691e5
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog
Expand Up @@ -4,6 +4,9 @@ Version 1.13.2+dev:
* Updated sprites for Naga Hunter and Naga Guardian line.
* Language and i18n:
* Updated translations: British English, Russian, Swedish
* WML engine:
* Added new event "unit placed", which triggers when (and regardless of how)
a unit appears on the map.
* Miscellaneous and bug fixes:
* Fix the new log code on Windows to actually use Unicode-aware functions
in a couple of places so Wesnoth does not quit on startup when trying to
Expand Down
4 changes: 4 additions & 0 deletions src/actions/attack.cpp
Expand Up @@ -1160,6 +1160,10 @@ namespace {
newunit.heal_all();
}
units_.add(death_loc, newunit);

game_events::entity_location reanim_loc(defender.loc_, newunit.underlying_id());
resources::game_events->pump().fire("unit placed", reanim_loc);

preferences::encountered_units().insert(newunit.type_id());
if (update_display_) {
resources::screen->invalidate(death_loc);
Expand Down
2 changes: 2 additions & 0 deletions src/actions/create.cpp
Expand Up @@ -641,6 +641,8 @@ place_recruit_result place_recruit(const unit &u, const map_location &recruit_lo
recruit_checksums(new_unit, wml_triggered);
resources::whiteboard->on_gamestate_change();

resources::game_events->pump().fire("unit placed", current_loc);

if ( fire_event ) {
const std::string event_name = is_recall ? "prerecall" : "prerecruit";
LOG_NG << "firing " << event_name << " event\n";
Expand Down
4 changes: 4 additions & 0 deletions src/actions/unit_creator.cpp
Expand Up @@ -24,6 +24,8 @@
#include "../config.hpp"
#include "../filter_context.hpp"
#include "../game_board.hpp"
#include "../game_events/manager.hpp"
#include "../game_events/pump.hpp"
#include "../game_preferences.hpp"
#include "../game_data.hpp" // for resources::gamedata conversion variable_set
#include "../gettext.hpp"
Expand Down Expand Up @@ -215,6 +217,8 @@ void unit_creator::post_create(const map_location &loc, const unit &new_unit, bo
}
}

resources::game_events->pump().fire("unit placed", loc);

if (resources::screen!=NULL) {

if (invalidate_ ) {
Expand Down
2 changes: 2 additions & 0 deletions src/game_events/action_wml.cpp
Expand Up @@ -1335,6 +1335,8 @@ WML_HANDLER_FUNCTION(unstore_unit, /*event_info*/, cfg)
resources::units->erase(loc);
resources::units->add(loc, *u);

resources::game_events->pump().fire("unit placed", loc);

config::attribute_value text = var["gender"].str() == "female" ? cfg["female_text"] : cfg["male_text"];
if(text.blank()) {
text = cfg["text"];
Expand Down
7 changes: 7 additions & 0 deletions src/play_controller.cpp
Expand Up @@ -373,6 +373,13 @@ void play_controller::fire_prestart()
// as those may cause the display to be refreshed.
update_locker lock_display(gui_->video());
gamestate().gamedata_.set_phase(game_data::PRESTART);

// Fire these right before prestart events, to catch only the units sides
// have started with.
BOOST_FOREACH(const unit& u, gamestate().board_.units()) {
pump().fire("unit placed", map_location(u.get_location()));
}

pump().fire("prestart");
// prestart event may modify start turn with WML, reflect any changes.
gamestate().gamedata_.get_variable("turn_number") = int(turn());
Expand Down
2 changes: 2 additions & 0 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -2357,6 +2357,8 @@ int game_lua_kernel::intf_put_unit(lua_State *L)
units().insert(u);
}

play_controller_.pump().fire("unit placed", loc);

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/synced_commands.cpp
Expand Up @@ -476,6 +476,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_create_unit, child, use_undo, /*show*/, e
// Add the unit to the board.
std::pair<unit_map::iterator, bool> add_result = resources::units->replace(loc, created);
resources::screen->invalidate_unit();
resources::game_events->pump().fire("unit placed", loc);
unit_display::unit_recruited(loc);

// Village capture?
Expand Down

0 comments on commit 80691e5

Please sign in to comment.