Fix mime wall & turf/tile helper issues. (#17844)

This commit is contained in:
Leon Friedrich
2023-07-06 16:43:49 +12:00
committed by GitHub
parent 88f9d2b6b8
commit 126f5d6dae
10 changed files with 55 additions and 38 deletions

View File

@@ -9,6 +9,8 @@ using Content.Shared.Mobs.Components;
using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Components;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Content.Server.Speech.Muting; using Content.Server.Speech.Muting;
using Robust.Shared.Containers;
using Robust.Shared.Map;
namespace Content.Server.Abilities.Mime namespace Content.Server.Abilities.Mime
{ {
@@ -19,7 +21,8 @@ namespace Content.Server.Abilities.Mime
[Dependency] private readonly AlertsSystem _alertsSystem = default!; [Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly EntityLookupSystem _lookupSystem = default!; [Dependency] private readonly EntityLookupSystem _lookupSystem = default!;
[Dependency] private readonly TurfSystem _turf = default!; [Dependency] private readonly TurfSystem _turf = default!;
[Dependency] private readonly IMapManager _mapMan = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IGameTiming _timing = default!;
public override void Initialize() public override void Initialize()
@@ -62,11 +65,14 @@ namespace Content.Server.Abilities.Mime
if (!component.Enabled) if (!component.Enabled)
return; return;
if (_container.IsEntityOrParentInContainer(uid))
return;
var xform = Transform(uid); var xform = Transform(uid);
// Get the tile in front of the mime // Get the tile in front of the mime
var offsetValue = xform.LocalRotation.ToWorldVec().Normalized; var offsetValue = xform.LocalRotation.ToWorldVec();
var coords = xform.Coordinates.Offset(offsetValue).SnapToGrid(EntityManager); var coords = xform.Coordinates.Offset(offsetValue).SnapToGrid(EntityManager, _mapMan);
var tile = coords.GetTileRef(); var tile = coords.GetTileRef(EntityManager, _mapMan);
if (tile == null) if (tile == null)
return; return;
@@ -88,7 +94,7 @@ namespace Content.Server.Abilities.Mime
} }
_popupSystem.PopupEntity(Loc.GetString("mime-invisible-wall-popup", ("mime", uid)), uid); _popupSystem.PopupEntity(Loc.GetString("mime-invisible-wall-popup", ("mime", uid)), uid);
// Make sure we set the invisible wall to despawn properly // Make sure we set the invisible wall to despawn properly
Spawn(component.WallPrototype, coords); Spawn(component.WallPrototype, _turf.GetTileCenter(tile.Value));
// Handle args so cooldown works // Handle args so cooldown works
args.Handled = true; args.Handled = true;
} }

View File

@@ -58,7 +58,8 @@ public sealed class CreateEntityTileReaction : ITileReaction
var xoffs = random.NextFloat(-RandomOffsetMax, RandomOffsetMax); var xoffs = random.NextFloat(-RandomOffsetMax, RandomOffsetMax);
var yoffs = random.NextFloat(-RandomOffsetMax, RandomOffsetMax); var yoffs = random.NextFloat(-RandomOffsetMax, RandomOffsetMax);
var pos = tile.GridPosition().Offset(new Vector2(0.5f + xoffs, 0.5f + yoffs)); var center = entMan.System<TurfSystem>().GetTileCenter(tile);
var pos = center.Offset(new Vector2(xoffs, yoffs));
entMan.SpawnEntity(Entity, pos); entMan.SpawnEntity(Entity, pos);
return Usage; return Usage;

View File

@@ -80,7 +80,7 @@ public sealed partial class ExplosionSystem : EntitySystem
HashSet<EntityUid> encounteredGrids = new(); HashSet<EntityUid> encounteredGrids = new();
Dictionary<EntityUid, HashSet<Vector2i>>? previousGridJump; Dictionary<EntityUid, HashSet<Vector2i>>? previousGridJump;
// variables for transforming between grid and space-coordiantes // variables for transforming between grid and space-coordinates
var spaceMatrix = Matrix3.Identity; var spaceMatrix = Matrix3.Identity;
var spaceAngle = Angle.Zero; var spaceAngle = Angle.Zero;
if (referenceGrid != null) if (referenceGrid != null)

View File

@@ -17,6 +17,7 @@ public sealed class TileSystem : EntitySystem
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly DecalSystem _decal = default!; [Dependency] private readonly DecalSystem _decal = default!;
[Dependency] private readonly TurfSystem _turf = default!;
public bool PryTile(Vector2i indices, EntityUid gridId) public bool PryTile(Vector2i indices, EntityUid gridId)
{ {
@@ -68,7 +69,7 @@ public sealed class TileSystem : EntitySystem
return false; return false;
var variant = _robustRandom.Pick(replacementTile.PlacementVariants); var variant = _robustRandom.Pick(replacementTile.PlacementVariants);
var decals = _decal.GetDecalsInRange(tileref.GridUid, tileref.GridPosition().SnapToGrid(EntityManager, _mapManager).Position, 0.5f); var decals = _decal.GetDecalsInRange(tileref.GridUid, _turf.GetTileCenter(tileref).Position, 0.5f);
foreach (var (id, _) in decals) foreach (var (id, _) in decals)
{ {
_decal.RemoveDecal(tileref.GridUid, id); _decal.RemoveDecal(tileref.GridUid, id);

View File

@@ -6,6 +6,7 @@ using Content.Server.Station.Components;
using Content.Server.Station.Systems; using Content.Server.Station.Systems;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Maps; using Content.Shared.Maps;
using Content.Shared.Physics;
using Content.Shared.Respawn; using Content.Shared.Respawn;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Random; using Robust.Shared.Random;
@@ -19,7 +20,7 @@ public sealed class SpecialRespawnSystem : SharedSpecialRespawnSystem
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly AtmosphereSystem _atmosphere = default!; [Dependency] private readonly AtmosphereSystem _atmosphere = default!;
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly StationSystem _stationSystem = default!; [Dependency] private readonly TurfSystem _turf = default!;
[Dependency] private readonly IChatManager _chat = default!; [Dependency] private readonly IChatManager _chat = default!;
public override void Initialize() public override void Initialize()
@@ -100,10 +101,15 @@ public sealed class SpecialRespawnSystem : SharedSpecialRespawnSystem
foreach (var tile in grid.GetTilesIntersecting(circle)) foreach (var tile in grid.GetTilesIntersecting(circle))
{ {
if (tile.IsSpace(_tileDefinitionManager) || tile.IsBlockedTurf(true) || !_atmosphere.IsTileMixtureProbablySafe(entityGridUid, entityMapUid.Value, grid.TileIndicesFor(mapPos))) if (tile.IsSpace(_tileDefinitionManager)
|| _turf.IsTileBlocked(tile, CollisionGroup.MobMask)
|| !_atmosphere.IsTileMixtureProbablySafe(entityGridUid, entityMapUid.Value,
grid.TileIndicesFor(mapPos)))
{
continue; continue;
}
pos = tile.GridPosition(); pos = _turf.GetTileCenter(tile);
found = true; found = true;
if (found) if (found)

View File

@@ -1,17 +1,10 @@
using System.Threading;
using Content.Server.Fluids.Components;
using Content.Server.Tools.Components; using Content.Server.Tools.Components;
using Content.Shared.Administration.Logs;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Fluids.Components; using Content.Shared.Fluids.Components;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Maps; using Content.Shared.Maps;
using Content.Shared.Tools.Components; using Content.Shared.Tools.Components;
using Robust.Shared.Audio;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Utility;
namespace Content.Server.Tools; namespace Content.Server.Tools;
@@ -41,20 +34,21 @@ public sealed partial class ToolSystem
var gridUid = args.Coordinates.GetGridUid(EntityManager); var gridUid = args.Coordinates.GetGridUid(EntityManager);
if (!_mapManager.TryGetGrid(gridUid, out var grid)) if (!_mapManager.TryGetGrid(gridUid, out var grid))
{ {
Logger.Error("Attempted to pry from a non-existent grid?"); Log.Error("Attempted to pry from a non-existent grid?");
return; return;
} }
var tile = grid.GetTileRef(args.Coordinates); var tile = grid.GetTileRef(args.Coordinates);
var center = _turf.GetTileCenter(tile);
if (args.Used != null) if (args.Used != null)
{ {
_adminLogger.Add(LogType.Action, LogImpact.Low, _adminLogger.Add(LogType.Action, LogImpact.Low,
$"{ToPrettyString(args.User):actor} used {ToPrettyString(args.Used.Value):tool} to pry {_tileDefinitionManager[tile.Tile.TypeId].Name} at {ToPrettyString(tile.GridUid):grid} {tile.GridPosition()}"); $"{ToPrettyString(args.User):actor} used {ToPrettyString(args.Used.Value):tool} to pry {_tileDefinitionManager[tile.Tile.TypeId].Name} at {center}");
} }
else else
{ {
_adminLogger.Add(LogType.Action, LogImpact.Low, _adminLogger.Add(LogType.Action, LogImpact.Low,
$"{ToPrettyString(args.User):actor} pried {_tileDefinitionManager[tile.Tile.TypeId].Name} at {ToPrettyString(tile.GridUid):grid} {tile.GridPosition()}"); $"{ToPrettyString(args.User):actor} pried {_tileDefinitionManager[tile.Tile.TypeId].Name} at {center}");
} }
_tile.PryTile(tile); _tile.PryTile(tile);

View File

@@ -2,6 +2,7 @@ using Content.Server.Atmos.EntitySystems;
using Content.Server.Chemistry.EntitySystems; using Content.Server.Chemistry.EntitySystems;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Server.Tools.Components; using Content.Server.Tools.Components;
using Content.Shared.Maps;
using Content.Shared.Tools; using Content.Shared.Tools;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Map; using Robust.Shared.Map;
@@ -17,6 +18,7 @@ namespace Content.Server.Tools
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!; [Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly TurfSystem _turf = default!;
public override void Initialize() public override void Initialize()
{ {

View File

@@ -9,22 +9,25 @@ namespace Content.Shared.Coordinates.Helpers
{ {
IoCManager.Resolve(ref entMan, ref mapManager); IoCManager.Resolve(ref entMan, ref mapManager);
var gridIdOpt = coordinates.GetGridUid(entMan); var gridId = coordinates.GetGridUid(entMan);
var tileSize = 1f; if (gridId == null)
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{ {
var grid = mapManager.GetGrid(gridId); var xformSys = entMan.System<SharedTransformSystem>();
tileSize = grid.TileSize; var mapPos = coordinates.ToMap(entMan, xformSys);
var mapX = (int)Math.Floor(mapPos.X) + 0.5f;
var mapY = (int)Math.Floor(mapPos.Y) + 0.5f;
mapPos = new MapCoordinates(new Vector2(mapX, mapY), mapPos.MapId);
return EntityCoordinates.FromMap(coordinates.EntityId, mapPos, xformSys);
} }
var localPos = coordinates.Position; var grid = mapManager.GetGrid(gridId.Value);
var tileSize = grid.TileSize;
var localPos = coordinates.WithEntityId(gridId.Value).Position;
var x = (int)Math.Floor(localPos.X / tileSize) + tileSize / 2f; var x = (int)Math.Floor(localPos.X / tileSize) + tileSize / 2f;
var y = (int)Math.Floor(localPos.Y / tileSize) + tileSize / 2f; var y = (int)Math.Floor(localPos.Y / tileSize) + tileSize / 2f;
var gridPos = new EntityCoordinates(gridId.Value, new Vector2(x, y));
return new EntityCoordinates(coordinates.EntityId, x, y); return gridPos.WithEntityId(coordinates.EntityId);
} }
public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, MapGridComponent grid) public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, MapGridComponent grid)

View File

@@ -140,13 +140,6 @@ namespace Content.Shared.Maps
return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<TurfSystem>().IsTileBlocked(turf, mask); return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<TurfSystem>().IsTileBlocked(turf, mask);
} }
public static EntityCoordinates GridPosition(this TileRef turf, IMapManager? mapManager = null)
{
mapManager ??= IoCManager.Resolve<IMapManager>();
return turf.GridIndices.ToEntityCoordinates(turf.GridUid, mapManager);
}
/// <summary> /// <summary>
/// Creates a box the size of a tile, at the same position in the world as the tile. /// Creates a box the size of a tile, at the same position in the world as the tile.
/// </summary> /// </summary>

View File

@@ -12,6 +12,7 @@ public sealed class TurfSystem : EntitySystem
{ {
[Dependency] private readonly EntityLookupSystem _entityLookup = default!; [Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly IMapManager _mapMan = default!;
/// <summary> /// <summary>
/// Returns true if a given tile is blocked by physics-enabled entities. /// Returns true if a given tile is blocked by physics-enabled entities.
@@ -84,4 +85,14 @@ public sealed class TurfSystem : EntitySystem
return false; return false;
} }
/// <summary>
/// Returns the location of the centre of the tile in grid coordinates.
/// </summary>
public EntityCoordinates GetTileCenter(TileRef turf)
{
var grid = _mapMan.GetGrid(turf.GridUid);
var center = (turf.GridIndices + new Vector2(0.5f, 0.5f)) * grid.TileSize;
return new EntityCoordinates(turf.GridUid, center);
}
} }