AzeorthCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
FactorySelector Namespace Reference

Classes

struct  PermissibleOrderPred
 

Functions

template<class T , class Value >
int32 GetPermitFor (T const *obj, Value const &value)
 
template<class AI , class T >
FactoryHolder< AI, T > const * SelectFactory (T *obj)
 
CreatureAISelectAI (Creature *creature)
 
MovementGeneratorSelectMovementGenerator (Unit *unit)
 
GameObjectAISelectGameObjectAI (GameObject *go)
 

Function Documentation

◆ GetPermitFor()

template<class T , class Value >
int32 FactorySelector::GetPermitFor ( T const *  obj,
Value const &  value 
)
inline
33 {
34 Permissible<T> const* const p = ASSERT_NOTNULL(dynamic_cast<Permissible<T> const*>(value.second.get()));
35 return p->Permit(obj);
36 }
#define ASSERT_NOTNULL(pointer)
Definition: Errors.h:85
Definition: FactoryHolder.h:50
virtual int32 Permit(T const *) const =0

References ASSERT_NOTNULL, and Permissible< T >::Permit().

Referenced by FactorySelector::PermissibleOrderPred< T >::operator()(), and SelectFactory().

◆ SelectAI()

AC_GAME_API CreatureAI * FactorySelector::SelectAI ( Creature creature)
80 {
81 // special pet case, if a tamed creature uses AIName (example SmartAI) we need to override it
82 if (creature->IsPet())
83 return ASSERT_NOTNULL(sCreatureAIRegistry->GetRegistryItem("PetAI"))->Create(creature);
84
85 // scriptname in db
86 if (CreatureAI* scriptedAI = sScriptMgr->GetCreatureAI(creature))
87 return scriptedAI;
88
89 return SelectFactory<CreatureAI>(creature)->Create(creature);
90 }
#define sCreatureAIRegistry
Definition: CreatureAIFactory.h:48
#define sScriptMgr
Definition: ScriptMgr.h:2690
Definition: CreatureAI.h:70
bool IsPet() const
Definition: Unit.h:1413

References ASSERT_NOTNULL, Unit::IsPet(), sCreatureAIRegistry, and sScriptMgr.

Referenced by Creature::AIM_Initialize().

◆ SelectFactory()

template<class AI , class T >
FactoryHolder< AI, T > const * FactorySelector::SelectFactory ( T *  obj)
inline
56 {
57 static_assert(std::is_same<AI, CreatureAI>::value || std::is_same<AI, GameObjectAI>::value, "Invalid template parameter");
58 static_assert(std::is_same<AI, CreatureAI>::value == std::is_same<T, Creature>::value, "Incompatible AI for type");
59 static_assert(std::is_same<AI, GameObjectAI>::value == std::is_same<T, GameObject>::value, "Incompatible AI for type");
60
62
63 // AIName in db
64 std::string const& aiName = obj->GetAIName();
65 if (!aiName.empty())
66 return AIRegistry::instance()->GetRegistryItem(aiName);
67
68 // select by permit check
69 typename AIRegistry::RegistryMapType const& items = AIRegistry::instance()->GetRegisteredItems();
70 auto itr = std::max_element(items.begin(), items.end(), PermissibleOrderPred<T>(obj));
71 if (itr != items.end() && GetPermitFor(obj, *itr) >= 0)
72 return itr->second.get();
73
74 // should _never_ happen, Null AI types defined as PERMIT_BASE_IDLE, it must've been found
75 ABORT();
76 return nullptr;
77 }
#define ABORT
Definition: Errors.h:76
Definition: CreatureAIRegistry.cpp:33
int32 GetPermitFor(T const *obj, Value const &value)
Definition: CreatureAISelector.cpp:32
Definition: ObjectRegistry.h:32
T const * GetRegistryItem(Key const &key) const
Returns a registry item.
Definition: ObjectRegistry.h:37
Definition: CreatureAISelector.cpp:40

References ABORT, GetPermitFor(), and ObjectRegistry< T, Key >::GetRegistryItem().

◆ SelectGameObjectAI()

AC_GAME_API GameObjectAI * FactorySelector::SelectGameObjectAI ( GameObject go)
104 {
105 // scriptname in db
106 if (GameObjectAI* scriptedAI = sScriptMgr->GetGameObjectAI(go))
107 return scriptedAI;
108
109 return SelectFactory<GameObjectAI>(go)->Create(go);
110 }
Definition: GameObjectAI.h:33

References sScriptMgr.

Referenced by GameObject::AIM_Initialize().

◆ SelectMovementGenerator()

AC_GAME_API MovementGenerator * FactorySelector::SelectMovementGenerator ( Unit unit)
93 {
95 if (Creature* creature = unit->ToCreature())
96 if (!creature->GetCharmerOrOwnerPlayerOrPlayerItself())
97 type = creature->GetDefaultMovementType();
98
99 MovementGeneratorCreator const* mv_factory = sMovementGeneratorRegistry->GetRegistryItem(type);
100 return ASSERT_NOTNULL(mv_factory)->Create(unit);
101 }
MovementGeneratorType
Definition: MotionMaster.h:36
@ IDLE_MOTION_TYPE
Definition: MotionMaster.h:37
#define sMovementGeneratorRegistry
Definition: MovementGenerator.h:107
Definition: FactoryHolder.h:29
Definition: Creature.h:46
Creature * ToCreature()
Definition: Object.h:197

References ASSERT_NOTNULL, IDLE_MOTION_TYPE, sMovementGeneratorRegistry, and Object::ToCreature().

Referenced by MotionMaster::InitDefault().