//
// 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:
//      Sewer Crab Script Object Class
//

#include "scripts/common.txt"

//-----------------------------------------------------------------------------
//
// Sewer Crab
//
//-----------------------------------------------------------------------------

/*
==============================================================
TurokSewerCrab
==============================================================
*/

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

	// Smoke39
	void InitHeight()
	{
		self.Height() += 23 * self.Scale().z;
	}
	bool Headshot( kVec3&in hitLoc )
	{
		// can't hit head from behind
		float f = ( hitLoc - self.Origin() ).Dot( kVec3(0,1,0) * kQuat( -self.Yaw(), 0,0,1 ) ) / self.Radius();
		if ( f < 0.85f )
			return false;
		f = (hitLoc.z - self.Origin().z) / self.Height();
		return f > 0.3f && f < 0.45f;
	}
	void SpawnHeadLine()
	{
		// c = a/h
		float angle = Math::ACos( 0.85f );
		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.45f )
				+ kVec3( 0, self.Radius(), 0 ) * kQuat( angle - i * delta - self.Yaw(), 0,0,1 ), -1 );
			Game.SpawnFx( "fx/TPlus/Debug_HeadLine.kfx", self.Origin() + kVec3( 0, 0, self.Height() * 0.3f )
				+ kVec3( 0, self.Radius(), 0 ) * kQuat( angle - i * delta - self.Yaw(), 0,0,1 ), -1 );
		}
	}

	kVec3 TrackPoint()
	{
		kVec3 v = FlameOffset();
		v.z -= 0.1f * self.Height();
		return self.Origin() + v * self.Rotation();
	}

	kVec3 DazeOffset()
	{
		if ( self.Flags() & AF_STATIONARY != 0 )
			return kVec3( 21, -85, 110 );
		return kVec3( -3, -109, 110 );
	}

	bool TranqDealsDamage()
	{
		return true;
	}

	// take a bit less knockback
	void TransferMomentum( float momentumTransfer, bool bExplode )
	{
		TurokEnemy::TransferMomentum( 0.75f * momentumTransfer, bExplode );
	}
}
