TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CreatureAIFactory.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITY_CREATUREAIFACTORY_H
20 #define TRINITY_CREATUREAIFACTORY_H
21 
22 //#include "Policies/Singleton.h"
23 #include "ObjectRegistry.h"
24 #include "FactoryHolder.h"
25 #include "GameObjectAI.h"
26 
27 struct SelectableAI : public FactoryHolder<CreatureAI>, public Permissible<Creature>
28 {
29  SelectableAI(const char* id) : FactoryHolder<CreatureAI>(id) { }
30 };
31 
32 template<class REAL_AI>
34 {
35  CreatureAIFactory(const char* name) : SelectableAI(name) { }
36 
37  CreatureAI* Create(void*) const override;
38 
39  int Permit(const Creature* c) const override { return REAL_AI::Permissible(c); }
40 };
41 
42 template<class REAL_AI>
43 inline CreatureAI*
45 {
46  Creature* creature = reinterpret_cast<Creature*>(data);
47  return (new REAL_AI(creature));
48 }
49 
52 
53 #define sCreatureAIRegistry CreatureAIRegistry::instance()
54 
55 //GO
56 struct SelectableGameObjectAI : public FactoryHolder<GameObjectAI>, public Permissible<GameObject>
57 {
59 };
60 
61 template<class REAL_GO_AI>
63 {
64  GameObjectAIFactory(const char* name) : SelectableGameObjectAI(name) { }
65 
66  GameObjectAI* Create(void*) const override;
67 
68  int Permit(const GameObject* g) const override { return REAL_GO_AI::Permissible(g); }
69 };
70 
71 template<class REAL_GO_AI>
72 inline GameObjectAI*
74 {
75  GameObject* go = reinterpret_cast<GameObject*>(data);
76  return (new REAL_GO_AI(go));
77 }
78 
81 
82 #define sGameObjectAIRegistry GameObjectAIRegistry::instance()
83 
84 #endif
Definition: CreatureAIFactory.h:27
Definition: CreatureAIFactory.h:33
Definition: FactoryHolder.h:29
Definition: Creature.h:467
FactoryHolder< CreatureAI >::FactoryHolderRegistry CreatureAIRegistry
Definition: CreatureAIFactory.h:51
Definition: GameObjectAI.h:29
CreatureAIFactory(const char *name)
Definition: CreatureAIFactory.h:35
SelectableAI(const char *id)
Definition: CreatureAIFactory.h:29
Definition: CreatureAI.h:68
Definition: GameObject.h:880
CreatureAI * Create(void *) const override
Abstract Factory create method.
Definition: CreatureAIFactory.h:44
FactoryHolder< GameObjectAI >::FactoryHolderRegistry GameObjectAIRegistry
Definition: CreatureAIFactory.h:80
FactoryHolder< CreatureAI > CreatureAICreator
Definition: CreatureAIFactory.h:50
Definition: CreatureAIFactory.h:56
Definition: CreatureAIFactory.h:62
GameObjectAIFactory(const char *name)
Definition: CreatureAIFactory.h:64
FactoryHolder< GameObjectAI > GameObjectAICreator
Definition: CreatureAIFactory.h:79
Definition: FactoryHolder.h:52
SelectableGameObjectAI(const char *id)
Definition: CreatureAIFactory.h:58
int Permit(const GameObject *g) const override
Definition: CreatureAIFactory.h:68
GameObjectAI * Create(void *) const override
Abstract Factory create method.
Definition: CreatureAIFactory.h:73
int Permit(const Creature *c) const override
Definition: CreatureAIFactory.h:39