Files
TeslaRel410/restoration/source410/BT/POWERSUB.CPP
T
CydandClaude Fable 5 b5e0c10737 Mech milestone phase 2: reconstruct Generator (power source) -- power pair complete
Generator : public HeatSink (classID 0xBC3) -- the voltage SOURCE that
PoweredSubsystems tap (currentTapCount = attached loads). Reconstructed from the
BT411 decomp + the surviving GNRATOR.TCP partial: ctor chains HeatSink, seeds
ratedVoltage/outputVoltage/maxTapCount/startTime/shortRecoveryTime + stateAlarm(5)
= AlarmIndicator, derives generatorNumber from the segment-name suffix. Statics,
dtor, TestClass/TestInstance/ResetToInitialState real (ResetToInitialState mirrors
the .TCP); GeneratorSimulation (per-frame voltage/short) staged. Master-instance
SetPerformance install deferred (per-frame sim staged anyway).

Power system pair now in place: Generator (source) + PoweredSubsystem (load).
Roster classes so far: MechSubsystem, HeatableSubsystem, HeatSink,
PoweredSubsystem, Sensor, Generator. BT: 27 ok; tree links clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 23:49:53 -05:00

240 lines
6.9 KiB
C++

//===========================================================================//
// File: powersub.cpp //
// Project: BattleTech Brick: Mech subsystems //
// Contents: PoweredSubsystem -- a HeatSink drawing electrical power //
//---------------------------------------------------------------------------//
// Copyright (C) 1995, Virtual World Entertainment, Inc. //
// All Rights reserved worldwide //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
//===========================================================================//
#include <bt.hpp>
#pragma hdrstop
#if !defined(POWERSUB_HPP)
# include <powersub.hpp>
#endif
#if !defined(MECH_HPP)
# include <mech.hpp>
#endif
//
//#############################################################################
// Shared data support
//#############################################################################
//
Derivation
PoweredSubsystem::ClassDerivations(
HeatSink::ClassDerivations,
"PoweredSubsystem"
);
PoweredSubsystem::SharedData
PoweredSubsystem::DefaultData(
PoweredSubsystem::ClassDerivations,
Subsystem::MessageHandlers,
Subsystem::AttributeIndex,
Subsystem::StateCount
);
//
//#############################################################################
// A HeatSink that draws electrical power from a generator.
//
// The voltage-source resolution (indexing the owner mech's SUBSYSTEM ROSTER to
// find the powering generator) and the master-instance electrical simulation
// need the roster populated -- which happens during the Mech ctor's
// segment-table walk -- so they are deferred to that phase (see MECHSUB.NOTES.md).
// The ctor here chains HeatSink and primes the electrical state; the subsystem
// constructs with no attached source (inputVoltage 0) until the wiring lands.
//#############################################################################
//
PoweredSubsystem::PoweredSubsystem(
Mech *owner,
int subsystem_ID,
SubsystemResource *subsystem_resource,
SharedData &shared_data
):
HeatSink(owner, subsystem_ID, subsystem_resource, shared_data),
voltageSource(),
electricalStateAlarm(5),
modeAlarm(3)
{
Check(owner);
Check_Pointer(subsystem_resource);
inputVoltage = 0.0f;
outputVoltage = 0.0f;
ratedVoltage = 0.0f;
Check_Fpu();
}
//
//#############################################################################
//#############################################################################
//
PoweredSubsystem::~PoweredSubsystem()
{
}
//
//#############################################################################
//#############################################################################
//
void
PoweredSubsystem::ResetToInitialState(Logical powered)
{
Check(this);
HeatSink::ResetToInitialState(powered);
inputVoltage = 0.0f;
outputVoltage = 0.0f;
electricalStateAlarm.SetLevel(0);
modeAlarm.SetLevel(0);
}
//
//#############################################################################
//#############################################################################
//
Logical
PoweredSubsystem::TestClass(Mech &)
{
return True;
}
Logical
PoweredSubsystem::TestInstance() const
{
return IsDerivedFrom(ClassDerivations);
}
//
//#############################################################################
// AttachToVoltageSource Link this subsystem to its powering generator.
// Deferred with the segment-walk (needs the populated roster).
//#############################################################################
//
void
PoweredSubsystem::AttachToVoltageSource(Subsystem *)
{
Fail("PoweredSubsystem::AttachToVoltageSource -- powersub.cpp not yet reconstructed");
}
//###########################################################################
//############################## Generator #############################
//###########################################################################
//
//#############################################################################
// Shared data support
//#############################################################################
//
Derivation
Generator::ClassDerivations(
HeatSink::ClassDerivations,
"Generator"
);
Generator::SharedData
Generator::DefaultData(
Generator::ClassDerivations,
Subsystem::MessageHandlers,
Subsystem::AttributeIndex,
Subsystem::StateCount
);
//
//#############################################################################
// The generator -- the voltage source loads tap.
//#############################################################################
//
Generator::Generator(
Mech *owner,
int subsystem_ID,
SubsystemResource *subsystem_resource,
SharedData &shared_data
):
HeatSink(owner, subsystem_ID, subsystem_resource, shared_data),
stateAlarm(5)
{
Check(owner);
Check_Pointer(subsystem_resource);
ratedVoltage = subsystem_resource->ratedVoltage;
outputVoltage = ratedVoltage;
maxTapCount = subsystem_resource->maxTapCount;
currentTapCount = 0;
percentVoltageAvailable = 1.0f;
startTime = subsystem_resource->startTime;
startTimer = startTime;
stateAlarm.SetLevel(GeneratorReady);
generatorOn = 1;
shortRecoveryTime = subsystem_resource->shortRecoveryTime;
shortTimer = shortRecoveryTime;
//
// Generator number from the last character of the segment name
// ('A' -> 1, 'B' -> 2, ...).
//
const char *name = GetName();
generatorNumber = name[strlen(name) - 1] - 0x40;
Check_Fpu();
}
//
//#############################################################################
//#############################################################################
//
Generator::~Generator()
{
}
//
//#############################################################################
//#############################################################################
//
Logical
Generator::TestClass(Mech &)
{
return True;
}
Logical
Generator::TestInstance() const
{
return IsDerivedFrom(ClassDerivations);
}
//
//#############################################################################
//#############################################################################
//
void
Generator::ResetToInitialState()
{
Check(this);
HeatSink::ResetToInitialState(True);
outputVoltage = ratedVoltage;
currentTapCount = 0;
percentVoltageAvailable = 1.0f;
startTimer = startTime;
shortTimer = shortRecoveryTime;
generatorOn = 1;
stateAlarm.SetLevel(GeneratorReady);
}
//
//#############################################################################
// Per-frame electrical simulation (voltage, short recovery). Not yet
// reconstructed -- fires only once the mech is ticking.
//#############################################################################
//
void
Generator::GeneratorSimulation(Scalar)
{
Fail("Generator::GeneratorSimulation -- powersub.cpp not yet reconstructed");
}