Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman committed Feb 2, 2025
1 parent f4f8fee commit f43bd51
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions Projects/Server/Maps/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -986,14 +986,7 @@ public bool LineOfSight(Point3D origin, Point3D destination)
(origin, destination) = (destination, origin);
}

Point3D p;
var path = new Point3DList();
TileFlag flags;

if (path.Count > 0)
{
path.Clear();
}

var xd = destination.X - origin.X;
var yd = destination.Y - origin.Y;
Expand All @@ -1008,15 +1001,17 @@ public bool LineOfSight(Point3D origin, Point3D destination)
double y = origin.Y;
double z = origin.Z;
double x = origin.X;
while (Utility.NumberBetween(x, destination.X, origin.X, 0.5) && Utility.NumberBetween(y, destination.Y, origin.Y, 0.5) &&
while (Utility.NumberBetween(x, destination.X, origin.X, 0.5) &&
Utility.NumberBetween(y, destination.Y, origin.Y, 0.5) &&
Utility.NumberBetween(z, destination.Z, origin.Z, 0.5))
{
var ix = (int)Math.Round(x);
var iy = (int)Math.Round(y);
var iz = (int)Math.Round(z);

if (path.Count > 0)
{
p = path.Last;
var p = path.Last;

if (p.X != ix || p.Y != iy || p.Z != iz)
{
Expand All @@ -1038,17 +1033,11 @@ public bool LineOfSight(Point3D origin, Point3D destination)
return true; // <--should never happen, but to be safe.
}

p = path.Last;

if (p != destination)
if (path.Last != destination)
{
path.Add(destination);
}

var pTop = origin;
var pBottom = destination;
Utility.FixPoints(ref pTop, ref pBottom);

var pathCount = path.Count;
var endTop = end.Z + 1;

Expand Down Expand Up @@ -1089,7 +1078,7 @@ public bool LineOfSight(Point3D origin, Point3D destination)

var id = TileData.ItemTable[t.ID & TileData.MaxItemValue];

flags = id.Flags;
var flags = id.Flags;

if (
t.Z <= pointTop && t.Z + id.CalcHeight >= point.Z &&
Expand Down Expand Up @@ -1121,6 +1110,10 @@ public bool LineOfSight(Point3D origin, Point3D destination)
}
}

var pTop = origin;
var pBottom = destination;
Utility.FixPoints(ref pTop, ref pBottom);

var rect = new Rectangle2D(pTop.X, pTop.Y, pBottom.X - pTop.X + 1, pBottom.Y - pTop.Y + 1);

foreach (var item in GetItemsInBounds(rect))
Expand All @@ -1136,7 +1129,7 @@ public bool LineOfSight(Point3D origin, Point3D destination)
}

var id = item.ItemData;
flags = id.Flags;
var flags = id.Flags;

if ((flags & (TileFlag.Window | TileFlag.NoShoot)) == 0)
{
Expand All @@ -1161,7 +1154,7 @@ public bool LineOfSight(Point3D origin, Point3D destination)
// Fix door bugging monsters when door is at the START or END of the LOS path by allowing LOS
!(flags.HasFlag(TileFlag.Door) &&
itemLocation.X == origin.X && itemLocation.Y == origin.Y ||
itemLocation.X == end.X && itemLocation.Y == end.Y) &&
itemLocation.X == destination.X && itemLocation.Y == destination.Y) &&

// Item is at some point along the path BEFORE the target
(itemLocation.X != end.X ||
Expand Down

0 comments on commit f43bd51

Please sign in to comment.