---------------------------------------------------------------------------
---------------------- Ankh functions -------------------------------------
---------------------------------------------------------------------------
-- The functions defined here are specific to the Ankh project           --
---------------------------------------------------------------------------

-- an empty table where the ankh functions go :)
ankh={}

---------------------------------------------------------------------------
-- initializes the scripted logic for the game
---------------------------------------------------------------------------
function ankh:initialize()
   self:initializeQuests()
   -- kick off the game logic after initialization
   -- this is a single shot, so it will not be called
   -- repeatedly
   
   --TaskMgr:subscribeTaskEvent("RenderTargetUpdater", "EventTaskUpdated", 
   --			      "ankh:startDemo",
   --	   	      true)

   

   --api:setObjectsVisibleByType(GameEntity.DefaultInteractor, false)

   api:script("AnkhDevAux.lua")

   Logger:setLoggingLevel(Log.LL_EVERYTHING)
end
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- initializes/creates all the quests for this game
---------------------------------------------------------------------------
function ankh:initializeQuests()

   local do1stPlayable = true
   local do2ndPlayable = false
   local doPressPreview = false

   local doDemo = true

   if doDemo then
      api:script("AnkhQuest_CrocMask.lua")
      api:script("AnkhQuest_Global.lua")
   elseif do1stPlayable then
      api:script("AnkhQuest_Bulbul_Demo.lua")
   else   
      api:script("AnkhQuest_Global.lua")
      api:script("AnkhQuest_Bulbul.lua")
      api:script("AnkhQuest_Burger.lua")
      api:script("AnkhQuest_TriggerControl.lua")
      api:script("AnkhQuest_CrocMask.lua")
      api:script("AnkhQuest_EnterPalace.lua")
      api:script("AnkhQuest_Embassy.lua")
      api:script("AnkhQuest_EnterTemple.lua")
      api:script("AnkhQuest_EscapeFromHome.lua")
      api:script("AnkhQuest_EscapePalace.lua")
      api:script("AnkhQuest_Final.lua")
      api:script("AnkhQuest_GardenBakery.lua")
      api:script("AnkhQuest_Garden.lua")
      api:script("AnkhQuest_Oasis.lua")
      api:script("AnkhQuest_Osiris.lua")
      api:script("AnkhQuest_Ritual.lua")
      api:script("AnkhQuest_EscapePalace.lua")
      api:script("AnkhQuest_SunOfCairo.lua")
      api:script("AnkhQuest_Sphinx.lua")
      api:script("AnkhQuest_EnterUnderworld.lua")
      api:script("AnkhIntro.lua")

      Global:init()
      Global:activate()
      TriggerControl:init()
      TriggerControl:activate()
      EscapeFromHome:init()
      Burger:init()
      CrocMask:init()
      Oasis:init()
      EnterPalace:init()
      EnterTemple:init()
      GardenBakery:init()
      Garden:init()
      Ritual:init()
      EscapePalace:init()
      Embassy:init()
      Bulbul:init()
      SunOfCairo:init()
      Sphinx:init()
      EnterUnderworld:init()
      Osiris:init()
   end

   if do2ndPlayable then
      iactor_home_noble_street_front_to_bazar:setConfiguration("Demo_iactor_home_noble_street_front_to_bazar")
   end

   if doPressPreview then
      --iactor_palace_prison_cell_to_palace_prison_tunnel:setConfiguration("Demo_iactor_palace_prison_cell_to_palace_prison_tunnel")
   end

end
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- initializes/creates all the conversations used within the first part
-- of the game 
---------------------------------------------------------------------------
function ankh:createConversations()
end
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- initializes/creates all the cutscenes used within the first part
-- of the game 
---------------------------------------------------------------------------
function ankh:createCutscenes()
end
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- starts/kicks off the game logic for the demo
---------------------------------------------------------------------------
function ankh:startDemo()
   CameraMgr:activateCamera("cam_palace_backdoor_entrance")

   Bulbul:init()
   Bulbul:activate()

   --LocationMgr:activateLocation("palace_backdoor")
   --api:cutscene("Bulbul_intro")

   api:cutscene("Bulbul_demo_intro")
   --LocationMgr:activateLocation("palace_backdoor")
   --LocationMgr:changeCameraAndOrLocation("palace_backdoor",
--					 "cam_palace_backdoor_entrance",
	--				 PinaVector3(0,0,0),
		--			 Rotate(Degree(0),Degree(0),Degree(0)),
			--		 "")
end
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- starts/kicks off the game logic
---------------------------------------------------------------------------
function ankh:start()
   TaskMgr:subscribeTaskEvent("RenderTargetUpdater", "EventTaskUpdated", 
			      "GameStateMgr:fadeIn(2.0)",
			      true)
   TaskMgr:subscribeTaskEvent("GameStateManager",
   			      "EventFadingInFinished",
   			      "Ankh:toggleMenu",
   			      true)
end
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- starts/kicks off the game logic
---------------------------------------------------------------------------
function ankh:startGameWithIntro()
   --Intro:activate()
   --TaskMgr:subscribeTaskEvent("RenderTargetUpdater", "EventTaskUpdated", 
	--		      "EscapeFromHome:activate()",
		--	      true)

   CrocMask:init()
   CrocMask:activate()

   api:cutscene("CrocMask_nile_scene")
end
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- starts/kicks off the game logic
---------------------------------------------------------------------------
function ankh:startGame()
   LocationMgr:activateLocation("home")
   TaskMgr:subscribeTaskEvent("RenderTargetUpdater", "EventTaskUpdated", 
			      "EscapeFromHome:activate()",
			      true)
end
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- utility function reparsing all the lua scripts (for devel/debug purposes)
---------------------------------------------------------------------------
function ankh:reparseAllScripts()
   api:script("AnkhInitialization.lua")
   api:script("PinaAPI.lua")
   ankh:initializeQuests()
end
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- encapsulates a simple object interaction
---------------------------------------------------------------------------
function ankh:playInteractionAnimation(p_Animation, p_Interactor, p_Sentence)
   local character = GameEntityMgr:getCharacter("char_assil")
   --character:attachToBone(p_Interactor)
   character:blendToPlayOnceAndBack(p_Animation)
   character:say(p_Sentence)
end
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- encapsulates a simple object interaction
---------------------------------------------------------------------------
function ankh:playInteractionAnimation_(p_Character, p_Animation,
					p_Interactor, p_Sentence)
   local character = GameEntityMgr:getCharacter(p_Character)
   --character:attachObject(p_Interactor)
   character:blendToPlayOnceAndBack(p_Animation)
   character:say(p_Sentence)
end
---------------------------------------------------------------------------
