diff --git a/restoration/source410/BT/PROJWEAP.CPP b/restoration/source410/BT/PROJWEAP.CPP index b7343ea1..29efed1e 100644 --- a/restoration/source410/BT/PROJWEAP.CPP +++ b/restoration/source410/BT/PROJWEAP.CPP @@ -123,6 +123,23 @@ ProjectileWeapon::~ProjectileWeapon() { } +// +//############################################################################# +// GetAmmoCount -- the linked bin's rounds (-1 with no bin). The cockpit's +// BallisticWeaponCluster ammo readout reads this each frame; the binary +// pointed its NumericDisplayInteger straight at the resolved bin's count. +//############################################################################# +// +int + ProjectileWeapon::GetAmmoCount() +{ + Check(this); + + AmmoBin + *bin = (AmmoBin *)ammoBinLink.Resolve(); + return (bin != NULL) ? bin->GetAmmoCount() : -1; +} + Logical ProjectileWeapon::TestClass(Mech &) { diff --git a/restoration/source410/BT/PROJWEAP.HPP b/restoration/source410/BT/PROJWEAP.HPP index 7ea259f7..27796546 100644 --- a/restoration/source410/BT/PROJWEAP.HPP +++ b/restoration/source410/BT/PROJWEAP.HPP @@ -98,6 +98,14 @@ ); ~ProjectileWeapon(); + // + // The linked bin's round count, or -1 when no bin is linked. The + // cockpit's ammo readout needs this from BT_L4 and the link itself + // is protected (the binary read the resolved bin's count direct). + // + int + GetAmmoCount(); + protected: SubsystemConnection ammoBinLink; int tracerInterval; diff --git a/restoration/source410/BT_L4/BTL4GAU2.CPP b/restoration/source410/BT_L4/BTL4GAU2.CPP index 4b526686..0d1fcbc1 100644 --- a/restoration/source410/BT_L4/BTL4GAU2.CPP +++ b/restoration/source410/BT_L4/BTL4GAU2.CPP @@ -90,6 +90,10 @@ # include #endif +#if !defined(PROJWEAP_HPP) +# include +#endif + #include static const Scalar SeekVoltageXScale = 230.0f; // 0x43660000 @@ -2633,6 +2637,25 @@ EnergyWeaponCluster::~EnergyWeaponCluster() //########################################################################### // +// +// The linked-bin round count for the ammo readout: ProjectileWeapon +// resolves its own bin (the link is protected), so the cluster asks the +// weapon. -1 (no bin) reads as 0 rounds on the dial. +// +static int + AmmoRoundsOf(Subsystem *subsystem) +{ + if (subsystem == NULL + || !subsystem->IsDerivedFrom(ProjectileWeapon::ClassDerivations)) + { + return 0; + } + + int + rounds = ((ProjectileWeapon *)subsystem)->GetAmmoCount(); + return (rounds > 0) ? rounds : 0; +} + // @004c9558 -- ctor: WeaponCluster base + the ammo panel: two // NumericDisplayIntegers (ammo counts), jam/fire TwoStates, a // NumericDisplayScalarTwoState (reload seconds), a destroyed TwoState, plus @@ -2680,8 +2703,12 @@ BallisticWeaponCluster::BallisticWeaponCluster( { int engPort = renderer_in->FindGraphicsPort(eng_port_name); + // + // LIVE: the linked bin's rounds, refreshed by Execute. + // + ammoRounds = AmmoRoundsOf(subsystem_in); int - *ammoValue = &UnboundIntegerSource; // INERT (see ledger) + *ammoValue = &ammoRounds; reloadStartTime = 0; // @0xF4 reloadSeconds = 0.0f; // @0xF8 @@ -2764,7 +2791,8 @@ void void BallisticWeaponCluster::Execute() { - jammed = WeaponJammedOf(subsystem); + jammed = WeaponJammedOf(subsystem); + ammoRounds = AmmoRoundsOf(subsystem); // // INERT: reload/feed state (binary bin+0x18c) -- no recon member; the diff --git a/restoration/source410/BT_L4/BTL4GAU2.HPP b/restoration/source410/BT_L4/BTL4GAU2.HPP index 99400c01..f00a90db 100644 --- a/restoration/source410/BT_L4/BTL4GAU2.HPP +++ b/restoration/source410/BT_L4/BTL4GAU2.HPP @@ -533,6 +533,13 @@ void DrawWarningLamp(int on); // @004c9b50 (override: dot + ammo colour swap) Logical TestInstance() const; // @004c9adc protected: + // + // The live ammo cell the two round counters point at. The binary + // pointed them at the resolved AmmoBin's count; the link is + // protected, so Execute copies it here each frame -- the same + // pattern this cluster already uses for jammed / reloadSeconds. + // + int ammoRounds; Logical jammed; // @0xE8 this[0x3A] Logical firing; // @0xEC this[0x3B] Logical reloading; // @0xF0 this[0x3C]