Files
TeslaRel410/restoration/source410/BT/SENSOR.CPP
T
CydandClaude Fable 5 d67f8d5eda BT410 Phase 5.3.27: the attribute wave -- 48/50 cockpit bindings go LIVE
The gauges now read the real simulation: heat/power/sensor/mech attribute
tables published under the 1995 L4GAUGE.CFG spellings the widgets already
bind by name.  Temperatures, coolant mass/capacity/leak rate, condenser
valve settings, generator voltages and numbers, radar percent, and the
mech's radar/speed rows all resolve to live members.

THE NUMBERING IS PINNED: the chain publishes 2..0x0E so
PoweredSubsystem::NextAttributeID lands on the authentic 0x0F -- the
surviving SENSOR.HPP numbers RadarPercent off it and MechWeapon's
binary-pinned table starts at 0x12, so its pads shrank 16 -> 3
(0x0F..0x11) exactly as the 5.3.x header comment predicted.  Sensor's
authentic enum finally has its table defined; MechWeapon/Sensor rechain to
PoweredSubsystem and Reservoir/AggregateHeatSink to HeatSink so the whole
family is visible where the cfg expects it.

Verified with BT_GAUGE_ATTR_LOG: 48 OK / 2 NULL (was 33/17, and 0/50 at
the block's birth).  The two remaining have no member to bind --
HeatSink/AmbientTemperature (a sim constant) and Searchlight/LightOn (a
memberless subclass) -- and fall to the documented zero cell.  Gauge
fight (15/15 rounds, 127 zone hits), smoke and novice all clean.

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

255 lines
6.8 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"
);
//
//#############################################################################
// Attribute table -- the AUTHENTIC surviving SENSOR.HPP enum
// (RadarPercent/SelfTest/BadVoltage off PoweredSubsystem::NextAttributeID =
// 0x0F). The cockpit map() binds "Avionics/RadarPercent".
//#############################################################################
//
const Sensor::IndexEntry
Sensor::AttributePointers[]=
{
ATTRIBUTE_ENTRY(Sensor, RadarPercent, radarPercent),
ATTRIBUTE_ENTRY(Sensor, SelfTest, selfTest),
ATTRIBUTE_ENTRY(Sensor, BadVoltage, badVoltage)
};
Sensor::AttributeIndexSet
Sensor::AttributeIndex(
ELEMENTS(Sensor::AttributePointers),
Sensor::AttributePointers,
PoweredSubsystem::AttributeIndex
);
Sensor::SharedData
Sensor::DefaultData(
Sensor::ClassDerivations,
Subsystem::MessageHandlers,
Sensor::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;
}