IfCleanedUp
  tmpargument = 1250    //25 seconds
  SetTime

// ZZ> This function spawns enemies when near a hero
IfTimeOut				// This is done every so often
  
  //Reset the timer
  tmpargument = rand & 63 + 20
  SetTime				  //
  
  SetTargetToNearbyEnemy		  // Look for enemies
    IfTargetIsOnHatedTeam         //
      tmpx = selfx
      tmpy = selfy
      GetTileXY
      tmpx = tmpargument
      tmpargument = 50  //mosquito is default
      
      //SEA
      tmpy = 0
      IfXIsEqualToY
        tmpargument = 37           //Squidgie
        tmpdistance = selfz + 200  //how high?
        tmpturn = rand                  //what direction should it face?
        tmpx = selfx               //where to spawn x
        tmpy = selfy              //where to spawn y
        SpawnExactCharacterXYZ
      
      //BEACH
      tmpy = 8
      IfXIsEqualToY
        tmpargument = 79           //crab
        tmpdistance = selfz + 200  //how high?
        tmpturn = selfturn         //what direction should it face?
        tmpx = targetx + 150               //where to spawn x
        tmpy = targety + 150              //where to spawn y
        SpawnExactCharacterXYZ
        tmpturn = rand                  //what direction should it face?
        tmpx = targetx - 150               //where to spawn x
        tmpy = targety - 150              //where to spawn y
        SpawnExactCharacterXYZ
      
      //DOOM WASTES
      tmpy = 16
      IfXIsEqualToY
        tmpargument = 18                    //ulna works okay
        tmpdistance = selfz + 200           //how high?
        tmpturn = rand                  //what direction should it face?
        tmpx = targetx + 150               //where to spawn x
        tmpy = targety + 150              //where to spawn y
        SpawnExactCharacterXYZ
        tmpturn = rand                  //what direction should it face?
        tmpx = targetx - 150               //where to spawn x
        tmpy = targety - 150              //where to spawn y
        SpawnExactCharacterXYZ
        tmpturn = rand                  //what direction should it face?
        tmpx = targetx - 150               //where to spawn x
        tmpy = targety + 150              //where to spawn y
        SpawnExactCharacterXYZ
        tmpturn = rand                  //what direction should it face?
        tmpx = targetx + 150               //where to spawn x
        tmpy = targety - 150              //where to spawn y
        SpawnExactCharacterXYZ
        tmpargument = 65
        tmpturn = rand                  //what direction should it face?
        tmpx = selfx               //where to spawn x
        tmpy = selfy              //where to spawn y
        SpawnExactCharacterXYZ
      
      //G'NOME LANDS
      tmpy = 24
      IfXIsEqualToY
        tmpargument = 72           //tranch
        tmpdistance = selfz + 200  //how high?
        tmpturn = selfturn         //what direction should it face?
        tmpx = selfx               //where to spawn x
        tmpy = selfy              //where to spawn y
        SpawnExactCharacterXYZ
      
      //FROZEN LANDS
      tmpy = 32
      IfXIsEqualToY
        tmpargument = 98           //ghoul - no good - replace
        tmpx = selfx               //where to spawn x
        tmpy = selfy               //where to spawn y
        tmpdistance = selfz + 200  //how high?
        tmpturn = selfturn         //what direction should it face?
        SpawnExactCharacterXYZ
      
      //ELVEN WOODS
      tmpy = 40
      IfXIsEqualToY
        tmpargument = 50            //mosquito
        tmpx = selfx + 150
        tmpy = selfy + 150
        tmpdistance = selfz + 200
        tmpturn = rand
        SpawnExactCharacterXYZ
        tmpx = selfx - 150
        tmpturn = rand
        SpawnExactCharacterXYZ
        tmpy = selfy - 150
        tmpturn = rand
        SpawnExactCharacterXYZ
        tmpx = selfx + 150
        tmpturn = rand
        SpawnExactCharacterXYZ        
      
      //PLAINS
      tmpy = 48
      IfXIsEqualToY
        tmpargument = 38           //grub bug
        tmpdistance = selfz  //how high?
        tmpturn = rand                  //what direction should it face?
        tmpx = targetx + 150               //where to spawn x
        tmpy = targety + 150              //where to spawn y
        SpawnExactCharacterXYZ
        tmpx = targetx - 150               //where to spawn x
        tmpy = targety - 150              //where to spawn y
        tmpturn = rand                  //what direction should it face?
        SpawnExactCharacterXYZ
        tmpx = targetx - 150               //where to spawn x
        tmpy = targety + 150              //where to spawn y
        tmpturn = rand                  //what direction should it face?
        SpawnExactCharacterXYZ
        tmpx = targetx + 150               //where to spawn x
        tmpy = targety - 150              //where to spawn y
        tmpturn = rand                  //what direction should it face?
        SpawnExactCharacterXYZ
               
      //MOUNTAINS               
      tmpy = 56
      IfXIsEqualToY
        tmpargument = 97           //cockatrice
        tmpx = selfx               //where to spawn x
        tmpy = selfy               //where to spawn y
        tmpdistance = selfz + 200  //how high?
        tmpturn = rand         //what direction should it face?
        SpawnExactCharacterXYZ
      
      //DESERT
      tmpy = 72
      IfXIsEqualToY
        tmpx = rand & 1
        tmpy = 0
        IfXIsEqualToY                //50/50 chance
          tmpargument = 72           //tranch
        Else
          tmpargument = 55           //Pit Cobra
        tmpdistance = selfz + 200  //how high?
        tmpturn = selfturn         //what direction should it face?
        tmpx = selfx               //where to spawn x
        tmpy = selfy              //where to spawn y
        SpawnExactCharacterXYZ
        tmpturn = rand
        tmpx = selfx + 200               //where to spawn x
        tmpy = selfy - 150              //where to spawn y
        SpawnExactCharacterXYZ

      //DEFAULT: Mosquito
      tmpx = tmpargument
      tmpy = 50
      IfXIsEqualToY
        tmpx = selfx + 150
        tmpy = selfy + 150
        tmpdistance = selfz + 200
        tmpturn = rand
        SpawnExactCharacterXYZ
        tmpx = selfx - 150
        SpawnExactCharacterXYZ
        tmpy = selfy - 150
        SpawnExactCharacterXYZ
        tmpx = selfx + 150
        SpawnExactCharacterXYZ

      //Move away and randomize
      tmpx = rand % 2550 - 1280 + selfx
      tmpy = rand % 2550 - 1280 + selfy
      Teleport
      tmpargument = 0		        //
      SendMessage		        //
      CleanUp
      
      //Wait long
      tmpargument = 1500
      SetTime
  Else					  // Wander around home position
    tmpx = rand % 5000 - 2500 + selfspawnx   //
    tmpy = rand % 5000 - 2500 + selfspawny   //
  ClearWaypoints			  //
  AddWaypoint				  //
  
End					// Finished with this character
