Deletes Entity.CanConsumeEnergy/TryConsumeEnergy and Reactor's own capacitor draining/filling (the demand-mechanism halves of Reactor.cs:90-141); adds PowerBus (one per Entity, stepped once per tick before equipment executes), IPowerConsumer on the five continuous draw sites (EnergyDraw, Thruster, AetherDrive, Radiator, ConstantWeapon), and EquippedItem.PowerSupply as the bus's grant ratio. Reactor keeps only its heat/throttle arithmetic, now driven by PowerBus.NetDraw instead of an accumulator any behaviour could add into. The four instant draws (InstantWeapon's burst/shot, Sensor's ping, Shield's hit taken) are out of scope for the bus this cut per the map; they spend capacitor charge directly and atomically via the new Entity.TrySpendCapacitorCharge/ CanSpendCapacitorCharge, replacing TryConsumeEnergy's old partial-drain-then- refuse bug for that path too. Named, temporary exception closed by Cut 4. docs/stats-and-power-cut.md Cut 3. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
96 lines
No EOL
3.6 KiB
C#
96 lines
No EOL
3.6 KiB
C#
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
using GameCult.Caching;
|
|
using MessagePack;
|
|
using Newtonsoft.Json;
|
|
using CultMath;
|
|
using static CultMath.math;
|
|
|
|
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), RuntimeInspectable]
|
|
public class ThrusterData : BehaviorData
|
|
{
|
|
[Inspectable, JsonProperty("thrust"), Key(1), RuntimeInspectable]
|
|
public PerformanceStat Thrust = new PerformanceStat();
|
|
|
|
[Inspectable, JsonProperty("visibility"), Key(2), RuntimeInspectable]
|
|
public PerformanceStat Visibility = new PerformanceStat();
|
|
|
|
[Inspectable, JsonProperty("heat"), Key(3), RuntimeInspectable]
|
|
public PerformanceStat Heat = new PerformanceStat();
|
|
|
|
[Inspectable, JsonProperty("energy"), Key(4), RuntimeInspectable]
|
|
public PerformanceStat EnergyUsage = new PerformanceStat();
|
|
|
|
[Inspectable, CultInspectorAssetGuid, JsonProperty("Particles"), Key(5)]
|
|
public string ParticlesPrefab;
|
|
|
|
public override Behavior CreateInstance(EquippedItem item)
|
|
{
|
|
return new Thruster(this, item);
|
|
}
|
|
|
|
public override Behavior CreateInstance(ConsumableItemEffect item)
|
|
{
|
|
return new Thruster(this, item);
|
|
}
|
|
}
|
|
|
|
public class Thruster : Behavior, IAnalogBehavior, IPowerConsumer
|
|
{
|
|
public float Thrust { get; private set; }
|
|
public float Torque { get; }
|
|
|
|
public float Axis
|
|
{
|
|
get => _input;
|
|
set => _input = saturate(value);
|
|
}
|
|
|
|
private ThrusterData _data;
|
|
|
|
private float _input;
|
|
|
|
public Thruster(ThrusterData data, EquippedItem item) : base(data, item)
|
|
{
|
|
_data = data;
|
|
var hullData = ItemManager.GetData(Entity.Hull) as HullData;
|
|
var hullCenter = hullData.Shape.CenterOfMass;
|
|
var itemData = ItemManager.GetData(item.EquippableItem);
|
|
var itemCenter = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation).CenterOfMass;
|
|
var toCenter = hullCenter - itemCenter;
|
|
Torque = -dot(normalize(toCenter), float2(1, 0).Rotate(item.EquippableItem.Rotation));
|
|
Thrust = Evaluate(_data.Thrust);
|
|
}
|
|
|
|
public Thruster(ThrusterData data, ConsumableItemEffect item) : base(data, item)
|
|
{
|
|
_data = data;
|
|
Torque = 0;
|
|
Thrust = Evaluate(_data.Thrust);
|
|
}
|
|
|
|
// Cut 3 (docs/stats-and-power-cut.md): the resolved stat times the behaviour-supplied throttle scalar (§1.2),
|
|
// exactly the shape the map names. _input is set externally (the ship's controls) before Entity.Update calls
|
|
// PowerBus.Step, so it is already current when this runs.
|
|
public float PowerRequest(float dt) => _input > .01f ? _input * Evaluate(_data.EnergyUsage) : 0f;
|
|
|
|
public override bool Execute(float dt)
|
|
{
|
|
Item.SetAudioParameter(SpecialAudioParameter.Intensity, _input);
|
|
if(_input > .01f && Item.PowerSupply >= 1f)
|
|
{
|
|
Thrust = Evaluate(_data.Thrust);
|
|
Entity.Velocity -= Direction.xz * _input * Thrust / Entity.Mass * dt;
|
|
Entity.Direction = mul(Entity.Direction,
|
|
CultMath.float2x2.Rotate(_input * Torque * Thrust * ItemManager.GameplaySettings.TorqueMultiplier / Entity.Mass * dt));
|
|
AddHeat(_input * Evaluate(_data.Heat) * dt);
|
|
var vis = _input * Evaluate(_data.Visibility);
|
|
if (!Entity.VisibilitySources.ContainsKey(this) || vis > Entity.VisibilitySources[this])
|
|
Entity.VisibilitySources[this] = vis;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
} |