@tool
extends HexTile
class_name HouseHexTile

@export var life_bar : Sprite3D
@export var house_model : Node3D
@export var house_model_broke : Node3D

@export var max_hp : float = 100.

@export var hp : float = max_hp :
    set(v):
        hp = v
        if is_node_ready():
            life_bar.scale = Vector3.ONE * hp / max_hp

@export var destroyed : bool = false : set = set_destroyed

func hit(damage = 1.):
    hp = max(0, hp - damage)

    if hp == 0:
        destroyed = true

func set_destroyed(_destroyed : bool = destroyed):
    destroyed = _destroyed

    if is_node_ready():
        house_model.visible = not destroyed
        house_model_broke.visible = destroyed
