*Move some AI functions to core. No real change.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-05-10 16:07:49 -05:00
parent 518ac83fbf
commit dcf41256dd
17 changed files with 775 additions and 725 deletions
+3 -163
View File
@@ -23,9 +23,7 @@
#include "Common.h"
#include "Platform/Define.h"
#include "Policies/Singleton.h"
#include "Dynamic/ObjectRegistry.h"
#include "Dynamic/FactoryHolder.h"
#include "UnitAI.h"
class WorldObject;
class Unit;
@@ -77,149 +75,11 @@ enum SCEquip
EQUIP_UNEQUIP = 0
};
enum AITarget
{
AITARGET_SELF,
AITARGET_VICTIM,
AITARGET_ENEMY,
AITARGET_ALLY,
AITARGET_BUFF,
AITARGET_DEBUFF,
};
enum AICondition
{
AICOND_AGGRO,
AICOND_COMBAT,
AICOND_DIE,
};
#define AI_DEFAULT_COOLDOWN 5000
struct AISpellInfoType
{
AISpellInfoType() : target(AITARGET_SELF), condition(AICOND_COMBAT), cooldown(AI_DEFAULT_COOLDOWN) {}
AITarget target;
AICondition condition;
uint32 cooldown;
};
extern AISpellInfoType *AISpellInfo;
class EventMap : private std::map<uint32, uint32>
{
private:
uint32 m_time, m_phase;
public:
explicit EventMap() : m_phase(0), m_time(0) {}
void Reset() { clear(); m_time = 0; m_phase = 0; }
void Update(uint32 time) { m_time += time; }
void SetPhase(uint32 phase)
{
if(phase && phase < 9)
m_phase = (1 << (phase + 24));
}
void ScheduleEvent(uint32 eventId, uint32 time, uint32 gcd = 0, uint32 phase = 0)
{
time += m_time;
if(gcd && gcd < 9)
eventId |= (1 << (gcd + 16));
if(phase && phase < 9)
eventId |= (1 << (phase + 24));
iterator itr = find(time);
while(itr != end())
{
++time;
itr = find(time);
}
insert(std::make_pair(time, eventId));
}
uint32 ExecuteEvent()
{
while(!empty())
{
if(begin()->first > m_time)
return 0;
else if(m_phase && (begin()->second & 0xFF000000) && !(begin()->second & m_phase))
erase(begin());
else
{
uint32 eventId = (begin()->second & 0x0000FFFF);
erase(begin());
return eventId;
}
}
return 0;
}
void DelayEvents(uint32 time, uint32 gcd)
{
time += m_time;
gcd = (1 << (gcd + 16));
for(iterator itr = begin(); itr != end();)
{
if(itr->first >= time)
break;
if(itr->second & gcd)
{
ScheduleEvent(time, itr->second);
erase(itr++);
}
else
++itr;
}
}
};
class TRINITY_DLL_SPEC UnitAI
{
protected:
Unit* const me;
public:
explicit UnitAI(Unit *u) : me(u) {}
virtual void AttackStart(Unit *);
virtual void UpdateAI(const uint32 diff) = 0;
virtual void InitializeAI() { Reset(); }
virtual void Reset() {};
// Called when unit is charmed
virtual void OnCharmed(bool apply) = 0;
// Pass parameters between AI
virtual void DoAction(const int32 param) {}
//Do melee swing of current victim if in rnage and ready and not casting
void DoMeleeAttackIfReady();
};
class TRINITY_DLL_SPEC PlayerAI : public UnitAI
{
protected:
Player* const me;
public:
explicit PlayerAI(Player *p) : UnitAI((Unit*)p), me(p) {}
void OnCharmed(bool apply);
};
class TRINITY_DLL_SPEC SimpleCharmedAI : public PlayerAI
{
public:
void UpdateAI(const uint32 diff);
};
class TRINITY_DLL_SPEC CreatureAI : public UnitAI
{
protected:
Creature* const me;
Creature* const m_creature;
Creature * const me;
Creature * const m_creature;
bool UpdateVictim();
public:
@@ -307,22 +167,6 @@ class TRINITY_DLL_SPEC CreatureAI : public UnitAI
void SelectTargetList(std::list<Unit*> &targetList, uint32 num, SelectAggroTarget target, float dist = 0, bool playerOnly = false, int32 aura = 0);
};
struct SelectableAI : public FactoryHolder<CreatureAI>, public Permissible<Creature>
{
SelectableAI(const char *id) : FactoryHolder<CreatureAI>(id) {}
};
template<class REAL_AI>
struct CreatureAIFactory : public SelectableAI
{
CreatureAIFactory(const char *name) : SelectableAI(name) {}
CreatureAI* Create(void *) const;
int Permit(const Creature *c) const { return REAL_AI::Permissible(c); }
};
enum Permitions
{
PERMIT_BASE_NO = -1,
@@ -333,8 +177,4 @@ enum Permitions
PERMIT_BASE_SPECIAL = 800
};
typedef FactoryHolder<CreatureAI> CreatureAICreator;
typedef FactoryHolder<CreatureAI>::FactoryHolderRegistry CreatureAIRegistry;
typedef FactoryHolder<CreatureAI>::FactoryHolderRepository CreatureAIRepository;
#endif