Files
TeslaRel410/restoration/source410/BT/MISLANCH.CPP
T
CydandClaude Fable 5 fdf26d6e55 BT410 Phase 5.3.19: teardown SOLVED -- flying missiles are the DEFAULT
The death-row page fault was the THIRD strike of the uninitialized
zone-array trap: the staged spawn rides the mech family's resourceID, whose
DamageZoneStream makes the Entity base ctor allocate the 20-pointer
damageZones[] array with UNINITIALIZED slots -- the Missile never fills it,
and ~Entity's teardown deleted 20 garbage pointers through trash vtables
(the dtor-chain bisect showed every dtor completing, then EIP-in-heap).
Fix: the Projectile ctor NULLs every inherited zone slot.  RULE, now
three-crashes-proven: any entity subclass that does not FILL the allocated
zone array must NULL it -- the engine never initializes the slots, on
construction OR destruction.

Missiles are now the default SRM delivery (BT_MISSILE_INSTANT=1 = the
5.3.18a instant-hit as an A/B opt-out).  Verified: 20 launches -> 20
detonations -> 20 clean death-row teardowns over a 110s mutual fight, zero
faults; smoke + novice regressions green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 13:39:18 -05:00

229 lines
6.7 KiB
C++

//===========================================================================//
// File: mislanch.cpp //
// Project: BattleTech Brick: Mech weapons //
// Contents: MissileLauncher -- a projectile weapon that fires missile salvos //
//---------------------------------------------------------------------------//
// 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(MISLANCH_HPP)
# include <mislanch.hpp>
#endif
#if !defined(MECH_HPP)
# include <mech.hpp>
#endif
#if !defined(MISSILE_HPP)
# include <missile.hpp>
#endif
#if !defined(APP_HPP)
# include <app.hpp>
#endif
#if !defined(HOSTMGR_HPP)
# include <hostmgr.hpp>
#endif
//
// STAGED launch speed (the binary derives it from the authored
// MuzzleVelocity vector -- the muzzle wave).
//
static const Scalar kMissileLaunchSpeed = 150.0f; // u/s
Derivation
MissileLauncher::ClassDerivations(
ProjectileWeapon::ClassDerivations,
"MissileLauncher"
);
MissileLauncher::SharedData
MissileLauncher::DefaultData(
MissileLauncher::ClassDerivations,
Subsystem::MessageHandlers,
Subsystem::AttributeIndex,
Subsystem::StateCount
);
MissileLauncher::MissileLauncher(
Mech *owner,
int subsystem_ID,
SubsystemResource *subsystem_resource,
SharedData &default_data
):
ProjectileWeapon(owner, subsystem_ID, subsystem_resource, default_data)
{
Check(owner);
Check_Pointer(subsystem_resource);
missileCount = subsystem_resource->missileCount;
//
// A salvo delivers missileCount missiles; split the per-shot damage across
// the salvo. (The per-missile launch mechanics live in FireWeapon, staged.)
//
if (missileCount > 0)
{
damageData.burstCount = missileCount;
damageData.damageAmount = damageData.damageAmount / (Scalar)missileCount;
}
Check_Fpu();
}
MissileLauncher::~MissileLauncher()
{
}
Logical
MissileLauncher::TestInstance() const
{
return IsDerivedFrom(ClassDerivations);
}
//
//#############################################################################
// Damage / death.
//#############################################################################
//
void
MissileLauncher::TakeDamage(Damage &damage)
{
Check(this);
ProjectileWeapon::TakeDamage(damage);
}
void
MissileLauncher::DeathReset(Logical /*full_reset*/)
{
Check(this);
}
//
// The missile-salvo discharge. Not yet reconstructed.
//
void
MissileLauncher::FireWeapon()
{
Check(this);
//
// PARTIAL (binary @004bcc60): the authentic body launches missileCount
// Missile entities toward the owner's target (each carrying the salvo-split
// damageData) and dumps the firing heat. The Missile entity spawn needs
// the entity-spawn + targeting waves; the view/target gate, ammo pull and
// recoil all live in the CALLER (ProjectileWeaponSimulation's Loaded case).
//
// Ballistic heatCostToFire is stored 1e7-unit-NATIVE in the stream (SRM6
// reads 5.06e7 = +641K on its own sink -- the same design magnitude as the
// PPC's +632K); dump it raw, under the heat-model experience gate (novice /
// standard fire generates no heat -- authentic). (The EMITTER's authored
// value is small and its 1e7 comes from the energy algebra.)
if (HeatModelActive())
{
AddPendingHeat(heatCostToFire);
}
//
// The salvo launch (binary @004bcc60): ONE cluster Missile entity per
// trigger, spawned through the Mover make machinery -- the MakeMessage's
// resourceID is this weapon's projectile GameModel (explosionResourceID
// @0x3e4), so the Mover base streams the authored mass/drag. The round
// carries the salvo-split cluster damage record (burstCount =
// missileCount rides into the gyro bounce + splash) and homes via its
// Seeker; the proximity fuse delivers the damage ONCE (the arcade
// economy, BT411 task #62). Muzzle = the mech origin STAGED (the
// authored MuzzleVelocity arc through the MOUNT segment frame is the
// muzzle wave). If the projectile model resource is absent the launch
// falls back to the 5.3.16 instant-hit delivery.
//
if (targetWithinRange && owner != NULL
&& owner->GetTargetEntity() != NULL
&& getenv("BT_MISSILE_INSTANT") != NULL)
{
//
// DEV opt-out (BT_MISSILE_INSTANT=1): the 5.3.18a instant-hit
// cluster message, kept for A/B damage-economy checks. The flying
// Missile below is the DEFAULT since 5.3.19 (teardown closed: the
// Projectile ctor NULLs the inherited zone slots).
//
SendDamage(owner->GetTargetEntity(), damageData);
}
else if (targetWithinRange && owner != NULL
&& owner->GetTargetEntity() != NULL)
{
//
// The MakeMessage's resourceID must be a resource FAMILY id -- the
// Mover base ctor runs its own SearchList(resourceID, GameModel),
// and SearchList CRASHES (engine @0x414938) when the id isn't in
// the top-level directory (member resources resolve only through
// their family head). The streamed explosionModelFile is a small
// INDEX (SRM6 reads 17) into a model list -- decoding it into the
// real projectile family is the projectile-model brick. Until
// then the round spawns on the OWNER's family (its GameModel
// member provably streams every boot -- the mech model params);
// our staged flight integration reads none of the Mover mass/drag.
//
{
HostManager *host_manager = application->GetHostManager();
Check(host_manager);
Origin muzzle = owner->localOrigin;
Mover::MakeMessage
spawn_round(
Entity::MakeMessageID,
sizeof(Mover::MakeMessage),
EntityID(host_manager->GetLocalHostID()),
(Entity::ClassID)MissileClassID,
EntityID::Null,
owner->GetResourceID(),
Entity::DefaultFlags,
muzzle,
Motion::Identity,
Motion::Identity
);
Missile *round = new Missile(&spawn_round);
Register_Object(round);
round->Launch(
owner,
owner->GetTargetEntity(),
damageData,
kMissileLaunchSpeed
);
}
}
if (getenv("BT_MECH_LOG"))
{
DEBUG_STREAM << "[fire] '" << GetName()
<< "' FIRED (salvo of " << missileCount
<< ", recharge=" << rechargeRate
<< "s heat+=" << heatCostToFire << ")" << endl << flush;
}
}
//
// Model-load-time construction. Not yet reconstructed.
//
Logical
MissileLauncher::CreateStreamedSubsystem(
ResourceFile *,
NotationFile *,
const char *,
const char *,
SubsystemResource *,
NotationFile *,
const ResourceDirectories *,
int
)
{
Fail("MissileLauncher::CreateStreamedSubsystem -- mislanch.cpp not yet reconstructed");
return False;
}