Persistant data storage now is local to the lua_ai_context
This commit is contained in:
parent
1974901deb
commit
de07362204
2 changed files with 16 additions and 20 deletions
|
@ -105,10 +105,7 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
|
|||
patrol_eval_rark = ptrl.eval
|
||||
-- End of patrol function // patrol_gen(ai, "Rark", {{x=14, y=7}, {x=15, y=7}, {x=15, y=8}, {x=14, y=8}})
|
||||
|
||||
function persistance_check()
|
||||
ai.data["pers"] = 182 -- we just set a variable to some value
|
||||
ai.data["stringg"] = " = it works"
|
||||
end
|
||||
|
||||
>>
|
||||
[/lua]
|
||||
[/event]
|
||||
|
@ -164,14 +161,6 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
|
|||
{MODIFY_AI_DELETE_CANDIDATE_ACTION 2 ca_loop firstca}
|
||||
[/event]
|
||||
|
||||
[event]
|
||||
name=side 2 turn 2
|
||||
first_time_only=yes
|
||||
[lua]
|
||||
code = << persistance_check() >>
|
||||
[/lua]
|
||||
[/event]
|
||||
|
||||
[side]
|
||||
type=Dwarvish Steelclad
|
||||
id=side_1_leader
|
||||
|
@ -303,9 +292,9 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
|
|||
code= <<
|
||||
--! ==============================================================
|
||||
ai = ...
|
||||
ai.data = {} -- @note: this shouldn't be here
|
||||
-- local data = {} -- @note: this shouldn't be here
|
||||
|
||||
local my_ai = { }
|
||||
local my_ai = { data = { ["pers"] = 5, ["stringg"] = "stringg" } }
|
||||
|
||||
|
||||
|
||||
|
@ -315,7 +304,7 @@ ai_stdlib.init(ai)
|
|||
|
||||
function my_ai:stage_hello()
|
||||
wesnoth.message('hello from stage!')
|
||||
wesnoth.message('PERSISTANCE: ' .. tostring(ai.data["pers"]) .. ai.data["stringg"])
|
||||
wesnoth.message('PERSISTANCE: ' .. tostring(self.data["pers"]) .. self.data["stringg"])
|
||||
end
|
||||
|
||||
function my_ai:candidate_action_evaluation_hello()
|
||||
|
|
|
@ -68,19 +68,26 @@ void lua_ai_context::init(lua_State *L)
|
|||
void lua_ai_context::get_persistent_data(config &cfg) const
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
lua_getglobal(L, "ai");
|
||||
|
||||
lua_pushlightuserdata(L, (void *)&aisKey);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
lua_rawgeti(L, -1, num_);
|
||||
|
||||
lua_getfield(L, -1, "data");
|
||||
luaW_toconfig(L, -1, cfg);
|
||||
|
||||
ERR_LUA << cfg << std::endl;
|
||||
|
||||
lua_settop(L, top);
|
||||
}
|
||||
|
||||
void lua_ai_context::set_persistent_data(const config &cfg)
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
lua_pushlightuserdata(L, (void *)&aisKey);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
lua_rawgeti(L, -1, num_);
|
||||
|
||||
lua_getglobal(L, "ai");
|
||||
luaW_pushconfig(L, cfg);
|
||||
lua_setfield(L, -2, "data");
|
||||
|
||||
|
@ -535,7 +542,7 @@ lua_ai_context* lua_ai_context::create(lua_State *L, char const *code, ai::engin
|
|||
// Aspects
|
||||
{ "get_aggression", &cfun_ai_get_aggression },
|
||||
{ "get_avoid", &cfun_ai_get_avoid },
|
||||
{ "get_attack_depth", &cfun_ai_get_attack_depth }, // { "get_", &cfun_ai_get_}, little template # TODELETE
|
||||
{ "get_attack_depth", &cfun_ai_get_attack_depth },
|
||||
{ "get_caution", &cfun_ai_get_caution },
|
||||
{ "get_grouping", &cfun_ai_get_grouping },
|
||||
{ "get_leader_aggression", &cfun_ai_get_leader_aggression },
|
||||
|
|
Loading…
Add table
Reference in a new issue