Add new AI aspect retreat_factor

This commit is contained in:
mattsc 2021-02-25 20:25:16 -08:00
parent 1ff1ada25c
commit efe5a4d497
11 changed files with 51 additions and 3 deletions

View file

@ -92,6 +92,7 @@
[/value]
[/default]
[/aspect]
{DEFAULT_ASPECT_VALUE retreat_factor 0.25}
{DEFAULT_ASPECT_VALUE scout_village_targeting 3}
{DEFAULT_ASPECT_VALUE simple_targeting no}
{DEFAULT_ASPECT_VALUE support_villages no}

View file

@ -60,7 +60,7 @@
[switch]
key=id
[case]
value=aggression,caution,leader_aggression,leader_value,scout_village_targeting,village_value,recruitment_diversity
value=aggression,caution,leader_aggression,leader_value,retreat_factor,scout_village_targeting,village_value,recruitment_diversity
super="{BASE}~real"
[/case]
[case]

View file

@ -48,6 +48,7 @@
{AI_ASPECT_KEY passive_leader_shares_keep s_bool}
{AI_ASPECT_KEY recruitment_diversity s_real}
{AI_ASPECT_KEY recruitment_randomness s_int}
{AI_ASPECT_KEY retreat_factor s_real}
{AI_ASPECT_KEY scout_village_targeting s_real}
{AI_ASPECT_KEY simple_targeting s_bool}
{AI_ASPECT_KEY support_villages s_bool}

View file

@ -154,6 +154,7 @@
{AI_MODIFY_MATCH_ASPECT caution real}
{AI_MODIFY_MATCH_ASPECT leader_aggression real}
{AI_MODIFY_MATCH_ASPECT leader_value real}
{AI_MODIFY_MATCH_ASPECT retreat_factor real}
{AI_MODIFY_MATCH_ASPECT scout_village_targeting real}
{AI_MODIFY_MATCH_ASPECT village_value real}
{AI_MODIFY_MATCH_ASPECT recruitment_diversity real}
@ -175,4 +176,3 @@
{AI_MODIFY_MATCH_ASPECT attacks attacks}
[/if]
[/tag]

View file

@ -76,7 +76,7 @@
("rulebase"))
("ai"
("team_formula" "register_candidate_action" "candidate_action" "not" "protect_area" "aspect" "leader_goal" "avoid" "vars" "modify_ai" "engine" "goal" "stage")
("priority" "formula" "eval_list" "_stage" "_aspect" "leader" "loop_formula" "y" "x" "passive_leader_shares_keep" "leader_aggression" "number_of_possible_recruits_to_force_recruit" "time_of_day" "ai_algorithm" "scout_village_targeting" "turns" "attack_depth" "grouping" "villages_per_scout" "leader_value" "village_value" "leader_shares_keep" "passive_leader" "recruitment_pattern" "simple_targeting" "recruitment_ignore_bad_combat" "recruitment_ignore_bad_movement" "caution" "aggression" "version" "description" "id"))
("priority" "formula" "eval_list" "_stage" "_aspect" "leader" "loop_formula" "y" "x" "passive_leader_shares_keep" "leader_aggression" "number_of_possible_recruits_to_force_recruit" "time_of_day" "ai_algorithm" "retreat_factor" "scout_village_targeting" "turns" "attack_depth" "grouping" "villages_per_scout" "leader_value" "village_value" "leader_shares_keep" "passive_leader" "recruitment_pattern" "simple_targeting" "recruitment_ignore_bad_combat" "recruitment_ignore_bad_movement" "caution" "aggression" "version" "description" "id"))
("side"
("leader" "variables" "goal" "village" "unit" "ai" "modifications")
("recall_cost" "village_support" "gold_lock" "faction_from_recruit" "income_lock" "team_lock" "disallow_observers" "variation" "ai_special" "hitpoints" "overlays" "ai_algorithm" "generate_name" "random_traits" "extra_recruit" "y" "x" "allow_player" "faction" "image" "experience" "race" "facing" "moves" "color" "share_maps" "share_view" "shroud" "fog" "profile" "scroll_to_leader" "village_gold" "unrenamable" "gender" "save_id" "income" "no_leader" "gold" "recruit" "canrecruit" "user_team_name" "team_name" "persistent" "max_moves" "type" "id" "name" "hidden" "controller" "side"))

View file

@ -196,6 +196,7 @@ readonly_context_impl::readonly_context_impl(side_context &context, const config
recruitment_randomness_(),
recruitment_save_gold_(),
recursion_counter_(context.get_recursion_count()),
retreat_factor_(),
scout_village_targeting_(),
simple_targeting_(),
srcdst_(),
@ -225,6 +226,7 @@ readonly_context_impl::readonly_context_impl(side_context &context, const config
add_known_aspect("recruitment_pattern",recruitment_pattern_);
add_known_aspect("recruitment_randomness",recruitment_randomness_);
add_known_aspect("recruitment_save_gold",recruitment_save_gold_);
add_known_aspect("retreat_factor",retreat_factor_);
add_known_aspect("scout_village_targeting",scout_village_targeting_);
add_known_aspect("simple_targeting",simple_targeting_);
add_known_aspect("support_villages",support_villages_);
@ -754,6 +756,14 @@ const config readonly_context_impl::get_recruitment_save_gold() const
return config();
}
double readonly_context_impl::get_retreat_factor() const
{
if (retreat_factor_) {
return retreat_factor_->get();
}
return 1;
}
double readonly_context_impl::get_scout_village_targeting() const
{
if (scout_village_targeting_) {

View file

@ -264,6 +264,8 @@ public:
virtual const config get_recruitment_save_gold() const = 0;
virtual double get_retreat_factor() const = 0;
virtual double get_scout_village_targeting() const = 0;
virtual bool get_simple_targeting() const = 0;
@ -713,6 +715,11 @@ public:
return target_->get_srcdst();
}
virtual double get_retreat_factor() const override
{
return target_->get_retreat_factor();
}
virtual double get_scout_village_targeting() const override
{
return target_->get_scout_village_targeting();
@ -1180,6 +1187,8 @@ public:
virtual const config get_recruitment_save_gold() const override;
virtual double get_retreat_factor() const override;
virtual double get_scout_village_targeting() const override;
virtual bool get_simple_targeting() const override;
@ -1295,6 +1304,7 @@ private:
typesafe_aspect_ptr<int> recruitment_randomness_;
typesafe_aspect_ptr<config> recruitment_save_gold_;
recursion_counter recursion_counter_;
typesafe_aspect_ptr<double> retreat_factor_;
typesafe_aspect_ptr<double> scout_village_targeting_;
typesafe_aspect_ptr<bool> simple_targeting_;
mutable move_map srcdst_;

View file

@ -346,6 +346,10 @@ variant formula_ai::get_value(const std::string& key) const
}
return variant(vars);
} else if(key == "retreat_factor")
{
return variant(get_retreat_factor()*1000,variant::DECIMAL_VARIANT);
} else if(key == "scout_village_targeting")
{
return variant(get_scout_village_targeting()*1000,variant::DECIMAL_VARIANT);

View file

@ -498,6 +498,14 @@ static int cfun_ai_get_recruitment_pattern(lua_State *L)
return 1;
}
static int cfun_ai_get_retreat_factor(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("retreat_factor");
double retreat_factor = get_readonly_context(L).get_retreat_factor();
lua_pushnumber(L, retreat_factor);
return 1;
}
static int cfun_ai_get_scout_village_targeting(lua_State *L)
{
DEPRECATED_ASPECT_MESSAGE("scout_village_targeting");
@ -896,6 +904,7 @@ static int impl_ai_get(lua_State* L)
{ "get_passive_leader", &cfun_ai_get_passive_leader },
{ "get_passive_leader_shares_keep", &cfun_ai_get_passive_leader_shares_keep },
{ "get_recruitment_pattern", &cfun_ai_get_recruitment_pattern },
{ "get_retreat_factor", &cfun_ai_get_retreat_factor },
{ "get_scout_village_targeting", &cfun_ai_get_scout_village_targeting },
{ "get_simple_targeting", &cfun_ai_get_simple_targeting },
{ "get_support_villages", &cfun_ai_get_support_villages },

View file

@ -254,6 +254,7 @@ const std::string holder::get_ai_overview()
s << "recruitment_randomness: " << this->ai_->get_recruitment_randomness() << std::endl;
s << "recruitment_save_gold: " << std::endl << "----config begin----" << std::endl;
s << this->ai_->get_recruitment_save_gold() << "-----config end-----" << std::endl;
s << "retreat_factor: " << this->ai_->get_retreat_factor() << std::endl;
s << "scout_village_targeting: " << this->ai_->get_scout_village_targeting() << std::endl;
s << "simple_targeting: " << cfg["simple_targeting"] << std::endl;
s << "support_villages: " << cfg["support_villages"] << std::endl;

View file

@ -236,6 +236,9 @@ static register_aspect_factory< composite_aspect<int>>
static register_aspect_factory< composite_aspect<config>>
recruitment_save_gold__composite_aspect_factory("recruitment_save_gold*composite_aspect");
static register_aspect_factory< composite_aspect<double>>
retreat_factor__composite_aspect_factory("retreat_factor*composite_aspect");
static register_aspect_factory< composite_aspect<double>>
scout_village_targeting__composite_aspect_factory("scout_village_targeting*composite_aspect");
@ -307,6 +310,9 @@ static register_aspect_factory< standard_aspect<int>>
static register_aspect_factory< standard_aspect<config>>
recruitment_save_gold__standard_aspect_factory("recruitment_save_gold*standard_aspect");
static register_aspect_factory< standard_aspect<double>>
retreat_factor__standard_aspect_factory("retreat_factor*standard_aspect");
static register_aspect_factory< standard_aspect<double>>
scout_village_targeting__standard_aspect_factory("scout_village_targeting*standard_aspect");
@ -382,6 +388,9 @@ static register_aspect_factory< standard_aspect<int>>
static register_aspect_factory< standard_aspect<config>>
recruitment_save_gold__standard_aspect_factory2("recruitment_save_gold*");
static register_aspect_factory< standard_aspect<double>>
retreat_factor__standard_aspect_factory2("retreat_factor*");
static register_aspect_factory< standard_aspect<double>>
scout_village_targeting__standard_aspect_factory2("scout_village_targeting*");
@ -435,6 +444,9 @@ static register_lua_aspect_factory< lua_aspect<utils::variant<bool, std::vector<
static register_lua_aspect_factory< lua_aspect<utils::variant<bool, std::vector<std::string>>>>
passive_leader_shares_keep__lua_aspect_factory("passive_leader_shares_keep*lua_aspect");
static register_lua_aspect_factory< lua_aspect<double>>
retreat_factor__lua_aspect_factory("retreat_factor*lua_aspect");
static register_lua_aspect_factory< lua_aspect<double>>
scout_village_targeting__lua_aspect_factory("scout_village_targeting*lua_aspect");