Fire mode is one property of a weapon's data (Automatic): creation and the semi-auto floor read it, the floor holds guided, mine, launcher and charged kinds and consumables; a step's rounds apply in arrival order, ties by shot id

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-10-23 06:12:55 +02:00
commit 1f7b971966
5 changed files with 128 additions and 28 deletions

View file

@ -9,10 +9,8 @@ using static CultMath.math;
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class AutoWeaponData : InstantWeaponData
{
public override Behavior CreateInstance(EquippedItem item)
{
return new AutoWeapon(this, item);
}
[IgnoreMember]
public override bool Automatic => true;
}
// A fully automatic gun: it fires every round its cooldown allows while its trigger is held, from the press (Activate)

View file

@ -21,14 +21,19 @@ public class InstantWeaponData : WeaponData
[Inspectable, JsonProperty("ammoInterval"), Key(20)]
public bool SingleAmmoBurst;
// The fire mode, the one fact creation and the semi-auto catalog check both read: an automatic gun fires every round its
// cooldown allows while its trigger is held, every other kind is semi-automatic (a press fires one burst).
[IgnoreMember]
public virtual bool Automatic => false;
public override Behavior CreateInstance(EquippedItem item)
{
return new InstantWeapon(this, item);
return Automatic ? new AutoWeapon(this, item) : new InstantWeapon(this, item);
}
public override Behavior CreateInstance(ConsumableItemEffect item)
{
return new InstantWeapon(this, item);
return Automatic ? new AutoWeapon(this, item) : new InstantWeapon(this, item);
}
// The shortest cooldown a plain (semi-automatic) gun may be authored with, 0.1 s: about ten presses a second. A faster one
@ -36,14 +41,19 @@ public class InstantWeaponData : WeaponData
// fire-mode-is-the-design); a gun that cycles faster is an AutoWeapon.
public const float ShortestSemiAutoCooldown = .1f;
// The plain guns of a catalog that cycle faster than a finger should have to: one fault line per gun.
public static IEnumerable<string> SemiAutoFaults(IEnumerable<GearData> catalog)
// The semi-automatic weapons of a catalog (gear and consumables, every kind that is not Automatic: plain, guided, mine,
// launcher, charged) that cycle faster than a finger should have to: one fault line per weapon.
public static IEnumerable<string> SemiAutoFaults(IEnumerable<ItemData> catalog)
{
foreach (var gear in catalog)
foreach (var behavior in gear.Behaviors)
if (behavior.GetType() == typeof(InstantWeaponData) && behavior is InstantWeaponData plain &&
Math.Min(plain.Cooldown.Min, plain.Cooldown.Max) < ShortestSemiAutoCooldown)
yield return $"{gear.Name}: a plain gun with a {Math.Min(plain.Cooldown.Min, plain.Cooldown.Max):0.###} s cooldown, below {ShortestSemiAutoCooldown} s; make it an AutoWeapon or slow it";
foreach (var item in catalog)
{
var behaviors = (item as GearData)?.Behaviors ?? (item as ConsumableItemData)?.Behaviors;
if (behaviors == null) continue;
foreach (var behavior in behaviors)
if (behavior is InstantWeaponData weapon && !weapon.Automatic &&
Math.Min(weapon.Cooldown.Min, weapon.Cooldown.Max) < ShortestSemiAutoCooldown)
yield return $"{item.Name}: a {weapon.GetType().Name} with a {Math.Min(weapon.Cooldown.Min, weapon.Cooldown.Max):0.###} s cooldown, below {ShortestSemiAutoCooldown} s; make it an AutoWeapon or slow it";
}
}
// The one formula of an instant weapon's damage per second at a range; the live weapon calls it with its evaluated

View file

@ -854,9 +854,9 @@ public static class FireControl
if (shots.Count == 0) return;
var now = zone.Time;
// In fire-time order, oldest first (the queue is kept in it by Fire), so which of a step's rounds breaks a shield or
// lands a kill follows sim time, not the order the shooters were stepped in. Shots queued while this walk runs are
// Commits walk the queue in fire-time order, oldest first (Fire keeps it in it). Shots queued while the walk runs are
// left to the next step.
List<(float Arrival, int Id)> arrived = null;
for (int i = 0, end = shots.Count; i < end;)
{
var shot = shots[i];
@ -892,20 +892,42 @@ public static class FireControl
if (shot.Committed && now >= shot.ArrivalTime)
{
// Cut 12.4(b) (docs/fire-control-cut.md, "Which model a shot uses"): Apply is the one owner of
// which model a shot uses, through its own switch on the frozen Fuse -- Step has no damage
// branch left. A direct hit, a proximity burst and a contact or delayed blast all arrive here
// the same way; only Apply decides what that means.
// Removed first: Apply reaches damage observers (user code), and a shot left in the queue by one
// that throws would resolve, and hurt, again on every later tick.
shots.RemoveAt(i);
end--;
Apply(zone, shot);
zone.ShotResolved.OnNext(shot.Outcome);
continue;
(arrived ??= new List<(float, int)>()).Add((shot.ArrivalTime, shot.ShotId));
}
i++;
}
if (arrived == null) return;
// The rounds that arrive in this step apply in arrival order, ties in shot-id order (ids rise as shots are made), so
// which of them breaks a shield or lands a kill follows when each hit, not the order the shooters were stepped in or the
// order their rounds left.
arrived.Sort((a, b) => a.Arrival != b.Arrival ? a.Arrival.CompareTo(b.Arrival) : a.Id.CompareTo(b.Id));
foreach (var (_, id) in arrived)
{
var i = shots.FindIndex(q => q.ShotId == id);
if (i < 0) continue;
var shot = shots[i];
var targetGone = shot.Target != null && !zone.Entities.Contains(shot.Target);
if (targetGone)
{
// As in the commit walk: a shot whose target left the zone in this step resolves as a miss.
var miss = MakeOutcome(shot, ShotResult.Miss, false, false, int2.zero, float2.zero, 0f, now);
shots.RemoveAt(i);
zone.ShotResolved.OnNext(miss);
continue;
}
// Cut 12.4(b) (docs/fire-control-cut.md, "Which model a shot uses"): Apply is the one owner of
// which model a shot uses, through its own switch on the frozen Fuse -- Step has no damage
// branch left. A direct hit, a proximity burst and a contact or delayed blast all arrive here
// the same way; only Apply decides what that means.
// Removed first: Apply reaches damage observers (user code), and a shot left in the queue by one
// that throws would resolve, and hurt, again on every later tick.
shots.RemoveAt(i);
Apply(zone, shot);
zone.ShotResolved.OnNext(shot.Outcome);
}
}
// R3/R4: the one roll. p_base was frozen at fire, PFire carrying the mount factor; the only thing measured live is how far the target has