unit: Added a simple delay flag for when an attack is ongoing
authorLukas Krickl <lukas@krickl.dev>
Wed, 27 Aug 2025 15:49:24 +0000 (17:49 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 27 Aug 2025 15:49:24 +0000 (17:49 +0200)
src/action.s
src/defs.s
src/unit.s

index 56ca42f8bca6c8e460a435464b0111be6aa15726..4e6cc7f7aca8898f895ca961b11f1c48c01e8047 100644 (file)
@@ -1,5 +1,5 @@
 #define ACTION_ATTACK_SPRITE1 0xA0 
-#define UNIT_ACTION_ATTACK_ANIM_LEN 1  
+#define UNIT_ACTION_ATTACK_ANIM_LEN 16         
 
        ; sets up default actions for a new game 
        ; for button A and button B
@@ -211,6 +211,11 @@ unit_action_attack:
        ret
 
 @done:
+       ; unset flag
+       ld a, [gameplay_flags]
+       and a, ~GPF_ATTACK_ONGOING & 0xFF
+       ld [gameplay_flags], a
+
        ; set animation timer and delay
        ld bc, st_unit_delay_to_active 
        ret
@@ -221,9 +226,12 @@ unit_action_attack:
        ;       returns:
        ;               bc: new state
 unit_action_attack_damage_calc:
-       ; TODO: do real damage calculation here
-       ; for now just delete the actor
+       ;  set flag
+       ld a, [gameplay_flags]
+       or a, GPF_ATTACK_ONGOING
+       ld [gameplay_flags], a
        
+       ; calculate damage
        push de
        call unit_attack_get_attack_tile
        call unit_find_at
index 8f78c52eeac3a3381be2ebbbb4e5cd09b7bcccff..f31e402ae861f0dd586adcb7c1cf5f0f3a5666cd 100644 (file)
        ; set if the player has taken their turn
        ; this will allow all other units to 
        ; perform their update
-.de GPF_PLAYER_TURN_TAKEN, 1
+.de GPF_PLAYER_TURN_TAKEN, 2 
+       ; set while an attack animation is playing
+       ; delay to active actor stats should wait until this
+       ; is cleared
+.de GPF_ATTACK_ONGOING, 4
 
   ; cell flags
 .se 1 
index 6e36a2359f7b2bdfbecb2268b159780397727958..5f27cb4975a20e26a726f2981c08cbe652f4c304 100644 (file)
@@ -755,8 +755,16 @@ unit_sleep:
   ; inputs:
   ;   de: unit
 unit_delay_to_active:
+       ; do not proceed if an attack animation is ongoing
+       ld a, [gameplay_flags]
+       and a, GPF_ATTACK_ONGOING
+       jr nz, @delay_again REL
+
   ldnull bc
   ret
+@delay_again:
+       ld bc, st_unit_delay_to_active
+       ret
 
   ; inputs
   ;   de: actor