37 #define DBG_AI_SIM_ACTIONS LOG_STREAM(debug, log_ai_sim_actions)
38 #define LOG_AI_SIM_ACTIONS LOG_STREAM(info, log_ai_sim_actions)
39 #define WRN_AI_SIM_ACTIONS LOG_STREAM(warn, log_ai_sim_actions)
40 #define ERR_AI_SIM_ACTIONS LOG_STREAM(err, log_ai_sim_actions)
53 << defend_unit->type_name() <<
" at " << defender_loc << std::endl;
54 LOG_AI_SIM_ACTIONS <<
"attacker's hp before attack: " << attack_unit->hitpoints() << std::endl;
55 LOG_AI_SIM_ACTIONS <<
"defender's hp before attack: " << defend_unit->hitpoints() << std::endl;
57 attack_unit->set_hitpoints(static_cast<int>(attacker_hp));
58 defend_unit->set_hitpoints(static_cast<int>(defender_hp));
60 LOG_AI_SIM_ACTIONS <<
"attacker's hp after attack: " << attack_unit->hitpoints() << std::endl;
61 LOG_AI_SIM_ACTIONS <<
"defender's hp after attack: " << defend_unit->hitpoints() << std::endl;
63 int attacker_xp = defend_unit->level();
64 int defender_xp = attack_unit->level();
65 bool attacker_died =
false;
66 bool defender_died =
false;
67 if(attack_unit->hitpoints() <= 0){
70 (*resources::units).erase(attacker_loc);
74 if(defend_unit->hitpoints() <= 0){
77 (*resources::units).erase(defender_loc);
82 attack_unit->set_experience(attack_unit->experience()+attacker_xp);
88 defend_unit->set_experience(defend_unit->experience()+defender_xp);
101 bool is_ok = unit_move.second;
109 move_unit->set_movement(move_unit->movement_left()-steps);
111 unit_location = move_unit->get_location();
113 LOG_AI_SIM_ACTIONS << move_unit->type_name() <<
" move from " << from <<
" to " << to << std::endl;
125 team own_team = (*resources::teams)[side-1];
130 own_team.
spend_gold(recall_unit->recall_cost()<0 ? own_team.
recall_cost() : recall_unit->recall_cost());
133 << recall_location <<
" spend " << own_team.
recall_cost() <<
" gold" << std::endl;
144 (*resources::teams)[side-1].spend_gold(u->
cost());
147 << recruit_location <<
" spend " << u->
cost() <<
" gold" << std::endl;
156 bool changed =
false;
158 stop_unit->set_movement(0,
true);
159 LOG_AI_SIM_ACTIONS <<
"remove (" << stop_unit->get_location() <<
") " << stop_unit->type_name() <<
"'s movement" << std::endl;
163 stop_unit->set_attacks(0);
164 LOG_AI_SIM_ACTIONS <<
"remove (" << stop_unit->get_location() <<
") " << stop_unit->type_name() <<
"'s attacks" << std::endl;
174 DBG_AI_SIM_ACTIONS <<
"Trigger dummy synced_command_result::do_execute()" << std::endl;
182 team *
t = unsigned(side - 1) < teams.size() ? &teams[side - 1] :
nullptr;
190 int old_owner_side = 0;
192 int i_side =
i - teams.begin() + 1;
193 if(!t || has_leader || t->
is_enemy(i_side)){
194 if(
i->owns_village(loc)){
195 old_owner_side = i_side;
196 i->lose_village(loc);
218 assert(add_result.second);
237 const std::vector<std::string>&
options = advance_unit->advances_to();
238 std::vector<config> mod_options = advance_unit->get_modification_advances();
241 size_t advance_choice = rand() % options_num;
242 unit advanced_unit(*advance_unit);
244 if(advance_choice < options.size()){
245 std::string advance_unit_typename = options[advance_choice];
248 ERR_AI_SIM_ACTIONS <<
"Simulating advancing to unknown unit type: " << advance_unit_typename;
249 assert(
false &&
"simulating to unknown unit type");
258 const config &mod_option = mod_options[advance_choice-options.size()];
void advance_unit(map_location loc, const std::string &advance_to, const bool &fire_event, const config *mod_option)
Function which will advance the unit at loc to 'advance_to'.
bool simulated_synced_command()
const t_string & type_name() const
The name of the unit in the current language setting.
const t_string & type_name() const
The unit type name.
void helper_place_unit(const unit &u, const map_location &loc)
unit_iterator find_leader(int side)
bool owns_village(const map_location &loc) const
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 is_enemy(int n) const
void advance_to(const unit_type &t, bool use_traits=false)
Advances this unit to another type.
unit_type_data unit_types
#define DBG_AI_SIM_ACTIONS
void set_state(const std::string &state, bool value)
bool simulated_attack(const map_location &attacker_loc, const map_location &defender_loc, double attacker_hp, double defender_hp)
unit_ptr extract_if_matches_id(const std::string &unit_id)
Find a unit by id, and extract from this object if found. Null if not found.
static std::vector< team > *& teams
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...
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.
bool simulated_recall(int side, const std::string &unit_id, const map_location &recall_location)
std::vector< team > * teams
static lg::log_domain log_ai_sim_actions("ai/sim_actions")
void spend_gold(const int amount)
std::pair< unit_iterator, bool > replace(const map_location &l, const unit &u)
Works like unit_map::add; but l is emptied first, if needed.
std::pair< unit_iterator, bool > add(const map_location &l, const unit &u)
Adds a copy of unit u at location l of the map.
Encapsulates the map of the game.
void helper_check_village(const map_location &loc, int side)
void add_modification(const std::string &type, const config &modification, bool no_add=false)
#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)
void set_movement(int moves, bool unit_action=false)
Set the unit's remaining movement to moves.
int number_of_possible_advances(const unit &u)
Determines the total number of available advancements (of any kind) for a given unit.
std::pair< unit_iterator, bool > move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
int max_experience() const
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
bool recall_unit(const std::string &id, team ¤t_team, const map_location &loc, const map_location &from, bool show, bool use_undo)
Recalls the unit with the indicated ID for the provided team.
recall_list_manager & recall_list()
void set_attacks(int left)
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.
unit_iterator find(size_t id)
A config object defines a single node in a WML file, with access to child nodes.
void set_experience(int xp)
GLsizei const GLcharARB ** string
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 get_village(const map_location &, const int owner_side, game_data *fire_event)
Acquires a village from owner_side. Pointer fire_event should be the game_data for the game if it is ...
Implement simulated actions.