* add helping methods for manipulating unit's health and use it where applicable
* fix some conversion warnings and cleanup code (formatting, CRLF, tabs to spaces)

--HG--
branch : trunk
This commit is contained in:
azazel
2010-08-26 01:20:57 +06:00
parent bb5f7b6492
commit 341e6303ef
166 changed files with 445 additions and 416 deletions
@@ -153,7 +153,8 @@ struct ScriptedAI : public CreatureAI
//Selects a unit from the creature's current aggro list
Unit* SelectUnit(SelectAggroTarget pTarget, uint32 uiPosition);
bool HealthBelowPct(uint64 pct) const { return me->GetHealth() * 100 < me->GetMaxHealth() * pct; }
bool HealthBelowPct(uint32 pct) const { return me->HealthBelowPct(pct); }
bool HealthAbovePct(uint32 pct) const { return me->HealthAbovePct(pct); }
//Returns spells that meet the specified criteria from the creatures spell list
SpellEntry const* SelectSpell(Unit* Target, uint32 School, uint32 Mechanic, SelectTargetType Targets, uint32 PowerCostMin, uint32 PowerCostMax, float RangeMin, float RangeMax, SelectEffect Effect);
@@ -103,7 +103,7 @@ void guardAI::UpdateAI(const uint32 diff)
SpellEntry const *info = NULL;
//Select a healing spell if less than 30% hp
if (me->GetHealth()*100 / me->GetMaxHealth() < 30)
if (HealthBelowPct(30))
info = SelectSpell(me, 0, 0, SELECT_TARGET_ANY_FRIEND, 0, 0, 0, 0, SELECT_EFFECT_HEALING);
//No healing spell available, select a hostile spell
@@ -134,7 +134,7 @@ void guardAI::UpdateAI(const uint32 diff)
SpellEntry const *info = NULL;
//Select a healing spell if less than 30% hp ONLY 33% of the time
if (me->GetHealth()*100 / me->GetMaxHealth() < 30 && rand() % 3 == 0)
if (HealthBelowPct(30) && rand() % 3 == 0)
info = SelectSpell(me, 0, 0, SELECT_TARGET_ANY_FRIEND, 0, 0, 0, 0, SELECT_EFFECT_HEALING);
//No healing spell available, See if we can cast a ranged spell (Range must be greater than ATTACK_DISTANCE)
@@ -214,7 +214,7 @@ void SimpleAI::UpdateAI(const uint32 diff)
if (Spell_Timer[i] <= diff)
{
//Check if this is a percentage based
if (Spell[i].First_Cast < 0 && Spell[i].First_Cast > -100 && me->GetHealth()*100 / me->GetMaxHealth() > uint32(-Spell[i].First_Cast))
if (Spell[i].First_Cast < 0 && Spell[i].First_Cast > -100 && HealthAbovePct(uint32(-Spell[i].First_Cast)))
continue;
//Check Current spell