From 483bd0a0e49a96eb6ae26fd18ce702a6a2a8a714 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 7 Sep 2025 06:08:41 +0200 Subject: [PATCH] action: moved melee attack to attack.s --- src/action.s | 119 -------------------------------------------------- src/attack.s | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.s | 2 + src/shoot.s | 1 + 4 files changed, 124 insertions(+), 119 deletions(-) create mode 100644 src/attack.s create mode 100644 src/shoot.s diff --git a/src/action.s b/src/action.s index 43ee5af..1cbd4bb 100644 --- a/src/action.s +++ b/src/action.s @@ -156,115 +156,6 @@ unit_attack_get_attack_tile: @not_right: ret - ; performs an attack - ; based on the units rt_action tmp value - ; inputs: - ; de: unit - ; returns: - ; bc: next action -unit_action_attack: - push de - - call unit_attack_get_attack_tile - - - ; draw a slash animation at that location - push bc - call load_unit_obj - call load_scroll - push bc - pop de ; de = scroll - pop bc ; bc = pos - ; hl = obj - ; write position - ld a, b ; y position - tile_to_scrn OBJ_OFF_Y, d - ld [hl+], a ; y position - - ld a, c ; x position - tile_to_scrn OBJ_OFF_X, e - ld [hl+], a ; x position - - ; write tile - ld a, ACTION_ATTACK_SPRITE1 - ld [hl+], a - - ; clear flags - xor a, a - ld [hl], a - - - ; check anim length - pop de - ld hl, act_rt_action_dat2 ; dat2 = animation frame count - add hl, de - ld a, [hl] - inc a - ld [hl], a - cp a, UNIT_ACTION_ATTACK_ANIM_LEN - jr z, @done REL - - ; TODO: on frame 0 perform attack action - - ; otherwsie keep going - ldnull bc - ret - -@done: - ; unset flag - ld a, [gpf_attack_ongoing] - dec a - ld [gpf_attack_ongoing], a - - ; set animation timer and delay - ld bc, st_unit_delay_to_active_template - ret - - ; performs damage calculations based on the attacked location - ; inputs: - ; de: unit - ; returns: - ; bc: new state -unit_action_attack_damage_calc: - - ; set flag - ld a, [gpf_attack_ongoing] - inc a - ld [gpf_attack_ongoing], a - - ; calculate damage - push de - call unit_attack_get_attack_tile - call unit_find_at - - ld a, h - or a, l - pop de - jp z, @miss ; no unit found - - - push hl - pop bc - ; de = attacker - ; bc = attacked unit - push hl - call stat_calc_physical_damage_vs - pop hl - - ld hl, STR_HIT_FOR - call ui_draw_status_stat - call ui_redraw_player - - ldnull bc - ret -@miss: - ld hl, STR_MISS - ld de, UI_STATUS_LINE - call puts - call ui_request_redraw - ldnull bc - ret - ; rests for a turn healing the unit ; and skipping the turn ; inputs: @@ -282,16 +173,6 @@ unit_action_rest: ldnull bc ret - ; default attack state -st_action_attack_init: - st_def 0x00, unit_action_attack_pick_direction_init, st_action_attack_pick_direction -st_action_attack_pick_direction: - st_def 0x00, unit_action_attack_pick_direction, st_action_attack_pick_direction -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/attack.s b/src/attack.s new file mode 100644 index 0000000..18acade --- /dev/null +++ b/src/attack.s @@ -0,0 +1,121 @@ +; melee attack action + + + ; performs an attack + ; based on the units rt_action tmp value + ; inputs: + ; de: unit + ; returns: + ; bc: next action +unit_action_attack: + push de + + call unit_attack_get_attack_tile + + + ; draw a slash animation at that location + push bc + call load_unit_obj + call load_scroll + push bc + pop de ; de = scroll + pop bc ; bc = pos + ; hl = obj + ; write position + ld a, b ; y position + tile_to_scrn OBJ_OFF_Y, d + ld [hl+], a ; y position + + ld a, c ; x position + tile_to_scrn OBJ_OFF_X, e + ld [hl+], a ; x position + + ; write tile + ld a, ACTION_ATTACK_SPRITE1 + ld [hl+], a + + ; clear flags + xor a, a + ld [hl], a + + + ; check anim length + pop de + ld hl, act_rt_action_dat2 ; dat2 = animation frame count + add hl, de + ld a, [hl] + inc a + ld [hl], a + cp a, UNIT_ACTION_ATTACK_ANIM_LEN + jr z, @done REL + + ; TODO: on frame 0 perform attack action + + ; otherwsie keep going + ldnull bc + ret + +@done: + ; unset flag + ld a, [gpf_attack_ongoing] + dec a + ld [gpf_attack_ongoing], a + + ; set animation timer and delay + ld bc, st_unit_delay_to_active_template + ret + + ; performs damage calculations based on the attacked location + ; inputs: + ; de: unit + ; returns: + ; bc: new state +unit_action_attack_damage_calc: + + ; set flag + ld a, [gpf_attack_ongoing] + inc a + ld [gpf_attack_ongoing], a + + ; calculate damage + push de + call unit_attack_get_attack_tile + call unit_find_at + + ld a, h + or a, l + pop de + jp z, @miss ; no unit found + + + push hl + pop bc + ; de = attacker + ; bc = attacked unit + push hl + call stat_calc_physical_damage_vs + pop hl + + ld hl, STR_HIT_FOR + call ui_draw_status_stat + call ui_redraw_player + + ldnull bc + ret +@miss: + ld hl, STR_MISS + ld de, UI_STATUS_LINE + call puts + call ui_request_redraw + ldnull bc + ret + + ; default attack state +st_action_attack_init: + st_def 0x00, unit_action_attack_pick_direction_init, st_action_attack_pick_direction +st_action_attack_pick_direction: + st_def 0x00, unit_action_attack_pick_direction, st_action_attack_pick_direction +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 diff --git a/src/main.s b/src/main.s index 1b45af6..202f777 100644 --- a/src/main.s +++ b/src/main.s @@ -79,6 +79,8 @@ main: #include "objanim.s" #include "battle.s" #include "action.s" +#include "attack.s" +#include "shoot.s" #include "action_menu.s" #include "select_menu.s" diff --git a/src/shoot.s b/src/shoot.s new file mode 100644 index 0000000..fc6d785 --- /dev/null +++ b/src/shoot.s @@ -0,0 +1 @@ +; shoot (ranged attack) actions -- 2.30.2