Skip to content

Commit

Permalink
[DEBUG] Try Catch and log GetCell crash (#4187)
Browse files Browse the repository at this point in the history
* [DEBUG] Try Catch and log GetCell crash

* Update PositionExtensions.cs
  • Loading branch information
LtRipley36706 authored Sep 16, 2024
1 parent a15dadd commit 5daa276
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions Source/ACE.Server/Entity/PositionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,50 +78,61 @@ public static Position FromGlobal(this Position p, Vector3 pos)
/// </summary>
public static uint GetCell(this Position p)
{
var landblock = LScape.get_landblock(p.LandblockId.Raw);

// dungeons
// TODO: investigate dungeons that are below actual traversable overworld terrain
// ex., 010AFFFF
//if (landblock.IsDungeon)
if (p.Indoors)
return GetIndoorCell(p);
try
{
//var landblock = LScape.get_landblock(p.LandblockId.Raw);

// outside - could be on landscape, in building, or underground cave
var cellID = GetOutdoorCell(p);
var landcell = LScape.get_landcell(cellID) as LandCell;
// dungeons
// TODO: investigate dungeons that are below actual traversable overworld terrain
// ex., 010AFFFF
//if (landblock.IsDungeon)
if (p.Indoors)
return GetIndoorCell(p);

if (landcell == null)
return cellID;
// outside - could be on landscape, in building, or underground cave
var cellID = GetOutdoorCell(p);
var landcell = LScape.get_landcell(cellID) as LandCell;

if (landcell.has_building())
{
var envCells = landcell.Building.get_building_cells();
foreach (var envCell in envCells)
if (envCell.point_in_cell(p.Pos))
return envCell.ID;
}
if (landcell == null)
return cellID;

// handle underground areas ie. caves
// get the terrain Z-height for this X/Y
Physics.Polygon walkable = null;
var terrainPoly = landcell.find_terrain_poly(p.Pos, ref walkable);
if (walkable != null)
{
Vector3 terrainPos = p.Pos;
walkable.Plane.set_height(ref terrainPos);

// are we below ground? if so, search all of the indoor cells for this landblock
if (terrainPos.Z > p.Pos.Z)
if (landcell.has_building())
{
var envCells = landblock.get_envcells();
var envCells = landcell.Building.get_building_cells();
foreach (var envCell in envCells)
if (envCell.point_in_cell(p.Pos))
return envCell.ID;
}

// handle underground areas ie. caves
// get the terrain Z-height for this X/Y
Physics.Polygon walkable = null;
var terrainPoly = landcell.find_terrain_poly(p.Pos, ref walkable);
if (walkable != null)
{
Vector3 terrainPos = p.Pos;
walkable.Plane.set_height(ref terrainPos);

// are we below ground? if so, search all of the indoor cells for this landblock
if (terrainPos.Z > p.Pos.Z)
{
var landblock = LScape.get_landblock(p.LandblockId.Raw);
var envCells = landblock.get_envcells();
foreach (var envCell in envCells)
if (envCell.point_in_cell(p.Pos))
return envCell.ID;
}
}

return cellID;
}
catch (Exception e)
{
log.ErrorFormat("GetCell() threw an exception: {0}\nposition as LOC => {1}", e.ToString(), p.ToLOCString());
log.Error(e);

return cellID;
return 0;
}
}

/// <summary>
Expand Down

0 comments on commit 5daa276

Please sign in to comment.