transformed wesnoth.get_time_of_day into a more useful implementation

(will extend with more parameters and return values)
This commit is contained in:
Anonymissimus 2011-06-07 15:26:57 +00:00
parent a1600a1a63
commit 87d505241e
2 changed files with 19 additions and 10 deletions

View file

@ -294,7 +294,7 @@ function my_ai:do_moves()
wesnoth.message('Support villages: ' .. tostring(ai.get_support_villages()))
wesnoth.message('Village value: ' .. ai.get_village_value())
wesnoth.message('Villages per scout: ' .. ai.get_villages_per_scout())
wesnoth.message('TOOD: ' .. wesnoth.get_time_of_day())
wesnoth.message('TOOD: ' .. wesnoth.get_time_of_day().id)
my_leader = wesnoth.get_units({canrecruit = true, side = ai.side})[1]
x,y = ai.suitable_keep(my_leader)

View file

@ -1620,6 +1620,23 @@ static int intf_get_terrain_info(lua_State *L)
return 1;
}
/**
* Gets time of day information.
* - Ret 1: table.
*/
static int intf_get_time_of_day(lua_State *L)
{
const time_of_day& tod = resources::tod_manager->get_time_of_day();
lua_newtable(L);
lua_pushstring(L, tod.id.c_str());
lua_setfield(L, -2, "id");
lua_pushinteger(L, tod.lawful_bonus);
lua_setfield(L, -2, "lawful_bonus");
return 1;
}
/**
* Gets the side of a village owner.
* - Args 1,2: map location.
@ -3158,14 +3175,6 @@ static int impl_theme_items_set(lua_State *L)
return 0;
}
// A function that pushesh the current ToD on the stack
static int intf_get_tod(lua_State *L)
{
std::string tod = resources::tod_manager->get_time_of_day().id;
lua_pushstring(L, tod.c_str());
return 1;
}
LuaKernel::LuaKernel(const config &cfg)
: mState(luaL_newstate()), level_(cfg)
{
@ -3216,7 +3225,7 @@ LuaKernel::LuaKernel(const config &cfg)
{ "get_sides", &intf_get_sides },
{ "get_terrain", &intf_get_terrain },
{ "get_terrain_info", &intf_get_terrain_info },
{ "get_time_of_day", &intf_get_tod },
{ "get_time_of_day", &intf_get_time_of_day },
{ "get_unit", &intf_get_unit },
{ "get_units", &intf_get_units },
{ "get_variable", &intf_get_variable },