//
// 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:
//      Warp Portal Object Class
//

#include "scripts/common.txt"

/*
==============================================================
HALLOROK21WarpPortal - Derived from TurokWarpPoint
==============================================================
*/

class HALLOROK21WarpPortal : ScriptObject
{
    kActor @self;
    float time;
    float delayTime;
    bool bActive;
    
    HALLOROK21WarpPortal(kActor @actor)
    {
        @self = actor;
		bActive = false;
    }
    
    /*
    ==============================================================
    OnTick
    ==============================================================
    */
    
    void OnTick(void)
    {
        if(bActive)
        {
            self.PlaySound("sounds/shaders/generic_187.ksnd");
            return;
        }		
    }
    
    /*
    ==============================================================
    OnBeginLevel
    ==============================================================
    */
    
    void OnBeginLevel(void)
    {
            self.Flags() |= AF_HIDDEN;
            self.Flags() &= ~AF_CANBETOUCHED;		
    }
	
    /*
    ==============================================================
    OnTouch
    ==============================================================
    */
    
    void OnTouch(kActor @theActorThatTouchedMe)
    {
        int mapID = 00;
        
        if(self.TID() <= 0)
        {
            return;
        }
        
        if(!theActorThatTouchedMe.InstanceOf("kexPuppet"))
        {
            return;
        }
		
        PlayLoop.StartWarp(theActorThatTouchedMe, self.TID(), mapID);
    }
    
    /*
    ==============================================================
    OnSpawn
    ==============================================================
    */
    
    void OnSpawn(void)
    {
            self.Flags() |= AF_HIDDEN;
            self.Flags() &= ~AF_CANBETOUCHED;
			bActive = true;
    }
};
