Add gravitycomponent support to maps (#9857)
* Add gravitycomponent support to maps The alert still needs fixing if you want planets. * move
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
|
using Content.Shared.Gravity;
|
||||||
using Content.Shared.Movement;
|
using Content.Shared.Movement;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
using Content.Shared.Movement.Systems;
|
using Content.Shared.Movement.Systems;
|
||||||
@@ -18,6 +19,7 @@ namespace Content.Shared.Friction
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||||
|
[Dependency] private readonly SharedGravitySystem _gravity = default!;
|
||||||
|
|
||||||
protected SharedMoverController Mover = default!;
|
protected SharedMoverController Mover = default!;
|
||||||
|
|
||||||
@@ -165,16 +167,14 @@ namespace Content.Shared.Friction
|
|||||||
[Pure]
|
[Pure]
|
||||||
private float GetTileFriction(PhysicsComponent body, TransformComponent xform)
|
private float GetTileFriction(PhysicsComponent body, TransformComponent xform)
|
||||||
{
|
{
|
||||||
var coords = xform.Coordinates;
|
|
||||||
|
|
||||||
// TODO: Make IsWeightless event-based; we already have grid traversals tracked so just raise events
|
// TODO: Make IsWeightless event-based; we already have grid traversals tracked so just raise events
|
||||||
if (body.Owner.IsWeightless(body, coords, _mapManager) ||
|
if (_gravity.IsWeightless(body.Owner, body, xform) ||
|
||||||
!_mapManager.TryGetGrid(xform.GridUid, out var grid))
|
!_mapManager.TryGetGrid(xform.GridUid, out var grid))
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
|
||||||
if (!coords.IsValid(EntityManager)) return 0.0f;
|
if (!xform.Coordinates.IsValid(EntityManager)) return 0.0f;
|
||||||
|
|
||||||
var tile = grid.GetTileRef(coords);
|
var tile = grid.GetTileRef(xform.Coordinates);
|
||||||
var tileDef = _tileDefinitionManager[tile.Tile.TypeId];
|
var tileDef = _tileDefinitionManager[tile.Tile.TypeId];
|
||||||
return tileDef.Friction;
|
return tileDef.Friction;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,50 @@
|
|||||||
|
using Content.Shared.Clothing;
|
||||||
|
using Content.Shared.Inventory;
|
||||||
|
using Content.Shared.Movement.Components;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Physics;
|
||||||
|
|
||||||
namespace Content.Shared.Gravity
|
namespace Content.Shared.Gravity
|
||||||
{
|
{
|
||||||
public abstract class SharedGravitySystem : EntitySystem
|
public abstract class SharedGravitySystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
|
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||||
|
|
||||||
|
public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, TransformComponent? xform = null)
|
||||||
|
{
|
||||||
|
Resolve(uid, ref body, false);
|
||||||
|
|
||||||
|
if ((body?.BodyType & (BodyType.Static | BodyType.Kinematic)) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (TryComp<MovementIgnoreGravityComponent>(uid, out var ignoreGravityComponent))
|
||||||
|
return ignoreGravityComponent.Weightless;
|
||||||
|
|
||||||
|
if (!Resolve(uid, ref xform)) return true;
|
||||||
|
|
||||||
|
// If grid / map has gravity
|
||||||
|
if ((TryComp<GravityComponent>(xform.GridUid, out var gravity) ||
|
||||||
|
TryComp(xform.MapUid, out gravity)) && gravity.Enabled)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// On the map then always weightless (unless it has gravity comp obv).
|
||||||
|
if (!_mapManager.TryGetGrid(xform.GridUid, out var grid))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Something holding us down
|
||||||
|
if (_inventory.TryGetSlotEntity(uid, "shoes", out var ent))
|
||||||
|
{
|
||||||
|
if (TryComp<MagbootsComponent>(ent, out var boots) && boots.On)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!xform.Coordinates.IsValid(EntityManager)) return true;
|
||||||
|
|
||||||
|
var tile = grid.GetTileRef(xform.Coordinates).Tile;
|
||||||
|
return tile.IsEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ namespace Content.Shared.Movement.Components
|
|||||||
|
|
||||||
public static class GravityExtensions
|
public static class GravityExtensions
|
||||||
{
|
{
|
||||||
|
[Obsolete("Use GravitySystem")]
|
||||||
public static bool IsWeightless(this EntityUid entity, PhysicsComponent? body = null, EntityCoordinates? coords = null, IMapManager? mapManager = null, IEntityManager? entityManager = null)
|
public static bool IsWeightless(this EntityUid entity, PhysicsComponent? body = null, EntityCoordinates? coords = null, IMapManager? mapManager = null, IEntityManager? entityManager = null)
|
||||||
{
|
{
|
||||||
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||||
@@ -47,10 +48,12 @@ namespace Content.Shared.Movement.Components
|
|||||||
var transform = entityManager.GetComponent<TransformComponent>(entity);
|
var transform = entityManager.GetComponent<TransformComponent>(entity);
|
||||||
var gridId = transform.GridUid;
|
var gridId = transform.GridUid;
|
||||||
|
|
||||||
|
if ((entityManager.TryGetComponent<GravityComponent>(transform.GridUid, out var gravity) ||
|
||||||
|
entityManager.TryGetComponent(transform.MapUid, out gravity)) && gravity.Enabled)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (gridId == null)
|
if (gridId == null)
|
||||||
{
|
{
|
||||||
// Not on a grid = no gravity for now.
|
|
||||||
// In the future, may want to allow maps to override to always have gravity instead.
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.Friction;
|
using Content.Shared.Friction;
|
||||||
|
using Content.Shared.Gravity;
|
||||||
using Content.Shared.Inventory;
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
using Content.Shared.MobState.Components;
|
using Content.Shared.MobState.Components;
|
||||||
@@ -34,6 +35,7 @@ namespace Content.Shared.Movement.Systems
|
|||||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||||
|
[Dependency] private readonly SharedGravitySystem _gravity = default!;
|
||||||
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
|
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
|
||||||
[Dependency] private readonly TagSystem _tags = default!;
|
[Dependency] private readonly TagSystem _tags = default!;
|
||||||
|
|
||||||
@@ -112,7 +114,7 @@ namespace Content.Shared.Movement.Systems
|
|||||||
}
|
}
|
||||||
|
|
||||||
UsedMobMovement[mover.Owner] = true;
|
UsedMobMovement[mover.Owner] = true;
|
||||||
var weightless = mover.Owner.IsWeightless(physicsComponent, mapManager: _mapManager, entityManager: EntityManager);
|
var weightless = _gravity.IsWeightless(mover.Owner, physicsComponent, xform);
|
||||||
var (walkDir, sprintDir) = GetVelocityInput(mover);
|
var (walkDir, sprintDir) = GetVelocityInput(mover);
|
||||||
var touching = false;
|
var touching = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Content.Shared.Gravity;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
using Content.Shared.Tag;
|
using Content.Shared.Tag;
|
||||||
@@ -16,6 +17,7 @@ public sealed class ThrowingSystem : EntitySystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const float FlyTime = 0.15f;
|
public const float FlyTime = 0.15f;
|
||||||
|
|
||||||
|
[Dependency] private readonly SharedGravitySystem _gravity = default!;
|
||||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||||
[Dependency] private readonly ThrownItemSystem _thrownSystem = default!;
|
[Dependency] private readonly ThrownItemSystem _thrownSystem = default!;
|
||||||
[Dependency] private readonly TagSystem _tagSystem = default!;
|
[Dependency] private readonly TagSystem _tagSystem = default!;
|
||||||
@@ -23,7 +25,7 @@ public sealed class ThrowingSystem : EntitySystem
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to throw the entity if it has a physics component, otherwise does nothing.
|
/// Tries to throw the entity if it has a physics component, otherwise does nothing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="entity">The entity being thrown.</param>
|
/// <param name="uid">The entity being thrown.</param>
|
||||||
/// <param name="direction">A vector pointing from the entity to its destination.</param>
|
/// <param name="direction">A vector pointing from the entity to its destination.</param>
|
||||||
/// <param name="strength">How much the direction vector should be multiplied for velocity.</param>
|
/// <param name="strength">How much the direction vector should be multiplied for velocity.</param>
|
||||||
/// <param name="user"></param>
|
/// <param name="user"></param>
|
||||||
@@ -97,10 +99,10 @@ public sealed class ThrowingSystem : EntitySystem
|
|||||||
if (user != null &&
|
if (user != null &&
|
||||||
pushbackRatio > 0.0f &&
|
pushbackRatio > 0.0f &&
|
||||||
physicsQuery.Value.TryGetComponent(user.Value, out var userPhysics) &&
|
physicsQuery.Value.TryGetComponent(user.Value, out var userPhysics) &&
|
||||||
user.Value.IsWeightless(userPhysics, entityManager: EntityManager))
|
_gravity.IsWeightless(user.Value, userPhysics))
|
||||||
{
|
{
|
||||||
var msg = new ThrowPushbackAttemptEvent();
|
var msg = new ThrowPushbackAttemptEvent();
|
||||||
RaiseLocalEvent(physics.Owner, msg, false);
|
RaiseLocalEvent(physics.Owner, msg);
|
||||||
|
|
||||||
if (!msg.Cancelled)
|
if (!msg.Cancelled)
|
||||||
userPhysics.ApplyLinearImpulse(-impulseVector * pushbackRatio);
|
userPhysics.ApplyLinearImpulse(-impulseVector * pushbackRatio);
|
||||||
|
|||||||
Reference in New Issue
Block a user