Add deprecation messages for old AI aspect fetchers

This commit also updates uses of these fetchers in mainline Lua code.
This commit is contained in:
Celtic Minstrel 2016-10-17 14:24:51 -04:00
parent ce4fd8a14d
commit e81131fcc5
7 changed files with 28 additions and 7 deletions

View file

@ -90,7 +90,7 @@ function ca_attack_highxp:evaluation(cfg, data)
local reaches = LS.create()
local attacker_copies = LS.create()
local aggression = ai.get_aggression()
local aggression = ai.aspects.aggression
local avoid_map = LS.of_pairs(ai.aspects.avoid)
local max_ca_score, max_rating, best_attack = 0, 0
for _,target_info in ipairs(target_infos) do

View file

@ -85,7 +85,7 @@ return {
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'castle_switch'
if AH.print_eval() then print_time(' - Evaluating castle_switch CA:') end
if ai.get_passive_leader() then
if ai.aspects.passive_leader then
-- Turn off this CA if the leader is passive
return 0
end

View file

@ -65,7 +65,7 @@ function ca_fast_combat:evaluation(cfg, data)
end
end
local aggression = ai.get_aggression()
local aggression = ai.aspects.aggression
if (aggression > 1) then aggression = 1 end
local own_value_weight = 1. - aggression

View file

@ -60,7 +60,7 @@ function ca_fast_combat_leader:evaluation(cfg, data)
end
end
local aggression = ai.get_aggression()
local aggression = ai.aspects.aggression
if (aggression > 1) then aggression = 1 end
local own_value_weight = 1. - aggression

View file

@ -29,7 +29,7 @@ function ca_fast_move:execution(cfg)
local goals = {}
-- Villages get added first, so that (hopefully, scouts and faster units will go for them first)
local village_value = ai.get_village_value()
local village_value = ai.aspects.village_value
if leader and (village_value > 0) then
local villages = wesnoth.get_villages()

View file

@ -61,7 +61,7 @@ function ca_healer_move:evaluation(cfg, data)
local enemy_attack_map = BC.get_attack_map(enemies)
for _,healee in ipairs(healees_MP) do wesnoth.put_unit(healee) end
local avoid_map = LS.of_pairs(ai.get_avoid())
local avoid_map = LS.of_pairs(ai.aspects.avoid)
local max_rating = -9e99
for _,healer in ipairs(healers) do

View file

@ -49,6 +49,7 @@
static lg::log_domain log_ai_engine_lua("ai/engine/lua");
#define LOG_LUA LOG_STREAM(info, log_ai_engine_lua)
#define WRN_LUA LOG_STREAM(warn, log_ai_engine_lua)
#define ERR_LUA LOG_STREAM(err, log_ai_engine_lua)
static char const aisKey[] = "ai contexts";
@ -379,9 +380,12 @@ static int cfun_ai_get_targets(lua_State *L)
return 1;
}
#define DEPRECATED_ASPECT_MESSAGE(name) WRN_LUA << "ai.get_" name "() is deprecated, use ai.aspects." name " instead\n"
// Aspect section
static int cfun_ai_get_aggression(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("aggression");
double aggression = get_readonly_context(L).get_aggression();
lua_pushnumber(L, aggression);
return 1;
@ -389,6 +393,7 @@ static int cfun_ai_get_aggression(lua_State *L)
static int cfun_ai_get_attack_depth(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("attack_depth");
int attack_depth = get_readonly_context(L).get_attack_depth();
lua_pushnumber(L, attack_depth);
return 1;
@ -396,6 +401,7 @@ static int cfun_ai_get_attack_depth(lua_State *L)
static int cfun_ai_get_attacks(lua_State *L)
{
// Unlike the other aspect fetchers, this one is not deprecated, because ai.aspects.attacks returns the viable units but this returns a full attack analysis
const ai::attacks_vector& attacks = get_readonly_context(L).get_attacks();
lua_createtable(L, attacks.size(), 0);
int table_index = lua_gettop(L);
@ -412,6 +418,7 @@ static int cfun_ai_get_attacks(lua_State *L)
static int cfun_ai_get_avoid(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("avoid");
std::set<map_location> locs;
terrain_filter avoid = get_readonly_context(L).get_avoid();
avoid.get_locations(locs);
@ -422,6 +429,7 @@ static int cfun_ai_get_avoid(lua_State *L)
static int cfun_ai_get_caution(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("caution");
double caution = get_readonly_context(L).get_caution();
lua_pushnumber(L, caution);
return 1;
@ -429,6 +437,7 @@ static int cfun_ai_get_caution(lua_State *L)
static int cfun_ai_get_grouping(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("grouping");
std::string grouping = get_readonly_context(L).get_grouping();
lua_pushstring(L, grouping.c_str());
return 1;
@ -436,6 +445,7 @@ static int cfun_ai_get_grouping(lua_State *L)
static int cfun_ai_get_leader_aggression(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("leader_aggression");
double leader_aggression = get_readonly_context(L).get_leader_aggression();
lua_pushnumber(L, leader_aggression);
return 1;
@ -443,6 +453,7 @@ static int cfun_ai_get_leader_aggression(lua_State *L)
static int cfun_ai_get_leader_goal(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("leader_goal");
config goal = get_readonly_context(L).get_leader_goal();
luaW_pushconfig(L, goal);
return 1;
@ -450,6 +461,7 @@ static int cfun_ai_get_leader_goal(lua_State *L)
static int cfun_ai_get_leader_ignores_keep(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("leader_ignores_keep");
bool leader_ignores_keep = get_readonly_context(L).get_leader_ignores_keep();
lua_pushboolean(L, leader_ignores_keep);
return 1;
@ -457,6 +469,7 @@ static int cfun_ai_get_leader_ignores_keep(lua_State *L)
static int cfun_ai_get_leader_value(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("leader_value");
double leader_value = get_readonly_context(L).get_leader_value();
lua_pushnumber(L, leader_value);
return 1;
@ -464,6 +477,7 @@ static int cfun_ai_get_leader_value(lua_State *L)
static int cfun_ai_get_passive_leader(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("passive_leader");
bool passive_leader = get_readonly_context(L).get_passive_leader();
lua_pushboolean(L, passive_leader);
return 1;
@ -471,6 +485,7 @@ static int cfun_ai_get_passive_leader(lua_State *L)
static int cfun_ai_get_passive_leader_shares_keep(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("passive_leader_shares_keep");
bool passive_leader_shares_keep = get_readonly_context(L).get_passive_leader_shares_keep();
lua_pushboolean(L, passive_leader_shares_keep);
return 1;
@ -478,9 +493,10 @@ static int cfun_ai_get_passive_leader_shares_keep(lua_State *L)
static int cfun_ai_get_recruitment_pattern(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("recruitment_pattern");
std::vector<std::string> recruiting = get_readonly_context(L).get_recruitment_pattern();
int size = recruiting.size();
lua_createtable(L, size, 0); // create an exmpty table with predefined size
lua_createtable(L, size, 0); // create an empty table with predefined size
for (int i = 0; i < size; ++i)
{
lua_pushinteger(L, i + 1); // Indexing in Lua starts from 1
@ -492,6 +508,7 @@ static int cfun_ai_get_recruitment_pattern(lua_State *L)
static int cfun_ai_get_scout_village_targeting(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("scout_village_targeting");
double scout_village_targeting = get_readonly_context(L).get_scout_village_targeting();
lua_pushnumber(L, scout_village_targeting);
return 1;
@ -499,6 +516,7 @@ static int cfun_ai_get_scout_village_targeting(lua_State *L)
static int cfun_ai_get_simple_targeting(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("simple_targeting");
bool simple_targeting = get_readonly_context(L).get_simple_targeting();
lua_pushboolean(L, simple_targeting);
return 1;
@ -506,6 +524,7 @@ static int cfun_ai_get_simple_targeting(lua_State *L)
static int cfun_ai_get_support_villages(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("support_villages");
bool support_villages = get_readonly_context(L).get_support_villages();
lua_pushboolean(L, support_villages);
return 1;
@ -513,6 +532,7 @@ static int cfun_ai_get_support_villages(lua_State *L)
static int cfun_ai_get_village_value(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("village_value");
double village_value = get_readonly_context(L).get_village_value();
lua_pushnumber(L, village_value);
return 1;
@ -520,6 +540,7 @@ static int cfun_ai_get_village_value(lua_State *L)
static int cfun_ai_get_villages_per_scout(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("villages_per_scout");
int villages_per_scout = get_readonly_context(L).get_villages_per_scout();
lua_pushnumber(L, villages_per_scout);
return 1;