//===========================================================================// // 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 #pragma hdrstop #if !defined(POWERSUB_HPP) # include #endif #if !defined(MECH_HPP) # include #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"); } //########################################################################### //############################ PowerWatcher ############################ //########################################################################### Derivation PowerWatcher::ClassDerivations( HeatWatcher::ClassDerivations, "PowerWatcher" ); PowerWatcher::SharedData PowerWatcher::DefaultData( PowerWatcher::ClassDerivations, Subsystem::MessageHandlers, Subsystem::AttributeIndex, Subsystem::StateCount ); PowerWatcher::PowerWatcher( Mech *owner, int subsystem_ID, SubsystemResource *subsystem_resource, SharedData &shared_data ): HeatWatcher(owner, subsystem_ID, subsystem_resource, shared_data), watchdogAlarm(5) { Check(owner); Check_Pointer(subsystem_resource); // // minVoltage is a scaled fraction of the watched supply; the exact scale // constant is a tuning value (stored 1:1 here until located). // minVoltage = subsystem_resource->minVoltagePercent; Check_Fpu(); } PowerWatcher::~PowerWatcher() { } Logical PowerWatcher::TestClass(Mech &) { return True; } Logical PowerWatcher::TestInstance() const { return IsDerivedFrom(ClassDerivations); } void PowerWatcher::ResetToInitialState(Logical powered) { Check(this); HeatWatcher::ResetToInitialState(powered); watchdogAlarm.SetLevel(0); } // // Per-frame supply-voltage watchdog. Not yet reconstructed. // void PowerWatcher::Simulation(Scalar) { Fail("PowerWatcher::Simulation -- powersub.cpp not yet reconstructed"); }