actions: Added basic rest action
authorLukas Krickl <lukas@krickl.dev>
Thu, 4 Sep 2025 15:58:52 +0000 (17:58 +0200)
committerLukas Krickl <lukas@krickl.dev>
Thu, 4 Sep 2025 15:58:52 +0000 (17:58 +0200)
For now this action always heals the player for 1 and skips the turn.

src/action.s
src/action_menu.s
src/stats.s

index d8080b7c8ffdd605ec5481c406caede4f70e1e8a..02fbf45765a3d3b29d5b9ed75783de6fe609f4e9 100644 (file)
@@ -264,7 +264,18 @@ unit_action_attack_damage_calc:
        call ui_request_redraw
        ldnull bc
        ret
-
+       
+       ; rests for a turn healing the unit
+       ; and skipping the turn
+       ; inputs:
+       ;               de: actor
+unit_action_rest:
+       ld a, 1
+       call stat_heal_by
+       call ui_redraw_player
+       call ui_request_redraw
+       ldnull bc
+       ret
 
        ; default attack state
 st_action_attack_init:
@@ -275,3 +286,7 @@ st_action_attack_direction_picked:
        st_def 0x00, unit_action_attack, st_action_attack_direction_picked
 st_action_attack_damage_actor:
        st_def 0x00, unit_action_attack_damage_calc, st_action_attack_direction_picked
+
+       ; rest action skips a turn
+st_action_rest:
+       st_def 0x00, unit_action_rest, st_unit_delay_to_active_template
index 874e9d9ccbedcf997d06363b078bba10d233afc2..494ca111f1aff3243f59790814b31ab95635ab13 100644 (file)
@@ -21,7 +21,7 @@ action_menu_str_table_end:
 action_menu_action_table:
        dw st_action_attack_init
        dw st_action_attack_init
-       dw st_action_attack_init
+       dw st_action_rest
 action_menu_action_table_end:
 
 #define ACTION_MENU_STR_TABLE_LEN (action_menu_str_table_end - action_menu_str_table) / 2
index 8b401413e47ea2ec8b8bc137118a5be55e01aa9a..7119d3cd293486cc0184cbaf0f3772f2cd9b43b7 100644 (file)
@@ -153,6 +153,36 @@ stat_calc_physical_damage_vs:
        ld [hl], a ; write 0 hp
        ld a, b ; a = damage dealt
        ret
+       
+       ; heals the actor by N
+       ; does not overheal
+       ; inputs:
+       ;               de: actor
+       ;                a: amount
+stat_heal_by:
+       ld b, a ; b = amount to heal by
+       ld hl, act_hp
+       add hl, de
+       ld a, [hl] ; a = current hp
+       add a, b ; a = new hp
+       
+       push hl
+       push af
+       call stat_calc_hp_max
+       ld b, a ; b = max hp
+       pop af
+       pop hl
+
+       cp a, b
+       ; a > b? (max > new value)
+       jr nc, @overheal REL
+       ld [hl], a ; write new value
+       ret
+@overheal:
+       ; set to max
+       ld a, b
+       ld [hl], a ; write max into hp
+       ret
 
   ; calculates the real speed state
   ; inputs: