diff options
| author | Shauren <shauren.trinity@gmail.com> | 2023-01-19 21:23:06 +0100 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2023-01-19 21:23:06 +0100 |
| commit | 3df16c12b75c27c85b720a3eced4943a06f060f5 (patch) | |
| tree | 6ae179130fae00602dc119bd2509fc50a71fbc11 /src/server/game | |
| parent | 8568b08350b954afb6603bf2c64897493230f2b1 (diff) | |
Core/Scripts: Move EvadeReason outside of CreatureAI class
Diffstat (limited to 'src/server/game')
| -rw-r--r-- | src/server/game/AI/CoreAI/PassiveAI.cpp | 4 | ||||
| -rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.cpp | 163 | ||||
| -rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.h | 85 | ||||
| -rw-r--r-- | src/server/game/AI/CoreAI/UnitAICommon.cpp | 186 | ||||
| -rw-r--r-- | src/server/game/AI/CoreAI/UnitAICommon.h | 117 | ||||
| -rw-r--r-- | src/server/game/AI/CoreAI/enuminfo_UnitAICommon.cpp | 73 | ||||
| -rw-r--r-- | src/server/game/AI/CreatureAI.cpp | 9 | ||||
| -rw-r--r-- | src/server/game/AI/CreatureAI.h | 14 | ||||
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 2 | ||||
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedEscortAI.h | 2 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 2 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.h | 2 | ||||
| -rw-r--r-- | src/server/game/AI/enuminfo_CreatureAI.cpp | 73 | ||||
| -rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 6 | ||||
| -rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 30 | ||||
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 10 | ||||
| -rw-r--r-- | src/server/game/Entities/Unit/UnitDefines.h | 10 |
17 files changed, 418 insertions, 370 deletions
diff --git a/src/server/game/AI/CoreAI/PassiveAI.cpp b/src/server/game/AI/CoreAI/PassiveAI.cpp index 63a6f9932a1..8bae96a6092 100644 --- a/src/server/game/AI/CoreAI/PassiveAI.cpp +++ b/src/server/game/AI/CoreAI/PassiveAI.cpp @@ -48,7 +48,7 @@ int32 NullCreatureAI::Permissible(Creature const* creature) void PassiveAI::UpdateAI(uint32) { if (me->IsEngaged() && !me->IsInCombat()) - EnterEvadeMode(EVADE_REASON_NO_HOSTILES); + EnterEvadeMode(EvadeReason::NoHostiles); } void PossessedAI::AttackStart(Unit* target) @@ -82,7 +82,7 @@ void CritterAI::JustEngagedWith(Unit* /*who*/) void CritterAI::MovementInform(uint32 type, uint32 /*id*/) { if (type == TIMED_FLEEING_MOTION_TYPE) - EnterEvadeMode(EVADE_REASON_OTHER); + EnterEvadeMode(EvadeReason::Other); } void CritterAI::EnterEvadeMode(EvadeReason why) diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp index a807a178acb..b503441b976 100644 --- a/src/server/game/AI/CoreAI/UnitAI.cpp +++ b/src/server/game/AI/CoreAI/UnitAI.cpp @@ -423,166 +423,3 @@ std::string UnitAI::GetDebugInfo() const << "Me: " << (me ? me->GetDebugInfo() : "NULL"); return sstr.str(); } - -DefaultTargetSelector::DefaultTargetSelector(Unit const* unit, float dist, bool playerOnly, bool withTank, int32 aura) - : _me(unit), _dist(dist), _playerOnly(playerOnly), _exception(!withTank ? unit->GetThreatManager().GetLastVictim() : nullptr), _aura(aura) -{ -} - -bool DefaultTargetSelector::operator()(Unit const* target) const -{ - if (!_me) - return false; - - if (!target) - return false; - - if (_exception && target == _exception) - return false; - - if (_playerOnly && (target->GetTypeId() != TYPEID_PLAYER)) - return false; - - if (_dist > 0.0f && !_me->IsWithinCombatRange(target, _dist)) - return false; - - if (_dist < 0.0f && _me->IsWithinCombatRange(target, -_dist)) - return false; - - if (_aura) - { - if (_aura > 0) - { - if (!target->HasAura(_aura)) - return false; - } - else - { - if (target->HasAura(-_aura)) - return false; - } - } - - return true; -} - -SpellTargetSelector::SpellTargetSelector(Unit* caster, uint32 spellId) : - _caster(caster), _spellInfo(sSpellMgr->GetSpellInfo(spellId, caster->GetMap()->GetDifficultyID())) -{ - ASSERT(_spellInfo); -} - -bool SpellTargetSelector::operator()(Unit const* target) const -{ - if (!target) - return false; - - if (_spellInfo->CheckTarget(_caster, target) != SPELL_CAST_OK) - return false; - - // copypasta from Spell::CheckRange - float minRange = 0.0f; - float maxRange = 0.0f; - float rangeMod = 0.0f; - if (_spellInfo->RangeEntry) - { - if (_spellInfo->RangeEntry->Flags & SPELL_RANGE_MELEE) - { - rangeMod = _caster->GetCombatReach() + 4.0f / 3.0f; - rangeMod += target->GetCombatReach(); - - rangeMod = std::max(rangeMod, NOMINAL_MELEE_RANGE); - } - else - { - float meleeRange = 0.0f; - if (_spellInfo->RangeEntry->Flags & SPELL_RANGE_RANGED) - { - meleeRange = _caster->GetCombatReach() + 4.0f / 3.0f; - meleeRange += target->GetCombatReach(); - - meleeRange = std::max(meleeRange, NOMINAL_MELEE_RANGE); - } - - minRange = _caster->GetSpellMinRangeForTarget(target, _spellInfo) + meleeRange; - maxRange = _caster->GetSpellMaxRangeForTarget(target, _spellInfo); - - rangeMod = _caster->GetCombatReach(); - rangeMod += target->GetCombatReach(); - - if (minRange > 0.0f && !(_spellInfo->RangeEntry->Flags & SPELL_RANGE_RANGED)) - minRange += rangeMod; - } - - if (_caster->isMoving() && target->isMoving() && !_caster->IsWalking() && !target->IsWalking() && - (_spellInfo->RangeEntry->Flags & SPELL_RANGE_MELEE || target->GetTypeId() == TYPEID_PLAYER)) - rangeMod += 8.0f / 3.0f; - } - - maxRange += rangeMod; - - minRange *= minRange; - maxRange *= maxRange; - - if (target != _caster) - { - if (_caster->GetExactDistSq(target) > maxRange) - return false; - - if (minRange > 0.0f && _caster->GetExactDistSq(target) < minRange) - return false; - } - - return true; -} - -bool NonTankTargetSelector::operator()(Unit const* target) const -{ - if (!target) - return false; - - if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER) - return false; - - if (Unit* currentVictim = _source->GetThreatManager().GetCurrentVictim()) - return target != currentVictim; - - return target != _source->GetVictim(); -} - -bool PowerUsersSelector::operator()(Unit const* target) const -{ - if (!_me || !target) - return false; - - if (target->GetPowerType() != _power) - return false; - - if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER) - return false; - - if (_dist > 0.0f && !_me->IsWithinCombatRange(target, _dist)) - return false; - - if (_dist < 0.0f && _me->IsWithinCombatRange(target, -_dist)) - return false; - - return true; -} - -bool FarthestTargetSelector::operator()(Unit const* target) const -{ - if (!_me || !target) - return false; - - if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER) - return false; - - if (_dist > 0.0f && !_me->IsWithinCombatRange(target, _dist)) - return false; - - if (_inLos && !_me->IsWithinLOSInMap(target)) - return false; - - return true; -} diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h index 631f4f45ff6..e7165b69d3f 100644 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -22,6 +22,7 @@ #include "ObjectGuid.h" #include "SharedDefines.h" #include "SpellDefines.h" +#include "UnitAICommon.h" #include <unordered_map> #define CAST_AI(a, b) (dynamic_cast<a*>(b)) @@ -45,90 +46,6 @@ enum Difficulty : uint8; enum MovementGeneratorType : uint8; enum SpellEffIndex : uint8; -// Selection method used by SelectTarget -enum class SelectTargetMethod -{ - Random, // just pick a random target - MaxThreat, // prefer targets higher in the threat list - MinThreat, // prefer targets lower in the threat list - MaxDistance, // prefer targets further from us - MinDistance // prefer targets closer to us -}; - -// default predicate function to select target based on distance, player and/or aura criteria -struct TC_GAME_API DefaultTargetSelector -{ - public: - // unit: the reference unit - // dist: if 0: ignored, if > 0: maximum distance to the reference unit, if < 0: minimum distance to the reference unit - // playerOnly: self explaining - // withMainTank: allow current tank to be selected - // aura: if 0: ignored, if > 0: the target shall have the aura, if < 0, the target shall NOT have the aura - DefaultTargetSelector(Unit const* unit, float dist, bool playerOnly, bool withMainTank, int32 aura); - bool operator()(Unit const* target) const; - - private: - Unit const* _me; - float _dist; - bool _playerOnly; - Unit const* _exception; - int32 _aura; -}; - -// Target selector for spell casts checking range, auras and attributes -/// @todo Add more checks from Spell::CheckCast -struct TC_GAME_API SpellTargetSelector -{ - public: - SpellTargetSelector(Unit* caster, uint32 spellId); - bool operator()(Unit const* target) const; - - private: - Unit const* _caster; - SpellInfo const* _spellInfo; -}; - -// Very simple target selector, will just skip main target -// NOTE: When passing to UnitAI::SelectTarget remember to use 0 as position for random selection -// because tank will not be in the temporary list -struct TC_GAME_API NonTankTargetSelector -{ - public: - NonTankTargetSelector(Unit* source, bool playerOnly = true) : _source(source), _playerOnly(playerOnly) { } - bool operator()(Unit const* target) const; - - private: - Unit* _source; - bool _playerOnly; -}; - -// Simple selector for units using mana -struct TC_GAME_API PowerUsersSelector -{ -public: - PowerUsersSelector(Unit const* unit, Powers power, float dist, bool playerOnly) : _me(unit), _power(power), _dist(dist), _playerOnly(playerOnly) { } - bool operator()(Unit const* target) const; - -private: - Unit const* _me; - Powers const _power; - float const _dist; - bool const _playerOnly; -}; - -struct TC_GAME_API FarthestTargetSelector -{ -public: - FarthestTargetSelector(Unit const* unit, float dist, bool playerOnly, bool inLos) : _me(unit), _dist(dist), _playerOnly(playerOnly), _inLos(inLos) {} - bool operator()(Unit const* target) const; - - private: - Unit const* _me; - float _dist; - bool _playerOnly; - bool _inLos; -}; - class TC_GAME_API UnitAI { protected: diff --git a/src/server/game/AI/CoreAI/UnitAICommon.cpp b/src/server/game/AI/CoreAI/UnitAICommon.cpp new file mode 100644 index 00000000000..51b60ed64f4 --- /dev/null +++ b/src/server/game/AI/CoreAI/UnitAICommon.cpp @@ -0,0 +1,186 @@ +/* + * 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/>. + */ + +#include "UnitAICommon.h" +#include "Map.h" +#include "Spell.h" +#include "SpellInfo.h" +#include "SpellMgr.h" +#include "Unit.h" + +DefaultTargetSelector::DefaultTargetSelector(Unit const* unit, float dist, bool playerOnly, bool withTank, int32 aura) + : _me(unit), _dist(dist), _playerOnly(playerOnly), _exception(!withTank ? unit->GetThreatManager().GetLastVictim() : nullptr), _aura(aura) +{ +} + +bool DefaultTargetSelector::operator()(Unit const* target) const +{ + if (!_me) + return false; + + if (!target) + return false; + + if (_exception && target == _exception) + return false; + + if (_playerOnly && (target->GetTypeId() != TYPEID_PLAYER)) + return false; + + if (_dist > 0.0f && !_me->IsWithinCombatRange(target, _dist)) + return false; + + if (_dist < 0.0f && _me->IsWithinCombatRange(target, -_dist)) + return false; + + if (_aura) + { + if (_aura > 0) + { + if (!target->HasAura(_aura)) + return false; + } + else + { + if (target->HasAura(-_aura)) + return false; + } + } + + return true; +} + +SpellTargetSelector::SpellTargetSelector(Unit* caster, uint32 spellId) : + _caster(caster), _spellInfo(sSpellMgr->GetSpellInfo(spellId, caster->GetMap()->GetDifficultyID())) +{ + ASSERT(_spellInfo); +} + +bool SpellTargetSelector::operator()(Unit const* target) const +{ + if (!target) + return false; + + if (_spellInfo->CheckTarget(_caster, target) != SPELL_CAST_OK) + return false; + + // copypasta from Spell::CheckRange + float minRange = 0.0f; + float maxRange = 0.0f; + float rangeMod = 0.0f; + if (_spellInfo->RangeEntry) + { + if (_spellInfo->RangeEntry->Flags & SPELL_RANGE_MELEE) + { + rangeMod = _caster->GetCombatReach() + 4.0f / 3.0f; + rangeMod += target->GetCombatReach(); + + rangeMod = std::max(rangeMod, NOMINAL_MELEE_RANGE); + } + else + { + float meleeRange = 0.0f; + if (_spellInfo->RangeEntry->Flags & SPELL_RANGE_RANGED) + { + meleeRange = _caster->GetCombatReach() + 4.0f / 3.0f; + meleeRange += target->GetCombatReach(); + + meleeRange = std::max(meleeRange, NOMINAL_MELEE_RANGE); + } + + minRange = _caster->GetSpellMinRangeForTarget(target, _spellInfo) + meleeRange; + maxRange = _caster->GetSpellMaxRangeForTarget(target, _spellInfo); + + rangeMod = _caster->GetCombatReach(); + rangeMod += target->GetCombatReach(); + + if (minRange > 0.0f && !(_spellInfo->RangeEntry->Flags & SPELL_RANGE_RANGED)) + minRange += rangeMod; + } + + if (_caster->isMoving() && target->isMoving() && !_caster->IsWalking() && !target->IsWalking() && + (_spellInfo->RangeEntry->Flags & SPELL_RANGE_MELEE || target->GetTypeId() == TYPEID_PLAYER)) + rangeMod += 8.0f / 3.0f; + } + + maxRange += rangeMod; + + minRange *= minRange; + maxRange *= maxRange; + + if (target != _caster) + { + if (_caster->GetExactDistSq(target) > maxRange) + return false; + + if (minRange > 0.0f && _caster->GetExactDistSq(target) < minRange) + return false; + } + + return true; +} + +bool NonTankTargetSelector::operator()(Unit const* target) const +{ + if (!target) + return false; + + if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER) + return false; + + if (Unit* currentVictim = _source->GetThreatManager().GetCurrentVictim()) + return target != currentVictim; + + return target != _source->GetVictim(); +} + +bool PowerUsersSelector::operator()(Unit const* target) const +{ + if (!_me || !target) + return false; + + if (target->GetPowerType() != _power) + return false; + + if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER) + return false; + + if (_dist > 0.0f && !_me->IsWithinCombatRange(target, _dist)) + return false; + + if (_dist < 0.0f && _me->IsWithinCombatRange(target, -_dist)) + return false; + + return true; +} + +bool FarthestTargetSelector::operator()(Unit const* target) const +{ + if (!_me || !target) + return false; + + if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER) + return false; + + if (_dist > 0.0f && !_me->IsWithinCombatRange(target, _dist)) + return false; + + if (_inLos && !_me->IsWithinLOSInMap(target)) + return false; + + return true; +} diff --git a/src/server/game/AI/CoreAI/UnitAICommon.h b/src/server/game/AI/CoreAI/UnitAICommon.h new file mode 100644 index 00000000000..1c27fb55341 --- /dev/null +++ b/src/server/game/AI/CoreAI/UnitAICommon.h @@ -0,0 +1,117 @@ +/* + * 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 TRINITYCORE_UNIT_AI_COMMON_H +#define TRINITYCORE_UNIT_AI_COMMON_H + +#include "Define.h" + +class SpellInfo; +class Unit; + +enum Powers : int8; + +// EnumUtils: DESCRIBE THIS +enum class EvadeReason +{ + NoHostiles, // the creature's threat list is empty + Boundary, // the creature has moved outside its evade boundary + NoPath, // the creature was unable to reach its target for over 5 seconds + SequenceBreak, // this is a boss and the pre-requisite encounters for engaging it are not defeated yet + Other, // anything else +}; + +// Selection method used by SelectTarget +enum class SelectTargetMethod +{ + Random, // just pick a random target + MaxThreat, // prefer targets higher in the threat list + MinThreat, // prefer targets lower in the threat list + MaxDistance, // prefer targets further from us + MinDistance // prefer targets closer to us +}; + +// default predicate function to select target based on distance, player and/or aura criteria +struct TC_GAME_API DefaultTargetSelector +{ + // unit: the reference unit + // dist: if 0: ignored, if > 0: maximum distance to the reference unit, if < 0: minimum distance to the reference unit + // playerOnly: self explaining + // withMainTank: allow current tank to be selected + // aura: if 0: ignored, if > 0: the target shall have the aura, if < 0, the target shall NOT have the aura + DefaultTargetSelector(Unit const* unit, float dist, bool playerOnly, bool withMainTank, int32 aura); + bool operator()(Unit const* target) const; + +private: + Unit const* _me; + float _dist; + bool _playerOnly; + Unit const* _exception; + int32 _aura; +}; + +// Target selector for spell casts checking range, auras and attributes +/// @todo Add more checks from Spell::CheckCast +struct TC_GAME_API SpellTargetSelector +{ + SpellTargetSelector(Unit* caster, uint32 spellId); + bool operator()(Unit const* target) const; + +private: + Unit const* _caster; + SpellInfo const* _spellInfo; +}; + +// Very simple target selector, will just skip main target +// NOTE: When passing to UnitAI::SelectTarget remember to use 0 as position for random selection +// because tank will not be in the temporary list +struct TC_GAME_API NonTankTargetSelector +{ + NonTankTargetSelector(Unit* source, bool playerOnly = true) : _source(source), _playerOnly(playerOnly) { } + bool operator()(Unit const* target) const; + +private: + Unit* _source; + bool _playerOnly; +}; + +// Simple selector for units using mana +struct TC_GAME_API PowerUsersSelector +{ + PowerUsersSelector(Unit const* unit, Powers power, float dist, bool playerOnly) : _me(unit), _power(power), _dist(dist), _playerOnly(playerOnly) { } + bool operator()(Unit const* target) const; + +private: + Unit const* _me; + Powers const _power; + float const _dist; + bool const _playerOnly; +}; + +struct TC_GAME_API FarthestTargetSelector +{ + FarthestTargetSelector(Unit const* unit, float dist, bool playerOnly, bool inLos) : _me(unit), _dist(dist), _playerOnly(playerOnly), _inLos(inLos) { } + bool operator()(Unit const* target) const; + +private: + Unit const* _me; + float _dist; + bool _playerOnly; + bool _inLos; +}; + +#endif // TRINITYCORE_UNIT_AI_COMMON_H diff --git a/src/server/game/AI/CoreAI/enuminfo_UnitAICommon.cpp b/src/server/game/AI/CoreAI/enuminfo_UnitAICommon.cpp new file mode 100644 index 00000000000..cd70ccd8211 --- /dev/null +++ b/src/server/game/AI/CoreAI/enuminfo_UnitAICommon.cpp @@ -0,0 +1,73 @@ +/* + * 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/>. + */ + +#include "UnitAICommon.h" +#include "Define.h" +#include "SmartEnum.h" +#include <stdexcept> + +namespace Trinity::Impl::EnumUtilsImpl +{ + +/******************************************************************\ +|* data for enum 'EvadeReason' in 'UnitAICommon.h' auto-generated *| +\******************************************************************/ +template <> +TC_API_EXPORT EnumText EnumUtils<EvadeReason>::ToString(EvadeReason value) +{ + switch (value) + { + case EvadeReason::NoHostiles: return { "NoHostiles", "NoHostiles", "the creature's threat list is empty" }; + case EvadeReason::Boundary: return { "Boundary", "Boundary", "the creature has moved outside its evade boundary" }; + case EvadeReason::NoPath: return { "NoPath", "NoPath", "the creature was unable to reach its target for over 5 seconds" }; + case EvadeReason::SequenceBreak: return { "SequenceBreak", "SequenceBreak", "this is a boss and the pre-requisite encounters for engaging it are not defeated yet" }; + case EvadeReason::Other: return { "Other", "Other", "anything else" }; + default: throw std::out_of_range("value"); + } +} + +template <> +TC_API_EXPORT size_t EnumUtils<EvadeReason>::Count() { return 5; } + +template <> +TC_API_EXPORT EvadeReason EnumUtils<EvadeReason>::FromIndex(size_t index) +{ + switch (index) + { + case 0: return EvadeReason::NoHostiles; + case 1: return EvadeReason::Boundary; + case 2: return EvadeReason::NoPath; + case 3: return EvadeReason::SequenceBreak; + case 4: return EvadeReason::Other; + default: throw std::out_of_range("index"); + } +} + +template <> +TC_API_EXPORT size_t EnumUtils<EvadeReason>::ToIndex(EvadeReason value) +{ + switch (value) + { + case EvadeReason::NoHostiles: return 0; + case EvadeReason::Boundary: return 1; + case EvadeReason::NoPath: return 2; + case EvadeReason::SequenceBreak: return 3; + case EvadeReason::Other: return 4; + default: throw std::out_of_range("value"); + } +} +} diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index 3d90489034c..0ae258856a6 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -30,6 +30,7 @@ #include "MotionMaster.h" #include "ObjectAccessor.h" #include "Player.h" +#include "SmartEnum.h" #include "SpellHistory.h" #include "TemporarySummon.h" #include "Vehicle.h" @@ -71,7 +72,7 @@ void CreatureAI::OnCharmed(bool isNew) me->LastCharmerGUID.Clear(); if (!me->IsInCombat()) - EnterEvadeMode(EVADE_REASON_NO_HOSTILES); + EnterEvadeMode(EvadeReason::NoHostiles); } UnitAI::OnCharmed(isNew); @@ -223,7 +224,7 @@ void CreatureAI::EnterEvadeMode(EvadeReason why) if (!_EnterEvadeMode(why)) return; - TC_LOG_DEBUG("scripts.ai", "CreatureAI::EnterEvadeMode: entering evade mode (why: {}) ({})", why, me->GetGUID().ToString()); + TC_LOG_DEBUG("scripts.ai", "CreatureAI::EnterEvadeMode: entering evade mode (why: {}) ({})", EnumUtils::ToConstant(why), me->GetGUID().ToString()); if (!me->GetVehicle()) // otherwise me will be in evade mode forever { @@ -265,7 +266,7 @@ bool CreatureAI::UpdateVictim() } else if (!me->IsInCombat()) { - EnterEvadeMode(EVADE_REASON_NO_HOSTILES); + EnterEvadeMode(EvadeReason::NoHostiles); return false; } else if (me->GetVictim()) @@ -440,7 +441,7 @@ bool CreatureAI::CheckInRoom() return true; else { - EnterEvadeMode(EVADE_REASON_BOUNDARY); + EnterEvadeMode(EvadeReason::Boundary); return false; } } diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index 041b27b6889..a6c03467ca2 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -67,16 +67,6 @@ class TC_GAME_API CreatureAI : public UnitAI Creature* DoSummonFlyer(uint32 entry, WorldObject* obj, float flightZ, float radius = 5.0f, Milliseconds despawnTime = 30s, TempSummonType summonType = TEMPSUMMON_CORPSE_TIMED_DESPAWN); public: - // EnumUtils: DESCRIBE THIS (in CreatureAI::) - enum EvadeReason - { - EVADE_REASON_NO_HOSTILES, // the creature's threat list is empty - EVADE_REASON_BOUNDARY, // the creature has moved outside its evade boundary - EVADE_REASON_NO_PATH, // the creature was unable to reach its target for over 5 seconds - EVADE_REASON_SEQUENCE_BREAK, // this is a boss and the pre-requisite encounters for engaging it are not defeated yet - EVADE_REASON_OTHER, // anything else - }; - explicit CreatureAI(Creature* creature, uint32 scriptId = {}); virtual ~CreatureAI(); @@ -97,7 +87,7 @@ class TC_GAME_API CreatureAI : public UnitAI void TriggerAlert(Unit const* who) const; // Called for reaction at stopping attack at no attackers or targets - virtual void EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER); + virtual void EnterEvadeMode(EvadeReason why = EvadeReason::Other); // Called for reaction whenever we start being in combat (overridden from base UnitAI) void JustEnteredCombat(Unit* /*who*/) override; @@ -250,7 +240,7 @@ class TC_GAME_API CreatureAI : public UnitAI void EngagementOver(); virtual void MoveInLineOfSight(Unit* /*who*/); - bool _EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER); + bool _EnterEvadeMode(EvadeReason why = EvadeReason::Other); CreatureBoundary const* _boundary; bool _negateBoundary; diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 13892b25bc8..e8711ffe473 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -540,7 +540,7 @@ void BossAI::_JustEngagedWith(Unit* who) // bosses do not respawn, check only on enter combat if (!instance->CheckRequiredBosses(_bossId, who->ToPlayer())) { - EnterEvadeMode(EVADE_REASON_SEQUENCE_BREAK); + EnterEvadeMode(EvadeReason::SequenceBreak); return; } instance->SetBossState(_bossId, IN_PROGRESS); diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h index ce37b3dfe73..3a5ed989f43 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h @@ -43,7 +43,7 @@ struct TC_GAME_API EscortAI : public ScriptedAI void MoveInLineOfSight(Unit* who) override; void JustDied(Unit*) override; void ReturnToLastPoint(); - void EnterEvadeMode(EvadeReason /*why*/ = EVADE_REASON_OTHER) override; + void EnterEvadeMode(EvadeReason why) override; void MovementInform(uint32, uint32) override; void UpdateAI(uint32 diff) override; // the "internal" update, calls UpdateEscortAI() diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index d05e22664b4..b7d94165672 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -716,7 +716,7 @@ void SmartAI::OnCharmed(bool isNew) me->LastCharmerGUID.Clear(); if (!me->IsInCombat()) - EnterEvadeMode(EVADE_REASON_NO_HOSTILES); + EnterEvadeMode(EvadeReason::NoHostiles); } } diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h index 1dfd2f9642b..b5f07778d32 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.h +++ b/src/server/game/AI/SmartScripts/SmartAI.h @@ -97,7 +97,7 @@ class TC_GAME_API SmartAI : public CreatureAI void JustEngagedWith(Unit* enemy) override; // Called for reaction at stopping attack at no attackers or targets - void EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER) override; + void EnterEvadeMode(EvadeReason why) override; // Called when the creature is killed void JustDied(Unit* killer) override; diff --git a/src/server/game/AI/enuminfo_CreatureAI.cpp b/src/server/game/AI/enuminfo_CreatureAI.cpp deleted file mode 100644 index c2865d4ebc4..00000000000 --- a/src/server/game/AI/enuminfo_CreatureAI.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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/>. - */ - -#include "CreatureAI.h" -#include "Define.h" -#include "SmartEnum.h" -#include <stdexcept> - -namespace Trinity::Impl::EnumUtilsImpl -{ - -/****************************************************************************\ -|* data for enum 'CreatureAI::EvadeReason' in 'CreatureAI.h' auto-generated *| -\****************************************************************************/ -template <> -TC_API_EXPORT EnumText EnumUtils<CreatureAI::EvadeReason>::ToString(CreatureAI::EvadeReason value) -{ - switch (value) - { - case CreatureAI::EVADE_REASON_NO_HOSTILES: return { "EVADE_REASON_NO_HOSTILES", "EVADE_REASON_NO_HOSTILES", "the creature's threat list is empty" }; - case CreatureAI::EVADE_REASON_BOUNDARY: return { "EVADE_REASON_BOUNDARY", "EVADE_REASON_BOUNDARY", "the creature has moved outside its evade boundary" }; - case CreatureAI::EVADE_REASON_NO_PATH: return { "EVADE_REASON_NO_PATH", "EVADE_REASON_NO_PATH", "the creature was unable to reach its target for over 5 seconds" }; - case CreatureAI::EVADE_REASON_SEQUENCE_BREAK: return { "EVADE_REASON_SEQUENCE_BREAK", "EVADE_REASON_SEQUENCE_BREAK", "this is a boss and the pre-requisite encounters for engaging it are not defeated yet" }; - case CreatureAI::EVADE_REASON_OTHER: return { "EVADE_REASON_OTHER", "EVADE_REASON_OTHER", "anything else" }; - default: throw std::out_of_range("value"); - } -} - -template <> -TC_API_EXPORT size_t EnumUtils<CreatureAI::EvadeReason>::Count() { return 5; } - -template <> -TC_API_EXPORT CreatureAI::EvadeReason EnumUtils<CreatureAI::EvadeReason>::FromIndex(size_t index) -{ - switch (index) - { - case 0: return CreatureAI::EVADE_REASON_NO_HOSTILES; - case 1: return CreatureAI::EVADE_REASON_BOUNDARY; - case 2: return CreatureAI::EVADE_REASON_NO_PATH; - case 3: return CreatureAI::EVADE_REASON_SEQUENCE_BREAK; - case 4: return CreatureAI::EVADE_REASON_OTHER; - default: throw std::out_of_range("index"); - } -} - -template <> -TC_API_EXPORT size_t EnumUtils<CreatureAI::EvadeReason>::ToIndex(CreatureAI::EvadeReason value) -{ - switch (value) - { - case CreatureAI::EVADE_REASON_NO_HOSTILES: return 0; - case CreatureAI::EVADE_REASON_BOUNDARY: return 1; - case CreatureAI::EVADE_REASON_NO_PATH: return 2; - case CreatureAI::EVADE_REASON_SEQUENCE_BREAK: return 3; - case CreatureAI::EVADE_REASON_OTHER: return 4; - default: throw std::out_of_range("value"); - } -} -} diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index aace76abc41..5196192ded6 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -890,7 +890,7 @@ void Creature::Update(uint32 diff) m_cannotReachTimer += diff; if (m_cannotReachTimer >= CREATURE_NOPATH_EVADE_TIME) if (CreatureAI* ai = AI()) - ai->EnterEvadeMode(CreatureAI::EVADE_REASON_NO_PATH); + ai->EnterEvadeMode(EvadeReason::NoPath); } break; } @@ -1235,7 +1235,7 @@ Unit* Creature::SelectVictim() { if ((*itr)->GetBase()->IsPermanent()) { - AI()->EnterEvadeMode(CreatureAI::EVADE_REASON_OTHER); + AI()->EnterEvadeMode(EvadeReason::Other); break; } } @@ -1243,7 +1243,7 @@ Unit* Creature::SelectVictim() } // enter in evade mode in other case - AI()->EnterEvadeMode(CreatureAI::EVADE_REASON_NO_HOSTILES); + AI()->EnterEvadeMode(EvadeReason::NoHostiles); return nullptr; } diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 55bc9162a0c..cb3bbe1a0d6 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -81,21 +81,6 @@ Object::Object() : m_values(this) m_objectUpdated = false; } -WorldObject::~WorldObject() -{ - // this may happen because there are many !create/delete - if (IsWorldObject() && m_currMap) - { - if (GetTypeId() == TYPEID_CORPSE) - { - TC_LOG_FATAL("misc", "WorldObject::~WorldObject Corpse Type: {} ({}) deleted but still in map!!", - ToCorpse()->GetType(), GetGUID().ToString()); - ABORT(); - } - ResetMap(); - } -} - Object::~Object() { if (IsInWorld()) @@ -868,6 +853,21 @@ m_currMap(nullptr), m_InstanceId(0), _dbPhase(0), m_notifyflags(0) m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE); } +WorldObject::~WorldObject() +{ + // this may happen because there are many !create/delete + if (IsWorldObject() && m_currMap) + { + if (GetTypeId() == TYPEID_CORPSE) + { + TC_LOG_FATAL("misc", "WorldObject::~WorldObject Corpse Type: {} ({}) deleted but still in map!!", + ToCorpse()->GetType(), GetGUID().ToString()); + ABORT(); + } + ResetMap(); + } +} + void WorldObject::SetWorldObject(bool on) { if (!IsInWorld()) diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 3192fb9015e..7297f65bb1a 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -333,16 +333,6 @@ enum CombatRating #define MAX_COMBAT_RATING 32 -enum DamageEffectType : uint8 -{ - DIRECT_DAMAGE = 0, // used for normal weapon damage (not for class abilities or spells) - SPELL_DIRECT_DAMAGE = 1, // spell/class abilities damage - DOT = 2, - HEAL = 3, - NODAMAGE = 4, // used also in case when damage applied to health but not applied to spell channelInterruptFlags/etc - SELF_DAMAGE = 5 -}; - enum UnitTypeMask { UNIT_MASK_NONE = 0x00000000, diff --git a/src/server/game/Entities/Unit/UnitDefines.h b/src/server/game/Entities/Unit/UnitDefines.h index 759f3070458..43fd866adb9 100644 --- a/src/server/game/Entities/Unit/UnitDefines.h +++ b/src/server/game/Entities/Unit/UnitDefines.h @@ -122,6 +122,16 @@ enum UnitMoveType #define MAX_MOVE_TYPE 9 +enum DamageEffectType : uint8 +{ + DIRECT_DAMAGE = 0, // used for normal weapon damage (not for class abilities or spells) + SPELL_DIRECT_DAMAGE = 1, // spell/class abilities damage + DOT = 2, + HEAL = 3, + NODAMAGE = 4, // used also in case when damage applied to health but not applied to spell channelInterruptFlags/etc + SELF_DAMAGE = 5 +}; + // Value masks for UNIT_FIELD_FLAGS // EnumUtils: DESCRIBE THIS enum UnitFlags : uint32 |
