Fixed an infinite loop bug
Fixed methods, that provided wrong objects to Lua
This commit is contained in:
parent
a7051503b8
commit
ecf23e8055
2 changed files with 35 additions and 18 deletions
|
@ -313,45 +313,54 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
|
|||
ai = ...
|
||||
-- local data = {} -- @note: this shouldn't be here
|
||||
|
||||
local my_ai = { data = { ["pers"] = 5, ["stringg"] = "stringg" } }
|
||||
|
||||
local my_ai = { }
|
||||
|
||||
-- data = { ["pers"] = 5, ["stringg"] = "stringg" }
|
||||
|
||||
local ai_stdlib = wesnoth.require('ai/lua/stdlib.lua');
|
||||
ai_stdlib.init(ai)
|
||||
|
||||
|
||||
function my_ai:stage_hello()
|
||||
--wesnoth.message('hello from stage!')
|
||||
wesnoth.message('hello from stage!')
|
||||
--wesnoth.message('PERSISTANCE: ' .. tostring(self.data["pers"]) .. self.data["stringg"])
|
||||
local tg = ai.get_targets()
|
||||
for k,v in pairs(tg) do
|
||||
if v.type==3 or v.type==4 then
|
||||
wesnoth.message(tg[k].type .. " " .. tg[k].value .. " " .. tg[k].loc.x .. " " ..tg[k].loc.y)
|
||||
end
|
||||
end
|
||||
|
||||
--local tg = ai.get_targets()
|
||||
--for k,v in pairs(tg) do
|
||||
-- if v.type==3 or v.type==4 then
|
||||
-- wesnoth.message(tg[k].type .. " " .. tg[k].value .. " " .. tg[k].loc.x .. " " ..tg[k].loc.y)
|
||||
-- end
|
||||
--end
|
||||
|
||||
end
|
||||
|
||||
function my_ai:candidate_action_evaluation_hello()
|
||||
--wesnoth.message('hello from candidate action evaluation!')
|
||||
wesnoth.message('hello from candidate action evaluation!')
|
||||
|
||||
return 42, {test=123}
|
||||
end
|
||||
|
||||
function my_ai:candidate_action_execution_hello(cfg)
|
||||
-- wesnoth.message('hello from candidate action execution!')
|
||||
wesnoth.message('hello from candidate action execution!')
|
||||
--wesnoth.message('test value is ') -- .. cfg.test) -- ERROR: cfg.test is nil here
|
||||
|
||||
self:do_moves()
|
||||
end
|
||||
|
||||
function my_ai:candidate_action_evaluation_hello2()
|
||||
--wesnoth.message('hello from second candidate action evaluation!')
|
||||
wesnoth.message('hello from second candidate action evaluation!')
|
||||
wesnoth.message("LuaDebug", "hello")
|
||||
local map = ai.get_enemy_dstsrc()
|
||||
wesnoth.message("LuaDebug", "hello " .. #map)
|
||||
for dst,src in pairs(map) do
|
||||
for k,v in pairs(src) do
|
||||
wesnoth.message("LuaDebug", dst.x .. "," .. dst.y .. " -> " .. v.x .. "," .. v.y)
|
||||
end
|
||||
end
|
||||
return 99
|
||||
end
|
||||
|
||||
function my_ai:candidate_action_execution_hello2()
|
||||
--wesnoth.message('hello from second candidate action execution!')
|
||||
wesnoth.message('hello from second candidate action execution!')
|
||||
self:do_moves()
|
||||
end
|
||||
|
||||
|
|
|
@ -502,13 +502,21 @@ static void push_map_location(lua_State *L, const map_location& ml)
|
|||
|
||||
static void push_move_map(lua_State *L, const move_map& m)
|
||||
{
|
||||
lua_createtable(L, 0, 0); // the main table
|
||||
|
||||
if (m.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
move_map::const_iterator it = m.begin();
|
||||
|
||||
int index = 1;
|
||||
|
||||
lua_createtable(L, 0, 0); // the main table
|
||||
|
||||
do {
|
||||
|
||||
do
|
||||
{
|
||||
map_location key = it->first;
|
||||
|
||||
push_map_location(L, key);
|
||||
|
@ -540,7 +548,7 @@ static int cfun_ai_get_dstsrc(lua_State *L)
|
|||
|
||||
static int cfun_ai_get_srcdst(lua_State *L)
|
||||
{
|
||||
move_map src_dst = get_readonly_context(L).get_dstsrc();
|
||||
move_map src_dst = get_readonly_context(L).get_srcdst();
|
||||
push_move_map(L, src_dst);
|
||||
return 1;
|
||||
}
|
||||
|
@ -554,7 +562,7 @@ static int cfun_ai_get_enemy_dstsrc(lua_State *L)
|
|||
|
||||
static int cfun_ai_get_enemy_srcdst(lua_State *L)
|
||||
{
|
||||
move_map enemy_src_dst = get_readonly_context(L).get_enemy_dstsrc();
|
||||
move_map enemy_src_dst = get_readonly_context(L).get_enemy_srcdst();
|
||||
push_move_map(L, enemy_src_dst);
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue