------ All content © 2008 DigiPen (USA) Corporation, all rights reserved. ------
--------------------------------------------------------------------------------
-- Fuctions!
-- This might look redundant, but avoids costly global lookup
--------------------------------------------------------------------------------
local PLAYER_gLantern                = Player.gLantern

local GLOBAL_TimeElapsed             = Global.TimeElapsed
local GLOBAL_SetGameMode             = Global.SetGameMode
local GLOBAL_CreateNewOldVine        = Global.CreateNewOldVine
local GLOBAL_CreateEntity            = Global.CreateEntity
local GLOBAL_DeleteEntityByPtr       = Global.DeleteEntityByPtr
local GLOBAL_FindEntityByName        = Global.FindEntityByName

local GLOBAL_ClearVines              = Global.ClearVines
local GLOBAL_NewVine                 = Global.NewVine
local GLOBAL_gVineEndPoint           = Global.gVineEndPoint

local ENTITY_SHR_sPosition           = Entity.SHR_sPosition
local ENTITY_SPT_GiveNumber          = Entity.SPT_GiveNumber
local ENTITY_SPT_GiveString          = Entity.SPT_GiveString
local ENTITY_GetMyPointer            = Entity.GetMyPointer

--------------------------------------------------------------------------------
-- Preloop for waiting
--------------------------------------------------------------------------------
GLOBAL_SetGameMode( false )

local data = {}
Entity:SPT_RefreshNumbers( data )
if( data.lantern )
then
  local elapsedTime = 0
  while( elapsedTime < 7500 ) 
  do
    coroutine.yield()

    elapsedTime = elapsedTime + GLOBAL_TimeElapsed()

  end

end

--------------------------------------------------------------------------------
-- Initialization
--------------------------------------------------------------------------------
local slideshow = GLOBAL_CreateEntity( "../../Assets/Xml/entities/game_Slideshow.xml" )
local tSlide = 8000
local tTransition = 1500
local slideCount = 2
local totalTime = slideCount * tSlide + ( slideCount - 1 ) * tTransition / 2

ENTITY_SPT_GiveString( slideshow, "ShowName", "MidSlides0" )
ENTITY_SPT_GiveNumber( slideshow, "TimePerSlide", tSlide )
ENTITY_SPT_GiveNumber( slideshow, "TransitionTime", tTransition )
ENTITY_SPT_GiveNumber( slideshow, "SlideCount", slideCount )

ENTITY_SPT_GiveString( slideshow, "Text1", "Passing a cluster of islands, Aster continues" )
ENTITY_SPT_GiveNumber( slideshow, "Height1", .3 ) -- Height does not have to be specified
ENTITY_SPT_GiveString( slideshow, "Text2", "Winding upward, the vine climbs high into the air" )
ENTITY_SPT_GiveNumber( slideshow, "Height2", .3 ) -- Height does not have to be specified

--------------------------------------------------------------------------------
-- Loop
--------------------------------------------------------------------------------
elapsedTime = 0
while( 1 ) 
do
  coroutine.yield()

  elapsedTime = elapsedTime + GLOBAL_TimeElapsed()
  if( elapsedTime > totalTime / 2 )
  then
    Global:AreaMsg( 2 )
    
    -- Get rid of the vine and start anew
    GLOBAL_ClearVines( )
    GLOBAL_NewVine( -3.0, 20.0, -68.0 )
    local twisty = GLOBAL_CreateNewOldVine( 45.0, -70.0, -100.0 )
    -- Hackiest hack in the history of hacks
    --Editor:AttachToIsland( 0, twisty, "../../Assets/Xml/entities/e_OldVine.xml" )

    -- Start Aster on the vine
    local aster = Player:gAster()
    local vPos = GLOBAL_gVineEndPoint( )
    ENTITY_SHR_sPosition( aster, vPos.x, vPos.y, vPos.z )


    -- Clean up this entity
    GLOBAL_DeleteEntityByPtr( ENTITY_GetMyPointer( Entity ) )

  end

end
