Files
TeslaRel410/restoration/source410/BT/SENSOR.CPP
T
CydandClaude Fable 5 3610ff1ecd BT410: entity simulation goes LIVE -- mission reaches RunningMission, mech + roster tick per-frame
The world now executes. Entity::Execute only PerformAndWatch's entities in
application state RunningMission, reached by two RunMissionMessages
(WaitingForLaunch->LaunchingMission->RunningMission). The 2nd is dispatched by
Player::ManageApplicationStatus when the launch fade expires -- but that only
runs inside PlayerSimulation, not the launch-phase HuntForDropZone. So the
player must switch Performance onto PlayerSimulation after it spawns.

- BTPLAYER.CPP DropZoneReplyMessageHandler: after CreatePlayerVehicle +
  InitializePlayerLink, choose the per-vehicle Performance by class -- Mech ->
  SetPerformance(PlayerSimulation)+SetScoringPlayerFlag; else CameraShipSimulation.
- BTPLAYER.CPP PlayerSimulation: chains the authentic base Player::PlayerSimulation
  (CalcRanking + ManageApplicationStatus + vehicle-pos copy + status service);
  console SCORE-delta flush deferred to the scoring wave.
- SENSOR.CPP SensorSimulation: minimal-safe partial (radarPercent = 1 -
  GetSubsystemDamageLevel, sensor healthy) so the roster tick path can't Fail
  once RunningMission engages. The heat/electrical gating awaits the power/heat
  sim wave (PoweredSubsystem/Generator/HeatSink/HeatWatcher *Simulation staged).

Verified: BT_MECH_LOG run reaches "[tick] roster live (first Sensor frame)",
two RunMissionHandler transitions, zero Fail/Exception. The mech is executed
each frame; its BODY Performance is still DoNothingOnce (real Mech::Simulate =
Phase 5.3, now the frontier).

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

202 lines
5.6 KiB
C++

//===========================================================================//
// 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 <bt.hpp>
#pragma hdrstop
#if !defined(SENSOR_HPP)
# include <sensor.hpp>
#endif
#if !defined(MECH_HPP)
# include <mech.hpp>
#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;
}