action: moved melee attack to attack.s
authorLukas Krickl <lukas@krickl.dev>
Sun, 7 Sep 2025 04:08:41 +0000 (06:08 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 7 Sep 2025 04:08:41 +0000 (06:08 +0200)
src/action.s
src/attack.s [new file with mode: 0644]
src/main.s
src/shoot.s [new file with mode: 0644]

index 43ee5afb14c91b67c650d2df112dd0087bc46ee6..1cbd4bb48901b6c9e59be867bf03ec4336d69e34 100644 (file)
@@ -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 (file)
index 0000000..18acade
--- /dev/null
@@ -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
index 1b45af6683593924b029ace43fe9a6b483b2aba1..202f777fe2c309ccb29e582f1251905935463325 100644 (file)
@@ -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 (file)
index 0000000..fc6d785
--- /dev/null
@@ -0,0 +1 @@
+; shoot (ranged attack) actions