Core/AI: variable naming standarization

plus minimum codestyle changes
This commit is contained in:
ccrs
2019-05-15 01:33:55 +02:00
parent 7025b00656
commit 179c7da1fc
19 changed files with 329 additions and 296 deletions

View File

@@ -57,31 +57,31 @@ void CombatAI::InitializeAI()
{
for (uint32 i = 0; i < MAX_CREATURE_SPELLS; ++i)
if (me->m_spells[i] && sSpellMgr->GetSpellInfo(me->m_spells[i]))
spells.push_back(me->m_spells[i]);
Spells.push_back(me->m_spells[i]);
CreatureAI::InitializeAI();
}
void CombatAI::Reset()
{
events.Reset();
Events.Reset();
}
void CombatAI::JustDied(Unit* killer)
{
for (SpellVct::iterator i = spells.begin(); i != spells.end(); ++i)
for (SpellVector::iterator i = Spells.begin(); i != Spells.end(); ++i)
if (AISpellInfo[*i].condition == AICOND_DIE)
me->CastSpell(killer, *i, true);
}
void CombatAI::JustEngagedWith(Unit* who)
{
for (SpellVct::iterator i = spells.begin(); i != spells.end(); ++i)
for (SpellVector::iterator i = Spells.begin(); i != Spells.end(); ++i)
{
if (AISpellInfo[*i].condition == AICOND_AGGRO)
me->CastSpell(who, *i, false);
else if (AISpellInfo[*i].condition == AICOND_COMBAT)
events.ScheduleEvent(*i, AISpellInfo[*i].cooldown + rand32() % AISpellInfo[*i].cooldown);
Events.ScheduleEvent(*i, AISpellInfo[*i].cooldown + rand32() % AISpellInfo[*i].cooldown);
}
}
@@ -90,15 +90,15 @@ void CombatAI::UpdateAI(uint32 diff)
if (!UpdateVictim())
return;
events.Update(diff);
Events.Update(diff);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
if (uint32 spellId = events.ExecuteEvent())
if (uint32 spellId = Events.ExecuteEvent())
{
DoCast(spellId);
events.ScheduleEvent(spellId, AISpellInfo[spellId].cooldown + rand32() % AISpellInfo[spellId].cooldown);
Events.ScheduleEvent(spellId, AISpellInfo[spellId].cooldown + rand32() % AISpellInfo[spellId].cooldown);
}
else
DoMeleeAttackIfReady();
@@ -106,7 +106,7 @@ void CombatAI::UpdateAI(uint32 diff)
void CombatAI::SpellInterrupted(uint32 spellId, uint32 unTimeMs)
{
events.RescheduleEvent(spellId, unTimeMs);
Events.RescheduleEvent(spellId, unTimeMs);
}
/////////////////
@@ -117,22 +117,22 @@ void CasterAI::InitializeAI()
{
CombatAI::InitializeAI();
m_attackDist = 30.0f;
for (SpellVct::iterator itr = spells.begin(); itr != spells.end(); ++itr)
if (AISpellInfo[*itr].condition == AICOND_COMBAT && m_attackDist > GetAISpellInfo(*itr)->maxRange)
m_attackDist = GetAISpellInfo(*itr)->maxRange;
if (m_attackDist == 30.0f)
m_attackDist = MELEE_RANGE;
_attackDistance = 30.0f;
for (SpellVector::iterator itr = Spells.begin(); itr != Spells.end(); ++itr)
if (AISpellInfo[*itr].condition == AICOND_COMBAT && _attackDistance > GetAISpellInfo(*itr)->maxRange)
_attackDistance = GetAISpellInfo(*itr)->maxRange;
if (_attackDistance == 30.0f)
_attackDistance = MELEE_RANGE;
}
void CasterAI::JustEngagedWith(Unit* who)
{
if (spells.empty())
if (Spells.empty())
return;
uint32 spell = rand32() % spells.size();
uint32 spell = rand32() % Spells.size();
uint32 count = 0;
for (SpellVct::iterator itr = spells.begin(); itr != spells.end(); ++itr, ++count)
for (SpellVector::iterator itr = Spells.begin(); itr != Spells.end(); ++itr, ++count)
{
if (AISpellInfo[*itr].condition == AICOND_AGGRO)
me->CastSpell(who, *itr, false);
@@ -141,10 +141,10 @@ void CasterAI::JustEngagedWith(Unit* who)
uint32 cooldown = GetAISpellInfo(*itr)->realCooldown;
if (count == spell)
{
DoCast(spells[spell]);
DoCast(Spells[spell]);
cooldown += me->GetCurrentSpellCastTime(*itr);
}
events.ScheduleEvent(*itr, cooldown);
Events.ScheduleEvent(*itr, cooldown);
}
}
}
@@ -154,7 +154,7 @@ void CasterAI::UpdateAI(uint32 diff)
if (!UpdateVictim())
return;
events.Update(diff);
Events.Update(diff);
if (me->GetVictim() && me->EnsureVictim()->HasBreakableByDamageCrowdControlAura(me))
{
@@ -165,11 +165,11 @@ void CasterAI::UpdateAI(uint32 diff)
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
if (uint32 spellId = events.ExecuteEvent())
if (uint32 spellId = Events.ExecuteEvent())
{
DoCast(spellId);
uint32 casttime = me->GetCurrentSpellCastTime(spellId);
events.ScheduleEvent(spellId, (casttime ? casttime : 500) + GetAISpellInfo(spellId)->realCooldown);
Events.ScheduleEvent(spellId, (casttime ? casttime : 500) + GetAISpellInfo(spellId)->realCooldown);
}
}
@@ -183,10 +183,10 @@ ArcherAI::ArcherAI(Creature* c) : CreatureAI(c)
TC_LOG_ERROR("misc", "ArcherAI set for creature (entry = %u) with spell1=0. AI will do nothing", me->GetEntry());
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(me->m_spells[0]);
m_minRange = spellInfo ? spellInfo->GetMinRange(false) : 0;
_minimumRange = spellInfo ? spellInfo->GetMinRange(false) : 0;
if (!m_minRange)
m_minRange = MELEE_RANGE;
if (!_minimumRange)
_minimumRange = MELEE_RANGE;
me->m_CombatDistance = spellInfo ? spellInfo->GetMaxRange(false) : 0;
me->m_SightDistance = me->m_CombatDistance;
}
@@ -196,7 +196,7 @@ void ArcherAI::AttackStart(Unit* who)
if (!who)
return;
if (me->IsWithinCombatRange(who, m_minRange))
if (me->IsWithinCombatRange(who, _minimumRange))
{
if (me->Attack(who, true) && !who->IsFlying())
me->GetMotionMaster()->MoveChase(who);
@@ -216,7 +216,7 @@ void ArcherAI::UpdateAI(uint32 /*diff*/)
if (!UpdateVictim())
return;
if (!me->IsWithinCombatRange(me->GetVictim(), m_minRange))
if (!me->IsWithinCombatRange(me->GetVictim(), _minimumRange))
DoSpellAttackIfReady(me->m_spells[0]);
else
DoMeleeAttackIfReady();
@@ -232,7 +232,7 @@ TurretAI::TurretAI(Creature* c) : CreatureAI(c)
TC_LOG_ERROR("misc", "TurretAI set for creature (entry = %u) with spell1=0. AI will do nothing", me->GetEntry());
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(me->m_spells[0]);
m_minRange = spellInfo ? spellInfo->GetMinRange(false) : 0;
_minimumRange = spellInfo ? spellInfo->GetMinRange(false) : 0;
me->m_CombatDistance = spellInfo ? spellInfo->GetMaxRange(false) : 0;
me->m_SightDistance = me->m_CombatDistance;
}
@@ -241,7 +241,7 @@ bool TurretAI::CanAIAttack(Unit const* who) const
{
/// @todo use one function to replace it
if (!me->IsWithinCombatRange(who, me->m_CombatDistance)
|| (m_minRange && me->IsWithinCombatRange(who, m_minRange)))
|| (_minimumRange && me->IsWithinCombatRange(who, _minimumRange)))
return false;
return true;
}
@@ -264,11 +264,11 @@ void TurretAI::UpdateAI(uint32 /*diff*/)
// VehicleAI
//////////////
VehicleAI::VehicleAI(Creature* creature) : CreatureAI(creature), m_HasConditions(false), m_ConditionsTimer(VEHICLE_CONDITION_CHECK_TIME)
VehicleAI::VehicleAI(Creature* creature) : CreatureAI(creature), _hasConditions(false), _conditionsTimer(VEHICLE_CONDITION_CHECK_TIME)
{
LoadConditions();
m_DoDismiss = false;
m_DismissTimer = VEHICLE_DISMISS_TIME;
_dismiss = false;
_dismissTimer = VEHICLE_DISMISS_TIME;
}
// NOTE: VehicleAI::UpdateAI runs even while the vehicle is mounted
@@ -276,42 +276,42 @@ void VehicleAI::UpdateAI(uint32 diff)
{
CheckConditions(diff);
if (m_DoDismiss)
if (_dismiss)
{
if (m_DismissTimer < diff)
if (_dismissTimer < diff)
{
m_DoDismiss = false;
_dismiss = false;
me->DespawnOrUnsummon();
}
else
m_DismissTimer -= diff;
_dismissTimer -= diff;
}
}
void VehicleAI::OnCharmed(bool /*isNew*/)
{
bool const charmed = me->IsCharmed();
if (!me->GetVehicleKit()->IsVehicleInUse() && !charmed && m_HasConditions) // was used and has conditions
if (!me->GetVehicleKit()->IsVehicleInUse() && !charmed && _hasConditions) // was used and has conditions
{
m_DoDismiss = true; // needs reset
_dismiss = true; // needs reset
}
else if (charmed)
m_DoDismiss = false; // in use again
_dismiss = false; // in use again
m_DismissTimer = VEHICLE_DISMISS_TIME; // reset timer
_dismissTimer = VEHICLE_DISMISS_TIME; // reset timer
}
void VehicleAI::LoadConditions()
{
m_HasConditions = sConditionMgr->HasConditionsForNotGroupedEntry(CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, me->GetEntry());
_hasConditions = sConditionMgr->HasConditionsForNotGroupedEntry(CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, me->GetEntry());
}
void VehicleAI::CheckConditions(uint32 diff)
{
if (!m_HasConditions)
if (!_hasConditions)
return;
if (m_ConditionsTimer <= diff)
if (_conditionsTimer <= diff)
{
if (Vehicle* vehicleKit = me->GetVehicleKit())
{
@@ -329,10 +329,10 @@ void VehicleAI::CheckConditions(uint32 diff)
}
}
m_ConditionsTimer = VEHICLE_CONDITION_CHECK_TIME;
_conditionsTimer = VEHICLE_CONDITION_CHECK_TIME;
}
else
m_ConditionsTimer -= diff;
_conditionsTimer -= diff;
}
int32 VehicleAI::Permissible(Creature const* creature)

View File

@@ -32,7 +32,7 @@ class TC_GAME_API AggressorAI : public CreatureAI
static int32 Permissible(Creature const* creature);
};
typedef std::vector<uint32> SpellVct;
typedef std::vector<uint32> SpellVector;
class TC_GAME_API CombatAI : public CreatureAI
{
@@ -49,20 +49,20 @@ class TC_GAME_API CombatAI : public CreatureAI
static int Permissible(Creature const* /*creature*/) { return PERMIT_BASE_NO; }
protected:
EventMap events;
SpellVct spells;
EventMap Events;
SpellVector Spells;
};
class TC_GAME_API CasterAI : public CombatAI
{
public:
explicit CasterAI(Creature* c) : CombatAI(c) { m_attackDist = MELEE_RANGE; }
explicit CasterAI(Creature* c) : CombatAI(c) { _attackDistance = MELEE_RANGE; }
void InitializeAI() override;
void AttackStart(Unit* victim) override { AttackStartCaster(victim, m_attackDist); }
void AttackStart(Unit* victim) override { AttackStartCaster(victim, _attackDistance); }
void UpdateAI(uint32 diff) override;
void JustEngagedWith(Unit* /*who*/) override;
private:
float m_attackDist;
float _attackDistance;
};
struct TC_GAME_API ArcherAI : public CreatureAI
@@ -75,7 +75,7 @@ struct TC_GAME_API ArcherAI : public CreatureAI
static int32 Permissible(Creature const* /*creature*/) { return PERMIT_BASE_NO; }
protected:
float m_minRange;
float _minimumRange;
};
struct TC_GAME_API TurretAI : public CreatureAI
@@ -89,7 +89,7 @@ struct TC_GAME_API TurretAI : public CreatureAI
static int32 Permissible(Creature const* /*creature*/) { return PERMIT_BASE_NO; }
protected:
float m_minRange;
float _minimumRange;
};
#define VEHICLE_CONDITION_CHECK_TIME 1000
@@ -110,10 +110,11 @@ struct TC_GAME_API VehicleAI : public CreatureAI
private:
void LoadConditions();
void CheckConditions(uint32 diff);
bool m_HasConditions;
uint32 m_ConditionsTimer;
bool m_DoDismiss;
uint32 m_DismissTimer;
bool _hasConditions;
uint32 _conditionsTimer;
bool _dismiss;
uint32 _dismissTimer;
};
#endif

View File

@@ -44,14 +44,14 @@ int32 PetAI::Permissible(Creature const* creature)
return PERMIT_BASE_NO;
}
PetAI::PetAI(Creature* c) : CreatureAI(c), i_tracker(TIME_INTERVAL_LOOK)
PetAI::PetAI(Creature* c) : CreatureAI(c), _tracker(TIME_INTERVAL_LOOK)
{
if (!me->GetCharmInfo())
throw InvalidAIException("Creature doesn't have a valid charm info");
UpdateAllies();
}
bool PetAI::_needToStop()
bool PetAI::NeedToStop()
{
// This is needed for charmed creatures, as once their target was reset other effects can trigger threat
if (me->IsCharmed() && me->GetVictim() == me->GetCharmer())
@@ -65,7 +65,7 @@ bool PetAI::_needToStop()
return !me->IsValidAttackTarget(me->GetVictim());
}
void PetAI::_stopAttack()
void PetAI::StopAttack()
{
if (!me->IsAlive())
{
@@ -89,11 +89,11 @@ void PetAI::UpdateAI(uint32 diff)
Unit* owner = me->GetCharmerOrOwner();
if (m_updateAlliesTimer <= diff)
if (_updateAlliesTimer <= diff)
// UpdateAllies self set update timer
UpdateAllies();
else
m_updateAlliesTimer -= diff;
_updateAlliesTimer -= diff;
if (me->GetVictim() && me->EnsureVictim()->IsAlive())
{
@@ -105,10 +105,10 @@ void PetAI::UpdateAI(uint32 diff)
return;
}
if (_needToStop())
if (NeedToStop())
{
TC_LOG_DEBUG("misc", "Pet AI stopped attacking [guid=%u]", me->GetGUID().GetCounter());
_stopAttack();
StopAttack();
return;
}
@@ -200,7 +200,7 @@ void PetAI::UpdateAI(uint32 diff)
// No enemy, check friendly
if (!spellUsed)
{
for (GuidSet::const_iterator tar = m_AllySet.begin(); tar != m_AllySet.end(); ++tar)
for (GuidSet::const_iterator tar = _allySet.begin(); tar != _allySet.end(); ++tar)
{
Unit* ally = ObjectAccessor::GetUnit(*me, *tar);
@@ -262,7 +262,7 @@ void PetAI::UpdateAI(uint32 diff)
void PetAI::UpdateAllies()
{
m_updateAlliesTimer = 10 * IN_MILLISECONDS; // update friendly targets every 10 seconds, lesser checks increase performance
_updateAlliesTimer = 10 * IN_MILLISECONDS; // update friendly targets every 10 seconds, lesser checks increase performance
Unit* owner = me->GetCharmerOrOwner();
if (!owner)
@@ -273,15 +273,15 @@ void PetAI::UpdateAllies()
group = player->GetGroup();
//only pet and owner/not in group->ok
if (m_AllySet.size() == 2 && !group)
if (_allySet.size() == 2 && !group)
return;
//owner is in group; group members filled in already (no raid -> subgroupcount = whole count)
if (group && !group->isRaidGroup() && m_AllySet.size() == (group->GetMembersCount() + 2))
if (group && !group->isRaidGroup() && _allySet.size() == (group->GetMembersCount() + 2))
return;
m_AllySet.clear();
m_AllySet.insert(me->GetGUID());
_allySet.clear();
_allySet.insert(me->GetGUID());
if (group) //add group
{
for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next())
@@ -293,11 +293,11 @@ void PetAI::UpdateAllies()
if (Target->GetGUID() == owner->GetGUID())
continue;
m_AllySet.insert(Target->GetGUID());
_allySet.insert(Target->GetGUID());
}
}
else //remove group
m_AllySet.insert(owner->GetGUID());
_allySet.insert(owner->GetGUID());
}
void PetAI::KilledUnit(Unit* victim)
@@ -309,7 +309,7 @@ void PetAI::KilledUnit(Unit* victim)
// Clear target just in case. May help problem where health / focus / mana
// regen gets stuck. Also resets attack command.
// Can't use _stopAttack() because that activates movement handlers and ignores
// Can't use StopAttack() because that activates movement handlers and ignores
// next target selection
me->AttackStop();
me->InterruptNonMeleeSpells(false);

View File

@@ -53,19 +53,17 @@ class TC_GAME_API PetAI : public CreatureAI
void EnterEvadeMode(EvadeReason /*why*/) override { } // For fleeing, pets don't use this type of Evade mechanic
private:
bool _needToStop(void);
void _stopAttack(void);
bool NeedToStop();
void StopAttack();
void UpdateAllies();
TimeTracker i_tracker;
GuidSet m_AllySet;
uint32 m_updateAlliesTimer;
Unit* SelectNextTarget(bool allowAutoSelect) const;
void HandleReturnMovement();
void DoAttack(Unit* target, bool chase);
bool CanAttack(Unit* target);
void ClearCharmInfoFlags();
TimeTracker _tracker;
GuidSet _allySet;
uint32 _updateAlliesTimer;
};
#endif

View File

@@ -33,7 +33,7 @@ int32 TotemAI::Permissible(Creature const* creature)
return PERMIT_BASE_NO;
}
TotemAI::TotemAI(Creature* c) : CreatureAI(c), i_victimGuid()
TotemAI::TotemAI(Creature* c) : CreatureAI(c), _victimGUID()
{
ASSERT(c->IsTotem());
}
@@ -64,7 +64,7 @@ void TotemAI::UpdateAI(uint32 /*diff*/)
// SPELLMOD_RANGE not applied in this place just because not existence range mods for attacking totems
// pointer to appropriate target if found any
Unit* victim = i_victimGuid ? ObjectAccessor::GetUnit(*me, i_victimGuid) : nullptr;
Unit* victim = _victimGUID ? ObjectAccessor::GetUnit(*me, _victimGUID) : nullptr;
// Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
if (!victim ||
@@ -81,13 +81,13 @@ void TotemAI::UpdateAI(uint32 /*diff*/)
if (victim)
{
// remember
i_victimGuid = victim->GetGUID();
_victimGUID = victim->GetGUID();
// attack
me->CastSpell(victim, me->ToTotem()->GetSpell());
}
else
i_victimGuid.Clear();
_victimGUID.Clear();
}
void TotemAI::AttackStart(Unit* /*victim*/)

View File

@@ -39,6 +39,6 @@ class TC_GAME_API TotemAI : public CreatureAI
static int32 Permissible(Creature const* creature);
private:
ObjectGuid i_victimGuid;
ObjectGuid _victimGUID;
};
#endif

View File

@@ -255,40 +255,40 @@ std::string UnitAI::GetDebugInfo() const
}
DefaultTargetSelector::DefaultTargetSelector(Unit const* unit, float dist, bool playerOnly, bool withTank, int32 aura)
: me(unit), m_dist(dist), m_playerOnly(playerOnly), except(!withTank ? unit->GetThreatManager().GetCurrentVictim() : nullptr), m_aura(aura)
: _me(unit), _dist(dist), _playerOnly(playerOnly), _exception(!withTank ? unit->GetThreatManager().GetCurrentVictim() : nullptr), _aura(aura)
{
}
bool DefaultTargetSelector::operator()(Unit const* target) const
{
if (!me)
if (!_me)
return false;
if (!target)
return false;
if (except && target == except)
if (_exception && target == _exception)
return false;
if (m_playerOnly && (target->GetTypeId() != TYPEID_PLAYER))
if (_playerOnly && (target->GetTypeId() != TYPEID_PLAYER))
return false;
if (m_dist > 0.0f && !me->IsWithinCombatRange(target, m_dist))
if (_dist > 0.0f && !_me->IsWithinCombatRange(target, _dist))
return false;
if (m_dist < 0.0f && me->IsWithinCombatRange(target, -m_dist))
if (_dist < 0.0f && _me->IsWithinCombatRange(target, -_dist))
return false;
if (m_aura)
if (_aura)
{
if (m_aura > 0)
if (_aura > 0)
{
if (!target->HasAura(m_aura))
if (!target->HasAura(_aura))
return false;
}
else
{
if (target->HasAura(-m_aura))
if (target->HasAura(-_aura))
return false;
}
}

View File

@@ -58,19 +58,21 @@ enum SelectAggroTarget
// default predicate function to select target based on distance, player and/or aura criteria
struct TC_GAME_API DefaultTargetSelector
{
Unit const* me;
float m_dist;
bool m_playerOnly;
Unit const* except;
int32 m_aura;
public:
// unit: the reference unit
// dist: if 0: ignored, if > 0: maximum distance to the reference unit, if < 0: minimum distance to the reference unit
// playerOnly: self explaining
// withMainTank: allow current tank to be selected
// aura: if 0: ignored, if > 0: the target shall have the aura, if < 0, the target shall NOT have the aura
DefaultTargetSelector(Unit const* unit, float dist, bool playerOnly, bool withMainTank, int32 aura);
bool operator()(Unit const* target) const;
// unit: the reference unit
// dist: if 0: ignored, if > 0: maximum distance to the reference unit, if < 0: minimum distance to the reference unit
// playerOnly: self explaining
// withMainTank: allow current tank to be selected
// aura: if 0: ignored, if > 0: the target shall have the aura, if < 0, the target shall NOT have the aura
DefaultTargetSelector(Unit const* unit, float dist, bool playerOnly, bool withMainTank, int32 aura);
bool operator()(Unit const* target) const;
private:
Unit const* _me;
float _dist;
bool _playerOnly;
Unit const* _exception;
int32 _aura;
};
// Target selector for spell casts checking range, auras and attributes

View File

@@ -49,7 +49,7 @@ void CreatureAI::OnCharmed(bool isNew)
AISpellInfoType* UnitAI::AISpellInfo;
AISpellInfoType* GetAISpellInfo(uint32 i) { return &UnitAI::AISpellInfo[i]; }
CreatureAI::CreatureAI(Creature* creature) : UnitAI(creature), me(creature), _boundary(nullptr), _negateBoundary(false), m_MoveInLineOfSight_locked(false)
CreatureAI::CreatureAI(Creature* creature) : UnitAI(creature), me(creature), _boundary(nullptr), _negateBoundary(false), _moveInLOSLocked(false)
{
}
@@ -96,11 +96,11 @@ void CreatureAI::DoZoneInCombat(Creature* creature /*= nullptr*/)
// MoveInLineOfSight can be called inside another MoveInLineOfSight and cause stack overflow
void CreatureAI::MoveInLineOfSight_Safe(Unit* who)
{
if (m_MoveInLineOfSight_locked == true)
if (_moveInLOSLocked == true)
return;
m_MoveInLineOfSight_locked = true;
_moveInLOSLocked = true;
MoveInLineOfSight(who);
m_MoveInLineOfSight_locked = false;
_moveInLOSLocked = false;
}
void CreatureAI::MoveInLineOfSight(Unit* who)
@@ -112,7 +112,7 @@ void CreatureAI::MoveInLineOfSight(Unit* who)
me->EngageWithTarget(who);
}
void CreatureAI::_OnOwnerCombatInteraction(Unit* target)
void CreatureAI::OnOwnerCombatInteraction(Unit* target)
{
if (!target || !me->IsAlive())
return;

View File

@@ -150,10 +150,10 @@ class TC_GAME_API CreatureAI : public UnitAI
virtual void ReceiveEmote(Player* /*player*/, uint32 /*emoteId*/) { }
// Called when owner takes damage
virtual void OwnerAttackedBy(Unit* attacker) { _OnOwnerCombatInteraction(attacker); }
virtual void OwnerAttackedBy(Unit* attacker) { OnOwnerCombatInteraction(attacker); }
// Called when owner attacks something
virtual void OwnerAttacked(Unit* target) { _OnOwnerCombatInteraction(target); }
virtual void OwnerAttacked(Unit* target) { OnOwnerCombatInteraction(target); }
/// == Triggered Actions Requested ==================
@@ -235,8 +235,9 @@ class TC_GAME_API CreatureAI : public UnitAI
bool _negateBoundary;
private:
bool m_MoveInLineOfSight_locked;
void _OnOwnerCombatInteraction(Unit* target);
void OnOwnerCombatInteraction(Unit* target);
bool _moveInLOSLocked;
};
enum Permitions : int32

View File

@@ -32,4 +32,5 @@ namespace FactorySelector
TC_GAME_API MovementGenerator* SelectMovementGenerator(Unit* unit);
TC_GAME_API GameObjectAI* SelectGameObjectAI(GameObject* go);
}
#endif

View File

@@ -40,19 +40,19 @@ struct TSpellSummary
void SummonList::Summon(Creature const* summon)
{
storage_.push_back(summon->GetGUID());
_storage.push_back(summon->GetGUID());
}
void SummonList::Despawn(Creature const* summon)
{
storage_.remove(summon->GetGUID());
_storage.remove(summon->GetGUID());
}
void SummonList::DoZoneInCombat(uint32 entry)
{
for (StorageType::iterator i = storage_.begin(); i != storage_.end();)
for (StorageType::iterator i = _storage.begin(); i != _storage.end();)
{
Creature* summon = ObjectAccessor::GetCreature(*me, *i);
Creature* summon = ObjectAccessor::GetCreature(*_me, *i);
++i;
if (summon && summon->IsAIEnabled()
&& (!entry || summon->GetEntry() == entry))
@@ -64,14 +64,14 @@ void SummonList::DoZoneInCombat(uint32 entry)
void SummonList::DespawnEntry(uint32 entry)
{
for (StorageType::iterator i = storage_.begin(); i != storage_.end();)
for (StorageType::iterator i = _storage.begin(); i != _storage.end();)
{
Creature* summon = ObjectAccessor::GetCreature(*me, *i);
Creature* summon = ObjectAccessor::GetCreature(*_me, *i);
if (!summon)
i = storage_.erase(i);
i = _storage.erase(i);
else if (summon->GetEntry() == entry)
{
i = storage_.erase(i);
i = _storage.erase(i);
summon->DespawnOrUnsummon();
}
else
@@ -81,10 +81,10 @@ void SummonList::DespawnEntry(uint32 entry)
void SummonList::DespawnAll()
{
while (!storage_.empty())
while (!_storage.empty())
{
Creature* summon = ObjectAccessor::GetCreature(*me, storage_.front());
storage_.pop_front();
Creature* summon = ObjectAccessor::GetCreature(*_me, _storage.front());
_storage.pop_front();
if (summon)
summon->DespawnOrUnsummon();
}
@@ -92,20 +92,20 @@ void SummonList::DespawnAll()
void SummonList::RemoveNotExisting()
{
for (StorageType::iterator i = storage_.begin(); i != storage_.end();)
for (StorageType::iterator i = _storage.begin(); i != _storage.end();)
{
if (ObjectAccessor::GetCreature(*me, *i))
if (ObjectAccessor::GetCreature(*_me, *i))
++i;
else
i = storage_.erase(i);
i = _storage.erase(i);
}
}
bool SummonList::HasEntry(uint32 entry) const
{
for (StorageType::const_iterator i = storage_.begin(); i != storage_.end(); ++i)
for (StorageType::const_iterator i = _storage.begin(); i != _storage.end(); ++i)
{
Creature* summon = ObjectAccessor::GetCreature(*me, *i);
Creature* summon = ObjectAccessor::GetCreature(*_me, *i);
if (summon && summon->GetEntry() == entry)
return true;
}
@@ -117,7 +117,7 @@ void SummonList::DoActionImpl(int32 action, StorageType const& summons)
{
for (auto const& guid : summons)
{
Creature* summon = ObjectAccessor::GetCreature(*me, guid);
Creature* summon = ObjectAccessor::GetCreature(*_me, guid);
if (summon && summon->IsAIEnabled())
summon->AI()->DoAction(action);
}

View File

@@ -35,52 +35,50 @@ public:
typedef StorageType::size_type size_type;
typedef StorageType::value_type value_type;
explicit SummonList(Creature* creature)
: me(creature)
{ }
explicit SummonList(Creature* creature) : _me(creature) { }
// And here we see a problem of original inheritance approach. People started
// to exploit presence of std::list members, so I have to provide wrappers
iterator begin()
{
return storage_.begin();
return _storage.begin();
}
const_iterator begin() const
{
return storage_.begin();
return _storage.begin();
}
iterator end()
{
return storage_.end();
return _storage.end();
}
const_iterator end() const
{
return storage_.end();
return _storage.end();
}
iterator erase(iterator i)
{
return storage_.erase(i);
return _storage.erase(i);
}
bool empty() const
{
return storage_.empty();
return _storage.empty();
}
size_type size() const
{
return storage_.size();
return _storage.size();
}
// Clear the underlying storage. This does NOT despawn the creatures - use DespawnAll for that!
void clear()
{
storage_.clear();
_storage.clear();
}
void Summon(Creature const* summon);
@@ -91,14 +89,14 @@ public:
template <typename T>
void DespawnIf(T const& predicate)
{
storage_.remove_if(predicate);
_storage.remove_if(predicate);
}
template <class Predicate>
void DoAction(int32 info, Predicate&& predicate, uint16 max = 0)
{
// We need to use a copy of SummonList here, otherwise original SummonList would be modified
StorageType listCopy = storage_;
StorageType listCopy = _storage;
Trinity::Containers::RandomResize<StorageType, Predicate>(listCopy, std::forward<Predicate>(predicate), max);
DoActionImpl(info, listCopy);
}
@@ -110,8 +108,8 @@ public:
private:
void DoActionImpl(int32 action, StorageType const& summons);
Creature* me;
StorageType storage_;
Creature* _me;
StorageType _storage;
};
class TC_GAME_API EntryCheckPredicate

View File

@@ -40,9 +40,9 @@ enum Points
};
FollowerAI::FollowerAI(Creature* creature) : ScriptedAI(creature),
m_uiUpdateFollowTimer(2500),
m_uiFollowState(STATE_FOLLOW_NONE),
m_pQuestForFollow(nullptr)
_updateFollowTimer(2500),
_followState(STATE_FOLLOW_NONE),
_questForFollow(nullptr)
{ }
void FollowerAI::AttackStart(Unit* who)
@@ -127,7 +127,7 @@ void FollowerAI::MoveInLineOfSight(Unit* who)
void FollowerAI::JustDied(Unit* /*killer*/)
{
if (!HasFollowState(STATE_FOLLOW_INPROGRESS) || !m_uiLeaderGUID || !m_pQuestForFollow)
if (!HasFollowState(STATE_FOLLOW_INPROGRESS) || !_leaderGUID || !_questForFollow)
return;
/// @todo need a better check for quests with time limit.
@@ -138,16 +138,16 @@ void FollowerAI::JustDied(Unit* /*killer*/)
for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
if (Player* member = groupRef->GetSource())
if (member->IsInMap(player))
member->FailQuest(m_pQuestForFollow->GetQuestId());
member->FailQuest(_questForFollow->GetQuestId());
}
else
player->FailQuest(m_pQuestForFollow->GetQuestId());
player->FailQuest(_questForFollow->GetQuestId());
}
}
void FollowerAI::JustAppeared()
{
m_uiFollowState = STATE_FOLLOW_NONE;
_followState = STATE_FOLLOW_NONE;
if (!IsCombatMovementAllowed())
SetCombatMovement(true);
@@ -189,7 +189,7 @@ void FollowerAI::UpdateAI(uint32 uiDiff)
{
if (HasFollowState(STATE_FOLLOW_INPROGRESS) && !me->GetVictim())
{
if (m_uiUpdateFollowTimer <= uiDiff)
if (_updateFollowTimer <= uiDiff)
{
if (HasFollowState(STATE_FOLLOW_COMPLETE) && !HasFollowState(STATE_FOLLOW_POSTEVENT))
{
@@ -237,10 +237,10 @@ void FollowerAI::UpdateAI(uint32 uiDiff)
return;
}
m_uiUpdateFollowTimer = 1000;
_updateFollowTimer = 1000;
}
else
m_uiUpdateFollowTimer -= uiDiff;
_updateFollowTimer -= uiDiff;
}
UpdateFollowerAI(uiDiff);
@@ -286,12 +286,12 @@ void FollowerAI::StartFollow(Player* player, uint32 factionForFollower, Quest co
}
//set variables
m_uiLeaderGUID = player->GetGUID();
_leaderGUID = player->GetGUID();
if (factionForFollower)
me->SetFaction(factionForFollower);
m_pQuestForFollow = quest;
_questForFollow = quest;
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE)
{
@@ -306,12 +306,12 @@ void FollowerAI::StartFollow(Player* player, uint32 factionForFollower, Quest co
me->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
TC_LOG_DEBUG("scripts", "FollowerAI start follow %s (%s)", player->GetName().c_str(), m_uiLeaderGUID.ToString().c_str());
TC_LOG_DEBUG("scripts", "FollowerAI start follow %s (%s)", player->GetName().c_str(), _leaderGUID.ToString().c_str());
}
Player* FollowerAI::GetLeaderForFollower()
{
if (Player* player = ObjectAccessor::GetPlayer(*me, m_uiLeaderGUID))
if (Player* player = ObjectAccessor::GetPlayer(*me, _leaderGUID))
{
if (player->IsAlive())
return player;
@@ -325,7 +325,7 @@ Player* FollowerAI::GetLeaderForFollower()
if (member && me->IsWithinDistInMap(member, MAX_PLAYER_DISTANCE) && member->IsAlive())
{
TC_LOG_DEBUG("scripts", "FollowerAI GetLeader changed and returned new leader.");
m_uiLeaderGUID = member->GetGUID();
_leaderGUID = member->GetGUID();
return member;
}
}

View File

@@ -61,22 +61,22 @@ class TC_GAME_API FollowerAI : public ScriptedAI
void SetFollowPaused(bool bPaused); //if special event require follow mode to hold/resume during the follow
void SetFollowComplete(bool bWithEndEvent = false);
bool HasFollowState(uint32 uiFollowState) { return (m_uiFollowState & uiFollowState) != 0; }
bool HasFollowState(uint32 uiFollowState) { return (_followState & uiFollowState) != 0; }
protected:
Player* GetLeaderForFollower();
private:
void AddFollowState(uint32 uiFollowState) { m_uiFollowState |= uiFollowState; }
void RemoveFollowState(uint32 uiFollowState) { m_uiFollowState &= ~uiFollowState; }
void AddFollowState(uint32 uiFollowState) { _followState |= uiFollowState; }
void RemoveFollowState(uint32 uiFollowState) { _followState &= ~uiFollowState; }
bool AssistPlayerInCombatAgainst(Unit* who);
ObjectGuid m_uiLeaderGUID;
uint32 m_uiUpdateFollowTimer;
uint32 m_uiFollowState;
ObjectGuid _leaderGUID;
uint32 _updateFollowTimer;
uint32 _followState;
Quest const* m_pQuestForFollow; //normally we have a quest
Quest const* _questForFollow;
};
#endif

View File

@@ -19,14 +19,46 @@
#include "Player.h"
#include "Creature.h"
uint32 GetGossipActionFor(Player* player, uint32 gossipListId) { return player->PlayerTalkClass->GetGossipOptionAction(gossipListId); }
void ClearGossipMenuFor(Player* player) { player->PlayerTalkClass->ClearMenus(); }
uint32 GetGossipActionFor(Player* player, uint32 gossipListId)
{
return player->PlayerTalkClass->GetGossipOptionAction(gossipListId);
}
void ClearGossipMenuFor(Player* player)
{
player->PlayerTalkClass->ClearMenus();
}
// Using provided text, not from DB
void AddGossipItemFor(Player* player, uint32 icon, std::string const& text, uint32 sender, uint32 action) { player->PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, icon, text, sender, action, "", 0); }
void AddGossipItemFor(Player* player, uint32 icon, std::string const& text, uint32 sender, uint32 action)
{
player->PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, icon, text, sender, action, "", 0);
}
// Using provided texts, not from DB
void AddGossipItemFor(Player* player, uint32 icon, std::string const& text, uint32 sender, uint32 action, std::string const& popupText, uint32 popupMoney, bool coded) { player->PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, icon, text, sender, action, popupText, popupMoney, coded); }
void AddGossipItemFor(Player* player, uint32 icon, std::string const& text, uint32 sender, uint32 action, std::string const& popupText, uint32 popupMoney, bool coded)
{
player->PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, icon, text, sender, action, popupText, popupMoney, coded);
}
// Uses gossip item info from DB
void AddGossipItemFor(Player* player, uint32 gossipMenuID, uint32 gossipMenuItemID, uint32 sender, uint32 action) { player->PlayerTalkClass->GetGossipMenu().AddMenuItem(gossipMenuID, gossipMenuItemID, sender, action); }
void SendGossipMenuFor(Player* player, uint32 npcTextID, ObjectGuid const& guid) { player->PlayerTalkClass->SendGossipMenu(npcTextID, guid); }
void SendGossipMenuFor(Player* player, uint32 npcTextID, Creature const* creature) { if (creature) SendGossipMenuFor(player, npcTextID, creature->GetGUID()); }
void CloseGossipMenuFor(Player* player) { player->PlayerTalkClass->SendCloseGossip(); }
void AddGossipItemFor(Player* player, uint32 gossipMenuID, uint32 gossipMenuItemID, uint32 sender, uint32 action)
{
player->PlayerTalkClass->GetGossipMenu().AddMenuItem(gossipMenuID, gossipMenuItemID, sender, action);
}
void SendGossipMenuFor(Player* player, uint32 npcTextID, ObjectGuid const& guid)
{
player->PlayerTalkClass->SendGossipMenu(npcTextID, guid);
}
void SendGossipMenuFor(Player* player, uint32 npcTextID, Creature const* creature)
{
if (creature)
SendGossipMenuFor(player, npcTextID, creature->GetGUID());
}
void CloseGossipMenuFor(Player* player)
{
player->PlayerTalkClass->SendCloseGossip();
}

View File

@@ -81,6 +81,7 @@ enum eTradeskill
};
class Creature;
uint32 TC_GAME_API GetGossipActionFor(Player* player, uint32 gossipListId);
void TC_GAME_API ClearGossipMenuFor(Player* player);
// Using provided text, not from DB

View File

@@ -29,17 +29,17 @@
#include "ScriptMgr.h"
#include "Vehicle.h"
SmartAI::SmartAI(Creature* creature) : CreatureAI(creature), mIsCharmed(false), mFollowCreditType(0), mFollowArrivedTimer(0), mFollowCredit(0), mFollowArrivedEntry(0), mFollowDist(0.f), mFollowAngle(0.f),
SmartAI::SmartAI(Creature* creature) : CreatureAI(creature), _charmed(false), _followCreditType(0), _followArrivedTimer(0), _followCredit(0), _followArrivedEntry(0), _followDistance(0.f), _followAngle(0.f),
_escortState(SMART_ESCORT_NONE), _escortNPCFlags(0), _escortInvokerCheckTimer(1000), _currentWaypointNode(0), _waypointReached(false), _waypointPauseTimer(0), _waypointPauseForced(false), _repeatWaypointPath(false),
_OOCReached(false), _waypointPathEnded(false), mRun(true), mEvadeDisabled(false), mCanAutoAttack(true), mCanCombatMove(true), mInvincibilityHpLevel(0), mDespawnTime(0), mDespawnState(0), mConditionsTimer(0),
_gossipReturn(false), mEscortQuestID(0)
_OOCReached(false), _waypointPathEnded(false), _run(true), _evadeDisabled(false), _canAutoAttack(true), _canCombatMove(true), _invincibilityHPLevel(0), _despawnTime(0), _despawnState(0), _vehicleConditionsTimer(0),
_gossipReturn(false), _escortQuestId(0)
{
mHasConditions = sConditionMgr->HasConditionsForNotGroupedEntry(CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, creature->GetEntry());
_vehicleConditions = sConditionMgr->HasConditionsForNotGroupedEntry(CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, creature->GetEntry());
}
bool SmartAI::IsAIControlled() const
{
return !mIsCharmed;
return !_charmed;
}
void SmartAI::StartPath(bool run/* = false*/, uint32 pathId/* = 0*/, bool repeat/* = false*/, Unit* invoker/* = nullptr*/, uint32 nodeId/* = 1*/)
@@ -101,7 +101,7 @@ bool SmartAI::LoadPath(uint32 entry)
{
Trinity::NormalizeMapCoord(waypoint.x);
Trinity::NormalizeMapCoord(waypoint.y);
waypoint.moveType = mRun ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK;
waypoint.moveType = _run ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK;
}
GetScript()->SetPathId(entry);
@@ -132,7 +132,7 @@ void SmartAI::PausePath(uint32 delay, bool forced)
if (forced)
{
_waypointPauseForced = forced;
SetRun(mRun);
SetRun(_run);
me->PauseMovement();
me->SetHomePosition(me->GetPosition());
}
@@ -151,7 +151,7 @@ void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail)
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE)
waypointInfo = me->GetCurrentWaypointInfo();
if (mDespawnState != 2)
if (_despawnState != 2)
SetDespawnTime(DespawnTime);
me->GetMotionMaster()->MoveIdle();
@@ -163,16 +163,16 @@ void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail)
{
if (waypointInfo.first)
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_ENDED, nullptr, waypointInfo.first, waypointInfo.second);
if (mDespawnState == 1)
if (_despawnState == 1)
StartDespawn();
}
return;
}
if (quest)
mEscortQuestID = quest;
_escortQuestId = quest;
if (mDespawnState != 2)
if (_despawnState != 2)
SetDespawnTime(DespawnTime);
me->GetMotionMaster()->MoveIdle();
@@ -195,16 +195,16 @@ void SmartAI::EndPath(bool fail)
}
ObjectVector const* targets = GetScript()->GetStoredTargetVector(SMART_ESCORT_TARGETS, *me);
if (targets && mEscortQuestID)
if (targets && _escortQuestId)
{
if (targets->size() == 1 && GetScript()->IsPlayer((*targets->begin())))
{
Player* player = targets->front()->ToPlayer();
if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
player->GroupEventHappens(mEscortQuestID, me);
player->GroupEventHappens(_escortQuestId, me);
if (fail)
player->FailQuest(mEscortQuestID);
player->FailQuest(_escortQuestId);
if (Group* group = player->GetGroup())
{
@@ -215,9 +215,9 @@ void SmartAI::EndPath(bool fail)
continue;
if (!fail && groupGuy->IsAtGroupRewardDistance(me) && !groupGuy->HasCorpse())
groupGuy->AreaExploredOrEventHappens(mEscortQuestID);
groupGuy->AreaExploredOrEventHappens(_escortQuestId);
else if (fail)
groupGuy->FailQuest(mEscortQuestID);
groupGuy->FailQuest(_escortQuestId);
}
}
}
@@ -229,9 +229,9 @@ void SmartAI::EndPath(bool fail)
{
Player* player = target->ToPlayer();
if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
player->AreaExploredOrEventHappens(mEscortQuestID);
player->AreaExploredOrEventHappens(_escortQuestId);
else if (fail)
player->FailQuest(mEscortQuestID);
player->FailQuest(_escortQuestId);
}
}
}
@@ -246,12 +246,12 @@ void SmartAI::EndPath(bool fail)
if (_repeatWaypointPath)
{
if (IsAIControlled())
StartPath(mRun, GetScript()->GetPathId(), _repeatWaypointPath);
StartPath(_run, GetScript()->GetPathId(), _repeatWaypointPath);
}
else
GetScript()->SetPathId(0);
if (mDespawnState == 1)
if (_despawnState == 1)
StartDespawn();
}
@@ -265,7 +265,7 @@ void SmartAI::ResumePath()
_waypointReached = false;
_waypointPauseTimer = 0;
SetRun(mRun);
SetRun(_run);
me->ResumeMovement();
}
@@ -294,7 +294,7 @@ void SmartAI::UpdateAI(uint32 diff)
if (!UpdateVictim())
return;
if (mCanAutoAttack)
if (_canAutoAttack)
DoMeleeAttackIfReady();
}
@@ -378,7 +378,7 @@ void SmartAI::WaypointReached(uint32 nodeId, uint32 pathId)
if (_currentWaypointNode == _path.nodes.size())
_waypointPathEnded = true;
else
SetRun(mRun);
SetRun(_run);
}
}
@@ -408,7 +408,7 @@ void SmartAI::MovementInform(uint32 type, uint32 id)
void SmartAI::EnterEvadeMode(EvadeReason /*why*/)
{
if (mEvadeDisabled)
if (_evadeDisabled)
{
GetScript()->ProcessEventsFor(SMART_EVENT_EVADE);
return;
@@ -427,7 +427,7 @@ void SmartAI::EnterEvadeMode(EvadeReason /*why*/)
GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); // must be after _EnterEvadeMode (spells, auras, ...)
SetRun(mRun);
SetRun(_run);
if (Unit* owner = me->GetCharmerOrOwner())
{
@@ -439,9 +439,9 @@ void SmartAI::EnterEvadeMode(EvadeReason /*why*/)
AddEscortState(SMART_ESCORT_RETURNING);
ReturnToLastOOCPos();
}
else if (Unit* target = mFollowGuid ? ObjectAccessor::GetUnit(*me, mFollowGuid) : nullptr)
else if (Unit* target = _followGUID ? ObjectAccessor::GetUnit(*me, _followGUID) : nullptr)
{
me->GetMotionMaster()->MoveFollow(target, mFollowDist, mFollowAngle);
me->GetMotionMaster()->MoveFollow(target, _followDistance, _followAngle);
// evade is not cleared in MoveFollow, so we can't keep it
me->ClearUnitState(UNIT_STATE_EVADE);
}
@@ -515,8 +515,8 @@ void SmartAI::InitializeAI()
{
GetScript()->OnInitialize(me);
mDespawnTime = 0;
mDespawnState = 0;
_despawnTime = 0;
_despawnState = 0;
_escortState = SMART_ESCORT_NONE;
me->SetVisible(true);
@@ -527,13 +527,13 @@ void SmartAI::InitializeAI()
GetScript()->OnReset();
}
mFollowGuid.Clear(); // do not reset follower on Reset(), we need it after combat evade
mFollowDist = 0;
mFollowAngle = 0;
mFollowCredit = 0;
mFollowArrivedTimer = 1000;
mFollowArrivedEntry = 0;
mFollowCreditType = 0;
_followGUID.Clear(); // do not reset follower on Reset(), we need it after combat evade
_followDistance = 0;
_followAngle = 0;
_followCredit = 0;
_followArrivedTimer = 1000;
_followArrivedEntry = 0;
_followCreditType = 0;
}
void SmartAI::JustReachedHome()
@@ -588,18 +588,18 @@ void SmartAI::AttackStart(Unit* who)
if (!IsAIControlled())
{
if (who)
me->Attack(who, mCanAutoAttack);
me->Attack(who, _canAutoAttack);
return;
}
if (who && me->Attack(who, mCanAutoAttack))
if (who && me->Attack(who, _canAutoAttack))
{
me->GetMotionMaster()->Clear(MOTION_PRIORITY_NORMAL);
me->PauseMovement();
if (mCanCombatMove)
if (_canCombatMove)
{
SetRun(mRun);
SetRun(_run);
me->GetMotionMaster()->MoveChase(who);
}
}
@@ -622,8 +622,8 @@ void SmartAI::DamageTaken(Unit* doneBy, uint32& damage)
if (!IsAIControlled()) // don't allow players to use unkillable units
return;
if (mInvincibilityHpLevel && (damage >= me->GetHealth() - mInvincibilityHpLevel))
damage = me->GetHealth() - mInvincibilityHpLevel; // damage should not be nullified, because of player damage req.
if (_invincibilityHPLevel && (damage >= me->GetHealth() - _invincibilityHPLevel))
damage = me->GetHealth() - _invincibilityHPLevel; // damage should not be nullified, because of player damage req.
}
void SmartAI::HealReceived(Unit* doneBy, uint32& addhealth)
@@ -670,14 +670,14 @@ void SmartAI::OnCharmed(bool /*isNew*/)
EndPath(true);
}
mIsCharmed = charmed;
_charmed = charmed;
if (!charmed && !me->IsInEvadeMode())
{
if (_repeatWaypointPath)
StartPath(mRun, GetScript()->GetPathId(), true);
StartPath(_run, GetScript()->GetPathId(), true);
else
me->SetWalk(!mRun);
me->SetWalk(!_run);
if (me->LastCharmerGUID)
{
@@ -716,7 +716,7 @@ ObjectGuid SmartAI::GetGUID(int32 /*id*/) const
void SmartAI::SetRun(bool run)
{
me->SetWalk(!run);
mRun = run;
_run = run;
for (auto& node : _path.nodes)
node.moveType = run ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK;
}
@@ -738,7 +738,7 @@ void SmartAI::SetSwim(bool swim)
void SmartAI::SetEvadeDisabled(bool disable)
{
mEvadeDisabled = disable;
_evadeDisabled = disable;
}
bool SmartAI::GossipHello(Player* player)
@@ -772,10 +772,10 @@ void SmartAI::QuestReward(Player* player, Quest const* quest, uint32 opt)
void SmartAI::SetCombatMove(bool on)
{
if (mCanCombatMove == on)
if (_canCombatMove == on)
return;
mCanCombatMove = on;
_canCombatMove = on;
if (!IsAIControlled())
return;
@@ -789,7 +789,7 @@ void SmartAI::SetCombatMove(bool on)
return movement->Mode == MOTION_MODE_DEFAULT && movement->Priority == MOTION_PRIORITY_NORMAL;
}))
{
SetRun(mRun);
SetRun(_run);
me->GetMotionMaster()->MoveChase(me->GetVictim());
}
}
@@ -809,38 +809,38 @@ void SmartAI::SetFollow(Unit* target, float dist, float angle, uint32 credit, ui
return;
}
mFollowGuid = target->GetGUID();
mFollowDist = dist;
mFollowAngle = angle;
mFollowArrivedTimer = 1000;
mFollowCredit = credit;
mFollowArrivedEntry = end;
mFollowCreditType = creditType;
SetRun(mRun);
me->GetMotionMaster()->MoveFollow(target, mFollowDist, mFollowAngle);
_followGUID = target->GetGUID();
_followDistance = dist;
_followAngle = angle;
_followArrivedTimer = 1000;
_followCredit = credit;
_followArrivedEntry = end;
_followCreditType = creditType;
SetRun(_run);
me->GetMotionMaster()->MoveFollow(target, _followDistance, _followAngle);
}
void SmartAI::StopFollow(bool complete)
{
mFollowGuid.Clear();
mFollowDist = 0;
mFollowAngle = 0;
mFollowCredit = 0;
mFollowArrivedTimer = 1000;
mFollowArrivedEntry = 0;
mFollowCreditType = 0;
_followGUID.Clear();
_followDistance = 0;
_followAngle = 0;
_followCredit = 0;
_followArrivedTimer = 1000;
_followArrivedEntry = 0;
_followCreditType = 0;
me->GetMotionMaster()->MoveIdle();
if (!complete)
return;
Player* player = ObjectAccessor::GetPlayer(*me, mFollowGuid);
Player* player = ObjectAccessor::GetPlayer(*me, _followGUID);
if (player)
{
if (!mFollowCreditType)
player->RewardPlayerAndGroupAtEvent(mFollowCredit, me);
if (!_followCreditType)
player->RewardPlayerAndGroupAtEvent(_followCredit, me);
else
player->GroupEventHappens(mFollowCredit, me);
player->GroupEventHappens(_followCredit, me);
}
SetDespawnTime(5000);
@@ -868,10 +868,10 @@ void SmartAI::OnSpellClick(Unit* clicker, bool spellClickHandled)
void SmartAI::CheckConditions(uint32 diff)
{
if (!mHasConditions)
if (!_vehicleConditions)
return;
if (mConditionsTimer <= diff)
if (_vehicleConditionsTimer <= diff)
{
if (Vehicle* vehicleKit = me->GetVehicleKit())
{
@@ -889,10 +889,10 @@ void SmartAI::CheckConditions(uint32 diff)
}
}
mConditionsTimer = 1000;
_vehicleConditionsTimer = 1000;
}
else
mConditionsTimer -= diff;
_vehicleConditionsTimer -= diff;
}
void SmartAI::UpdatePath(uint32 diff)
@@ -904,7 +904,7 @@ void SmartAI::UpdatePath(uint32 diff)
{
if (!IsEscortInvokerInRange())
{
StopPath(0, mEscortQuestID, true);
StopPath(0, _escortQuestId, true);
// allow to properly hook out of range despawn action, which in most cases should perform the same operation as dying
GetScript()->ProcessEventsFor(SMART_EVENT_DEATH, me);
@@ -948,41 +948,41 @@ void SmartAI::UpdatePath(uint32 diff)
void SmartAI::UpdateFollow(uint32 diff)
{
if (mFollowGuid)
if (_followGUID)
{
if (mFollowArrivedTimer < diff)
if (_followArrivedTimer < diff)
{
if (me->FindNearestCreature(mFollowArrivedEntry, INTERACTION_DISTANCE, true))
if (me->FindNearestCreature(_followArrivedEntry, INTERACTION_DISTANCE, true))
{
StopFollow(true);
return;
}
mFollowArrivedTimer = 1000;
_followArrivedTimer = 1000;
}
else
mFollowArrivedTimer -= diff;
_followArrivedTimer -= diff;
}
}
void SmartAI::UpdateDespawn(uint32 diff)
{
if (mDespawnState <= 1 || mDespawnState > 3)
if (_despawnState <= 1 || _despawnState > 3)
return;
if (mDespawnTime < diff)
if (_despawnTime < diff)
{
if (mDespawnState == 2)
if (_despawnState == 2)
{
me->SetVisible(false);
mDespawnTime = 5000;
mDespawnState++;
_despawnTime = 5000;
_despawnState++;
}
else
me->DespawnOrUnsummon();
}
else
mDespawnTime -= diff;
_despawnTime -= diff;
}
void SmartGameObjectAI::UpdateAI(uint32 diff)

View File

@@ -61,9 +61,9 @@ class TC_GAME_API SmartAI : public CreatureAI
bool HasEscortState(uint32 uiEscortState) const { return (_escortState & uiEscortState) != 0; }
void AddEscortState(uint32 uiEscortState) { _escortState |= uiEscortState; }
void RemoveEscortState(uint32 uiEscortState) { _escortState &= ~uiEscortState; }
void SetAutoAttack(bool on) { mCanAutoAttack = on; }
void SetAutoAttack(bool on) { _canAutoAttack = on; }
void SetCombatMove(bool on);
bool CanCombatMove() { return mCanCombatMove; }
bool CanCombatMove() { return _canCombatMove; }
void SetFollow(Unit* target, float dist = 0.0f, float angle = 0.0f, uint32 credit = 0, uint32 end = 0, uint32 creditType = 0);
void StopFollow(bool complete);
bool IsEscortInvokerInRange();
@@ -74,7 +74,7 @@ class TC_GAME_API SmartAI : public CreatureAI
void WaypointPathEnded(uint32 nodeId, uint32 pathId) override;
void SetTimedActionList(SmartScriptHolder& e, uint32 entry, Unit* invoker);
SmartScript* GetScript() { return &mScript; }
SmartScript* GetScript() { return &_script; }
// Called at reaching home after evade, InitializeAI(), EnterEvadeMode() for resetting variables
void JustReachedHome() override;
@@ -169,7 +169,7 @@ class TC_GAME_API SmartAI : public CreatureAI
void SetEvadeDisabled(bool disable = true);
void SetInvincibilityHpLevel(uint32 level) { mInvincibilityHpLevel = level; }
void SetInvincibilityHpLevel(uint32 level) { _invincibilityHPLevel = level; }
bool GossipHello(Player* player) override;
bool GossipSelect(Player* player, uint32 menuId, uint32 gossipListId) override;
@@ -180,10 +180,10 @@ class TC_GAME_API SmartAI : public CreatureAI
void SetDespawnTime (uint32 t)
{
mDespawnTime = t;
mDespawnState = t ? 1 : 0;
_despawnTime = t;
_despawnState = t ? 1 : 0;
}
void StartDespawn() { mDespawnState = 2; }
void StartDespawn() { _despawnState = 2; }
void OnSpellClick(Unit* clicker, bool spellClickHandled) override;
@@ -191,7 +191,7 @@ class TC_GAME_API SmartAI : public CreatureAI
void SetGossipReturn(bool val) { _gossipReturn = val; }
void SetEscortQuest(uint32 questID) { mEscortQuestID = questID; }
void SetEscortQuest(uint32 questID) { _escortQuestId = questID; }
private:
bool AssistPlayerInCombatAgainst(Unit* who);
@@ -201,16 +201,15 @@ class TC_GAME_API SmartAI : public CreatureAI
void UpdateFollow(uint32 diff);
void UpdateDespawn(uint32 diff);
SmartScript mScript;
bool mIsCharmed;
uint32 mFollowCreditType;
uint32 mFollowArrivedTimer;
uint32 mFollowCredit;
uint32 mFollowArrivedEntry;
ObjectGuid mFollowGuid;
float mFollowDist;
float mFollowAngle;
SmartScript _script;
bool _charmed;
uint32 _followCreditType;
uint32 _followArrivedTimer;
uint32 _followCredit;
uint32 _followArrivedEntry;
ObjectGuid _followGUID;
float _followDistance;
float _followAngle;
uint32 _escortState;
uint32 _escortNPCFlags;
@@ -224,23 +223,23 @@ class TC_GAME_API SmartAI : public CreatureAI
bool _OOCReached;
bool _waypointPathEnded;
bool mRun;
bool mEvadeDisabled;
bool mCanAutoAttack;
bool mCanCombatMove;
uint32 mInvincibilityHpLevel;
bool _run;
bool _evadeDisabled;
bool _canAutoAttack;
bool _canCombatMove;
uint32 _invincibilityHPLevel;
uint32 mDespawnTime;
uint32 mDespawnState;
uint32 _despawnTime;
uint32 _despawnState;
// Vehicle conditions
bool mHasConditions;
uint32 mConditionsTimer;
bool _vehicleConditions;
uint32 _vehicleConditionsTimer;
// Gossip
bool _gossipReturn;
uint32 mEscortQuestID;
uint32 _escortQuestId;
};
class TC_GAME_API SmartGameObjectAI : public GameObjectAI
@@ -252,7 +251,7 @@ class TC_GAME_API SmartGameObjectAI : public GameObjectAI
void UpdateAI(uint32 diff) override;
void InitializeAI() override;
void Reset() override;
SmartScript* GetScript() { return &mScript; }
SmartScript* GetScript() { return &_script; }
static int32 Permissible(GameObject const* /*go*/) { return PERMIT_BASE_NO; }
bool GossipHello(Player* player) override;
@@ -273,7 +272,7 @@ class TC_GAME_API SmartGameObjectAI : public GameObjectAI
void SetGossipReturn(bool val) { _gossipReturn = val; }
private:
SmartScript mScript;
SmartScript _script;
// Gossip
bool _gossipReturn;