APC & SMES appearances. (#78)
* CEV-Eris SMES sprite as RSI. Has been modified so that the light overlay states use alpha blending. * Add tiny glow to SMES display sprite. * Appearances work v2 * More WiP * RoundToLevels works correctly on even level counts now. * SMES -> Smes because MS guidelines. * CEV-Eris APC sprite. * APC visuals. * Reduce SMES scale again to normal levels. * Update submodule
This commit is contained in:
committed by
GitHub
parent
7629d447aa
commit
ad5c82fec9
50
Content.Server/GameObjects/Components/Power/ApcComponent.cs
Normal file
50
Content.Server/GameObjects/Components/Power/ApcComponent.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power
|
||||
{
|
||||
public class ApcComponent : Component
|
||||
{
|
||||
public override string Name => "Apc";
|
||||
|
||||
PowerStorageComponent Storage;
|
||||
AppearanceComponent Appearance;
|
||||
|
||||
ApcChargeState LastChargeState;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Storage = Owner.GetComponent<PowerStorageComponent>();
|
||||
Appearance = Owner.GetComponent<AppearanceComponent>();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var newState = CalcChargeState();
|
||||
if (newState != LastChargeState)
|
||||
{
|
||||
LastChargeState = newState;
|
||||
Appearance.SetData(ApcVisuals.ChargeState, newState);
|
||||
}
|
||||
}
|
||||
|
||||
ApcChargeState CalcChargeState()
|
||||
{
|
||||
var storageCharge = Storage.GetChargeState();
|
||||
if (storageCharge == ChargeState.Discharging)
|
||||
{
|
||||
return ApcChargeState.Lack;
|
||||
}
|
||||
|
||||
if (storageCharge == ChargeState.Charging)
|
||||
{
|
||||
return ApcChargeState.Charging;
|
||||
}
|
||||
|
||||
// Still.
|
||||
return Storage.Full ? ApcChargeState.Full : ApcChargeState.Lack;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
@@ -61,9 +62,11 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
|
||||
if (attacked.TryGetComponent<PowerStorageComponent>(out var storage))
|
||||
{
|
||||
var stateSeconds = (DateTime.Now - storage.LastChargeStateChange).TotalSeconds;
|
||||
builder.AppendFormat(@"Power Storage:
|
||||
Capacity: {0}, Charge: {1}, ChargeRate: {2}, DistributionRate: {3}, ChargePowernet: {4}
|
||||
", storage.Capacity, storage.Charge, storage.ChargeRate, storage.DistributionRate, storage.ChargePowernet);
|
||||
LastChargeState: {5} ({6}), LastChargeStateChange: {7:0.00} seconds ago.
|
||||
", storage.Capacity, storage.Charge, storage.ChargeRate, storage.DistributionRate, storage.ChargePowernet, storage.LastChargeState, storage.GetChargeState(), stateSeconds);
|
||||
}
|
||||
|
||||
if (attacked.TryGetComponent<PowerTransferComponent>(out var transfer))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using SS14.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Utility;
|
||||
@@ -14,6 +15,9 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
{
|
||||
public override string Name => "PowerStorage";
|
||||
|
||||
public ChargeState LastChargeState { get; private set; } = ChargeState.Still;
|
||||
public DateTime LastChargeStateChange { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Maximum amount of energy the internal battery can store.
|
||||
/// In Joules.
|
||||
@@ -38,6 +42,8 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
/// </summary>
|
||||
public float DistributionRate { get; private set; } = 1000;
|
||||
|
||||
public bool Full => Charge >= Capacity;
|
||||
|
||||
private bool _chargepowernet = false;
|
||||
|
||||
/// <summary>
|
||||
@@ -129,15 +135,19 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
public void DeductCharge(float todeduct)
|
||||
{
|
||||
Charge = Math.Max(0, Charge - todeduct);
|
||||
LastChargeState = ChargeState.Discharging;
|
||||
LastChargeStateChange = DateTime.Now;
|
||||
}
|
||||
|
||||
public void AddCharge(float charge)
|
||||
{
|
||||
Charge = Math.Min(Capacity, Charge + charge);
|
||||
LastChargeState = ChargeState.Charging;
|
||||
LastChargeStateChange = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the charge available from the energy storage
|
||||
/// Returns the amount of energy that can be taken in by this storage in the specified amount of time.
|
||||
/// </summary>
|
||||
public float RequestCharge(float frameTime)
|
||||
{
|
||||
@@ -145,15 +155,33 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the charge available from the energy storage
|
||||
/// Returns the amount of energy available for discharge in the specified amount of time.
|
||||
/// </summary>
|
||||
public float AvailableCharge(float frameTime)
|
||||
{
|
||||
return Math.Min(DistributionRate * frameTime, Charge);
|
||||
}
|
||||
|
||||
public ChargeState GetChargeState()
|
||||
{
|
||||
return GetChargeState(TimeSpan.FromSeconds(1));
|
||||
}
|
||||
|
||||
public ChargeState GetChargeState(TimeSpan timeout)
|
||||
{
|
||||
if (LastChargeStateChange + timeout > DateTime.Now)
|
||||
{
|
||||
return LastChargeState;
|
||||
}
|
||||
return ChargeState.Still;
|
||||
}
|
||||
|
||||
public void ChargePowerTick(float frameTime)
|
||||
{
|
||||
if (Full)
|
||||
{
|
||||
return;
|
||||
}
|
||||
AddCharge(RequestCharge(frameTime));
|
||||
}
|
||||
|
||||
|
||||
@@ -145,6 +145,10 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
break;
|
||||
}
|
||||
var demand = consumer.RequestCharge(frameTime);
|
||||
if (demand == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var taken = Math.Min(demand, totalRemaining);
|
||||
totalRemaining -= taken;
|
||||
consumer.AddCharge(taken);
|
||||
@@ -155,6 +159,10 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
foreach (var supplier in PowerStorageSupplierList)
|
||||
{
|
||||
var load = supplier.AvailableCharge(frameTime);
|
||||
if (load == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var added = Math.Min(load, supplierUsed);
|
||||
supplierUsed -= added;
|
||||
supplier.DeductCharge(added);
|
||||
|
||||
53
Content.Server/GameObjects/Components/Power/SMESComponent.cs
Normal file
53
Content.Server/GameObjects/Components/Power/SMESComponent.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Content.Shared.Utility;
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the "user-facing" side of the actual SMES object.
|
||||
/// This is operations that are specific to the SMES, like UI and visuals.
|
||||
/// Code interfacing with the powernet is handled in <see cref="PowerStorageComponent" />.
|
||||
/// </summary>
|
||||
public class SmesComponent : Component
|
||||
{
|
||||
public override string Name => "Smes";
|
||||
|
||||
PowerStorageComponent Storage;
|
||||
AppearanceComponent Appearance;
|
||||
|
||||
int LastChargeLevel = 0;
|
||||
ChargeState LastChargeState;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Storage = Owner.GetComponent<PowerStorageComponent>();
|
||||
Appearance = Owner.GetComponent<AppearanceComponent>();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var newLevel = CalcChargeLevel();
|
||||
if (newLevel != LastChargeLevel)
|
||||
{
|
||||
LastChargeLevel = newLevel;
|
||||
Appearance.SetData(SmesVisuals.LastChargeLevel, newLevel);
|
||||
}
|
||||
|
||||
var newState = Storage.GetChargeState();
|
||||
if (newState != LastChargeState)
|
||||
{
|
||||
LastChargeState = newState;
|
||||
Appearance.SetData(SmesVisuals.LastChargeState, newState);
|
||||
}
|
||||
}
|
||||
|
||||
int CalcChargeLevel()
|
||||
{
|
||||
return ContentHelpers.RoundToLevels(Storage.Charge, Storage.Capacity, 6);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user