Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions orders/IMPLEMENTATION-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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).
15 changes: 7 additions & 8 deletions orders/SPEC-QUESTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
2 changes: 2 additions & 0 deletions orders/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
45 changes: 41 additions & 4 deletions orders/src/gettype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion orders/src/kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
}
}
42 changes: 16 additions & 26 deletions orders/src/kinds_a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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])));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down
Loading
Loading