From b7287e85e4bc8acb2b95271ece9dd8a5b93873cd Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 1 Jan 2023 00:26:53 +0100 Subject: [PATCH 01/17] Core/Misc: Fixed deprecation warnings for c++20 (cherry picked from commit ba9bbbc9d0c3b80d8954ad6390d23ae3d0f804b2) --- dep/g3dlite/G3D-v9.0 hotfix10.diff | 20 ++ dep/g3dlite/G3D-v9.0 hotfix11.diff | 13 + dep/g3dlite/G3D-v9.0 hotfix12.diff | 192 ++++++++++++ dep/g3dlite/G3D-v9.0 hotfix15.diff | 288 ++++++++++++++++++ dep/g3dlite/G3D-v9.0 hotfix17.diff | 13 + dep/g3dlite/Readme.txt | 1 + dep/g3dlite/include/G3D/AABox.h | 10 +- dep/g3dlite/include/G3D/Array.h | 4 +- dep/g3dlite/include/G3D/AtomicInt32.h | 4 +- dep/g3dlite/include/G3D/HashTrait.h | 1 - dep/g3dlite/include/G3D/Random.h | 1 + dep/g3dlite/include/G3D/System.h | 4 + dep/g3dlite/include/G3D/Vector2.h | 7 +- dep/g3dlite/include/G3D/Vector3.h | 12 +- dep/g3dlite/include/G3D/Vector4.h | 1 - dep/g3dlite/include/G3D/debugAssert.h | 3 +- dep/g3dlite/include/G3D/platform.h | 3 + dep/g3dlite/source/FileSystem.cpp | 2 +- dep/g3dlite/source/Random.cpp | 5 + dep/g3dlite/source/Vector2.cpp | 1 + dep/g3dlite/source/Vector3.cpp | 1 + dep/g3dlite/source/debugAssert.cpp | 1 + src/common/Collision/Maps/TileAssembler.cpp | 10 +- src/common/Collision/Maps/TileAssembler.h | 1 - src/common/Cryptography/CryptoHash.h | 1 + .../game/AuctionHouse/AuctionHouseMgr.cpp | 6 +- .../AuctionHouseBot/AuctionHouseBotBuyer.cpp | 4 +- src/server/game/Battlefield/Battlefield.cpp | 2 +- .../Battlegrounds/Zones/BattlegroundAB.cpp | 8 +- .../Battlegrounds/Zones/BattlegroundAV.cpp | 22 +- .../Battlegrounds/Zones/BattlegroundIC.cpp | 10 +- .../Battlegrounds/Zones/BattlegroundSA.cpp | 8 +- src/server/game/DataStores/M2Stores.cpp | 10 +- src/server/game/Entities/Object/Position.cpp | 2 +- src/server/game/Entities/Object/Position.h | 4 +- src/server/game/Entities/Pet/Pet.cpp | 4 +- src/server/game/Entities/Player/Player.cpp | 16 +- .../game/Entities/Transport/Transport.cpp | 4 +- src/server/game/Entities/Unit/StatSystem.cpp | 18 +- src/server/game/Entities/Unit/Unit.cpp | 26 +- src/server/game/Entities/Unit/Unit.h | 18 +- src/server/game/Guilds/Guild.cpp | 2 +- src/server/game/Instances/InstanceSaveMgr.cpp | 4 +- src/server/game/Maps/TransportMgr.cpp | 8 +- src/server/game/Movement/MotionMaster.cpp | 6 +- .../game/Movement/Spline/MoveSpline.cpp | 7 +- src/server/game/Scripting/ScriptReloadMgr.cpp | 6 +- .../game/Server/Packets/MailPackets.cpp | 3 +- .../game/Spells/Auras/SpellAuraEffects.cpp | 5 +- src/server/game/Spells/SpellEffects.cpp | 2 +- src/server/game/Spells/SpellInfo.cpp | 4 +- src/server/game/Tickets/TicketMgr.cpp | 2 +- src/server/scripts/Commands/cs_rbac.cpp | 1 + .../ScarletEnclave/chapter1.cpp | 2 +- .../EasternKingdoms/ZulAman/boss_hexlord.cpp | 2 +- .../culling_of_stratholme.cpp | 28 +- .../TempleOfAhnQiraj/boss_twinemperors.cpp | 3 +- .../scripts/Kalimdor/zone_bloodmyst_isle.cpp | 14 +- src/server/scripts/Kalimdor/zone_silithus.cpp | 6 +- .../Northrend/Naxxramas/boss_maexxna.cpp | 2 +- .../Ulduar/HallsOfLightning/boss_ionar.cpp | 3 +- src/server/scripts/Spells/spell_pet.cpp | 8 +- src/server/scripts/Spells/spell_warlock.cpp | 2 +- src/server/scripts/World/npcs_special.cpp | 2 +- .../shared/DataStores/DBCStorageIterator.h | 72 +++-- 65 files changed, 753 insertions(+), 202 deletions(-) create mode 100644 dep/g3dlite/G3D-v9.0 hotfix10.diff create mode 100644 dep/g3dlite/G3D-v9.0 hotfix11.diff create mode 100644 dep/g3dlite/G3D-v9.0 hotfix12.diff create mode 100644 dep/g3dlite/G3D-v9.0 hotfix15.diff create mode 100644 dep/g3dlite/G3D-v9.0 hotfix17.diff diff --git a/dep/g3dlite/G3D-v9.0 hotfix10.diff b/dep/g3dlite/G3D-v9.0 hotfix10.diff new file mode 100644 index 00000000000..343ac7090fa --- /dev/null +++ b/dep/g3dlite/G3D-v9.0 hotfix10.diff @@ -0,0 +1,20 @@ +diff --git a/dep/g3dlite/include/G3D/Array.h b/dep/g3dlite/include/G3D/Array.h +index c562f5c920f7..c86b20fd7e97 100644 +--- a/dep/g3dlite/include/G3D/Array.h ++++ b/dep/g3dlite/include/G3D/Array.h +@@ -346,6 +346,7 @@ class Array { + + /** Resizes this to match the size of \a other and then copies the data from other using memcpy. This is only safe for POD types */ + void copyPOD(const Array& other) { ++ static_assert(std::is_standard_layout_v && std::is_trivial_v, "copyPOD called on non-POD type"); + if (numAllocated < other.num) { + m_memoryManager->free(data); + data = NULL; +@@ -364,6 +365,7 @@ class Array { + /** Resizes this to just barely match the size of \a other + itself and then copies the data to the end of the array from other using memcpy. + This is only safe for POD types */ + void appendPOD(const Array& other) { ++ static_assert(std::is_standard_layout_v && std::is_trivial_v, "appendPOD called on non-POD type"); + const size_t oldSize = num; + num += other.num; + if (numAllocated < num) { diff --git a/dep/g3dlite/G3D-v9.0 hotfix11.diff b/dep/g3dlite/G3D-v9.0 hotfix11.diff new file mode 100644 index 00000000000..5c94416d649 --- /dev/null +++ b/dep/g3dlite/G3D-v9.0 hotfix11.diff @@ -0,0 +1,13 @@ +diff --git a/dep/g3dlite/source/fileutils.cpp b/dep/g3dlite/source/fileutils.cpp +index 2788adad3bcd..f5310084cec7 100644 +--- a/dep/g3dlite/source/fileutils.cpp ++++ b/dep/g3dlite/source/fileutils.cpp +@@ -490,7 +490,7 @@ void parseFilename( + + } + +- } else if ((f.size() >= 2) & isSlash(f[0]) && isSlash(f[1])) { ++ } else if ((f.size() >= 2) && isSlash(f[0]) && isSlash(f[1])) { + + // e.g. //foo + root = f.substr(0, 2); diff --git a/dep/g3dlite/G3D-v9.0 hotfix12.diff b/dep/g3dlite/G3D-v9.0 hotfix12.diff new file mode 100644 index 00000000000..6594539f245 --- /dev/null +++ b/dep/g3dlite/G3D-v9.0 hotfix12.diff @@ -0,0 +1,192 @@ +diff --git a/dep/g3dlite/include/G3D/AtomicInt32.h b/dep/g3dlite/include/G3D/AtomicInt32.h +index 7b56e001ae29..9824d426d741 100644 +--- a/dep/g3dlite/include/G3D/AtomicInt32.h ++++ b/dep/g3dlite/include/G3D/AtomicInt32.h +@@ -76,12 +76,16 @@ class AtomicInt32 { + + # elif defined(G3D_LINUX) || defined(G3D_FREEBSD) + +- int32 old; +- asm volatile ("lock; xaddl %0,%1" +- : "=r"(old), "=m"(m_value) /* outputs */ +- : "0"(x), "m"(m_value) /* inputs */ +- : "memory", "cc"); +- return old; ++# if defined(__aarch64__) ++ return __sync_fetch_and_add(&m_value, x); ++# else ++ int32 old; ++ asm volatile ("lock; xaddl %0,%1" ++ : "=r"(old), "=m"(m_value) /* outputs */ ++ : "0"(x), "m"(m_value) /* inputs */ ++ : "memory", "cc"); ++ return old; ++# endif + + # elif defined(G3D_OSX) + +@@ -115,14 +119,18 @@ class AtomicInt32 { + // Note: returns the newly decremented value + return InterlockedDecrement(&m_value); + # elif defined(G3D_LINUX) || defined(G3D_FREEBSD) +- unsigned char nz; +- +- asm volatile ("lock; decl %1;\n\t" +- "setnz %%al" +- : "=a" (nz) +- : "m" (m_value) +- : "memory", "cc"); +- return nz; ++# if defined(__aarch64__) ++ return __sync_sub_and_fetch(&m_value, 1); ++# else ++ unsigned char nz; ++ ++ asm volatile ("lock; decl %1;\n\t" ++ "setnz %%al" ++ : "=a" (nz) ++ : "m" (m_value) ++ : "memory", "cc"); ++ return nz; ++# endif + # elif defined(G3D_OSX) + // Note: returns the newly decremented value + return OSAtomicDecrement32(&m_value); +@@ -143,17 +151,21 @@ class AtomicInt32 { + # if defined(G3D_WINDOWS) + return InterlockedCompareExchange(&m_value, exchange, comperand); + # elif defined(G3D_LINUX) || defined(G3D_FREEBSD) || defined(G3D_OSX) +- // Based on Apache Portable Runtime +- // http://koders.com/c/fid3B6631EE94542CDBAA03E822CA780CBA1B024822.aspx +- int32 ret; +- asm volatile ("lock; cmpxchgl %1, %2" +- : "=a" (ret) +- : "r" (exchange), "m" (m_value), "0"(comperand) +- : "memory", "cc"); +- return ret; +- +- // Note that OSAtomicCompareAndSwap32 does not return a useful value for us +- // so it can't satisfy the cmpxchgl contract. ++# if defined(__aarch64__) ++ return __sync_val_compare_and_swap(&m_value, comperand, exchange); ++# else ++ // Based on Apache Portable Runtime ++ // http://koders.com/c/fid3B6631EE94542CDBAA03E822CA780CBA1B024822.aspx ++ int32 ret; ++ asm volatile ("lock; cmpxchgl %1, %2" ++ : "=a" (ret) ++ : "r" (exchange), "m" (m_value), "0"(comperand) ++ : "memory", "cc"); ++ return ret; ++ ++ // Note that OSAtomicCompareAndSwap32 does not return a useful value for us ++ // so it can't satisfy the cmpxchgl contract. ++# endif + # endif + } + +diff --git a/dep/g3dlite/include/G3D/System.h b/dep/g3dlite/include/G3D/System.h +index 4624dd916474..9ed88957d755 100644 +--- a/dep/g3dlite/include/G3D/System.h ++++ b/dep/g3dlite/include/G3D/System.h +@@ -21,6 +21,10 @@ + #include "G3D/FileNotFound.h" + #include + ++#if defined(__aarch64__) ++#include ++#endif ++ + #ifdef G3D_OSX + #define Zone OSX_Zone + # include +@@ -497,15 +501,37 @@ class System { + #elif defined(G3D_LINUX) + + inline uint64 System::getCycleCount() { +- uint32 timehi, timelo; ++# if defined(__aarch64__) ++# if (__ARM_ARCH >= 6) // V6 is the earliest arch that has a standard cyclecount ++ uint32_t pmccntr; ++ uint32_t pmuseren; ++ uint32_t pmcntenset; ++ // Read the user mode perf monitor counter access permissions. ++ __asm__ __volatile__("mrc p15, 0, %w0, c9, c14, 0" : "=r"(pmuseren)); ++ if (pmuseren & 1) { // Allows reading perfmon counters for user mode code. ++ __asm__ __volatile__("mrc p15, 0, %w0, c9, c12, 1" : "=r"(pmcntenset)); ++ if (pmcntenset & 0x80000000ul) { // Is it counting? ++ __asm__ __volatile__("mrc p15, 0, %w0, c9, c13, 0" : "=r"(pmccntr)); ++ // The counter is set up to count every 64th cycle ++ return static_cast(pmccntr) * 64; // Should optimize to << 6 ++ } ++ } ++# endif + +- __asm__ __volatile__ ( +- "rdtsc " +- : "=a" (timelo), +- "=d" (timehi) +- : ); ++ struct timeval tv; ++ gettimeofday(&tv, nullptr); ++ return static_cast(tv.tv_sec) * 1000000 + tv.tv_usec; ++# else ++ uint32 timehi, timelo; ++ ++ __asm__ __volatile__ ( ++ "rdtsc " ++ : "=a" (timelo), ++ "=d" (timehi) ++ : ); + +- return ((uint64)timehi << 32) + (uint64)timelo; ++ return ((uint64)timehi << 32) + (uint64)timelo; ++# endif + } + + #elif defined(G3D_OSX) +diff --git a/dep/g3dlite/include/G3D/platform.h b/dep/g3dlite/include/G3D/platform.h +index 439495ab1315..d043f21491ad 100644 +--- a/dep/g3dlite/include/G3D/platform.h ++++ b/dep/g3dlite/include/G3D/platform.h +@@ -273,7 +273,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {\ + # define __stdcall __attribute__((stdcall)) + # endif + +-# elif defined(__x86_64__) ++# elif defined(__x86_64__) || defined(__arm) || defined(__aarch64__) + + # ifndef __cdecl + # define __cdecl +diff --git a/dep/g3dlite/source/System.cpp b/dep/g3dlite/source/System.cpp +index b841e23c497e..4a75d320b8d3 100644 +--- a/dep/g3dlite/source/System.cpp ++++ b/dep/g3dlite/source/System.cpp +@@ -79,8 +79,9 @@ + #endif + + // SIMM include ++#if !defined(__aarch64__) + #include +- ++#endif + + namespace G3D { + +@@ -1697,6 +1698,16 @@ void System::cpuid(CPUIDFunction func, uint32& eax, uint32& ebx, uint32& ecx, ui + edx = regs[3]; + } + ++#elif defined(__aarch64__) || defined(G3D_OSX) && ! defined(G3D_OSX_INTEL) ++ ++// non-x86 CPU; no CPUID ++void System::cpuid(CPUIDFunction func, uint32& eax, uint32& ebx, uint32& ecx, uint32& edx) { ++ eax = 0; ++ ebx = 0; ++ ecx = 0; ++ edx = 0; ++} ++ + #else + + // See http://sam.zoy.org/blog/2007-04-13-shlib-with-non-pic-code-have-inline-assembly-and-pic-mix-well diff --git a/dep/g3dlite/G3D-v9.0 hotfix15.diff b/dep/g3dlite/G3D-v9.0 hotfix15.diff new file mode 100644 index 00000000000..d385def554a --- /dev/null +++ b/dep/g3dlite/G3D-v9.0 hotfix15.diff @@ -0,0 +1,288 @@ +diff --git a/dep/g3dlite/include/G3D/AABox.h b/dep/g3dlite/include/G3D/AABox.h +index 7a47ea63aa..97a47cf986 100644 +--- a/dep/g3dlite/include/G3D/AABox.h ++++ b/dep/g3dlite/include/G3D/AABox.h +@@ -17,14 +17,14 @@ + + #include "G3D/platform.h" + #include "G3D/debug.h" +-#include "G3D/Array.h" +-#include "G3D/Plane.h" +-#include "G3D/Sphere.h" + #include "G3D/Vector3.h" + + namespace G3D { + + class Any; ++template class Array; ++class Plane; ++class Sphere; + + /** + An axis-aligned box. +@@ -221,7 +221,7 @@ public: + + */ + bool culledBy +- (const Array& plane, ++ (const Array& plane, + int32& cullingPlaneIndex, + const uint32 testMask, + uint32& childMask) const; +@@ -230,7 +230,7 @@ public: + Conservative culling test that does not produce a mask for children. + */ + bool culledBy +- (const Array& plane, ++ (const Array& plane, + int32& cullingPlaneIndex = dummy, + const uint32 testMask = 0xFFFFFFFF) const; + +diff --git a/dep/g3dlite/include/G3D/AtomicInt32.h b/dep/g3dlite/include/G3D/AtomicInt32.h +index 9824d426d7..51561e3dcc 100644 +--- a/dep/g3dlite/include/G3D/AtomicInt32.h ++++ b/dep/g3dlite/include/G3D/AtomicInt32.h +@@ -12,7 +12,9 @@ + #include "G3D/platform.h" + #include "G3D/g3dmath.h" + +-#if defined(G3D_OSX) ++#if defined(G3D_WINDOWS) ++# include ++#elif defined(G3D_OSX) + # include + #endif + +diff --git a/dep/g3dlite/include/G3D/HashTrait.h b/dep/g3dlite/include/G3D/HashTrait.h +index 1de3777bae..6199f4504e 100644 +--- a/dep/g3dlite/include/G3D/HashTrait.h ++++ b/dep/g3dlite/include/G3D/HashTrait.h +@@ -13,7 +13,6 @@ + #define G3D_HashTrait_h + + #include "G3D/platform.h" +-#include "G3D/Crypto.h" + #include "G3D/g3dmath.h" + #include "G3D/uint128.h" + #include +diff --git a/dep/g3dlite/include/G3D/Random.h b/dep/g3dlite/include/G3D/Random.h +index 9d911806a9..359755044a 100644 +--- a/dep/g3dlite/include/G3D/Random.h ++++ b/dep/g3dlite/include/G3D/Random.h +@@ -159,6 +159,7 @@ public: + static Random& common(); + }; + ++Random& commonRandom(); + } + + #endif +diff --git a/dep/g3dlite/include/G3D/System.h b/dep/g3dlite/include/G3D/System.h +index 9ed88957d7..81c83527c9 100644 +--- a/dep/g3dlite/include/G3D/System.h ++++ b/dep/g3dlite/include/G3D/System.h +@@ -21,6 +21,10 @@ + #include "G3D/FileNotFound.h" + #include + ++#ifdef G3D_WINDOWS ++#include ++#endif ++ + #if defined(__aarch64__) + #include + #endif +diff --git a/dep/g3dlite/include/G3D/Vector2.h b/dep/g3dlite/include/G3D/Vector2.h +index 65cf7fa8f2..696889d630 100644 +--- a/dep/g3dlite/include/G3D/Vector2.h ++++ b/dep/g3dlite/include/G3D/Vector2.h +@@ -19,20 +19,21 @@ + + #include "G3D/platform.h" + #include "G3D/g3dmath.h" +-#include "G3D/Table.h" + #include "G3D/HashTrait.h" + #include "G3D/Vector2int16.h" + #include "G3D/Vector2unorm16.h" +-#include "G3D/Random.h" + + namespace G3D { + ++class Random; + class Vector2; + class Vector3; + class Vector4; + class Vector2int32; + class Any; + ++Random& commonRandom(); ++ + /** + Do not subclass-- this implementation makes assumptions about the + memory layout. +@@ -210,7 +211,7 @@ public: + } + + /** Uniformly distributed random vector on the unit sphere */ +- static Vector2 random(Random& r = Random::common()); ++ static Vector2 random(Random& r = commonRandom()); + + // Special values. + // Intentionally not inlined: see Matrix3::identity() for details. +diff --git a/dep/g3dlite/include/G3D/Vector3.h b/dep/g3dlite/include/G3D/Vector3.h +index 05d9b11ed5..c79f70b916 100644 +--- a/dep/g3dlite/include/G3D/Vector3.h ++++ b/dep/g3dlite/include/G3D/Vector3.h +@@ -17,9 +17,7 @@ + + #include "G3D/platform.h" + #include "G3D/g3dmath.h" +-#include "G3D/Random.h" + #include "G3D/Vector2.h" +-#include "G3D/Table.h" + #include "G3D/HashTrait.h" + #include "G3D/PositionTrait.h" + #include "G3D/Vector2.h" +@@ -365,7 +363,7 @@ public: + Distribution rendered by G3D::DirectionHistogram: + \image html vector3-random.png + */ +- static Vector3 random(Random& r = Random::common()); ++ static Vector3 random(Random& r = commonRandom()); + + /** \brief Random unit vector, distributed according to \f$\max(\cos \theta,0)\f$. + +@@ -380,9 +378,9 @@ public: + + @cite Henrik Wann Jensen, Realistic Image Synthesis using Photon Mapping eqn 2.24 + */ +- static Vector3 cosHemiRandom(const Vector3& n, Random& r = Random::common()); ++ static Vector3 cosHemiRandom(const Vector3& n, Random& r = commonRandom()); + +- static Vector3 cosSphereRandom(const Vector3& n, Random& r = Random::common()); ++ static Vector3 cosSphereRandom(const Vector3& n, Random& r = commonRandom()); + + /** \brief Random unit vector, distributed according to \f$\max(\cos^k \theta,0)\f$. + +@@ -397,7 +395,7 @@ public: + + @cite Ashikhmin and Shirley, An anisotropic Phong BRDF model, Journal of Graphics Tools, 2002 + */ +- static Vector3 cosPowHemiRandom(const Vector3& n, const float k, Random& r = Random::common()); ++ static Vector3 cosPowHemiRandom(const Vector3& n, const float k, Random& r = commonRandom()); + + /** + \brief Random vector distributed over the hemisphere about normal. +@@ -405,7 +403,7 @@ public: + Distribution rendered by G3D::DirectionHistogram: + \image html vector3-hemirandom.png + */ +- static Vector3 hemiRandom(const Vector3& normal, Random& r = Random::common()); ++ static Vector3 hemiRandom(const Vector3& normal, Random& r = commonRandom()); + + inline float sum() const { + return x + y + z; +diff --git a/dep/g3dlite/include/G3D/Vector4.h b/dep/g3dlite/include/G3D/Vector4.h +index 24521efc93..0f0ea459df 100644 +--- a/dep/g3dlite/include/G3D/Vector4.h ++++ b/dep/g3dlite/include/G3D/Vector4.h +@@ -19,7 +19,6 @@ + #include "G3D/g3dmath.h" + #include "G3D/Vector3.h" + #include "G3D/Vector2.h" +-#include "G3D/Table.h" + #include "G3D/HashTrait.h" + #include "G3D/PositionTrait.h" + #include +diff --git a/dep/g3dlite/include/G3D/debugAssert.h b/dep/g3dlite/include/G3D/debugAssert.h +index edff671061..197312bd12 100644 +--- a/dep/g3dlite/include/G3D/debugAssert.h ++++ b/dep/g3dlite/include/G3D/debugAssert.h +@@ -32,6 +32,7 @@ + #include + + #ifdef _MSC_VER ++#include + // conditional expression is constant + # pragma warning (disable : 4127) + #endif +@@ -116,7 +117,7 @@ namespace _internal { + #ifdef G3D_DEBUG + + # if defined(_MSC_VER) +-# define rawBreak() ::DebugBreak(); ++# define rawBreak() ::__debugbreak(); + # elif defined(__i386__) + // gcc on intel + # define rawBreak() __asm__ __volatile__ ( "int $3" ); +diff --git a/dep/g3dlite/include/G3D/platform.h b/dep/g3dlite/include/G3D/platform.h +index d043f21491..9202fe41d0 100644 +--- a/dep/g3dlite/include/G3D/platform.h ++++ b/dep/g3dlite/include/G3D/platform.h +@@ -190,6 +190,7 @@ These control the version of Winsock used by G3D. + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_Compiler_Reference.asp + // + ++#if 0 + // DLL runtime + #ifndef _DLL + #define _DLL +@@ -227,6 +228,8 @@ These control the version of Winsock used by G3D. + # undef WIN32_LEAN_AND_MEAN + # undef NOMINMAX + ++#endif // 0 ++ + # ifdef _G3D_INTERNAL_HIDE_WINSOCK_ + # undef _G3D_INTERNAL_HIDE_WINSOCK_ + # undef _WINSOCKAPI_ +diff --git a/dep/g3dlite/source/Random.cpp b/dep/g3dlite/source/Random.cpp +index cbfa07dec0..a31d52a557 100644 +--- a/dep/g3dlite/source/Random.cpp ++++ b/dep/g3dlite/source/Random.cpp +@@ -227,4 +227,9 @@ void Random::sphere(float& x, float& y, float& z) { + z *= s; + } + ++Random& commonRandom() ++{ ++ return Random::common(); ++} ++ + } // G3D +diff --git a/dep/g3dlite/source/Vector2.cpp b/dep/g3dlite/source/Vector2.cpp +index a6edea9a83..194cd3090d 100644 +--- a/dep/g3dlite/source/Vector2.cpp ++++ b/dep/g3dlite/source/Vector2.cpp +@@ -23,6 +23,7 @@ + #include "G3D/TextInput.h" + #include "G3D/TextOutput.h" + #include "G3D/Any.h" ++#include "G3D/Random.h" + + namespace G3D { + +diff --git a/dep/g3dlite/source/Vector3.cpp b/dep/g3dlite/source/Vector3.cpp +index e2d9643e5c..ccbf7d6a0b 100644 +--- a/dep/g3dlite/source/Vector3.cpp ++++ b/dep/g3dlite/source/Vector3.cpp +@@ -28,6 +28,7 @@ + #include "G3D/Vector4.h" + #include "G3D/Vector3int32.h" + #include "G3D/Any.h" ++#include "G3D/Random.h" + + namespace G3D { + +diff --git a/dep/g3dlite/source/debugAssert.cpp b/dep/g3dlite/source/debugAssert.cpp +index 3c3e43a0af..ff843fb7ee 100644 +--- a/dep/g3dlite/source/debugAssert.cpp ++++ b/dep/g3dlite/source/debugAssert.cpp +@@ -23,6 +23,7 @@ + #include + + #ifdef _MSC_VER ++#include + // disable: "C++ exception handler used" + # pragma warning (push) + # pragma warning (disable : 4530) diff --git a/dep/g3dlite/G3D-v9.0 hotfix17.diff b/dep/g3dlite/G3D-v9.0 hotfix17.diff new file mode 100644 index 00000000000..cb5367c65f4 --- /dev/null +++ b/dep/g3dlite/G3D-v9.0 hotfix17.diff @@ -0,0 +1,13 @@ +diff --git a/dep/g3dlite/source/FileSystem.cpp b/dep/g3dlite/source/FileSystem.cpp +index 0898af7953..ff5da02344 100644 +--- a/dep/g3dlite/source/FileSystem.cpp ++++ b/dep/g3dlite/source/FileSystem.cpp +@@ -35,7 +35,7 @@ + # include + # include + # define _getcwd getcwd +-# if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ++# if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) + # define stat64 stat + # endif + # define _stat stat diff --git a/dep/g3dlite/Readme.txt b/dep/g3dlite/Readme.txt index 5477030e5cb..3318bcbb3ed 100644 --- a/dep/g3dlite/Readme.txt +++ b/dep/g3dlite/Readme.txt @@ -24,4 +24,5 @@ G3D-v9.0 hotfix11.diff - 2017-11-11 - static analysis issue fix G3D-v9.0 hotfix12.diff - 2020-02-23 - ARM64 build fix G3D-v9.0 hotfix13.diff - 2020-08-04 - MSVC build fix with /permissive- G3D-v9.0 hotfix14.diff - 2022-01-16 - warning fixes +G3D-v9.0 hotfix15.diff - 2022-02-11 - purge Windows.h includes from public headers G3D-v9.0 hotfix16.diff - 2022-02-11 - Fix *BSD compile errors diff --git a/dep/g3dlite/include/G3D/AABox.h b/dep/g3dlite/include/G3D/AABox.h index 7a47ea63aa2..97a47cf9865 100644 --- a/dep/g3dlite/include/G3D/AABox.h +++ b/dep/g3dlite/include/G3D/AABox.h @@ -17,14 +17,14 @@ #include "G3D/platform.h" #include "G3D/debug.h" -#include "G3D/Array.h" -#include "G3D/Plane.h" -#include "G3D/Sphere.h" #include "G3D/Vector3.h" namespace G3D { class Any; +template class Array; +class Plane; +class Sphere; /** An axis-aligned box. @@ -221,7 +221,7 @@ class AABox { */ bool culledBy - (const Array& plane, + (const Array& plane, int32& cullingPlaneIndex, const uint32 testMask, uint32& childMask) const; @@ -230,7 +230,7 @@ class AABox { Conservative culling test that does not produce a mask for children. */ bool culledBy - (const Array& plane, + (const Array& plane, int32& cullingPlaneIndex = dummy, const uint32 testMask = 0xFFFFFFFF) const; diff --git a/dep/g3dlite/include/G3D/Array.h b/dep/g3dlite/include/G3D/Array.h index c86b20fd7e9..788237dce54 100644 --- a/dep/g3dlite/include/G3D/Array.h +++ b/dep/g3dlite/include/G3D/Array.h @@ -346,7 +346,7 @@ class Array { /** Resizes this to match the size of \a other and then copies the data from other using memcpy. This is only safe for POD types */ void copyPOD(const Array& other) { - static_assert(std::is_pod::value, "copyPOD called on non-POD type"); + static_assert(std::is_standard_layout_v && std::is_trivial_v, "copyPOD called on non-POD type"); if (numAllocated < other.num) { m_memoryManager->free(data); data = NULL; @@ -365,7 +365,7 @@ class Array { /** Resizes this to just barely match the size of \a other + itself and then copies the data to the end of the array from other using memcpy. This is only safe for POD types */ void appendPOD(const Array& other) { - static_assert(std::is_pod::value, "appendPOD called on non-POD type"); + static_assert(std::is_standard_layout_v && std::is_trivial_v, "appendPOD called on non-POD type"); const size_t oldSize = num; num += other.num; if (numAllocated < num) { diff --git a/dep/g3dlite/include/G3D/AtomicInt32.h b/dep/g3dlite/include/G3D/AtomicInt32.h index 9824d426d74..51561e3dcc4 100644 --- a/dep/g3dlite/include/G3D/AtomicInt32.h +++ b/dep/g3dlite/include/G3D/AtomicInt32.h @@ -12,7 +12,9 @@ #include "G3D/platform.h" #include "G3D/g3dmath.h" -#if defined(G3D_OSX) +#if defined(G3D_WINDOWS) +# include +#elif defined(G3D_OSX) # include #endif diff --git a/dep/g3dlite/include/G3D/HashTrait.h b/dep/g3dlite/include/G3D/HashTrait.h index 1de3777baec..6199f4504ed 100644 --- a/dep/g3dlite/include/G3D/HashTrait.h +++ b/dep/g3dlite/include/G3D/HashTrait.h @@ -13,7 +13,6 @@ #define G3D_HashTrait_h #include "G3D/platform.h" -#include "G3D/Crypto.h" #include "G3D/g3dmath.h" #include "G3D/uint128.h" #include diff --git a/dep/g3dlite/include/G3D/Random.h b/dep/g3dlite/include/G3D/Random.h index 9d911806a97..359755044a8 100644 --- a/dep/g3dlite/include/G3D/Random.h +++ b/dep/g3dlite/include/G3D/Random.h @@ -159,6 +159,7 @@ class Random { static Random& common(); }; +Random& commonRandom(); } #endif diff --git a/dep/g3dlite/include/G3D/System.h b/dep/g3dlite/include/G3D/System.h index 9ed88957d75..81c83527c9c 100644 --- a/dep/g3dlite/include/G3D/System.h +++ b/dep/g3dlite/include/G3D/System.h @@ -21,6 +21,10 @@ #include "G3D/FileNotFound.h" #include +#ifdef G3D_WINDOWS +#include +#endif + #if defined(__aarch64__) #include #endif diff --git a/dep/g3dlite/include/G3D/Vector2.h b/dep/g3dlite/include/G3D/Vector2.h index 65cf7fa8f2f..696889d6302 100644 --- a/dep/g3dlite/include/G3D/Vector2.h +++ b/dep/g3dlite/include/G3D/Vector2.h @@ -19,20 +19,21 @@ #include "G3D/platform.h" #include "G3D/g3dmath.h" -#include "G3D/Table.h" #include "G3D/HashTrait.h" #include "G3D/Vector2int16.h" #include "G3D/Vector2unorm16.h" -#include "G3D/Random.h" namespace G3D { +class Random; class Vector2; class Vector3; class Vector4; class Vector2int32; class Any; +Random& commonRandom(); + /** Do not subclass-- this implementation makes assumptions about the memory layout. @@ -210,7 +211,7 @@ class Vector2 { } /** Uniformly distributed random vector on the unit sphere */ - static Vector2 random(Random& r = Random::common()); + static Vector2 random(Random& r = commonRandom()); // Special values. // Intentionally not inlined: see Matrix3::identity() for details. diff --git a/dep/g3dlite/include/G3D/Vector3.h b/dep/g3dlite/include/G3D/Vector3.h index 05d9b11ed57..c79f70b916b 100644 --- a/dep/g3dlite/include/G3D/Vector3.h +++ b/dep/g3dlite/include/G3D/Vector3.h @@ -17,9 +17,7 @@ #include "G3D/platform.h" #include "G3D/g3dmath.h" -#include "G3D/Random.h" #include "G3D/Vector2.h" -#include "G3D/Table.h" #include "G3D/HashTrait.h" #include "G3D/PositionTrait.h" #include "G3D/Vector2.h" @@ -365,7 +363,7 @@ class Vector3 { Distribution rendered by G3D::DirectionHistogram: \image html vector3-random.png */ - static Vector3 random(Random& r = Random::common()); + static Vector3 random(Random& r = commonRandom()); /** \brief Random unit vector, distributed according to \f$\max(\cos \theta,0)\f$. @@ -380,9 +378,9 @@ class Vector3 { @cite Henrik Wann Jensen, Realistic Image Synthesis using Photon Mapping eqn 2.24 */ - static Vector3 cosHemiRandom(const Vector3& n, Random& r = Random::common()); + static Vector3 cosHemiRandom(const Vector3& n, Random& r = commonRandom()); - static Vector3 cosSphereRandom(const Vector3& n, Random& r = Random::common()); + static Vector3 cosSphereRandom(const Vector3& n, Random& r = commonRandom()); /** \brief Random unit vector, distributed according to \f$\max(\cos^k \theta,0)\f$. @@ -397,7 +395,7 @@ class Vector3 { @cite Ashikhmin and Shirley, An anisotropic Phong BRDF model, Journal of Graphics Tools, 2002 */ - static Vector3 cosPowHemiRandom(const Vector3& n, const float k, Random& r = Random::common()); + static Vector3 cosPowHemiRandom(const Vector3& n, const float k, Random& r = commonRandom()); /** \brief Random vector distributed over the hemisphere about normal. @@ -405,7 +403,7 @@ class Vector3 { Distribution rendered by G3D::DirectionHistogram: \image html vector3-hemirandom.png */ - static Vector3 hemiRandom(const Vector3& normal, Random& r = Random::common()); + static Vector3 hemiRandom(const Vector3& normal, Random& r = commonRandom()); inline float sum() const { return x + y + z; diff --git a/dep/g3dlite/include/G3D/Vector4.h b/dep/g3dlite/include/G3D/Vector4.h index 24521efc93c..0f0ea459dfa 100644 --- a/dep/g3dlite/include/G3D/Vector4.h +++ b/dep/g3dlite/include/G3D/Vector4.h @@ -19,7 +19,6 @@ #include "G3D/g3dmath.h" #include "G3D/Vector3.h" #include "G3D/Vector2.h" -#include "G3D/Table.h" #include "G3D/HashTrait.h" #include "G3D/PositionTrait.h" #include diff --git a/dep/g3dlite/include/G3D/debugAssert.h b/dep/g3dlite/include/G3D/debugAssert.h index edff671061d..197312bd12e 100644 --- a/dep/g3dlite/include/G3D/debugAssert.h +++ b/dep/g3dlite/include/G3D/debugAssert.h @@ -32,6 +32,7 @@ #include #ifdef _MSC_VER +#include // conditional expression is constant # pragma warning (disable : 4127) #endif @@ -116,7 +117,7 @@ namespace _internal { #ifdef G3D_DEBUG # if defined(_MSC_VER) -# define rawBreak() ::DebugBreak(); +# define rawBreak() ::__debugbreak(); # elif defined(__i386__) // gcc on intel # define rawBreak() __asm__ __volatile__ ( "int $3" ); diff --git a/dep/g3dlite/include/G3D/platform.h b/dep/g3dlite/include/G3D/platform.h index d043f21491a..9202fe41d0b 100644 --- a/dep/g3dlite/include/G3D/platform.h +++ b/dep/g3dlite/include/G3D/platform.h @@ -190,6 +190,7 @@ These control the version of Winsock used by G3D. // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_Compiler_Reference.asp // +#if 0 // DLL runtime #ifndef _DLL #define _DLL @@ -227,6 +228,8 @@ These control the version of Winsock used by G3D. # undef WIN32_LEAN_AND_MEAN # undef NOMINMAX +#endif // 0 + # ifdef _G3D_INTERNAL_HIDE_WINSOCK_ # undef _G3D_INTERNAL_HIDE_WINSOCK_ # undef _WINSOCKAPI_ diff --git a/dep/g3dlite/source/FileSystem.cpp b/dep/g3dlite/source/FileSystem.cpp index 0898af79534..ff5da023443 100644 --- a/dep/g3dlite/source/FileSystem.cpp +++ b/dep/g3dlite/source/FileSystem.cpp @@ -35,7 +35,7 @@ # include # include # define _getcwd getcwd -# if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) +# if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) # define stat64 stat # endif # define _stat stat diff --git a/dep/g3dlite/source/Random.cpp b/dep/g3dlite/source/Random.cpp index cbfa07dec0b..a31d52a557c 100644 --- a/dep/g3dlite/source/Random.cpp +++ b/dep/g3dlite/source/Random.cpp @@ -227,4 +227,9 @@ void Random::sphere(float& x, float& y, float& z) { z *= s; } +Random& commonRandom() +{ + return Random::common(); +} + } // G3D diff --git a/dep/g3dlite/source/Vector2.cpp b/dep/g3dlite/source/Vector2.cpp index a6edea9a83f..194cd3090de 100644 --- a/dep/g3dlite/source/Vector2.cpp +++ b/dep/g3dlite/source/Vector2.cpp @@ -23,6 +23,7 @@ #include "G3D/TextInput.h" #include "G3D/TextOutput.h" #include "G3D/Any.h" +#include "G3D/Random.h" namespace G3D { diff --git a/dep/g3dlite/source/Vector3.cpp b/dep/g3dlite/source/Vector3.cpp index e2d9643e5cc..ccbf7d6a0bd 100644 --- a/dep/g3dlite/source/Vector3.cpp +++ b/dep/g3dlite/source/Vector3.cpp @@ -28,6 +28,7 @@ #include "G3D/Vector4.h" #include "G3D/Vector3int32.h" #include "G3D/Any.h" +#include "G3D/Random.h" namespace G3D { diff --git a/dep/g3dlite/source/debugAssert.cpp b/dep/g3dlite/source/debugAssert.cpp index 3c3e43a0af9..ff843fb7ee0 100644 --- a/dep/g3dlite/source/debugAssert.cpp +++ b/dep/g3dlite/source/debugAssert.cpp @@ -23,6 +23,7 @@ #include #ifdef _MSC_VER +#include // disable: "C++ exception handler used" # pragma warning (push) # pragma warning (disable : 4530) diff --git a/src/common/Collision/Maps/TileAssembler.cpp b/src/common/Collision/Maps/TileAssembler.cpp index c8dc2d46620..27dc57c7c86 100644 --- a/src/common/Collision/Maps/TileAssembler.cpp +++ b/src/common/Collision/Maps/TileAssembler.cpp @@ -214,7 +214,6 @@ namespace VMAP } printf("Read coordinate mapping...\n"); uint32 mapID, tileX, tileY, check; - G3D::Vector3 v1, v2; ModelSpawn spawn; while (!feof(dirf)) { @@ -222,8 +221,13 @@ namespace VMAP check = fread(&mapID, sizeof(uint32), 1, dirf); if (check == 0) // EoF... break; - fread(&tileX, sizeof(uint32), 1, dirf); - fread(&tileY, sizeof(uint32), 1, dirf); + check = fread(&tileX, sizeof(uint32), 1, dirf); + if (check == 0) // EoF... + break; + check = fread(&tileY, sizeof(uint32), 1, dirf); + if (check == 0) // EoF... + break; + if (!ModelSpawn::readFromFile(dirf, spawn)) break; diff --git a/src/common/Collision/Maps/TileAssembler.h b/src/common/Collision/Maps/TileAssembler.h index 010cb590407..bdad179ad06 100644 --- a/src/common/Collision/Maps/TileAssembler.h +++ b/src/common/Collision/Maps/TileAssembler.h @@ -94,7 +94,6 @@ namespace VMAP private: std::string iDestDir; std::string iSrcDir; - G3D::Table iUniqueNameIds; MapData mapData; std::set spawnedModelFiles; diff --git a/src/common/Cryptography/CryptoHash.h b/src/common/Cryptography/CryptoHash.h index 01b488cb4dd..49d421c7fb1 100644 --- a/src/common/Cryptography/CryptoHash.h +++ b/src/common/Cryptography/CryptoHash.h @@ -24,6 +24,7 @@ #include #include #include +#include #include class BigNumber; diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 60d9d057429..0b56c3b07c3 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -91,7 +91,7 @@ uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 uint32 MSV = pItem->GetTemplate()->SellPrice; if (MSV <= 0) - return AH_MINIMUM_DEPOSIT * sWorld->getRate(RATE_AUCTION_DEPOSIT); + return float(AH_MINIMUM_DEPOSIT) * sWorld->getRate(RATE_AUCTION_DEPOSIT); float multiplier = CalculatePct(float(entry->DepositRate), 3); uint32 timeHr = (((time / 60) / 60) / 12); @@ -113,8 +113,8 @@ uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 TC_LOG_DEBUG("auctionHouse", "Deposit: %u", deposit); TC_LOG_DEBUG("auctionHouse", "Deposit rm: %f", remainderbase * count); - if (deposit < AH_MINIMUM_DEPOSIT * sWorld->getRate(RATE_AUCTION_DEPOSIT)) - return AH_MINIMUM_DEPOSIT * sWorld->getRate(RATE_AUCTION_DEPOSIT); + if (deposit < float(AH_MINIMUM_DEPOSIT) * sWorld->getRate(RATE_AUCTION_DEPOSIT)) + return float(AH_MINIMUM_DEPOSIT) * sWorld->getRate(RATE_AUCTION_DEPOSIT); else return deposit; } diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp index a025d75d9fc..3594a4200b9 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp +++ b/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp @@ -389,7 +389,7 @@ uint32 AuctionBotBuyer::GetChanceMultiplier(uint32 quality) // Buys the auction and does necessary actions to complete the buyout void AuctionBotBuyer::BuyEntry(AuctionEntry* auction, AuctionHouseObject* auctionHouse) { - TC_LOG_DEBUG("ahbot", "AHBot: Entry %u bought at %.2fg", auction->Id, float(auction->buyout) / GOLD); + TC_LOG_DEBUG("ahbot", "AHBot: Entry %u bought at %.2fg", auction->Id, float(auction->buyout) / float(GOLD)); CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction(); @@ -420,7 +420,7 @@ void AuctionBotBuyer::BuyEntry(AuctionEntry* auction, AuctionHouseObject* auctio // Bids on the auction and does the necessary actions for bidding void AuctionBotBuyer::PlaceBidToEntry(AuctionEntry* auction, uint32 bidPrice) { - TC_LOG_DEBUG("ahbot", "AHBot: Bid placed to entry %u, %.2fg", auction->Id, float(bidPrice) / GOLD); + TC_LOG_DEBUG("ahbot", "AHBot: Bid placed to entry %u, %.2fg", auction->Id, float(bidPrice) / float(GOLD)); CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction(); diff --git a/src/server/game/Battlefield/Battlefield.cpp b/src/server/game/Battlefield/Battlefield.cpp index 99fedbaa4f7..f8c8ba59d1e 100644 --- a/src/server/game/Battlefield/Battlefield.cpp +++ b/src/server/game/Battlefield/Battlefield.cpp @@ -1000,7 +1000,7 @@ bool BfCapturePoint::Update(uint32 diff) } // get the difference of numbers - float fact_diff = ((float) m_activePlayers[TEAM_ALLIANCE].size() - (float) m_activePlayers[TEAM_HORDE].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL; + float fact_diff = ((float) m_activePlayers[TEAM_ALLIANCE].size() - (float) m_activePlayers[TEAM_HORDE].size()) * diff / float(BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL); if (G3D::fuzzyEq(fact_diff, 0.0f)) return false; diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp index 0cc836d3877..aaf3552edc1 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp @@ -378,7 +378,7 @@ void BattlegroundAB::_NodeOccupied(uint8 node, Team team) uint8 capturedNodes = 0; for (uint8 i = 0; i < BG_AB_DYNAMIC_NODES_COUNT; ++i) - if (m_Nodes[i] == GetTeamIndexByTeamId(team) + BG_AB_NODE_TYPE_OCCUPIED && !m_NodeTimers[i]) + if (m_Nodes[i] == uint8(GetTeamIndexByTeamId(team)) + BG_AB_NODE_TYPE_OCCUPIED && !m_NodeTimers[i]) ++capturedNodes; if (capturedNodes >= 5) @@ -472,7 +472,7 @@ void BattlegroundAB::EventPlayerClickedOnFlag(Player* source, GameObject* /*targ { UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1); m_prevNodes[node] = m_Nodes[node]; - m_Nodes[node] = teamIndex + BG_AB_NODE_TYPE_CONTESTED; + m_Nodes[node] = uint8(teamIndex) + BG_AB_NODE_TYPE_CONTESTED; // burn current contested banner _DelBanner(node, BG_AB_NODE_TYPE_CONTESTED, !teamIndex); // create new contested banner @@ -490,7 +490,7 @@ void BattlegroundAB::EventPlayerClickedOnFlag(Player* source, GameObject* /*targ { UpdatePlayerScore(source, SCORE_BASES_DEFENDED, 1); m_prevNodes[node] = m_Nodes[node]; - m_Nodes[node] = teamIndex + BG_AB_NODE_TYPE_OCCUPIED; + m_Nodes[node] = uint8(teamIndex) + BG_AB_NODE_TYPE_OCCUPIED; // burn current contested banner _DelBanner(node, BG_AB_NODE_TYPE_CONTESTED, !teamIndex); // create new occupied banner @@ -511,7 +511,7 @@ void BattlegroundAB::EventPlayerClickedOnFlag(Player* source, GameObject* /*targ { UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1); m_prevNodes[node] = m_Nodes[node]; - m_Nodes[node] = teamIndex + BG_AB_NODE_TYPE_CONTESTED; + m_Nodes[node] = uint8(teamIndex) + BG_AB_NODE_TYPE_CONTESTED; // burn current occupied banner _DelBanner(node, BG_AB_NODE_TYPE_OCCUPIED, !teamIndex); // create new contested banner diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundAV.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundAV.cpp index e972a57f294..3f1a5f99d66 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundAV.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundAV.cpp @@ -40,7 +40,7 @@ void BattlegroundAVScore::BuildObjectivesBlock(WorldPacket& data) BattlegroundAV::BattlegroundAV() { BgObjects.resize(BG_AV_OBJECT_MAX); - BgCreatures.resize(AV_CPLACE_MAX+AV_STATICCPLACE_MAX); + BgCreatures.resize(AV_CPLACE_MAX + AsUnderlyingType(AV_STATICCPLACE_MAX)); for (uint8 i = 0; i < 2; i++) { @@ -287,7 +287,7 @@ Creature* BattlegroundAV::AddAVCreature(uint16 cinfoid, uint16 type) { bool isStatic = false; Creature* creature = nullptr; - ASSERT(type < AV_CPLACE_MAX + AV_STATICCPLACE_MAX); + ASSERT(type < AV_CPLACE_MAX + AsUnderlyingType(AV_STATICCPLACE_MAX)); if (type >= AV_CPLACE_MAX) //static { type -= AV_CPLACE_MAX; @@ -591,8 +591,8 @@ void BattlegroundAV::EventPlayerDestroyedPoint(BG_AV_Nodes node) RewardReputationToTeam(owner == ALLIANCE ? 730 : 729, BG_AV_REP_TOWER, owner); RewardHonorToTeam(GetBonusHonorFromKill(BG_AV_KILL_TOWER), owner); - SpawnBGObject(BG_AV_OBJECT_TAURA_A_DUNBALDAR_SOUTH+GetTeamIndexByTeamId(owner)+(2*tmp), RESPAWN_ONE_DAY); - SpawnBGObject(BG_AV_OBJECT_TFLAG_A_DUNBALDAR_SOUTH+GetTeamIndexByTeamId(owner)+(2*tmp), RESPAWN_ONE_DAY); + SpawnBGObject(BG_AV_OBJECT_TAURA_A_DUNBALDAR_SOUTH + uint32(GetTeamIndexByTeamId(owner)) + (2 * tmp), RESPAWN_ONE_DAY); + SpawnBGObject(BG_AV_OBJECT_TFLAG_A_DUNBALDAR_SOUTH + uint32(GetTeamIndexByTeamId(owner)) + (2 * tmp), RESPAWN_ONE_DAY); } else { @@ -600,8 +600,8 @@ void BattlegroundAV::EventPlayerDestroyedPoint(BG_AV_Nodes node) SpawnBGObject(object-11, RESPAWN_IMMEDIATELY); else SpawnBGObject(object+11, RESPAWN_IMMEDIATELY); - SpawnBGObject(BG_AV_OBJECT_AURA_N_FIRSTAID_STATION+3*node, RESPAWN_ONE_DAY); - SpawnBGObject(BG_AV_OBJECT_AURA_A_FIRSTAID_STATION+GetTeamIndexByTeamId(owner)+3*node, RESPAWN_IMMEDIATELY); + SpawnBGObject(BG_AV_OBJECT_AURA_N_FIRSTAID_STATION + 3 * node, RESPAWN_ONE_DAY); + SpawnBGObject(BG_AV_OBJECT_AURA_A_FIRSTAID_STATION + uint32(GetTeamIndexByTeamId(owner)) + 3 * node, RESPAWN_IMMEDIATELY); PopulateNode(node); if (node == BG_AV_NODES_SNOWFALL_GRAVE) //snowfall eyecandy { @@ -906,8 +906,8 @@ void BattlegroundAV::EventPlayerDefendsPoint(Player* player, uint32 object) if (!IsTower(node)) { - SpawnBGObject(BG_AV_OBJECT_AURA_N_FIRSTAID_STATION+3*node, RESPAWN_ONE_DAY); - SpawnBGObject(BG_AV_OBJECT_AURA_A_FIRSTAID_STATION+GetTeamIndexByTeamId(team)+3*node, RESPAWN_IMMEDIATELY); + SpawnBGObject(BG_AV_OBJECT_AURA_N_FIRSTAID_STATION + 3 * node, RESPAWN_ONE_DAY); + SpawnBGObject(BG_AV_OBJECT_AURA_A_FIRSTAID_STATION + uint32(GetTeamIndexByTeamId(team)) + 3 * node, RESPAWN_IMMEDIATELY); } // despawn old go SpawnBGObject(object, RESPAWN_ONE_DAY); @@ -1012,8 +1012,8 @@ void BattlegroundAV::EventPlayerAssaultsPoint(Player* player, uint32 object) else { //spawning/despawning of aura - SpawnBGObject(BG_AV_OBJECT_AURA_N_FIRSTAID_STATION+3*node, RESPAWN_IMMEDIATELY); //neutral aura spawn - SpawnBGObject(BG_AV_OBJECT_AURA_A_FIRSTAID_STATION+GetTeamIndexByTeamId(owner)+3*node, RESPAWN_ONE_DAY); //teeamaura despawn + SpawnBGObject(BG_AV_OBJECT_AURA_N_FIRSTAID_STATION + 3 * node, RESPAWN_IMMEDIATELY); //neutral aura spawn + SpawnBGObject(BG_AV_OBJECT_AURA_A_FIRSTAID_STATION + uint32(GetTeamIndexByTeamId(owner)) + 3 * node, RESPAWN_ONE_DAY); //teeamaura despawn RelocateDeadPlayers(BgCreatures[node]); } @@ -1503,7 +1503,7 @@ void BattlegroundAV::ResetBGSubclass() InitNode(BG_AV_NODES_SNOWFALL_GRAVE, AV_NEUTRAL_TEAM, false); //give snowfall neutral owner m_Mine_Timer = AV_MINE_TICK_TIMER; - for (uint16 i = 0; i < AV_CPLACE_MAX+AV_STATICCPLACE_MAX; i++) + for (uint16 i = 0; i < AV_CPLACE_MAX + AsUnderlyingType(AV_STATICCPLACE_MAX); i++) if (BgCreatures[i]) DelCreature(i); } diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp index 6ff89cfb440..eb443c02de6 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp @@ -447,13 +447,13 @@ void BattlegroundIC::EventPlayerClickedOnFlag(Player* player, GameObject* target nodePoint[i].timer = BANNER_STATE_CHANGE_TIME; // 1 minute for last change (real faction banner) nodePoint[i].needChange = true; - RelocateDeadPlayers(BgCreatures[BG_IC_NPC_SPIRIT_GUIDE_1 + nodePoint[i].nodeType - 2]); + RelocateDeadPlayers(BgCreatures[BG_IC_NPC_SPIRIT_GUIDE_1 + uint32(nodePoint[i].nodeType) - 2]); // if we are here means that the point has been lost, or it is the first capture if (nodePoint[i].nodeType != NODE_TYPE_REFINERY && nodePoint[i].nodeType != NODE_TYPE_QUARRY) - if (BgCreatures[BG_IC_NPC_SPIRIT_GUIDE_1+(nodePoint[i].nodeType)-2]) - DelCreature(BG_IC_NPC_SPIRIT_GUIDE_1+(nodePoint[i].nodeType)-2); + if (!BgCreatures[BG_IC_NPC_SPIRIT_GUIDE_1 + uint32(nodePoint[i].nodeType) - 2].IsEmpty()) + DelCreature(BG_IC_NPC_SPIRIT_GUIDE_1 + uint32(nodePoint[i].nodeType) - 2); UpdatePlayerScore(player, SCORE_BASES_ASSAULTED, 1); @@ -596,7 +596,7 @@ void BattlegroundIC::HandleCapturedNodes(ICNodePoint* node, bool recapture) { if (node->nodeType != NODE_TYPE_REFINERY && node->nodeType != NODE_TYPE_QUARRY) { - if (!AddSpiritGuide(BG_IC_NPC_SPIRIT_GUIDE_1+node->nodeType-2, BG_IC_SpiritGuidePos[node->nodeType], node->faction)) + if (!AddSpiritGuide(BG_IC_NPC_SPIRIT_GUIDE_1 + uint32(node->nodeType) - 2, BG_IC_SpiritGuidePos[node->nodeType], node->faction)) TC_LOG_ERROR("bg.battleground", "Isle of Conquest: Failed to spawn spirit guide! point: %u, team: %u, ", node->nodeType, node->faction); } @@ -897,7 +897,7 @@ WorldSafeLocsEntry const* BattlegroundIC::GetClosestGraveyard(Player* player) } // If not, place ghost on starting location if (!good_entry) - good_entry = sWorldSafeLocsStore.LookupEntry(BG_IC_GraveyardIds[teamIndex+MAX_NODE_TYPES]); + good_entry = sWorldSafeLocsStore.LookupEntry(BG_IC_GraveyardIds[uint32(teamIndex) + MAX_NODE_TYPES]); return good_entry; } diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp index f6b997c2527..4b5366674db 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp @@ -41,7 +41,7 @@ BattlegroundSA::BattlegroundSA() StartMessageIds[BG_STARTING_EVENT_FOURTH] = 0; // handle by Kanrethad BgObjects.resize(BG_SA_MAXOBJ); - BgCreatures.resize(BG_SA_MAXNPC + BG_SA_MAX_GY); + BgCreatures.resize(AsUnderlyingType(BG_SA_MAXNPC) + AsUnderlyingType(BG_SA_MAX_GY)); TimerEnabled = false; UpdateWaitTimer = 0; SignaledRoundTwo = false; @@ -105,7 +105,7 @@ bool BattlegroundSA::ResetObjs() for (uint8 i = 0; i < BG_SA_MAXNPC; i++) DelCreature(i); - for (uint8 i = BG_SA_MAXNPC; i < BG_SA_MAXNPC + BG_SA_MAX_GY; i++) + for (uint8 i = BG_SA_MAXNPC; i < AsUnderlyingType(BG_SA_MAXNPC) + AsUnderlyingType(BG_SA_MAX_GY); i++) DelCreature(i); for (uint8 i = 0; i < MAX_GATES; ++i) @@ -808,7 +808,7 @@ void BattlegroundSA::CaptureGraveyard(BG_SA_Graveyards i, Player* Source) if (GraveyardStatus[i] == Attackers) return; - DelCreature(BG_SA_MAXNPC + i); + DelCreature(AsUnderlyingType(BG_SA_MAXNPC) + i); GraveyardStatus[i] = Source->GetTeamId(); WorldSafeLocsEntry const* sg = sWorldSafeLocsStore.LookupEntry(BG_SA_GYEntries[i]); if (!sg) @@ -817,7 +817,7 @@ void BattlegroundSA::CaptureGraveyard(BG_SA_Graveyards i, Player* Source) return; } - AddSpiritGuide(i + BG_SA_MAXNPC, sg->Loc.X, sg->Loc.Y, sg->Loc.Z, BG_SA_GYOrientation[i], GraveyardStatus[i]); + AddSpiritGuide(i + AsUnderlyingType(BG_SA_MAXNPC), sg->Loc.X, sg->Loc.Y, sg->Loc.Z, BG_SA_GYOrientation[i], GraveyardStatus[i]); uint32 npc = 0; uint32 flag = 0; diff --git a/src/server/game/DataStores/M2Stores.cpp b/src/server/game/DataStores/M2Stores.cpp index d8caf1b340d..1614862b65f 100644 --- a/src/server/game/DataStores/M2Stores.cpp +++ b/src/server/game/DataStores/M2Stores.cpp @@ -15,17 +15,15 @@ * with this program. If not, see . */ -#include "DBCStores.h" -#include "Common.h" +#include "M2Stores.h" #include "Containers.h" +#include "DBCStores.h" #include "Log.h" #include "M2Structure.h" -#include "M2Stores.h" -#include "World.h" +#include "Timer.h" #include +#include #include -#include -#include typedef std::vector FlyByCameraCollection; std::unordered_map sFlyByCameraStore; diff --git a/src/server/game/Entities/Object/Position.cpp b/src/server/game/Entities/Object/Position.cpp index 1304acebe5d..ecbe15d96cd 100644 --- a/src/server/game/Entities/Object/Position.cpp +++ b/src/server/game/Entities/Object/Position.cpp @@ -25,7 +25,7 @@ #include #include -bool Position::operator==(Position const& a) +bool Position::operator==(Position const& a) const { return (G3D::fuzzyEq(a.m_positionX, m_positionX) && G3D::fuzzyEq(a.m_positionY, m_positionY) && diff --git a/src/server/game/Entities/Object/Position.h b/src/server/game/Entities/Object/Position.h index a9713f9443c..d029c270380 100644 --- a/src/server/game/Entities/Object/Position.h +++ b/src/server/game/Entities/Object/Position.h @@ -61,8 +61,8 @@ struct TC_GAME_API Position float m_orientation; public: - bool operator==(Position const& a); - bool operator!=(Position const& a) { return !(operator==(a)); } + bool operator==(Position const& a) const; + bool operator!=(Position const& a) const { return !(operator==(a)); } void Relocate(float x, float y) { m_positionX = x; m_positionY = y; } void Relocate(float x, float y, float z) { Relocate(x, y); m_positionZ = z; } diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index 26297f26f63..8e57375e2e8 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -960,8 +960,8 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) case SUMMON_PET: { // the damage bonus used for pets is either fire or shadow damage, whatever is higher - int32 fire = GetOwner()->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE); - int32 shadow = GetOwner()->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW); + int32 fire = GetOwner()->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_FIRE)); + int32 shadow = GetOwner()->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_SHADOW)); int32 val = (fire > shadow) ? fire : shadow; if (val < 0) val = 0; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 7cf2edefaab..1eceae7f9bc 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -2172,7 +2172,7 @@ void Player::Regenerate(Powers power) if (m_regenTimerCount >= 2000) SetPower(power, curValue); else - UpdateUInt32Value(UNIT_FIELD_POWER1 + power, curValue); + UpdateUInt32Value(UNIT_FIELD_POWER1 + AsUnderlyingType(power), curValue); } void Player::RegenerateHealth() @@ -2808,8 +2808,8 @@ void Player::InitStatsForLevel(bool reapplyMods) // set armor (resistance 0) to original value (create_agility*2) SetArmor(int32(m_createStats[STAT_AGILITY]*2)); - SetFloatValue(UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE + SPELL_SCHOOL_NORMAL, 0.0f); - SetFloatValue(UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE + SPELL_SCHOOL_NORMAL, 0.0f); + SetFloatValue(UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE + AsUnderlyingType(SPELL_SCHOOL_NORMAL), 0.0f); + SetFloatValue(UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE + AsUnderlyingType(SPELL_SCHOOL_NORMAL), 0.0f); // set other resistance to original value (0) for (uint8 i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i) { @@ -5361,7 +5361,7 @@ void Player::GetDodgeFromAgility(float &diminishing, float &nondiminishing) cons return; /// @todo research if talents/effects that increase total agility by x% should increase non-diminishing part - float base_agility = GetCreateStat(STAT_AGILITY) * GetPctModifierValue(UnitMods(UNIT_MOD_STAT_START + STAT_AGILITY), BASE_PCT); + float base_agility = GetCreateStat(STAT_AGILITY) * GetPctModifierValue(UnitMods(UNIT_MOD_STAT_START + AsUnderlyingType(STAT_AGILITY)), BASE_PCT); float bonus_agility = GetStat(STAT_AGILITY) - base_agility; // calculate diminishing (green in char screen) and non-diminishing (white) contribution @@ -5404,7 +5404,7 @@ float Player::GetRatingMultiplier(CombatRating cr) const float Player::GetRatingBonusValue(CombatRating cr) const { - return float(GetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + cr)) * GetRatingMultiplier(cr); + return float(GetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + AsUnderlyingType(cr))) * GetRatingMultiplier(cr); } float Player::GetExpertiseDodgeOrParryReduction(WeaponAttackType attType) const @@ -5507,7 +5507,7 @@ void Player::UpdateRating(CombatRating cr) if (amount < 0) amount = 0; - SetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + cr, uint32(amount)); + SetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + AsUnderlyingType(cr), uint32(amount)); bool affectStats = CanModifyStats(); @@ -8055,7 +8055,7 @@ void Player::CastItemCombatSpell(DamageInfo const& damageInfo, Item* item, ItemT for (SpellEffectInfo const& spellEffectInfo : spellInfo->GetEffects()) if (spellEffectInfo.IsEffect()) - args.AddSpellMod(static_cast(SPELLVALUE_BASE_POINT0 + spellEffectInfo.EffectIndex), CalculatePct(spellEffectInfo.CalcValue(this), effectPct)); + args.AddSpellMod(static_cast(SPELLVALUE_BASE_POINT0 + AsUnderlyingType(spellEffectInfo.EffectIndex)), CalculatePct(spellEffectInfo.CalcValue(this), effectPct)); } CastSpell(target, spellInfo->Id, args); } @@ -20261,7 +20261,7 @@ void Player::_SaveStats(CharacterDatabaseTransaction trans) const stmt->setUInt32(index++, GetUInt32Value(UNIT_FIELD_ATTACK_POWER)); stmt->setUInt32(index++, GetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER)); stmt->setUInt32(index++, GetBaseSpellPowerBonus()); - stmt->setUInt32(index++, GetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + CR_CRIT_TAKEN_SPELL)); + stmt->setUInt32(index++, GetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + AsUnderlyingType(CR_CRIT_TAKEN_SPELL))); trans->Append(stmt); } diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index 6e4b0ed7857..cd1b4f4b819 100644 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -585,8 +585,8 @@ float Transport::CalculateSegmentPos(float now) KeyFrame const& frame = *_currentFrame; const float speed = float(m_goInfo->moTransport.moveSpeed); const float accel = float(m_goInfo->moTransport.accelRate); - float timeSinceStop = frame.TimeFrom + (now - (1.0f/IN_MILLISECONDS) * frame.DepartureTime); - float timeUntilStop = frame.TimeTo - (now - (1.0f/IN_MILLISECONDS) * frame.DepartureTime); + float timeSinceStop = frame.TimeFrom + (now - (1.0f / float(IN_MILLISECONDS)) * frame.DepartureTime); + float timeUntilStop = frame.TimeTo - (now - (1.0f / float(IN_MILLISECONDS)) * frame.DepartureTime); float segmentPos, dist; float accelTime = _transportInfo->accelTime; float accelDist = _transportInfo->accelDist; diff --git a/src/server/game/Entities/Unit/StatSystem.cpp b/src/server/game/Entities/Unit/StatSystem.cpp index 5dccf992645..b4c09f71e31 100644 --- a/src/server/game/Entities/Unit/StatSystem.cpp +++ b/src/server/game/Entities/Unit/StatSystem.cpp @@ -316,7 +316,7 @@ void Player::UpdateMaxHealth() void Player::UpdateMaxPower(Powers power) { - UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + power); + UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + AsUnderlyingType(power)); float bonusPower = (power == POWER_MANA && GetCreatePowerValue(power) > 0) ? GetManaBonusFromIntellect() : 0; @@ -851,7 +851,7 @@ void Player::UpdateSpellCritChance(uint32 school) void Player::UpdateArmorPenetration(int32 amount) { // Store Rating Value - SetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + CR_ARMOR_PENETRATION, amount); + SetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + AsUnderlyingType(CR_ARMOR_PENETRATION), amount); } void Player::UpdateMeleeHitChances() @@ -1036,7 +1036,7 @@ void Creature::UpdateMaxHealth() void Creature::UpdateMaxPower(Powers power) { - UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + power); + UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + AsUnderlyingType(power)); float value = GetFlatModifierValue(unitMod, BASE_VALUE) + GetCreatePowerValue(power); value *= GetPctModifierValue(unitMod, BASE_PCT); @@ -1329,7 +1329,7 @@ void Guardian::UpdateMaxHealth() void Guardian::UpdateMaxPower(Powers power) { - UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + power); + UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + AsUnderlyingType(power)); float addValue = (power == POWER_MANA) ? GetStat(STAT_INTELLECT) - GetCreateStat(STAT_INTELLECT) : 0.0f; float multiplicator = 15.0f; @@ -1409,8 +1409,8 @@ void Guardian::UpdateAttackPowerAndDamage(bool ranged) //demons benefit from warlocks shadow or fire damage else if (IsPet()) { - int32 fire = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_FIRE); - int32 shadow = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_SHADOW); + int32 fire = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_FIRE)) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + AsUnderlyingType(SPELL_SCHOOL_FIRE)); + int32 shadow = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_SHADOW)) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + AsUnderlyingType(SPELL_SCHOOL_SHADOW)); int32 maximum = (fire > shadow) ? fire : shadow; if (maximum < 0) maximum = 0; @@ -1420,7 +1420,7 @@ void Guardian::UpdateAttackPowerAndDamage(bool ranged) //water elementals benefit from mage's frost damage else if (GetEntry() == ENTRY_WATER_ELEMENTAL) { - int32 frost = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FROST) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_FROST); + int32 frost = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_FROST)) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + AsUnderlyingType(SPELL_SCHOOL_FROST)); if (frost < 0) frost = 0; SetBonusDamage(int32(frost * 0.4f)); @@ -1453,14 +1453,14 @@ void Guardian::UpdateDamagePhysical(WeaponAttackType attType) //force of nature if (GetEntry() == ENTRY_TREANT) { - int32 spellDmg = m_owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_NATURE) - m_owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_NATURE); + int32 spellDmg = m_owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_NATURE)) - m_owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + AsUnderlyingType(SPELL_SCHOOL_NATURE)); if (spellDmg > 0) bonusDamage = spellDmg * 0.09f; } //greater fire elemental else if (GetEntry() == ENTRY_FIRE_ELEMENTAL) { - int32 spellDmg = m_owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE) - m_owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_FIRE); + int32 spellDmg = m_owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_FIRE)) - m_owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + AsUnderlyingType(SPELL_SCHOOL_FIRE)); if (spellDmg > 0) bonusDamage = spellDmg * 0.4f; } diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index f2f1fbb955e..be5927abd26 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -4954,8 +4954,8 @@ void Unit::UpdateResistanceBuffModsMod(SpellSchools school) modPos *= factor; modNeg *= factor; - SetFloatValue(UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE + school, modPos); - SetFloatValue(UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE + school, modNeg); + SetFloatValue(UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE + AsUnderlyingType(school), modPos); + SetFloatValue(UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE + AsUnderlyingType(school), modNeg); } void Unit::InitStatBuffMods() @@ -4972,7 +4972,7 @@ void Unit::UpdateStatBuffMod(Stats stat) float modNeg = 0.0f; float factor = 0.0f; - UnitMods const unitMod = static_cast(UNIT_MOD_STAT_START + stat); + UnitMods const unitMod = static_cast(UNIT_MOD_STAT_START + AsUnderlyingType(stat)); // includes value from items and enchantments float modValue = GetFlatModifierValue(unitMod, BASE_VALUE); @@ -5021,8 +5021,8 @@ void Unit::UpdateStatBuffMod(Stats stat) modPos *= factor; modNeg *= factor; - SetFloatValue(UNIT_FIELD_POSSTAT0 + stat, modPos); - SetFloatValue(UNIT_FIELD_NEGSTAT0 + stat, modNeg); + SetFloatValue(UNIT_FIELD_POSSTAT0 + AsUnderlyingType(stat), modPos); + SetFloatValue(UNIT_FIELD_NEGSTAT0 + AsUnderlyingType(stat), modNeg); } void Unit::_RegisterDynObject(DynamicObject* dynObj) @@ -7023,7 +7023,7 @@ float Unit::SpellCritChanceDone(SpellInfo const* spellInfo, SpellSchoolMask scho crit_chance = 0.0f; // For other schools else if (GetTypeId() == TYPEID_PLAYER) - crit_chance = GetFloatValue(PLAYER_SPELL_CRIT_PERCENTAGE1 + GetFirstSchoolInMask(schoolMask)); + crit_chance = GetFloatValue(PLAYER_SPELL_CRIT_PERCENTAGE1 + AsUnderlyingType(GetFirstSchoolInMask(schoolMask))); else { crit_chance = (float)m_baseSpellCritChance; @@ -8461,7 +8461,7 @@ int32 Unit::ModifyPower(Powers power, int32 dVal, bool withPowerUpdate /*= true* uint32 Unit::GetAttackTime(WeaponAttackType att) const { - float f_BaseAttackTime = GetFloatValue(UNIT_FIELD_BASEATTACKTIME + att) / m_modAttackSpeedPct[att]; + float f_BaseAttackTime = GetFloatValue(UNIT_FIELD_BASEATTACKTIME + AsUnderlyingType(att)) / m_modAttackSpeedPct[att]; return (uint32)f_BaseAttackTime; } @@ -9212,7 +9212,7 @@ void Unit::UpdateAllDamagePctDoneMods() float Unit::GetTotalStatValue(Stats stat) const { - UnitMods unitMod = UnitMods(UNIT_MOD_STAT_START + stat); + UnitMods unitMod = UnitMods(UNIT_MOD_STAT_START + AsUnderlyingType(stat)); // value = ((base_value * base_pct) + total_value) * total_pct float value = GetFlatModifierValue(unitMod, BASE_VALUE) + GetCreateStat(stat); @@ -9411,7 +9411,7 @@ void Unit::SetPower(Powers power, uint32 val, bool withPowerUpdate /*= true*/) if (maxPower < val) val = maxPower; - SetStatInt32Value(UNIT_FIELD_POWER1 + power, val); + SetStatInt32Value(UNIT_FIELD_POWER1 + AsUnderlyingType(power), val); if (withPowerUpdate) { @@ -9446,7 +9446,7 @@ void Unit::SetPower(Powers power, uint32 val, bool withPowerUpdate /*= true*/) void Unit::SetMaxPower(Powers power, uint32 val) { uint32 cur_power = GetPower(power); - SetStatInt32Value(UNIT_FIELD_MAXPOWER1 + power, val); + SetStatInt32Value(UNIT_FIELD_MAXPOWER1 + AsUnderlyingType(power), val); // group update if (GetTypeId() == TYPEID_PLAYER) @@ -10603,7 +10603,7 @@ void ApplyPercentModFloatVar(float& var, float val, bool apply) void Unit::ApplyAttackTimePercentMod(WeaponAttackType att, float val, bool apply) { - float amount = GetFloatValue(UNIT_FIELD_BASEATTACKTIME + att); + float amount = GetFloatValue(UNIT_FIELD_BASEATTACKTIME + AsUnderlyingType(att)); float remainingTimePct = (float)m_attackTimer[att] / (GetAttackTime(att) * m_modAttackSpeedPct[att]); if (val > 0.f) @@ -10617,7 +10617,7 @@ void Unit::ApplyAttackTimePercentMod(WeaponAttackType att, float val, bool apply ApplyPercentModFloatVar(amount, -val, apply); } - SetFloatValue(UNIT_FIELD_BASEATTACKTIME + att, amount); + SetFloatValue(UNIT_FIELD_BASEATTACKTIME + AsUnderlyingType(att), amount); m_attackTimer[att] = uint32(GetAttackTime(att) * m_modAttackSpeedPct[att] * remainingTimePct); } @@ -12754,7 +12754,7 @@ void Unit::_ExitVehicle(Position const* exitPosition) } } - std::function initializer = [=, vehicleCollisionHeight = vehicle->GetBase()->GetCollisionHeight()](Movement::MoveSplineInit& init) + std::function initializer = [=, this, vehicleCollisionHeight = vehicle->GetBase()->GetCollisionHeight()](Movement::MoveSplineInit& init) { float height = pos.GetPositionZ() + vehicleCollisionHeight; diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index b7d8afcf47e..99fb781cef8 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -899,14 +899,14 @@ class TC_GAME_API Unit : public WorldObject virtual Gender GetNativeGender() const { return GetGender(); } virtual void SetNativeGender(Gender gender) { SetGender(gender); } - float GetStat(Stats stat) const { return float(GetUInt32Value(UNIT_FIELD_STAT0+stat)); } - void SetStat(Stats stat, int32 val) { SetStatInt32Value(UNIT_FIELD_STAT0+stat, val); } + float GetStat(Stats stat) const { return float(GetUInt32Value(UNIT_FIELD_STAT0 + int32(stat))); } + void SetStat(Stats stat, int32 val) { SetStatInt32Value(UNIT_FIELD_STAT0 + int32(stat), val); } uint32 GetArmor() const { return GetResistance(SPELL_SCHOOL_NORMAL); } void SetArmor(int32 val) { SetResistance(SPELL_SCHOOL_NORMAL, val); } - int32 GetResistance(SpellSchools school) const { return GetInt32Value(UNIT_FIELD_RESISTANCES + school); } + int32 GetResistance(SpellSchools school) const { return GetInt32Value(UNIT_FIELD_RESISTANCES + int32(school)); } int32 GetResistance(SpellSchoolMask mask) const; - void SetResistance(SpellSchools school, int32 val) { SetStatInt32Value(UNIT_FIELD_RESISTANCES + school, val); } + void SetResistance(SpellSchools school, int32 val) { SetStatInt32Value(UNIT_FIELD_RESISTANCES + int32(school), val); } static float CalculateAverageResistReduction(WorldObject const* caster, SpellSchoolMask schoolMask, Unit const* victim, SpellInfo const* spellInfo = nullptr); uint32 GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH); } @@ -930,8 +930,8 @@ class TC_GAME_API Unit : public WorldObject Powers GetPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_POWER_TYPE)); } void SetPowerType(Powers power, bool sendUpdate = true); void UpdateDisplayPower(); - uint32 GetPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_POWER1 +power); } - uint32 GetMaxPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1+power); } + uint32 GetPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_POWER1 + int32(power)); } + uint32 GetMaxPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1 + int32(power)); } float GetPowerPct(Powers power) const { return GetMaxPower(power) ? 100.f * GetPower(power) / GetMaxPower(power) : 0.0f; } int32 CountPctFromMaxPower(Powers power, int32 pct) const { return CalculatePct(GetMaxPower(power), pct); } void SetPower(Powers power, uint32 val, bool withPowerUpdate = true); @@ -941,7 +941,7 @@ class TC_GAME_API Unit : public WorldObject int32 ModifyPower(Powers power, int32 val, bool withPowerUpdate = true); uint32 GetAttackTime(WeaponAttackType att) const; - void SetAttackTime(WeaponAttackType att, uint32 val) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME+att, val*m_modAttackSpeedPct[att]); } + void SetAttackTime(WeaponAttackType att, uint32 val) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME + int32(att), val * m_modAttackSpeedPct[att]); } void ApplyAttackTimePercentMod(WeaponAttackType att, float val, bool apply); void ApplyCastTimePercentMod(float val, bool apply); @@ -1450,8 +1450,8 @@ class TC_GAME_API Unit : public WorldObject void SetCreateMana(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_MANA, val); } uint32 GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA); } uint32 GetCreatePowerValue(Powers power) const; - float GetPosStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0+stat); } - float GetNegStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0+stat); } + float GetPosStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0 + int32(stat)); } + float GetNegStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0 + int32(stat)); } float GetCreateStat(Stats stat) const { return m_createStats[stat]; } uint32 GetChannelSpellId() const { return GetUInt32Value(UNIT_CHANNEL_SPELL); } diff --git a/src/server/game/Guilds/Guild.cpp b/src/server/game/Guilds/Guild.cpp index f7b26e1caca..109be7c4968 100644 --- a/src/server/game/Guilds/Guild.cpp +++ b/src/server/game/Guilds/Guild.cpp @@ -1258,7 +1258,7 @@ void Guild::HandleRoster(WorldSession* session) memberData.Guid = member.GetGUID(); memberData.RankID = int32(member.GetRankId()); memberData.AreaID = int32(member.GetZoneId()); - memberData.LastSave = float(float(GameTime::GetGameTime() - member.GetLogoutTime()) / DAY); + memberData.LastSave = float(float(GameTime::GetGameTime() - member.GetLogoutTime()) / float(DAY)); memberData.Status = member.GetFlags(); memberData.Level = member.GetLevel(); diff --git a/src/server/game/Instances/InstanceSaveMgr.cpp b/src/server/game/Instances/InstanceSaveMgr.cpp index 41f5b42bc17..1680ed23b74 100644 --- a/src/server/game/Instances/InstanceSaveMgr.cpp +++ b/src/server/game/Instances/InstanceSaveMgr.cpp @@ -394,7 +394,7 @@ void InstanceSaveManager::LoadResetTimes() continue; // the reset_delay must be at least one day - uint32 period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME))/DAY) * DAY); + uint32 period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / float(DAY)) * float(DAY)); if (period < DAY) period = DAY; @@ -451,7 +451,7 @@ time_t InstanceSaveManager::GetSubsequentResetTime(uint32 mapid, Difficulty diff } time_t resetHour = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR); - time_t period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / DAY) * DAY); + time_t period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / float(DAY)) * float(DAY)); if (period < DAY) period = DAY; diff --git a/src/server/game/Maps/TransportMgr.cpp b/src/server/game/Maps/TransportMgr.cpp index 37ca7fcd7c0..ed0cfc71b17 100644 --- a/src/server/game/Maps/TransportMgr.cpp +++ b/src/server/game/Maps/TransportMgr.cpp @@ -327,7 +327,7 @@ void TransportMgr::GeneratePath(GameObjectTemplate const* goInfo, TransportTempl if (keyFrames[0].IsStopFrame()) { curPathTime = float(keyFrames[0].Node->Delay); - keyFrames[0].DepartureTime = uint32(curPathTime * IN_MILLISECONDS); + keyFrames[0].DepartureTime = uint32(curPathTime * float(IN_MILLISECONDS)); } for (size_t i = 1; i < keyFrames.size(); ++i) @@ -335,15 +335,15 @@ void TransportMgr::GeneratePath(GameObjectTemplate const* goInfo, TransportTempl curPathTime += keyFrames[i - 1].TimeTo; if (keyFrames[i].IsStopFrame()) { - keyFrames[i].ArriveTime = uint32(curPathTime * IN_MILLISECONDS); + keyFrames[i].ArriveTime = uint32(curPathTime * float(IN_MILLISECONDS)); keyFrames[i - 1].NextArriveTime = keyFrames[i].ArriveTime; curPathTime += float(keyFrames[i].Node->Delay); - keyFrames[i].DepartureTime = uint32(curPathTime * IN_MILLISECONDS); + keyFrames[i].DepartureTime = uint32(curPathTime * float(IN_MILLISECONDS)); } else { curPathTime -= keyFrames[i].TimeTo; - keyFrames[i].ArriveTime = uint32(curPathTime * IN_MILLISECONDS); + keyFrames[i].ArriveTime = uint32(curPathTime * float(IN_MILLISECONDS)); keyFrames[i - 1].NextArriveTime = keyFrames[i].ArriveTime; keyFrames[i].DepartureTime = keyFrames[i].ArriveTime; } diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index 636e121c2ab..4a137dcce91 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -686,7 +686,7 @@ void MotionMaster::MoveCloserAndStop(uint32 id, Unit* target, float distance) else { // We are already close enough. We just need to turn toward the target without changing position. - std::function initializer = [=, target = target->GetGUID()](Movement::MoveSplineInit& init) + std::function initializer = [=, this, target = target->GetGUID()](Movement::MoveSplineInit& init) { init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ()); init.SetFacing(target); @@ -840,7 +840,7 @@ void MotionMaster::MoveJump(float x, float y, float z, float o, float speedXY, f void MotionMaster::MoveCirclePath(float x, float y, float z, float radius, bool clockwise, uint8 stepCount) { - std::function initializer = [=](Movement::MoveSplineInit& init) + std::function initializer = [=, this](Movement::MoveSplineInit& init) { float step = 2 * float(M_PI) / stepCount * (clockwise ? -1.0f : 1.0f); Position const& pos = { x, y, z, 0.0f }; @@ -962,7 +962,7 @@ void MotionMaster::MoveFall(uint32 id/* = 0*/) return; } - std::function initializer = [=](Movement::MoveSplineInit& init) + std::function initializer = [=, this](Movement::MoveSplineInit& init) { init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), tz + _owner->GetHoverOffset(), false); init.SetFall(); diff --git a/src/server/game/Movement/Spline/MoveSpline.cpp b/src/server/game/Movement/Spline/MoveSpline.cpp index ded1aa69521..21bd7068bb7 100644 --- a/src/server/game/Movement/Spline/MoveSpline.cpp +++ b/src/server/game/Movement/Spline/MoveSpline.cpp @@ -220,14 +220,11 @@ bool MoveSplineInitArgs::_checkPathBounds() const { if (!(flags & MoveSplineFlag::Mask_CatmullRom) && path.size() > 2) { - enum{ - MAX_OFFSET = (1 << 11) / 2 - }; + constexpr float MAX_OFFSET = float((1 << 11) / 2); Vector3 middle = (path.front()+path.back()) / 2; - Vector3 offset; for (uint32 i = 1; i < path.size()-1; ++i) { - offset = path[i] - middle; + Vector3 offset = path[i] - middle; if (std::fabs(offset.x) >= MAX_OFFSET || std::fabs(offset.y) >= MAX_OFFSET || std::fabs(offset.z) >= MAX_OFFSET) { TC_LOG_ERROR("misc", "MoveSplineInitArgs::_checkPathBounds check failed"); diff --git a/src/server/game/Scripting/ScriptReloadMgr.cpp b/src/server/game/Scripting/ScriptReloadMgr.cpp index 321af22be02..b2f20bff184 100644 --- a/src/server/game/Scripting/ScriptReloadMgr.cpp +++ b/src/server/game/Scripting/ScriptReloadMgr.cpp @@ -986,7 +986,7 @@ class HotSwapScriptReloadMgr final // the module which prevents it from unloading. // The module will be unloaded once all scripts provided from the module // are destroyed. - if (!ref->second.first.unique()) + if (ref->second.first.use_count() != 1) { TC_LOG_INFO("scripts.hotswap", "Script module %s is still used by %lu spell, aura or instance scripts. " @@ -1569,7 +1569,7 @@ void SourceUpdateListener::handleFileAction(efsw::WatchID watchid, std::string c return; } - auto const path = fs::absolute( + fs::path path = fs::absolute( filename, dir); @@ -1578,7 +1578,7 @@ void SourceUpdateListener::handleFileAction(efsw::WatchID watchid, std::string c return; /// Thread safe part - sScriptReloadMgr->QueueMessage([=](HotSwapScriptReloadMgr* reloader) + sScriptReloadMgr->QueueMessage([=, this, path = std::move(path)](HotSwapScriptReloadMgr* reloader) { TC_LOG_TRACE("scripts.hotswap", "Detected source change on module \"%s\", " "queued for recompilation...", script_module_name_.c_str()); diff --git a/src/server/game/Server/Packets/MailPackets.cpp b/src/server/game/Server/Packets/MailPackets.cpp index 47db7120e76..5e0c745e333 100644 --- a/src/server/game/Server/Packets/MailPackets.cpp +++ b/src/server/game/Server/Packets/MailPackets.cpp @@ -16,6 +16,7 @@ */ #include "MailPackets.h" +#include "GameTime.h" #include "Item.h" #include "Mail.h" #include "Player.h" @@ -87,7 +88,7 @@ WorldPackets::Mail::MailListEntry::MailListEntry(::Mail const* mail, ::Player* p StationeryID = mail->stationery; SentMoney = mail->money; Flags = mail->checked; - DaysLeft = float(mail->expire_time - time(nullptr)) / DAY; + DaysLeft = float(mail->expire_time - GameTime::GetGameTime()) / float(DAY); MailTemplateID = mail->mailTemplateId; Subject = mail->subject; Body = mail->body; diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index 0d7f351389a..eb6ffc3012b 100644 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -3712,8 +3712,7 @@ void AuraEffect::HandleAuraModIncreaseEnergy(AuraApplication const* aurApp, uint return; Unit* target = aurApp->GetTarget(); - Powers powerType = Powers(GetMiscValue()); - UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType); + UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + GetMiscValue()); target->HandleStatFlatModifier(unitMod, TOTAL_VALUE, float(GetAmount()), apply); } @@ -3725,7 +3724,7 @@ void AuraEffect::HandleAuraModIncreaseEnergyPercent(AuraApplication const* aurAp Unit* target = aurApp->GetTarget(); Powers powerType = Powers(GetMiscValue()); - UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType); + UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + GetMiscValue()); // Save old powers for further calculation int32 oldPower = int32(target->GetPower(powerType)); diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index db9b38b5288..29bb4cec9f1 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -653,7 +653,7 @@ void Spell::EffectSchoolDMG() float average = (minTotal + maxTotal) / 2; // Add main hand dps * effect[2] amount int32 count = unitCaster->CalculateSpellDamage(m_spellInfo->GetEffect(EFFECT_2)); - damage += count * int32(average * IN_MILLISECONDS) / unitCaster->GetAttackTime(BASE_ATTACK); + damage += count * int32(average * float(IN_MILLISECONDS)) / unitCaster->GetAttackTime(BASE_ATTACK); break; } // Shield of Righteousness diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp index 56d8c741cdd..38347a1bae5 100644 --- a/src/server/game/Spells/SpellInfo.cpp +++ b/src/server/game/Spells/SpellInfo.cpp @@ -3214,7 +3214,7 @@ int32 SpellInfo::CalcPowerCost(WorldObject const* caster, SpellSchoolMask school } SpellSchools school = GetFirstSchoolInMask(schoolMask); // Flat mod from caster auras by spell school - powerCost += unitCaster->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER + school); + powerCost += unitCaster->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER + AsUnderlyingType(school)); // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost) if (HasAttribute(SPELL_ATTR4_SPELL_VS_EXTEND_COST)) @@ -3244,7 +3244,7 @@ int32 SpellInfo::CalcPowerCost(WorldObject const* caster, SpellSchoolMask school } // PCT mod from user auras by school - powerCost = int32(powerCost * (1.0f + unitCaster->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER + school))); + powerCost = int32(powerCost * (1.0f + unitCaster->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER + AsUnderlyingType(school)))); if (powerCost < 0) powerCost = 0; return powerCost; diff --git a/src/server/game/Tickets/TicketMgr.cpp b/src/server/game/Tickets/TicketMgr.cpp index e6ad0dce98c..9d6ce882431 100644 --- a/src/server/game/Tickets/TicketMgr.cpp +++ b/src/server/game/Tickets/TicketMgr.cpp @@ -30,7 +30,7 @@ #include "WorldPacket.h" #include "WorldSession.h" -inline float GetAge(uint64 t) { return float(GameTime::GetGameTime() - t) / DAY; } +inline float GetAge(uint64 t) { return float(GameTime::GetGameTime() - t) / float(DAY); } /////////////////////////////////////////////////////////////////////////////////////////////////// // GM ticket diff --git a/src/server/scripts/Commands/cs_rbac.cpp b/src/server/scripts/Commands/cs_rbac.cpp index 622b625ee3c..9976fbd9bf7 100644 --- a/src/server/scripts/Commands/cs_rbac.cpp +++ b/src/server/scripts/Commands/cs_rbac.cpp @@ -34,6 +34,7 @@ EndScriptData */ struct RBACCommandData { + RBACCommandData(rbac::RBACData* rbac_, bool needDelete_) : rbac(rbac_), needDelete(needDelete_) { } RBACCommandData(RBACCommandData const&) = delete; ~RBACCommandData() { diff --git a/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp b/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp index d87d2aa17dc..b6c3e849f4b 100644 --- a/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp +++ b/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp @@ -472,7 +472,7 @@ struct npc_eye_of_acherus : public ScriptedAI break; case EVENT_LAUNCH_TOWARDS_DESTINATION: { - std::function initializer = [=](Movement::MoveSplineInit& init) + std::function initializer = [=, me = me](Movement::MoveSplineInit& init) { Movement::PointsArray path(EyeOfAcherusPath, EyeOfAcherusPath + EyeOfAcherusPathSize); init.MovebyPath(path); diff --git a/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp b/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp index 3a5dc9f3e87..8f1116c7c71 100644 --- a/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp +++ b/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp @@ -710,7 +710,7 @@ class boss_gazakroth : public CreatureScript if (firebolt_timer <= diff) { DoCastVictim(SPELL_FIREBOLT, false); - firebolt_timer = 0.7 * IN_MILLISECONDS; + firebolt_timer = 700; } else firebolt_timer -= diff; diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/culling_of_stratholme.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/culling_of_stratholme.cpp index efbdd91ca8f..200ee9d35ca 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/culling_of_stratholme.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/culling_of_stratholme.cpp @@ -306,12 +306,12 @@ class npc_chromie_start : public CreatureScript { InitGossipMenuFor(player, GOSSIP_MENU_INITIAL); if (player->CanBeGameMaster()) // GM instance state override menu - AddGossipItemFor(player, GOSSIP_ICON_INTERACT_1, "[GM] Access instance control panel", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_OPEN_GM_MENU); + AddGossipItemFor(player, GOSSIP_ICON_INTERACT_1, "[GM] Access instance control panel", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_OPEN_GM_MENU)); uint32 state = instance->GetData(DATA_INSTANCE_PROGRESS); if (state < PURGE_STARTING) { - AddGossipItemFor(player, GOSSIP_MENU_INITIAL, GOSSIP_OPTION_EXPLAIN, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_EXPLAIN); + AddGossipItemFor(player, GOSSIP_MENU_INITIAL, GOSSIP_OPTION_EXPLAIN, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_EXPLAIN)); { bool shouldAddSkipGossip = true; Map::PlayerList const& players = instance->instance->GetPlayers(); @@ -329,13 +329,13 @@ class npc_chromie_start : public CreatureScript } } if (shouldAddSkipGossip) - AddGossipItemFor(player, GOSSIP_MENU_INITIAL, GOSSIP_OPTION_SKIP, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_SKIP); + AddGossipItemFor(player, GOSSIP_MENU_INITIAL, GOSSIP_OPTION_SKIP, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_SKIP)); } SendGossipMenuFor(player, GOSSIP_TEXT_INITIAL, me->GetGUID()); } else { - AddGossipItemFor(player, GOSSIP_MENU_INITIAL, GOSSIP_OPTION_TELEPORT, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_TELEPORT); + AddGossipItemFor(player, GOSSIP_MENU_INITIAL, GOSSIP_OPTION_TELEPORT, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_TELEPORT)); SendGossipMenuFor(player, GOSSIP_TEXT_TELEPORT, me->GetGUID()); } } @@ -352,12 +352,12 @@ class npc_chromie_start : public CreatureScript { case GOSSIP_OFFSET_EXPLAIN: InitGossipMenuFor(player, GOSSIP_MENU_EXPLAIN_1); - AddGossipItemFor(player, GOSSIP_MENU_EXPLAIN_1, GOSSIP_OPTION_EXPLAIN_1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_EXPLAIN_1); + AddGossipItemFor(player, GOSSIP_MENU_EXPLAIN_1, GOSSIP_OPTION_EXPLAIN_1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_EXPLAIN_1)); SendGossipMenuFor(player, GOSSIP_TEXT_EXPLAIN_1, me->GetGUID()); break; case GOSSIP_OFFSET_SKIP: InitGossipMenuFor(player, GOSSIP_MENU_SKIP_1); - AddGossipItemFor(player, GOSSIP_MENU_SKIP_1, GOSSIP_OPTION_SKIP_1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_SKIP_1); + AddGossipItemFor(player, GOSSIP_MENU_SKIP_1, GOSSIP_OPTION_SKIP_1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_SKIP_1)); SendGossipMenuFor(player, GOSSIP_TEXT_SKIP_1, me->GetGUID()); break; case GOSSIP_OFFSET_SKIP_1: @@ -369,7 +369,7 @@ class npc_chromie_start : public CreatureScript break; case GOSSIP_OFFSET_EXPLAIN_1: InitGossipMenuFor(player, GOSSIP_MENU_EXPLAIN_2); - AddGossipItemFor(player, GOSSIP_MENU_EXPLAIN_2, GOSSIP_OPTION_EXPLAIN_2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_EXPLAIN_2); + AddGossipItemFor(player, GOSSIP_MENU_EXPLAIN_2, GOSSIP_OPTION_EXPLAIN_2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_EXPLAIN_2)); SendGossipMenuFor(player, GOSSIP_TEXT_EXPLAIN_2, me->GetGUID()); break; case GOSSIP_OFFSET_EXPLAIN_2: @@ -379,16 +379,16 @@ class npc_chromie_start : public CreatureScript me->CastSpell(player, SPELL_SUMMON_ARCANE_DISRUPTOR); break; case GOSSIP_OFFSET_OPEN_GM_MENU: - AddGossipItemFor(player, GOSSIP_ICON_INTERACT_1, "Teleport all players to Arthas", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_GM_INITIAL); + AddGossipItemFor(player, GOSSIP_ICON_INTERACT_1, "Teleport all players to Arthas", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_GM_INITIAL)); for (uint32 state = 1; state <= COMPLETE; state = state << 1) { if (GetStableStateFor(COSProgressStates(state)) == state) - AddGossipItemFor(player, GOSSIP_ICON_INTERACT_1, Trinity::StringFormat("Set instance progress to 0x%05X", state).c_str(), GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_GM_INITIAL + state); + AddGossipItemFor(player, GOSSIP_ICON_INTERACT_1, Trinity::StringFormat("Set instance progress to 0x%05X", state), GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_GM_INITIAL) + state); } for (uint32 state = 1; state <= COMPLETE; state = state << 1) { if (GetStableStateFor(COSProgressStates(state)) != state) - AddGossipItemFor(player, GOSSIP_ICON_INTERACT_1, Trinity::StringFormat("Force state to 0x%05X (UNSTABLE)", state).c_str(), GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_GM_INITIAL + state); + AddGossipItemFor(player, GOSSIP_ICON_INTERACT_1, Trinity::StringFormat("Force state to 0x%05X (UNSTABLE)", state), GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_GM_INITIAL) + state); } SendGossipMenuFor(player, GOSSIP_TEXT_SKIP_1, me->GetGUID()); break; @@ -404,7 +404,7 @@ class npc_chromie_start : public CreatureScript if (!player->CanBeGameMaster()) break; if (InstanceScript* instance = me->GetInstanceScript()) - instance->SetData(DATA_GM_OVERRIDE, action - GOSSIP_ACTION_INFO_DEF - GOSSIP_OFFSET_GM_INITIAL); + instance->SetData(DATA_GM_OVERRIDE, action - GOSSIP_ACTION_INFO_DEF - AsUnderlyingType(GOSSIP_OFFSET_GM_INITIAL)); break; } return false; @@ -514,7 +514,7 @@ class npc_chromie_middle : public CreatureScript player->PrepareQuestMenu(me->GetGUID()); if (Instance->GetData(DATA_INSTANCE_PROGRESS) == CRATES_DONE) - AddGossipItemFor(player, GOSSIP_MENU_STEP1, GOSSIP_OPTION_STEP1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_STEP1); + AddGossipItemFor(player, GOSSIP_MENU_STEP1, GOSSIP_OPTION_STEP1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_STEP1)); SendGossipMenuFor(player, GOSSIP_TEXT_STEP1, me->GetGUID()); return true; } @@ -527,12 +527,12 @@ class npc_chromie_middle : public CreatureScript { case GOSSIP_OFFSET_STEP1: InitGossipMenuFor(player, GOSSIP_MENU_STEP2); - AddGossipItemFor(player, GOSSIP_MENU_STEP2, GOSSIP_OPTION_STEP2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_STEP2); + AddGossipItemFor(player, GOSSIP_MENU_STEP2, GOSSIP_OPTION_STEP2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_STEP2)); SendGossipMenuFor(player, GOSSIP_TEXT_STEP2, me->GetGUID()); break; case GOSSIP_OFFSET_STEP2: InitGossipMenuFor(player, GOSSIP_MENU_STEP3); - AddGossipItemFor(player, GOSSIP_MENU_STEP3, GOSSIP_OPTION_STEP3, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + GOSSIP_OFFSET_STEP3); + AddGossipItemFor(player, GOSSIP_MENU_STEP3, GOSSIP_OPTION_STEP3, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + AsUnderlyingType(GOSSIP_OFFSET_STEP3)); SendGossipMenuFor(player, GOSSIP_TEXT_STEP3, me->GetGUID()); break; case GOSSIP_OFFSET_STEP3: diff --git a/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_twinemperors.cpp b/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_twinemperors.cpp index e13337d64dc..9c7fc4753d2 100644 --- a/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_twinemperors.cpp +++ b/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_twinemperors.cpp @@ -60,12 +60,13 @@ enum Sound enum Misc { - PULL_RANGE = 50, ABUSE_BUG_RANGE = 20, VEKLOR_DIST = 20, // VL will not come to melee when attacking TELEPORTTIME = 30000 }; +static constexpr float PULL_RANGE = 50.0f; + struct boss_twinemperorsAI : public BossAI { boss_twinemperorsAI(Creature* creature): BossAI(creature, DATA_TWIN_EMPERORS) diff --git a/src/server/scripts/Kalimdor/zone_bloodmyst_isle.cpp b/src/server/scripts/Kalimdor/zone_bloodmyst_isle.cpp index ca4ae2107d9..7cf2891403e 100644 --- a/src/server/scripts/Kalimdor/zone_bloodmyst_isle.cpp +++ b/src/server/scripts/Kalimdor/zone_bloodmyst_isle.cpp @@ -436,12 +436,12 @@ class npc_demolitionist_legoso : public CreatureScript break; case PHASE_PLANT_FIRST_STAND: // plant first explosives stage 1 stand me->SetStandState(UNIT_STAND_STATE_STAND); - _moveTimer = 0.5* IN_MILLISECONDS; + _moveTimer = 0.5* AsUnderlyingType(IN_MILLISECONDS); _phase = PHASE_PLANT_FIRST_WORK; break; case PHASE_PLANT_FIRST_WORK: // plant first explosives stage 2 work Talk(SAY_LEGOSO_4); - _moveTimer = 17.5 * IN_MILLISECONDS; + _moveTimer = 17.5 * AsUnderlyingType(IN_MILLISECONDS); _phase = PHASE_PLANT_FIRST_FINISH; break; case PHASE_PLANT_FIRST_FINISH: // plant first explosives finish @@ -455,7 +455,7 @@ class npc_demolitionist_legoso : public CreatureScript // force runoff movement so he will not screw up next waypoint me->GetMotionMaster()->MovePoint(WP_EXPLOSIVES_FIRST_RUNOFF, -1955.6f, -10669.8f, 110.65f, false); Talk(SAY_LEGOSO_5); - _moveTimer = 1.5 * IN_MILLISECONDS; + _moveTimer = 1.5 * AsUnderlyingType(IN_MILLISECONDS); _phase = PHASE_CONTINUE; break; case PHASE_PLANT_FIRST_TIMER_1: // first explosives detonate timer 1 @@ -661,7 +661,7 @@ class npc_demolitionist_legoso : public CreatureScript SetEscortPaused(true); me->SetFacingToObject(player); Talk(SAY_LEGOSO_1); - _moveTimer = 2.5 * IN_MILLISECONDS; + _moveTimer = 2.5 * AsUnderlyingType(IN_MILLISECONDS); _phase = PHASE_CONTINUE; break; case WP_EXPLOSIVES_FIRST_POINT: @@ -681,7 +681,7 @@ class npc_demolitionist_legoso : public CreatureScript break; case WP_DEBUG_1: SetEscortPaused(true); - _moveTimer = 0.5 * IN_MILLISECONDS; + _moveTimer = 0.5 * AsUnderlyingType(IN_MILLISECONDS); _phase = PHASE_WP_26; break; case WP_SIRONAS_HILL: @@ -708,12 +708,12 @@ class npc_demolitionist_legoso : public CreatureScript } case WP_EXPLOSIVES_SECOND_BATTLEROAR: SetEscortPaused(true); - _moveTimer = 0.2 * IN_MILLISECONDS; + _moveTimer = 0.2 * AsUnderlyingType(IN_MILLISECONDS); _phase = PHASE_MEET_SIRONAS_ROAR; break; case WP_EXPLOSIVES_SECOND_PLANT: SetEscortPaused(true); - _moveTimer = 0.5 * IN_MILLISECONDS; + _moveTimer = 0.5 * AsUnderlyingType(IN_MILLISECONDS); _phase = PHASE_PLANT_SECOND_KNEEL; break; case WP_EXPLOSIVES_SECOND_DETONATE: diff --git a/src/server/scripts/Kalimdor/zone_silithus.cpp b/src/server/scripts/Kalimdor/zone_silithus.cpp index cc96f07496a..49b25a27040 100644 --- a/src/server/scripts/Kalimdor/zone_silithus.cpp +++ b/src/server/scripts/Kalimdor/zone_silithus.cpp @@ -879,7 +879,7 @@ class npc_anachronos_quest_trigger : public CreatureScript Player* groupMember = nullptr; uint8 GroupMemberCount = 0; - uint8 DeadMemberCount = 0; + //uint8 DeadMemberCount = 0; uint8 FailedMemberCount = 0; Group::MemberSlotList const& members = EventGroup->GetMemberSlots(); @@ -896,8 +896,8 @@ class npc_anachronos_quest_trigger : public CreatureScript } ++GroupMemberCount; - if (groupMember->isDead()) - ++DeadMemberCount; + //if (groupMember->isDead()) + // ++DeadMemberCount; } if (GroupMemberCount == FailedMemberCount || !player->IsWithinDistInMap(me, EVENT_AREA_RADIUS)) diff --git a/src/server/scripts/Northrend/Naxxramas/boss_maexxna.cpp b/src/server/scripts/Northrend/Naxxramas/boss_maexxna.cpp index 3ee434e343e..a0824886d4a 100644 --- a/src/server/scripts/Northrend/Naxxramas/boss_maexxna.cpp +++ b/src/server/scripts/Northrend/Naxxramas/boss_maexxna.cpp @@ -198,7 +198,7 @@ struct npc_webwrap : public NullCreatureAI victimGUID = guid; if (Unit* victim = ObjectAccessor::GetUnit(*me, victimGUID)) { - visibleTimer = (me->GetDistance2d(victim)/WEB_WRAP_MOVE_SPEED + 0.5f) * IN_MILLISECONDS; + visibleTimer = (me->GetDistance2d(victim) / WEB_WRAP_MOVE_SPEED + 0.5f) * AsUnderlyingType(IN_MILLISECONDS); victim->CastSpell(victim, SPELL_WEB_WRAP, me->GetGUID()); } } diff --git a/src/server/scripts/Northrend/Ulduar/HallsOfLightning/boss_ionar.cpp b/src/server/scripts/Northrend/Ulduar/HallsOfLightning/boss_ionar.cpp index b68d64307a2..fef51b6481f 100644 --- a/src/server/scripts/Northrend/Ulduar/HallsOfLightning/boss_ionar.cpp +++ b/src/server/scripts/Northrend/Ulduar/HallsOfLightning/boss_ionar.cpp @@ -57,10 +57,11 @@ enum Creatures enum Misc { DATA_MAX_SPARKS = 5, - DATA_MAX_SPARK_DISTANCE = 90, // Distance to boss - prevent runs through the whole instance DATA_POINT_CALLBACK = 0 }; +static constexpr float DATA_MAX_SPARK_DISTANCE = 90; // Distance to boss - prevent runs through the whole instance + /*###### ## Boss Ionar ######*/ diff --git a/src/server/scripts/Spells/spell_pet.cpp b/src/server/scripts/Spells/spell_pet.cpp index 068ee909857..201903d1a7d 100644 --- a/src/server/scripts/Spells/spell_pet.cpp +++ b/src/server/scripts/Spells/spell_pet.cpp @@ -306,8 +306,8 @@ class spell_warl_pet_scaling_01 : public SpellScriptLoader if (Unit* owner = pet->ToPet()->GetOwner()) { - int32 fire = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_FIRE); - int32 shadow = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_SHADOW); + int32 fire = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_FIRE)) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + AsUnderlyingType(SPELL_SCHOOL_FIRE)); + int32 shadow = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_SHADOW)) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + AsUnderlyingType(SPELL_SCHOOL_SHADOW)); int32 maximum = (fire > shadow) ? fire : shadow; if (maximum < 0) maximum = 0; @@ -334,8 +334,8 @@ class spell_warl_pet_scaling_01 : public SpellScriptLoader if (Unit* owner = pet->ToPet()->GetOwner()) { //the damage bonus used for pets is either fire or shadow damage, whatever is higher - int32 fire = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_FIRE); - int32 shadow = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_SHADOW); + int32 fire = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_FIRE)) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + AsUnderlyingType(SPELL_SCHOOL_FIRE)); + int32 shadow = owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_SHADOW)) - owner->GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + AsUnderlyingType(SPELL_SCHOOL_SHADOW)); int32 maximum = (fire > shadow) ? fire : shadow; float bonusDamage = 0.0f; diff --git a/src/server/scripts/Spells/spell_warlock.cpp b/src/server/scripts/Spells/spell_warlock.cpp index a55e4ecb42a..8e05a5ecdaa 100644 --- a/src/server/scripts/Spells/spell_warlock.cpp +++ b/src/server/scripts/Spells/spell_warlock.cpp @@ -727,7 +727,7 @@ class spell_warl_life_tap : public SpellScript int32 base = GetEffectInfo(effIndex).CalcValue(); float penalty = caster->CalculateSpellpowerCoefficientLevelPenalty(GetSpellInfo()); - float fmana = (float)base + caster->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW) * 0.5f * penalty; + float fmana = (float)base + caster->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + AsUnderlyingType(SPELL_SCHOOL_SHADOW)) * 0.5f * penalty; // Improved Life Tap mod if (AuraEffect const* aurEff = caster->GetDummyAuraEffect(SPELLFAMILY_WARLOCK, WARLOCK_ICON_ID_IMPROVED_LIFE_TAP, 0)) diff --git a/src/server/scripts/World/npcs_special.cpp b/src/server/scripts/World/npcs_special.cpp index 069360bc77f..36b93e66e2e 100644 --- a/src/server/scripts/World/npcs_special.cpp +++ b/src/server/scripts/World/npcs_special.cpp @@ -2085,7 +2085,7 @@ class npc_train_wrecker : public CreatureScript { me->SetFacingTo(target->GetOrientation()); me->HandleEmoteCommand(EMOTE_ONESHOT_ATTACK1H); - _timer = 1.5 * IN_MILLISECONDS; + _timer = 1.5 * AsUnderlyingType(IN_MILLISECONDS); _nextAction = EVENT_DO_WRECK; } else diff --git a/src/server/shared/DataStores/DBCStorageIterator.h b/src/server/shared/DataStores/DBCStorageIterator.h index 7f27be9b459..d4ac54bc64c 100644 --- a/src/server/shared/DataStores/DBCStorageIterator.h +++ b/src/server/shared/DataStores/DBCStorageIterator.h @@ -21,49 +21,55 @@ #include "Define.h" #include -template -class DBCStorageIterator : public std::iterator +template +class DBCStorageIterator { - public: - DBCStorageIterator() : _index(nullptr), _pos(0), _end(0) { } - DBCStorageIterator(T** index, uint32 size, uint32 pos = 0) : _index(index), _pos(pos), _end(size) +public: + using iterator_category = std::forward_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = T*; + using reference = T&; + + DBCStorageIterator() : _index(nullptr), _pos(0), _end(0) { } + DBCStorageIterator(T const* const* index, uint32 size, uint32 pos = 0) : _index(index), _pos(pos), _end(size) + { + if (_pos < _end) { - if (_pos < _end) - { - while (_pos < _end && !_index[_pos]) - ++_pos; - } + while (_pos < _end && !_index[_pos]) + ++_pos; } + } - T const* operator->() { return _index[_pos]; } - T const* operator*() { return _index[_pos]; } + T const* operator->() const { return _index[_pos]; } + T const* operator*() const { return _index[_pos]; } - bool operator==(DBCStorageIterator const& right) const { /*ASSERT(_index == right._index, "Iterator belongs to a different container")*/ return _pos == right._pos; } - bool operator!=(DBCStorageIterator const& right) const { return !(*this == right); } + bool operator==(DBCStorageIterator const& right) const { /*ASSERT(_index == right._index, "Iterator belongs to a different container")*/ return _pos == right._pos; } + bool operator!=(DBCStorageIterator const& right) const { return !(*this == right); } - DBCStorageIterator& operator++() + DBCStorageIterator& operator++() + { + if (_pos < _end) { - if (_pos < _end) - { - do - ++_pos; - while (_pos < _end && !_index[_pos]); - } - - return *this; + do + ++_pos; + while (_pos < _end && !_index[_pos]); } - DBCStorageIterator operator++(int) - { - DBCStorageIterator tmp = *this; - ++*this; - return tmp; - } + return *this; + } + + DBCStorageIterator operator++(int) + { + DBCStorageIterator tmp = *this; + ++*this; + return tmp; + } - private: - T** _index; - uint32 _pos; - uint32 _end; +private: + T const* const* _index; + uint32 _pos; + uint32 _end; }; #endif // DBCStorageIterator_h__ From 203bc3afa0d234177959ebdc896a401bdcf2da4c Mon Sep 17 00:00:00 2001 From: Shauren Date: Tue, 20 Dec 2022 01:03:07 +0100 Subject: [PATCH 02/17] Core/Threading: Modernize ProducerConsumerQueue a bit to fix GCC build Closes #28607 (cherry picked from commit 85d5f4bc0683d99cfaab244a8f0355b463f93267) --- src/common/Threading/ProducerConsumerQueue.h | 36 +++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/common/Threading/ProducerConsumerQueue.h b/src/common/Threading/ProducerConsumerQueue.h index 778f434e9de..04c2017c1f7 100644 --- a/src/common/Threading/ProducerConsumerQueue.h +++ b/src/common/Threading/ProducerConsumerQueue.h @@ -15,8 +15,8 @@ * with this program. If not, see . */ -#ifndef _PCQ_H -#define _PCQ_H +#ifndef TRINITY_PRODUCER_CONSUMER_QUEUE_H +#define TRINITY_PRODUCER_CONSUMER_QUEUE_H #include #include @@ -28,16 +28,24 @@ template class ProducerConsumerQueue { private: - std::mutex _queueLock; + mutable std::mutex _queueLock; std::queue _queue; std::condition_variable _condition; std::atomic _shutdown; public: - ProducerConsumerQueue() : _shutdown(false) { } + ProducerConsumerQueue() : _shutdown(false) { } - void Push(const T& value) + void Push(T const& value) + { + std::lock_guard lock(_queueLock); + _queue.push(value); + + _condition.notify_one(); + } + + void Push(T&& value) { std::lock_guard lock(_queueLock); _queue.push(std::move(value)); @@ -45,7 +53,7 @@ class ProducerConsumerQueue _condition.notify_one(); } - bool Empty() + bool Empty() const { std::lock_guard lock(_queueLock); @@ -54,6 +62,8 @@ class ProducerConsumerQueue size_t Size() const { + std::lock_guard lock(_queueLock); + return _queue.size(); } @@ -64,7 +74,7 @@ class ProducerConsumerQueue if (_queue.empty() || _shutdown) return false; - value = _queue.front(); + value = std::move(_queue.front()); _queue.pop(); @@ -96,7 +106,8 @@ class ProducerConsumerQueue { T& value = _queue.front(); - DeleteQueuedObject(value); + if constexpr (std::is_pointer_v) + delete value; _queue.pop(); } @@ -105,13 +116,6 @@ class ProducerConsumerQueue _condition.notify_all(); } - -private: - template - typename std::enable_if::value>::type DeleteQueuedObject(E& obj) { delete obj; } - - template - typename std::enable_if::value>::type DeleteQueuedObject(E const& /*packet*/) { } }; -#endif +#endif // TRINITY_PRODUCER_CONSUMER_QUEUE_H From 85fc9d93b5e89d09b61a271e05e7de8a3dca2359 Mon Sep 17 00:00:00 2001 From: Shauren Date: Tue, 31 Jan 2023 18:17:34 +0100 Subject: [PATCH 03/17] Dep: Upgrade utfcpp to 3.2.3 (cherry picked from commit 74dc88eb54751d5cd3eb8c379cdf9b2bdbbaa1ec) --- dep/PackageList.txt | 4 +- dep/utf8cpp/utf8/checked.h | 86 +++++++++++++---------------- dep/utf8cpp/utf8/core.h | 92 +++++++++++++++++++++++++------ dep/utf8cpp/utf8/cpp11.h | 103 +++++++++++++++++++++++++++++++++++ dep/utf8cpp/utf8/cpp17.h | 103 +++++++++++++++++++++++++++++++++++ dep/utf8cpp/utf8/unchecked.h | 93 ++++++++++++++++++++----------- 6 files changed, 383 insertions(+), 98 deletions(-) create mode 100644 dep/utf8cpp/utf8/cpp11.h create mode 100644 dep/utf8cpp/utf8/cpp17.h diff --git a/dep/PackageList.txt b/dep/PackageList.txt index e50d50ca930..e4b2ece30b2 100644 --- a/dep/PackageList.txt +++ b/dep/PackageList.txt @@ -49,8 +49,8 @@ SFMT (SIMD-oriented Fast Mersenne Twister) Version: 73bcba2e483640b8d50c1275514326dd4c1b0ca4 utf8-cpp (UTF-8 with C++ in a Portable Way) - http://utfcpp.sourceforge.net/ - Version: 2.3.4 + https://github.com/nemtrif/utfcpp + Version: 3.2.3 zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library) http://www.zlib.net/ diff --git a/dep/utf8cpp/utf8/checked.h b/dep/utf8cpp/utf8/checked.h index 13311551381..512dcc2fbac 100644 --- a/dep/utf8cpp/utf8/checked.h +++ b/dep/utf8cpp/utf8/checked.h @@ -1,4 +1,4 @@ -// Copyright 2006 Nemanja Trifunovic +// Copyright 2006-2016 Nemanja Trifunovic /* Permission is hereby granted, free of charge, to any person or organization @@ -41,8 +41,8 @@ namespace utf8 class invalid_code_point : public exception { uint32_t cp; public: - invalid_code_point(uint32_t cp) : cp(cp) {} - virtual const char* what() const throw() { return "Invalid code point"; } + invalid_code_point(uint32_t codepoint) : cp(codepoint) {} + virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Invalid code point"; } uint32_t code_point() const {return cp;} }; @@ -50,7 +50,8 @@ namespace utf8 uint8_t u8; public: invalid_utf8 (uint8_t u) : u8(u) {} - virtual const char* what() const throw() { return "Invalid UTF-8"; } + invalid_utf8 (char c) : u8(static_cast(c)) {} + virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Invalid UTF-8"; } uint8_t utf8_octet() const {return u8;} }; @@ -58,13 +59,13 @@ namespace utf8 uint16_t u16; public: invalid_utf16 (uint16_t u) : u16(u) {} - virtual const char* what() const throw() { return "Invalid UTF-16"; } + virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Invalid UTF-16"; } uint16_t utf16_word() const {return u16;} }; class not_enough_room : public exception { public: - virtual const char* what() const throw() { return "Not enough space"; } + virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Not enough space"; } }; /// The library API - functions intended to be called by the users @@ -75,24 +76,7 @@ namespace utf8 if (!utf8::internal::is_code_point_valid(cp)) throw invalid_code_point(cp); - if (cp < 0x80) // one octet - *(result++) = static_cast(cp); - else if (cp < 0x800) { // two octets - *(result++) = static_cast((cp >> 6) | 0xc0); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else if (cp < 0x10000) { // three octets - *(result++) = static_cast((cp >> 12) | 0xe0); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else { // four octets - *(result++) = static_cast((cp >> 18) | 0xf0); - *(result++) = static_cast(((cp >> 12) & 0x3f) | 0x80); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - return result; + return internal::append(cp, result); } template @@ -107,7 +91,9 @@ namespace utf8 *out++ = *it; break; case internal::NOT_ENOUGH_ROOM: - throw not_enough_room(); + out = utf8::append (replacement, out); + start = end; + break; case internal::INVALID_LEAD: out = utf8::append (replacement, out); ++start; @@ -146,7 +132,7 @@ namespace utf8 case internal::INVALID_LEAD : case internal::INCOMPLETE_SEQUENCE : case internal::OVERLONG_SEQUENCE : - throw invalid_utf8(*it); + throw invalid_utf8(static_cast(*it)); case internal::INVALID_CODE_POINT : throw invalid_code_point(cp); } @@ -174,23 +160,19 @@ namespace utf8 return utf8::peek_next(it, end); } - /// Deprecated in versions that include "prior" - template - uint32_t previous(octet_iterator& it, octet_iterator pass_start) - { - octet_iterator end = it; - while (utf8::internal::is_trail(*(--it))) - if (it == pass_start) - throw invalid_utf8(*it); // error - no lead byte in the sequence - octet_iterator temp = it; - return utf8::next(temp, end); - } - template void advance (octet_iterator& it, distance_type n, octet_iterator end) { - for (distance_type i = 0; i < n; ++i) - utf8::next(it, end); + const distance_type zero(0); + if (n < zero) { + // backward + for (distance_type i = n; i < zero; ++i) + utf8::prior(it, end); + } else { + // forward + for (distance_type i = zero; i < n; ++i) + utf8::next(it, end); + } } template @@ -233,7 +215,7 @@ namespace utf8 template u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result) { - while (start != end) { + while (start < end) { uint32_t cp = utf8::next(start, end); if (cp > 0xffff) { //make a surrogate pair *result++ = static_cast((cp >> 10) + internal::LEAD_OFFSET); @@ -257,7 +239,7 @@ namespace utf8 template u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result) { - while (start != end) + while (start < end) (*result++) = utf8::next(start, end); return result; @@ -265,16 +247,21 @@ namespace utf8 // The iterator class template - class iterator : public std::iterator { + class iterator { octet_iterator it; octet_iterator range_start; octet_iterator range_end; public: + typedef uint32_t value_type; + typedef uint32_t* pointer; + typedef uint32_t& reference; + typedef std::ptrdiff_t difference_type; + typedef std::bidirectional_iterator_tag iterator_category; iterator () {} explicit iterator (const octet_iterator& octet_it, - const octet_iterator& range_start, - const octet_iterator& range_end) : - it(octet_it), range_start(range_start), range_end(range_end) + const octet_iterator& rangestart, + const octet_iterator& rangeend) : + it(octet_it), range_start(rangestart), range_end(rangeend) { if (it < range_start || it > range_end) throw std::out_of_range("Invalid utf-8 iterator position"); @@ -322,6 +309,11 @@ namespace utf8 } // namespace utf8 -#endif //header guard +#if UTF_CPP_CPLUSPLUS >= 201703L // C++ 17 or later +#include "cpp17.h" +#elif UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later +#include "cpp11.h" +#endif // C++ 11 or later +#endif //header guard diff --git a/dep/utf8cpp/utf8/core.h b/dep/utf8cpp/utf8/core.h index 693d388c078..34371ee31c8 100644 --- a/dep/utf8cpp/utf8/core.h +++ b/dep/utf8cpp/utf8/core.h @@ -30,6 +30,23 @@ DEALINGS IN THE SOFTWARE. #include +// Determine the C++ standard version. +// If the user defines UTF_CPP_CPLUSPLUS, use that. +// Otherwise, trust the unreliable predefined macro __cplusplus + +#if !defined UTF_CPP_CPLUSPLUS + #define UTF_CPP_CPLUSPLUS __cplusplus +#endif + +#if UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later + #define UTF_CPP_OVERRIDE override + #define UTF_CPP_NOEXCEPT noexcept +#else // C++ 98/03 + #define UTF_CPP_OVERRIDE + #define UTF_CPP_NOEXCEPT throw() +#endif // C++ 11 or later + + namespace utf8 { // The typedefs for 8-bit, 16-bit and 32-bit unsigned integers @@ -49,8 +66,8 @@ namespace internal const uint16_t LEAD_SURROGATE_MAX = 0xdbffu; const uint16_t TRAIL_SURROGATE_MIN = 0xdc00u; const uint16_t TRAIL_SURROGATE_MAX = 0xdfffu; - const uint16_t LEAD_OFFSET = LEAD_SURROGATE_MIN - (0x10000 >> 10); - const uint32_t SURROGATE_OFFSET = 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN; + const uint16_t LEAD_OFFSET = 0xd7c0u; // LEAD_SURROGATE_MIN - (0x10000 >> 10) + const uint32_t SURROGATE_OFFSET = 0xfca02400u; // 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN // Maximum valid value for a Unicode code point const uint32_t CODE_POINT_MAX = 0x0010ffffu; @@ -142,7 +159,7 @@ namespace internal if (!utf8::internal::is_trail(*it)) return INCOMPLETE_SEQUENCE; - + return UTF8_OK; } @@ -165,7 +182,7 @@ namespace internal { if (it == end) return NOT_ENOUGH_ROOM; - + code_point = utf8::internal::mask8(*it); UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) @@ -222,6 +239,9 @@ namespace internal template utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point) { + if (it == end) + return NOT_ENOUGH_ROOM; + // Save the original value of it so we can go back in case of failure // Of course, it does not make much sense with i.e. stream iterators octet_iterator original_it = it; @@ -234,7 +254,7 @@ namespace internal // Get trail octets and calculate the code point utf_error err = UTF8_OK; switch (length) { - case 0: + case 0: return INVALID_LEAD; case 1: err = utf8::internal::get_sequence_1(it, end, cp); @@ -277,6 +297,55 @@ namespace internal return utf8::internal::validate_next(it, end, ignored); } + // Internal implementation of both checked and unchecked append() function + // This function will be invoked by the overloads below, as they will know + // the octet_type. + template + octet_iterator append(uint32_t cp, octet_iterator result) { + if (cp < 0x80) // one octet + *(result++) = static_cast(cp); + else if (cp < 0x800) { // two octets + *(result++) = static_cast((cp >> 6) | 0xc0); + *(result++) = static_cast((cp & 0x3f) | 0x80); + } + else if (cp < 0x10000) { // three octets + *(result++) = static_cast((cp >> 12) | 0xe0); + *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); + *(result++) = static_cast((cp & 0x3f) | 0x80); + } + else { // four octets + *(result++) = static_cast((cp >> 18) | 0xf0); + *(result++) = static_cast(((cp >> 12) & 0x3f)| 0x80); + *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); + *(result++) = static_cast((cp & 0x3f) | 0x80); + } + return result; + } + + // One of the following overloads will be invoked from the API calls + + // A simple (but dangerous) case: the caller appends byte(s) to a char array + inline char* append(uint32_t cp, char* result) { + return append(cp, result); + } + + // Hopefully, most common case: the caller uses back_inserter + // i.e. append(cp, std::back_inserter(str)); + template + std::back_insert_iterator append + (uint32_t cp, std::back_insert_iterator result) { + return append, + typename container_type::value_type>(cp, result); + } + + // The caller uses some other kind of output operator - not covered above + // Note that in this case we are not able to determine octet_type + // so we assume it's uint_8; that can cause a conversion warning if we are wrong. + template + octet_iterator append(uint32_t cp, octet_iterator result) { + return append(cp, result); + } + } // namespace internal /// The library API - functions intended to be called by the users @@ -310,18 +379,7 @@ namespace internal ((it != end) && (utf8::internal::mask8(*it++)) == bom[1]) && ((it != end) && (utf8::internal::mask8(*it)) == bom[2]) ); - } - - //Deprecated in release 2.3 - template - inline bool is_bom (octet_iterator it) - { - return ( - (utf8::internal::mask8(*it++)) == bom[0] && - (utf8::internal::mask8(*it++)) == bom[1] && - (utf8::internal::mask8(*it)) == bom[2] - ); - } + } } // namespace utf8 #endif // header guard diff --git a/dep/utf8cpp/utf8/cpp11.h b/dep/utf8cpp/utf8/cpp11.h new file mode 100644 index 00000000000..2366f12915c --- /dev/null +++ b/dep/utf8cpp/utf8/cpp11.h @@ -0,0 +1,103 @@ +// Copyright 2018 Nemanja Trifunovic + +/* +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +*/ + + +#ifndef UTF8_FOR_CPP_a184c22c_d012_11e8_a8d5_f2801f1b9fd1 +#define UTF8_FOR_CPP_a184c22c_d012_11e8_a8d5_f2801f1b9fd1 + +#include "checked.h" +#include + +namespace utf8 +{ + + inline void append(char32_t cp, std::string& s) + { + append(uint32_t(cp), std::back_inserter(s)); + } + + inline std::string utf16to8(const std::u16string& s) + { + std::string result; + utf16to8(s.begin(), s.end(), std::back_inserter(result)); + return result; + } + + inline std::u16string utf8to16(const std::string& s) + { + std::u16string result; + utf8to16(s.begin(), s.end(), std::back_inserter(result)); + return result; + } + + inline std::string utf32to8(const std::u32string& s) + { + std::string result; + utf32to8(s.begin(), s.end(), std::back_inserter(result)); + return result; + } + + inline std::u32string utf8to32(const std::string& s) + { + std::u32string result; + utf8to32(s.begin(), s.end(), std::back_inserter(result)); + return result; + } + + inline std::size_t find_invalid(const std::string& s) + { + std::string::const_iterator invalid = find_invalid(s.begin(), s.end()); + return (invalid == s.end()) ? std::string::npos : static_cast(invalid - s.begin()); + } + + inline bool is_valid(const std::string& s) + { + return is_valid(s.begin(), s.end()); + } + + inline std::string replace_invalid(const std::string& s, char32_t replacement) + { + std::string result; + replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement); + return result; + } + + inline std::string replace_invalid(const std::string& s) + { + std::string result; + replace_invalid(s.begin(), s.end(), std::back_inserter(result)); + return result; + } + + inline bool starts_with_bom(const std::string& s) + { + return starts_with_bom(s.begin(), s.end()); + } + +} // namespace utf8 + +#endif // header guard + diff --git a/dep/utf8cpp/utf8/cpp17.h b/dep/utf8cpp/utf8/cpp17.h new file mode 100644 index 00000000000..32a77ce3075 --- /dev/null +++ b/dep/utf8cpp/utf8/cpp17.h @@ -0,0 +1,103 @@ +// Copyright 2018 Nemanja Trifunovic + +/* +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +*/ + + +#ifndef UTF8_FOR_CPP_7e906c01_03a3_4daf_b420_ea7ea952b3c9 +#define UTF8_FOR_CPP_7e906c01_03a3_4daf_b420_ea7ea952b3c9 + +#include "checked.h" +#include + +namespace utf8 +{ + + inline void append(char32_t cp, std::string& s) + { + append(uint32_t(cp), std::back_inserter(s)); + } + + inline std::string utf16to8(std::u16string_view s) + { + std::string result; + utf16to8(s.begin(), s.end(), std::back_inserter(result)); + return result; + } + + inline std::u16string utf8to16(std::string_view s) + { + std::u16string result; + utf8to16(s.begin(), s.end(), std::back_inserter(result)); + return result; + } + + inline std::string utf32to8(std::u32string_view s) + { + std::string result; + utf32to8(s.begin(), s.end(), std::back_inserter(result)); + return result; + } + + inline std::u32string utf8to32(std::string_view s) + { + std::u32string result; + utf8to32(s.begin(), s.end(), std::back_inserter(result)); + return result; + } + + inline std::size_t find_invalid(std::string_view s) + { + std::string_view::const_iterator invalid = find_invalid(s.begin(), s.end()); + return (invalid == s.end()) ? std::string_view::npos : static_cast(invalid - s.begin()); + } + + inline bool is_valid(std::string_view s) + { + return is_valid(s.begin(), s.end()); + } + + inline std::string replace_invalid(std::string_view s, char32_t replacement) + { + std::string result; + replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement); + return result; + } + + inline std::string replace_invalid(std::string_view s) + { + std::string result; + replace_invalid(s.begin(), s.end(), std::back_inserter(result)); + return result; + } + + inline bool starts_with_bom(std::string_view s) + { + return starts_with_bom(s.begin(), s.end()); + } + +} // namespace utf8 + +#endif // header guard + diff --git a/dep/utf8cpp/utf8/unchecked.h b/dep/utf8cpp/utf8/unchecked.h index cb2427166b1..8fe83c9ecbc 100644 --- a/dep/utf8cpp/utf8/unchecked.h +++ b/dep/utf8cpp/utf8/unchecked.h @@ -32,29 +32,52 @@ DEALINGS IN THE SOFTWARE. namespace utf8 { - namespace unchecked + namespace unchecked { template octet_iterator append(uint32_t cp, octet_iterator result) { - if (cp < 0x80) // one octet - *(result++) = static_cast(cp); - else if (cp < 0x800) { // two octets - *(result++) = static_cast((cp >> 6) | 0xc0); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else if (cp < 0x10000) { // three octets - *(result++) = static_cast((cp >> 12) | 0xe0); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else { // four octets - *(result++) = static_cast((cp >> 18) | 0xf0); - *(result++) = static_cast(((cp >> 12) & 0x3f)| 0x80); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); + return internal::append(cp, result); + } + + template + output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement) + { + while (start != end) { + octet_iterator sequence_start = start; + internal::utf_error err_code = utf8::internal::validate_next(start, end); + switch (err_code) { + case internal::UTF8_OK : + for (octet_iterator it = sequence_start; it != start; ++it) + *out++ = *it; + break; + case internal::NOT_ENOUGH_ROOM: + out = utf8::unchecked::append (replacement, out); + start = end; + break; + case internal::INVALID_LEAD: + out = utf8::unchecked::append (replacement, out); + ++start; + break; + case internal::INCOMPLETE_SEQUENCE: + case internal::OVERLONG_SEQUENCE: + case internal::INVALID_CODE_POINT: + out = utf8::unchecked::append (replacement, out); + ++start; + // just one replacement mark for the sequence + while (start != end && utf8::internal::is_trail(*start)) + ++start; + break; + } } - return result; + return out; + } + + template + inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out) + { + static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd); + return utf8::unchecked::replace_invalid(start, end, out, replacement_marker); } template @@ -85,13 +108,13 @@ namespace utf8 break; } ++it; - return cp; + return cp; } template uint32_t peek_next(octet_iterator it) { - return utf8::unchecked::next(it); + return utf8::unchecked::next(it); } template @@ -102,18 +125,19 @@ namespace utf8 return utf8::unchecked::next(temp); } - // Deprecated in versions that include prior, but only for the sake of consistency (see utf8::previous) - template - inline uint32_t previous(octet_iterator& it) - { - return utf8::unchecked::prior(it); - } - template void advance (octet_iterator& it, distance_type n) { - for (distance_type i = 0; i < n; ++i) - utf8::unchecked::next(it); + const distance_type zero(0); + if (n < zero) { + // backward + for (distance_type i = n; i < zero; ++i) + utf8::unchecked::prior(it); + } else { + // forward + for (distance_type i = zero; i < n; ++i) + utf8::unchecked::next(it); + } } template @@ -128,7 +152,7 @@ namespace utf8 template octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result) - { + { while (start != end) { uint32_t cp = utf8::internal::mask16(*start++); // Take care of surrogate pairs first @@ -138,7 +162,7 @@ namespace utf8 } result = utf8::unchecked::append(cp, result); } - return result; + return result; } template @@ -176,9 +200,14 @@ namespace utf8 // The iterator class template - class iterator : public std::iterator { + class iterator { octet_iterator it; public: + typedef uint32_t value_type; + typedef uint32_t* pointer; + typedef uint32_t& reference; + typedef std::ptrdiff_t difference_type; + typedef std::bidirectional_iterator_tag iterator_category; iterator () {} explicit iterator (const octet_iterator& octet_it): it(octet_it) {} // the default "big three" are OK From 97c977d0fba75183f58062f124402530a91dac9b Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 1 Jan 2023 00:26:53 +0100 Subject: [PATCH 04/17] Build: Update required compilers to current debian stable and VS 2022 GCC: 10 Clang: 11 MSVC: 2022 (cherry picked from commit 0a1b40241a12b2b2f4549edf0ee263e91236145b) --- .github/workflows/gcc-build.yml | 4 ++-- cmake/compiler/clang/settings.cmake | 2 +- cmake/compiler/gcc/settings.cmake | 2 +- cmake/compiler/msvc/settings.cmake | 13 +++++-------- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/gcc-build.yml b/.github/workflows/gcc-build.yml index 4438a1ae89e..73830ebbd5a 100644 --- a/.github/workflows/gcc-build.yml +++ b/.github/workflows/gcc-build.yml @@ -11,8 +11,8 @@ jobs: - uses: actions/checkout@v2 - name: Dependencies run: | - sudo apt-get update && sudo apt-get install -yq libboost-all-dev g++-8 - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100 --slave /usr/bin/g++ g++ /usr/bin/g++-8 + sudo apt-get update && sudo apt-get install -yq libboost-all-dev g++-10 + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 - name: Setup run: | mkdir bin diff --git a/cmake/compiler/clang/settings.cmake b/cmake/compiler/clang/settings.cmake index 896dd0ef157..02bdc8e2583 100644 --- a/cmake/compiler/clang/settings.cmake +++ b/cmake/compiler/clang/settings.cmake @@ -3,7 +3,7 @@ target_compile_definitions(trinity-compile-option-interface INTERFACE -D_BUILD_DIRECTIVE="$") -set(CLANG_EXPECTED_VERSION 7.0.0) +set(CLANG_EXPECTED_VERSION 11.0.0) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS CLANG_EXPECTED_VERSION) message(FATAL_ERROR "Clang: TrinityCore requires version ${CLANG_EXPECTED_VERSION} to build but found ${CMAKE_CXX_COMPILER_VERSION}") diff --git a/cmake/compiler/gcc/settings.cmake b/cmake/compiler/gcc/settings.cmake index d0f7ebc2f3f..6608190d1bf 100644 --- a/cmake/compiler/gcc/settings.cmake +++ b/cmake/compiler/gcc/settings.cmake @@ -3,7 +3,7 @@ target_compile_definitions(trinity-compile-option-interface INTERFACE -D_BUILD_DIRECTIVE="$") -set(GCC_EXPECTED_VERSION 8.3.0) +set(GCC_EXPECTED_VERSION 10.0.0) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS GCC_EXPECTED_VERSION) message(FATAL_ERROR "GCC: TrinityCore requires version ${GCC_EXPECTED_VERSION} to build but found ${CMAKE_CXX_COMPILER_VERSION}") diff --git a/cmake/compiler/msvc/settings.cmake b/cmake/compiler/msvc/settings.cmake index cdc3f1b6acf..f6947d6eaad 100644 --- a/cmake/compiler/msvc/settings.cmake +++ b/cmake/compiler/msvc/settings.cmake @@ -1,8 +1,8 @@ # set up output paths for executable binaries (.exe-files, and .dll-files on DLL-capable platforms) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(MSVC_EXPECTED_VERSION 19.24) -set(MSVC_EXPECTED_VERSION_STRING "Microsoft Visual Studio 2019 16.4") +set(MSVC_EXPECTED_VERSION 19.30) +set(MSVC_EXPECTED_VERSION_STRING "Microsoft Visual Studio 2022 17") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MSVC_EXPECTED_VERSION) message(FATAL_ERROR "MSVC: TrinityCore requires version ${MSVC_EXPECTED_VERSION} (${MSVC_EXPECTED_VERSION_STRING}) to build but found ${CMAKE_CXX_COMPILER_VERSION}") @@ -88,12 +88,9 @@ endif() # that the program will eventually be linked with a conforming operator new implementation, # and can omit all of these extra null checks from your program. # http://blogs.msdn.com/b/vcblog/archive/2015/08/06/new-in-vs-2015-zc-throwingnew.aspx -if(NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0.23026.0)) - # makes this flag a requirement to build TC at all - target_compile_options(trinity-compile-option-interface - INTERFACE - /Zc:throwingNew) -endif() +target_compile_options(trinity-compile-option-interface + INTERFACE + /Zc:throwingNew) # Define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES - eliminates the warning by changing the strcpy call to strcpy_s, which prevents buffer overruns target_compile_definitions(trinity-compile-option-interface From d0553d499b17b5e20640cea5187934ff0bcbc528 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 1 Jan 2023 00:26:53 +0100 Subject: [PATCH 05/17] Build: Enable C++20 (cherry picked from commit 989f84c5f2db4d1ea75e5b2020be6ef4bf770366) --- cmake/macros/ConfigureBaseTargets.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/macros/ConfigureBaseTargets.cmake b/cmake/macros/ConfigureBaseTargets.cmake index 7710b0e2911..26878eec1ba 100644 --- a/cmake/macros/ConfigureBaseTargets.cmake +++ b/cmake/macros/ConfigureBaseTargets.cmake @@ -12,14 +12,14 @@ add_library(trinity-compile-option-interface INTERFACE) # Use -std=c++11 instead of -std=gnu++11 -set(CXX_EXTENSIONS OFF) +set(CMAKE_CXX_EXTENSIONS OFF) # An interface library to make the target features available to other targets add_library(trinity-feature-interface INTERFACE) target_compile_features(trinity-feature-interface INTERFACE - cxx_std_17) + cxx_std_20) # An interface library to make the warnings level available to other targets # This interface taget is set-up through the platform specific script From 73e7f0fe6d5ea2c75ad452effe9d7b95dd323ea2 Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 5 Jan 2023 12:16:21 +0100 Subject: [PATCH 06/17] Core/Misc: Added a include hack for msvc to use only c++17 bits from it (cherry picked from commit 585900f42d064b9f6adc08015605931163ea79c8) --- src/common/Logging/Log.cpp | 2 +- src/common/Utilities/ByteConverter.h | 5 +++-- src/common/Utilities/Duration.h | 5 +++++ src/common/Utilities/TaskScheduler.h | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/common/Logging/Log.cpp b/src/common/Logging/Log.cpp index c4a00af8c9e..96dadcb82c5 100644 --- a/src/common/Logging/Log.cpp +++ b/src/common/Logging/Log.cpp @@ -20,6 +20,7 @@ #include "AppenderFile.h" #include "Common.h" #include "Config.h" +#include "Duration.h" #include "Errors.h" #include "Logger.h" #include "LogMessage.h" @@ -27,7 +28,6 @@ #include "Strand.h" #include "StringConvert.h" #include "Util.h" -#include #include Log::Log() : AppenderId(0), lowestLogLevel(LOG_LEVEL_FATAL), _ioContext(nullptr), _strand(nullptr) diff --git a/src/common/Utilities/ByteConverter.h b/src/common/Utilities/ByteConverter.h index 59be4adb86b..d9b74b83264 100644 --- a/src/common/Utilities/ByteConverter.h +++ b/src/common/Utilities/ByteConverter.h @@ -23,14 +23,15 @@ */ #include "Define.h" -#include namespace ByteConverter { template inline void convert(char *val) { - std::swap(*val, *(val + T - 1)); + char tmp = *val; + *val = *(val + T - 1); + *(val + T - 1) = tmp; convert(val + 1); } diff --git a/src/common/Utilities/Duration.h b/src/common/Utilities/Duration.h index f506467abda..b4c3f17cb3e 100644 --- a/src/common/Utilities/Duration.h +++ b/src/common/Utilities/Duration.h @@ -18,7 +18,12 @@ #ifndef _DURATION_H_ #define _DURATION_H_ +// HACKS TERRITORY +#if __has_include(<__msvc_chrono.hpp>) +#include <__msvc_chrono.hpp> // skip all the formatting/istream/locale/mutex bloat +#else #include +#endif /// Milliseconds shorthand typedef. typedef std::chrono::milliseconds Milliseconds; diff --git a/src/common/Utilities/TaskScheduler.h b/src/common/Utilities/TaskScheduler.h index 6bd50cf5b6d..4d6761780be 100644 --- a/src/common/Utilities/TaskScheduler.h +++ b/src/common/Utilities/TaskScheduler.h @@ -22,7 +22,6 @@ #include "Optional.h" #include "Random.h" #include -#include #include #include #include From b8dc87a0e03123e0b37d1940a20424d703053ffe Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 5 Jan 2023 16:59:16 +0100 Subject: [PATCH 07/17] Core/Spells: Hide spell effect immunity info implementation details (cherry picked from commit dcb589946bf55fee1c1a78d99f4ee721ac799ef8) --- .../game/Spells/Auras/SpellAuraEffects.cpp | 14 +-- src/server/game/Spells/SpellInfo.cpp | 102 ++++++++++++++---- src/server/game/Spells/SpellInfo.h | 36 +++---- 3 files changed, 103 insertions(+), 49 deletions(-) diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index eb6ffc3012b..f420d1debd3 100644 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -3118,7 +3118,7 @@ void AuraEffect::HandleModMechanicImmunityMask(AuraApplication const* aurApp, ui return; Unit* target = aurApp->GetTarget(); - m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetEffIndex(), apply); + m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetSpellEffectInfo(), apply); } void AuraEffect::HandleModMechanicImmunity(AuraApplication const* aurApp, uint8 mode, bool apply) const @@ -3127,7 +3127,7 @@ void AuraEffect::HandleModMechanicImmunity(AuraApplication const* aurApp, uint8 return; Unit* target = aurApp->GetTarget(); - m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetEffIndex(), apply); + m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetSpellEffectInfo(), apply); } void AuraEffect::HandleAuraModEffectImmunity(AuraApplication const* aurApp, uint8 mode, bool apply) const @@ -3136,7 +3136,7 @@ void AuraEffect::HandleAuraModEffectImmunity(AuraApplication const* aurApp, uint return; Unit* target = aurApp->GetTarget(); - m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetEffIndex(), apply); + m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetSpellEffectInfo(), apply); // when removing flag aura, handle flag drop Player* player = target->ToPlayer(); @@ -3158,7 +3158,7 @@ void AuraEffect::HandleAuraModStateImmunity(AuraApplication const* aurApp, uint8 return; Unit* target = aurApp->GetTarget(); - m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetEffIndex(), apply); + m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetSpellEffectInfo(), apply); } void AuraEffect::HandleAuraModSchoolImmunity(AuraApplication const* aurApp, uint8 mode, bool apply) const @@ -3167,7 +3167,7 @@ void AuraEffect::HandleAuraModSchoolImmunity(AuraApplication const* aurApp, uint return; Unit* target = aurApp->GetTarget(); - m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetEffIndex(), apply); + m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetSpellEffectInfo(), apply); if (GetSpellInfo()->Mechanic == MECHANIC_BANISH) { @@ -3219,7 +3219,7 @@ void AuraEffect::HandleAuraModDmgImmunity(AuraApplication const* aurApp, uint8 m return; Unit* target = aurApp->GetTarget(); - m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetEffIndex(), apply); + m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetSpellEffectInfo(), apply); if (apply) { @@ -3241,7 +3241,7 @@ void AuraEffect::HandleAuraModDispelImmunity(AuraApplication const* aurApp, uint return; Unit* target = aurApp->GetTarget(); - m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetEffIndex(), apply); + m_spellInfo->ApplyAllSpellImmunitiesTo(target, GetSpellEffectInfo(), apply); } /*********************************************************/ diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp index 38347a1bae5..dd3c8ede288 100644 --- a/src/server/game/Spells/SpellInfo.cpp +++ b/src/server/game/Spells/SpellInfo.cpp @@ -30,6 +30,7 @@ #include "SpellAuraEffects.h" #include "SpellMgr.h" #include "Vehicle.h" +#include uint32 GetTargetFlagMask(SpellTargetObjectTypes objType) { @@ -211,6 +212,26 @@ uint32 SpellImplicitTargetInfo::GetExplicitTargetMask(bool& srcSet, bool& dstSet return targetMask; } +struct SpellEffectInfo::ImmunityInfo +{ + ImmunityInfo() = default; + ~ImmunityInfo() = default; + + ImmunityInfo(ImmunityInfo const&) = delete; + ImmunityInfo(ImmunityInfo&&) noexcept = delete; + ImmunityInfo& operator=(ImmunityInfo const&) = delete; + ImmunityInfo& operator=(ImmunityInfo&&) noexcept = delete; + + uint32 SchoolImmuneMask = 0; + uint32 ApplyHarmfulAuraImmuneMask = 0; + uint32 MechanicImmuneMask = 0; + uint32 DispelImmune = 0; + uint32 DamageSchoolMask = 0; + + boost::container::flat_set AuraTypeImmune; + boost::container::flat_set SpellEffectImmune; +}; + std::array SpellImplicitTargetInfo::_data = { { {TARGET_OBJECT_TYPE_NONE, TARGET_REFERENCE_TYPE_NONE, TARGET_SELECT_CATEGORY_NYI, TARGET_CHECK_DEFAULT, TARGET_DIR_NONE}, // @@ -326,6 +347,13 @@ std::array SpellImplic {TARGET_OBJECT_TYPE_DEST, TARGET_REFERENCE_TYPE_NONE, TARGET_SELECT_CATEGORY_NYI, TARGET_CHECK_ENTRY, TARGET_DIR_NONE}, // 110 TARGET_UNIT_CONE_ENTRY_110 } }; +SpellEffectInfo::SpellEffectInfo() : _spellInfo(nullptr), EffectIndex(EFFECT_0), Effect(SPELL_EFFECT_NONE), ApplyAuraName(SPELL_AURA_NONE), + Amplitude(0), DieSides(0), RealPointsPerLevel(0), BasePoints(0), PointsPerComboPoint(0), ValueMultiplier(0), DamageMultiplier(0), + BonusMultiplier(0), MiscValue(0), MiscValueB(0), Mechanic(MECHANIC_NONE), RadiusEntry(nullptr), ChainTarget(0), ItemType(0), + TriggerSpell(0), ImplicitTargetConditions(nullptr), _immunityInfo(nullptr) +{ +} + SpellEffectInfo::SpellEffectInfo(SpellEntry const* spellEntry, SpellInfo const* spellInfo, uint8 effIndex) { _spellInfo = spellInfo; @@ -351,6 +379,17 @@ SpellEffectInfo::SpellEffectInfo(SpellEntry const* spellEntry, SpellInfo const* TriggerSpell = spellEntry->EffectTriggerSpell[effIndex]; SpellClassMask = spellEntry->EffectSpellClassMask[effIndex]; ImplicitTargetConditions = nullptr; + _immunityInfo = nullptr; +} + +SpellEffectInfo::SpellEffectInfo(SpellEffectInfo const&) = default; +SpellEffectInfo::SpellEffectInfo(SpellEffectInfo&&) noexcept = default; +SpellEffectInfo& SpellEffectInfo::operator=(SpellEffectInfo const&) = default; +SpellEffectInfo& SpellEffectInfo::operator=(SpellEffectInfo&&) noexcept = default; + +SpellEffectInfo::~SpellEffectInfo() +{ + delete _immunityInfo; } bool SpellEffectInfo::IsEffect() const @@ -2545,6 +2584,8 @@ int32 SpellInfo::GetDiminishingReturnsLimitDuration(bool triggered) const void SpellInfo::_LoadImmunityInfo() { + std::unique_ptr workBuffer = std::make_unique(); + for (SpellEffectInfo& effect : _GetEffects()) { uint32 schoolImmunityMask = 0; @@ -2556,7 +2597,7 @@ void SpellInfo::_LoadImmunityInfo() int32 miscVal = effect.MiscValue; int32 amount = effect.CalcValue(); - ImmunityInfo& immuneInfo = _immunityInfo[effect.EffectIndex]; + SpellEffectInfo::ImmunityInfo& immuneInfo = *workBuffer; switch (effect.ApplyAuraName) { @@ -2736,7 +2777,7 @@ void SpellInfo::_LoadImmunityInfo() break; default: if (miscVal < 1) - continue; + break; mechanicImmunityMask |= 1 << miscVal; break; @@ -2786,6 +2827,18 @@ void SpellInfo::_LoadImmunityInfo() immuneInfo.AuraTypeImmune.shrink_to_fit(); immuneInfo.SpellEffectImmune.shrink_to_fit(); + if (immuneInfo.SchoolImmuneMask + || immuneInfo.ApplyHarmfulAuraImmuneMask + || immuneInfo.MechanicImmuneMask + || immuneInfo.DispelImmune + || immuneInfo.DamageSchoolMask + || !immuneInfo.AuraTypeImmune.empty() + || !immuneInfo.SpellEffectImmune.empty()) + { + effect._immunityInfo = workBuffer.release(); + workBuffer = std::make_unique(); + } + _allowedMechanicMask |= immuneInfo.MechanicImmuneMask; } @@ -2827,11 +2880,13 @@ void SpellInfo::_LoadImmunityInfo() } } -void SpellInfo::ApplyAllSpellImmunitiesTo(Unit* target, uint8 effIndex, bool apply) const +void SpellInfo::ApplyAllSpellImmunitiesTo(Unit* target, SpellEffectInfo const& spellEffectInfo, bool apply) const { - ImmunityInfo const& immuneInfo = _immunityInfo[effIndex]; + SpellEffectInfo::ImmunityInfo const* immuneInfo = spellEffectInfo.GetImmunityInfo(); + if (!immuneInfo) + return; - if (uint32 schoolImmunity = immuneInfo.SchoolImmuneMask) + if (uint32 schoolImmunity = immuneInfo->SchoolImmuneMask) { target->ApplySpellImmune(Id, IMMUNITY_SCHOOL, schoolImmunity, apply); @@ -2849,7 +2904,7 @@ void SpellInfo::ApplyAllSpellImmunitiesTo(Unit* target, uint8 effIndex, bool app } } - if (uint32 mechanicImmunity = immuneInfo.MechanicImmuneMask) + if (uint32 mechanicImmunity = immuneInfo->MechanicImmuneMask) { for (uint32 i = 0; i < MAX_MECHANIC; ++i) if (mechanicImmunity & (1 << i)) @@ -2878,7 +2933,7 @@ void SpellInfo::ApplyAllSpellImmunitiesTo(Unit* target, uint8 effIndex, bool app } } - if (uint32 dispelImmunity = immuneInfo.DispelImmune) + if (uint32 dispelImmunity = immuneInfo->DispelImmune) { target->ApplySpellImmune(Id, IMMUNITY_DISPEL, dispelImmunity, apply); @@ -2895,10 +2950,10 @@ void SpellInfo::ApplyAllSpellImmunitiesTo(Unit* target, uint8 effIndex, bool app } } - if (uint32 damageImmunity = immuneInfo.DamageSchoolMask) + if (uint32 damageImmunity = immuneInfo->DamageSchoolMask) target->ApplySpellImmune(Id, IMMUNITY_DAMAGE, damageImmunity, apply); - for (AuraType auraType : immuneInfo.AuraTypeImmune) + for (AuraType auraType : immuneInfo->AuraTypeImmune) { target->ApplySpellImmune(Id, IMMUNITY_STATE, auraType, apply); if (apply && HasAttribute(SPELL_ATTR1_DISPEL_AURAS_ON_IMMUNITY)) @@ -2909,7 +2964,7 @@ void SpellInfo::ApplyAllSpellImmunitiesTo(Unit* target, uint8 effIndex, bool app }); } - for (SpellEffects effectType : immuneInfo.SpellEffectImmune) + for (SpellEffects effectType : immuneInfo->SpellEffectImmune) target->ApplySpellImmune(Id, IMMUNITY_EFFECT, effectType, apply); } @@ -2918,20 +2973,27 @@ bool SpellInfo::CanSpellProvideImmunityAgainstAura(SpellInfo const* auraSpellInf if (!auraSpellInfo) return false; - for (ImmunityInfo const& immuneInfo : _immunityInfo) + for (SpellEffectInfo const& effectInfo : _effects) { + if (!effectInfo.IsEffect()) + continue; + + SpellEffectInfo::ImmunityInfo const* immuneInfo = effectInfo.GetImmunityInfo(); + if (!immuneInfo) + continue; + if (!auraSpellInfo->HasAttribute(SPELL_ATTR1_UNAFFECTED_BY_SCHOOL_IMMUNE) && !auraSpellInfo->HasAttribute(SPELL_ATTR2_UNAFFECTED_BY_AURA_SCHOOL_IMMUNE)) { - if (uint32 schoolImmunity = immuneInfo.SchoolImmuneMask) + if (uint32 schoolImmunity = immuneInfo->SchoolImmuneMask) if ((auraSpellInfo->SchoolMask & schoolImmunity) != 0) return true; } - if (uint32 mechanicImmunity = immuneInfo.MechanicImmuneMask) + if (uint32 mechanicImmunity = immuneInfo->MechanicImmuneMask) if ((mechanicImmunity & (1 << auraSpellInfo->Mechanic)) != 0) return true; - if (uint32 dispelImmunity = immuneInfo.DispelImmune) + if (uint32 dispelImmunity = immuneInfo->DispelImmune) if (auraSpellInfo->Dispel == dispelImmunity) return true; @@ -2941,8 +3003,8 @@ bool SpellInfo::CanSpellProvideImmunityAgainstAura(SpellInfo const* auraSpellInf if (!auraSpellEffectInfo.IsEffect()) continue; - auto spellImmuneItr = immuneInfo.SpellEffectImmune.find(auraSpellEffectInfo.Effect); - if (spellImmuneItr == immuneInfo.SpellEffectImmune.cend()) + auto spellImmuneItr = immuneInfo->SpellEffectImmune.find(auraSpellEffectInfo.Effect); + if (spellImmuneItr == immuneInfo->SpellEffectImmune.cend()) { immuneToAllEffects = false; break; @@ -2950,7 +3012,7 @@ bool SpellInfo::CanSpellProvideImmunityAgainstAura(SpellInfo const* auraSpellInf if (uint32 mechanic = auraSpellEffectInfo.Mechanic) { - if (!(immuneInfo.MechanicImmuneMask & (1 << mechanic))) + if (!(immuneInfo->MechanicImmuneMask & (1 << mechanic))) { immuneToAllEffects = false; break; @@ -2962,13 +3024,13 @@ bool SpellInfo::CanSpellProvideImmunityAgainstAura(SpellInfo const* auraSpellInf if (AuraType auraName = auraSpellEffectInfo.ApplyAuraName) { bool isImmuneToAuraEffectApply = false; - auto auraImmuneItr = immuneInfo.AuraTypeImmune.find(auraName); - if (auraImmuneItr != immuneInfo.AuraTypeImmune.cend()) + auto auraImmuneItr = immuneInfo->AuraTypeImmune.find(auraName); + if (auraImmuneItr != immuneInfo->AuraTypeImmune.cend()) isImmuneToAuraEffectApply = true; if (!isImmuneToAuraEffectApply && !auraSpellInfo->IsPositiveEffect(auraSpellEffectInfo.EffectIndex) && !auraSpellInfo->HasAttribute(SPELL_ATTR2_UNAFFECTED_BY_AURA_SCHOOL_IMMUNE)) { - if (uint32 applyHarmfulAuraImmunityMask = immuneInfo.ApplyHarmfulAuraImmuneMask) + if (uint32 applyHarmfulAuraImmunityMask = immuneInfo->ApplyHarmfulAuraImmuneMask) if ((auraSpellInfo->GetSchoolMask() & applyHarmfulAuraImmunityMask) != 0) isImmuneToAuraEffectApply = true; } diff --git a/src/server/game/Spells/SpellInfo.h b/src/server/game/Spells/SpellInfo.h index 51d34e2d443..426c067317a 100644 --- a/src/server/game/Spells/SpellInfo.h +++ b/src/server/game/Spells/SpellInfo.h @@ -24,8 +24,6 @@ #include "Object.h" #include "SpellAuraDefines.h" -#include - class AuraEffect; class Item; class Player; @@ -208,6 +206,7 @@ class TC_GAME_API SpellImplicitTargetInfo class TC_GAME_API SpellEffectInfo { + friend class SpellInfo; SpellInfo const* _spellInfo; public: SpellEffIndex EffectIndex; @@ -233,11 +232,13 @@ class TC_GAME_API SpellEffectInfo flag96 SpellClassMask; std::vector* ImplicitTargetConditions; - SpellEffectInfo() : _spellInfo(nullptr), EffectIndex(EFFECT_0), Effect(SPELL_EFFECT_NONE), ApplyAuraName(SPELL_AURA_NONE), Amplitude(0), DieSides(0), - RealPointsPerLevel(0), BasePoints(0), PointsPerComboPoint(0), ValueMultiplier(0), DamageMultiplier(0), - BonusMultiplier(0), MiscValue(0), MiscValueB(0), Mechanic(MECHANIC_NONE), RadiusEntry(nullptr), ChainTarget(0), - ItemType(0), TriggerSpell(0), ImplicitTargetConditions(nullptr) {} - SpellEffectInfo(SpellEntry const* spellEntry, SpellInfo const* spellInfo, uint8 effIndex); + SpellEffectInfo(); + explicit SpellEffectInfo(SpellEntry const* spellEntry, SpellInfo const* spellInfo, uint8 effIndex); + SpellEffectInfo(SpellEffectInfo const&); + SpellEffectInfo(SpellEffectInfo&&) noexcept; + SpellEffectInfo& operator=(SpellEffectInfo const&); + SpellEffectInfo& operator=(SpellEffectInfo&&) noexcept; + ~SpellEffectInfo(); bool IsEffect() const; bool IsEffect(SpellEffects effectName) const; @@ -261,6 +262,9 @@ class TC_GAME_API SpellEffectInfo SpellEffectImplicitTargetTypes GetImplicitTargetType() const; SpellTargetObjectTypes GetUsedTargetObjectType() const; + struct ImmunityInfo; + ImmunityInfo const* GetImmunityInfo() const { return _immunityInfo; } + private: struct StaticData { @@ -268,6 +272,8 @@ class TC_GAME_API SpellEffectInfo SpellTargetObjectTypes UsedTargetObjectType; // defines valid target object type for spell effect }; static std::array _data; + + ImmunityInfo* _immunityInfo; }; struct TC_GAME_API SpellDiminishInfo @@ -278,18 +284,6 @@ struct TC_GAME_API SpellDiminishInfo int32 DiminishDurationLimit = 0; }; -struct TC_GAME_API ImmunityInfo -{ - uint32 SchoolImmuneMask = 0; - uint32 ApplyHarmfulAuraImmuneMask = 0; - uint32 MechanicImmuneMask = 0; - uint32 DispelImmune = 0; - uint32 DamageSchoolMask = 0; - - boost::container::flat_set AuraTypeImmune; - boost::container::flat_set SpellEffectImmune; -}; - class TC_GAME_API SpellInfo { friend class SpellMgr; @@ -498,7 +492,7 @@ class TC_GAME_API SpellInfo int32 GetDiminishingReturnsLimitDuration(bool triggered) const; // spell immunities - void ApplyAllSpellImmunitiesTo(Unit* target, uint8 effIndex, bool apply) const; + void ApplyAllSpellImmunitiesTo(Unit* target, SpellEffectInfo const& spellEffectInfo, bool apply) const; bool CanSpellProvideImmunityAgainstAura(SpellInfo const* auraSpellInfo) const; bool SpellCancelsAuraEffect(AuraEffect const* aurEff) const; @@ -528,8 +522,6 @@ class TC_GAME_API SpellInfo SpellDiminishInfo _diminishInfoTriggered; uint32 _allowedMechanicMask; - - std::array _immunityInfo; }; #endif // _SPELLINFO_H From 30adff16ae8806b7d5df824b6d3fdd331f7ff233 Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 6 Jan 2023 16:51:01 +0100 Subject: [PATCH 08/17] Core/Utils: Replace boost flat_set with our own (cherry picked from commit 42fbcf2fc58690346ef1db12803b79634985d44f) --- src/common/Containers/FlatSet.h | 105 +++++++++++++++++++++++++++ src/server/game/Spells/SpellInfo.cpp | 10 +-- tests/common/FlatSet.cpp | 60 +++++++++++++++ 3 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 src/common/Containers/FlatSet.h create mode 100644 tests/common/FlatSet.cpp diff --git a/src/common/Containers/FlatSet.h b/src/common/Containers/FlatSet.h new file mode 100644 index 00000000000..5602ba17254 --- /dev/null +++ b/src/common/Containers/FlatSet.h @@ -0,0 +1,105 @@ +/* + * 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 . + */ +#ifndef TRINITYCORE_FLAT_SET_H +#define TRINITYCORE_FLAT_SET_H + +#include +#include + +namespace Trinity::Containers +{ +template , class KeyContainer = std::vector> +class FlatSet +{ +public: + using iterator = typename KeyContainer::iterator; + using const_iterator = typename KeyContainer::const_iterator; + + bool empty() const { return _storage.empty(); } + auto size() const { return _storage.size(); } + + auto begin() { return _storage.begin(); } + auto begin() const { return _storage.begin(); } + + auto end() { return _storage.end(); } + auto end() const { return _storage.end(); } + + auto find(Key const& value) const + { + auto end = this->end(); + auto itr = std::lower_bound(this->begin(), end, value, Compare()); + if (itr != end && Compare()(value, *itr)) + itr = end; + + return itr; + } + + auto find(Key const& value) + { + auto end = this->end(); + auto itr = std::lower_bound(this->begin(), end, value, Compare()); + if (itr != end && Compare()(value, *itr)) + itr = end; + + return itr; + } + + template + std::pair emplace(Args&&... args) + { + Key newElement(std::forward(args)...); + auto end = this->end(); + auto itr = std::lower_bound(this->begin(), end, newElement, Compare()); + if (itr != end && !Compare()(newElement, *itr)) + return { itr, false }; + + return { _storage.emplace(itr, std::move(newElement)), true }; + } + + std::pair insert(Key const& key) { return emplace(key); } + + std::size_t erase(Key const& key) + { + auto itr = this->find(key); + if (itr == this->end()) + return 0; + + this->erase(itr); + return 1; + } + auto erase(const_iterator itr) { return _storage.erase(itr); } + + void clear() { _storage.clear(); } + + void shrink_to_fit() { _storage.shrink_to_fit(); } + + friend bool operator==(FlatSet const& left, FlatSet const& right) + { + return left._storage == right._storage; + } + + friend bool operator!=(FlatSet const& left, FlatSet const& right) + { + return !(left == right); + } + +private: + KeyContainer _storage; +}; +} + +#endif // TRINITYCORE_FLAT_SET_H diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp index dd3c8ede288..1cd54720d54 100644 --- a/src/server/game/Spells/SpellInfo.cpp +++ b/src/server/game/Spells/SpellInfo.cpp @@ -20,6 +20,7 @@ #include "Corpse.h" #include "Creature.h" #include "DBCStores.h" +#include "FlatSet.h" #include "Item.h" #include "ItemTemplate.h" #include "Log.h" @@ -30,7 +31,6 @@ #include "SpellAuraEffects.h" #include "SpellMgr.h" #include "Vehicle.h" -#include uint32 GetTargetFlagMask(SpellTargetObjectTypes objType) { @@ -228,8 +228,8 @@ struct SpellEffectInfo::ImmunityInfo uint32 DispelImmune = 0; uint32 DamageSchoolMask = 0; - boost::container::flat_set AuraTypeImmune; - boost::container::flat_set SpellEffectImmune; + Trinity::Containers::FlatSet AuraTypeImmune; + Trinity::Containers::FlatSet SpellEffectImmune; }; std::array SpellImplicitTargetInfo::_data = @@ -3004,7 +3004,7 @@ bool SpellInfo::CanSpellProvideImmunityAgainstAura(SpellInfo const* auraSpellInf continue; auto spellImmuneItr = immuneInfo->SpellEffectImmune.find(auraSpellEffectInfo.Effect); - if (spellImmuneItr == immuneInfo->SpellEffectImmune.cend()) + if (spellImmuneItr == immuneInfo->SpellEffectImmune.end()) { immuneToAllEffects = false; break; @@ -3025,7 +3025,7 @@ bool SpellInfo::CanSpellProvideImmunityAgainstAura(SpellInfo const* auraSpellInf { bool isImmuneToAuraEffectApply = false; auto auraImmuneItr = immuneInfo->AuraTypeImmune.find(auraName); - if (auraImmuneItr != immuneInfo->AuraTypeImmune.cend()) + if (auraImmuneItr != immuneInfo->AuraTypeImmune.end()) isImmuneToAuraEffectApply = true; if (!isImmuneToAuraEffectApply && !auraSpellInfo->IsPositiveEffect(auraSpellEffectInfo.EffectIndex) && !auraSpellInfo->HasAttribute(SPELL_ATTR2_UNAFFECTED_BY_AURA_SCHOOL_IMMUNE)) diff --git a/tests/common/FlatSet.cpp b/tests/common/FlatSet.cpp new file mode 100644 index 00000000000..a0c50a62a45 --- /dev/null +++ b/tests/common/FlatSet.cpp @@ -0,0 +1,60 @@ +/* + * 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 . + */ + +#include "tc_catch2.h" + +#include "FlatSet.h" + +TEST_CASE("Insertion", "[FlatSet]") +{ + Trinity::Containers::FlatSet flat; + + REQUIRE(flat.insert(5).second == true); + REQUIRE(flat.insert(3).second == true); + REQUIRE(flat.insert(9).second == true); + REQUIRE(flat.insert(7).second == true); + + REQUIRE(flat.insert(5).second == false); + REQUIRE(flat.insert(3).second == false); + REQUIRE(flat.insert(9).second == false); + REQUIRE(flat.insert(7).second == false); + + REQUIRE(flat.size() == 4); + + auto itr = flat.begin(); + REQUIRE(*itr == 3); + ++itr; + REQUIRE(*itr == 5); + ++itr; + REQUIRE(*itr == 7); + ++itr; + REQUIRE(*itr == 9); + ++itr; + REQUIRE(itr == flat.end()); +} + +TEST_CASE("Erase", "[FlatSet]") +{ + Trinity::Containers::FlatSet flat; + flat.insert(3); + flat.insert(5); + flat.insert(7); + flat.insert(9); + + REQUIRE(flat.erase(7) == 1); + REQUIRE(flat.size() == 3); +} From f5a2e2ae13e3f7b505b069c1cd98e3157c31c83a Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 6 Jan 2023 16:52:44 +0100 Subject: [PATCH 09/17] Core/Misc: Replaced boost::container::static_vector in packet classes with plain vector with custom static storage allocatlr (cherry picked from commit b65c3f5f4a4edbc953c405bfacd33f186f3a1931) --- dep/CMakeLists.txt | 1 + dep/PackageList.txt | 4 + dep/short_alloc/CMakeLists.txt | 15 ++ dep/short_alloc/short_alloc/short_alloc.h | 162 +++++++++++++++++ src/common/CMakeLists.txt | 3 +- .../game/Server/Packets/PacketUtilities.cpp | 12 +- .../game/Server/Packets/PacketUtilities.h | 169 ++++++------------ 7 files changed, 244 insertions(+), 122 deletions(-) create mode 100644 dep/short_alloc/CMakeLists.txt create mode 100644 dep/short_alloc/short_alloc/short_alloc.h diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt index a87f460ed95..71fa48710ce 100644 --- a/dep/CMakeLists.txt +++ b/dep/CMakeLists.txt @@ -29,6 +29,7 @@ if(SERVERS) add_subdirectory(readline) add_subdirectory(gsoap) add_subdirectory(efsw) + add_subdirectory(short_alloc) endif() if(TOOLS) diff --git a/dep/PackageList.txt b/dep/PackageList.txt index e4b2ece30b2..026578d952c 100644 --- a/dep/PackageList.txt +++ b/dep/PackageList.txt @@ -72,3 +72,7 @@ argon2 catch2 https://github.com/catchorg/Catch2 Version: v2.13.0 + +short_alloc (Stack based allocator) https://howardhinnant.github.io/stack_alloc.html + https://howardhinnant.github.io/short_alloc.h + Version: N/A diff --git a/dep/short_alloc/CMakeLists.txt b/dep/short_alloc/CMakeLists.txt new file mode 100644 index 00000000000..fc6ae3941b7 --- /dev/null +++ b/dep/short_alloc/CMakeLists.txt @@ -0,0 +1,15 @@ +# This file is part of the TrinityCore Project. See AUTHORS file for Copyright information +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +add_library(short_alloc INTERFACE) + +target_include_directories(short_alloc + INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/dep/short_alloc/short_alloc/short_alloc.h b/dep/short_alloc/short_alloc/short_alloc.h new file mode 100644 index 00000000000..eb8d02c7917 --- /dev/null +++ b/dep/short_alloc/short_alloc/short_alloc.h @@ -0,0 +1,162 @@ +#ifndef SHORT_ALLOC_H +#define SHORT_ALLOC_H + +// The MIT License (MIT) +// +// Copyright (c) 2015 Howard Hinnant +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include +#include +#include + +namespace short_alloc +{ +template +class arena +{ + alignas(alignment) char buf_[N]; + char* ptr_; + +public: + ~arena() {ptr_ = nullptr;} + arena() noexcept : ptr_(buf_) {} + arena(const arena&) = delete; + arena& operator=(const arena&) = delete; + + template char* allocate(std::size_t n); + void deallocate(char* p, std::size_t n) noexcept; + + static constexpr std::size_t size() noexcept {return N;} + std::size_t used() const noexcept {return static_cast(ptr_ - buf_);} + void reset() noexcept {ptr_ = buf_;} + +private: + static + std::size_t + align_up(std::size_t n) noexcept + {return (n + (alignment-1)) & ~(alignment-1);} + + bool + pointer_in_buffer(char* p) noexcept + { + return std::uintptr_t(buf_) <= std::uintptr_t(p) && + std::uintptr_t(p) <= std::uintptr_t(buf_) + N; + } +}; + +template +template +char* +arena::allocate(std::size_t n) +{ + static_assert(ReqAlign <= alignment, "alignment is too small for this arena"); + assert(pointer_in_buffer(ptr_) && "short_alloc has outlived arena"); + auto const aligned_n = align_up(n); + if (static_cast(buf_ + N - ptr_) >= aligned_n) + { + char* r = ptr_; + ptr_ += aligned_n; + return r; + } + + static_assert(alignment <= alignof(std::max_align_t), "you've chosen an " + "alignment that is larger than alignof(std::max_align_t), and " + "cannot be guaranteed by normal operator new"); + return static_cast(::operator new(n)); +} + +template +void +arena::deallocate(char* p, std::size_t n) noexcept +{ + assert(pointer_in_buffer(ptr_) && "short_alloc has outlived arena"); + if (pointer_in_buffer(p)) + { + n = align_up(n); + if (p + n == ptr_) + ptr_ = p; + } + else + ::operator delete(p); +} + +template +class short_alloc +{ +public: + using value_type = T; + static auto constexpr alignment = Align; + static auto constexpr size = N; + using arena_type = arena; + +private: + arena_type& a_; + +public: + short_alloc(const short_alloc&) = default; + short_alloc& operator=(const short_alloc&) = delete; + + short_alloc(arena_type& a) noexcept : a_(a) + { + static_assert(size % alignment == 0, + "size N needs to be a multiple of alignment Align"); + } + template + short_alloc(const short_alloc& a) noexcept + : a_(a.a_) {} + + template struct rebind {using other = short_alloc<_Up, N, alignment>;}; + + T* allocate(std::size_t n) + { + return reinterpret_cast(a_.template allocate(n*sizeof(T))); + } + void deallocate(T* p, std::size_t n) noexcept + { + a_.deallocate(reinterpret_cast(p), n*sizeof(T)); + } + + template + friend + bool + operator==(const short_alloc& x, const short_alloc& y) noexcept; + + template friend class short_alloc; +}; + +template +inline +bool +operator==(const short_alloc& x, const short_alloc& y) noexcept +{ + return N == M && A1 == A2 && &x.a_ == &y.a_; +} + +template +inline +bool +operator!=(const short_alloc& x, const short_alloc& y) noexcept +{ + return !(x == y); +} +} +#endif // SHORT_ALLOC_H diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 5258258a7c6..67d0d663c73 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -72,7 +72,8 @@ target_link_libraries(common openssl valgrind threads - jemalloc) + jemalloc + short_alloc) add_dependencies(common revision_data.h) diff --git a/src/server/game/Server/Packets/PacketUtilities.cpp b/src/server/game/Server/Packets/PacketUtilities.cpp index 862c643013c..fe7487daaee 100644 --- a/src/server/game/Server/Packets/PacketUtilities.cpp +++ b/src/server/game/Server/Packets/PacketUtilities.cpp @@ -17,10 +17,7 @@ #include "PacketUtilities.h" #include "Hyperlinks.h" -#include "Errors.h" #include -#include -#include WorldPackets::InvalidStringValueException::InvalidStringValueException(std::string const& value) : ByteBufferInvalidValueException("string", value.c_str()) { @@ -61,12 +58,5 @@ bool WorldPackets::Strings::NoHyperlinks::Validate(std::string const& value) WorldPackets::PacketArrayMaxCapacityException::PacketArrayMaxCapacityException(std::size_t requestedSize, std::size_t sizeLimit) { - std::ostringstream builder; - builder << "Attempted to read more array elements from packet " << requestedSize << " than allowed " << sizeLimit; - message().assign(builder.str()); -} - -void WorldPackets::CheckCompactArrayMaskOverflow(std::size_t index, std::size_t limit) -{ - ASSERT(index < limit, "Attempted to insert " SZFMTD " values into CompactArray but it can only hold " SZFMTD, index, limit); + message().assign("Attempted to read more array elements from packet " + Trinity::ToString(requestedSize) + " than allowed " + Trinity::ToString(sizeLimit)); } diff --git a/src/server/game/Server/Packets/PacketUtilities.h b/src/server/game/Server/Packets/PacketUtilities.h index 0c06be5ea71..8b05803bb2b 100644 --- a/src/server/game/Server/Packets/PacketUtilities.h +++ b/src/server/game/Server/Packets/PacketUtilities.h @@ -20,6 +20,7 @@ #include "ByteBuffer.h" #include "Tuples.h" +#include #include namespace WorldPackets @@ -114,21 +115,49 @@ namespace WorldPackets /** * Utility class for automated prevention of loop counter spoofing in client packets */ - template + template class Array { - typedef std::vector storage_type; + public: + using allocator_type = short_alloc::short_alloc; + using arena_type = typename allocator_type::arena_type; - typedef typename storage_type::value_type value_type; - typedef typename storage_type::size_type size_type; - typedef typename storage_type::reference reference; - typedef typename storage_type::const_reference const_reference; - typedef typename storage_type::iterator iterator; - typedef typename storage_type::const_iterator const_iterator; + using storage_type = std::vector; - public: - Array() : _limit(N) { } - Array(size_type limit) : _limit(limit) { } + using max_capacity = std::integral_constant; + + using value_type = typename storage_type::value_type; + using size_type = typename storage_type::size_type; + using pointer = typename storage_type::pointer; + using const_pointer = typename storage_type::const_pointer; + using reference = typename storage_type::reference; + using const_reference = typename storage_type::const_reference; + using iterator = typename storage_type::iterator; + using const_iterator = typename storage_type::const_iterator; + + Array() : _storage(_data) { } + + Array(Array const& other) : Array() + { + for (T const& element : other) + _storage.push_back(element); + } + + Array(Array&& other) noexcept = delete; + + Array& operator=(Array const& other) + { + if (this == &other) + return *this; + + _storage.clear(); + for (T const& element : other) + _storage.push_back(element); + + return *this; + } + + Array& operator=(Array&& other) noexcept = delete; iterator begin() { return _storage.begin(); } const_iterator begin() const { return _storage.begin(); } @@ -136,6 +165,9 @@ namespace WorldPackets iterator end() { return _storage.end(); } const_iterator end() const { return _storage.end(); } + pointer data() { return _storage.data(); } + const_pointer data() const { return _storage.data(); } + size_type size() const { return _storage.size(); } bool empty() const { return _storage.empty(); } @@ -144,132 +176,49 @@ namespace WorldPackets void resize(size_type newSize) { - if (newSize > _limit) - throw PacketArrayMaxCapacityException(newSize, _limit); + if (newSize > max_capacity::value) + throw PacketArrayMaxCapacityException(newSize, max_capacity::value); _storage.resize(newSize); } - void reserve(size_type newSize) - { - if (newSize > _limit) - throw PacketArrayMaxCapacityException(newSize, _limit); - - _storage.reserve(newSize); - } - void push_back(value_type const& value) { - if (_storage.size() >= _limit) - throw PacketArrayMaxCapacityException(_storage.size() + 1, _limit); + if (_storage.size() >= max_capacity::value) + throw PacketArrayMaxCapacityException(_storage.size() + 1, max_capacity::value); _storage.push_back(value); } void push_back(value_type&& value) { - if (_storage.size() >= _limit) - throw PacketArrayMaxCapacityException(_storage.size() + 1, _limit); + if (_storage.size() >= max_capacity::value) + throw PacketArrayMaxCapacityException(_storage.size() + 1, max_capacity::value); _storage.push_back(std::forward(value)); } - private: - storage_type _storage; - size_type _limit; - }; - - void CheckCompactArrayMaskOverflow(std::size_t index, std::size_t limit); - - template - class CompactArray - { - public: - CompactArray() : _mask(0) { } - - CompactArray(CompactArray const& right) - : _mask(right._mask), _contents(right._contents) { } - - CompactArray(CompactArray&& right) - : _mask(right._mask), _contents(std::move(right._contents)) - { - right._mask = 0; - } - - CompactArray& operator=(CompactArray const& right) - { - _mask = right._mask; - _contents = right._contents; - return *this; - } - - CompactArray& operator=(CompactArray&& right) + template + T& emplace_back(Args&&... args) { - _mask = right._mask; - right._mask = 0; - _contents = std::move(right._contents); - return *this; + _storage.emplace_back(std::forward(args)...); + return _storage.back(); } - uint32 GetMask() const { return _mask; } - T const& operator[](std::size_t index) const { return _contents.at(index); } - std::size_t GetSize() const { return _contents.size(); } - - void Insert(std::size_t index, T const& value) + iterator erase(const_iterator first, const_iterator last) { - CheckCompactArrayMaskOverflow(index, sizeof(_mask) * 8); - - _mask |= 1 << index; - if (_contents.size() <= index) - _contents.resize(index + 1); - _contents[index] = value; + return _storage.erase(first, last); } - void Clear() + void clear() { - _mask = 0; - _contents.clear(); + _storage.clear(); } - bool operator==(CompactArray const& r) const - { - if (_mask != r._mask) - return false; - - return _contents == r._contents; - } - - bool operator!=(CompactArray const& r) const { return !(*this == r); } - private: - uint32 _mask; - std::vector _contents; + arena_type _data; + storage_type _storage; }; - - template - ByteBuffer& operator<<(ByteBuffer& data, CompactArray const& v) - { - uint32 mask = v.GetMask(); - data << uint32(mask); - for (std::size_t i = 0; i < v.GetSize(); ++i) - if (mask & (1 << i)) - data << v[i]; - - return data; - } - - template - ByteBuffer& operator>>(ByteBuffer& data, CompactArray& v) - { - uint32 mask; - data >> mask; - - for (std::size_t index = 0; mask != 0; mask >>= 1, ++index) - if ((mask & 1) != 0) - v.Insert(index, data.read()); - - return data; - } } #endif // PacketUtilities_h__ From cccc062ea002ee63e0288d5a71356f45f7094287 Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 6 Jan 2023 16:54:16 +0100 Subject: [PATCH 10/17] Core/Misc: Remove boost::heap::fibonacci_heap from header files (cherry picked from commit e8e330addd55dffa8e34716c7e1969ad243d65b3) --- src/common/Utilities/IteratorPair.h | 26 +++-- src/server/game/AI/CoreAI/UnitAI.cpp | 92 +++++++++++++++++- src/server/game/AI/CoreAI/UnitAI.h | 96 ++----------------- .../game/AI/ScriptedAI/ScriptedCreature.cpp | 5 +- .../game/AI/ScriptedAI/ScriptedCreature.h | 8 +- src/server/game/Combat/ThreatManager.cpp | 92 ++++++++++++++---- src/server/game/Combat/ThreatManager.h | 49 ++++++---- src/server/game/Maps/Map.cpp | 42 +++++--- src/server/game/Maps/Map.h | 7 +- tests/game/ThreatListIterator.cpp | 65 +++++++++++++ 10 files changed, 322 insertions(+), 160 deletions(-) create mode 100644 tests/game/ThreatListIterator.cpp diff --git a/src/common/Utilities/IteratorPair.h b/src/common/Utilities/IteratorPair.h index d243349b2de..7e7583bfdd7 100644 --- a/src/common/Utilities/IteratorPair.h +++ b/src/common/Utilities/IteratorPair.h @@ -28,27 +28,39 @@ namespace Trinity * * @brief Utility class to enable range for loop syntax for multimap.equal_range uses */ - template + template class IteratorPair { public: constexpr IteratorPair() : _iterators() { } - constexpr IteratorPair(iterator first, iterator second) : _iterators(first, second) { } - constexpr IteratorPair(std::pair iterators) : _iterators(iterators) { } + constexpr IteratorPair(iterator first, end_iterator second) : _iterators(first, second) { } + constexpr IteratorPair(std::pair iterators) : _iterators(iterators) { } constexpr iterator begin() const { return _iterators.first; } - constexpr iterator end() const { return _iterators.second; } + constexpr end_iterator end() const { return _iterators.second; } private: - std::pair _iterators; + std::pair _iterators; }; namespace Containers { + template + constexpr IteratorPair MakeIteratorPair(iterator first, end_iterator second) + { + return { first, second }; + } + + template + constexpr IteratorPair MakeIteratorPair(std::pair iterators) + { + return iterators; + } + template - inline auto MapEqualRange(M& map, typename M::key_type const& key) -> IteratorPair + auto MapEqualRange(M& map, typename M::key_type const& key) { - return { map.equal_range(key) }; + return MakeIteratorPair(map.equal_range(key)); } } //! namespace Containers diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp index 79d847cfe41..35d2e256851 100644 --- a/src/server/game/AI/CoreAI/UnitAI.cpp +++ b/src/server/game/AI/CoreAI/UnitAI.cpp @@ -16,6 +16,7 @@ */ #include "UnitAI.h" +#include "Containers.h" #include "Creature.h" #include "CreatureAIImpl.h" #include "MotionMaster.h" @@ -233,14 +234,97 @@ void UnitAI::FillAISpellInfo() } } -ThreatManager& UnitAI::GetThreatManager() +Unit* UnitAI::FinalizeTargetSelection(std::list& targetList, SelectTargetMethod targetType) { - return me->GetThreatManager(); + // maybe nothing fulfills the predicate + if (targetList.empty()) + return nullptr; + + switch (targetType) + { + case SelectTargetMethod::MaxThreat: + case SelectTargetMethod::MinThreat: + case SelectTargetMethod::MaxDistance: + case SelectTargetMethod::MinDistance: + return targetList.front(); + case SelectTargetMethod::Random: + return Trinity::Containers::SelectRandomContainerElement(targetList); + default: + break; + } + + return nullptr; } -void UnitAI::SortByDistance(std::list& list, bool ascending) +bool UnitAI::PrepareTargetListSelection(std::list& targetList, SelectTargetMethod targetType, uint32 offset) { - list.sort(Trinity::ObjectDistanceOrderPred(me, ascending)); + targetList.clear(); + ThreatManager& mgr = me->GetThreatManager(); + // shortcut: we're gonna ignore the first elements, and there's at most elements, so we ignore them all - nothing to do here + if (mgr.GetThreatListSize() <= offset) + return false; + + if (targetType == SelectTargetMethod::MaxDistance || targetType == SelectTargetMethod::MinDistance) + { + for (ThreatReference const* ref : mgr.GetUnsortedThreatList()) + { + if (ref->IsOffline()) + continue; + + targetList.push_back(ref->GetVictim()); + } + } + else + { + Unit* currentVictim = mgr.GetCurrentVictim(); + if (currentVictim) + targetList.push_back(currentVictim); + + for (ThreatReference const* ref : mgr.GetSortedThreatList()) + { + if (ref->IsOffline()) + continue; + + Unit* thisTarget = ref->GetVictim(); + if (thisTarget != currentVictim) + targetList.push_back(thisTarget); + } + } + + // shortcut: the list isn't gonna get any larger + if (targetList.size() <= offset) + { + targetList.clear(); + return false; + } + + // right now, list is unsorted for DISTANCE types - re-sort by SelectTargetMethod::MaxDistance + if (targetType == SelectTargetMethod::MaxDistance || targetType == SelectTargetMethod::MinDistance) + targetList.sort(Trinity::ObjectDistanceOrderPred(me, targetType == SelectTargetMethod::MinDistance)); + + // now the list is MAX sorted, reverse for MIN types + if (targetType == SelectTargetMethod::MinThreat) + targetList.reverse(); + + // ignore the first elements + while (offset) + { + targetList.pop_front(); + --offset; + } + + return true; +} + +void UnitAI::FinalizeTargetListSelection(std::list& targetList, uint32 num, SelectTargetMethod targetType) +{ + if (targetList.size() <= num) + return; + + if (targetType == SelectTargetMethod::Random) + Trinity::Containers::RandomResize(targetList, num); + else + targetList.resize(num); } std::string UnitAI::GetDebugInfo() const diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h index 3a146126469..0a7e10a34f6 100644 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -18,12 +18,11 @@ #ifndef TRINITY_UNITAI_H #define TRINITY_UNITAI_H -#include "Containers.h" #include "Errors.h" #include "EventMap.h" #include "ObjectGuid.h" +#include "SharedDefines.h" #include "SpellDefines.h" -#include "ThreatManager.h" #define CAST_AI(a, b) (dynamic_cast(b)) #define ENSURE_AI(a,b) (EnsureAI(b)) @@ -175,30 +174,10 @@ class TC_GAME_API UnitAI template Unit* SelectTarget(SelectTargetMethod targetType, uint32 offset, PREDICATE const& predicate) { - ThreatManager& mgr = GetThreatManager(); - // shortcut: if we ignore the first elements, and there are at most elements, then we ignore ALL elements - if (mgr.GetThreatListSize() <= offset) - return nullptr; - std::list targetList; - SelectTargetList(targetList, mgr.GetThreatListSize(), targetType, offset, predicate); - - // maybe nothing fulfills the predicate - if (targetList.empty()) - return nullptr; - - switch (targetType) - { - case SelectTargetMethod::MaxThreat: - case SelectTargetMethod::MinThreat: - case SelectTargetMethod::MaxDistance: - case SelectTargetMethod::MinDistance: - return targetList.front(); - case SelectTargetMethod::Random: - return Trinity::Containers::SelectRandomContainerElement(targetList); - default: - return nullptr; - } + SelectTargetList(targetList, std::numeric_limits::max(), targetType, offset, predicate); + + return FinalizeTargetSelection(targetList, targetType); } // Select the best (up to) targets (in order) from the threat list that fulfill the following: @@ -219,71 +198,13 @@ class TC_GAME_API UnitAI template void SelectTargetList(std::list& targetList, uint32 num, SelectTargetMethod targetType, uint32 offset, PREDICATE const& predicate) { - targetList.clear(); - ThreatManager& mgr = GetThreatManager(); - // shortcut: we're gonna ignore the first elements, and there's at most elements, so we ignore them all - nothing to do here - if (mgr.GetThreatListSize() <= offset) + if (!PrepareTargetListSelection(targetList, targetType, offset)) return; - if (targetType == SelectTargetMethod::MaxDistance || targetType == SelectTargetMethod::MinDistance) - { - for (ThreatReference const* ref : mgr.GetUnsortedThreatList()) - { - if (ref->IsOffline()) - continue; - - targetList.push_back(ref->GetVictim()); - } - } - else - { - Unit* currentVictim = mgr.GetCurrentVictim(); - if (currentVictim) - targetList.push_back(currentVictim); - - for (ThreatReference const* ref : mgr.GetSortedThreatList()) - { - if (ref->IsOffline()) - continue; - - Unit* thisTarget = ref->GetVictim(); - if (thisTarget != currentVictim) - targetList.push_back(thisTarget); - } - } - - // shortcut: the list isn't gonna get any larger - if (targetList.size() <= offset) - { - targetList.clear(); - return; - } - - // right now, list is unsorted for DISTANCE types - re-sort by SelectTargetMethod::MaxDistance - if (targetType == SelectTargetMethod::MaxDistance || targetType == SelectTargetMethod::MinDistance) - SortByDistance(targetList, targetType == SelectTargetMethod::MinDistance); - - // now the list is MAX sorted, reverse for MIN types - if (targetType == SelectTargetMethod::MinThreat) - targetList.reverse(); - - // ignore the first elements - while (offset) - { - targetList.pop_front(); - --offset; - } - // then finally filter by predicate targetList.remove_if([&predicate](Unit* target) { return !predicate(target); }); - if (targetList.size() <= num) - return; - - if (targetType == SelectTargetMethod::Random) - Trinity::Containers::RandomResize(targetList, num); - else - targetList.resize(num); + FinalizeTargetListSelection(targetList, num, targetType); } // Called when the unit enters combat @@ -340,8 +261,9 @@ class TC_GAME_API UnitAI UnitAI(UnitAI const& right) = delete; UnitAI& operator=(UnitAI const& right) = delete; - ThreatManager& GetThreatManager(); - void SortByDistance(std::list& list, bool ascending = true); + Unit* FinalizeTargetSelection(std::list& targetList, SelectTargetMethod targetType); + bool PrepareTargetListSelection(std::list& targetList, SelectTargetMethod targetType, uint32 offset); + void FinalizeTargetListSelection(std::list& targetList, uint32 num, SelectTargetMethod targetType); }; #endif diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 4625876abb9..e0c8efe8d7d 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -114,8 +114,11 @@ bool SummonList::HasEntry(uint32 entry) const return false; } -void SummonList::DoActionImpl(int32 action, StorageType const& summons) +void SummonList::DoActionImpl(int32 action, StorageType& summons, uint16 max) { + if (max) + Trinity::Containers::RandomResize(summons, max); + for (ObjectGuid const& guid : summons) { Creature* summon = ObjectAccessor::GetCreature(*_me, guid); diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index eec1ce71700..1616d3e5787 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -95,9 +95,9 @@ class TC_GAME_API SummonList void DoAction(int32 info, Predicate&& predicate, uint16 max = 0) { // We need to use a copy of SummonList here, otherwise original SummonList would be modified - StorageType listCopy = _storage; - Trinity::Containers::RandomResize(listCopy, std::forward(predicate), max); - DoActionImpl(info, listCopy); + StorageType listCopy; + std::copy_if(std::begin(_storage), std::end(_storage), std::inserter(listCopy, std::end(listCopy)), predicate); + DoActionImpl(info, listCopy, max); } void DoZoneInCombat(uint32 entry = 0); @@ -105,7 +105,7 @@ class TC_GAME_API SummonList bool HasEntry(uint32 entry) const; private: - void DoActionImpl(int32 action, StorageType const& summons); + void DoActionImpl(int32 action, StorageType& summons, uint16 max); Creature* _me; StorageType _storage; diff --git a/src/server/game/Combat/ThreatManager.cpp b/src/server/game/Combat/ThreatManager.cpp index d1eaa230139..bf859907bec 100644 --- a/src/server/game/Combat/ThreatManager.cpp +++ b/src/server/game/Combat/ThreatManager.cpp @@ -31,12 +31,18 @@ #include "ObjectAccessor.h" #include "WorldPacket.h" #include +#include #include "Hacks/boost_1_74_fibonacci_heap.h" -BOOST_1_74_FIBONACCI_HEAP_MSVC_COMPILE_FIX(ThreatManager::threat_list_heap::value_type) const CompareThreatLessThan ThreatManager::CompareThreat; +class ThreatManager::Heap : public boost::heap::fibonacci_heap> +{ +}; + +BOOST_1_74_FIBONACCI_HEAP_MSVC_COMPILE_FIX(ThreatManager::Heap::value_type) + void ThreatReference::AddThreat(float amount) { if (amount == 0.0f) @@ -153,6 +159,24 @@ void ThreatReference::UnregisterAndFree() delete this; } +class ThreatReferenceImpl : public ThreatReference +{ +public: + explicit ThreatReferenceImpl(ThreatManager* mgr, Unit* victim) : ThreatReference(mgr, victim) { } + + ThreatManager::Heap::handle_type _handle; +}; + +void ThreatReference::HeapNotifyIncreased() +{ + _mgr._sortedThreatList->increase(static_cast(this)->_handle); +} + +void ThreatReference::HeapNotifyDecreased() +{ + _mgr._sortedThreatList->decrease(static_cast(this)->_handle); +} + /*static*/ bool ThreatManager::CanHaveThreatList(Unit const* who) { Creature const* cWho = who->ToCreature(); @@ -173,7 +197,8 @@ void ThreatReference::UnregisterAndFree() return true; } -ThreatManager::ThreatManager(Unit* owner) : _owner(owner), _ownerCanHaveThreatList(false), _needClientUpdate(false), _updateTimer(THREAT_UPDATE_INTERVAL), _currentVictimRef(nullptr), _fixateRef(nullptr) +ThreatManager::ThreatManager(Unit* owner) : _owner(owner), _ownerCanHaveThreatList(false), _needClientUpdate(false), _updateTimer(THREAT_UPDATE_INTERVAL), + _sortedThreatList(std::make_unique()), _currentVictimRef(nullptr), _fixateRef(nullptr) { for (int8 i = 0; i < MAX_SPELL_SCHOOL; ++i) _singleSchoolModifiers[i] = 1.0f; @@ -182,7 +207,7 @@ ThreatManager::ThreatManager(Unit* owner) : _owner(owner), _ownerCanHaveThreatLi ThreatManager::~ThreatManager() { ASSERT(_myThreatListEntries.empty(), "ThreatManager::~ThreatManager - %s: we still have %zu things threatening us, one of them is %s.", _owner->GetGUID().ToString().c_str(), _myThreatListEntries.size(), _myThreatListEntries.begin()->first.ToString().c_str()); - ASSERT(_sortedThreatList.empty(), "ThreatManager::~ThreatManager - %s: we still have %zu things threatening us, one of them is %s.", _owner->GetGUID().ToString().c_str(), _sortedThreatList.size(), (*_sortedThreatList.begin())->GetVictim()->GetGUID().ToString().c_str()); + ASSERT(_sortedThreatList->empty(), "ThreatManager::~ThreatManager - %s: we still have %zu things threatening us, one of them is %s.", _owner->GetGUID().ToString().c_str(), _sortedThreatList->size(), (*_sortedThreatList->begin())->GetVictim()->GetGUID().ToString().c_str()); ASSERT(_threatenedByMe.empty(), "ThreatManager::~ThreatManager - %s: we are still threatening %zu things, one of them is %s.", _owner->GetGUID().ToString().c_str(), _threatenedByMe.size(), _threatenedByMe.begin()->first.ToString().c_str()); } @@ -221,7 +246,7 @@ Unit* ThreatManager::GetLastVictim() const Unit* ThreatManager::GetAnyTarget() const { - for (ThreatReference const* ref : _sortedThreatList) + for (ThreatReference const* ref : *_sortedThreatList) if (!ref->IsOffline()) return ref->GetVictim(); return nullptr; @@ -230,8 +255,8 @@ Unit* ThreatManager::GetAnyTarget() const bool ThreatManager::IsThreatListEmpty(bool includeOffline) const { if (includeOffline) - return _sortedThreatList.empty(); - for (ThreatReference const* ref : _sortedThreatList) + return _sortedThreatList->empty(); + for (ThreatReference const* ref : *_sortedThreatList) if (ref->IsAvailable()) return false; return true; @@ -254,11 +279,44 @@ float ThreatManager::GetThreat(Unit const* who, bool includeOffline) const return (includeOffline || it->second->IsAvailable()) ? it->second->GetThreat() : 0.0f; } +size_t ThreatManager::GetThreatListSize() const +{ + return _sortedThreatList->size(); +} + +Trinity::IteratorPair ThreatManager::GetUnsortedThreatList() const +{ + auto itr = _myThreatListEntries.begin(); + auto end = _myThreatListEntries.end(); + std::function generator = [itr, end]() mutable -> ThreatReference const* + { + if (itr == end) + return nullptr; + + return (itr++)->second; + }; + return { ThreatListIterator{ std::move(generator) }, nullptr }; +} + +Trinity::IteratorPair ThreatManager::GetSortedThreatList() const +{ + auto itr = _sortedThreatList->ordered_begin(); + auto end = _sortedThreatList->ordered_end(); + std::function generator = [itr, end]() mutable -> ThreatReference const* + { + if (itr == end) + return nullptr; + + return *(itr++); + }; + return { ThreatListIterator{ std::move(generator) }, nullptr }; +} + std::vector ThreatManager::GetModifiableThreatList() { std::vector list; list.reserve(_myThreatListEntries.size()); - for (auto it = _sortedThreatList.ordered_begin(), end = _sortedThreatList.ordered_end(); it != end; ++it) + for (auto it = _sortedThreatList->ordered_begin(), end = _sortedThreatList->ordered_end(); it != end; ++it) list.push_back(const_cast(*it)); return list; } @@ -407,7 +465,7 @@ void ThreatManager::AddThreat(Unit* target, float amount, SpellInfo const* spell } // ok, we're now in combat - create the threat list reference and push it to the respective managers - ThreatReference* ref = new ThreatReference(this, target); + ThreatReference* ref = new ThreatReferenceImpl(this, target); PutThreatListRef(target->GetGUID(), ref); target->GetThreatManager().PutThreatenedByMeRef(_owner->GetGUID(), ref); @@ -430,10 +488,10 @@ void ThreatManager::ScaleThreat(Unit* target, float factor) void ThreatManager::MatchUnitThreatToHighestThreat(Unit* target) { - if (_sortedThreatList.empty()) + if (_sortedThreatList->empty()) return; - auto it = _sortedThreatList.ordered_begin(), end = _sortedThreatList.ordered_end(); + auto it = _sortedThreatList->ordered_begin(), end = _sortedThreatList->ordered_end(); ThreatReference const* highest = *it; if (!highest->IsAvailable()) return; @@ -542,7 +600,7 @@ void ThreatManager::UpdateVictim() ThreatReference const* ThreatManager::ReselectVictim() { - if (_sortedThreatList.empty()) + if (_sortedThreatList->empty()) return nullptr; for (auto const& pair : _myThreatListEntries) @@ -556,7 +614,7 @@ ThreatReference const* ThreatManager::ReselectVictim() if (oldVictimRef && oldVictimRef->IsOffline()) oldVictimRef = nullptr; // in 99% of cases - we won't need to actually look at anything beyond the first element - ThreatReference const* highest = _sortedThreatList.top(); + ThreatReference const* highest = _sortedThreatList->top(); // if the highest reference is offline, the entire list is offline, and we indicate this if (!highest->IsAvailable()) return nullptr; @@ -574,7 +632,7 @@ ThreatReference const* ThreatManager::ReselectVictim() return highest; // If we get here, highest threat is ranged, but below 130% of current - there might be a melee that breaks 110% below us somewhere, so now we need to actually look at the next highest element // luckily, this is a heap, so getting the next highest element is O(log n), and we're just gonna do that repeatedly until we've seen enough targets (or find a target) - auto it = _sortedThreatList.ordered_begin(), end = _sortedThreatList.ordered_end(); + auto it = _sortedThreatList->ordered_begin(), end = _sortedThreatList->ordered_end(); while (it != end) { ThreatReference const* next = *it; @@ -781,14 +839,14 @@ void ThreatManager::SendRemoveToClients(Unit const* victim) const void ThreatManager::SendThreatListToClients(bool newHighest) const { - WorldPacket data(newHighest ? SMSG_HIGHEST_THREAT_UPDATE : SMSG_THREAT_UPDATE, (_sortedThreatList.size() + 2) * 8); // guess + WorldPacket data(newHighest ? SMSG_HIGHEST_THREAT_UPDATE : SMSG_THREAT_UPDATE, (_sortedThreatList->size() + 2) * 8); // guess data << _owner->GetPackGUID(); if (newHighest) data << _currentVictimRef->GetVictim()->GetPackGUID(); size_t countPos = data.wpos(); data << uint32(0); // placeholder uint32 count = 0; - for (ThreatReference const* ref : _sortedThreatList) + for (ThreatReference const* ref : *_sortedThreatList) { if (!ref->IsAvailable()) continue; @@ -806,7 +864,7 @@ void ThreatManager::PutThreatListRef(ObjectGuid const& guid, ThreatReference* re auto& inMap = _myThreatListEntries[guid]; ASSERT(!inMap, "Duplicate threat reference at %p being inserted on %s for %s - memory leak!", ref, _owner->GetGUID().ToString().c_str(), guid.ToString().c_str()); inMap = ref; - ref->_handle = _sortedThreatList.push(ref); + static_cast(ref)->_handle = _sortedThreatList->push(ref); } void ThreatManager::PurgeThreatListRef(ObjectGuid const& guid) @@ -816,7 +874,7 @@ void ThreatManager::PurgeThreatListRef(ObjectGuid const& guid) return; ThreatReference* ref = it->second; _myThreatListEntries.erase(it); - _sortedThreatList.erase(ref->_handle); + _sortedThreatList->erase(static_cast(ref)->_handle); if (_fixateRef == ref) _fixateRef = nullptr; diff --git a/src/server/game/Combat/ThreatManager.h b/src/server/game/Combat/ThreatManager.h index 8e722707f91..36885802068 100644 --- a/src/server/game/Combat/ThreatManager.h +++ b/src/server/game/Combat/ThreatManager.h @@ -22,7 +22,6 @@ #include "IteratorPair.h" #include "ObjectGuid.h" #include "SharedDefines.h" -#include #include #include #include @@ -81,7 +80,7 @@ struct CompareThreatLessThan class TC_GAME_API ThreatManager { public: - typedef boost::heap::fibonacci_heap> threat_list_heap; + class Heap; class ThreatListIterator; static const uint32 THREAT_UPDATE_INTERVAL = 1000u; @@ -115,14 +114,14 @@ class TC_GAME_API ThreatManager bool IsThreatenedBy(Unit const* who, bool includeOffline = false) const; // returns ThreatReference amount if a ref exists, 0.0f otherwise float GetThreat(Unit const* who, bool includeOffline = false) const; - size_t GetThreatListSize() const { return _sortedThreatList.size(); } + size_t GetThreatListSize() const; // fastest of the three threat list getters - gets the threat list in "arbitrary" order // iterators will invalidate on adding/removing entries from the threat list; slightly less finicky than GetSorted. - Trinity::IteratorPair GetUnsortedThreatList() const { return { _myThreatListEntries.begin(), _myThreatListEntries.end() }; } + Trinity::IteratorPair GetUnsortedThreatList() const; // slightly slower than GetUnsorted, but, well...sorted - only use it if you need the sorted property, of course // this iterator pair will invalidate on any modification (even indirect) of the threat list; spell casts and similar can all induce this! // note: current tank is NOT guaranteed to be the first entry in this list - check GetLastVictim separately if you want that! - Trinity::IteratorPair GetSortedThreatList() const { return { _sortedThreatList.ordered_begin(), _sortedThreatList.ordered_end() }; } + Trinity::IteratorPair GetSortedThreatList() const; // slowest of the three threat list getters (by far), but lets you modify the threat references - this is also sorted std::vector GetModifiableThreatList(); @@ -198,7 +197,7 @@ class TC_GAME_API ThreatManager bool _needClientUpdate; uint32 _updateTimer; - threat_list_heap _sortedThreatList; + std::unique_ptr _sortedThreatList; std::unordered_map _myThreatListEntries; // AI notifies are delayed to ensure we are in a consistent state before we call out to arbitrary logic @@ -231,19 +230,26 @@ class TC_GAME_API ThreatManager class ThreatListIterator { - private: - decltype(_myThreatListEntries)::const_iterator _it; - - public: - ThreatReference const* operator*() const { return _it->second; } - ThreatReference const* operator->() const { return _it->second; } - ThreatListIterator& operator++() { ++_it; return *this; } - bool operator==(ThreatListIterator const& o) const { return _it == o._it; } - bool operator!=(ThreatListIterator const& o) const { return _it != o._it; } - ThreatListIterator(decltype(_it) it) : _it(it) {} + private: + std::function _generator; + ThreatReference const* _current; + + friend ThreatManager; + explicit ThreatListIterator(std::function&& generator) + : _generator(std::move(generator)), _current(_generator()) {} + + public: + ThreatReference const* operator*() const { return _current; } + ThreatReference const* operator->() const { return _current; } + ThreatListIterator& operator++() { _current = _generator(); return *this; } + bool operator==(ThreatListIterator const& o) const { return _current == o._current; } + bool operator!=(ThreatListIterator const& o) const { return _current != o._current; } + bool operator==(std::nullptr_t) const { return _current == nullptr; } + bool operator!=(std::nullptr_t) const { return _current != nullptr; } }; friend class ThreatReference; + friend class ThreatReferenceImpl; friend struct CompareThreatLessThan; friend class debug_commandscript; }; @@ -274,16 +280,18 @@ class TC_GAME_API ThreatReference void ClearThreat(); // dealloc's this - private: + protected: static bool FlagsAllowFighting(Unit const* a, Unit const* b); - ThreatReference(ThreatManager* mgr, Unit* victim) : + explicit ThreatReference(ThreatManager* mgr, Unit* victim) : _owner(reinterpret_cast(mgr->_owner)), _mgr(*mgr), _victim(victim), _baseAmount(0.0f), _tempModifier(0), _taunted(TAUNT_STATE_NONE) { _online = ONLINE_STATE_OFFLINE; } + virtual ~ThreatReference() = default; + void UnregisterAndFree(); bool ShouldBeOffline() const; @@ -291,14 +299,13 @@ class TC_GAME_API ThreatReference void UpdateTauntState(TauntState state = TAUNT_STATE_NONE); Creature* const _owner; ThreatManager& _mgr; - void HeapNotifyIncreased() { _mgr._sortedThreatList.increase(_handle); } - void HeapNotifyDecreased() { _mgr._sortedThreatList.decrease(_handle); } + void HeapNotifyIncreased(); + void HeapNotifyDecreased(); Unit* const _victim; OnlineState _online; float _baseAmount; int32 _tempModifier; // Temporary effects (auras with SPELL_AURA_MOD_TOTAL_THREAT) - set from victim's threatmanager in ThreatManager::UpdateMyTempModifiers TauntState _taunted; - ThreatManager::threat_list_heap::handle_type _handle; public: ThreatReference(ThreatReference const&) = delete; diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index a206b6529d0..cf358105825 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -48,11 +48,11 @@ #include "Weather.h" #include "WeatherMgr.h" #include "World.h" +#include #include #include #include "Hacks/boost_1_74_fibonacci_heap.h" -BOOST_1_74_FIBONACCI_HEAP_MSVC_COMPILE_FIX(RespawnListContainer::value_type) u_map_magic MapMagic = { {'M','A','P','S'} }; uint32 MapVersionMagic = 10; @@ -72,6 +72,20 @@ GridState* si_GridStates[MAX_GRID_STATE]; ZoneDynamicInfo::ZoneDynamicInfo() : MusicId(0), DefaultWeather(nullptr), WeatherId(WEATHER_STATE_FINE), Intensity(0.0f) { } +struct RespawnInfoWithHandle; +struct RespawnListContainer : boost::heap::fibonacci_heap> +{ +}; + +BOOST_1_74_FIBONACCI_HEAP_MSVC_COMPILE_FIX(RespawnListContainer::value_type) + +struct RespawnInfoWithHandle : RespawnInfo +{ + explicit RespawnInfoWithHandle(RespawnInfo const& other) : RespawnInfo(other) { } + + RespawnListContainer::handle_type handle; +}; + Map::~Map() { // UnloadAll must be called before deleting the map @@ -274,7 +288,7 @@ m_unloadTimer(0), m_VisibleDistance(DEFAULT_VISIBILITY_DISTANCE), m_VisibilityNotifyPeriod(DEFAULT_VISIBILITY_NOTIFY_PERIOD), m_activeNonPlayersIter(m_activeNonPlayers.end()), _transportsUpdateIter(_transports.end()), i_gridExpiry(expiry), -i_scriptLock(false), _respawnCheckTimer(0) +i_scriptLock(false), _respawnTimes(std::make_unique()), _respawnCheckTimer(0) { m_parentMap = (_parent ? _parent : this); for (unsigned int idx=0; idx < MAX_NUMBER_OF_GRIDS; ++idx) @@ -3109,7 +3123,7 @@ void Map::Respawn(RespawnInfo* info, CharacterDatabaseTransaction dbTrans) if (info->respawnTime <= GameTime::GetGameTime()) return; info->respawnTime = GameTime::GetGameTime(); - _respawnTimes.increase(info->handle); + _respawnTimes->increase(static_cast(info)->handle); SaveRespawnInfoDB(*info, dbTrans); } @@ -3163,8 +3177,8 @@ bool Map::AddRespawnInfo(RespawnInfo const& info) else ABORT_MSG("Invalid respawn info for spawn id (%u,%u) being inserted", uint32(info.type), info.spawnId); - RespawnInfo * ri = new RespawnInfo(info); - ri->handle = _respawnTimes.push(ri); + RespawnInfoWithHandle* ri = new RespawnInfoWithHandle(info); + ri->handle = _respawnTimes->push(ri); bySpawnIdMap.emplace(ri->spawnId, ri); return true; } @@ -3195,9 +3209,9 @@ RespawnInfo* Map::GetRespawnInfo(SpawnObjectType type, ObjectGuid::LowType spawn void Map::UnloadAllRespawnInfos() // delete everything from memory { - for (RespawnInfo* info : _respawnTimes) + for (RespawnInfo* info : *_respawnTimes) delete info; - _respawnTimes.clear(); + _respawnTimes->clear(); _creatureRespawnTimesBySpawnId.clear(); _gameObjectRespawnTimesBySpawnId.clear(); } @@ -3215,7 +3229,7 @@ void Map::DeleteRespawnInfo(RespawnInfo* info, CharacterDatabaseTransaction dbTr spawnMap.erase(it); // respawn heap - _respawnTimes.erase(info->handle); + _respawnTimes->erase(static_cast(info)->handle); // database DeleteRespawnInfoFromDB(info->type, info->spawnId, dbTrans); @@ -3263,16 +3277,16 @@ void Map::DoRespawn(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 gr void Map::ProcessRespawns() { time_t now = GameTime::GetGameTime(); - while (!_respawnTimes.empty()) + while (!_respawnTimes->empty()) { - RespawnInfo* next = _respawnTimes.top(); + RespawnInfoWithHandle* next = _respawnTimes->top(); if (now < next->respawnTime) // done for this tick break; if (uint32 poolId = sPoolMgr->IsPartOfAPool(next->type, next->spawnId)) // is this part of a pool? { // if yes, respawn will be handled by (external) pooling logic, just delete the respawn time // step 1: remove entry from maps to avoid it being reachable by outside logic - _respawnTimes.pop(); + _respawnTimes->pop(); GetRespawnMapForType(next->type).erase(next->spawnId); // step 2: tell pooling logic to do its thing @@ -3285,7 +3299,7 @@ void Map::ProcessRespawns() else if (CheckRespawn(next)) // see if we're allowed to respawn { // ok, respawn // step 1: remove entry from maps to avoid it being reachable by outside logic - _respawnTimes.pop(); + _respawnTimes->pop(); GetRespawnMapForType(next->type).erase(next->spawnId); // step 2: do the respawn, which involves external logic @@ -3297,7 +3311,7 @@ void Map::ProcessRespawns() } else if (!next->respawnTime) { // just remove this respawn entry without rescheduling - _respawnTimes.pop(); + _respawnTimes->pop(); GetRespawnMapForType(next->type).erase(next->spawnId); RemoveRespawnTime(next->type, next->spawnId, nullptr, true); delete next; @@ -3305,7 +3319,7 @@ void Map::ProcessRespawns() else { // new respawn time, update heap position ASSERT(now < next->respawnTime); // infinite loop guard - _respawnTimes.decrease(next->handle); + _respawnTimes->decrease(next->handle); SaveRespawnInfoDB(*next); } } diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 66c8e0c9059..bf013d0d6ad 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -32,7 +32,6 @@ #include "SpawnData.h" #include "Timer.h" #include "Transaction.h" -#include #include #include #include @@ -293,8 +292,7 @@ struct CompareRespawnInfo bool operator()(RespawnInfo const* a, RespawnInfo const* b) const; }; using ZoneDynamicInfoMap = std::unordered_map; -using RespawnListContainer = boost::heap::fibonacci_heap>; -using RespawnListHandle = RespawnListContainer::handle_type; +struct RespawnListContainer; using RespawnInfoMap = std::unordered_map; struct RespawnInfo { @@ -303,7 +301,6 @@ struct RespawnInfo uint32 entry; time_t respawnTime; uint32 gridId; - RespawnListHandle handle; }; inline bool CompareRespawnInfo::operator()(RespawnInfo const* a, RespawnInfo const* b) const { @@ -845,7 +842,7 @@ class TC_GAME_API Map : public GridRefManager m_activeNonPlayers.erase(obj); } - RespawnListContainer _respawnTimes; + std::unique_ptr _respawnTimes; RespawnInfoMap _creatureRespawnTimesBySpawnId; RespawnInfoMap _gameObjectRespawnTimesBySpawnId; RespawnInfoMap& GetRespawnMapForType(SpawnObjectType type) diff --git a/tests/game/ThreatListIterator.cpp b/tests/game/ThreatListIterator.cpp new file mode 100644 index 00000000000..7121b783579 --- /dev/null +++ b/tests/game/ThreatListIterator.cpp @@ -0,0 +1,65 @@ +/* + * 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 . + */ + +#include "tc_catch2.h" + +#include "IteratorPair.h" + +class ThreatListIterator +{ +private: + std::function _generator; + int const* _current; + +public: + explicit ThreatListIterator(std::function&& generator) + : _generator(std::move(generator)), _current(_generator()) + { } + + int const* operator*() const { return _current; } + int const* operator->() const { return _current; } + ThreatListIterator& operator++() { _current = _generator(); return *this; } + bool operator==(ThreatListIterator const& o) const { return _current == o._current; } + bool operator!=(ThreatListIterator const& o) const { return _current != o._current; } + bool operator==(std::nullptr_t) const { return _current == nullptr; } + bool operator!=(std::nullptr_t) const { return _current != nullptr; } +}; + +std::vector ints{ 1, 2, 3, 4 }; + +Trinity::IteratorPair GetUnsortedThreatList() +{ + auto itr = ints.begin(); + auto end = ints.end(); + std::function generator = [itr, end]() mutable -> int const* + { + if (itr == end) + return nullptr; + + return &*(itr++); + }; + return { ThreatListIterator{ std::move(generator) }, nullptr }; +} + +TEST_CASE("Check generator logic", "[ThreatListIterator]") +{ + std::vector iterated; + for (int const* i : GetUnsortedThreatList()) + iterated.push_back(*i); + + REQUIRE(iterated == ints); +} From ad3fc81db9cfb899fc72dfef175cd897c9a4b05c Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 12 Aug 2023 15:54:57 +0200 Subject: [PATCH 11/17] Core/Misc: Add missing Containers.h include where neccessary --- src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 1 + src/server/game/AI/SmartScripts/SmartScript.cpp | 1 + src/server/game/Combat/CombatManager.cpp | 1 + src/server/game/Entities/Creature/Creature.cpp | 1 + src/server/game/Entities/GameObject/GameObject.cpp | 1 + src/server/game/Entities/Player/Player.cpp | 1 + src/server/game/Entities/Unit/Unit.cpp | 1 + src/server/game/Spells/Spell.cpp | 1 + src/server/game/Texts/CreatureTextMgr.cpp | 1 + .../BlackrockDepths/boss_coren_direbrew.cpp | 1 + .../BlackrockMountain/MoltenCore/boss_shazzrah.cpp | 1 + .../MoltenCore/boss_sulfuron_harbinger.cpp | 1 + .../EasternKingdoms/Karazhan/boss_midnight.cpp | 1 + .../EasternKingdoms/Karazhan/boss_moroes.cpp | 1 + .../Karazhan/boss_prince_malchezaar.cpp | 1 + .../ScarletMonastery/boss_headless_horseman.cpp | 1 + .../ShadowfangKeep/boss_apothecary_hummel.cpp | 1 + .../EasternKingdoms/ZulAman/boss_hexlord.cpp | 1 + .../scripts/EasternKingdoms/zone_elwynn_forest.cpp | 1 + src/server/scripts/Events/childrens_week.cpp | 1 + src/server/scripts/Events/hallows_end.cpp | 1 + src/server/scripts/Events/love_is_in_the_air.cpp | 1 + src/server/scripts/Events/winter_veil.cpp | 1 + .../CullingOfStratholme/npc_arthas.cpp | 1 + .../scripts/Kalimdor/RuinsOfAhnQiraj/boss_moam.cpp | 1 + .../scripts/Kalimdor/zone_bloodmyst_isle.cpp | 1 + .../Ahnkahet/boss_jedoga_shadowseeker.cpp | 1 + .../AzjolNerub/AzjolNerub/boss_anubarak.cpp | 1 + .../ObsidianSanctum/boss_sartharion.cpp | 1 + .../ChamberOfAspects/RubySanctum/boss_halion.cpp | 1 + .../RubySanctum/boss_saviana_ragefire.cpp | 1 + .../TrialOfTheChampion/boss_argent_challenge.cpp | 1 + .../TrialOfTheCrusader/boss_lord_jaraxxus.cpp | 1 + .../ForgeOfSouls/boss_devourer_of_souls.cpp | 1 + .../instance_halls_of_reflection.cpp | 1 + .../IcecrownCitadel/boss_blood_queen_lana_thel.cpp | 9 +++++---- .../IcecrownCitadel/boss_deathbringer_saurfang.cpp | 3 ++- .../Northrend/IcecrownCitadel/boss_festergut.cpp | 3 ++- .../boss_icecrown_gunship_battle.cpp | 12 ++++++------ .../IcecrownCitadel/boss_lady_deathwhisper.cpp | 5 +++-- .../IcecrownCitadel/boss_lord_marrowgar.cpp | 2 +- .../IcecrownCitadel/boss_professor_putricide.cpp | 5 +++-- .../Northrend/IcecrownCitadel/boss_rotface.cpp | 5 +++-- .../Northrend/IcecrownCitadel/boss_sindragosa.cpp | 5 ++++- .../IcecrownCitadel/boss_sister_svalna.cpp | 14 ++------------ .../IcecrownCitadel/boss_the_lich_king.cpp | 6 +++--- .../IcecrownCitadel/boss_valithria_dreamwalker.cpp | 8 ++++---- .../go_icecrown_citadel_teleport.cpp | 1 + .../Northrend/IcecrownCitadel/icecrown_citadel.cpp | 6 ++---- .../IcecrownCitadel/instance_icecrown_citadel.cpp | 1 + .../Northrend/Naxxramas/boss_anubrekhan.cpp | 1 + .../Northrend/Nexus/EyeOfEternity/boss_malygos.cpp | 1 + .../Ulduar/Ulduar/boss_algalon_the_observer.cpp | 1 + .../Ulduar/Ulduar/boss_flame_leviathan.cpp | 1 + .../Northrend/Ulduar/Ulduar/boss_general_vezax.cpp | 1 + .../Northrend/Ulduar/Ulduar/boss_mimiron.cpp | 1 + .../Northrend/Ulduar/Ulduar/boss_thorim.cpp | 1 + .../scripts/Northrend/Ulduar/Ulduar/boss_xt002.cpp | 1 + .../Northrend/VaultOfArchavon/boss_emalon.cpp | 1 + .../scripts/Northrend/VioletHold/boss_xevozz.cpp | 1 + .../scripts/Northrend/zone_borean_tundra.cpp | 1 + src/server/scripts/Northrend/zone_dalaran.cpp | 1 + .../scripts/Northrend/zone_howling_fjord.cpp | 1 + src/server/scripts/Northrend/zone_icecrown.cpp | 1 + .../SethekkHalls/boss_talon_king_ikiss.cpp | 1 + .../ShadowLabyrinth/boss_grandmaster_vorpil.cpp | 1 + .../scripts/Outland/BlackTemple/boss_illidan.cpp | 1 + .../Outland/BlackTemple/boss_illidari_council.cpp | 1 + .../BlackTemple/boss_reliquary_of_souls.cpp | 1 + .../CoilfangReservoir/TheSlavePens/boss_ahune.cpp | 1 + .../HellfireCitadel/BloodFurnace/boss_broggok.cpp | 1 + .../scripts/Outland/zone_hellfire_peninsula.cpp | 1 + src/server/scripts/Outland/zone_netherstorm.cpp | 1 + .../scripts/Outland/zone_terokkar_forest.cpp | 1 + src/server/scripts/Pet/pet_hunter.cpp | 1 + src/server/scripts/Spells/spell_generic.cpp | 1 + src/server/scripts/World/npcs_special.cpp | 1 + 77 files changed, 104 insertions(+), 43 deletions(-) diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index e0c8efe8d7d..2a4f0908be5 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -19,6 +19,7 @@ #include "AreaBoundary.h" #include "Cell.h" #include "CellImpl.h" +#include "Containers.h" #include "DBCStores.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index c4087ed21cf..ec51e8b3dc6 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -18,6 +18,7 @@ #include "SmartScript.h" #include "CellImpl.h" #include "ChatTextBuilder.h" +#include "Containers.h" #include "Creature.h" #include "CreatureTextMgr.h" #include "CreatureTextMgrImpl.h" diff --git a/src/server/game/Combat/CombatManager.cpp b/src/server/game/Combat/CombatManager.cpp index fa297239c11..005e0d8e664 100644 --- a/src/server/game/Combat/CombatManager.cpp +++ b/src/server/game/Combat/CombatManager.cpp @@ -16,6 +16,7 @@ */ #include "CombatManager.h" +#include "Containers.h" #include "Creature.h" #include "Unit.h" #include "CreatureAI.h" diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 0b0d343830b..9194d1f7641 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -19,6 +19,7 @@ #include "BattlegroundMgr.h" #include "CellImpl.h" #include "Common.h" +#include "Containers.h" #include "CreatureAI.h" #include "CreatureAISelector.h" #include "CreatureGroups.h" diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 27b3afc81e7..7ea636fe75b 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -18,6 +18,7 @@ #include "GameObject.h" #include "Battleground.h" #include "CellImpl.h" +#include "Containers.h" #include "CreatureAISelector.h" #include "DatabaseEnv.h" #include "GameObjectAI.h" diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 1eceae7f9bc..8f51ddc2b08 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -37,6 +37,7 @@ #include "CombatPackets.h" #include "Common.h" #include "ConditionMgr.h" +#include "Containers.h" #include "CreatureAI.h" #include "DatabaseEnv.h" #include "DisableMgr.h" diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index be5927abd26..d7ec00b2a09 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -29,6 +29,7 @@ #include "CombatPackets.h" #include "Common.h" #include "ConditionMgr.h" +#include "Containers.h" #include "CreatureAI.h" #include "CreatureAIImpl.h" #include "CreatureGroups.h" diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index ecc4855eacd..6f9a62ee806 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -22,6 +22,7 @@ #include "CellImpl.h" #include "Common.h" #include "ConditionMgr.h" +#include "Containers.h" #include "DatabaseEnv.h" #include "DBCStores.h" #include "DisableMgr.h" diff --git a/src/server/game/Texts/CreatureTextMgr.cpp b/src/server/game/Texts/CreatureTextMgr.cpp index 5d37aa2f507..ba0592ab147 100644 --- a/src/server/game/Texts/CreatureTextMgr.cpp +++ b/src/server/game/Texts/CreatureTextMgr.cpp @@ -20,6 +20,7 @@ #include "CellImpl.h" #include "Chat.h" #include "Common.h" +#include "Containers.h" #include "DatabaseEnv.h" #include "DBCStores.h" #include "GridNotifiersImpl.h" diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_coren_direbrew.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_coren_direbrew.cpp index 67c8444e607..f4fee8fa86a 100644 --- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_coren_direbrew.cpp +++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_coren_direbrew.cpp @@ -17,6 +17,7 @@ #include "ScriptMgr.h" #include "blackrock_depths.h" +#include "Containers.h" #include "GameObjectAI.h" #include "GridNotifiers.h" #include "Group.h" diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_shazzrah.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_shazzrah.cpp index 941813f36c8..78946546c00 100644 --- a/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_shazzrah.cpp +++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_shazzrah.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "molten_core.h" #include "ScriptedCreature.h" #include "SpellScript.h" diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_sulfuron_harbinger.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_sulfuron_harbinger.cpp index 0964034fc8d..8dbcdde8d57 100644 --- a/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_sulfuron_harbinger.cpp +++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_sulfuron_harbinger.cpp @@ -23,6 +23,7 @@ SDCategory: Molten Core EndScriptData */ #include "ScriptMgr.h" +#include "Containers.h" #include "molten_core.h" #include "ObjectMgr.h" #include "ScriptedCreature.h" diff --git a/src/server/scripts/EasternKingdoms/Karazhan/boss_midnight.cpp b/src/server/scripts/EasternKingdoms/Karazhan/boss_midnight.cpp index a6d81bf851c..bda652002c2 100644 --- a/src/server/scripts/EasternKingdoms/Karazhan/boss_midnight.cpp +++ b/src/server/scripts/EasternKingdoms/Karazhan/boss_midnight.cpp @@ -23,6 +23,7 @@ SDCategory: Karazhan EndScriptData */ #include "ScriptMgr.h" +#include "Containers.h" #include "karazhan.h" #include "MotionMaster.h" #include "ObjectAccessor.h" diff --git a/src/server/scripts/EasternKingdoms/Karazhan/boss_moroes.cpp b/src/server/scripts/EasternKingdoms/Karazhan/boss_moroes.cpp index e8ca9296103..20bfda0099d 100644 --- a/src/server/scripts/EasternKingdoms/Karazhan/boss_moroes.cpp +++ b/src/server/scripts/EasternKingdoms/Karazhan/boss_moroes.cpp @@ -23,6 +23,7 @@ SDCategory: Karazhan EndScriptData */ #include "ScriptMgr.h" +#include "Containers.h" #include "karazhan.h" #include "InstanceScript.h" #include "ObjectAccessor.h" diff --git a/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp b/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp index 31a8fdf8a00..55d4bd348bd 100644 --- a/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp +++ b/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp @@ -23,6 +23,7 @@ SDCategory: Karazhan EndScriptData */ #include "ScriptMgr.h" +#include "Containers.h" #include "karazhan.h" #include "InstanceScript.h" #include "ObjectAccessor.h" diff --git a/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_headless_horseman.cpp b/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_headless_horseman.cpp index 9bb3b7c0a00..0c280e3c321 100644 --- a/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_headless_horseman.cpp +++ b/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_headless_horseman.cpp @@ -16,6 +16,7 @@ */ #include "scarlet_monastery.h" +#include "Containers.h" #include "CreatureTextMgr.h" #include "GameObject.h" #include "GameObjectAI.h" diff --git a/src/server/scripts/EasternKingdoms/ShadowfangKeep/boss_apothecary_hummel.cpp b/src/server/scripts/EasternKingdoms/ShadowfangKeep/boss_apothecary_hummel.cpp index 8531267112a..2babe0a7e80 100644 --- a/src/server/scripts/EasternKingdoms/ShadowfangKeep/boss_apothecary_hummel.cpp +++ b/src/server/scripts/EasternKingdoms/ShadowfangKeep/boss_apothecary_hummel.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "GridNotifiersImpl.h" #include "Group.h" #include "InstanceScript.h" diff --git a/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp b/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp index 8f1116c7c71..36e1f7496fb 100644 --- a/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp +++ b/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp @@ -23,6 +23,7 @@ SDCategory: Zul'Aman EndScriptData */ #include "ScriptMgr.h" +#include "Containers.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "ObjectAccessor.h" diff --git a/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp b/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp index ebe2e29554f..009af793d19 100644 --- a/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp +++ b/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "MotionMaster.h" #include "ObjectAccessor.h" #include "GameEventMgr.h" diff --git a/src/server/scripts/Events/childrens_week.cpp b/src/server/scripts/Events/childrens_week.cpp index b4dc1f6beae..5c586ab55e8 100644 --- a/src/server/scripts/Events/childrens_week.cpp +++ b/src/server/scripts/Events/childrens_week.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "MotionMaster.h" #include "ObjectAccessor.h" #include "Player.h" diff --git a/src/server/scripts/Events/hallows_end.cpp b/src/server/scripts/Events/hallows_end.cpp index 1ed0500eb40..3744aaca6ed 100644 --- a/src/server/scripts/Events/hallows_end.cpp +++ b/src/server/scripts/Events/hallows_end.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "CreatureAIImpl.h" #include "Player.h" #include "ScriptedCreature.h" diff --git a/src/server/scripts/Events/love_is_in_the_air.cpp b/src/server/scripts/Events/love_is_in_the_air.cpp index 9eb84ce21d3..c79aea25f16 100644 --- a/src/server/scripts/Events/love_is_in_the_air.cpp +++ b/src/server/scripts/Events/love_is_in_the_air.cpp @@ -17,6 +17,7 @@ #include "ScriptMgr.h" #include "CellImpl.h" +#include "Containers.h" #include "CreatureAIImpl.h" #include "GridNotifiersImpl.h" #include "Player.h" diff --git a/src/server/scripts/Events/winter_veil.cpp b/src/server/scripts/Events/winter_veil.cpp index cce3d07bf52..f54eb12457c 100644 --- a/src/server/scripts/Events/winter_veil.cpp +++ b/src/server/scripts/Events/winter_veil.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "CreatureAIImpl.h" #include "Player.h" #include "ScriptedCreature.h" diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/npc_arthas.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/npc_arthas.cpp index f0e5ba85aef..4c12db12493 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/npc_arthas.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/npc_arthas.cpp @@ -16,6 +16,7 @@ */ #include "culling_of_stratholme.h" +#include "Containers.h" #include "GameObject.h" #include "InstanceScript.h" #include "Log.h" diff --git a/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_moam.cpp b/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_moam.cpp index ad1294edc99..484144c389b 100644 --- a/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_moam.cpp +++ b/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_moam.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "ScriptedCreature.h" #include "ruins_of_ahnqiraj.h" diff --git a/src/server/scripts/Kalimdor/zone_bloodmyst_isle.cpp b/src/server/scripts/Kalimdor/zone_bloodmyst_isle.cpp index 7cf2891403e..7702167c291 100644 --- a/src/server/scripts/Kalimdor/zone_bloodmyst_isle.cpp +++ b/src/server/scripts/Kalimdor/zone_bloodmyst_isle.cpp @@ -17,6 +17,7 @@ #include "ScriptMgr.h" #include "CellImpl.h" +#include "Containers.h" #include "GridNotifiersImpl.h" #include "Group.h" #include "MotionMaster.h" diff --git a/src/server/scripts/Northrend/AzjolNerub/Ahnkahet/boss_jedoga_shadowseeker.cpp b/src/server/scripts/Northrend/AzjolNerub/Ahnkahet/boss_jedoga_shadowseeker.cpp index 8f8202d30c4..ecac6e679fb 100644 --- a/src/server/scripts/Northrend/AzjolNerub/Ahnkahet/boss_jedoga_shadowseeker.cpp +++ b/src/server/scripts/Northrend/AzjolNerub/Ahnkahet/boss_jedoga_shadowseeker.cpp @@ -16,6 +16,7 @@ */ #include "ahnkahet.h" +#include "Containers.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "ObjectAccessor.h" diff --git a/src/server/scripts/Northrend/AzjolNerub/AzjolNerub/boss_anubarak.cpp b/src/server/scripts/Northrend/AzjolNerub/AzjolNerub/boss_anubarak.cpp index c8100dfc797..4082d324c9a 100644 --- a/src/server/scripts/Northrend/AzjolNerub/AzjolNerub/boss_anubarak.cpp +++ b/src/server/scripts/Northrend/AzjolNerub/AzjolNerub/boss_anubarak.cpp @@ -18,6 +18,7 @@ #include "ScriptMgr.h" #include "AreaBoundary.h" #include "azjol_nerub.h" +#include "Containers.h" #include "GameObject.h" #include "InstanceScript.h" #include "MotionMaster.h" diff --git a/src/server/scripts/Northrend/ChamberOfAspects/ObsidianSanctum/boss_sartharion.cpp b/src/server/scripts/Northrend/ChamberOfAspects/ObsidianSanctum/boss_sartharion.cpp index 89083426350..f822e458231 100644 --- a/src/server/scripts/Northrend/ChamberOfAspects/ObsidianSanctum/boss_sartharion.cpp +++ b/src/server/scripts/Northrend/ChamberOfAspects/ObsidianSanctum/boss_sartharion.cpp @@ -17,6 +17,7 @@ #include "ScriptMgr.h" #include "CellImpl.h" +#include "Containers.h" #include "GridNotifiersImpl.h" #include "InstanceScript.h" #include "MotionMaster.h" diff --git a/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_halion.cpp b/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_halion.cpp index 22c59cfeb48..e600dd9c88c 100644 --- a/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_halion.cpp +++ b/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_halion.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "DBCStores.h" #include "GameObject.h" #include "GameObjectAI.h" diff --git a/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_saviana_ragefire.cpp b/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_saviana_ragefire.cpp index 790cf502574..6cd0f835c9b 100644 --- a/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_saviana_ragefire.cpp +++ b/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_saviana_ragefire.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "Map.h" #include "MotionMaster.h" #include "ruby_sanctum.h" diff --git a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheChampion/boss_argent_challenge.cpp b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheChampion/boss_argent_challenge.cpp index dbbdb2eb37a..8f2aa82f273 100644 --- a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheChampion/boss_argent_challenge.cpp +++ b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheChampion/boss_argent_challenge.cpp @@ -23,6 +23,7 @@ SDCategory: Trial of the Champion EndScriptData */ #include "ScriptMgr.h" +#include "Containers.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "ObjectAccessor.h" diff --git a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_lord_jaraxxus.cpp b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_lord_jaraxxus.cpp index 4a09f73bae2..fa1b4fc11c7 100644 --- a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_lord_jaraxxus.cpp +++ b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_lord_jaraxxus.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "Player.h" diff --git a/src/server/scripts/Northrend/FrozenHalls/ForgeOfSouls/boss_devourer_of_souls.cpp b/src/server/scripts/Northrend/FrozenHalls/ForgeOfSouls/boss_devourer_of_souls.cpp index 5b63c77bffc..d96ac600698 100644 --- a/src/server/scripts/Northrend/FrozenHalls/ForgeOfSouls/boss_devourer_of_souls.cpp +++ b/src/server/scripts/Northrend/FrozenHalls/ForgeOfSouls/boss_devourer_of_souls.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "forge_of_souls.h" #include "InstanceScript.h" #include "Map.h" diff --git a/src/server/scripts/Northrend/FrozenHalls/HallsOfReflection/instance_halls_of_reflection.cpp b/src/server/scripts/Northrend/FrozenHalls/HallsOfReflection/instance_halls_of_reflection.cpp index a6301396b1f..6d2b7a36979 100644 --- a/src/server/scripts/Northrend/FrozenHalls/HallsOfReflection/instance_halls_of_reflection.cpp +++ b/src/server/scripts/Northrend/FrozenHalls/HallsOfReflection/instance_halls_of_reflection.cpp @@ -16,6 +16,7 @@ */ #include "halls_of_reflection.h" +#include "Containers.h" #include "InstanceScript.h" #include "Map.h" #include "Player.h" diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_blood_queen_lana_thel.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_blood_queen_lana_thel.cpp index fd37731f973..eda41e694f0 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_blood_queen_lana_thel.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_blood_queen_lana_thel.cpp @@ -15,18 +15,19 @@ * with this program. If not, see . */ -#include "ScriptMgr.h" -#include "GridNotifiers.h" #include "icecrown_citadel.h" +#include "Containers.h" +#include "GridNotifiers.h" #include "InstanceScript.h" #include "Map.h" #include "MotionMaster.h" #include "ObjectAccessor.h" +#include "Player.h" #include "ScriptedCreature.h" -#include "Spell.h" +#include "ScriptMgr.h" +#include "SpellAuraEffects.h" #include "SpellMgr.h" #include "SpellScript.h" -#include "SpellAuraEffects.h" enum Texts { diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_deathbringer_saurfang.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_deathbringer_saurfang.cpp index bd75bdb7929..209dd71150b 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_deathbringer_saurfang.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_deathbringer_saurfang.cpp @@ -15,14 +15,15 @@ * with this program. If not, see . */ -#include "ScriptMgr.h" #include "icecrown_citadel.h" +#include "Containers.h" #include "InstanceScript.h" #include "Map.h" #include "MotionMaster.h" #include "ObjectAccessor.h" #include "ScriptedCreature.h" #include "ScriptedGossip.h" +#include "ScriptMgr.h" #include "SpellAuras.h" #include "SpellScript.h" diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_festergut.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_festergut.cpp index 9d97075c789..1392186e23f 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_festergut.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_festergut.cpp @@ -15,13 +15,14 @@ * with this program. If not, see . */ -#include "ScriptMgr.h" #include "icecrown_citadel.h" +#include "Containers.h" #include "InstanceScript.h" #include "Map.h" #include "ObjectAccessor.h" #include "Player.h" #include "ScriptedCreature.h" +#include "ScriptMgr.h" #include "SpellAuras.h" #include "SpellMgr.h" #include "SpellScript.h" diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp index 36324199d84..24ce5a81eb9 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp @@ -15,26 +15,26 @@ * with this program. If not, see . */ -#include "ScriptMgr.h" +#include "icecrown_citadel.h" #include "CellImpl.h" +#include "Containers.h" #include "CreatureTextMgr.h" -#include "GossipDef.h" #include "GridNotifiersImpl.h" -#include "icecrown_citadel.h" #include "InstanceScript.h" +#include "Map.h" #include "MotionMaster.h" -#include "MoveSpline.h" #include "MoveSplineInit.h" #include "ObjectAccessor.h" #include "PassiveAI.h" #include "ScriptedCreature.h" +#include "ScriptedGossip.h" +#include "ScriptMgr.h" #include "SpellAuraEffects.h" #include "SpellHistory.h" #include "SpellMgr.h" #include "SpellScript.h" #include "TemporarySummon.h" #include "Transport.h" -#include "TransportMgr.h" #include "Vehicle.h" #include @@ -1736,7 +1736,7 @@ class spell_igb_rocket_pack : public AuraScript void HandlePeriodic(AuraEffect const* /*aurEff*/) { - if (GetTarget()->movespline->Finalized()) + if (!GetTarget()->IsSplineEnabled()) Remove(AURA_REMOVE_BY_EXPIRE); } diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_lady_deathwhisper.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_lady_deathwhisper.cpp index 81aca39d354..cbbcbb0446d 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_lady_deathwhisper.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_lady_deathwhisper.cpp @@ -15,15 +15,16 @@ * with this program. If not, see . */ -#include "ScriptMgr.h" -#include "Group.h" #include "icecrown_citadel.h" +#include "Containers.h" +#include "Group.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "ObjectAccessor.h" #include "Player.h" #include "QuestPools.h" #include "ScriptedCreature.h" +#include "ScriptMgr.h" #include "SpellAuraEffects.h" #include "SpellInfo.h" #include "SpellScript.h" diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_lord_marrowgar.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_lord_marrowgar.cpp index 952ab992e02..2aa6877a392 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_lord_marrowgar.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_lord_marrowgar.cpp @@ -15,7 +15,6 @@ * with this program. If not, see . */ -#include "ScriptMgr.h" #include "icecrown_citadel.h" #include "InstanceScript.h" #include "Map.h" @@ -25,6 +24,7 @@ #include "Player.h" #include "PointMovementGenerator.h" #include "ScriptedCreature.h" +#include "ScriptMgr.h" #include "SpellAuras.h" #include "SpellScript.h" #include "TemporarySummon.h" diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_professor_putricide.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_professor_putricide.cpp index 60cc7afc273..ac7aceb2c40 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_professor_putricide.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_professor_putricide.cpp @@ -15,16 +15,17 @@ * with this program. If not, see . */ -#include "ScriptMgr.h" +#include "icecrown_citadel.h" +#include "Containers.h" #include "DBCStores.h" #include "GridNotifiers.h" #include "Group.h" -#include "icecrown_citadel.h" #include "InstanceScript.h" #include "Map.h" #include "MotionMaster.h" #include "ObjectAccessor.h" #include "ScriptedCreature.h" +#include "ScriptMgr.h" #include "Spell.h" #include "SpellAuraEffects.h" #include "SpellMgr.h" diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_rotface.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_rotface.cpp index 4942b608875..1fbae959f9f 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_rotface.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_rotface.cpp @@ -15,13 +15,14 @@ * with this program. If not, see . */ -#include "ScriptMgr.h" -#include "GridNotifiers.h" #include "icecrown_citadel.h" +#include "Containers.h" +#include "GridNotifiers.h" #include "InstanceScript.h" #include "Map.h" #include "ObjectAccessor.h" #include "ScriptedCreature.h" +#include "ScriptMgr.h" #include "SpellAuras.h" #include "SpellScript.h" #include "TemporarySummon.h" diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_sindragosa.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_sindragosa.cpp index 496f85ea76f..f8a322f54a1 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_sindragosa.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_sindragosa.cpp @@ -15,8 +15,8 @@ * with this program. If not, see . */ -#include "icecrown_citadel.h" #include "CommonHelpers.h" +#include "icecrown_citadel.h" #include "Containers.h" #include "GridNotifiers.h" #include "InstanceScript.h" @@ -26,7 +26,10 @@ #include "ObjectMgr.h" #include "ScriptedCreature.h" #include "ScriptMgr.h" +#include "Spell.h" #include "SpellAuraEffects.h" +#include "SpellAuras.h" +#include "SpellInfo.h" #include "SpellMgr.h" #include "SpellScript.h" #include "TemporarySummon.h" diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_sister_svalna.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_sister_svalna.cpp index 59a6f4791f2..3451c02529a 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_sister_svalna.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_sister_svalna.cpp @@ -17,25 +17,15 @@ #include "icecrown_citadel.h" #include "CellImpl.h" -#include "Creature.h" -#include "CreatureAI.h" -#include "CreatureData.h" -#include "EventProcessor.h" -#include "InstanceScript.h" +#include "Containers.h" #include "GridNotifiersImpl.h" -#include "Map.h" +#include "InstanceScript.h" #include "MotionMaster.h" -#include "MovementDefines.h" #include "ObjectAccessor.h" -#include "PetDefines.h" -#include "ScriptedCreature.h" #include "ScriptedEscortAI.h" #include "ScriptMgr.h" -#include "SpellDefines.h" -#include "SpellInfo.h" #include "SpellScript.h" #include "TemporarySummon.h" -#include "Unit.h" #include "VehicleDefines.h" enum ICCSisterSvalnaTexts diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp index 5dd848c2045..60e2fdd7e7e 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp @@ -15,17 +15,17 @@ * with this program. If not, see . */ -#include "ScriptMgr.h" +#include "icecrown_citadel.h" #include "CellImpl.h" +#include "Containers.h" #include "CreatureTextMgr.h" #include "DBCStores.h" #include "GridNotifiersImpl.h" -#include "icecrown_citadel.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "ObjectAccessor.h" #include "ScriptedCreature.h" -#include "Spell.h" +#include "ScriptMgr.h" #include "SpellAuraEffects.h" #include "SpellScript.h" #include "TemporarySummon.h" diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_valithria_dreamwalker.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_valithria_dreamwalker.cpp index 7da5f75564d..54aaf207e6b 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_valithria_dreamwalker.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_valithria_dreamwalker.cpp @@ -15,15 +15,15 @@ * with this program. If not, see . */ -#include "ScriptMgr.h" +#include "icecrown_citadel.h" #include "CellImpl.h" +#include "Containers.h" #include "GridNotifiersImpl.h" -#include "icecrown_citadel.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "ObjectAccessor.h" -#include "ObjectMgr.h" #include "ScriptedCreature.h" +#include "ScriptMgr.h" #include "SpellAuraEffects.h" #include "SpellScript.h" @@ -274,7 +274,7 @@ struct boss_valithria_dreamwalker : public ScriptedAI void InitializeAI() override { - if (CreatureData const* data = sObjectMgr->GetCreatureData(me->GetSpawnId())) + if (CreatureData const* data = me->GetCreatureData()) if (data->curhealth) _spawnHealth = data->curhealth; diff --git a/src/server/scripts/Northrend/IcecrownCitadel/go_icecrown_citadel_teleport.cpp b/src/server/scripts/Northrend/IcecrownCitadel/go_icecrown_citadel_teleport.cpp index ebc500029a7..50cf7d6862e 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/go_icecrown_citadel_teleport.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/go_icecrown_citadel_teleport.cpp @@ -19,6 +19,7 @@ #include "GameObject.h" #include "GameObjectAI.h" #include "InstanceScript.h" +#include "Map.h" #include "Player.h" #include "ScriptedGossip.h" #include "ScriptMgr.h" diff --git a/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp b/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp index 6c8aea53349..748337fba72 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp @@ -17,9 +17,7 @@ #include "icecrown_citadel.h" #include "CellImpl.h" -#include "Creature.h" -#include "CreatureAI.h" -#include "GameObject.h" +#include "Containers.h" #include "GameObjectAI.h" #include "GridNotifiersImpl.h" #include "InstanceScript.h" @@ -28,10 +26,10 @@ #include "PassiveAI.h" #include "ScriptedCreature.h" #include "ScriptMgr.h" +#include "SpellAuras.h" #include "SpellMgr.h" #include "SpellScript.h" #include "TemporarySummon.h" -#include "VehicleDefines.h" enum ICCTexts { diff --git a/src/server/scripts/Northrend/IcecrownCitadel/instance_icecrown_citadel.cpp b/src/server/scripts/Northrend/IcecrownCitadel/instance_icecrown_citadel.cpp index 849d8c8b54f..339406ae897 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/instance_icecrown_citadel.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/instance_icecrown_citadel.cpp @@ -19,6 +19,7 @@ #include "AreaBoundary.h" #include "Creature.h" #include "CreatureAI.h" +#include "EventMap.h" #include "InstanceScript.h" #include "Map.h" #include "ObjectMgr.h" diff --git a/src/server/scripts/Northrend/Naxxramas/boss_anubrekhan.cpp b/src/server/scripts/Northrend/Naxxramas/boss_anubrekhan.cpp index 8de4ebc2086..fff21635599 100644 --- a/src/server/scripts/Northrend/Naxxramas/boss_anubrekhan.cpp +++ b/src/server/scripts/Northrend/Naxxramas/boss_anubrekhan.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "InstanceScript.h" #include "ObjectAccessor.h" #include "naxxramas.h" diff --git a/src/server/scripts/Northrend/Nexus/EyeOfEternity/boss_malygos.cpp b/src/server/scripts/Northrend/Nexus/EyeOfEternity/boss_malygos.cpp index b8b6f9fd6c9..45970362dc1 100644 --- a/src/server/scripts/Northrend/Nexus/EyeOfEternity/boss_malygos.cpp +++ b/src/server/scripts/Northrend/Nexus/EyeOfEternity/boss_malygos.cpp @@ -21,6 +21,7 @@ Script Data End */ #include "ScriptMgr.h" #include "CombatAI.h" +#include "Containers.h" #include "CreatureTextMgr.h" #include "eye_of_eternity.h" #include "GameObject.h" diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_algalon_the_observer.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_algalon_the_observer.cpp index a2883db6550..56437f61bc0 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_algalon_the_observer.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_algalon_the_observer.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "DBCStores.h" #include "GameObject.h" #include "GameObjectAI.h" diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_flame_leviathan.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_flame_leviathan.cpp index 78387df18e8..f22345a329d 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_flame_leviathan.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_flame_leviathan.cpp @@ -25,6 +25,7 @@ #include "ScriptMgr.h" #include "CellImpl.h" #include "CombatAI.h" +#include "Containers.h" #include "GameObjectAI.h" #include "GridNotifiersImpl.h" #include "InstanceScript.h" diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_general_vezax.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_general_vezax.cpp index cd9c171a4de..24ddcc66d55 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_general_vezax.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_general_vezax.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "InstanceScript.h" #include "Map.h" #include "MotionMaster.h" diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_mimiron.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_mimiron.cpp index 068cd1b6201..13f75169878 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_mimiron.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_mimiron.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "GameObject.h" #include "GameObjectAI.h" #include "GridNotifiers.h" diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_thorim.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_thorim.cpp index d6b23fa120e..bb927142fdd 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_thorim.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_thorim.cpp @@ -18,6 +18,7 @@ #include "ScriptMgr.h" #include "AreaBoundary.h" #include "CellImpl.h" +#include "Containers.h" #include "GridNotifiersImpl.h" #include "InstanceScript.h" #include "MotionMaster.h" diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_xt002.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_xt002.cpp index f766667b910..8b893810917 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_xt002.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_xt002.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "ObjectAccessor.h" diff --git a/src/server/scripts/Northrend/VaultOfArchavon/boss_emalon.cpp b/src/server/scripts/Northrend/VaultOfArchavon/boss_emalon.cpp index 502cb354493..1eef9198b57 100644 --- a/src/server/scripts/Northrend/VaultOfArchavon/boss_emalon.cpp +++ b/src/server/scripts/Northrend/VaultOfArchavon/boss_emalon.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "InstanceScript.h" #include "ObjectAccessor.h" #include "ScriptedCreature.h" diff --git a/src/server/scripts/Northrend/VioletHold/boss_xevozz.cpp b/src/server/scripts/Northrend/VioletHold/boss_xevozz.cpp index 2daf5475d4f..450f32f8124 100644 --- a/src/server/scripts/Northrend/VioletHold/boss_xevozz.cpp +++ b/src/server/scripts/Northrend/VioletHold/boss_xevozz.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "Player.h" diff --git a/src/server/scripts/Northrend/zone_borean_tundra.cpp b/src/server/scripts/Northrend/zone_borean_tundra.cpp index 7112d4b27cd..2c7870b4834 100644 --- a/src/server/scripts/Northrend/zone_borean_tundra.cpp +++ b/src/server/scripts/Northrend/zone_borean_tundra.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "CreatureAIImpl.h" #include "GameObject.h" #include "GameObjectAI.h" diff --git a/src/server/scripts/Northrend/zone_dalaran.cpp b/src/server/scripts/Northrend/zone_dalaran.cpp index 1dbf0001d92..f07d65e94f5 100644 --- a/src/server/scripts/Northrend/zone_dalaran.cpp +++ b/src/server/scripts/Northrend/zone_dalaran.cpp @@ -24,6 +24,7 @@ SDCategory: Dalaran Script Data End */ #include "ScriptMgr.h" +#include "Containers.h" #include "DatabaseEnv.h" #include "Mail.h" #include "Map.h" diff --git a/src/server/scripts/Northrend/zone_howling_fjord.cpp b/src/server/scripts/Northrend/zone_howling_fjord.cpp index 9bdd11e9cbe..1450d58956e 100644 --- a/src/server/scripts/Northrend/zone_howling_fjord.cpp +++ b/src/server/scripts/Northrend/zone_howling_fjord.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "MotionMaster.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" diff --git a/src/server/scripts/Northrend/zone_icecrown.cpp b/src/server/scripts/Northrend/zone_icecrown.cpp index e536c9c7ec3..0d4481cb673 100644 --- a/src/server/scripts/Northrend/zone_icecrown.cpp +++ b/src/server/scripts/Northrend/zone_icecrown.cpp @@ -17,6 +17,7 @@ #include "ScriptMgr.h" #include "CombatAI.h" +#include "Containers.h" #include "MotionMaster.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" diff --git a/src/server/scripts/Outland/Auchindoun/SethekkHalls/boss_talon_king_ikiss.cpp b/src/server/scripts/Outland/Auchindoun/SethekkHalls/boss_talon_king_ikiss.cpp index 63e2ed68a5b..06b5676e72e 100644 --- a/src/server/scripts/Outland/Auchindoun/SethekkHalls/boss_talon_king_ikiss.cpp +++ b/src/server/scripts/Outland/Auchindoun/SethekkHalls/boss_talon_king_ikiss.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "ScriptedCreature.h" #include "SpellScript.h" #include "sethekk_halls.h" diff --git a/src/server/scripts/Outland/Auchindoun/ShadowLabyrinth/boss_grandmaster_vorpil.cpp b/src/server/scripts/Outland/Auchindoun/ShadowLabyrinth/boss_grandmaster_vorpil.cpp index 0604e9e62db..de1d1107cd2 100644 --- a/src/server/scripts/Outland/Auchindoun/ShadowLabyrinth/boss_grandmaster_vorpil.cpp +++ b/src/server/scripts/Outland/Auchindoun/ShadowLabyrinth/boss_grandmaster_vorpil.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "ObjectAccessor.h" diff --git a/src/server/scripts/Outland/BlackTemple/boss_illidan.cpp b/src/server/scripts/Outland/BlackTemple/boss_illidan.cpp index b3e1ff47dc2..952fa800a05 100644 --- a/src/server/scripts/Outland/BlackTemple/boss_illidan.cpp +++ b/src/server/scripts/Outland/BlackTemple/boss_illidan.cpp @@ -17,6 +17,7 @@ #include "ScriptMgr.h" #include "black_temple.h" +#include "Containers.h" #include "GridNotifiersImpl.h" #include "InstanceScript.h" #include "Map.h" diff --git a/src/server/scripts/Outland/BlackTemple/boss_illidari_council.cpp b/src/server/scripts/Outland/BlackTemple/boss_illidari_council.cpp index e3973970bee..8515c2f0004 100644 --- a/src/server/scripts/Outland/BlackTemple/boss_illidari_council.cpp +++ b/src/server/scripts/Outland/BlackTemple/boss_illidari_council.cpp @@ -18,6 +18,7 @@ #include "ScriptMgr.h" #include "black_temple.h" #include "CellImpl.h" +#include "Containers.h" #include "GridNotifiersImpl.h" #include "InstanceScript.h" #include "PassiveAI.h" diff --git a/src/server/scripts/Outland/BlackTemple/boss_reliquary_of_souls.cpp b/src/server/scripts/Outland/BlackTemple/boss_reliquary_of_souls.cpp index 093c0a346ee..4e81dc242fd 100644 --- a/src/server/scripts/Outland/BlackTemple/boss_reliquary_of_souls.cpp +++ b/src/server/scripts/Outland/BlackTemple/boss_reliquary_of_souls.cpp @@ -17,6 +17,7 @@ #include "ScriptMgr.h" #include "black_temple.h" +#include "Containers.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "Player.h" diff --git a/src/server/scripts/Outland/CoilfangReservoir/TheSlavePens/boss_ahune.cpp b/src/server/scripts/Outland/CoilfangReservoir/TheSlavePens/boss_ahune.cpp index 8b2f00256fe..3cd67e7970d 100644 --- a/src/server/scripts/Outland/CoilfangReservoir/TheSlavePens/boss_ahune.cpp +++ b/src/server/scripts/Outland/CoilfangReservoir/TheSlavePens/boss_ahune.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "CreatureTextMgr.h" #include "GameObject.h" #include "GameObjectAI.h" diff --git a/src/server/scripts/Outland/HellfireCitadel/BloodFurnace/boss_broggok.cpp b/src/server/scripts/Outland/HellfireCitadel/BloodFurnace/boss_broggok.cpp index 6f4cb101c31..57d19f73a37 100644 --- a/src/server/scripts/Outland/HellfireCitadel/BloodFurnace/boss_broggok.cpp +++ b/src/server/scripts/Outland/HellfireCitadel/BloodFurnace/boss_broggok.cpp @@ -17,6 +17,7 @@ #include "ScriptMgr.h" #include "blood_furnace.h" +#include "Containers.h" #include "GameObject.h" #include "GameObjectAI.h" #include "InstanceScript.h" diff --git a/src/server/scripts/Outland/zone_hellfire_peninsula.cpp b/src/server/scripts/Outland/zone_hellfire_peninsula.cpp index 2feff3863d6..b77262e6f4e 100644 --- a/src/server/scripts/Outland/zone_hellfire_peninsula.cpp +++ b/src/server/scripts/Outland/zone_hellfire_peninsula.cpp @@ -17,6 +17,7 @@ #include "ScriptMgr.h" #include "CellImpl.h" +#include "Containers.h" #include "GridNotifiersImpl.h" #include "Log.h" #include "MotionMaster.h" diff --git a/src/server/scripts/Outland/zone_netherstorm.cpp b/src/server/scripts/Outland/zone_netherstorm.cpp index 3cd74d6dda6..c0f9081764b 100644 --- a/src/server/scripts/Outland/zone_netherstorm.cpp +++ b/src/server/scripts/Outland/zone_netherstorm.cpp @@ -27,6 +27,7 @@ npc_commander_dawnforge EndContentData */ #include "ScriptMgr.h" +#include "Containers.h" #include "Log.h" #include "ObjectAccessor.h" #include "Player.h" diff --git a/src/server/scripts/Outland/zone_terokkar_forest.cpp b/src/server/scripts/Outland/zone_terokkar_forest.cpp index 985e0105341..a7c1e94fb72 100644 --- a/src/server/scripts/Outland/zone_terokkar_forest.cpp +++ b/src/server/scripts/Outland/zone_terokkar_forest.cpp @@ -16,6 +16,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "GameObject.h" #include "Group.h" #include "Map.h" diff --git a/src/server/scripts/Pet/pet_hunter.cpp b/src/server/scripts/Pet/pet_hunter.cpp index 3557ebb829a..9894e948252 100644 --- a/src/server/scripts/Pet/pet_hunter.cpp +++ b/src/server/scripts/Pet/pet_hunter.cpp @@ -21,6 +21,7 @@ */ #include "ScriptMgr.h" +#include "Containers.h" #include "CreatureAIImpl.h" #include "ScriptedCreature.h" #include "SpellScript.h" diff --git a/src/server/scripts/Spells/spell_generic.cpp b/src/server/scripts/Spells/spell_generic.cpp index e5d16284aed..e11fdce65a5 100644 --- a/src/server/scripts/Spells/spell_generic.cpp +++ b/src/server/scripts/Spells/spell_generic.cpp @@ -25,6 +25,7 @@ #include "ScriptMgr.h" #include "Battleground.h" #include "CellImpl.h" +#include "Containers.h" #include "DBCStores.h" #include "GameTime.h" #include "GridNotifiersImpl.h" diff --git a/src/server/scripts/World/npcs_special.cpp b/src/server/scripts/World/npcs_special.cpp index 36b93e66e2e..e9f6fa7f605 100644 --- a/src/server/scripts/World/npcs_special.cpp +++ b/src/server/scripts/World/npcs_special.cpp @@ -18,6 +18,7 @@ #include "ScriptMgr.h" #include "CellImpl.h" #include "CombatAI.h" +#include "Containers.h" #include "CreatureTextMgr.h" #include "GameEventMgr.h" #include "GridNotifiersImpl.h" From 777b001d2df40d1f94269231a6832180e851c438 Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 6 Jan 2023 16:55:25 +0100 Subject: [PATCH 12/17] Core/Misc: Use boost/circular_buffer forward declaration headers in our headers (cherry picked from commit 1afec8be634fc3fd09fc5ea38ba71f0cc9259c7e) --- src/server/game/Handlers/MovementHandler.cpp | 18 ++++++++---------- src/server/game/Server/WorldSession.cpp | 3 ++- src/server/game/Server/WorldSession.h | 4 ++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/server/game/Handlers/MovementHandler.cpp b/src/server/game/Handlers/MovementHandler.cpp index b3ce3b97892..f458eca6f41 100644 --- a/src/server/game/Handlers/MovementHandler.cpp +++ b/src/server/game/Handlers/MovementHandler.cpp @@ -39,6 +39,7 @@ #include #include #include +#include void WorldSession::HandleMoveWorldportAckOpcode(WorldPacket & /*recvData*/) { @@ -954,7 +955,7 @@ void WorldSession::HandleTimeSyncResponse(WorldPacket& recvData) serverTime = clockDelta + clientTime */ int64 clockDelta = (int64)serverTimeAtSent + (int64)lagDelay - (int64)clientTimestamp; - _timeSyncClockDeltaQueue.push_back(std::pair(clockDelta, roundTripDuration)); + _timeSyncClockDeltaQueue->push_back(std::pair(clockDelta, roundTripDuration)); ComputeNewClockDelta(); } @@ -967,18 +968,18 @@ void WorldSession::ComputeNewClockDelta() accumulator_set > latencyAccumulator; - for (auto pair : _timeSyncClockDeltaQueue) - latencyAccumulator(pair.second); + for (auto [_, roundTripDuration] : *_timeSyncClockDeltaQueue) + latencyAccumulator(roundTripDuration); uint32 latencyMedian = static_cast(std::round(median(latencyAccumulator))); uint32 latencyStandardDeviation = static_cast(std::round(sqrt(variance(latencyAccumulator)))); accumulator_set > clockDeltasAfterFiltering; uint32 sampleSizeAfterFiltering = 0; - for (auto pair : _timeSyncClockDeltaQueue) + for (auto [clockDelta, roundTripDuration] : *_timeSyncClockDeltaQueue) { - if (pair.second < latencyStandardDeviation + latencyMedian) { - clockDeltasAfterFiltering(pair.first); + if (roundTripDuration < latencyStandardDeviation + latencyMedian) { + clockDeltasAfterFiltering(clockDelta); sampleSizeAfterFiltering++; } } @@ -990,8 +991,5 @@ void WorldSession::ComputeNewClockDelta() _timeSyncClockDelta = meanClockDelta; } else if (_timeSyncClockDelta == 0) - { - std::pair back = _timeSyncClockDeltaQueue.back(); - _timeSyncClockDelta = back.first; - } + _timeSyncClockDelta = _timeSyncClockDeltaQueue->back().first; } diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 968e3149894..8b0eefe157b 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -54,6 +54,7 @@ #include "World.h" #include "WorldPacket.h" #include "WorldSocket.h" +#include #include namespace { @@ -133,7 +134,7 @@ WorldSession::WorldSession(uint32 id, std::string&& name, std::shared_ptr>>(6)), _timeSyncClockDelta(0), _pendingTimeSyncRequests(), _timeSyncNextCounter(0), diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 8c2f073fa67..10f198e1795 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -30,11 +30,11 @@ #include "ObjectGuid.h" #include "Packet.h" #include "SharedDefines.h" +#include #include #include #include #include -#include class Creature; class GameClient; @@ -1236,7 +1236,7 @@ class TC_GAME_API WorldSession bool forceExit; ObjectGuid m_currentBankerGUID; - boost::circular_buffer> _timeSyncClockDeltaQueue; // first member: clockDelta. Second member: latency of the packet exchange that was used to compute that clockDelta. + std::unique_ptr>> _timeSyncClockDeltaQueue; // first member: clockDelta. Second member: latency of the packet exchange that was used to compute that clockDelta. int64 _timeSyncClockDelta; void ComputeNewClockDelta(); From 58f0c4b15a48772e4b9280a3e35fba90ecc4c31f Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 6 Jan 2023 16:55:58 +0100 Subject: [PATCH 13/17] Tests: Fixed environment variable confg test compilation on windows (cherry picked from commit cd62dc44916cd2d3e9522e1373e27bd01b27c84f) --- tests/common/Config.cpp | 22 ++++++++++++---------- tests/common/StringConvert.cpp | 14 +++++++------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/tests/common/Config.cpp b/tests/common/Config.cpp index fb657c358fd..639622c41e6 100644 --- a/tests/common/Config.cpp +++ b/tests/common/Config.cpp @@ -21,6 +21,8 @@ #include "Config.h" #include #include +#include +#include #include std::string CreateConfigWithMap(std::map const& map) @@ -36,10 +38,10 @@ std::string CreateConfigWithMap(std::map const& map) iniStream.close(); - return mTempFileAbs.native(); + return mTempFileAbs.string(); } -TEST_CASE("Envariable variables", "[Config]") +TEST_CASE("Environment variables", "[Config]") { std::map config; config["Int.Nested"] = "4242"; @@ -57,7 +59,7 @@ TEST_CASE("Envariable variables", "[Config]") { REQUIRE(sConfigMgr->GetIntDefault("Int.Nested", 10) == 4242); - setenv("TC_INT_NESTED", "8080", 1); + putenv(strdup("TC_INT_NESTED=8080")); REQUIRE(!sConfigMgr->OverrideWithEnvVariablesIfAny().empty()); REQUIRE(sConfigMgr->GetIntDefault("Int.Nested", 10) == 8080); } @@ -66,7 +68,7 @@ TEST_CASE("Envariable variables", "[Config]") { REQUIRE(sConfigMgr->GetStringDefault("lower", "") == "simpleString"); - setenv("TC_LOWER", "envstring", 1); + putenv(strdup("TC_LOWER=envstring")); REQUIRE(!sConfigMgr->OverrideWithEnvVariablesIfAny().empty()); REQUIRE(sConfigMgr->GetStringDefault("lower", "") == "envstring"); } @@ -75,29 +77,29 @@ TEST_CASE("Envariable variables", "[Config]") { REQUIRE(sConfigMgr->GetStringDefault("UPPER", "") == "simpleString"); - setenv("TC_UPPER", "envupperstring", 1); + putenv(strdup("TC_UPPER=envupperstring")); REQUIRE(!sConfigMgr->OverrideWithEnvVariablesIfAny().empty()); REQUIRE(sConfigMgr->GetStringDefault("UPPER", "") == "envupperstring"); } SECTION("Long nested name with number") { - REQUIRE(sConfigMgr->GetFloatDefault("SomeLong.NestedNameWithNumber.Like1", 0) == 1); + REQUIRE(sConfigMgr->GetFloatDefault("SomeLong.NestedNameWithNumber.Like1", 0) == 1.0f); - setenv("TC_SOME_LONG_NESTED_NAME_WITH_NUMBER_LIKE_1", "42", 1); + putenv(strdup("TC_SOME_LONG_NESTED_NAME_WITH_NUMBER_LIKE_1=42")); REQUIRE(!sConfigMgr->OverrideWithEnvVariablesIfAny().empty()); - REQUIRE(sConfigMgr->GetFloatDefault("SomeLong.NestedNameWithNumber.Like1", 0) == 42); + REQUIRE(sConfigMgr->GetFloatDefault("SomeLong.NestedNameWithNumber.Like1", 0) == 42.0f); } SECTION("String that not exist in config") { - setenv("TC_UNIQUE_STRING", "somevalue", 1); + putenv(strdup("TC_UNIQUE_STRING=somevalue")); REQUIRE(sConfigMgr->GetStringDefault("Unique.String", "") == "somevalue"); } SECTION("Int that not exist in config") { - setenv("TC_UNIQUE_INT", "100", 1); + putenv(strdup("TC_UNIQUE_INT=100")); REQUIRE(sConfigMgr->GetIntDefault("Unique.Int", 1) == 100); } diff --git a/tests/common/StringConvert.cpp b/tests/common/StringConvert.cpp index c1a6f5da7f8..d5ee53ed81b 100644 --- a/tests/common/StringConvert.cpp +++ b/tests/common/StringConvert.cpp @@ -21,24 +21,24 @@ TEST_CASE("String to uint32", "[StringConvert]") { - REQUIRE(Trinity::StringTo("42") == 42); - REQUIRE(Trinity::StringTo("42", 10) == 42); + REQUIRE(Trinity::StringTo("42") == 42u); + REQUIRE(Trinity::StringTo("42", 10) == 42u); REQUIRE(Trinity::StringTo(" 42") == std::nullopt); REQUIRE(Trinity::StringTo("tail42") == std::nullopt); REQUIRE(Trinity::StringTo("42tail") == std::nullopt); - REQUIRE(Trinity::StringTo("ff", 16) == 0xff); + REQUIRE(Trinity::StringTo("ff", 16) == 0xFFu); REQUIRE(Trinity::StringTo("0xff") == std::nullopt); - REQUIRE(Trinity::StringTo("0xff", 0) == 0xff); + REQUIRE(Trinity::StringTo("0xff", 0) == 0xFFu); - REQUIRE(Trinity::StringTo("101010", 2) == 0b101010); + REQUIRE(Trinity::StringTo("101010", 2) == 0b101010u); REQUIRE(Trinity::StringTo("0b101010") == std::nullopt); - REQUIRE(Trinity::StringTo("0b101010", 0) == 0b101010); + REQUIRE(Trinity::StringTo("0b101010", 0) == 0b101010u); REQUIRE(Trinity::StringTo("5000000000") == std::nullopt); REQUIRE(Trinity::StringTo("100000000", 16) == std::nullopt); REQUIRE(Trinity::StringTo("0x100000000", 0) == std::nullopt); - REQUIRE(Trinity::StringTo("0xffffffff", 0) == 0xffffffff); + REQUIRE(Trinity::StringTo("0xffffffff", 0) == 0xFFFFFFFF); } TEST_CASE("String to uint64", "[StringConvert]") From d251ab647dd4f48603b37b7150627a39e9a30f45 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 7 Jan 2023 22:38:21 +0100 Subject: [PATCH 14/17] Core/Misc: Migrate our c++20 advstd to standard features (cherry picked from commit 7830e5a7a1b93b0cd083baa3b70a0cfeb475f5f5) --- src/common/Utilities/EventProcessor.h | 3 +-- src/common/Utilities/Types.h | 4 ++-- src/common/Utilities/advstd.h | 17 ----------------- src/server/game/Chat/ChatCommands/ChatCommand.h | 3 +-- .../game/Chat/ChatCommands/ChatCommandTags.h | 3 +-- 5 files changed, 5 insertions(+), 25 deletions(-) diff --git a/src/common/Utilities/EventProcessor.h b/src/common/Utilities/EventProcessor.h index 2bf68216569..5cb51086891 100644 --- a/src/common/Utilities/EventProcessor.h +++ b/src/common/Utilities/EventProcessor.h @@ -18,7 +18,6 @@ #ifndef __EVENTPROCESSOR_H #define __EVENTPROCESSOR_H -#include "advstd.h" #include "Define.h" #include "Duration.h" #include "Random.h" @@ -89,7 +88,7 @@ class LambdaBasicEvent : public BasicEvent }; template -using is_lambda_event = std::enable_if_t>>>; +using is_lambda_event = std::enable_if_t>>>; class TC_COMMON_API EventProcessor { diff --git a/src/common/Utilities/Types.h b/src/common/Utilities/Types.h index 223a09c4ee3..922be079de0 100644 --- a/src/common/Utilities/Types.h +++ b/src/common/Utilities/Types.h @@ -18,7 +18,7 @@ #ifndef Types_h__ #define Types_h__ -#include "advstd.h" +#include namespace Trinity { @@ -35,7 +35,7 @@ namespace Trinity }; template typename Check, typename T1, typename... Ts> - struct find_type_if : std::conditional_t::value, advstd::type_identity, find_type_if> + struct find_type_if : std::conditional_t::value, std::type_identity, find_type_if> { }; diff --git a/src/common/Utilities/advstd.h b/src/common/Utilities/advstd.h index 2552f7d12bb..ff2717c9755 100644 --- a/src/common/Utilities/advstd.h +++ b/src/common/Utilities/advstd.h @@ -18,26 +18,9 @@ #ifndef TRINITY_ADVSTD_H #define TRINITY_ADVSTD_H -#include -#include - // this namespace holds implementations of upcoming stdlib features that our c++ version doesn't have yet namespace advstd { - // C++20 advstd::remove_cvref_t - template - using remove_cvref_t = std::remove_cv_t>; - - // C++20 std::type_identity - template - struct type_identity - { - using type = T; - }; - - // C++20 std::type_identity_t - template - using type_identity_t = typename type_identity::type; } #endif diff --git a/src/server/game/Chat/ChatCommands/ChatCommand.h b/src/server/game/Chat/ChatCommands/ChatCommand.h index 9520a7ce7dd..329eecfc567 100644 --- a/src/server/game/Chat/ChatCommands/ChatCommand.h +++ b/src/server/game/Chat/ChatCommands/ChatCommand.h @@ -18,7 +18,6 @@ #ifndef TRINITY_CHATCOMMAND_H #define TRINITY_CHATCOMMAND_H -#include "advstd.h" #include "ChatCommandArgs.h" #include "ChatCommandTags.h" #include "Define.h" @@ -116,7 +115,7 @@ namespace Trinity::Impl::ChatCommands } template struct HandlerToTuple { static_assert(Trinity::dependant_false_v, "Invalid command handler signature"); }; - template struct HandlerToTuple { using type = std::tuple...>; }; + template struct HandlerToTuple { using type = std::tuple...>; }; template using TupleType = typename HandlerToTuple::type; struct CommandInvoker diff --git a/src/server/game/Chat/ChatCommands/ChatCommandTags.h b/src/server/game/Chat/ChatCommands/ChatCommandTags.h index 0e2b79421c4..b90c614e85d 100644 --- a/src/server/game/Chat/ChatCommands/ChatCommandTags.h +++ b/src/server/game/Chat/ChatCommands/ChatCommandTags.h @@ -18,7 +18,6 @@ #ifndef TRINITY_CHATCOMMANDTAGS_H #define TRINITY_CHATCOMMANDTAGS_H -#include "advstd.h" #include "ChatCommandHelpers.h" #include "Hyperlinks.h" #include "ObjectGuid.h" @@ -213,7 +212,7 @@ namespace Trinity::ChatCommands struct Hyperlink : Trinity::Impl::ChatCommands::ContainerTag { using value_type = typename linktag::value_type; - using storage_type = advstd::remove_cvref_t; + using storage_type = std::remove_cvref_t; operator value_type() const { return val; } value_type operator*() const { return val; } From 27cd5a90f4c1f34c47cd4e1bd1a616e9b11b10ec Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 7 Jan 2023 22:38:21 +0100 Subject: [PATCH 15/17] Core/Misc: Replace enable_if overload selection with if constexpr (cherry picked from commit a53e4a57565d3375a978effbbc32d3eed6aac7e3) --- src/common/Containers/Utilities/MapUtils.h | 51 ++++ src/common/Utilities/Containers.h | 76 ++---- src/common/Utilities/Util.cpp | 2 +- src/common/Utilities/Util.h | 19 +- .../game/Chat/ChatCommands/ChatCommandArgs.h | 6 +- .../Grids/Dynamic/TypeContainerFunctions.h | 253 ++++++------------ src/server/scripts/Commands/cs_gobject.cpp | 2 +- src/server/scripts/Commands/cs_npc.cpp | 2 +- 8 files changed, 185 insertions(+), 226 deletions(-) create mode 100644 src/common/Containers/Utilities/MapUtils.h diff --git a/src/common/Containers/Utilities/MapUtils.h b/src/common/Containers/Utilities/MapUtils.h new file mode 100644 index 00000000000..7cf07243b0a --- /dev/null +++ b/src/common/Containers/Utilities/MapUtils.h @@ -0,0 +1,51 @@ +/* + * 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 . + */ + +#ifndef TRINITYCORE_MAP_UTILS_H +#define TRINITYCORE_MAP_UTILS_H + +#include + +namespace Trinity::Containers +{ +/** + * Returns a pointer to mapped value (or the value itself if map stores pointers) + */ +template +auto MapGetValuePtr(M& map, typename M::key_type const& key) +{ + auto itr = map.find(key); + if constexpr (std::is_pointer_v) + return itr != map.end() ? itr->second : nullptr; + else + return itr != map.end() ? &itr->second : nullptr; +} + +template class M, class... Rest> +void MultimapErasePair(M& multimap, K const& key, V const& value) +{ + auto range = multimap.equal_range(key); + for (auto itr = range.first; itr != range.second;) + { + if (itr->second == value) + itr = multimap.erase(itr); + else + ++itr; + } +} +} +#endif // TRINITYCORE_MAP_UTILS_H diff --git a/src/common/Utilities/Containers.h b/src/common/Utilities/Containers.h index 916026b7408..a55602a3163 100644 --- a/src/common/Utilities/Containers.h +++ b/src/common/Utilities/Containers.h @@ -19,6 +19,7 @@ #define TRINITY_CONTAINERS_H #include "Define.h" +#include "MapUtils.h" #include "Random.h" #include #include @@ -29,18 +30,6 @@ namespace Trinity { - template - constexpr inline T* AddressOrSelf(T* ptr) - { - return ptr; - } - - template - constexpr inline T* AddressOrSelf(T& not_ptr) - { - return std::addressof(not_ptr); - } - template class CheckedBufferOutputIterator { @@ -207,55 +196,44 @@ namespace Trinity return false; } - /** - * Returns a pointer to mapped value (or the value itself if map stores pointers) - */ - template - inline auto MapGetValuePtr(M& map, typename M::key_type const& key) -> decltype(AddressOrSelf(map.find(key)->second)) - { - auto itr = map.find(key); - return itr != map.end() ? AddressOrSelf(itr->second) : nullptr; - } - - template class M, class... Rest> - void MultimapErasePair(M& multimap, K const& key, V const& value) + namespace Impl { - auto range = multimap.equal_range(key); - for (auto itr = range.first; itr != range.second;) + template + void EraseIfMoveAssignable(Container& c, Predicate p) { - if (itr->second == value) - itr = multimap.erase(itr); - else - ++itr; + auto wpos = c.begin(); + for (auto rpos = c.begin(), end = c.end(); rpos != end; ++rpos) + { + if (!p(*rpos)) + { + if (rpos != wpos) + std::swap(*rpos, *wpos); + ++wpos; + } + } + c.erase(wpos, c.end()); } - } - template - std::enable_if_t().begin())>, void> EraseIf(Container& c, Predicate p) - { - auto wpos = c.begin(); - for (auto rpos = c.begin(), end = c.end(); rpos != end; ++rpos) + template + void EraseIfNotMoveAssignable(Container& c, Predicate p) { - if (!p(*rpos)) + for (auto it = c.begin(); it != c.end();) { - if (rpos != wpos) - std::swap(*rpos, *wpos); - ++wpos; + if (p(*it)) + it = c.erase(it); + else + ++it; } } - c.erase(wpos, c.end()); } template - std::enable_if_t().begin())>, void> EraseIf(Container& c, Predicate p) + void EraseIf(Container& c, Predicate p) { - for (auto it = c.begin(); it != c.end();) - { - if (p(*it)) - it = c.erase(it); - else - ++it; - } + if constexpr (std::is_move_assignable_v) + Impl::EraseIfMoveAssignable(c, std::ref(p)); + else + Impl::EraseIfNotMoveAssignable(c, std::ref(p)); } } //! namespace Containers diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 45ab3098e91..4693bd9eb08 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -708,7 +708,7 @@ bool StringCompareLessI(std::string_view a, std::string_view b) return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), [](char c1, char c2) { return std::tolower(c1) < std::tolower(c2); }); } -std::string GetTypeName(std::type_info const& info) +std::string Trinity::Impl::GetTypeName(std::type_info const& info) { return boost::core::demangle(info.name()); } diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index 87dd45d3cbc..d37b86f85e5 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -557,10 +557,23 @@ Ret* Coalesce(T1* first, T*... rest) return static_cast(first); } -TC_COMMON_API std::string GetTypeName(std::type_info const&); +namespace Trinity +{ +namespace Impl +{ + TC_COMMON_API std::string GetTypeName(std::type_info const&); +} + template -std::string GetTypeName() { return GetTypeName(typeid(T)); } +std::string GetTypeName() { return Impl::GetTypeName(typeid(T)); } template -std::enable_if_t, std::type_info>, std::string> GetTypeName(T&& v) { return GetTypeName(typeid(v)); } +std::string GetTypeName(T&& v) +{ + if constexpr (std::is_same_v, std::type_info>) + return Impl::GetTypeName(v); + else + return Impl::GetTypeName(typeid(v)); +} +} #endif diff --git a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h index 4b36b28b26d..71d115923ab 100644 --- a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h +++ b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h @@ -62,12 +62,12 @@ namespace Trinity::Impl::ChatCommands if (Optional v = StringTo(token, 0)) val = *v; else - return FormatTrinityString(handler, LANG_CMDPARSER_STRING_VALUE_INVALID, STRING_VIEW_FMT_ARG(token), GetTypeName().c_str()); + return FormatTrinityString(handler, LANG_CMDPARSER_STRING_VALUE_INVALID, STRING_VIEW_FMT_ARG(token), Trinity::GetTypeName().c_str()); if constexpr (std::is_floating_point_v) { if (!std::isfinite(val)) - return FormatTrinityString(handler, LANG_CMDPARSER_STRING_VALUE_INVALID, STRING_VIEW_FMT_ARG(token), GetTypeName().c_str()); + return FormatTrinityString(handler, LANG_CMDPARSER_STRING_VALUE_INVALID, STRING_VIEW_FMT_ARG(token), Trinity::GetTypeName().c_str()); } return tail; @@ -200,7 +200,7 @@ namespace Trinity::Impl::ChatCommands } if (next1) - return FormatTrinityString(handler, LANG_CMDPARSER_STRING_VALUE_INVALID, STRING_VIEW_FMT_ARG(strVal), GetTypeName().c_str()); + return FormatTrinityString(handler, LANG_CMDPARSER_STRING_VALUE_INVALID, STRING_VIEW_FMT_ARG(strVal), Trinity::GetTypeName().c_str()); else return next1; } diff --git a/src/server/game/Grids/Dynamic/TypeContainerFunctions.h b/src/server/game/Grids/Dynamic/TypeContainerFunctions.h index 94d9a7e1594..6a614e94eb6 100644 --- a/src/server/game/Grids/Dynamic/TypeContainerFunctions.h +++ b/src/server/game/Grids/Dynamic/TypeContainerFunctions.h @@ -33,210 +33,127 @@ namespace Trinity { // Helpers // Insert helpers - template - bool Insert(ContainerUnorderedMap& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* obj) + template + inline bool Insert(ContainerUnorderedMap, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* obj) { - auto i = elements._element.find(handle); - if (i == elements._element.end()) + if constexpr (std::is_same_v) { - elements._element[handle] = obj; - return true; + auto i = elements._elements._element.find(handle); + if (i == elements._elements._element.end()) + { + elements._elements._element[handle] = obj; + return true; + } + else + { + ASSERT(i->second == obj, "Object with certain key already in but objects are different!"); + return false; + } } - else - { - ASSERT(i->second == obj, "Object with certain key already in but objects are different!"); - return false; - } - } - template - bool Insert(ContainerUnorderedMap& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - - template - bool Insert(ContainerUnorderedMap& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; + if constexpr (std::is_same_v) + return false; + else + return Insert(elements._TailElements, handle, obj); } + // Find helpers template - bool Insert(ContainerUnorderedMap, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* obj) + inline SPECIFIC_TYPE* Find(ContainerUnorderedMap, KEY_TYPE> const& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* obj) { - bool ret = Insert(elements._elements, handle, obj); - return ret ? ret : Insert(elements._TailElements, handle, obj); - } + if constexpr (std::is_same_v) + { + auto i = elements._elements._element.find(handle); + if (i == elements._elements._element.end()) + return nullptr; + else + return i->second; + } - // Find helpers - template - SPECIFIC_TYPE* Find(ContainerUnorderedMap const& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) - { - auto i = elements._element.find(handle); - if (i == elements._element.end()) + if constexpr (std::is_same_v) return nullptr; else - return i->second; - } - - template - SPECIFIC_TYPE* Find(ContainerUnorderedMap const& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; - } - - template - SPECIFIC_TYPE* Find(ContainerUnorderedMap const& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; - } - - template - SPECIFIC_TYPE* Find(ContainerUnorderedMap, KEY_TYPE> const& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) - { - SPECIFIC_TYPE* ret = Find(elements._elements, handle, (SPECIFIC_TYPE*)nullptr); - return ret ? ret : Find(elements._TailElements, handle, (SPECIFIC_TYPE*)nullptr); + return Find(elements._TailElements, handle, obj); } // Erase helpers - template - bool Remove(ContainerUnorderedMap& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) - { - elements._element.erase(handle); - return true; - } - - template - bool Remove(ContainerUnorderedMap& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - - template - bool Remove(ContainerUnorderedMap& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - template - bool Remove(ContainerUnorderedMap, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) - { - bool ret = Remove(elements._elements, handle, (SPECIFIC_TYPE*)nullptr); - return ret ? ret : Remove(elements._TailElements, handle, (SPECIFIC_TYPE*)nullptr); - } - - // Count helpers - template - bool Size(ContainerUnorderedMap const& elements, std::size_t* size, SPECIFIC_TYPE* /*obj*/) - { - *size = elements._element.size(); - return true; - } - - template - bool Size(ContainerUnorderedMap const& /*elements*/, std::size_t* /*size*/, SPECIFIC_TYPE* /*obj*/) + inline bool Remove(ContainerUnorderedMap, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* obj) { - return false; - } + if constexpr (std::is_same_v) + { + elements._elements._element.erase(handle); + return true; + } - template - bool Size(ContainerUnorderedMap const& /*elements*/, std::size_t* /*size*/, SPECIFIC_TYPE* /*obj*/) - { - return false; + if constexpr (std::is_same_v) + return false; + else + return Remove(elements._TailElements, handle, obj); } + // Count helpers template - bool Size(ContainerUnorderedMap, KEY_TYPE> const& elements, std::size_t* size, SPECIFIC_TYPE* /*obj*/) + inline bool Size(ContainerUnorderedMap, KEY_TYPE> const& elements, std::size_t* size, SPECIFIC_TYPE* obj) { - bool ret = Size(elements._elements, size, (SPECIFIC_TYPE*)nullptr); - return ret ? ret : Size(elements._TailElements, size, (SPECIFIC_TYPE*)nullptr); + if constexpr (std::is_same_v) + { + *size = elements._elements._element.size(); + return true; + } + + if constexpr (std::is_same_v) + return false; + else + return Size(elements._TailElements, size, obj); } /* ContainerMapList Helpers */ // count functions - template - size_t Count(ContainerMapList const& elements, SPECIFIC_TYPE* /*fake*/) - { - return elements._element.getSize(); - } - - template - size_t Count(ContainerMapList const& /*elements*/, SPECIFIC_TYPE* /*fake*/) - { - return 0; - } - - template - size_t Count(ContainerMapList const& /*elements*/, SPECIFIC_TYPE* /*fake*/) - { - return 0; - } - - template - size_t Count(ContainerMapList> const& elements, SPECIFIC_TYPE* fake) - { - return Count(elements._elements, fake); - } - template - size_t Count(ContainerMapList> const& elements, SPECIFIC_TYPE* fake) + inline size_t Count(ContainerMapList> const& elements, SPECIFIC_TYPE* fake) { - return Count(elements._TailElements, fake); - } - - // non-const insert functions - template - SPECIFIC_TYPE* Insert(ContainerMapList& elements, SPECIFIC_TYPE* obj) - { - //elements._element[hdl] = obj; - obj->AddToGrid(elements._element); - return obj; - } - - template - SPECIFIC_TYPE* Insert(ContainerMapList& /*elements*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; - } + if constexpr (std::is_same_v) + { + return elements._elements._element.getSize(); + } - // this is a missed - template - SPECIFIC_TYPE* Insert(ContainerMapList& /*elements*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; // a missed + if constexpr (std::is_same_v) + return 0; + else + return Count(elements._TailElements, fake); } - // Recursion + // non-const insert functions template - SPECIFIC_TYPE* Insert(ContainerMapList>& elements, SPECIFIC_TYPE* obj) + inline SPECIFIC_TYPE* Insert(ContainerMapList>& elements, SPECIFIC_TYPE* obj) { - SPECIFIC_TYPE* t = Insert(elements._elements, obj); - return (t != nullptr ? t : Insert(elements._TailElements, obj)); + if constexpr (std::is_same_v) + { + obj->AddToGrid(elements._elements._element); + return obj; + } + + if constexpr (std::is_same_v) + return nullptr; + else + return Insert(elements._TailElements, obj); } //// non-const remove method - //template SPECIFIC_TYPE* Remove(ContainerMapList & /*elements*/, SPECIFIC_TYPE *obj) - //{ - // obj->GetGridRef().unlink(); - // return obj; - //} - - //template SPECIFIC_TYPE* Remove(ContainerMapList &/*elements*/, SPECIFIC_TYPE * /*obj*/) - //{ - // return nullptr; - //} - - //// this is a missed - //template SPECIFIC_TYPE* Remove(ContainerMapList &/*elements*/, SPECIFIC_TYPE * /*obj*/) - //{ - // return nullptr; // a missed - //} - - //template SPECIFIC_TYPE* Remove(ContainerMapList > &elements, SPECIFIC_TYPE *obj) + //template + //SPECIFIC_TYPE* Remove(ContainerMapList>& elements, SPECIFIC_TYPE* obj) //{ - // // The head element is bad - // SPECIFIC_TYPE* t = Remove(elements._elements, obj); - // return (t != nullptr ? t : Remove(elements._TailElements, obj)); + // if constexpr (std::is_same_v) + // { + // obj->GetGridRef().unlink(); + // return obj; + // } + + // if constexpr (std::is_same_v) + // return nullptr; + // else + // return Remove(elements._TailElements, obj); //} } #endif diff --git a/src/server/scripts/Commands/cs_gobject.cpp b/src/server/scripts/Commands/cs_gobject.cpp index 806b195924b..0293ae9a93c 100644 --- a/src/server/scripts/Commands/cs_gobject.cpp +++ b/src/server/scripts/Commands/cs_gobject.cpp @@ -577,7 +577,7 @@ class gobject_commandscript : public CommandScript handler->PSendSysMessage(LANG_GOINFO_SIZE, gameObjectInfo->size); handler->PSendSysMessage(LANG_OBJECTINFO_AIINFO, gameObjectInfo->AIName.c_str(), sObjectMgr->GetScriptName(gameObjectInfo->ScriptId).c_str()); if (GameObjectAI const* ai = thisGO ? thisGO->AI() : nullptr) - handler->PSendSysMessage(LANG_OBJECTINFO_AITYPE, GetTypeName(*ai).c_str()); + handler->PSendSysMessage(LANG_OBJECTINFO_AITYPE, Trinity::GetTypeName(*ai).c_str()); if (GameObjectDisplayInfoEntry const* modelInfo = sGameObjectDisplayInfoStore.LookupEntry(displayId)) handler->PSendSysMessage(LANG_GOINFO_MODEL, modelInfo->GeoBoxMax.X, modelInfo->GeoBoxMax.Y, modelInfo->GeoBoxMax.Z, modelInfo->GeoBoxMin.X, modelInfo->GeoBoxMin.Y, modelInfo->GeoBoxMin.Z); diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index e4ee87db7b6..b2c6cef3229 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -509,7 +509,7 @@ class npc_commandscript : public CommandScript handler->PSendSysMessage(LANG_OBJECTINFO_AIINFO, target->GetAIName().c_str(), target->GetScriptName().c_str()); handler->PSendSysMessage(LANG_NPCINFO_REACTSTATE, DescribeReactState(target->GetReactState())); if (CreatureAI const* ai = target->AI()) - handler->PSendSysMessage(LANG_OBJECTINFO_AITYPE, GetTypeName(*ai).c_str()); + handler->PSendSysMessage(LANG_OBJECTINFO_AITYPE, Trinity::GetTypeName(*ai).c_str()); handler->PSendSysMessage(LANG_NPCINFO_FLAGS_EXTRA, cInfo->flags_extra); for (CreatureFlagsExtra flag : EnumUtils::Iterate()) if (cInfo->flags_extra & flag) From 3144566584642a455df7b8ec9d46974f1b8d1a56 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 7 Jan 2023 22:38:21 +0100 Subject: [PATCH 16/17] Core/Misc: Include cleanup, 2023 edition (cherry picked from commit 92ed5e8af1f8b1aac085fd9b0ea93afb2b6795d4) --- src/common/Common.h | 21 +- .../game/Battlegrounds/Battleground.cpp | 2 +- src/server/game/Battlegrounds/Battleground.h | 3 +- src/server/game/Combat/ThreatManager.h | 1 + .../game/Entities/Object/ObjectGuid.cpp | 36 +- src/server/game/Entities/Object/ObjectGuid.h | 43 +- src/server/game/Globals/ObjectMgr.cpp | 23 +- src/server/game/Globals/ObjectMgr.h | 16 +- src/server/game/Grids/Dynamic/TypeContainer.h | 167 ++++-- src/server/game/Grids/GridDefines.h | 7 +- src/server/game/Grids/NGrid.cpp | 7 + src/server/game/Instances/InstanceScript.h | 5 +- src/server/game/Maps/Map.cpp | 11 + src/server/game/Maps/Map.h | 19 +- src/server/game/Scripting/ScriptMgr.cpp | 507 +++++++++++++++++- src/server/game/Scripting/ScriptMgr.h | 337 ++++++------ src/server/game/Spells/SpellScript.cpp | 12 + src/server/game/Spells/SpellScript.h | 6 +- src/server/shared/Realm/Realm.h | 1 + .../worldserver/CommandLine/CliRunnable.cpp | 2 + src/tools/mmaps_generator/PathCommon.h | 3 +- 21 files changed, 898 insertions(+), 331 deletions(-) diff --git a/src/common/Common.h b/src/common/Common.h index 92c0453ddc0..141b163a63e 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -20,27 +20,8 @@ #include "Define.h" #include -#include #include -#include - -#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS -# include - -# if TRINITY_COMPILER == TRINITY_COMPILER_INTEL -# if !defined(BOOST_ASIO_HAS_MOVE) -# define BOOST_ASIO_HAS_MOVE -# endif // !defined(BOOST_ASIO_HAS_MOVE) -# endif // if TRINITY_COMPILER == TRINITY_COMPILER_INTEL -#else -# include -# include -# include -# include -# include -# include -# include -#endif +#include #if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index 7377caa7943..19d5f28eef6 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -1068,7 +1068,7 @@ void Battleground::EventPlayerLoggedIn(Player* player) { ObjectGuid guid = player->GetGUID(); // player is correct pointer - for (GuidDeque::iterator itr = m_OfflineQueue.begin(); itr != m_OfflineQueue.end(); ++itr) + for (auto itr = m_OfflineQueue.begin(); itr != m_OfflineQueue.end(); ++itr) { if (*itr == guid) { diff --git a/src/server/game/Battlegrounds/Battleground.h b/src/server/game/Battlegrounds/Battleground.h index dcceb4d1127..4671ba22780 100644 --- a/src/server/game/Battlegrounds/Battleground.h +++ b/src/server/game/Battlegrounds/Battleground.h @@ -23,6 +23,7 @@ #include "ObjectGuid.h" #include "Position.h" #include "SharedDefines.h" +#include #include namespace WorldPackets @@ -592,7 +593,7 @@ class TC_GAME_API Battleground // Player lists GuidVector m_ResurrectQueue; // Player GUID - GuidDeque m_OfflineQueue; // Player GUID + std::deque m_OfflineQueue; // Player GUID // Invited counters are useful for player invitation to BG - do not allow, if BG is started to one faction to have 2 more players than another faction // Invited counters will be changed only when removing already invited player from queue, removing player from battleground and inviting player to BG diff --git a/src/server/game/Combat/ThreatManager.h b/src/server/game/Combat/ThreatManager.h index 36885802068..8cc792b0c1f 100644 --- a/src/server/game/Combat/ThreatManager.h +++ b/src/server/game/Combat/ThreatManager.h @@ -23,6 +23,7 @@ #include "ObjectGuid.h" #include "SharedDefines.h" #include +#include #include #include diff --git a/src/server/game/Entities/Object/ObjectGuid.cpp b/src/server/game/Entities/Object/ObjectGuid.cpp index 959a994c043..3de8cb7b2dc 100644 --- a/src/server/game/Entities/Object/ObjectGuid.cpp +++ b/src/server/game/Entities/Object/ObjectGuid.cpp @@ -91,31 +91,27 @@ ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid) return buf; } -void ObjectGuidGeneratorBase::HandleCounterOverflow(HighGuid high) +ObjectGuid::LowType ObjectGuidGenerator::Generate() { - TC_LOG_ERROR("misc", "%s guid overflow!! Can't continue, shutting down server. ", ObjectGuid::GetTypeName(high)); + if (_nextGuid >= ObjectGuid::GetMaxCounter(_high) - 1) + HandleCounterOverflow(); + + if (_high == HighGuid::Unit || _high == HighGuid::Vehicle || _high == HighGuid::GameObject || _high == HighGuid::Transport) + CheckGuidTrigger(); + + return _nextGuid++; +} + +void ObjectGuidGenerator::HandleCounterOverflow() +{ + TC_LOG_ERROR("misc", "%s guid overflow!! Can't continue, shutting down server. ", ObjectGuid::GetTypeName(_high)); World::StopNow(ERROR_EXIT_CODE); } -void ObjectGuidGeneratorBase::CheckGuidTrigger(ObjectGuid::LowType guidlow) +void ObjectGuidGenerator::CheckGuidTrigger() { - if (!sWorld->IsGuidAlert() && guidlow > sWorld->getIntConfig(CONFIG_RESPAWN_GUIDALERTLEVEL)) + if (!sWorld->IsGuidAlert() && _nextGuid > sWorld->getIntConfig(CONFIG_RESPAWN_GUIDALERTLEVEL)) sWorld->TriggerGuidAlert(); - else if (!sWorld->IsGuidWarning() && guidlow > sWorld->getIntConfig(CONFIG_RESPAWN_GUIDWARNLEVEL)) + else if (!sWorld->IsGuidWarning() && _nextGuid > sWorld->getIntConfig(CONFIG_RESPAWN_GUIDWARNLEVEL)) sWorld->TriggerGuidWarning(); } - -#define GUID_TRAIT_INSTANTIATE_GUID( HIGH_GUID ) \ - template class TC_GAME_API ObjectGuidGenerator< HIGH_GUID >; - -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Container) -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Player) -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::GameObject) -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Transport) -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Unit) -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Pet) -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Vehicle) -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::DynamicObject) -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Mo_Transport) -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Instance) -GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Group) diff --git a/src/server/game/Entities/Object/ObjectGuid.h b/src/server/game/Entities/Object/ObjectGuid.h index 31996595d0a..46b23671257 100644 --- a/src/server/game/Entities/Object/ObjectGuid.h +++ b/src/server/game/Entities/Object/ObjectGuid.h @@ -20,7 +20,6 @@ #include "ByteBuffer.h" #include "Define.h" -#include #include #include #include @@ -248,11 +247,10 @@ class TC_GAME_API ObjectGuid }; // Some Shared defines -typedef std::set GuidSet; -typedef std::list GuidList; -typedef std::deque GuidDeque; -typedef std::vector GuidVector; -typedef std::unordered_set GuidUnorderedSet; +using GuidSet = std::set; +using GuidList = std::list; +using GuidVector = std::vector; +using GuidUnorderedSet = std::unordered_set; // minimum buffer size for packed guid is 9 bytes #define PACKED_GUID_MIN_BUFFER_SIZE 9 @@ -275,40 +273,23 @@ class TC_GAME_API PackedGuid ByteBuffer _packedGuid; }; -class TC_GAME_API ObjectGuidGeneratorBase +class TC_GAME_API ObjectGuidGenerator { public: - ObjectGuidGeneratorBase(ObjectGuid::LowType start = 1) : _nextGuid(start) { } + explicit ObjectGuidGenerator(HighGuid high, ObjectGuid::LowType start = 1) : _high(high), _nextGuid(start) { } + ~ObjectGuidGenerator() = default; - virtual void Set(ObjectGuid::LowType val) { _nextGuid = val; } - virtual ObjectGuid::LowType Generate() = 0; + void Set(ObjectGuid::LowType val) { _nextGuid = val; } + ObjectGuid::LowType Generate(); ObjectGuid::LowType GetNextAfterMaxUsed() const { return _nextGuid; } - virtual ~ObjectGuidGeneratorBase() { } protected: - static void HandleCounterOverflow(HighGuid high); - static void CheckGuidTrigger(ObjectGuid::LowType guid); + void HandleCounterOverflow(); + void CheckGuidTrigger(); + HighGuid _high; ObjectGuid::LowType _nextGuid; }; -template -class TC_GAME_API ObjectGuidGenerator : public ObjectGuidGeneratorBase -{ -public: - explicit ObjectGuidGenerator(ObjectGuid::LowType start = 1) : ObjectGuidGeneratorBase(start) { } - - ObjectGuid::LowType Generate() override - { - if (_nextGuid >= ObjectGuid::GetMaxCounter(high) - 1) - HandleCounterOverflow(high); - - if (high == HighGuid::Unit || high == HighGuid::GameObject) - CheckGuidTrigger(_nextGuid); - - return _nextGuid++; - } -}; - TC_GAME_API ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid); TC_GAME_API ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid); diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index fc867d69235..24f8c9ce466 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -7431,21 +7431,21 @@ void ObjectMgr::SetHighestGuids() { QueryResult result = CharacterDatabase.Query("SELECT MAX(guid) FROM characters"); if (result) - GetGuidSequenceGenerator().Set((*result)[0].GetUInt32()+1); + GetGuidSequenceGenerator(HighGuid::Player).Set((*result)[0].GetUInt32() + 1); result = CharacterDatabase.Query("SELECT MAX(guid) FROM item_instance"); if (result) - GetGuidSequenceGenerator().Set((*result)[0].GetUInt32()+1); + GetGuidSequenceGenerator(HighGuid::Item).Set((*result)[0].GetUInt32() + 1); // Cleanup other tables from nonexistent guids ( >= _hiItemGuid) - CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", GetGuidSequenceGenerator().GetNextAfterMaxUsed()); // One-time query - CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid >= '%u'", GetGuidSequenceGenerator().GetNextAfterMaxUsed()); // One-time query - CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE itemguid >= '%u'", GetGuidSequenceGenerator().GetNextAfterMaxUsed()); // One-time query - CharacterDatabase.PExecute("DELETE FROM guild_bank_item WHERE item_guid >= '%u'", GetGuidSequenceGenerator().GetNextAfterMaxUsed()); // One-time query + CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", GetGuidSequenceGenerator(HighGuid::Item).GetNextAfterMaxUsed()); // One-time query + CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid >= '%u'", GetGuidSequenceGenerator(HighGuid::Item).GetNextAfterMaxUsed()); // One-time query + CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE itemguid >= '%u'", GetGuidSequenceGenerator(HighGuid::Item).GetNextAfterMaxUsed()); // One-time query + CharacterDatabase.PExecute("DELETE FROM guild_bank_item WHERE item_guid >= '%u'", GetGuidSequenceGenerator(HighGuid::Item).GetNextAfterMaxUsed()); // One-time query result = WorldDatabase.Query("SELECT MAX(guid) FROM transports"); if (result) - GetGuidSequenceGenerator().Set((*result)[0].GetUInt32()+1); + GetGuidSequenceGenerator(HighGuid::Transport).Set((*result)[0].GetUInt32() + 1); result = CharacterDatabase.Query("SELECT MAX(id) FROM auctionhouse"); if (result) @@ -7480,6 +7480,15 @@ void ObjectMgr::SetHighestGuids() _gameObjectSpawnId = (*result)[0].GetUInt32() + 1; } +ObjectGuidGenerator& ObjectMgr::GetGuidSequenceGenerator(HighGuid high) +{ + auto itr = _guidGenerators.find(high); + if (itr == _guidGenerators.end()) + itr = _guidGenerators.insert(std::make_pair(high, std::make_unique(high))).first; + + return *itr->second; +} + uint32 ObjectMgr::GenerateAuctionID() { if (_auctionId >= 0xFFFFFFFE) diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 875949faf16..8ea3c22213c 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -1254,10 +1254,10 @@ class TC_GAME_API ObjectMgr void SetHighestGuids(); template - inline ObjectGuidGeneratorBase& GetGenerator() + ObjectGuidGenerator& GetGenerator() { static_assert(ObjectGuidTraits::Global, "Only global guid can be generated in ObjectMgr context"); - return GetGuidSequenceGenerator(); + return GetGuidSequenceGenerator(type); } uint32 GenerateAuctionID(); @@ -1584,17 +1584,9 @@ class TC_GAME_API ObjectMgr ObjectGuid::LowType _gameObjectSpawnId; // first free low guid for selected guid type - template - inline ObjectGuidGeneratorBase& GetGuidSequenceGenerator() - { - auto itr = _guidGenerators.find(high); - if (itr == _guidGenerators.end()) - itr = _guidGenerators.insert(std::make_pair(high, std::unique_ptr>(new ObjectGuidGenerator()))).first; - - return *itr->second; - } + ObjectGuidGenerator& GetGuidSequenceGenerator(HighGuid high); - std::map> _guidGenerators; + std::map> _guidGenerators; QuestContainer _questTemplates; typedef std::unordered_map GossipTextContainer; diff --git a/src/server/game/Grids/Dynamic/TypeContainer.h b/src/server/game/Grids/Dynamic/TypeContainer.h index f790f0e3904..14d22d8056c 100644 --- a/src/server/game/Grids/Dynamic/TypeContainer.h +++ b/src/server/game/Grids/Dynamic/TypeContainer.h @@ -38,7 +38,6 @@ template struct ContainerMapList { - //std::map _element; GridRefManager _element; }; @@ -84,67 +83,145 @@ struct ContainerUnorderedMap, KEY_TYPE> template class TypeMapContainer { - public: - template size_t Count() const { return Trinity::Count(i_elements, (SPECIFIC_TYPE*)nullptr); } - - /// inserts a specific object into the container - template - bool insert(SPECIFIC_TYPE *obj) - { - SPECIFIC_TYPE* t = Trinity::Insert(i_elements, obj); - return (t != nullptr); - } - - /// Removes the object from the container, and returns the removed object - //template - //bool remove(SPECIFIC_TYPE* obj) - //{ - // SPECIFIC_TYPE* t = Trinity::Remove(i_elements, obj); - // return (t != nullptr); - //} - - ContainerMapList & GetElements(void) { return i_elements; } - const ContainerMapList & GetElements(void) const { return i_elements;} - - private: - ContainerMapList i_elements; +public: + TypeMapContainer(); + TypeMapContainer(TypeMapContainer const&) = default; + TypeMapContainer(TypeMapContainer&&) noexcept = default; + TypeMapContainer& operator=(TypeMapContainer const&) = default; + TypeMapContainer& operator=(TypeMapContainer&&) noexcept = default; + ~TypeMapContainer(); + + template + size_t Count() const; + + /// inserts a specific object into the container + template + bool insert(SPECIFIC_TYPE *obj); + + /// Removes the object from the container, and returns the removed object + //template + //bool remove(SPECIFIC_TYPE* obj) + //{ + // SPECIFIC_TYPE* t = Trinity::Remove(i_elements, obj); + // return (t != nullptr); + //} + + ContainerMapList& GetElements(void); + const ContainerMapList& GetElements(void) const; + +private: + ContainerMapList i_elements; }; +template +TypeMapContainer::TypeMapContainer() = default; + +template +TypeMapContainer::~TypeMapContainer() = default; + +template +template +size_t TypeMapContainer::Count() const +{ + return Trinity::Count(i_elements, (SPECIFIC_TYPE*)nullptr); +} + +template +template +bool TypeMapContainer::insert(SPECIFIC_TYPE* obj) +{ + SPECIFIC_TYPE* t = Trinity::Insert(i_elements, obj); + return (t != nullptr); +} + +template +ContainerMapList& TypeMapContainer::GetElements() +{ + return i_elements; +} + +template +const ContainerMapList& TypeMapContainer::GetElements() const +{ + return i_elements; +} + template class TypeUnorderedMapContainer { public: + TypeUnorderedMapContainer(); + TypeUnorderedMapContainer(TypeUnorderedMapContainer const&) = default; + TypeUnorderedMapContainer(TypeUnorderedMapContainer&&) noexcept = default; + TypeUnorderedMapContainer& operator=(TypeUnorderedMapContainer const&) = default; + TypeUnorderedMapContainer& operator=(TypeUnorderedMapContainer&&) noexcept = default; + ~TypeUnorderedMapContainer(); + template - bool Insert(KEY_TYPE const& handle, SPECIFIC_TYPE* obj) - { - return Trinity::Insert(_elements, handle, obj); - } + bool Insert(KEY_TYPE const& handle, SPECIFIC_TYPE* obj); template - bool Remove(KEY_TYPE const& handle) - { - return Trinity::Remove(_elements, handle, (SPECIFIC_TYPE*)nullptr); - } + bool Remove(KEY_TYPE const& handle); template - SPECIFIC_TYPE* Find(KEY_TYPE const& handle) - { - return Trinity::Find(_elements, handle, (SPECIFIC_TYPE*)nullptr); - } + SPECIFIC_TYPE* Find(KEY_TYPE const& handle); template - std::size_t Size() const - { - std::size_t size = 0; - Trinity::Size(_elements, &size, (SPECIFIC_TYPE*)nullptr); - return size; - } + std::size_t Size() const; - ContainerUnorderedMap& GetElements() { return _elements; } - ContainerUnorderedMap const& GetElements() const { return _elements; } + ContainerUnorderedMap& GetElements(); + ContainerUnorderedMap const& GetElements() const; private: ContainerUnorderedMap _elements; }; +template +TypeUnorderedMapContainer::TypeUnorderedMapContainer() = default; + +template +TypeUnorderedMapContainer::~TypeUnorderedMapContainer() = default; + +template +template +bool TypeUnorderedMapContainer::Insert(KEY_TYPE const& handle, SPECIFIC_TYPE* obj) +{ + return Trinity::Insert(_elements, handle, obj); +} + +template +template +bool TypeUnorderedMapContainer::Remove(KEY_TYPE const& handle) +{ + return Trinity::Remove(_elements, handle, (SPECIFIC_TYPE*)nullptr); +} + +template +template +SPECIFIC_TYPE* TypeUnorderedMapContainer::Find(KEY_TYPE const& handle) +{ + return Trinity::Find(_elements, handle, (SPECIFIC_TYPE*)nullptr); +} + +template +template +std::size_t TypeUnorderedMapContainer::Size() const +{ + std::size_t size = 0; + Trinity::Size(_elements, &size, (SPECIFIC_TYPE*)nullptr); + return size; +} + +template +ContainerUnorderedMap& TypeUnorderedMapContainer::GetElements() +{ + return _elements; +} + +template +ContainerUnorderedMap const& TypeUnorderedMapContainer::GetElements() const +{ + return _elements; +} + #endif diff --git a/src/server/game/Grids/GridDefines.h b/src/server/game/Grids/GridDefines.h index a709cc586e8..4ba7f33db81 100644 --- a/src/server/game/Grids/GridDefines.h +++ b/src/server/game/Grids/GridDefines.h @@ -76,12 +76,17 @@ enum GridMapTypeMask GRID_MAP_TYPE_MASK_ALL = 0x1F }; +extern template class Grid; +extern template class NGrid; + +extern template class TypeMapContainer; +extern template class TypeMapContainer; + typedef Grid GridType; typedef NGrid NGridType; typedef TypeMapContainer GridTypeMapContainer; typedef TypeMapContainer WorldTypeMapContainer; -typedef TypeUnorderedMapContainer MapStoredObjectTypesContainer; template struct CoordPair diff --git a/src/server/game/Grids/NGrid.cpp b/src/server/game/Grids/NGrid.cpp index 214bbc8adbd..cd77630fb99 100644 --- a/src/server/game/Grids/NGrid.cpp +++ b/src/server/game/Grids/NGrid.cpp @@ -16,6 +16,7 @@ */ #include "NGrid.h" +#include "GridDefines.h" #include "Random.h" GridInfo::GridInfo() : i_timer(0), vis_Update(0, irand(0, DEFAULT_VISIBILITY_NOTIFY_PERIOD)), @@ -27,3 +28,9 @@ GridInfo::GridInfo(time_t expiry, bool unload /*= true */) : i_timer(expiry), vi i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload), i_unloadReferenceLock(false) { } + +template class Grid; +template class NGrid; + +template class TC_GAME_API TypeMapContainer; +template class TC_GAME_API TypeMapContainer; diff --git a/src/server/game/Instances/InstanceScript.h b/src/server/game/Instances/InstanceScript.h index bd93498877a..063362af456 100644 --- a/src/server/game/Instances/InstanceScript.h +++ b/src/server/game/Instances/InstanceScript.h @@ -22,9 +22,12 @@ #include "Common.h" #include "Duration.h" #include -#include #include +#ifdef TRINITY_API_USE_DYNAMIC_LINKING +#include +#endif + #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()) #define OUT_LOAD_INST_DATA(a) TC_LOG_DEBUG("scripts", "Loading Instance Data for Instance %s (Map %d, Instance Id %d). Input is '%s'", instance->GetMapName(), instance->GetId(), instance->GetInstanceId(), a) diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index cf358105825..eb0809398bb 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -3522,6 +3522,15 @@ bool Map::IsSpawnGroupActive(uint32 groupId) const return (_toggledSpawnGroupIds.find(groupId) != _toggledSpawnGroupIds.end()) != !(data->flags & SPAWNGROUP_FLAG_MANUAL_SPAWN); } +ObjectGuidGenerator& Map::GetGuidSequenceGenerator(HighGuid high) +{ + auto itr = _guidGenerators.find(high); + if (itr == _guidGenerators.end()) + itr = _guidGenerators.insert(std::make_pair(high, std::make_unique(high))).first; + + return *itr->second; +} + void Map::AddFarSpellCallback(FarSpellCallback&& callback) { _farSpellCallbacks.Enqueue(new FarSpellCallback(std::move(callback))); @@ -4841,3 +4850,5 @@ std::string InstanceMap::GetDebugInfo() const << "ScriptId: " << GetScriptId() << " ScriptName: " << GetScriptName(); return sstr.str(); } + +template class TC_GAME_API TypeUnorderedMapContainer; diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index bf013d0d6ad..237ce5ff654 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -314,6 +314,9 @@ inline bool CompareRespawnInfo::operator()(RespawnInfo const* a, RespawnInfo con return a->type < b->type; } +extern template class TypeUnorderedMapContainer; +typedef TypeUnorderedMapContainer MapStoredObjectTypesContainer; + class TC_GAME_API Map : public GridRefManager { friend class MapReference; @@ -620,14 +623,14 @@ class TC_GAME_API Map : public GridRefManager inline ObjectGuid::LowType GenerateLowGuid() { static_assert(ObjectGuidTraits::MapSpecific, "Only map specific guid can be generated in Map context"); - return GetGuidSequenceGenerator().Generate(); + return GetGuidSequenceGenerator(high).Generate(); } template inline ObjectGuid::LowType GetMaxLowGuid() { static_assert(ObjectGuidTraits::MapSpecific, "Only map specific guid can be retrieved in Map context"); - return GetGuidSequenceGenerator().GetNextAfterMaxUsed(); + return GetGuidSequenceGenerator(high).GetNextAfterMaxUsed(); } void AddUpdateObject(Object* obj) @@ -879,17 +882,9 @@ class TC_GAME_API Map : public GridRefManager ZoneDynamicInfoMap _zoneDynamicInfo; IntervalTimer _weatherUpdateTimer; - template - inline ObjectGuidGeneratorBase& GetGuidSequenceGenerator() - { - auto itr = _guidGenerators.find(high); - if (itr == _guidGenerators.end()) - itr = _guidGenerators.insert(std::make_pair(high, std::unique_ptr>(new ObjectGuidGenerator()))).first; - - return *itr->second; - } + ObjectGuidGenerator& GetGuidSequenceGenerator(HighGuid high); - std::map> _guidGenerators; + std::map> _guidGenerators; MapStoredObjectTypesContainer _objectsStore; CreatureBySpawnIdContainer _creatureBySpawnIdStore; GameObjectBySpawnIdContainer _gameobjectBySpawnIdStore; diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index be8494df7eb..4d19c9a8513 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -1008,6 +1008,11 @@ ScriptObject::~ScriptObject() sScriptMgr->DecreaseScriptCount(); } +std::string const& ScriptObject::GetName() const +{ + return _name; +} + ScriptMgr::ScriptMgr() : _scriptCount(0), _script_loader_callback(nullptr) { @@ -2129,32 +2134,160 @@ SpellScriptLoader::SpellScriptLoader(char const* name) ScriptRegistry::Instance()->AddScript(this); } +SpellScript* SpellScriptLoader::GetSpellScript() const +{ + return nullptr; +} + +AuraScript* SpellScriptLoader::GetAuraScript() const +{ + return nullptr; +} + ServerScript::ServerScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } +void ServerScript::OnNetworkStart() +{ +} + +void ServerScript::OnNetworkStop() +{ +} + +void ServerScript::OnSocketOpen(std::shared_ptr /*socket*/) +{ +} + +void ServerScript::OnSocketClose(std::shared_ptr /*socket*/) +{ +} + +void ServerScript::OnPacketSend(WorldSession* /*session*/, WorldPacket& /*packet*/) +{ +} + +void ServerScript::OnPacketReceive(WorldSession* /*session*/, WorldPacket& /*packet*/) +{ +} + WorldScript::WorldScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } +void WorldScript::OnOpenStateChange(bool /*open*/) +{ +} + +void WorldScript::OnConfigLoad(bool /*reload*/) +{ +} + +void WorldScript::OnMotdChange(std::string& /*newMotd*/) +{ +} + +void WorldScript::OnShutdownInitiate(ShutdownExitCode /*code*/, ShutdownMask /*mask*/) +{ +} + +void WorldScript::OnShutdownCancel() +{ +} + +void WorldScript::OnUpdate(uint32 /*diff*/) +{ +} + +void WorldScript::OnStartup() +{ +} + +void WorldScript::OnShutdown() +{ +} + FormulaScript::FormulaScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } -UnitScript::UnitScript(char const* name) - : ScriptObject(name) +void FormulaScript::OnHonorCalculation(float& /*honor*/, uint8 /*level*/, float /*multiplier*/) +{ +} + +void FormulaScript::OnGrayLevelCalculation(uint8& /*grayLevel*/, uint8 /*playerLevel*/) +{ +} + +void FormulaScript::OnColorCodeCalculation(XPColorChar& /*color*/, uint8 /*playerLevel*/, uint8 /*mobLevel*/) +{ +} + +void FormulaScript::OnZeroDifferenceCalculation(uint8& /*diff*/, uint8 /*playerLevel*/) +{ +} + +void FormulaScript::OnBaseGainCalculation(uint32& /*gain*/, uint8 /*playerLevel*/, uint8 /*mobLevel*/, ContentLevels /*content*/) +{ +} + +void FormulaScript::OnGainCalculation(uint32& /*gain*/, Player* /*player*/, Unit* /*unit*/) +{ +} + +void FormulaScript::OnGroupRateCalculation(float& /*rate*/, uint32 /*count*/, bool /*isRaid*/) +{ +} + +template +MapScript::MapScript(MapEntry const* mapEntry) : _mapEntry(mapEntry) +{ +} + +template +MapEntry const* MapScript::GetEntry() const +{ + return _mapEntry; +} + +template +void MapScript::OnCreate(TMap* /*map*/) +{ +} + +template +void MapScript::OnDestroy(TMap* /*map*/) +{ +} + +template +void MapScript::OnPlayerEnter(TMap* /*map*/, Player* /*player*/) +{ +} + +template +void MapScript::OnPlayerLeave(TMap* /*map*/, Player* /*player*/) +{ +} + +template +void MapScript::OnUpdate(TMap* /*map*/, uint32 /*diff*/) { - ScriptRegistry::Instance()->AddScript(this); } +template class TC_GAME_API MapScript; +template class TC_GAME_API MapScript; +template class TC_GAME_API MapScript; + WorldMapScript::WorldMapScript(char const* name, uint32 mapId) - : ScriptObject(name), MapScript(sMapStore.LookupEntry(mapId)) + : ScriptObject(name), MapScript(sMapStore.LookupEntry(mapId)) { if (!GetEntry()) TC_LOG_ERROR("scripts", "Invalid WorldMapScript for %u; no such map ID.", mapId); @@ -2166,7 +2299,7 @@ WorldMapScript::WorldMapScript(char const* name, uint32 mapId) } InstanceMapScript::InstanceMapScript(char const* name, uint32 mapId) - : ScriptObject(name), MapScript(sMapStore.LookupEntry(mapId)) + : ScriptObject(name), MapScript(sMapStore.LookupEntry(mapId)) { if (!GetEntry()) TC_LOG_ERROR("scripts", "Invalid InstanceMapScript for %u; no such map ID.", mapId); @@ -2177,8 +2310,13 @@ InstanceMapScript::InstanceMapScript(char const* name, uint32 mapId) ScriptRegistry::Instance()->AddScript(this); } +InstanceScript* InstanceMapScript::GetInstanceScript(InstanceMap* /*map*/) const +{ + return nullptr; +} + BattlegroundMapScript::BattlegroundMapScript(char const* name, uint32 mapId) - : ScriptObject(name), MapScript(sMapStore.LookupEntry(mapId)) + : ScriptObject(name), MapScript(sMapStore.LookupEntry(mapId)) { if (!GetEntry()) TC_LOG_ERROR("scripts", "Invalid BattlegroundMapScript for %u; no such map ID.", mapId); @@ -2195,6 +2333,57 @@ ItemScript::ItemScript(char const* name) ScriptRegistry::Instance()->AddScript(this); } +bool ItemScript::OnQuestAccept(Player* /*player*/, Item* /*item*/, Quest const* /*quest*/) +{ + return false; +} + +bool ItemScript::OnUse(Player* /*player*/, Item* /*item*/, SpellCastTargets const& /*targets*/) +{ + return false; +} + +bool ItemScript::OnExpire(Player* /*player*/, ItemTemplate const* /*proto*/) +{ + return false; +} + +bool ItemScript::OnRemove(Player* /*player*/, Item* /*item*/) +{ + return false; +} + +bool ItemScript::OnCastItemCombatSpell(Player* /*player*/, Unit* /*victim*/, SpellInfo const* /*spellInfo*/, Item* /*item*/) +{ + return true; +} + +UnitScript::UnitScript(char const* name) + : ScriptObject(name) +{ + ScriptRegistry::Instance()->AddScript(this); +} + +void UnitScript::OnHeal(Unit* /*healer*/, Unit* /*reciever*/, uint32& /*gain*/) +{ +} + +void UnitScript::OnDamage(Unit* /*attacker*/, Unit* /*victim*/, uint32& /*damage*/) +{ +} + +void UnitScript::ModifyPeriodicDamageAurasTick(Unit* /*target*/, Unit* /*attacker*/, uint32& /*damage*/) +{ +} + +void UnitScript::ModifyMeleeDamage(Unit* /*target*/, Unit* /*attacker*/, uint32& /*damage*/) +{ +} + +void UnitScript::ModifySpellDamageTaken(Unit* /*target*/, Unit* /*attacker*/, int32& /*damage*/) +{ +} + CreatureScript::CreatureScript(char const* name) : ScriptObject(name) { @@ -2213,6 +2402,11 @@ AreaTriggerScript::AreaTriggerScript(char const* name) ScriptRegistry::Instance()->AddScript(this); } +bool AreaTriggerScript::OnTrigger(Player* /*player*/, AreaTriggerEntry const* /*trigger*/) +{ + return false; +} + bool OnlyOnceAreaTriggerScript::OnTrigger(Player* player, AreaTriggerEntry const* trigger) { uint32 const triggerId = trigger->ID; @@ -2225,7 +2419,7 @@ bool OnlyOnceAreaTriggerScript::OnTrigger(Player* player, AreaTriggerEntry const return true; } -void OnlyOnceAreaTriggerScript::ResetAreaTriggerDone(InstanceScript* script, uint32 triggerId) { script->ResetAreaTriggerDone(triggerId); } +void OnlyOnceAreaTriggerScript::ResetAreaTriggerDone(InstanceScript* instance, uint32 triggerId) { instance->ResetAreaTriggerDone(triggerId); } void OnlyOnceAreaTriggerScript::ResetAreaTriggerDone(Player const* player, AreaTriggerEntry const* trigger) { if (InstanceScript* instance = player->GetInstanceScript()) ResetAreaTriggerDone(instance, trigger->ID); } BattlefieldScript::BattlefieldScript(char const* name) @@ -2258,36 +2452,113 @@ WeatherScript::WeatherScript(char const* name) ScriptRegistry::Instance()->AddScript(this); } +void WeatherScript::OnChange(Weather* /*weather*/, WeatherState /*state*/, float /*grade*/) +{ +} + +void WeatherScript::OnUpdate(Weather* /*weather*/, uint32 /*diff*/) +{ +} + AuctionHouseScript::AuctionHouseScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } +void AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionEntry* /*entry*/) +{ +} + +void AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, AuctionEntry* /*entry*/) +{ +} + +void AuctionHouseScript::OnAuctionSuccessful(AuctionHouseObject* /*ah*/, AuctionEntry* /*entry*/) +{ +} + +void AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* /*ah*/, AuctionEntry* /*entry*/) +{ +} + ConditionScript::ConditionScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } +bool ConditionScript::OnConditionCheck(Condition const* /*condition*/, ConditionSourceInfo& /*sourceInfo*/) +{ + return true; +} + VehicleScript::VehicleScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } +void VehicleScript::OnInstall(Vehicle* /*veh*/) +{ +} + +void VehicleScript::OnUninstall(Vehicle* /*veh*/) +{ +} + +void VehicleScript::OnReset(Vehicle* /*veh*/) +{ +} + +void VehicleScript::OnInstallAccessory(Vehicle* /*veh*/, Creature* /*accessory*/) +{ +} + +void VehicleScript::OnAddPassenger(Vehicle* /*veh*/, Unit* /*passenger*/, int8 /*seatId*/) +{ +} + +void VehicleScript::OnRemovePassenger(Vehicle* /*veh*/, Unit* /*passenger*/) +{ +} + DynamicObjectScript::DynamicObjectScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } +void DynamicObjectScript::OnUpdate(DynamicObject* /*obj*/, uint32 /*diff*/) +{ +} + TransportScript::TransportScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } +void TransportScript::OnAddPassenger(Transport* /*transport*/, Player* /*player*/) +{ +} + +void TransportScript::OnAddCreaturePassenger(Transport* /*transport*/, Creature* /*creature*/) +{ +} + +void TransportScript::OnRemovePassenger(Transport* /*transport*/, Player* /*player*/) +{ +} + +void TransportScript::OnRelocate(Transport* /*transport*/, uint32 /*waypointId*/, uint32 /*mapId*/, float /*x*/, float /*y*/, float /*z*/) +{ +} + +void TransportScript::OnUpdate(Transport* /*transport*/, uint32 /*diff*/) +{ +} + AchievementCriteriaScript::AchievementCriteriaScript(char const* name) : ScriptObject(name) { @@ -2300,24 +2571,246 @@ PlayerScript::PlayerScript(char const* name) ScriptRegistry::Instance()->AddScript(this); } +void PlayerScript::OnPVPKill(Player* /*killer*/, Player* /*killed*/) +{ +} + +void PlayerScript::OnCreatureKill(Player* /*killer*/, Creature* /*killed*/) +{ +} + +void PlayerScript::OnPlayerKilledByCreature(Creature* /*killer*/, Player* /*killed*/) +{ +} + +void PlayerScript::OnLevelChanged(Player* /*player*/, uint8 /*oldLevel*/) +{ +} + +void PlayerScript::OnFreeTalentPointsChanged(Player* /*player*/, uint32 /*points*/) +{ +} + +void PlayerScript::OnTalentsReset(Player* /*player*/, bool /*noCost*/) +{ +} + +void PlayerScript::OnMoneyChanged(Player* /*player*/, int32& /*amount*/) +{ +} + +void PlayerScript::OnMoneyLimit(Player* /*player*/, int32 /*amount*/) +{ +} + +void PlayerScript::OnGiveXP(Player* /*player*/, uint32& /*amount*/, Unit* /*victim*/) +{ +} + +void PlayerScript::OnReputationChange(Player* /*player*/, uint32 /*factionId*/, int32& /*standing*/, bool /*incremental*/) +{ +} + +void PlayerScript::OnDuelRequest(Player* /*target*/, Player* /*challenger*/) +{ +} + +void PlayerScript::OnDuelStart(Player* /*player1*/, Player* /*player2*/) +{ +} + +void PlayerScript::OnDuelEnd(Player* /*winner*/, Player* /*loser*/, DuelCompleteType /*type*/) +{ +} + +void PlayerScript::OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string& /*msg*/) +{ +} + +void PlayerScript::OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string& /*msg*/, Player* /*receiver*/) +{ +} + +void PlayerScript::OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string& /*msg*/, Group* /*group*/) +{ +} + +void PlayerScript::OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string& /*msg*/, Guild* /*guild*/) +{ +} + +void PlayerScript::OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string& /*msg*/, Channel* /*channel*/) +{ +} + +void PlayerScript::OnEmote(Player* /*player*/, Emote /*emote*/) +{ +} + +void PlayerScript::OnTextEmote(Player* /*player*/, uint32 /*textEmote*/, uint32 /*emoteNum*/, ObjectGuid /*guid*/) +{ +} + +void PlayerScript::OnSpellCast(Player* /*player*/, Spell* /*spell*/, bool /*skipCheck*/) +{ +} + +void PlayerScript::OnLogin(Player* /*player*/, bool /*firstLogin*/) +{ +} + +void PlayerScript::OnLogout(Player* /*player*/) +{ +} + +void PlayerScript::OnCreate(Player* /*player*/) +{ +} + +void PlayerScript::OnDelete(ObjectGuid /*guid*/, uint32 /*accountId*/) +{ +} + +void PlayerScript::OnFailedDelete(ObjectGuid /*guid*/, uint32 /*accountId*/) +{ +} + +void PlayerScript::OnSave(Player* /*player*/) +{ +} + +void PlayerScript::OnBindToInstance(Player* /*player*/, Difficulty /*difficulty*/, uint32 /*mapId*/, bool /*permanent*/, uint8 /*extendState*/) +{ +} + +void PlayerScript::OnUpdateZone(Player* /*player*/, uint32 /*newZone*/, uint32 /*newArea*/) +{ +} + +void PlayerScript::OnMapChanged(Player* /*player*/) +{ +} + +void PlayerScript::OnQuestStatusChange(Player* /*player*/, uint32 /*questId*/) +{ +} + +void PlayerScript::OnPlayerRepop(Player* /*player*/) +{ +} + +void PlayerScript::OnMovieComplete(Player* /*player*/, uint32 /*movieId*/) +{ +} + AccountScript::AccountScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } +void AccountScript::OnAccountLogin(uint32 /*accountId*/) +{ +} + +void AccountScript::OnFailedAccountLogin(uint32 /*accountId*/) +{ +} + +void AccountScript::OnEmailChange(uint32 /*accountId*/) +{ +} + +void AccountScript::OnFailedEmailChange(uint32 /*accountId*/) +{ +} + +void AccountScript::OnPasswordChange(uint32 /*accountId*/) +{ +} + +void AccountScript::OnFailedPasswordChange(uint32 /*accountId*/) +{ +} + GuildScript::GuildScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } +void GuildScript::OnAddMember(Guild* /*guild*/, Player* /*player*/, uint8& /*plRank*/) +{ +} + +void GuildScript::OnRemoveMember(Guild* /*guild*/, Player* /*player*/, bool /*isDisbanding*/, bool /*isKicked*/) +{ +} + +void GuildScript::OnMOTDChanged(Guild* /*guild*/, std::string const& /*newMotd*/) +{ +} + +void GuildScript::OnInfoChanged(Guild* /*guild*/, std::string const& /*newInfo*/) +{ +} + +void GuildScript::OnCreate(Guild* /*guild*/, Player* /*leader*/, std::string const& /*name*/) +{ +} + +void GuildScript::OnDisband(Guild* /*guild*/) +{ +} + +void GuildScript::OnMemberWitdrawMoney(Guild* /*guild*/, Player* /*player*/, uint32& /*amount*/, bool /*isRepair*/) +{ +} + +void GuildScript::OnMemberDepositMoney(Guild* /*guild*/, Player* /*player*/, uint32& /*amount*/) +{ +} + +void GuildScript::OnItemMove(Guild* /*guild*/, Player* /*player*/, Item* /*pItem*/, bool /*isSrcBank*/, uint8 /*srcContainer*/, uint8 /*srcSlotId*/, bool /*isDestBank*/, + uint8 /*destContainer*/, uint8 /*destSlotId*/) +{ +} + +void GuildScript::OnEvent(Guild* /*guild*/, uint8 /*eventType*/, ObjectGuid::LowType /*playerGuid1*/, ObjectGuid::LowType /*playerGuid2*/, uint8 /*newRank*/) +{ +} + +void GuildScript::OnBankEvent(Guild* /*guild*/, uint8 /*eventType*/, uint8 /*tabId*/, ObjectGuid::LowType /*playerGuid*/, uint32 /*itemOrMoney*/, uint16 /*itemStackCount*/, + uint8 /*destTabId*/) +{ +} + GroupScript::GroupScript(char const* name) : ScriptObject(name) { ScriptRegistry::Instance()->AddScript(this); } +void GroupScript::OnAddMember(Group* /*group*/, ObjectGuid /*guid*/) +{ +} + +void GroupScript::OnInviteMember(Group* /*group*/, ObjectGuid /*guid*/) +{ +} + +void GroupScript::OnRemoveMember(Group* /*group*/, ObjectGuid /*guid*/, RemoveMethod /*method*/, ObjectGuid /*kicker*/, char const* /*reason*/) +{ +} + +void GroupScript::OnChangeLeader(Group* /*group*/, ObjectGuid /*newLeaderGuid*/, ObjectGuid /*oldLeaderGuid*/) +{ +} + +void GroupScript::OnDisband(Group* /*group*/) +{ +} + // Specialize for each script type class like so: template class TC_GAME_API ScriptRegistry; template class TC_GAME_API ScriptRegistry; diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index b0f641b80e4..d43b8e1c8b8 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -22,6 +22,7 @@ #include "ObjectGuid.h" #include "Tuples.h" #include "Types.h" +#include #include class AccountMgr; @@ -172,7 +173,7 @@ class TC_GAME_API ScriptObject public: - const std::string& GetName() const { return _name; } + std::string const& GetName() const; protected: @@ -181,150 +182,136 @@ class TC_GAME_API ScriptObject private: - const std::string _name; -}; - -template class UpdatableScript -{ - protected: - - UpdatableScript() - { - } - - virtual ~UpdatableScript() { } - - public: - - virtual void OnUpdate(TObject* /*obj*/, uint32 /*diff*/) { } + std::string const _name; }; class TC_GAME_API SpellScriptLoader : public ScriptObject { protected: - SpellScriptLoader(char const* name); + explicit SpellScriptLoader(char const* name); public: // Should return a fully valid SpellScript pointer. - virtual SpellScript* GetSpellScript() const { return nullptr; } + virtual SpellScript* GetSpellScript() const; // Should return a fully valid AuraScript pointer. - virtual AuraScript* GetAuraScript() const { return nullptr; } + virtual AuraScript* GetAuraScript() const; }; class TC_GAME_API ServerScript : public ScriptObject { protected: - ServerScript(char const* name); + explicit ServerScript(char const* name); public: // Called when reactive socket I/O is started (WorldTcpSessionMgr). - virtual void OnNetworkStart() { } + virtual void OnNetworkStart(); // Called when reactive I/O is stopped. - virtual void OnNetworkStop() { } + virtual void OnNetworkStop(); // Called when a remote socket establishes a connection to the server. Do not store the socket object. - virtual void OnSocketOpen(std::shared_ptr /*socket*/) { } + virtual void OnSocketOpen(std::shared_ptr socket); // Called when a socket is closed. Do not store the socket object, and do not rely on the connection // being open; it is not. - virtual void OnSocketClose(std::shared_ptr /*socket*/) { } + virtual void OnSocketClose(std::shared_ptr socket); // Called when a packet is sent to a client. The packet object is a copy of the original packet, so reading // and modifying it is safe. - virtual void OnPacketSend(WorldSession* /*session*/, WorldPacket& /*packet*/) { } + virtual void OnPacketSend(WorldSession* session, WorldPacket& packet); // Called when a (valid) packet is received by a client. The packet object is a copy of the original packet, so // reading and modifying it is safe. Make sure to check WorldSession pointer before usage, it might be null in case of auth packets - virtual void OnPacketReceive(WorldSession* /*session*/, WorldPacket& /*packet*/) { } + virtual void OnPacketReceive(WorldSession* session, WorldPacket& packet); }; class TC_GAME_API WorldScript : public ScriptObject { protected: - WorldScript(char const* name); + explicit WorldScript(char const* name); public: // Called when the open/closed state of the world changes. - virtual void OnOpenStateChange(bool /*open*/) { } + virtual void OnOpenStateChange(bool open); // Called after the world configuration is (re)loaded. - virtual void OnConfigLoad(bool /*reload*/) { } + virtual void OnConfigLoad(bool reload); // Called before the message of the day is changed. - virtual void OnMotdChange(std::string& /*newMotd*/) { } + virtual void OnMotdChange(std::string& newMotd); // Called when a world shutdown is initiated. - virtual void OnShutdownInitiate(ShutdownExitCode /*code*/, ShutdownMask /*mask*/) { } + virtual void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask); // Called when a world shutdown is cancelled. - virtual void OnShutdownCancel() { } + virtual void OnShutdownCancel(); // Called on every world tick (don't execute too heavy code here). - virtual void OnUpdate(uint32 /*diff*/) { } + virtual void OnUpdate(uint32 diff); // Called when the world is started. - virtual void OnStartup() { } + virtual void OnStartup(); // Called when the world is actually shut down. - virtual void OnShutdown() { } + virtual void OnShutdown(); }; class TC_GAME_API FormulaScript : public ScriptObject { protected: - FormulaScript(char const* name); + explicit FormulaScript(char const* name); public: // Called after calculating honor. - virtual void OnHonorCalculation(float& /*honor*/, uint8 /*level*/, float /*multiplier*/) { } + virtual void OnHonorCalculation(float& honor, uint8 level, float multiplier); // Called after gray level calculation. - virtual void OnGrayLevelCalculation(uint8& /*grayLevel*/, uint8 /*playerLevel*/) { } + virtual void OnGrayLevelCalculation(uint8& grayLevel, uint8 playerLevel); // Called after calculating experience color. - virtual void OnColorCodeCalculation(XPColorChar& /*color*/, uint8 /*playerLevel*/, uint8 /*mobLevel*/) { } + virtual void OnColorCodeCalculation(XPColorChar& color, uint8 playerLevel, uint8 mobLevel); // Called after calculating zero difference. - virtual void OnZeroDifferenceCalculation(uint8& /*diff*/, uint8 /*playerLevel*/) { } + virtual void OnZeroDifferenceCalculation(uint8& diff, uint8 playerLevel); // Called after calculating base experience gain. - virtual void OnBaseGainCalculation(uint32& /*gain*/, uint8 /*playerLevel*/, uint8 /*mobLevel*/, ContentLevels /*content*/) { } + virtual void OnBaseGainCalculation(uint32& gain, uint8 playerLevel, uint8 mobLevel, ContentLevels content); // Called after calculating experience gain. - virtual void OnGainCalculation(uint32& /*gain*/, Player* /*player*/, Unit* /*unit*/) { } + virtual void OnGainCalculation(uint32& gain, Player* player, Unit* unit); // Called when calculating the experience rate for group experience. - virtual void OnGroupRateCalculation(float& /*rate*/, uint32 /*count*/, bool /*isRaid*/) { } + virtual void OnGroupRateCalculation(float& rate, uint32 count, bool isRaid); }; -template class MapScript : public UpdatableScript +template +class TC_GAME_API MapScript { - MapEntry const* _mapEntry; + MapEntry const* _mapEntry; protected: - MapScript(MapEntry const* mapEntry) : _mapEntry(mapEntry) { } + explicit MapScript(MapEntry const* mapEntry); public: // Gets the MapEntry structure associated with this script. Can return NULL. - MapEntry const* GetEntry() { return _mapEntry; } + MapEntry const* GetEntry() const; // Called when the map is created. - virtual void OnCreate(TMap* /*map*/) { } + virtual void OnCreate(TMap* map); // Called just before the map is destroyed. - virtual void OnDestroy(TMap* /*map*/) { } + virtual void OnDestroy(TMap* map); // Called when a grid map is loaded. virtual void OnLoadGridMap(TMap* /*map*/, GridMap* /*gmap*/, uint32 /*gx*/, uint32 /*gy*/) { } @@ -333,119 +320,120 @@ template class MapScript : public UpdatableScript virtual void OnUnloadGridMap(TMap* /*map*/, GridMap* /*gmap*/, uint32 /*gx*/, uint32 /*gy*/) { } // Called when a player enters the map. - virtual void OnPlayerEnter(TMap* /*map*/, Player* /*player*/) { } + virtual void OnPlayerEnter(TMap* map, Player* player); // Called when a player leaves the map. - virtual void OnPlayerLeave(TMap* /*map*/, Player* /*player*/) { } + virtual void OnPlayerLeave(TMap* map, Player* player); + + virtual void OnUpdate(TMap* map, uint32 diff); }; class TC_GAME_API WorldMapScript : public ScriptObject, public MapScript { protected: - WorldMapScript(char const* name, uint32 mapId); + explicit WorldMapScript(char const* name, uint32 mapId); }; -class TC_GAME_API InstanceMapScript - : public ScriptObject, public MapScript +class TC_GAME_API InstanceMapScript : public ScriptObject, public MapScript { protected: - InstanceMapScript(char const* name, uint32 mapId); + explicit InstanceMapScript(char const* name, uint32 mapId); public: // Gets an InstanceScript object for this instance. - virtual InstanceScript* GetInstanceScript(InstanceMap* /*map*/) const { return nullptr; } + virtual InstanceScript* GetInstanceScript(InstanceMap* map) const; }; class TC_GAME_API BattlegroundMapScript : public ScriptObject, public MapScript { protected: - BattlegroundMapScript(char const* name, uint32 mapId); + explicit BattlegroundMapScript(char const* name, uint32 mapId); }; class TC_GAME_API ItemScript : public ScriptObject { protected: - ItemScript(char const* name); + explicit ItemScript(char const* name); public: // Called when a player accepts a quest from the item. - virtual bool OnQuestAccept(Player* /*player*/, Item* /*item*/, Quest const* /*quest*/) { return false; } + virtual bool OnQuestAccept(Player* player, Item* item, Quest const* quest); // Called when a player uses the item. - virtual bool OnUse(Player* /*player*/, Item* /*item*/, SpellCastTargets const& /*targets*/) { return false; } + virtual bool OnUse(Player* player, Item* item, SpellCastTargets const& targets); // Called when the item expires (is destroyed). - virtual bool OnExpire(Player* /*player*/, ItemTemplate const* /*proto*/) { return false; } + virtual bool OnExpire(Player* player, ItemTemplate const* proto); // Called when the item is destroyed. - virtual bool OnRemove(Player* /*player*/, Item* /*item*/) { return false; } + virtual bool OnRemove(Player* player, Item* item); // Called before casting a combat spell from this item (chance on hit spells of item template, can be used to prevent cast if returning false) - virtual bool OnCastItemCombatSpell(Player* /*player*/, Unit* /*victim*/, SpellInfo const* /*spellInfo*/, Item* /*item*/) { return true; } + virtual bool OnCastItemCombatSpell(Player* player, Unit* victim, SpellInfo const* spellInfo, Item* item); }; class TC_GAME_API UnitScript : public ScriptObject { protected: - UnitScript(char const* name); + explicit UnitScript(char const* name); public: // Called when a unit deals healing to another unit - virtual void OnHeal(Unit* /*healer*/, Unit* /*reciever*/, uint32& /*gain*/) { } + virtual void OnHeal(Unit* healer, Unit* reciever, uint32& gain); // Called when a unit deals damage to another unit - virtual void OnDamage(Unit* /*attacker*/, Unit* /*victim*/, uint32& /*damage*/) { } + virtual void OnDamage(Unit* attacker, Unit* victim, uint32& damage); // Called when DoT's Tick Damage is being Dealt - virtual void ModifyPeriodicDamageAurasTick(Unit* /*target*/, Unit* /*attacker*/, uint32& /*damage*/) { } + virtual void ModifyPeriodicDamageAurasTick(Unit* target, Unit* attacker, uint32& damage); // Called when Melee Damage is being Dealt - virtual void ModifyMeleeDamage(Unit* /*target*/, Unit* /*attacker*/, uint32& /*damage*/) { } + virtual void ModifyMeleeDamage(Unit* target, Unit* attacker, uint32& damage); // Called when Spell Damage is being Dealt - virtual void ModifySpellDamageTaken(Unit* /*target*/, Unit* /*attacker*/, int32& /*damage*/) { } + virtual void ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& damage); }; class TC_GAME_API CreatureScript : public ScriptObject { protected: - CreatureScript(char const* name); + explicit CreatureScript(char const* name); public: // Called when a CreatureAI object is needed for the creature. - virtual CreatureAI* GetAI(Creature* /*creature*/) const = 0; + virtual CreatureAI* GetAI(Creature* creature) const = 0; }; class TC_GAME_API GameObjectScript : public ScriptObject { protected: - GameObjectScript(char const* name); + explicit GameObjectScript(char const* name); public: // Called when a GameObjectAI object is needed for the gameobject. - virtual GameObjectAI* GetAI(GameObject* /*go*/) const = 0; + virtual GameObjectAI* GetAI(GameObject* go) const = 0; }; class TC_GAME_API AreaTriggerScript : public ScriptObject { protected: - AreaTriggerScript(char const* name); + explicit AreaTriggerScript(char const* name); public: // Called when the area trigger is activated by a player. - virtual bool OnTrigger(Player* /*player*/, AreaTriggerEntry const* /*trigger*/) { return false; } + virtual bool OnTrigger(Player* player, AreaTriggerEntry const* trigger); }; class TC_GAME_API OnlyOnceAreaTriggerScript : public AreaTriggerScript @@ -457,16 +445,16 @@ class TC_GAME_API OnlyOnceAreaTriggerScript : public AreaTriggerScript protected: // returns true if the trigger was successfully handled, false if we should try again next time - virtual bool TryHandleOnce(Player* /*player*/, AreaTriggerEntry const* /*trigger*/) = 0; - void ResetAreaTriggerDone(InstanceScript* /*instance*/, uint32 /*triggerId*/); - void ResetAreaTriggerDone(Player const* /*player*/, AreaTriggerEntry const* /*trigger*/); + virtual bool TryHandleOnce(Player* player, AreaTriggerEntry const* trigger) = 0; + void ResetAreaTriggerDone(InstanceScript* instance, uint32 triggerId); + void ResetAreaTriggerDone(Player const* player, AreaTriggerEntry const* trigger); }; class TC_GAME_API BattlefieldScript : public ScriptObject { protected: - BattlefieldScript(char const* name); + explicit BattlefieldScript(char const* name); public: @@ -477,7 +465,7 @@ class TC_GAME_API BattlegroundScript : public ScriptObject { protected: - BattlegroundScript(char const* name); + explicit BattlegroundScript(char const* name); public: @@ -489,7 +477,7 @@ class TC_GAME_API OutdoorPvPScript : public ScriptObject { protected: - OutdoorPvPScript(char const* name); + explicit OutdoorPvPScript(char const* name); public: @@ -501,7 +489,7 @@ class TC_GAME_API CommandScript : public ScriptObject { protected: - CommandScript(char const* name); + explicit CommandScript(char const* name); public: @@ -509,111 +497,119 @@ class TC_GAME_API CommandScript : public ScriptObject virtual std::vector GetCommands() const = 0; }; -class TC_GAME_API WeatherScript : public ScriptObject, public UpdatableScript +class TC_GAME_API WeatherScript : public ScriptObject { protected: - WeatherScript(char const* name); + explicit WeatherScript(char const* name); public: // Called when the weather changes in the zone this script is associated with. - virtual void OnChange(Weather* /*weather*/, WeatherState /*state*/, float /*grade*/) { } + virtual void OnChange(Weather* weather, WeatherState state, float grade); + + virtual void OnUpdate(Weather* weather, uint32 diff); }; class TC_GAME_API AuctionHouseScript : public ScriptObject { protected: - AuctionHouseScript(char const* name); + explicit AuctionHouseScript(char const* name); public: // Called when an auction is added to an auction house. - virtual void OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionEntry* /*entry*/) { } + virtual void OnAuctionAdd(AuctionHouseObject* ah, AuctionEntry* entry); // Called when an auction is removed from an auction house. - virtual void OnAuctionRemove(AuctionHouseObject* /*ah*/, AuctionEntry* /*entry*/) { } + virtual void OnAuctionRemove(AuctionHouseObject* ah, AuctionEntry* entry); // Called when an auction was succesfully completed. - virtual void OnAuctionSuccessful(AuctionHouseObject* /*ah*/, AuctionEntry* /*entry*/) { } + virtual void OnAuctionSuccessful(AuctionHouseObject* ah, AuctionEntry* entry); // Called when an auction expires. - virtual void OnAuctionExpire(AuctionHouseObject* /*ah*/, AuctionEntry* /*entry*/) { } + virtual void OnAuctionExpire(AuctionHouseObject* ah, AuctionEntry* entry); }; class TC_GAME_API ConditionScript : public ScriptObject { protected: - ConditionScript(char const* name); + explicit ConditionScript(char const* name); public: // Called when a single condition is checked for a player. - virtual bool OnConditionCheck(Condition const* /*condition*/, ConditionSourceInfo& /*sourceInfo*/) { return true; } + virtual bool OnConditionCheck(Condition const* condition, ConditionSourceInfo& sourceInfo); }; class TC_GAME_API VehicleScript : public ScriptObject { protected: - VehicleScript(char const* name); + explicit VehicleScript(char const* name); public: // Called after a vehicle is installed. - virtual void OnInstall(Vehicle* /*veh*/) { } + virtual void OnInstall(Vehicle* veh); // Called after a vehicle is uninstalled. - virtual void OnUninstall(Vehicle* /*veh*/) { } + virtual void OnUninstall(Vehicle* veh); // Called when a vehicle resets. - virtual void OnReset(Vehicle* /*veh*/) { } + virtual void OnReset(Vehicle* veh); // Called after an accessory is installed in a vehicle. - virtual void OnInstallAccessory(Vehicle* /*veh*/, Creature* /*accessory*/) { } + virtual void OnInstallAccessory(Vehicle* veh, Creature* accessory); // Called after a passenger is added to a vehicle. - virtual void OnAddPassenger(Vehicle* /*veh*/, Unit* /*passenger*/, int8 /*seatId*/) { } + virtual void OnAddPassenger(Vehicle* veh, Unit* passenger, int8 seatId); // Called after a passenger is removed from a vehicle. - virtual void OnRemovePassenger(Vehicle* /*veh*/, Unit* /*passenger*/) { } + virtual void OnRemovePassenger(Vehicle* veh, Unit* passenger); }; -class TC_GAME_API DynamicObjectScript : public ScriptObject, public UpdatableScript +class TC_GAME_API DynamicObjectScript : public ScriptObject { protected: - DynamicObjectScript(char const* name); + explicit DynamicObjectScript(char const* name); + + public: + + virtual void OnUpdate(DynamicObject* obj, uint32 diff); }; -class TC_GAME_API TransportScript : public ScriptObject, public UpdatableScript +class TC_GAME_API TransportScript : public ScriptObject { protected: - TransportScript(char const* name); + explicit TransportScript(char const* name); public: // Called when a player boards the transport. - virtual void OnAddPassenger(Transport* /*transport*/, Player* /*player*/) { } + virtual void OnAddPassenger(Transport* transport, Player* player); // Called when a creature boards the transport. - virtual void OnAddCreaturePassenger(Transport* /*transport*/, Creature* /*creature*/) { } + virtual void OnAddCreaturePassenger(Transport* transport, Creature* creature); // Called when a player exits the transport. - virtual void OnRemovePassenger(Transport* /*transport*/, Player* /*player*/) { } + virtual void OnRemovePassenger(Transport* transport, Player* player); // Called when a transport moves. - virtual void OnRelocate(Transport* /*transport*/, uint32 /*waypointId*/, uint32 /*mapId*/, float /*x*/, float /*y*/, float /*z*/) { } + virtual void OnRelocate(Transport* transport, uint32 waypointId, uint32 mapId, float x, float y, float z); + + virtual void OnUpdate(Transport* transport, uint32 diff); }; class TC_GAME_API AchievementCriteriaScript : public ScriptObject { protected: - AchievementCriteriaScript(char const* name); + explicit AchievementCriteriaScript(char const* name); public: @@ -625,198 +621,199 @@ class TC_GAME_API PlayerScript : public ScriptObject { protected: - PlayerScript(char const* name); + explicit PlayerScript(char const* name); public: // Called when a player kills another player - virtual void OnPVPKill(Player* /*killer*/, Player* /*killed*/) { } + virtual void OnPVPKill(Player* killer, Player* killed); // Called when a player kills a creature - virtual void OnCreatureKill(Player* /*killer*/, Creature* /*killed*/) { } + virtual void OnCreatureKill(Player* killer, Creature* killed); // Called when a player is killed by a creature - virtual void OnPlayerKilledByCreature(Creature* /*killer*/, Player* /*killed*/) { } + virtual void OnPlayerKilledByCreature(Creature* killer, Player* killed); // Called when a player's level changes (after the level is applied) - virtual void OnLevelChanged(Player* /*player*/, uint8 /*oldLevel*/) { } + virtual void OnLevelChanged(Player* player, uint8 oldLevel); // Called when a player's free talent points change (right before the change is applied) - virtual void OnFreeTalentPointsChanged(Player* /*player*/, uint32 /*points*/) { } + virtual void OnFreeTalentPointsChanged(Player* player, uint32 points); // Called when a player's talent points are reset (right before the reset is done) - virtual void OnTalentsReset(Player* /*player*/, bool /*noCost*/) { } + virtual void OnTalentsReset(Player* player, bool noCost); // Called when a player's money is modified (before the modification is done) - virtual void OnMoneyChanged(Player* /*player*/, int32& /*amount*/) { } + virtual void OnMoneyChanged(Player* player, int32& amount); // Called when a player's money is at limit (amount = money tried to add) - virtual void OnMoneyLimit(Player* /*player*/, int32 /*amount*/) { } + virtual void OnMoneyLimit(Player* player, int32 amount); // Called when a player gains XP (before anything is given) - virtual void OnGiveXP(Player* /*player*/, uint32& /*amount*/, Unit* /*victim*/) { } + virtual void OnGiveXP(Player* player, uint32& amount, Unit* victim); // Called when a player's reputation changes (before it is actually changed) - virtual void OnReputationChange(Player* /*player*/, uint32 /*factionId*/, int32& /*standing*/, bool /*incremental*/) { } + virtual void OnReputationChange(Player* player, uint32 factionId, int32& standing, bool incremental); // Called when a duel is requested - virtual void OnDuelRequest(Player* /*target*/, Player* /*challenger*/) { } + virtual void OnDuelRequest(Player* target, Player* challenger); // Called when a duel starts (after 3s countdown) - virtual void OnDuelStart(Player* /*player1*/, Player* /*player2*/) { } + virtual void OnDuelStart(Player* player1, Player* player2); // Called when a duel ends - virtual void OnDuelEnd(Player* /*winner*/, Player* /*loser*/, DuelCompleteType /*type*/) { } + virtual void OnDuelEnd(Player* winner, Player* loser, DuelCompleteType type); // The following methods are called when a player sends a chat message. - virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string& /*msg*/) { } + virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg); - virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string& /*msg*/, Player* /*receiver*/) { } + virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Player* receiver); - virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string& /*msg*/, Group* /*group*/) { } + virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group* group); - virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string& /*msg*/, Guild* /*guild*/) { } + virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild* guild); - virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string& /*msg*/, Channel* /*channel*/) { } + virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel); // Both of the below are called on emote opcodes. - virtual void OnEmote(Player* /*player*/, Emote /*emote*/) { } + virtual void OnEmote(Player* player, Emote emote); - virtual void OnTextEmote(Player* /*player*/, uint32 /*textEmote*/, uint32 /*emoteNum*/, ObjectGuid /*guid*/) { } + virtual void OnTextEmote(Player* player, uint32 textEmote, uint32 emoteNum, ObjectGuid guid); // Called in Spell::Cast. - virtual void OnSpellCast(Player* /*player*/, Spell* /*spell*/, bool /*skipCheck*/) { } + virtual void OnSpellCast(Player* player, Spell* spell, bool skipCheck); // Called when a player logs in. - virtual void OnLogin(Player* /*player*/, bool /*firstLogin*/) { } + virtual void OnLogin(Player* player, bool firstLogin); // Called when a player logs out. - virtual void OnLogout(Player* /*player*/) { } + virtual void OnLogout(Player* player); // Called when a player is created. - virtual void OnCreate(Player* /*player*/) { } + virtual void OnCreate(Player* player); // Called when a player is deleted. - virtual void OnDelete(ObjectGuid /*guid*/, uint32 /*accountId*/) { } + virtual void OnDelete(ObjectGuid guid, uint32 accountId); // Called when a player delete failed - virtual void OnFailedDelete(ObjectGuid /*guid*/, uint32 /*accountId*/) { } + virtual void OnFailedDelete(ObjectGuid guid, uint32 accountId); // Called when a player is about to be saved. - virtual void OnSave(Player* /*player*/) { } + virtual void OnSave(Player* player); // Called when a player is bound to an instance - virtual void OnBindToInstance(Player* /*player*/, Difficulty /*difficulty*/, uint32 /*mapId*/, bool /*permanent*/, uint8 /*extendState*/) { } + virtual void OnBindToInstance(Player* player, Difficulty difficulty, uint32 mapId, bool permanent, uint8 extendState); // Called when a player switches to a new zone - virtual void OnUpdateZone(Player* /*player*/, uint32 /*newZone*/, uint32 /*newArea*/) { } + virtual void OnUpdateZone(Player* player, uint32 newZone, uint32 newArea); // Called when a player changes to a new map (after moving to new map) - virtual void OnMapChanged(Player* /*player*/) { } + virtual void OnMapChanged(Player* player); // Called when a player obtains progress on a quest's objective virtual void OnQuestObjectiveProgress(Player* /*player*/, Quest const* /*quest*/, uint32 /*objectiveIndex*/, uint16 /*progress*/) { } // Called after a player's quest status has been changed - virtual void OnQuestStatusChange(Player* /*player*/, uint32 /*questId*/) { } + virtual void OnQuestStatusChange(Player* player, uint32 questId); + + // Called when a player presses release when he died + virtual void OnPlayerRepop(Player* player); // Called when a player completes a movie - virtual void OnMovieComplete(Player* /*player*/, uint32 /*movieId*/) { } + virtual void OnMovieComplete(Player* player, uint32 movieId); - // Called when a player presses release when he died - virtual void OnPlayerRepop(Player* /*player*/) { } }; class TC_GAME_API AccountScript : public ScriptObject { protected: - AccountScript(char const* name); + explicit AccountScript(char const* name); public: // Called when an account logged in succesfully - virtual void OnAccountLogin(uint32 /*accountId*/) {} + virtual void OnAccountLogin(uint32 accountId); // Called when an account login failed - virtual void OnFailedAccountLogin(uint32 /*accountId*/) {} + virtual void OnFailedAccountLogin(uint32 accountId); // Called when Email is successfully changed for Account - virtual void OnEmailChange(uint32 /*accountId*/) {} + virtual void OnEmailChange(uint32 accountId); // Called when Email failed to change for Account - virtual void OnFailedEmailChange(uint32 /*accountId*/) {} + virtual void OnFailedEmailChange(uint32 accountId); // Called when Password is successfully changed for Account - virtual void OnPasswordChange(uint32 /*accountId*/) {} + virtual void OnPasswordChange(uint32 accountId); // Called when Password failed to change for Account - virtual void OnFailedPasswordChange(uint32 /*accountId*/) {} + virtual void OnFailedPasswordChange(uint32 accountId); }; class TC_GAME_API GuildScript : public ScriptObject { protected: - GuildScript(char const* name); + explicit GuildScript(char const* name); public: // Called when a member is added to the guild. - virtual void OnAddMember(Guild* /*guild*/, Player* /*player*/, uint8& /*plRank*/) { } + virtual void OnAddMember(Guild* guild, Player* player, uint8& plRank); // Called when a member is removed from the guild. - virtual void OnRemoveMember(Guild* /*guild*/, Player* /*player*/, bool /*isDisbanding*/, bool /*isKicked*/) { } + virtual void OnRemoveMember(Guild* guild, Player* player, bool isDisbanding, bool isKicked); // Called when the guild MOTD (message of the day) changes. - virtual void OnMOTDChanged(Guild* /*guild*/, const std::string& /*newMotd*/) { } + virtual void OnMOTDChanged(Guild* guild, std::string const& newMotd); // Called when the guild info is altered. - virtual void OnInfoChanged(Guild* /*guild*/, const std::string& /*newInfo*/) { } + virtual void OnInfoChanged(Guild* guild, std::string const& newInfo); // Called when a guild is created. - virtual void OnCreate(Guild* /*guild*/, Player* /*leader*/, const std::string& /*name*/) { } + virtual void OnCreate(Guild* guild, Player* leader, std::string const& name); // Called when a guild is disbanded. - virtual void OnDisband(Guild* /*guild*/) { } + virtual void OnDisband(Guild* guild); // Called when a guild member withdraws money from a guild bank. - virtual void OnMemberWitdrawMoney(Guild* /*guild*/, Player* /*player*/, uint32& /*amount*/, bool /*isRepair*/) { } + virtual void OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair); // Called when a guild member deposits money in a guild bank. - virtual void OnMemberDepositMoney(Guild* /*guild*/, Player* /*player*/, uint32& /*amount*/) { } + virtual void OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount); // Called when a guild member moves an item in a guild bank. - virtual void OnItemMove(Guild* /*guild*/, Player* /*player*/, Item* /*pItem*/, bool /*isSrcBank*/, uint8 /*srcContainer*/, uint8 /*srcSlotId*/, - bool /*isDestBank*/, uint8 /*destContainer*/, uint8 /*destSlotId*/) { } + virtual void OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, + bool isDestBank, uint8 destContainer, uint8 destSlotId); - virtual void OnEvent(Guild* /*guild*/, uint8 /*eventType*/, ObjectGuid::LowType /*playerGuid1*/, ObjectGuid::LowType /*playerGuid2*/, uint8 /*newRank*/) { } + virtual void OnEvent(Guild* guild, uint8 eventType, ObjectGuid::LowType playerGuid1, ObjectGuid::LowType playerGuid2, uint8 newRank); - virtual void OnBankEvent(Guild* /*guild*/, uint8 /*eventType*/, uint8 /*tabId*/, ObjectGuid::LowType /*playerGuid*/, uint32 /*itemOrMoney*/, uint16 /*itemStackCount*/, uint8 /*destTabId*/) { } + virtual void OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, ObjectGuid::LowType playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId); }; class TC_GAME_API GroupScript : public ScriptObject { protected: - GroupScript(char const* name); + explicit GroupScript(char const* name); public: // Called when a member is added to a group. - virtual void OnAddMember(Group* /*group*/, ObjectGuid /*guid*/) { } + virtual void OnAddMember(Group* group, ObjectGuid guid); // Called when a member is invited to join a group. - virtual void OnInviteMember(Group* /*group*/, ObjectGuid /*guid*/) { } + virtual void OnInviteMember(Group* group, ObjectGuid guid); // Called when a member is removed from a group. - virtual void OnRemoveMember(Group* /*group*/, ObjectGuid /*guid*/, RemoveMethod /*method*/, ObjectGuid /*kicker*/, char const* /*reason*/) { } + virtual void OnRemoveMember(Group* group, ObjectGuid guid, RemoveMethod method, ObjectGuid kicker, char const* reason); // Called when the leader of a group is changed. - virtual void OnChangeLeader(Group* /*group*/, ObjectGuid /*newLeaderGuid*/, ObjectGuid /*oldLeaderGuid*/) { } + virtual void OnChangeLeader(Group* group, ObjectGuid newLeaderGuid, ObjectGuid oldLeaderGuid); // Called when a group is disbanded. - virtual void OnDisband(Group* /*group*/) { } + virtual void OnDisband(Group* group); }; // Manages registration, loading, and execution of scripts. diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp index a822e3a0147..b8b52bf62f6 100644 --- a/src/server/game/Spells/SpellScript.cpp +++ b/src/server/game/Spells/SpellScript.cpp @@ -336,6 +336,12 @@ void SpellScript::DestinationTargetSelectHandler::Call(SpellScript* spellScript, (spellScript->*DestinationTargetSelectHandlerScript)(target); } +SpellScript::SpellScript(): m_spell(nullptr), m_hitPreventEffectMask(0), m_hitPreventDefaultEffectMask(0) +{ +} + +SpellScript::~SpellScript() = default; + bool SpellScript::_Validate(SpellInfo const* entry) { for (auto itr = OnEffectLaunch.begin(); itr != OnEffectLaunch.end(); ++itr) @@ -1009,6 +1015,12 @@ void AuraScript::EffectProcHandler::Call(AuraScript* auraScript, AuraEffect cons (auraScript->*_EffectHandlerScript)(aurEff, eventInfo); } +AuraScript::AuraScript(): _SpellScript(), m_aura(nullptr), m_auraApplication(nullptr), m_defaultActionPrevented(false) +{ +} + +AuraScript::~AuraScript() = default; + bool AuraScript::_Load(Aura* aura) { m_aura = aura; diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h index f2d4c422b5a..91eb9cf5c3b 100644 --- a/src/server/game/Spells/SpellScript.h +++ b/src/server/game/Spells/SpellScript.h @@ -325,6 +325,8 @@ class TC_GAME_API SpellScript : public _SpellScript #define PrepareSpellScript(CLASSNAME) SPELLSCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) SPELLSCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME) public: + SpellScript(); + ~SpellScript(); bool _Validate(SpellInfo const* entry) override; bool _Load(Spell* spell); void _InitHit(); @@ -730,8 +732,8 @@ class TC_GAME_API AuraScript : public _SpellScript #define PrepareAuraScript(CLASSNAME) AURASCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) AURASCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME) public: - AuraScript() : _SpellScript(), m_aura(nullptr), m_auraApplication(nullptr), m_defaultActionPrevented(false) - { } + AuraScript(); + ~AuraScript(); bool _Validate(SpellInfo const* entry) override; bool _Load(Aura* aura); void _PrepareScriptCall(AuraScriptHookType hookType, AuraApplication const* aurApp = nullptr); diff --git a/src/server/shared/Realm/Realm.h b/src/server/shared/Realm/Realm.h index f5856de5b77..fb19bd78d69 100644 --- a/src/server/shared/Realm/Realm.h +++ b/src/server/shared/Realm/Realm.h @@ -20,6 +20,7 @@ #include "Common.h" #include "AsioHacksFwd.h" +#include enum RealmFlags { diff --git a/src/server/worldserver/CommandLine/CliRunnable.cpp b/src/server/worldserver/CommandLine/CliRunnable.cpp index c5a14c9dcc2..878b70eab41 100644 --- a/src/server/worldserver/CommandLine/CliRunnable.cpp +++ b/src/server/worldserver/CommandLine/CliRunnable.cpp @@ -35,6 +35,8 @@ #include #include #include +#else +#include #endif static constexpr char CLI_PREFIX[] = "TC> "; diff --git a/src/tools/mmaps_generator/PathCommon.h b/src/tools/mmaps_generator/PathCommon.h index 6dbe5630297..4f29a034d92 100644 --- a/src/tools/mmaps_generator/PathCommon.h +++ b/src/tools/mmaps_generator/PathCommon.h @@ -18,7 +18,8 @@ #ifndef _MMAP_COMMON_H #define _MMAP_COMMON_H -#include "Common.h" +#include "Define.h" +#include #include #include From ede36202162fc7daa49ed2ef51948f65418dd1bc Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 12 Aug 2023 18:26:15 +0200 Subject: [PATCH 17/17] CI: Switch appveyor to use VS 2022 --- appveyor.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index bcf994ead93..7cf92124e00 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,10 +1,10 @@ version: 1.0.{build} -image: Visual Studio 2019 +image: Visual Studio 2022 clone_depth: 1 init: - ps: '' environment: - BOOST_ROOT: C:\Libraries\boost_1_77_0 + BOOST_ROOT: C:\Libraries\boost_1_73_0 OPENSSL_ROOT_DIR: C:\OpenSSL-v111-Win64 build_script: - cmd: >- @@ -12,9 +12,9 @@ build_script: md build && cd build - cmake -G"Visual Studio 16 2019" -A x64 -DSCRIPTS=dynamic -DTOOLS=True -DCMAKE_CXX_FLAGS=" /DWIN32 /D_WINDOWS /W3 /GR /EHsc /WX" -DCMAKE_C_FLAGS="/DWIN32 /D_WINDOWS /W3 /WX" .. + cmake -G"Visual Studio 17 2022" -A x64 -DSCRIPTS=dynamic -DTOOLS=True -DCMAKE_CXX_FLAGS=" /DWIN32 /D_WINDOWS /W3 /GR /EHsc /WX" -DCMAKE_C_FLAGS="/DWIN32 /D_WINDOWS /W3 /WX" .. - "%programfiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\amd64\MsBuild.exe" /nologo /m:2 /p:Configuration=RelWithDebInfo /p:Platform="X64" /verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" "TrinityCore.sln" + "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" /nologo /m:2 /p:Configuration=RelWithDebInfo /p:Platform="X64" /verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" "TrinityCore.sln" cd bin\RelWithDebInfo\ @@ -26,16 +26,16 @@ build_script: cd .. - 7z a TrinityCoreWin64VS2019.zip .\RelWithDebInfo\* + 7z a TrinityCoreWin64VS2022.zip .\RelWithDebInfo\* del /F /Q /S "RelWithDebInfo\*.pdb" > NUL - 7z a TrinityCoreWin64VS2019NoSymbols.zip .\RelWithDebInfo\* + 7z a TrinityCoreWin64VS2022NoSymbols.zip .\RelWithDebInfo\* test: off artifacts: -- path: build\bin\TrinityCoreWin64VS2019.zip - name: TrinityCoreWin64VS2019 +- path: build\bin\TrinityCoreWin64VS2022.zip + name: TrinityCoreWin64VS2022 -- path: build\bin\TrinityCoreWin64VS2019NoSymbols.zip - name: TrinityCoreWin64VS2019NoSymbols +- path: build\bin\TrinityCoreWin64VS2022NoSymbols.zip + name: TrinityCoreWin64VS2022NoSymbols