aboutsummaryrefslogtreecommitdiff
path: root/src/game/CreatureAI.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/CreatureAI.h')
-rw-r--r--src/game/CreatureAI.h134
1 files changed, 59 insertions, 75 deletions
diff --git a/src/game/CreatureAI.h b/src/game/CreatureAI.h
index b7a584fd36e..91fabe30448 100644
--- a/src/game/CreatureAI.h
+++ b/src/game/CreatureAI.h
@@ -1,7 +1,7 @@
/*
- * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
- * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
+ * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,12 +21,10 @@
#ifndef TRINITY_CREATUREAI_H
#define TRINITY_CREATUREAI_H
+#include "UnitAI.h"
#include "Common.h"
-#include "Platform/Define.h"
-#include "Policies/Singleton.h"
-#include "Dynamic/ObjectRegistry.h"
-#include "Dynamic/FactoryHolder.h"
+class WorldObject;
class Unit;
class Creature;
class Player;
@@ -36,7 +34,7 @@ struct SpellEntry;
#define VISIBILITY_RANGE 10000
//Spell targets used by SelectSpell
-enum SelectTarget
+enum SelectTargetType
{
SELECT_TARGET_DONTCARE = 0, //All target types allowed
@@ -60,73 +58,42 @@ enum SelectEffect
SELECT_EFFECT_AURA, //Spell applies an aura
};
-//Selection method used by SelectTarget
-enum SelectAggroTarget
+enum SCEquip
{
- SELECT_TARGET_RANDOM = 0, //Just selects a random target
- SELECT_TARGET_TOPAGGRO, //Selects targes from top aggro to bottom
- SELECT_TARGET_BOTTOMAGGRO, //Selects targets from bottom aggro to top
- SELECT_TARGET_NEAREST,
- SELECT_TARGET_FARTHEST,
-};
-
-class TRINITY_DLL_SPEC UnitAI
-{
- protected:
- Unit *me;
- public:
- 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 *me;
- public:
- 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);
+ EQUIP_NO_CHANGE = -1,
+ EQUIP_UNEQUIP = 0
};
class TRINITY_DLL_SPEC CreatureAI : public UnitAI
{
protected:
- Creature *me;
+ Creature * const me;
+ Creature * const m_creature;
bool UpdateVictim();
+ bool UpdateVictimWithGaze();
+ bool UpdateCombatState();
+
+ void SelectNearestTarget(Unit *who);
public:
- CreatureAI(Creature *c) : UnitAI((Unit*)c), me(c) {}
+ explicit CreatureAI(Creature *c) : UnitAI((Unit*)c), me(c), m_creature(c) {}
virtual ~CreatureAI() {}
- // Called if IsVisible(Unit *who) is true at each *who move
+ ///== Reactions At =================================
+
+ // Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter
virtual void MoveInLineOfSight(Unit *);
- // Called at stopping attack by any attacker
+ // Called for reaction at stopping attack at no attackers or targets
virtual void EnterEvadeMode();
+ // Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
+ virtual void EnterCombat(Unit* /*enemy*/) {}
+
// Called at any Damage from any attacker (before damage apply)
+ // Note: it for recalculation damage or special reaction at damage
+ // for attack reaction use AttackedBy called for not DOT damage in Unit::DealDamage also
virtual void DamageTaken(Unit *done_by, uint32 & /*damage*/) {}
// Called when the creature is killed
@@ -146,32 +113,53 @@ class TRINITY_DLL_SPEC CreatureAI : public UnitAI
// Called when spell hits a target
virtual void SpellHitTarget(Unit* target, const SpellEntry*) {}
- // Called when vitim entered water and creature can not enter water
- virtual bool canReachByRangeAttack(Unit*) { return false; }
+ // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
+ //virtual void AttackedBy(Unit* attacker);
// Called when creature is spawned or respawned (for reseting variables)
- virtual void JustRespawned() {}
+ virtual void JustRespawned() { Reset(); }
// Called at waypoint reached or point movement finished
virtual void MovementInform(uint32 /*MovementType*/, uint32 /*Data*/) {}
void OnCharmed(bool apply);
-};
-struct SelectableAI : public FactoryHolder<CreatureAI>, public Permissible<Creature>
-{
+ //virtual void SpellClick(Player *player) {}
- SelectableAI(const char *id) : FactoryHolder<CreatureAI>(id) {}
-};
+ // Called at reaching home after evade
+ virtual void JustReachedHome() {}
-template<class REAL_AI>
-struct CreatureAIFactory : public SelectableAI
-{
- CreatureAIFactory(const char *name) : SelectableAI(name) {}
+ void DoZoneInCombat(Creature* pUnit = NULL);
+
+ // Called at text emote receive from player
+ virtual void ReceiveEmote(Player* pPlayer, uint32 text_emote) {}
+
+ ///== Triggered Actions Requested ==================
- CreatureAI* Create(void *) const;
+ // Called when creature attack expected (if creature can and no have current victim)
+ // Note: for reaction at hostile action must be called AttackedBy function.
+ //virtual void AttackStart(Unit *) {}
- int Permit(const Creature *c) const { return REAL_AI::Permissible(c); }
+ // Called at World update tick
+ //virtual void UpdateAI(const uint32 diff ) {}
+
+ ///== State checks =================================
+
+ // Is unit visible for MoveInLineOfSight
+ //virtual bool IsVisible(Unit *) const { return false; }
+
+ // Called when victim entered water and creature can not enter water
+ virtual bool canReachByRangeAttack(Unit*) { return false; }
+
+ ///== Fields =======================================
+
+ // Pointer to controlled by AI creature
+ //Creature* const m_creature;
+
+ void SetGazeOn(Unit *target);
+
+ protected:
+ bool _EnterEvadeMode();
};
enum Permitions
@@ -184,8 +172,4 @@ enum Permitions
PERMIT_BASE_SPECIAL = 800
};
-typedef FactoryHolder<CreatureAI> CreatureAICreator;
-typedef FactoryHolder<CreatureAI>::FactoryHolderRegistry CreatureAIRegistry;
-typedef FactoryHolder<CreatureAI>::FactoryHolderRepository CreatureAIRepository;
#endif
-