diff options
| author | Shauren <shauren.trinity@gmail.com> | 2017-05-28 16:34:44 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2017-05-28 16:34:44 +0200 |
| commit | a0a158b5b851db7e2c16819ec89e913d914a3aba (patch) | |
| tree | e2170b14fe7bba2bf70c30500eb129c6eadc2c20 /src/server/game | |
| parent | d427fed13b49aec1722544b3ca72a0a41160bbe3 (diff) | |
Core/Scripts: Include cleanup
Diffstat (limited to 'src/server/game')
37 files changed, 321 insertions, 190 deletions
diff --git a/src/server/game/AI/CoreAI/CombatAI.cpp b/src/server/game/AI/CoreAI/CombatAI.cpp index d9aaf102db7..88ef940ace3 100644 --- a/src/server/game/AI/CoreAI/CombatAI.cpp +++ b/src/server/game/AI/CoreAI/CombatAI.cpp @@ -17,12 +17,15 @@ */ #include "CombatAI.h" -#include "SpellMgr.h" -#include "SpellInfo.h" -#include "Vehicle.h" +#include "ConditionMgr.h" +#include "Creature.h" +#include "CreatureAIImpl.h" +#include "Log.h" #include "ObjectAccessor.h" #include "Player.h" -#include "Log.h" +#include "SpellInfo.h" +#include "SpellMgr.h" +#include "Vehicle.h" ///////////////// // AggressorAI diff --git a/src/server/game/AI/CoreAI/CombatAI.h b/src/server/game/AI/CoreAI/CombatAI.h index 27f8efa712a..519c8a794c8 100644 --- a/src/server/game/AI/CoreAI/CombatAI.h +++ b/src/server/game/AI/CoreAI/CombatAI.h @@ -20,8 +20,6 @@ #define TRINITY_COMBATAI_H #include "CreatureAI.h" -#include "CreatureAIImpl.h" -#include "ConditionMgr.h" class Creature; diff --git a/src/server/game/AI/CoreAI/GuardAI.cpp b/src/server/game/AI/CoreAI/GuardAI.cpp index 25757ef5025..b52168a6f77 100644 --- a/src/server/game/AI/CoreAI/GuardAI.cpp +++ b/src/server/game/AI/CoreAI/GuardAI.cpp @@ -17,10 +17,15 @@ */ #include "GuardAI.h" +#include "Creature.h" #include "Errors.h" #include "Log.h" #include "Player.h" +GuardAI::GuardAI(Creature* creature) : ScriptedAI(creature) +{ +} + int GuardAI::Permissible(Creature const* creature) { if (creature->IsGuard()) @@ -29,7 +34,13 @@ int GuardAI::Permissible(Creature const* creature) return PERMIT_BASE_NO; } -GuardAI::GuardAI(Creature* creature) : ScriptedAI(creature) { } +void GuardAI::UpdateAI(uint32 diff) +{ + if (!UpdateVictim()) + return; + + DoMeleeAttackIfReady(); +} bool GuardAI::CanSeeAlways(WorldObject const* obj) { diff --git a/src/server/game/AI/CoreAI/GuardAI.h b/src/server/game/AI/CoreAI/GuardAI.h index dfcf5997f4f..263f1d6abf3 100644 --- a/src/server/game/AI/CoreAI/GuardAI.h +++ b/src/server/game/AI/CoreAI/GuardAI.h @@ -29,6 +29,7 @@ class TC_GAME_API GuardAI : public ScriptedAI explicit GuardAI(Creature* creature); static int Permissible(Creature const* creature); + void UpdateAI(uint32 diff) override; bool CanSeeAlways(WorldObject const* obj) override; void EnterEvadeMode(EvadeReason /*why*/) override; diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp index 65ce74106d3..4507d064bea 100644 --- a/src/server/game/AI/CoreAI/UnitAI.cpp +++ b/src/server/game/AI/CoreAI/UnitAI.cpp @@ -40,6 +40,12 @@ void UnitAI::AttackStart(Unit* victim) } } +void UnitAI::InitializeAI() +{ + if (!me->isDead()) + Reset(); +} + void UnitAI::AttackStartCaster(Unit* victim, float dist) { if (victim && me->Attack(victim, false)) @@ -230,6 +236,11 @@ void UnitAI::FillAISpellInfo() } } +ThreatManager& UnitAI::GetThreatManager() +{ + return me->getThreatManager(); +} + bool DefaultTargetSelector::operator()(Unit const* target) const { if (!me) @@ -347,3 +358,8 @@ bool NonTankTargetSelector::operator()(Unit const* target) const return target != _source->GetVictim(); } + +void SortByDistanceTo(Unit* reference, std::list<Unit*>& targets) +{ + targets.sort(Trinity::ObjectDistanceOrderPred(reference)); +} diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h index c9f56d5caba..e34c17e641a 100644 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -19,11 +19,10 @@ #ifndef TRINITY_UNITAI_H #define TRINITY_UNITAI_H -#include "Define.h" -#include "Unit.h" #include "Containers.h" #include "EventMap.h" -#include <list> +#include "ObjectGuid.h" +#include "ThreatManager.h" #define CAST_AI(a, b) (dynamic_cast<a*>(b)) #define ENSURE_AI(a,b) (EnsureAI<a>(b)) @@ -38,7 +37,11 @@ inline T* EnsureAI(U* ai) class Player; class Quest; +class SpellInfo; +class Unit; struct AISpellInfoType; +enum DamageEffectType : uint8; +enum SpellEffIndex : uint8; //Selection method used by SelectTarget enum SelectAggroTarget @@ -51,9 +54,9 @@ enum SelectAggroTarget }; // default predicate function to select target based on distance, player and/or aura criteria -struct TC_GAME_API DefaultTargetSelector : public std::unary_function<Unit*, bool> +struct TC_GAME_API DefaultTargetSelector { - const Unit* me; + Unit const* me; float m_dist; bool m_playerOnly; int32 m_aura; @@ -94,6 +97,8 @@ struct TC_GAME_API NonTankTargetSelector : public std::unary_function<Unit*, boo bool _playerOnly; }; +TC_GAME_API void SortByDistanceTo(Unit* reference, std::list<Unit*>& targets); + class TC_GAME_API UnitAI { protected: @@ -106,7 +111,7 @@ class TC_GAME_API UnitAI virtual void AttackStart(Unit* /*target*/); virtual void UpdateAI(uint32 diff) = 0; - virtual void InitializeAI() { if (!me->isDead()) Reset(); } + virtual void InitializeAI(); virtual void Reset() { } @@ -122,16 +127,16 @@ class TC_GAME_API UnitAI Unit* SelectTarget(SelectAggroTarget targetType, uint32 position = 0, float dist = 0.0f, bool playerOnly = false, int32 aura = 0); // Select the targets satisfying the predicate. - // predicate shall extend std::unary_function<Unit*, bool> - template<class PREDICATE> Unit* SelectTarget(SelectAggroTarget targetType, uint32 position, PREDICATE const& predicate) + template<class PREDICATE> + Unit* SelectTarget(SelectAggroTarget targetType, uint32 position, PREDICATE const& predicate) { - ThreatContainer::StorageType const& threatlist = me->getThreatManager().getThreatList(); + ThreatContainer::StorageType const& threatlist = GetThreatManager().getThreatList(); if (position >= threatlist.size()) return nullptr; std::list<Unit*> targetList; Unit* currentVictim = nullptr; - if (auto currentVictimReference = me->getThreatManager().getCurrentVictim()) + if (auto currentVictimReference = GetThreatManager().getCurrentVictim()) { currentVictim = currentVictimReference->getTarget(); @@ -140,42 +145,38 @@ class TC_GAME_API UnitAI targetList.push_back(currentVictim); } - for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr) + for (HostileReference* hostileRef : threatlist) { - if (currentVictim != nullptr && (*itr)->getTarget() != currentVictim && predicate((*itr)->getTarget())) - targetList.push_back((*itr)->getTarget()); - else if (currentVictim == nullptr && predicate((*itr)->getTarget())) - targetList.push_back((*itr)->getTarget()); + if (currentVictim != nullptr && hostileRef->getTarget() != currentVictim && predicate(hostileRef->getTarget())) + targetList.push_back(hostileRef->getTarget()); + else if (currentVictim == nullptr && predicate(hostileRef->getTarget())) + targetList.push_back(hostileRef->getTarget()); } if (position >= targetList.size()) return nullptr; if (targetType == SELECT_TARGET_NEAREST || targetType == SELECT_TARGET_FARTHEST) - targetList.sort(Trinity::ObjectDistanceOrderPred(me)); + SortByDistanceTo(me, targetList); switch (targetType) { case SELECT_TARGET_NEAREST: case SELECT_TARGET_TOPAGGRO: { - std::list<Unit*>::iterator itr = targetList.begin(); + auto itr = targetList.begin(); std::advance(itr, position); return *itr; } case SELECT_TARGET_FARTHEST: case SELECT_TARGET_BOTTOMAGGRO: { - std::list<Unit*>::reverse_iterator ritr = targetList.rbegin(); + auto ritr = targetList.rbegin(); std::advance(ritr, position); return *ritr; } case SELECT_TARGET_RANDOM: - { - std::list<Unit*>::iterator itr = targetList.begin(); - std::advance(itr, urand(position, uint32(targetList.size() - 1))); - return *itr; - } + return Trinity::Containers::SelectRandomContainerElement(targetList); default: break; } @@ -186,22 +187,22 @@ class TC_GAME_API UnitAI void SelectTargetList(std::list<Unit*>& targetList, uint32 num, SelectAggroTarget targetType, float dist = 0.0f, bool playerOnly = false, int32 aura = 0); // Select the targets satifying the predicate. - // predicate shall extend std::unary_function<Unit*, bool> - template <class PREDICATE> void SelectTargetList(std::list<Unit*>& targetList, PREDICATE const& predicate, uint32 maxTargets, SelectAggroTarget targetType) + template <class PREDICATE> + void SelectTargetList(std::list<Unit*>& targetList, PREDICATE const& predicate, uint32 maxTargets, SelectAggroTarget targetType) { - ThreatContainer::StorageType const& threatlist = me->getThreatManager().getThreatList(); + ThreatContainer::StorageType const& threatlist = GetThreatManager().getThreatList(); if (threatlist.empty()) return; - for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr) - if (predicate((*itr)->getTarget())) - targetList.push_back((*itr)->getTarget()); + for (HostileReference* hostileRef : threatlist) + if (predicate(hostileRef->getTarget())) + targetList.push_back(hostileRef->getTarget()); if (targetList.size() < maxTargets) return; if (targetType == SELECT_TARGET_NEAREST || targetType == SELECT_TARGET_FARTHEST) - targetList.sort(Trinity::ObjectDistanceOrderPred(me)); + SortByDistanceTo(me, targetList); if (targetType == SELECT_TARGET_FARTHEST || targetType == SELECT_TARGET_BOTTOMAGGRO) targetList.reverse(); @@ -256,6 +257,8 @@ class TC_GAME_API UnitAI private: UnitAI(UnitAI const& right) = delete; UnitAI& operator=(UnitAI const& right) = delete; + + ThreatManager& GetThreatManager(); }; #endif diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index faac3ad6767..2dd54975ba6 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -17,16 +17,18 @@ */ #include "CreatureAI.h" -#include "CreatureAIImpl.h" +#include "AreaBoundary.h" #include "Creature.h" -#include "World.h" -#include "SpellMgr.h" -#include "Vehicle.h" +#include "CreatureAIImpl.h" +#include "CreatureTextMgr.h" +#include "Language.h" #include "Log.h" #include "MapReference.h" #include "Player.h" -#include "CreatureTextMgr.h" -#include "Language.h" +#include "SpellMgr.h" +#include "TemporarySummon.h" +#include "Vehicle.h" +#include "World.h" //Disable CreatureAI when charmed void CreatureAI::OnCharmed(bool apply) @@ -39,7 +41,7 @@ void CreatureAI::OnCharmed(bool apply) } AISpellInfoType* UnitAI::AISpellInfo; -AISpellInfoType* GetAISpellInfo(uint32 i) { return &CreatureAI::AISpellInfo[i]; } +AISpellInfoType* GetAISpellInfo(uint32 i) { return &UnitAI::AISpellInfo[i]; } CreatureAI::CreatureAI(Creature* creature) : UnitAI(creature), me(creature), _boundary(nullptr), m_MoveInLineOfSight_locked(false) { @@ -364,8 +366,8 @@ bool CreatureAI::CheckBoundary(Position const* who) const who = me; if (_boundary) - for (CreatureBoundary::const_iterator it = _boundary->begin(); it != _boundary->end(); ++it) - if (!(*it)->IsWithinBoundary(who)) + for (AreaBoundary const* boundary : *_boundary) + if (!boundary->IsWithinBoundary(who)) return false; return true; diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index 0e7652569fb..63ecf516666 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -20,15 +20,19 @@ #define TRINITY_CREATUREAI_H #include "UnitAI.h" -#include "AreaBoundary.h" #include "Common.h" +#include "ObjectDefines.h" -class WorldObject; -class Unit; +class AreaBoundary; +class AreaTrigger; class Creature; -class Player; +class DynamicObject; +class GameObject; class PlayerAI; -class SpellInfo; +class WorldObject; +struct Position; + +typedef std::set<AreaBoundary const*> CreatureBoundary; #define TIME_INTERVAL_LOOK 5000 #define VISIBILITY_RANGE 10000 @@ -64,7 +68,6 @@ enum SCEquip EQUIP_UNEQUIP = 0 }; -typedef std::set<AreaBoundary const*> CreatureBoundary; class TC_GAME_API CreatureAI : public UnitAI { protected: diff --git a/src/server/game/AI/CreatureAIImpl.h b/src/server/game/AI/CreatureAIImpl.h index e0346eac10a..39261718180 100644 --- a/src/server/game/AI/CreatureAIImpl.h +++ b/src/server/game/AI/CreatureAIImpl.h @@ -17,17 +17,13 @@ #ifndef CREATUREAIIMPL_H #define CREATUREAIIMPL_H -#include "Common.h" -#include "Define.h" -#include "TemporarySummon.h" -#include "CreatureAI.h" -#include "SpellMgr.h" - -#include <functional> +#include "Random.h" #include <type_traits> +class WorldObject; + template<typename First, typename Second, typename... Rest> -static inline First const& RAND(First const& first, Second const& second, Rest const&... rest) +inline First const& RAND(First const& first, Second const& second, Rest const&... rest) { std::reference_wrapper<typename std::add_const<First>::type> const pack[] = { first, second, rest... }; return pack[urand(0, sizeof...(rest) + 1)].get(); @@ -65,5 +61,15 @@ struct AISpellInfoType AISpellInfoType* GetAISpellInfo(uint32 i); -#endif +TC_GAME_API bool InstanceHasScript(WorldObject const* obj, char const* scriptName); + +template<class AI, class T> +inline AI* GetInstanceAI(T* obj, char const* scriptName) +{ + if (InstanceHasScript(obj, scriptName)) + return new AI(obj); + + return nullptr; +} +#endif diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 12220998df2..f9334bf9710 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -17,14 +17,15 @@ */ #include "ScriptedCreature.h" -#include "Spell.h" -#include "GridNotifiers.h" -#include "GridNotifiersImpl.h" +#include "AreaBoundary.h" #include "Cell.h" #include "CellImpl.h" +#include "GridNotifiers.h" +#include "GridNotifiersImpl.h" +#include "InstanceScript.h" #include "Log.h" #include "ObjectMgr.h" -#include "AreaBoundary.h" +#include "Spell.h" // Spell summary for ScriptedAI::SelectSpell struct TSpellSummary @@ -33,6 +34,16 @@ struct TSpellSummary uint8 Effects; // set of enum SelectEffect } extern* SpellSummary; +void SummonList::Summon(Creature const* summon) +{ + storage_.push_back(summon->GetGUID()); +} + +void SummonList::Despawn(Creature const* summon) +{ + storage_.remove(summon->GetGUID()); +} + void SummonList::DoZoneInCombat(uint32 entry, float maxRangeToNearestTarget) { for (StorageType::iterator i = storage_.begin(); i != storage_.end();) @@ -190,6 +201,16 @@ Creature* ScriptedAI::DoSpawnCreature(uint32 entry, float offsetX, float offsetY return me->SummonCreature(entry, me->GetPositionX() + offsetX, me->GetPositionY() + offsetY, me->GetPositionZ() + offsetZ, angle, TempSummonType(type), despawntime); } +bool ScriptedAI::HealthBelowPct(uint32 pct) const +{ + return me->HealthBelowPct(pct); +} + +bool ScriptedAI::HealthAbovePct(uint32 pct) const +{ + return me->HealthAbovePct(pct); +} + SpellInfo const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 mechanic, SelectTargetType targets, float rangeMin, float rangeMax, SelectEffect effect) { //No target so we can't cast @@ -482,6 +503,11 @@ void BossAI::_JustDied() instance->SetBossState(_bossId, DONE); } +void BossAI::_JustReachedHome() +{ + me->setActive(false); +} + void BossAI::_EnterCombat() { if (instance) @@ -545,6 +571,11 @@ void BossAI::UpdateAI(uint32 diff) DoMeleeAttackIfReady(); } +bool BossAI::CanAIAttack(Unit const* target) const +{ + return CheckBoundary(target); +} + void BossAI::_DespawnAtEvade(uint32 delayToRespawn, Creature* who) { if (delayToRespawn < 2) diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index e9c8168cf63..8b634579b48 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -19,10 +19,9 @@ #ifndef SCRIPTEDCREATURE_H_ #define SCRIPTEDCREATURE_H_ -#include "Creature.h" #include "CreatureAI.h" -#include "CreatureAIImpl.h" -#include "InstanceScript.h" +#include "Creature.h" // convenience include for scripts, all uses of ScriptedCreature also need Creature (except ScriptedCreature itself doesn't need Creature) +#include "DBCEnums.h" #include "TaskScheduler.h" class InstanceScript; @@ -84,8 +83,8 @@ public: storage_.clear(); } - void Summon(Creature const* summon) { storage_.push_back(summon->GetGUID()); } - void Despawn(Creature const* summon) { storage_.remove(summon->GetGUID()); } + void Summon(Creature const* summon); + void Despawn(Creature const* summon); void DespawnEntry(uint32 entry); void DespawnAll(); @@ -236,8 +235,8 @@ struct TC_GAME_API ScriptedAI : public CreatureAI //Spawns a creature relative to me Creature* DoSpawnCreature(uint32 entry, float offsetX, float offsetY, float offsetZ, float angle, uint32 type, uint32 despawntime); - bool HealthBelowPct(uint32 pct) const { return me->HealthBelowPct(pct); } - bool HealthAbovePct(uint32 pct) const { return me->HealthAbovePct(pct); } + bool HealthBelowPct(uint32 pct) const; + bool HealthAbovePct(uint32 pct) const; //Returns spells that meet the specified criteria from the creatures spell list SpellInfo const* SelectSpell(Unit* target, uint32 school, uint32 mechanic, SelectTargetType targets, float rangeMin, float rangeMax, SelectEffect effect); @@ -349,13 +348,13 @@ class TC_GAME_API BossAI : public ScriptedAI void JustDied(Unit* /*killer*/) override { _JustDied(); } void JustReachedHome() override { _JustReachedHome(); } - bool CanAIAttack(Unit const* target) const override { return CheckBoundary(target); } + bool CanAIAttack(Unit const* target) const override; protected: void _Reset(); void _EnterCombat(); void _JustDied(); - void _JustReachedHome() { me->setActive(false); } + void _JustReachedHome(); void _DespawnAtEvade(uint32 delayToRespawn = 30, Creature* who = nullptr); void _DespawnAtEvade(Seconds const& time, Creature* who = nullptr) { _DespawnAtEvade(uint32(time.count()), who); } diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index efa096196f3..e0de158831c 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -24,11 +24,11 @@ SDCategory: Npc EndScriptData */ #include "ScriptedEscortAI.h" +#include "Creature.h" #include "Group.h" #include "Log.h" #include "ObjectAccessor.h" #include "Player.h" -#include "ScriptedCreature.h" enum Points { diff --git a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp index e6fa110ad7f..7a1bcb14680 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp @@ -24,11 +24,11 @@ SDCategory: Npc EndScriptData */ #include "ScriptedFollowerAI.h" +#include "Creature.h" #include "Log.h" #include "Group.h" #include "ObjectAccessor.h" #include "Player.h" -#include "ScriptedCreature.h" const float MAX_PLAYER_DISTANCE = 100.0f; diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index afaffc5abb8..0280af9498e 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -22,18 +22,19 @@ #include "CreatureTextMgr.h" #include "GameEventMgr.h" #include "GameObject.h" +#include "GossipDef.h" #include "GridNotifiersImpl.h" #include "InstanceScript.h" #include "Language.h" #include "Log.h" #include "Map.h" #include "ObjectAccessor.h" +#include "ObjectMgr.h" #include "Random.h" -#include "ScriptedCreature.h" -#include "ScriptedGossip.h" #include "SmartAI.h" #include "SpellAuras.h" #include "Vehicle.h" +#include <G3D/Quat.h> SmartScript::SmartScript() { @@ -1447,7 +1448,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u Position pos = (*itr)->GetPositionWithOffset(Position(e.target.x, e.target.y, e.target.z, e.target.o)); G3D::Quat rot = G3D::Matrix3::fromEulerAnglesZYX(pos.GetOrientation(), 0.f, 0.f); - summoner->SummonGameObject(e.action.summonGO.entry, pos, rot, e.action.summonGO.despawnTime); + summoner->SummonGameObject(e.action.summonGO.entry, pos, QuaternionData(rot.x, rot.y, rot.z, rot.w), e.action.summonGO.despawnTime); } delete targets; @@ -1457,7 +1458,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u break; G3D::Quat rot = G3D::Matrix3::fromEulerAnglesZYX(e.target.o, 0.f, 0.f); - summoner->SummonGameObject(e.action.summonGO.entry, Position(e.target.x, e.target.y, e.target.z, e.target.o), rot, e.action.summonGO.despawnTime); + summoner->SummonGameObject(e.action.summonGO.entry, Position(e.target.x, e.target.y, e.target.z, e.target.o), QuaternionData(rot.x, rot.y, rot.z, rot.w), e.action.summonGO.despawnTime); break; } case SMART_ACTION_KILL_UNIT: @@ -2294,9 +2295,9 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u if (e.action.sendGossipMenu.gossipMenuId) player->PrepareGossipMenu(GetBaseObject(), e.action.sendGossipMenu.gossipMenuId, true); else - ClearGossipMenuFor(player); + player->PlayerTalkClass->ClearMenus(); - SendGossipMenuFor(player, e.action.sendGossipMenu.gossipNpcTextId, GetBaseObject()->GetGUID()); + player->PlayerTalkClass->SendGossipMenu(e.action.sendGossipMenu.gossipNpcTextId, GetBaseObject()->GetGUID()); } } @@ -2971,13 +2972,13 @@ ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /* } case SMART_TARGET_CLOSEST_CREATURE: { - if (Creature* target = GetClosestCreatureWithEntry(baseObject, e.target.closest.entry, float(e.target.closest.dist ? e.target.closest.dist : 100), !e.target.closest.dead)) + if (Creature* target = baseObject->FindNearestCreature(e.target.closest.entry, float(e.target.closest.dist ? e.target.closest.dist : 100), !e.target.closest.dead)) l->push_back(target); break; } case SMART_TARGET_CLOSEST_GAMEOBJECT: { - if (GameObject* target = GetClosestGameObjectWithEntry(baseObject, e.target.closest.entry, float(e.target.closest.dist ? e.target.closest.dist : 100))) + if (GameObject* target = baseObject->FindNearestGameObject(e.target.closest.entry, float(e.target.closest.dist ? e.target.closest.dist : 100))) l->push_back(target); break; } diff --git a/src/server/game/Battlefield/Battlefield.cpp b/src/server/game/Battlefield/Battlefield.cpp index 2e243dd851d..f8538ab0a43 100644 --- a/src/server/game/Battlefield/Battlefield.cpp +++ b/src/server/game/Battlefield/Battlefield.cpp @@ -822,7 +822,7 @@ Creature* Battlefield::SpawnCreature(uint32 entry, Position const& pos) } // Method for spawning gameobject on map -GameObject* Battlefield::SpawnGameObject(uint32 entry, Position const& pos, G3D::Quat const& rot) +GameObject* Battlefield::SpawnGameObject(uint32 entry, Position const& pos, QuaternionData const& rot) { // Get map object Map* map = sMapMgr->CreateBaseMap(m_MapId); diff --git a/src/server/game/Battlefield/Battlefield.h b/src/server/game/Battlefield/Battlefield.h index 71b48f81de1..6cfe1158d08 100644 --- a/src/server/game/Battlefield/Battlefield.h +++ b/src/server/game/Battlefield/Battlefield.h @@ -76,8 +76,8 @@ class Map; class Player; class Unit; class WorldPacket; - struct Position; +struct QuaternionData; struct WorldSafeLocsEntry; namespace WorldPackets @@ -88,11 +88,6 @@ namespace WorldPackets } } -namespace G3D -{ - class Quat; -} - typedef std::vector<BfGraveyard*> GraveyardVect; typedef std::map<ObjectGuid, time_t> PlayerTimerMap; @@ -313,7 +308,7 @@ class TC_GAME_API Battlefield : public ZoneScript // Misc methods Creature* SpawnCreature(uint32 entry, Position const& pos); - GameObject* SpawnGameObject(uint32 entry, Position const& pos, G3D::Quat const& rot); + GameObject* SpawnGameObject(uint32 entry, Position const& pos, QuaternionData const& rot); Creature* GetCreature(ObjectGuid guid); GameObject* GetGameObject(ObjectGuid guid); diff --git a/src/server/game/Battlefield/Zones/BattlefieldTB.cpp b/src/server/game/Battlefield/Zones/BattlefieldTB.cpp index b4f9ff8cfca..60948cec1ab 100644 --- a/src/server/game/Battlefield/Zones/BattlefieldTB.cpp +++ b/src/server/game/Battlefield/Zones/BattlefieldTB.cpp @@ -97,7 +97,7 @@ bool BattlefieldTB::SetupBattlefield() TolBaradCapturePoint* capturePoint = new TolBaradCapturePoint(this, GetDefenderTeam()); //Spawn flag pole - if (GameObject* go = SpawnGameObject(TBCapturePoints[i].entryFlagPole[GetDefenderTeam()], TBCapturePoints[i].pos, G3D::Quat())) + if (GameObject* go = SpawnGameObject(TBCapturePoints[i].entryFlagPole[GetDefenderTeam()], TBCapturePoints[i].pos, QuaternionData())) { go->SetGoArtKit(GetDefenderTeam() == TEAM_ALLIANCE ? TB_GO_ARTKIT_FLAG_ALLIANCE : TB_GO_ARTKIT_FLAG_HORDE); capturePoint->SetCapturePointData(go); @@ -107,7 +107,7 @@ bool BattlefieldTB::SetupBattlefield() // Spawn towers for (uint8 i = 0; i < TB_TOWERS_COUNT; i++) - if (GameObject* go = SpawnGameObject(TBTowers[i].entry, TBTowers[i].pos, G3D::Quat())) + if (GameObject* go = SpawnGameObject(TBTowers[i].entry, TBTowers[i].pos, QuaternionData())) Towers.insert(go->GetGUID()); // Init Graveyards @@ -511,7 +511,7 @@ void BattlefieldTB::UpdateNPCsAndGameObjects() TolBaradCapturePoint* capturePoint = new TolBaradCapturePoint(this, GetDefenderTeam()); //Spawn flag pole - if (GameObject* go = SpawnGameObject(TBCapturePoints[i].entryFlagPole[GetDefenderTeam()], TBCapturePoints[i].pos, G3D::Quat())) + if (GameObject* go = SpawnGameObject(TBCapturePoints[i].entryFlagPole[GetDefenderTeam()], TBCapturePoints[i].pos, QuaternionData())) { go->SetGoArtKit(GetDefenderTeam() == TEAM_ALLIANCE ? TB_GO_ARTKIT_FLAG_ALLIANCE : TB_GO_ARTKIT_FLAG_HORDE); capturePoint->SetCapturePointData(go); @@ -548,7 +548,7 @@ void BattlefieldTB::UpdateNPCsAndGameObjects() // Spawn portals for (uint8 i = 0; i < TB_PORTAL_MAX; i++) - if (GameObject* go = SpawnGameObject(TBPortalEntry[GetDefenderTeam()], TBPortals[i], G3D::Quat())) + if (GameObject* go = SpawnGameObject(TBPortalEntry[GetDefenderTeam()], TBPortals[i], QuaternionData())) TemporaryGOs.insert(go->GetGUID()); // Update towers @@ -574,7 +574,7 @@ void BattlefieldTB::UpdateNPCsAndGameObjects() // Spawn banners for (uint8 i = 0; i < TB_BANNER_MAX; i++) - if (GameObject* go = SpawnGameObject(TBBannerEntry[GetDefenderTeam()], TBBanners[i], G3D::Quat())) + if (GameObject* go = SpawnGameObject(TBBannerEntry[GetDefenderTeam()], TBBanners[i], QuaternionData())) TemporaryGOs.insert(go->GetGUID()); // Set graveyard controls diff --git a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp index 7e3cea34858..180cfe4c3f4 100644 --- a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp +++ b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp @@ -59,7 +59,7 @@ uint32 const WintergraspFaction[] = { 1732, 1735, 35 }; Position const WintergraspStalkerPos = { 4948.985f, 2937.789f, 550.5172f, 1.815142f }; Position const WintergraspRelicPos = { 5440.379f, 2840.493f, 430.2816f, -1.832595f }; -G3D::Quat const WintergraspRelicRot = { 0.f, 0.f, -0.7933531f, 0.6087617f }; +QuaternionData const WintergraspRelicRot = { 0.f, 0.f, -0.7933531f, 0.6087617f }; uint8 const WG_MAX_OBJ = 32; uint8 const WG_MAX_TURRET = 15; @@ -79,7 +79,7 @@ struct WintergraspBuildingSpawnData uint32 entry; uint32 WorldState; Position pos; - G3D::Quat rot; + QuaternionData rot; WintergraspGameObjectBuildingType type; }; @@ -252,7 +252,7 @@ WintergraspObjectPositionData const WGOutsideNPC[WG_MAX_OUTSIDE_NPC] = struct WintergraspGameObjectData { Position Pos; - G3D::Quat Rot; + QuaternionData Rot; uint32 HordeEntry; uint32 AllianceEntry; }; diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index 8aba555031b..533577e7c22 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -41,6 +41,7 @@ #include "Util.h" #include "WorldPacket.h" #include "WorldStatePackets.h" +#include <G3D/Quat.h> namespace Trinity { @@ -1464,14 +1465,18 @@ bool Battleground::AddObject(uint32 type, uint32 entry, float x, float y, float if (!map) return false; - G3D::Quat rot(rotation0, rotation1, rotation2, rotation3); + QuaternionData rot(rotation0, rotation1, rotation2, rotation3); // Temporally add safety check for bad spawns and send log (object rotations need to be rechecked in sniff) if (!rotation0 && !rotation1 && !rotation2 && !rotation3) { TC_LOG_DEBUG("bg.battleground", "Battleground::AddObject: gameoobject [entry: %u, object type: %u] for BG (map: %u) has zeroed rotation fields, " "orientation used temporally, but please fix the spawn", entry, type, m_MapId); - rot = G3D::Matrix3::fromEulerAnglesZYX(o, 0.f, 0.f); + G3D::Quat fallbackRot = G3D::Matrix3::fromEulerAnglesZYX(o, 0.f, 0.f); + rot.x = fallbackRot.x; + rot.y = fallbackRot.y; + rot.z = fallbackRot.z; + rot.w = fallbackRot.w; } // Must be created this way, adding to godatamap would add it to the base map of the instance diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp index 774fca9c7de..7c0f08378c0 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp @@ -154,8 +154,8 @@ bool BattlegroundSA::ResetObjs() } // MAD props for Kiper for discovering those values - 4 hours of his work. - GetBGObject(BG_SA_BOAT_ONE)->SetParentRotation(G3D::Quat(0.f, 0.f, 1.0f, 0.0002f)); - GetBGObject(BG_SA_BOAT_TWO)->SetParentRotation(G3D::Quat(0.f, 0.f, 1.0f, 0.00001f)); + GetBGObject(BG_SA_BOAT_ONE)->SetParentRotation(QuaternionData(0.f, 0.f, 1.0f, 0.0002f)); + GetBGObject(BG_SA_BOAT_TWO)->SetParentRotation(QuaternionData(0.f, 0.f, 1.0f, 0.00001f)); SpawnBGObject(BG_SA_BOAT_ONE, RESPAWN_IMMEDIATELY); SpawnBGObject(BG_SA_BOAT_TWO, RESPAWN_IMMEDIATELY); diff --git a/src/server/game/DungeonFinding/LFGMgr.h b/src/server/game/DungeonFinding/LFGMgr.h index e7b18c816cd..9c0d5c91960 100644 --- a/src/server/game/DungeonFinding/LFGMgr.h +++ b/src/server/game/DungeonFinding/LFGMgr.h @@ -19,7 +19,7 @@ #define _LFGMGR_H #include "Common.h" -#include "Field.h" +#include "DatabaseEnvFwd.h" #include "LFG.h" #include "LFGQueue.h" #include "LFGGroupData.h" diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index c1fb6620fa5..4bb4901823a 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -39,6 +39,7 @@ #include "Transport.h" #include "UpdateFieldFlags.h" #include "World.h" +#include <G3D/Quat.h> GameObject::GameObject() : WorldObject(false), MapObject(), m_model(nullptr), m_goValue(), m_AI(nullptr), _animKitId(0) @@ -183,7 +184,7 @@ void GameObject::RemoveFromWorld() } } -bool GameObject::Create(uint32 name_id, Map* map, uint32 /*phaseMask*/, Position const& pos, G3D::Quat const& rotation, uint32 animprogress, GOState go_state, uint32 artKit /*= 0*/) +bool GameObject::Create(uint32 name_id, Map* map, uint32 /*phaseMask*/, Position const& pos, QuaternionData const& rotation, uint32 animprogress, GOState go_state, uint32 artKit /*= 0*/) { ASSERT(map); SetMap(map); @@ -237,11 +238,11 @@ bool GameObject::Create(uint32 name_id, Map* map, uint32 /*phaseMask*/, Position return false; } - SetWorldRotation(rotation); + SetWorldRotation(rotation.x, rotation.y, rotation.z, rotation.w); GameObjectAddon const* gameObjectAddon = sObjectMgr->GetGameObjectAddon(GetSpawnId()); // For most of gameobjects is (0, 0, 0, 1) quaternion, there are only some transports with not standard rotation - G3D::Quat parentRotation; + QuaternionData parentRotation; if (gameObjectAddon) parentRotation = gameObjectAddon->ParentRotation; @@ -2027,13 +2028,18 @@ void GameObject::UpdatePackedRotation() m_packedRotation = z | (y << 21) | (x << 42); } -void GameObject::SetWorldRotation(G3D::Quat const& rot) +void GameObject::SetWorldRotation(float qx, float qy, float qz, float qw) { - m_worldRotation = rot.toUnit(); + G3D::Quat rotation(qx, qy, qz, qw); + rotation.unitize(); + m_worldRotation.x = rotation.x; + m_worldRotation.y = rotation.y; + m_worldRotation.z = rotation.z; + m_worldRotation.w = rotation.w; UpdatePackedRotation(); } -void GameObject::SetParentRotation(G3D::Quat const& rotation) +void GameObject::SetParentRotation(QuaternionData const& rotation) { SetFloatValue(GAMEOBJECT_PARENTROTATION + 0, rotation.x); SetFloatValue(GAMEOBJECT_PARENTROTATION + 1, rotation.y); @@ -2043,7 +2049,8 @@ void GameObject::SetParentRotation(G3D::Quat const& rotation) void GameObject::SetWorldRotationAngles(float z_rot, float y_rot, float x_rot) { - SetWorldRotation(G3D::Quat(G3D::Matrix3::fromEulerAnglesZYX(z_rot, y_rot, x_rot))); + G3D::Quat quat(G3D::Matrix3::fromEulerAnglesZYX(z_rot, y_rot, x_rot)); + SetWorldRotation(quat.x, quat.y, quat.z, quat.w); } void GameObject::ModifyHealth(int32 change, Unit* attackerOrHealer /*= nullptr*/, uint32 spellId /*= 0*/) diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index 64c0ed1711c..0e225bf5faa 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -25,7 +25,6 @@ #include "Loot.h" #include "DatabaseEnvFwd.h" #include "MapObject.h" -#include <G3D/Quat.h> class GameObjectAI; class Group; @@ -871,10 +870,20 @@ struct GameObjectLocale std::vector<std::string> Unk1; }; +struct QuaternionData +{ + float x, y, z, w; + + QuaternionData() : x(0.0f), y(0.0f), z(0.0f), w(1.0f) {} + QuaternionData(float X, float Y, float Z, float W) : x(X), y(Y), z(Z), w(W) {} + + bool isUnit() const { return fabs(x * x + y * y + z * z + w * w - 1.0f) < 1e-5; } +}; + // `gameobject_addon` table struct GameObjectAddon { - G3D::Quat ParentRotation; + QuaternionData ParentRotation; InvisibilityType invisibilityType; uint32 InvisibilityValue; }; @@ -893,7 +902,7 @@ struct GameObjectData float posY; float posZ; float orientation; - G3D::Quat rotation; + QuaternionData rotation; int32 spawntimesecs; uint32 animprogress; GOState go_state; @@ -938,7 +947,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject> void RemoveFromWorld() override; void CleanupsBeforeDelete(bool finalCleanup = true) override; - bool Create(uint32 name_id, Map* map, uint32 phaseMask, Position const& pos, G3D::Quat const& rotation, uint32 animprogress, GOState go_state, uint32 artKit = 0); + bool Create(uint32 name_id, Map* map, uint32 phaseMask, Position const& pos, QuaternionData const& rotation, uint32 animprogress, GOState go_state, uint32 artKit = 0); void Update(uint32 p_time) override; GameObjectTemplate const* GetGOInfo() const { return m_goInfo; } GameObjectTemplateAddon const* GetTemplateAddon() const { return m_goTemplateAddon; } @@ -953,9 +962,8 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject> // z_rot, y_rot, x_rot - rotation angles around z, y and x axes void SetWorldRotationAngles(float z_rot, float y_rot, float x_rot); - void SetWorldRotation(G3D::Quat const& rot); - G3D::Quat const& GetWorldRotation() const { return m_worldRotation; } - void SetParentRotation(G3D::Quat const& rotation); // transforms(rotates) transport's path + void SetWorldRotation(float qx, float qy, float qz, float qw); + void SetParentRotation(QuaternionData const& rotation); // transforms(rotates) transport's path int64 GetPackedWorldRotation() const { return m_packedRotation; } // overwrite WorldObject function for proper name localization @@ -1166,7 +1174,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject> GameObjectValue m_goValue; int64 m_packedRotation; - G3D::Quat m_worldRotation; + QuaternionData m_worldRotation; Position m_stationaryPosition; ObjectGuid m_lootRecipient; diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index a97451b1c05..61baafd3c97 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2494,7 +2494,7 @@ TempSummon* WorldObject::SummonCreature(uint32 id, float x, float y, float z, fl return SummonCreature(id, pos, spwtype, despwtime, 0); } -GameObject* WorldObject::SummonGameObject(uint32 entry, Position const& pos, G3D::Quat const& rot, uint32 respawnTime) +GameObject* WorldObject::SummonGameObject(uint32 entry, Position const& pos, QuaternionData const& rot, uint32 respawnTime) { if (!IsInWorld()) return nullptr; @@ -2526,7 +2526,7 @@ GameObject* WorldObject::SummonGameObject(uint32 entry, Position const& pos, G3D return go; } -GameObject* WorldObject::SummonGameObject(uint32 entry, float x, float y, float z, float ang, G3D::Quat const& rot, uint32 respawnTime) +GameObject* WorldObject::SummonGameObject(uint32 entry, float x, float y, float z, float ang, QuaternionData const& rot, uint32 respawnTime) { if (!x && !y && !z) { diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index c5a34ab4a55..d01c4f6cd9e 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -51,11 +51,7 @@ class UpdateData; class WorldObject; class WorldPacket; class ZoneScript; - -namespace G3D -{ - class Quat; -} +struct QuaternionData; typedef std::unordered_map<Player*, UpdateData> UpdateDataMapType; @@ -510,8 +506,8 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation TempSummon* SummonCreature(uint32 id, Position const& pos, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0, uint32 vehId = 0) const; TempSummon* SummonCreature(uint32 id, float x, float y, float z, float ang = 0, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0) const; - GameObject* SummonGameObject(uint32 entry, Position const& pos, G3D::Quat const& rot, uint32 respawnTime /* s */); - GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, G3D::Quat const& rot, uint32 respawnTime /* s */); + GameObject* SummonGameObject(uint32 entry, Position const& pos, QuaternionData const& rot, uint32 respawnTime /* s */); + GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, QuaternionData const& rot, uint32 respawnTime /* s */); Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL); void SummonCreatureGroup(uint8 group, std::list<TempSummon*>* list = NULL); diff --git a/src/server/game/Entities/Player/KillRewarder.cpp b/src/server/game/Entities/Player/KillRewarder.cpp index a45ed4e64bd..f7a62a2ae5d 100644 --- a/src/server/game/Entities/Player/KillRewarder.cpp +++ b/src/server/game/Entities/Player/KillRewarder.cpp @@ -276,7 +276,7 @@ void KillRewarder::Reward() { if (victim->IsDungeonBoss()) if (InstanceScript* instance = _victim->GetInstanceScript()) - instance->UpdateEncounterState(ENCOUNTER_CREDIT_KILL_CREATURE, _victim->GetEntry(), _victim); + instance->UpdateEncounterStateForKilledCreature(_victim->GetEntry(), _victim); if (ObjectGuid::LowType guildId = victim->GetMap()->GetOwnerGuildId()) if (Guild* guild = sGuildMgr->GetGuildById(guildId)) diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index 672903f8dea..7b9ab021d5b 100644 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -99,8 +99,8 @@ bool Transport::Create(ObjectGuid::LowType guidlow, uint32 entry, uint32 mapid, SetGoType(GAMEOBJECT_TYPE_MAP_OBJ_TRANSPORT); SetGoAnimProgress(animprogress); SetName(goinfo->name); - SetWorldRotation(G3D::Quat()); - SetParentRotation(G3D::Quat()); + SetWorldRotation(0.0f, 0.0f, 0.0f, 1.0f); + SetParentRotation(QuaternionData()); m_model = CreateModel(); return true; diff --git a/src/server/game/Garrison/Garrison.cpp b/src/server/game/Garrison/Garrison.cpp index b0fb39d3a94..15eb4880c1d 100644 --- a/src/server/game/Garrison/Garrison.cpp +++ b/src/server/game/Garrison/Garrison.cpp @@ -732,7 +732,7 @@ GameObject* Garrison::Plot::CreateGameObject(Map* map, GarrisonFactionIndex fact } GameObject* building = new GameObject(); - if (!building->Create(entry, map, 0, PacketInfo.PlotPos.Pos, G3D::Quat(), 255, GO_STATE_READY)) + if (!building->Create(entry, map, 0, PacketInfo.PlotPos.Pos, QuaternionData(), 255, GO_STATE_READY)) { delete building; return nullptr; @@ -744,7 +744,7 @@ GameObject* Garrison::Plot::CreateGameObject(Map* map, GarrisonFactionIndex fact { Position const& pos2 = finalizeInfo->FactionInfo[faction].Pos; GameObject* finalizer = new GameObject(); - if (finalizer->Create(finalizeInfo->FactionInfo[faction].GameObjectId, map, 0, pos2, G3D::Quat(), 255, GO_STATE_READY)) + if (finalizer->Create(finalizeInfo->FactionInfo[faction].GameObjectId, map, 0, pos2, QuaternionData(), 255, GO_STATE_READY)) { // set some spell id to make the object delete itself after use finalizer->SetSpellId(finalizer->GetGOInfo()->goober.spell); diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index dfa88d4faaa..e01f73abde6 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -1205,7 +1205,7 @@ void ObjectMgr::LoadGameObjectAddons() } GameObjectAddon& gameObjectAddon = _gameObjectAddonStore[guid]; - gameObjectAddon.ParentRotation = G3D::Quat(fields[1].GetFloat(), fields[2].GetFloat(), fields[3].GetFloat(), fields[4].GetFloat()); + gameObjectAddon.ParentRotation = QuaternionData(fields[1].GetFloat(), fields[2].GetFloat(), fields[3].GetFloat(), fields[4].GetFloat()); gameObjectAddon.invisibilityType = InvisibilityType(fields[5].GetUInt8()); gameObjectAddon.InvisibilityValue = fields[6].GetUInt32(); @@ -1225,7 +1225,7 @@ void ObjectMgr::LoadGameObjectAddons() if (!gameObjectAddon.ParentRotation.isUnit()) { TC_LOG_ERROR("sql.sql", "GameObject (GUID: " UI64FMTD ") has invalid parent rotation in `gameobject_addon`, set to default", guid); - gameObjectAddon.ParentRotation = G3D::Quat(); + gameObjectAddon.ParentRotation = QuaternionData(); } ++count; diff --git a/src/server/game/Instances/InstanceScript.cpp b/src/server/game/Instances/InstanceScript.cpp index 7b0cd9305da..2abee1258ab 100644 --- a/src/server/game/Instances/InstanceScript.cpp +++ b/src/server/game/Instances/InstanceScript.cpp @@ -17,8 +17,10 @@ */ #include "InstanceScript.h" +#include "AreaBoundary.h" #include "Creature.h" #include "CreatureAI.h" +#include "CreatureAIImpl.h" #include "DatabaseEnv.h" #include "GameObject.h" #include "Group.h" @@ -27,12 +29,14 @@ #include "LFGMgr.h" #include "Log.h" #include "Map.h" +#include "ObjectMgr.h" #include "Opcodes.h" #include "Pet.h" #include "Player.h" #include "RBAC.h" #include "ScriptMgr.h" #include "ScriptReloadMgr.h" +#include "World.h" #include "WorldSession.h" #include <sstream> @@ -118,6 +122,16 @@ ObjectGuid InstanceScript::GetGuidData(uint32 type) const return GetObjectGuid(type); } +Creature* InstanceScript::GetCreature(uint32 type) +{ + return instance->GetCreature(GetObjectGuid(type)); +} + +GameObject* InstanceScript::GetGameObject(uint32 type) +{ + return instance->GetGameObject(GetObjectGuid(type)); +} + void InstanceScript::SetHeaders(std::string const& dataHeaders) { for (char header : dataHeaders) @@ -606,6 +620,11 @@ void InstanceScript::DoCastSpellOnPlayers(uint32 spell) player->CastSpell(player, spell, true); } +bool InstanceScript::ServerAllowsTwoSideGroups() +{ + return sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP); +} + bool InstanceScript::CheckAchievementCriteriaMeet(uint32 criteria_id, Player const* /*source*/, Unit const* /*target*/ /*= NULL*/, uint32 /*miscvalue1*/ /*= 0*/) { TC_LOG_ERROR("misc", "Achievement system call InstanceScript::CheckAchievementCriteriaMeet but instance script for map %u not have implementation for achievement criteria %u", @@ -726,6 +745,16 @@ void InstanceScript::UpdateEncounterState(EncounterCreditType type, uint32 credi } } +void InstanceScript::UpdateEncounterStateForKilledCreature(uint32 creatureId, Unit* source) +{ + UpdateEncounterState(ENCOUNTER_CREDIT_KILL_CREATURE, creatureId, source); +} + +void InstanceScript::UpdateEncounterStateForSpellCast(uint32 spellId, Unit* source) +{ + UpdateEncounterState(ENCOUNTER_CREDIT_CAST_SPELL, spellId, source); +} + void InstanceScript::UpdatePhasing() { Map::PlayerList const& players = instance->GetPlayers(); @@ -813,3 +842,11 @@ uint32 InstanceScript::GetCombatResurrectionChargeInterval() const return interval; } + +bool InstanceHasScript(WorldObject const* obj, char const* scriptName) +{ + if (InstanceMap* instance = obj->GetMap()->ToInstanceMap()) + return instance->GetScriptName() == scriptName; + + return false; +} diff --git a/src/server/game/Instances/InstanceScript.h b/src/server/game/Instances/InstanceScript.h index d4ff288baa5..29db8d031ed 100644 --- a/src/server/game/Instances/InstanceScript.h +++ b/src/server/game/Instances/InstanceScript.h @@ -19,12 +19,11 @@ #ifndef TRINITY_INSTANCE_DATA_H #define TRINITY_INSTANCE_DATA_H -#include <set> #include "ZoneScript.h" -#include "World.h" -#include "ObjectMgr.h" -#include "CreatureAI.h" -#include "Packets/WorldStatePackets.h" +#include "Common.h" +#include <map> +#include <memory> +#include <set> #define OUT_SAVE_INST_DATA TC_LOG_DEBUG("scripts", "Saving Instance Data for Instance %s (Map %d, Instance Id %d)", instance->GetMapName(), instance->GetId(), instance->GetInstanceId()) #define OUT_SAVE_INST_DATA_COMPLETE TC_LOG_DEBUG("scripts", "Saving Instance Data for Instance %s (Map %d, Instance Id %d) completed.", instance->GetMapName(), instance->GetId(), instance->GetInstanceId()) @@ -32,12 +31,23 @@ #define OUT_LOAD_INST_DATA_COMPLETE TC_LOG_DEBUG("scripts", "Instance Data Load for Instance %s (Map %d, Instance Id: %d) is complete.", instance->GetMapName(), instance->GetId(), instance->GetInstanceId()) #define OUT_LOAD_INST_DATA_FAIL TC_LOG_ERROR("scripts", "Unable to load Instance Data for Instance %s (Map %d, Instance Id: %d).", instance->GetMapName(), instance->GetId(), instance->GetInstanceId()) -class Map; -class Unit; -class Player; -class GameObject; +class AreaBoundary; class Creature; +class GameObject; +class Map; class ModuleReference; +class Player; +class Unit; +enum CriteriaTypes : uint8; +enum CriteriaTimedTypes : uint8; +enum EncounterCreditType : uint8; +namespace WorldPackets +{ + namespace WorldState + { + class InitWorldStates; + } +} enum EncounterFrameType { @@ -109,6 +119,8 @@ struct ObjectData uint32 type; }; +typedef std::set<AreaBoundary const*> CreatureBoundary; + struct BossInfo { BossInfo() : state(TO_BE_DECIDED) { } @@ -179,14 +191,8 @@ class TC_GAME_API InstanceScript : public ZoneScript ObjectGuid GetObjectGuid(uint32 type) const; virtual ObjectGuid GetGuidData(uint32 type) const override; - inline Creature* GetCreature(uint32 type) - { - return instance->GetCreature(GetObjectGuid(type)); - } - inline GameObject* GetGameObject(uint32 type) - { - return instance->GetGameObject(GetObjectGuid(type)); - } + Creature* GetCreature(uint32 type); + GameObject* GetGameObject(uint32 type); // Called when a player successfully enters the instance. virtual void OnPlayerEnter(Player* /*player*/) { } @@ -223,7 +229,7 @@ class TC_GAME_API InstanceScript : public ZoneScript void DoCastSpellOnPlayers(uint32 spell); // Return wether server allow two side groups or not - bool ServerAllowsTwoSideGroups() { return sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP); } + bool ServerAllowsTwoSideGroups(); virtual bool SetBossState(uint32 id, EncounterState state); EncounterState GetBossState(uint32 id) const { return id < bosses.size() ? bosses[id].state : TO_BE_DECIDED; } @@ -238,7 +244,8 @@ class TC_GAME_API InstanceScript : public ZoneScript virtual bool CheckRequiredBosses(uint32 /*bossId*/, Player const* /*player*/ = nullptr) const { return true; } // Checks encounter state at kill/spellcast - void UpdateEncounterState(EncounterCreditType type, uint32 creditEntry, Unit* source); + void UpdateEncounterStateForKilledCreature(uint32 creatureId, Unit* source); + void UpdateEncounterStateForSpellCast(uint32 spellId, Unit* source); // Used only during loading void SetCompletedEncountersMask(uint32 newMask) { completedEncounters = newMask; } @@ -309,6 +316,7 @@ class TC_GAME_API InstanceScript : public ZoneScript private: static void LoadObjectData(ObjectData const* creatureData, ObjectInfoMap& objectInfo); + void UpdateEncounterState(EncounterCreditType type, uint32 creditEntry, Unit* source); std::vector<char> headers; std::vector<BossInfo> bosses; @@ -330,25 +338,4 @@ class TC_GAME_API InstanceScript : public ZoneScript #endif // #ifndef TRINITY_API_USE_DYNAMIC_LINKING }; -template<class AI, class T> -AI* GetInstanceAI(T* obj, char const* scriptName) -{ - if (InstanceMap* instance = obj->GetMap()->ToInstanceMap()) - if (instance->GetInstanceScript()) - if (instance->GetScriptId() == sObjectMgr->GetScriptId(scriptName)) - return new AI(obj); - - return NULL; -} - -template<class AI, class T> -AI* GetInstanceAI(T* obj) -{ - if (InstanceMap* instance = obj->GetMap()->ToInstanceMap()) - if (instance->GetInstanceScript()) - return new AI(obj); - - return NULL; -} - #endif // TRINITY_INSTANCE_DATA_H diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 7c29dd65373..5fe949dec57 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -3512,6 +3512,11 @@ bool InstanceMap::Reset(uint8 method) return m_mapRefManager.isEmpty(); } +std::string const& InstanceMap::GetScriptName() const +{ + return sObjectMgr->GetScriptName(i_script_id); +} + void InstanceMap::PermBindAllPlayers() { if (!IsDungeon()) diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 1c9ae67cbcb..f58859316ff 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -771,6 +771,7 @@ class TC_GAME_API InstanceMap : public Map void CreateInstanceData(bool load); bool Reset(uint8 method); uint32 GetScriptId() const { return i_script_id; } + std::string const& GetScriptName() const; InstanceScript* GetInstanceScript() { return i_data; } InstanceScript const* GetInstanceScript() const { return i_data; } InstanceScenario* GetInstanceScenario() { return i_scenario; } diff --git a/src/server/game/Server/Packets/CombatLogPackets.h b/src/server/game/Server/Packets/CombatLogPackets.h index 33ef377323c..5f30b5c65e1 100644 --- a/src/server/game/Server/Packets/CombatLogPackets.h +++ b/src/server/game/Server/Packets/CombatLogPackets.h @@ -190,7 +190,7 @@ namespace WorldPackets int32 OverEnergize = 0; }; - class SpellInstakillLog final : public ServerPacket + class TC_GAME_API SpellInstakillLog final : public ServerPacket { public: SpellInstakillLog() : ServerPacket(SMSG_SPELL_INSTAKILL_LOG, 16 + 16 + 4) { } diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index a5d97bc8843..25cf8d8d897 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -3159,7 +3159,7 @@ void Spell::EffectSummonObjectWild(SpellEffIndex effIndex) Map* map = target->GetMap(); G3D::Quat rot = G3D::Matrix3::fromEulerAnglesZYX(target->GetOrientation(), 0.f, 0.f); - if (!pGameObj->Create(gameobject_id, map, m_caster->GetPhaseMask(), Position(x, y, z, target->GetOrientation()), rot, 255, GO_STATE_READY)) + if (!pGameObj->Create(gameobject_id, map, m_caster->GetPhaseMask(), Position(x, y, z, target->GetOrientation()), QuaternionData(rot.x, rot.y, rot.z, rot.w), 255, GO_STATE_READY)) { delete pGameObj; return; @@ -3185,7 +3185,7 @@ void Spell::EffectSummonObjectWild(SpellEffIndex effIndex) if (uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry()) { GameObject* linkedGO = new GameObject(); - if (linkedGO->Create(linkedEntry, map, m_caster->GetPhaseMask(), Position(x, y, z, target->GetOrientation()), rot, 255, GO_STATE_READY)) + if (linkedGO->Create(linkedEntry, map, m_caster->GetPhaseMask(), Position(x, y, z, target->GetOrientation()), QuaternionData(rot.x, rot.y, rot.z, rot.w), 255, GO_STATE_READY)) { linkedGO->CopyPhaseFrom(m_caster); @@ -3735,7 +3735,7 @@ void Spell::EffectDuel(SpellEffIndex effIndex) Map* map = m_caster->GetMap(); G3D::Quat rot = G3D::Matrix3::fromEulerAnglesZYX(pos.GetOrientation(), 0.f, 0.f); - if (!pGameObj->Create(gameobject_id, map, m_caster->GetPhaseMask(), pos, rot, 0, GO_STATE_READY)) + if (!pGameObj->Create(gameobject_id, map, m_caster->GetPhaseMask(), pos, QuaternionData(rot.x, rot.y, rot.z, rot.w), 0, GO_STATE_READY)) { delete pGameObj; return; @@ -4071,7 +4071,7 @@ void Spell::EffectSummonObject(SpellEffIndex effIndex) Map* map = m_caster->GetMap(); G3D::Quat rot = G3D::Matrix3::fromEulerAnglesZYX(m_caster->GetOrientation(), 0.f, 0.f); - if (!go->Create(go_id, map, m_caster->GetPhaseMask(), Position(x, y, z, m_caster->GetOrientation()), rot, 255, GO_STATE_READY)) + if (!go->Create(go_id, map, m_caster->GetPhaseMask(), Position(x, y, z, m_caster->GetOrientation()), QuaternionData(rot.x, rot.y, rot.z, rot.w), 255, GO_STATE_READY)) { delete go; return; @@ -4755,7 +4755,7 @@ void Spell::EffectTransmitted(SpellEffIndex effIndex) Position pos = { fx, fy, fz, m_caster->GetOrientation() }; G3D::Quat rot = G3D::Matrix3::fromEulerAnglesZYX(m_caster->GetOrientation(), 0.f, 0.f); - if (!pGameObj->Create(name_id, cMap, m_caster->GetPhaseMask(), pos, rot, 255, GO_STATE_READY)) + if (!pGameObj->Create(name_id, cMap, m_caster->GetPhaseMask(), pos, QuaternionData(rot.x, rot.y, rot.z, rot.w), 255, GO_STATE_READY)) { delete pGameObj; return; @@ -4822,7 +4822,7 @@ void Spell::EffectTransmitted(SpellEffIndex effIndex) if (uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry()) { GameObject* linkedGO = new GameObject; - if (linkedGO->Create(linkedEntry, cMap, m_caster->GetPhaseMask(), pos, rot, 255, GO_STATE_READY)) + if (linkedGO->Create(linkedEntry, cMap, m_caster->GetPhaseMask(), pos, QuaternionData(rot.x, rot.y, rot.z, rot.w), 255, GO_STATE_READY)) { linkedGO->CopyPhaseFrom(m_caster); diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp index a450751df2d..c96086f89ce 100644 --- a/src/server/game/Spells/SpellScript.cpp +++ b/src/server/game/Spells/SpellScript.cpp @@ -34,15 +34,19 @@ bool _SpellScript::_Validate(SpellInfo const* entry) return true; } -bool _SpellScript::ValidateSpellInfo(std::vector<uint32> spellIds) +bool _SpellScript::_ValidateSpellInfo(uint32 const* begin, uint32 const* end) { - for (uint32 spellId : spellIds) - if (!sSpellMgr->GetSpellInfo(spellId)) + bool allValid = true; + while (begin != end) + { + if (!sSpellMgr->GetSpellInfo(*begin)) { - TC_LOG_ERROR("scripts.spells", "_SpellScript::ValidateSpellInfo: Spell %u does not exist.", spellId); - return false; + TC_LOG_ERROR("scripts.spells", "_SpellScript::ValidateSpellInfo: Spell %u does not exist.", *begin); + allValid = false; } - return true; + ++begin; + } + return allValid; } void _SpellScript::_Register() diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h index 17b512ed052..ee1a058f543 100644 --- a/src/server/game/Spells/SpellScript.h +++ b/src/server/game/Spells/SpellScript.h @@ -141,7 +141,19 @@ class TC_GAME_API _SpellScript // use for: deallocating memory allocated by script virtual void Unload() { } // Helpers - static bool ValidateSpellInfo(std::vector<uint32> spellIds); + static bool ValidateSpellInfo(std::initializer_list<uint32> spellIds) + { + return _ValidateSpellInfo(spellIds.begin(), spellIds.end()); + } + + template<class T> + static bool ValidateSpellInfo(T const& spellIds) + { + return _ValidateSpellInfo(std::begin(spellIds), std::end(spellIds)); + } + +private: + static bool _ValidateSpellInfo(uint32 const* begin, uint32 const* end); }; // SpellScript interface - enum used for runtime checks of script function calls |
