*AI structure update.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-01-30 18:10:05 -06:00
parent 03234a0657
commit 8fee06f041
266 changed files with 460 additions and 598 deletions
+2 -44
View File
@@ -38,29 +38,10 @@ AggressorAI::Permissible(const Creature *creature)
return PERMIT_BASE_NO;
}
AggressorAI::AggressorAI(Creature *c) : i_creature(*c), i_victimGuid(0), i_state(STATE_NORMAL), i_tracker(TIME_INTERVAL_LOOK)
AggressorAI::AggressorAI(Creature *c) : CreatureAI(c), i_creature(*c), i_victimGuid(0), i_state(STATE_NORMAL), i_tracker(TIME_INTERVAL_LOOK)
{
}
void
AggressorAI::MoveInLineOfSight(Unit *u)
{
if(!i_creature.getVictim() && i_creature.canStartAttack(u))
AttackStart(u);
/*
if(!i_creature.getVictim())
{
AttackStart(u);
}
else if(sMapStore.LookupEntry(i_creature.GetMapId())->IsDungeon())
{
u->SetInCombatWith(&i_creature);
i_creature.AddThreat(u, 0.0f);
}
*/
}
void AggressorAI::EnterEvadeMode()
{
if( !i_creature.isAlive() )
@@ -118,7 +99,7 @@ void
AggressorAI::UpdateAI(const uint32 /*diff*/)
{
// update i_victimGuid if i_creature.getVictim() !=0 and changed
if(!i_creature.SelectHostilTarget() || !i_creature.getVictim())
if(!UpdateVictim())
return;
i_victimGuid = i_creature.getVictim()->GetGUID();
@@ -132,26 +113,3 @@ AggressorAI::UpdateAI(const uint32 /*diff*/)
}
}
}
bool
AggressorAI::IsVisible(Unit *pl) const
{
return i_creature.GetDistance(pl) < sWorld.getConfig(CONFIG_SIGHT_MONSTER)
&& pl->isVisibleForOrDetect(&i_creature,true);
}
void
AggressorAI::AttackStart(Unit *u)
{
if( !u )
return;
if(i_creature.Attack(u,true))
{
i_creature.AddThreat(u, 0.0f);
// DEBUG_LOG("Creature %s tagged a victim to kill [guid=%u]", i_creature.GetName(), u->GetGUIDLow());
i_victimGuid = u->GetGUID();
i_creature.GetMotionMaster()->MoveChase(u);
}
}
-3
View File
@@ -38,10 +38,7 @@ class TRINITY_DLL_DECL AggressorAI : public CreatureAI
AggressorAI(Creature *c);
void MoveInLineOfSight(Unit *);
void AttackStart(Unit *);
void EnterEvadeMode();
bool IsVisible(Unit *) const;
void UpdateAI(const uint32);
static int Permissible(const Creature *);
+1 -1
View File
@@ -632,7 +632,7 @@ class TRINITY_DLL_SPEC Creature : public Unit
bool IsFormationLeader() {return (GetDBTableGUIDLow() && GetDBTableGUIDLow() == m_formationID);}
uint32 GetFormationID(){return m_formationID;}
Unit *SelectHostilTarget();
Unit *SelectVictim();
protected:
bool CreateFromProto(uint32 guidlow,uint32 Entry,uint32 team, const CreatureData *data = NULL);
bool InitEntry(uint32 entry, uint32 team=ALLIANCE, const CreatureData* data=NULL);
+26 -11
View File
@@ -20,17 +20,39 @@
#include "CreatureAI.h"
#include "Creature.h"
#include "Player.h"
#include "Pet.h"
#include "SpellAuras.h"
CreatureAI::~CreatureAI()
void UnitAI::AttackStart(Unit *victim)
{
if(!victim)
return;
if(me->Attack(victim, true))
{
//DEBUG_LOG("Creature %s tagged a victim to kill [guid=%u]", me->GetName(), victim->GetGUIDLow());
me->GetMotionMaster()->MoveChase(victim);
}
}
void CreatureAI::MoveInLineOfSight(Unit *who)
{
if(!me->getVictim() && me->canStartAttack(who))
AttackStart(who);
}
bool CreatureAI::UpdateVictim()
{
if(!me->isInCombat())
return false;
if(Unit *victim = me->SelectVictim())
AttackStart(victim);
return me->getVictim();
}
void CreatureAI::EnterEvadeMode()
{
if(!me) return;
me->RemoveAllAuras();
me->DeleteThreatList();
me->CombatStop();
@@ -62,12 +84,5 @@ void SimpleCharmedAI::UpdateAI(const uint32 /*diff*/)
Unit *target = me->getVictim();
if(!target || !charmer->canAttack(target))
{
target = charmer->SelectNearestTarget();
if(!target)
return;
me->GetMotionMaster()->MoveChase(target);
me->Attack(target, true);
}
AttackStart(charmer->SelectNearestTarget());
}
+19 -17
View File
@@ -29,6 +29,7 @@
class Unit;
class Creature;
class Player;
struct SpellEntry;
#define TIME_INTERVAL_LOOK 5000
@@ -71,34 +72,41 @@ enum SelectAggroTarget
class TRINITY_DLL_SPEC UnitAI
{
public:
UnitAI(Unit *u) : me(u) {}
virtual void UpdateAI(const uint32 diff) = 0;
protected:
Unit *me;
public:
UnitAI(Unit *u) : me(u) {}
virtual void AttackStart(Unit *);
virtual void UpdateAI(const uint32 diff) = 0;
};
class TRINITY_DLL_SPEC SimpleCharmedAI : public UnitAI
class TRINITY_DLL_SPEC PlayerAI : public UnitAI
{
protected:
Player *me;
public:
PlayerAI(Player *p) : UnitAI((Unit*)p), me(p) {}
};
class TRINITY_DLL_SPEC SimpleCharmedAI : public PlayerAI
{
public:
virtual void UpdateAI(const uint32 diff);
void UpdateAI(const uint32 diff);
};
class TRINITY_DLL_SPEC CreatureAI : public UnitAI
{
protected:
Creature *me;
bool UpdateVictim();
public:
CreatureAI() : UnitAI(NULL), me(NULL) {}
CreatureAI(Creature *c) : UnitAI((Unit*)c), me(c) {}
virtual ~CreatureAI();
virtual ~CreatureAI() {}
// Called if IsVisible(Unit *who) is true at each *who move
virtual void MoveInLineOfSight(Unit *) = 0;
// Called at each attack of m_creature by any victim
virtual void AttackStart(Unit *) = 0;
virtual void MoveInLineOfSight(Unit *);
// Called at stopping attack by any attacker
virtual void EnterEvadeMode();
@@ -106,12 +114,6 @@ class TRINITY_DLL_SPEC CreatureAI : public UnitAI
// Called at any Damage from any attacker (before damage apply)
virtual void DamageTaken(Unit *done_by, uint32 & /*damage*/) {}
// Is unit visible for MoveInLineOfSight
virtual bool IsVisible(Unit *) const = 0;
// Called at World update tick
virtual void UpdateAI(const uint32 diff ) = 0;
// Called when the creature is killed
virtual void JustDied(Unit *) {}
+2 -16
View File
@@ -33,7 +33,7 @@ int GuardAI::Permissible(const Creature *creature)
return PERMIT_BASE_NO;
}
GuardAI::GuardAI(Creature *c) : i_creature(*c), i_victimGuid(0), i_state(STATE_NORMAL), i_tracker(TIME_INTERVAL_LOOK)
GuardAI::GuardAI(Creature *c) : CreatureAI(c), i_creature(*c), i_victimGuid(0), i_state(STATE_NORMAL), i_tracker(TIME_INTERVAL_LOOK)
{
}
@@ -110,7 +110,7 @@ void GuardAI::EnterEvadeMode()
void GuardAI::UpdateAI(const uint32 /*diff*/)
{
// update i_victimGuid if i_creature.getVictim() !=0 and changed
if(!i_creature.SelectHostilTarget() || !i_creature.getVictim())
if(!UpdateVictim())
return;
i_victimGuid = i_creature.getVictim()->GetGUID();
@@ -131,20 +131,6 @@ bool GuardAI::IsVisible(Unit *pl) const
&& pl->isVisibleForOrDetect(&i_creature,true);
}
void GuardAI::AttackStart(Unit *u)
{
if( !u )
return;
// DEBUG_LOG("Creature %s tagged a victim to kill [guid=%u]", i_creature.GetName(), u->GetGUIDLow());
if(i_creature.Attack(u,true))
{
i_creature.AddThreat(u, 0.0f);
i_victimGuid = u->GetGUID();
i_creature.GetMotionMaster()->MoveChase(u);
}
}
void GuardAI::JustDied(Unit *killer)
{
if(Player* pkiller = killer->GetCharmerOrOwnerPlayerOrPlayerItself())
-1
View File
@@ -39,7 +39,6 @@ class TRINITY_DLL_DECL GuardAI : public CreatureAI
GuardAI(Creature *c);
void MoveInLineOfSight(Unit *);
void AttackStart(Unit *);
void EnterEvadeMode();
void JustDied(Unit *);
bool IsVisible(Unit *) const;
+1 -2
View File
@@ -32,8 +32,6 @@ class TRINITY_DLL_DECL PassiveAI : public CreatureAI
void MoveInLineOfSight(Unit *) {}
void AttackStart(Unit *) {}
bool IsVisible(Unit *) const { return false; }
void UpdateAI(const uint32);
static int Permissible(const Creature *) { return PERMIT_BASE_IDLE; }
};
@@ -43,6 +41,7 @@ class TRINITY_DLL_DECL NullCreatureAI : public PassiveAI
public:
NullCreatureAI(Creature *c) : PassiveAI(c) {}
void UpdateAI(const uint32) {}
void EnterEvadeMode() {}
};
+5 -24
View File
@@ -25,18 +25,18 @@
#define MAX_OUTDOOR_PVP_DISTANCE 200 // the max value in capture point type go data0 is 100 currently, so use twice that much to handle leaving as well
OutdoorPvPObjectiveAI::OutdoorPvPObjectiveAI(Creature *c) : i_creature(*c)
OutdoorPvPObjectiveAI::OutdoorPvPObjectiveAI(Creature *c) : NullCreatureAI(c)
{
sLog.outDebug("OutdoorPvP objective AI assigned to creature guid %u", i_creature.GetGUIDLow());
i_creature.SetReactState(REACT_AGGRESSIVE);
sLog.outDebug("OutdoorPvP objective AI assigned to creature guid %u", me->GetGUIDLow());
me->SetReactState(REACT_AGGRESSIVE);
}
void OutdoorPvPObjectiveAI::MoveInLineOfSight(Unit *u)
{
// IsVisible only passes for players in range, so no need to check again
// leaving/entering distance will be checked based on go range data
if((u->GetTypeId() == TYPEID_PLAYER) && i_creature.IsWithinDistInMap(u, MAX_OUTDOOR_PVP_DISTANCE))
sOutdoorPvPMgr.HandleCaptureCreaturePlayerMoveInLos(((Player*)u),&i_creature);
if((u->GetTypeId() == TYPEID_PLAYER) && me->IsWithinDistInMap(u, MAX_OUTDOOR_PVP_DISTANCE))
sOutdoorPvPMgr.HandleCaptureCreaturePlayerMoveInLos(((Player*)u), me);
}
int OutdoorPvPObjectiveAI::Permissible(const Creature * c)
@@ -45,22 +45,3 @@ int OutdoorPvPObjectiveAI::Permissible(const Creature * c)
return PERMIT_BASE_NO;
}
bool OutdoorPvPObjectiveAI::IsVisible(Unit *pl) const
{
return (pl->GetTypeId() == TYPEID_PLAYER) && (i_creature.GetDistance(pl) < MAX_OUTDOOR_PVP_DISTANCE);
}
void OutdoorPvPObjectiveAI::AttackStart(Unit *)
{
//EnterEvadeMode();
}
void OutdoorPvPObjectiveAI::EnterEvadeMode()
{
// i_creature.DeleteThreatList();
// i_creature.CombatStop();
}
void OutdoorPvPObjectiveAI::UpdateAI(const uint32 diff)
{
}
+2 -10
View File
@@ -19,25 +19,17 @@
#ifndef TRINITY_OUTDOORPVPOBJECTIVEAI_H
#define TRINITY_OUTDOORPVPOBJECTIVEAI_H
#include "CreatureAI.h"
#include "NullCreatureAI.h"
class Creature;
class TRINITY_DLL_DECL OutdoorPvPObjectiveAI : public CreatureAI
class TRINITY_DLL_DECL OutdoorPvPObjectiveAI : public NullCreatureAI
{
public:
OutdoorPvPObjectiveAI(Creature *c);
void MoveInLineOfSight(Unit *);
bool IsVisible(Unit *) const;
void AttackStart(Unit *);
void EnterEvadeMode();
void UpdateAI(const uint32 diff);
static int Permissible(const Creature *);
private:
Creature &i_creature;
};
#endif
+1 -13
View File
@@ -38,7 +38,7 @@ int PetAI::Permissible(const Creature *creature)
return PERMIT_BASE_NO;
}
PetAI::PetAI(Creature *c) : i_pet(*c), i_tracker(TIME_INTERVAL_LOOK), inCombat(false)
PetAI::PetAI(Creature *c) : CreatureAI(c), i_pet(*c), i_tracker(TIME_INTERVAL_LOOK), inCombat(false)
{
m_AllySet.clear();
UpdateAllies();
@@ -87,11 +87,6 @@ void PetAI::EnterEvadeMode()
{
}
bool PetAI::IsVisible(Unit *pl) const
{
return _isVisible(pl);
}
bool PetAI::_needToStop() const
{
// This is needed for charmed creatures, as once their target was reset other effects can trigger threat
@@ -291,13 +286,6 @@ void PetAI::UpdateAI(const uint32 diff)
}
}
bool PetAI::_isVisible(Unit *u) const
{
//return false; //( ((Creature*)&i_pet)->GetDistanceSq(u) * 1.0<= sWorld.getConfig(CONFIG_SIGHT_GUARDER) && !u->m_stealth && u->isAlive());
return i_pet.GetDistance(u) < sWorld.getConfig(CONFIG_SIGHT_GUARDER)
&& u->isVisibleForOrDetect(&i_pet,true);
}
void PetAI::UpdateAllies()
{
Unit* owner = i_pet.GetCharmerOrOwner();
-1
View File
@@ -36,7 +36,6 @@ class TRINITY_DLL_DECL PetAI : public CreatureAI
void MoveInLineOfSight(Unit *);
void AttackStart(Unit *);
void EnterEvadeMode();
bool IsVisible(Unit *) const;
void JustDied(Unit* who) { _stopAttack(); }
void UpdateAI(const uint32);
-6
View File
@@ -107,12 +107,6 @@ void PossessedAI::UpdateAI(const uint32 diff)
}
}
bool PossessedAI::_isVisible(Unit *u) const
{
return i_pet.GetDistance(u) < sWorld.getConfig(CONFIG_SIGHT_MONSTER)
&& u->isVisibleForOrDetect(&i_pet,true);
}
void PossessedAI::JustDied(Unit *u)
{
// We died while possessed, disable our loot
+1 -2
View File
@@ -28,7 +28,7 @@ class Creature;
class TRINITY_DLL_DECL PossessedAI : public CreatureAI
{
public:
PossessedAI(Creature *c) : i_pet(*c), i_victimGuid(0) {}
PossessedAI(Creature *c) : CreatureAI(c), i_pet(*c), i_victimGuid(0) {}
// Possessed creatures shouldn't aggro by themselves
void MoveInLineOfSight(Unit *) {}
@@ -36,7 +36,6 @@ class TRINITY_DLL_DECL PossessedAI : public CreatureAI
void EnterEvadeMode() {}
void JustDied(Unit*);
void KilledUnit(Unit* victim);
bool IsVisible(Unit * u) const { return _isVisible(u); }
void UpdateAI(const uint32);
// Never permit this to be used, it must always be initialized with Creature::InitPossessedAI()
+1 -17
View File
@@ -41,22 +41,6 @@ ReactorAI::MoveInLineOfSight(Unit *)
{
}
void
ReactorAI::AttackStart(Unit *p)
{
if(!p)
return;
if(i_creature.Attack(p,true))
{
DEBUG_LOG("Tag unit GUID: %u (TypeId: %u) as a victim", p->GetGUIDLow(), p->GetTypeId());
i_creature.AddThreat(p, 0.0f);
i_victimGuid = p->GetGUID();
i_creature.GetMotionMaster()->MoveChase(p);
}
}
bool
ReactorAI::IsVisible(Unit *) const
{
@@ -67,7 +51,7 @@ void
ReactorAI::UpdateAI(const uint32 /*time_diff*/)
{
// update i_victimGuid if i_creature.getVictim() !=0 and changed
if(!i_creature.SelectHostilTarget() || !i_creature.getVictim())
if(!UpdateVictim())
return;
i_victimGuid = i_creature.getVictim()->GetGUID();
+1 -2
View File
@@ -29,10 +29,9 @@ class TRINITY_DLL_DECL ReactorAI : public CreatureAI
{
public:
ReactorAI(Creature *c) : i_creature(*c), i_victimGuid(0) {}
ReactorAI(Creature *c) : CreatureAI(c), i_creature(*c), i_victimGuid(0) {}
void MoveInLineOfSight(Unit *);
void AttackStart(Unit *);
void EnterEvadeMode();
bool IsVisible(Unit *) const;
+1 -1
View File
@@ -40,7 +40,7 @@ TotemAI::Permissible(const Creature *creature)
return PERMIT_BASE_NO;
}
TotemAI::TotemAI(Creature *c) : i_totem(static_cast<Totem&>(*c)), i_victimGuid(0)
TotemAI::TotemAI(Creature *c) : CreatureAI(c), i_totem(static_cast<Totem&>(*c)), i_victimGuid(0)
{
}
+8 -19
View File
@@ -8208,6 +8208,7 @@ bool Unit::Attack(Unit *victim, bool meleeAttack)
SetInCombatWith(victim);
if(victim->GetTypeId() == TYPEID_PLAYER)
victim->SetInCombatWith(this);
AddThreat(victim, 0.0f);
}
// delay offhand weapon attack to next attack time
@@ -10408,7 +10409,7 @@ void Unit::TauntFadeOut(Unit *taunter)
//======================================================================
Unit* Creature::SelectHostilTarget()
Unit* Creature::SelectVictim()
{
//function provides main threat functionality
//next-victim-selection algorithm and evade mode are called
@@ -10420,10 +10421,6 @@ Unit* Creature::SelectHostilTarget()
Unit* target = NULL;
//This function only useful once AI has been initialized
if (!AI())
return NULL;
if(!m_ThreatManager.isThreatListEmpty())
{
if(!HasAuraType(SPELL_AURA_MOD_TAUNT))
@@ -10438,18 +10435,15 @@ Unit* Creature::SelectHostilTarget()
{
if(!hasUnitState(UNIT_STAT_STUNNED))
SetInFront(target);
AI()->AttackStart(target);
return getVictim();
return target;
}
// no target but something prevent go to evade mode
if( !isInCombat() /*|| HasAuraType(SPELL_AURA_MOD_TAUNT)*/ )
return NULL;
// last case when creature don't must go to evade mode:
// it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
// for example at owner command to pet attack some far away creature
// Note: creature not have targeted movement generator but have attacker in this case
if(m_attackers.size())
return NULL;
/*if( GetMotionMaster()->GetCurrentMovementGeneratorType() != TARGETED_MOTION_TYPE )
{
for(AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr)
@@ -10462,14 +10456,9 @@ Unit* Creature::SelectHostilTarget()
// search nearby enemy before enter evade mode
if(HasReactState(REACT_AGGRESSIVE))
{
if(target = SelectNearestTarget())
{
if(!IsOutOfThreatArea(target))
{
AI()->AttackStart(target);
return getVictim();
}
}
target = SelectNearestTarget();
if(target && !IsOutOfThreatArea(target))
return target;
}
if(m_invisibilityMask)
-1
View File
@@ -1238,7 +1238,6 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
void AddThreat(Unit* pVictim, float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL, SpellEntry const *threatSpell = NULL);
float ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL);
void DeleteThreatList();
//bool SelectHostilTarget();
void TauntApply(Unit* pVictim);
void TauntFadeOut(Unit *taunter);
ThreatManager& getThreatManager() { return m_ThreatManager; }