From: Lukas Krickl Date: Sat, 16 Aug 2025 04:17:34 +0000 (+0200) Subject: unit: Added basic stub for handling assinged actions on A or B X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=1160771cfabd81e1475e4547c5b98baf97dbc507;p=gbrg%2F.git unit: Added basic stub for handling assinged actions on A or B --- diff --git a/src/action.s b/src/action.s new file mode 100644 index 0000000..0b8929a --- /dev/null +++ b/src/action.s @@ -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 diff --git a/src/defs.s b/src/defs.s index e9a414b..85579ed 100644 --- a/src/defs.s +++ b/src/defs.s @@ -177,12 +177,6 @@ ; 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 @@ -349,13 +343,11 @@ .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 diff --git a/src/macros.inc b/src/macros.inc index 8cd0b60..903578e 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -190,8 +190,6 @@ .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) diff --git a/src/main.s b/src/main.s index 14b03a7..fd06531 100644 --- a/src/main.s +++ b/src/main.s @@ -78,6 +78,7 @@ main: #include "actsave.s" #include "objanim.s" #include "battle.s" +#include "action.s" ; fill bank .fill 0xFF, 0x4000 - $ diff --git a/src/unit.s b/src/unit.s index 4920fb1..11971a4 100644 --- a/src/unit.s +++ b/src/unit.s @@ -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 diff --git a/src/update.s b/src/update.s index 18f48fe..39958bf 100644 --- a/src/update.s +++ b/src/update.s @@ -54,6 +54,7 @@ new_game_init: call ui_init call unit_load_default_player + call actions_new_game_init ; init initial map diff --git a/src/wram.s b/src/wram.s index d8d9b84..b7a49d2 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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: