From: Lukas Krickl Date: Fri, 22 Aug 2025 15:53:09 +0000 (+0200) Subject: act_save: actsave now stores mp and hp X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=3b0d67bba9140090c9bfed943112b2e38a98b50b;p=gbrg%2F.git act_save: actsave now stores mp and hp Added damage calculation to attack. Fixed a bug in act_sg that caused the previous slot to be re-read by the wrong map. This was fixed by storign the previous frame's player map cursor. This allows us to use the previous frame as a save location and the current value as a restore location. --- diff --git a/src/action.s b/src/action.s index d8a9c8c..21adf4a 100644 --- a/src/action.s +++ b/src/action.s @@ -223,15 +223,19 @@ unit_action_attack: unit_action_attack_damage_calc: ; TODO: do real damage calculation here ; for now just delete the actor - + + push de call unit_attack_get_attack_tile call unit_find_at - ; set type to NULL - ld de, act_type - add hl, de - ld a, ACT_T_NULL - ld [hl], a + pop de + push hl + pop bc + ; de = attacker + ; bc = attacked unit + push hl + call stat_calc_physical_damage_vs + pop hl ldnull bc ret diff --git a/src/actortables.s b/src/actortables.s index c528f78..a4b668d 100644 --- a/src/actortables.s +++ b/src/actortables.s @@ -11,7 +11,7 @@ floor_1_actor_table: map_c_actor_table: .db 7 ; size -dw unit_demo_2 +dw unit_demo_warrior dw unit_demo_warrior dw unit_demo_warrior dw unit_demo_mage diff --git a/src/actsave.s b/src/actsave.s index f632eef..edd6598 100644 --- a/src/actsave.s +++ b/src/actsave.s @@ -9,11 +9,11 @@ act_save_init: ; loads current start of save game slot ; based on the current map seed index + ; inputs: + ; a: map cursor ; returns: ; bc: act save game slot act_sg_load_current_slot: - ld a, [player_map_cursor] ; a = seed index - ld hl, act_sg ; no need to loop if a is 0 cp a, 0 @@ -28,6 +28,7 @@ act_sg_load_current_slot: @done: push hl pop bc ; we want return value in bc + BREAK ret @@ -41,6 +42,8 @@ act_sg_store: ld a, [map_header+1] or a, b ret z + + ld a, [player_map_cursor_prev] call act_sg_load_current_slot ld hl, p0_units @@ -91,6 +94,26 @@ act_sg_store_single: inc bc pop hl + ; store hp + push hl + ld de, act_hp + add hl, de + + ld a, [hl] + ld [bc], a + inc bc + pop hl + + ; sotre mp + push hl + ld de, act_mp + add hl, de + + ld a, [hl] + ld [bc], a + inc bc + pop hl + ; advance to next actor ld de, act_size add hl, de @@ -100,6 +123,7 @@ act_sg_store_single: ; restores actor save game based on ; current map's seed offset act_sg_restore: + ld a, [player_map_cursor] call act_sg_load_current_slot ; skip over player .rep i, act_sg_size, 1, inc bc @@ -156,6 +180,27 @@ act_sg_restore_single: pop hl + ; load hp + push hl + ld de, act_hp + add hl, de + + ld a, [bc] + ld [hl], a + inc bc + + pop hl + + ; load mp + push hl + ld de, act_mp + add hl, de + + ld a, [bc] + ld [hl], a + inc bc + pop hl + ld de, act_size add hl, de ; next actor ret diff --git a/src/defs.s b/src/defs.s index 849af37..f2182dc 100644 --- a/src/defs.s +++ b/src/defs.s @@ -254,6 +254,8 @@ .de act_sg_pos_y, 1 .de act_sg_pos_x, 1 .de act_sg_p0, 1 +.de act_sg_hp, 1 +.de act_sg_mana, 1 .de act_sg_size, 0 #define ACT_SG_DEFAULT_VALUE 0xFF diff --git a/src/stats.s b/src/stats.s index fbeccb0..ffac5a3 100644 --- a/src/stats.s +++ b/src/stats.s @@ -74,6 +74,7 @@ stat_calc_hp_max: ; a: damage stat_calc_physical_damage_vs: ; actor 1 + push bc call stat_calc_weapon_damage ; a = damage @@ -81,19 +82,18 @@ stat_calc_physical_damage_vs: ; weapon damage + strenth / 8 call stat_calc_str - sla a ; / 2 - sla a ; / 4 - sla a ; / 8 + sra a ; / 2 + sra a ; / 4 + sra a ; / 8 add a, b ld b, a ; b = real damage ; actor 2 - push bc pop de ; de = actor2 now ; damage - ac/2 call stat_calc_ac - sla a + sra a sub_ba jp c, @no_damage @@ -110,6 +110,9 @@ stat_calc_physical_damage_vs: ; write new hp ld [hl], a + + ; a = damage dealt + ld a, b ret @no_damage: @@ -118,6 +121,7 @@ stat_calc_physical_damage_vs: @dead: xor a, a ld [hl], a ; write 0 hp + ld a, b ; a = damage dealt ret ; calculates the real speed state diff --git a/src/unit_cpu.s b/src/unit_cpu.s index 2325cad..e6c2af4 100644 --- a/src/unit_cpu.s +++ b/src/unit_cpu.s @@ -1,5 +1,27 @@ #define UNIT_SCAN_RANGE_Y MAP_H/4 #define UNIT_SCAN_RANGE_X MAP_W/4 + + ; checks if the unit is dead + ; if so sets type to 0 + ; inputs: + ; de: actor + ; returns: + ; z-flag if dead +unit_cpu_check_dead: + ld hl, act_hp + add hl, de + ld a, [hl] + cp a, 0 + ret nz ; not dead + push af + + ld a, ACT_T_NULL + ld hl, act_type + add hl, de + ld [hl], a ; set type to NULL + + pop af + ret ; handles cpu inputs ; chaser CPU script @@ -9,6 +31,11 @@ ; bc: next state unit_handle_cpu_inputs: #define MOVE_MADE scratch + + ; check if dead + ; if so set type to 0 + call unit_cpu_check_dead + ret z ; check if player has taken turn ; if not exit diff --git a/src/update.s b/src/update.s index 5cad867..37e862f 100644 --- a/src/update.s +++ b/src/update.s @@ -23,6 +23,9 @@ update_game: ld de, objanim call st_update + ld a, [player_map_cursor] + ld [player_map_cursor_prev], a + ldnull bc ret diff --git a/src/wram.s b/src/wram.s index d157d9c..3537764 100644 --- a/src/wram.s +++ b/src/wram.s @@ -161,6 +161,8 @@ p0_units: .adv act_size * UNITS_MAX ; go left: dec ; go right: inc player_map_cursor: .adv 1 + ; the previous frame's map cursor +player_map_cursor_prev: .adv 1 ; one byte per map ; indicating where doors should be placed