/*
 * Copyright (c) 2016-2019 Marco Hladik <marco@icculus.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

class func_vip_safetyzone
{
	void() func_vip_safetyzone;
	virtual void() touch;
};

/* Hack! Make this better? */
void VIP_Rescue(entity targ)
{
	entity eOld = self;
	self = other;
	Spawn_MakeSpectator();
	self.classname = "player";
	self.team = TEAM_CT;
	forceinfokey(self, "*dead", "0");
	iAlivePlayers_CT--;
	self = eOld;
}

void func_vip_safetyzone::touch(void)
{
	if (other.classname == "player") {
		if (other.team == TEAM_VIP) {
			/* In Assassination, all Counter-Terrorists receive a $2500
			 *  reward if they won by successfully guaranteeing
			 *  the escape of the VIP. */
			Rules_RoundOver(TEAM_CT, 2500, FALSE);
			VIP_Rescue(other);
		}
		other.fInVIPZone = TRUE;
	}
}

void func_vip_safetyzone::func_vip_safetyzone(void)
{
	angles = '0 0 0';
	movetype = MOVETYPE_NONE;
	solid = SOLID_TRIGGER;

	if (model) {
		setmodel(this, model);
	} else {
		setsize(this, mins, maxs);
	}

	model = 0;
	iVIPZones++;
}
