TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FactorySelector Namespace Reference

Functions

CreatureAIselectAI (Creature *creature)
 
MovementGeneratorselectMovementGenerator (Creature *creature)
 
GameObjectAISelectGameObjectAI (GameObject *go)
 

Function Documentation

TC_GAME_API CreatureAI * FactorySelector::selectAI ( Creature creature)
31  {
32  const CreatureAICreator* ai_factory = NULL;
33 
34  if (creature->IsPet())
35  ai_factory = sCreatureAIRegistry->GetRegistryItem("PetAI");
36 
37  //scriptname in db
38  if (!ai_factory)
39  if (CreatureAI* scriptedAI = sScriptMgr->GetCreatureAI(creature))
40  return scriptedAI;
41 
42  // AIname in db
43  std::string ainame=creature->GetAIName();
44  if (!ai_factory && !ainame.empty())
45  ai_factory = sCreatureAIRegistry->GetRegistryItem(ainame);
46 
47  // select by NPC flags
48  if (!ai_factory)
49  {
50  if (creature->IsVehicle())
51  ai_factory = sCreatureAIRegistry->GetRegistryItem("VehicleAI");
52  else if (creature->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN) && ((Guardian*)creature)->GetOwner()->GetTypeId() == TYPEID_PLAYER)
53  ai_factory = sCreatureAIRegistry->GetRegistryItem("PetAI");
54  else if (creature->HasFlag64(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK))
55  ai_factory = sCreatureAIRegistry->GetRegistryItem("NullCreatureAI");
56  else if (creature->IsGuard())
57  ai_factory = sCreatureAIRegistry->GetRegistryItem("GuardAI");
58  else if (creature->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))
59  ai_factory = sCreatureAIRegistry->GetRegistryItem("PetAI");
60  else if (creature->IsTotem())
61  ai_factory = sCreatureAIRegistry->GetRegistryItem("TotemAI");
62  else if (creature->IsTrigger())
63  {
64  if (creature->m_spells[0])
65  ai_factory = sCreatureAIRegistry->GetRegistryItem("TriggerAI");
66  else
67  ai_factory = sCreatureAIRegistry->GetRegistryItem("NullCreatureAI");
68  }
69  else if (creature->IsCritter() && !creature->HasUnitTypeMask(UNIT_MASK_GUARDIAN))
70  ai_factory = sCreatureAIRegistry->GetRegistryItem("CritterAI");
71  }
72 
73  // select by permit check
74  if (!ai_factory)
75  {
76  int best_val = -1;
77  typedef CreatureAIRegistry::RegistryMapType RMT;
78  RMT const& l = sCreatureAIRegistry->GetRegisteredItems();
79  for (RMT::const_iterator iter = l.begin(); iter != l.end(); ++iter)
80  {
81  const CreatureAICreator* factory = iter->second;
82  const SelectableAI* p = dynamic_cast<const SelectableAI*>(factory);
83  ASSERT(p);
84  int val = p->Permit(creature);
85  if (val > best_val)
86  {
87  best_val = val;
88  ai_factory = p;
89  }
90  }
91  }
92 
93  // select NullCreatureAI if not another cases
94  ainame = (ai_factory == NULL) ? "NullCreatureAI" : ai_factory->key();
95 
96  TC_LOG_DEBUG("scripts", "Creature %s (%s DB GUID: " UI64FMTD ") is using AI type: %s.", creature->GetName().c_str(), creature->GetGUID().ToString().c_str(), creature->GetSpawnId(), ainame.c_str());
97  return (ai_factory == NULL ? new NullCreatureAI(creature) : ai_factory->Create(creature));
98  }
virtual T * Create(void *data=NULL) const =0
Abstract Factory create method.
Definition: TemporarySummon.h:83
Definition: Unit.h:759
Definition: CreatureAIFactory.h:27
bool IsVehicle() const
Definition: Unit.h:1406
Definition: Unit.h:860
#define sCreatureAIRegistry
Definition: CreatureAIFactory.h:53
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: Unit.h:866
#define UI64FMTD
Definition: Define.h:137
Definition: CreatureAI.h:68
bool IsPet() const
Definition: Unit.h:1403
virtual int Permit(const T *) const =0
Definition: ObjectGuid.h:33
uint32 HasUnitTypeMask(uint32 mask) const
Definition: Unit.h:1399
#define ASSERT
Definition: Errors.h:55
Definition: UpdateFields.h:135
#define sScriptMgr
Definition: ScriptMgr.h:837
Definition: PassiveAI.h:52
std::string GetAIName() const
Definition: Creature.cpp:2417
Key key() const
Definition: FactoryHolder.h:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TC_GAME_API GameObjectAI * FactorySelector::SelectGameObjectAI ( GameObject go)
129  {
130  GameObjectAICreator const* ai_factory = NULL;
131 
132  // scriptname in db
133  if (GameObjectAI* scriptedAI = sScriptMgr->GetGameObjectAI(go))
134  return scriptedAI;
135 
136  ai_factory = sGameObjectAIRegistry->GetRegistryItem(go->GetAIName());
137 
138  //future goAI types go here
139 
140  std::string ainame = (ai_factory == NULL || go->GetScriptId()) ? "NullGameObjectAI" : ai_factory->key();
141 
142  TC_LOG_DEBUG("scripts", "%s used AI is %s.", go->GetGUID().ToString().c_str(), ainame.c_str());
143 
144  return (ai_factory == NULL ? new NullGameObjectAI(go) : ai_factory->Create(go));
145  }
virtual T * Create(void *data=NULL) const =0
Abstract Factory create method.
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
#define sGameObjectAIRegistry
Definition: CreatureAIFactory.h:82
std::string GetAIName() const
Definition: GameObject.cpp:90
Definition: GameObjectAI.h:29
ObjectGuid const & GetGUID() const
Definition: Object.h:105
#define sScriptMgr
Definition: ScriptMgr.h:837
Definition: GameObjectAI.h:66
virtual uint32 GetScriptId() const
Definition: GameObject.h:1060
Key key() const
Definition: FactoryHolder.h:36
std::string ToString() const
Definition: ObjectGuid.cpp:99

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TC_GAME_API MovementGenerator * FactorySelector::selectMovementGenerator ( Creature creature)
101  {
102  MovementGeneratorRegistry& mv_registry(*MovementGeneratorRegistry::instance());
103  ASSERT(creature->GetCreatureTemplate());
104  const MovementGeneratorCreator* mv_factory = mv_registry.GetRegistryItem(creature->GetDefaultMovementType());
105 
106  /* if (mv_factory == NULL)
107  {
108  int best_val = -1;
109  StringVector l;
110  mv_registry.GetRegisteredItems(l);
111  for (StringVector::iterator iter = l.begin(); iter != l.end(); ++iter)
112  {
113  const MovementGeneratorCreator *factory = mv_registry.GetRegistryItem((*iter).c_str());
114  const SelectableMovement *p = dynamic_cast<const SelectableMovement *>(factory);
115  ASSERT(p != NULL);
116  int val = p->Permit(creature);
117  if (val > best_val)
118  {
119  best_val = val;
120  mv_factory = p;
121  }
122  }
123  }*/
124 
125  return (mv_factory == NULL ? NULL : mv_factory->Create(creature));
126  }
MovementGeneratorType GetDefaultMovementType() const
Definition: Creature.h:624
arena_t NULL
Definition: jemalloc_internal.h:624
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:558
FactoryHolder< MovementGenerator, MovementGeneratorType >::FactoryHolderRegistry MovementGeneratorRegistry
Definition: MovementGenerator.h:93
#define ASSERT
Definition: Errors.h:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function: