unit: Added basic stub for handling assinged actions on A or B
authorLukas Krickl <lukas@krickl.dev>
Sat, 16 Aug 2025 04:17:34 +0000 (06:17 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 16 Aug 2025 04:17:34 +0000 (06:17 +0200)
src/action.s [new file with mode: 0644]
src/defs.s
src/macros.inc
src/main.s
src/unit.s
src/update.s
src/wram.s

diff --git a/src/action.s b/src/action.s
new file mode 100644 (file)
index 0000000..0b8929a
--- /dev/null
@@ -0,0 +1,47 @@
+       
+       ; sets up default actions for a new game 
+       ; for button A and button B
+actions_new_game_init:
+       ; write default action ptrs
+       ld hl, action_btna  
+       
+       ; default A button action
+       ld a, st_action_attack HI 
+       ld [hl+], a
+       ld a, st_action_attack LO 
+       ld [hl+], a
+
+       ; default B button action
+       ld a, st_action_attack HI
+       ld [hl+], a
+       ld a, st_action_attack LO 
+       ld [hl+], a
+
+       ret
+
+       ; handles an assinged action
+       ; a player can assign any in-game action to either A or B
+       ; inputs:
+       ;               hl: action ptr (usually action btna or action btnb)
+       ;       returns:
+       ;               bc: next state
+unit_handle_assigned_action:
+       ; load state ptr for action
+       ld a, [hl+] 
+       ld b, a
+       ld a, [hl]
+       ld c, a
+       ret
+       
+       ; picks a direction for an attack
+       ;       inputs:
+       ;               de: unit
+       ;       returns:
+       ;               bc: next action
+unit_action_attack_pick_direction:
+       ldnull bc
+       ret
+
+       ; default attack state
+st_action_attack:
+       st_def 0x00, unit_action_attack_pick_direction, st_action_attack 
index e9a414b419e77b3ec282b1d18a46a2fdb0a6cc7c..85579ed95ca9a7b989771c8957a3b82d9959abe5 100644 (file)
   ; last collision with actor
   ; set during unit_collision_woth_any_other
 .de act_rt_collided_with, 2
-       ; indicates which order the actor has in battle mode
-       ; the actors attack rotuine should wait until battle_order == their battle order
-       ; and then perform an action
-       ; battle order should also determine where the battle draw rotuine 
-       ; draws the actor
-.de act_rt_battle_order, 1
 
   ; sub-tile drawing vars
   ; during this animation the actor is already technically in its new 
 .de obja_timer, 1
 .de obja_size, 0
 
-#define BR_MAX 4
 
-       ; battle record
+       ; action struct
 .se 0
-.de br_act_ptr, 2
-.de br_size, 0 
-
+.de action_st_action_ptr, 2
+.de action_size, 0 
 
 ; special text commands
 
index 8cd0b609404da6a21d197956fae7461366b2de26..903578ec117eca6b9b5245ec0121f7fdf425b32c 100644 (file)
   .db 0  ; act_rt_sub_tile 
   ; act_rt_loot_table_dat
   dw 0
-       ; battle order
-       .db 0
 #endmacro
   
   ; defines an actor's stats (1/2)
index 14b03a7b3b9db2e273c1e1eb57d501048b630060..fd065319b51dbd3b6af5b0cc50ef9de54fe656c9 100644 (file)
@@ -78,6 +78,7 @@ main:
 #include "actsave.s"
 #include "objanim.s"
 #include "battle.s"
+#include "action.s"
 
 ; fill bank
 .fill 0xFF, 0x4000 - $
index 4920fb149f6d38033cf9a824ee2aefaba0ea4f5b..11971a4b617117557c6f799f49a520955ec22916 100644 (file)
@@ -293,6 +293,15 @@ unit_handle_inputs:
   ; push next state to the stack for now
   ld bc, NULL
   push bc
+
+       ld b, BTNA
+       input_just
+       ld hl, action_btna
+       jr z, @nota REL
+               pop bc 
+               call unit_handle_assigned_action 
+               push bc ; bc = next state
+@nota:
   
   ld b, BTNUP
   input_held 
index 18f48fe88feb501f0f858301ab88661305fc298c..39958bf92ab62938e0f10beeda51e0b3bfa81c58 100644 (file)
@@ -54,6 +54,7 @@ new_game_init:
   call ui_init
 
   call unit_load_default_player
+       call actions_new_game_init
 
   ; init initial map
   
index d8d9b84aa4b77203c8cf5bae58dacc372a90f275..b7a49d26c1d53d50449b3a57c61c568df74782f7 100644 (file)
@@ -177,9 +177,8 @@ map_header: .adv 2
 act_sg: .adv act_sg_size * UNITS_MAX * FLOOR_MAP_COUNT
 act_sg_end:
 
-battle_records: .adv br_size * BR_MAX
- ; current battle number
- ; compate to act_rt_battle_order to see whose turn it is
-battle_order: .adv 1
+; buttton-assigned actions
+action_btna: .adv action_size
+action_btnb: .adv action_size
 
 state_end: