Remove Explicit GridId References (#8315)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -41,7 +41,7 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
|
||||
float intensityStepSize,
|
||||
int typeIndex,
|
||||
Dictionary<Vector2i, NeighborFlag> edgeTiles,
|
||||
GridId? referenceGrid,
|
||||
EntityUid? referenceGrid,
|
||||
Matrix3 spaceMatrix,
|
||||
Angle spaceAngle)
|
||||
{
|
||||
@@ -63,7 +63,7 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
|
||||
}
|
||||
}
|
||||
|
||||
if (referenceGrid == Grid.Index)
|
||||
if (referenceGrid == Grid.GridEntityId)
|
||||
return;
|
||||
|
||||
_needToTransform = true;
|
||||
|
||||
@@ -19,11 +19,11 @@ public sealed class ExplosionSpaceTileFlood : ExplosionTileFlood
|
||||
/// After every iteration, this data set will store all the grid-tiles that were reached as a result of the
|
||||
/// explosion expanding in space.
|
||||
/// </summary>
|
||||
public Dictionary<GridId, HashSet<Vector2i>> GridJump = new();
|
||||
public Dictionary<EntityUid, HashSet<Vector2i>> GridJump = new();
|
||||
|
||||
public ushort TileSize = ExplosionSystem.DefaultTileSize;
|
||||
|
||||
public ExplosionSpaceTileFlood(ExplosionSystem system, MapCoordinates epicentre, GridId? referenceGrid, List<GridId> localGrids, float maxDistance)
|
||||
public ExplosionSpaceTileFlood(ExplosionSystem system, MapCoordinates epicentre, EntityUid? referenceGrid, List<EntityUid> localGrids, float maxDistance)
|
||||
{
|
||||
(_gridBlockMap, TileSize) = system.TransformGridEdges(epicentre, referenceGrid, localGrids, maxDistance);
|
||||
system.GetUnblockedDirections(_gridBlockMap, TileSize);
|
||||
|
||||
@@ -39,9 +39,9 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
//
|
||||
// We then need this data for every tile on a grid. So this mess of a variable maps the Grid ID and Vector2i grid
|
||||
// indices to this tile-data struct.
|
||||
private Dictionary<GridId, Dictionary<Vector2i, TileData>> _airtightMap = new();
|
||||
private Dictionary<EntityUid, Dictionary<Vector2i, TileData>> _airtightMap = new();
|
||||
|
||||
public void UpdateAirtightMap(GridId gridId, Vector2i tile, EntityQuery<AirtightComponent>? query = null)
|
||||
public void UpdateAirtightMap(EntityUid gridId, Vector2i tile, EntityQuery<AirtightComponent>? query = null)
|
||||
{
|
||||
if (_mapManager.TryGetGrid(gridId, out var grid))
|
||||
UpdateAirtightMap(grid, tile, query);
|
||||
@@ -62,8 +62,8 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
var tolerance = new float[_explosionTypes.Count];
|
||||
var blockedDirections = AtmosDirection.Invalid;
|
||||
|
||||
if (!_airtightMap.ContainsKey(grid.Index))
|
||||
_airtightMap[grid.Index] = new();
|
||||
if (!_airtightMap.ContainsKey(grid.GridEntityId))
|
||||
_airtightMap[grid.GridEntityId] = new();
|
||||
|
||||
query ??= EntityManager.GetEntityQuery<AirtightComponent>();
|
||||
var damageQuery = EntityManager.GetEntityQuery<DamageableComponent>();
|
||||
@@ -83,9 +83,9 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
}
|
||||
|
||||
if (blockedDirections != AtmosDirection.Invalid)
|
||||
_airtightMap[grid.Index][tile] = new(tolerance, blockedDirections);
|
||||
_airtightMap[grid.GridEntityId][tile] = new(tolerance, blockedDirections);
|
||||
else
|
||||
_airtightMap[grid.Index].Remove(tile);
|
||||
_airtightMap[grid.GridEntityId].Remove(tile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,7 +100,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
if (!EntityManager.TryGetComponent(uid, out TransformComponent? transform) || !transform.Anchored)
|
||||
return;
|
||||
|
||||
if (!_mapManager.TryGetGrid(transform.GridID, out var grid))
|
||||
if (!_mapManager.TryGetGrid(transform.GridEntityId, out var grid))
|
||||
return;
|
||||
|
||||
UpdateAirtightMap(grid, grid.CoordinatesToTile(transform.Coordinates));
|
||||
|
||||
@@ -11,7 +11,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Set of tiles of each grid that are directly adjacent to space, along with the directions that face space.
|
||||
/// </summary>
|
||||
private Dictionary<GridId, Dictionary<Vector2i, NeighborFlag>> _gridEdges = new();
|
||||
private Dictionary<EntityUid, Dictionary<Vector2i, NeighborFlag>> _gridEdges = new();
|
||||
|
||||
/// <summary>
|
||||
/// On grid startup, prepare a map of grid edges.
|
||||
@@ -42,8 +42,8 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
/// </summary>
|
||||
public (Dictionary<Vector2i, BlockedSpaceTile>, ushort) TransformGridEdges(
|
||||
MapCoordinates epicentre,
|
||||
GridId? referenceGrid,
|
||||
List<GridId> localGrids,
|
||||
EntityUid? referenceGrid,
|
||||
List<EntityUid> localGrids,
|
||||
float maxDistance)
|
||||
{
|
||||
Dictionary<Vector2i, BlockedSpaceTile> transformedEdges = new();
|
||||
@@ -230,10 +230,10 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
|
||||
var tileRef = ev.NewTile;
|
||||
|
||||
if (!_gridEdges.TryGetValue(tileRef.GridIndex, out var edges))
|
||||
if (!_gridEdges.TryGetValue(tileRef.GridUid, out var edges))
|
||||
{
|
||||
edges = new();
|
||||
_gridEdges[tileRef.GridIndex] = edges;
|
||||
_gridEdges[tileRef.GridUid] = edges;
|
||||
}
|
||||
|
||||
if (tileRef.Tile.IsEmpty)
|
||||
@@ -373,10 +373,10 @@ public sealed class BlockedSpaceTile
|
||||
public sealed class GridEdgeData
|
||||
{
|
||||
public Vector2i Tile;
|
||||
public GridId? Grid;
|
||||
public EntityUid? Grid;
|
||||
public Box2Rotated Box;
|
||||
|
||||
public GridEdgeData(Vector2i tile, GridId? grid, Vector2 center, Angle angle, float size)
|
||||
public GridEdgeData(Vector2i tile, EntityUid? grid, Vector2 center, Angle angle, float size)
|
||||
{
|
||||
Tile = tile;
|
||||
Grid = grid;
|
||||
|
||||
@@ -22,7 +22,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
/// <param name="maxIntensity">The maximum intensity that the explosion can have at any given tile. This
|
||||
/// effectively caps the damage that this explosion can do.</param>
|
||||
/// <returns>A list of tile-sets and a list of intensity values which describe the explosion.</returns>
|
||||
private (int, List<float>, ExplosionSpaceTileFlood?, Dictionary<GridId, ExplosionGridTileFlood>, Matrix3)? GetExplosionTiles(
|
||||
private (int, List<float>, ExplosionSpaceTileFlood?, Dictionary<EntityUid, ExplosionGridTileFlood>, Matrix3)? GetExplosionTiles(
|
||||
MapCoordinates epicenter,
|
||||
string typeID,
|
||||
float totalIntensity,
|
||||
@@ -39,7 +39,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
}
|
||||
|
||||
Vector2i initialTile;
|
||||
GridId? epicentreGrid = null;
|
||||
EntityUid? epicentreGrid = null;
|
||||
var (localGrids, referenceGrid, maxDistance) = GetLocalGrids(epicenter, totalIntensity, slope, maxIntensity);
|
||||
|
||||
// get the epicenter tile indices
|
||||
@@ -47,7 +47,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
candidateGrid.TryGetTileRef(candidateGrid.WorldToTile(epicenter.Position), out var tileRef) &&
|
||||
!tileRef.Tile.IsEmpty)
|
||||
{
|
||||
epicentreGrid = candidateGrid.Index;
|
||||
epicentreGrid = candidateGrid.GridEntityId;
|
||||
initialTile = tileRef.GridIndices;
|
||||
}
|
||||
else if (referenceGrid != null)
|
||||
@@ -64,7 +64,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
}
|
||||
|
||||
// Main data for the exploding tiles in space and on various grids
|
||||
Dictionary<GridId, ExplosionGridTileFlood> gridData = new();
|
||||
Dictionary<EntityUid, ExplosionGridTileFlood> gridData = new();
|
||||
ExplosionSpaceTileFlood? spaceData = null;
|
||||
|
||||
// The intensity slope is how much the intensity drop over a one-tile distance. The actual algorithm step-size is half of thhat.
|
||||
@@ -76,8 +76,8 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
HashSet<Vector2i> previousSpaceJump;
|
||||
|
||||
// As above, but for space-based explosion propagating from space onto grids.
|
||||
HashSet<GridId> encounteredGrids = new();
|
||||
Dictionary<GridId, HashSet<Vector2i>>? previousGridJump;
|
||||
HashSet<EntityUid> encounteredGrids = new();
|
||||
Dictionary<EntityUid, HashSet<Vector2i>>? previousGridJump;
|
||||
|
||||
// variables for transforming between grid and space-coordiantes
|
||||
var spaceMatrix = Matrix3.Identity;
|
||||
@@ -256,7 +256,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
/// match a separate grid. This is done so that if you have something like a tiny suicide-bomb shuttle exploding
|
||||
/// near a large station, the explosion will still orient to match the station, not the tiny shuttle.
|
||||
/// </remarks>
|
||||
public (List<GridId>, GridId?, float) GetLocalGrids(MapCoordinates epicenter, float totalIntensity, float slope, float maxIntensity)
|
||||
public (List<EntityUid>, EntityUid?, float) GetLocalGrids(MapCoordinates epicenter, float totalIntensity, float slope, float maxIntensity)
|
||||
{
|
||||
// Get the explosion radius (approx radius if it were in open-space). Note that if the explosion is confined in
|
||||
// some directions but not in others, the actual explosion may reach further than this distance from the
|
||||
@@ -266,7 +266,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
// to avoid a silly lookup for silly input numbers, cap the radius to half of the theoretical maximum (lookup area gets doubled later on).
|
||||
radius = Math.Min(radius, MaxIterations / 4);
|
||||
|
||||
GridId? referenceGrid = null;
|
||||
EntityUid? referenceGrid = null;
|
||||
float mass = 0;
|
||||
|
||||
// First attempt to find a grid that is relatively close to the explosion's center. Instead of looking in a
|
||||
@@ -278,7 +278,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
if (TryComp(grid.GridEntityId, out PhysicsComponent? physics) && physics.Mass > mass)
|
||||
{
|
||||
mass = physics.Mass;
|
||||
referenceGrid = grid.Index;
|
||||
referenceGrid = grid.GridEntityId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
radius *= 4;
|
||||
box = Box2.CenteredAround(epicenter.Position, (radius, radius));
|
||||
var mapGrids = _mapManager.FindGridsIntersecting(epicenter.MapId, box).ToList();
|
||||
var grids = mapGrids.Select(x => x.Index).ToList();
|
||||
var grids = mapGrids.Select(x => x.GridEntityId).ToList();
|
||||
|
||||
if (referenceGrid != null)
|
||||
return (grids, referenceGrid, radius);
|
||||
@@ -305,7 +305,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
if (TryComp(grid.GridEntityId, out PhysicsComponent? physics) && physics.Mass > mass)
|
||||
{
|
||||
mass = physics.Mass;
|
||||
referenceGrid = grid.Index;
|
||||
referenceGrid = grid.GridEntityId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -308,10 +308,10 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
{
|
||||
var spaceTiles = spaceData?.TileLists;
|
||||
|
||||
Dictionary<GridId, Dictionary<int, List<Vector2i>>> tileLists = new();
|
||||
Dictionary<EntityUid, Dictionary<int, List<Vector2i>>> tileLists = new();
|
||||
foreach (var grid in gridData)
|
||||
{
|
||||
tileLists.Add(grid.Grid.Index, grid.TileLists);
|
||||
tileLists.Add(grid.Grid.GridEntityId, grid.TileLists);
|
||||
}
|
||||
|
||||
return new ExplosionEvent(_explosionCounter, epicenter, id, iterationIntensity, spaceTiles, tileLists, spaceMatrix, spaceData?.TileSize ?? DefaultTileSize);
|
||||
|
||||
Reference in New Issue
Block a user