Make Saltern driveable (#4257)
* Broadphase refactor (content) * Shuttle jank * Fixes * Testing jank * Features and things * Balance stuffsies * AHHHHHHHHHHHHHHHH * Mass and stuff working * Fix drops * Another balance pass * Balance AGEN * Add in stuff for rotating shuttles for debugging * Nothing to see here * Testbed stuffsies * Fix some tests * Fixen test * Try fixing map * Shuttle movement balance pass * lasaggne * Basic Helmsman console working * Slight docking cleanup * Helmsman requires power * Basic shuttle test * Stuff * Fix computations * Add shuttle console to saltern * Rename helmsman to shuttleconsole * Final stretch * More tweaks * Fix piloting prediction for now.
This commit is contained in:
12
Content.Client/Shuttles/ShuttleConsoleComponent.cs
Normal file
12
Content.Client/Shuttles/ShuttleConsoleComponent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Content.Shared.Shuttles;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Shuttles
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedShuttleConsoleComponent))]
|
||||
internal sealed class ShuttleConsoleComponent : SharedShuttleConsoleComponent
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
9
Content.Client/Shuttles/ShuttleConsoleSystem.cs
Normal file
9
Content.Client/Shuttles/ShuttleConsoleSystem.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Content.Shared.Shuttles;
|
||||
|
||||
namespace Content.Client.Shuttles
|
||||
{
|
||||
internal sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ namespace Content.Client.Tools.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent()]
|
||||
|
||||
public class WelderComponent : SharedToolComponent, IItemStatus
|
||||
{
|
||||
public override string Name => "Welder";
|
||||
|
||||
@@ -126,8 +126,7 @@ namespace Content.IntegrationTests.Tests.Doors
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
var mapId = new MapId(1);
|
||||
mapManager.CreateNewMapEntity(mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
|
||||
var humanCoordinates = new MapCoordinates((physicsDummyStartingX, 0), mapId);
|
||||
physicsDummy = entityManager.SpawnEntity("PhysicsDummy", humanCoordinates);
|
||||
@@ -159,6 +158,7 @@ namespace Content.IntegrationTests.Tests.Doors
|
||||
// Sanity check
|
||||
// Sloth: Okay I'm sorry but I hate having to rewrite tests for every refactor
|
||||
// If you see this yell at me in discord so I can continue to pretend this didn't happen.
|
||||
// REMINDER THAT I STILL HAVE TO FIX THIS TEST EVERY OTHER PHYSICS PR
|
||||
// Assert.That(physicsDummy.Transform.MapPosition.X, Is.GreaterThan(physicsDummyStartingX));
|
||||
|
||||
// Blocked by the airlock
|
||||
|
||||
@@ -27,12 +27,12 @@ namespace Content.IntegrationTests.Tests
|
||||
var mapLoader = server.ResolveDependency<IMapLoader>();
|
||||
var mapManager = server.ResolveDependency<IMapManager>();
|
||||
var entityManager = server.ResolveDependency<IEntityManager>();
|
||||
var resManager = server.ResolveDependency<IResourceManager>();
|
||||
|
||||
server.Post(() =>
|
||||
{
|
||||
var dir = new ResourcePath(mapPath).Directory;
|
||||
IoCManager.Resolve<IResourceManager>()
|
||||
.UserData.CreateDir(dir);
|
||||
resManager.UserData.CreateDir(dir);
|
||||
|
||||
var mapId = mapManager.CreateMap(new MapId(5));
|
||||
|
||||
|
||||
49
Content.IntegrationTests/Tests/ShuttleTest.cs
Normal file
49
Content.IntegrationTests/Tests/ShuttleTest.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Shuttles;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.IntegrationTests.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ShuttleTest : ContentIntegrationTest
|
||||
{
|
||||
[Test]
|
||||
public async Task Test()
|
||||
{
|
||||
var server = StartServer();
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
|
||||
var entMan = server.ResolveDependency<IEntityManager>();
|
||||
var mapMan = server.ResolveDependency<IMapManager>();
|
||||
IEntity? gridEnt = null;
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGrid(mapId);
|
||||
gridEnt = entMan.GetEntity(grid.GridEntityId);
|
||||
|
||||
Assert.That(gridEnt.TryGetComponent(out ShuttleComponent? shuttleComponent));
|
||||
Assert.That(gridEnt.TryGetComponent(out PhysicsComponent? physicsComponent));
|
||||
Assert.That(physicsComponent!.BodyType, Is.EqualTo(BodyType.Dynamic));
|
||||
Assert.That(gridEnt.Transform.LocalPosition, Is.EqualTo(Vector2.Zero));
|
||||
physicsComponent.ApplyLinearImpulse(Vector2.One);
|
||||
});
|
||||
|
||||
// TODO: Should have tests that collision + rendertree + pointlights work on a moved grid but I'll deal with that
|
||||
// when we get rotations.
|
||||
await server.WaitRunTicks(1);
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
Assert.That(gridEnt?.Transform.LocalPosition, Is.Not.EqualTo(Vector2.Zero));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Spawning;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Utility
|
||||
@@ -39,7 +40,7 @@ namespace Content.IntegrationTests.Tests.Utility
|
||||
|
||||
var sMapManager = server.ResolveDependency<IMapManager>();
|
||||
var sEntityManager = server.ResolveDependency<IEntityManager>();
|
||||
var broady = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<SharedBroadPhaseSystem>();
|
||||
var broady = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<SharedBroadphaseSystem>();
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Content.Server.AI.Utils
|
||||
angle.ToVec(),
|
||||
(int)(CollisionGroup.Opaque | CollisionGroup.Impassable | CollisionGroup.MobImpassable));
|
||||
|
||||
var rayCastResults = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(owner.Transform.MapID, ray, range, owner).ToList();
|
||||
var rayCastResults = EntitySystem.Get<SharedBroadphaseSystem>().IntersectRay(owner.Transform.MapID, ray, range, owner).ToList();
|
||||
|
||||
return rayCastResults.Count > 0 && rayCastResults[0].HitEntity == target;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Content.Server.Shuttle;
|
||||
using Content.Server.Shuttles;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Shuttles;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Alert.Click
|
||||
@@ -14,9 +16,10 @@ namespace Content.Server.Alert.Click
|
||||
{
|
||||
public void AlertClicked(ClickAlertEventArgs args)
|
||||
{
|
||||
if (args.Player.TryGetComponent(out ShuttleControllerComponent? controller))
|
||||
if (args.Player.TryGetComponent(out PilotComponent? pilotComponent) &&
|
||||
pilotComponent.Console != null)
|
||||
{
|
||||
controller.RemoveController();
|
||||
EntitySystem.Get<ShuttleConsoleSystem>().RemovePilot(pilotComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
@@ -387,7 +388,7 @@ namespace Content.Server.Doors.Components
|
||||
|
||||
if (safety && Owner.TryGetComponent(out PhysicsComponent? physicsComponent))
|
||||
{
|
||||
var broadPhaseSystem = EntitySystem.Get<SharedBroadPhaseSystem>();
|
||||
var broadPhaseSystem = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
|
||||
// Use this version so we can ignore the CanCollide being false
|
||||
foreach(var e in broadPhaseSystem.GetCollidingEntities(physicsComponent.Owner.Transform.MapID, physicsComponent.GetWorldAABB()))
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Inventory.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Movement.Components;
|
||||
using Content.Server.Shuttle;
|
||||
using Content.Server.Shuttles;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Shuttles;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Player;
|
||||
@@ -37,12 +42,17 @@ namespace Content.Server.Physics.Controllers
|
||||
private const float StepSoundMoveDistanceRunning = 2;
|
||||
private const float StepSoundMoveDistanceWalking = 1.5f;
|
||||
|
||||
private float _shuttleDockSpeedCap;
|
||||
|
||||
private HashSet<EntityUid> _excludedMobs = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_audioSystem = EntitySystem.Get<AudioSystem>();
|
||||
|
||||
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
||||
configManager.OnValueChanged(CCVars.ShuttleDockSpeedCap, value => _shuttleDockSpeedCap = value, true);
|
||||
}
|
||||
|
||||
public override void UpdateBeforeSolve(bool prediction, float frameTime)
|
||||
@@ -56,8 +66,9 @@ namespace Content.Server.Physics.Controllers
|
||||
HandleMobMovement(mover, physics, mobMover);
|
||||
}
|
||||
|
||||
foreach (var mover in ComponentManager.EntityQuery<ShuttleControllerComponent>())
|
||||
foreach (var (pilot, mover) in ComponentManager.EntityQuery<PilotComponent, SharedPlayerInputMoverComponent>())
|
||||
{
|
||||
if (pilot.Console == null) continue;
|
||||
_excludedMobs.Add(mover.Owner.Uid);
|
||||
HandleShuttleMovement(mover);
|
||||
}
|
||||
@@ -76,13 +87,70 @@ namespace Content.Server.Physics.Controllers
|
||||
* The reason for this is that vehicles change direction very slowly compared to players so you don't really have the requirement for quick movement anyway
|
||||
* As such could probably just look at applying a force / impulse to the shuttle server-side only so it controls like the titanic.
|
||||
*/
|
||||
private void HandleShuttleMovement(ShuttleControllerComponent mover)
|
||||
private void HandleShuttleMovement(SharedPlayerInputMoverComponent mover)
|
||||
{
|
||||
var gridId = mover.Owner.Transform.GridID;
|
||||
|
||||
if (!_mapManager.TryGetGrid(gridId, out var grid) || !EntityManager.TryGetEntity(grid.GridEntityId, out var gridEntity)) return;
|
||||
|
||||
// This is on shuttle branch trust me
|
||||
if (!gridEntity.TryGetComponent(out ShuttleComponent? shuttleComponent) ||
|
||||
!gridEntity.TryGetComponent(out PhysicsComponent? physicsComponent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Depending whether you have "cruise" mode on (tank controls, higher speed) or "docking" mode on (strafing, lower speed)
|
||||
// inputs will do different things.
|
||||
// TODO: Do that
|
||||
float speedCap;
|
||||
// This is comically fast for debugging
|
||||
var angularSpeed = 20000f;
|
||||
|
||||
// ShuttleSystem has already worked out the ratio so we'll just multiply it back by the mass.
|
||||
var movement = (mover.VelocityDir.walking + mover.VelocityDir.sprinting);
|
||||
|
||||
switch (shuttleComponent.Mode)
|
||||
{
|
||||
case ShuttleMode.Docking:
|
||||
if (movement.Length != 0f)
|
||||
physicsComponent.ApplyLinearImpulse(physicsComponent.Owner.Transform.WorldRotation.RotateVec(movement) * shuttleComponent.SpeedMultipler * physicsComponent.Mass);
|
||||
|
||||
speedCap = _shuttleDockSpeedCap;
|
||||
break;
|
||||
case ShuttleMode.Cruise:
|
||||
if (movement.Length != 0.0f)
|
||||
{
|
||||
// Currently this is slow BUT we'd have a separate multiplier for docking and cruising or whatever.
|
||||
physicsComponent.ApplyLinearImpulse((physicsComponent.Owner.Transform.WorldRotation + new Angle(MathF.PI / 2)).ToVec() *
|
||||
shuttleComponent.SpeedMultipler *
|
||||
physicsComponent.Mass *
|
||||
movement.Y *
|
||||
10);
|
||||
physicsComponent.ApplyAngularImpulse(movement.X * angularSpeed);
|
||||
}
|
||||
|
||||
// TODO WHEN THIS ACTUALLY WORKS
|
||||
speedCap = _shuttleDockSpeedCap * 10;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
// Look don't my ride ass on this stuff most of the PR was just getting the thing working, we can
|
||||
// ideaguys the shit out of it later.
|
||||
|
||||
var velocity = physicsComponent.LinearVelocity;
|
||||
|
||||
if (velocity.Length < 0.1f && movement.Length == 0f)
|
||||
{
|
||||
physicsComponent.LinearVelocity = Vector2.Zero;
|
||||
return;
|
||||
}
|
||||
|
||||
if (velocity.Length > speedCap)
|
||||
{
|
||||
physicsComponent.LinearVelocity = velocity.Normalized * speedCap;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void HandleFootsteps(IMoverComponent mover, IMobMoverComponent mobMover)
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Content.Server.Physics
|
||||
public class TestbedCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "testbed";
|
||||
public string Description => "Loads a physics testbed and teleports your player there";
|
||||
public string Description => "Loads a physics testbed on the specified map.";
|
||||
public string Help => $"{Command} <mapid> <test>";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
@@ -127,7 +127,10 @@ namespace Content.Server.Physics
|
||||
CollisionMask = (int) CollisionGroup.Impassable,
|
||||
Hard = true
|
||||
};
|
||||
ground.AddFixture(horizontalFixture);
|
||||
|
||||
var broadphase = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
|
||||
broadphase.CreateFixture(ground, horizontalFixture);
|
||||
|
||||
var vertical = new EdgeShape(new Vector2(10, 0), new Vector2(10, 10));
|
||||
var verticalFixture = new Fixture(ground, vertical)
|
||||
@@ -136,7 +139,8 @@ namespace Content.Server.Physics
|
||||
CollisionMask = (int) CollisionGroup.Impassable,
|
||||
Hard = true
|
||||
};
|
||||
ground.AddFixture(verticalFixture);
|
||||
|
||||
broadphase.CreateFixture(ground, verticalFixture);
|
||||
|
||||
var xs = new[]
|
||||
{
|
||||
@@ -157,7 +161,6 @@ namespace Content.Server.Physics
|
||||
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)).AddComponent<PhysicsComponent>();
|
||||
|
||||
box.BodyType = BodyType.Dynamic;
|
||||
box.SleepingAllowed = false;
|
||||
shape = new PolygonShape();
|
||||
shape.SetAsBox(0.5f, 0.5f);
|
||||
box.FixedRotation = false;
|
||||
@@ -169,7 +172,8 @@ namespace Content.Server.Physics
|
||||
CollisionLayer = (int) CollisionGroup.Impassable,
|
||||
Hard = true,
|
||||
};
|
||||
box.AddFixture(fixture);
|
||||
|
||||
broadphase.CreateFixture(box, fixture);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,7 +191,9 @@ namespace Content.Server.Physics
|
||||
CollisionMask = (int) CollisionGroup.Impassable,
|
||||
Hard = true
|
||||
};
|
||||
ground.AddFixture(horizontalFixture);
|
||||
|
||||
var broadphase = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
broadphase.CreateFixture(ground, horizontalFixture);
|
||||
|
||||
var vertical = new EdgeShape(new Vector2(10, 0), new Vector2(10, 10));
|
||||
var verticalFixture = new Fixture(ground, vertical)
|
||||
@@ -196,7 +202,8 @@ namespace Content.Server.Physics
|
||||
CollisionMask = (int) CollisionGroup.Impassable,
|
||||
Hard = true
|
||||
};
|
||||
ground.AddFixture(verticalFixture);
|
||||
|
||||
broadphase.CreateFixture(ground, verticalFixture);
|
||||
|
||||
var xs = new[]
|
||||
{
|
||||
@@ -217,7 +224,6 @@ namespace Content.Server.Physics
|
||||
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)).AddComponent<PhysicsComponent>();
|
||||
|
||||
box.BodyType = BodyType.Dynamic;
|
||||
box.SleepingAllowed = false;
|
||||
shape = new PhysShapeCircle {Radius = 0.5f};
|
||||
box.FixedRotation = false;
|
||||
// TODO: Need to detect shape and work out if we need to use fixedrotation
|
||||
@@ -228,7 +234,8 @@ namespace Content.Server.Physics
|
||||
CollisionLayer = (int) CollisionGroup.Impassable,
|
||||
Hard = true,
|
||||
};
|
||||
box.AddFixture(fixture);
|
||||
|
||||
broadphase.CreateFixture(box, fixture);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -249,7 +256,8 @@ namespace Content.Server.Physics
|
||||
Hard = true
|
||||
};
|
||||
|
||||
ground.AddFixture(horizontalFixture);
|
||||
var broadphase = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
broadphase.CreateFixture(ground, horizontalFixture);
|
||||
|
||||
// Setup boxes
|
||||
float a = 0.5f;
|
||||
@@ -270,7 +278,7 @@ namespace Content.Server.Physics
|
||||
var box = entityManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)).AddComponent<PhysicsComponent>();
|
||||
box.BodyType = BodyType.Dynamic;
|
||||
box.Owner.Transform.WorldPosition = y;
|
||||
box.AddFixture(
|
||||
broadphase.CreateFixture(box,
|
||||
new Fixture(box, shape) {
|
||||
CollisionLayer = (int) CollisionGroup.Impassable,
|
||||
CollisionMask = (int) CollisionGroup.Impassable,
|
||||
|
||||
@@ -1,197 +0,0 @@
|
||||
using Content.Server.Alert;
|
||||
using Content.Server.Buckle.Components;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Shuttle
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IMoverComponent))]
|
||||
internal class ShuttleControllerComponent : Component, IMoverComponent
|
||||
{
|
||||
private bool _movingUp;
|
||||
private bool _movingDown;
|
||||
private bool _movingLeft;
|
||||
private bool _movingRight;
|
||||
|
||||
/// <summary>
|
||||
/// ID of the alert to show when piloting
|
||||
/// </summary>
|
||||
[DataField("pilotingAlertType")]
|
||||
private AlertType _pilotingAlertType = AlertType.PilotingShuttle;
|
||||
|
||||
/// <summary>
|
||||
/// The entity that's currently controlling this component.
|
||||
/// Changed from <see cref="SetController"/> and <see cref="RemoveController"/>
|
||||
/// </summary>
|
||||
private IEntity? _controller;
|
||||
|
||||
public override string Name => "ShuttleController";
|
||||
|
||||
public bool IgnorePaused => false;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float CurrentWalkSpeed { get; } = 8;
|
||||
public float CurrentSprintSpeed => 0;
|
||||
|
||||
public bool Sprinting => false;
|
||||
|
||||
public (Vector2 walking, Vector2 sprinting) VelocityDir { get; set; } = (Vector2.Zero, Vector2.Zero);
|
||||
|
||||
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled)
|
||||
{
|
||||
VelocityDir = (CalcNewVelocity(direction, enabled), Vector2.Zero);
|
||||
}
|
||||
|
||||
public void SetSprinting(ushort subTick, bool walking)
|
||||
{
|
||||
// Shuttles can't sprint.
|
||||
}
|
||||
|
||||
private Vector2 CalcNewVelocity(Direction direction, bool enabled)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.East:
|
||||
_movingRight = enabled;
|
||||
break;
|
||||
case Direction.North:
|
||||
_movingUp = enabled;
|
||||
break;
|
||||
case Direction.West:
|
||||
_movingLeft = enabled;
|
||||
break;
|
||||
case Direction.South:
|
||||
_movingDown = enabled;
|
||||
break;
|
||||
}
|
||||
|
||||
// key directions are in screen coordinates
|
||||
// _moveDir is in world coordinates
|
||||
// if the camera is moved, this needs to be changed
|
||||
|
||||
var x = 0;
|
||||
x -= _movingLeft ? 1 : 0;
|
||||
x += _movingRight ? 1 : 0;
|
||||
|
||||
var y = 0;
|
||||
y -= _movingDown ? 1 : 0;
|
||||
y += _movingUp ? 1 : 0;
|
||||
|
||||
var result = new Vector2(x, y);
|
||||
|
||||
// can't normalize zero length vector
|
||||
if (result.LengthSquared > 1.0e-6)
|
||||
{
|
||||
result = result.Normalized;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the entity currently controlling this shuttle controller
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to set</param>
|
||||
private void SetController(IEntity entity)
|
||||
{
|
||||
if (_controller != null ||
|
||||
!entity.TryGetComponent(out MindComponent? mind) ||
|
||||
mind.Mind == null ||
|
||||
!Owner.TryGetComponent(out ServerAlertsComponent? status))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mind.Mind.Visit(Owner);
|
||||
_controller = entity;
|
||||
|
||||
status.ShowAlert(_pilotingAlertType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the current controller
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to remove, or null to force the removal of any current controller</param>
|
||||
public void RemoveController(IEntity? entity = null)
|
||||
{
|
||||
if (_controller == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are not forcing a controller removal and the entity is not the current controller
|
||||
if (entity != null && entity != _controller)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateRemovedEntity(entity ?? _controller);
|
||||
|
||||
_controller = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the state of an entity that is no longer controlling this shuttle controller.
|
||||
/// Called from <see cref="RemoveController"/>
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to update</param>
|
||||
private void UpdateRemovedEntity(IEntity entity)
|
||||
{
|
||||
if (Owner.TryGetComponent(out ServerAlertsComponent? status))
|
||||
{
|
||||
status.ClearAlert(_pilotingAlertType);
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out MindComponent? mind))
|
||||
{
|
||||
mind.Mind?.UnVisit();
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out BuckleComponent? buckle))
|
||||
{
|
||||
buckle.TryUnbuckle(entity, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void BuckleChanged(IEntity entity, in bool buckled)
|
||||
{
|
||||
Logger.DebugS("shuttle", $"Pilot={entity.Name}, buckled={buckled}");
|
||||
|
||||
if (buckled)
|
||||
{
|
||||
SetController(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveController(entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Owner.EnsureComponent<ServerAlertsComponent>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case StrapChangeMessage strap:
|
||||
BuckleChanged(strap.Entity, strap.Buckled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Content.Server/Shuttles/ShuttleComponent.cs
Normal file
11
Content.Server/Shuttles/ShuttleComponent.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Content.Shared.Shuttles;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Shuttles
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ShuttleComponent : SharedShuttleComponent
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
21
Content.Server/Shuttles/ShuttleConsoleComponent.cs
Normal file
21
Content.Server/Shuttles/ShuttleConsoleComponent.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Shuttles;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Shuttles
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedShuttleConsoleComponent))]
|
||||
internal sealed class ShuttleConsoleComponent : SharedShuttleConsoleComponent
|
||||
{
|
||||
[ViewVariables]
|
||||
public List<PilotComponent> SubscribedPilots = new();
|
||||
|
||||
/// <summary>
|
||||
/// Whether the console can be used to pilot. Toggled whenever it gets powered / unpowered.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool Enabled { get; set; } = false;
|
||||
}
|
||||
}
|
||||
169
Content.Server/Shuttles/ShuttleConsoleSystem.cs
Normal file
169
Content.Server/Shuttles/ShuttleConsoleSystem.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Alert;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Shuttles;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Shuttles
|
||||
{
|
||||
internal sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ShuttleConsoleComponent, ComponentShutdown>(HandleConsoleShutdown);
|
||||
SubscribeLocalEvent<PilotComponent, ComponentShutdown>(HandlePilotShutdown);
|
||||
SubscribeLocalEvent<ShuttleConsoleComponent, ActivateInWorldEvent>(HandleConsoleInteract);
|
||||
SubscribeLocalEvent<PilotComponent, MoveEvent>(HandlePilotMove);
|
||||
SubscribeLocalEvent<ShuttleConsoleComponent, PowerChangedEvent>(HandlePowerChange);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
foreach (var comp in ComponentManager.EntityQuery<PilotComponent>().ToArray())
|
||||
{
|
||||
if (comp.Console == null) continue;
|
||||
|
||||
if (!Get<ActionBlockerSystem>().CanInteract(comp.Owner))
|
||||
{
|
||||
RemovePilot(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Console requires power to operate.
|
||||
/// </summary>
|
||||
private void HandlePowerChange(EntityUid uid, ShuttleConsoleComponent component, PowerChangedEvent args)
|
||||
{
|
||||
if (!args.Powered)
|
||||
{
|
||||
component.Enabled = false;
|
||||
|
||||
ClearPilots(component);
|
||||
}
|
||||
else
|
||||
{
|
||||
component.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If pilot is moved then we'll stop them from piloting.
|
||||
/// </summary>
|
||||
private void HandlePilotMove(EntityUid uid, PilotComponent component, MoveEvent args)
|
||||
{
|
||||
if (component.Console == null) return;
|
||||
RemovePilot(component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For now pilots just interact with the console and can start piloting with wasd.
|
||||
/// </summary>
|
||||
private void HandleConsoleInteract(EntityUid uid, ShuttleConsoleComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (!args.User.HasTag("CanPilot"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var pilotComponent = args.User.EnsureComponent<PilotComponent>();
|
||||
|
||||
if (!component.Enabled)
|
||||
{
|
||||
args.User.PopupMessage($"Console is not powered.");
|
||||
return;
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
var console = pilotComponent.Console;
|
||||
|
||||
if (console != null)
|
||||
{
|
||||
RemovePilot(pilotComponent);
|
||||
|
||||
if (console != component)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AddPilot(args.User, component);
|
||||
}
|
||||
|
||||
private void HandlePilotShutdown(EntityUid uid, PilotComponent component, ComponentShutdown args)
|
||||
{
|
||||
RemovePilot(component);
|
||||
}
|
||||
|
||||
private void HandleConsoleShutdown(EntityUid uid, ShuttleConsoleComponent component, ComponentShutdown args)
|
||||
{
|
||||
ClearPilots(component);
|
||||
}
|
||||
|
||||
public void AddPilot(IEntity entity, ShuttleConsoleComponent component)
|
||||
{
|
||||
if (!Get<ActionBlockerSystem>().CanInteract(entity) ||
|
||||
!entity.TryGetComponent(out PilotComponent? pilotComponent) ||
|
||||
component.SubscribedPilots.Contains(pilotComponent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
component.SubscribedPilots.Add(pilotComponent);
|
||||
|
||||
if (entity.TryGetComponent(out ServerAlertsComponent? alertsComponent))
|
||||
{
|
||||
alertsComponent.ShowAlert(AlertType.PilotingShuttle);
|
||||
}
|
||||
|
||||
entity.PopupMessage(Loc.GetString("shuttle-pilot-start"));
|
||||
pilotComponent.Console = component;
|
||||
pilotComponent.Dirty();
|
||||
}
|
||||
|
||||
public void RemovePilot(PilotComponent pilotComponent)
|
||||
{
|
||||
var console = pilotComponent.Console;
|
||||
|
||||
if (console is not ShuttleConsoleComponent helmsman) return;
|
||||
|
||||
pilotComponent.Console = null;
|
||||
|
||||
if (!helmsman.SubscribedPilots.Remove(pilotComponent)) return;
|
||||
|
||||
if (pilotComponent.Owner.TryGetComponent(out ServerAlertsComponent? alertsComponent))
|
||||
{
|
||||
alertsComponent.ClearAlert(AlertType.PilotingShuttle);
|
||||
}
|
||||
|
||||
pilotComponent.Owner.PopupMessage(Loc.GetString("shuttle-pilot-end"));
|
||||
// TODO: RemoveComponent<T> is cooked and doesn't sync to client so this fucks up movement prediction.
|
||||
// ComponentManager.RemoveComponent<PilotComponent>(pilotComponent.Owner.Uid);
|
||||
pilotComponent.Console = null;
|
||||
pilotComponent.Dirty();
|
||||
}
|
||||
|
||||
public void RemovePilot(IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out PilotComponent? pilotComponent)) return;
|
||||
|
||||
RemovePilot(pilotComponent);
|
||||
}
|
||||
|
||||
public void ClearPilots(ShuttleConsoleComponent component)
|
||||
{
|
||||
foreach (var pilot in component.SubscribedPilots)
|
||||
{
|
||||
RemovePilot(pilot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
147
Content.Server/Shuttles/ShuttleSystem.cs
Normal file
147
Content.Server/Shuttles/ShuttleSystem.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using Content.Shared.Shuttles;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Physics;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.Server.Shuttles
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class ShuttleSystem : EntitySystem
|
||||
{
|
||||
private const float TileMassMultiplier = 1f;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ShuttleComponent, ComponentStartup>(HandleShuttleStartup);
|
||||
SubscribeLocalEvent<ShuttleComponent, ComponentShutdown>(HandleShuttleShutdown);
|
||||
|
||||
SubscribeLocalEvent<GridInitializeEvent>(HandleGridInit);
|
||||
SubscribeLocalEvent<GridFixtureChangeEvent>(HandleGridFixtureChange);
|
||||
}
|
||||
|
||||
private void HandleGridFixtureChange(GridFixtureChangeEvent args)
|
||||
{
|
||||
var fixture = args.NewFixture;
|
||||
|
||||
if (fixture == null) return;
|
||||
|
||||
fixture.Mass = fixture.Area * TileMassMultiplier;
|
||||
|
||||
if (fixture.Body.Owner.TryGetComponent(out ShuttleComponent? shuttleComponent))
|
||||
{
|
||||
RecalculateSpeedMultiplier(shuttleComponent, fixture.Body);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleGridInit(GridInitializeEvent ev)
|
||||
{
|
||||
EntityManager.GetEntity(ev.EntityUid).EnsureComponent<ShuttleComponent>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cache the thrust available to this shuttle.
|
||||
/// </summary>
|
||||
private void RecalculateSpeedMultiplier(SharedShuttleComponent shuttle, PhysicsComponent physics)
|
||||
{
|
||||
// TODO: Need per direction speed (Never Eat Soggy Weetbix).
|
||||
// TODO: This will need hella tweaking.
|
||||
var thrusters = physics.FixtureCount;
|
||||
|
||||
if (thrusters == 0)
|
||||
{
|
||||
shuttle.SpeedMultipler = 0f;
|
||||
}
|
||||
|
||||
const float ThrustPerThruster = 0.25f;
|
||||
const float MinimumThrustRequired = 0.005f;
|
||||
|
||||
// Just so someone can't slap a single thruster on a station and call it a day; need to hit a minimum amount.
|
||||
var thrustRatio = Math.Max(0, thrusters * ThrustPerThruster / physics.Mass);
|
||||
|
||||
if (thrustRatio < MinimumThrustRequired)
|
||||
shuttle.SpeedMultipler = 0f;
|
||||
|
||||
const float MaxThrust = 10f;
|
||||
// This doesn't need to align with MinimumThrustRequired; if you set this higher it just means the first few additional
|
||||
// thrusters won't do anything.
|
||||
const float MinThrust = MinimumThrustRequired;
|
||||
|
||||
shuttle.SpeedMultipler = MathF.Max(MinThrust, MathF.Min(MaxThrust, thrustRatio));
|
||||
}
|
||||
|
||||
private void HandleShuttleStartup(EntityUid uid, ShuttleComponent component, ComponentStartup args)
|
||||
{
|
||||
if (!component.Owner.HasComponent<IMapGridComponent>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!component.Owner.TryGetComponent(out PhysicsComponent? physicsComponent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.Enabled)
|
||||
{
|
||||
Enable(physicsComponent);
|
||||
}
|
||||
|
||||
if (component.Owner.TryGetComponent(out ShuttleComponent? shuttleComponent))
|
||||
{
|
||||
RecalculateSpeedMultiplier(shuttleComponent, physicsComponent);
|
||||
}
|
||||
}
|
||||
|
||||
public void Toggle(ShuttleComponent component)
|
||||
{
|
||||
if (!component.Owner.TryGetComponent(out PhysicsComponent? physicsComponent)) return;
|
||||
|
||||
component.Enabled = !component.Enabled;
|
||||
|
||||
if (component.Enabled)
|
||||
{
|
||||
Enable(physicsComponent);
|
||||
}
|
||||
else
|
||||
{
|
||||
Disable(physicsComponent);
|
||||
}
|
||||
}
|
||||
|
||||
private void Enable(PhysicsComponent component)
|
||||
{
|
||||
component.BodyType = BodyType.Dynamic;
|
||||
component.BodyStatus = BodyStatus.InAir;
|
||||
//component.FixedRotation = false; TODO WHEN ROTATING SHUTTLES FIXED.
|
||||
component.FixedRotation = true;
|
||||
component.LinearDamping = 0.05f;
|
||||
}
|
||||
|
||||
private void Disable(PhysicsComponent component)
|
||||
{
|
||||
component.BodyType = BodyType.Static;
|
||||
component.BodyStatus = BodyStatus.OnGround;
|
||||
component.FixedRotation = true;
|
||||
}
|
||||
|
||||
private void HandleShuttleShutdown(EntityUid uid, ShuttleComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (!component.Owner.TryGetComponent(out PhysicsComponent? physicsComponent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Disable(physicsComponent);
|
||||
|
||||
foreach (var fixture in physicsComponent.Fixtures)
|
||||
{
|
||||
fixture.Mass = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ namespace Content.Server.Singularity.Components
|
||||
|
||||
var dirVec = direction.ToVec();
|
||||
var ray = new CollisionRay(Owner.Transform.WorldPosition, dirVec, (int) CollisionGroup.MobMask);
|
||||
var rawRayCastResults = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
|
||||
var rawRayCastResults = EntitySystem.Get<SharedBroadphaseSystem>().IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
|
||||
|
||||
var rayCastResults = rawRayCastResults as RayCastResults[] ?? rawRayCastResults.ToArray();
|
||||
if(!rayCastResults.Any()) continue;
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace Content.Server.Solar.EntitySystems
|
||||
// Determine if the solar panel is occluded, and zero out coverage if so.
|
||||
// FIXME: The "Opaque" collision group doesn't seem to work right now.
|
||||
var ray = new CollisionRay(entity.Transform.WorldPosition, TowardsSun.ToWorldVec(), (int) CollisionGroup.Opaque);
|
||||
var rayCastResults = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(entity.Transform.MapID, ray, SunOcclusionCheckDistance, entity);
|
||||
var rayCastResults = EntitySystem.Get<SharedBroadphaseSystem>().IntersectRay(entity.Transform.MapID, ray, SunOcclusionCheckDistance, entity);
|
||||
if (rayCastResults.Any())
|
||||
coverage = 0;
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace Content.Server.Weapon.Melee
|
||||
for (var i = 0; i < increments; i++)
|
||||
{
|
||||
var castAngle = new Angle(baseAngle + increment * i);
|
||||
var res = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(mapId,
|
||||
var res = EntitySystem.Get<SharedBroadphaseSystem>().IntersectRay(mapId,
|
||||
new CollisionRay(position, castAngle.ToWorldVec(),
|
||||
(int) (CollisionGroup.Impassable | CollisionGroup.MobImpassable)), range, ignore).ToList();
|
||||
|
||||
|
||||
@@ -366,7 +366,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
// FIXME: Work around issue where inserting and removing an entity from a container,
|
||||
// then setting its linear velocity in the same tick resets velocity back to zero.
|
||||
// See SharedBroadPhaseSystem.HandleContainerInsert()... It sets Awake to false, which causes this.
|
||||
// See SharedBroadphaseSystem.HandleContainerInsert()... It sets Awake to false, which causes this.
|
||||
projectile.SpawnTimer(TimeSpan.FromMilliseconds(25), () =>
|
||||
{
|
||||
projectile
|
||||
@@ -402,7 +402,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
private void FireHitscan(IEntity shooter, HitscanComponent hitscan, Angle angle)
|
||||
{
|
||||
var ray = new CollisionRay(Owner.Transform.Coordinates.ToMapPos(Owner.EntityManager), angle.ToVec(), (int) hitscan.CollisionMask);
|
||||
var physicsManager = EntitySystem.Get<SharedBroadPhaseSystem>();
|
||||
var physicsManager = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
var rayCastResults = physicsManager.IntersectRay(Owner.Transform.MapID, ray, hitscan.MaxLength, shooter, false).ToList();
|
||||
|
||||
if (rayCastResults.Count >= 1)
|
||||
|
||||
@@ -339,6 +339,14 @@ namespace Content.Shared.CCVar
|
||||
|
||||
public static readonly CVarDef<bool> BanHardwareIds =
|
||||
CVarDef.Create("ban.hardware_ids", false, CVar.SERVERONLY);
|
||||
|
||||
/*
|
||||
* Shuttles
|
||||
*/
|
||||
// Once cruising actually gets implemented I'd likely drop this speed to 3 maybe.
|
||||
public static readonly CVarDef<float> ShuttleDockSpeedCap =
|
||||
CVarDef.Create("shuttle.dock_speed_cap", 5f, CVar.SERVERONLY);
|
||||
|
||||
/*
|
||||
* VIEWPORT
|
||||
*/
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Content.Shared.Construction.Conditions
|
||||
return false;
|
||||
|
||||
// now we need to check that user actually tries to build wallmount on a wall
|
||||
var physics = EntitySystem.Get<SharedBroadPhaseSystem>();
|
||||
var physics = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
var rUserToObj = new CollisionRay(userWorldPosition, userToObject.Normalized, (int) CollisionGroup.Impassable);
|
||||
var length = userToObject.Length;
|
||||
var userToObjRaycastResults = physics.IntersectRayWithPredicate(user.Transform.MapID, rUserToObj, maxLength: length,
|
||||
|
||||
@@ -72,6 +72,9 @@ namespace Content.Shared.Examine
|
||||
|
||||
public static bool InRangeUnOccluded(MapCoordinates origin, MapCoordinates other, float range, Ignored? predicate, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
if (origin.MapId == MapId.Nullspace ||
|
||||
other.MapId == MapId.Nullspace) return false;
|
||||
|
||||
var occluderSystem = Get<OccluderSystem>();
|
||||
if (!origin.InRange(other, range)) return false;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Controllers;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Content.Shared.Friction
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
|
||||
private SharedBroadPhaseSystem _broadPhaseSystem = default!;
|
||||
private SharedBroadphaseSystem _broadPhaseSystem = default!;
|
||||
|
||||
private float _stopSpeed;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Content.Shared.Friction
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_broadPhaseSystem = EntitySystem.Get<SharedBroadPhaseSystem>();
|
||||
_broadPhaseSystem = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
|
||||
_frictionModifier = _configManager.GetCVar(CCVars.TileFrictionModifier);
|
||||
_configManager.OnValueChanged(CCVars.TileFrictionModifier, value => _frictionModifier = value);
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Content.Shared.Interaction
|
||||
|
||||
predicate ??= _ => false;
|
||||
var ray = new CollisionRay(origin.Position, dir.Normalized, collisionMask);
|
||||
var rayResults = Get<SharedBroadPhaseSystem>().IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();
|
||||
var rayResults = Get<SharedBroadphaseSystem>().IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();
|
||||
|
||||
if (rayResults.Count == 0) return dir.Length;
|
||||
return (rayResults[0].HitPos - origin.Position).Length;
|
||||
@@ -122,7 +122,7 @@ namespace Content.Shared.Interaction
|
||||
predicate ??= _ => false;
|
||||
|
||||
var ray = new CollisionRay(origin.Position, dir.Normalized, (int) collisionMask);
|
||||
var rayResults = Get<SharedBroadPhaseSystem>().IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();
|
||||
var rayResults = Get<SharedBroadphaseSystem>().IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();
|
||||
|
||||
if (rayResults.Count == 0) return true;
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace Content.Shared.Maps
|
||||
/// </summary>
|
||||
public static bool IsBlockedTurf(this TileRef turf, bool filterMobs)
|
||||
{
|
||||
var physics = EntitySystem.Get<SharedBroadPhaseSystem>();
|
||||
var physics = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
|
||||
var worldBox = GetWorldTileBox(turf);
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ namespace Content.Shared.Movement
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
private SharedBroadPhaseSystem _broadPhaseSystem = default!;
|
||||
private SharedBroadphaseSystem _broadPhaseSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_broadPhaseSystem = EntitySystem.Get<SharedBroadPhaseSystem>();
|
||||
_broadPhaseSystem = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,7 +100,7 @@ namespace Content.Shared.Movement
|
||||
physicsComponent.LinearVelocity = total;
|
||||
}
|
||||
|
||||
public static bool UseMobMovement(SharedBroadPhaseSystem broadPhaseSystem, PhysicsComponent body, IMapManager mapManager)
|
||||
public static bool UseMobMovement(SharedBroadphaseSystem broadPhaseSystem, PhysicsComponent body, IMapManager mapManager)
|
||||
{
|
||||
return (body.BodyStatus == BodyStatus.OnGround) &
|
||||
body.Owner.HasComponent<IMobStateComponent>() &&
|
||||
@@ -118,7 +118,7 @@ namespace Content.Shared.Movement
|
||||
/// <param name="mover"></param>
|
||||
/// <param name="collider"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsAroundCollider(SharedBroadPhaseSystem broadPhaseSystem, ITransformComponent transform, IMobMoverComponent mover, IPhysBody collider)
|
||||
public static bool IsAroundCollider(SharedBroadphaseSystem broadPhaseSystem, ITransformComponent transform, IMobMoverComponent mover, IPhysBody collider)
|
||||
{
|
||||
var enlargedAABB = collider.GetWorldAABB().Enlarged(mover.GrabRange);
|
||||
|
||||
|
||||
58
Content.Shared/Shuttles/PilotComponent.cs
Normal file
58
Content.Shared/Shuttles/PilotComponent.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Shuttles
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores what shuttle this entity is currently piloting.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent()]
|
||||
public sealed class PilotComponent : Component
|
||||
{
|
||||
public override string Name => "Pilot";
|
||||
[ViewVariables] public SharedShuttleConsoleComponent? Console { get; set; }
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
if (curState is not PilotComponentState state) return;
|
||||
|
||||
if (state.Console == null)
|
||||
{
|
||||
Console = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Owner.EntityManager.TryGetEntity(state.Console.Value, out var consoleEnt) ||
|
||||
!consoleEnt.TryGetComponent(out SharedShuttleConsoleComponent? shuttleConsoleComponent))
|
||||
{
|
||||
Logger.Warning($"Unable to set Helmsman console to {state.Console.Value}");
|
||||
return;
|
||||
}
|
||||
|
||||
Console = shuttleConsoleComponent;
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new PilotComponentState(Console?.Owner.Uid);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class PilotComponentState : ComponentState
|
||||
{
|
||||
public EntityUid? Console { get; }
|
||||
|
||||
public PilotComponentState(EntityUid? uid)
|
||||
{
|
||||
Console = uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Content.Shared/Shuttles/SharedShuttleComponent.cs
Normal file
28
Content.Shared/Shuttles/SharedShuttleComponent.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Shuttles
|
||||
{
|
||||
public abstract class SharedShuttleComponent : Component
|
||||
{
|
||||
public override string Name => "Shuttle";
|
||||
|
||||
[ViewVariables]
|
||||
public virtual bool Enabled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// How much our linear impulse is multiplied by.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float SpeedMultipler { get; set; } = 200.0f;
|
||||
|
||||
[ViewVariables]
|
||||
public ShuttleMode Mode { get; set; } = ShuttleMode.Docking;
|
||||
}
|
||||
|
||||
public enum ShuttleMode : byte
|
||||
{
|
||||
Docking,
|
||||
Cruise,
|
||||
}
|
||||
}
|
||||
14
Content.Shared/Shuttles/SharedShuttleConsoleComponent.cs
Normal file
14
Content.Shared/Shuttles/SharedShuttleConsoleComponent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Shuttles
|
||||
{
|
||||
/// <summary>
|
||||
/// Interact with to start piloting a shuttle.
|
||||
/// </summary>
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedShuttleConsoleComponent : Component
|
||||
{
|
||||
public override string Name => "ShuttleConsole";
|
||||
}
|
||||
}
|
||||
20
Content.Shared/Shuttles/SharedShuttleConsoleSystem.cs
Normal file
20
Content.Shared/Shuttles/SharedShuttleConsoleSystem.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Content.Shared.Movement;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Shuttles
|
||||
{
|
||||
public abstract class SharedShuttleConsoleSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<PilotComponent, MovementAttemptEvent>(HandleMovementBlock);
|
||||
}
|
||||
|
||||
private void HandleMovementBlock(EntityUid uid, PilotComponent component, MovementAttemptEvent args)
|
||||
{
|
||||
if (component.Console == null) return;
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using Content.Shared.Physics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
|
||||
namespace Content.Shared.Spawning
|
||||
@@ -15,9 +16,9 @@ namespace Content.Shared.Spawning
|
||||
EntityCoordinates coordinates,
|
||||
CollisionGroup collisionLayer,
|
||||
in Box2? box = null,
|
||||
SharedBroadPhaseSystem? physicsManager = null)
|
||||
SharedBroadphaseSystem? physicsManager = null)
|
||||
{
|
||||
physicsManager ??= EntitySystem.Get<SharedBroadPhaseSystem>();
|
||||
physicsManager ??= EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
var mapCoordinates = coordinates.ToMap(entityManager);
|
||||
|
||||
return entityManager.SpawnIfUnobstructed(prototypeName, mapCoordinates, collisionLayer, box, physicsManager);
|
||||
@@ -29,10 +30,10 @@ namespace Content.Shared.Spawning
|
||||
MapCoordinates coordinates,
|
||||
CollisionGroup collisionLayer,
|
||||
in Box2? box = null,
|
||||
SharedBroadPhaseSystem? collision = null)
|
||||
SharedBroadphaseSystem? collision = null)
|
||||
{
|
||||
var boxOrDefault = box.GetValueOrDefault(Box2.UnitCentered);
|
||||
collision ??= EntitySystem.Get<SharedBroadPhaseSystem>();
|
||||
collision ??= EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
|
||||
foreach (var body in collision.GetCollidingEntities(coordinates.MapId, in boxOrDefault))
|
||||
{
|
||||
@@ -60,7 +61,7 @@ namespace Content.Shared.Spawning
|
||||
CollisionGroup collisionLayer,
|
||||
[NotNullWhen(true)] out IEntity? entity,
|
||||
Box2? box = null,
|
||||
SharedBroadPhaseSystem? physicsManager = null)
|
||||
SharedBroadphaseSystem? physicsManager = null)
|
||||
{
|
||||
entity = entityManager.SpawnIfUnobstructed(prototypeName, coordinates, collisionLayer, box, physicsManager);
|
||||
|
||||
@@ -74,7 +75,7 @@ namespace Content.Shared.Spawning
|
||||
CollisionGroup collisionLayer,
|
||||
[NotNullWhen(true)] out IEntity? entity,
|
||||
in Box2? box = null,
|
||||
SharedBroadPhaseSystem? physicsManager = null)
|
||||
SharedBroadphaseSystem? physicsManager = null)
|
||||
{
|
||||
entity = entityManager.SpawnIfUnobstructed(prototypeName, coordinates, collisionLayer, box, physicsManager);
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@ namespace Content.Shared.Throwing
|
||||
Logger.Error($"Tried to remove throwing fixture for {component.Owner} but none found?");
|
||||
return;
|
||||
}
|
||||
physicsComponent.RemoveFixture(fixture);
|
||||
|
||||
Get<SharedBroadphaseSystem>().DestroyFixture(physicsComponent, fixture);
|
||||
}
|
||||
|
||||
private void ThrowItem(EntityUid uid, ThrownItemComponent component, ThrownEvent args)
|
||||
@@ -54,8 +55,7 @@ namespace Content.Shared.Throwing
|
||||
}
|
||||
|
||||
var shape = physicsComponent.Fixtures[0].Shape;
|
||||
var fixture = new Fixture(physicsComponent, shape) {CollisionLayer = (int) CollisionGroup.ThrownItem, Hard = false, ID = ThrowingFixture};
|
||||
physicsComponent.AddFixture(fixture);
|
||||
Get<SharedBroadphaseSystem>().CreateFixture(physicsComponent, new Fixture(physicsComponent, shape) {CollisionLayer = (int) CollisionGroup.ThrownItem, Hard = false, ID = ThrowingFixture});
|
||||
}
|
||||
|
||||
private void HandleCollision(EntityUid uid, ThrownItemComponent component, StartCollideEvent args)
|
||||
|
||||
2
Resources/Locale/en-US/shuttles/console.ftl
Normal file
2
Resources/Locale/en-US/shuttles/console.ftl
Normal file
@@ -0,0 +1,2 @@
|
||||
shuttle-pilot-start = Piloting ship
|
||||
shuttle-pilot-end = Stopped piloting
|
||||
File diff suppressed because it is too large
Load Diff
@@ -136,7 +136,7 @@
|
||||
alertType: PilotingShuttle
|
||||
category: Piloting
|
||||
onClick: !type:StopPiloting { }
|
||||
icon: /Textures/Interface/Alerts/Buckle/buckled.png
|
||||
icon: /Textures/Interface/Alerts/piloting.png
|
||||
name: Piloting Shuttle
|
||||
description: You are piloting a shuttle. Click the alert to stop.
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
components:
|
||||
- type: Tag
|
||||
tags:
|
||||
- CanPilot
|
||||
- FootstepSound
|
||||
- type: Reactive
|
||||
reactions:
|
||||
@@ -253,6 +254,7 @@
|
||||
- type: Sprite
|
||||
netsync: false
|
||||
drawdepth: Mobs
|
||||
noRot: true
|
||||
# TODO BODY Turn these into individual body parts?
|
||||
layers:
|
||||
- map: ["enum.HumanoidVisualLayers.Chest"]
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
- type: entity
|
||||
id: PilotSeatChair
|
||||
parent: BaseStructure
|
||||
name: pilot seat
|
||||
description: The pilot seat of a prestigious battle cruiser.
|
||||
components:
|
||||
- type: Sprite
|
||||
sprite: Structures/Furniture/furniture.rsi
|
||||
state: shuttle_chair
|
||||
- type: Physics
|
||||
bodyType: Static
|
||||
fixtures:
|
||||
- shape:
|
||||
!type:PhysShapeAabb
|
||||
bounds: "-0.5,-0.25,0.5,0.25"
|
||||
mask:
|
||||
- Impassable
|
||||
- VaultImpassable
|
||||
- SmallImpassable
|
||||
- type: InteractionOutline
|
||||
- type: Damageable
|
||||
resistances: metallicResistances
|
||||
- type: Destructible
|
||||
thresholds:
|
||||
- trigger:
|
||||
!type:DamageTrigger
|
||||
damage: 100
|
||||
behaviors:
|
||||
- !type:DoActsBehavior
|
||||
acts: ["Destruction"]
|
||||
- type: ShuttleController
|
||||
- type: Strap
|
||||
position: Stand
|
||||
@@ -199,3 +199,26 @@
|
||||
MaterialWoodPlank:
|
||||
min: 1
|
||||
max: 1
|
||||
|
||||
- type: entity
|
||||
name: pilot seat
|
||||
id: ChairPilotSeat
|
||||
parent: SeatBase
|
||||
description: The pilot seat of a prestigious ship.
|
||||
components:
|
||||
- type: Anchorable
|
||||
- type: Rotatable
|
||||
- type: Sprite
|
||||
sprite: Structures/Furniture/furniture.rsi
|
||||
state: shuttle_chair
|
||||
netsync: false
|
||||
- type: Physics
|
||||
bodyType: Static
|
||||
fixtures:
|
||||
- shape:
|
||||
!type:PhysShapeAabb
|
||||
bounds: "-0.45, -0.45, 0.05, 0.45"
|
||||
mask:
|
||||
- Impassable
|
||||
- VaultImpassable
|
||||
- SmallImpassable
|
||||
|
||||
@@ -12,6 +12,17 @@
|
||||
|
||||
- type: entity
|
||||
parent: ComputerBase
|
||||
id: ComputerShuttleBase
|
||||
name: shuttle console
|
||||
description: Used to pilot a shuttle.
|
||||
abstract: true
|
||||
components:
|
||||
- type: ShuttleConsole
|
||||
- type: ApcPowerReceiver
|
||||
powerLoad: 200
|
||||
|
||||
- type: entity
|
||||
parent: ComputerShuttleBase
|
||||
id: ComputerShuttle
|
||||
name: shuttle console
|
||||
description: Used to pilot a shuttle.
|
||||
@@ -23,7 +34,7 @@
|
||||
screen: shuttle
|
||||
|
||||
- type: entity
|
||||
parent: ComputerBase
|
||||
parent: ComputerShuttleBase
|
||||
id: ComputerShuttleSyndie
|
||||
name: syndicate shuttle console
|
||||
description: Used to pilot a syndicate shuttle.
|
||||
@@ -79,7 +90,7 @@
|
||||
- key: enum.ResearchClientUiKey.Key
|
||||
type: ResearchClientBoundUserInterface
|
||||
- type: ApcPowerReceiver
|
||||
load: 200
|
||||
powerLoad: 200
|
||||
priority: Low
|
||||
- type: Computer
|
||||
board: ResearchComputerCircuitboard
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
- type: Sprite
|
||||
netsync: false
|
||||
sprite: Structures/Storage/closet.rsi
|
||||
noRot: true
|
||||
layers:
|
||||
- state: generic
|
||||
- state: generic_door
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
- type: Tag
|
||||
id: BotanySharp
|
||||
|
||||
- type: Tag
|
||||
id: CanPilot
|
||||
|
||||
- type: Tag
|
||||
id: ConveyorAssembly
|
||||
|
||||
|
||||
BIN
Resources/Textures/Interface/Alerts/piloting.png
Normal file
BIN
Resources/Textures/Interface/Alerts/piloting.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 255 B |
Reference in New Issue
Block a user