Skip to content

Commit

Permalink
Ftl mass calculate (#12)
Browse files Browse the repository at this point in the history
* dynamic-ftlmass-calculate

* big-thrusters

* large-thruster-fix
  • Loading branch information
Fragoler authored Apr 6, 2024
1 parent e29b1bf commit 2ad321d
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Content.Server/Shuttles/Systems/ShuttleConsoleSystem.FTL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ private void ConsoleFTL(Entity<ShuttleConsoleComponent> ent, EntityCoordinates t
if (!_shuttle.CanFTL(shuttleUid.Value, out var reason))
{
// TODO: Session popup
// Exodus-DynamicFTLMass-start
_popup.PopupEntity(reason, ent.Owner, Shared.Popups.PopupType.Medium);
// Exodus-DynamicFTLMass-end
return;
}

Expand Down
15 changes: 13 additions & 2 deletions Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed partial class ShuttleSystem
public const float DefaultTravelTime = 20f;
public const float DefaultArrivalTime = 5f;
private const float FTLCooldown = 10f;
public const float FTLMassLimit = 300f;
public const float FTLMassParametr = 0.5f; // Exodus-DynamicFTLMass

// I'm too lazy to make CVars.

Expand Down Expand Up @@ -210,7 +210,11 @@ public bool CanFTL(EntityUid shuttleUid, [NotNullWhen(false)] out string? reason
return false;
}

if (TryComp(shuttleUid, out PhysicsComponent? shuttlePhysics) && shuttlePhysics.Mass > FTLMassLimit)
// Exodus-DynamicFTLMass-start
if (TryComp(shuttleUid, out PhysicsComponent? shuttlePhysics) &&
TryComp<ShuttleComponent>(shuttleUid, out var shuttleComp) &&
shuttlePhysics.Mass > CalculateFTLMassLimit(shuttleUid, shuttleComp))
// Exodus-DynamicFTLMass-end
{
reason = Loc.GetString("shuttle-console-mass");
return false;
Expand All @@ -235,6 +239,13 @@ public bool CanFTL(EntityUid shuttleUid, [NotNullWhen(false)] out string? reason
return true;
}

// Exodus-DynamicFTLMass-start
public float CalculateFTLMassLimit(EntityUid shuttleUid, ShuttleComponent shuttleComp)
{
return _thruster.GetThrustValueDirection(shuttleComp, DirectionFlag.North) * FTLMassParametr;
}
// Exodus-DynamicFTLMass-end

/// <summary>
/// Moves a shuttle from its current position to the target one without any checks. Goes through the hyperspace map while the timer is running.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Content.Server/Shuttles/Systems/ThrusterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,15 @@ public void SetAngularThrust(ShuttleComponent component, bool on)

#endregion


// Exodus-DynamicFTLMass-start
public float GetThrustValueDirection(ShuttleComponent shuttleComp, DirectionFlag flag)
{
var index = GetFlagIndex(flag);
return shuttleComp.LinearThrust[index];
}
// Exodus-DynamicFTLMass-end

private int GetFlagIndex(DirectionFlag flag)
{
return (int) Math.Log2((int) flag);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ent-BigThruster = большой ракетный двигатель
.desc = { ent-Thruster.desc }
ent-LargeThruster = огромный ракетный двигатель
.desc = { ent-Thruster.desc }
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
- type: entity
id: BigThruster
parent: Thruster
name: big thruster
description: A thruster that allows a shuttle to move.
components:
- type: Thruster
thrust: 300
burnShape:
- 0.4,0.5
- -0.4,2.2
- -0.6,2.2
- -1.4,0.5
damage:
types:
Heat: 150
- type: Fixtures
fixtures:
fix1:
shape:
!type:PhysShapeAabb
bounds: "-1.45,-1.45,0.45,0.45"
density: 60
mask:
- MachineMask
layer:
- MachineLayer
- type: Sprite
sprite: Structures/Shuttles/thruster.rsi
scale: 2.0,2.0
offset: -0.5,-0.5
layers:
- state: base
map: ["enum.ThrusterVisualLayers.Base"]
- state: thrust
map: ["enum.ThrusterVisualLayers.ThrustOn"]
shader: unshaded
visible: false
- state: thrust_burn_unshaded
map: ["enum.ThrusterVisualLayers.ThrustingUnshaded"]
shader: unshaded
visible: false
offset: 0, 1

- type: entity
id: LargeThruster
parent: Thruster
name: large thruster
description: A thruster that allows a shuttle to move.
components:
- type: Thruster
thrust: 700
burnShape:
- 1.4,0.5
- -0.3,3.2
- 0.3,3.2
- -1.4,0.5
damage:
types:
Heat: 500
- type: Fixtures
fixtures:
fix1:
shape:
!type:PhysShapeAabb
bounds: "-1.45,-2.45,1.45,0.45"
density: 60
mask:
- MachineMask
layer:
- MachineLayer
- type: Sprite
sprite: Structures/Shuttles/thruster.rsi
scale: 3.0,3.0
offset: 0,-1
layers:
- state: base
map: ["enum.ThrusterVisualLayers.Base"]
- state: thrust
map: ["enum.ThrusterVisualLayers.ThrustOn"]
shader: unshaded
visible: false
- state: thrust_burn_unshaded
map: ["enum.ThrusterVisualLayers.ThrustingUnshaded"]
shader: unshaded
visible: false
offset: 0, 1

0 comments on commit 2ad321d

Please sign in to comment.