LuaAI: added missing field from the attacks vector
This commit is contained in:
parent
6e737aa0e2
commit
0c238ef35c
2 changed files with 34 additions and 3 deletions
|
@ -264,11 +264,12 @@ function my_ai:stage_hello()
|
|||
local debug_utils = wesnoth.require "~add-ons/Wesnoth_Lua_Pack/debug_utils.lua"
|
||||
|
||||
local mm = ai.get_attacks()
|
||||
wesnoth.message(mm[2]:rating());
|
||||
wesnoth.message(mm[3]:rating());
|
||||
|
||||
|
||||
--wesnoth.message("type " .. type(mo))
|
||||
--debug_utils.dbms(dstsrc,false,"variable",false)
|
||||
--debug_utils.dbms(mm,false,"variable",false)
|
||||
debug_utils.dbms(mm[2].target,false,"variable",false)
|
||||
debug_utils.dbms(mm[2].movements,false,"variable",false)
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -528,6 +528,32 @@ static int cfun_attack_rating(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void push_movements(lua_State *L, const std::vector< std::pair < map_location, map_location > > & moves)
|
||||
{
|
||||
lua_createtable(L, moves.size(), 0);
|
||||
|
||||
int table_index = lua_gettop(L);
|
||||
|
||||
std::vector< std::pair < map_location, map_location > >::const_iterator move = moves.begin();
|
||||
|
||||
for (int i = 1; move != moves.end(); move++, i++)
|
||||
{
|
||||
lua_createtable(L, 2, 0); // Creating a table for a pair of map_location's
|
||||
|
||||
lua_pushstring(L, "first");
|
||||
push_map_location(L, move->first);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushstring(L, "second");
|
||||
push_map_location(L, move->second);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_rawseti(L, table_index, i); // setting the pair as an element of the movements table
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void push_attack_analysis(lua_State *L, attack_analysis& aa)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
@ -543,6 +569,10 @@ static void push_attack_analysis(lua_State *L, attack_analysis& aa)
|
|||
lua_pushcclosure(L, &cfun_attack_rating, 1);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushstring(L, "movements");
|
||||
push_movements(L, aa.movements);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushstring(L, "target");
|
||||
push_map_location(L, aa.target);
|
||||
lua_rawset(L, -3);
|
||||
|
|
Loading…
Add table
Reference in a new issue