//
// Copyright(C) 2014-2015 Samuel Villarreal
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// DESCRIPTION:
//      Level Script For Level05.map
//

#include "scripts/common.txt"

/*
==============================================================
Script 0
==============================================================
*/

$script 0
{
    bool bStartedIntro;
    bool bNewGame;
    
    GameVariables.GetBool("g_newgame", bNewGame);
    GameVariables.GetBool("bStartedHubIntro", bStartedIntro);
    
    if(bNewGame)
    {
        // make sure all chronoscepter and key pieces have been cleared when
        // starting a new game
        GameVariables.SetValue("chronoPieceFlags", "0");
        GameVariables.SetValue("hubPanelPieces1", "0");
        GameVariables.SetValue("hubPanelPieces2", "0");
        GameVariables.SetValue("hubPanelPieces3", "0");
        GameVariables.SetValue("hubPanelPieces4", "0");
        GameVariables.SetValue("hubPanelPieces5", "0");
        GameVariables.SetValue("hubPanelPieces6", "0");
        GameVariables.SetValue("hubPanelPieces7", "0");
    }
    
    // start the cinematic if we're starting a new game, but also make
    // sure that we don't trigger this if we're entering this level normally
    if(bStartedIntro && !bNewGame)
    {
        return;
    }
    
    Camera.StartCinematic(CMF_LOCK_PLAYER|CMF_NO_LETTERBOX|CMF_NO_INITIAL_FADEOUT);
    GameVariables.SetValue("bStartedHubIntro", "1");
    
    Camera.fov = 74.0f;
    
    //
    // the camera zooms in and rotates around the hub.
    // two separate camera paths are blended together. Neat eh?
    //
    
    Camera.SetFinalView(0);
    Camera.SetRotateEyeVector(kVec3(-(179*GAME_SCALE), (358*GAME_SCALE), (100*GAME_SCALE)));
    
    Camera.SetPositionTrack(1, 
                            kVec3(-(179*GAME_SCALE), (358*GAME_SCALE), (250*GAME_SCALE)),
                            kVec3(-(179*GAME_SCALE), (358*GAME_SCALE), (100*GAME_SCALE)),
                            kVec3(-(179*GAME_SCALE), (358*GAME_SCALE), (90*GAME_SCALE)),
                            kVec3(-(179*GAME_SCALE), (358*GAME_SCALE), (90*GAME_SCALE)));
                                       
    Camera.AutoPlayPositionTrack(1, 6.0f, CMLT_LINEAR);
    
    Camera.SetRotationTrack(2,
                            Math::Deg2Rad(-360.0f),
                            Math::Deg2Rad(0.0f),
                            (70*GAME_SCALE),
                            (70*GAME_SCALE),
                            (10*GAME_SCALE),
                            (10*GAME_SCALE),
                            (6*GAME_SCALE),
                            (6*GAME_SCALE));
                                       
    Camera.AutoPlayRotationTrack(2, 32.0f, CMLT_LINEARLOOP);
    
    Camera.AutoPlayBlendTrack(0, 1, 2, 6.0f, CMLT_COSINE);
    
    Game.CallDelayedMapScript(2, instigator, 1.0f);
    
    delay(2.0f);
    
    Game.PrintLine("$str_178", 1, 512);
    Game.PrintLine("$str_177", 2, 512);
    Game.PrintLine("$str_176", 3, 512);
    
    delay(10.0f);
    PlayLoop.ChangeMap("levels/level04.map");
}

/*
==============================================================
Script 2
==============================================================
*/

$script 2
{
    if(Camera.UserInterrupted())
    {
        Game.CallDelayedMapScript(3, instigator, 0);
        return;
    }
    
    $restart;
}

/*
==============================================================
Script 3
==============================================================
*/

$script 3
{
    PlayLoop.ChangeMap("levels/level04.map");
}
