mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-02 21:13:26 +00:00
reduce ai header dependencies
This commit is contained in:
parent
31ffceb09c
commit
1460db5c8b
@ -536,9 +536,9 @@ battle_context::battle_context(const unit_map& units,
|
||||
ddef = &defender.attacks()[defender_weapon];
|
||||
}
|
||||
assert(!defender_stats_ && !attacker_combatant_ && !defender_combatant_);
|
||||
attacker_stats_ = new unit_stats(attacker, attacker_loc, attacker_weapon,
|
||||
attacker_stats_ = new battle_context_unit_stats(attacker, attacker_loc, attacker_weapon,
|
||||
true, defender, defender_loc, ddef, units);
|
||||
defender_stats_ = new unit_stats(defender, defender_loc, defender_weapon, false,
|
||||
defender_stats_ = new battle_context_unit_stats(defender, defender_loc, defender_weapon, false,
|
||||
attacker, attacker_loc, adef, units);
|
||||
}
|
||||
}
|
||||
@ -549,9 +549,9 @@ battle_context::battle_context(const unit_map& units,
|
||||
*this = other;
|
||||
}
|
||||
|
||||
battle_context::battle_context(const unit_stats &att, const unit_stats &def) :
|
||||
attacker_stats_(new unit_stats(att)),
|
||||
defender_stats_(new unit_stats(def)),
|
||||
battle_context::battle_context(const battle_context_unit_stats &att, const battle_context_unit_stats &def) :
|
||||
attacker_stats_(new battle_context_unit_stats(att)),
|
||||
defender_stats_(new battle_context_unit_stats(def)),
|
||||
attacker_combatant_(0),
|
||||
defender_combatant_(0)
|
||||
{
|
||||
@ -571,8 +571,8 @@ battle_context& battle_context::operator=(const battle_context &other)
|
||||
delete defender_stats_;
|
||||
delete attacker_combatant_;
|
||||
delete defender_combatant_;
|
||||
attacker_stats_ = new unit_stats(*other.attacker_stats_);
|
||||
defender_stats_ = new unit_stats(*other.defender_stats_);
|
||||
attacker_stats_ = new battle_context_unit_stats(*other.attacker_stats_);
|
||||
defender_stats_ = new battle_context_unit_stats(*other.defender_stats_);
|
||||
attacker_combatant_ = other.attacker_combatant_ ? new combatant(*other.attacker_combatant_, *attacker_stats_) : NULL;
|
||||
defender_combatant_ = other.defender_combatant_ ? new combatant(*other.defender_combatant_, *defender_stats_) : NULL;
|
||||
}
|
||||
@ -615,7 +615,7 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
|
||||
const attack_type &def = defender.attacks()[choices[i]];
|
||||
if (def.defense_weight() > max_weight) {
|
||||
max_weight = def.defense_weight();
|
||||
unit_stats *def_stats = new unit_stats(defender, defender_loc, choices[i], false,
|
||||
battle_context_unit_stats *def_stats = new battle_context_unit_stats(defender, defender_loc, choices[i], false,
|
||||
attacker, attacker_loc, &att, units);
|
||||
min_rating = static_cast<int>(def_stats->num_blows * def_stats->damage *
|
||||
def_stats->chance_to_hit * def.defense_weight());
|
||||
@ -623,7 +623,7 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
|
||||
delete def_stats;
|
||||
}
|
||||
else if (def.defense_weight() == max_weight) {
|
||||
unit_stats *def_stats = new unit_stats(defender, defender_loc, choices[i], false,
|
||||
battle_context_unit_stats *def_stats = new battle_context_unit_stats(defender, defender_loc, choices[i], false,
|
||||
attacker, attacker_loc, &att, units);
|
||||
int simple_rating = static_cast<int>(def_stats->num_blows * def_stats->damage *
|
||||
def_stats->chance_to_hit * def.defense_weight());
|
||||
@ -637,9 +637,9 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
|
||||
// Multiple options: simulate them, save best.
|
||||
for (i = 0; i < choices.size(); ++i) {
|
||||
const attack_type &def = defender.attacks()[choices[i]];
|
||||
unit_stats *att_stats = new unit_stats(attacker, attacker_loc, attacker_weapon,
|
||||
battle_context_unit_stats *att_stats = new battle_context_unit_stats(attacker, attacker_loc, attacker_weapon,
|
||||
true, defender, defender_loc, &def, units);
|
||||
unit_stats *def_stats = new unit_stats(defender, defender_loc, choices[i], false,
|
||||
battle_context_unit_stats *def_stats = new battle_context_unit_stats(defender, defender_loc, choices[i], false,
|
||||
attacker, attacker_loc, &att, units);
|
||||
|
||||
combatant *att_comb = new combatant(*att_stats);
|
||||
@ -695,7 +695,7 @@ int battle_context::choose_attacker_weapon(const unit &attacker, const unit &def
|
||||
}
|
||||
|
||||
// Multiple options: simulate them, save best.
|
||||
unit_stats *best_att_stats = NULL, *best_def_stats = NULL;
|
||||
battle_context_unit_stats *best_att_stats = NULL, *best_def_stats = NULL;
|
||||
combatant *best_att_comb = NULL, *best_def_comb = NULL;
|
||||
|
||||
for (i = 0; i < choices.size(); ++i) {
|
||||
@ -708,9 +708,9 @@ int battle_context::choose_attacker_weapon(const unit &attacker, const unit &def
|
||||
if (def_weapon >= 0) {
|
||||
def = &defender.attacks()[def_weapon];
|
||||
}
|
||||
attacker_stats_ = new unit_stats(attacker, attacker_loc, choices[i],
|
||||
attacker_stats_ = new battle_context_unit_stats(attacker, attacker_loc, choices[i],
|
||||
true, defender, defender_loc, def, units);
|
||||
defender_stats_ = new unit_stats(defender, defender_loc, def_weapon, false,
|
||||
defender_stats_ = new battle_context_unit_stats(defender, defender_loc, def_weapon, false,
|
||||
attacker, attacker_loc, &att, units);
|
||||
attacker_combatant_ = new combatant(*attacker_stats_);
|
||||
defender_combatant_ = new combatant(*defender_stats_, prev_def);
|
||||
@ -779,7 +779,7 @@ bool battle_context::better_combat(const combatant &us_a, const combatant &them_
|
||||
return them_a.average_hp() < them_b.average_hp();
|
||||
}
|
||||
|
||||
/** @todo FIXME: better to initialize combatant initially (move into unit_stats?), just do fight() when required. */
|
||||
/** @todo FIXME: better to initialize combatant initially (move into battle_context_unit_stats?), just do fight() when required. */
|
||||
const combatant &battle_context::get_attacker_combatant(const combatant *prev_def)
|
||||
{
|
||||
// We calculate this lazily, since AI doesn't always need it.
|
||||
@ -804,7 +804,7 @@ const combatant &battle_context::get_defender_combatant(const combatant *prev_de
|
||||
return *defender_combatant_;
|
||||
}
|
||||
|
||||
battle_context::unit_stats::unit_stats(const unit &u, const map_location& u_loc,
|
||||
battle_context_unit_stats::battle_context_unit_stats(const unit &u, const map_location& u_loc,
|
||||
int u_attack_num, bool attacking,
|
||||
const unit &opp, const map_location& opp_loc,
|
||||
const attack_type *opp_weapon,
|
||||
@ -942,11 +942,11 @@ battle_context::unit_stats::unit_stats(const unit &u, const map_location& u_loc,
|
||||
}
|
||||
}
|
||||
|
||||
battle_context::unit_stats::~unit_stats()
|
||||
battle_context_unit_stats::~battle_context_unit_stats()
|
||||
{
|
||||
}
|
||||
|
||||
void battle_context::unit_stats::dump() const
|
||||
void battle_context_unit_stats::dump() const
|
||||
{
|
||||
printf("==================================\n");
|
||||
printf("is_attacker: %d\n", static_cast<int>(is_attacker));
|
||||
@ -1017,8 +1017,8 @@ class attack
|
||||
};
|
||||
|
||||
battle_context *bc_;
|
||||
const battle_context::unit_stats *a_stats_;
|
||||
const battle_context::unit_stats *d_stats_;
|
||||
const battle_context_unit_stats *a_stats_;
|
||||
const battle_context_unit_stats *d_stats_;
|
||||
|
||||
int abs_n_attack_, abs_n_defend_;
|
||||
bool update_att_fog_, update_def_fog_, update_minimap_;
|
||||
@ -1112,11 +1112,11 @@ void attack::refresh_bc()
|
||||
}
|
||||
if(!a_.valid() || !d_.valid()) {
|
||||
// Fix pointer to weapons
|
||||
const_cast<battle_context::unit_stats*>(a_stats_)->weapon =
|
||||
const_cast<battle_context_unit_stats*>(a_stats_)->weapon =
|
||||
a_.valid() && a_.weapon_ >= 0
|
||||
? &a_.get_unit().attacks()[a_.weapon_] : NULL;
|
||||
|
||||
const_cast<battle_context::unit_stats*>(d_stats_)->weapon =
|
||||
const_cast<battle_context_unit_stats*>(d_stats_)->weapon =
|
||||
d_.valid() && d_.weapon_ >= 0
|
||||
? &d_.get_unit().attacks()[d_.weapon_] : NULL;
|
||||
|
||||
@ -1207,7 +1207,7 @@ bool attack::perform_hit(bool attacker_turn, statistics::attack_context &stats)
|
||||
unit_info
|
||||
&attacker = *(attacker_turn ? &a_ : &d_),
|
||||
&defender = *(attacker_turn ? &d_ : &a_);
|
||||
const battle_context::unit_stats
|
||||
const battle_context_unit_stats
|
||||
*&attacker_stats = *(attacker_turn ? &a_stats_ : &d_stats_),
|
||||
*&defender_stats = *(attacker_turn ? &d_stats_ : &a_stats_);
|
||||
int &abs_n = *(attacker_turn ? &abs_n_attack_ : &abs_n_defend_);
|
||||
|
@ -100,54 +100,55 @@ void place_recruit(const unit &u, const map_location &recruit_location,
|
||||
bool is_recall, bool show = false, bool full_movement = false,
|
||||
bool wml_triggered = false);
|
||||
|
||||
/** Structure describing the statistics of a unit involved in the battle. */
|
||||
struct battle_context_unit_stats
|
||||
{
|
||||
const attack_type *weapon; /**< The weapon used by the unit to attack the opponent, or NULL if there is none. */
|
||||
int attack_num; /**< Index into unit->attacks() or -1 for none. */
|
||||
bool is_attacker; /**< True if the unit is the attacker. */
|
||||
bool is_poisoned; /**< True if the unit is poisoned at the beginning of the battle. */
|
||||
bool is_slowed; /**< True if the unit is slowed at the beginning of the battle. */
|
||||
bool slows; /**< Attack slows opponent when it hits. */
|
||||
bool drains; /**< Attack drains opponent when it hits. */
|
||||
bool petrifies; /**< Attack petrifies opponent when it hits. */
|
||||
bool plagues; /**< Attack turns opponent into a zombie when fatal. */
|
||||
bool poisons; /**< Attack poisons opponent when it hits. */
|
||||
bool backstab_pos; /**<
|
||||
* True if the attacker is in *position* to backstab the defender (this is used to
|
||||
* determine whether to apply the backstab bonus in case the attacker has backstab).
|
||||
*/
|
||||
bool swarm; /**< Attack has swarm special. */
|
||||
bool firststrike; /**< Attack has firststrike special. */
|
||||
unsigned int experience, max_experience;
|
||||
unsigned int level;
|
||||
|
||||
unsigned int rounds; /**< Berserk special can force us to fight more than one round. */
|
||||
unsigned int hp; /**< Hitpoints of the unit at the beginning of the battle. */
|
||||
unsigned int max_hp; /**< Maximum hitpoints of the unit. */
|
||||
unsigned int chance_to_hit; /**< Effective chance to hit as a percentage (all factors accounted for). */
|
||||
int damage; /**< Effective damage of the weapon (all factors accounted for). */
|
||||
int slow_damage; /**< Effective damage if unit becomes slowed (== damage, if already slowed) */
|
||||
unsigned int num_blows; /**< Effective number of blows, takes swarm into account. */
|
||||
unsigned int swarm_min; /**< Minimum number of blows with swarm (equal to num_blows if swarm isn't used). */
|
||||
unsigned int swarm_max; /**< Maximum number of blows with swarm (equal to num_blows if swarm isn't used). */
|
||||
|
||||
std::string plague_type; /**< The plague type used by the attack, if any. */
|
||||
|
||||
battle_context_unit_stats(const unit &u, const map_location& u_loc,
|
||||
int u_attack_num, bool attacking,
|
||||
const unit &opp, const map_location& opp_loc,
|
||||
const attack_type *opp_weapon,
|
||||
const unit_map& units);
|
||||
~battle_context_unit_stats();
|
||||
|
||||
/** Dumps the statistics of a unit on stdout. Remove it eventually. */
|
||||
void dump() const;
|
||||
};
|
||||
|
||||
/** Computes the statistics of a battle between an attacker and a defender unit. */
|
||||
class battle_context
|
||||
{
|
||||
public:
|
||||
/** Structure describing the statistics of a unit involved in the battle. */
|
||||
struct unit_stats
|
||||
{
|
||||
const attack_type *weapon; /**< The weapon used by the unit to attack the opponent, or NULL if there is none. */
|
||||
int attack_num; /**< Index into unit->attacks() or -1 for none. */
|
||||
bool is_attacker; /**< True if the unit is the attacker. */
|
||||
bool is_poisoned; /**< True if the unit is poisoned at the beginning of the battle. */
|
||||
bool is_slowed; /**< True if the unit is slowed at the beginning of the battle. */
|
||||
bool slows; /**< Attack slows opponent when it hits. */
|
||||
bool drains; /**< Attack drains opponent when it hits. */
|
||||
bool petrifies; /**< Attack petrifies opponent when it hits. */
|
||||
bool plagues; /**< Attack turns opponent into a zombie when fatal. */
|
||||
bool poisons; /**< Attack poisons opponent when it hits. */
|
||||
bool backstab_pos; /**<
|
||||
* True if the attacker is in *position* to backstab the defender (this is used to
|
||||
* determine whether to apply the backstab bonus in case the attacker has backstab).
|
||||
*/
|
||||
bool swarm; /**< Attack has swarm special. */
|
||||
bool firststrike; /**< Attack has firststrike special. */
|
||||
unsigned int experience, max_experience;
|
||||
unsigned int level;
|
||||
|
||||
unsigned int rounds; /**< Berserk special can force us to fight more than one round. */
|
||||
unsigned int hp; /**< Hitpoints of the unit at the beginning of the battle. */
|
||||
unsigned int max_hp; /**< Maximum hitpoints of the unit. */
|
||||
unsigned int chance_to_hit; /**< Effective chance to hit as a percentage (all factors accounted for). */
|
||||
int damage; /**< Effective damage of the weapon (all factors accounted for). */
|
||||
int slow_damage; /**< Effective damage if unit becomes slowed (== damage, if already slowed) */
|
||||
unsigned int num_blows; /**< Effective number of blows, takes swarm into account. */
|
||||
unsigned int swarm_min; /**< Minimum number of blows with swarm (equal to num_blows if swarm isn't used). */
|
||||
unsigned int swarm_max; /**< Maximum number of blows with swarm (equal to num_blows if swarm isn't used). */
|
||||
|
||||
std::string plague_type; /**< The plague type used by the attack, if any. */
|
||||
|
||||
unit_stats(const unit &u, const map_location& u_loc,
|
||||
int u_attack_num, bool attacking,
|
||||
const unit &opp, const map_location& opp_loc,
|
||||
const attack_type *opp_weapon,
|
||||
const unit_map& units);
|
||||
~unit_stats();
|
||||
|
||||
/** Dumps the statistics of a unit on stdout. Remove it eventually. */
|
||||
void dump() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* If no attacker_weapon is given, we select the best one,
|
||||
@ -159,8 +160,8 @@ public:
|
||||
const map_location& attacker_loc, const map_location& defender_loc,
|
||||
int attacker_weapon = -1, int defender_weapon = -1, double aggression = 0.0, const combatant *prev_def = NULL, const unit* attacker_ptr=NULL);
|
||||
|
||||
/** Used by the AI which caches unit_stats */
|
||||
battle_context(const unit_stats &att, const unit_stats &def);
|
||||
/** Used by the AI which caches battle_context_unit_stats */
|
||||
battle_context(const battle_context_unit_stats &att, const battle_context_unit_stats &def);
|
||||
|
||||
battle_context(const battle_context &other);
|
||||
~battle_context();
|
||||
@ -168,10 +169,10 @@ public:
|
||||
battle_context& operator=(const battle_context &other);
|
||||
|
||||
/** This method returns the statistics of the attacker. */
|
||||
const unit_stats& get_attacker_stats() const { return *attacker_stats_; }
|
||||
const battle_context_unit_stats& get_attacker_stats() const { return *attacker_stats_; }
|
||||
|
||||
/** This method returns the statistics of the defender. */
|
||||
const unit_stats& get_defender_stats() const { return *defender_stats_; }
|
||||
const battle_context_unit_stats& get_defender_stats() const { return *defender_stats_; }
|
||||
|
||||
/** Get the simulation results. */
|
||||
const combatant &get_attacker_combatant(const combatant *prev_def = NULL);
|
||||
@ -195,7 +196,7 @@ private:
|
||||
const map_location& attacker_loc, const map_location& defender_loc, const combatant *prev_def);
|
||||
|
||||
/** Statistics of the units. */
|
||||
unit_stats *attacker_stats_, *defender_stats_;
|
||||
battle_context_unit_stats *attacker_stats_, *defender_stats_;
|
||||
|
||||
/** Outcome of simulated fight. */
|
||||
combatant *attacker_combatant_, *defender_combatant_;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "property_handler.hpp"
|
||||
#include "stage.hpp"
|
||||
#include "../manager.hpp"
|
||||
#include "../../actions.hpp"
|
||||
#include "../../foreach.hpp"
|
||||
#include "../../log.hpp"
|
||||
|
||||
|
@ -28,6 +28,12 @@
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
namespace pathfind {
|
||||
|
||||
struct pathfind;
|
||||
|
||||
} //of namespace pathfind
|
||||
|
||||
namespace ai {
|
||||
|
||||
static lg::log_domain log_ai_component("ai/component");
|
||||
|
@ -21,10 +21,14 @@
|
||||
#include "engine_lua.hpp"
|
||||
#include "rca.hpp"
|
||||
#include "stage.hpp"
|
||||
|
||||
#include "../gamestate_observer.hpp"
|
||||
|
||||
#include "../../log.hpp"
|
||||
#include "../../resources.hpp"
|
||||
#include "../../scripting/lua.hpp"
|
||||
#include "../gamestate_observer.hpp"
|
||||
#include "../../util.hpp"
|
||||
|
||||
|
||||
namespace ai {
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
#include "../contexts.hpp"
|
||||
#include "../game_info.hpp"
|
||||
#include "../../terrain_filter.hpp"
|
||||
|
||||
//included for 'target' markers
|
||||
#include "../default/contexts.hpp"
|
||||
@ -43,6 +42,8 @@
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
class terrain_filter;
|
||||
|
||||
namespace ai {
|
||||
|
||||
class goal : public readonly_context_proxy, public component {
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "rca.hpp"
|
||||
#include "../../foreach.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../util.hpp"
|
||||
#include "../../serialization/string_utils.hpp"
|
||||
|
||||
namespace ai {
|
||||
|
||||
|
@ -27,7 +27,10 @@
|
||||
#include "../default/contexts.hpp"
|
||||
#include "../game_info.hpp"
|
||||
#include "../manager.hpp"
|
||||
#include "../../terrain_translation.hpp"
|
||||
#include "../../terrain_filter.hpp"
|
||||
#include "../../util.hpp"
|
||||
#include "../../serialization/string_utils.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "../formula_callable.hpp"
|
||||
#include "../formula_function.hpp"
|
||||
#include "../formula_fwd.hpp"
|
||||
#include "../game_display.hpp"
|
||||
#include "../game_end_exceptions.hpp"
|
||||
#include "../game_events.hpp"
|
||||
#include "../game_preferences.hpp"
|
||||
@ -85,6 +86,11 @@ void readwrite_context_impl::raise_gamestate_changed() const
|
||||
}
|
||||
|
||||
|
||||
team& readwrite_context_impl::current_team_w()
|
||||
{
|
||||
return get_info_w().teams[get_side()-1];
|
||||
}
|
||||
|
||||
attack_result_ptr readwrite_context_impl::execute_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon){
|
||||
return actions::execute_attack_action(get_side(),true,attacker_loc,defender_loc,attacker_weapon, get_aggression());
|
||||
}
|
||||
@ -283,6 +289,12 @@ void readonly_context_impl::diagnostic(const std::string& msg)
|
||||
}
|
||||
|
||||
|
||||
const team& readonly_context_impl::current_team() const
|
||||
{
|
||||
return get_info().teams[get_side()-1];
|
||||
}
|
||||
|
||||
|
||||
void readonly_context_impl::log_message(const std::string& msg)
|
||||
{
|
||||
if(game_config::debug) {
|
||||
@ -1120,7 +1132,7 @@ const map_location& readonly_context_impl::suitable_keep(const map_location& lea
|
||||
|
||||
/** Weapon choice cache, to speed simulations. */
|
||||
std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context::unit_stats,battle_context::unit_stats> >& readonly_context_impl::unit_stats_cache() const
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& readonly_context_impl::unit_stats_cache() const
|
||||
{
|
||||
return unit_stats_cache_;
|
||||
}
|
||||
|
@ -21,14 +21,14 @@
|
||||
#ifndef AI_CONTEXTS_HPP_INCLUDED
|
||||
#define AI_CONTEXTS_HPP_INCLUDED
|
||||
|
||||
class game_display;
|
||||
class gamemap;
|
||||
|
||||
#include "game_info.hpp"
|
||||
#include "../game_display.hpp"
|
||||
#include "../gamestatus.hpp"
|
||||
#include "../generic_event.hpp"
|
||||
#include "../playturn.hpp"
|
||||
#include "../config.hpp"
|
||||
#include "../terrain_translation.hpp"
|
||||
#include "../terrain_filter.hpp"
|
||||
|
||||
|
||||
//#include "../unit.hpp"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
@ -36,7 +36,14 @@ class gamemap;
|
||||
#pragma warning(disable:4250)
|
||||
#endif
|
||||
|
||||
class battle_context;
|
||||
class battle_context_unit_stats;
|
||||
class game_display;
|
||||
class gamemap;
|
||||
class variant;
|
||||
class terrain_filter;
|
||||
class unit;
|
||||
class unit_type;
|
||||
|
||||
namespace ai {
|
||||
|
||||
@ -367,7 +374,7 @@ public:
|
||||
|
||||
|
||||
virtual std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context::unit_stats,battle_context::unit_stats> >& unit_stats_cache() const = 0;
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& unit_stats_cache() const = 0;
|
||||
|
||||
};
|
||||
|
||||
@ -884,7 +891,7 @@ public:
|
||||
|
||||
|
||||
virtual std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context::unit_stats,battle_context::unit_stats> >& unit_stats_cache() const
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& unit_stats_cache() const
|
||||
{
|
||||
return target_->unit_stats_cache();
|
||||
}
|
||||
@ -1051,7 +1058,7 @@ public:
|
||||
|
||||
|
||||
/** Return a reference to the 'team' object for the AI. */
|
||||
const team& current_team() const { return get_info().teams[get_side()-1]; }
|
||||
const team& current_team() const;
|
||||
|
||||
|
||||
/** Show a diagnostic message on the screen. */
|
||||
@ -1344,7 +1351,7 @@ public:
|
||||
|
||||
|
||||
virtual std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context::unit_stats,battle_context::unit_stats> >& unit_stats_cache() const;
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& unit_stats_cache() const;
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
@ -1392,7 +1399,7 @@ private:
|
||||
mutable move_map srcdst_;
|
||||
aspect_type< bool >::typesafe_ptr support_villages_;
|
||||
mutable std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context::unit_stats,battle_context::unit_stats> > unit_stats_cache_;
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> > unit_stats_cache_;
|
||||
aspect_type< double >::typesafe_ptr village_value_;
|
||||
aspect_type< int >::typesafe_ptr villages_per_scout_;
|
||||
|
||||
@ -1476,7 +1483,7 @@ public:
|
||||
|
||||
|
||||
/** Return a reference to the 'team' object for the AI. */
|
||||
virtual team& current_team_w() { return get_info_w().teams[get_side()-1]; }
|
||||
virtual team& current_team_w();
|
||||
|
||||
|
||||
/** Notifies all interested observers of the event respectively. */
|
||||
|
@ -37,6 +37,8 @@
|
||||
#include "../../unit_display.hpp"
|
||||
#include "../../wml_exception.hpp"
|
||||
|
||||
#include "../../pathfind/pathfind.hpp"
|
||||
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
@ -32,6 +32,14 @@
|
||||
#pragma warning(disable:4250)
|
||||
#endif
|
||||
|
||||
|
||||
namespace pathfind {
|
||||
|
||||
struct plain_route;
|
||||
|
||||
} // of namespace pathfind
|
||||
|
||||
|
||||
namespace ai {
|
||||
|
||||
class formula_ai;
|
||||
|
@ -111,7 +111,7 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
|
||||
|
||||
// This cache is only about 99% correct, but speeds up evaluation by about 1000 times.
|
||||
// We recalculate when we actually attack.
|
||||
std::map<std::pair<map_location, const unit_type *>,std::pair<battle_context::unit_stats,battle_context::unit_stats> >::iterator usc;
|
||||
std::map<std::pair<map_location, const unit_type *>,std::pair<battle_context_unit_stats,battle_context_unit_stats> >::iterator usc;
|
||||
const unit_type *up_type = up->type();
|
||||
if(up_type) {
|
||||
usc = ai_obj.unit_stats_cache().find(std::pair<map_location, const unit_type *>(target, up_type));
|
||||
@ -136,9 +136,9 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
|
||||
prev_def = &bc->get_defender_combatant(prev_def);
|
||||
|
||||
if (!from_cache && up_type) {
|
||||
ai_obj.unit_stats_cache().insert(std::pair<std::pair<map_location, const unit_type *>,std::pair<battle_context::unit_stats,battle_context::unit_stats> >
|
||||
ai_obj.unit_stats_cache().insert(std::pair<std::pair<map_location, const unit_type *>,std::pair<battle_context_unit_stats,battle_context_unit_stats> >
|
||||
(std::pair<map_location, const unit_type *>(target, up_type),
|
||||
std::pair<battle_context::unit_stats,battle_context::unit_stats>(bc->get_attacker_stats(),
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats>(bc->get_attacker_stats(),
|
||||
bc->get_defender_stats())));
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,9 @@
|
||||
#include "../../foreach.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../map.hpp"
|
||||
#include "../../team.hpp"
|
||||
#include "../composite/goal.hpp"
|
||||
#include "../../pathfind/pathfind.hpp"
|
||||
|
||||
static lg::log_domain log_ai("ai/general");
|
||||
#define DBG_AI LOG_STREAM(debug, log_ai)
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "../../global.hpp"
|
||||
|
||||
#include "../contexts.hpp"
|
||||
#include "formula_callable.hpp"
|
||||
#include "unit_map.hpp"
|
||||
#include <vector>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "../../map.hpp"
|
||||
#include "../../terrain_filter.hpp"
|
||||
#include "../../wml_exception.hpp"
|
||||
#include "../../pathfind/pathfind.hpp"
|
||||
|
||||
|
||||
static lg::log_domain log_ai("ai/move");
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "ai.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../map.hpp"
|
||||
#include "../../unit.hpp"
|
||||
#include "../../team.hpp"
|
||||
|
||||
#include <numeric>
|
||||
|
||||
|
@ -30,12 +30,14 @@
|
||||
#include "../manager.hpp"
|
||||
|
||||
#include "../../callable_objects.hpp"
|
||||
#include "../../game_display.hpp"
|
||||
#include "../../foreach.hpp"
|
||||
#include "../../formula_debugger.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../menu_events.hpp"
|
||||
#include "../../terrain_filter.hpp"
|
||||
#include "../../tod_manager.hpp"
|
||||
#include "../../pathfind/pathfind.hpp"
|
||||
|
||||
static lg::log_domain log_formula_ai("ai/engine/fai");
|
||||
#define DBG_AI LOG_STREAM(debug, log_formula_ai)
|
||||
|
@ -53,6 +53,12 @@ typedef std::multiset< unit_formula_pair, game_logic::unit_formula_compare > uni
|
||||
|
||||
}
|
||||
|
||||
namespace pathfind {
|
||||
|
||||
struct plain_route;
|
||||
|
||||
} // of namespace pathfind
|
||||
|
||||
namespace ai {
|
||||
|
||||
class formula_ai : public readonly_context_proxy, public game_logic::formula_callable {
|
||||
|
@ -24,12 +24,15 @@
|
||||
#include "../../attack_prediction.hpp"
|
||||
#include "../../filesystem.hpp"
|
||||
#include "../../foreach.hpp"
|
||||
#include "../../game_display.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../map_label.hpp"
|
||||
#include "../../menu_events.hpp"
|
||||
#include "../../replay.hpp"
|
||||
#include "../../terrain_filter.hpp"
|
||||
#include "../../unit.hpp"
|
||||
#include "../../pathfind/pathfind.hpp"
|
||||
|
||||
|
||||
static lg::log_domain log_formula_ai("ai/engine/fai");
|
||||
#define LOG_AI LOG_STREAM(info, log_formula_ai)
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "game_info.hpp"
|
||||
|
||||
#include "../formula_callable.hpp"
|
||||
#include "../savegame_config.hpp"
|
||||
|
||||
#include "default/contexts.hpp"
|
||||
|
||||
|
@ -20,10 +20,14 @@
|
||||
#include "aspect_attacks.hpp"
|
||||
|
||||
#include "../manager.hpp"
|
||||
#include "../../actions.hpp"
|
||||
#include "../../foreach.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../map.hpp"
|
||||
#include "../../team.hpp"
|
||||
#include "../../tod_manager.hpp"
|
||||
#include "../../unit.hpp"
|
||||
#include "../../pathfind/pathfind.hpp"
|
||||
|
||||
namespace ai {
|
||||
|
||||
|
@ -22,9 +22,12 @@
|
||||
#include "../manager.hpp"
|
||||
#include "../composite/engine.hpp"
|
||||
#include "../composite/rca.hpp"
|
||||
#include "../../gamestatus.hpp"
|
||||
#include "../../foreach.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../wml_exception.hpp"
|
||||
#include "../../pathfind/pathfind.hpp"
|
||||
|
||||
|
||||
#include <numeric>
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "../../foreach.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../terrain_filter.hpp"
|
||||
#include "../../pathfind/pathfind.hpp"
|
||||
|
||||
namespace ai {
|
||||
|
||||
|
@ -36,6 +36,12 @@
|
||||
#pragma warning(disable:4250)
|
||||
#endif
|
||||
|
||||
namespace pathfind {
|
||||
|
||||
struct plain_route;
|
||||
|
||||
} //of namespace pathfind
|
||||
|
||||
namespace ai {
|
||||
|
||||
namespace testing_ai_default {
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "../../foreach.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../terrain_filter.hpp"
|
||||
#include "../../pathfind/pathfind.hpp"
|
||||
|
||||
namespace ai {
|
||||
|
||||
|
@ -36,6 +36,12 @@
|
||||
#pragma warning(disable:4250)
|
||||
#endif
|
||||
|
||||
namespace pathfind {
|
||||
|
||||
struct plain_route;
|
||||
|
||||
} //of namespace pathfind
|
||||
|
||||
namespace ai {
|
||||
|
||||
namespace testing_ai_default {
|
||||
|
@ -479,7 +479,7 @@ void prob_matrix::receive_blow_a(unsigned damage, unsigned slow_damage, double h
|
||||
|
||||
} // end anon namespace
|
||||
|
||||
unsigned combatant::hp_dist_size(const battle_context::unit_stats &u, const combatant *prev)
|
||||
unsigned combatant::hp_dist_size(const battle_context_unit_stats &u, const combatant *prev)
|
||||
{
|
||||
// Our summary must be as big as previous one.
|
||||
if (prev) {
|
||||
@ -491,7 +491,7 @@ unsigned combatant::hp_dist_size(const battle_context::unit_stats &u, const comb
|
||||
return u.max_hp + 1;
|
||||
}
|
||||
|
||||
combatant::combatant(const battle_context::unit_stats &u, const combatant *prev)
|
||||
combatant::combatant(const battle_context_unit_stats &u, const combatant *prev)
|
||||
: hp_dist(hp_dist_size(u, prev)),
|
||||
untouched(0.0),
|
||||
poisoned(0.0),
|
||||
@ -513,8 +513,8 @@ combatant::combatant(const battle_context::unit_stats &u, const combatant *prev)
|
||||
}
|
||||
}
|
||||
|
||||
// Copy constructor (except use this copy of unit_stats)
|
||||
combatant::combatant(const combatant &that, const battle_context::unit_stats &u)
|
||||
// Copy constructor (except use this copy of battle_context_unit_stats)
|
||||
combatant::combatant(const combatant &that, const battle_context_unit_stats &u)
|
||||
: hp_dist(that.hp_dist), untouched(that.untouched), poisoned(that.poisoned), slowed(that.slowed), u_(u), hit_chances_(that.hit_chances_)
|
||||
{
|
||||
summary[0] = that.summary[0];
|
||||
|
@ -27,10 +27,10 @@
|
||||
struct combatant
|
||||
{
|
||||
/** Construct a combatant. */
|
||||
combatant(const battle_context::unit_stats &u, const combatant *prev = NULL);
|
||||
combatant(const battle_context_unit_stats &u, const combatant *prev = NULL);
|
||||
|
||||
/** Copy constructor */
|
||||
combatant(const combatant &that, const battle_context::unit_stats &u);
|
||||
combatant(const combatant &that, const battle_context_unit_stats &u);
|
||||
|
||||
/** Simulate a fight! Can be called multiple times for cumulative calculations. */
|
||||
void fight(combatant &opponent, bool levelup_considered=true);
|
||||
@ -61,7 +61,7 @@ private:
|
||||
unsigned min_hp() const;
|
||||
|
||||
/** HP distribution we could end up with. */
|
||||
static unsigned hp_dist_size(const battle_context::unit_stats &u, const combatant *prev);
|
||||
static unsigned hp_dist_size(const battle_context_unit_stats &u, const combatant *prev);
|
||||
|
||||
/** Combat without chance of death, berserk, slow or drain is simple. */
|
||||
void no_death_fight(combatant &opponent);
|
||||
@ -75,7 +75,7 @@ private:
|
||||
/** We must adjust for swarm after every combat. */
|
||||
void adjust_hitchance();
|
||||
|
||||
const battle_context::unit_stats &u_;
|
||||
const battle_context_unit_stats &u_;
|
||||
|
||||
/** Usually uniform, but if we have swarm, then can be different. */
|
||||
std::vector<double> hit_chances_;
|
||||
|
@ -88,8 +88,8 @@ battle_prediction_pane::battle_prediction_pane(const battle_context &bc,
|
||||
combatant defender_combatant(bc.get_defender_stats());
|
||||
attacker_combatant.fight(defender_combatant);
|
||||
|
||||
const battle_context::unit_stats& attacker_stats = bc.get_attacker_stats();
|
||||
const battle_context::unit_stats& defender_stats = bc.get_defender_stats();
|
||||
const battle_context_unit_stats& attacker_stats = bc.get_attacker_stats();
|
||||
const battle_context_unit_stats& defender_stats = bc.get_defender_stats();
|
||||
|
||||
// Create the hitpoints distribution graphics.
|
||||
std::vector<std::pair<int, double> > hp_prob_vector;
|
||||
@ -141,7 +141,7 @@ battle_prediction_pane::battle_prediction_pane(const battle_context &bc,
|
||||
set_measurements(dialog_width_, dialog_height_);
|
||||
}
|
||||
|
||||
void battle_prediction_pane::get_unit_strings(const battle_context::unit_stats& stats,
|
||||
void battle_prediction_pane::get_unit_strings(const battle_context_unit_stats& stats,
|
||||
const unit& u, const map_location& u_loc, float u_unscathed,
|
||||
const unit& opp, const map_location& opp_loc, const attack_type *opp_weapon,
|
||||
std::vector<std::string>& left_strings, std::vector<std::string>& right_strings,
|
||||
@ -405,8 +405,8 @@ void battle_prediction_pane::draw_unit(int x_off, int damage_line_skip, int left
|
||||
}
|
||||
|
||||
void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<int, double> >& hp_prob_vector,
|
||||
const battle_context::unit_stats& stats,
|
||||
const battle_context::unit_stats& opp_stats,
|
||||
const battle_context_unit_stats& stats,
|
||||
const battle_context_unit_stats& opp_stats,
|
||||
surface& surf, int& width, int& height)
|
||||
{
|
||||
// Font size. If you change this, you must update the separator space.
|
||||
|
@ -73,7 +73,7 @@ private:
|
||||
|
||||
// This method builds the strings describing the unit damage modifiers.
|
||||
// Read the code to understand the arguments.
|
||||
void get_unit_strings(const battle_context::unit_stats& stats,
|
||||
void get_unit_strings(const battle_context_unit_stats& stats,
|
||||
const unit& u, const map_location& u_loc, float u_unscathed,
|
||||
const unit& opp, const map_location& opp_loc, const attack_type *opp_weapon,
|
||||
std::vector<std::string>& left_strings, std::vector<std::string>& right_strings,
|
||||
@ -103,8 +103,8 @@ private:
|
||||
// It draws the image in the surface 'surf' and set the width and
|
||||
// height of the image in the fields specified.
|
||||
void get_hp_distrib_surface(const std::vector<std::pair<int, double> >& hp_prob_vector,
|
||||
const battle_context::unit_stats& stats,
|
||||
const battle_context::unit_stats& opp_stats,
|
||||
const battle_context_unit_stats& stats,
|
||||
const battle_context_unit_stats& opp_stats,
|
||||
surface& surf, int& width, int& height);
|
||||
|
||||
// This method blends a RGB color. The method takes as input a surface,
|
||||
|
@ -104,10 +104,10 @@ static void set_weapon_info(twindow& window
|
||||
attack_type no_weapon(empty);
|
||||
|
||||
for (size_t i = 0; i < weapons.size(); ++i) {
|
||||
const battle_context::unit_stats& attacker =
|
||||
const battle_context_unit_stats& attacker =
|
||||
weapons[i].get_attacker_stats();
|
||||
|
||||
const battle_context::unit_stats& defender =
|
||||
const battle_context_unit_stats& defender =
|
||||
weapons[i].get_defender_stats();
|
||||
|
||||
const attack_type& attacker_weapon = attack_type(*attacker.weapon);
|
||||
|
@ -683,8 +683,8 @@ int mouse_handler::show_attack_dialog(const map_location& attacker_loc, const ma
|
||||
std::vector<std::string> items;
|
||||
|
||||
for (unsigned int i = 0; i < bc_vector.size(); i++) {
|
||||
const battle_context::unit_stats& att = bc_vector[i].get_attacker_stats();
|
||||
const battle_context::unit_stats& def = bc_vector[i].get_defender_stats();
|
||||
const battle_context_unit_stats& att = bc_vector[i].get_attacker_stats();
|
||||
const battle_context_unit_stats& def = bc_vector[i].get_defender_stats();
|
||||
config tmp_config;
|
||||
attack_type no_weapon(tmp_config);
|
||||
const attack_type& attw = attack_type(*att.weapon);
|
||||
@ -787,8 +787,8 @@ void mouse_handler::attack_enemy_(unit_map::iterator attacker, unit_map::iterato
|
||||
const map_location defender_loc = defender->get_location();
|
||||
|
||||
commands_disabled++;
|
||||
const battle_context::unit_stats &att = bc_vector[choice].get_attacker_stats();
|
||||
const battle_context::unit_stats &def = bc_vector[choice].get_defender_stats();
|
||||
const battle_context_unit_stats &att = bc_vector[choice].get_attacker_stats();
|
||||
const battle_context_unit_stats &def = bc_vector[choice].get_defender_stats();
|
||||
|
||||
attacker->set_goto(map_location());
|
||||
clear_undo_stack();
|
||||
|
Loading…
x
Reference in New Issue
Block a user