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

-- We need to spawn them this way to restrict this hero to 1 per team

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

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

function State_Init(message)
	if message == OnEnter then
		--Sleep(5) --Hyperspace time
		--Object.Suspend_Locomotor(true)
		Object.Hide(true)
		Object.Prevent_All_Fire(true)

		ref_type = Find_Object_Type("TIE_Prototype")
		position = Object.Get_Position()
		player = Object.Get_Owner()

		hero = Create_Generic_Object(ref_type, position, player)
		hero.Enable_Behavior(24, false) -- Behavior 24 is REVEAL
		hero.Teleport_And_Face(Object)
		hero.Cinematic_Hyperspace_In(1)
		Sleep(3)
		hero.Enable_Behavior(24, true)

	elseif message == OnUpdate then
		if hero.Is_Valid() == false then
			Object.Despawn()
		end	
	end
end