SimRateTests: the fixture gun's round costs what the fixture reactor can pay at 0.01 s
This commit is contained in:
parent
a1519c9b2b
commit
d038ee393a
2 changed files with 4 additions and 6 deletions
|
|
@ -64,7 +64,6 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
|
|||
// The shooter asked for fire during this step (Activate): a weapon asked of for the whole step fires every round its
|
||||
// cooldown allows inside it, rather than one per step. Cleared when the step ends.
|
||||
private bool _pulled;
|
||||
public string DiagBreak = ""; public int DiagRetriggers;
|
||||
// The shortest cycle a countdown divides by: a cooldown of zero would otherwise fire without end in one step.
|
||||
private const float ShortestCycle = .0005f;
|
||||
|
||||
|
|
@ -305,7 +304,6 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
|
|||
if (!refused && !_burstPaid && (!TrySpendActivationEnergy() || !UseAmmo(dt)))
|
||||
{
|
||||
_burstRemaining = 0;
|
||||
DiagBreak = $"spend failed charge={_capacitor.Charge} cap={_capacitor.Capacity}";
|
||||
return false;
|
||||
}
|
||||
if (!refused)
|
||||
|
|
@ -342,11 +340,10 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
|
|||
ended |= FinishCountdown(dt);
|
||||
// The trigger is held and the weapon is ready: the next burst starts now, at the moment the cooldown ended (what it
|
||||
// ran past zero is how long ago, at the step's end), or at the step's start when the weapon was already ready.
|
||||
if (!Repeats || _burstRemaining > 0 || !CanFire || (retriggered && !_burstStarted)) { DiagBreak = $"cond Repeats={Repeats} rem={_burstRemaining} can={CanFire} re={retriggered} started={_burstStarted} cd={_cooldown} cooling={_coolingDown}"; break; }
|
||||
if (!Repeats || _burstRemaining > 0 || !CanFire || (retriggered && !_burstStarted)) break;
|
||||
retriggered = true;
|
||||
DiagRetriggers++;
|
||||
Trigger();
|
||||
if (_burstRemaining == 0) { DiagBreak = "trigger refused"; break; }
|
||||
if (_burstRemaining == 0) break;
|
||||
if (ended)
|
||||
{
|
||||
_burstTimer = TakeOvershoot();
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public sealed partial class ContactRevealTests
|
|||
var name = $"Gun@{cooldown:R}";
|
||||
if (_openCache.GetByName<ItemData>(name) != null) return name;
|
||||
var gun = Armed(new InstantWeaponData { Count = Const(1), BurstTime = Const(0), Cooldown = Const(cooldown) }, 0);
|
||||
gun.Energy = Const(1); // the fixture reactor pays a round a hundredth of a second apart; the rounds-per-step tests top up nothing
|
||||
_openCache.Upsert(new WeaponItemData
|
||||
{
|
||||
Name = name, Hardpoint = HardpointType.Sensors, Shape = new Shape(), Durability = 1,
|
||||
|
|
@ -293,7 +294,7 @@ public sealed partial class ContactRevealTests
|
|||
var rounds = HoldTrigger(ship, Guns(ship)[0], dt, 10f, fireTimes);
|
||||
var probe = (InstantWeapon) Guns(ship)[0].Behaviors.Single(b => b is InstantWeapon);
|
||||
var cap = (InputCapacitor) typeof(InstantWeapon).GetField("_capacitor", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(probe);
|
||||
Assert.True(abs(rounds.Count - 1000f) <= 1.01f, $"dt {dt}: {rounds.Count} rounds in 10 s, expected 1000 +-1; capacity {cap.Capacity} rate {cap.Rate} charge {cap.Charge} cooldown {probe.Cooldown} canfire {probe.CanFire} firing {probe.Firing} retriggers {probe.DiagRetriggers} break {probe.DiagBreak}");
|
||||
Assert.True(abs(rounds.Count - 1000f) <= 1.01f, $"dt {dt}: {rounds.Count} rounds in 10 s, expected 1000 +-1; capacity {cap.Capacity} rate {cap.Rate} charge {cap.Charge} cooldown {probe.Cooldown} canfire {probe.CanFire} firing {probe.Firing}");
|
||||
Assert.Equal(rounds.Count, fireTimes.Count);
|
||||
for (var i = 1; i < fireTimes.Count; i++)
|
||||
Assert.True(abs(fireTimes[i] - fireTimes[i - 1] - .01f) < 2e-4f, $"dt {dt}: rounds {i - 1} and {i} born {fireTimes[i - 1]:R} and {fireTimes[i]:R}");
|
||||
|
|
|
|||
Loading…
Reference in a new issue