From: Lukas Krickl Date: Mon, 16 Jun 2025 04:49:23 +0000 (+0200) Subject: unit: reworked moves stat to have the max calculated X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=e3a24024a1e4aef9eb7e70d4346064932d2eb333;p=gbrg%2F.git unit: reworked moves stat to have the max calculated removed initiative stat. This stat will be calculated entierly based on other stats in the future --- diff --git a/TODO.md b/TODO.md index 995c9ee..bb89fee 100644 --- a/TODO.md +++ b/TODO.md @@ -8,10 +8,10 @@ ## Combat -[ ] Unit is selected based on the unit initiative queue +[x] Unit is selected based on the unit initiative queue [ ] A unit may skip its turn (moved to end of queue) [x] Units have a move counter -[ ] Move counter should be 1 for most units +[x] Move counter should be 1 for most units [x] Display moves in UI for selected units [x] Each action consumes moves [x] Units are moved one tile at a time @@ -22,14 +22,12 @@ [ ] When a unit moves away from an adjacent melee unit it can attack [x] Units are selected in a queue of initiative [x] Once the queue is empty it is reset -[ ] Units use state machines to update -[ ] Each unit's start state is a polling state -[ ] The polling state can either be player input or CPU input -[ ] Mark the current active unit with a cursor -[ ] When starting an encounter the player can place all hero units and troops based on initiative -[ ] The player can collect up to 5 initiative points -[ ] Initiative can be spent on deployment or special moves -[ ] Rework all max stats to be calculated (e.g. hp max is calculated based on endurance) +[x] Units use state machines to update +[x] Each unit's start state is a polling state +[x] The polling state can either be player input or CPU input +[x] Mark the current active unit with a cursor +[x] When starting an encounter the player can place all hero units and troops based on initiative +[x] Rework all max stats to be calculated (e.g. hp max is calculated based on endurance) ## Map @@ -37,7 +35,7 @@ [x] A map may reduce the playfield by making out of bounds tiles walls [x] The camera always centers on the current unit [x] All units are always visible -[ ] Tiles can be impassible, walls or walkable +[x] Tiles can be impassible, walls or walkable [ ] Tiles may cost extra movement to pass ## Units @@ -59,11 +57,9 @@ [ ] Only center camera on player ### Dice display -[ ] When a unit fails to take initiative display dice roll and focus on unit with camera -[ ] Update dice display for n frames until timer is 0 -[ ] Then continue the game -[ ] Rework dice display to be a per-unit runtime only flag -[ ] Dice display per unit should update in draw if timer is not 0 +[x] Update dice display for n frames until timer is 0 +[x] Rework dice display to be a per-unit runtime only flag +[x] Dice display per unit should update in draw if timer is not 0 ## Randomness diff --git a/src/defs.s b/src/defs.s index bfa1822..2b7a6ff 100644 --- a/src/defs.s +++ b/src/defs.s @@ -81,25 +81,10 @@ ; stats struct - ; with current and max - ; used for hp, mp, fatigue, moves - ; all other stats only have a max value - ; and their real value is calculated before use + ; this tracks the current value. most real values + ; are calculated ; e.g. stat_calc_str with actor as input - ; used for stats that can change and reset - ; regularly -.se 0 -.de stat_cur, 1 -.de stat_max, 1 -.de stat_size, 0 - - ; lite stat with max value only - ; used for stats that are not intended to - ; decrease regularly - ; stat lite's real value is - ; calculated using an actor - ; and stat_calc_nnn calls -#define stat_lite_size 1 +#define stat_size 1 ; status effect .se 0 @@ -154,19 +139,18 @@ .de act_hp, stat_size .de act_mp, stat_size .de act_fatigue, stat_size -.de act_ac, stat_lite_size +.de act_ac, stat_size .de act_moves, stat_size ; moves for each turn -.de act_init, stat_lite_size ; initiative value ; stats2 -.de act_str, stat_lite_size -.de act_int, stat_lite_size -.de act_dex, stat_lite_size -.de act_luck, stat_lite_size -.de act_will, stat_lite_size -.de act_charisma, stat_lite_size -.de act_endurance, stat_lite_size -.de act_speed, stat_lite_size +.de act_str, stat_size +.de act_int, stat_size +.de act_dex, stat_size +.de act_luck, stat_size +.de act_will, stat_size +.de act_charisma, stat_size +.de act_endurance, stat_size +.de act_speed, stat_size ; attributes ; describes skills @@ -175,7 +159,8 @@ ; stores items, for all actors but player ; there are 4 inventory slots. ; if the actor is type player a special inventory - ; used instead + ; used instead + ; call unit_get_inventory to get a ptr and length ; equipment ; stores all items equiped diff --git a/src/macros.inc b/src/macros.inc index 9fc0ce0..9d2162d 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -169,15 +169,13 @@ ; $4 fatigue points ; $5 armor ; $6 moves - ; $7 initiative #macro act_stat_def1 .db $1 ; level - .db $2, $2 ; hp hp max - .db $3, $3 ; mp mp max - .db $4, $4 ; fatigue fatigue max + .db $2 ; hp hp max + .db $3 ; mp mp max + .db $4 ; fatigue fatigue max .db $5 ; ac - .db $6, $6 ; moves moves max - .db $7 ; initiative + .db $6 ; moves moves max #endmacro ; $1 str diff --git a/src/stats.s b/src/stats.s index 3ecac69..c3b3b56 100644 --- a/src/stats.s +++ b/src/stats.s @@ -6,3 +6,25 @@ ; a: str value 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/unit.s b/src/unit.s index e76b495..83e0391 100644 --- a/src/unit.s +++ b/src/unit.s @@ -610,12 +610,13 @@ unit_next_no_current: push hl ; check if this actor is better ; than the previous actor - ld de, act_init - add hl, de ld a, [unit_next_best_init] cp a, 0 ; if prev best is 0 proceed anyway ld d, a ; d = previous best init - ld a, [hl] ; a = init of new actor + + 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 @@ -627,16 +628,6 @@ unit_next_no_current: pop hl push hl - ; this unit is better - ; but it can fail an initiative roll - push af - call roll_d16 - ld d, a ; d = roll value - pop af ; a = init value - cp a, d - call nc, unit_dice_display_set_hl - jr nc, @skip REL ; d < a - ld [unit_next_best_init], a ld a, l @@ -685,12 +676,14 @@ unit_reset_all_moves: ld b, UNITS_MAX ld hl, p0_units @loop: - push hl - ld de, act_moves+1 - add hl, de ; hl = act_moves_max + push hl - ld a, [hl] - dec hl ; hl = current moves + 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 @@ -815,7 +808,7 @@ unit_get_equipment: unit_demo_1: st_def 0x00, unit_demo_1_init, st_unit_idle act_def ACT_T_DEMO_1, 0, 2, 2, 0 - act_stat_def1 1, 1, 1, 1, 1, 3, 3 + act_stat_def1 1, 1, 1, 1, 1, 1 act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 act_attr_def_empty act_inventory_empty @@ -828,7 +821,7 @@ unit_demo_1: 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, 0, 3 + act_stat_def1 1, 1, 1, 1, 1, 1 act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 act_attr_def_empty act_inventory_empty @@ -841,7 +834,7 @@ unit_demo_2: unit_demo_3: st_def 0x00, unit_demo_1_init, st_unit_idle act_def ACT_T_DEMO_1, 0, 4, 4, 0 - act_stat_def1 1, 1, 1, 1, 1, 4, 5 + act_stat_def1 1, 1, 1, 1, 1, 1 act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 act_attr_def_empty act_inventory_empty