39 #define DBG_AI_SIM_ACTIONS LOG_STREAM(debug, log_ai_sim_actions)
40 #define LOG_AI_SIM_ACTIONS LOG_STREAM(info, log_ai_sim_actions)
41 #define WRN_AI_SIM_ACTIONS LOG_STREAM(warn, log_ai_sim_actions)
42 #define ERR_AI_SIM_ACTIONS LOG_STREAM(err, log_ai_sim_actions)
55 << defend_unit->type_name() <<
" at " << defender_loc;
59 attack_unit->set_hitpoints(
static_cast<int>(attacker_hp));
60 defend_unit->set_hitpoints(
static_cast<int>(defender_hp));
67 bool attacker_died =
false;
68 bool defender_died =
false;
76 if(defend_unit->hitpoints() <= 0){
90 defend_unit->set_experience(defend_unit->experience()+defender_xp);
115 unit_location =
move_unit->get_location();
137 << recall_location <<
" spend " << own_team.
recall_cost() <<
" gold";
151 << recruit_location <<
" spend " << u->
cost() <<
" gold";
160 bool changed =
false;
162 stop_unit->set_movement(0,
true);
163 LOG_AI_SIM_ACTIONS <<
"remove (" << stop_unit->get_location() <<
") " << stop_unit->type_name() <<
"'s movement";
167 stop_unit->set_attacks(0);
168 LOG_AI_SIM_ACTIONS <<
"remove (" << stop_unit->get_location() <<
") " << stop_unit->type_name() <<
"'s attacks";
186 team *
t =
static_cast<unsigned>(side - 1) < teams.size() ? &teams[side - 1] :
nullptr;
187 if(
t &&
t->owns_village(loc)){
194 int old_owner_side = 0;
195 for(
team& tm : teams) {
196 int i_side = tm.side();
197 if(!
t || has_leader ||
t->is_enemy(i_side)){
198 if(tm.owns_village(loc)){
199 old_owner_side = i_side;
200 tm.lose_village(loc);
210 t->get_village(loc, old_owner_side,
nullptr);
217 new_unit->set_movement(0,
true);
218 new_unit->set_attacks(0);
219 new_unit->heal_fully();
220 new_unit->set_location(loc);
241 const std::vector<std::string>& options =
advance_unit->advances_to();
242 std::vector<config> mod_options =
advance_unit->get_modification_advances();
246 unit_ptr advanced_unit = (*advance_unit).clone();
248 if(advance_choice < options.size()){
249 std::string advance_unit_typename = options[advance_choice];
252 ERR_AI_SIM_ACTIONS <<
"Simulating advancing to unknown unit type: " << advance_unit_typename;
255 advanced_unit->set_experience(advanced_unit->experience_overflow());
256 advanced_unit->advance_to(*advanced_type);
257 advanced_unit->heal_fully();
262 const config &mod_option = mod_options[advance_choice-options.size()];
263 advanced_unit->set_experience(advanced_unit->experience_overflow());
264 advanced_unit->add_modification(
"advancement", mod_option);
void attack_unit(const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display)
Performs an attack.
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'.
A config object defines a single node in a WML file, with access to child nodes.
virtual const std::vector< team > & teams() const override
virtual const unit_map & units() const override
int get_random_int(int min, int max)
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.
This class stores all the data for a single 'side' (in game nomenclature).
void spend_gold(const int amount)
recall_list_manager & recall_list()
umap_retval_pair_t replace(const map_location &l, unit_ptr p)
Works like unit_map::add; but l is emptied first, if needed.
unit_iterator find(std::size_t id)
unit_iterator find_leader(int side)
umap_retval_pair_t insert(unit_ptr p)
Inserts the unit pointed to by p into the map.
umap_retval_pair_t move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
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.
A single unit type that the player may recruit.
const t_string & type_name() const
The name of the unit in the current language setting.
This class represents a single unit of a specific type.
static unit_ptr create(const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
Initializes a unit from a config.
@ STATE_PETRIFIED
The unit is poisoned - it loses health each turn.
@ STATE_POISONED
The unit is slowed - it moves slower and does less damage.
Standard logging facilities (interface).
bool recall_unit(const std::string &id, team ¤t_team, const map_location &loc, const map_location &from, map_location::direction facing)
Recalls the unit with the indicated ID for the provided team.
void recruit_unit(const unit_type &u_type, int side_num, const map_location &loc, const map_location &from)
Recruits a unit of the given type for the given side.
A small explanation about what's going on here: Each action has access to two game_info objects First...
bool simulated_attack(const map_location &attacker_loc, const map_location &defender_loc, double attacker_hp, double defender_hp)
bool simulated_stopunit(const map_location &unit_location, bool remove_movement, bool remove_attacks)
void helper_check_village(const map_location &loc, int side)
void helper_place_unit(const unit &u, const map_location &loc)
bool simulated_move(int side, const map_location &from, const map_location &to, int steps, map_location &unit_location)
bool simulated_recruit(int side, const unit_type *u, const map_location &recruit_location)
bool simulated_synced_command()
static lg::log_domain log_ai_sim_actions("ai/sim_actions")
bool simulated_recall(int side, const std::string &unit_id, const map_location &recall_location)
void helper_advance_unit(const map_location &loc)
rng * generator
This generator is automatically synced during synced context.
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.
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.
int number_of_possible_advances(const unit &u)
Determines the total number of available advancements (of any kind) for a given unit.
std::string & erase(std::string &str, const std::size_t start, const std::size_t len)
Erases a portion of a UTF-8 string.
std::shared_ptr< unit > unit_ptr
#define DBG_AI_SIM_ACTIONS
#define ERR_AI_SIM_ACTIONS
#define LOG_AI_SIM_ACTIONS
Implement simulated actions.
Encapsulates the map of the game.
unit_type_data unit_types