//
// 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 Level43.map
//

#include "scripts/common.txt"

kActor @arrow = null;
int introState = 0;

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

$script 0
{
    Player.Actor().Flags() &= ~AF_NODRAW;
    Player.Actor().AnimState().Set(anim_special_event01, 8.0f, 0);
    
    introState = 0;
    
    @arrow = World.GetActorByTID(5);
    
    if(!(arrow is null))
    {
        arrow.AnimState().Set(anim_weaponIdle, 8.0f, 0);
    }
    
    Camera.StartCinematic(CMF_LOCK_PLAYER|CMF_NO_LETTERBOX|CMF_NO_INITIAL_FADEOUT);
    Camera.fov = 74.0f;
    Camera.SetLookAtActor(Player.Actor().CastToActor());
    Camera.SetFinalView(0);
    Camera.SetRotationTrack(0,
                                       Math::Deg2Rad(180.0f),
                                       0,
                                       5*GAME_SCALE,
                                       8*GAME_SCALE,
                                       GAME_SCALE,
                                       7*GAME_SCALE,
                                       GAME_SCALE,
                                       (7*GAME_SCALE)-0.01f);
                                       
    Camera.AutoPlayRotationTrack(0, 12.8f, CMLT_COSINE);
    
    Player.Actor().ModelVariation() = TV_BOW;
    Game.CallDelayedMapScript(5, instigator, 0);
    Game.CallDelayedMapScript(4, instigator, 0);
}

/*
==============================================================
Script 1
==============================================================
*/

$script 1
{
    Camera.fov = (90.0f - Camera.fov) * 0.012f + Camera.fov;
    $restart;
}

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

$script 2
{
    Game.HaltMapScript(1);
    Game.HaltMapScript(4);
    Game.Restart();
}

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

Called from player animation and script
==============================================================
*/

$script 3
{
    switch(++introState)
    {
    case 1:
        Game.CallDelayedMapScript(1, instigator, 0);
        break;
    case 2:
        Game.HaltMapScript(1);
        break;
    case 3:
        Game.CallDelayedMapScript(2, instigator, 0);
        break;
    }
}

/*
==============================================================
Script 4
==============================================================
*/

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