aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2017-12-28 12:12:58 -0300
committerfunjoker <funjoker109@gmail.com>2021-04-15 05:53:27 +0200
commit523dab764b0b3ebe76f957115e976b36fb79987e (patch)
tree58915173a1e50194338174f47092b7470c1ac481
parenta7883380ce4c827db103b0c43faca6632c3d1f66 (diff)
Core/AI: Added a way to specify if certain AI types mustn't be allowed on DB
Ref 072c884ed86a9bf895cd5f53b0f6480ae14c3059 Ref 2c7e921cdc14527bd99d6976793e69999f262f9d (cherry picked from commit a998bba5c239d6bae8426b989ec96475efb969ae)
-rw-r--r--src/server/game/AI/CreatureAIFactory.h17
-rw-r--r--src/server/game/AI/CreatureAIRegistry.cpp4
-rw-r--r--src/server/game/AI/GameObjectAIFactory.h17
-rw-r--r--src/server/game/AI/SelectableAI.h39
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp25
5 files changed, 67 insertions, 35 deletions
diff --git a/src/server/game/AI/CreatureAIFactory.h b/src/server/game/AI/CreatureAIFactory.h
index 70de867e8e8..d8d9c5ea828 100644
--- a/src/server/game/AI/CreatureAIFactory.h
+++ b/src/server/game/AI/CreatureAIFactory.h
@@ -19,22 +19,15 @@
#define TRINITY_CREATUREAIFACTORY_H
#include "ObjectRegistry.h"
-#include "FactoryHolder.h"
+#include "SelectableAI.h"
class Creature;
class CreatureAI;
-typedef FactoryHolder<CreatureAI, Creature> CreatureAICreator;
-
-struct SelectableAI : public CreatureAICreator, public Permissible<Creature>
-{
- SelectableAI(std::string const& name) : CreatureAICreator(name), Permissible<Creature>() { }
-};
-
-template<class REAL_AI>
-struct CreatureAIFactory : public SelectableAI
+template <class REAL_AI, bool is_db_allowed = true>
+struct CreatureAIFactory : public SelectableAI<Creature, CreatureAI, is_db_allowed>
{
- CreatureAIFactory(std::string const& name) : SelectableAI(name) { }
+ CreatureAIFactory(std::string const& name) : SelectableAI<Creature, CreatureAI, is_db_allowed>(name) { }
inline CreatureAI* Create(Creature* c) const override
{
@@ -47,7 +40,7 @@ struct CreatureAIFactory : public SelectableAI
}
};
-typedef CreatureAICreator::FactoryHolderRegistry CreatureAIRegistry;
+typedef SelectableAI<Creature, CreatureAI>::FactoryHolderRegistry CreatureAIRegistry;
#define sCreatureAIRegistry CreatureAIRegistry::instance()
diff --git a/src/server/game/AI/CreatureAIRegistry.cpp b/src/server/game/AI/CreatureAIRegistry.cpp
index 35ba2a56be6..10a06384f49 100644
--- a/src/server/game/AI/CreatureAIRegistry.cpp
+++ b/src/server/game/AI/CreatureAIRegistry.cpp
@@ -41,8 +41,8 @@ namespace AIRegistry
(new CreatureAIFactory<PassiveAI>("PassiveAI"))->RegisterSelf();
(new CreatureAIFactory<CritterAI>("CritterAI"))->RegisterSelf();
(new CreatureAIFactory<GuardAI>("GuardAI"))->RegisterSelf();
- (new CreatureAIFactory<PetAI>("PetAI"))->RegisterSelf();
- (new CreatureAIFactory<TotemAI>("TotemAI"))->RegisterSelf();
+ (new CreatureAIFactory<PetAI, false>("PetAI"))->RegisterSelf();
+ (new CreatureAIFactory<TotemAI, false>("TotemAI"))->RegisterSelf();
(new CreatureAIFactory<CombatAI>("CombatAI"))->RegisterSelf();
(new CreatureAIFactory<ArcherAI>("ArcherAI"))->RegisterSelf();
(new CreatureAIFactory<TurretAI>("TurretAI"))->RegisterSelf();
diff --git a/src/server/game/AI/GameObjectAIFactory.h b/src/server/game/AI/GameObjectAIFactory.h
index 88dcb5cbb81..99d3214b5de 100644
--- a/src/server/game/AI/GameObjectAIFactory.h
+++ b/src/server/game/AI/GameObjectAIFactory.h
@@ -19,22 +19,15 @@
#define TRINITY_GAMEOBJECTAIFACTORY_H
#include "ObjectRegistry.h"
-#include "FactoryHolder.h"
+#include "SelectableAI.h"
class GameObject;
class GameObjectAI;
-typedef FactoryHolder<GameObjectAI, GameObject> GameObjectAICreator;
-
-struct SelectableGameObjectAI : public GameObjectAICreator, public Permissible<GameObject>
-{
- SelectableGameObjectAI(std::string const& name) : GameObjectAICreator(name), Permissible<GameObject>() { }
-};
-
-template<class REAL_GO_AI>
-struct GameObjectAIFactory : public SelectableGameObjectAI
+template <class REAL_GO_AI, bool is_db_allowed = true>
+struct GameObjectAIFactory : public SelectableAI<GameObject, GameObjectAI, is_db_allowed>
{
- GameObjectAIFactory(std::string const& name) : SelectableGameObjectAI(name) { }
+ GameObjectAIFactory(std::string const& name) : SelectableAI<GameObject, GameObjectAI, is_db_allowed>(name) { }
GameObjectAI* Create(GameObject* go) const override
{
@@ -47,7 +40,7 @@ struct GameObjectAIFactory : public SelectableGameObjectAI
}
};
-typedef GameObjectAICreator::FactoryHolderRegistry GameObjectAIRegistry;
+typedef SelectableAI<GameObject, GameObjectAI>::FactoryHolderRegistry GameObjectAIRegistry;
#define sGameObjectAIRegistry GameObjectAIRegistry::instance()
diff --git a/src/server/game/AI/SelectableAI.h b/src/server/game/AI/SelectableAI.h
new file mode 100644
index 00000000000..7b28049ffd5
--- /dev/null
+++ b/src/server/game/AI/SelectableAI.h
@@ -0,0 +1,39 @@
+/*
+ * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
+ *
+ * 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 the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SelectableAI_h__
+#define SelectableAI_h__
+
+#include "FactoryHolder.h"
+
+class DBPermit
+{
+ public:
+ virtual ~DBPermit() { }
+ virtual bool IsScriptNameAllowedInDB() const = 0;
+};
+
+template <class O, class AI, bool is_db_allowed = true>
+struct SelectableAI : public FactoryHolder<AI, O>, public Permissible<O>, public DBPermit
+{
+ SelectableAI(std::string const& name) : FactoryHolder<AI, O>(name), Permissible<O>(), DBPermit() { }
+
+ bool IsScriptNameAllowedInDB() const final override { return is_db_allowed; }
+};
+
+
+#endif // SelectableAI_h__
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 387910ee1e0..12f14c6bbcb 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -946,16 +946,23 @@ void ObjectMgr::CheckCreatureTemplate(CreatureTemplate const* cInfo)
const_cast<CreatureTemplate*>(cInfo)->maxgold = cInfo->mingold;
}
- if (cInfo->AIName == "TotemAI" || cInfo->AIName == "PetAI")
+ if (!cInfo->AIName.empty())
{
- TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has not-allowed `AIName` '%s' set, removing", cInfo->Entry, cInfo->AIName.c_str());
- const_cast<CreatureTemplate*>(cInfo)->AIName.clear();
- }
-
- if (!cInfo->AIName.empty() && !sCreatureAIRegistry->HasItem(cInfo->AIName))
- {
- TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has non-registered `AIName` '%s' set, removing", cInfo->Entry, cInfo->AIName.c_str());
- const_cast<CreatureTemplate*>(cInfo)->AIName.clear();
+ auto registryItem = sCreatureAIRegistry->GetRegistryItem(cInfo->AIName);
+ if (!registryItem)
+ {
+ TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has non-registered `AIName` '%s' set, removing", cInfo->Entry, cInfo->AIName.c_str());
+ const_cast<CreatureTemplate*>(cInfo)->AIName.clear();
+ }
+ else
+ {
+ DBPermit const* permit = dynamic_cast<DBPermit const*>(registryItem);
+ if (!ASSERT_NOTNULL(permit)->IsScriptNameAllowedInDB())
+ {
+ TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has not-allowed `AIName` '%s' set, removing", cInfo->Entry, cInfo->AIName.c_str());
+ const_cast<CreatureTemplate*>(cInfo)->AIName.clear();
+ }
+ }
}
FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(cInfo->faction);