Fix weather blocking in some instances (#14561)

This commit is contained in:
metalgearsloth
2023-03-11 14:11:19 +11:00
committed by GitHub
parent 304ec2c8b3
commit 22ae0e7ed8
5 changed files with 26 additions and 4 deletions

View File

@@ -95,6 +95,7 @@ public sealed class WeatherOverlay : Overlay
{ {
var bodyQuery = _entManager.GetEntityQuery<PhysicsComponent>(); var bodyQuery = _entManager.GetEntityQuery<PhysicsComponent>();
var xformQuery = _entManager.GetEntityQuery<TransformComponent>(); var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
var weatherIgnoreQuery = _entManager.GetEntityQuery<IgnoreWeatherComponent>();
foreach (var grid in _mapManager.FindGridsIntersecting(mapId, worldAABB)) foreach (var grid in _mapManager.FindGridsIntersecting(mapId, worldAABB))
{ {
@@ -105,7 +106,7 @@ public sealed class WeatherOverlay : Overlay
foreach (var tile in grid.GetTilesIntersecting(worldAABB)) foreach (var tile in grid.GetTilesIntersecting(worldAABB))
{ {
// Ignored tiles for stencil // Ignored tiles for stencil
if (_weather.CanWeatherAffect(grid, tile, bodyQuery)) if (_weather.CanWeatherAffect(grid, tile, weatherIgnoreQuery, bodyQuery))
{ {
continue; continue;
} }

View File

@@ -82,6 +82,7 @@ public sealed class WeatherSystem : SharedWeatherSystem
// If we don't have a nearest node don't play any sound. // If we don't have a nearest node don't play any sound.
EntityCoordinates? nearestNode = null; EntityCoordinates? nearestNode = null;
var bodyQuery = GetEntityQuery<PhysicsComponent>(); var bodyQuery = GetEntityQuery<PhysicsComponent>();
var weatherIgnoreQuery = GetEntityQuery<IgnoreWeatherComponent>();
var visited = new HashSet<Vector2i>(); var visited = new HashSet<Vector2i>();
while (frontier.TryDequeue(out var node)) while (frontier.TryDequeue(out var node))
@@ -89,7 +90,7 @@ public sealed class WeatherSystem : SharedWeatherSystem
if (!visited.Add(node.GridIndices)) if (!visited.Add(node.GridIndices))
continue; continue;
if (!CanWeatherAffect(grid, node, bodyQuery)) if (!CanWeatherAffect(grid, node, weatherIgnoreQuery, bodyQuery))
{ {
// Add neighbors // Add neighbors
// TODO: Ideally we pick some deterministically random direction and use that // TODO: Ideally we pick some deterministically random direction and use that

View File

@@ -0,0 +1,12 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Weather;
/// <summary>
/// This entity will be ignored for considering weather on a tile
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed class IgnoreWeatherComponent : Component
{
}

View File

@@ -36,7 +36,11 @@ public abstract class SharedWeatherSystem : EntitySystem
} }
} }
public bool CanWeatherAffect(MapGridComponent grid, TileRef tileRef, EntityQuery<PhysicsComponent> bodyQuery) public bool CanWeatherAffect(
MapGridComponent grid,
TileRef tileRef,
EntityQuery<IgnoreWeatherComponent> weatherIgnoreQuery,
EntityQuery<PhysicsComponent> bodyQuery)
{ {
if (tileRef.Tile.IsEmpty) if (tileRef.Tile.IsEmpty)
return true; return true;
@@ -50,7 +54,10 @@ public abstract class SharedWeatherSystem : EntitySystem
while (anchoredEnts.MoveNext(out var ent)) while (anchoredEnts.MoveNext(out var ent))
{ {
if (bodyQuery.TryGetComponent(ent, out var body) && body.CanCollide) if (!weatherIgnoreQuery.HasComponent(ent.Value) &&
bodyQuery.TryGetComponent(ent, out var body) &&
body.Hard &&
body.CanCollide)
{ {
return false; return false;
} }

View File

@@ -37,6 +37,7 @@
description: Yep, it's a tree. description: Yep, it's a tree.
abstract: true abstract: true
components: components:
- type: IgnoreWeather
- type: SpriteFade - type: SpriteFade
- type: Clickable - type: Clickable
- type: Sprite - type: Sprite