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

#include "scripts/common.txt"

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

$script 0
{
    int gotKey;
    
    GameVariables.GetInt("bGotMantisKey", gotKey);
    
    if(gotKey == 1)
    {
        // hopefully this is the only actor in this level that has this TID
        kActor @exitPortal = World.GetActorByTID(667);
        
        if(!(exitPortal is null))
        {
            // we need to know what area this actor is in
            int areaID = exitPortal.AreaID();
            
            if(areaID <= -1)
            {
                // oh dear...
                return;
            }
            
            if((World.GetAreaFlags(areaID) & AAF_TELEPORTAIR) == 0)
            {
                // oh dear...
                return;
            }
            
            // though args can be used for anything, they are typically used
            // in this fashion:
            //
            // 0: warp ID
            // 1: warp level ID or trigger sound ID
            // 2: checkpoint ID
            // 3: tag ID
            // 4: floor damage hit points
            // 5: floor damage rate
            
            // change to warp tag 10666 (in front of hub)
            World.ChangeAreaArg(areaID, 0, 10666);
            
            // change to level 5 (main hub)
            World.ChangeAreaArg(areaID, 1, 5);
        }
    }
}
