move "modify_ai" to the game lua kernel

This commit is contained in:
Chris Beck 2015-04-11 22:09:06 -04:00
parent e28a6bfcc6
commit a5d3c64d10
4 changed files with 22 additions and 10 deletions

View file

@ -1132,6 +1132,13 @@ function wml_actions.store_side(cfg)
end
end
-- This is the port of the old [modify_ai] into lua. It is different from wesnoth.modify_ai in that it uses a standard side filter.
-- I don't know why these functions were made to behave differently, but this seems to be the more powerful and useful one according
-- to mattsc's comments
function wml_actions.modify_ai(cfg)
wesnoth.modify_ai_wml(cfg)
end
function wml_actions.add_ai_behavior(cfg)
local unit = wesnoth.get_units(helper.get_child(cfg, "filter"))[1] or
helper.wml_error("[add_ai_behavior]: no unit specified")

View file

@ -704,16 +704,6 @@ WML_HANDLER_FUNCTION(message, event_info, cfg)
}
}
WML_HANDLER_FUNCTION(modify_ai, /*event_info*/, cfg)
{
side_filter ssf(cfg, resources::filter_con);
std::vector<int> sides = ssf.get_teams();
BOOST_FOREACH(const int &side_num, sides)
{
ai::manager::modify_active_ai_for_side(side_num,cfg.get_parsed_config());
}
}
WML_HANDLER_FUNCTION(modify_turns, /*event_info*/, cfg)
{
config::attribute_value value = cfg["value"];

View file

@ -2955,6 +2955,19 @@ int game_lua_kernel::intf_match_side(lua_State *L)
return 1;
}
int game_lua_kernel::intf_modify_ai_wml(lua_State *L)
{
vconfig cfg(luaW_checkvconfig(L, 1));
side_filter ssf(cfg, &game_state_);
std::vector<int> sides = ssf.get_teams();
BOOST_FOREACH(const int &side_num, sides)
{
ai::manager::modify_active_ai_for_side(side_num,cfg.get_parsed_config());
}
return 0;
}
int game_lua_kernel::intf_modify_side(lua_State *L)
{
vconfig cfg(luaW_checkvconfig(L, 1));
@ -4027,6 +4040,7 @@ game_lua_kernel::game_lua_kernel(const config &cfg, CVideo * video, game_state &
{ "match_side", &dispatch<&game_lua_kernel::intf_match_side > },
{ "match_unit", &dispatch<&game_lua_kernel::intf_match_unit > },
{ "message", &dispatch<&game_lua_kernel::intf_message > },
{ "modify_ai_wml", &dispatch<&game_lua_kernel::intf_modify_ai_wml > },
{ "modify_side", &dispatch<&game_lua_kernel::intf_modify_side > },
{ "open_help", &dispatch<&game_lua_kernel::intf_open_help > },
{ "play_sound", &dispatch<&game_lua_kernel::intf_play_sound > },

View file

@ -132,6 +132,7 @@ class game_lua_kernel : public lua_kernel_base
int intf_get_villages(lua_State *L);
int intf_match_location(lua_State *L);
int intf_match_side(lua_State *L);
int intf_modify_ai_wml(lua_State *L);
int intf_modify_side(lua_State *L);
int intf_get_sides(lua_State* L);
int intf_add_tile_overlay(lua_State *L);