attr: added hp calculation
authorLukas Krickl <lukas@krickl.dev>
Sat, 17 Jan 2026 15:44:02 +0000 (16:44 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 17 Jan 2026 15:44:02 +0000 (16:44 +0100)
src/attributes.s
src/defs.s
src/player.s

index 335e788349438fa6bc44f148e604a1cc7ffdc426..bf753fc94e8aab6037d39de8fcd5117129398308 100644 (file)
@@ -1,10 +1,58 @@
 
+       ; generall attributes are either returned
+       ; in a (8 bit stats) or bc (16 bit stats)
+
 attr_null:
 attrdef 0, 0, 0, 0, 0
 
 attr_bat:
 attrdef 1, 0, 0, 0, 0
 
+       ; gets the max hp for an actor
+       ; hp formula:
+       ;               4*stam
+       ; inputs:
+       ;               de: actor
+       ;       returns:
+       ;               bc: max hp
+act_attr_get_max_hp:
+       ld a, [de]
+       cp a, ACT_T_PLAYER
+       jp nz, @npc ; not a player
+       
+       
+
+@npc:
+       call act_attr_get_stam
+       ld hl, 0
+       ld de, 4
+@mul:
+               add hl, de
+               dec a
+               jr nz, @mul REL
+
+       push hl
+       pop bc ; bc = hp max
+       
+       ret
+
+       ; get actor stamina
+       ; inputs:
+       ;               de: actor
+       ;       returns:
+       ;               a: stamina
+act_attr_get_stam:
+       ld a, [de]
+       cp a, ACT_T_PLAYER
+       jp nz, @npc ; not a player
+       
+@npc:  
+       call act_load_attr_table
+       ld hl, attr_stam
+       add hl, bc
+       ld a, [hl] ; a = stamina
+       ret
+
        ; gets strength attribute
        ; of a given actor
        ; inputs:
index 61ae2888352d6f042d9cb795ffd9881d908a7f70..1f9e0d9123ea1f95ebc5040d2ecf575f9be7f66b 100644 (file)
@@ -64,6 +64,7 @@
 .de act_p0, 1
        ; state parameter
 .de act_state, 1
+       ; hp/mp stored in BE
 .de act_hp, 2
 .de act_mp, 2
        ; currently active buff id
index 97eafe450a8c267b3604f7ece9020736f6895036..1202ccdf9ae578ea6892431ee5646988513d4152 100644 (file)
@@ -49,6 +49,15 @@ player_init:
        ; set default view
        ld a, 3
        ld [player_viewradius], a
+
+       ; 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+1], a
+
        
        ret