The emitter charge cycle is now the authentic electrical model end to end.
- WIRE-VERIFIED resource fix: the Emitter block is graphicLength /
dischargeTime / seekVoltage[5] (FRACTIONS of the generator's rated voltage,
-1 sentinel) / seekVoltageRecommendedIndex. The old two-field guess read
seekVoltage[3]=0.99 as "dischargeTime 0.99s" -- the true PPC discharge is
0.2s, and the calibration reads seekV={6000,7000,8000,9900} x rated 10000,
recommended gear 2: the documented curve exactly.
- Ctor calibration (@004bb120): energyTotal=(dmg+heat)x1e7; EC pins
E=0.5V^2EC to energyTotal at the recommended gear; voltageScale calibrates
the exponential charge to reach seekV[rec] in the authored RechargeRate
seconds cold; damageFraction = the damage share.
- TrackSeekVoltage (@004ba838) + ChargeTimeScale (@004b0d50): the charge
integrates from the generator through the heat-stretched time scale, and
the I2R loss heats the GENERATOR -- verified GeneratorA at 477.9K charging
its PPC (BT411 predicted ~+480K) while the avionics generator idles at 77.
Hot generators charge slower: the heat/firepower feedback loop is CLOSED.
- Emitter::ComputeOutputVoltage override (now virtual, as in the binary
vtable): dial = level/seekV[gear], 0.01 snap, over-1 clamp.
- Sub-stepped Loading (1/60s slices -- the BT411 weapon-brick fix) + the
documented-divergence overcharge rescue. VERIFIED: the PPC loads at level
~7920, inside the binary's exact [7920,8080] snap window.
- FireWeapon energy algebra (@004bace8): damage/heat = energy shares x
chargeRatio^2. VERIFIED dmg=11.78 / heat=1.079e8 at ratio 0.9906. The
heatCost x 1e7 partial is retired -- heat now comes from the energy.
Zero Fail; jams/shutdowns regressions stay live under spam.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
334 lines
9.4 KiB
C++
334 lines
9.4 KiB
C++
//===========================================================================//
|
|
// File: powersub.hpp //
|
|
// Project: BattleTech //
|
|
// Contents: Implementation details for powered subsystems //
|
|
//---------------------------------------------------------------------------//
|
|
// Date Who Modification //
|
|
// -------- --- ---------------------------------------------------------- //
|
|
// //
|
|
//---------------------------------------------------------------------------//
|
|
// Copyright (C) 1995, Virtual World Entertainment, Inc. //
|
|
// All Rights reserved worldwide //
|
|
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
|
|
//===========================================================================//
|
|
|
|
#if !defined(POWERSUB_HPP)
|
|
# define POWERSUB_HPP
|
|
|
|
# if !defined(HEAT_HPP)
|
|
# include <heat.hpp>
|
|
# endif
|
|
|
|
//##################### Forward Class Declarations #######################
|
|
class Mech;
|
|
|
|
//###########################################################################
|
|
//################### PoweredSubsystem Model Resource ###################
|
|
//###########################################################################
|
|
|
|
struct PoweredSubsystem__SubsystemResource:
|
|
public HeatSink::SubsystemResource
|
|
{
|
|
int voltageSourceIndex;
|
|
Scalar thermalResistivityCoefficient;
|
|
int auxScreenNumber;
|
|
int auxScreenPlacement;
|
|
char auxScreenLabel[64];
|
|
char engScreenLabel[64];
|
|
Scalar startTime;
|
|
};
|
|
|
|
//###########################################################################
|
|
//######################### PoweredSubsystem ############################
|
|
//###########################################################################
|
|
|
|
class PoweredSubsystem:
|
|
public HeatSink
|
|
{
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Shared Data Support
|
|
//
|
|
public:
|
|
static Derivation ClassDerivations;
|
|
static SharedData DefaultData;
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Test Class Support
|
|
//
|
|
public:
|
|
static Logical
|
|
TestClass(Mech &);
|
|
Logical
|
|
TestInstance() const;
|
|
void
|
|
ResetToInitialState(Logical powered);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Electrical state machine (carried in electricalStateAlarm, 5 levels) and
|
|
// the connection-mode indicator (modeAlarm, 3 levels).
|
|
//
|
|
public:
|
|
enum ElectricalState {
|
|
Starting = 0, // powering up; startTimer counts toward startTime
|
|
NoVoltage = 1, // voltage source missing / unresolvable
|
|
Shorted = 2, // source generator shorted
|
|
GeneratorOff = 3, // source generator off / not ready
|
|
Ready = 4 // powered and operating
|
|
};
|
|
|
|
enum ConnectMode {
|
|
ManualConnect = 0,
|
|
Connected = 1,
|
|
AutoConnect = 2
|
|
};
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Power support
|
|
//
|
|
public:
|
|
Subsystem*
|
|
ResolveVoltageSource() { return voltageSource.Resolve(); }
|
|
int
|
|
AttachToVoltageSource(Subsystem *source);
|
|
unsigned
|
|
GetVoltageState() { Check(this); return electricalStateAlarm.GetLevel(); }
|
|
|
|
//
|
|
// The charge time-scale (binary @004b0d50) -- the heat/firepower
|
|
// feedback: the base voltageScale (the ctor-calibrated exponential
|
|
// charge constant) stretched by the powering generator's temperature
|
|
// rise above its start point.
|
|
//
|
|
Scalar
|
|
ChargeTimeScale();
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Per-frame simulation (heat step + the electrical state machine).
|
|
//
|
|
public:
|
|
typedef void
|
|
(PoweredSubsystem::*Performance)(Scalar time_slice);
|
|
void
|
|
SetPerformance(Performance performance)
|
|
{
|
|
Check(this);
|
|
activePerformance = (Simulation::Performance)performance;
|
|
}
|
|
|
|
void
|
|
PoweredSubsystemSimulation(Scalar time_slice);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Construction and Destruction
|
|
//
|
|
public:
|
|
typedef PoweredSubsystem__SubsystemResource SubsystemResource;
|
|
|
|
PoweredSubsystem(
|
|
Mech *owner,
|
|
int subsystem_ID,
|
|
SubsystemResource *subsystem_resource,
|
|
SharedData &shared_data = DefaultData
|
|
);
|
|
|
|
~PoweredSubsystem();
|
|
|
|
static int
|
|
CreateStreamedSubsystem(
|
|
NotationFile *model_file,
|
|
const char *model_name,
|
|
const char *subsystem_name,
|
|
SubsystemResource *subsystem_resource,
|
|
NotationFile *subsystem_file,
|
|
const ResourceDirectories *directories,
|
|
int passes = 1
|
|
);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Local Data
|
|
//
|
|
protected:
|
|
Scalar inputVoltage;
|
|
Scalar outputVoltage;
|
|
Scalar ratedVoltage;
|
|
SubsystemConnection voltageSource;
|
|
AlarmIndicator electricalStateAlarm;
|
|
AlarmIndicator modeAlarm;
|
|
Scalar thermalResistivityCoefficient;
|
|
Scalar startTime;
|
|
Scalar startTimer;
|
|
Scalar voltageScale;
|
|
};
|
|
|
|
//###########################################################################
|
|
//################### PowerWatcher Model Resource ######################
|
|
//###########################################################################
|
|
|
|
struct PowerWatcher__SubsystemResource:
|
|
public HeatWatcher::SubsystemResource
|
|
{
|
|
Scalar minVoltagePercent;
|
|
};
|
|
|
|
//###########################################################################
|
|
//############################ PowerWatcher ############################
|
|
//###########################################################################
|
|
//
|
|
// A HeatWatcher that also watches its subject's supply voltage. Base of the
|
|
// Torso / HUD / Gyroscope cockpit subsystems.
|
|
//
|
|
class PowerWatcher:
|
|
public HeatWatcher
|
|
{
|
|
public:
|
|
static Derivation ClassDerivations;
|
|
static SharedData DefaultData;
|
|
|
|
static Logical
|
|
TestClass(Mech &);
|
|
Logical
|
|
TestInstance() const;
|
|
void
|
|
ResetToInitialState(Logical powered);
|
|
void
|
|
Simulation(Scalar time_slice);
|
|
|
|
public:
|
|
typedef PowerWatcher__SubsystemResource SubsystemResource;
|
|
|
|
PowerWatcher(
|
|
Mech *owner,
|
|
int subsystem_ID,
|
|
SubsystemResource *subsystem_resource,
|
|
SharedData &shared_data = DefaultData
|
|
);
|
|
~PowerWatcher();
|
|
|
|
protected:
|
|
Scalar minVoltage;
|
|
AlarmIndicator watchdogAlarm;
|
|
};
|
|
|
|
//###########################################################################
|
|
//#################### Generator Model Resource ########################
|
|
//###########################################################################
|
|
|
|
struct Generator__SubsystemResource:
|
|
public HeatSink::SubsystemResource
|
|
{
|
|
Scalar ratedVoltage;
|
|
int maxTapCount;
|
|
Scalar startTime;
|
|
Scalar shortRecoveryTime;
|
|
};
|
|
|
|
//###########################################################################
|
|
//############################## Generator #############################
|
|
//###########################################################################
|
|
//
|
|
// The voltage SOURCE a PoweredSubsystem attaches to (currentTapCount tracks
|
|
// attached loads). A HeatSink that produces power.
|
|
//
|
|
class Generator:
|
|
public HeatSink
|
|
{
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Shared Data Support
|
|
//
|
|
public:
|
|
static Derivation ClassDerivations;
|
|
static SharedData DefaultData;
|
|
|
|
enum {
|
|
GeneratorOff = 0,
|
|
GeneratorStarting,
|
|
GeneratorReady,
|
|
GeneratorShorted,
|
|
GeneratorFailed,
|
|
GeneratorStateCount
|
|
};
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Test / reset
|
|
//
|
|
public:
|
|
static Logical
|
|
TestClass(Mech &);
|
|
Logical
|
|
TestInstance() const;
|
|
void
|
|
ResetToInitialState();
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Power interface
|
|
//
|
|
public:
|
|
Scalar MeasuredVoltage() { Check(this); return outputVoltage; }
|
|
Scalar RatedVoltageOf() { Check(this); return ratedVoltage; }
|
|
int GetGeneratorNumber(){ Check(this); return generatorNumber; }
|
|
unsigned
|
|
GeneratorStateOf() { Check(this); return stateAlarm.GetLevel(); }
|
|
|
|
//
|
|
// Tap the generator for one load (a PoweredSubsystem attaching): -1 when
|
|
// every tap is taken, else 0.
|
|
//
|
|
int
|
|
TapVoltageSource()
|
|
{
|
|
Check(this);
|
|
if (currentTapCount >= maxTapCount)
|
|
{
|
|
return -1;
|
|
}
|
|
++currentTapCount;
|
|
return 0;
|
|
}
|
|
|
|
typedef void
|
|
(Generator::*Performance)(Scalar time_slice);
|
|
void
|
|
SetPerformance(Performance performance)
|
|
{
|
|
Check(this);
|
|
activePerformance = (Simulation::Performance)performance;
|
|
}
|
|
|
|
void
|
|
GeneratorSimulation(Scalar time_slice);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Construction and Destruction
|
|
//
|
|
public:
|
|
typedef Generator__SubsystemResource SubsystemResource;
|
|
|
|
Generator(
|
|
Mech *owner,
|
|
int subsystem_ID,
|
|
SubsystemResource *subsystem_resource,
|
|
SharedData &shared_data = DefaultData
|
|
);
|
|
|
|
~Generator();
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Local Data
|
|
//
|
|
public:
|
|
Scalar percentVoltageAvailable;
|
|
int generatorOn;
|
|
Scalar ratedVoltage;
|
|
Scalar outputVoltage;
|
|
int generatorNumber;
|
|
int maxTapCount;
|
|
int currentTapCount;
|
|
Scalar startTime;
|
|
Scalar startTimer;
|
|
Scalar shortRecoveryTime;
|
|
Scalar shortTimer;
|
|
AlarmIndicator stateAlarm;
|
|
};
|
|
|
|
#endif
|