The SRM6 MissileLaunchers now run the authentic ballistic fire cycle against their linked AmmoBins, wire-verified end to end. - PROJWEAP ProjectileWeaponSimulation (PARTIAL, binary @004bbd04 -- fully recovered in the BT411 RE): one trigger-edge sample; the dry-bin gate pins NoAmmo(7) every frame; Loaded(2) -- the AMMO PULL LIVES IN THE CALLER (a denied shot does the 4->2 denial blip with NO ammo pulled -- early-returning gates from FireWeapon while the caller cycles the alarm is the 1995 "denied shot fakes a full firing cycle" defect class); granted -> Firing -> FireWeapon -> Loading (or NoAmmo on the emptying pull), recoil=rechargeRate; Loading bleeds recoil -> Loaded when a round is chambered, dial animates; Jammed(5) held; NoAmmo(7) = the roach-motel (re-asserts unconditionally). Deferred: electrical step, gate 1, eject, jam roll, HasActiveTarget. - AMMOBIN: FeedAmmo() + GetAmmoState() (1 round-ready / 2 EMPTY). - ammoBinLink wired from the resource's ammoBinIndex (the bin's roster slot). - WIRE-VERIFIED RESOURCE ALIGNMENT: a raw-stream dump pinned the ProjectileWeapon field block +3 ints past our staged struct (the MechWeapon resource ancestry runs 3 ints short -- the pip-family fields). Fixed with resourceAlignPad[3]; phantom muzzleVelocity/missileCount tail dropped. Confirmed on-wire: ammoBinIndex=27/29 (the exact bin slots), tracerInterval=1, minTOF=0.5, minVolt%=0.3, minJam=0.05, missileCount=6 (an SRM6!). - MECHWEAP: weapon-state enum extended to the full 1995 set (DryTrigger 1, Jammed 5, TriggerDuringJam 6, NoAmmo 7; count 8). - MISLANCH FireWeapon PARTIAL (@004bcc60: heat + salvo spawn only -- spawn needs the entity/targeting waves). VERIFIED headlessly (BT_FORCE_FIRE): bins resolve with the authored 24 rounds; SRM6s fire 6-missile salvos at the authored 1s cadence, rounds 24->0; after the 24th salvo the launcher goes DRY and stays silent across ~3,000 subsequent fire events while the energy weapons keep cycling. Zero Fail. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
307 lines
8.3 KiB
C++
307 lines
8.3 KiB
C++
//===========================================================================//
|
|
// File: projweap.cpp //
|
|
// Project: BattleTech Brick: Mech weapons //
|
|
// Contents: ProjectileWeapon -- ballistic (ammo-fed) weapon base //
|
|
//---------------------------------------------------------------------------//
|
|
// 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(PROJWEAP_HPP)
|
|
# include <projweap.hpp>
|
|
#endif
|
|
|
|
#if !defined(MECH_HPP)
|
|
# include <mech.hpp>
|
|
#endif
|
|
|
|
#if !defined(AMMOBIN_HPP)
|
|
# include <ammobin.hpp>
|
|
#endif
|
|
|
|
Derivation
|
|
ProjectileWeapon::ClassDerivations(
|
|
MechWeapon::ClassDerivations,
|
|
"ProjectileWeapon"
|
|
);
|
|
|
|
ProjectileWeapon::SharedData
|
|
ProjectileWeapon::DefaultData(
|
|
ProjectileWeapon::ClassDerivations,
|
|
MechWeapon::MessageHandlers,
|
|
MechWeapon::AttributeIndex,
|
|
Subsystem::StateCount
|
|
);
|
|
|
|
ProjectileWeapon::ProjectileWeapon(
|
|
Mech *owner,
|
|
int subsystem_ID,
|
|
SubsystemResource *subsystem_resource,
|
|
SharedData &shared_data
|
|
):
|
|
MechWeapon(owner, subsystem_ID, subsystem_resource, shared_data),
|
|
ammoBinLink()
|
|
{
|
|
Check(owner);
|
|
Check_Pointer(subsystem_resource);
|
|
|
|
tracerInterval = subsystem_resource->tracerInterval;
|
|
minTimeOfFlight = subsystem_resource->minTimeOfFlight;
|
|
minJamChance = subsystem_resource->minJamChance;
|
|
minVoltagePercentToFire = subsystem_resource->minVoltagePercentToFire;
|
|
|
|
tracerCounter = 0;
|
|
ejectState = 0;
|
|
totalTimeToEject = 0.0f;
|
|
timeToEject = 0.0f;
|
|
percentOfEject = 0.0f;
|
|
tracerModelHandle = 0;
|
|
leadPosition = Point3D(0.0f, 0.0f, 0.0f);
|
|
launchVelocity = Vector3D(0.0f, 0.0f, 0.0f);
|
|
tracerOrigin = Vector3D(0.0f, 0.0f, 0.0f);
|
|
|
|
//
|
|
// Link the AmmoBin subsystem the resource references by roster index (the
|
|
// binary ctor resolves it from the owner's subsystem table and connects the
|
|
// embedded link @0x43C). Shipped content always links a bin; log when the
|
|
// data doesn't resolve one.
|
|
//
|
|
{
|
|
Subsystem *roster_bin = NULL;
|
|
if (subsystem_resource->ammoBinIndex >= 0
|
|
&& subsystem_resource->ammoBinIndex < owner->GetSubsystemCount())
|
|
{
|
|
roster_bin = owner->GetSubsystem(subsystem_resource->ammoBinIndex);
|
|
}
|
|
if (roster_bin != NULL)
|
|
{
|
|
ammoBinLink.Add(roster_bin);
|
|
}
|
|
if (getenv("BT_MECH_LOG"))
|
|
{
|
|
DEBUG_STREAM << "[proj] '" << GetName()
|
|
<< "' ammoBinIndex=" << subsystem_resource->ammoBinIndex
|
|
<< " -> ";
|
|
if (roster_bin != NULL)
|
|
{
|
|
DEBUG_STREAM << roster_bin->GetName()
|
|
<< " (rounds=" << ((AmmoBin *)roster_bin)->GetAmmoCount() << ")";
|
|
}
|
|
else
|
|
{
|
|
DEBUG_STREAM << "<no bin>";
|
|
}
|
|
DEBUG_STREAM << endl << flush;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Install the ballistic fire state machine (a replicant copy is driven by
|
|
// console updates instead).
|
|
//
|
|
if (owner->GetInstance() != Entity::ReplicantInstance)
|
|
{
|
|
SetPerformance(&ProjectileWeapon::ProjectileWeaponSimulation);
|
|
}
|
|
|
|
Check_Fpu();
|
|
}
|
|
|
|
ProjectileWeapon::~ProjectileWeapon()
|
|
{
|
|
}
|
|
|
|
Logical
|
|
ProjectileWeapon::TestClass(Mech &)
|
|
{
|
|
return True;
|
|
}
|
|
|
|
Logical
|
|
ProjectileWeapon::TestInstance() const
|
|
{
|
|
return IsDerivedFrom(ClassDerivations);
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// FireWeapon The ballistic discharge (PARTIAL -- binary @004bc104). The
|
|
// authentic body is heat + projectile/tracer spawn ONLY: the view/target gate,
|
|
// the ammo pull and the recoil set all live in the CALLER (the Loaded case of
|
|
// ProjectileWeaponSimulation) -- early-returning any gate from here while the
|
|
// caller cycles the alarm anyway is exactly the 1995 "denied shot fakes a full
|
|
// firing cycle" defect class. The projectile spawn (Missile entities /
|
|
// tracer) needs the entity-spawn + targeting waves; MissileLauncher overrides
|
|
// this for the salvo launch.
|
|
//#############################################################################
|
|
//
|
|
void
|
|
ProjectileWeapon::FireWeapon()
|
|
{
|
|
Check(this);
|
|
|
|
if (getenv("BT_MECH_LOG"))
|
|
{
|
|
DEBUG_STREAM << "[fire] '" << GetName()
|
|
<< "' FIRED (ballistic, recharge=" << rechargeRate << "s)"
|
|
<< endl << flush;
|
|
}
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// ProjectileWeaponSimulation The ballistic per-frame fire state machine
|
|
// (binary @004bbd04, FULLY RECOVERED in the BT411 RE). The weapon state is
|
|
// carried in the weapon alarm: 0/1/4/6 transient audio blips, 2 Loaded,
|
|
// 3 Loading, 5 Jammed, 7 unavailable/NoAmmo (the roach-motel: nothing in the
|
|
// machine ever leaves it -- only a mission reset does).
|
|
//
|
|
// PARTIAL: the leading PoweredSubsystemSimulation electrical step, the
|
|
// destroyed / FailureHeat / mech-disabled hard gate (gate 1), the magazine
|
|
// eject, the electrical-Ready recoil gate, the heat-scaled jam roll and the
|
|
// HasActiveTarget half of the fire gate are deferred with the power / heat /
|
|
// damage / targeting waves. What runs is authentic in shape: the single
|
|
// trigger-edge sample, the dry-bin gate (gate 2), the Loaded ammo-pull ->
|
|
// Firing -> Loading cycle with the denial blip, the Loading recoil bleed +
|
|
// recharge dial, and the NoAmmo dry-fire blip.
|
|
//
|
|
// DEV hook BT_FORCE_FIRE=1: pulses the trigger whenever the weapon is Loaded
|
|
// (same as the emitter hook) -- every armed weapon auto-fires at its authored
|
|
// cadence until its bin runs dry.
|
|
//#############################################################################
|
|
//
|
|
void
|
|
ProjectileWeapon::ProjectileWeaponSimulation(Scalar time_slice)
|
|
{
|
|
Check(this);
|
|
|
|
{
|
|
static int forceFire = -1;
|
|
if (forceFire < 0)
|
|
{
|
|
forceFire = (getenv("BT_FORCE_FIRE") != NULL) ? 1 : 0;
|
|
}
|
|
if (forceFire)
|
|
{
|
|
fireImpulse = (GetWeaponState() == LoadedState) ? 1.0f : 0.0f;
|
|
}
|
|
}
|
|
|
|
//
|
|
// The trigger edge is sampled ONCE, before the gates.
|
|
//
|
|
Logical trigger = CheckFireEdge();
|
|
|
|
//
|
|
// Gate 2: the linked AmmoBin. Empty (or missing) -> pin unavailable EVERY
|
|
// frame while dry.
|
|
//
|
|
AmmoBin *bin = (AmmoBin *)ammoBinLink.Resolve();
|
|
if (bin != NULL && bin->GetAmmoState() == AmmoBin::AmmoEmptyState)
|
|
{
|
|
if (getenv("BT_MECH_LOG") && GetWeaponState() != NoAmmoState)
|
|
{
|
|
DEBUG_STREAM << "[fire] '" << GetName()
|
|
<< "' -> NoAmmo (bin dry)" << endl << flush;
|
|
}
|
|
weaponAlarm.SetLevel(NoAmmoState);
|
|
}
|
|
|
|
switch (GetWeaponState())
|
|
{
|
|
case LoadedState:
|
|
if (trigger)
|
|
{
|
|
if (viewFireEnable)
|
|
{
|
|
//
|
|
// The ammo pull happens HERE, in the caller -- a failed pull
|
|
// just stays Loaded, silently.
|
|
//
|
|
if (bin != NULL && bin->FeedAmmo() != 0)
|
|
{
|
|
weaponAlarm.SetLevel(FiringState);
|
|
ForceUpdate();
|
|
FireWeapon();
|
|
if (bin->GetAmmoState() == AmmoBin::AmmoEmptyState)
|
|
{
|
|
weaponAlarm.SetLevel(NoAmmoState);
|
|
}
|
|
else
|
|
{
|
|
weaponAlarm.SetLevel(LoadingState);
|
|
}
|
|
ForceUpdate();
|
|
recoil = rechargeRate;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// THE DENIAL BLIP: a shot denied by the look-view gate does
|
|
// SetLevel(4); SetLevel(2) -- a one-frame audio blip, the pip
|
|
// stays Loaded and NO ammo is pulled.
|
|
//
|
|
weaponAlarm.SetLevel(TriggerDuringLoadState);
|
|
weaponAlarm.SetLevel(LoadedState);
|
|
}
|
|
}
|
|
break;
|
|
|
|
case LoadingState:
|
|
if (trigger)
|
|
{
|
|
weaponAlarm.SetLevel(TriggerDuringLoadState);
|
|
weaponAlarm.SetLevel(LoadingState);
|
|
}
|
|
//
|
|
// Recoil bleeds down; at zero (and a round chambered) -> Loaded.
|
|
//
|
|
recoil -= time_slice;
|
|
if (recoil < 0.0f)
|
|
{
|
|
recoil = 0.0f;
|
|
if (bin != NULL && bin->GetAmmoState() == AmmoBin::AmmoLoadedState)
|
|
{
|
|
weaponAlarm.SetLevel(LoadedState);
|
|
if (getenv("BT_MECH_LOG"))
|
|
{
|
|
DEBUG_STREAM << "[fire] '" << GetName()
|
|
<< "' LOADED (rounds=" << bin->GetAmmoCount() << ")"
|
|
<< endl << flush;
|
|
}
|
|
}
|
|
}
|
|
ComputeOutputVoltage();
|
|
break;
|
|
|
|
case JammedState:
|
|
if (trigger)
|
|
{
|
|
weaponAlarm.SetLevel(TriggerDuringJamState);
|
|
weaponAlarm.SetLevel(JammedState);
|
|
}
|
|
recoil = rechargeRate;
|
|
break;
|
|
|
|
case NoAmmoState:
|
|
if (trigger)
|
|
{
|
|
weaponAlarm.SetLevel(DryTriggerState); // the dry-fire blip
|
|
}
|
|
weaponAlarm.SetLevel(NoAmmoState); // re-assert (the roach-motel)
|
|
recoil = rechargeRate;
|
|
ComputeOutputVoltage(); // dial pinned at 0
|
|
break;
|
|
|
|
default: // 0/1/4/6: transient audio-blip states, no case body
|
|
break;
|
|
}
|
|
|
|
Check_Fpu();
|
|
}
|