Npc positioning Implemented slope check to avoid unwanted climbing for some kind of movements (backwards, repositioning etc.) Implemented backwards movement Re-implemented circle repositioning algorithm (smartest than retail, but with the same feeling) Fixed random position of summoned minions Improved pet following movement. Also, they attack NPC from behind now. Thanks to @Footman Swimming creatures Fixed max_z coordinate for swimming creatures. Now only part of their body is allowed to be out of the water level Fixed pathfinder for swimming creatures creating shortcuts for specific segments, now they swim underwater to reach the seashore instead of flying above the water level. Creatures with water InhabitType but no swimming flag now, when not in combat, will walk on water depth instead of swimming. Thanks @jackpoz for the original code UNIT_FLAG_SWIMMING in UpdateEnvironmentIfNeeded to show the swimming animation correctly when underwater Implemented HasEnoughWater check to avoid swimming creatures to go where the water level is too low but also to properly enable swimming animation only when a creature has enough water to swim. Walking creatures Extended the DetourNavMeshQuery adding area cost based on walkability (slope angle + source height) to find better paths at runtime instead of completely remove them from mmaps improve Z height in certain conditions (see #4205, #4203, #4247 ) Flying creatures Rewriting of the hover system Removed hacks and improved the UpdateEnvironmentIfNeeded. Now creatures can properly switch from flying to walk etc. Spells LOS on spell effect must be calculated on CollisionHeight and HitSpherePoint instead of position coords. Improved position for object/creature spawned via spells Improved checks for Fleeing movements (fear spells) Other improvements Implemented method to calculate the CollisionWidth from dbc (used by repositioning algorithm etc.) Improved raycast and collision checks Co-authored-by: Footman <p.alexej@freenet.de> Co-authored-by: Helias <stefanoborzi32@gmail.com> Co-authored-by: Francesco Borzì <borzifrancesco@gmail.com> Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
90 lines
2.9 KiB
C++
90 lines
2.9 KiB
C++
/*
|
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2
|
|
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
*/
|
|
|
|
#ifndef _MMAP_MANAGER_H
|
|
#define _MMAP_MANAGER_H
|
|
|
|
#include "DetourAlloc.h"
|
|
#include "DetourNavMesh.h"
|
|
#include "DetourExtended.h"
|
|
#include "World.h"
|
|
#include <unordered_map>
|
|
|
|
// memory management
|
|
inline void* dtCustomAlloc(size_t size, dtAllocHint /*hint*/)
|
|
{
|
|
return (void*)new unsigned char[size];
|
|
}
|
|
|
|
inline void dtCustomFree(void* ptr)
|
|
{
|
|
delete [] (unsigned char*)ptr;
|
|
}
|
|
|
|
// move map related classes
|
|
namespace MMAP
|
|
{
|
|
typedef std::unordered_map<uint32, dtTileRef> MMapTileSet;
|
|
typedef std::unordered_map<uint32, dtNavMeshQuery*> NavMeshQuerySet;
|
|
|
|
// dummy struct to hold map's mmap data
|
|
struct MMapData
|
|
{
|
|
MMapData(dtNavMesh* mesh) : navMesh(mesh) {}
|
|
~MMapData()
|
|
{
|
|
for (NavMeshQuerySet::iterator i = navMeshQueries.begin(); i != navMeshQueries.end(); ++i)
|
|
dtFreeNavMeshQuery(i->second);
|
|
|
|
if (navMesh)
|
|
dtFreeNavMesh(navMesh);
|
|
}
|
|
|
|
dtNavMesh* navMesh;
|
|
|
|
// we have to use single dtNavMeshQuery for every instance, since those are not thread safe
|
|
NavMeshQuerySet navMeshQueries; // instanceId to query
|
|
MMapTileSet mmapLoadedTiles; // maps [map grid coords] to [dtTile]
|
|
};
|
|
|
|
typedef std::unordered_map<uint32, MMapData*> MMapDataSet;
|
|
|
|
// singleton class
|
|
// holds all all access to mmap loading unloading and meshes
|
|
class MMapManager
|
|
{
|
|
public:
|
|
MMapManager() : loadedTiles(0) {}
|
|
~MMapManager();
|
|
|
|
bool loadMap(uint32 mapId, int32 x, int32 y);
|
|
bool unloadMap(uint32 mapId, int32 x, int32 y);
|
|
bool unloadMap(uint32 mapId);
|
|
bool unloadMapInstance(uint32 mapId, uint32 instanceId);
|
|
|
|
// the returned [dtNavMeshQuery const*] is NOT threadsafe
|
|
dtNavMeshQuery const* GetNavMeshQuery(uint32 mapId, uint32 instanceId);
|
|
dtNavMesh const* GetNavMesh(uint32 mapId);
|
|
|
|
uint32 getLoadedTilesCount() const { return loadedTiles; }
|
|
uint32 getLoadedMapsCount() const { return loadedMMaps.size(); }
|
|
|
|
ACE_RW_Thread_Mutex& GetMMapLock(uint32 mapId);
|
|
ACE_RW_Thread_Mutex& GetMMapGeneralLock() { return MMapLock; } // pussywizard: in case a per-map mutex can't be found, should never happen
|
|
ACE_RW_Thread_Mutex& GetManagerLock() { return MMapManagerLock; }
|
|
private:
|
|
bool loadMapData(uint32 mapId);
|
|
uint32 packTileID(int32 x, int32 y);
|
|
|
|
MMapDataSet loadedMMaps;
|
|
uint32 loadedTiles;
|
|
|
|
ACE_RW_Thread_Mutex MMapManagerLock;
|
|
ACE_RW_Thread_Mutex MMapLock; // pussywizard: in case a per-map mutex can't be found, should never happen
|
|
};
|
|
}
|
|
|
|
#endif |