Skip to content

Instantly share code, notes, and snippets.

@vermie
Created August 25, 2010 02:30
Show Gist options
  • Save vermie/548726 to your computer and use it in GitHub Desktop.
Save vermie/548726 to your computer and use it in GitHub Desktop.
diff --git a/src/game/AggressorAI.cpp b/src/game/AggressorAI.cpp
index a5fed3e..0579836 100644
--- a/src/game/AggressorAI.cpp
+++ b/src/game/AggressorAI.cpp
@@ -48,7 +48,7 @@ AggressorAI::MoveInLineOfSight(Unit *u)
return;
if (m_creature->CanInitiateAttack() && u->isTargetableForAttack() &&
- m_creature->IsHostileTo(u) && u->isInAccessablePlaceFor(m_creature))
+ m_creature->IsHostileTo(u) && u->isInAccessiblePlaceFor(m_creature))
{
float attackRadius = m_creature->GetAttackDistance(u);
if(m_creature->IsWithinDistInMap(u, attackRadius) && m_creature->IsWithinLOSInMap(u) )
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index c63a58b..3e81c22 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -1769,7 +1769,7 @@ bool Creature::IsOutOfThreatArea(Unit* pVictim) const
if (!pVictim->isTargetableForAttack())
return true;
- if (!pVictim->isInAccessablePlaceFor(this))
+ if (!pVictim->isInAccessiblePlaceFor(this))
return true;
if (!pVictim->isVisibleForOrDetect(this,this,false))
@@ -1786,6 +1786,24 @@ bool Creature::IsOutOfThreatArea(Unit* pVictim) const
ThreatRadius > AttackDist ? ThreatRadius : AttackDist);
}
+bool Creature::IsFlyingInAir() const
+{
+ // creatures that can't fly never fly - just fall or something
+ if (!canFly())
+ return false;
+
+ float creatureZ = GetPositionZ();
+ float groundZ = GetBaseMap()->GetHeight(GetPositionX(), GetPositionY(), creatureZ);
+ float waterZ = GetBaseMap()->GetWaterLevel(GetPositionX(), GetPositionY());
+ float mapZ = groundZ > waterZ ? groundZ : waterZ;
+
+ // TODO: creature z attack range should be variable, like for giants?
+ if (creatureZ + CREATURE_Z_ATTACK_RANGE >= mapZ)
+ return true;
+
+ return false;
+}
+
CreatureDataAddon const* Creature::GetCreatureAddon() const
{
if (m_DBTableGuid)
diff --git a/src/game/Creature.h b/src/game/Creature.h
index 69d57e4..9455aba 100644
--- a/src/game/Creature.h
+++ b/src/game/Creature.h
@@ -422,6 +422,7 @@ class MANGOS_DLL_SPEC Creature : public Unit
bool isCanInteractWithBattleMaster(Player* player, bool msg) const;
bool isCanTrainingAndResetTalentsOf(Player* pPlayer) const;
bool IsOutOfThreatArea(Unit* pVictim) const;
+ bool IsFlyingInAir() const;
bool IsImmunedToSpell(SpellEntry const* spellInfo);
// redefine Unit::IsImmunedToSpell
bool IsImmunedToSpellEffect(SpellEntry const* spellInfo, SpellEffectIndex index) const;
diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp
index c8f261d..30b4bc1 100644
--- a/src/game/CreatureEventAI.cpp
+++ b/src/game/CreatureEventAI.cpp
@@ -1066,7 +1066,7 @@ void CreatureEventAI::MoveInLineOfSight(Unit *who)
return;
if (m_creature->CanInitiateAttack() && who->isTargetableForAttack() &&
- m_creature->IsHostileTo(who) && who->isInAccessablePlaceFor(m_creature))
+ m_creature->IsHostileTo(who) && who->isInAccessiblePlaceFor(m_creature))
{
if (!m_creature->canFly() && m_creature->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE)
return;
diff --git a/src/game/GuardAI.cpp b/src/game/GuardAI.cpp
index 5818bed..d828c0e 100644
--- a/src/game/GuardAI.cpp
+++ b/src/game/GuardAI.cpp
@@ -43,7 +43,7 @@ void GuardAI::MoveInLineOfSight(Unit *u)
if (!m_creature->getVictim() && u->isTargetableForAttack() &&
( u->IsHostileToPlayers() || m_creature->IsHostileTo(u) /*|| u->getVictim() && m_creature->IsFriendlyTo(u->getVictim())*/ ) &&
- u->isInAccessablePlaceFor(m_creature))
+ u->isInAccessiblePlaceFor(m_creature))
{
float attackRadius = m_creature->GetAttackDistance(u);
if (m_creature->IsWithinDistInMap(u,attackRadius))
diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp
index f243f74..3e436fc 100644
--- a/src/game/PetAI.cpp
+++ b/src/game/PetAI.cpp
@@ -54,7 +54,7 @@ void PetAI::MoveInLineOfSight(Unit *u)
return;
if (u->isTargetableForAttack() && m_creature->IsHostileTo( u ) &&
- u->isInAccessablePlaceFor(m_creature))
+ u->isInAccessiblePlaceFor(m_creature))
{
float attackRadius = m_creature->GetAttackDistance(u);
if(m_creature->IsWithinDistInMap(u, attackRadius) && m_creature->GetDistanceZ(u) <= CREATURE_Z_ATTACK_RANGE)
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index 0572c21..bda5c2f 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -21103,6 +21103,21 @@ bool Player::CanStartFlyInArea(uint32 mapid, uint32 zone, uint32 area) const
return true;
}
+bool Player::IsFlyingInAir() const
+{
+ // check for flying aura
+ if(!(IsFlying() || (HasAuraType(SPELL_AURA_FLY) || HasAuraType(SPELL_AURA_MOD_FLIGHT_SPEED))))
+ return false;
+
+ // player has flying aura, but may be close to the ground
+ float playerZ = GetPositionZ();
+ float groundZ = GetBaseMap()->GetHeight(GetPositionX(), GetPositionY(), playerZ);
+ float waterZ = GetBaseMap()->GetWaterLevel(GetPositionX(), GetPositionY());
+
+ // TODO: creature z attack range should be variable, like for giants?
+ return playerZ >= (std::max(groundZ, waterZ) + CREATURE_Z_ATTACK_RANGE);
+}
+
struct DoPlayerLearnSpell
{
DoPlayerLearnSpell(Player& _player) : player(_player) {}
diff --git a/src/game/Player.h b/src/game/Player.h
index 17e14b3..1918074 100644
--- a/src/game/Player.h
+++ b/src/game/Player.h
@@ -2238,6 +2238,7 @@ class MANGOS_DLL_SPEC Player : public Unit
bool CanFly() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_CAN_FLY); }
bool IsFlying() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_FLYING); }
bool IsFreeFlying() const { return HasAuraType(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED) || HasAuraType(SPELL_AURA_FLY); }
+ bool IsFlyingInAir() const;
bool CanStartFlyInArea(uint32 mapid, uint32 zone, uint32 area) const;
void SetClientControl(Unit* target, uint8 allowMove);
diff --git a/src/game/ThreatManager.cpp b/src/game/ThreatManager.cpp
index 61689ea..a4a60aa 100644
--- a/src/game/ThreatManager.cpp
+++ b/src/game/ThreatManager.cpp
@@ -140,7 +140,7 @@ void HostileReference::updateOnlineStatus()
!getTarget()->IsTaxiFlying()))
{
Creature* creature = (Creature* ) getSourceUnit();
- online = getTarget()->isInAccessablePlaceFor(creature);
+ online = getTarget()->isInAccessiblePlaceFor(creature);
if(!online)
{
if(creature->AI()->canReachByRangeAttack(getTarget()))
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index ee69f76..fd2011e 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -3604,10 +3604,12 @@ void Unit::SetFacingToObject(WorldObject* pObject)
SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_FACINGTARGET, ((Creature*)this)->GetSplineFlags(), 0, NULL, pObject->GetGUID());
}
-bool Unit::isInAccessablePlaceFor(Creature const* c) const
+bool Unit::isInAccessiblePlaceFor(Creature const* c) const
{
if(IsInWater())
return c->canSwim();
+ else if (IsFlyingInAir())
+ return c->canFly();
else
return c->canWalk() || c->canFly();
}
@@ -8398,7 +8400,7 @@ bool Unit::SelectHostileTarget()
{
--aura;
if ( (caster = (*aura)->GetCaster()) &&
- caster->IsInMap(this) && caster->isTargetableForAttack() && caster->isInAccessablePlaceFor((Creature*)this) )
+ caster->IsInMap(this) && caster->isTargetableForAttack() && caster->isInAccessiblePlaceFor((Creature*)this) )
{
target = caster;
break;
@@ -8433,7 +8435,7 @@ bool Unit::SelectHostileTarget()
{
for(AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr)
{
- if ((*itr)->IsInMap(this) && (*itr)->isTargetableForAttack() && (*itr)->isInAccessablePlaceFor((Creature*)this))
+ if ((*itr)->IsInMap(this) && (*itr)->isTargetableForAttack() && (*itr)->isInAccessiblePlaceFor((Creature*)this))
return false;
}
}
diff --git a/src/game/Unit.h b/src/game/Unit.h
index 4fda849..fd4314c 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -1394,7 +1394,8 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
virtual bool IsInWater() const;
virtual bool IsUnderWater() const;
- bool isInAccessablePlaceFor(Creature const* c) const;
+ virtual bool IsFlyingInAir() const = 0;
+ bool isInAccessiblePlaceFor(Creature const* c) const;
void SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, uint32 OverHeal, bool critical = false);
void SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage,Powers powertype);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment