From 74b54e9b0699b26fd8a05fe6e662b1c2674e26dc Mon Sep 17 00:00:00 2001 From: Oscar Bailey <79094698+ozgb@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:28:25 +0000 Subject: [PATCH 1/9] Update: State the interceptor sweep limits A cycle of noExplode interceptors is outside the contract, the sweep may be bounded only above every chain the reference ends, a module clears a sweep's work at its start, source is 0 or a pool unit, and a feature index at or above featureCount has no case. The pin moves to the kit that holds ai-antinuke-pair, a two-level chain. Assisted-by: Claude:claude-sonnet-5-5 --- specs/weapons.md | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/specs/weapons.md b/specs/weapons.md index 2dc8636..a80c61b 100644 --- a/specs/weapons.md +++ b/specs/weapons.md @@ -406,7 +406,10 @@ For each cell, in *z* then *x* order, for the cell's `unit` and then its `unit2` For the cell's features, when the weapon does not have bit 14 of `flags` set: a cell whose `feature` is 0xfffe is first replaced by its origin cell, read with `los_radar.GetMapCell` at (*x* − its -`offsetX`, *z* − its `offsetY`); a `feature` of 0xfffb or above is skipped. The distance from the +`offsetX`, *z* − its `offsetY`); a `feature` of 0xfffb or above is skipped. A `feature` below 0xfffb is +an index below `Game.featureCount` in every valid block, so the rule has no case for one at or above it: +the reference reads `Game.features` there as it is, and a module may treat such a cell as having no +feature. The distance from the centre to the feature is, when the visited cell's `flags` bit 0 is set, the length of the centre minus `Game.spots[cell.spot].pos`; otherwise `features.GetFootprintCentre` of the visited cell's coordinates and the feature, and the length of the gap to the centre it writes. A distance below the radius adds @@ -418,7 +421,24 @@ is not this weapon, and whose squared distance from its position to the centre ( signed 64 bits, squared, the high 32 bits summed) is below `areaOfEffect²`, is detonated with no unit, and `network.SendProjectileDetonated` is called twice: with the attacker and that projectile, then with the attacker and this weapon. The sweep has no limit on how deep it nests: a detonated interceptor -projectile whose own detonation reaches the area damage sweeps in turn, to any depth. +projectile whose own detonation reaches the area damage sweeps in turn, to any depth. The two +announcements of a projectile follow everything its detonation does, the sweeps nested in it included: +in `ai-antinuke-pair` at tick 5926, interceptor projectile 3 (attacker `Unit#252`) detonates projectile +4, whose own sweep detonates projectile 5, and the calls come in the order (`Unit#253`, 5), (`Unit#253`, +4), (`Unit#252`, 4), (`Unit#252`, 3). + +A projectile whose weapon does not have `noExplode` set has its `dead` bit set by its detonation before +its area damage runs (step 2 of "A detonation"), so no later sweep detonates it again, and a chain of +such projectiles has at most as many levels as the table has projectiles (300). A projectile whose +weapon has `noExplode` set keeps its `dead` bit clear, unless step 3 of "A detonation" ends its +detonation (which sets the bit and runs no area damage), so each later sweep that reaches one whose +detonation ran the area damage detonates it again: a chain through one can pass the table's size, and two such interceptor projectiles that are in +each other's reach (directly, or through the sweeps of others) detonate each other without end. That +cycle is outside the contract: the reference has no result for it, because its stack overflows, and no +recording or vector holds one. Short of a cycle every chain ends, and the sweep detonates it to its +end. A module may bound the depth, provided no chain that ends in the reference reaches the bound. +Whatever work the module keeps for a sweep outside its stack, it clears at the start of each sweep, so a +trap in the middle of one leaves nothing that a later call reads (`docs/module-abi.md`, section 12). Finally, when the weapon's attacker is not null, HIT is published on it with the enemy and then the friendly total. @@ -497,6 +517,11 @@ weapon, and no scenario reaches one (#25). | SET_STOCKPILES 267 | each slot that has a weapon gets the stockpile `stockpiles[w]` (its low 8 bits) | 1 | | ADD_STOCKPILE 269 | the slot's stockpile rises by one (8 bits) | 1 | +**The `source` of DAMAGE and REMOTE_DAMAGE** is 0 (no attacker) or the block offset of a slot of +`Game.units` inside the pool, as the `unit` of the other kinds is. Any other value is outside the +contract: the reference takes it for a unit's address as it stands, so it has no defined result, and no +recording holds one. The event is not refused for it; a module may take such a `source` for no attacker. + **A unit's slots set up** (INIT_SLOTS): for each slot *w*: `reloadTimer` 0; `flags` keeps bits 5 to 7, its bit 0 becomes 0, bits 2 and 3 become *w*, its bit 4 becomes 1 and its bit 1 becomes 1 when the definition's `weapons[w]` is not weapon 0; `weapon` becomes `u.def.weapons[w]`; `stockpile` 0; `muzzleAimFromDeltaZ` becomes @@ -1070,12 +1095,14 @@ Not recorded in the kit's recordings (`docs/replay-format.md`, "Not recorded"), reason: - An interceptor shot: the recorded interceptor is the anti-nuke of `orders-weapon-build`, which - searches and finds no projectile, so `FindTargetableProjectile`'s hit, a projectile's chase of its - `interceptedProjectile` and `SendProjectileDetonated` are unrecorded. + searches and finds no projectile, so `FindTargetableProjectile`'s hit and a projectile's chase of its + `interceptedProjectile` are unrecorded. `ai-antinuke-pair` (ticks 5920 to 5930) holds the + detonation of interceptor projectiles and its two `SendProjectileDetonated` calls each, in a chain of + two levels. - `network.SendWeaponFire`, `network.SendUnitDamage`, `network.SendWeaponFireAt` and `network.SendProjectileDetonated`: they act only in a network game. The kit's stated limits (`docs/replay-format.md`, "Not recorded", weapons) also leave unjudged the two points' addresses, - interceptor chains deeper than four, a moved interceptor with a dead target, writes through a corrupt + interceptor chains deeper than two levels, a moved interceptor with a dead target, writes through a corrupt pointer of the block and a damage table above 65536 entries. - A hit of a paralyser weapon (a DAMAGE event of kind 2), PARALYZE's effect, damage of kind 11 and the recorded kinds' other values: the recorded DAMAGE events are of kinds 3 and 10. @@ -1122,5 +1149,5 @@ Questions the kit leaves open, which this spec does not answer: ## 8. Kit version -Kit `interfaces-v92` and `reference-traces-v60`, the versions the gate judges against. Interface +Kit `interfaces-v99` and `reference-traces-v63`, the versions the gate judges against. Interface `weapons` 4.0. From 3711b0e18be6a931f828e3369d1cef93a838b498 Mon Sep 17 00:00:00 2001 From: Oscar Bailey <79094698+ozgb@users.noreply.github.com> Date: Mon, 30 Nov 2026 01:15:58 +0000 Subject: [PATCH 2/9] Update: Pin the weapons spec to interfaces-v102 The kit holds ai-antinuke-pair, the two-level interceptor chain. Assisted-by: Claude:claude-sonnet-5-5 --- specs/weapons.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/weapons.md b/specs/weapons.md index a80c61b..6e89ffd 100644 --- a/specs/weapons.md +++ b/specs/weapons.md @@ -1149,5 +1149,5 @@ Questions the kit leaves open, which this spec does not answer: ## 8. Kit version -Kit `interfaces-v99` and `reference-traces-v63`, the versions the gate judges against. Interface +Kit `interfaces-v102` and `reference-traces-v64`, the versions the gate judges against. Interface `weapons` 4.0. From 1bd197a9cc4dcba469e170e1a81089a96991427c Mon Sep 17 00:00:00 2001 From: Oscar Bailey <79094698+ozgb@users.noreply.github.com> Date: Mon, 30 Nov 2026 01:25:03 +0000 Subject: [PATCH 3/9] Update: Answer the phase 1 review of the sweep rules The second announcement names the projectile whose sweep it is, the reach arithmetic is exact, the contract covers chains of up to 300 levels, nested sweeps share one work state cleared at the outermost sweep, and the feature and source cases are stated. Assisted-by: Claude:claude-sonnet-5-5 --- specs/weapons.md | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/specs/weapons.md b/specs/weapons.md index 6e89ffd..f1155b2 100644 --- a/specs/weapons.md +++ b/specs/weapons.md @@ -406,10 +406,11 @@ For each cell, in *z* then *x* order, for the cell's `unit` and then its `unit2` For the cell's features, when the weapon does not have bit 14 of `flags` set: a cell whose `feature` is 0xfffe is first replaced by its origin cell, read with `los_radar.GetMapCell` at (*x* − its -`offsetX`, *z* − its `offsetY`); a `feature` of 0xfffb or above is skipped. A `feature` below 0xfffb is -an index below `Game.featureCount` in every valid block, so the rule has no case for one at or above it: -the reference reads `Game.features` there as it is, and a module may treat such a cell as having no -feature. The distance from the +`offsetX`, *z* − its `offsetY`); a `feature` of 0xfffb or above is skipped, tested on the cell that results +from that replacement (so an origin cell whose own `feature` is 0xfffb or above is skipped). A `feature` +below 0xfffb is an index below `Game.featureCount` in every valid block, and an origin cell that does +not exist is a case no valid block has: both are outside the contract, and no recording holds +either. The distance from the centre to the feature is, when the visited cell's `flags` bit 0 is set, the length of the centre minus `Game.spots[cell.spot].pos`; otherwise `features.GetFootprintCentre` of the visited cell's coordinates and the feature, and the length of the gap to the centre it writes. A distance below the radius adds @@ -417,11 +418,15 @@ the origin cell to the list (once) and publishes the features' DAMAGE (kind 34) *x* and *z* and the weapon's index in `Game.weapons`. When the weapon has `interceptor` set, every projectile in the table that has its `dead` bit clear and -is not this weapon, and whose squared distance from its position to the centre (each difference taken in -signed 64 bits, squared, the high 32 bits summed) is below `areaOfEffect²`, is detonated with no unit, -and `network.SendProjectileDetonated` is called twice: with the attacker and that projectile, then with -the attacker and this weapon. The sweep has no limit on how deep it nests: a detonated interceptor -projectile whose own detonation reaches the area damage sweeps in turn, to any depth. The two +is not the projectile being detonated, and whose squared distance from its position to the centre (each +difference taken as a signed 32-bit value that wraps, squared in signed 64 bits, the high 32 bits of +each square summed as signed 32-bit numbers) is below `areaOfEffect²` (the 16-bit `areaOfEffect` squared as a signed 32-bit product, so a +value of 46341 or more squares to a negative number), is detonated with no unit, and +`network.SendProjectileDetonated` is called twice: with the attacker and that projectile, then with the +attacker and the projectile being detonated (the one whose sweep this is). A detonation that an +AREA_DAMAGE or DETONATE event starts has no projectile of the table to pass: the second call's +argument is the event's own record, which no recording holds (the call acts only in a network game). A detonated interceptor projectile whose own detonation reaches the area +damage sweeps in turn, inside the sweep that detonated it. The two announcements of a projectile follow everything its detonation does, the sweeps nested in it included: in `ai-antinuke-pair` at tick 5926, interceptor projectile 3 (attacker `Unit#252`) detonates projectile 4, whose own sweep detonates projectile 5, and the calls come in the order (`Unit#253`, 5), (`Unit#253`, @@ -432,13 +437,15 @@ its area damage runs (step 2 of "A detonation"), so no later sweep detonates it such projectiles has at most as many levels as the table has projectiles (300). A projectile whose weapon has `noExplode` set keeps its `dead` bit clear, unless step 3 of "A detonation" ends its detonation (which sets the bit and runs no area damage), so each later sweep that reaches one whose -detonation ran the area damage detonates it again: a chain through one can pass the table's size, and two such interceptor projectiles that are in -each other's reach (directly, or through the sweeps of others) detonate each other without end. That -cycle is outside the contract: the reference has no result for it, because its stack overflows, and no -recording or vector holds one. Short of a cycle every chain ends, and the sweep detonates it to its -end. A module may bound the depth, provided no chain that ends in the reference reaches the bound. -Whatever work the module keeps for a sweep outside its stack, it clears at the start of each sweep, so a -trap in the middle of one leaves nothing that a later call reads (`docs/module-abi.md`, section 12). +detonation ran the area damage detonates it again, and a chain through one can have more levels than +the table has entries. Two interceptor projectiles, of the same weapon or of two, that are both +`noExplode` and in each other's reach (directly, or through the sweeps of others) detonate each other without end: +the reference has no result for that cycle, and it is outside the contract. So is a chain of more +than 300 levels, which only a `noExplode` interceptor can make (no weapon of the game's data is both), +and no recording or vector holds one. The contract is every chain of up to 300 levels, which the +sweep detonates to its end, in the depth-first order above. The work a module keeps for the nested +sweeps outside its stack is empty when the outermost sweep starts (a sweep started while none runs) +and when it ends (`docs/module-abi.md`, section 12). Finally, when the weapon's attacker is not null, HIT is published on it with the enemy and then the friendly total. @@ -518,9 +525,9 @@ weapon, and no scenario reaches one (#25). | ADD_STOCKPILE 269 | the slot's stockpile rises by one (8 bits) | 1 | **The `source` of DAMAGE and REMOTE_DAMAGE** is 0 (no attacker) or the block offset of a slot of -`Game.units` inside the pool, as the `unit` of the other kinds is. Any other value is outside the -contract: the reference takes it for a unit's address as it stands, so it has no defined result, and no -recording holds one. The event is not refused for it; a module may take such a `source` for no attacker. +`Game.units` inside the pool (the first slot included), by the test the table above gives for `unit`. +The reference does no such test; any other value is outside the contract: the reference has no result for it, and no recording holds +one. The event is not refused for it. **A unit's slots set up** (INIT_SLOTS): for each slot *w*: `reloadTimer` 0; `flags` keeps bits 5 to 7, its bit 0 becomes 0, bits 2 and 3 become *w*, its bit 4 becomes 1 and its bit 1 becomes 1 when the From cb78b99a8cb35fed686f56b2bb1228c75e67cdf1 Mon Sep 17 00:00:00 2001 From: Implementer Date: Mon, 30 Nov 2026 01:38:42 +0000 Subject: [PATCH 4/9] Fix: Follow the new interceptor sweep rules Assisted-by: Claude Code:claude-sonnet-5-5 --- weapons/IMPLEMENTATION-NOTES.md | 16 +++++++++++++ weapons/src/lib.rs | 41 ++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/weapons/IMPLEMENTATION-NOTES.md b/weapons/IMPLEMENTATION-NOTES.md index 6751cb9..7a7a134 100644 --- a/weapons/IMPLEMENTATION-NOTES.md +++ b/weapons/IMPLEMENTATION-NOTES.md @@ -112,3 +112,19 @@ Verdict of the third-review build (req22): `equal`, all 9 recordings (module 669 area-damage text is silent; this is the safe reading, unjudged). - 4 kept: `g_extTdf` is in the manifest's data list. 5 fixed: stale notes corrected here. 6 fixed: `U_PITCH`. - Verdict of the fourth-review build: req1 `equal`, all 9 recordings (module 69006 bytes). + +## Spec change (interfaces-v102, reference-traces-v64): interceptor chains + +- Spec diff read: the sweep excludes the projectile being detonated (not every projectile of the same weapon); each + coordinate difference wraps as signed 32-bit before squaring; `areaOfEffect²` is a signed 32-bit product; the two + `SendProjectileDetonated` calls are (attacker, swept projectile) then (attacker, projectile being detonated), after + everything the detonation does; an event-started detonation passes the event record. `FRAME` has 11 words now (the + projectile being detonated is the new one); the bit-14 / 0xfffb feature rules and the DAMAGE `source` text already + matched the code. +- New recording `ai-antinuke-pair` exposed a collision bug that no earlier recording reached: a feature in the cell was + detonating the projectile even when `feature.height + cell.low` was not above the whole y (the spec's step 7 only + lets a feature survive when that test holds). Fixed in `collision`. +- Verdicts in order: req1 differs (ai-antinuke-pair, tick 5920, extra cell lookup); req2/req3 were probes + (detonations disabled) to locate the cause; req4 `equal` on all 10 recordings. +- Unclear: step 7's wording ("when a feature remains and its height plus low is above y: ... A surviving feature + detonates") reads as if a feature below that height still survives; the recording says it does not. diff --git a/weapons/src/lib.rs b/weapons/src/lib.rs index fe75517..961b965 100644 --- a/weapons/src/lib.rs +++ b/weapons/src/lib.rs @@ -1176,7 +1176,7 @@ fn weapon_index(wd: u32) -> i32 { fn detonate(p: u32, hit: u32) { if let Some((wd, pos, owner, att)) = detonate_pre(p, hit) { - area_damage(wd, &pos, owner, att); + area_damage(wd, &pos, owner, att, p); } } @@ -1241,20 +1241,20 @@ fn clampi(v: i32, lo: i32, hi: i32) -> i32 { } /// One level of an interceptor sweep: the weapon, its centre, the attacker, the damage totals, the -/// next projectile index, the count and the projectile whose detonation is running. -const FRAME_WORDS: usize = 10; +/// next projectile index, the count, the projectile being detonated and the one whose announcement is due. +const FRAME_WORDS: usize = 11; /// Every level detonates a distinct live projectile of the table, so 300 levels are the most. const FRAMES: usize = 304; static mut FRAME: [u32; FRAMES * FRAME_WORDS] = [0; FRAMES * FRAME_WORDS]; /// The area damage of a detonation, and the sweeps of the interceptor projectiles it detonates in /// turn, depth first: the levels live in `FRAME`, which is all zero again when this returns. -fn area_damage(wd: u32, c: &V3, owner: i32, att: u32) { +fn area_damage(wd: u32, c: &V3, owner: i32, att: u32, proj: u32) { let frame = unsafe { &mut *core::ptr::addr_of_mut!(FRAME) }; let mut sp = 0usize; - let mut cur = Some((wd, *c, owner, att)); + let mut cur = Some((wd, *c, owner, att, proj)); loop { - if let Some((wd, c, owner, att)) = cur.take() { + if let Some((wd, c, owner, att, pj)) = cur.take() { let (enemy, friendly) = area_sweep(wd, &c, owner, att); if wflags(wd) & WF_INTERCEPTOR != 0 && sp < FRAMES { let f = &mut frame[sp * FRAME_WORDS..(sp + 1) * FRAME_WORDS]; @@ -1268,6 +1268,7 @@ fn area_damage(wd: u32, c: &V3, owner: i32, att: u32) { f[7] = 0; f[8] = r32(game(G_PROJ_COUNT)) as u32; f[9] = 0; + f[10] = pj; sp += 1; } else if att != 0 { hit_effect(att, enemy, friendly); @@ -1281,7 +1282,7 @@ fn area_damage(wd: u32, c: &V3, owner: i32, att: u32) { if f[9] != 0 { unsafe { net_projectile_detonated(att, f[9]); - net_projectile_detonated(att, wd); + net_projectile_detonated(att, f[10]); } f[9] = 0; } @@ -1290,15 +1291,15 @@ fn area_damage(wd: u32, c: &V3, owner: i32, att: u32) { while f[7] < f[8] { let q = proj_at(f[7] as i32); f[7] += 1; - if is_dead(q) || r32(q + P_TYPE) == boff(wd) { + if is_dead(q) || q == f[10] { continue; } - let s = sq_hi64(r32(q + P_POS) as i64 - c[0] as i64) - .wrapping_add(sq_hi64(r32(q + P_POS + 4) as i64 - c[1] as i64)) - .wrapping_add(sq_hi64(r32(q + P_POS + 8) as i64 - c[2] as i64)); + let s = sq_hi64(r32(q + P_POS).wrapping_sub(c[0]) as i64) + .wrapping_add(sq_hi64(r32(q + P_POS + 4).wrapping_sub(c[1]) as i64)) + .wrapping_add(sq_hi64(r32(q + P_POS + 8).wrapping_sub(c[2]) as i64)); if s < r2 { f[9] = q; - cur = detonate_pre(q, 0); + cur = detonate_pre(q, 0).map(|(w, p, o, a)| (w, p, o, a, q)); break; } } @@ -1522,12 +1523,16 @@ fn collision(p: u32) { if f < 0xfffb && f < r32(game(G_FEATURE_COUNT)) { feature = lin(r32(game(G_FEATURES))) + f as u32 * 256; } - if feature != 0 && r8(feature + 250) + low > ywhole { - if r16(p + P_CELL_X) == cx && r16(p + P_CELL_Z) == cz { - feature = 0; + if feature != 0 { + if r8(feature + 250) + low > ywhole { + if r16(p + P_CELL_X) == cx && r16(p + P_CELL_Z) == cz { + feature = 0; + } else { + w16(p + P_CELL_X, cx); + w16(p + P_CELL_Z, cz); + } } else { - w16(p + P_CELL_X, cx); - w16(p + P_CELL_Z, cz); + feature = 0; } } if feature != 0 { @@ -2869,7 +2874,7 @@ pub extern "C" fn Apply(ev: u32, size: u32) -> i32 { return 0; } let wd = weapons_base() + widx as u32 * W_SIZE; - area_damage(wd, &rd3(ev + 12), 0, 0); + area_damage(wd, &rd3(ev + 12), 0, 0, ev); 1 } 266 => { From 203f94b5231e516d202f7e2162cd27b0c127c915 Mon Sep 17 00:00:00 2001 From: Oscar Bailey <79094698+ozgb@users.noreply.github.com> Date: Mon, 30 Nov 2026 01:40:43 +0000 Subject: [PATCH 5/9] Update: State the collision rule's feature height test The recording ai-antinuke-pair showed that a feature not above the projectile's whole y must not detonate it, which step 7 left open. Assisted-by: Claude:claude-sonnet-5-5 --- specs/weapons.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/specs/weapons.md b/specs/weapons.md index f1155b2..eba2ae9 100644 --- a/specs/weapons.md +++ b/specs/weapons.md @@ -485,10 +485,12 @@ Given a projectile *p* and its weapon, at its position: 7. Features: *cx* = the whole *x* ÷ 16 and *cz* = the whole *z* ÷ 16, both as signed 16-bit. The cell's `feature` *f* is resolved: *f* below 0xfffb is `Game.features[f]` when *f* is below `Game.featureCount`, else none; 0xfffe means the cell's origin (the cell at `offsetX` and `offsetY` - back, whose feature is used), and any other value of 0xfffb and above none. When a feature remains and - its `height` plus the cell's `low` is above the whole *y*: when the projectile's `cellX` and `cellZ` - already equal *cx* and *cz* the feature is dropped (the projectile already hit this cell), else they - become *cx* and *cz*. A surviving feature detonates *p* with no unit and the rule ends. + back, whose feature is used), and any other value of 0xfffb and above none. A feature whose `height` + plus the cell's `low` is not above the whole *y* is dropped, and a feature that is above it is dropped + too when the projectile's `cellX` and `cellZ` already equal *cx* and *cz* (the projectile already hit + this cell); otherwise `cellX` and `cellZ` become *cx* and *cz*, and that feature survives (`cellX` and + `cellZ` change only in this case). A surviving feature detonates *p* with no unit + and the rule ends. 8. When the cell's `low` is above the whole *y*: a weapon with `groundBounce` set gets `direction.y = −(direction.y >> 2)` (arithmetic shift) and the rule ends without a detonation; any other weapon detonates *p* with no unit and the rule ends. From eb33e722530cc4799b9c921756c45892b5c59a10 Mon Sep 17 00:00:00 2001 From: Implementer Date: Mon, 30 Nov 2026 01:44:52 +0000 Subject: [PATCH 6/9] Fix: Address review and merge the spec change Assisted-by: Claude Code:claude-sonnet-5-5 --- weapons/IMPLEMENTATION-NOTES.md | 9 ++++++++- weapons/src/lib.rs | 13 +++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/weapons/IMPLEMENTATION-NOTES.md b/weapons/IMPLEMENTATION-NOTES.md index 7a7a134..45179bf 100644 --- a/weapons/IMPLEMENTATION-NOTES.md +++ b/weapons/IMPLEMENTATION-NOTES.md @@ -103,7 +103,7 @@ Verdict of the third-review build (req22): `equal`, all 9 recordings (module 669 ## Fourth review: answers - 1 fixed: `area_damage` is iterative. The levels of nested interceptor sweeps live in a static `FRAME` array (304 - levels of 10 words; every level detonates a distinct live projectile, so the 300-entry table bounds the depth), + levels of 10 words; a chain of up to 300 levels is the contract; a noExplode interceptor could chain deeper, which is out of contract, and the extra level takes the plain hit branch), each frame zeroed when popped, so the statics are unchanged after a tick. `detonate` is split into `detonate_pre` (up to the area damage, which it returns) and the loop runs it, keeping the depth-first order of events and `SendProjectileDetonated` calls. The old `DEPTH` static and the cap of 12 are gone; the stack no longer grows with depth. @@ -128,3 +128,10 @@ Verdict of the third-review build (req22): `equal`, all 9 recordings (module 669 (detonations disabled) to locate the cause; req4 `equal` on all 10 recordings. - Unclear: step 7's wording ("when a feature remains and its height plus low is above y: ... A surviving feature detonates") reads as if a feature below that height still survives; the recording says it does not. + +## Fifth review and spec merge (interfaces-v102) + +- Merged `spec-weapons-1338`. The step 7 feature rule (a feature not above the cell is dropped) was already what the code does; the spec now says it. +- DETONATE 258 now passes the event record `ev` to `SendProjectileDetonated` (`detonate_as`), not a stack address. +- The area radius squared uses `wrapping_mul`, so it does not depend on the overflow-checks profile. +- Chain depth comment/notes corrected: 300 levels is the contract, not a guarantee for noExplode chains. diff --git a/weapons/src/lib.rs b/weapons/src/lib.rs index 961b965..d5e2955 100644 --- a/weapons/src/lib.rs +++ b/weapons/src/lib.rs @@ -1175,8 +1175,13 @@ fn weapon_index(wd: u32) -> i32 { } fn detonate(p: u32, hit: u32) { + detonate_as(p, hit, p); +} + +/// `detonate` with `proj` as the record the area damage announces (an event's record for events). +fn detonate_as(p: u32, hit: u32, proj: u32) { if let Some((wd, pos, owner, att)) = detonate_pre(p, hit) { - area_damage(wd, &pos, owner, att, p); + area_damage(wd, &pos, owner, att, proj); } } @@ -1243,7 +1248,7 @@ fn clampi(v: i32, lo: i32, hi: i32) -> i32 { /// One level of an interceptor sweep: the weapon, its centre, the attacker, the damage totals, the /// next projectile index, the count, the projectile being detonated and the one whose announcement is due. const FRAME_WORDS: usize = 11; -/// Every level detonates a distinct live projectile of the table, so 300 levels are the most. +/// Room for every chain of up to 300 levels (the contract); a `noExplode` chain can be deeper, and is cut here. const FRAMES: usize = 304; static mut FRAME: [u32; FRAMES * FRAME_WORDS] = [0; FRAMES * FRAME_WORDS]; @@ -1287,7 +1292,7 @@ fn area_damage(wd: u32, c: &V3, owner: i32, att: u32, proj: u32) { f[9] = 0; } let c = [f[1] as i32, f[2] as i32, f[3] as i32]; - let r2 = (r16u(wd + W_AOE) * r16u(wd + W_AOE)) as i32; + let r2 = r16u(wd + W_AOE).wrapping_mul(r16u(wd + W_AOE)); while f[7] < f[8] { let q = proj_at(f[7] as i32); f[7] += 1; @@ -2805,7 +2810,7 @@ pub extern "C" fn Apply(ev: u32, size: u32) -> i32 { w32(p + P_TYPE, boff(wd)); wr3(p + P_POS, &rd3(u + U_POS)); w8(p + P_OWNER, r8(u + U_PLAYER_INDEX)); - detonate(p, 0); + detonate_as(p, 0, ev); } 1 } From 6af2d36b8bbfecb02f37eba2f9800b1fc459ab02 Mon Sep 17 00:00:00 2001 From: Oscar Bailey <79094698+ozgb@users.noreply.github.com> Date: Mon, 30 Nov 2026 01:58:35 +0000 Subject: [PATCH 7/9] Update: Settle the event announcement and the aim heading A detonation an event starts passes 0 as the second announced projectile, and a lineOfSight turret's heading subtracts the unit's. Assisted-by: Claude:claude-sonnet-5-5 --- specs/weapons.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/specs/weapons.md b/specs/weapons.md index eba2ae9..6ff5812 100644 --- a/specs/weapons.md +++ b/specs/weapons.md @@ -424,8 +424,9 @@ each square summed as signed 32-bit numbers) is below `areaOfEffect²` (the 16-b value of 46341 or more squares to a negative number), is detonated with no unit, and `network.SendProjectileDetonated` is called twice: with the attacker and that projectile, then with the attacker and the projectile being detonated (the one whose sweep this is). A detonation that an -AREA_DAMAGE or DETONATE event starts has no projectile of the table to pass: the second call's -argument is the event's own record, which no recording holds (the call acts only in a network game). A detonated interceptor projectile whose own detonation reaches the area +AREA_DAMAGE or DETONATE event starts has no projectile of the table to pass: the call's second +argument is the event's own record, which is no block address, so a module passes 0 there (the call +acts only in a network game, and no recording holds one). A detonated interceptor projectile whose own detonation reaches the area damage sweeps in turn, inside the sweep that detonated it. The two announcements of a projectile follow everything its detonation does, the sweeps nested in it included: in `ai-antinuke-pair` at tick 5926, interceptor projectile 3 (attacker `Unit#252`) detonates projectile @@ -793,7 +794,7 @@ For each slot *w* from 0 to 2, in order: - With the slot's weapon `ballistic`: `scripts.GetAimFromPosition` gives the aim point; the differences to *pos* give the heading (`heading(dx, dz) − u.heading`, 16 bits) and the pitch (the launch angle rule of (dx, dy, dz, speed, pitch)); a pitch of 0x8000 means no aim. With `lineOfSight`: the heading - is `heading` of the differences, and the pitch is `heading` of minus *dy*'s whole part and of the + is `heading` of the differences minus `u.heading` (16 bits), and the pitch is `heading` of minus *dy*'s whole part and of the truncated `distance(dx, dz)` cut to 16 bits; any other weapon has no aim. - With no aim: the slot's bit 0 is cleared, OUT_OF_REACH is published and the handler returns 0. When the aim tolerance test (below) fails: the slot's bit 0 is cleared and it returns 0. From 98e04ffec5f33144ea2883f14fe3afa544b6bec7 Mon Sep 17 00:00:00 2001 From: Implementer Date: Mon, 30 Nov 2026 02:00:18 +0000 Subject: [PATCH 8/9] Fix: Follow the event argument and wrap chase test Assisted-by: Claude Code:claude-sonnet-5-5 --- weapons/IMPLEMENTATION-NOTES.md | 10 ++++++++++ weapons/src/lib.rs | 12 ++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/weapons/IMPLEMENTATION-NOTES.md b/weapons/IMPLEMENTATION-NOTES.md index 45179bf..6f5fc95 100644 --- a/weapons/IMPLEMENTATION-NOTES.md +++ b/weapons/IMPLEMENTATION-NOTES.md @@ -135,3 +135,13 @@ Verdict of the third-review build (req22): `equal`, all 9 recordings (module 669 - DETONATE 258 now passes the event record `ev` to `SendProjectileDetonated` (`detonate_as`), not a stack address. - The area radius squared uses `wrapping_mul`, so it does not depend on the overflow-checks profile. - Chain depth comment/notes corrected: 300 levels is the contract, not a guarantee for noExplode chains. + +## Spec change: event detonation argument and aim heading + +- Merged the new `spec-weapons-1338` commit. An AREA_DAMAGE or DETONATE event now passes 0 (not the event record) as the + second `SendProjectileDetonated` argument; a `lineOfSight` aim heading is `heading` minus `u.heading` (code already did). + This supersedes the earlier "passes the event record" note and the review's risks 2 and 3. +- Review risk 1 fixed: the interceptor chase test in `collision` wraps each difference to 32 bits and squares + `areaOfEffect` as a signed 32-bit product, like the sweep. +- Verdict of this build (req1): `equal` on all 10 recordings (module 69052 bytes). +- Left as is: the table anchor and `g_extTdf` (needed by the manifest), and the raw frame array (nits 5, 6). diff --git a/weapons/src/lib.rs b/weapons/src/lib.rs index d5e2955..cab0604 100644 --- a/weapons/src/lib.rs +++ b/weapons/src/lib.rs @@ -1489,11 +1489,11 @@ fn collision(p: u32) { let inter = r32(p + P_INTERCEPT); if inter != 0 { let q = lin(inter) + P_POS; - let s = sq_hi64(r32(p + P_POS) as i64 - r32(q) as i64) - .wrapping_add(sq_hi64(r32(p + P_POS + 4) as i64 - r32(q + 4) as i64)) - .wrapping_add(sq_hi64(r32(p + P_POS + 8) as i64 - r32(q + 8) as i64)); + let s = sq_hi64(r32(p + P_POS).wrapping_sub(r32(q)) as i64) + .wrapping_add(sq_hi64(r32(p + P_POS + 4).wrapping_sub(r32(q + 4)) as i64)) + .wrapping_add(sq_hi64(r32(p + P_POS + 8).wrapping_sub(r32(q + 8)) as i64)); let aoe = r16u(wd + W_AOE); - if s < aoe * aoe { + if s < (aoe as i32).wrapping_mul(aoe as i32) { detonate(p, 0); } } @@ -2810,7 +2810,7 @@ pub extern "C" fn Apply(ev: u32, size: u32) -> i32 { w32(p + P_TYPE, boff(wd)); wr3(p + P_POS, &rd3(u + U_POS)); w8(p + P_OWNER, r8(u + U_PLAYER_INDEX)); - detonate_as(p, 0, ev); + detonate_as(p, 0, 0); } 1 } @@ -2879,7 +2879,7 @@ pub extern "C" fn Apply(ev: u32, size: u32) -> i32 { return 0; } let wd = weapons_base() + widx as u32 * W_SIZE; - area_damage(wd, &rd3(ev + 12), 0, 0, ev); + area_damage(wd, &rd3(ev + 12), 0, 0, 0); 1 } 266 => { From 9a3c764ee88fb1b0bdfc77ae46fd7ca5d8d05eb5 Mon Sep 17 00:00:00 2001 From: Implementer Date: Mon, 30 Nov 2026 02:03:46 +0000 Subject: [PATCH 9/9] Docs: Fix stale notes found in the review Assisted-by: Claude Code:claude-sonnet-5-5 --- weapons/IMPLEMENTATION-NOTES.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/weapons/IMPLEMENTATION-NOTES.md b/weapons/IMPLEMENTATION-NOTES.md index 6f5fc95..ea6db1a 100644 --- a/weapons/IMPLEMENTATION-NOTES.md +++ b/weapons/IMPLEMENTATION-NOTES.md @@ -132,7 +132,7 @@ Verdict of the third-review build (req22): `equal`, all 9 recordings (module 669 ## Fifth review and spec merge (interfaces-v102) - Merged `spec-weapons-1338`. The step 7 feature rule (a feature not above the cell is dropped) was already what the code does; the spec now says it. -- DETONATE 258 now passes the event record `ev` to `SendProjectileDetonated` (`detonate_as`), not a stack address. +- DETONATE 258 went through `detonate_as` (first passing the event record; superseded below: it now passes 0). - The area radius squared uses `wrapping_mul`, so it does not depend on the overflow-checks profile. - Chain depth comment/notes corrected: 300 levels is the contract, not a guarantee for noExplode chains. @@ -145,3 +145,8 @@ Verdict of the third-review build (req22): `equal`, all 9 recordings (module 669 `areaOfEffect` as a signed 32-bit product, like the sweep. - Verdict of this build (req1): `equal` on all 10 recordings (module 69052 bytes). - Left as is: the table anchor and `g_extTdf` (needed by the manifest), and the raw frame array (nits 5, 6). + +## Sixth review + +- Nit fixed: stale notes corrected (`FRAME` has 11 words; event-started detonations pass 0). No code change; the + last submission (req1, `equal` on all 10 recordings) is of the current source.