Skip to content

Commit

Permalink
Add deprecation messages for old AI aspect fetchers
Browse files Browse the repository at this point in the history
This commit also updates uses of these fetchers in mainline Lua code.
  • Loading branch information
CelticMinstrel committed Oct 17, 2016
1 parent ce4fd8a commit e81131f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion data/ai/lua/ca_high_xp_attack.lua
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/ai/lua/generic_rush_engine.lua
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/ai/micro_ais/cas/ca_fast_combat.lua
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion data/ai/micro_ais/cas/ca_fast_combat_leader.lua
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion data/ai/micro_ais/cas/ca_fast_move.lua
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion data/ai/micro_ais/cas/ca_healer_move.lua
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion src/ai/lua/core.cpp
Expand Up @@ -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";
Expand Down Expand Up @@ -379,23 +380,28 @@ 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;
}

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;
}

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);
Expand All @@ -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);
Expand All @@ -422,65 +429,74 @@ 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;
}

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;
}

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;
}

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;
}

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;
}

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;
}

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;
}

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;
}

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
Expand All @@ -492,34 +508,39 @@ 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;
}

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;
}

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;
}

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;
}

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;
Expand Down

0 comments on commit e81131f

Please sign in to comment.