Adds style cop (#109)
This commit is contained in:
parent
3e715bcb60
commit
556a17aba8
1725 changed files with 33831 additions and 38046 deletions
|
|
@ -24,11 +24,11 @@ namespace Server.PathAlgorithms.FastAStar
|
|||
private const int PlaneHeight = 20;
|
||||
public static PathAlgorithm Instance = new FastAStarAlgorithm();
|
||||
|
||||
private static Direction[] m_Path = new Direction[AreaSize * AreaSize];
|
||||
private static PathNode[] m_Nodes = new PathNode[NodeCount];
|
||||
private static BitArray m_Touched = new BitArray(NodeCount);
|
||||
private static BitArray m_OnOpen = new BitArray(NodeCount);
|
||||
private static int[] m_Successors = new int[8];
|
||||
private static readonly Direction[] m_Path = new Direction[AreaSize * AreaSize];
|
||||
private static readonly PathNode[] m_Nodes = new PathNode[NodeCount];
|
||||
private static readonly BitArray m_Touched = new BitArray(NodeCount);
|
||||
private static readonly BitArray m_OnOpen = new BitArray(NodeCount);
|
||||
private static readonly int[] m_Successors = new int[8];
|
||||
|
||||
private static int m_xOffset, m_yOffset;
|
||||
private static int m_OpenList;
|
||||
|
|
@ -158,26 +158,26 @@ namespace Server.PathAlgorithms.FastAStar
|
|||
|
||||
if (wasTouched)
|
||||
continue;
|
||||
|
||||
|
||||
int newCost = m_Nodes[bestNode].cost + 1;
|
||||
int newTotal = newCost + Heuristic(newNode % AreaSize, newNode / AreaSize % AreaSize,
|
||||
m_Nodes[newNode].z);
|
||||
m_Nodes[newNode].z);
|
||||
|
||||
if (m_Nodes[newNode].total <= newTotal)
|
||||
continue;
|
||||
|
||||
|
||||
m_Nodes[newNode].parent = bestNode;
|
||||
m_Nodes[newNode].cost = newCost;
|
||||
m_Nodes[newNode].total = newTotal;
|
||||
|
||||
if (m_OnOpen[newNode])
|
||||
continue;
|
||||
|
||||
|
||||
AddToChain(newNode);
|
||||
|
||||
if (newNode != destNode)
|
||||
continue;
|
||||
|
||||
|
||||
int pathCount = 0;
|
||||
int parent = m_Nodes[newNode].parent;
|
||||
|
||||
|
|
@ -311,4 +311,4 @@ namespace Server.PathAlgorithms.FastAStar
|
|||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
#region References
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Server.Movement
|
||||
{
|
||||
public class FastMovementImpl : IMovementImpl
|
||||
|
|
@ -156,7 +152,7 @@ namespace Server.Movement
|
|||
if ((itemData.Flags & ImpassableSurface) == 0) return true;
|
||||
|
||||
if (((itemData.Flags & TileFlag.Door) != 0 || itemID == 0x692 || itemID == 0x846 || itemID == 0x873 ||
|
||||
itemID >= 0x6F5 && itemID <= 0x6F6) && ignoreDoors)
|
||||
(itemID >= 0x6F5 && itemID <= 0x6F6)) && ignoreDoors)
|
||||
return true;
|
||||
|
||||
if ((itemID == 0x82 || itemID == 0x3946 || itemID == 0x3956) && ignoreSpellFields) return true;
|
||||
|
|
@ -217,14 +213,10 @@ namespace Server.Movement
|
|||
ItemData itemData;
|
||||
TileFlag flags;
|
||||
|
||||
#region Tiles
|
||||
|
||||
foreach (StaticTile tile in tiles)
|
||||
{
|
||||
itemData = TileData.ItemTable[tile.ID & TileData.MaxItemValue];
|
||||
|
||||
#region SA
|
||||
|
||||
if (m.Flying && Insensitive.Equals(itemData.Name, "hover over"))
|
||||
{
|
||||
newZ = tile.Z;
|
||||
|
|
@ -242,7 +234,7 @@ namespace Server.Movement
|
|||
}
|
||||
else if (x >= 42 && x <= 89)
|
||||
{
|
||||
if (y >= 333 && y <= 399 || y >= 531 && y <= 597 || y >= 739 && y <= 805)
|
||||
if ((y >= 333 && y <= 399) || (y >= 531 && y <= 597) || (y >= 739 && y <= 805))
|
||||
{
|
||||
if (tile.Z > newZ) newZ = tile.Z;
|
||||
|
||||
|
|
@ -251,8 +243,6 @@ namespace Server.Movement
|
|||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
flags = itemData.Flags;
|
||||
|
||||
if ((flags & ImpassableSurface) != TileFlag.Surface && (!canSwim || (flags & TileFlag.Wet) == 0)) continue;
|
||||
|
|
@ -269,7 +259,7 @@ namespace Server.Movement
|
|||
{
|
||||
int cmp = Math.Abs(ourZ - m.Z) - Math.Abs(newZ - m.Z);
|
||||
|
||||
if (cmp > 0 || cmp == 0 && ourZ > newZ) continue;
|
||||
if (cmp > 0 || (cmp == 0 && ourZ > newZ)) continue;
|
||||
}
|
||||
|
||||
if (ourTop > testTop) testTop = ourTop;
|
||||
|
|
@ -293,25 +283,17 @@ namespace Server.Movement
|
|||
moveIsOk = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Items
|
||||
|
||||
foreach (Item item in items)
|
||||
{
|
||||
itemData = item.ItemData;
|
||||
flags = itemData.Flags;
|
||||
|
||||
#region SA
|
||||
|
||||
if (m.Flying && Insensitive.Equals(itemData.Name, "hover over"))
|
||||
{
|
||||
newZ = item.Z;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
if (item.Movable) continue;
|
||||
|
||||
if ((flags & ImpassableSurface) != TileFlag.Surface && (!m.CanSwim || (flags & TileFlag.Wet) == 0)) continue;
|
||||
|
|
@ -328,7 +310,7 @@ namespace Server.Movement
|
|||
{
|
||||
int cmp = Math.Abs(ourZ - m.Z) - Math.Abs(newZ - m.Z);
|
||||
|
||||
if (cmp > 0 || cmp == 0 && ourZ > newZ) continue;
|
||||
if (cmp > 0 || (cmp == 0 && ourZ > newZ)) continue;
|
||||
}
|
||||
|
||||
if (ourTop > testTop) testTop = ourTop;
|
||||
|
|
@ -352,8 +334,6 @@ namespace Server.Movement
|
|||
moveIsOk = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
if (!considerLand || landBlocks || stepTop < landZ) return moveIsOk;
|
||||
|
||||
ourZ = landCenter;
|
||||
|
|
@ -368,7 +348,7 @@ namespace Server.Movement
|
|||
{
|
||||
int cmp = Math.Abs(ourZ - m.Z) - Math.Abs(newZ - m.Z);
|
||||
|
||||
if (cmp > 0 || cmp == 0 && ourZ > newZ) shouldCheck = false;
|
||||
if (cmp > 0 || (cmp == 0 && ourZ > newZ)) shouldCheck = false;
|
||||
}
|
||||
|
||||
if (!shouldCheck || !IsOk(ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items)) return moveIsOk;
|
||||
|
|
|
|||
|
|
@ -12,29 +12,29 @@ namespace Server.Movement
|
|||
|
||||
private const TileFlag ImpassableSurface = TileFlag.Impassable | TileFlag.Surface;
|
||||
|
||||
private List<Mobile>[] m_MobPools = {
|
||||
private readonly List<Mobile>[] m_MobPools = {
|
||||
new List<Mobile>(), new List<Mobile>(),
|
||||
new List<Mobile>()
|
||||
};
|
||||
|
||||
private List<Item>[] m_Pools = {
|
||||
private readonly List<Item>[] m_Pools = {
|
||||
new List<Item>(), new List<Item>(),
|
||||
new List<Item>(), new List<Item>()
|
||||
};
|
||||
|
||||
private List<Sector> m_Sectors = new List<Sector>();
|
||||
private readonly List<Sector> m_Sectors = new List<Sector>();
|
||||
|
||||
private MovementImpl()
|
||||
{
|
||||
}
|
||||
|
||||
public static bool AlwaysIgnoreDoors{ get; set; }
|
||||
public static bool AlwaysIgnoreDoors { get; set; }
|
||||
|
||||
public static bool IgnoreMovableImpassables{ get; set; }
|
||||
public static bool IgnoreMovableImpassables { get; set; }
|
||||
|
||||
public static bool IgnoreSpellFields{ get; set; }
|
||||
public static bool IgnoreSpellFields { get; set; }
|
||||
|
||||
public static Point3D Goal{ get; set; }
|
||||
public static Point3D Goal { get; set; }
|
||||
|
||||
public bool CheckMovement(Mobile m, Map map, Point3D loc, Direction d, out int newZ)
|
||||
{
|
||||
|
|
@ -299,7 +299,7 @@ namespace Server.Movement
|
|||
if ((flags & ImpassableSurface) != 0) // Impassable || Surface
|
||||
{
|
||||
if (ignoreDoors && ((flags & TileFlag.Door) != 0 || itemID == 0x692 || itemID == 0x846 ||
|
||||
itemID == 0x873 || itemID >= 0x6F5 && itemID <= 0x6F6))
|
||||
itemID == 0x873 || (itemID >= 0x6F5 && itemID <= 0x6F6)))
|
||||
continue;
|
||||
|
||||
if (ignoreSpellFields && (itemID == 0x82 || itemID == 0x3946 || itemID == 0x3956))
|
||||
|
|
@ -327,11 +327,9 @@ namespace Server.Movement
|
|||
bool landBlocks = (TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Impassable) != 0;
|
||||
bool considerLand = !landTile.Ignored;
|
||||
|
||||
if (landBlocks && canSwim && (TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Wet) != 0
|
||||
) //Impassable, Can Swim, and Is water. Don't block it.
|
||||
if (landBlocks && canSwim && (TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Wet) != 0) // Impassable, Can Swim, and Is water. Don't block it.
|
||||
landBlocks = false;
|
||||
else if (cantWalk && (TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Wet) == 0
|
||||
) //Can't walk and it's not water
|
||||
else if (cantWalk && (TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Wet) == 0) // Can't walk and it's not water
|
||||
landBlocks = true;
|
||||
|
||||
int landZ = 0, landCenter = 0, landTop = 0;
|
||||
|
|
@ -346,7 +344,6 @@ namespace Server.Movement
|
|||
bool ignoreDoors = AlwaysIgnoreDoors || !m.Alive || m.Body.BodyID == 0x3DB || m.IsDeadBondedPet;
|
||||
bool ignoreSpellFields = m is PlayerMobile && map != Map.Felucca;
|
||||
|
||||
#region Tiles
|
||||
for (int i = 0; i < tiles.Length; ++i)
|
||||
{
|
||||
StaticTile tile = tiles[i];
|
||||
|
|
@ -369,7 +366,7 @@ namespace Server.Movement
|
|||
{
|
||||
int cmp = Math.Abs(ourZ - m.Z) - Math.Abs(newZ - m.Z);
|
||||
|
||||
if (cmp > 0 || cmp == 0 && ourZ > newZ)
|
||||
if (cmp > 0 || (cmp == 0 && ourZ > newZ))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -399,10 +396,6 @@ namespace Server.Movement
|
|||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Items
|
||||
|
||||
for (int i = 0; i < items.Count; ++i)
|
||||
{
|
||||
Item item = items[i];
|
||||
|
|
@ -410,7 +403,7 @@ namespace Server.Movement
|
|||
TileFlag flags = itemData.Flags;
|
||||
|
||||
if (!item.Movable && ((flags & ImpassableSurface) == TileFlag.Surface ||
|
||||
m.CanSwim && (flags & TileFlag.Wet) != 0)) // Surface && !Impassable && !Movable
|
||||
(m.CanSwim && (flags & TileFlag.Wet) != 0))) // Surface && !Impassable && !Movable
|
||||
{
|
||||
if (cantWalk && (flags & TileFlag.Wet) == 0)
|
||||
continue;
|
||||
|
|
@ -424,7 +417,7 @@ namespace Server.Movement
|
|||
{
|
||||
int cmp = Math.Abs(ourZ - m.Z) - Math.Abs(newZ - m.Z);
|
||||
|
||||
if (cmp > 0 || cmp == 0 && ourZ > newZ)
|
||||
if (cmp > 0 || (cmp == 0 && ourZ > newZ))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -455,8 +448,6 @@ namespace Server.Movement
|
|||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
if (considerLand && !landBlocks && stepTop >= landZ)
|
||||
{
|
||||
int ourZ = landCenter;
|
||||
|
|
@ -471,7 +462,7 @@ namespace Server.Movement
|
|||
{
|
||||
int cmp = Math.Abs(ourZ - m.Z) - Math.Abs(newZ - m.Z);
|
||||
|
||||
if (cmp > 0 || cmp == 0 && ourZ > newZ)
|
||||
if (cmp > 0 || (cmp == 0 && ourZ > newZ))
|
||||
shouldCheck = false;
|
||||
}
|
||||
|
||||
|
|
@ -482,8 +473,6 @@ namespace Server.Movement
|
|||
}
|
||||
}
|
||||
|
||||
#region Mobiles
|
||||
|
||||
for (int i = 0; moveIsOk && i < mobiles.Count; ++i)
|
||||
{
|
||||
Mobile mob = mobiles[i];
|
||||
|
|
@ -491,14 +480,13 @@ namespace Server.Movement
|
|||
if (mob != m && mob.Z + 15 > newZ && newZ + 15 > mob.Z && !CanMoveOver(m, mob))
|
||||
moveIsOk = false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
return moveIsOk;
|
||||
}
|
||||
|
||||
private bool CanMoveOver(Mobile m, Mobile t) =>
|
||||
!t.Alive || !m.Alive || t.IsDeadBondedPet || m.IsDeadBondedPet ||
|
||||
t.Hidden && t.AccessLevel > AccessLevel.Player;
|
||||
(t.Hidden && t.AccessLevel > AccessLevel.Player);
|
||||
|
||||
private void GetStartZ(Mobile m, Map map, Point3D loc, List<Item> itemList, out int zLow, out int zTop)
|
||||
{
|
||||
|
|
@ -542,7 +530,7 @@ namespace Server.Movement
|
|||
int calcTop = tile.Z + id.CalcHeight;
|
||||
|
||||
if ((!isSet || calcTop >= zCenter) &&
|
||||
((id.Flags & TileFlag.Surface) != 0 || m.CanSwim && (id.Flags & TileFlag.Wet) != 0) && loc.Z >= calcTop)
|
||||
((id.Flags & TileFlag.Surface) != 0 || (m.CanSwim && (id.Flags & TileFlag.Wet) != 0)) && loc.Z >= calcTop)
|
||||
{
|
||||
if (m.CantWalk && (id.Flags & TileFlag.Wet) == 0)
|
||||
continue;
|
||||
|
|
@ -564,7 +552,7 @@ namespace Server.Movement
|
|||
int calcTop = item.Z + id.CalcHeight;
|
||||
|
||||
if ((!isSet || calcTop >= zCenter) &&
|
||||
((id.Flags & TileFlag.Surface) != 0 || m.CanSwim && (id.Flags & TileFlag.Wet) != 0) && loc.Z >= calcTop)
|
||||
((id.Flags & TileFlag.Surface) != 0 || (m.CanSwim && (id.Flags & TileFlag.Wet) != 0)) && loc.Z >= calcTop)
|
||||
{
|
||||
if (m.CantWalk && (id.Flags & TileFlag.Wet) == 0)
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -38,17 +38,17 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public Map Map{ get; }
|
||||
public Map Map { get; }
|
||||
|
||||
public Point3D Start{ get; }
|
||||
public Point3D Start { get; }
|
||||
|
||||
public Point3D Goal{ get; }
|
||||
public Point3D Goal { get; }
|
||||
|
||||
public Direction[] Directions{ get; }
|
||||
public Direction[] Directions { get; }
|
||||
|
||||
public bool Success => Directions?.Length > 0;
|
||||
|
||||
public static PathAlgorithm OverrideAlgorithm{ get; set; }
|
||||
public static PathAlgorithm OverrideAlgorithm { get; set; }
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ namespace Server.PathAlgorithms
|
|||
{
|
||||
public abstract class PathAlgorithm
|
||||
{
|
||||
private static Direction[] m_CalcDirections = {
|
||||
private static readonly Direction[] m_CalcDirections = {
|
||||
Direction.Up,
|
||||
Direction.North,
|
||||
Direction.Right,
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ namespace Server
|
|||
public class PathFollower
|
||||
{
|
||||
// Should we use pathfinding? 'false' for not
|
||||
private static bool Enabled = true;
|
||||
private static readonly bool Enabled = true;
|
||||
|
||||
private static TimeSpan RepathDelay = TimeSpan.FromSeconds(2.0);
|
||||
private static readonly TimeSpan RepathDelay = TimeSpan.FromSeconds(2.0);
|
||||
|
||||
private Mobile m_From;
|
||||
private readonly Mobile m_From;
|
||||
private int m_Index;
|
||||
private DateTime m_LastPathTime;
|
||||
private Point3D m_Next, m_LastGoalLoc;
|
||||
|
|
@ -22,9 +22,9 @@ namespace Server
|
|||
Goal = goal;
|
||||
}
|
||||
|
||||
public MoveMethod Mover{ get; set; }
|
||||
public MoveMethod Mover { get; set; }
|
||||
|
||||
public IPoint3D Goal{ get; }
|
||||
public IPoint3D Goal { get; }
|
||||
|
||||
public MoveResult Move(Direction d)
|
||||
{
|
||||
|
|
@ -72,7 +72,7 @@ namespace Server
|
|||
|
||||
Point3D goal = GetGoalLocation();
|
||||
|
||||
if (m_Path != null && (m_Path.Success && goal == m_LastGoalLoc || m_LastPathTime + RepathDelay > DateTime.Now) &&
|
||||
if (m_Path != null && ((m_Path.Success && goal == m_LastGoalLoc) || m_LastPathTime + RepathDelay > DateTime.Now) &&
|
||||
!(m_Path.Success && Check(m_From.Location, m_LastGoalLoc, 0)))
|
||||
return false;
|
||||
|
||||
|
|
@ -87,7 +87,6 @@ namespace Server
|
|||
Advance(ref m_Next, m_Index);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public bool Check(Point3D loc, Point3D goal, int range) => Utility.InRange(loc, goal, range) && (range > 1 || Math.Abs(loc.Z - goal.Z) < 16);
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ namespace Server.PathAlgorithms.SlowAStar
|
|||
private const int MaxNodes = MaxDepth * 16;
|
||||
public static PathAlgorithm Instance = new SlowAStarAlgorithm();
|
||||
|
||||
private static PathNode[] m_Closed = new PathNode[MaxNodes];
|
||||
private static PathNode[] m_Open = new PathNode[MaxNodes];
|
||||
private static PathNode[] m_Successors = new PathNode[8];
|
||||
private static Direction[] m_Path = new Direction[MaxNodes];
|
||||
private static readonly PathNode[] m_Closed = new PathNode[MaxNodes];
|
||||
private static readonly PathNode[] m_Open = new PathNode[MaxNodes];
|
||||
private static readonly PathNode[] m_Successors = new PathNode[8];
|
||||
private static readonly Direction[] m_Path = new Direction[MaxNodes];
|
||||
|
||||
private Point3D m_Goal;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue