----------------------------------------------------------------------------------------------------------------
-- Actor / NIS helper functions
-- (c) 2005 Relic Entertainment Inc.


-- This is a table of the all actors used in NISlet speech events.
-- Each actor needs a blueprint and a speech icon associated with it.
-- NOTE: As you update these, make sure to update the @extdesc in Util_PlayActorSpeech below!

function Actor_Init()

	ACTOR = {}
	
	-- Generic
	ACTOR.GenericAlly =	{group = SGroup_Create("actorgroup_1"),	icon = "InGame\\portraits\\speech_allied_soldier"}
	ACTOR.GenericAxis =	{group = SGroup_Create("actorgroup_2"), icon = "InGame\\portraits\\speech_axis_soldier"}
	ACTOR.Intel =		{group = SGroup_Create("actorgroup_intel"), icon = "InGame\\portraits\\tutorial_guy"}

	-- SP Characters
	ACTOR.McKay = 		{group = SGroup_Create("actorgroup_mckay"), icon = "InGame\\portraits\\speech_allied_mackay"}
	ACTOR.Conti = 		{group = SGroup_Create("actorgroup_conti"), icon = "InGame\\portraits\\speech_allied_conti"}
	ACTOR.Thompson = 	{group = SGroup_Create("actorgroup_thompson"), icon = "InGame\\portraits\\speech_allied_thompson"}
	ACTOR.Carota =		{group = SGroup_Create("actorgroup_carota"), icon = "InGame\\portraits\\speech_allied_carota"}
	ACTOR.Lewis =		{group = SGroup_Create("actorgroup_lewis"), icon = "InGame\\portraits\\speech_allied_lewis"}
	
end

Scar_AddInit(Actor_Init)



--? @group Presentation

--? @shortdesc Tie a single squad to an actor, so audio comes from a squad member
--? @result Void
--? @args ActorTable actor, SquadID squad
function Actor_SetFromSquad(actor, squadid)
	SGroup_Add(actor.group, squadid)
end


--? @shortdesc Tie an entire sgroup to an actor, so audio comes from a squad member
--? @result Void
--? @args ActorTable actor, SGroupID sgroup
function Actor_SetFromSGroup(actor, sgroupid)
	SGroup_AddGroup(actor.group, sgroupid)
end


--? @shortdesc Clear ties between an actor and any units
--? @result Void
--? @args ActorTable actor
function Actor_Clear(actor)
	SGroup_Clear(actor.group)
end


function Actor_PlaySpeechInternal(portrait, actor, locID, continueButton, stickySubtitle, blockInput)

	if continueButton == nil then continueButton = false end
	if stickySubtitle == nil then stickySubtitle = false end
	if blockInput == nil then blockInput = false end

	-- single place to check SP mission path...
	local path = ""
	if g_MissionSpeechPath ~= nil then
		path = g_MissionSpeechPath
	end
	
	-- play speech
	if( SGroup_CountSpawned(actor.group) == 0 ) then
		Subtitle_PlaySpeech(actor.icon, locID, not portrait, continueButton, blockInput, stickySubtitle, path)
	else
		local squad = SGroup_GetSpawnedSquadAt(actor.group, World_GetRand(1, SGroup_CountSpawned(actor.group)))
		Subtitle_PlaySquadSpeech(squad, actor.icon, locID, not portrait, continueButton, blockInput, stickySubtitle, path)
	end

end


--? @shortdesc Plays a speech event for a given actor WITH a portrait and subtitle
--? @result Void
--? @args ActorTable actor, Integer locID[, Boolean continueButton, Boolean stickySubtitle, Boolean blockInput]
--? @extdesc Be VERY careful how you use the 'blockInput' parameter. It blocks all input except mouse movement, a few critical keyboard keys, and the Continue and Menu buttons. So you should always allow a continue button when blocking input. You shouldn't block input for a sticky subtitle!
--? If the speech file is not available, a placeholder time will be calculated for the message using the number of words and the message will be displayed for that length of time.\n
--? Actors: ACTOR.GenericAlly, ACTOR.GenericAxis, ACTOR.Keller, ACTOR.McKay, ACTOR.Conti, ACTOR.Franks, ACTOR.Peoples, ACTOR.Coogi, etc...
function Actor_PlaySpeech(actor, locID, continueButton, stickySubtitle, blockInput)
	Actor_PlaySpeechInternal(true, actor, locID, continueButton, stickySubtitle, blockInput)
end


--? @shortdesc Plays a speech event for a given actor WITHOUT a portrait or subtitle. See Actor_PlaySpeech for more details
--? @result Void
--? @args ActorTable actor, Integer locID[, Boolean continueButton, Boolean stickySubtitle, Boolean blockInput]
function Actor_PlaySpeechWithoutPortrait(actor, locID, continueButton, stickySubtitle, blockInput)
	Actor_PlaySpeechInternal(false, actor, locID, continueButton, stickySubtitle, blockInput)
end
