AzerothCore 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
32 {
33 Permissible<T> const* const p = ASSERT_NOTNULL(dynamic_cast<Permissible<T> const*>(value.second.get()));
34 return p->Permit(obj);
35 }
#define ASSERT_NOTNULL(pointer)
Definition: Errors.h:85
Definition: FactoryHolder.h:49
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)
79 {
80 // special pet case, if a tamed creature uses AIName (example SmartAI) we need to override it
81 if (creature->IsPet())
82 return ASSERT_NOTNULL(sCreatureAIRegistry->GetRegistryItem("PetAI"))->Create(creature);
83
84 // scriptname in db
85 if (CreatureAI* scriptedAI = sScriptMgr->GetCreatureAI(creature))
86 return scriptedAI;
87
88 return SelectFactory<CreatureAI>(creature)->Create(creature);
89 }
#define sCreatureAIRegistry
Definition: CreatureAIFactory.h:48
#define sScriptMgr
Definition: ScriptMgr.h:709
Definition: CreatureAI.h:70
bool IsPet() const
Definition: Unit.h:754

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

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

◆ SelectGameObjectAI()

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

References sScriptMgr.

Referenced by GameObject::AIM_Initialize().

◆ SelectMovementGenerator()

AC_GAME_API MovementGenerator * FactorySelector::SelectMovementGenerator ( Unit unit)
92 {
94 if (Creature* creature = unit->ToCreature())
95 if (!creature->GetCharmerOrOwnerPlayerOrPlayerItself())
96 type = creature->GetDefaultMovementType();
97
98 MovementGeneratorCreator const* mv_factory = sMovementGeneratorRegistry->GetRegistryItem(type);
99 return ASSERT_NOTNULL(mv_factory)->Create(unit);
100 }
MovementGeneratorType
Definition: MotionMaster.h:38
@ IDLE_MOTION_TYPE
Definition: MotionMaster.h:39
#define sMovementGeneratorRegistry
Definition: MovementGenerator.h:105
Definition: FactoryHolder.h:28
Definition: Creature.h:43
Creature * ToCreature()
Definition: Object.h:202

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

Referenced by MotionMaster::InitDefault().