-- Star Wars Empire at War: Secrets of a Fallen Empire
-- Lua Script: //Scripts/GameObject/ObjectScript_SpawnStarBaseHealer.lua
-- Author: Galyana
-- Updated: 6 February, 2026

-- Heals all stations at game start to fix an odd bug
-- Hardpoints will be full healed but stations will still show missing health on healthbar

require("PGStateMachine")
require("PGSpawnUnits")

function Definitions()
	ServiceRate = 1
	Define_State("State_Init", State_Init);
end

function State_Init(message)
	ref_type = Find_Object_Type("Generic_Starbase_Healing_Marker")
	position = Object.Get_Position()
	player = Object.Get_Owner()

	if message == OnEnter then
		Sleep(3)
		
		-- We don't want additional healers spawning if a new level 1 base is constructed
		if GetCurrentTime() >= 30 then
			ScriptExit()
		end
		
		-- Only spawn the healer if our health is below 100%
		if Object.Get_Health() < 1.0 then
			healer = Create_Generic_Object(ref_type, position, player)
			Sleep(5)
			healer.Despawn()
		end
	end

	ScriptExit()
end