Add new AI aspect leader_ignores_keep.
If set, AI leaders do not move to the closest keep at the beginning of the turn. Instead, they participate in the move_to_targets candidate action (and all other CAs in which they already participated anyway, of course). The default value is 'no', which leaves the default behavior unchanged.
This commit is contained in:
parent
08925883f9
commit
40c7046b5a
10 changed files with 58 additions and 3 deletions
|
@ -58,6 +58,7 @@
|
|||
{DEFAULT_ASPECT_VALUE grouping offensive}
|
||||
{DEFAULT_ASPECT_VALUE leader_aggression -4.0}
|
||||
{DEFAULT_ASPECT_EMPTY leader_goal}
|
||||
{DEFAULT_ASPECT_VALUE leader_ignores_keep no}
|
||||
{DEFAULT_ASPECT_VALUE leader_value 3.0}
|
||||
{DEFAULT_ASPECT_VALUE number_of_possible_recruits_to_force_recruit 3.1}
|
||||
{DEFAULT_ASPECT_VALUE passive_leader no}
|
||||
|
|
|
@ -68,6 +68,7 @@ void configuration::init(const config &game_config)
|
|||
well_known_aspects.push_back(well_known_aspect("grouping"));
|
||||
well_known_aspects.push_back(well_known_aspect("leader_aggression"));
|
||||
well_known_aspects.push_back(well_known_aspect("leader_goal",false));
|
||||
well_known_aspects.push_back(well_known_aspect("leader_ignores_keep"));
|
||||
well_known_aspects.push_back(well_known_aspect("leader_value"));
|
||||
well_known_aspects.push_back(well_known_aspect("number_of_possible_recruits_to_force_recruit"));
|
||||
well_known_aspects.push_back(well_known_aspect("passive_leader"));
|
||||
|
|
|
@ -168,6 +168,7 @@ readonly_context_impl::readonly_context_impl(side_context &context, const config
|
|||
keeps_(),
|
||||
leader_aggression_(),
|
||||
leader_goal_(),
|
||||
leader_ignores_keep_(),
|
||||
leader_value_(),
|
||||
move_maps_enemy_valid_(false),
|
||||
move_maps_valid_(false),
|
||||
|
@ -203,6 +204,7 @@ readonly_context_impl::readonly_context_impl(side_context &context, const config
|
|||
add_known_aspect("grouping",grouping_);
|
||||
add_known_aspect("leader_aggression",leader_aggression_);
|
||||
add_known_aspect("leader_goal",leader_goal_);
|
||||
add_known_aspect("leader_ignores_keep",leader_ignores_keep_);
|
||||
add_known_aspect("leader_value",leader_value_);
|
||||
add_known_aspect("number_of_possible_recruits_to_force_recruit",number_of_possible_recruits_to_force_recruit_);
|
||||
add_known_aspect("passive_leader",passive_leader_);
|
||||
|
@ -673,6 +675,15 @@ config readonly_context_impl::get_leader_goal() const
|
|||
}
|
||||
|
||||
|
||||
bool readonly_context_impl::get_leader_ignores_keep() const
|
||||
{
|
||||
if (leader_ignores_keep_) {
|
||||
return leader_ignores_keep_->get();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
double readonly_context_impl::get_leader_value() const
|
||||
{
|
||||
if (leader_value_) {
|
||||
|
|
|
@ -276,6 +276,9 @@ public:
|
|||
virtual config get_leader_goal() const = 0;
|
||||
|
||||
|
||||
virtual bool get_leader_ignores_keep() const = 0;
|
||||
|
||||
|
||||
virtual double get_leader_value() const = 0;
|
||||
|
||||
|
||||
|
@ -740,6 +743,12 @@ public:
|
|||
}
|
||||
|
||||
|
||||
virtual bool get_leader_ignores_keep() const
|
||||
{
|
||||
return target_->get_leader_ignores_keep();
|
||||
}
|
||||
|
||||
|
||||
virtual double get_leader_value() const
|
||||
{
|
||||
return target_->get_leader_value();
|
||||
|
@ -1316,6 +1325,9 @@ public:
|
|||
virtual config get_leader_goal() const;
|
||||
|
||||
|
||||
virtual bool get_leader_ignores_keep() const;
|
||||
|
||||
|
||||
virtual double get_leader_value() const;
|
||||
|
||||
|
||||
|
@ -1451,6 +1463,7 @@ private:
|
|||
mutable keeps_cache keeps_;
|
||||
aspect_type<double>::typesafe_ptr leader_aggression_;
|
||||
aspect_type< config >::typesafe_ptr leader_goal_;
|
||||
aspect_type<bool>::typesafe_ptr leader_ignores_keep_;
|
||||
aspect_type< double >::typesafe_ptr leader_value_;
|
||||
mutable bool move_maps_enemy_valid_;
|
||||
mutable bool move_maps_valid_;
|
||||
|
|
|
@ -590,6 +590,10 @@ variant formula_ai::get_value(const std::string& key) const
|
|||
{
|
||||
return variant(get_leader_aggression()*1000,variant::DECIMAL_VARIANT);
|
||||
|
||||
} else if(key == "leader_ignores_keep")
|
||||
{
|
||||
return variant(get_leader_ignores_keep());
|
||||
|
||||
} else if(key == "leader_value")
|
||||
{
|
||||
return variant(get_leader_value()*1000,variant::DECIMAL_VARIANT);
|
||||
|
|
|
@ -460,6 +460,13 @@ static int cfun_ai_get_leader_goal(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int cfun_ai_get_leader_ignores_keep(lua_State *L)
|
||||
{
|
||||
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)
|
||||
{
|
||||
double leader_value = get_readonly_context(L).get_leader_value();
|
||||
|
@ -849,6 +856,7 @@ lua_ai_context* lua_ai_context::create(lua_State *L, char const *code, ai::engin
|
|||
{ "get_grouping", &cfun_ai_get_grouping },
|
||||
{ "get_leader_aggression", &cfun_ai_get_leader_aggression },
|
||||
{ "get_leader_goal", &cfun_ai_get_leader_goal },
|
||||
{ "get_leader_ignores_keep", &cfun_ai_get_leader_ignores_keep},
|
||||
{ "get_leader_value", &cfun_ai_get_leader_value },
|
||||
{ "get_number_of_possible_recruits_to_force_recruit", &cfun_ai_get_number_of_possible_recruits_to_force_recruit},
|
||||
{ "get_passive_leader", &cfun_ai_get_passive_leader },
|
||||
|
|
|
@ -240,6 +240,7 @@ const std::string holder::get_ai_overview()
|
|||
s << "caution: " << this->ai_->get_caution() << std::endl;
|
||||
s << "grouping: " << this->ai_->get_grouping() << std::endl;
|
||||
s << "leader_aggression: " << this->ai_->get_leader_aggression() << std::endl;
|
||||
s << "leader_ignores_keep: " << this->ai_->get_leader_ignores_keep() << std::endl;
|
||||
s << "leader_value: " << this->ai_->get_leader_value() << std::endl;
|
||||
s << "number_of_possible_recruits_to_force_recruit: " << this->ai_->get_number_of_possible_recruits_to_force_recruit() << std::endl;
|
||||
s << "passive_leader: " << this->ai_->get_passive_leader() << std::endl;
|
||||
|
|
|
@ -249,6 +249,9 @@ static register_aspect_factory< composite_aspect<double> >
|
|||
static register_aspect_factory< composite_aspect<config> >
|
||||
leader_goal__composite_aspect_factory("leader_goal*composite_aspect");
|
||||
|
||||
static register_aspect_factory< composite_aspect<bool> >
|
||||
leader_igores_keep__composite_aspect_factory("leader_ignores_keep*composite_aspect");
|
||||
|
||||
static register_aspect_factory< composite_aspect<double> >
|
||||
leader_value__composite_aspect_factory("leader_value*composite_aspect");
|
||||
|
||||
|
@ -314,6 +317,9 @@ static register_aspect_factory< standard_aspect<double> >
|
|||
static register_aspect_factory< standard_aspect<config> >
|
||||
leader_goal__standard_aspect_factory("leader_goal*standard_aspect");
|
||||
|
||||
static register_aspect_factory< standard_aspect<bool> >
|
||||
leader_ignores_keep__standard_aspect_factory("leader_ignores_keep*standard_aspect");
|
||||
|
||||
static register_aspect_factory< standard_aspect<double> >
|
||||
leader_value__standard_aspect_factory("leader_value*standard_aspect");
|
||||
|
||||
|
@ -382,6 +388,9 @@ static register_aspect_factory< standard_aspect<double> >
|
|||
static register_aspect_factory< standard_aspect<config> >
|
||||
leader_goal__standard_aspect_factory2("leader_goal*");
|
||||
|
||||
static register_aspect_factory< standard_aspect<bool> >
|
||||
leader_ignores_keep__standard_aspect_factory2("leader_ignores_keep*");
|
||||
|
||||
static register_aspect_factory< standard_aspect<double> >
|
||||
leader_value__standard_aspect_factory2("leader_value*");
|
||||
|
||||
|
@ -443,6 +452,9 @@ static register_lua_aspect_factory< lua_aspect<double> >
|
|||
static register_lua_aspect_factory< lua_aspect<config> >
|
||||
leader_goal__lua_aspect_factory("leader_goal*lua_aspect");
|
||||
|
||||
static register_lua_aspect_factory< lua_aspect<bool> >
|
||||
leader_ignores_keep__lua_aspect_factory("leader_ignores_keep*lua_aspect");
|
||||
|
||||
static register_lua_aspect_factory< lua_aspect<double> >
|
||||
leader_value__lua_aspect_factory("leader_value*lua_aspect");
|
||||
|
||||
|
|
|
@ -742,6 +742,10 @@ double move_leader_to_keep_phase::evaluate()
|
|||
{
|
||||
unit_map &units_ = *resources::units;
|
||||
const unit_map::iterator leader = units_.find_leader(get_side());
|
||||
|
||||
if(get_leader_ignores_keep()){
|
||||
return BAD_SCORE;
|
||||
}
|
||||
if(get_passive_leader() && !get_passive_leader_shares_keep()){
|
||||
return BAD_SCORE;
|
||||
}
|
||||
|
|
|
@ -280,7 +280,7 @@ std::pair<map_location,map_location> testing_move_to_targets_phase::choose_move(
|
|||
|
||||
//find the first eligible unit
|
||||
for(u = units_.begin(); u != units_.end(); ++u) {
|
||||
if (!(u->side() != get_side() || u->can_recruit() || u->movement_left() <= 0 || u->incapacitated())) {
|
||||
if (!(u->side() != get_side() || (u->can_recruit() and !get_leader_ignores_keep()) || u->movement_left() <= 0 || u->incapacitated())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ std::pair<map_location,map_location> testing_move_to_targets_phase::choose_move(
|
|||
LOG_AI << "complex targeting...\n";
|
||||
//now see if any other unit can put a better bid forward
|
||||
for(++u; u != units_.end(); ++u) {
|
||||
if (u->side() != get_side() || u->can_recruit() ||
|
||||
if (u->side() != get_side() || (u->can_recruit() and !get_leader_ignores_keep()) ||
|
||||
u->movement_left() <= 0 || u->get_state("guardian") ||
|
||||
u->incapacitated())
|
||||
{
|
||||
|
@ -687,7 +687,7 @@ map_location testing_move_to_targets_phase::form_group(const std::vector<map_loc
|
|||
++n;
|
||||
} else {
|
||||
const unit_map::const_iterator un = units_.find(j->second);
|
||||
if(un == units_.end() || un->can_recruit() || un->movement_left() < un->total_movement()) {
|
||||
if(un == units_.end() || (un->can_recruit() and !get_leader_ignores_keep()) || un->movement_left() < un->total_movement()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue