attr: added sub16 call for attacking
authorLukas Krickl <lukas@krickl.dev>
Mon, 2 Feb 2026 13:28:59 +0000 (14:28 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 2 Feb 2026 13:28:59 +0000 (14:28 +0100)
src/actor.s
src/attributes.s
src/defs.s
src/math.s
src/player.s

index f347edffebeb2d98ec194d77807d884014381a4c..ab27f0fc973c00a61dc52b257e05038890a6ec67 100644 (file)
@@ -268,9 +268,9 @@ act_init_set_tact:
        ld hl, act_hp
        add hl, de
        ; set default hp
-       ld a, b
-       ld [hl+], a
        ld a, c
+       ld [hl+], a
+       ld a, b
        ld [hl], a
        
 
index 4266598548804142914d688fc7d764c05c108a18..f70e9d30c21f6779b27e4f5baa25c08d5bacaae9 100644 (file)
@@ -105,10 +105,53 @@ act_attr_get_weapon_damage:
        ; bc = damage
        ret
 
+       ; gets actor's current hp
+       ; inputs:
+       ;               de: actor
+       ;       returns:
+       ;               bc: current hp
+act_attr_get_hp:
+       ld hl, act_hp
+       add hl, de
+       ld a, [hl+]
+       ld c, a
+       ld a, [hl]
+       ld b, a
+       ret
+
+       ; writes hp
+       ; inputs:
+       ;               de: actor
+       ;               bc: new hp value
+act_attr_write_hp:
+       ld hl, act_hp
+       add hl, de
+       ld a, c
+       ld [hl+], a
+       ld a, b
+       ld [hl], a
+       ret
+
        ; takes weapon type damage
        ; inputs:
        ;               de: actor to take damage
        ;               bc: damage value
 act_attr_take_weapon_damage:
+       push de
+       
+       ; TODO: apply resistances to bc
+
+       m16_write_bc m16_b
+       call act_attr_get_hp
+       m16_write_bc m16_a
+       call m16_sub
+       ; a - b
+       
+       ; read result back
+       m16_read_bc m16_a
+
+       pop de
+       call act_attr_write_hp
+
        call act_die
        ret
index 61c72b79afd5f643b899bc9ad4cc22d912fe1077..9e8e307305a62b6d56210b10db09c53af1d06caa 100644 (file)
@@ -68,7 +68,7 @@
 .de act_p0, 1
        ; state parameter
 .de act_state, 1
-       ; hp/mp stored in BE
+       ; hp/mp stored in LE
 .de act_hp, 2
 .de act_mp, 2
        ; currently active buff id
index 3517e1e97d7a412e59cf30fd8bd42d63c80992dc..c83aed80e58dacb762b634159b266ebe9b3919cb 100644 (file)
@@ -7,19 +7,19 @@
        ld a, c
        ld [$1], a
        ld a, b
-       ld [$1+1], c
+       ld [$1+1], a
 #endmacro
 #macro m16_write_de
        ld a, e
        ld [$1], a
        ld a, d
-       ld [$1+1], c
+       ld [$1+1], a
 #endmacro
 #macro m16_write_hl
        ld a, l
        ld [$1], a
        ld a, h
-       ld [$1+1], c
+       ld [$1+1], a
 #endmacro
 
 
index 9914d537d3207b321c7809ff73b1f8bbe34d616c..b61f052544fff80051139ef447aadc2005eda66a 100644 (file)
@@ -66,9 +66,9 @@ player_init:
        ; set current hp
        ld de, player
        call act_attr_get_max_hp
-       ld a, b
-       ld [player+act_hp], a
        ld a, c
+       ld [player+act_hp], a
+       ld a, b
        ld [player+act_hp+1], a
                
        _player_set_target -1, 0