Moved [fire_event] to Lua.
This commit is contained in:
parent
38d1c25baa
commit
b72831642a
2 changed files with 19 additions and 41 deletions
|
@ -167,6 +167,24 @@ local function wml_store_unit_type(cfg)
|
|||
end
|
||||
end
|
||||
|
||||
local function wml_fire_event(cfg)
|
||||
local u1 = helper.get_child(cfg, "primary_unit")
|
||||
u1 = u1 and wesnoth.get_units(u1)[1]
|
||||
local x1, y1 = 0, 0
|
||||
if u1 then x1, y1 = u1.x, u1.y end
|
||||
|
||||
local u2 = helper.get_child(cfg, "secondary_unit")
|
||||
u2 = u2 and wesnoth.get_units(u2)[1]
|
||||
local x2, y2 = 0, 0
|
||||
if u2 then x2, y2 = u2.x, u2.y end
|
||||
|
||||
local w1 = helper.get_child(cfg, "primary_attack")
|
||||
local w2 = helper.get_child(cfg, "secondary_attack")
|
||||
if w2 then w1 = w1 or {} end
|
||||
|
||||
wesnoth.fire_event(cfg.name, x1, y1, x2, y2, w1, w2)
|
||||
end
|
||||
|
||||
local function wml_action_tag(cfg)
|
||||
-- The new tag's name
|
||||
local name = cfg.name or
|
||||
|
@ -191,4 +209,5 @@ wesnoth.register_wml_action("store_gold", wml_store_gold)
|
|||
wesnoth.register_wml_action("clear_variable", wml_clear_variable)
|
||||
wesnoth.register_wml_action("store_unit_type", wml_store_unit_type)
|
||||
wesnoth.register_wml_action("store_unit_type_ids", wml_store_unit_type_ids)
|
||||
wesnoth.register_wml_action("fire_event", wml_fire_event)
|
||||
wesnoth.register_wml_action("wml_action", wml_action_tag)
|
||||
|
|
|
@ -2036,47 +2036,6 @@ WML_HANDLER_FUNCTION(kill, event_info, cfg)
|
|||
}
|
||||
}
|
||||
|
||||
// Fire any events
|
||||
WML_HANDLER_FUNCTION(fire_event, /*event_info*/, cfg)
|
||||
{
|
||||
unit_map *units = resources::units;
|
||||
gamemap *game_map = resources::game_map;
|
||||
|
||||
map_location loc1,loc2;
|
||||
config data;
|
||||
if (cfg.has_child("primary_unit")) {
|
||||
vconfig primary_unit_filter = cfg.child("primary_unit");
|
||||
foreach (const unit &u, *units) {
|
||||
if (game_events::unit_matches_filter(u, primary_unit_filter)) {
|
||||
loc1 = u.get_location();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!game_map->on_board(loc1)) {
|
||||
WRN_NG << "failed to match [primary_unit] in [fire_event] with a single on-board unit\n";
|
||||
}
|
||||
}
|
||||
if (cfg.has_child("primary_attack")) {
|
||||
data.add_child("first", cfg.child("primary_attack").get_parsed_config());
|
||||
}
|
||||
if (cfg.has_child("secondary_unit")) {
|
||||
vconfig secondary_unit_filter = cfg.child("secondary_unit");
|
||||
foreach (const unit &u, *units) {
|
||||
if (game_events::unit_matches_filter(u, secondary_unit_filter)) {
|
||||
loc2 = u.get_location();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!game_map->on_board(loc2)) {
|
||||
WRN_NG << "failed to match [secondary_unit] in [fire_event] with a single on-board unit\n";
|
||||
}
|
||||
}
|
||||
if (cfg.has_child("secondary_attack")) {
|
||||
data.add_child("second", cfg.child("secondary_attack").get_parsed_config());
|
||||
}
|
||||
game_events::fire(cfg["name"],loc1,loc2,data);
|
||||
}
|
||||
|
||||
// Setting of menu items
|
||||
WML_HANDLER_FUNCTION(set_menu_item, /*event_info*/, cfg)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue