#include "Behaviors/StateMachine.h"

$nodeclass ForkJoinBehavior : StateNode {
	$setupmachine {
		//Set up nodes for state machine	
		launch: StateNode
		noblink: LedNode [setPriority(MotionManager::kBackgroundPriority);
	              	 getMC()->set(RobotInfo::AllLEDMask,0.0)]
		//Set of nodes for transitioning forward
		powerflashf:LedNode[getMC()->set(RobotInfo::PowerRedLEDMask, 1.0)]
		playflashf: LedNode[getMC()->set(RobotInfo::PlayLEDMask, 1.0)]
		advflashf: LedNode[getMC()->set(RobotInfo::AdvanceLEDMask, 1.0)]
		//Set of nodes for transitioning backward
		powerflashb:LedNode[getMC()->set(RobotInfo::PowerRedLEDMask, 1.0)]
		playflashb: LedNode[getMC()->set(RobotInfo::PlayLEDMask, 1.0)]
		advflashb: LedNode[getMC()->set(RobotInfo::AdvanceLEDMask, 1.0)]
		//Set of nodes for barking forward
		barklowf: SoundNode("howl.wav")
		barkmedf: SoundNode("roar.wav")
		yipperf: SoundNode("ping.wav")
		//Set of nodes for barking backward
		barklowb: SoundNode("howl.wav")
		barkmedb: SoundNode("roar.wav")
		yipperb: SoundNode("ping.wav")
		
		//Setup launch transition
		launch =N=> {noblink, powerflashf,barklowf}

		//Setup forward transitions
		{powerflashf,barklowf} =C(2)=> {playflashf,barkmedf}
		{playflashf,barkmedf} =C(2)=> {advflashf,yipperf}
		{advflashf,yipperf} =C(2)=> {powerflashf,barklowf}

		//Setup backward transitions
		{powerflashb,barklowb} =C(2)=> {advflashb,yipperb}
		{advflashb,yipperb} =C(2)=> {playflashb,barkmedb} 
		{playflashb,barkmedb} =C(2)=> {powerflashb,barklowb} 

		//Setup forward to backward transitions
		{powerflashf,barklowf} =B(BumpLeftButOffset)=> 	{advflashb,yipperb}
		{playflashf,barkmedf} =B(BumpLeftButOffset)=> {powerflashb,barklowb}
		{advflashf,yipperf} =B(BumpLeftButOffset)=> {playflashb,barkmedb} 

		//Setup backward to forward transitions
		{powerflashb,barklowb} =B(BumpLeftButOffset)=> {playflashf,barkmedf}
		{advflashb,yipperb} =B(BumpLeftButOffset)=> {powerflashf,barklowf}
		{playflashb,barkmedb} =B(BumpLeftButOffset)=> {advflashf,yipperf}
	}
}
REGISTER_BEHAVIOR(ForkJoinBehavior);
