Replace every usage of GridCoordinates with EntityCoordinates (#2021)

* Update RobustToolbox

* Transition direct type usages

* More updates

* Fix invalid use of to map

* Update RobustToolbox

* Fix dropping items

* Rename name usages of "GridCoordinates" to "EntityCoordinates"

* Revert "Update RobustToolbox"

This reverts commit 9f334a17c5908ded0043a63158bb671e4aa3f346.

* Revert "Update RobustToolbox"

This reverts commit 3a9c8cfa3606fa501aa84407796d2ad920853a09.

# Conflicts:
#	RobustToolbox

* Fix cursed IMapGrid method usage.

* GridTileLookupTest now uses EntityCoordinates

Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
Co-authored-by: Víctor Aguilera Puerto <zddm@outlook.es>
This commit is contained in:
DrSmugleaf
2020-09-06 16:11:53 +02:00
committed by GitHub
parent 72d2318ea7
commit 48b61f6bcc
196 changed files with 780 additions and 676 deletions

View File

@@ -38,6 +38,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
*/
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
private PathfindingSystem _pathfindingSystem;
@@ -160,7 +161,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
/// <returns></returns>
public bool CanAccess(IEntity entity, IEntity target, float range = 0.0f)
{
var targetTile = _mapManager.GetGrid(target.Transform.GridID).GetTileRef(target.Transform.GridPosition);
var targetTile = _mapManager.GetGrid(target.Transform.GridID).GetTileRef(target.Transform.Coordinates);
var targetNode = _pathfindingSystem.GetNode(targetTile);
var collisionMask = 0;
@@ -198,7 +199,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
return false;
}
var entityTile = _mapManager.GetGrid(entity.Transform.GridID).GetTileRef(entity.Transform.GridPosition);
var entityTile = _mapManager.GetGrid(entity.Transform.GridID).GetTileRef(entity.Transform.Coordinates);
var entityNode = _pathfindingSystem.GetNode(entityTile);
var entityRegion = GetRegion(entityNode);
var targetRegion = GetRegion(targetNode);
@@ -408,7 +409,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
/// <returns></returns>
public PathfindingRegion GetRegion(IEntity entity)
{
var entityTile = _mapManager.GetGrid(entity.Transform.GridID).GetTileRef(entity.Transform.GridPosition);
var entityTile = _mapManager.GetGrid(entity.Transform.GridID).GetTileRef(entity.Transform.Coordinates);
var entityNode = _pathfindingSystem.GetNode(entityTile);
return GetRegion(entityNode);
}
@@ -632,7 +633,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
{
return;
}
if (!_regions.ContainsKey(chunk.GridId))
{
_regions.Add(chunk.GridId, new Dictionary<PathfindingChunk, HashSet<PathfindingRegion>>());
@@ -714,7 +715,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
foreach (var node in region.Nodes)
{
var nodeVector = grid.GridTileToLocal(node.TileRef.GridIndices).ToMapPos(_mapManager);
var nodeVector = grid.GridTileToLocal(node.TileRef.GridIndices).ToMapPos(_entityManager);
debugRegionNodes.Add(nodeVector);
}
@@ -743,7 +744,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
foreach (var node in region.Nodes)
{
var nodeVector = grid.GridTileToLocal(node.TileRef.GridIndices).ToMapPos(_mapManager);
var nodeVector = grid.GridTileToLocal(node.TileRef.GridIndices).ToMapPos(_entityManager);
debugResult[_runningCacheIdx].Add(nodeVector);
}

View File

@@ -30,6 +30,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
public class PathfindingSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public IReadOnlyDictionary<GridId, Dictionary<MapIndices, PathfindingChunk>> Graph => _graph;
private readonly Dictionary<GridId, Dictionary<MapIndices, PathfindingChunk>> _graph = new Dictionary<GridId, Dictionary<MapIndices, PathfindingChunk>>();
@@ -180,7 +181,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
/// <returns></returns>
public PathfindingNode GetNode(IEntity entity)
{
var tile = _mapManager.GetGrid(entity.Transform.GridID).GetTileRef(entity.Transform.GridPosition);
var tile = _mapManager.GetGrid(entity.Transform.GridID).GetTileRef(entity.Transform.Coordinates);
return GetNode(tile);
}
@@ -280,7 +281,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
}
var grid = _mapManager.GetGrid(entity.Transform.GridID);
var tileRef = grid.GetTileRef(entity.Transform.GridPosition);
var tileRef = grid.GetTileRef(entity.Transform.Coordinates);
var chunk = GetChunk(tileRef);
var node = chunk.GetNode(tileRef);
@@ -337,7 +338,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
// The pathfinding graph is tile-based so first we'll check if they're on a different tile and if we need to update.
// If you get entities bigger than 1 tile wide you'll need some other system so god help you.
var newTile = _mapManager.GetGrid(moveEvent.NewPosition.GridID).GetTileRef(moveEvent.NewPosition);
var newTile = _mapManager.GetGrid(moveEvent.NewPosition.GetGridId(_entityManager)).GetTileRef(moveEvent.NewPosition);
if (oldNode == null || oldNode.TileRef == newTile)
{
@@ -359,9 +360,10 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
// TODO: Need to rethink the pathfinder utils (traversable etc.). Maybe just chuck them all in PathfindingSystem
// Otherwise you get the steerer using this and the pathfinders using a different traversable.
// Also look at increasing tile cost the more physics entities are on it
public bool CanTraverse(IEntity entity, GridCoordinates grid)
public bool CanTraverse(IEntity entity, EntityCoordinates coordinates)
{
var tile = _mapManager.GetGrid(grid.GridID).GetTileRef(grid);
var gridId = coordinates.GetGridId(_entityManager);
var tile = _mapManager.GetGrid(gridId).GetTileRef(coordinates);
var node = GetNode(tile);
return CanTraverse(entity, node);
}

View File

@@ -35,16 +35,16 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
foreach (var tile in routeDebug.Route)
{
var tileGrid = mapManager.GetGrid(tile.GridIndex).GridTileToLocal(tile.GridIndices);
route.Add(mapManager.GetGrid(tile.GridIndex).LocalToWorld(tileGrid).Position);
route.Add(tileGrid.ToMapPos(EntityManager));
}
var cameFrom = new Dictionary<Vector2, Vector2>();
foreach (var (from, to) in routeDebug.CameFrom)
{
var tileOneGrid = mapManager.GetGrid(from.GridIndex).GridTileToLocal(from.GridIndices);
var tileOneWorld = mapManager.GetGrid(from.GridIndex).LocalToWorld(tileOneGrid).Position;
var tileOneWorld = tileOneGrid.ToMapPos(EntityManager);
var tileTwoGrid = mapManager.GetGrid(to.GridIndex).GridTileToLocal(to.GridIndices);
var tileTwoWorld = mapManager.GetGrid(to.GridIndex).LocalToWorld(tileTwoGrid).Position;
var tileTwoWorld = tileTwoGrid.ToMapPos(EntityManager);
cameFrom.Add(tileOneWorld, tileTwoWorld);
}
@@ -52,7 +52,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
foreach (var (tile, score) in routeDebug.GScores)
{
var tileGrid = mapManager.GetGrid(tile.GridIndex).GridTileToLocal(tile.GridIndices);
gScores.Add(mapManager.GetGrid(tile.GridIndex).LocalToWorld(tileGrid).Position, score);
gScores.Add(tileGrid.ToMapPos(EntityManager), score);
}
var systemMessage = new SharedAiDebug.AStarRouteMessage(
@@ -73,14 +73,14 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
foreach (var tile in routeDebug.Route)
{
var tileGrid = mapManager.GetGrid(tile.GridIndex).GridTileToLocal(tile.GridIndices);
route.Add(mapManager.GetGrid(tile.GridIndex).LocalToWorld(tileGrid).Position);
route.Add(tileGrid.ToMapPos(EntityManager));
}
var jumpNodes = new List<Vector2>();
foreach (var tile in routeDebug.JumpNodes)
{
var tileGrid = mapManager.GetGrid(tile.GridIndex).GridTileToLocal(tile.GridIndices);
jumpNodes.Add(mapManager.GetGrid(tile.GridIndex).LocalToWorld(tileGrid).Position);
jumpNodes.Add(tileGrid.ToMapPos(EntityManager));
}
var systemMessage = new SharedAiDebug.JpsRouteMessage(

View File

@@ -25,8 +25,9 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
public sealed class AiSteeringSystem : EntitySystem
{
// http://www.red3d.com/cwr/papers/1999/gdc99steer.html for a steering overview
[Dependency] private IMapManager _mapManager = default!;
[Dependency] private IPauseManager _pauseManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPauseManager _pauseManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
private PathfindingSystem _pathfindingSystem;
@@ -57,7 +58,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
private int _listIndex;
// Cache nextGrid
private readonly Dictionary<IEntity, GridCoordinates> _nextGrid = new Dictionary<IEntity, GridCoordinates>();
private readonly Dictionary<IEntity, EntityCoordinates> _nextGrid = new Dictionary<IEntity, EntityCoordinates>();
/// <summary>
/// Current live paths for AI
@@ -78,11 +79,11 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
/// <summary>
/// Get a fixed position for the target entity; if they move then re-path
/// </summary>
private readonly Dictionary<IEntity, GridCoordinates> _entityTargetPosition = new Dictionary<IEntity, GridCoordinates>();
private readonly Dictionary<IEntity, EntityCoordinates> _entityTargetPosition = new Dictionary<IEntity, EntityCoordinates>();
// Anti-Stuck
// Given the collision avoidance can lead to twitching need to store a reference position and check if we've been near this too long
private readonly Dictionary<IEntity, GridCoordinates> _stuckPositions = new Dictionary<IEntity, GridCoordinates>();
private readonly Dictionary<IEntity, EntityCoordinates> _stuckPositions = new Dictionary<IEntity, EntityCoordinates>();
public override void Initialize()
{
@@ -268,7 +269,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
// Validation
// Check if we can even arrive -> Currently only samegrid movement supported
if (entity.Transform.GridID != steeringRequest.TargetGrid.GridID)
if (entity.Transform.GridID != steeringRequest.TargetGrid.GetGridId(_entityManager))
{
controller.VelocityDir = Vector2.Zero;
return SteeringStatus.NoPath;
@@ -413,7 +414,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
var cancelToken = new CancellationTokenSource();
var gridManager = _mapManager.GetGrid(entity.Transform.GridID);
var startTile = gridManager.GetTileRef(entity.Transform.GridPosition);
var startTile = gridManager.GetTileRef(entity.Transform.Coordinates);
var endTile = gridManager.GetTileRef(steeringRequest.TargetGrid);
var collisionMask = 0;
if (entity.TryGetComponent(out ICollidableComponent collidableComponent))
@@ -443,7 +444,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
{
_pathfindingRequests.Remove(entity);
var entityTile = _mapManager.GetGrid(entity.Transform.GridID).GetTileRef(entity.Transform.GridPosition);
var entityTile = _mapManager.GetGrid(entity.Transform.GridID).GetTileRef(entity.Transform.Coordinates);
var tile = path.Dequeue();
var closestDistance = PathfindingHelpers.OctileDistance(entityTile, tile);
@@ -465,12 +466,12 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
}
/// <summary>
/// Get the next tile as GridCoordinates
/// Get the next tile as EntityCoordinates
/// </summary>
/// <param name="entity"></param>
/// <param name="steeringRequest"></param>
/// <returns></returns>
private GridCoordinates? NextGrid(IEntity entity, IAiSteeringRequest steeringRequest)
private EntityCoordinates? NextGrid(IEntity entity, IAiSteeringRequest steeringRequest)
{
// Remove the cached grid
if (!_paths.ContainsKey(entity) && _nextGrid.ContainsKey(entity))
@@ -481,7 +482,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
// If no tiles left just move towards the target (if we're close)
if (!_paths.ContainsKey(entity) || _paths[entity].Count == 0)
{
if ((steeringRequest.TargetGrid.Position - entity.Transform.GridPosition.Position).Length <= 2.0f)
if ((steeringRequest.TargetGrid.Position - entity.Transform.Coordinates.Position).Length <= 2.0f)
{
return steeringRequest.TargetGrid;
}
@@ -491,7 +492,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
}
if (!_nextGrid.TryGetValue(entity, out var nextGrid) ||
(nextGrid.Position - entity.Transform.GridPosition.Position).Length <= TileTolerance)
(nextGrid.Position - entity.Transform.Coordinates.Position).Length <= TileTolerance)
{
UpdateGridCache(entity);
nextGrid = _nextGrid[entity];
@@ -502,7 +503,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
}
/// <summary>
/// Rather than converting TileRef to GridCoordinates over and over we'll just cache it
/// Rather than converting TileRef to EntityCoordinates over and over we'll just cache it
/// </summary>
/// <param name="entity"></param>
/// <param name="dequeue"></param>
@@ -515,19 +516,19 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
}
/// <summary>
/// Check if we've been near our last GridCoordinates too long and try to fix it
/// Check if we've been near our last EntityCoordinates too long and try to fix it
/// </summary>
/// <param name="entity"></param>
private void HandleStuck(IEntity entity)
{
if (!_stuckPositions.TryGetValue(entity, out var stuckPosition))
{
_stuckPositions[entity] = entity.Transform.GridPosition;
_stuckPositions[entity] = entity.Transform.Coordinates;
_stuckCounter[entity] = 0;
return;
}
if ((entity.Transform.GridPosition.Position - stuckPosition.Position).Length <= 1.0f)
if ((entity.Transform.Coordinates.Position - stuckPosition.Position).Length <= 1.0f)
{
_stuckCounter.TryGetValue(entity, out var stuckCount);
_stuckCounter[entity] = stuckCount + 1;
@@ -535,7 +536,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
else
{
// No longer stuck
_stuckPositions[entity] = entity.Transform.GridPosition;
_stuckPositions[entity] = entity.Transform.Coordinates;
_stuckCounter[entity] = 0;
return;
}
@@ -558,11 +559,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
/// <param name="entity"></param>
/// <param name="grid"></param>
/// <returns></returns>
private Vector2 Seek(IEntity entity, GridCoordinates grid)
private Vector2 Seek(IEntity entity, EntityCoordinates grid)
{
// is-even much
var entityPos = entity.Transform.GridPosition;
return entityPos == grid ? Vector2.Zero : (grid.Position - entityPos.Position).Normalized;
var entityPos = entity.Transform.Coordinates;
return entityPos == grid
? Vector2.Zero
: (grid.Position - entityPos.Position).Normalized;
}
/// <summary>
@@ -572,9 +575,9 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
/// <param name="grid"></param>
/// <param name="slowingDistance"></param>
/// <returns></returns>
private Vector2 Arrival(IEntity entity, GridCoordinates grid, float slowingDistance = 1.0f)
private Vector2 Arrival(IEntity entity, EntityCoordinates grid, float slowingDistance = 1.0f)
{
var entityPos = entity.Transform.GridPosition;
var entityPos = entity.Transform.Coordinates;
DebugTools.Assert(slowingDistance > 0.0f);
if (entityPos == grid)
{
@@ -593,8 +596,8 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
/// <returns></returns>
private Vector2 Pursuit(IEntity entity, IEntity target)
{
var entityPos = entity.Transform.GridPosition;
var targetPos = target.Transform.GridPosition;
var entityPos = entity.Transform.Coordinates;
var targetPos = target.Transform.Coordinates;
if (entityPos == targetPos)
{
return Vector2.Zero;
@@ -630,7 +633,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
var avoidanceVector = Vector2.Zero;
var checkTiles = new HashSet<TileRef>();
var avoidTiles = new HashSet<TileRef>();
var entityGridCoords = entity.Transform.GridPosition;
var entityGridCoords = entity.Transform.Coordinates;
var grid = _mapManager.GetGrid(entity.Transform.GridID);
var currentTile = grid.GetTileRef(entityGridCoords);
var halfwayTile = grid.GetTileRef(entityGridCoords.Offset(direction / 2));
@@ -665,7 +668,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
continue;
}
var centerGrid = physicsEntity.Transform.GridPosition;
var centerGrid = physicsEntity.Transform.Coordinates;
// Check how close we are to center of tile and get the inverse; if we're closer this is stronger
var additionalVector = (centerGrid.Position - entityGridCoords.Position);
var distance = additionalVector.Length;

View File

@@ -7,16 +7,16 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
{
public SteeringStatus Status { get; set; } = SteeringStatus.Pending;
public MapCoordinates TargetMap => _target.Transform.MapPosition;
public GridCoordinates TargetGrid => _target.Transform.GridPosition;
public EntityCoordinates TargetGrid => _target.Transform.Coordinates;
public IEntity Target => _target;
private IEntity _target;
/// <inheritdoc />
public float ArrivalDistance { get; }
/// <inheritdoc />
public float PathfindingProximity { get; }
/// <summary>
/// How far the target can move before we re-path
/// </summary>
@@ -24,12 +24,12 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
/// <inheritdoc />
public bool RequiresInRangeUnobstructed { get; }
/// <summary>
/// To avoid spamming InRangeUnobstructed we'll apply a cd to it.
/// </summary>
public float TimeUntilInteractionCheck { get; set; }
public EntityTargetSteeringRequest(IEntity target, float arrivalDistance, float pathfindingProximity = 0.5f, bool requiresInRangeUnobstructed = false)
{
_target = target;
@@ -38,4 +38,4 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
RequiresInRangeUnobstructed = requiresInRangeUnobstructed;
}
}
}
}

View File

@@ -1,3 +1,4 @@
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map;
@@ -8,7 +9,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
{
public SteeringStatus Status { get; set; } = SteeringStatus.Pending;
public MapCoordinates TargetMap { get; }
public GridCoordinates TargetGrid { get; }
public EntityCoordinates TargetGrid { get; }
/// <inheritdoc />
public float ArrivalDistance { get; }
/// <inheritdoc />
@@ -19,15 +20,15 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
public float TimeUntilInteractionCheck { get; set; } = 0.0f;
public GridTargetSteeringRequest(GridCoordinates targetGrid, float arrivalDistance, float pathfindingProximity = 0.5f, bool requiresInRangeUnobstructed = false)
public GridTargetSteeringRequest(EntityCoordinates targetGrid, float arrivalDistance, float pathfindingProximity = 0.5f, bool requiresInRangeUnobstructed = false)
{
// Get it once up front so we the manager doesn't have to continuously get it
var mapManager = IoCManager.Resolve<IMapManager>();
TargetMap = targetGrid.ToMap(mapManager);
var entityManager = IoCManager.Resolve<IEntityManager>();
TargetMap = targetGrid.ToMap(entityManager);
TargetGrid = targetGrid;
ArrivalDistance = arrivalDistance;
PathfindingProximity = pathfindingProximity;
RequiresInRangeUnobstructed = requiresInRangeUnobstructed;
}
}
}
}

View File

@@ -6,25 +6,25 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
{
SteeringStatus Status { get; set; }
MapCoordinates TargetMap { get; }
GridCoordinates TargetGrid { get; }
EntityCoordinates TargetGrid { get; }
/// <summary>
/// How close we have to get before we've arrived
/// </summary>
float ArrivalDistance { get; }
/// <summary>
/// How close the pathfinder needs to get. Typically you want this set lower than ArrivalDistance
/// </summary>
float PathfindingProximity { get; }
/// <summary>
/// If we need LOS on the entity first before interaction
/// </summary>
bool RequiresInRangeUnobstructed { get; }
/// <summary>
/// To avoid spamming InRangeUnobstructed we'll apply a cd to it.
/// </summary>
public float TimeUntilInteractionCheck { get; set; }
}
}
}

View File

@@ -207,7 +207,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
continue;
}
var entityTile = grid.GetTileRef(entity.Transform.GridPosition).GridIndices;
var entityTile = grid.GetTileRef(entity.Transform.Coordinates).GridIndices;
for (var x = -maxXDiff; x <= maxXDiff; x++)
{

View File

@@ -6,7 +6,6 @@ using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Movement;
using Content.Server.GameObjects.Components.Timing;
using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Server.Utility;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.EntitySystemMessages;
using Content.Shared.GameObjects.EntitySystems;
@@ -40,6 +39,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
public sealed class InteractionSystem : SharedInteractionSystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override void Initialize()
{
@@ -94,7 +94,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
}
private bool HandleActivateItemInWorld(ICommonSession session, GridCoordinates coords, EntityUid uid)
private bool HandleActivateItemInWorld(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
if (!EntityManager.TryGetEntity(uid, out var used))
return false;
@@ -106,7 +106,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
return false;
}
if (!playerEnt.Transform.GridPosition.InRange(_mapManager, used.Transform.GridPosition, InteractionRange))
if (!playerEnt.Transform.Coordinates.InRange(EntityManager, used.Transform.Coordinates, InteractionRange))
{
return false;
}
@@ -151,10 +151,10 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
}
private bool HandleWideAttack(ICommonSession session, GridCoordinates coords, EntityUid uid)
private bool HandleWideAttack(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
// client sanitization
if (!_mapManager.GridExists(coords.GridID))
if (!_mapManager.GridExists(coords.GetGridId(_entityManager)))
{
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
return true;
@@ -189,7 +189,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
/// <param name="entity"></param>
/// <param name="coords"></param>
/// <param name="uid"></param>
internal void UseItemInHand(IEntity entity, GridCoordinates coords, EntityUid uid)
internal void UseItemInHand(IEntity entity, EntityCoordinates coords, EntityUid uid)
{
if (entity.HasComponent<BasicActorComponent>())
{
@@ -206,10 +206,10 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
}
private bool HandleClientUseItemInHand(ICommonSession session, GridCoordinates coords, EntityUid uid)
private bool HandleClientUseItemInHand(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
// client sanitization
if (!_mapManager.GridExists(coords.GridID))
if (!_mapManager.GridExists(coords.GetGridId(_entityManager)))
{
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
return true;
@@ -237,10 +237,10 @@ namespace Content.Server.GameObjects.EntitySystems.Click
return true;
}
private bool HandleTryPullObject(ICommonSession session, GridCoordinates coords, EntityUid uid)
private bool HandleTryPullObject(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
// client sanitization
if (!_mapManager.GridExists(coords.GridID))
if (!_mapManager.GridExists(coords.GetGridId(_entityManager)))
{
Logger.InfoS("system.interaction", $"Invalid Coordinates for pulling: client={session}, coords={coords}");
return false;
@@ -282,7 +282,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
return false;
}
var dist = player.Transform.GridPosition.Position - pulledObject.Transform.GridPosition.Position;
var dist = player.Transform.Coordinates.Position - pulledObject.Transform.Coordinates.Position;
if (dist.LengthSquared > InteractionRangeSquared)
{
return false;
@@ -308,7 +308,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
return false;
}
private void UserInteraction(IEntity player, GridCoordinates coordinates, EntityUid clickedUid)
private void UserInteraction(IEntity player, EntityCoordinates coordinates, EntityUid clickedUid)
{
// Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null
if (!EntityManager.TryGetEntity(clickedUid, out var attacked))
@@ -323,7 +323,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
// Verify player is on the same map as the entity he clicked on
if (_mapManager.GetGrid(coordinates.GridID).ParentMapId != playerTransform.MapID)
if (_mapManager.GetGrid(coordinates.GetGridId(EntityManager)).ParentMapId != playerTransform.MapID)
{
Logger.WarningS("system.interaction",
$"Player named {player.Name} clicked on a map he isn't located on");
@@ -340,7 +340,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
if (ActionBlockerSystem.CanChangeDirection(player))
{
var diff = coordinates.ToMapPos(_mapManager) - playerTransform.MapPosition.Position;
var diff = coordinates.ToMapPos(EntityManager) - playerTransform.MapPosition.Position;
if (diff.LengthSquared > 0.01f)
{
playerTransform.LocalRotation = new Angle(diff);
@@ -373,7 +373,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
if (item != null)
{
// After attack: Check if we clicked on an empty location, if so the only interaction we can do is AfterInteract
var distSqrt = (playerTransform.WorldPosition - coordinates.ToMapPos(_mapManager)).LengthSquared;
var distSqrt = (playerTransform.WorldPosition - coordinates.ToMapPos(EntityManager)).LengthSquared;
InteractAfter(player, item, coordinates, distSqrt <= InteractionRangeSquared);
}
@@ -418,7 +418,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
/// <summary>
/// We didn't click on any entity, try doing an AfterInteract on the click location
/// </summary>
private void InteractAfter(IEntity user, IEntity weapon, GridCoordinates clickLocation, bool canReach)
private void InteractAfter(IEntity user, IEntity weapon, EntityCoordinates clickLocation, bool canReach)
{
var message = new AfterInteractMessage(user, weapon, null, clickLocation, canReach);
RaiseLocalEvent(message);
@@ -440,7 +440,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
/// Uses a weapon/object on an entity
/// Finds components with the InteractUsing interface and calls their function
/// </summary>
public async Task Interaction(IEntity user, IEntity weapon, IEntity attacked, GridCoordinates clickLocation)
public async Task Interaction(IEntity user, IEntity weapon, IEntity attacked, EntityCoordinates clickLocation)
{
var attackMsg = new InteractUsingMessage(user, weapon, attacked, clickLocation);
RaiseLocalEvent(attackMsg);
@@ -607,7 +607,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
/// Calls Land on all components that implement the ILand interface
/// on an entity that has landed after being thrown.
/// </summary>
public void LandInteraction(IEntity user, IEntity landing, GridCoordinates landLocation)
public void LandInteraction(IEntity user, IEntity landing, EntityCoordinates landLocation)
{
var landMsg = new LandMessage(user, landing, landLocation);
RaiseLocalEvent(landMsg);
@@ -752,7 +752,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
/// Will have two behaviors, either "uses" the weapon at range on the entity if it is capable of accepting that action
/// Or it will use the weapon itself on the position clicked, regardless of what was there
/// </summary>
public void RangedInteraction(IEntity user, IEntity weapon, IEntity attacked, GridCoordinates clickLocation)
public void RangedInteraction(IEntity user, IEntity weapon, IEntity attacked, EntityCoordinates clickLocation)
{
var rangedMsg = new RangedInteractMessage(user, weapon, attacked, clickLocation);
RaiseLocalEvent(rangedMsg);
@@ -793,10 +793,10 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
}
private void DoAttack(IEntity player, GridCoordinates coordinates, bool wideAttack, EntityUid target = default)
private void DoAttack(IEntity player, EntityCoordinates coordinates, bool wideAttack, EntityUid target = default)
{
// Verify player is on the same map as the entity he clicked on
if (_mapManager.GetGrid(coordinates.GridID).ParentMapId != player.Transform.MapID)
if (_mapManager.GetGrid(coordinates.GetGridId(_entityManager)).ParentMapId != player.Transform.MapID)
{
Logger.WarningS("system.interaction",
$"Player named {player.Name} clicked on a map he isn't located on");
@@ -804,7 +804,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
if (!ActionBlockerSystem.CanAttack(player) ||
(!wideAttack && !InRangeUnobstructed(player.Transform.MapPosition, coordinates.ToMap(_mapManager), ignoreInsideBlocker:true)))
(!wideAttack && !player.InRangeUnobstructed(coordinates, ignoreInsideBlocker:true)))
{
return;
}

View File

@@ -6,7 +6,6 @@ using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.Utility;
using Content.Shared.Construction;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Interactable;
@@ -20,7 +19,6 @@ using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -36,7 +34,6 @@ namespace Content.Server.GameObjects.EntitySystems
internal class ConstructionSystem : SharedConstructionSystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
private readonly Dictionary<string, ConstructionPrototype> _craftRecipes = new Dictionary<string, ConstructionPrototype>();
@@ -240,7 +237,7 @@ namespace Content.Server.GameObjects.EntitySystems
{ ConstructionStepMaterial.MaterialType.Glass, "GlassSheet1" }
};
private bool TryStartStructureConstruction(IEntity placingEnt, GridCoordinates loc, string prototypeName, Angle angle)
private bool TryStartStructureConstruction(IEntity placingEnt, EntityCoordinates loc, string prototypeName, Angle angle)
{
var prototype = _prototypeManager.Index<ConstructionPrototype>(prototypeName);
@@ -380,7 +377,7 @@ namespace Content.Server.GameObjects.EntitySystems
var stage = constructPrototype.Stages[constructionComponent.Stage];
if (await TryProcessStep(constructEntity, stage.Forward, handTool, user, transformComponent.GridPosition))
if (await TryProcessStep(constructEntity, stage.Forward, handTool, user, transformComponent.Coordinates))
{
constructionComponent.Stage++;
if (constructionComponent.Stage == constructPrototype.Stages.Count - 1)
@@ -402,7 +399,7 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
else if (await TryProcessStep(constructEntity, stage.Backward, handTool, user, transformComponent.GridPosition))
else if (await TryProcessStep(constructEntity, stage.Backward, handTool, user, transformComponent.Coordinates))
{
constructionComponent.Stage--;
stage = constructPrototype.Stages[constructionComponent.Stage];
@@ -439,7 +436,7 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
private async Task<bool> TryProcessStep(IEntity constructEntity, ConstructionStep step, IEntity slapped, IEntity user, GridCoordinates gridCoords)
private async Task<bool> TryProcessStep(IEntity constructEntity, ConstructionStep step, IEntity slapped, IEntity user, EntityCoordinates gridCoords)
{
if (step == null)
{

View File

@@ -23,9 +23,9 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter
public float Elapsed { get; set; }
public GridCoordinates UserGrid { get; }
public EntityCoordinates UserGrid { get; }
public GridCoordinates TargetGrid { get; }
public EntityCoordinates TargetGrid { get; }
private bool _tookDamage;
@@ -42,13 +42,13 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter
if (eventArgs.BreakOnUserMove)
{
UserGrid = eventArgs.User.Transform.GridPosition;
UserGrid = eventArgs.User.Transform.Coordinates;
}
if (eventArgs.BreakOnTargetMove)
{
// Target should never be null if the bool is set.
TargetGrid = eventArgs.Target!.Transform.GridPosition;
TargetGrid = eventArgs.Target!.Transform.Coordinates;
}
// For this we need to stay on the same hand slot and need the same item in that hand slot
@@ -94,7 +94,7 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter
{
Tcs.SetResult(DoAfterStatus.Finished);
}
return;
}
@@ -110,7 +110,7 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter
{
return true;
}
//https://github.com/tgstation/tgstation/blob/1aa293ea337283a0191140a878eeba319221e5df/code/__HELPERS/mobs.dm
if (EventArgs.CancelToken.IsCancellationRequested)
{
@@ -118,12 +118,12 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter
}
// TODO :Handle inertia in space.
if (EventArgs.BreakOnUserMove && EventArgs.User.Transform.GridPosition != UserGrid)
if (EventArgs.BreakOnUserMove && EventArgs.User.Transform.Coordinates != UserGrid)
{
return true;
}
if (EventArgs.BreakOnTargetMove && EventArgs.Target!.Transform.GridPosition != TargetGrid)
if (EventArgs.BreakOnTargetMove && EventArgs.Target!.Transform.Coordinates != TargetGrid)
{
return true;
}
@@ -170,7 +170,7 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter
}
}
}
return false;
}

View File

@@ -10,12 +10,14 @@ using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Input;
using Content.Shared.Interfaces;
using Content.Shared.Utility;
using JetBrains.Annotations;
using Robust.Server.GameObjects.EntitySystemMessages;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Input.Binding;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
@@ -28,6 +30,7 @@ namespace Content.Server.GameObjects.EntitySystems
internal sealed class HandsSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
private const float ThrowForce = 1.5f; // Throwing force of mobs in Newtons
@@ -107,7 +110,7 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
private bool HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
private bool HandleDrop(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
var ent = ((IPlayerSession) session).AttachedEntity;
@@ -120,13 +123,13 @@ namespace Content.Server.GameObjects.EntitySystems
if (handsComp.GetActiveHand == null)
return false;
var entCoords = ent.Transform.GridPosition.Position;
var entCoords = ent.Transform.Coordinates.Position;
var entToDesiredDropCoords = coords.Position - entCoords;
var targetLength = Math.Min(entToDesiredDropCoords.Length, SharedInteractionSystem.InteractionRange - 0.001f); // InteractionRange is reduced due to InRange not dealing with floating point error
var newCoords = new GridCoordinates((entToDesiredDropCoords.Normalized * targetLength) + entCoords, coords.GridID);
var rayLength = Get<SharedInteractionSystem>().UnobstructedDistance(ent.Transform.MapPosition, newCoords.ToMap(_mapManager), ignoredEnt: ent);
var newCoords = coords.WithPosition((entToDesiredDropCoords.Normalized * targetLength) + entCoords).ToMap(_entityManager);
var rayLength = Get<SharedInteractionSystem>().UnobstructedDistance(ent.Transform.MapPosition, newCoords, ignoredEnt: ent);
handsComp.Drop(handsComp.ActiveHand, new GridCoordinates(entCoords + (entToDesiredDropCoords.Normalized * rayLength), coords.GridID));
handsComp.Drop(handsComp.ActiveHand, coords.WithPosition(entCoords + (entToDesiredDropCoords.Normalized * rayLength)));
return true;
}
@@ -139,7 +142,7 @@ namespace Content.Server.GameObjects.EntitySystems
handsComp.ActivateItem();
}
private bool HandleThrowItem(ICommonSession session, GridCoordinates coords, EntityUid uid)
private bool HandleThrowItem(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
var plyEnt = ((IPlayerSession)session).AttachedEntity;
@@ -165,14 +168,14 @@ namespace Content.Server.GameObjects.EntitySystems
else
{
stackComp.Use(1);
throwEnt = throwEnt.EntityManager.SpawnEntity(throwEnt.Prototype.ID, plyEnt.Transform.GridPosition);
throwEnt = throwEnt.EntityManager.SpawnEntity(throwEnt.Prototype.ID, plyEnt.Transform.Coordinates);
// can only throw one item at a time, regardless of what the prototype stack size is.
if (throwEnt.TryGetComponent<StackComponent>(out var newStackComp))
newStackComp.Count = 1;
}
ThrowHelper.ThrowTo(throwEnt, ThrowForce, coords, plyEnt.Transform.GridPosition, false, plyEnt);
ThrowHelper.ThrowTo(throwEnt, ThrowForce, coords, plyEnt.Transform.Coordinates, false, plyEnt);
return true;
}
@@ -228,7 +231,7 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
private bool HandleMovePulledObject(ICommonSession session, GridCoordinates coords, EntityUid uid)
private bool HandleMovePulledObject(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
var playerEntity = session.AttachedEntity;
@@ -238,7 +241,7 @@ namespace Content.Server.GameObjects.EntitySystems
return false;
}
hands.MovePulledObject(playerEntity.Transform.GridPosition, coords);
hands.MovePulledObject(playerEntity.Transform.Coordinates, coords);
return false;
}

View File

@@ -9,15 +9,16 @@ namespace Content.Server.GameObjects.EntitySystems
{
internal sealed class ListeningSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
public void PingListeners(IEntity source, GridCoordinates sourcePos, string message)
public void PingListeners(IEntity source, EntityCoordinates sourcePos, string message)
{
foreach (var listener in ComponentManager.EntityQuery<ListeningComponent>())
{
var dist = sourcePos.Distance(_mapManager, listener.Owner.Transform.GridPosition);
if (!sourcePos.TryDistance(EntityManager, listener.Owner.Transform.Coordinates, out var distance))
{
return;
}
listener.PassSpeechData(message, source, dist);
listener.PassSpeechData(message, source, distance);
}
}
}

View File

@@ -17,6 +17,7 @@ using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.Timing;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
@@ -35,6 +36,7 @@ namespace Content.Server.GameObjects.EntitySystems
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
private AudioSystem _audioSystem = default!;
@@ -92,14 +94,18 @@ namespace Content.Server.GameObjects.EntitySystems
{
var transform = mover.Owner.Transform;
// Handle footsteps.
if (_mapManager.GridExists(mover.LastPosition.GridID))
if (_mapManager.GridExists(mover.LastPosition.GetGridId(EntityManager)))
{
// Can happen when teleporting between grids.
var distance = transform.GridPosition.Distance(_mapManager, mover.LastPosition);
if (!transform.Coordinates.TryDistance(_entityManager, mover.LastPosition, out var distance))
{
return;
}
mover.StepSoundDistance += distance;
}
mover.LastPosition = transform.GridPosition;
mover.LastPosition = transform.Coordinates;
float distanceNeeded;
if (mover.Sprinting)
{
@@ -127,15 +133,15 @@ namespace Content.Server.GameObjects.EntitySystems
}
else
{
PlayFootstepSound(transform.GridPosition);
PlayFootstepSound(transform.Coordinates);
}
}
}
private void PlayFootstepSound(GridCoordinates coordinates)
private void PlayFootstepSound(EntityCoordinates coordinates)
{
// Step one: figure out sound collection prototype.
var grid = _mapManager.GetGrid(coordinates.GridID);
var grid = _mapManager.GetGrid(coordinates.GetGridId(EntityManager));
var tile = grid.GetTileRef(coordinates);
// If the coordinates have a catwalk, it's always catwalk.

View File

@@ -75,12 +75,12 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
public bool InRange(GridCoordinates from, GridCoordinates to)
public bool InRange(EntityCoordinates from, EntityCoordinates to)
{
return from.InRange(_mapManager, to, 15);
return from.InRange(EntityManager, to, 15);
}
public bool TryPoint(ICommonSession? session, GridCoordinates coords, EntityUid uid)
public bool TryPoint(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
{
var player = (session as IPlayerSession)?.ContentData()?.Mind?.CurrentEntity;
if (player == null)
@@ -100,7 +100,7 @@ namespace Content.Server.GameObjects.EntitySystems
return false;
}
if (!InRange(coords, player.Transform.GridPosition))
if (!InRange(coords, player.Transform.Coordinates))
{
player.PopupMessage(Loc.GetString("You can't reach there!"));
return false;
@@ -108,7 +108,7 @@ namespace Content.Server.GameObjects.EntitySystems
if (ActionBlockerSystem.CanChangeDirection(player))
{
var diff = coords.ToMapPos(_mapManager) - player.Transform.MapPosition.Position;
var diff = coords.ToMapPos(EntityManager) - player.Transform.MapPosition.Position;
if (diff.LengthSquared > 0.01f)
{
player.Transform.LocalRotation = new Angle(diff);
@@ -154,7 +154,7 @@ namespace Content.Server.GameObjects.EntitySystems
}
else
{
var tileRef = _mapManager.GetGrid(coords.GridID).GetTileRef(coords);
var tileRef = _mapManager.GetGrid(coords.GetGridId(EntityManager)).GetTileRef(coords);
var tileDef = _tileDefinitionManager[tileRef.Tile.TypeId];
selfMessage = Loc.GetString("You point at {0}.", tileDef.DisplayName);

View File

@@ -64,7 +64,7 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
private bool HandleUse(ICommonSession session, GridCoordinates coords, EntityUid uid)
private bool HandleUse(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
if (!_transmitters.TryGetValue(session.SessionId, out var signalTransmitter))
{
@@ -76,11 +76,6 @@ namespace Content.Server.GameObjects.EntitySystems
return false;
}
if (entity == null)
{
return false;
}
if (entity.TryGetComponent<SignalReceiverComponent>(out var signalReceiver))
{
if (signalReceiver.Interact(session.AttachedEntity, signalTransmitter))