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

#include "scripts/common.txt"

//-----------------------------------------------------------------------------
//
// Sentry
//
//-----------------------------------------------------------------------------

/*
==============================================================
TurokSentry
==============================================================
*/

final class TurokSentry : TurokEnemy
{
	TurokSentry(kActor @actor)
	{
		super(actor);
	}

	// Smoke39
	void InitHeight()
	{
		self.Height() += 23 * self.Scale().z;
	}

	bool Headshot( kVec3&in hitLoc )
	{
		// can't hit head from behind
		if ( Math::Fabs( self.GetTurnYaw(hitLoc) ) > Math::Deg2Rad( 30 ) )
			return false;
		return  (hitLoc.z - self.Origin().z) / self.Height() > 0.7f;
	}
	void SpawnHeadLine()
	{
		// c = a/h
		float angle = Math::Deg2Rad( 30 );
		float delta = 2 * angle / 3;
		for ( int i = 0;  i < 4;  i++ )
		{
			Game.SpawnFx( "fx/TPlus/Debug_HeadLine.kfx", self.Origin() + kVec3( 0, 0, self.Height() * 0.7f )
				+ kVec3( 0, self.Radius(), 0 ) * kQuat( angle - i * delta - self.Yaw(), 0,0,1 ), -1 );
		}
	}

	kVec3 DazeOffset()
	{
		if ( self.Flags() & AF_STATIONARY != 0 )
			return kVec3( -10, -10, 177 );
		return kVec3( 0, -50, 177 );
	}

	// nothing does knockback to mechanical enemies yet,
	// but in case any ever do, big robots should take less knockback than, e.g., robo grunts
	void TransferMomentum( float momentumTransfer, bool bExplode )
	{
		TurokEnemy::TransferMomentum( 0.5f * momentumTransfer, bExplode );
	}

	/*
	==============================================================
	GunFire
	==============================================================
	*/

	void GunFire(kActor @instigator, const float w, const float x, const float y, const float z)
	{
		if(self.GetTarget() is null)
		{
			return;
		}

		if(w > 0.0f)
		{
			self.PlaySound("sounds/shaders/auto_shotgun_shot.ksnd");
			self.SpawnProjectile("fx/robot_bullet.kfx", kVec3(x, y, z),
				self.GetTarget().Origin(), Math::Deg2Rad(45.0f));
		}
		else
		{
			self.PlaySound("sounds/shaders/missile_launch.ksnd");
			// Smoke39
//			self.SpawnProjectile("fx/robot_rocket.kfx", kVec3(x, y, z),
//				self.GetTarget().Origin(), Math::Deg2Rad(45.0f));
			SpawnProj( "fx/robot_rocket.kfx", kVec3(x,y,z) );
		}
	}

	/*
	==============================================================
	RoboShutdown
	==============================================================
	*/

	void RoboShutdown(kActor @instigator, const float w, const float x, const float y, const float z)
	{
		self.PlaySound("sounds/shaders/robot_shutdown.ksnd");
	}

	/*
	==============================================================
	Explosion1Sound
	==============================================================
	*/

	void Explosion1Sound(kActor @instigator, const float w, const float x, const float y, const float z)
	{
		self.PlaySound("sounds/shaders/explosion_1.ksnd");
	}
}
