Launchers draw real rounds: Missiles commodity and recipe, a reload that pays its crate, a reserve readout
Rulings ballistics-real-ammo and ballistics-cycle-power, follow-up launcher-ammunition. The Munitions batch adds the Missiles commodity (a high-explosive warhead and a rocket motor at the munitions works; guidance waits on the electronics chain) and sets AmmoType=Missiles on the five launcher designs; reactor energy per shot stays as authored. InstantWeapon: the reload used to refill the magazine on its timer and never reach the cargo branch in UseAmmo, so no ammunition-fed weapon ever paid a round. The refill now takes one unit of AmmoType from cargo (TakeReloadRound) and, with none, the magazine stays empty; UseAmmo only starts a reload when a unit is there. Weapon.Reserve exposes the cargo count and the HUD shows rounds/reserve for magazine weapons. Tests: shipped launchers all name Missiles and Missiles has a recipe; a fed weapon fires its magazine and no more without crates, reloads once per crate; Reserve equals the cargo count and falls per reload. The commodity count pin goes 22 to 23. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9135360beb
commit
8f77000844
7 changed files with 149 additions and 16 deletions
|
|
@ -229,7 +229,7 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
|
|||
if (!_coolingDown || !(_cooldown < 0)) return false;
|
||||
_overshoot = min(-_cooldown * CountdownSpan, dt);
|
||||
_coolingDown = false;
|
||||
if (_data.MagazineSize > 0 && _ammo == 0)
|
||||
if (_data.MagazineSize > 0 && _ammo == 0 && TakeReloadRound())
|
||||
{
|
||||
_ammo = _data.MagazineSize;
|
||||
OnReloadComplete?.Invoke();
|
||||
|
|
@ -239,6 +239,17 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
|
|||
return true;
|
||||
}
|
||||
|
||||
// A reload pays a round (ruling ballistics-real-ammo): one unit of the weapon's AmmoType leaves the cargo as the magazine refills,
|
||||
// and with none to take the magazine stays empty. A weapon with no AmmoType reloads free.
|
||||
private bool TakeReloadRound()
|
||||
{
|
||||
if (!_data.AmmoType.IsSet()) return true;
|
||||
var cargo = Entity.FindItemInCargo(_data.AmmoType.Key);
|
||||
if (cargo == null) return false;
|
||||
if (cargo.ItemsOfType[_data.AmmoType.Key][0] is SimpleCommodity simpleCommodity) cargo.Remove(simpleCommodity, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
private float CountdownSpan => max(ShortestCycle, _data.MagazineSize > 0 && _ammo == 0 ? _data.ReloadTime : Cooldown);
|
||||
|
||||
// A countdown that starts outside a round (a charge failing) carries the last one's overshoot like every restart.
|
||||
|
|
@ -265,18 +276,8 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
|
|||
return true;
|
||||
}
|
||||
|
||||
var hasAmmo = true;
|
||||
if (_data.AmmoType.IsSet())
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_data.AmmoType.Key);
|
||||
if (cargo != null)
|
||||
{
|
||||
var item = cargo.ItemsOfType[_data.AmmoType.Key][0];
|
||||
if (item is SimpleCommodity simpleCommodity)
|
||||
cargo.Remove(simpleCommodity, 1);
|
||||
}
|
||||
else hasAmmo = false;
|
||||
}
|
||||
// The reload starts only if a round is there to load; FinishCountdown takes it.
|
||||
var hasAmmo = !_data.AmmoType.IsSet() || Entity.CountItemsInCargo(_data.AmmoType.Key) > 0;
|
||||
if(hasAmmo)
|
||||
{
|
||||
OnReloadBegin?.Invoke();
|
||||
|
|
|
|||
|
|
@ -102,6 +102,8 @@ public abstract class Weapon : ActivatedBehavior
|
|||
public abstract float DamagePerSecond { get; }
|
||||
public abstract float RangeDamagePerSecond(float range);
|
||||
public abstract int Ammo { get; }
|
||||
// Rounds in the ship's cargo that reload this weapon's magazine: crates of AmmoType, 0 when the weapon draws none.
|
||||
public int Reserve => _data.AmmoType.IsSet() ? Entity.CountItemsInCargo(_data.AmmoType.Key) : 0;
|
||||
public WeaponData WeaponData => _data;
|
||||
public float RangeFactor(float at) => WeaponData.RangeFactor(MinRange, EffectiveRange, Range, _data.DamageAtMaxRange, at);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue