Fix some [modify_ai] isses (addresses GNA25558)

As far as I can tell, the most likely cause of the bug was that several
cases of [modify_ai]action=add were called with a path that lacked the final
empty braces at the end of the path.

This commit makes both the tag and the underlying Lua API calls explicitly
handle this case as if the final empty braces were, in fact, present.
This commit is contained in:
Celtic Minstrel 2017-03-10 00:08:20 -05:00
parent 0702fe32a3
commit 6de1c9441f
2 changed files with 6 additions and 3 deletions

View File

@ -741,7 +741,7 @@ function wml_actions.modify_ai(cfg)
local component, final
if cfg.action == "add" or cfg.action == "change" then
local start = string.find(cfg.path, "[a-z_]+%[[a-z0-9_*]*%]$")
final = string.find(cfg.path, '[', start, true) - 1
final = start and (string.find(cfg.path, '[', start, true) - 1) or -1
local comp_type = string.sub(cfg.path, start, final)
component = helper.get_child(cfg, comp_type)
if component == nil then

View File

@ -2883,9 +2883,12 @@ static int intf_modify_ai(lua_State *L, const char* action)
return 0;
}
config component = luaW_checkconfig(L, 3);
size_t open_brak = path.find_last_of('[');
size_t len = std::string::npos, open_brak = path.find_last_of('[');
size_t dot = path.find_last_of('.');
cfg.add_child(path.substr(dot + 1, open_brak - dot - 1), component);
if(open_brak != len) {
len = open_brak = dot - 1;
}
cfg.add_child(path.substr(dot + 1, len), component);
ai::manager::modify_active_ai_for_side(side_num, cfg);
return 0;
}