Change over solar panel breakage to use more construction graphs (#5395)
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Server.Solar.EntitySystems;
|
using Content.Server.Solar.EntitySystems;
|
||||||
using Content.Shared.Acts;
|
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Shared.Analyzers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
@@ -16,67 +16,24 @@ namespace Content.Server.Solar.Components
|
|||||||
/// It generates power from the sun based on coverage.
|
/// It generates power from the sun based on coverage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public class SolarPanelComponent : Component, IBreakAct
|
[Friend(typeof(PowerSolarSystem))]
|
||||||
|
public class SolarPanelComponent : Component
|
||||||
{
|
{
|
||||||
public override string Name => "SolarPanel";
|
public override string Name => "SolarPanel";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Maximum supply output by this panel (coverage = 1)
|
/// Maximum supply output by this panel (coverage = 1)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("maxsupply")]
|
[DataField("maxSupply")]
|
||||||
private int _maxSupply = 1500;
|
[ViewVariables]
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
public int MaxSupply = 1500;
|
||||||
public int MaxSupply
|
|
||||||
{
|
|
||||||
get => _maxSupply;
|
|
||||||
set {
|
|
||||||
_maxSupply = value;
|
|
||||||
UpdateSupply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current coverage of this panel (from 0 to 1).
|
/// Current coverage of this panel (from 0 to 1).
|
||||||
/// This is updated by <see cref='PowerSolarSystem'/>.
|
/// This is updated by <see cref='PowerSolarSystem'/>.
|
||||||
/// </summary>
|
/// DO NOT WRITE WITHOUT CALLING UpdateSupply()!
|
||||||
private float _coverage = 0;
|
|
||||||
[ViewVariables]
|
|
||||||
public float Coverage
|
|
||||||
{
|
|
||||||
get => _coverage;
|
|
||||||
set {
|
|
||||||
// This gets updated once-per-tick, so avoid updating it if truly unnecessary
|
|
||||||
if (_coverage != value) {
|
|
||||||
_coverage = value;
|
|
||||||
UpdateSupply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The game time (<see cref='IGameTiming'/>) of the next coverage update.
|
|
||||||
/// This may have a random offset applied.
|
|
||||||
/// This is used to reduce solar panel updates and stagger them to prevent lagspikes.
|
|
||||||
/// This should only be updated by the PowerSolarSystem but is viewable for debugging.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public TimeSpan TimeOfNextCoverageUpdate = TimeSpan.MinValue;
|
public float Coverage { get; set; } = 0;
|
||||||
|
|
||||||
private void UpdateSupply()
|
|
||||||
{
|
|
||||||
if (Owner.TryGetComponent<PowerSupplierComponent>(out var supplier))
|
|
||||||
{
|
|
||||||
supplier.MaxSupply = (int) (_maxSupply * _coverage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnBreak(BreakageEventArgs args)
|
|
||||||
{
|
|
||||||
if (!Owner.TryGetComponent<SpriteComponent>(out var sprite))
|
|
||||||
return;
|
|
||||||
|
|
||||||
sprite.LayerSetState(0, "broken");
|
|
||||||
MaxSupply = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,6 @@ namespace Content.Server.Solar.EntitySystems
|
|||||||
if (coverage > 0)
|
if (coverage > 0)
|
||||||
{
|
{
|
||||||
// Determine if the solar panel is occluded, and zero out coverage if so.
|
// 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 ray = new CollisionRay(entity.Transform.WorldPosition, TowardsSun.ToWorldVec(), (int) CollisionGroup.Opaque);
|
||||||
var rayCastResults = _physicsSystem.IntersectRayWithPredicate(
|
var rayCastResults = _physicsSystem.IntersectRayWithPredicate(
|
||||||
entity.Transform.MapID,
|
entity.Transform.MapID,
|
||||||
@@ -167,9 +166,10 @@ namespace Content.Server.Solar.EntitySystems
|
|||||||
|
|
||||||
// Total coverage calculated; apply it to the panel.
|
// Total coverage calculated; apply it to the panel.
|
||||||
panel.Coverage = coverage;
|
panel.Coverage = coverage;
|
||||||
|
UpdateSupply(panel.OwnerUid, panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateSupply(
|
public void UpdateSupply(
|
||||||
EntityUid uid,
|
EntityUid uid,
|
||||||
SolarPanelComponent? solar = null,
|
SolarPanelComponent? solar = null,
|
||||||
PowerSupplierComponent? supplier = null)
|
PowerSupplierComponent? supplier = null)
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
- type: entity
|
- type: entity
|
||||||
id: SolarPanel
|
id: SolarPanelBasePhysSprite
|
||||||
|
abstract: true
|
||||||
name: solar panel
|
name: solar panel
|
||||||
placement:
|
placement:
|
||||||
mode: SnapgridCenter
|
mode: SnapgridCenter
|
||||||
components:
|
components:
|
||||||
- type: Clickable
|
- type: Clickable
|
||||||
- type: InteractionOutline
|
- type: InteractionOutline
|
||||||
|
- type: Transform
|
||||||
|
anchored: true
|
||||||
- type: Physics
|
- type: Physics
|
||||||
bodyType: Static
|
bodyType: Static
|
||||||
fixtures:
|
fixtures:
|
||||||
@@ -32,13 +35,18 @@
|
|||||||
output:
|
output:
|
||||||
!type:CableDeviceNode
|
!type:CableDeviceNode
|
||||||
nodeGroupID: HVPower
|
nodeGroupID: HVPower
|
||||||
|
- type: Anchorable
|
||||||
|
- type: Pullable
|
||||||
|
|
||||||
|
- type: entity
|
||||||
|
id: SolarPanel
|
||||||
|
parent: SolarPanelBasePhysSprite
|
||||||
|
name: solar panel
|
||||||
|
components:
|
||||||
- type: PowerSupplier
|
- type: PowerSupplier
|
||||||
supplyRampTolerance: 500
|
supplyRampTolerance: 500
|
||||||
supplyRampRate: 500
|
supplyRampRate: 500
|
||||||
- type: SolarPanel
|
- type: SolarPanel
|
||||||
supply: 1500
|
|
||||||
- type: Transform
|
|
||||||
anchored: true
|
|
||||||
- type: Damageable
|
- type: Damageable
|
||||||
damageContainer: Inorganic
|
damageContainer: Inorganic
|
||||||
damageModifierSet: Metallic
|
damageModifierSet: Metallic
|
||||||
@@ -48,14 +56,48 @@
|
|||||||
!type:DamageTrigger
|
!type:DamageTrigger
|
||||||
damage: 100
|
damage: 100
|
||||||
behaviors:
|
behaviors:
|
||||||
|
- !type:PlaySoundBehavior
|
||||||
|
sound:
|
||||||
|
collection: GlassBreak
|
||||||
|
- !type:ChangeConstructionNodeBehavior
|
||||||
|
node: solarpanel_broken
|
||||||
- !type:DoActsBehavior
|
- !type:DoActsBehavior
|
||||||
acts: ["Breakage"]
|
acts: ["Breakage"]
|
||||||
- type: Anchorable
|
|
||||||
- type: Pullable
|
|
||||||
- type: Construction
|
- type: Construction
|
||||||
graph: solarpanel
|
graph: solarpanel
|
||||||
node: solarpanel
|
node: solarpanel
|
||||||
|
|
||||||
|
- type: entity
|
||||||
|
id: SolarPanelBroken
|
||||||
|
parent: SolarPanelBasePhysSprite
|
||||||
|
name: solar panel
|
||||||
|
suffix: Broken
|
||||||
|
components:
|
||||||
|
- type: Sprite
|
||||||
|
state: broken
|
||||||
|
- type: Damageable
|
||||||
|
damageContainer: Inorganic
|
||||||
|
damageModifierSet: Metallic
|
||||||
|
- type: Destructible
|
||||||
|
thresholds:
|
||||||
|
- trigger:
|
||||||
|
!type:DamageTrigger
|
||||||
|
damage: 50
|
||||||
|
behaviors:
|
||||||
|
- !type:PlaySoundBehavior
|
||||||
|
sound:
|
||||||
|
collection: GlassBreak
|
||||||
|
- !type:SpawnEntitiesBehavior
|
||||||
|
spawn:
|
||||||
|
ShardGlass:
|
||||||
|
min: 1
|
||||||
|
max: 2
|
||||||
|
- !type:DoActsBehavior
|
||||||
|
acts: [ "Destruction" ]
|
||||||
|
- type: Construction
|
||||||
|
graph: solarpanel
|
||||||
|
node: solarpanel_broken
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: SolarAssembly
|
id: SolarAssembly
|
||||||
name: solar assembly
|
name: solar assembly
|
||||||
@@ -69,7 +111,8 @@
|
|||||||
bodyType: Static
|
bodyType: Static
|
||||||
fixtures:
|
fixtures:
|
||||||
- shape:
|
- shape:
|
||||||
!type:PhysShapeAabb {}
|
!type:PhysShapeCircle
|
||||||
|
radius: 0.25
|
||||||
mass: 75
|
mass: 75
|
||||||
mask:
|
mask:
|
||||||
- VaultImpassable
|
- VaultImpassable
|
||||||
|
|||||||
@@ -59,6 +59,8 @@
|
|||||||
edges:
|
edges:
|
||||||
- to: solarassembly
|
- to: solarassembly
|
||||||
completed:
|
completed:
|
||||||
|
- !type:SnapToGrid
|
||||||
|
southRotation: true
|
||||||
- !type:SpawnPrototype
|
- !type:SpawnPrototype
|
||||||
prototype: SheetGlass1
|
prototype: SheetGlass1
|
||||||
amount: 2
|
amount: 2
|
||||||
@@ -68,12 +70,31 @@
|
|||||||
steps:
|
steps:
|
||||||
- tool: Prying
|
- tool: Prying
|
||||||
doAfter: 0.5
|
doAfter: 0.5
|
||||||
|
|
||||||
|
- node: solarpanel_broken
|
||||||
|
entity: SolarPanelBroken
|
||||||
|
edges:
|
||||||
|
- to: solarassembly
|
||||||
|
completed:
|
||||||
|
- !type:SnapToGrid
|
||||||
|
southRotation: true
|
||||||
|
- !type:SpawnPrototype
|
||||||
|
prototype: ShardGlass
|
||||||
|
amount: 2
|
||||||
|
conditions:
|
||||||
|
- !type:EntityAnchored
|
||||||
|
anchored: true
|
||||||
|
steps:
|
||||||
|
- tool: Prying
|
||||||
|
doAfter: 0.5
|
||||||
|
|
||||||
- node: solartracker
|
- node: solartracker
|
||||||
entity: SolarTracker
|
entity: SolarTracker
|
||||||
edges:
|
edges:
|
||||||
- to: solarassembly
|
- to: solarassembly
|
||||||
completed:
|
completed:
|
||||||
|
- !type:SnapToGrid
|
||||||
|
southRotation: true
|
||||||
- !type:SpawnPrototype
|
- !type:SpawnPrototype
|
||||||
prototype: SheetGlass1
|
prototype: SheetGlass1
|
||||||
amount: 2
|
amount: 2
|
||||||
|
|||||||
Reference in New Issue
Block a user