unit: removed turn-based code
authorLukas Krickl <lukas@krickl.dev>
Sat, 21 Jun 2025 14:03:10 +0000 (16:03 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 21 Jun 2025 14:03:10 +0000 (16:03 +0200)
This change removes a lot of turn based code around moves, moves max
initiavite etc.
It also simply sets all units to active which effectively makes the game
real time.

src/actortables.s
src/defs.s
src/macros.inc
src/map.s
src/player.s
src/stats.s
src/ui.s
src/unit.s
src/unit_demo.s
src/update.s

index bf7807afdd09f149cd613f15b34f86faf0e6f446..331ecc8c521ed620d34c18fcba6b24979cb696c4 100644 (file)
@@ -3,7 +3,7 @@
 default_map_actor_table:
 .db 2 ; size
 dw unit_demo_2
-dw unit_demo_3
+dw unit_demo_3
 
 
 
index 88b927da5ecf67062cc5e0c8300642ad2e9a82a9..b70653412adc6c74cb6b900465c46023b770de74 100644 (file)
@@ -49,7 +49,6 @@
 
   ; gameplay flags
 .se 1
-.de GPF_UNIT_NEXT, 1
 
   ; cell flags
 .se 1 
 .de act_mp, stat_size
 .de act_fatigue, stat_size
 .de act_ac, stat_size 
-.de act_moves, stat_size ; moves for each turn
 
   ; stats2
 .de act_str, stat_size
index 7ff8947e2c05619a390da2900cffc75b9b4a292c..5ec9ae7611252e0d5ff6c467651754b4eac024b4 100644 (file)
   ;   $3 mana points
   ;   $4 fatigue points
   ;   $5 armor
-  ;   $6 moves
 #macro act_stat_def1
   .db $1 ; level
   .db $2 ; hp hp max
   .db $3 ; mp mp max
   .db $4 ; fatigue fatigue max
   .db $5 ; ac
-  .db $6 ; moves moves max
 #endmacro
 
   ;   $1 str
index db453b3cd02969d78fdcdc5f33c42fe7d16b1a10..d629f6b9020c3f515dee39044bfb098c2ef18728 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -233,8 +233,8 @@ map_actors_load:
   jr nz, @loop REL
 
   ; hand over control to a unit
-  ld de, p_empty_unit
-  call unit_next_request
+  ld de, player_unit 
+  call unit_wake_up 
   ret
 
   ; loads map tilesets
@@ -300,29 +300,6 @@ map_draw_all:
 
   ret
 
-  ; sets up some actors for debug purposes 
-map_load_demo_actors:
-  ; load a single demo actor into p0 units
-  ld de, unit_player
-  ld hl, p0_units
-  ld bc, act_size
-  call memcpy
-
-  ld de, unit_demo_2
-  ld hl, p0_units + act_size
-  ld bc, act_size
-  call memcpy
-
-  ld de, unit_demo_3
-  ld hl, p0_units + act_size * 2
-  ld bc, act_size
-  call memcpy
-  
-  ld de, p_empty_unit
-  call unit_next_request
-
-  ret
-
   ; empty actor table 
 map_actor_table_null:
 .db 0
index a2d31fc48ed2bab6441811f2d95d822834bb5430..c3f1cb8573337b9a32e309a9bd7686f2b06e765b 100644 (file)
@@ -8,8 +8,6 @@ unit_load_default_player:
   ld bc, act_size
   call memcpy
 
-  ld de, p_empty_unit
-  call unit_next_request
   ret
 
 unit_player_init:
@@ -42,7 +40,7 @@ unit_player_update:
 unit_player:
   st_def 0x00, unit_player_init, st_unit_idle
   act_def ACT_T_DEMO_1, 0, 2, 2, 0
-  act_stat_def1 1, 1, 1, 1, 1, 1 
+  act_stat_def1 1, 1, 1, 1, 1
   act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 
   act_attr_def_empty
   act_inventory_empty
index c3b3b56f90f887c7ae2841838eb3e4b8aa8e60a5..4dd2f9b084161fe9562ddccf0476f8b476a7fa72 100644 (file)
@@ -7,24 +7,3 @@
 stat_calc_str:
   ret
 
-  ; calculates the current actor's initiative
-  ; inputs:
-  ;   de: actor
-  ; returns:
-  ;   a: init
-stat_calc_init:
-  ; TODO
-  ; for now we just hard-code
-  ld a, 1
-  ret
-
-  ; calculates the current actor's max moves
-  ; inputs:
-  ;   de: actor
-  ; retrns:
-  ;   a: moves max
-stat_calc_moves_max:
-  ; TODO
-  ; for now we just hard-code
-  ld a, 1
-  ret
index efda7bb0399fc29f01272bdb7da9bdbff0903b14..f72464ef2ca7c6ca3cf78126bc108ebd299b4de8 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -47,45 +47,4 @@ ui_draw:
   xor a, DRAWF_UPDATE_UI
   ld [draw_flags], a
   
-  ld a, [ui_draw_actor]
-  ld l, a
-  ld a, [ui_draw_actor+1]
-  ld h, a
-  ; hl = actor 
-  ld de, act_moves
-  add hl, de ; hl = current moves
-  ld a, [hl] ; a = counter
-  ld d, a ; d = counter
-
-  call stat_calc_moves_max
-  ; a = moves max counter
-  sub a, d ; max - current
-  ld e, a ; e = moves max counter
-
-  ld hl, SCRN1+1
-
-  ; draw to screen
-  ld a, d
-  cp a, 0
-  jr z, @skip_loop_current REL
-
-  ld a, UI_TILE_MOVE
-@loop_current:
-    ld [hl+], a
-    dec d
-  jr nz, @loop_current REL
-
-@skip_loop_current:
-
-  ; draw used moves 
-  ld a, e ; check if e is already 0
-  cp a, 0
-  ret z ; do not draw if e is 0
-  
-  ld a, UI_TILE_MOVE_USED
-@loop_max:
-    ld [hl+], a
-    dec e
-  jr nz, @loop_max REL 
-  
   ret
index 344af061f4776f85862b40076d265523a7ba83a1..583f7bd50999199023822d3ecbbc813357d9dc42 100644 (file)
@@ -63,29 +63,6 @@ unit_update_draw:
   call_hl
   ret
 
-unit_handle_cpu_inputs:
-  ; pick where to go 
-  call roll_d16
-  and a, 3 ; 0-3
-  ; 0 == left
-  cp a, 0
-  call z, unit_try_move_left
-
-  ; 1 == right
-  cp a, 1
-  call z, unit_try_move_right
-
-  ; 2 == up
-  cp a, 2
-  call z, unit_try_move_up
-
-  ; 3 == down
-  cp a, 3
-  call z, unit_try_move_down
-
-  ld bc, st_unit_delay_to_active_fast
-  ret
-
 
   ; inputs
   ;   de: actor
@@ -355,9 +332,6 @@ unit_collides_with_any_other:
   ;   actor initiative based on tile flags
   ;   actor position
 unit_try_move_up:
-  call unit_use_move
-  ret z
-
   ; y - 1
   unit_test_collision dec b, CF_COLLISION
 
@@ -374,9 +348,6 @@ unit_try_move_up:
   ret
 
 unit_try_move_down:
-  call unit_use_move
-  ret z
-  
   ; y + 1
   unit_test_collision inc b, CF_COLLISION
 
@@ -392,9 +363,6 @@ unit_try_move_down:
   ret
 
 unit_try_move_left:
-  call unit_use_move
-  ret z
-  
   ; x - 1
   unit_test_collision dec c, CF_COLLISION
 
@@ -410,8 +378,6 @@ unit_try_move_left:
   ret
 
 unit_try_move_right:
-  call unit_use_move
-  ret z
   
   ; x + 1
   unit_test_collision inc c, CF_COLLISION
@@ -427,32 +393,6 @@ unit_try_move_right:
   ld [hl], a
   ret 
 
-  ; 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
-  pop de ; hl = act_moves
-
-  ld a, [hl] ; current
-  cp a, 0 ; if 0 exit
-  ret z
-
-  dec a
-  ld [hl], a
-  
-  ; we need the z flag to not be set ehre
-  ; so just do something that will always unset it
-  or a, 1
-  ret
-
   ; centers the current scroll on the selected unit
   ; snaps to corners of the map
   ; inputs:
@@ -559,193 +499,6 @@ unit_sleep:
   call memcpy
   ret
 
-  ; requests unit next
-  ; to be executed
-  ; inputs: 
-  ;   de: current unit
-unit_next_request:
-  ld a, [gameplay_flags]
-  and a, GPF_UNIT_NEXT
-  ret nz ; do not call again if flag is set
-
-  ld a, [gameplay_flags]
-  or a, GPF_UNIT_NEXT
-  ld [gameplay_flags], a
-
-  ld a, e
-  ld [gameplay_unit_current], a
-  ld a, d
-  ld [gameplay_unit_current+1], a
-  
-  ; set up delay timer
-  ld a, 16
-  ld [unit_next_timer], a
-
-  ret
-
-  ; finds a unit with a higher initiative value 
-  ; than the current one that has moves > 0 set
-  ; if all unts have have 0 moves, set moves to
-  ; initial value and try again
-  ; when a unit has higher initiative it can still fail
-  ; to take the turn if it rolls a d16 and the roll is < initiative
-  ; skips any ACT_T_NULL types
-  ; inputs:
-  ;   gameplay_unit_current: unit that requested a change
-  ; uses:
-  ;   unit_next_best_init: as a temporary buffer
-unit_next:
-  ; if the unit_next timer is not 8
-  ; wait and timer--
-  ld a, [unit_next_timer]
-  cp a, 0
-  jr z, @go REL
-    dec a
-    ld [unit_next_timer], a
-    ret
-@go:
-  ; unset flag
-  ld a, [gameplay_flags]
-  xor a, GPF_UNIT_NEXT
-  ld [gameplay_flags], a
-
-  ; load requestor unit
-  ld a, [gameplay_unit_current]
-  ld e, a
-  ld a, [gameplay_unit_current+1]
-  ld d, a
-
-  push de
-  call unit_sleep
-  pop de
-  ; set moves of current unit to 0
-  ld hl, act_moves
-  add hl, de
-  ld [hl], 0 ; moves = 0
-unit_next_no_current:
-@again:
-  xor a, a
-  ld [unit_next_best_init], a
-
-  ; clear current ptr
-  ld [unit_next_best_act_ptr], a
-  ld [unit_next_best_act_ptr+1], a
-
-  ld hl, p0_units 
-  ld b, UNITS_MAX
-
-  ; same as unit_next:
-  ; inputs:
-  ;   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
-    push hl
-    ld de, act_moves
-    add hl, de
-    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 a, [unit_next_best_init]
-      cp a, 0 ; if prev best is 0 proceed anyway
-      ld d, a ; d = previous best init
-
-      pop de ; de = actor 
-      push de ; store again for later
-      call stat_calc_init ; 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 c, @skip REL ; d > a?
-@first_hit:
-        ; otherwise store new init value and hl
-        pop hl
-        push hl
-
-        ld [unit_next_best_init], a
-
-        ld a, l
-        ld [unit_next_best_act_ptr], a
-        ld a, h
-        ld [unit_next_best_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
-
-  ; if here unit_next_best_act_ptr is still 0000
-  ; reste all moves and try again
-  ld a, [unit_next_best_act_ptr]
-  ld b, a
-  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
-
-  push de
-  call unit_wake_up
-  pop de
-  call ui_unit_need_draw
-  ret
-
-@retry:
-  call unit_reset_all_moves
-  jp @again
-
-  ; resets all moves
-  ; of all actors in p0 and p1_unts
-unit_reset_all_moves:
-  ld b, UNITS_MAX 
-  ld hl, p0_units
-@loop:
-    push hl
-
-    pop de
-    push de
-    call stat_calc_moves_max
-    
-    ld de, act_moves
-    add hl, de ; hl = current moves
-    ld [hl], a ; moves are now reset
-
-    pop hl
-    ld de, act_size
-    add hl, de ; move to next act
-    dec b
-  jr nz, @loop REL
-
-  ret
-
   ; called before switching to active
   ; this call also checks if the unit may need to 
   ; hand over control to a new unit
@@ -754,11 +507,6 @@ unit_reset_all_moves:
   ;   de: unit
 unit_delay_to_active:
   call unit_resume_objs
-  ld hl, act_moves
-  add hl, de ; hl = moves
-  ld a, [hl]
-  cp a, 0
-  call z, unit_next_request
   ldnull bc
   ret
 
index 13da365d09cf8fab2d42f421793b4e6a11c2e9ed..630d9f235ab3f106328e838cc692592c0cd52599 100644 (file)
@@ -8,19 +8,41 @@ unit_demo_1_cpu_update:
   push de
   call unit_handle_cpu_inputs
   pop de
+
   ret
 
+unit_handle_cpu_inputs:
+  ; pick where to go 
+  call roll_d16
+  and a, 3 ; 0-3
+  ; 0 == left
+  cp a, 0
+  call z, unit_try_move_left
+
+  ; 1 == right
+  cp a, 1
+  call z, unit_try_move_right
+
+  ; 2 == up
+  cp a, 2
+  call z, unit_try_move_up
+
+  ; 3 == down
+  cp a, 3
+  call z, unit_try_move_down
+
+  ld bc, st_unit_delay_to_active
+  ret
+
+
 unit_demo_1_cpu_update_idle:
-  call unit_use_move
-  call unit_next_request
   ldnull bc
   ret
 
 unit_demo_2:
   st_def 0x00, unit_demo_1_init, st_unit_idle
   act_def ACT_T_DEMO_1, 0, 3, 3, 0 
-  act_stat_def1 1, 1, 1, 1, 1, 1 
+  act_stat_def1 1, 1, 1, 1, 1
   act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 
   act_attr_def_empty
   act_inventory_empty
@@ -31,9 +53,9 @@ unit_demo_2:
   act_rt_def
 
 unit_demo_3:
-  st_def 0x00, unit_demo_1_init, st_unit_idle
+  st_def 0x00, unit_demo_1_init, st_unit_demo_1_cpu_update
   act_def ACT_T_DEMO_1, 0, 4, 4, 0 
-  act_stat_def1 1, 1, 1, 1, 1, 1 
+  act_stat_def1 1, 1, 1, 1, 1 
   act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 
   act_attr_def_empty
   act_inventory_empty
index bdc3555e1b512b6f2ff63aa3a84b673e2ffe66c5..33270073b7d75a35681789d46c32929accb68f64 100644 (file)
@@ -16,10 +16,6 @@ update_game:
   ld hl, p0_units
   call units_update
 
-  ld a, [gameplay_flags]
-  and a, GPF_UNIT_NEXT
-  call nz, unit_next
-
   ldnull bc
   ret