/* Generic Carnivore Thirst Behaviour
//
*/

machine CarnThirst
{
	default state ThirstStart
	{
		action StartLook("LookProximity", 0.5)
		action AddRandomAnimation("call", "02_lp", 10.0, 15.0)
		action AddRandomAnimation("tail", "flck_lp", 3.0, 5.0)

		action SetAutoMovementBlend(true)
		action SetRunMode(false)
		action SetSpeedModifierWalk(1.0)
		action ClearTarget()
		transition
		{
			goto PreWanderAcquire
		}
	}

	state PreWanderAcquire
	{
		transition IsTargetPosWaterArea()
		{
			goto StartSeek
		}
		transition AcquireWaterPoint(false)
		{
			goto StartSeek
		}
		transition
		{
			goto Wander
		}
	}

	state Wander
	{
		transition SetWander() == true
		{
			goto PostWanderAcquire
		}
	}

	state PostWanderAcquire
	{
		transition AcquireWaterPoint(false)
		{
			goto StartSeek
		}
		transition HasArrived()
		{
			goto Wander
		}
	}

	state StartSeek
	{
		transition SeekWaterPoint()
		{
			action SetFlockImpulse(false)
			action SetRandomTimerBetween(1, 25.0, 30.0)
			goto Seek
		}
		transition
		{
			goto Wander
		}
	}

	state Seek
	{
		transition IsInWaterArea()
		{
			action FaceWaterPoint()
			goto FaceWater
		}
		transition HasArrived()
		{
			action FaceWaterPoint()
			goto FaceWater
		}
		transition IsTimerUp(1)
		{
			goto SeekFailWander
		}
		transition AcquireWaterPoint(false)
		{
			goto SeekWaterClose
		}
	}

	state FaceWater
	{
		transition HasArrived()
		{
			goto Drink
		}
	}

	state SeekWaterClose
	{
		transition SeekWaterPoint()
		{
			action SetRandomTimerBetween(1, 70.0, 75.0)
			goto SeekWaterCloseLoop
		}
		transition
		{
			goto Wander
		}
	}

	state SeekWaterCloseLoop
	{
		transition IsInWaterArea()
		{
			action FaceWaterPoint()
			goto FaceWater
		}
		transition HasArrived()
		{
			action FaceWaterPoint()
			goto FaceWater
		}
		transition IsTimerUp(1)
		{
			goto SeekFailWander
		}
	}

	state SeekFailWander
	{
		transition
		{
			action SetRandomTimerBetween(1, 6.0, 7.0)
			action SetWander()
			goto SeekFailWanderLoop
		}
	}

	state SeekFailWanderLoop
	{
		transition HasArrived()
		{
			goto Wander
		}
		transition IsTimerUp(1)
		{
			goto Wander
		}
	}

	state Drink
	{
		action SendEnclosureEvent("drinking")
		action StopAllRandomAnimations()
		action SetStandStill()
		action StopLook()
		action PlayAnim("drink", "st", false)
		;//action AddTerritoryFactor("water")
		transition
		{
			goto DrinkWait
		}
	}

	state DrinkWait
	{
		transition IsAnimPlaying("drink", "lp", false) == true
		{
			action SetRandomTimerBetween(1, 3.0, 5.0)
			goto DrinkLoop
		}

		;// new anim system causing issues...
		transition IsAnimPlaying("drink", "st", false) == false
		{
			action SetRandomTimerBetween(1, 3.0, 3.0)
			goto DrinkWaitTempFix
		}
	}

	;// new anim system causing issues...
	state DrinkWaitTempFix
	{
		transition IsAnimPlaying("drink","lp", false)
		{
			action SetRandomTimerBetween(1, 3.0, 5.0)
			goto DrinkLoop
		}

		transition IsTimerUp(1)
		{
			goto DrinkBreak
		}
	}

	state DrinkLoop
	{
		action UpdateDeltaVariable("Water", 0.02)
		transition IsTimerUp(1)
		{
			goto DrinkBreak
		}
	}

	state DrinkBreak
	{
		action StopAnimState("drink")
		transition
		{
			goto DrinkBreakStart
		}
	}

	state DrinkBreakStart
	{
		action StartLook("LookProximity", 0.5)
		action AddRandomAnimation("tail", "flck_lp", 3.0, 5.0)
		transition IsIdleLocked() == false
		{
			action SetRandomTimerBetween(1, 4.0, 6.0)
			goto DrinkBreakLoop
		}
	}

	state DrinkBreakLoop
	{
		transition IsTimerUp(1)
		{
			goto Drink
		}
	}

;------------------------ Exit States Begin ----------------------
	exitstart state CleanUp
	{
		action StopAnimState("drink")
		transition
		{
			goto CleanUpWait
		}
	}

	state CleanUpWait
	{
		transition IsAnimStatePlaying("drink", true) == false
		{
			action SetRandomTimerBetween(1, 20.0, 30.0)
			goto CleanUpIdleWait
		}
	}

	state CleanUpIdleWait
	{
		transition IsIdleLocked() == false
		{
			goto CleanUpEnd
		}
		transition IsTimerUp(1)
		{
			goto CleanUpEnd
		}
	}

	exitend state CleanUpEnd
	{
		action SetFlockImpulse(true)
		action StopLook()
	}
;------------------------ Exit States End ----------------------
}
