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:
metalgearsloth
2021-07-21 21:15:12 +10:00
committed by GitHub
parent 55087a6f16
commit 500b9cb1ea
44 changed files with 1042 additions and 1601 deletions

View File

@@ -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;
}

View File

@@ -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);
}
}
}

View File

@@ -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()))

View File

@@ -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)

View File

@@ -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,13 +278,13 @@ 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,
Hard = true,
Mass = 5.0f,
});
CollisionLayer = (int) CollisionGroup.Impassable,
CollisionMask = (int) CollisionGroup.Impassable,
Hard = true,
Mass = 5.0f,
});
y += deltaY;
}

View File

@@ -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;
}
}
}
}

View File

@@ -0,0 +1,11 @@
using Content.Shared.Shuttles;
using Robust.Shared.GameObjects;
namespace Content.Server.Shuttles
{
[RegisterComponent]
public class ShuttleComponent : SharedShuttleComponent
{
}
}

View 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;
}
}

View 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);
}
}
}
}

View 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;
}
}
}
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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)