@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:
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
--- /dev/null
+; 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