39 #define DBG_NG LOG_STREAM(debug, log_engine)
46 heal_unit(
unit &patient,
const std::vector<unit *> &treaters,
int healing,
55 std::vector<unit *> healers;
69 if ( status ==
"cured" )
72 if ( status ==
"slowed" )
85 std::vector<unit *> & healers)
93 if ( patient.
side() == side )
102 curing = std::max(curing, poison_status((*regen.first)[
"poison"]));
103 if ( curing == POISON_CURE )
114 POISON_STATUS this_cure = poison_status((*heal.first)[
"poison"]);
115 if ( this_cure <= curing )
122 assert(cure_it != units.
end());
123 const int cure_side = cure_it->side();
128 if ( teams[cure_side-1].is_enemy(side) )
132 if ( cure_side != side )
133 this_cure = POISON_SLOW;
137 if ( this_cure == POISON_CURE ) {
139 healers.push_back(&*cure_it);
149 if ( curer != units.
end() )
150 healers.push_back(&*curer);
160 inline bool update_healing(
int & healing,
int & harming,
int value)
163 if ( value > healing ) {
169 if ( value < harming ) {
181 int heal_amount(
int side,
const unit & patient, std::vector<unit *> & healers)
189 if ( patient.
side() == side )
192 update_healing(healing, harming,
198 update_healing(healing, harming, regen_effect.get_composite_value());
205 while ( heal_it != heal_list.
end() ) {
207 assert(healer != units.
end());
209 if ( healer->side() != side )
210 heal_it = heal_list.
erase(heal_it);
217 if ( update_healing(healing, harming, heal_effect.get_composite_value()) )
221 healers.push_back(&*units.
find(heal.loc));
223 if ( !healers.empty() ) {
224 DBG_NG <<
"Unit has " << healers.size() <<
" healers.\n";
228 return healing + harming;
235 void do_heal(
unit &patient,
int amount,
bool cure_poison)
240 patient.
heal(amount);
241 else if ( amount < 0 )
251 void animate_heals(std::list<heal_unit> &unit_list)
255 while ( !unit_list.empty() )
258 int min_dist = INT_MAX;
262 check_it != unit_list.end(); ++check_it )
265 if ( distance < min_dist ) {
275 if ( nearest->cure_poison )
277 _(
"female^cured") : _(
"cured");
281 nearest->amount, cure_text);
282 do_heal(nearest->healed, nearest->amount, nearest->cure_poison);
285 last_loc = nearest->healed.get_location();
286 unit_list.erase(nearest);
296 DBG_NG <<
"beginning of healing calculations\n";
298 std::list<heal_unit> unit_list;
304 if ( patient.
side() == side )
313 std::vector<unit *> healers;
317 if ( patient.
side() == side ) {
325 healing += heal_amount(side, patient, healers);
328 curing = poison_progress(side, patient, healers);
331 if ( curing == POISON_NORMAL && patient.
side() == side )
337 int min_heal = std::min(0, 1 - patient.
hitpoints());
338 if ( healing < min_heal )
340 else if ( healing > max_heal )
344 if ( curing != POISON_CURE && healing == 0 )
347 if (!healers.empty()) {
348 DBG_NG <<
"Just before healing animations, unit has " << healers.size() <<
" potential healers.\n";
351 const team & viewing_team =
356 unit_list.push_front(heal_unit(patient, healers, healing, curing == POISON_CURE));
361 do_heal(patient, healing, curing == POISON_CURE);
365 animate_heals(unit_list);
367 DBG_NG <<
"end of healing calculations\n";
void set_resting(bool rest)
play_controller * controller
bool is_visible_to_team(team const &team, gamemap const &map, bool const see_all=true) const
static lg::log_domain log_engine("engine")
const map_location & get_location() const
int max_hitpoints() const
bool get_state(const std::string &state) const
iterator erase(const iterator &erase_it)
void invalidate_unit()
Function to invalidate that unit status displayed on the sidebar.
void set_state(const std::string &state, bool value)
std::vector< unit_ability >::iterator iterator
static std::vector< team > *& teams
This class stores all the data for a single 'side' (in game nomenclature).
static UNUSEDNOWARN std::string _(const char *str)
bool incapacitated() const
std::vector< team > * teams
size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
GLsizei const GLfloat * value
void unit_healing(unit &healed, const std::vector< unit * > &healers, int healing, const std::string &extra_text)
This will use a poisoning anim if healing<0.
const std::string ¶meters float amount
Encapsulates the map of the game.
void calculate_healing(int side, bool update_display)
Calculates healing for all units for the given side.
std::pair< const config *, map_location > unit_ability
The things contained within a unit_ability_list.
bool take_hit(int damage)
Called on every draw.
unit_ability_list get_abilities(const std::string &tag_name, const map_location &loc) const
virtual const gamemap & map() const
Various functions that implement healing of units (when a side turn starts).
Standard logging facilities (interface).
Container associating units to locations.
size_t viewing_team() const
The viewing team is the team currently viewing the game.
unit_iterator find(size_t id)
GLsizei const GLcharARB ** string
Display units performing various actions: moving, attacking, and dying.