TrinityCore
Loading...
Searching...
No Matches
CreatureAIImpl.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17#ifndef CREATUREAIIMPL_H
18#define CREATUREAIIMPL_H
19
20#include "Random.h"
21#include <type_traits>
22#include <functional>
23
24class WorldObject;
25
26template<typename First, typename Second, typename... Rest>
27inline First const& RAND(First const& first, Second const& second, Rest const&... rest)
28{
29 std::reference_wrapper<typename std::add_const<First>::type> const pack[] = { first, second, rest... };
30 return pack[urand(0, sizeof...(rest) + 1)].get();
31}
32
42
49
50#define AI_DEFAULT_COOLDOWN 5000
51
62
64
65TC_GAME_API bool InstanceHasScript(WorldObject const* obj, char const* scriptName);
66
67template <class AI, class T>
68AI* GetInstanceAI(T* obj, char const* scriptName)
69{
70 if (InstanceHasScript(obj, scriptName))
71 return new AI(obj);
72
73 return nullptr;
74}
75
76#endif
AITarget
@ AITARGET_ALLY
@ AITARGET_BUFF
@ AITARGET_SELF
@ AITARGET_VICTIM
@ AITARGET_ENEMY
@ AITARGET_DEBUFF
TC_GAME_API bool InstanceHasScript(WorldObject const *obj, char const *scriptName)
AISpellInfoType * GetAISpellInfo(uint32 i)
#define AI_DEFAULT_COOLDOWN
First const & RAND(First const &first, Second const &second, Rest const &... rest)
AI * GetInstanceAI(T *obj, char const *scriptName)
AICondition
@ AICOND_COMBAT
@ AICOND_AGGRO
@ AICOND_DIE
#define TC_GAME_API
Definition Define.h:114
uint32_t uint32
Definition Define.h:133
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:42
AICondition condition