From e63d69ca447424480d183a247f56428023246e41 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 18 May 2025 06:31:02 +0200 Subject: [PATCH] unit: wip for unit switching --- src/defs.s | 2 ++ src/unit.s | 25 +++++++++++++++++++++++++ src/wram.s | 3 +++ 3 files changed, 30 insertions(+) diff --git a/src/defs.s b/src/defs.s index 50d9010..cf84ffd 100644 --- a/src/defs.s +++ b/src/defs.s @@ -33,6 +33,8 @@ #define CURSOR_MIN_Y 0 #define CURSOR_MAX_Y 0xB8 +#define PLAYERS 2 + ; draw flags .se 1 .de DRAWF_UPDATE_UI, 1 diff --git a/src/unit.s b/src/unit.s index 795b415..35cabac 100644 --- a/src/unit.s +++ b/src/unit.s @@ -325,6 +325,12 @@ unit_switch_to_active: ; inputs: ; de: unit unit_switch_to_idle: + ld hl, act_st_idle + add hl, de ; hl = st_idle ptr + ld a, [hl+] + ld c, a + ld a, [hl] + ld b, a ret ; finds a unit with a higher initiative value @@ -334,9 +340,28 @@ unit_switch_to_idle: ; skips any ACT_T_NULL types ; inputs: ; de: unit + ; uses: + ; unit_next_best_init: as a temporary buffer unit_next: + xor a, a + ld [unit_next_best_init], a + + ld hl, p0_units + ld b, UNITS_MAX * PLAYERS + + ; same as unit_next: + ; inputs: + ; de: unit + ; hl: unit table + ; b: unit count +@unit_next_loop: + + dec b + jr nz, @unit_next_loop REL + ret + unit_demo_1: st_def 0x00, unit_demo_1_init, st_unit_demo_1_update act_def ACT_T_DEMO_1, 0, 1, 2, 3, 4, 5, 2, 2, 0 diff --git a/src/wram.s b/src/wram.s index 77cc0e1..021154b 100644 --- a/src/wram.s +++ b/src/wram.s @@ -16,6 +16,9 @@ prev_inputs: .adv 1 game_mode: .adv st_size +; current best init found in units_next +unit_next_best_init: .adv 1 + ; actors ; actors are state machines ; they get updated once a frame -- 2.30.2