From: Lukas Krickl Date: Fri, 22 Aug 2025 12:35:17 +0000 (+0200) Subject: stats: Added basic damage calculation X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=b3af087214f1a7dc032e2e3b03d721e69ec55616;p=gbrg%2F.git stats: Added basic damage calculation --- diff --git a/src/macros.inc b/src/macros.inc index 808b29c..43b33fd 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -265,3 +265,17 @@ #macro farcall rst 0x10 #endmacro + + ; subtracts b-a + ; inputs: + ; a, b + ; returns: + ; b: thew new value + ; uses: + ; c, a, b +#macro sub_ba + ld c, a + ld a, b + sub a, c + ld b, a +#endmacro diff --git a/src/stats.s b/src/stats.s index acc6263..fbeccb0 100644 --- a/src/stats.s +++ b/src/stats.s @@ -64,6 +64,8 @@ stat_calc_hp_max: ; calculates physical damage of ; one actor agains another + ; formula: + ; physical damage = (weapon damage a1 + strength a1 / 8) - (ac a2 / 2) ; inputs: ; de: actor1 ; bc: actor2 @@ -71,19 +73,52 @@ stat_calc_hp_max: ; sub damage from actor2 ; a: damage stat_calc_physical_damage_vs: + ; actor 1 + call stat_calc_weapon_damage ; a = damage - push bc - pop de ; de = actor2 now ld b, a ; b = weapon damage + ; weapon damage + strenth / 8 + call stat_calc_str + sla a ; / 2 + sla a ; / 4 + sla 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 + sub_ba + jp c, @no_damage + ; b = damage to apply + + ; apply damage + + ld hl, act_hp + add hl, de + ; hl = act2 hp + ld a, [hl] + sub a, b + jp c, @dead + + ; write new hp + ld [hl], a ret @no_damage: xor a, a ret +@dead: + xor a, a + ld [hl], a ; write 0 hp + ret ; calculates the real speed state ; inputs: