unit: reworked moves stat to have the max calculated
authorLukas Krickl <lukas@krickl.dev>
Mon, 16 Jun 2025 04:49:23 +0000 (06:49 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 16 Jun 2025 04:49:23 +0000 (06:49 +0200)
removed initiative stat. This stat will be calculated entierly based on
other stats in the future

TODO.md
src/defs.s
src/macros.inc
src/stats.s
src/unit.s

diff --git a/TODO.md b/TODO.md
index 995c9ee3ec1e1de338dc76cb341f185b9f03314e..bb89fee419b0947a34fe7f45de1708a28749949f 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -8,10 +8,10 @@
 
 ## Combat
 
-[ ] Unit is selected based on the unit initiative queue 
+[x] Unit is selected based on the unit initiative queue 
 [ ] A unit may skip its turn (moved to end of queue)
 [x] Units have a move counter
-[ ] Move counter should be 1 for most units
+[x] Move counter should be 1 for most units
 [x] Display moves in UI for selected units
 [x] Each action consumes moves
 [x] Units are moved one tile at a time 
 [ ] When a unit moves away from an adjacent melee unit it can attack
 [x] Units are selected in a queue of initiative 
 [x] Once the queue is empty it is reset 
-[ ] Units use state machines to update
-[ ] Each unit's start state is a polling state 
-[ ] The polling state can either be player input or CPU input
-[ ] Mark the current active unit with a cursor
-[ ] When starting an encounter the player can place all hero units and troops based on initiative 
-[ ] The player can collect up to 5 initiative points
-[ ] Initiative can be spent on deployment or special moves
-[ ] Rework all max stats to be calculated (e.g. hp max is calculated based on endurance)
+[x] Units use state machines to update
+[x] Each unit's start state is a polling state 
+[x] The polling state can either be player input or CPU input
+[x] Mark the current active unit with a cursor
+[x] When starting an encounter the player can place all hero units and troops based on initiative 
+[x] Rework all max stats to be calculated (e.g. hp max is calculated based on endurance)
 
 ## Map
 
@@ -37,7 +35,7 @@
 [x] A map may reduce the playfield by making out of bounds tiles walls 
 [x] The camera always centers on the current unit
 [x] All units are always visible
-[ ] Tiles can be impassible, walls or walkable
+[x] Tiles can be impassible, walls or walkable
 [ ] Tiles may cost extra movement to pass
 
 ## Units
 [ ] Only center camera on player
 
 ### Dice display
-[ ] When a unit fails to take initiative display dice roll and focus on unit with camera
-[ ] Update dice display for n frames until timer is 0
-[ ] Then continue the game
-[ ] Rework dice display to be a per-unit runtime only flag
-[ ] Dice display per unit should update in draw if timer is not 0
+[x] Update dice display for n frames until timer is 0
+[x] Rework dice display to be a per-unit runtime only flag
+[x] Dice display per unit should update in draw if timer is not 0
 
 ## Randomness
 
index bfa1822bb25775bfd631a182bde4c45764c73826..2b7a6fff9675d76fb3c7f168c14f2d4047a6ed05 100644 (file)
 
 
   ; stats struct
-  ; with current and max
-  ; used for hp, mp, fatigue, moves
-  ; all other stats only have a max value
-  ; and their real value is calculated before use
+  ; this tracks the current value. most real values
+  ; are calculated
   ; e.g. stat_calc_str with actor as input
-  ; used for stats that can change and reset 
-  ; regularly
-.se 0
-.de stat_cur, 1
-.de stat_max, 1
-.de stat_size, 0
-  
-  ; lite stat with max value only
-  ; used for stats that are not intended to
-  ; decrease regularly
-  ; stat lite's real value is 
-  ; calculated using an actor 
-  ; and stat_calc_nnn calls
-#define stat_lite_size 1
+#define stat_size 1
 
   ; status effect
 .se 0
 .de act_hp, stat_size
 .de act_mp, stat_size
 .de act_fatigue, stat_size
-.de act_ac, stat_lite_size 
+.de act_ac, stat_size 
 .de act_moves, stat_size ; moves for each turn
-.de act_init, stat_lite_size ; initiative value
 
   ; stats2
-.de act_str, stat_lite_size
-.de act_int, stat_lite_size
-.de act_dex, stat_lite_size
-.de act_luck, stat_lite_size
-.de act_will, stat_lite_size
-.de act_charisma, stat_lite_size
-.de act_endurance, stat_lite_size
-.de act_speed, stat_lite_size
+.de act_str, stat_size
+.de act_int, stat_size
+.de act_dex, stat_size
+.de act_luck, stat_size
+.de act_will, stat_size
+.de act_charisma, stat_size
+.de act_endurance, stat_size
+.de act_speed, stat_size
 
   ; attributes
   ; describes skills
   ; stores items, for all actors but player
   ; there are 4 inventory slots.
   ; if the actor is type player a special inventory 
-  ; used instead 
+  ; used instead
+  ; call unit_get_inventory to get a ptr and length
 
   ; equipment 
   ; stores all items equiped
index 9fc0ce0d6454f757f590f86f130dbeb96c8b39cb..9d2162dbda02f207d3341ee63afbd5e362ab024f 100644 (file)
   ;   $4 fatigue points
   ;   $5 armor
   ;   $6 moves
-  ;   $7 initiative
 #macro act_stat_def1
   .db $1 ; level
-  .db $2, $2 ; hp hp max
-  .db $3, $3 ; mp mp max
-  .db $4, $4 ; fatigue fatigue max
+  .db $2 ; hp hp max
+  .db $3 ; mp mp max
+  .db $4 ; fatigue fatigue max
   .db $5 ; ac
-  .db $6, $6 ; moves moves max
-  .db $7 ; initiative
+  .db $6 ; moves moves max
 #endmacro
 
   ;   $1 str
index 3ecac691aeb10529a94269d042abfeb19381819b..c3b3b56f90f887c7ae2841838eb3e4b8aa8e60a5 100644 (file)
@@ -6,3 +6,25 @@
   ;   a: str value
 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 e76b495223780208ce122234d10a190471d70ded..83e0391ebc619f2eb44e6b457068a8379cfcac64 100644 (file)
@@ -610,12 +610,13 @@ unit_next_no_current:
       push hl
       ; check if this actor is better 
       ; than the previous actor
-      ld de, act_init
-      add hl, de
       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 
+
+      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 
@@ -627,16 +628,6 @@ unit_next_no_current:
         pop hl
         push hl
 
-        ; this unit is better
-        ; but it can fail an initiative roll
-        push af
-        call roll_d16
-        ld d, a ; d = roll value 
-        pop af ; a = init value
-        cp a, d
-        call nc, unit_dice_display_set_hl
-        jr nc, @skip REL ; d < a
-
         ld [unit_next_best_init], a
 
         ld a, l
@@ -685,12 +676,14 @@ unit_reset_all_moves:
   ld b, UNITS_MAX 
   ld hl, p0_units
 @loop:
-    push hl 
-    ld de, act_moves+1
-    add hl, de ; hl = act_moves_max
+    push hl
 
-    ld a, [hl]
-    dec hl ; hl = current moves
+    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
@@ -815,7 +808,7 @@ unit_get_equipment:
 unit_demo_1:
   st_def 0x00, unit_demo_1_init, st_unit_idle
   act_def ACT_T_DEMO_1, 0, 2, 2, 0
-  act_stat_def1 1, 1, 1, 1, 1, 3, 3 
+  act_stat_def1 1, 1, 1, 1, 1, 1 
   act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 
   act_attr_def_empty
   act_inventory_empty
@@ -828,7 +821,7 @@ unit_demo_1:
 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, 0, 3 
+  act_stat_def1 1, 1, 1, 1, 1, 1 
   act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 
   act_attr_def_empty
   act_inventory_empty
@@ -841,7 +834,7 @@ unit_demo_2:
 unit_demo_3:
   st_def 0x00, unit_demo_1_init, st_unit_idle
   act_def ACT_T_DEMO_1, 0, 4, 4, 0 
-  act_stat_def1 1, 1, 1, 1, 1, 4, 5 
+  act_stat_def1 1, 1, 1, 1, 1, 1 
   act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 
   act_attr_def_empty
   act_inventory_empty