From 9dc63c0ee0cb36aff06da7d52b4a2eb2b8745c55 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 21 Jun 2025 16:03:10 +0200 Subject: [PATCH] unit: removed turn-based code This change removes a lot of turn based code around moves, moves max initiavite etc. It also simply sets all units to active which effectively makes the game real time. --- src/actortables.s | 2 +- src/defs.s | 2 - src/macros.inc | 2 - src/map.s | 27 +---- src/player.s | 4 +- src/stats.s | 21 ---- src/ui.s | 41 -------- src/unit.s | 252 ---------------------------------------------- src/unit_demo.s | 34 +++++-- src/update.s | 4 - 10 files changed, 32 insertions(+), 357 deletions(-) diff --git a/src/actortables.s b/src/actortables.s index bf7807a..331ecc8 100644 --- a/src/actortables.s +++ b/src/actortables.s @@ -3,7 +3,7 @@ default_map_actor_table: .db 2 ; size dw unit_demo_2 -; dw unit_demo_3 +dw unit_demo_3 diff --git a/src/defs.s b/src/defs.s index 88b927d..b706534 100644 --- a/src/defs.s +++ b/src/defs.s @@ -49,7 +49,6 @@ ; gameplay flags .se 1 -.de GPF_UNIT_NEXT, 1 ; cell flags .se 1 @@ -143,7 +142,6 @@ .de act_mp, stat_size .de act_fatigue, stat_size .de act_ac, stat_size -.de act_moves, stat_size ; moves for each turn ; stats2 .de act_str, stat_size diff --git a/src/macros.inc b/src/macros.inc index 7ff8947..5ec9ae7 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -188,14 +188,12 @@ ; $3 mana points ; $4 fatigue points ; $5 armor - ; $6 moves #macro act_stat_def1 .db $1 ; level .db $2 ; hp hp max .db $3 ; mp mp max .db $4 ; fatigue fatigue max .db $5 ; ac - .db $6 ; moves moves max #endmacro ; $1 str diff --git a/src/map.s b/src/map.s index db453b3..d629f6b 100644 --- a/src/map.s +++ b/src/map.s @@ -233,8 +233,8 @@ map_actors_load: jr nz, @loop REL ; hand over control to a unit - ld de, p_empty_unit - call unit_next_request + ld de, player_unit + call unit_wake_up ret ; loads map tilesets @@ -300,29 +300,6 @@ map_draw_all: ret - ; sets up some actors for debug purposes -map_load_demo_actors: - ; load a single demo actor into p0 units - ld de, unit_player - ld hl, p0_units - ld bc, act_size - call memcpy - - ld de, unit_demo_2 - ld hl, p0_units + act_size - ld bc, act_size - call memcpy - - ld de, unit_demo_3 - ld hl, p0_units + act_size * 2 - ld bc, act_size - call memcpy - - ld de, p_empty_unit - call unit_next_request - - ret - ; empty actor table map_actor_table_null: .db 0 diff --git a/src/player.s b/src/player.s index a2d31fc..c3f1cb8 100644 --- a/src/player.s +++ b/src/player.s @@ -8,8 +8,6 @@ unit_load_default_player: ld bc, act_size call memcpy - ld de, p_empty_unit - call unit_next_request ret unit_player_init: @@ -42,7 +40,7 @@ unit_player_update: unit_player: st_def 0x00, unit_player_init, st_unit_idle act_def ACT_T_DEMO_1, 0, 2, 2, 0 - act_stat_def1 1, 1, 1, 1, 1, 1 + act_stat_def1 1, 1, 1, 1, 1 act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 act_attr_def_empty act_inventory_empty diff --git a/src/stats.s b/src/stats.s index c3b3b56..4dd2f9b 100644 --- a/src/stats.s +++ b/src/stats.s @@ -7,24 +7,3 @@ stat_calc_str: ret - ; calculates the current actor's initiative - ; inputs: - ; de: actor - ; returns: - ; a: init -stat_calc_init: - ; TODO - ; for now we just hard-code - ld a, 1 - ret - - ; calculates the current actor's max moves - ; inputs: - ; de: actor - ; retrns: - ; a: moves max -stat_calc_moves_max: - ; TODO - ; for now we just hard-code - ld a, 1 - ret diff --git a/src/ui.s b/src/ui.s index efda7bb..f72464e 100644 --- a/src/ui.s +++ b/src/ui.s @@ -47,45 +47,4 @@ ui_draw: xor a, DRAWF_UPDATE_UI ld [draw_flags], a - ld a, [ui_draw_actor] - ld l, a - ld a, [ui_draw_actor+1] - ld h, a - ; hl = actor - ld de, act_moves - add hl, de ; hl = current moves - ld a, [hl] ; a = counter - ld d, a ; d = counter - - call stat_calc_moves_max - ; a = moves max counter - sub a, d ; max - current - ld e, a ; e = moves max counter - - ld hl, SCRN1+1 - - ; draw to screen - ld a, d - cp a, 0 - jr z, @skip_loop_current REL - - ld a, UI_TILE_MOVE -@loop_current: - ld [hl+], a - dec d - jr nz, @loop_current REL - -@skip_loop_current: - - ; draw used moves - ld a, e ; check if e is already 0 - cp a, 0 - ret z ; do not draw if e is 0 - - ld a, UI_TILE_MOVE_USED -@loop_max: - ld [hl+], a - dec e - jr nz, @loop_max REL - ret diff --git a/src/unit.s b/src/unit.s index 344af06..583f7bd 100644 --- a/src/unit.s +++ b/src/unit.s @@ -63,29 +63,6 @@ unit_update_draw: call_hl ret -unit_handle_cpu_inputs: - ; pick where to go - call roll_d16 - and a, 3 ; 0-3 - ; 0 == left - cp a, 0 - call z, unit_try_move_left - - ; 1 == right - cp a, 1 - call z, unit_try_move_right - - ; 2 == up - cp a, 2 - call z, unit_try_move_up - - ; 3 == down - cp a, 3 - call z, unit_try_move_down - - ld bc, st_unit_delay_to_active_fast - ret - ; inputs ; de: actor @@ -355,9 +332,6 @@ unit_collides_with_any_other: ; actor initiative based on tile flags ; actor position unit_try_move_up: - call unit_use_move - ret z - ; y - 1 unit_test_collision dec b, CF_COLLISION @@ -374,9 +348,6 @@ unit_try_move_up: ret unit_try_move_down: - call unit_use_move - ret z - ; y + 1 unit_test_collision inc b, CF_COLLISION @@ -392,9 +363,6 @@ unit_try_move_down: ret unit_try_move_left: - call unit_use_move - ret z - ; x - 1 unit_test_collision dec c, CF_COLLISION @@ -410,8 +378,6 @@ unit_try_move_left: ret unit_try_move_right: - call unit_use_move - ret z ; x + 1 unit_test_collision inc c, CF_COLLISION @@ -427,32 +393,6 @@ unit_try_move_right: ld [hl], a ret - ; consumes a move - ; sets UI redraw flag - ; fails (z flag set) if no moves left - ; switches to next unit if moves reach 0 - ; inputs: - ; de: unit -unit_use_move: - push de - call ui_unit_need_draw - - ld hl, act_moves - add hl, de - pop de ; hl = act_moves - - ld a, [hl] ; current - cp a, 0 ; if 0 exit - ret z - - dec a - ld [hl], a - - ; we need the z flag to not be set ehre - ; so just do something that will always unset it - or a, 1 - ret - ; centers the current scroll on the selected unit ; snaps to corners of the map ; inputs: @@ -559,193 +499,6 @@ unit_sleep: call memcpy ret - ; requests unit next - ; to be executed - ; inputs: - ; de: current unit -unit_next_request: - ld a, [gameplay_flags] - and a, GPF_UNIT_NEXT - ret nz ; do not call again if flag is set - - ld a, [gameplay_flags] - or a, GPF_UNIT_NEXT - ld [gameplay_flags], a - - ld a, e - ld [gameplay_unit_current], a - ld a, d - ld [gameplay_unit_current+1], a - - ; set up delay timer - ld a, 16 - ld [unit_next_timer], a - - ret - - ; finds a unit with a higher initiative value - ; than the current one that has moves > 0 set - ; if all unts have have 0 moves, set moves to - ; initial value and try again - ; when a unit has higher initiative it can still fail - ; to take the turn if it rolls a d16 and the roll is < initiative - ; skips any ACT_T_NULL types - ; inputs: - ; gameplay_unit_current: unit that requested a change - ; uses: - ; unit_next_best_init: as a temporary buffer -unit_next: - ; if the unit_next timer is not 8 - ; wait and timer-- - ld a, [unit_next_timer] - cp a, 0 - jr z, @go REL - dec a - ld [unit_next_timer], a - ret -@go: - ; unset flag - ld a, [gameplay_flags] - xor a, GPF_UNIT_NEXT - ld [gameplay_flags], a - - ; load requestor unit - ld a, [gameplay_unit_current] - ld e, a - ld a, [gameplay_unit_current+1] - ld d, a - - push de - call unit_sleep - pop de - ; set moves of current unit to 0 - ld hl, act_moves - add hl, de - ld [hl], 0 ; moves = 0 -unit_next_no_current: -@again: - xor a, a - ld [unit_next_best_init], a - - ; clear current ptr - ld [unit_next_best_act_ptr], a - ld [unit_next_best_act_ptr+1], a - - ld hl, p0_units - ld b, UNITS_MAX - - ; same as unit_next: - ; inputs: - ; de: free to use - ; hl: unit table - ; b: unit count -@unit_next_loop: - push hl ; save table - ld de, act_type - add hl, de ; hl = type - - ; check type skip it NULL - ld a, [hl] - cp a, ACT_T_NULL - jr z, @skip REL - - ; check if moves are not 0 - pop hl - push hl - ld de, act_moves - add hl, de - ld a, [hl] - cp a, 0 - jr z, @skip REL - - pop hl - push hl - ; check if this actor is better - ; than the previous actor - ld a, [unit_next_best_init] - cp a, 0 ; if prev best is 0 proceed anyway - ld d, a ; d = previous best init - - pop de ; de = actor - push de ; store again for later - call stat_calc_init ; a = init of new actor - jr z, @first_hit REL ; on first match - - ; check if this init value is better - ; if not proceed - cp a, d - jr c, @skip REL ; d > a? -@first_hit: - ; otherwise store new init value and hl - pop hl - push hl - - ld [unit_next_best_init], a - - ld a, l - ld [unit_next_best_act_ptr], a - ld a, h - ld [unit_next_best_act_ptr+1], a - -@skip: - pop hl ; restore table - ld de, act_size - add hl, de ; next act - - dec b - jr nz, @unit_next_loop REL - - ; if here unit_next_best_act_ptr is still 0000 - ; reste all moves and try again - ld a, [unit_next_best_act_ptr] - ld b, a - ld a, [unit_next_best_act_ptr+1] - xor a, b - jr z, @retry REL - - ; load new bext into hl - ; and set active - ld a, [unit_next_best_act_ptr] - ld [ui_draw_actor], a - ld e, a - ld a, [unit_next_best_act_ptr+1] - ld [ui_draw_actor+1], a - ld d, a - - push de - call unit_wake_up - pop de - call ui_unit_need_draw - ret - -@retry: - call unit_reset_all_moves - jp @again - - ; resets all moves - ; of all actors in p0 and p1_unts -unit_reset_all_moves: - ld b, UNITS_MAX - ld hl, p0_units -@loop: - push hl - - pop de - push de - call stat_calc_moves_max - - ld de, act_moves - add hl, de ; hl = current moves - ld [hl], a ; moves are now reset - - pop hl - ld de, act_size - add hl, de ; move to next act - dec b - jr nz, @loop REL - - ret - ; called before switching to active ; this call also checks if the unit may need to ; hand over control to a new unit @@ -754,11 +507,6 @@ unit_reset_all_moves: ; de: unit unit_delay_to_active: call unit_resume_objs - ld hl, act_moves - add hl, de ; hl = moves - ld a, [hl] - cp a, 0 - call z, unit_next_request ldnull bc ret diff --git a/src/unit_demo.s b/src/unit_demo.s index 13da365..630d9f2 100644 --- a/src/unit_demo.s +++ b/src/unit_demo.s @@ -8,19 +8,41 @@ unit_demo_1_cpu_update: push de call unit_handle_cpu_inputs pop de - + ret +unit_handle_cpu_inputs: + ; pick where to go + call roll_d16 + and a, 3 ; 0-3 + ; 0 == left + cp a, 0 + call z, unit_try_move_left + + ; 1 == right + cp a, 1 + call z, unit_try_move_right + + ; 2 == up + cp a, 2 + call z, unit_try_move_up + + ; 3 == down + cp a, 3 + call z, unit_try_move_down + + ld bc, st_unit_delay_to_active + ret + + unit_demo_1_cpu_update_idle: - call unit_use_move - call unit_next_request ldnull bc ret unit_demo_2: st_def 0x00, unit_demo_1_init, st_unit_idle act_def ACT_T_DEMO_1, 0, 3, 3, 0 - act_stat_def1 1, 1, 1, 1, 1, 1 + act_stat_def1 1, 1, 1, 1, 1 act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 act_attr_def_empty act_inventory_empty @@ -31,9 +53,9 @@ unit_demo_2: act_rt_def unit_demo_3: - st_def 0x00, unit_demo_1_init, st_unit_idle + st_def 0x00, unit_demo_1_init, st_unit_demo_1_cpu_update act_def ACT_T_DEMO_1, 0, 4, 4, 0 - act_stat_def1 1, 1, 1, 1, 1, 1 + act_stat_def1 1, 1, 1, 1, 1 act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 act_attr_def_empty act_inventory_empty diff --git a/src/update.s b/src/update.s index bdc3555..3327007 100644 --- a/src/update.s +++ b/src/update.s @@ -16,10 +16,6 @@ update_game: ld hl, p0_units call units_update - ld a, [gameplay_flags] - and a, GPF_UNIT_NEXT - call nz, unit_next - ldnull bc ret -- 2.30.2