From: Lukas Krickl Date: Sun, 18 May 2025 05:33:37 +0000 (+0200) Subject: unit: wip actor switching X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=7c8503092cad47c2ecc26475e72f83fa6fb4da7a;p=gbrg%2F.git unit: wip actor switching --- diff --git a/src/unit.s b/src/unit.s index 35cabac..9f462d0 100644 --- a/src/unit.s +++ b/src/unit.s @@ -339,26 +339,89 @@ unit_switch_to_idle: ; initial value and try again ; skips any ACT_T_NULL types ; inputs: - ; de: unit + ; de: current unit ; uses: ; unit_next_best_init: as a temporary buffer unit_next: + ; set moves of current unit to 0 + ld hl, act_moves + add hl, de + xor a, a + ld [hl], a ; moves = 0 ld [unit_next_best_init], a + ; clear current ptr + ld [unit_next_bext_act_ptr], a + ld [unit_next_bext_act_ptr+1], a + ld hl, p0_units ld b, UNITS_MAX * PLAYERS ; same as unit_next: ; inputs: - ; de: unit + ; de: free to use ; hl: unit table ; b: unit count @unit_next_loop: - + push hl ; save table + ld de, act_type + add hl, de ; hl = type + + ; check type skip it NULL + ld a, [hl] + cp a, ACT_T_NULL + jr z, @skip REL + + ; check if moves are not 0 + pop hl + ld de, act_moves + ld a, [hl] + cp a, 0 + jr z, @skip REL + + pop hl + push hl + ; check if this actor is better + ; than the previous actor + ld de, act_init + add hl, de + ld a, [hl] + ld d, a ; b = init of new actor + + ld a, [unit_next_best_init] + ; check if this init value is better + ; if not proceed + cp a, d + jr nc, @skip REL ; d > a? + + ; otherwise store new init value and hl + pop hl + push hl + ld [unit_next_best_init], a + + ld a, l + ld [unit_next_bext_act_ptr], a + ld a, h + ld [unit_next_bext_act_ptr+1], a + +@skip: + pop hl ; restore table + ld de, act_size + add hl, de ; next act + dec b jr nz, @unit_next_loop REL + ; TODO: + ; if here unit_next_best_act_ptr is still 0000 + ; reste all moves and try again + + ret + + ; resets all moves + ; of all actors un p0 and p1_unts +unit_reset_all_moves: ret diff --git a/src/wram.s b/src/wram.s index 021154b..d3fd167 100644 --- a/src/wram.s +++ b/src/wram.s @@ -18,6 +18,7 @@ game_mode: .adv st_size ; current best init found in units_next unit_next_best_init: .adv 1 +unit_next_bext_act_ptr: .adv 2 ; actors ; actors are state machines