38 #define DBG_AI_SIM_ACTIONS LOG_STREAM(debug, log_ai_sim_actions) 39 #define LOG_AI_SIM_ACTIONS LOG_STREAM(info, log_ai_sim_actions) 40 #define WRN_AI_SIM_ACTIONS LOG_STREAM(warn, log_ai_sim_actions) 41 #define ERR_AI_SIM_ACTIONS LOG_STREAM(err, log_ai_sim_actions) 54 << defend_unit->type_name() <<
" at " << defender_loc << std::endl;
55 LOG_AI_SIM_ACTIONS <<
"attacker's hp before attack: " << attack_unit->hitpoints() << std::endl;
56 LOG_AI_SIM_ACTIONS <<
"defender's hp before attack: " << defend_unit->hitpoints() << std::endl;
58 attack_unit->set_hitpoints(static_cast<int>(attacker_hp));
59 defend_unit->set_hitpoints(static_cast<int>(defender_hp));
61 LOG_AI_SIM_ACTIONS <<
"attacker's hp after attack: " << attack_unit->hitpoints() << std::endl;
62 LOG_AI_SIM_ACTIONS <<
"defender's hp after attack: " << defend_unit->hitpoints() << std::endl;
66 bool attacker_died =
false;
67 bool defender_died =
false;
68 if(attack_unit->hitpoints() <= 0){
75 if(defend_unit->hitpoints() <= 0){
83 attack_unit->set_experience(attack_unit->experience()+attacker_xp);
89 defend_unit->set_experience(defend_unit->experience()+defender_xp);
114 unit_location =
move_unit->get_location();
133 own_team.
spend_gold(recall_unit->recall_cost()<0 ? own_team.
recall_cost() : recall_unit->recall_cost());
136 << recall_location <<
" spend " << own_team.
recall_cost() <<
" gold" << std::endl;
150 << recruit_location <<
" spend " << u->
cost() <<
" gold" << std::endl;
159 bool changed =
false;
161 stop_unit->set_movement(0,
true);
162 LOG_AI_SIM_ACTIONS <<
"remove (" << stop_unit->get_location() <<
") " << stop_unit->type_name() <<
"'s movement" << std::endl;
166 stop_unit->set_attacks(0);
167 LOG_AI_SIM_ACTIONS <<
"remove (" << stop_unit->get_location() <<
") " << stop_unit->type_name() <<
"'s attacks" << std::endl;
177 DBG_AI_SIM_ACTIONS <<
"Trigger dummy synced_command_result::do_execute()" << std::endl;
185 team *
t =
static_cast<unsigned>(side - 1) < teams.size() ? &teams[side - 1] :
nullptr;
193 int old_owner_side = 0;
195 int i_side = std::distance(teams.begin(),
i) + 1;
196 if(!t || has_leader || t->
is_enemy(i_side)){
197 if(
i->owns_village(loc)){
198 old_owner_side = i_side;
199 i->lose_village(loc);
216 new_unit->set_movement(0,
true);
217 new_unit->set_attacks(0);
218 new_unit->heal_fully();
219 new_unit->set_location(loc);
240 const std::vector<std::string>&
options = advance_unit->advances_to();
241 std::vector<config> mod_options = advance_unit->get_modification_advances();
245 unit_ptr advanced_unit = (*advance_unit).clone();
247 if(advance_choice < options.size()){
248 std::string advance_unit_typename = options[advance_choice];
251 ERR_AI_SIM_ACTIONS <<
"Simulating advancing to unknown unit type: " << advance_unit_typename;
252 assert(
false &&
"simulating to unknown unit type");
254 advanced_unit->set_experience(advanced_unit->experience_overflow());
255 advanced_unit->advance_to(*advanced_type);
256 advanced_unit->heal_fully();
261 const config &mod_option = mod_options[advance_choice-options.size()];
262 advanced_unit->set_experience(advanced_unit->experience_overflow());
263 advanced_unit->add_modification(
"advancement", mod_option);
267 LOG_AI_SIM_ACTIONS << advance_unit->type_name() <<
" at " << loc <<
" advanced to " << advanced_unit->type_name() << std::endl;
bool simulated_synced_command()
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
virtual const std::vector< team > & teams() const override
virtual const unit_map & units() const override
This class represents a single unit of a specific type.
void helper_place_unit(const unit &u, const map_location &loc)
umap_retval_pair_t insert(unit_ptr p)
Inserts the unit pointed to by p into the map.
unit_iterator find_leader(int side)
bool will_certainly_advance(const unit_map::iterator &u)
Encapsulates the logic for deciding whether an iterator u points to a unit that can advance...
bool recall_unit(const std::string &id, team ¤t_team, const map_location &loc, const map_location &from, map_location::DIRECTION facing, bool show, bool use_undo)
Recalls the unit with the indicated ID for the provided team.
The unit is slowed - it moves slower and does less damage.
unit_type_data unit_types
The unit is poisoned - it loses health each turn.
#define DBG_AI_SIM_ACTIONS
bool simulated_attack(const map_location &attacker_loc, const map_location &defender_loc, double attacker_hp, double defender_hp)
std::shared_ptr< unit > unit_ptr
static unit_ptr create(const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
Initializes a unit from a config.
A single unit type that the player may recruit.
umap_retval_pair_t replace(const map_location &l, unit_ptr p)
Works like unit_map::add; but l is emptied first, if needed.
This class stores all the data for a single 'side' (in game nomenclature).
A small explanation about what's going on here: Each action has access to two game_info objects First...
bool simulated_recall(int side, const std::string &unit_id, const map_location &recall_location)
static lg::log_domain log_ai_sim_actions("ai/sim_actions")
const t_string & type_name() const
The name of the unit in the current language setting.
void erase(const std::string &key)
bool is_enemy(int n) const
umap_retval_pair_t move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
void spend_gold(const int amount)
Encapsulates the map of the game.
unit_iterator find(std::size_t id)
void advance_unit(map_location loc, const advancement_option &advance_to, bool fire_event)
Function which will advance the unit at loc to 'advance_to'.
void helper_check_village(const map_location &loc, int side)
#define ERR_AI_SIM_ACTIONS
void helper_advance_unit(const map_location &loc)
bool simulated_stopunit(const map_location &unit_location, bool remove_movement, bool remove_attacks)
int number_of_possible_advances(const unit &u)
Determines the total number of available advancements (of any kind) for a given unit.
int get_random_int(int min, int max)
This helper method provides a random int from the underlying generator, using results of next_random...
unit_ptr extract_if_matches_id(const std::string &unit_id, int *pos=nullptr)
Find a unit by id, and extract from this object if found.
rng * generator
This generator is automatically synced during synced context.
void recruit_unit(const unit_type &u_type, int side_num, const map_location &loc, const map_location &from, bool show, bool use_undo)
Recruits a unit of the given type for the given side.
game_events::pump_result_t get_village(const map_location &, const int owner_side, game_data *fire_event)
Acquires a village from owner_side.
bool simulated_move(int side, const map_location &from, const map_location &to, int steps, map_location &unit_location)
void attack_unit(const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display)
Performs an attack.
bool simulated_recruit(int side, const unit_type *u, const map_location &recruit_location)
Standard logging facilities (interface).
#define LOG_AI_SIM_ACTIONS
recall_list_manager & recall_list()
bool owns_village(const map_location &loc) const
A config object defines a single node in a WML file, with access to child nodes.
std::string::const_iterator iterator
void move_unit(const std::vector< map_location > &path, unit_ptr u, bool animate, map_location::DIRECTION dir, bool force_scroll)
Display a unit moving along a given path.
Implement simulated actions.