<?xml version="1.0" encoding="utf-8"?>
<Behaviors>
	<Machine>
		<Name>Run</Name>
		<InitialState>RunStart</InitialState>
		<State Name="RunStart">
			<Transition Input="heartbeat" Destination="RunStop"/>
		</State>
		<State Name="RunStop">
			<Transition Input="heartbeat" Destination="RunStart"/>
		</State>
	</Machine>
	
	<Machine>
		<Name>TrilobiteWallListen</Name>
		<InitialState>Idle</InitialState>
		
		<State Name="Idle">
			<Transition Input="heardNoise" Destination="DelayBeforeAttack"/>
		</State>
				
		<State Name="DelayBeforeAttack" State="Delay">
			<Property Name="MinDelay" Value="0.01"/>
			<Property Name="MaxDelay" Value="0.05"/>
			<Transition Input="delayDone" Destination="TrilobiteDig"/>
		</State>
		
		<State Name="TrilobiteDig">
			<Transition Input="digDone" Destination="Timeout"/>
		</State>
		
		<State Name="Timeout" State="Delay">			
			<Property Name="MinDelay" Value="0.5"/>
			<Property Name="MaxDelay" Value="1.5"/>
			<Transition Input="heardNoise" Destination=""/>
			<Transition Input="delayDone" Destination="Idle"/>
		</State>
	</Machine>
	
	<Machine>
		<Name>TrilobiteWall</Name>
		<InitialState>TrilobiteWallListen</InitialState>
		
		<State Machine="TrilobiteWallListen">
			<Transition Input="playerDestroyedWall" Destination="Suicide"/>
			<Transition Input="lostWall" Destination="Spawn"/>
		</State>
		
		<State Name="Spawn">
			<Property Name="SpawnEnemy" Value="enemy_trilobite"/>
			<Transition Input="spawnDone" Destination="Zombiefy"/>
		</State>
		
		<State Name="Suicide"> <!-- Killed by player. Spawn loot, play effects, etc. -->
		</State>
		
		<State Name="Zombiefy"> <!-- Got free (ie, spawned a Trilobite walker). Just remove this entity. -->
		</State>
	</Machine>
	
	<Machine>
		<Name>TrilobiteMechaWallListen</Name>
		<InitialState>Idle</InitialState>
		
		<State Name="Idle">
			<Transition Input="heardNoise" Destination="DelayBeforeAttack"/>
			<Transition Input="heartbeat" Destination="FindEnemy"/>
		</State>
				
		<State Name="FindEnemy">
			<Property Name="Radius" Value="80"/>
			<Transition Input="foundEnemy" Destination="DelayBeforeAttack"/>
			<Transition Input="notFoundEnemy" Destination="Idle"/>
		</State>
				
		<State Name="DelayBeforeAttack" State="Delay">
			<Property Name="MinDelay" Value="0.01"/>
			<Property Name="MaxDelay" Value="0.05"/>
			<Transition Input="delayDone" Destination="TrilobiteDig"/>
		</State>
		
		<State Name="TrilobiteDig">
			<Transition Input="digDone" Destination="Timeout"/>
		</State>
		
		<State Name="Timeout" State="Delay">			
			<Property Name="MinDelay" Value="0.5"/>
			<Property Name="MaxDelay" Value="1.5"/>
			<Transition Input="heardNoise" Destination=""/>
			<Transition Input="delayDone" Destination="Idle"/>
		</State>
	</Machine>
	
	<Machine>
		<Name>TrilobiteMechaWall</Name>
		<InitialState>TrilobiteMechaWallListen</InitialState>
		
		<State Machine="TrilobiteMechaWallListen">
			<Transition Input="playerDestroyedWall" Destination="Suicide"/>
			<Transition Input="lostWall" Destination="Spawn"/>
		</State>
		
		<State Name="Spawn">
			<Property Name="SpawnEnemy" Value="enemy_trilobite_mecha"/>
			<Transition Input="spawnDone" Destination="Zombiefy"/>
		</State>
		
		<State Name="Suicide">
		</State>
		
		<State Name="Zombiefy">
		</State>
	</Machine>
	
	<Machine>
		<Name>Trilobite</Name>
		<InitialState>FlipCoin</InitialState>
		
		<State Name="FlipCoin">
			<Transition Input="heads" Destination="MoveLeft"/>
			<Transition Input="tails" Destination="MoveRight"/>
		</State>
		<State Name="MoveLeft">
			<Transition Input="collision" Destination="MoveRight"/>
			<Transition Input="atEdge" Destination="MoveRight"/>
			<Transition Input="metSomeone" Destination="MoveRight"/>
			<Transition Input="damageFront" Destination="MoveRight"/>
			<!-- <Transition Input="heartbeat" Destination="RunStop"/> -->
		</State>
		<State Name="MoveRight">
			<Transition Input="collision" Destination="MoveLeft"/>
			<Transition Input="atEdge" Destination="MoveLeft"/>
			<Transition Input="metSomeone" Destination="MoveLeft"/>
			<Transition Input="damageFront" Destination="MoveLeft"/>
			<!-- <Transition Input="heartbeat" Destination="RunStop"/> -->
		</State>
		<State Name="RunStart">
			<Transition Input="done" Destination="ResetHeartBeat"/>
		</State>
		<State Name="ResetHeartBeat">
			<Transition Input="done" Destination="ChangeDirection"/>
		</State>
		<State Name="RunStop">
			<Transition Input="done" Destination="ContinueMoving"/>
		</State>
		<State Name="ContinueMoving" State="FacingRight">
			<Transition Input="true" Destination="MoveRight"/>
			<Transition Input="false" Destination="MoveLeft"/>
		</State>
		<State Name="ChangeDirection" State="FacingRight">
			<Transition Input="true" Destination="MoveLeft"/>
			<Transition Input="false" Destination="MoveRight"/>
		</State>
	</Machine>
	
	<Machine>
		<Name>TrilobiteMecha</Name>
		<InitialState>FlipCoin</InitialState>
		
		<State Name="FlipCoin">
			<Transition Input="heads" Destination="MoveLeft"/>
			<Transition Input="tails" Destination="MoveRight"/>
		</State>
		<State Name="MoveLeft">
			<Transition Input="heartbeat" Destination="MaybePause"/>
			<Transition Input="collision" Destination="MoveRight"/>
			<Transition Input="atEdge" Destination="MoveRight"/>
			<Transition Input="metSomeone" Destination="MoveRight"/>
			<Transition Input="damageFront" Destination="Jump"/>
			<Transition Input="damageBack" Destination="ChangeDirection"/>
		</State>
		<State Name="MoveRight">
			<Transition Input="heartbeat" Destination="MaybePause"/>
			<Transition Input="collision" Destination="MoveLeft"/>
			<Transition Input="atEdge" Destination="MoveLeft"/>
			<Transition Input="metSomeone" Destination="MoveLeft"/>
			<Transition Input="damageFront" Destination="Jump"/>
			<Transition Input="damageBack" Destination="ChangeDirection"/>
		</State>
		<State Name="Jump">
			<Transition Input="done" Destination="ContinueMoving"/>
		</State>
		<State Name="Pause" State="Delay">
			<Property Name="MinDelay" Value="0.1"/>
			<Property Name="MaxDelay" Value="1"/>
			<Transition Input="delayDone" Destination="PauseDone"/>
			<Transition Input="attacked" Destination="Jump"/>
		</State>
		<State Name="PauseDone" State="Random">
		<Property Name="Chance" Value="0.75"/>
			<Transition Input="true" Destination="ContinueMoving"/>
			<Transition Input="false" Destination="ChangeDirection"/>
		</State>
		<State Name="ContinueMoving" State="FacingRight">
			<Transition Input="true" Destination="MoveRight"/>
			<Transition Input="false" Destination="MoveLeft"/>
		</State>
		<State Name="ChangeDirection" State="FacingRight">
			<Transition Input="true" Destination="MoveLeft"/>
			<Transition Input="false" Destination="MoveRight"/>
		</State>
		<State Name="MaybePause" State="Random">
			<Property Name="Chance" Value="0.75"/>
			<Transition Input="true" Destination="Pause"/>
			<Transition Input="false" Destination="ContinueMoving"/>
		</State>
		<State Name="FindEnemyAhead">
			<Property Name="Distance" Value="100"/>
			<Property Name="Height" Value="80"/>
			<Transition Input="foundEnemy" Destination="Jump"/>
			<Transition Input="notFoundEnemy" Destination="Pause"/>
		</State>
		<State Name="ChangeDirection" State="FacingRight">
			<Transition Input="true" Destination="FaceLeft"/>
			<Transition Input="false" Destination="FaceRight"/>
		</State>
		<State Name="FaceLeft">
			<Transition Input="faceLeftDone" Destination="FindEnemyAhead"/>
		</State>
		<State Name="FaceRight">
			<Transition Input="faceRightDone" Destination="FindEnemyAhead"/>
		</State>
	</Machine>

	<Machine>
		<Name>Shiner</Name>
		<InitialState>ArmChance</InitialState>
		
		<State Name="ArmChance" State="Random">
			<Property Name="Chance" Value="0.5"/>
			<Transition Input="true" Destination="GiveWeapon"/>
			<Transition Input="false" Destination="Idle"/>
		</State>
		<State Name="GiveWeapon" State="SetWeapon">
			<Property Name="Index" Value="1"/>
			<Transition Input="setWeaponDone" Destination="Idle"/>
		</State>
				
		<State Name="Idle">
			<Transition Input="attacked" Destination="SurpriseAttacked"/>
			<Transition Input="heardNoise" Destination="WakeUp"/>
			<Transition Input="touched" Destination="WakeUp"/>
			<Transition Input="lostGround" Destination="WakeUp"/>
		</State>
		
		<State Name="WakeUp" State="SetActivateBarrels">
			<Property Name="ActivateBarrels" Value="1"/>
			<Transition Input="done" Destination="PlaySound"/>
		</State>

		<State Name="PlaySound" State="PlaySound">
			<Property Name="SoundCue" Value="enemy_shiner_wake"/>
			<Transition Input="done" Destination="TestDirection"/>
		</State>
		
		<State Name="Timeout" State="Delay">
			<Property Name="MinDelay" Value="1.5"/>
			<Property Name="MaxDelay" Value="1.5"/>
			<Transition Input="attacked" Destination="TestDirection"/>
			<Transition Input="delayDone" Destination="Idle"/>
		</State>
		
		<State Name="TestDirection" State="PlayerDirection">
			<Transition Input="damageFront" Destination=""/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="left" Destination="MoveRight"/>
			<Transition Input="right" Destination="MoveLeft"/>
		</State>
		<State Name="ContinueMoving" State="FacingRight">
			<Transition Input="true" Destination="MoveRight"/>
			<Transition Input="false" Destination="MoveLeft"/>
		</State>
		<State Name="MoveLeft">
			<Transition Input="heartbeat" Destination="CanAttack"/>
			<Transition Input="collision" Destination="MoveRight"/>
			<Transition Input="damageFront" Destination="MoveRight"/>
			<Transition Input="metSomeone" Destination="MoveRight"/>
			<Transition Input="attacked" Destination=""/>
			<Transition Input="heardNoise" Destination=""/>
			<Transition Input="touched" Destination=""/>
			<Transition Input="lostGround" Destination=""/>
		</State>
		<State Name="MoveRight">
			<Transition Input="heartbeat" Destination="CanAttack"/>
			<Transition Input="collision" Destination="MoveLeft"/>
			<Transition Input="damageFront" Destination="MoveLeft"/>
			<Transition Input="metSomeone" Destination="MoveLeft"/>
			<Transition Input="attacked" Destination=""/>
			<Transition Input="heardNoise" Destination=""/>
			<Transition Input="touched" Destination=""/>
			<Transition Input="lostGround" Destination=""/>
		</State>
		
		<State Name="CanAttack">
			<Transition Input="true" Destination="FindEnemyAhead"/>
			<Transition Input="false" Destination="ContinueMoving"/>
		</State>
		
		<State Name="FindEnemyAhead">
			<Property Name="Distance" Value="170"/>
			<Property Name="Height" Value="120"/>
			<Transition Input="foundEnemy" Destination="Attack"/>
			<Transition Input="notFoundEnemy" Destination="ContinueMoving"/>
		</State>
		
		<State Name="Attack">
			<Transition Input="attackDone" Destination="DisableWeapon"/>
		</State>
		<State Name="DisableWeapon" State="SetWeapon">
			<Property Name="Index" Value="0"/>
			<Transition Input="setWeaponDone" Destination="TestDirection"/>
		</State>		
		<!--<State Name="SurpriseAttacked" State="SetGoodLoot">
			<Transition Input="setGoodLootDone" Destination="Suicide"/>
		</State>-->
		<State Name="SurpriseAttacked" State="Suicide">
		</State>
	</Machine>
	
	<Machine>
		<Name>Boozer</Name>
		<InitialState>Idle</InitialState>
		
		<State Name="Idle">
			<Transition Input="heartbeat" Destination="FindEnemyAhead2"/>
			<Transition Input="damageBack" Destination="ChangeDirection"/>
			<Transition Input="lostGround" Destination="Idle2"/>
		</State>
		
		<State Name="Idle2" State="Idle">
			<Transition Input="heartbeat" Destination=""/>
		</State>
		
		<State Name="ChangeDirectionChance" State="Random">
			<Property Name="Chance" Value="0.6"/>
			<Transition Input="true" Destination="ChangeDirection"/>
			<Transition Input="false" Destination="Idle"/>
		</State>
		
		<State Name="ChangeDirection" State="FacingRight">
			<Transition Input="true" Destination="FaceLeft"/>
			<Transition Input="false" Destination="FaceRight"/>
		</State>
		
		<State Name="FaceLeft">
			<Transition Input="faceLeftDone" Destination="FindEnemyAhead"/>			
		</State>
		
		<State Name="FaceRight">
			<Transition Input="faceRightDone" Destination="FindEnemyAhead"/>			
		</State>
		
		<State Name="FindEnemyAhead">
			<Property Name="Distance" Value="170"/>
			<Property Name="Height" Value="200"/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="foundEnemy" Destination="Attack"/>
			<Transition Input="notFoundEnemy" Destination="Idle"/>
		</State>
		
		<State Name="FindEnemyAhead2">
			<Property Name="Distance" Value="170"/>
			<Property Name="Height" Value="200"/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="foundEnemy" Destination="Attack"/>
			<Transition Input="notFoundEnemy" Destination="ChangeDirectionChance"/>
		</State>

		<State Name="TestDirection" State="PlayerDirection">			
			<Transition Input="left" Destination="FaceLeft"/>
			<Transition Input="right" Destination="FaceRight"/>
		</State>
		
		<State Name="Attack">
			<Transition Input="attackDone" Destination="Idle"/>
			<Transition Input="lostGround" Destination="Idle2"/>
		</State>
	</Machine>
	
	<Machine>
		<Name>Barrel</Name>
		<InitialState>BarrelIdle</InitialState>
		
		<State Name="BarrelIdle">
		</State>
	</Machine>
	
	<Machine>
		<Name>Shroom</Name>
		<InitialState>Idle</InitialState>
		
		<State Name="Idle">
			<Transition Input="lostWall" Destination="Suicide"/>
		</State>
		<State Name="Suicide">
		</State>
	</Machine>
	
	<Machine>
		<Name>Turret</Name>
		<InitialState>Idle</InitialState>
		
		<State Name="Idle" State="CannonScan">
			<Property Name="Speed" Value="0.5"/>
			<Transition Input="heartbeat" Destination="FindEnemy"/>
			<Transition Input="lostWall" Destination="Suicide"/>
		</State>
		
		<State Name="FindEnemy">
			<Property Name="Radius" Value="160"/>
			<Transition Input="foundEnemy" Destination="AimForEnemy"/>
			<Transition Input="notFoundEnemy" Destination="Idle"/>
		</State>
		
		<State Name="AimForEnemy">
			<Transition Input="targetLocked" Destination="SetWeaponAim"/>
			<Transition Input="targetLost" Destination="Idle"/>
			<Transition Input="lostWall" Destination="Suicide"/>
		</State>
		
		<State Name="SetWeaponAim" State="SetWeapon">
			<Property Name="Index" Value="0"/>
			<Transition Input="setWeaponDone" Destination="AimBeam"/>
		</State>
		
		<State Name="AimBeam" State="Attack">
			<Transition Input="attackDone" Destination="SetWeaponAttack"/>
			<Transition Input="lostWall" Destination="Suicide"/>
		</State>
		
		<State Name="SetWeaponAttack" State="SetWeapon">
			<Property Name="Index" Value="1"/>
			<Transition Input="setWeaponDone" Destination="Attack"/>
		</State>
		
		<State Name="Attack">
			<Transition Input="attackDone" Destination="Idle"/>
			<Transition Input="lostWall" Destination="Suicide"/>
		</State>
		
		<State Name="Suicide">
		</State>
	</Machine>
	
	<Machine>
		<Name>Turtle</Name>
		<InitialState>ContinueMoving</InitialState>
		
		<State Name="ContinueMoving" State="FacingRight">
			<Transition Input="true" Destination="MoveRight"/>
			<Transition Input="false" Destination="MoveLeft"/>
		</State>
		<State Name="MoveLeft">
			<Transition Input="heartbeat" Destination="FindEnemyAhead"/>
			<Transition Input="collision" Destination="MoveRight"/>
			<Transition Input="metSomeone" Destination="MoveRight"/>
			<Transition Input="damageFront" Destination="TurtleHide"/>
			<Transition Input="damageBack" Destination="ChangeDirection"/>
		</State>
		<State Name="MoveRight">
			<Transition Input="heartbeat" Destination="FindEnemyAhead"/>
			<Transition Input="collision" Destination="MoveLeft"/>
			<Transition Input="metSomeone" Destination="MoveLeft"/>
			<Transition Input="damageFront" Destination="TurtleHide"/>
			<Transition Input="damageBack" Destination="ChangeDirection"/>
		</State>
		<State Name="ChangeDirection" State="FacingRight">
			<Transition Input="true" Destination="FaceLeft"/>
			<Transition Input="false" Destination="FaceRight"/>
		</State>
		<State Name="FindEnemyAhead">
			<Property Name="Distance" Value="140"/>
			<Property Name="Height" Value="80"/>
			<Property Name="OffsetX" Value="0"/>
			<Transition Input="foundEnemy" Destination="TurtleHide"/>
			<Transition Input="notFoundEnemy" Destination="ContinueMoving"/>
		</State>
		<State Name="TurtleHide">
			<Property Name="Sound" Value="enemy_turtle_hide"/>
			<Transition Input="hideDone" Destination="DelayHide"/>
		</State>
		<State Name="DelayHide" State="Delay">
			<Property Name="MinDelay" Value="0.6"/>
			<Property Name="MaxDelay" Value="0.6"/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="delayDone" Destination="Attack"/>
		</State>
		<State Name="FaceLeft">
			<Transition Input="faceLeftDone" Destination="FindEnemyAhead"/>
		</State>
		<State Name="FaceRight">
			<Transition Input="faceRightDone" Destination="FindEnemyAhead"/>
		</State>
		<State Name="Attack">
			<Transition Input="attackDone" Destination="TurtleUnhide"/>
		</State>		
		<State Name="TurtleUnhide">
			<Property Name="Sound" Value="enemy_turtle_unhide"/>			
			<Transition Input="unhideDone" Destination="DelayUnhide"/>
		</State>
		<State Name="DelayUnhide" State="Delay">
			<Property Name="MinDelay" Value="0.5"/>
			<Property Name="MaxDelay" Value="0.5"/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="delayDone" Destination="ClearInputs"/>
		</State>
		<State Name="ClearInputs"> <!-- We do not want the attacked-input to stick -->
			<Transition Input="clearDone" Destination="ContinueMoving"/>
		</State>
	</Machine>
	
	<Machine>
		<Name>VectronMinion_Charging</Name>
		<InitialState>PlaySound</InitialState>
		<State Name="PlaySound" State="PlaySound">
			<Property Name="SoundCue" Value="minion_charge"/>
			<Transition Input="done" Destination="DelayCharge"/>
		</State>
		
		<State Name="DelayCharge" State="Delay">
			<Property Name="MinDelay" Value="0.5"/>
			<Property Name="MaxDelay" Value="0.5"/>
			<Transition Input="delayDone" Destination="RunStart"/>
		</State>
		<State Name="RunStart">
			<Transition Input="done" Destination="ContinueMoving"/>
			<Transition Input="collision" Destination=""/>
		</State>
		<State Name="ContinueMoving" State="FacingRight">
			<Transition Input="true" Destination="MoveRight"/>
			<Transition Input="false" Destination="MoveLeft"/>
		</State>
		<State Name="MoveLeft">
			<Transition Input="collision" Destination="Suicide"/>
			<Transition Input="atStep" Destination="Jump"/>
			<Transition Input="atEdge" Destination="Jump"/>
			<Transition Input="attacked" Destination="Suicide"/>
			<Transition Input="metEnemy" Destination="Suicide"/>
			<Transition Input="heartbeat" Destination=""/>
		</State>
		<State Name="MoveRight">
			<Transition Input="collision" Destination="Suicide"/>
			<Transition Input="atStep" Destination="Jump"/>
			<Transition Input="atEdge" Destination="Jump"/>
			<Transition Input="attacked" Destination="Suicide"/>
			<Transition Input="metEnemy" Destination="Suicide"/>
			<Transition Input="heartbeat" Destination=""/>
		</State>
		<State Name="Jump">
			<Transition Input="done" Destination="ContinueMoving"/>
		</State>
		<State Name="Suicide">
		</State>
	</Machine>
	<Machine>
		<Name>VectronMinion</Name>
		<InitialState>FlipCoin</InitialState>
		
		<State Name="FlipCoin">
			<Transition Input="heads" Destination="MoveLeft"/>
			<Transition Input="tails" Destination="MoveRight"/>
		</State>
		<!-- Move back and forth, but jump across edges and up steps.
			Explode on impact with enemy. -->
		<State Name="MoveLeft">
			<Transition Input="heartbeat" Destination="FindEnemyAhead"/>
			<Transition Input="collision" Destination=""/>
			<Transition Input="collisionGround" Destination="MoveRight"/>
			<Transition Input="atStep" Destination="Jump"/>
			<Transition Input="atEdge" Destination="ConsiderJumpDown"/>
			<Transition Input="attacked" Destination="Suicide"/>
			<Transition Input="metEnemy" Destination="Suicide"/>
		</State>
		<State Name="MoveRight">
			<Transition Input="heartbeat" Destination="FindEnemyAhead"/>
			<Transition Input="collision" Destination=""/>
			<Transition Input="collisionGround" Destination="MoveLeft"/>
			<Transition Input="atStep" Destination="Jump"/>
			<Transition Input="atEdge" Destination="ConsiderJumpDown"/>
			<Transition Input="attacked" Destination="Suicide"/>
			<Transition Input="metEnemy" Destination="Suicide"/>
		</State>
		<State Name="Jump">
			<Transition Input="done" Destination="ContinueMoving"/>
		</State>
		<State Name="ConsiderJumpDown" State="FlipCoin">
			<Transition Input="heads" Destination="ChangeDirection"/>
			<Transition Input="tails" Destination="SetCheckEdgeTimer"/>
		</State>
		<State Name="SetCheckEdgeTimer">
			<Property Name="Time" Value="1"/>
			<Transition Input="done" Destination="ContinueMoving"/>
		</State>		
		<State Name="ContinueMoving" State="FacingRight">
			<Transition Input="true" Destination="MoveRight"/>
			<Transition Input="false" Destination="MoveLeft"/>
		</State>
		<State Name="ChangeDirection" State="FacingRight">
			<Transition Input="true" Destination="MoveLeft"/>
			<Transition Input="false" Destination="MoveRight"/>
		</State>
		<State Name="FindEnemyAhead">
			<Property Name="Distance" Value="200"/>
			<Property Name="Height" Value="20"/>
			<Transition Input="foundEnemy" Destination="RunStart"/>
			<Transition Input="notFoundEnemy" Destination="ContinueMoving"/>
		</State>
		<!-- If it finds an enemy, charge towards it and explode -->
		<State Name="RunStart" Machine="VectronMinion_Charging">
			
		</State>
		<State Name="Suicide">
		</State>
	</Machine>
	
	<Machine>
		<Name>Spike</Name>
		<InitialState>Idle</InitialState>
		
		<State Name="Idle">
			<Transition Input="heartbeat" Destination="FindEnemy"/>
			<Transition Input="lostWall" Destination="Suicide"/>
		</State>
		
		<State Name="FindEnemy">
			<Property Name="Radius" Value="20"/>
			<Property Name="OffsetY" Value="-10"/>
			<Transition Input="foundEnemy" Destination="Attack"/>
			<Transition Input="notFoundEnemy" Destination="Idle"/>
		</State>
		
		<State Name="Attack">
			<Transition Input="lostWall" Destination="Suicide"/>
			<Transition Input="attackDone" Destination="Idle"/>
		</State>
		
		<State Name="Suicide">
		</State>
	</Machine>
	
	<Machine>
		<Name>Fallblock</Name>
		<InitialState>FallblockUpdate</InitialState>
		
		<State Name="FallblockUpdate">
			<Property Name="WakeTime" Value="0.9"/>
		</State>
	</Machine>

	<Machine>
		<Name>Doucheblock</Name>
		<InitialState>FindAnimationDirection</InitialState>
		
		<State Name="FindAnimationDirection">
			<Transition Input="done" Destination="FallblockUpdate"/>
		</State>

		<State Name="FallblockUpdate">
			<Property Name="WakeTime" Value="0.9"/>
		</State>
	</Machine>
	
	<Machine>
		<Name>Ladder</Name>
		<InitialState>Idle</InitialState>
		
		<State Name="Idle">
		</State>
	</Machine>

	<Machine>
		<Name>Lantern</Name>
		<InitialState>HasGround</InitialState>
		
		<State Name="HasGround">
			<Transition Input="true" Destination="Idle"/>
			<Transition Input="false" Destination="Zombiefy"/>
		</State>
		
		<State Name="Idle" State="CheckGround">
			<Transition Input="lostWall" Destination="Suicide"/>
		</State>
		<State Name="Suicide">
		</State>
		<State Name="Zombiefy">
		</State>
	</Machine>

	<Machine>
		<Name>Pool</Name>
		<InitialState>Idle</InitialState>
		<State Name="Idle">
		</State>
	</Machine>

	<Machine>
		<Name>JumpPlate</Name>
		<InitialState>Idle</InitialState>

		<State Name="Idle">
			<Transition Input="lostGround" Destination="Suicide"/>
		</State>
		<State Name="Suicide"/>
	</Machine>

	<Machine>
		<Name>NPC</Name>
		<InitialState>Patrol</InitialState>

		<State Name="Patrol">
			<Transition Input="walkTo" Destination="WalkTo"/>
			<Transition Input="foundRusty" Destination="WaitOnRusty"/>
			<Transition Input="stop" Destination="Stop"/>
		</State>
		<State Name="WalkTo">
			<Transition Input="atTarget" Destination="Patrol"/>
			<Transition Input="timeout" Destination="Patrol"/>
			<Transition Input="stop" Destination="Stop"/>
		</State>
		<State Name="WaitOnRusty">
			<Transition Input="walkTo" Destination="WalkTo"/>
			<Transition Input="lostRusty" Destination="Patrol"/>
			<Transition Input="stop" Destination="Stop"/>
		</State>
		<State Name="Stop">
			<Transition Input="timeout" Destination="Patrol"/>
			<Transition Input="walkTo" Destination="WalkTo"/>
			<Transition Input="stop" Destination="Stop"/>
		</State>
	</Machine>

	<Machine>
		<Name>Hola</Name>
		<InitialState>WaitOnRusty</InitialState>

		<State Name="WaitOnRusty">
		</State>
	</Machine>

	<Machine>
		<Name>Acidblock</Name>
		<InitialState>Idle</InitialState>

		<State Name="Idle">
			<Transition Input="heartbeat" Destination="Attack"/>
			<Transition Input="lostWall" Destination="Suicide"/>
		</State>

		<State Name="Attack">
			<Transition Input="attackDone" Destination="Idle"/>
		</State>

		<State Name="Suicide">
		</State>
	</Machine>

	<Machine>
		<Name>LaserBox</Name>
		<InitialState>Idle</InitialState>
		
		<State Name="Idle">
			<Transition Input="heartbeat" Destination="FindEnemyIdle"/>
		</State>
		<State Name="FindEnemyIdle" State="FindEnemy">
			<Property Name="Radius" Value="150"/>
			<Transition Input="foundEnemy" Destination="EnableAnimation"/>
			<Transition Input="notFoundEnemy" Destination="Idle"/>
		</State>
				
		<State Name="EnableAnimation" State="SimpleAnimation">
			<Property Name="Animation" Value="open"/>
			<Property Name="PlayOnce" Value="1"/>
			<Transition Input="done" Destination="DelayBeforeAttack"/>
		</State>
		<State Name="DelayBeforeAttack" State="CompositeState">
			<Property Name="State0" Value="AimForEnemy"/>
			<Property Name="State1" Value="Delay"/>
			<Property Name="MinDelay" Value="0.5"/>
			<Property Name="MaxDelay" Value="0.5"/>
			<Transition Input="delayDone" Destination="EnableBeamsSound"/>
			<Transition Input="targetLost" Destination="DisableAnimation"/>
		</State>
		<State Name="EnableBeams">
			<Transition Input="done" Destination="AimForEnemy"/>
		</State>
		<State Name="EnableBeamsSound" State="PlaySound">
			<Property Name="SoundCue" Value="laserbox_wake"/>
			<Transition Input="done" Destination="EnableBeams"/>
		</State>

		<State Name="FindEnemyActive" State="FindEnemy">
			<Property Name="Radius" Value="150"/>
			<Transition Input="foundEnemy" Destination="AimForEnemy"/>
			<Transition Input="notFoundEnemy" Destination="WaitBeforeDisable"/>
		</State>
		<State Name="AimForEnemy" State="CompositeState">
			<Property Name="State0" Value="AimForEnemy"/>
			<Property Name="State1" Value="Delay"/>
			<Property Name="CustomTimer" Value="blinkTimer"/>
			<Property Name="MinDelay" Value="3"/>
			<Property Name="MaxDelay" Value="5"/>
			<Transition Input="heartbeat" Destination="FindEnemyActive"/>
			<Transition Input="delayDone" Destination="Blink"/>
			<Transition Input="targetLost" Destination="WaitBeforeDisable"/>
			<Transition Input="attacked" Destination="Hide"/>
		</State>
		<State Name="Blink" State="SimpleAnimation">
			<Property Name="Animation" Value="blink"/>
			<Property Name="PlayOnce" Value="1"/>
			<Transition Input="done" Destination="WaitForBlink"/>
		</State>
		<State Name="WaitForBlink" State="Delay">
			<Property Name="MinDelay" Value="0.25"/>
			<Property Name="MaxDelay" Value="0.25"/>
			<Transition Input="delayDone" Destination="BlinkDone"/>
		</State>
		<State Name="BlinkDone" State="SimpleAnimation">
			<Property Name="Animation" Value="opened"/>
			<Property Name="PlayOnce" Value="1"/>
			<Transition Input="done" Destination="FindEnemyActive"/>
		</State>
						
		<State Name="WaitBeforeDisable" State="Delay">
			<Property Name="MinDelay" Value="1"/>
			<Property Name="MaxDelay" Value="1"/>
			<Transition Input="delayDone" Destination="ConfirmGone"/>
			<Transition Input="attacked" Destination="Hide"/>
		</State>
		
		<State Name="ConfirmGone" State="FindEnemy">
			<Property Name="Radius" Value="150"/>
			<Transition Input="foundEnemy" Destination="AimForEnemy"/>
			<Transition Input="notFoundEnemy" Destination="DisableBeamsSound"/>
		</State>
		
		<State Name="DisableBeamsSound" State="PlaySound">
			<Property Name="SoundCue" Value="laserbox_sleep"/>
			<Transition Input="done" Destination="DisableBeams"/>
		</State>
		
		<State Name="DisableBeams">
			<Transition Input="done" Destination="DisableAnimation"/>
		</State>
		<State Name="DisableAnimation" State="SimpleAnimation">
			<Property Name="Animation" Value="close"/>
			<Property Name="PlayOnce" Value="1"/>
			<Transition Input="done" Destination="Idle"/>
		</State>
				
		<State Name="Hide" State="DisableBeams">
			<Transition Input="done" Destination="DisableAnimationAndWait"/>
		</State>
		<State Name="DisableAnimationAndWait" State="SimpleAnimation">
			<Property Name="Animation" Value="close"/>
			<Property Name="PlayOnce" Value="1"/>
			<Transition Input="done" Destination="Wait"/>
		</State>		
		<State Name="Wait" State="Delay">
			<Property Name="MinDelay" Value="6"/>
			<Property Name="MaxDelay" Value="6"/>
			<Transition Input="attacked" Destination=""/>
			<Transition Input="delayDone" Destination="Idle"/>
		</State>		
	</Machine>
	
	<Machine>
		<Name>UpgradePodium</Name>
		<InitialState>PodiumUpdate</InitialState>
		
		<State Name="PodiumUpdate">
			<Transition Input="done" Destination="Idle"/>
		</State>
		
		<State Name="Idle">
			<Transition Input="touched" Destination="PodiumUpdate"/>
		</State>
	</Machine>

	<Machine>
		<Name>Teleporter</Name>
		<InitialState>Teleporter</InitialState>

		<State Name="Teleporter" State="CompositeState">
			<Property Name="State0" Value="Teleporter"/>
			<Property Name="State1" Value="CheckGround"/>
			<Property Name="WakeTime" Value="4.0"/>
			<Transition Input="lostWall" Destination="DeleteTeleporter"/>
		</State>
		<State Name="DeleteTeleporter">
		</State>
	</Machine>

	<Machine>
		<Name>TownTeleporter</Name>
		<InitialState>TownTeleporterVisibility</InitialState>

		<State Name="TownTeleporterVisibility">
			<Transition Input="done" Destination="Teleporter"/>
		</State>
		<State Name="Teleporter">
		</State>
	</Machine>

	<Machine>
		<Name>BossGenerator</Name>
		<InitialState>GeneratorSetup</InitialState>

		<State Name="GeneratorSetup">
			<Transition Input="done" Destination="GeneratorInactive"/>
		</State>

		<State Name="GeneratorInactive">
			<Transition Input="spawnGenerator" Destination="GeneratorActivation"/>
		</State>

		<State Name="GeneratorActivation">
			<Transition Input="done" Destination="GeneratorActive"/>
		</State>

		<State Name="GeneratorActive">
			<Transition Input="attacked" Destination="GeneratorCheckDamage"/>
		</State>

		<State Name="GeneratorCheckDamage">
			<Transition Input="false" Destination="GeneratorActive"/>
			<Transition Input="true" Destination="GeneratorInactive"/>
		</State>
	</Machine>

	<Machine>
		<Name>BossCore</Name>
		<InitialState>BossSetup</InitialState>

		<State Name="BossSetup">
			<Transition Input="done" Destination="BossWaiting"/>
		</State>

		<State Name="BossWaiting" State="Idle">
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="BossStart" Destination="BossStart"/>
		</State>

		<State Name="BossStart">
			<Transition Input="done" Destination="RespawnGenerators"/>
		</State>
		
		<State Name="BossIdle" State="CompositeState">
			<Property Name="State0" Value="Delay"/>
			<Property Name="State1" Value="BossIdle"/>
			<Property Name="MinDelay" Value="0.5"/>
			<Property Name="MaxDelay" Value="0.5"/>
			<Property Name="CustomTimer" Value="idleTimer"/>
			<Transition Input="attacked" Destination=""/>
			<Transition Input="targetLocked" Destination=""/>
			<Transition Input="targetLost" Destination=""/>
			<Transition Input="heartbeat" Destination="ChooseAttack"/>
			<Transition Input="delayDone" Destination="FindEnemyIdle"/>
			<Transition Input="generatorAttacked" Destination="StartTargetLaser"/>
			<Transition Input="generatorDestroyed" Destination="CheckGenerators"/>
		</State>
		<State Name="FindEnemyIdle" State="FindEnemy">
			<Property Name="Radius" Value="400"/>
			<Transition Input="foundEnemy" Destination="BossIdle"/>
			<Transition Input="notFoundEnemy" Destination="BossIdle"/>
		</State>

		<!-- Decide which attack to use. -->
		<State Name="ChooseAttack" State="CompositeState">
			<Property Name="State0" Value="FindEnemy"/>
			<Property Name="State1" Value="BossAttack"/>
			<Property Name="Radius" Value="400"/>
			<Transition Input="foundEnemy" Destination=""/>
			<Transition Input="notFoundEnemy" Destination=""/>
			<Transition Input="spawnEnemy" Destination="SpawnEnemy"/>
			<Transition Input="targetLaser" Destination="StartTargetLaser"/>
			<Transition Input="spinLaser" Destination="StartSpinLaser"/>
		</State>

		<!-- Requests attack, unless there are already too many enemies about. Randomize enemy type? -->
		<State Name="SpawnEnemy">
			<Transition Input="done" Destination="BossIdle"/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="generatorAttacked" Destination="StartTargetLaser"/>
			<Transition Input="generatorDestroyed" Destination="CheckGenerators"/>
		</State>

		<!-- Start of Spin Laser behavior chain. Laser setup sound/animation. Warns player what's happening. -->
		<State Name="StartSpinLaser">
			<Transition Input="done" Destination="SpinLaser"/>
		</State>
		<!-- Laser shooting sound/animation. Enables beam. -->
		<State Name="SpinLaser">
			<Transition Input="done" Destination="BossIdle"/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="generatorAttacked" Destination=""/>
			<Transition Input="generatorDestroyed" Destination="CheckGenerators"/>
		</State>

		<!-- Start of Target Laser behavior chain -->
		<State Name="StartTargetLaser">
			<Transition Input="done" Destination="FindEnemyTarget"/>
		</State>
		<State Name="FindEnemyTarget" State="FindEnemy">
			<Property Name="Radius" Value="700"/>
			<Transition Input="foundEnemy" Destination="AimLaser"/>
			<Transition Input="notFoundEnemy" Destination="BossIdle"/>
		</State>
		<State Name="AimLaser" State="AimForEnemy">
			<Transition Input="targetLocked" Destination="LockOnLaser"/>
			<Transition Input="targetLost" Destination="BossIdle"/>
		</State>
		<State Name="LockOnLaser">
			<Transition Input="done" Destination="TargetLaser"/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="generatorAttacked" Destination=""/>
			<Transition Input="generatorDestroyed" Destination="CheckGenerators"/>
		</State>
		<!-- Laser shooting sound/animation. Enables beam. -->
		<State Name="TargetLaser">
			<Transition Input="done" Destination="BossIdle"/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="generatorAttacked" Destination=""/>
			<Transition Input="generatorDestroyed" Destination="CheckGenerators"/>
		</State>

		<!-- Are any generators still active? -->
		<State Name="CheckGenerators">
			<Transition Input="true" Destination="BossIdle"/>
			<Transition Input="false" Destination="Vulnerable"/>
		</State>

		<!-- The ongoing state while vulnerable. -->
		<State Name="Vulnerable">
			<Transition Input="attacked" Destination="CheckNextPhase"/>
			<Transition Input="tooLongTime" Destination="RespawnGeneratorsDelay"/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="generatorAttacked" Destination=""/>
			<Transition Input="generatorDestroyed" Destination=""/>
		</State>

		<!-- If false, resets state variables and is the place for any phase-specific changes. -->
		<State Name="CheckNextPhase">
			<Transition Input="false" Destination="Vulnerable"/>
			<Transition Input="true" Destination="RespawnGeneratorsExplosion"/>
			<Transition Input="itIsOverNow" Destination="ItIsOverNow"/>
		</State>

		<State Name="RespawnGeneratorsExplosion" State="Explosion">
			<Transition Input="done" Destination="RespawnGeneratorsDelay"/>
		</State>
			
		<!-- Wakes up and looks intimidating for a moment before shockwave and regen. -->
		<State Name="RespawnGeneratorsDelay" State="CompositeState">
			<Property Name="State0" Value="Delay"/>
			<Property Name="State1" Value="TriggerAnimation"/>
			<Property Name="State2" Value="RestoreBackdrop"/>
			<Property Name="MinDelay" Value="2"/>
			<Property Name="MaxDelay" Value="2"/>
			<Property Name="Animation" Value="respawn"/>
			<Transition Input="heartbeat" Destination=""/>
			<Transition Input="attacked" Destination=""/>
			<Transition Input="done" Destination=""/>
			<Transition Input="delayDone" Destination="RespawnGenerators"/>
		</State>

		<!-- Respawns some random generators. How many depends on phase. -->
		<State Name="RespawnGenerators">
			<Transition Input="done" Destination="BossIdle"/>
		</State>

		<State Name="ItIsOverNow">
			<Transition Input="heartbeat" Destination="Explosion"/>
			<Transition Input="done" Destination="EpilogueDelay"/>
		</State>
		<State Name="Explosion">
			<Transition Input="done" Destination="ItIsOverNow"/>
		</State>
		<State Name="EpilogueDelay" State="Delay">
			<Property Name="MinDelay" Value="4"/>
			<Property Name="MaxDelay" Value="4"/>
		</State>

	</Machine>
</Behaviors>
