//===========================================================================// // File: sensor.cpp // // Project: BattleTech Brick: Mech subsystems // // Contents: Sensor -- the radar / targeting subsystem // //---------------------------------------------------------------------------// // Copyright (C) 1995, Virtual World Entertainment, Inc. // // All Rights reserved worldwide // // This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL // //===========================================================================// #include #pragma hdrstop #if !defined(SENSOR_HPP) # include #endif #if !defined(MECH_HPP) # include #endif // //############################################################################# // Shared data support //############################################################################# // Derivation Sensor::ClassDerivations( PoweredSubsystem::ClassDerivations, "Sensor" ); Sensor::SharedData Sensor::DefaultData( Sensor::ClassDerivations, Subsystem::MessageHandlers, Subsystem::AttributeIndex, Subsystem::StateCount ); // //############################################################################# // The radar / targeting subsystem. A non-replicant (master) instance runs the // per-frame SensorSimulation. //############################################################################# // Sensor::Sensor( Mech *owner, int subsystem_ID, SubsystemResource *subsystem_resource ): PoweredSubsystem(owner, subsystem_ID, subsystem_resource, DefaultData) { Check(owner); Check_Pointer(subsystem_resource); radarPercent = 1.0f; // RadarBaseline selfTest = False; badVoltage = False; // // Install the per-frame performance unless the owner is a replicant copy // (which is driven by console updates instead). // if (owner->GetInstance() != Entity::ReplicantInstance) { SetPerformance(&Sensor::SensorSimulation); } Check_Fpu(); } // //############################################################################# //############################################################################# // Sensor::~Sensor() { } // //############################################################################# //############################################################################# // Logical Sensor::TestClass(Mech &) { return True; } Logical Sensor::TestInstance() const { return IsDerivedFrom(ClassDerivations); } // //############################################################################# //############################################################################# // void Sensor::ResetToInitialState() { Check(this); radarPercent = 1.0f; // RadarBaseline selfTest = False; badVoltage = False; PoweredSubsystem::ResetToInitialState(True); } // //############################################################################# // Per-frame radar / targeting update. Not yet reconstructed -- fires only once // the mech is ticking. //############################################################################# // void Sensor::SensorSimulation(Scalar) { Check(this); // // Minimal safe per-frame sensor update (PARTIAL reconstruction). The // authentic SensorSimulation (BT411 @004b1c4c) first runs // PoweredSubsystem::PoweredSubsystemSimulation, then gates radarPercent / // selfTest / badVoltage on the heat state (Normal / Degradation / Failure) // and the electrical Ready state -- both of which live in the power/heat // per-frame sim chain that is not yet reconstructed (the powersub/heat // *Simulation methods are staged). Until that wave, derive radarPercent // from the one reconstructed input -- this sensor's own structural damage // level ([0,1], 0 intact .. 1 destroyed) -- and report the sensor healthy. // This keeps the engine's roster tick path (Entity::PerformAndWatch) safe // while producing a real radar-capability value. See SENSOR.NOTES.md. // radarPercent = 1.0f - GetSubsystemDamageLevel(); // RadarBaseline - zoneDamage if (radarPercent < 0.0f) { radarPercent = 0.0f; } selfTest = True; badVoltage = False; { // // One-shot confirmation that the engine's per-frame entity/roster tick // (Entity::PerformAndWatch) has engaged -- i.e. the mission reached // RunningMission and the mech is being simulated each frame. // static int firstTick = 0; if (!firstTick && getenv("BT_MECH_LOG")) { firstTick = 1; DEBUG_STREAM << "[tick] roster live (first Sensor frame), radarPercent=" << radarPercent << endl << flush; } } Check_Fpu(); } // //############################################################################# // Damage / death. //############################################################################# // void Sensor::TakeDamage(Damage &damage) { Check(this); PoweredSubsystem::TakeDamage(damage); } void Sensor::DeathReset(Logical /*full_recovery*/) { Check(this); ResetToInitialState(); } // //############################################################################# // CreateStreamedSubsystem Model-load-time construction. Not yet reconstructed // (see MECHSUB.NOTES.md -- the 4.10 subsystem stream format). //############################################################################# // int Sensor::CreateStreamedSubsystem( NotationFile *, const char *, const char *, SubsystemResource *, NotationFile *, const ResourceDirectories *, int ) { Fail("Sensor::CreateStreamedSubsystem -- sensor.cpp not yet reconstructed"); return 0; }