From: Lukas Krickl Date: Mon, 19 May 2025 16:09:26 +0000 (+0200) Subject: unit: wip unit switching X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=cff3f486f48135108ad3ec4d13b63dbecc12f0c5;p=gbrg%2F.git unit: wip unit switching This still has very broken side effects. Unit switching breaks the camera and the active actor. The second actor should be switched to but it is not moving at all. --- diff --git a/src/map.s b/src/map.s index 6b961ba..1e777e6 100644 --- a/src/map.s +++ b/src/map.s @@ -108,6 +108,11 @@ map_load_demo_actors: ld hl, p0_units ld bc, act_size call memcpy + + ld de, unit_demo_1 + ld hl, p0_units + act_size + ld bc, act_size + call memcpy ret #include "default_map.s" diff --git a/src/unit.s b/src/unit.s index 90d949d..6e13caf 100644 --- a/src/unit.s +++ b/src/unit.s @@ -237,10 +237,12 @@ unit_try_move_right: ; consumes a move ; sets UI redraw flag ; fails (z flag set) if no moves left + ; switches to next unit if moves reach 0 ; inputs: ; de: unit unit_use_move: push de + call ui_unit_need_draw ld hl, act_moves add hl, de @@ -248,10 +250,14 @@ unit_use_move: ld a, [hl] ; current cp a, 0 + + push_all + call z, unit_next + pop_all ret z + dec a ld [hl], a - call ui_unit_need_draw ret ; centers the current scroll on the selected unit @@ -343,6 +349,7 @@ unit_switch_to_idle: ; 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 @@ -352,8 +359,8 @@ unit_next: 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 [unit_next_best_act_ptr], a + ld [unit_next_best_act_ptr+1], a ld hl, p0_units ld b, UNITS_MAX * PLAYERS @@ -375,7 +382,9 @@ unit_next: ; check if moves are not 0 pop hl + push hl ld de, act_moves + add hl, de ld a, [hl] cp a, 0 jr z, @skip REL @@ -388,7 +397,6 @@ unit_next: 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 @@ -401,9 +409,9 @@ unit_next: ld [unit_next_best_init], a ld a, l - ld [unit_next_bext_act_ptr], a + ld [unit_next_best_act_ptr], a ld a, h - ld [unit_next_bext_act_ptr+1], a + ld [unit_next_best_act_ptr+1], a @skip: pop hl ; restore table @@ -415,11 +423,22 @@ unit_next: ; if here unit_next_best_act_ptr is still 0000 ; reste all moves and try again - ld a, [unit_next_bext_act_ptr] + ld a, [unit_next_best_act_ptr] ld b, a - ld a, [unit_next_bext_act_ptr+1] + ld a, [unit_next_best_act_ptr+1] xor a, b jr z, @retry REL + + ; load new bext into hl + ; and set active + ld a, [unit_next_best_act_ptr] + ld [ui_draw_actor], a + ld e, a + ld a, [unit_next_best_act_ptr+1] + ld [ui_draw_actor+1], a + ld d, a + call unit_switch_to_active + ret @retry: diff --git a/src/wram.s b/src/wram.s index d3fd167..51e1fe8 100644 --- a/src/wram.s +++ b/src/wram.s @@ -18,7 +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 +unit_next_best_act_ptr: .adv 2 ; actors ; actors are state machines