Rip out remaining machine upgrades (#24413)
* Rip out remaining machine upgrades * eek
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Power.Components
|
||||
{
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed partial class UpgradeBatteryComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The machine part that affects the power capacity.
|
||||
/// </summary>
|
||||
[DataField("machinePartPowerCapacity", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
|
||||
public string MachinePartPowerCapacity = "PowerCell";
|
||||
|
||||
/// <summary>
|
||||
/// The machine part rating is raised to this power when calculating power gain
|
||||
/// </summary>
|
||||
[DataField("maxChargeMultiplier")]
|
||||
public float MaxChargeMultiplier = 2f;
|
||||
|
||||
/// <summary>
|
||||
/// Power gain scaling
|
||||
/// </summary>
|
||||
[DataField("baseMaxCharge")]
|
||||
public float BaseMaxCharge = 8000000;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Power.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is used for machines whose power draw
|
||||
/// can be decreased through machine part upgrades.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class UpgradePowerDrawComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The base power draw of the machine.
|
||||
/// Prioritizes hv/mv draw over lv draw.
|
||||
/// Value is initializezd on map init from <see cref="ApcPowerReceiverComponent"/>
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float BaseLoad;
|
||||
|
||||
/// <summary>
|
||||
/// The machine part that affects the power draw.
|
||||
/// </summary>
|
||||
[DataField("machinePartPowerDraw", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>)), ViewVariables(VVAccess.ReadWrite)]
|
||||
public string MachinePartPowerDraw = "Capacitor";
|
||||
|
||||
/// <summary>
|
||||
/// The multiplier used for scaling the power draw.
|
||||
/// </summary>
|
||||
[DataField("powerDrawMultiplier", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float PowerDrawMultiplier = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// What type of scaling is being used?
|
||||
/// </summary>
|
||||
[DataField("scaling", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public MachineUpgradeScalingType Scaling;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Power.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed partial class UpgradePowerSupplierComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float BaseSupplyRate;
|
||||
|
||||
/// <summary>
|
||||
/// The machine part that affects the power supplu.
|
||||
/// </summary>
|
||||
[DataField("machinePartPowerSupply", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>)), ViewVariables(VVAccess.ReadWrite)]
|
||||
public string MachinePartPowerSupply = "Capacitor";
|
||||
|
||||
/// <summary>
|
||||
/// The multiplier used for scaling the power supply.
|
||||
/// </summary>
|
||||
[DataField("powerSupplyMultiplier", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float PowerSupplyMultiplier = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// What type of scaling is being used?
|
||||
/// </summary>
|
||||
[DataField("scaling", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public MachineUpgradeScalingType Scaling;
|
||||
|
||||
/// <summary>
|
||||
/// The current value that the power supply is being scaled by,
|
||||
/// </summary>
|
||||
[DataField("actualScalar"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float ActualScalar = 1f;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Power.Components
|
||||
{
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed partial class UpgradePowerSupplyRampingComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float BaseRampRate;
|
||||
|
||||
/// <summary>
|
||||
/// The machine part that affects the power supply ramping
|
||||
/// </summary>
|
||||
[DataField("machinePartPowerCapacity", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
|
||||
public string MachinePartRampRate = "Capacitor";
|
||||
|
||||
/// <summary>
|
||||
/// The multiplier used for scaling the power supply ramping
|
||||
/// </summary>
|
||||
[DataField("supplyRampingMultiplier")]
|
||||
public float SupplyRampingMultiplier = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// What type of scaling is being used?
|
||||
/// </summary>
|
||||
[DataField("scaling", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public MachineUpgradeScalingType Scaling;
|
||||
|
||||
/// <summary>
|
||||
/// The current value that the power supply is being scaled by
|
||||
/// </summary>
|
||||
[DataField("actualScalar"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float ActualScalar = 1f;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using Content.Server.Construction;
|
||||
using Content.Server.Power.Components;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Server.Power.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class UpgradeBatterySystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly BatterySystem _batterySystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<UpgradeBatteryComponent, RefreshPartsEvent>(OnRefreshParts);
|
||||
SubscribeLocalEvent<UpgradeBatteryComponent, UpgradeExamineEvent>(OnUpgradeExamine);
|
||||
}
|
||||
|
||||
public void OnRefreshParts(EntityUid uid, UpgradeBatteryComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
var powerCellRating = args.PartRatings[component.MachinePartPowerCapacity];
|
||||
|
||||
if (TryComp<BatteryComponent>(uid, out var batteryComp))
|
||||
{
|
||||
_batterySystem.SetMaxCharge(uid, MathF.Pow(component.MaxChargeMultiplier, powerCellRating - 1) * component.BaseMaxCharge, batteryComp);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUpgradeExamine(EntityUid uid, UpgradeBatteryComponent component, UpgradeExamineEvent args)
|
||||
{
|
||||
// UpgradeBatteryComponent.MaxChargeMultiplier is not the actual multiplier, so we have to do this.
|
||||
if (TryComp<BatteryComponent>(uid, out var batteryComp))
|
||||
{
|
||||
args.AddPercentageUpgrade("upgrade-max-charge", batteryComp.MaxCharge / component.BaseMaxCharge);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
using Content.Server.Construction;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Server.Power.Components;
|
||||
|
||||
namespace Content.Server.Power.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// This handles using upgraded machine parts
|
||||
/// to modify the power supply/generation of a machine.
|
||||
/// </summary>
|
||||
public sealed class UpgradePowerSystem : EntitySystem
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<UpgradePowerDrawComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<UpgradePowerDrawComponent, RefreshPartsEvent>(OnRefreshParts);
|
||||
SubscribeLocalEvent<UpgradePowerDrawComponent, UpgradeExamineEvent>(OnUpgradeExamine);
|
||||
|
||||
SubscribeLocalEvent<UpgradePowerSupplierComponent, MapInitEvent>(OnSupplierMapInit);
|
||||
SubscribeLocalEvent<UpgradePowerSupplierComponent, RefreshPartsEvent>(OnSupplierRefreshParts);
|
||||
SubscribeLocalEvent<UpgradePowerSupplierComponent, UpgradeExamineEvent>(OnSupplierUpgradeExamine);
|
||||
|
||||
SubscribeLocalEvent<UpgradePowerSupplyRampingComponent, MapInitEvent>(OnSupplyRampingMapInit);
|
||||
SubscribeLocalEvent<UpgradePowerSupplyRampingComponent, RefreshPartsEvent>(OnSupplyRampingRefreshParts);
|
||||
SubscribeLocalEvent<UpgradePowerSupplyRampingComponent, UpgradeExamineEvent>(OnSupplyRampingUpgradeExamine);
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, UpgradePowerDrawComponent component, MapInitEvent args)
|
||||
{
|
||||
if (TryComp<PowerConsumerComponent>(uid, out var powa))
|
||||
component.BaseLoad = powa.DrawRate;
|
||||
else if (TryComp<ApcPowerReceiverComponent>(uid, out var powa2))
|
||||
component.BaseLoad = powa2.Load;
|
||||
}
|
||||
|
||||
private void OnRefreshParts(EntityUid uid, UpgradePowerDrawComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
var load = component.BaseLoad;
|
||||
var rating = args.PartRatings[component.MachinePartPowerDraw];
|
||||
switch (component.Scaling)
|
||||
{
|
||||
case MachineUpgradeScalingType.Linear:
|
||||
load += component.PowerDrawMultiplier * (rating - 1);
|
||||
break;
|
||||
case MachineUpgradeScalingType.Exponential:
|
||||
load *= MathF.Pow(component.PowerDrawMultiplier, rating - 1);
|
||||
break;
|
||||
default:
|
||||
Log.Error($"invalid power scaling type for {ToPrettyString(uid)}.");
|
||||
load = 0;
|
||||
break;
|
||||
}
|
||||
if (TryComp<ApcPowerReceiverComponent>(uid, out var powa))
|
||||
powa.Load = load;
|
||||
if (TryComp<PowerConsumerComponent>(uid, out var powa2))
|
||||
powa2.DrawRate = load;
|
||||
}
|
||||
|
||||
private void OnUpgradeExamine(EntityUid uid, UpgradePowerDrawComponent component, UpgradeExamineEvent args)
|
||||
{
|
||||
// UpgradePowerDrawComponent.PowerDrawMultiplier is not the actual multiplier, so we have to do this.
|
||||
var powerDrawMultiplier = CompOrNull<ApcPowerReceiverComponent>(uid)?.Load / component.BaseLoad
|
||||
?? CompOrNull<PowerConsumerComponent>(uid)?.DrawRate / component.BaseLoad;
|
||||
|
||||
if (powerDrawMultiplier is not null)
|
||||
args.AddPercentageUpgrade("upgrade-power-draw", powerDrawMultiplier.Value);
|
||||
}
|
||||
|
||||
private void OnSupplierMapInit(EntityUid uid, UpgradePowerSupplierComponent component, MapInitEvent args)
|
||||
{
|
||||
if (TryComp<PowerSupplierComponent>(uid, out var supplier))
|
||||
component.BaseSupplyRate = supplier.MaxSupply;
|
||||
}
|
||||
|
||||
private void OnSupplierRefreshParts(EntityUid uid, UpgradePowerSupplierComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
var supply = component.BaseSupplyRate;
|
||||
var rating = args.PartRatings[component.MachinePartPowerSupply];
|
||||
switch (component.Scaling)
|
||||
{
|
||||
case MachineUpgradeScalingType.Linear:
|
||||
supply += component.PowerSupplyMultiplier * component.BaseSupplyRate * (rating - 1);
|
||||
break;
|
||||
case MachineUpgradeScalingType.Exponential:
|
||||
supply *= MathF.Pow(component.PowerSupplyMultiplier, rating - 1);
|
||||
break;
|
||||
default:
|
||||
Log.Error($"invalid power scaling type for {ToPrettyString(uid)}.");
|
||||
supply = component.BaseSupplyRate;
|
||||
break;
|
||||
}
|
||||
|
||||
component.ActualScalar = supply / component.BaseSupplyRate;
|
||||
|
||||
if (TryComp<PowerSupplierComponent>(uid, out var powa))
|
||||
powa.MaxSupply = supply;
|
||||
}
|
||||
|
||||
private void OnSupplierUpgradeExamine(EntityUid uid, UpgradePowerSupplierComponent component, UpgradeExamineEvent args)
|
||||
{
|
||||
args.AddPercentageUpgrade("upgrade-power-supply", component.ActualScalar);
|
||||
}
|
||||
|
||||
private void OnSupplyRampingMapInit(EntityUid uid, UpgradePowerSupplyRampingComponent component, MapInitEvent args)
|
||||
{
|
||||
if (TryComp<PowerNetworkBatteryComponent>(uid, out var battery))
|
||||
component.BaseRampRate = battery.SupplyRampRate;
|
||||
}
|
||||
|
||||
private void OnSupplyRampingRefreshParts(EntityUid uid, UpgradePowerSupplyRampingComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
var rampRate = component.BaseRampRate;
|
||||
var rating = args.PartRatings[component.MachinePartRampRate];
|
||||
switch (component.Scaling)
|
||||
{
|
||||
case MachineUpgradeScalingType.Linear:
|
||||
rampRate += component.SupplyRampingMultiplier * component.BaseRampRate * (rating - 1);
|
||||
break;
|
||||
case MachineUpgradeScalingType.Exponential:
|
||||
rampRate *= MathF.Pow(component.SupplyRampingMultiplier, rating - 1);
|
||||
break;
|
||||
default:
|
||||
Log.Error($"invalid power supply ramping type for {ToPrettyString(uid)}.");
|
||||
rampRate = component.BaseRampRate;
|
||||
break;
|
||||
}
|
||||
|
||||
component.ActualScalar = rampRate / component.BaseRampRate;
|
||||
|
||||
if (TryComp<PowerNetworkBatteryComponent>(uid, out var battery))
|
||||
battery.SupplyRampRate = rampRate;
|
||||
}
|
||||
|
||||
private void OnSupplyRampingUpgradeExamine(EntityUid uid, UpgradePowerSupplyRampingComponent component, UpgradeExamineEvent args)
|
||||
{
|
||||
args.AddPercentageUpgrade("upgrade-power-supply-ramping", component.ActualScalar);
|
||||
}
|
||||
}
|
||||
@@ -26,11 +26,8 @@ public sealed class GeneratorSystem : SharedGeneratorSystem
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
[Dependency] private readonly PuddleSystem _puddle = default!;
|
||||
|
||||
private EntityQuery<UpgradePowerSupplierComponent> _upgradeQuery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_upgradeQuery = GetEntityQuery<UpgradePowerSupplierComponent>();
|
||||
|
||||
UpdatesBefore.Add(typeof(PowerNetSystem));
|
||||
|
||||
@@ -216,9 +213,7 @@ public sealed class GeneratorSystem : SharedGeneratorSystem
|
||||
|
||||
supplier.Enabled = true;
|
||||
|
||||
var upgradeMultiplier = _upgradeQuery.CompOrNull(uid)?.ActualScalar ?? 1f;
|
||||
|
||||
supplier.MaxSupply = gen.TargetPower * upgradeMultiplier;
|
||||
supplier.MaxSupply = gen.TargetPower;
|
||||
|
||||
var eff = 1 / CalcFuelEfficiency(gen.TargetPower, gen.OptimalPower, gen);
|
||||
var consumption = gen.OptimalBurnRate * frameTime * eff;
|
||||
|
||||
Reference in New Issue
Block a user