Added tag [kill][secondary_unit] for specifying the killing unit.

(patch #1960)
This commit is contained in:
Anonymissimus 2010-09-13 16:32:13 +00:00
parent 7f8dc5e83d
commit 33fceff06b
2 changed files with 25 additions and 2 deletions

View file

@ -102,6 +102,7 @@ Version 1.9.0+svn:
* Added cost display for planned recruits and recalls
* Fixed bug #16554 : Infinite attacks with the whiteboard
* WML Engine:
* Added tag [kill][secondary_unit] for specifying the killing unit.
* Added a LOW_MEM define to WML to be able to adapt WML to low memory
builds.
* Added event: side turn X

View file

@ -1857,6 +1857,25 @@ typedef boost::scoped_ptr<recursion_preventer> recursion_preventer_ptr;
WML_HANDLER_FUNCTION(kill, event_info, cfg)
{
bool secondary_unit = cfg.has_child("secondary_unit");
game_events::entity_location killer_loc(map_location(0, 0));
if(cfg["fire_event"].to_bool() && secondary_unit)
{
secondary_unit = false;
for(unit_map::const_unit_iterator unit = resources::units->begin();
unit != resources::units->end(); ++unit) {
if(game_events::unit_matches_filter(*unit, cfg.child("secondary_unit")))
{
killer_loc = game_events::entity_location(*unit);
secondary_unit = true;
break;
}
}
if(!secondary_unit) {
WRN_NG << "failed to match [secondary_unit] in [kill] with a single on-board unit\n";
}
}
// Use (x,y) iteration, because firing events ruins unit_map iteration
for (map_location loc(0,0); loc.x < resources::game_map->w(); ++loc.x)
{
@ -1867,6 +1886,9 @@ WML_HANDLER_FUNCTION(kill, event_info, cfg)
{
bool fire_event = false;
game_events::entity_location death_loc(*un);
if(!secondary_unit) {
killer_loc = game_events::entity_location(*un);
}
if (cfg["fire_event"].to_bool())
{
// Prevent infinite recursion of 'die' events
@ -1886,7 +1908,7 @@ WML_HANDLER_FUNCTION(kill, event_info, cfg)
}
}
if (fire_event) {
game_events::fire("last breath", death_loc, death_loc);
game_events::fire("last breath", death_loc, killer_loc);
}
if (cfg["animate"].to_bool()) {
resources::screen->scroll_to_tile(loc);
@ -1896,7 +1918,7 @@ WML_HANDLER_FUNCTION(kill, event_info, cfg)
}
if (fire_event)
{
game_events::fire("die", death_loc, death_loc);
game_events::fire("die", death_loc, killer_loc);
un = resources::units->find(death_loc);
if (un != resources::units->end() && death_loc.matches_unit(*un)) {
resources::units->erase(un);