#include "Behaviors/StateMachine.h"

$nodeclass HW1_Prob4 : StateNode {
  $setupmachine {
    launch: StateNode =N=> {howlf, redf}
    
    howlf:    SoundNode($,"howl.wav")[setAutoStop(true)]
    barklowf: SoundNode($,"barklow.wav")[setAutoStop(true)]
    pingf:    SoundNode($,"ping.wav")[setAutoStop(true)]
    tocf:     SoundNode($,"toc.wav")[setAutoStop(true)]

    redf:    LedNode [getMC()->cset(RobotInfo::RedLEDMask,1.0)]
    yellowf: LedNode [getMC()->cset(RobotInfo::YellowLEDMask,1.0)]
    greenf:  LedNode [getMC()->cset(RobotInfo::GreenLEDMask,1.0)]
    bluef:   LedNode [getMC()->cset(RobotInfo::BlueLEDMask,1.0)]

    {howlf, redf}       =C(2)=> {barklowf, yellowf}
    {barklowf, yellowf} =C(2)=> {pingf, greenf}
    {pingf, greenf}     =C(2)=> {tocf, bluef}
    {tocf, bluef}       =C(2)=> {howlf, redf}
    
    howlr:    SoundNode($,"howl.wav")[setAutoStop(true)]
    barklowr: SoundNode($,"barklow.wav")[setAutoStop(true)]
    pingr:    SoundNode($,"ping.wav")[setAutoStop(true)]
    tocr:     SoundNode($,"toc.wav")[setAutoStop(true)]

    redr:    LedNode [getMC()->cset(RobotInfo::RedLEDMask,1.0)]
    yellowr: LedNode [getMC()->cset(RobotInfo::YellowLEDMask,1.0)]
    greenr:  LedNode [getMC()->cset(RobotInfo::GreenLEDMask,1.0)]
    bluer:   LedNode [getMC()->cset(RobotInfo::BlueLEDMask,1.0)]

    {howlr, redr}       =C(2)=> {tocr, bluer}
    {barklowr, yellowr} =C(2)=> {howlr, redr}
    {pingr, greenr}     =C(2)=> {barklowr, yellowr}
    {tocr, bluer}       =C(2)=> {pingr, greenr}

    {howlf, redf} =B(RobotInfo::GreenButOffset)=> {tocr, bluer}
    {tocr, bluer} =B(RobotInfo::GreenButOffset)=> {howlf, redf}

    {barklowf, yellowf} =B(RobotInfo::GreenButOffset)=> {howlr, redr}
    {howlr, redr} =B(RobotInfo::GreenButOffset)=> {barklowf, yellowf}

    {pingf, greenf} =B(RobotInfo::GreenButOffset)=> {barklowr, yellowr}
    {barklowr, yellowr} =B(RobotInfo::GreenButOffset)=> {pingf, greenf}

    {tocf, bluef} =B(RobotInfo::GreenButOffset)=> {pingr, greenr}
    {pingr, greenr} =B(RobotInfo::GreenButOffset)=> {tocf, bluef}
  }
}

REGISTER_BEHAVIOR(HW1_Prob4);
