The full circuit, workflow-researched (5 parallel dossiers over BT411 + the engine) and adversarially reviewed (3 lenses) before landing: Mech side: the once-per-death transition in Simulate (freeze, motion kill, DeathShutdown sweep, MASTER-only VehicleDead(-1) to the player link); Mech::Reset @0049fb74 (reposition + heal every hull zone + the roster DeathReset sweep + PreRun -- the reset-based respawn that REUSES the entity); dead-owner terms in both weapon hard gates (wrecks fall silent). Player side: the VehicleDead(-1) branch (deathPending dedup, deathCount bump+stamp, scenario-role life debit, +5s re-post -> the engine drop-zone hunt) and the DropZoneReply respawn branch (reset the dead mech at the replied drop zone; probes on a live mech are moot). Subsystem side: the engine base virtual DeathReset implemented across the family -- MechSubsystem (zone heal + DestroyedState clear), MechWeapon (full powered/thermal restore + fresh Loading cycle), AmmoBin (restock from the ctor-cached count), HeatSink/HeatWatcher/PowerWatcher/Generator/Sensor/ MissileLauncher. Review catches fixed before commit: AmmoBin restocked through the FREED padBuffer pointer (use-after-free -> initialAmmoCount; MechSubsystem:: resource is now documented as never-deref-post-ctor); died-hot weapons respawned at FailureHeat (now full thermal re-init); Generator tap counts desynced across reset (preserved); Sensor skipped the base heal; PowerWatcher inherited a statically-bound reset; cooling toggle + connect mode restored. Verified: kill -> wreck (0 shots while dead) -> +5s -> drop-zone hunt -> HEALED + placed at a real drop zone -> 134 shots after respawn incl. 12 SRM (restock proof); unowned enemy wreck settles silently; fight/smoke/novice regressions green, zero faults. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
233 lines
6.0 KiB
C++
233 lines
6.0 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 time_slice)
|
|
{
|
|
Check(this);
|
|
|
|
//
|
|
// The authentic per-frame sensor update (binary @004b1c4c): the
|
|
// PoweredSubsystem step first, then radarPercent = baseline - structural
|
|
// damage, gated by the electrical Ready state and the heat state.
|
|
// (Still deferred: the novice-mode HeatModelOff gate -- the player
|
|
// experience switch -- joins with the player-link accessor wave.)
|
|
//
|
|
PoweredSubsystemSimulation(time_slice);
|
|
|
|
radarPercent = 1.0f - GetSubsystemDamageLevel(); // RadarBaseline - zoneDamage
|
|
if (radarPercent < 0.0f)
|
|
{
|
|
radarPercent = 0.0f;
|
|
}
|
|
selfTest = True;
|
|
|
|
if (GetVoltageState() == Ready)
|
|
{
|
|
badVoltage = False;
|
|
}
|
|
else
|
|
{
|
|
badVoltage = True;
|
|
radarPercent = 0.0f;
|
|
}
|
|
|
|
switch (GetHeatState())
|
|
{
|
|
case NormalHeat:
|
|
selfTest = True;
|
|
break;
|
|
|
|
case DegradationHeat:
|
|
radarPercent *= 0.5f; // HeatDegradationScale
|
|
selfTest = True;
|
|
break;
|
|
|
|
case FailureHeat:
|
|
radarPercent = 0.0f;
|
|
selfTest = False;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
{
|
|
//
|
|
// 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 << " voltState=" << GetVoltageState()
|
|
<< endl << flush;
|
|
}
|
|
}
|
|
|
|
Check_Fpu();
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// Damage / death.
|
|
//#############################################################################
|
|
//
|
|
void
|
|
Sensor::TakeDamage(Damage &damage)
|
|
{
|
|
Check(this);
|
|
PoweredSubsystem::TakeDamage(damage);
|
|
}
|
|
|
|
void
|
|
Sensor::DeathReset(Logical full_recovery)
|
|
{
|
|
Check(this);
|
|
//
|
|
// The base heal FIRST (private zone + DestroyedState + status level --
|
|
// a crit-killed radar must come back), then the sensor re-baseline.
|
|
//
|
|
MechSubsystem::DeathReset(full_recovery);
|
|
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;
|
|
}
|