/* Generic Swiping with Tail Machine // // The pusher needs to call the following actions before running this machine: // // action SetNumPassedParam(1) ; sets up the parameters required by this machine // action SetPassedParamTailAttack(0) ; The type of tail attack // ; - 0 aggressive: chases enemy(s) // ; - 1 territorial: tries to keep enemy(s) from territory // ; - 2 defensive: retreats or stays in the same spot while attacking // call Swipe returnState ; sets the target to run this machine // */ machine Swipe { default state SwipeInit { ; aggressive: chases enemy(s) transition GetPassedParam(0) == 0 { action SetNumPassedParam(3) action SetPassedParam(0, 0) action Print("Agressive tail attack\n"); goto SwipeStart } ; territorial: tries to keep enemy(s) from territory transition GetPassedParam(0) == 1 { action SetNumPassedParam(2) action SetPassedParam(0, 1) action Print("territorial tail attack\n"); goto SwipeStart } ; defensive: retreats or stays in the same spot while attacking transition GetPassedParam(0) == 2 { action SetNumPassedParam(2) action SetPassedParam(0, 2) action Print("Defensive tail attack\n"); goto SwipeStart } ; debug stuff transition { action Print("Unknown tail attack type passed to Swipe.fsm!\n"); action Assert(0) action SetNumPassedParam(2) action SetPassedParam(0, 0) goto SwipeStart } } state SwipeStart { ; aggressive: chases enemy(s) transition GetPassedParam(0) == 0 { action Print("Agressive tail attack\n"); goto AgressiveStart } ; territorial: tries to keep enemy(s) from territory transition GetPassedParam(0) == 1 { action Print("territorial tail attack\n"); goto TerritoryStart } ; defensive: retreats or stays in the same spot while attacking transition GetPassedParam(0) == 2 { action Print("Defensive tail attack\n"); goto DefensiveStart } } state AgressiveStart { ;action AcquireTarget("aggressor") action AcquireDinoTargetInProximity(60.0, 100.0) action SetSpeedModifierRun(5.0) action SetRunMode(true) transition HasTarget() { action Print("Ver 5") action Print("found aggressor target!! ") ;face target sideways action SeekTarget() goto FoundTarget } transition { goto AgressiveSeek } } state AgressiveSeek { action SetWander() action SetRandomTimerBetween(1, 2.0, 8.0) transition { goto AgressiveSeekWait } } state AgressiveSeekWait { transition IsTimerUp(1) { goto AgressiveStart } } state TerritoryStart { ; move back inside territory transition IsUnitInsideTerritory(1.1) == false { action SeekRandomPointInsideTerritory(0.9) action SetSpeedModifierWalk(2.0) action SetRunMode(false) goto GoBackInsideTerritory } action AcquireDinoTargetInProximity(10.0, 100.0) action SetSpeedModifierRun(5.0) action SetRunMode(true) transition HasTarget() { ;face target sideways action SeekTarget() goto FoundTarget } } state GoBackInsideTerritory { transition IsUnitInsideTerritory(0.9) { goto TerritoryStart } ; if I'm being attacked, defend myself! } state DefensiveStart { transition GetVariable("health") > 80.0 { action Print("Health is bigger than 80.0") action SetSpeedModifierWalk(2.0) action SetRunMode(false) action SetStandStill() goto DefensiveStart2 } transition { action Print("Health is Less than 80.0") goto DefensiveStart2 } } state DefensiveStart2 { action AcquireDinoTargetInProximity(10.0, 100.0) action SetSpeedModifierRun(5.0) action SetRunMode(true) transition HasTarget() { ;face target sideways ;action SeekTarget() goto FoundTarget } } state FoundTarget { transition { action SetParam(0, 2) call Swipe SwipeStart } transition InTargetProximity(5.0) { action Print("in target prox\n") action FaceSideOnToTarget() goto CloseToTarget } } state CloseToTarget { transition IsTargetOnLeft() { action Print("Target is on left \n") action SetPassedParam(1, 0) ; set the swipe side to be the left goto StartSwipe } transition { action Print("Target is on right \n") action SetPassedParam(1, 1) ; set the swipe side to be the right goto StartSwipe } } state StartSwipe { action Print("Swipeing!\n ") ; are we swiping left? transition GetPassedParam(1) == 0 { action PlayAnimSpeed("def", "tl_lt_st", true, 1.0) goto StartSwipeWait } ; are we swiping right? ;transition GetPassedParam(1) == 1 transition { action PlayAnimSpeed("def", "tl_rt_st", true, 1.0) goto StartSwipeWait } } state StartSwipeWait { transition AnimStateFinished("def") { goto StartSwipeStartEndSwipe } } state StartSwipeStartEndSwipe { ;// set the return value to be put in param 3 (index 2) action SetPassedParam(0, 2) transition GetPassedParam(1) == 0 { action PlayAnimSpeed("def", "tl_lt_ed", true, 1.0) goto CheckSwipeHit } ; are we swiping right? ;transition GetPassedParam(1) == 1 transition { action PlayAnimSpeed("def", "tl_rt_ed", true, 1.0) goto CheckSwipeHit } } state CheckSwipeHit { transition AnimStateFinished("def") { action Print("Finished swipe and missed!\n") goto SwipeMiss } transition IsTargetFSMRunning(fsm::"KnockOver") == false;// check if already knocked over { goto CheckSwipeHit } transition CheckTailHittingTarget(-0.5) { action Print("Found target in range!\n") goto PushTarget } } state ContinueCheckSwipeHit { transition AnimStateFinished("def") { action Print("Hit with tail and done\n") action ClearTarget() goto SwipeStart } transition IsTargetFSMRunning(fsm::"KnockOver") == false;// check if already knocked over { goto CheckSwipeHit } transition CheckTailHittingTarget(-1000.5) { action Print("Found target in range!\n") goto PushTarget } } state PushTarget { action SetTargetToSlave() ; sets target into command mode action PushTarget() ; sets the targets steering into a pushed mode action SetNumPassedParamTarget(1) ; sets up the parameters required by this machine action SetPassedParamTargetKnockDir(0) ; " " " " action SetTargetsTargetToMe() action SetTargetFSM(fsm::"KnockOver") transition HasTarget() == false { action Print("PushTarget - doesnt have a target!!\n") goto ContinueCheckSwipeHit } transition { action Print("PushTarget - has a target!!\n") goto ContinueCheckSwipeHit } } state SwipeMiss { action Print("Swipe Missed!"); ; aggressive: chases enemy(s) transition GetPassedParam(0) == 0 { ;try go get to a better place to hit target action AvoidTarget(10.0, false) goto AggressiveSwipeMissWait } ; territorial: tries to keep enemy(s) from territory transition GetPassedParam(0) == 1 { goto TerritorySwipeMissWait } ; defensive: retreats or stays in the same spot while attacking ;GetPassedParam(0) == 2 transition { goto DefensiveSwipeMissWait } } state AggressiveSwipeMissWait { transition IsAtDistanceFromTargetOrGreater(10.0) { goto SwipeStart } } state TerritorySwipeMissWait { transition IsUnitInsideTerritory(1.1) { goto SwipeStart } transition { action SeekRandomPointInsideTerritory(1.1) goto TerritorySwipeMissWait2 } } state TerritorySwipeMissWait2 { transition IsUnitInsideTerritory(1.1) { goto SwipeStart } } state DefensiveSwipeMissWait { ; if we are injured.. run transition GetVariable("health") < 80.0 { action AvoidTarget() goto SwipeStart } ; stay, and keep defending transition { goto SwipeStart } } ;------------------------ Exit States Begin ---------------------- exitstart state CleanUp { action SetSpeedModifier(1.0) action SetRunMode(false) action SetAutoMovementBlend(true) action LookEnd() transition { goto CleanUpEnd } } exitend state CleanUpEnd { } ;------------------------ Exit States End ---------------------- }