The energy weapons now run a live fire cycle, and the REAL trigger wiring is in place: the 1995 MechWeapon attribute table (binary @0x511890) is published with PINNED IDs, so the streamed per-mech fire-button mappings bind TriggerState (0x13) -> fireImpulse and the controls push writes the trigger into the weapon. - MECHWEAP: attribute enum + table (PercentDone 0x12, TriggerState 0x13, DistanceToTarget 0x14, TargetWithinRange 0x15, WeaponRange 0x16, EstimatedReadyTime 0x1A, RearFiring 0x1B, WeaponState 0x1C). Pads bridge the chain gap 2..0x11 -- LOAD-BEARING: AttributeIndexSet::Build leaves uncovered gap slots as uninitialized garbage, so every ID up to the max must be covered (they shrink to the authentic 0x0F..0x11 when the parent attribute waves land; SENSOR.HPP pins PoweredSubsystem::NextAttributeID at 0x0F). - MECHWEAP: fire-machine members (fireImpulse/previousFireImpulse, rechargeLevel, rangeToTarget, effectiveRange, estimatedReadyTime, recoil, weaponAlarm 0/2/3/4); CheckFireEdge (@004b9608, BIT-PATTERN int compare -- TriggerState carries raw ControlsButton ints whose release value is a float NaN; IEEE compare would latch the detector shut); ComputeOutputVoltage (@004b9c9c recharge dial). - EMITTER: EmitterSimulation (PARTIAL @004baa88) -- Firing/Loaded/Loading FSM on the weapon alarm, viewFireEnable gate at Loaded->Firing, recoil-decay recharge over the authored RechargeRate seconds; FireWeapon (PARTIAL @004bace8) discharge bookkeeping; ChargeLevel re-pinned to the authentic 0x1D; index re-chained to MechWeapon's. Deferred: electrical charge model (TrackSeekVoltage), heat dump, HasActiveTarget gate, beam/damage submission. - BT_FORCE_FIRE dev hook: trigger pulse whenever Loaded (auto-fire cadence). VERIFIED headlessly: forward view -- PPC_1/2 + ERMLaser_1 cycle FIRED->LOADED at the authored 0.6s/1s cadence, rear lasers silent; BT_FORCE_LOOK=3 -- ONLY the rear lasers (ERMLaser_2/3) fire. The view-fire x fire-FSM interlock holds both directions. Zero Fail. (SRM6 ballistic FSM = a later increment.) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
271 lines
7.5 KiB
C++
271 lines
7.5 KiB
C++
//===========================================================================//
|
|
// File: emitter.cpp //
|
|
// Project: BattleTech Brick: Mech weapons //
|
|
// Contents: Emitter -- the energy-weapon (beam) 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(EMITTER_HPP)
|
|
# include <emitter.hpp>
|
|
#endif
|
|
|
|
#if !defined(MECH_HPP)
|
|
# include <mech.hpp>
|
|
#endif
|
|
|
|
Derivation
|
|
Emitter::ClassDerivations(
|
|
MechWeapon::ClassDerivations,
|
|
"Emitter"
|
|
);
|
|
|
|
//
|
|
//#############################################################################
|
|
// Attribute Support. Emitter publishes the beam charge level (ChargeLevel, at
|
|
// the authentic 0x1D past the MechWeapon table end): the HUD weapon-charge
|
|
// gauge binds it, and -- load-bearing -- GaussRifle's AttributeIndex chains
|
|
// THIS index (GAUSS.CPP), and PPC::DefaultData binds it via the inherited
|
|
// PPC::AttributeIndex. It MUST be a real defined index (a declared-but-
|
|
// undefined Emitter::AttributeIndex leaves activeAttributeIndex NULL and
|
|
// faults the first GetAttributePointer on any PPC/Gauss). Chained to the
|
|
// MechWeapon index so every energy weapon exposes the full weapon table
|
|
// (TriggerState / PercentDone / ...).
|
|
//#############################################################################
|
|
//
|
|
const Emitter::IndexEntry
|
|
Emitter::AttributePointers[]=
|
|
{
|
|
ATTRIBUTE_ENTRY(Emitter, ChargeLevel, chargeLevel)
|
|
};
|
|
|
|
Emitter::AttributeIndexSet
|
|
Emitter::AttributeIndex(
|
|
ELEMENTS(Emitter::AttributePointers),
|
|
Emitter::AttributePointers,
|
|
MechWeapon::AttributeIndex
|
|
);
|
|
|
|
Emitter::SharedData
|
|
Emitter::DefaultData(
|
|
Emitter::ClassDerivations,
|
|
MechWeapon::MessageHandlers,
|
|
Emitter::AttributeIndex,
|
|
Subsystem::StateCount
|
|
);
|
|
|
|
Emitter::Emitter(
|
|
Mech *owner,
|
|
int subsystem_ID,
|
|
SubsystemResource *subsystem_resource,
|
|
SharedData &shared_data
|
|
):
|
|
MechWeapon(owner, subsystem_ID, subsystem_resource, shared_data)
|
|
{
|
|
Check(owner);
|
|
Check_Pointer(subsystem_resource);
|
|
|
|
chargeLevel = 0.0f;
|
|
dischargeTime = subsystem_resource->dischargeTime;
|
|
dischargeTimer = 0.0f;
|
|
|
|
//
|
|
// Install the beam-weapon fire state machine (a replicant copy is driven by
|
|
// console updates / ServiceDischarge instead, still staged).
|
|
//
|
|
if (owner->GetInstance() != Entity::ReplicantInstance)
|
|
{
|
|
SetPerformance(&Emitter::EmitterSimulation);
|
|
}
|
|
|
|
Check_Fpu();
|
|
}
|
|
|
|
Emitter::~Emitter()
|
|
{
|
|
}
|
|
|
|
Logical
|
|
Emitter::TestClass(Mech &)
|
|
{
|
|
return True;
|
|
}
|
|
|
|
Logical
|
|
Emitter::TestInstance() const
|
|
{
|
|
return IsDerivedFrom(ClassDerivations);
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// FireWeapon The energy-beam discharge (PARTIAL -- binary @004bace8). The
|
|
// authentic body: re-arm the beam-on countdown, compute the per-shot damage /
|
|
// heat from the charge energy (0.5*V^2*EC closed forms), dump the heat into
|
|
// the inherited thermal accumulator, spend the charge, build the beam
|
|
// (muzzle -> target) and submit the Damage record at the owner's target.
|
|
// The energy/heat algebra needs the electrical charge model (TrackSeekVoltage
|
|
// / seekVoltage / generator -- the powersub wave), and the beam/damage need
|
|
// the targeting slot + renderer. This partial performs the DISCHARGE
|
|
// bookkeeping -- countdown re-arm, charge spent, recoil loaded so the recharge
|
|
// dial animates -- so the fire state machine runs end-to-end.
|
|
//#############################################################################
|
|
//
|
|
void
|
|
Emitter::FireWeapon()
|
|
{
|
|
Check(this);
|
|
|
|
dischargeTimer = dischargeTime;
|
|
chargeLevel = 0.0f;
|
|
recoil = rechargeRate; // full recoil -> dial 0, decays in Loading
|
|
ComputeOutputVoltage();
|
|
|
|
if (getenv("BT_MECH_LOG"))
|
|
{
|
|
DEBUG_STREAM << "[fire] '" << GetName()
|
|
<< "' FIRED (discharge=" << dischargeTime
|
|
<< "s recharge=" << rechargeRate << "s)" << endl << flush;
|
|
}
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// ResetFiringState (binary @004ba9a8) -- the beam has finished: drop back to
|
|
// Loading so the recharge cycle begins.
|
|
//#############################################################################
|
|
//
|
|
void
|
|
Emitter::ResetFiringState()
|
|
{
|
|
Check(this);
|
|
|
|
weaponAlarm.SetLevel(LoadingState);
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// EmitterSimulation The beam-weapon per-frame fire state machine (binary
|
|
// @004baa88). The weapon state is carried in the weapon alarm level:
|
|
// 0 = Firing, 2 = Loaded (ready), 3 = Loading, 4 = the trigger-during-load
|
|
// blip. PARTIAL: the leading PoweredSubsystem electrical step and the
|
|
// destroyed / heat-failure / dead-mech hard gates are deferred with the
|
|
// power / heat / damage waves; the Loading charge uses the authored
|
|
// RechargeRate seconds directly (recoil decay -> ComputeOutputVoltage dial)
|
|
// instead of the TrackSeekVoltage generator integration; the Loaded->Firing
|
|
// gate honors viewFireEnable (the look-view arm) -- the HasActiveTarget gate
|
|
// joins it with the targeting wave.
|
|
//
|
|
// DEV hook BT_FORCE_FIRE=1: pulses the trigger whenever the weapon is Loaded
|
|
// (press while Loaded, release otherwise), so every armed weapon auto-fires at
|
|
// its authored recharge cadence -- the headless fire-cycle verification.
|
|
//#############################################################################
|
|
//
|
|
void
|
|
Emitter::EmitterSimulation(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;
|
|
}
|
|
}
|
|
|
|
Logical fireEdge = CheckFireEdge();
|
|
|
|
switch (GetWeaponState())
|
|
{
|
|
case FiringState:
|
|
//
|
|
// Count the beam-on timer down; when it expires, drop to Loading.
|
|
//
|
|
dischargeTimer -= time_slice;
|
|
if (dischargeTimer <= 0.0f)
|
|
{
|
|
ResetFiringState();
|
|
}
|
|
break;
|
|
|
|
case LoadedState:
|
|
if (fireEdge)
|
|
{
|
|
if (viewFireEnable)
|
|
{
|
|
weaponAlarm.SetLevel(FiringState);
|
|
FireWeapon();
|
|
}
|
|
else
|
|
{
|
|
weaponAlarm.SetLevel(TriggerDuringLoadState);
|
|
weaponAlarm.SetLevel(LoadedState);
|
|
}
|
|
}
|
|
break;
|
|
|
|
case LoadingState:
|
|
if (fireEdge)
|
|
{
|
|
weaponAlarm.SetLevel(TriggerDuringLoadState);
|
|
weaponAlarm.SetLevel(LoadingState);
|
|
}
|
|
//
|
|
// Recharge: decay the recoil over the authored RechargeRate seconds;
|
|
// the dial (rechargeLevel) rises 0 -> 1 with it.
|
|
//
|
|
recoil -= time_slice;
|
|
if (recoil <= 0.0f)
|
|
{
|
|
recoil = 0.0f;
|
|
}
|
|
ComputeOutputVoltage();
|
|
if (recoil == 0.0f)
|
|
{
|
|
weaponAlarm.SetLevel(LoadedState);
|
|
if (getenv("BT_MECH_LOG"))
|
|
{
|
|
DEBUG_STREAM << "[fire] '" << GetName()
|
|
<< "' LOADED" << endl << flush;
|
|
}
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
Check_Fpu();
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// CreateStreamedSubsystem Model-load-time construction. Not yet reconstructed.
|
|
//#############################################################################
|
|
//
|
|
int
|
|
Emitter::CreateStreamedSubsystem(
|
|
ResourceFile *,
|
|
NotationFile *,
|
|
const char *,
|
|
const char *,
|
|
SubsystemResource *,
|
|
NotationFile *,
|
|
const ResourceDirectories *,
|
|
int
|
|
)
|
|
{
|
|
Fail("Emitter::CreateStreamedSubsystem -- emitter.cpp not yet reconstructed");
|
|
return 0;
|
|
}
|