unit: wip for unit switching
authorLukas Krickl <lukas@krickl.dev>
Sun, 18 May 2025 04:31:02 +0000 (06:31 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 18 May 2025 04:31:02 +0000 (06:31 +0200)
src/defs.s
src/unit.s
src/wram.s

index 50d90106643cbfb9c48e9f51fd3cad96b791e7e2..cf84ffd855846fe1cac520554ac3b9caae2e001a 100644 (file)
@@ -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
index 795b4157546b315c41e19bdf554b70c55f11decf..35cabac29861b52ae7989e2be1d566613c860cb4 100644 (file)
@@ -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 
index 77cc0e1e1d8b3ff5fdd2405357f1e3aca1512a87..021154b4194ec94e5c2dda580ad13e50aa59b384 100644 (file)
@@ -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