Cargo shuttle changes (#14363)

This commit is contained in:
metalgearsloth
2023-03-23 16:10:49 +11:00
committed by GitHub
parent 7f4bb7fe8a
commit 569f30b721
26 changed files with 523 additions and 628 deletions

View File

@@ -144,12 +144,13 @@ namespace Content.Server.Shuttles.Systems
private void Cleanup(DockingComponent dockA)
{
_pathfinding.RemovePortal(dockA.PathfindHandle);
_jointSystem.RemoveJoint(dockA.DockJoint!);
if (dockA.DockJoint != null)
_jointSystem.RemoveJoint(dockA.DockJoint);
var dockBUid = dockA.DockedWith;
if (dockBUid == null ||
dockA.DockJoint == null ||
!TryComp(dockBUid, out DockingComponent? dockB))
{
DebugTools.Assert(false);
@@ -187,9 +188,9 @@ namespace Content.Server.Shuttles.Systems
GridBUid = gridBUid!.Value,
};
EntityManager.EventBus.RaiseLocalEvent(dockA.Owner, msg, false);
EntityManager.EventBus.RaiseLocalEvent(dockB.Owner, msg, false);
EntityManager.EventBus.RaiseEvent(EventSource.Local, msg);
RaiseLocalEvent(dockA.Owner, msg);
RaiseLocalEvent(dockB.Owner, msg);
RaiseLocalEvent(msg);
}
private void OnStartup(EntityUid uid, DockingComponent component, ComponentStartup args)
@@ -208,7 +209,7 @@ namespace Content.Server.Shuttles.Systems
var otherDock = EntityManager.GetComponent<DockingComponent>(component.DockedWith.Value);
DebugTools.Assert(otherDock.DockedWith != null);
Dock(component, otherDock);
Dock(uid, component, component.DockedWith.Value, otherDock);
DebugTools.Assert(component.Docked && otherDock.Docked);
}
}
@@ -234,7 +235,7 @@ namespace Content.Server.Shuttles.Systems
var other = Comp<DockingComponent>(component.DockedWith!.Value);
Undock(component);
Dock(component, other);
Dock(uid, component, component.DockedWith.Value, other);
_console.RefreshShuttleConsoles();
}
@@ -278,91 +279,96 @@ namespace Content.Server.Shuttles.Systems
/// <summary>
/// Docks 2 ports together and assumes it is valid.
/// </summary>
public void Dock(DockingComponent dockA, DockingComponent dockB)
public void Dock(EntityUid dockAUid, DockingComponent dockA, EntityUid dockBUid, DockingComponent dockB)
{
if (dockB.Owner.GetHashCode() < dockA.Owner.GetHashCode())
if (dockBUid.GetHashCode() < dockAUid.GetHashCode())
{
(dockA, dockB) = (dockB, dockA);
}
_sawmill.Debug($"Docking between {dockA.Owner} and {dockB.Owner}");
_sawmill.Debug($"Docking between {dockAUid} and {dockBUid}");
// https://gamedev.stackexchange.com/questions/98772/b2distancejoint-with-frequency-equal-to-0-vs-b2weldjoint
// We could also potentially use a prismatic joint? Depending if we want clamps that can extend or whatever
var dockAXform = EntityManager.GetComponent<TransformComponent>(dockA.Owner);
var dockBXform = EntityManager.GetComponent<TransformComponent>(dockB.Owner);
var dockAXform = EntityManager.GetComponent<TransformComponent>(dockAUid);
var dockBXform = EntityManager.GetComponent<TransformComponent>(dockBUid);
DebugTools.Assert(dockAXform.GridUid != null);
DebugTools.Assert(dockBXform.GridUid != null);
var gridA = dockAXform.GridUid!.Value;
var gridB = dockBXform.GridUid!.Value;
SharedJointSystem.LinearStiffness(
2f,
0.7f,
EntityManager.GetComponent<PhysicsComponent>(gridA).Mass,
EntityManager.GetComponent<PhysicsComponent>(gridB).Mass,
out var stiffness,
out var damping);
// These need playing around with
// Could also potentially have collideconnected false and stiffness 0 but it was a bit more suss???
WeldJoint joint;
// Pre-existing joint so use that.
if (dockA.DockJointId != null)
// May not be possible if map or the likes.
if (TryComp<PhysicsComponent>(gridA, out var gridPhysicsA) &&
TryComp<PhysicsComponent>(gridB, out var gridPhysicsB))
{
DebugTools.Assert(dockB.DockJointId == dockA.DockJointId);
joint = _jointSystem.GetOrCreateWeldJoint(gridA, gridB, dockA.DockJointId);
}
else
{
joint = _jointSystem.GetOrCreateWeldJoint(gridA, gridB, DockingJoint + dockA.Owner);
SharedJointSystem.LinearStiffness(
2f,
0.7f,
EntityManager.GetComponent<PhysicsComponent>(gridA).Mass,
EntityManager.GetComponent<PhysicsComponent>(gridB).Mass,
out var stiffness,
out var damping);
// These need playing around with
// Could also potentially have collideconnected false and stiffness 0 but it was a bit more suss???
WeldJoint joint;
// Pre-existing joint so use that.
if (dockA.DockJointId != null)
{
DebugTools.Assert(dockB.DockJointId == dockA.DockJointId);
joint = _jointSystem.GetOrCreateWeldJoint(gridA, gridB, dockA.DockJointId);
}
else
{
joint = _jointSystem.GetOrCreateWeldJoint(gridA, gridB, DockingJoint + dockAUid);
}
var gridAXform = EntityManager.GetComponent<TransformComponent>(gridA);
var gridBXform = EntityManager.GetComponent<TransformComponent>(gridB);
var anchorA = dockAXform.LocalPosition + dockAXform.LocalRotation.ToWorldVec() / 2f;
var anchorB = dockBXform.LocalPosition + dockBXform.LocalRotation.ToWorldVec() / 2f;
joint.LocalAnchorA = anchorA;
joint.LocalAnchorB = anchorB;
joint.ReferenceAngle = (float) (gridBXform.WorldRotation - gridAXform.WorldRotation);
joint.CollideConnected = true;
joint.Stiffness = stiffness;
joint.Damping = damping;
dockA.DockJoint = joint;
dockA.DockJointId = joint.ID;
dockB.DockJoint = joint;
dockB.DockJointId = joint.ID;
}
var gridAXform = EntityManager.GetComponent<TransformComponent>(gridA);
var gridBXform = EntityManager.GetComponent<TransformComponent>(gridB);
dockA.DockedWith = dockBUid;
dockB.DockedWith = dockAUid;
var anchorA = dockAXform.LocalPosition + dockAXform.LocalRotation.ToWorldVec() / 2f;
var anchorB = dockBXform.LocalPosition + dockBXform.LocalRotation.ToWorldVec() / 2f;
joint.LocalAnchorA = anchorA;
joint.LocalAnchorB = anchorB;
joint.ReferenceAngle = (float) (gridBXform.WorldRotation - gridAXform.WorldRotation);
joint.CollideConnected = true;
joint.Stiffness = stiffness;
joint.Damping = damping;
dockA.DockedWith = dockB.Owner;
dockB.DockedWith = dockA.Owner;
dockA.DockJoint = joint;
dockA.DockJointId = joint.ID;
dockB.DockJoint = joint;
dockB.DockJointId = joint.ID;
if (TryComp(dockA.Owner, out DoorComponent? doorA))
if (TryComp(dockAUid, out DoorComponent? doorA))
{
if (_doorSystem.TryOpen(doorA.Owner, doorA))
{
doorA.ChangeAirtight = false;
if (TryComp<AirlockComponent>(dockA.Owner, out var airlockA))
if (TryComp<AirlockComponent>(dockAUid, out var airlockA))
{
_airlocks.SetBoltsWithAudio(dockA.Owner, airlockA, true);
_airlocks.SetBoltsWithAudio(dockAUid, airlockA, true);
}
}
}
if (TryComp(dockB.Owner, out DoorComponent? doorB))
if (TryComp(dockBUid, out DoorComponent? doorB))
{
if (_doorSystem.TryOpen(doorB.Owner, doorB))
{
doorB.ChangeAirtight = false;
if (TryComp<AirlockComponent>(dockB.Owner, out var airlockB))
if (TryComp<AirlockComponent>(dockBUid, out var airlockB))
{
_airlocks.SetBoltsWithAudio(dockB.Owner, airlockB, true);
_airlocks.SetBoltsWithAudio(dockBUid, airlockB, true);
}
}
}
@@ -381,9 +387,9 @@ namespace Content.Server.Shuttles.Systems
GridBUid = gridB,
};
EntityManager.EventBus.RaiseLocalEvent(dockA.Owner, msg, false);
EntityManager.EventBus.RaiseLocalEvent(dockB.Owner, msg, false);
EntityManager.EventBus.RaiseEvent(EventSource.Local, msg);
RaiseLocalEvent(dockAUid, msg);
RaiseLocalEvent(dockBUid, msg);
RaiseLocalEvent(msg);
}
private bool CanDock(DockingComponent dockA, DockingComponent dockB)
@@ -433,11 +439,11 @@ namespace Content.Server.Shuttles.Systems
/// <summary>
/// Attempts to dock 2 ports together and will return early if it's not possible.
/// </summary>
private void TryDock(DockingComponent dockA, DockingComponent dockB)
private void TryDock(EntityUid dockAUid, DockingComponent dockA, EntityUid dockBUid, DockingComponent dockB)
{
if (!CanDock(dockA, dockB)) return;
Dock(dockA, dockB);
Dock(dockAUid, dockA, dockBUid, dockB);
}
public void Undock(DockingComponent dock)