Files
TeslaRel410/restoration/source410/BT/AMMOBIN.CPP
T
CydandClaude Fable 5 623c872c92 BT410 Phase 5.3.24: the death -> respawn cycle -- mechs DIE and COME BACK
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>
2026-07-24 16:35:05 -05:00

105 lines
2.7 KiB
C++

//===========================================================================//
// File: ammobin.cpp //
// Project: BattleTech Brick: Mech weapons //
// Contents: AmmoBin -- ammunition store with cook-off heat //
//---------------------------------------------------------------------------//
// 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(AMMOBIN_HPP)
# include <ammobin.hpp>
#endif
#if !defined(MECH_HPP)
# include <mech.hpp>
#endif
Derivation
AmmoBin::ClassDerivations(
HeatWatcher::ClassDerivations,
"AmmoBin"
);
AmmoBin::SharedData
AmmoBin::DefaultData(
AmmoBin::ClassDerivations,
Subsystem::MessageHandlers,
Subsystem::AttributeIndex,
Subsystem::StateCount
);
AmmoBin::AmmoBin(
Mech *owner,
int subsystem_ID,
SubsystemResource *resource,
SharedData &shared_data
):
HeatWatcher(owner, subsystem_ID, resource, shared_data),
ammoAlarm(6)
{
Check(owner);
Check_Pointer(resource);
ammoCount = resource->ammoCount;
initialAmmoCount = resource->ammoCount;
feedRate = resource->feedRate;
feedTimer = 0.0f;
ammoClassID = resource->ammoClassID;
ammoModelFile = resource->ammoModelFile;
explosionModelFile = resource->explosionModelFile;
heatPerRound = resource->heatPerRound;
cookOffArmed = 0;
cookOffTime = 0;
reserved = 0;
for (int i = 0; i < 12; ++i)
{
cookOffState[i] = 0;
}
Check_Fpu();
}
AmmoBin::~AmmoBin()
{
}
Logical
AmmoBin::TestClass(Mech &)
{
return True;
}
Logical
AmmoBin::TestInstance() const
{
return IsDerivedFrom(ClassDerivations);
}
//
//#############################################################################
// DeathReset -- the respawn restock: base heal + refill from the authored
// resource count (the launchers' NoAmmo state releases in their own reset).
//#############################################################################
//
void
AmmoBin::DeathReset(Logical full_reset)
{
Check(this);
HeatWatcher::DeathReset(full_reset);
//
// Restock from the CTOR-CACHED authored count -- NEVER through the
// `resource` member: it points into the Mech ctor's padded stream copy,
// which is delete[]d before the ctor returns (a respawn-time deref
// reads freed heap -- caught by the 5.3.24 adversarial review).
//
ammoCount = initialAmmoCount;
}