From b49d7779c9cd8793a264846145327c50a05c3b7e Mon Sep 17 00:00:00 2001 From: "J. Tyne" Date: Mon, 27 Aug 2012 13:14:06 +0000 Subject: [PATCH] Sync healing with the animation. --- src/actions/heal.cpp | 47 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/actions/heal.cpp b/src/actions/heal.cpp index 6d15dfaa057..90d5a70adf9 100644 --- a/src/actions/heal.cpp +++ b/src/actions/heal.cpp @@ -43,20 +43,24 @@ namespace { // Contains the data needed to display healing. struct heal_unit { - heal_unit(unit &patient, const std::vector &treaters, int healing) : + heal_unit(unit &patient, const std::vector &treaters, int healing, + bool poison) : healed(patient), healers(treaters), - amount(healing) + amount(healing), + cure_poison(poison) {} unit & healed; std::vector healers; int amount; + bool cure_poison; }; // Keep these ordered from weakest cure to strongest cure. enum POISON_STATUS { POISON_NORMAL, POISON_SLOW , POISON_CURE }; + /** * Converts a string into its corresponding POISON_STATUS. */ @@ -75,7 +79,7 @@ namespace { /** * Determines if @a patient is affected by anything that impacts poison. - * If cured by a unit, that unit is returned through (added to) @a healers. + * If cured by a unit, that unit is added to @a healers. */ POISON_STATUS poison_progress(int side, const unit & patient, std::vector & healers) @@ -151,7 +155,7 @@ namespace { /** * Calculate how much @patient heals this turn. - * If cured by units, those units are returned through (added to) @a healers. + * If healed by units, those units are added to @a healers. */ int heal_amount(int side, const unit & patient, std::vector & healers) { @@ -204,6 +208,21 @@ namespace { } + /** + * Handles the actual healing. + */ + void do_heal(unit &patient, int amount, bool cure_poison) + { + if ( cure_poison ) + patient.set_state(unit::STATE_POISONED, false); + if ( amount > 0) + patient.heal(amount); + else if ( amount < 0 ) + patient.take_hit(-amount); + resources::screen->invalidate_unit(); + } + + /** * Animates the healings in the provided list. * (The list will be empty when this returns.) @@ -231,9 +250,13 @@ namespace { } } - last_loc = nearest->healed.get_location(); + // The heal (animated, then actual): unit_display::unit_healing(nearest->healed, nearest->healers, nearest->amount); + do_heal(nearest->healed, nearest->amount, nearest->cure_poison); + + // Update the loop variables. + last_loc = nearest->healed.get_location(); unit_list.erase(nearest); } } @@ -303,15 +326,13 @@ void calculate_healing(int side, bool update_display) if (!recorder.is_skipping() && update_display && patient.is_visible_to_team(viewing_team, false) ) { - unit_list.push_front(heal_unit(patient, healers, healing)); + unit_list.push_front(heal_unit(patient, healers, healing, curing == POISON_CURE)); + } + else + { + // Do the healing now since it will not be animated. + do_heal(patient, healing, curing == POISON_CURE); } - if ( curing == POISON_CURE ) - patient.set_state(unit::STATE_POISONED, false); - if (healing > 0) - patient.heal(healing); - else if (healing < 0) - patient.take_hit(-healing); - resources::screen->invalidate_unit(); } animate_heals(unit_list);