Skip to content

Commit

Permalink
[modify_side][ai] with ai_algorithm now replaces the AI (fixes #1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed May 22, 2017
1 parent 80a87d0 commit 39dad27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 9 additions & 2 deletions data/lua/wml/modify_side.lua
Expand Up @@ -92,12 +92,19 @@ function wesnoth.wml_actions.modify_side(cfg)
if cfg.switch_ai then
wesnoth.switch_ai(side.side, cfg.switch_ai)
end
local ai = {}
local ai, replace_ai = {}, false
for next_ai in helper.child_range(cfg, "ai") do
table.insert(ai, T.ai(next_ai))
if next_ai.ai_algorithm then
replace_ai = true
end
end
if #ai > 0 then
wesnoth.append_ai(side.side, ai)
if replace_ai then
wesnoth.switch_ai(side.side, ai)
else
wesnoth.append_ai(side.side, ai)
end
end
end
for i,key in ipairs(side_changes_needing_redraw) do
Expand Down
14 changes: 9 additions & 5 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -2977,11 +2977,15 @@ static int intf_modify_ai(lua_State *L, const char* action)
static int intf_switch_ai(lua_State *L)
{
int side_num = luaL_checkinteger(L, 1);
std::string file = luaL_checkstring(L, 2);
if(!ai::manager::add_ai_for_side_from_file(side_num, file)) {
std::string err = formatter() << "Could not load AI for side " << side_num + 1 << " from file " << file;
lua_pushlstring(L, err.c_str(), err.length());
return lua_error(L);
if(lua_isstring(L, 2)) {
std::string file = luaL_checkstring(L, 2);
if(!ai::manager::add_ai_for_side_from_file(side_num, file)) {
std::string err = formatter() << "Could not load AI for side " << side_num << " from file " << file;
lua_pushlstring(L, err.c_str(), err.length());
return lua_error(L);
}
} else {
ai::manager::add_ai_for_side_from_config(side_num, luaW_checkconfig(L, 2));
}
return 0;
}
Expand Down

0 comments on commit 39dad27

Please sign in to comment.