Core/Maps: Improvements to terrain swap handling
Port From (https://github.com/TrinityCore/TrinityCore/commit/eba31dea27b7fdc4a49c024898ef3a01bcbc7295)
This commit is contained in:
@@ -33,7 +33,8 @@ namespace Game.Collision
|
|||||||
{
|
{
|
||||||
Success,
|
Success,
|
||||||
FileNotFound,
|
FileNotFound,
|
||||||
VersionMismatch
|
VersionMismatch,
|
||||||
|
InvalidFile
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VMapManager : Singleton<VMapManager>
|
public class VMapManager : Singleton<VMapManager>
|
||||||
|
|||||||
@@ -233,8 +233,14 @@ namespace Game.Collision
|
|||||||
if (!File.Exists(tilefile))
|
if (!File.Exists(tilefile))
|
||||||
{
|
{
|
||||||
int parentMapId = vm.GetParentMapId(mapID);
|
int parentMapId = vm.GetParentMapId(mapID);
|
||||||
if (parentMapId != -1)
|
while (parentMapId != -1)
|
||||||
|
{
|
||||||
tilefile = vmapPath + GetTileFileName((uint)parentMapId, tileX, tileY);
|
tilefile = vmapPath + GetTileFileName((uint)parentMapId, tileX, tileY);
|
||||||
|
if (File.Exists(tilefile))
|
||||||
|
break;
|
||||||
|
|
||||||
|
parentMapId = vm.GetParentMapId((uint)parentMapId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!File.Exists(tilefile))
|
if (!File.Exists(tilefile))
|
||||||
|
|||||||
@@ -4692,7 +4692,7 @@ namespace Game.Entities
|
|||||||
AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(GetAreaId());
|
AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(GetAreaId());
|
||||||
|
|
||||||
// Such zones are considered unreachable as a ghost and the player must be automatically revived
|
// Such zones are considered unreachable as a ghost and the player must be automatically revived
|
||||||
if ((!IsAlive() && zone != null && zone.Flags[0].HasAnyFlag(AreaFlags.NeedFly)) || GetTransport() != null || GetPositionZ() < GetMap().GetMinHeight(GetPositionX(), GetPositionY()))
|
if ((!IsAlive() && zone != null && zone.Flags[0].HasAnyFlag(AreaFlags.NeedFly)) || GetTransport() != null || GetPositionZ() < GetMap().GetMinHeight(GetPhaseShift(), GetPositionX(), GetPositionY()))
|
||||||
{
|
{
|
||||||
ResurrectPlayer(0.5f);
|
ResurrectPlayer(0.5f);
|
||||||
SpawnCorpseBones();
|
SpawnCorpseBones();
|
||||||
@@ -4729,7 +4729,7 @@ namespace Game.Entities
|
|||||||
SendPacket(packet);
|
SendPacket(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (GetPositionZ() < GetMap().GetMinHeight(GetPositionX(), GetPositionY()))
|
else if (GetPositionZ() < GetMap().GetMinHeight(GetPhaseShift(), GetPositionX(), GetPositionY()))
|
||||||
TeleportTo(homebind);
|
TeleportTo(homebind);
|
||||||
|
|
||||||
RemovePlayerFlag(PlayerFlags.IsOutOfBounds);
|
RemovePlayerFlag(PlayerFlags.IsOutOfBounds);
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ namespace Game
|
|||||||
|
|
||||||
plrMover.UpdateFallInformationIfNeed(movementInfo, opcode);
|
plrMover.UpdateFallInformationIfNeed(movementInfo, opcode);
|
||||||
|
|
||||||
if (movementInfo.Pos.posZ < plrMover.GetMap().GetMinHeight(movementInfo.Pos.GetPositionX(), movementInfo.Pos.GetPositionY()))
|
if (movementInfo.Pos.posZ < plrMover.GetMap().GetMinHeight(plrMover.GetPhaseShift(), movementInfo.Pos.GetPositionX(), movementInfo.Pos.GetPositionY()))
|
||||||
{
|
{
|
||||||
if (!(plrMover.GetBattleground() && plrMover.GetBattleground().HandlePlayerUnderMap(GetPlayer())))
|
if (!(plrMover.GetBattleground() && plrMover.GetBattleground().HandlePlayerUnderMap(GetPlayer())))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ using Game.DataStorage;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Game.Collision;
|
||||||
|
|
||||||
namespace Game.Maps
|
namespace Game.Maps
|
||||||
{
|
{
|
||||||
@@ -36,41 +37,40 @@ namespace Game.Maps
|
|||||||
_liquidLevel = MapConst.InvalidHeight;
|
_liquidLevel = MapConst.InvalidHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool LoadData(string filename)
|
public LoadResult LoadData(string filename)
|
||||||
{
|
{
|
||||||
UnloadData();
|
UnloadData();
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
return true;
|
return LoadResult.FileNotFound;
|
||||||
|
|
||||||
_fileExists = true;
|
|
||||||
using (BinaryReader reader = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read)))
|
using (BinaryReader reader = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read)))
|
||||||
{
|
{
|
||||||
MapFileHeader header = reader.Read<MapFileHeader>();
|
MapFileHeader header = reader.Read<MapFileHeader>();
|
||||||
if (header.mapMagic != MapConst.MapMagic || header.versionMagic != MapConst.MapVersionMagic)
|
if (header.mapMagic != MapConst.MapMagic || header.versionMagic != MapConst.MapVersionMagic)
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Maps, $"Map file '{filename}' is from an incompatible map version. Please recreate using the mapextractor.");
|
Log.outError(LogFilter.Maps, $"Map file '{filename}' is from an incompatible map version. Please recreate using the mapextractor.");
|
||||||
return false;
|
return LoadResult.InvalidFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header.areaMapOffset != 0 && !LoadAreaData(reader, header.areaMapOffset))
|
if (header.areaMapOffset != 0 && !LoadAreaData(reader, header.areaMapOffset))
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Maps, "Error loading map area data");
|
Log.outError(LogFilter.Maps, "Error loading map area data");
|
||||||
return false;
|
return LoadResult.InvalidFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header.heightMapOffset != 0 && !LoadHeightData(reader, header.heightMapOffset))
|
if (header.heightMapOffset != 0 && !LoadHeightData(reader, header.heightMapOffset))
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Maps, "Error loading map height data");
|
Log.outError(LogFilter.Maps, "Error loading map height data");
|
||||||
return false;
|
return LoadResult.InvalidFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header.liquidMapOffset != 0 && !LoadLiquidData(reader, header.liquidMapOffset))
|
if (header.liquidMapOffset != 0 && !LoadLiquidData(reader, header.liquidMapOffset))
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Maps, "Error loading map liquids data");
|
Log.outError(LogFilter.Maps, "Error loading map liquids data");
|
||||||
return false;
|
return LoadResult.InvalidFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return LoadResult.Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,6 @@ namespace Game.Maps
|
|||||||
_liquidFlags = null;
|
_liquidFlags = null;
|
||||||
_liquidMap = null;
|
_liquidMap = null;
|
||||||
_gridGetHeight = GetHeightFromFlat;
|
_gridGetHeight = GetHeightFromFlat;
|
||||||
_fileExists = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoadAreaData(BinaryReader reader, uint offset)
|
bool LoadAreaData(BinaryReader reader, uint offset)
|
||||||
@@ -596,8 +595,6 @@ namespace Game.Maps
|
|||||||
|
|
||||||
public float GetHeight(float x, float y) { return _gridGetHeight(x, y); }
|
public float GetHeight(float x, float y) { return _gridGetHeight(x, y); }
|
||||||
|
|
||||||
public bool GileExists() { return _fileExists; }
|
|
||||||
|
|
||||||
#region Fields
|
#region Fields
|
||||||
delegate float GetHeightDel(float x, float y);
|
delegate float GetHeightDel(float x, float y);
|
||||||
|
|
||||||
@@ -630,7 +627,6 @@ namespace Game.Maps
|
|||||||
byte _liquidOffY;
|
byte _liquidOffY;
|
||||||
byte _liquidWidth;
|
byte _liquidWidth;
|
||||||
byte _liquidHeight;
|
byte _liquidHeight;
|
||||||
bool _fileExists;
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+80
-50
@@ -32,6 +32,7 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Game.Maps
|
namespace Game.Maps
|
||||||
{
|
{
|
||||||
@@ -106,6 +107,22 @@ namespace Game.Maps
|
|||||||
Global.MMapMgr.UnloadMapInstance(GetId(), i_InstanceId);
|
Global.MMapMgr.UnloadMapInstance(GetId(), i_InstanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DiscoverGridMapFiles()
|
||||||
|
{
|
||||||
|
for (uint gx = 0; gx < MapConst.MaxGrids; ++gx)
|
||||||
|
for (uint gy = 0; gy < MapConst.MaxGrids; ++gy)
|
||||||
|
i_gridFileExists[(int)(gx * MapConst.MaxGrids + gy)] = ExistMap(GetId(), gx, gy);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map GetRootParentTerrainMap()
|
||||||
|
{
|
||||||
|
Map map = this;
|
||||||
|
while (map != map.m_parentTerrainMap)
|
||||||
|
map = map.m_parentTerrainMap;
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool ExistMap(uint mapid, uint gx, uint gy)
|
public static bool ExistMap(uint mapid, uint gx, uint gy)
|
||||||
{
|
{
|
||||||
string fileName = $"{Global.WorldMgr.GetDataPath()}/maps/{mapid:D4}_{gx:D2}_{gy:D2}.map";
|
string fileName = $"{Global.WorldMgr.GetDataPath()}/maps/{mapid:D4}_{gx:D2}_{gy:D2}.map";
|
||||||
@@ -195,29 +212,33 @@ namespace Game.Maps
|
|||||||
if (map.GridMaps[gx][gy] != null)
|
if (map.GridMaps[gx][gy] != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Map parent = map.m_parentMap;
|
// map file name
|
||||||
++parent.GridMapReference[gx][gy];
|
string fileName = $"{Global.WorldMgr.GetDataPath()}/maps/{map.GetId():D4}_{gx:D2}_{gy:D2}.map";
|
||||||
|
Log.outInfo(LogFilter.Maps, "Loading map {0}", fileName);
|
||||||
|
|
||||||
// load grid map for base map
|
// loading data
|
||||||
if (parent != map)
|
GridMap gridMap = new GridMap();
|
||||||
|
LoadResult gridMapLoadResult = gridMap.LoadData(fileName);
|
||||||
|
if (gridMapLoadResult == LoadResult.Success)
|
||||||
|
map.GridMaps[gx][gy] = gridMap;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
GridCoord ngridCoord = new GridCoord((MapConst.MaxGrids - 1) - gx, (MapConst.MaxGrids - 1) - gy);
|
map.i_gridFileExists[(int)(gx * MapConst.MaxGrids + gy)] = false;
|
||||||
if (parent.GridMaps[gx][gy] == null)
|
Map parentTerrain = map;
|
||||||
parent.EnsureGridCreated(ngridCoord);
|
while (parentTerrain != parentTerrain.m_parentTerrainMap)
|
||||||
|
{
|
||||||
|
map.GridMaps[gx][gy] = parentTerrain.m_parentTerrainMap.GridMaps[gx][gy];
|
||||||
|
if (map.GridMaps[gx][gy] != null)
|
||||||
|
break;
|
||||||
|
|
||||||
map.GridMaps[gx][gy] = parent.GridMaps[gx][gy];
|
parentTerrain = parentTerrain.m_parentTerrainMap;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// map file name
|
if (map.GridMaps[gx][gy] != null)
|
||||||
string filename = $"{Global.WorldMgr.GetDataPath()}/maps/{map.GetId():D4}_{gx:D2}_{gy:D2}.map";
|
Global.ScriptMgr.OnLoadGridMap(map, map.GridMaps[gx][gy], gx, gy);
|
||||||
Log.outInfo(LogFilter.Maps, "Loading map {0}", filename);
|
else if (gridMapLoadResult == LoadResult.InvalidFile)
|
||||||
// loading data
|
Log.outError(LogFilter.Maps, $"Error loading map file: {fileName}");
|
||||||
map.GridMaps[gx][gy] = new GridMap();
|
|
||||||
if (!map.GridMaps[gx][gy].LoadData(filename))
|
|
||||||
Log.outError(LogFilter.Maps, "Error loading map file: {0}", filename);
|
|
||||||
|
|
||||||
Global.ScriptMgr.OnLoadGridMap(map, map.GridMaps[gx][gy], gx, gy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnloadMap(uint gx, uint gy)
|
void UnloadMap(uint gx, uint gy)
|
||||||
@@ -230,25 +251,18 @@ namespace Game.Maps
|
|||||||
|
|
||||||
void UnloadMapImpl(Map map, uint gx, uint gy)
|
void UnloadMapImpl(Map map, uint gx, uint gy)
|
||||||
{
|
{
|
||||||
if (map.GridMaps[gx][gy] != null)
|
|
||||||
{
|
|
||||||
Map parent = map.m_parentMap;
|
|
||||||
|
|
||||||
if ((--parent.GridMapReference[gx][gy]) == 0)
|
|
||||||
{
|
|
||||||
parent.GridMaps[gx][gy].UnloadData();
|
|
||||||
parent.GridMaps[gx][gy] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
map.GridMaps[gx][gy] = null;
|
map.GridMaps[gx][gy] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadMapAndVMap(uint gx, uint gy)
|
void LoadMapAndVMap(uint gx, uint gy)
|
||||||
{
|
{
|
||||||
LoadMap(gx, gy);
|
LoadMap(gx, gy);
|
||||||
LoadVMap(gx, gy);
|
// Only load the data for the base map
|
||||||
LoadMMap(gx, gy);
|
if (this == m_parentMap)
|
||||||
|
{
|
||||||
|
LoadVMap(gx, gy);
|
||||||
|
LoadMMap(gx, gy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadAllCells()
|
public void LoadAllCells()
|
||||||
@@ -404,7 +418,21 @@ namespace Game.Maps
|
|||||||
uint gy = (MapConst.MaxGrids - 1) - p.Y_coord;
|
uint gy = (MapConst.MaxGrids - 1) - p.Y_coord;
|
||||||
|
|
||||||
if (GridMaps[gx][gy] == null)
|
if (GridMaps[gx][gy] == null)
|
||||||
m_parentTerrainMap.LoadMapAndVMap(gx, gy);
|
{
|
||||||
|
Map rootParentTerrainMap = m_parentMap.GetRootParentTerrainMap();
|
||||||
|
// because LoadMapAndVMap is always entered using rootParentTerrainMap, we can only lock that once and not have to do it for every child map
|
||||||
|
if (this != rootParentTerrainMap)
|
||||||
|
Monitor.Enter(rootParentTerrainMap._gridLock);
|
||||||
|
|
||||||
|
if (m_parentMap.GridMaps[gx][gy] == null)
|
||||||
|
rootParentTerrainMap.LoadMapAndVMap(gx, gy);
|
||||||
|
|
||||||
|
if (m_parentMap.GridMaps[gx][gy] != null)
|
||||||
|
{
|
||||||
|
GridMaps[gx][gy] = m_parentMap.GridMaps[gx][gy];
|
||||||
|
++rootParentTerrainMap.GridMapReference[gx][gy];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1614,9 +1642,13 @@ namespace Game.Maps
|
|||||||
// delete grid map, but don't delete if it is from parent map (and thus only reference)
|
// delete grid map, but don't delete if it is from parent map (and thus only reference)
|
||||||
if (GridMaps[gx][gy] != null)
|
if (GridMaps[gx][gy] != null)
|
||||||
{
|
{
|
||||||
m_parentTerrainMap.UnloadMap(gx, gy);
|
Map terrainRoot = m_parentMap.GetRootParentTerrainMap();
|
||||||
Global.VMapMgr.UnloadMap(m_parentTerrainMap.GetId(), gx, gy);
|
if (--terrainRoot.GridMapReference[gx][gy] == 0)
|
||||||
Global.MMapMgr.UnloadMap(m_parentTerrainMap.GetId(), gx, gy);
|
{
|
||||||
|
m_parentMap.GetRootParentTerrainMap().UnloadMap(gx, gy);
|
||||||
|
Global.VMapMgr.UnloadMap(terrainRoot.GetId(), gx, gy);
|
||||||
|
Global.MMapMgr.UnloadMap(terrainRoot.GetId(), gx, gy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.outDebug(LogFilter.Maps, "Unloading grid[{0}, {1}] for map {2} finished", x, y, GetId());
|
Log.outDebug(LogFilter.Maps, "Unloading grid[{0}, {1}] for map {2} finished", x, y, GetId());
|
||||||
@@ -1690,9 +1722,6 @@ namespace Game.Maps
|
|||||||
|
|
||||||
GridMap GetGridMap(uint mapId, float x, float y)
|
GridMap GetGridMap(uint mapId, float x, float y)
|
||||||
{
|
{
|
||||||
if (GetId() == mapId)
|
|
||||||
return GetGridMap(x, y);
|
|
||||||
|
|
||||||
// half opt method
|
// half opt method
|
||||||
uint gx = (uint)(MapConst.CenterGridId - x / MapConst.SizeofGrids); //grid x
|
uint gx = (uint)(MapConst.CenterGridId - x / MapConst.SizeofGrids); //grid x
|
||||||
uint gy = (uint)(MapConst.CenterGridId - y / MapConst.SizeofGrids); //grid y
|
uint gy = (uint)(MapConst.CenterGridId - y / MapConst.SizeofGrids); //grid y
|
||||||
@@ -1702,16 +1731,16 @@ namespace Game.Maps
|
|||||||
|
|
||||||
GridMap grid = GridMaps[gx][gy];
|
GridMap grid = GridMaps[gx][gy];
|
||||||
var childMap = m_childTerrainMaps.Find(childTerrainMap => childTerrainMap.GetId() == mapId);
|
var childMap = m_childTerrainMaps.Find(childTerrainMap => childTerrainMap.GetId() == mapId);
|
||||||
if (childMap != null && childMap.GridMaps[gx][gy].GileExists())
|
if (childMap != null && childMap.GridMaps[gx][gy] != null)
|
||||||
grid = childMap.GridMaps[gx][gy];
|
grid = childMap.GridMaps[gx][gy];
|
||||||
|
|
||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasGridMap(uint mapId, uint gx, uint gy)
|
public bool HasChildMapGridFile(uint mapId, uint gx, uint gy)
|
||||||
{
|
{
|
||||||
var childMap = m_childTerrainMaps.Find(childTerrainMap => childTerrainMap.GetId() == mapId);
|
var childMap = m_childTerrainMaps.Find(childTerrainMap => childTerrainMap.GetId() == mapId);
|
||||||
return childMap != null && childMap.GridMaps[gx][gy] != null && childMap.GridMaps[gx][gy].GileExists();
|
return childMap != null && childMap.i_gridFileExists[(int)(gx * MapConst.MaxGrids + gy)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetWaterOrGroundLevel(PhaseShift phaseShift, float x, float y, float z)
|
public float GetWaterOrGroundLevel(PhaseShift phaseShift, float x, float y, float z)
|
||||||
@@ -1722,7 +1751,7 @@ namespace Game.Maps
|
|||||||
|
|
||||||
public float GetWaterOrGroundLevel(PhaseShift phaseShift, float x, float y, float z, ref float ground, bool swim = false)
|
public float GetWaterOrGroundLevel(PhaseShift phaseShift, float x, float y, float z, ref float ground, bool swim = false)
|
||||||
{
|
{
|
||||||
if (GetGridMap(x, y) != null)
|
if (GetGridMap(PhasingHandler.GetTerrainMapId(phaseShift, this, x, y), x, y) != null)
|
||||||
{
|
{
|
||||||
// we need ground level (including grid height version) for proper return water level in point
|
// we need ground level (including grid height version) for proper return water level in point
|
||||||
float ground_z = GetHeight(phaseShift, x, y, z, true, 50.0f);
|
float ground_z = GetHeight(phaseShift, x, y, z, true, 50.0f);
|
||||||
@@ -1742,7 +1771,7 @@ namespace Game.Maps
|
|||||||
// find raw .map surface under Z coordinates
|
// find raw .map surface under Z coordinates
|
||||||
float mapHeight = MapConst.VMAPInvalidHeightValue;
|
float mapHeight = MapConst.VMAPInvalidHeightValue;
|
||||||
uint terrainMapId = PhasingHandler.GetTerrainMapId(phaseShift, this, x, y);
|
uint terrainMapId = PhasingHandler.GetTerrainMapId(phaseShift, this, x, y);
|
||||||
GridMap gmap = m_parentTerrainMap.GetGridMap(terrainMapId, x, y);
|
GridMap gmap = GetGridMap(terrainMapId, x, y);
|
||||||
if (gmap != null)
|
if (gmap != null)
|
||||||
{
|
{
|
||||||
float gridHeight = gmap.GetHeight(x, y);
|
float gridHeight = gmap.GetHeight(x, y);
|
||||||
@@ -1779,9 +1808,9 @@ namespace Game.Maps
|
|||||||
return mapHeight; // explicitly use map data
|
return mapHeight; // explicitly use map data
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetMinHeight(float x, float y)
|
public float GetMinHeight(PhaseShift phaseShift, float x, float y)
|
||||||
{
|
{
|
||||||
GridMap grid = GetGridMap(x, y);
|
GridMap grid = GetGridMap(PhasingHandler.GetTerrainMapId(phaseShift, this, x, y), x, y);
|
||||||
if (grid != null)
|
if (grid != null)
|
||||||
return grid.GetMinHeight(x, y);
|
return grid.GetMinHeight(x, y);
|
||||||
|
|
||||||
@@ -1887,7 +1916,7 @@ namespace Game.Maps
|
|||||||
if (hasVmapAreaInfo || hasDynamicAreaInfo)
|
if (hasVmapAreaInfo || hasDynamicAreaInfo)
|
||||||
{
|
{
|
||||||
// check if there's terrain between player height and object height
|
// check if there's terrain between player height and object height
|
||||||
GridMap gmap = m_parentTerrainMap.GetGridMap(terrainMapId, x, y);
|
GridMap gmap = GetGridMap(terrainMapId, x, y);
|
||||||
if (gmap != null)
|
if (gmap != null)
|
||||||
{
|
{
|
||||||
float mapHeight = gmap.GetHeight(x, y);
|
float mapHeight = gmap.GetHeight(x, y);
|
||||||
@@ -1929,7 +1958,7 @@ namespace Game.Maps
|
|||||||
|
|
||||||
if (areaId == 0)
|
if (areaId == 0)
|
||||||
{
|
{
|
||||||
GridMap gmap = m_parentTerrainMap.GetGridMap(PhasingHandler.GetTerrainMapId(phaseShift, this, x, y), x, y);
|
GridMap gmap = GetGridMap(PhasingHandler.GetTerrainMapId(phaseShift, this, x, y), x, y);
|
||||||
if (gmap != null)
|
if (gmap != null)
|
||||||
areaId = gmap.GetArea(x, y);
|
areaId = gmap.GetArea(x, y);
|
||||||
|
|
||||||
@@ -1968,7 +1997,7 @@ namespace Game.Maps
|
|||||||
|
|
||||||
private byte GetTerrainType(PhaseShift phaseShift, float x, float y)
|
private byte GetTerrainType(PhaseShift phaseShift, float x, float y)
|
||||||
{
|
{
|
||||||
GridMap gmap = m_parentTerrainMap.GetGridMap(PhasingHandler.GetTerrainMapId(phaseShift, this, x, y), x, y);
|
GridMap gmap = GetGridMap(PhasingHandler.GetTerrainMapId(phaseShift, this, x, y), x, y);
|
||||||
if (gmap != null)
|
if (gmap != null)
|
||||||
return gmap.GetTerrainType(x, y);
|
return gmap.GetTerrainType(x, y);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2046,7 +2075,7 @@ namespace Game.Maps
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GridMap gmap = m_parentTerrainMap.GetGridMap(terrainMapId, x, y);
|
GridMap gmap = GetGridMap(terrainMapId, x, y);
|
||||||
if (gmap != null)
|
if (gmap != null)
|
||||||
{
|
{
|
||||||
var map_data = new LiquidData();
|
var map_data = new LiquidData();
|
||||||
@@ -2068,7 +2097,7 @@ namespace Game.Maps
|
|||||||
|
|
||||||
public float GetWaterLevel(PhaseShift phaseShift, float x, float y)
|
public float GetWaterLevel(PhaseShift phaseShift, float x, float y)
|
||||||
{
|
{
|
||||||
GridMap gmap = m_parentTerrainMap.GetGridMap(PhasingHandler.GetTerrainMapId(phaseShift, this, x, y), x, y);
|
GridMap gmap = GetGridMap(PhasingHandler.GetTerrainMapId(phaseShift, this, x, y), x, y);
|
||||||
if (gmap != null)
|
if (gmap != null)
|
||||||
return gmap.GetLiquidLevel(x, y);
|
return gmap.GetLiquidLevel(x, y);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -4320,6 +4349,7 @@ namespace Game.Maps
|
|||||||
List<Map> m_childTerrainMaps = new List<Map>(); // contains m_parentMap of maps that have MapEntry::ParentMapID == GetId()
|
List<Map> m_childTerrainMaps = new List<Map>(); // contains m_parentMap of maps that have MapEntry::ParentMapID == GetId()
|
||||||
SortedMultiMap<long, ScriptAction> m_scriptSchedule = new SortedMultiMap<long, ScriptAction>();
|
SortedMultiMap<long, ScriptAction> m_scriptSchedule = new SortedMultiMap<long, ScriptAction>();
|
||||||
|
|
||||||
|
BitSet i_gridFileExists = new BitSet(MapConst.MaxGrids * MapConst.MaxGrids); // cache what grids are available for this map (not including parent/child maps)
|
||||||
BitSet marked_cells = new BitSet(MapConst.TotalCellsPerMap * MapConst.TotalCellsPerMap);
|
BitSet marked_cells = new BitSet(MapConst.TotalCellsPerMap * MapConst.TotalCellsPerMap);
|
||||||
public Dictionary<uint, CreatureGroup> CreatureGroupHolder = new Dictionary<uint, CreatureGroup>();
|
public Dictionary<uint, CreatureGroup> CreatureGroupHolder = new Dictionary<uint, CreatureGroup>();
|
||||||
internal uint i_InstanceId;
|
internal uint i_InstanceId;
|
||||||
|
|||||||
@@ -60,9 +60,9 @@ namespace Game.Entities
|
|||||||
{
|
{
|
||||||
var entry = CliDB.MapStorage.LookupByKey(id);
|
var entry = CliDB.MapStorage.LookupByKey(id);
|
||||||
Cypher.Assert(entry != null);
|
Cypher.Assert(entry != null);
|
||||||
if (entry.ParentMapID != -1)
|
if (entry.ParentMapID != -1 || entry.CosmeticParentMapID != -1)
|
||||||
{
|
{
|
||||||
CreateBaseMap((uint)entry.ParentMapID);
|
CreateBaseMap((uint)(entry.ParentMapID != -1 ? entry.ParentMapID : entry.CosmeticParentMapID));
|
||||||
|
|
||||||
// must have been created by parent map
|
// must have been created by parent map
|
||||||
map = FindBaseMap(id);
|
map = FindBaseMap(id);
|
||||||
@@ -84,6 +84,8 @@ namespace Game.Entities
|
|||||||
else
|
else
|
||||||
map = new Map(mapEntry.Id, i_gridCleanUpDelay, 0, Difficulty.None);
|
map = new Map(mapEntry.Id, i_gridCleanUpDelay, 0, Difficulty.None);
|
||||||
|
|
||||||
|
map.DiscoverGridMapFiles();
|
||||||
|
|
||||||
i_maps[mapEntry.Id] = map;
|
i_maps[mapEntry.Id] = map;
|
||||||
|
|
||||||
foreach (uint childMapId in _parentMapData[mapEntry.Id])
|
foreach (uint childMapId in _parentMapData[mapEntry.Id])
|
||||||
@@ -265,16 +267,14 @@ namespace Game.Entities
|
|||||||
|
|
||||||
public void UnloadAll()
|
public void UnloadAll()
|
||||||
{
|
{
|
||||||
// first unlink child maps
|
// first unload maps
|
||||||
foreach (var pair in i_maps)
|
foreach (var pair in i_maps)
|
||||||
pair.Value.UnlinkAllChildTerrainMaps();
|
|
||||||
|
|
||||||
foreach (var pair in i_maps.ToList())
|
|
||||||
{
|
|
||||||
pair.Value.UnloadAll();
|
pair.Value.UnloadAll();
|
||||||
|
|
||||||
|
foreach (var pair in i_maps)
|
||||||
pair.Value.Dispose();
|
pair.Value.Dispose();
|
||||||
i_maps.Remove(pair.Key);
|
|
||||||
}
|
i_maps.Clear();
|
||||||
|
|
||||||
if (m_updater != null)
|
if (m_updater != null)
|
||||||
m_updater.Deactivate();
|
m_updater.Deactivate();
|
||||||
|
|||||||
@@ -471,19 +471,12 @@ namespace Game
|
|||||||
return phaseShift.VisibleMapIds.First().Key;
|
return phaseShift.VisibleMapIds.First().Key;
|
||||||
|
|
||||||
GridCoord gridCoord = GridDefines.ComputeGridCoord(x, y);
|
GridCoord gridCoord = GridDefines.ComputeGridCoord(x, y);
|
||||||
uint gx = (uint)((MapConst.MaxGrids - 1) - gridCoord.X_coord);
|
uint gx = ((MapConst.MaxGrids - 1) - gridCoord.X_coord);
|
||||||
uint gy = (uint)((MapConst.MaxGrids - 1) - gridCoord.Y_coord);
|
uint gy = ((MapConst.MaxGrids - 1) - gridCoord.Y_coord);
|
||||||
|
|
||||||
uint gxbegin = Math.Max(gx - 1, 0);
|
foreach (var visibleMap in phaseShift.VisibleMapIds)
|
||||||
uint gxend = Math.Min(gx + 1, MapConst.MaxGrids);
|
if (map.HasChildMapGridFile(visibleMap.Key, gx, gy))
|
||||||
uint gybegin = Math.Max(gy - 1, 0);
|
return visibleMap.Key;
|
||||||
uint gyend = Math.Min(gy + 1, MapConst.MaxGrids);
|
|
||||||
|
|
||||||
foreach (var itr in phaseShift.VisibleMapIds)
|
|
||||||
for (uint gxi = gxbegin; gxi < gxend; ++gxi)
|
|
||||||
for (uint gyi = gybegin; gyi < gyend; ++gyi)
|
|
||||||
if (map.HasGridMap(itr.Key, gxi, gyi))
|
|
||||||
return itr.Key;
|
|
||||||
|
|
||||||
return map.GetId();
|
return map.GetId();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -360,7 +360,12 @@ namespace Game
|
|||||||
foreach (MapRecord mapEntry in CliDB.MapStorage.Values)
|
foreach (MapRecord mapEntry in CliDB.MapStorage.Values)
|
||||||
{
|
{
|
||||||
if (mapEntry.ParentMapID != -1)
|
if (mapEntry.ParentMapID != -1)
|
||||||
|
{
|
||||||
|
Cypher.Assert(mapEntry.CosmeticParentMapID == -1 || mapEntry.ParentMapID == mapEntry.CosmeticParentMapID, $"Inconsistent parent map data for map {mapEntry.Id} (ParentMapID = {mapEntry.ParentMapID}, CosmeticParentMapID = {mapEntry.CosmeticParentMapID})");
|
||||||
mapData.Add((uint)mapEntry.ParentMapID, mapEntry.Id);
|
mapData.Add((uint)mapEntry.ParentMapID, mapEntry.Id);
|
||||||
|
}
|
||||||
|
else if (mapEntry.CosmeticParentMapID != -1)
|
||||||
|
mapData.Add((uint)mapEntry.CosmeticParentMapID, mapEntry.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Global.MapMgr.InitializeParentMapData(mapData);
|
Global.MapMgr.InitializeParentMapData(mapData);
|
||||||
|
|||||||
Reference in New Issue
Block a user