//The states
//0: Walking around in city
//1: Stay idle or return to beginning point
//2: In combat

// Get mean if characters wanna be bad
IfAttacked
  Run
  CallForHelp
  JoinEvilTeam
  tmpargument = 2
  SetState
IfCalledForHelp
  JoinEvilTeam
  Walk
IfKilled
  CallForHelp			//Warn friends

IfSpawned
  tmpargument = rand & 3	//Randomize skin
  ChangeArmor
  Sneak				//Dont run around

//------------------------------------------------------------------------------
// ZZ> Handle normal state
IfTimeOut
  tmpargument = rand % 200 + 80 
  SetTime

//WANDER AROUND
  IfStateIs0
    tmpx = rand % 2024 - 1012 + selfx
    tmpy = rand % 2024 - 1012 + selfy
    tmpturn = rand & 511 - 256 + selfturn
    Compass
    ClearWaypoints
    AddWaypoint
    SetTargetToNearbyEnemy		//Enemy near, go combat mode
      tmpargument = 2
      SetState
      tmpargument = 50
      SetTime
      CallForHelp

//IDLE OR RETURN TO START
  IfStateIs1
    tmpx = selfspawnx			//Return to where it was spawned
    tmpy = selfspawny
    ClearWaypoints
    AddWaypoint
    SetTargetToNearbyEnemy		//Enemy near, go combat mode
      tmpargument = 2
      SetState
      tmpargument = 50
      SetTime
      CallForHelp

//IN COMBAT
  IfStateIs2
    SetTargetToNearbyEnemy
      IfFacingTarget			//Attack enemy?
        tmpx = targetdistance
        tmpy = 100
        IfXIsLessThanY
          tmpargument = LATCHRIGHT
          PressLatchButton
      Else
        tmpx = targetx			//Get in combat position
        tmpy = targety
        tmpturn = targetturnto
        tmpdistance = 200
        Compass
        ClearWaypoints
        AddWaypoint
    Else
      tmpargument = 0
      SetState
    tmpargument = 60
    SetTime

//What to do if bumped
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnHatedTeam
    IfFacingTarget			//Attack enemies
      tmpargument = LATCHRIGHT
      PressLatchButton
    Else
      tmpx = targetx			//Move towards enemy
      tmpy = targety
      ClearWaypoints
      AddWaypoint
  Else
    tmpx = rand & 511 - 256 + selfx	//Try to move out of friendlies way
    tmpy = rand & 511 - 256 + selfy
    tmpdistance = 100
    tmpturn = targetturnto + 32768
    Compass
    ClearWaypoints
    AddWaypoint
    SetTargetToOldTarget

//------------------------------------------------------------------------------
End
//------------------------------------------------------------------------------

