layoutWoods2BobcatCave.mExits =
{
}

layoutWoods2BobcatCave.mPOIs = 
{
}

layoutWoods2BobcatCave.mHOs = 
{
	[objectHoCan] = 
	{
		siblings = {objectHoCanLit},
	},
}

layoutWoods2BobcatCave.mIOs =
{
	[objectIoCaveHitarea] = 
	{
		links = {objectHoRock01, objectHoRock02, objectHoRock03},
		cursor = kCursorDefault,
	}
}
layoutWoods2BobcatCave.bobCatScared = false
layoutWoods2BobcatCave.bobcatEvading = false
layoutWoods2BobcatCave.animateWoods2Bobcat = true
layoutWoods2BobcatCave.timeFallBack = 100
layoutWoods2BobcatCave.timeHideDelay = 800
layoutWoods2BobcatCave.timeLastHideDelay = 1500
layoutWoods2BobcatCave.timeReturnToSpot = 1000
layoutWoods2BobcatCave.stonesThrown = 0		-- Needed for changing x positions
layoutWoods2BobcatCave.xChange = {}
layoutWoods2BobcatCave.xChange[1] = 30
layoutWoods2BobcatCave.xChange[2] = -50
layoutWoods2BobcatCave.xChange[3] = 0
layoutWoods2BobcatCave.timeAttack = 150
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:onConstruct()
	
	Layout.onConstruct(self)
	
end
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:onInitialize()

	Layout.onInitialize(self)
	
	objectScareBobcatCaverun:ss(kInactive)
	objectScareBobcatCaverunFace01:ss(kInactive)
	objectScareBobcatCaverunFace02:ss(kInactive)
	
	objectCaveEyes:relocatePivotPoint("center")
	objectCaveBobcat:relocatePivotPoint(124, 217)
	objectScareBobcatCaverunFace01:relocatePivotPoint("center")
	objectScareBobcatCaverunFace02:relocatePivotPoint("center")

end
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:onClickHO(object, x, y)

	if ((goalFindWater:isStarted() and not (goalFindWater:isFinished())) and 
		((object == objectHoCan) and (not objectIoCaveHitarea:isDone())) ) then
		
		think("MESSAGE_SCARE_BOBCAT")
		
		if (objectHoRock01:isIdle()) then objectHoRock01:ss(kActive) end
		if (objectHoRock02:isIdle()) then objectHoRock02:ss(kActive) end
		if (objectHoRock03:isIdle()) then objectHoRock03:ss(kActive) end
		objectIoCaveHitarea:ss(kActive)
		return true, false, false
		
	else
		if (object == objectHoCan) then
			objectTinCan:ss(kDone)
		end
		
		return Layout.onClickHO(self, object, x, y)
		
	end
	
end
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:onQuickPlay()
	objectHoRock01:ss(kFound)
	objectHoRock02:ss(kFound)
	objectHoRock03:ss(kFound)
	objectIoCaveHitarea:ss(kActive)	
end
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:onUsedAll(object, props)

	if (object == objectIoCaveHitarea) then
		self.bobCatScared = true
	end
	
	return Layout:onUsedAll(object, props)

end
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:blinkEyes()
	
	if (self.bobcatEvading) then
		-- If the bobcat is evading, wait for a bit and check later on if he can blink again:
		objectCaveEyes:animate("blinkBobCatEyes",
			{ delay=100				}
		)
	else
		
		local watching 	= math.random(3500, 5000)
		local closed 	= math.random(100, 120)
	
		objectCaveEyes:animate("blinkBobCatEyes",
			{ alpha=1,					},
			{ delay=watching			},
			{ alpha=0,					},
			{ delay=closed				}
		)
			
		if (self.animateWoods2Bobcat == true) then
			objectBobcatEyes:animate("blinkBobCatEyes2",
				{ alpha=1,					},
				{ delay=watching			},
				{ alpha=0,					},
				{ delay=closed				}
			)
		else
			objectBobcatEyes:setAlpha(0)
		end
		
	end

end
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:evadeStone()
	
	self.stonesThrown = self.stonesThrown + 1
	
	self.bobcatEvading = true
	
	if (self.stonesThrown < 3) then
	
		objectCaveEyes:animate("bobCatEvade_blocking",
			{
				{alpha = 0.3, duration = self.timeFallBack},
				{scale = 0.9, duration = self.timeFallBack},
				{x = objectCaveEyes:x() + self.xChange[self.stonesThrown], duration=self.timeFallBack}
			},
			{delay = self.timeHideDelay},
			{
				{alpha = 1, duration = self.timeReturnToSpot},
				{scale = 1, duration = self.timeReturnToSpot}
			}
		)
		
		objectCaveBobcat:animate(
			{ command="playTrack track=ANGRY_BOBCAT", target=self },
			{
				{alpha = 0.3, duration = self.timeFallBack},
				{scale = 0.9, duration = self.timeFallBack},
				{x = objectCaveBobcat:x() + self.xChange[self.stonesThrown], duration=self.timeFallBack}
			},
			{delay = self.timeHideDelay},
			{
				{alpha = 1, duration = self.timeReturnToSpot},
				{scale = 1, duration = self.timeReturnToSpot}
			}
		)
	
	else
		
		objectCaveEyes:animate("bobCatEvade_blocking",
			{
				{alpha = 0.3, duration = self.timeFallBack},
				{scale = 0.90, duration = self.timeFallBack},
			},
			{delay = self.timeLastHideDelay }
		)
		
		objectCaveBobcat:animate(
			{ command="playTrack track=ANGRY_BOBCAT", target=self },
			{
				{alpha = 0.3, duration = self.timeFallBack},
				{scale = 0.9, duration = self.timeFallBack}
			},
			{delay = self.timeLastHideDelay}
		)
		
	end
	
end
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:onAnimationFinish(animationName)
	
	if ((animationName == "blinkBobCatEyes") and (objectIoCaveHitarea:isActive())) then
		self:blinkEyes()
	
	elseif (animationName == "bobCatEvade_blocking") then
		
		self.bobcatEvading = false
		
		if (self.bobCatScared == true) then
			ghf.cancelAnimation("blinkBobCatEyes")
			ghf.cancelAnimation("blinkBobCatEyes2")
			
			objectIoCaveHitarea:ss(kDone)
			objectCaveEyes:ss(kDone)
			objectBobcatEyes:ss(kDone)
			objectCaveBobcat:ss(kDone)
			
			objectScareBobcatCaverunFace01:setScale(0.1)
			objectScareBobcatCaverunFace01:setAlpha(0)
			objectScareBobcatCaverunFace01:ss(kIdle)
			objectScareBobcatCaverunFace01:animate("scareBobcatAttack_blocking",
				{
					{alpha = 1, duration = self.timeAttack},
					{scale = 1, duration = self.timeAttack},
					{ command="playTrack track=VERY_ANGRY_BOBCAT", target=self },
				}
			)
		end
	
	elseif (animationName == "scareBobcatAttack_blocking") then	
		
		objectScareBobcatCaverunFace02:setAlpha(0)
		objectScareBobcatCaverunFace02:ss(kIdle)
		
		local numBlinks = 3
		local delay = 0
		
		for i=1, numBlinks do
			
			local blinkDuration = 85
			local blinkDelay = 75
		
			objectScareBobcatCaverunFace02:animate("scareBobcatHiss" .. i,
				{ delay=delay			},
				{ alpha=0				},
				{ delay=blinkDuration	},
				{ alpha=1				},
				{ delay=blinkDuration	}
			)
			
			delay = delay + blinkDelay + ( 2 * blinkDuration )
			
		end
		
		self:animate("scareBobcatHiss_blocking",
			{ delay=delay		}
		)
	
	elseif (animationName == "scareBobcatHiss_blocking") then	
		
		objectScareBobcatCaverunFace01:ss(kDone)
		objectScareBobcatCaverunFace02:ss(kDone)
		
		objectScareBobcatCaverun:ss(kIdle)
		objectScareBobcatCaverun:animate("bobcatRunAway_blocking",
			{ startframe=0, 		frametime=100			},
			{ alpha=0										}
		)
		
	elseif (animationName == "bobcatRunAway_blocking") then	
		
		objectScareBobcatCaverun:ss(kDone)
		
	end
	
	Layout.onAnimationFinish(self, animationName)
	
end
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:onUseObject(selectedObject, targetObject, targetProps)
	
	if (targetObject == objectIoCaveHitarea and 
		(selectedObject == objectHoRock01 or 
		selectedObject == objectHoRock02 or 
		selectedObject == objectHoRock03)) then
		
		self:evadeStone()
		
	end
	
	return Layout.onUseObject(self, selectedObject, targetObject, targetProps)
	
end
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:onShow()
	
	-- make sure we don't see the bobcat eyes in the original woods2 layout
	self.animateWoods2Bobcat = false

	Layout.onShow(self)
	
	-- think that we shouldn't get too close
	if (objectHoCan:isIdle()) then
		think("MESSAGE_ANIMALDEN_NO_ASSIGNMENT")
	end	
	
end
-- ----------------------------------------------------------------------------
function layoutWoods2BobcatCave:onHide()

	-- Make sure we see the bobcat eyes in the original woods2 layout again:
	self.animateWoods2Bobcat = true

	Layout.onHide(self)
	
end
