wip: unit switching bugfixing
authorLukas Krickl <lukas@krickl.dev>
Tue, 20 May 2025 12:53:22 +0000 (14:53 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 20 May 2025 12:53:22 +0000 (14:53 +0200)
The switching code is still broken, but now at least the correct init
value and actor ptr are stored by the end :^)

src/map.s
src/ui.s
src/unit.s
src/update.s

index 1aa148dc6b69f9a5a698bce13f661bf0689148f1..b103d87d0a40ef844c0c32e50c0b953c85f7a6a6 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -114,7 +114,8 @@ map_load_demo_actors:
   ld bc, act_size
   call memcpy
 
-  call unit_next_no_current 
+  call unit_next_no_current
+  call ui_unit_need_draw
 
   ret
 
index b305c00f16a1ad84b4c3870067c600a8a63ace83..e3d28824dbfec980980d5d6f2e7fc7054187a3d4 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -41,8 +41,6 @@ ui_display_current_unit:
   ; this should only be called 
   ; during blanking 
 ui_draw:
-  call ui_display_current_unit
-
   ld a, [draw_flags]
   xor a, DRAWF_UPDATE_UI
   ld [draw_flags], a
index 201277a36c9f7a3bc1ee590af97fd7ecdc637247..564dcb69e93ca6efedd82768d99e68e201736833 100644 (file)
@@ -402,14 +402,17 @@ unit_next_no_current:
       ; 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]
+      cp a, 0 ; if prev best is 0 proceed anyway
+      ld d, a ; d = previous best init
+      ld a, [hl] ; a = init of new actor 
+      jr z, @first_hit REL ; on first match
+
       ; check if this init value is better 
       ; if not proceed
       cp a, d 
-      jr nc, @skip REL ; d > a?
-
+      jr c, @skip REL ; d > a?
+@first_hit:
         ; otherwise store new init value and hl
         pop hl
         push hl
@@ -478,7 +481,7 @@ unit_reset_all_moves:
 
 unit_demo_1:
   st_def 0x00, unit_demo_1_init, st_unit_demo_1_idle
-  act_def ACT_T_DEMO_1, 0, 1, 2, 3, 4, 5, 2, 2, 0 
+  act_def ACT_T_DEMO_1, 0, 1, 2, 3, 4, 6, 2, 2, 0 
   act_st_def NULL, NULL, st_unit_demo_1_update, st_unit_demo_1_idle
 
 
index 95c051c00bcb61b4211ba91979aca6f611f1e16a..2c83a230af9eb68ed1b745f3375889366bfc7624 100644 (file)
@@ -9,6 +9,7 @@ update_game:
   ld a, [draw_flags]
   and a, DRAWF_UPDATE_UI
   call nz, ui_draw
+  call ui_display_current_unit
 
   ld hl, p0_units
   call units_update