diff --git a/orders/IMPLEMENTATION-NOTES.md b/orders/IMPLEMENTATION-NOTES.md index 222729b..89d4e24 100644 --- a/orders/IMPLEMENTATION-NOTES.md +++ b/orders/IMPLEMENTATION-NOTES.md @@ -10,7 +10,7 @@ - `src/mem.rs`: raw (unaligned) access to the shared memory and the field offsets of `layout.json` that the module reads (every block record is packed). Pointers in the block are offsets; the code keeps linear addresses and converts with `lin` / `off`. -- `src/api.rs`: the 52 imports of the manifest entry and one function per publish (`services.Emit` +- `src/api.rs`: the 54 imports of the manifest entry and one function per publish (`services.Emit` payloads) and sim event. - `src/ord.rs`: making an order, the list operations, the end of an order, the movement goals (release / attach / approach / ring / marker / move), the shared helpers of the kinds (build gap, @@ -114,10 +114,31 @@ Other notes: - `ce211bf`: `economy.RequestGranted` is imported and called by `BuildWeapon`; judged `equal` on all sixteen recordings. - An earlier attempt at review finding 1 (kinds by `MissionTypeFromName`) was submitted several times and every submission was `differs`, because the replay's order type table `name` words hold no addresses the module can read - the names at. That is a kit gap (SPEC-QUESTIONS #7). Finding 1 is **not fixed**; the attempt was discarded and the - tree reset to `ce211bf`. + the names at. That was then a kit gap (SPEC-QUESTIONS #7); it is resolved since (kinds are found by name with `kid()`). - Resubmitted `ce211bf` unchanged: `equal` (req1 of this session). - Finding 2 (two live `&mut` borrows of `SCRATCH`): fixed. `scratch()` is gone; `scratch_ids/words/big()` return raw field pointers, so no reference to the whole static is formed, and the helpers that run while a list is live touch only other fields. req2: `equal` on all sixteen recordings. -- Findings 3 to 6: unchanged (reclaim pick is still a kit gap; budgets `not_judged`). +- Findings 3 to 6: unchanged (budgets `not_judged`; the reclaim pick is now an import, see below). + +## Update for the v109 kit + +- Order kinds are found by name: `gettype::kid(n)` gives the index of the name of entry `n` of the recordings' table + (`names.rs`) through `MissionTypeFromName` semantics, at each use; `gettype::canon(k)` gives the recordings' number + of table entry `k` by its name. `new_order` callers, kind comparisons, `GetOrderType`'s answers and the queue build + kinds use `kid`; the run of an order is chosen by `canon` of the entry at the order's kind (see SPEC-QUESTIONS 8). +- `map.PickRandomReclaimableResourcesInRadius` is imported; `reclaim_pick` (kinds_b.rs) passes a `PICK` static in the + window and is used by `RepairPatrol` and `VTOL_RepairPatrol` (new row). +- The scratch statics are reached only through raw pointers (`scratch_*()` return `*mut`; the list helpers take + `*mut u32`); no `&mut` to them is formed. +- Verdicts: req1: `equal` on all 20 recordings (including `mission-passes-z-renumbered`, `mission-build-unit`, + `mission-kill-of-type`). +- Unclear: the opaque `notify` word (SPEC-QUESTIONS 8); the earlier questions 2 to 6 stand. + +## Review of the v109 submission + +- Fixed: `PICK` is zeroed before `reclaim_pick` returns, so the statics are byte-identical between calls (ABI 12). +- Fixed: bare kind numbers in `ExpandGroupCommand` (25/54), the three GETBUILT adds (19) and PARK (28) now use `kid()`. +- Fixed: `BuildWeapon` masks the slot once (`& 3`), so the read and the ADD_STOCKPILE publish use the same index. +- Removed dead code (`K_VTOL_LANDING`, `D_UNITNAME`, `alloc_u16_of`, `kind_of`, the `let _ =` leftovers). +- Not part of this pass: findings 4, 5, 7 to 11 and 13 (see SPEC-QUESTIONS.md for 9, 10, 11, 13). diff --git a/orders/SPEC-QUESTIONS.md b/orders/SPEC-QUESTIONS.md index 80c25e2..a32a6e0 100644 --- a/orders/SPEC-QUESTIONS.md +++ b/orders/SPEC-QUESTIONS.md @@ -3,9 +3,7 @@ None of these blocks the recordings route (every recording is `equal`); they are points where the spec or kit leaves a choice that no recording settles. Each was resolved the way stated. -1. **`map.PickRandomReclaimableResourcesInRadius` is not an import of the entry** (spec section 7, - "Gaps in the kit"). The reclaim pick of `RepairPatrol` and `VTOL_RepairPatrol` answers "none". - `economy.RequestGranted` is now imported and called (commit `ce211bf`); `BuildWeapon` uses its answer. +1. **Resolved.** `map.PickRandomReclaimableResourcesInRadius` is now an import of the entry and is called by `RepairPatrol` and `VTOL_RepairPatrol`. 2. **`ReclaimUnit` state 5, BUSY (900).** The row reads "when `radius` >= 15: DAMAGE (V, `ticks`, 5); BUSY (900); the nano point of U; ...". It is not clear whether BUSY belongs to the `radius` >= 15 condition. The module publishes BUSY on every pulse of the row (as `Capture` and `Reclaim` do @@ -22,8 +20,9 @@ the spec or kit leaves a choice that no recording settles. Each was resolved the record at the block base in each case. 6. **Name pointer of the order type table** (`OrderTableEntry.name`): `MissionTypeFromName` reads it as a linear address (what the replayer stores for a `char *`). No recording calls the slot. -7. **Open, waits on the kit: the table `name` words of a replay hold no readable addresses.** Review - finding 1 (order kinds decided through `MissionTypeFromName`, spec section 3 "Order type names") needs - the names of the order type table. In a replay the `name` words of `OrderTableEntry` are not addresses - at which the module can read the names, so every attempt at it was judged `differs`. Not fixed; the - module keeps the kind numbers of the recordings' table. The kit's maintainers are to supply readable names. +7. **Resolved.** The `name` words of the order type table are linear addresses of the names (spec section 3); `MissionTypeFromName` and every kind the module names is found through them. +8. **The `notify` word is opaque.** The spec says the run is the table entry's `notify` word, but the word's value in a replay is the replayer's own address for `orderNotify[j]`, and the kit does not say how a module reads j from it. The module chooses the run by the entry's `name` (which the spec's table pairs with j), so an entry with a name the recordings' table lacks runs as `Ready` (`orderNotify[0]`, as the two extra entries of `mission-passes-z-renumbered.txt` have). A table whose `notify` words differ from the names' pairing would differ; no recording has one. +9. **Bytes after a NUL in a QUEUE_BUILD name.** "N contains MAKENUKE/MAKEANTI anywhere": the module searches all 32 bytes, including those after the first NUL. The spec does not say whether the text ends at the NUL. +10. **Feature numbers 0xfffb to 0xfffe in `Reclaim`, `Resurrect` and `VTOL_Reclaim`.** Only 0xffff is excluded by the spec; `sim-events.md` calls 0xfffb and up markers, not features. The module excludes only 0xffff. +11. **Wake frame 0xffffffff.** "0xffffffff never wakes": the module tests `tick >= wakeFrame` with no exception; the tick 0xffffffff is unreachable in practice. +12. **Capture time with `maxHealth` 0.** Step 3 says only "the division unsigned"; the module returns 0 for a zero divisor to avoid a trap. The spec does not say what the result is. diff --git a/orders/src/api.rs b/orders/src/api.rs index 50b3294..1450070 100644 --- a/orders/src/api.rs +++ b/orders/src/api.rs @@ -82,6 +82,8 @@ extern "C" { #[link(wasm_import_module = "map")] extern "C" { + #[link_name = "PickRandomReclaimableResourcesInRadius"] + pub fn pick_random_reclaimable(p: u32, r: i32, e: u32, e_amount: u32, m: u32, m_amount: u32) -> i32; #[link_name = "UnitsInRange"] pub fn units_in_range(p: u32, r: i32, skip: i32, ids: u32, cap: i32) -> i32; #[link_name = "CanPlaceUnitFootprint"] diff --git a/orders/src/gettype.rs b/orders/src/gettype.rs index e7c758b..56dda11 100644 --- a/orders/src/gettype.rs +++ b/orders/src/gettype.rs @@ -67,7 +67,18 @@ fn feature_check(u: u32, d: u32, bit: u32, p: u32) -> bool { marked(feature_at(p)) } +/// The kind a click gives: its index in the order type table, found by the kind's name. pub fn get_order_type(mode: u32, u: u32, t: u32, p: u32) -> u32 { + let k = order_type_n(mode, u, t, p); + if k == 0 { + 0 + } else { + kid(k) + } +} + +/// The same, as the number of the recordings' table. +fn order_type_n(mode: u32, u: u32, t: u32, p: u32) -> u32 { let mode = mode & 0xff; let d = unit_def(u); let f1 = def_flags1(d); @@ -92,7 +103,7 @@ pub fn get_order_type(mode: u32, u: u32, t: u32, p: u32) -> u32 { 1 => { if ri32(game() + G_INTERFACE_TYPE) == 1 { if has(f2, 0x10) && enemy { - return get_order_type(3, u, t, p); + return order_type_n(3, u, t, p); } if has(f2, 0x400) && enemy { return pick(59, 33); @@ -124,13 +135,13 @@ pub fn get_order_type(mode: u32, u: u32, t: u32, p: u32) -> u32 { return pick(55, 26); } if has(f2, 0x10) && enemy { - return get_order_type(3, u, t, p); + return order_type_n(3, u, t, p); } if has(f2, 0x400) && enemy { - return get_order_type(12, u, t, p); + return order_type_n(12, u, t, p); } if t != 0 && can_repair(t) && build_left_nz(t) { - return get_order_type(8, u, t, p); + return order_type_n(8, u, t, p); } if t != 0 && r8(t + U_PLAYER_INDEX) == r8(game() + G_LOCAL_PLAYER) && has(unit_flags(t), 0x20) && !build_left_nz(t) && ri32(t + U_POST_TRANSFER) == 0 { let c = lin(r32(t + U_CARRIER)); @@ -384,3 +395,29 @@ pub fn mission_type_from_name(name: u32) -> u32 { } 0 } + +/// The kind named by entry `n` of the recordings' table, found by its name at the moment it is used +/// (0, `Ready`, when the table lacks it). +pub fn kid(n: u32) -> u32 { + if n == 0 || n >= 68 { + return n; + } + mission_type_from_name(crate::names::NAMES[n as usize].as_ptr() as u32) +} + +/// The number the recordings' table gives the kind of table entry `k`, by the entry's name: +/// 0xfe when `k` is outside the table, 0xff for a name the recordings' table lacks. +pub fn canon(k: u32) -> u32 { + if k >= table_count() { + return 0xfe; + } + let nm = r32(table_first() + ENTRY_SIZE * k + E_NAME); + let mut j = 0; + while j < 68 { + if strcmpi(nm, crate::names::NAMES[j].as_ptr() as u32) == 0 { + return j as u32; + } + j += 1; + } + 0xff +} diff --git a/orders/src/kinds.rs b/orders/src/kinds.rs index 3a08a23..aa46534 100644 --- a/orders/src/kinds.rs +++ b/orders/src/kinds.rs @@ -8,7 +8,7 @@ use crate::ord::*; /// The run of the order's kind with the order's code: its result. pub fn run_kind(r: &Run) -> u32 { - match r8(r.o + O_KIND) { + match crate::gettype::canon(r8(r.o + O_KIND)) { 0 => k_ready(r), 1 => k_activate(r), 2 => k_air_strike(r), @@ -75,6 +75,7 @@ pub fn run_kind(r: &Run) -> u32 { 65 => k_vtol_unload(r), 66 => k_wait(r), 67 => k_wait_for_attack(r), + 0xff => k_ready(r), _ => 7, } } diff --git a/orders/src/kinds_a.rs b/orders/src/kinds_a.rs index 1f68dba..dd4c5c6 100644 --- a/orders/src/kinds_a.rs +++ b/orders/src/kinds_a.rs @@ -9,12 +9,11 @@ use crate::rt; pub const K_VTOL_SEEKATTACK: u32 = 62; pub const K_VTOL_SEEKGUARD: u32 = 63; pub const K_VTOL_EVADE: u32 = 48; -pub const K_VTOL_LANDING: u32 = 53; pub const K_SELFDESTRUCT: u32 = 38; /// A copy of the order's position, to pass by address. fn seek_attack_tail(r: &Run, t: u32, p: V3) { - let o = new_order(K_VTOL_SEEKATTACK, t, Some(p), 0, 0, 0); + let o = new_order(kid(K_VTOL_SEEKATTACK), t, Some(p), 0, 0, 0); add_tail(r.u, o); } @@ -232,7 +231,7 @@ pub fn k_air_to_air(r: &Run) -> u32 { 2 } else { release(r); - let e = new_order(K_VTOL_EVADE, t, None, 0, 0, 0); + let e = new_order(kid(K_VTOL_EVADE), t, None, 0, 0, 0); insert_front(u, e); set_ticks(o, 0); set_oflags(o, 0); @@ -244,7 +243,7 @@ pub fn k_air_to_air(r: &Run) -> u32 { } pub fn k_air_to_ground(r: &Run) -> u32 { - let (u, o, c, d) = (r.u, r.o, r.c, r.d); + let (u, o, d) = (r.u, r.o, r.d); let w = ri32(blk(r32(u + 4 + 12)) + W_RANGE); if let Some(x) = air_attack_prelude(r, 0x1000a) { return x; @@ -260,7 +259,6 @@ pub fn k_air_to_ground(r: &Run) -> u32 { if leash(r) { return 5; } - let _ = c; let up = upos(u); let op = opos(o); let dist = ftol(rt::hyp(op[0].wrapping_sub(up[0]), op[2].wrapping_sub(up[2]))); @@ -321,12 +319,11 @@ pub fn k_air_to_ground(r: &Run) -> u32 { } pub fn k_air_to_ground_hover(r: &Run) -> u32 { - let (u, o, c, d) = (r.u, r.o, r.c, r.d); + let (u, o, d) = (r.u, r.o, r.d); let w = ri32(blk(r32(u + 4 + 12)) + W_RANGE); if let Some(x) = air_attack_prelude(r, 0x10008) { return x; } - let _ = c; let t = tgt(o); if off_map_return(r) { return 2; @@ -534,7 +531,7 @@ pub fn k_attack_kamikaze(r: &Run) -> u32 { 1 => { if has(c, 0x20) { speech(u, 6, 0); - let s = new_order(K_SELFDESTRUCT, 0, None, 1, 0, 0); + let s = new_order(kid(K_SELFDESTRUCT), 0, None, 1, 0, 0); insert_front(u, s); 5 } else if has(c, 0x40) { @@ -596,7 +593,6 @@ pub fn k_attack_utype(r: &Run) -> u32 { 1 } 1 => { - let g = game(); let end = g_units_end(); let mut best = 0u32; let mut best_score = 0x7fff_ffffi32; @@ -617,7 +613,6 @@ pub fn k_attack_utype(r: &Run) -> u32 { } v = v.wrapping_add(UNIT_SIZE); } - let _ = g; if best == 0 { return 5; } @@ -716,7 +711,7 @@ pub fn k_building_build(r: &Run) -> u32 { speech(u, 9, 30); attach_to_piece(v, u, p, 1); set_stance(v, 3, move_order(u), fire_order(u), 0); - add_order(v, 19, 1, u, None, 0, 0); + add_order(v, kid(19), 1, u, None, 0, 0); set_state_bits(u, 8, 1); menu_update(u); 1 @@ -771,14 +766,14 @@ pub fn centre_of(c: [i16; 2], fx: i32, fy: i32) -> (i32, i32) { pub fn k_build_weapon(r: &Run) -> u32 { let (u, o) = (r.u, r.o); - let w = otick(o) as u32; - let wd = blk(u_weapon_def(u, w & 3)); + let w = otick(o) as u32 & 3; + let wd = blk(u_weapon_def(u, w)); match state(o) { 0 => { if radius(o) <= 0 { return 5; } - if u_weapon_stockpile(u, w & 3) >= 200 { + if u_weapon_stockpile(u, w) >= 200 { wake(o, 300); return 2; } @@ -911,11 +906,6 @@ pub fn k_capture(r: &Run) -> u32 { } } -/// The unit's first order of a guarded unit etc. -fn kind_of(o: u32) -> u32 { - r8(o + O_KIND) -} - pub fn k_follow_ground(r: &Run) -> u32 { let (u, o, c, d) = (r.u, r.o, r.c, r.d); let g = tgt(o); @@ -961,21 +951,21 @@ pub fn k_follow_ground(r: &Run) -> u32 { } } let l = first_order(g); - if l != 0 && kind_of(l) != 0 && has(def_flags1(d), 0x40) && has(def_flags1(unit_def(g)), 0x40) && has(flags42(l), 0x100000) && tgt(l) != u { - let lk = kind_of(l); + if l != 0 && r8(l + O_KIND) != 0 && has(def_flags1(d), 0x40) && has(def_flags1(unit_def(g)), 0x40) && has(flags42(l), 0x100000) && tgt(l) != u { + let lk = r8(l + O_KIND); let lf = flags42(l); let lt = tgt(l); let actionable = (has(lf, 0x200) && lt != 0) || has(lf, 0x400); - if lk != 25 && lk != 12 && actionable { + if lk != kid(25) && lk != kid(12) && actionable { release(r); let no = new_order(lk, lt, Some(opos(l)), 0, 0, 0); insert_front(u, no); set_oflags(o, 0); return 3; } - if (lk == 25 || lk == 12) && lt != 0 { + if (lk == kid(25) || lk == kid(12)) && lt != 0 { release(r); - let no = new_order(23, lt, Some(opos(l)), 0, 0, 0); + let no = new_order(kid(23), lt, Some(opos(l)), 0, 0, 0); insert_front(u, no); set_oflags(o, 0); return 3; @@ -1039,7 +1029,7 @@ fn finish_rule(r: &Run) { if b != 0 { let mut q = first_order(b); while q != 0 { - let k = kind_of(q); + let k = crate::gettype::canon(r8(q + O_KIND)); if k == 30 || k == 31 { let mode = if k == 30 { 2 } else { 9 }; let kk = get_order_type(mode, u, 0, q + O_POS); @@ -1061,7 +1051,7 @@ fn finish_rule(r: &Run) { } } if !added { - add_order(u, 28, 1, 0, None, 0, 0); + add_order(u, kid(28), 1, 0, None, 0, 0); } } diff --git a/orders/src/kinds_b.rs b/orders/src/kinds_b.rs index 10645d2..067ce7e 100644 --- a/orders/src/kinds_b.rs +++ b/orders/src/kinds_b.rs @@ -67,7 +67,7 @@ pub fn k_mobile_build(r: &Run) -> u32 { } speech(u, 9, 30); dirty_mark(u); - add_order(n, 19, 1, u, None, 0, 0); + add_order(n, kid(19), 1, u, None, 0, 0); start_building_script(r, build_heading(u, pos3(n + U_POS))); 1 } @@ -133,8 +133,9 @@ pub fn k_park(r: &Run) -> u32 { } if flying(d) { set_opos(o, upos(u)); - w8(o + O_KIND, 55); - set42(o, (table_flags(55) & !0x600) | (flags42(o) & 0x600)); + let vm = kid(55); + w8(o + O_KIND, vm); + set42(o, (table_flags(vm) & !0x600) | (flags42(o) & 0x600)); return 0; } let mut n = ri16(u + U_FOOTPRINT); @@ -424,7 +425,7 @@ pub fn k_reclaim_unit(r: &Run) -> u32 { } /// The reclaim rows: the first that holds gives a point. -fn reclaim_point(p: u32, e: Option<(V3, f32)>, m: Option<(V3, f32)>) -> Option { +pub fn reclaim_point(p: u32, e: Option<(V3, f32)>, m: Option<(V3, f32)>) -> Option { let en = rf32(p + P_ENERGY) as f64; let me = rf32(p + P_METAL) as f64; let enc = rf32(p + P_ENERGY_CAP) as f64; @@ -452,10 +453,62 @@ fn reclaim_point(p: u32, e: Option<(V3, f32)>, m: Option<(V3, f32)>) -> Option Option<(Option<(V3, f32)>, Option<(V3, f32)>)> { - None +/// The out arguments of the reclaim pick, in the module's window: two cells that hold the +/// addresses of two `Vec3` records, and two floats. +#[repr(C)] +struct Pick { + pos: V3, + e_cell: u32, + m_cell: u32, + e_rec: V3, + m_rec: V3, + e_amount: f32, + m_amount: f32, +} +static mut PICK: Pick = Pick { pos: [0; 3], e_cell: 0, m_cell: 0, e_rec: [0; 3], m_rec: [0; 3], e_amount: 0.0, m_amount: 0.0 }; + +/// The reclaim pick (U.pos, rad): the energy and the metal it found, each a point and an amount. +pub fn reclaim_pick(u: u32, rad: i32) -> Option<(Option<(V3, f32)>, Option<(V3, f32)>)> { + let out = reclaim_pick_run(u, rad); + // Statics are byte-identical between calls (ABI 12). + unsafe { core::ptr::write_bytes(core::ptr::addr_of_mut!(PICK), 0, 1) }; + out +} + +fn reclaim_pick_run(u: u32, rad: i32) -> Option<(Option<(V3, f32)>, Option<(V3, f32)>)> { + use core::ptr::{addr_of_mut, read_volatile, write_volatile}; + let p = addr_of_mut!(PICK); + unsafe { + write_volatile(addr_of_mut!((*p).pos), upos(u)); + write_volatile(addr_of_mut!((*p).e_rec), [0; 3]); + write_volatile(addr_of_mut!((*p).m_rec), [0; 3]); + write_volatile(addr_of_mut!((*p).e_cell), addr_of_mut!((*p).e_rec) as u32); + write_volatile(addr_of_mut!((*p).m_cell), addr_of_mut!((*p).m_rec) as u32); + write_volatile(addr_of_mut!((*p).e_amount), 0.0); + write_volatile(addr_of_mut!((*p).m_amount), 0.0); + let a = pick_random_reclaimable( + addr_of_mut!((*p).pos) as u32, + rad, + addr_of_mut!((*p).e_cell) as u32, + addr_of_mut!((*p).e_amount) as u32, + addr_of_mut!((*p).m_cell) as u32, + addr_of_mut!((*p).m_amount) as u32, + ); + if a == 0 { + return None; + } + let one = |cell: *mut u32, rec: *mut V3, amount: *mut f32| { + if read_volatile(cell) == 0 { + None + } else { + let q = read_volatile(rec); + Some(([q[0], 0, q[2]], read_volatile(amount))) + } + }; + let e = one(addr_of_mut!((*p).e_cell), addr_of_mut!((*p).e_rec), addr_of_mut!((*p).e_amount)); + let m = one(addr_of_mut!((*p).m_cell), addr_of_mut!((*p).m_rec), addr_of_mut!((*p).m_amount)); + Some((e, m)) + } } pub fn k_repair_patrol(r: &Run) -> u32 { @@ -484,11 +537,11 @@ pub fn k_repair_patrol(r: &Run) -> u32 { let low = en < enc * 0.2 || me < mec * 0.2; let mut found = 0u32; if en >= enc * 0.2 { - let list = unsafe { &mut *scratch_big() }; + let list = scratch_big().cast::(); let n = repairable_list(u, ri16(d + D_RANGE).wrapping_shl(16), list); if n > 0 { let i = unsafe { random_int(n as i32) } as usize; - let v = list[i]; + let v = unsafe { list.add(i).read() }; if allied(p, player_index(unit_player(v))) { let k = get_order_type(8, u, v, 0); if k != 0 { @@ -504,7 +557,7 @@ pub fn k_repair_patrol(r: &Run) -> u32 { if let Some((e, m)) = reclaim_pick(u, ri16(d + D_RANGE).wrapping_shl(16)) { if let Some(x) = reclaim_point(p, e, m) { release(r); - let no = new_order(32, 0, Some(x), 0, 0, 0); + let no = new_order(kid(32), 0, Some(x), 0, 0, 0); insert_front(u, no); release(r); set_oflags(o, 0); @@ -875,7 +928,7 @@ pub fn k_standby_mine(r: &Run) -> u32 { 1 => { let v = unsafe { find_best_target_if_fire_at_will(u) }; if v != 0 && unit_flags(v) & 3 == 1 && has(unit_flags(u), UF_FIRE_ORDER) { - let s = new_order(K_SELFDESTRUCT, 0, None, 1, 0, 0); + let s = new_order(kid(K_SELFDESTRUCT), 0, None, 1, 0, 0); insert_front(u, s); return 5; } @@ -916,7 +969,7 @@ pub fn k_stop(r: &Run) -> u32 { t_clear(u, 1); t_clear(u, 2); if unit_flags(u) & 3 == 2 && flying(r.d) { - let no = new_order(52, 0, Some(upos(u)), 0, 0, 0); + let no = new_order(kid(52), 0, Some(upos(u)), 0, 0, 0); insert_front(u, no); } 5 diff --git a/orders/src/kinds_c.rs b/orders/src/kinds_c.rs index ffe15c1..afaffb3 100644 --- a/orders/src/kinds_c.rs +++ b/orders/src/kinds_c.rs @@ -73,7 +73,7 @@ pub fn k_vtol_follow(r: &Run) -> u32 { let t = tgt(o); if t == 0 || has(c, 0x48) { if r32(o + O_NEXT) == 0 { - let no = new_order(K_VTOL_SEEKGUARD, t, Some(opos(o)), 0, 0, 0); + let no = new_order(kid(K_VTOL_SEEKGUARD), t, Some(opos(o)), 0, 0, 0); add_tail(u, no); } return 5; @@ -132,18 +132,19 @@ pub fn k_vtol_follow(r: &Run) -> u32 { let lk = r8(l + O_KIND); let lf = flags42(l); let lt = tgt(l); - let building = lk == 25 || lk == 12 || lk == 54; + let lc = canon(lk); + let building = lc == 25 || lc == 12 || lc == 54; let actionable = (has(lf, 0x200) && lt != 0) || has(lf, 0x400); if !building && actionable { release(r); - let no = new_order(vtol_kind(lk), lt, Some(opos(l)), 0, 0, 0); + let no = new_order(if vtol_kind(lc) == lc { lk } else { kid(vtol_kind(lc)) }, lt, Some(opos(l)), 0, 0, 0); insert_front(u, no); set_oflags(o, 0); return 3; } if building && lt != 0 { release(r); - let no = new_order(51, lt, Some(opos(l)), 0, 0, 0); + let no = new_order(kid(51), lt, Some(opos(l)), 0, 0, 0); insert_front(u, no); set_oflags(o, 0); return 3; @@ -371,8 +372,8 @@ pub fn k_vtol_landing(r: &Run) -> u32 { } } 1 => { - let inner = landing_pad_search(r, h, -1); - let p = landing_pad_search(r, h, inner); + let inner = landing_pad_search(h, -1); + let p = landing_pad_search(h, inner); if p != -1 { set_state(o, 2); 2 @@ -394,7 +395,7 @@ pub fn k_vtol_landing(r: &Run) -> u32 { 1 } 3 => { - let p = landing_pad_search(r, h, -1); + let p = landing_pad_search(h, -1); set_ticks(o, p); if p == -1 { speech(u, 7, 16); @@ -411,7 +412,7 @@ pub fn k_vtol_landing(r: &Run) -> u32 { if has(c, 0x20) { return 1; } - let p = landing_pad_search(r, h, otick(o)); + let p = landing_pad_search(h, otick(o)); set_ticks(o, p); if p == -1 { speech(u, 7, 14); @@ -446,7 +447,7 @@ pub fn k_vtol_landing(r: &Run) -> u32 { let hd = unit_def(h); if health_below(u, max_health(d)) && has(def_flags1(hd), 0x200) && has(def_flags1(hd), 0x40) && build_left_zero(h) { release(r); - let no = new_order(40, h, None, 0, 0, 0); + let no = new_order(kid(40), h, None, 0, 0, 0); insert_front(u, no); } } @@ -521,7 +522,7 @@ pub fn k_vtol_mobile_build(r: &Run) -> u32 { return 8; } speech(u, 9, 30); - add_order(t, 19, 1, u, None, 0, 0); + add_order(t, kid(19), 1, u, None, 0, 0); start_building_script(r, build_heading(u, upos_of(t))); dirty_mark(u); 1 @@ -862,11 +863,11 @@ pub fn k_vtol_repair_patrol(r: &Run) -> u32 { let mut a1 = 0; let mut a2 = 0; if en >= enc * 0.2 { - let list = unsafe { &mut *scratch_big() }; + let list = scratch_big().cast::(); let n = repairable_list(u, ri16(d + D_RANGE).wrapping_shl(16), list); if n > 0 { let i = unsafe { random_int(n as i32) } as usize; - v = list[i]; + v = unsafe { list.add(i).read() }; a1 = unsafe { can_repair(u, v) }; if a1 == 0 || rf32(v + U_BUILD_LEFT) != 0.0 { a2 = unsafe { can_repair(u, v) }; @@ -878,18 +879,26 @@ pub fn k_vtol_repair_patrol(r: &Run) -> u32 { } if v != 0 && a2 != 0 && rf32(v + U_BUILD_LEFT) != 0.0 { release(r); - let no = new_order(51, v, None, 0, 0, 0); + let no = new_order(kid(51), v, None, 0, 0, 0); insert_front(u, no); set_oflags(o, 0); return 3; } + if let Some((e, m)) = reclaim_pick(u, 0xf00000) { + if let Some(x) = reclaim_point(p, e, m) { + release(r); + let no = new_order(kid(58), 0, Some(x), 0, 0, 0); + insert_front(u, no); + set_oflags(o, 0); + return 3; + } + } 2 } _ => 7, } } - pub fn k_vtol_repair_unit(r: &Run) -> u32 { let (u, o, c, d) = (r.u, r.o, r.c, r.d); let t = tgt(o); @@ -1036,10 +1045,10 @@ pub fn k_vtol_seek_guard(r: &Run) -> u32 { if pad_diversion(r) { return 0; } - let list = unsafe { &mut *scratch_big() }; + let list = scratch_big().cast::(); let n = ground_allies(u, ri16(d + D_RANGE).wrapping_shl(16), list); if n >= 1 { - let a = list[0]; + let a = unsafe { list.read() }; release(r); let k = get_order_type(7, u, a, 0); let no = new_order(k, a, None, 0, 0, 0); @@ -1097,7 +1106,7 @@ pub fn k_vtol_standby(r: &Run) -> u32 { set_state(o, 1); return 2; } - let no = new_order(52, 0, Some(opos(o)), 0, 0, 0); + let no = new_order(kid(52), 0, Some(opos(o)), 0, 0, 0); insert_front(u, no); return 5; } diff --git a/orders/src/lib.rs b/orders/src/lib.rs index 13334d2..6d51f43 100644 --- a/orders/src/lib.rs +++ b/orders/src/lib.rs @@ -9,6 +9,7 @@ mod kinds_a; mod kinds_b; mod kinds_c; mod mem; +mod names; mod ord; mod rt; mod slots; diff --git a/orders/src/mem.rs b/orders/src/mem.rs index 1525762..c31be66 100644 --- a/orders/src/mem.rs +++ b/orders/src/mem.rs @@ -191,7 +191,6 @@ pub const O_ATTACHED: u32 = 82; pub const ORDER_SIZE: u32 = 86; // ---- UnitDef ---- -pub const D_UNITNAME: u32 = 32; pub const D_MIN_X: u32 = 350; pub const D_MIN_Y: u32 = 354; pub const D_MIN_Z: u32 = 358; diff --git a/orders/src/names.rs b/orders/src/names.rs new file mode 100644 index 0000000..bfd68c8 --- /dev/null +++ b/orders/src/names.rs @@ -0,0 +1,72 @@ +//! The kinds of the recordings' table, by name: the module finds a kind by its name in the table in the block. + +pub static NAMES: [&[u8]; 68] = [ + b"\0", + b"Activate\0", + b"AirStrike\0", + b"AirToAir\0", + b"AirToGround\0", + b"AirToGroundHover\0", + b"Attack_Chase\0", + b"Attack_Kamikaze\0", + b"Attack_NoMove\0", + b"AttackSpecial\0", + b"AttackUType\0", + b"BeCarried\0", + b"BuildingBuild\0", + b"BuildWeapon\0", + b"Capture\0", + b"Cloak_Off\0", + b"Cloak_On\0", + b"Deactivate\0", + b"Follow_Ground\0", + b"GetBuilt\0", + b"Ground_Pickup\0", + b"Ground_Unload\0", + b"Guard_NoMove\0", + b"HelpBuild\0", + b"MakeSelectable\0", + b"MobileBuild\0", + b"Move_Ground\0", + b"Paralyze\0", + b"Park\0", + b"Patrol\0", + b"QMove\0", + b"QPatrol\0", + b"Reclaim\0", + b"ReclaimUnit\0", + b"RepairPatrol\0", + b"RepairUnit\0", + b"RepairUnitNoMove\0", + b"Resurrect\0", + b"SelfDestruct\0", + b"SelfDestructFG\0", + b"SelfRepair\0", + b"Standby\0", + b"Standby_Mine\0", + b"Standing_FireOrder\0", + b"Standing_MoveOrder\0", + b"Stop\0", + b"Suppress\0", + b"Teleport\0", + b"VTOL_Evade\0", + b"VTOL_Follow\0", + b"VTOL_GetRepaired\0", + b"VTOL_HelpBuild\0", + b"VTOL_LandIfCan\0", + b"VTOL_Landing\0", + b"VTOL_MobileBuild\0", + b"VTOL_Move\0", + b"VTOL_Patrol\0", + b"VTOL_Pickup\0", + b"VTOL_Reclaim\0", + b"VTOL_ReclaimUnit\0", + b"VTOL_RepairPatrol\0", + b"VTOL_RepairUnit\0", + b"VTOL_SeekAttack\0", + b"VTOL_SeekGuard\0", + b"VTOL_Standby\0", + b"VTOL_Unload\0", + b"Wait\0", + b"WaitForAttack\0", +]; diff --git a/orders/src/ord.rs b/orders/src/ord.rs index 8b220dc..ddba004 100644 --- a/orders/src/ord.rs +++ b/orders/src/ord.rs @@ -2,6 +2,7 @@ use crate::api::*; use crate::mem::*; +use crate::gettype::kid; use crate::rt; /// A run of an order: the unit, the order, the code and the unit's type. @@ -252,11 +253,6 @@ pub fn allied(p: u32, idx: u32) -> bool { pub fn player_index(p: u32) -> u32 { r8(p + P_INDEX) } -#[inline(always)] -pub fn alloc_u16_of(u: u32) -> u32 { - r16(u + U_DEF_INDEX) -} - /// Whether a type set at block offset `s` contains type number t (unbounded read). pub fn set_contains(s: u32, t: u32) -> bool { let a = base().wrapping_add(s).wrapping_add(4 * (t >> 5)); @@ -733,7 +729,7 @@ pub fn climb(r: &Run) { // ---- unit lists from imports ---- /// The units in range (P, rad): their records, appended to `out`; returns the count. -pub fn units_in_range(p: u32, rad: i32, out: &mut [u32; BIG_LEN]) -> usize { +pub fn units_in_range(p: u32, rad: i32, out: *mut u32) -> usize { let mut n = 0usize; let mut skip = 0i32; let ids = scratch_ids() as u32; @@ -743,7 +739,8 @@ pub fn units_in_range(p: u32, rad: i32, out: &mut [u32; BIG_LEN]) -> usize { let mut i = 0; while i < g { if n < BIG_LEN { - out[n] = g_units().wrapping_add(UNIT_SIZE.wrapping_mul(unsafe { (*scratch_ids())[i] } as u32)); + let id = unsafe { scratch_ids().cast::().add(i).read() }; + unsafe { out.add(n).write(g_units().wrapping_add(UNIT_SIZE.wrapping_mul(id as u32))) }; n += 1; } i += 1; @@ -780,14 +777,14 @@ pub fn repairable(u: u32, v: u32) -> bool { } /// The repairable list (r) of U. -pub fn repairable_list(u: u32, rad: i32, out: &mut [u32; BIG_LEN]) -> usize { +pub fn repairable_list(u: u32, rad: i32, out: *mut u32) -> usize { let up = u + U_POS; let n = units_in_range(up, rad, out); let mut k = 0; let mut i = 0; while i < n { - if repairable(u, out[i]) { - out[k] = out[i]; + if repairable(u, unsafe { out.add(i).read() }) { + unsafe { out.add(k).write(out.add(i).read()) }; k += 1; } i += 1; @@ -796,17 +793,17 @@ pub fn repairable_list(u: u32, rad: i32, out: &mut [u32; BIG_LEN]) -> usize { } /// The ground allies (r) of U. -pub fn ground_allies(u: u32, rad: i32, out: &mut [u32; BIG_LEN]) -> usize { +pub fn ground_allies(u: u32, rad: i32, out: *mut u32) -> usize { let n = units_in_range(u + U_POS, rad, out); let up = unit_player(u); let ui = player_index(up); let mut k = 0; let mut i = 0; while i < n { - let v = out[i]; + let v = unsafe { out.add(i).read() }; let vp = unit_player(v); if allied(vp, ui) && !has(def_flags1(unit_def(v)), 0x800) && v != u { - out[k] = v; + unsafe { out.add(k).write(v) }; k += 1; } i += 1; @@ -862,14 +859,14 @@ pub fn pad_diversion(r: &Run) -> bool { release(r); let k = unsafe { random_int(n as i32) }; let pad = lin(r32(buf + 4 * (k as u32))); - let o = new_order(53, pad, None, 0, 0, 0); + let o = new_order(kid(53), pad, None, 0, 0, 0); insert_front(r.u, o); set_oflags(r.o, 0); true } /// The landing pad search (H, p): the slot found, or -1. -pub fn landing_pad_search(r: &Run, h: u32, p: i32) -> i32 { +pub fn landing_pad_search(h: u32, p: i32) -> i32 { if p != -1 && unsafe { is_pad_slot_free(h, p) } != 0 { return p; } @@ -885,7 +882,6 @@ pub fn landing_pad_search(r: &Run, h: u32, p: i32) -> i32 { ); } let q = unsafe { core::ptr::read_volatile(&q) }; - let _ = r; let mut i = 0; while i < 4 { if q[i] != -1 && unsafe { is_pad_slot_free(h, q[i]) } != 0 { diff --git a/orders/src/slots.rs b/orders/src/slots.rs index 0b9f8a1..b1c3970 100644 --- a/orders/src/slots.rs +++ b/orders/src/slots.rs @@ -94,7 +94,7 @@ pub fn apply(ev: u32, size: u32) -> u32 { let c = lin(r32(u + U_CARRIER)); if c != 0 { delete_all(u, false); - let o = new_order(11, c, None, 0, 0, 0); + let o = new_order(kid(11), c, None, 0, 0, 0); insert_front(u, o); } 1 @@ -110,10 +110,10 @@ pub fn apply(ev: u32, size: u32) -> u32 { } 294 => { let f = first_order(u); - if f != 0 && r8(f + O_KIND) == 27 { + if f != 0 && r8(f + O_KIND) == kid(27) { set_ticks(f, otick(f).wrapping_add(ri32(ev + 8))); } else { - let o = new_order(27, 0, None, ri32(ev + 8), 0, 0); + let o = new_order(kid(27), 0, None, ri32(ev + 8), 0, 0); insert_front(u, o); } 1 @@ -193,7 +193,7 @@ fn queue_build(u: u32, count: i32, name_at: u32) { let k; let id: i32; if contains_bytes(&name, b"MAKENUKE") || contains_bytes(&name, b"MAKEANTI") { - k = 13u32; + k = kid(13); id = 0; } else { let a = unsafe { find_unit_type_id(name.as_ptr() as u32) } as u32 & 0xffff; @@ -201,7 +201,7 @@ fn queue_build(u: u32, count: i32, name_at: u32) { return; } id = a as i32; - k = if has_motion(u) { 25 } else { 12 }; + k = if has_motion(u) { kid(25) } else { kid(12) }; } let second = table_flags(k) & 0x40000 != 0; let cell = u + if second { U_LIST2 } else { U_LIST }; @@ -344,7 +344,7 @@ pub fn expand_group_command(cmd: u32, size: u32) -> u32 { if u != x { let k = if mode == 0 { ty & 0xff } else { get_order_type(mode, u, x, cmd + 28) & 0xff }; let d = unit_def(u); - let skip = k == 0 || (k == 43 && r8(d + D_FLAGS2) & 0x2 == 0) || (k == 44 && r8(d + D_FLAGS2) & 0x1 == 0); + let skip = k == 0 || (k == kid(43) && r8(d + D_FLAGS2) & 0x2 == 0) || (k == kid(44) && r8(d + D_FLAGS2) & 0x1 == 0); if !skip { let mut ps = pos; if has_pos && table_flags(k) & 0x2 != 0 { @@ -373,7 +373,7 @@ pub fn expand_group_command(cmd: u32, size: u32) -> u32 { let d = unit_def(u); let f1 = def_flags1(d); if has(f1, 0x40) { - let k = if has(f1, 0x800) { 54 } else { 25 }; + let k = if has(f1, 0x800) { kid(54) } else { kid(25) }; let (hp, pp) = if has_pos { (true, pos) } else { (false, [0, 0, 0]) }; command(u, k, queue, 0, hp, pp, p0, p1); count += 1; diff --git a/specs/orders.md b/specs/orders.md index 4b4c467..275bebb 100644 --- a/specs/orders.md +++ b/specs/orders.md @@ -45,7 +45,7 @@ and 9.1): - `name` and `interface`: `orders`. - `majors`: `orders` 6, `movement` 5, `units` 7, `scripts` 3, `weapons` 4, `map` 9, `network` 2, `los_radar` 5, - `features` 5, `targeting` 4, `mission` 2, `services` 4. + `features` 5, `targeting` 4, `mission` 2, `economy` 5, `services` 4. - `data_base` 458752 (0x70000) and `table_base` 304: the module's window of `window` (32768) bytes and its `table_slots` table entries (ABI 2.2 and 2.3). Everything the module keeps outside the block (none between calls: ABI section 12) and every buffer it passes to an import lies in that window. @@ -125,6 +125,7 @@ and only its low byte is used. | `map.SnapWorldPosToFootprint` | `[block, linear] -> void` | `MobileBuild`, `VTOL_MobileBuild`: the build site | | `map.CanPlaceFootprintAt` | `[block, linear] -> int` | `VTOL_LandIfCan` | | `map.IsPadSlotFree` | `[block, int] -> int` | "the landing pad search", `VTOL_Landing` state 6 | +| `map.PickRandomReclaimableResourcesInRadius` | `[linear, int, linear, linear, linear, linear] -> int` | "the reclaim pick": `RepairPatrol`, `VTOL_RepairPatrol` | | `map.GetGroundHeight` | `[linear] -> int` | "the site point", "the feature box", `VTOL_LandIfCan`, `VTOL_Reclaim` | | `network.SendFeatureReclaimed` | `[block, int, int] -> void` | `Resurrect` state 5, in game type 3 | | `network.SendScriptCall` | `[block, int, int, int, int, int, int] -> int` | "start the building script", "stop the building script" | @@ -149,16 +150,16 @@ and only its low byte is used. The recordings carry `services.Emit` as `services.SchedPublish 3 ` (3 is orders' outbox), `targeting.FindBestTargetIfFireAtWill` as `services.ScheduleTargetingFireAtWill`, `targeting.GetWeaponTargetUnit` as `services.ScheduleTargetingTargetUnit`, `map.CanPlaceUnitFootprint` as -`services.ScheduleMapCanPlaceUnitFootprint` and `economy.RequestGranted` as `services.ScheduleEconomyRequestGranted` -(ABI 9.3, "Routes in the recordings"). A line of the last gives the unit and the resources, then the answer: +`services.ScheduleMapCanPlaceUnitFootprint`, `economy.RequestGranted` as `services.ScheduleEconomyRequestGranted` and +`map.PickRandomReclaimableResourcesInRadius` as `services.ScheduleMapPickReclaimable` (ABI 9.3, "Routes in the recordings"). +A line of `economy.RequestGranted` gives the unit and the resources, then the answer: `i services.ScheduleEconomyRequestGranted Unit#2 3 = 1` (`orders-weapon-build.txt`, tick 700). -**A call that is not in the entry.** Section 4 names one more call, "the reclaim pick" -(`map.PickRandomReclaimableResourcesInRadius`, whose signature the manifest has under `signatures.map`, and which -`docs/schedule.md` lists among the imports of `orders.RunOrders`), in `RepairPatrol` and `VTOL_RepairPatrol`. It is -not an import of the entry above, and the module imports the entry's imports and nothing else (ABI 9.1). It is a kit -gap ("Gaps in the kit"): the rows of section 4 that use it are the behaviour, and no recording of orders reaches the -call (section 7). The host runs the engine's native orders for a `blocked` entry (ABI 4.2). +The recording of the reclaim pick is `i services.ScheduleMapPickReclaimable = ` followed by the four +lines `o energy`, `o energyAmount`, `o metal` and `o metalAmount` (ABI 9.3, the paragraph on the pick). Two +recordings reach it: `mission-build-unit.txt`, tick 121 (radius 13107200, answer 0, both points `null` and both amounts 0), and +`mission-kill-of-type.txt`, tick 128 (radius 15728640, answer 1: energy at (46661632, 13107200) with amount +`f32:0x41c80000`, metal at (46661632, 9961472) with amount `f32:0x42480000`). The module makes no draw for the pick (section 4, "The reclaim pick"). The host runs the engine's native orders for a `blocked` entry (ABI 4.2). - Hooks: `interfaces/orders.h` names AllowBuild, AircraftSeekRepair, GuardResponse and IdleBuilderAction on `RunOrders`, and AllowCommand on `GetOrderType` and on the event kind COMMAND; every other slot says "Hooks: @@ -347,12 +348,13 @@ and *end* (the block offset one past the storage), each a `Ref` stored as a bloc `value` and `name` are text the engine slot sets: the `name` and `value` columns of the table below, as the recordings carry them (`r SimGlobals.g_missionOrderTableVec[K].name "..."`, a text line). The module never writes them. `name` is a `char *` (`layout.json`), so the word holds the linear address of the kind's zero-terminated name, -not a block offset: the replayer allocates each recorded string and stores its address in the word -(`docs/replay-format.md`, the field of kind `cstring`). The module reads the bytes for the comparison of +not a block offset: in a WASM replay, as in a WASM game, it is an address of the load data region, where the host has +placed the recorded text and where it stays unchanged for the match (`docs/orders-interface.md`, "The order type table's text +words"; `docs/replay-format.md`, the field of kind `cstring`). The module reads the bytes for the comparison of `MissionTypeFromName` only; it never keeps the address or changes the bytes. No slot of orders reads `value`. **Which behaviour runs.** `notify` is an engine code address: the module never calls through it or computes with -it. The engine slot fills the table identically every game, so the behaviour of an order of kind K is the +it. The engine slot fills the table identically in every recorded game, so there the behaviour of an order of kind K is the `orderNotify` index j that the table below gives for K (the recordings write the field as that index, `r SimGlobals.g_missionOrderTableVec[K].notify orderNotify[j]`); `data/replay_schema.json` (`annotations.code_tables.orderNotify.entries`) names entry j by the order type it stands for. Section 4, "Order @@ -526,7 +528,13 @@ Each term is defined once; section 4 uses it by its name, in quotes where the na menu update arguments `[U.id]` are U's index in the unit array. - **Order type names.** A rule that names an order type by a string, such as `MOBILEBUILD`, means the index that `MissionTypeFromName` gives that string at the moment the rule uses it (0, `Ready`, when the table lacks it). The - indices of the recordings' table are given in brackets: `MOBILEBUILD` (`MobileBuild`, 25). The rule is the name. + indices of the recordings' table are given in brackets: `MOBILEBUILD` (`MobileBuild`, 25). The rule is the name, and the + number is only that of the recordings' table: the table is in the order of its names, so a table with other entries (a + mod's) gives a kind another index. Every kind this spec names, in a row, a heading or a bracket, is found by its name at + the moment it is used; a module that compared with the recorded numbers would differ on `mission-passes-z-renumbered.txt`, + which is `mission-passes-z.txt` with two entries added to its table, `Aa_Extra` at 1 and `Bu_Extra` at 13, and every kind + after each one up by one (`BuildingBuild` is 14 there). The run of an order is the `notify` word of the table entry at + the order's own kind, never a number fixed by the module. - **A kind byte** is a 32-bit payload field truncated to its low 8 bits, as an index in the order type table. - **whole(v)**: the high 16 bits of a 32-bit word, as a signed 16-bit value (`Unit.xWhole` is whole(`Unit.posX`), `Unit.zWhole` whole(`Unit.posZ`)). @@ -807,8 +815,7 @@ SET_BUILD_STATE, and orders' COMMAND, CLEAR_NET_DIRTY, UNLINK) are written out w - **The feature box**: lo = (cell.x << 20, *h* << 16, cell.y << 20) with *h* = `map.GetGroundHeight` of lo (its y word not set before the call); hi = lo + (`F.footprintX` << 20, `F.height` << 16, `F.footprintZ` << 20), wrapping. - **The reclaim pick (P, r)** answers four things: an energy point and amount and a metal point and amount. It is a - call to map, `map.PickRandomReclaimableResourcesInRadius(P, r, &E, &eAmount, &M, &mAmount)` (an import the entry - does not list yet: "Gaps in the kit"): P a `Vec3` passed by address; E and M two words of the module that hold, + call to map, `map.PickRandomReclaimableResourcesInRadius(P, r, &E, &eAmount, &M, &mAmount)` (an import of the entry, section 2): P a `Vec3` passed by address; E and M two words of the module that hold, before the call, the linear addresses of two `Vec3` records of the module; eAmount and mAmount two floats. For a kind the pick found, map writes the chosen point's `x` and `z` into the record the word points at (its `y` is never set, so it is not compared), writes the amount into the float, and leaves the word as it is; for a kind it found nothing @@ -1813,7 +1820,10 @@ Every run starts with the site cell and size (one `features.FindFeatureAtPos`), | state 5 | features' RECLAIM 35 (20): `unit` *U*, `pos` `O.pos` | none | 5 | | any other state | none | none | 7 | -The time: `F.energy` + `F.metal` summed in double, times 0.5, plus 15, then ftol. Recorded: unrecorded. +The time: `F.energy` + `F.metal` summed in double, times 0.5, plus 15, then ftol. Recorded: `orders-reclaim-feature.txt`, `Unit#1`, `Order#1`. Tick 243, state 4: CLEAR_NET_DIRTY (12), then +`features.FindFeatureAtPos (41943040,65536,17039360) = 1` (cell (40,16), size (1,1)); `ticks` becomes −2, `wakeFrame` 245, `state` 5. +Tick 245, state 5: CLEAR_NET_DIRTY, the find again, features' RECLAIM 35 (20 bytes), then the order ends (the stop-building script +call and a new default order). #### `ReclaimUnit` (kind 33) @@ -1951,7 +1961,9 @@ index is its offset from `Game.cells` divided by 13; "mod" and "div" truncate. ` low 16 bits, unsigned. With `D.buildRate` below 30 the divisor is 0.0, the quotient an infinity or a NaN, and ftol gives 0: `radius` is 0. The SET_ANGLES uses the spot of the cell the import answers without testing it, and a cell feature of 0xfffb or more ends the order with N already made (Q32). Failure answers: `CreateUnit` 0 keeps the state at 5 (the next run retries); `GetGameType` is only -compared with 3. Recorded: unrecorded. +compared with 3. Recorded: `orders-tier2-core.txt`, `Unit#3`, `Order#2`. Tick 614: CLEAR_NET_DIRTY, the find (answer 204, cell (38,14), +size (4,4)), the nano point, one `map.GetGroundHeight`, one `RecordSimEvent` of kind 3, a 12-byte publish; `wakeFrame` 615. Tick 615: +the find twice, then `units.CreateUnit 0 246 (41943040,65536,17039360) 0 1 0 = Unit#2`, whose fields the recording gives as `o` lines. #### `SelfDestruct` (kind 38) and `SelfDestructFG` (kind 39) @@ -2327,7 +2339,9 @@ Otherwise, when `F.flags` lacks 0x80: result 8. | 4 | | features' RECLAIM 35 (20): `unit` *U*, `pos` `O.pos` | 5 | | other | | none | 7 | -Recorded: unrecorded. +Recorded: `mission-kill-of-type.txt`, tick 128, `Unit#304`, `Order#198`, made by the `VTOL_RepairPatrol` run of the same call: +`services.RandomInt 15 = 14`, a 12-byte publish, `features.FindFeatureAtPos (46661632,0,9961472) = 22` (cell (44,8), size (2,2)), publishes +of 12, 16 and 12 bytes, the find again, `movement.NewPathOrderAt Order#198 (46661632,0,9961472) = PathOrder#3`, a 12-byte publish; `state` 2, `attached` `PathOrder#3`, `flags` 224. #### `VTOL_ReclaimUnit` (kind 59) @@ -2381,7 +2395,10 @@ The state 1 run. It always starts with a path target to `O.pos`, SET_ALTITUDE (* | none of the above, the reclaim pick (`U.pos`, 0xf00000) answers 1 and a reclaim row gives X | the diversion's test; the repair test's; the pick; release the target; a new order (`VTOL_RECLAIM` (`VTOL_Reclaim`, 58), no target, position X, 0, 0, 0) at the front | `flags` becomes 0 | 3 | | otherwise | the diversion's test; the repair test's; the pick | none | 2 | -The pick is asked whatever the resources are. Recorded: unrecorded. +The pick is asked whatever the resources are. Recorded: `mission-kill-of-type.txt`, tick 128, `Unit#304`, `Order#197` (the pick's +answer 1 with energy and metal both found: the order made is `VTOL_Reclaim`, `Order#198`, at the position of the metal point (46661632, 0, +9961472) with `y` 0). In the same call the new order runs its first pass; the call ends with `Order#197`'s `state` 1 and `wakeFrame` 172. +`mission-build-unit.txt`, tick 121 shows the pick answering 0 (section 2). #### `VTOL_RepairUnit` (kind 61) @@ -2821,20 +2838,19 @@ other modes run inside `ExpandGroupCommand` and inside runs); an order in `Unit. runs of `Ready`, `Activate`, `AirToAir`, `AirToGround`, `AirToGroundHover`, `Attack_Kamikaze`, `Attack_NoMove`, `AttackSpecial`, `AttackUType`, `Capture`, `Cloak_Off`, `Cloak_On`, `Deactivate`, `MakeSelectable`, `Paralyze`, `Park`, `Patrol`, `QMove`, -`QPatrol`, `Reclaim`, `RepairUnit`, `RepairUnitNoMove`, `Resurrect`, `SelfDestruct`, `SelfDestructFG`, +`QPatrol`, `RepairUnit`, `RepairUnitNoMove`, `SelfDestruct`, `SelfDestructFG`, `Standby_Mine`, `Standing_FireOrder`, `Standing_MoveOrder`, `Stop`, `Suppress`, `Teleport`, `VTOL_Evade`, -`VTOL_GetRepaired`, `VTOL_HelpBuild`, `VTOL_MobileBuild`, `VTOL_Move`, `VTOL_Reclaim`, -`VTOL_ReclaimUnit`, `VTOL_RepairPatrol`, `VTOL_Unload`, `Wait` and +`VTOL_GetRepaired`, `VTOL_HelpBuild`, `VTOL_MobileBuild`, `VTOL_Move`, +`VTOL_ReclaimUnit`, `VTOL_Unload`, `Wait` and `WaitForAttack`; and of the recorded kinds, `SelfRepair` state 0, `BeCarried` state 0, the `RepairPatrol` reclaim and `VTOL_Patrol` with a pad diversion or a target. `Ground_Unload` is recorded in state 1 only. QUEUE_BUILD (`mission-passes-z.txt` tick 30), ATTACKED (`mission-build-unit.txt` ticks 73 and 74) and `GetOrderFlags` (`mission-build-unit.txt` ticks 73 and 74) are recorded as calls of their own. -No recording calls 10 of the entry's 53 imports: `movement.NewPathOrderToUnitAt`, `movement.NewAirManeuverOrder`, -`units.GetFactoriesInRadius`, `scripts.GetPieceOffset`, `network.SendFeatureReclaimed`, -`network.SendScriptCallByName`, `los_radar.GetOriginCellAtPosition`, `features.GetCellFeature`, -`features.FindFeatureAtPos` and `mission.GetGameType`. The kit gives the reason for each (`data/replay_schema.json`, -`annotations.subsystems.orders.unrecorded_imports`; `docs/replay-format.md`). Its list has twelve names: the other two, +No recording calls 6 of the entry's 54 imports: `movement.NewPathOrderToUnitAt`, `movement.NewAirManeuverOrder`, +`units.GetFactoriesInRadius`, `scripts.GetPieceOffset`, `network.SendFeatureReclaimed` and +`network.SendScriptCallByName`. The kit gives the reason for each (`data/replay_schema.json`, +`annotations.subsystems.orders.unrecorded_imports`; `docs/replay-format.md`). Its list has eight names: the other two, `movement.LoadTarget` and `units.LoadUnit`, are calls of the engine's `LoadOrders` (load class), not imports of the entry. The recordings route can't judge a call of them; only the scenarios would, and those are not played while the entry is blocked ("Gaps in the kit"). @@ -2842,15 +2858,9 @@ scenarios would, and those are not played while the entry is blocked ("Gaps in t - **Payloads by size.** The recordings carry each publish as `services.SchedPublish 3 `, without its fields, so the gate compares an effect by its size and by what its subscribers write (the `o` lines after it), not by its payload. -- **The reclaim pick.** `RepairPatrol` and `VTOL_RepairPatrol` choose resources to reclaim through - `map.PickRandomReclaimableResourcesInRadius`, which the manifest has under `signatures.map` but the entry does not - import, and no row of ABI 9.3's table maps a recorded call to it. The kit records map's slot (`docs/replay-format.md`, - the map recordings, with the `outptr` and `scalar` out argument forms), but no recording of - orders carries the call. The pick's choice and draws are map's; until the entry lists the import, a module can't make - the call (section 2, "A call that is not in the entry"). - **A blocked entry.** `blocked` is `true` in the kit's manifest, so the entry has no `fuel_budget` and no `size_budget` until the kit sets them; the gate judges a module of it on the recordings route (ABI 4.2, section 15), with `scenarios: not_judged`. -- **Unrecorded imports.** The 10 imports of section 7 that no recording calls have no recorded argument or answer form, +- **Unrecorded imports.** The 6 imports of section 7 that no recording calls have no recorded argument or answer form, so no check judges them while the entry is blocked. - **Fields no recording carries.** No recording has a line of a `UnitTypeSet` (`bits`), `Cell` (`feature`, `offsetX`, `offsetY`, `spot`), `Feature` or `FeatureSpot` field. An object an import answers starts zeroed in the replay @@ -2867,6 +2877,6 @@ scenarios would, and those are not played while the entry is blocked ("Gaps in t ## 8. Kit version -Kit `interfaces-v84` and `reference-traces-v58`, the versions the gate judges against. Interface `orders` 6.2. The +Kit `interfaces-v109` and `reference-traces-v65`, the versions the gate judges against. Interface `orders` 6.2. The imports are against `movement` 5, `units` 7, `scripts` 3, `weapons` 4, `map` 9, `network` 2, `los_radar` 5, `features` 5, `targeting` 4, `mission` 2, `economy` 5 and `services` 4.