From: Lukas Krickl Date: Thu, 4 Sep 2025 15:58:52 +0000 (+0200) Subject: actions: Added basic rest action X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=9fe0a6bfa07e8f3993590b0b1a5792c3cec818ef;p=gbrg%2F.git actions: Added basic rest action For now this action always heals the player for 1 and skips the turn. --- diff --git a/src/action.s b/src/action.s index d8080b7..02fbf45 100644 --- a/src/action.s +++ b/src/action.s @@ -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 diff --git a/src/action_menu.s b/src/action_menu.s index 874e9d9..494ca11 100644 --- a/src/action_menu.s +++ b/src/action_menu.s @@ -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 diff --git a/src/stats.s b/src/stats.s index 8b40141..7119d3c 100644 --- a/src/stats.s +++ b/src/stats.s @@ -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: