diff --git a/Content.Server/Solar/Components/SolarPanelComponent.cs b/Content.Server/Solar/Components/SolarPanelComponent.cs
index c2f631fbca..b1576a46d9 100644
--- a/Content.Server/Solar/Components/SolarPanelComponent.cs
+++ b/Content.Server/Solar/Components/SolarPanelComponent.cs
@@ -1,8 +1,8 @@
using System;
using Content.Server.Power.Components;
using Content.Server.Solar.EntitySystems;
-using Content.Shared.Acts;
using Robust.Server.GameObjects;
+using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Timing;
@@ -16,67 +16,24 @@ namespace Content.Server.Solar.Components
/// It generates power from the sun based on coverage.
///
[RegisterComponent]
- public class SolarPanelComponent : Component, IBreakAct
+ [Friend(typeof(PowerSolarSystem))]
+ public class SolarPanelComponent : Component
{
public override string Name => "SolarPanel";
///
/// Maximum supply output by this panel (coverage = 1)
///
- [DataField("maxsupply")]
- private int _maxSupply = 1500;
- [ViewVariables(VVAccess.ReadWrite)]
- public int MaxSupply
- {
- get => _maxSupply;
- set {
- _maxSupply = value;
- UpdateSupply();
- }
- }
+ [DataField("maxSupply")]
+ [ViewVariables]
+ public int MaxSupply = 1500;
///
/// Current coverage of this panel (from 0 to 1).
/// This is updated by .
- ///
- 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();
- }
- }
- }
-
- ///
- /// The game time () 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.
+ /// DO NOT WRITE WITHOUT CALLING UpdateSupply()!
///
[ViewVariables]
- public TimeSpan TimeOfNextCoverageUpdate = TimeSpan.MinValue;
-
- private void UpdateSupply()
- {
- if (Owner.TryGetComponent(out var supplier))
- {
- supplier.MaxSupply = (int) (_maxSupply * _coverage);
- }
- }
-
- public void OnBreak(BreakageEventArgs args)
- {
- if (!Owner.TryGetComponent(out var sprite))
- return;
-
- sprite.LayerSetState(0, "broken");
- MaxSupply = 0;
- }
+ public float Coverage { get; set; } = 0;
}
}
diff --git a/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs b/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs
index 366cab3885..bef808674a 100644
--- a/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs
+++ b/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs
@@ -154,7 +154,6 @@ namespace Content.Server.Solar.EntitySystems
if (coverage > 0)
{
// 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 = _physicsSystem.IntersectRayWithPredicate(
entity.Transform.MapID,
@@ -167,9 +166,10 @@ namespace Content.Server.Solar.EntitySystems
// Total coverage calculated; apply it to the panel.
panel.Coverage = coverage;
+ UpdateSupply(panel.OwnerUid, panel);
}
- private void UpdateSupply(
+ public void UpdateSupply(
EntityUid uid,
SolarPanelComponent? solar = null,
PowerSupplierComponent? supplier = null)
diff --git a/Resources/Prototypes/Entities/Structures/Power/Generation/solar.yml b/Resources/Prototypes/Entities/Structures/Power/Generation/solar.yml
index e37246add0..a676deeb7e 100644
--- a/Resources/Prototypes/Entities/Structures/Power/Generation/solar.yml
+++ b/Resources/Prototypes/Entities/Structures/Power/Generation/solar.yml
@@ -1,11 +1,14 @@
- type: entity
- id: SolarPanel
+ id: SolarPanelBasePhysSprite
+ abstract: true
name: solar panel
placement:
mode: SnapgridCenter
components:
- type: Clickable
- type: InteractionOutline
+ - type: Transform
+ anchored: true
- type: Physics
bodyType: Static
fixtures:
@@ -32,13 +35,18 @@
output:
!type:CableDeviceNode
nodeGroupID: HVPower
+ - type: Anchorable
+ - type: Pullable
+
+- type: entity
+ id: SolarPanel
+ parent: SolarPanelBasePhysSprite
+ name: solar panel
+ components:
- type: PowerSupplier
supplyRampTolerance: 500
supplyRampRate: 500
- type: SolarPanel
- supply: 1500
- - type: Transform
- anchored: true
- type: Damageable
damageContainer: Inorganic
damageModifierSet: Metallic
@@ -48,14 +56,48 @@
!type:DamageTrigger
damage: 100
behaviors:
+ - !type:PlaySoundBehavior
+ sound:
+ collection: GlassBreak
+ - !type:ChangeConstructionNodeBehavior
+ node: solarpanel_broken
- !type:DoActsBehavior
acts: ["Breakage"]
- - type: Anchorable
- - type: Pullable
- type: Construction
graph: 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
id: SolarAssembly
name: solar assembly
@@ -69,7 +111,8 @@
bodyType: Static
fixtures:
- shape:
- !type:PhysShapeAabb {}
+ !type:PhysShapeCircle
+ radius: 0.25
mass: 75
mask:
- VaultImpassable
diff --git a/Resources/Prototypes/Recipes/Construction/Graphs/solarpanel.yml b/Resources/Prototypes/Recipes/Construction/Graphs/solarpanel.yml
index f33bd8444c..2412ca127e 100644
--- a/Resources/Prototypes/Recipes/Construction/Graphs/solarpanel.yml
+++ b/Resources/Prototypes/Recipes/Construction/Graphs/solarpanel.yml
@@ -59,6 +59,8 @@
edges:
- to: solarassembly
completed:
+ - !type:SnapToGrid
+ southRotation: true
- !type:SpawnPrototype
prototype: SheetGlass1
amount: 2
@@ -68,12 +70,31 @@
steps:
- tool: Prying
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
entity: SolarTracker
edges:
- to: solarassembly
completed:
+ - !type:SnapToGrid
+ southRotation: true
- !type:SpawnPrototype
prototype: SheetGlass1
amount: 2