unit: added retry code for next unit selector
authorLukas Krickl <lukas@krickl.dev>
Sun, 18 May 2025 08:49:59 +0000 (10:49 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 18 May 2025 08:49:59 +0000 (10:49 +0200)
src/unit.s

index 9f462d0e366cd750d8b43ce330f3aa34cbfd3c0c..302accb7a4a5f3ebf682bf3a329a75614609f621 100644 (file)
@@ -346,9 +346,9 @@ unit_next:
   ; set moves of current unit to 0
   ld hl, act_moves
   add hl, de
-
+  ld [hl], 0 ; moves = 0
+@again:
   xor a, a
-  ld [hl], a ; moves = 0
   ld [unit_next_best_init], a
 
   ; clear current ptr
@@ -413,12 +413,19 @@ unit_next:
     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
-  
+  ld a, [unit_next_bext_act_ptr]
+  ld b, a
+  ld a, [unit_next_bext_act_ptr+1]
+  xor a, b
+  jr z, @retry REL
   ret
 
+@retry:
+  call unit_reset_all_moves
+  jp @again
+
   ; resets all moves
   ; of all actors un p0 and p1_unts
 unit_reset_all_moves: