32 #include "formula/callable_objects.hpp"
35 #define LOG_AI LOG_STREAM(info, log_ai)
36 #define ERR_AI LOG_STREAM(err, log_ai)
43 const move_map& enemy_dstsrc,
double aggression)
46 assert(defend_it != units.
end());
52 for(tile = 0; tile != 6; ++tile) {
66 defend_it->hitpoints();
73 double cost_sum = 0.0;
76 const double cost = att->cost();
89 double def_avg_experience = 0.0;
90 double first_chance_kill = 0.0;
92 double prob_dead_already = 0.0;
94 std::vector<std::pair<map_location,map_location> >::const_iterator
m;
102 up->set_location(m->second);
104 double m_aggression = aggression;
106 if (up->can_recruit()) {
113 bool from_cache =
false;
118 const readonly_context::unit_stats_cache_t::key_type cache_key = std::make_pair(
target, &up->type());
122 usc->second.first.attack_num <
123 static_cast<int>(up->attacks().size())) {
144 double prob_fought = (1.0 - prob_dead_already);
147 double prob_killed = def.
hp_dist[0] - prob_dead_already;
148 prob_dead_already = def.
hp_dist[0];
150 double prob_died = att.
hp_dist[0];
151 double prob_survived = (1.0 - prob_died) * prob_fought;
153 double cost = up->cost();
154 const bool on_village = map.
is_village(m->second);
156 cost += (double(up->experience()) / up->max_experience())*cost;
174 double advance_prob = 0.0;
176 if (!up->advances_to().empty()) {
177 int xp_for_advance = up->max_experience() - up->experience();
181 if (xp_for_advance <= 0)
184 int fight_xp = defend_it->level();
187 if (fight_xp >= xp_for_advance) {
188 advance_prob = prob_fought;
190 }
else if (kill_xp >= xp_for_advance) {
191 advance_prob = prob_killed;
200 fight_xp * (prob_fought - prob_killed)
204 (kill_xp * prob_killed + fight_xp * (prob_fought - prob_killed))
223 int fight_xp = up->level();
225 def_avg_experience += fight_xp * (1.0 - att.
hp_dist[0]) + kill_xp * att.
hp_dist[0];
227 first_chance_kill = def.
hp_dist[0];
231 if (!defend_it->advances_to().empty() &&
232 def_avg_experience >= defend_it->max_experience() - defend_it->experience()) {
247 units.
move(m->second, m->first);
254 for(std::set<map_location>::const_iterator
i = attacks.begin();
i != attacks.end(); ++
i) {
290 LOG_AI <<
"attack option has base value " << value <<
" with exposure " << exposure <<
": "
292 value -= exposure*(1.0-aggression);
338 if(key ==
"target") {
340 }
else if(key ==
"movements") {
341 std::vector<variant>
res;
350 }
else if(key ==
"units") {
351 std::vector<variant>
res;
357 }
else if(key ==
"target_value") {
359 }
else if(key ==
"avg_losses") {
361 }
else if(key ==
"chance_to_kill") {
363 }
else if(key ==
"avg_damage_inflicted") {
365 }
else if(key ==
"target_starting_damage") {
367 }
else if(key ==
"avg_damage_taken") {
369 }
else if(key ==
"resources_used") {
371 }
else if(key ==
"terrain_quality") {
373 }
else if(key ==
"alternative_terrain_quality") {
375 }
else if(key ==
"vulnerability") {
377 }
else if(key ==
"support") {
379 }
else if(key ==
"leader_threat") {
381 }
else if(key ==
"uses_leader") {
383 }
else if(key ==
"is_surrounded") {
bool leader_threat
Is true if the unit is a threat to our leader.
double avg_damage_taken
The average hitpoints damage taken.
std::vector< double > hp_dist
Resulting probability distribution (might be not as large as max_hp)
variant get_value(const std::string &key) const
Various functions that implement attacks and attack calculations.
const combatant & get_attacker_combatant(const combatant *prev_def=nullptr)
Get the simulation results.
double avg_damage_inflicted
The average hitpoints damage inflicted.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
bool is_village(const map_location &loc) const
bool is_enemy(int n) const
double vulnerability
The vulnerability is the power projection of enemy units onto the hex we're standing on...
double resources_used
The sum of the values of units used in the attack.
double chance_to_kill
Estimated % chance to kill the unit.
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
int target_starting_damage
double terrain_quality
The weighted average of the % chance to hit each attacking unit.
double target_value
The value of the unit being targeted.
const combatant & get_defender_combatant(const combatant *prev_def=nullptr)
std::multimap< map_location, map_location > move_map
The standard way in which a map of possible moves is recorded.
A small explanation about what's going on here: Each action has access to two game_info objects First...
void analyze(const gamemap &map, unit_map &units, const readonly_context &ai_obj, const move_map &dstsrc, const move_map &srcdst, const move_map &enemy_dstsrc, double aggression)
virtual unit_stats_cache_t & unit_stats_cache() const =0
std::pair< unit_iterator, bool > insert(unit_ptr p)
Adds the unit to the map.
size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
double alternative_terrain_quality
The weighted average of the % defense of the best possible terrain that the attacking units could rea...
void get_inputs(std::vector< game_logic::formula_input > *inputs) const
GLsizei const GLfloat * value
bool attack_close(const map_location &loc) const
const battle_context_unit_stats & get_defender_stats() const
This method returns the statistics of the defender.
bool plagues
Attack turns opponent into a zombie when fatal.
Encapsulates the map of the game.
Computes the statistics of a battle between an attacker and a defender unit.
Managing the AIs lifecycle - headers.
static lg::log_domain log_ai("ai/attack")
Encapsulates the map of the game.
bool uses_leader
Is true if this attack sequence makes use of the leader.
virtual const team & current_team() const =0
std::vector< std::pair< map_location, map_location > > movements
std::set< map_location > recent_attacks
hack.
double avg_losses
The value on average, of units lost in the combat.
bool is_poisoned
True if the unit is poisoned at the beginning of the battle.
std::pair< unit_iterator, bool > move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
virtual defensive_position const & best_defensive_position(const map_location &unit, const move_map &dstsrc, const move_map &srcdst, const move_map &enemy_dstsrc) const =0
static game_info & get_ai_info()
Gets global AI-game info.
unit_ptr extract(const map_location &loc)
Extracts a unit from the map.
Standard logging facilities (interface).
virtual double get_leader_aggression() const =0
Container associating units to locations.
bool is_surrounded
Is true if the units involved in this attack sequence are surrounded.
double average_hp(unsigned int healing=0) const
What's the average hp (weighted average of hp_dist).
const battle_context_unit_stats & get_attacker_stats() const
This method returns the statistics of the attacker.
unit_iterator find(size_t id)
GLsizei const GLcharARB ** string
virtual double get_caution() const =0
double poisoned
Resulting chance we are poisoned.
double rating(double aggression, const readonly_context &ai_obj) const
int gives_healing(const map_location &loc) const