BT410 Phase 5.3.18: flying missiles -- spawn/home/detonate LIVE, teardown open
The Missile entity family is reconstructed: Projectile : Mover gets a real make-path ctor; Missile hosts the Seeker + MissleThruster roster (the AUTHENTIC surviving SEEKER.HPP / MISTHRST.HPP interfaces -- the 1995 misspelling included) and flies the binary's guided integrator (@004bef78): age/lifetime, seeker re-lead with the decoded loft constants (200/50/300/0.1), thruster burn, steering (gain 4.0, deadband 1e-4), and the proximity fuse delivering the cluster damage ONCE with the launcher as inflictor. Live-verified end-to-end: LAUNCH -> flight telemetry (thruster visibly accelerating) -> DETONATE on the target ~0.9s out. OPEN: the first ~Missile off the death row completes, then the frame page-faults with EIP in the heap -- the first entity/subsystem teardown the reconstructed sim has ever run. The spawn path is therefore OPT-IN (BT_MISSILE_FLIGHT=1); default SRM delivery stays the 5.3.18a instant-hit cluster (verified 1:1, zero exceptions). Forensics + engine truths (SearchList crashes on non-directory ids; MakeMessages need FAMILY resource ids; explosionModelFile is a model-list INDEX) in MISSILE.NOTES.md. Also fixed on the way: the Subsystem NAME ctor left damageZone UNINITIALIZED (latent garbage for every name-built subsystem). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
//===========================================================================//
|
||||
// Project: BattleTech //
|
||||
// File: missile.cpp //
|
||||
// Project: BattleTech Brick: Mech weapons //
|
||||
// Contents: Missile -- the guided self-propelled projectile entity //
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (C) 1995, Virtual World Entertainment, Inc. //
|
||||
// All Rights reserved worldwide //
|
||||
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
|
||||
//===========================================================================//
|
||||
//
|
||||
// RECONSTRUCTED against the binary via the BT411 decomp (ctor @004bf5b4,
|
||||
// MoveAndCollide @004bef78, allocator @004bf8bc) and the surviving
|
||||
// SEEKER.HPP / MISTHRST.HPP. See MISSILE.NOTES.md for the staged pieces
|
||||
// (flight constants pending the missile GameModel record decode; world
|
||||
// collision + explosion entity are the render/effects wave).
|
||||
//
|
||||
|
||||
#include <bt.hpp>
|
||||
#pragma hdrstop
|
||||
@@ -13,6 +22,34 @@
|
||||
# include <missile.hpp>
|
||||
#endif
|
||||
|
||||
#if !defined(SEEKER_HPP)
|
||||
# include <seeker.hpp>
|
||||
#endif
|
||||
|
||||
#if !defined(MISTHRST_HPP)
|
||||
# include <misthrst.hpp>
|
||||
#endif
|
||||
|
||||
#if !defined(MECH_HPP)
|
||||
# include <mech.hpp>
|
||||
#endif
|
||||
|
||||
#if !defined(RANDOM_HPP)
|
||||
# include <random.hpp>
|
||||
#endif
|
||||
|
||||
//
|
||||
// Guidance tuning (binary .rdata @004bf594..@004bf5b0, BT411-decoded).
|
||||
// STAGED-DEFAULT flight envelope: lifetime / thrust come from the missile
|
||||
// GameModel record (model +0x44 / +0x48) once that layout is decoded; until
|
||||
// then the defaults below fly a believable SRM (fast, short-burn).
|
||||
//
|
||||
static const Scalar MissileSteerEps = 1.0e-4f; // _DAT_004bf598 steering deadband
|
||||
static const Scalar MissileTurnGain = 4.0f; // _DAT_004bf5a4 turn rate gain (1/s)
|
||||
static const Scalar MissileDriftGain = 0.1f; // _DAT_004bf5a8
|
||||
static const Scalar DefaultLifetime = 10.0f; // model +0x44 (staged default)
|
||||
static const Scalar DefaultFuseRadius = 20.0f; // proximity fuse (staged)
|
||||
|
||||
Derivation
|
||||
Missile::ClassDerivations(
|
||||
Projectile::ClassDerivations,
|
||||
@@ -29,8 +66,259 @@ Missile::SharedData
|
||||
);
|
||||
|
||||
Missile*
|
||||
Missile::Make(MakeMessage *)
|
||||
Missile::Make(MakeMessage *creation_message)
|
||||
{
|
||||
Fail("Missile::Make -- missile.cpp not yet reconstructed");
|
||||
return NULL;
|
||||
return new Missile(creation_message);
|
||||
}
|
||||
|
||||
//
|
||||
//#############################################################################
|
||||
// Construction (binary @004bf5b4). Chains the Projectile base (Entity
|
||||
// transform + Mover motion/model stream -- the MakeMessage's resourceID is
|
||||
// the launcher's explosion/projectile GameModel). The subsystem roster is
|
||||
// built in Launch(), which carries the target the binary's spawn descriptor
|
||||
// delivered to the ctor.
|
||||
//#############################################################################
|
||||
//
|
||||
Missile::Missile(
|
||||
MakeMessage *creation_message,
|
||||
SharedData &shared_data
|
||||
):
|
||||
Projectile(creation_message, shared_data)
|
||||
{
|
||||
Check(creation_message);
|
||||
|
||||
lifetime = DefaultLifetime;
|
||||
ageFraction = 0.0f;
|
||||
age = 0.0f;
|
||||
detonationFlag = 0;
|
||||
flightVelocity = Vector3D(0.0f, 0.0f, 0.0f);
|
||||
fuseRadius = DefaultFuseRadius;
|
||||
launcherEntityID = EntityID::Null;
|
||||
telemetryCountdown = 0;
|
||||
|
||||
Check_Fpu();
|
||||
}
|
||||
|
||||
Missile::~Missile()
|
||||
{
|
||||
if (getenv("BT_MECH_LOG"))
|
||||
{
|
||||
DEBUG_STREAM << "[msl] dtor (death row fry)" << endl << flush;
|
||||
}
|
||||
}
|
||||
|
||||
Logical
|
||||
Missile::TestInstance() const
|
||||
{
|
||||
return IsDerivedFrom(ClassDerivations);
|
||||
}
|
||||
|
||||
//
|
||||
//#############################################################################
|
||||
// Launch -- seed the flight (the binary ctor tail + spawn-descriptor
|
||||
// unpack). Builds the two-subsystem roster (Seeker @004bec34 with the
|
||||
// homing target, MissileThruster @004be7c4), aims the initial velocity at
|
||||
// the target and installs the guided integrator as the per-frame
|
||||
// Performance. Tail = SetValidFlag(), like every 1995 entity.
|
||||
//#############################################################################
|
||||
//
|
||||
void
|
||||
Missile::Launch(
|
||||
Mech *launcher,
|
||||
Entity *target,
|
||||
Damage &damage,
|
||||
Scalar launch_speed
|
||||
)
|
||||
{
|
||||
Check(this);
|
||||
Check(launcher);
|
||||
|
||||
launcherEntityID = launcher->GetEntityID();
|
||||
damageData = damage;
|
||||
|
||||
//
|
||||
// The 2-entry subsystem roster (binary this[0x49] = 2).
|
||||
//
|
||||
subsystemCount = SubsystemCount;
|
||||
subsystemArray = new Subsystem *[SubsystemCount];
|
||||
Register_Pointer(subsystemArray);
|
||||
subsystemArray[SeekerSubsystem] =
|
||||
new Seeker(this, SeekerSubsystem, NULL, target,
|
||||
Point3D(0.0f, 0.0f, 0.0f));
|
||||
Register_Object(subsystemArray[SeekerSubsystem]);
|
||||
subsystemArray[MissileThrusterSubsystem] =
|
||||
new MissileThruster(this, MissileThrusterSubsystem, NULL);
|
||||
Register_Object(subsystemArray[MissileThrusterSubsystem]);
|
||||
|
||||
//
|
||||
// Initial velocity: straight at the target's current position (the
|
||||
// authored MuzzleVelocity up-tilt arc through the MOUNT frame is the
|
||||
// muzzle wave -- the seeker converges either way).
|
||||
//
|
||||
if (target != NULL)
|
||||
{
|
||||
Vector3D aim;
|
||||
aim.Subtract(
|
||||
target->localOrigin.linearPosition,
|
||||
localOrigin.linearPosition
|
||||
);
|
||||
Scalar range = aim.Length();
|
||||
if (range > 0.01f)
|
||||
{
|
||||
flightVelocity.x = aim.x / range * launch_speed;
|
||||
flightVelocity.y = aim.y / range * launch_speed;
|
||||
flightVelocity.z = aim.z / range * launch_speed;
|
||||
}
|
||||
}
|
||||
|
||||
SetPerformance(&Missile::MoveAndCollide);
|
||||
AlwaysExecute();
|
||||
SetValidFlag();
|
||||
|
||||
if (getenv("BT_MECH_LOG"))
|
||||
{
|
||||
DEBUG_STREAM << "[msl] LAUNCH from " << launcherEntityID
|
||||
<< " at (" << localOrigin.linearPosition.x
|
||||
<< "," << localOrigin.linearPosition.y
|
||||
<< "," << localOrigin.linearPosition.z
|
||||
<< ") spd=" << launch_speed
|
||||
<< " dmg=" << damageData.damageAmount
|
||||
<< "x" << damageData.burstCount << endl << flush;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//#############################################################################
|
||||
// MoveAndCollide (binary @004bef78) -- the guided per-frame integrator.
|
||||
//
|
||||
// 1. Age; past the lifetime the round fizzles (death row, no damage).
|
||||
// 2. Re-lead the target (Seeker::FindTarget) + bleed the thruster burn.
|
||||
// 3. Steer the velocity toward the Seeker's lead point (turn gain 4.0,
|
||||
// deadband 1e-4) and integrate the position.
|
||||
// 4. Proximity fuse: inside fuseRadius of the aim point the round
|
||||
// DETONATES -- the cluster damage record lands on the target (random
|
||||
// hull zone interim, same as the direct path) and the round retires.
|
||||
// World-geometry collision (@0042291c) + the explosion entity
|
||||
// (@004be078, ClassID 0x5C) are the render/effects wave.
|
||||
//#############################################################################
|
||||
//
|
||||
void
|
||||
Missile::MoveAndCollide(Scalar time_slice)
|
||||
{
|
||||
Check(this);
|
||||
|
||||
age += time_slice;
|
||||
ageFraction = (age <= lifetime) ? age / lifetime : 1.0f;
|
||||
if (age > lifetime)
|
||||
{
|
||||
if (getenv("BT_MECH_LOG"))
|
||||
{
|
||||
DEBUG_STREAM << "[msl] fizzle (lifetime) at ("
|
||||
<< localOrigin.linearPosition.x << ","
|
||||
<< localOrigin.linearPosition.y << ","
|
||||
<< localOrigin.linearPosition.z << ")" << endl << flush;
|
||||
}
|
||||
CondemnToDeathRow();
|
||||
Check_Fpu();
|
||||
return;
|
||||
}
|
||||
|
||||
Seeker *seeker =
|
||||
(Seeker *)subsystemArray[SeekerSubsystem];
|
||||
MissileThruster *thruster =
|
||||
(MissileThruster *)subsystemArray[MissileThrusterSubsystem];
|
||||
Check(seeker);
|
||||
Check(thruster);
|
||||
|
||||
//
|
||||
// The hosted subsystems are advanced FROM the integrator (the binary
|
||||
// folds their work into this pass -- no separate roster tick).
|
||||
//
|
||||
seeker->FindTarget(time_slice);
|
||||
thruster->MissileThrusterSimulation(time_slice);
|
||||
|
||||
//
|
||||
// Steering: bend the velocity toward the seeker's lead point at
|
||||
// MissileTurnGain per second, holding speed; the thruster adds pace
|
||||
// while burning.
|
||||
//
|
||||
Vector3D toLead;
|
||||
toLead.Subtract(seeker->targetPosition, localOrigin.linearPosition);
|
||||
Scalar range = toLead.Length();
|
||||
|
||||
Scalar speed = flightVelocity.Length();
|
||||
if (thruster->burnTimeRemaining > 0.0f)
|
||||
{
|
||||
speed += thruster->thrusterAcceleration * time_slice;
|
||||
}
|
||||
|
||||
if (range > MissileSteerEps)
|
||||
{
|
||||
Scalar blend = MissileTurnGain * time_slice;
|
||||
if (blend > 1.0f)
|
||||
{
|
||||
blend = 1.0f;
|
||||
}
|
||||
Vector3D desired;
|
||||
desired.x = toLead.x / range * speed;
|
||||
desired.y = toLead.y / range * speed;
|
||||
desired.z = toLead.z / range * speed;
|
||||
flightVelocity.x += (desired.x - flightVelocity.x) * blend;
|
||||
flightVelocity.y += (desired.y - flightVelocity.y) * blend;
|
||||
flightVelocity.z += (desired.z - flightVelocity.z) * blend;
|
||||
}
|
||||
|
||||
localOrigin.linearPosition.x += flightVelocity.x * time_slice;
|
||||
localOrigin.linearPosition.y += flightVelocity.y * time_slice;
|
||||
localOrigin.linearPosition.z += flightVelocity.z * time_slice;
|
||||
localToWorld = localOrigin;
|
||||
|
||||
//
|
||||
// The proximity fuse (the BANKED seeker notes: fuse on the seeker's
|
||||
// rangeToTarget).
|
||||
//
|
||||
seeker->rangeToTarget = range;
|
||||
if (range <= fuseRadius && seeker->targetEntity != NULL)
|
||||
{
|
||||
Entity *victim = seeker->targetEntity;
|
||||
int zone = -1;
|
||||
if (victim->damageZoneCount > 0)
|
||||
{
|
||||
zone = Random(victim->damageZoneCount);
|
||||
}
|
||||
Entity::TakeDamageMessage
|
||||
hit(
|
||||
Entity::TakeDamageMessageID,
|
||||
sizeof(Entity::TakeDamageMessage),
|
||||
launcherEntityID,
|
||||
zone,
|
||||
damageData
|
||||
);
|
||||
victim->Dispatch(&hit);
|
||||
|
||||
if (getenv("BT_MECH_LOG"))
|
||||
{
|
||||
DEBUG_STREAM << "[msl] DETONATE on zone " << zone
|
||||
<< " amount=" << damageData.damageAmount
|
||||
<< " burst=" << damageData.burstCount
|
||||
<< " after " << age << "s" << endl << flush;
|
||||
}
|
||||
CondemnToDeathRow();
|
||||
Check_Fpu();
|
||||
return;
|
||||
}
|
||||
|
||||
if (getenv("BT_MECH_LOG") && --telemetryCountdown <= 0)
|
||||
{
|
||||
telemetryCountdown = 30;
|
||||
DEBUG_STREAM << "[msl] t=" << age
|
||||
<< " pos=(" << localOrigin.linearPosition.x
|
||||
<< "," << localOrigin.linearPosition.y
|
||||
<< "," << localOrigin.linearPosition.z
|
||||
<< ") range=" << range
|
||||
<< " spd=" << speed << endl << flush;
|
||||
}
|
||||
|
||||
Check_Fpu();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user