// City goblin sentry

ON INIT {
 SET £friend "goblin_castle"
 SET §return 0
 SET §care_about_mice 1 
 SET_SPEAK_PITCH 0.88
 ACCEPT
}

ON INITEND {
 SETMOVEMODE WALK
 SETWEAPON SHORT_SWORD
 BEHAVIOR WANDER_AROUND 500
 SETTARGET NONE
 SET £key_carried "Portcullis"
 SET £flee_marker "FLEE_MARKER_0041"
 SET £helping_buddy "GOBLIN_BASE_0046"
 SENDEVENT -ir DURABILITY 100 "23"
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 6
 ACCEPT
}

ON COUNCIL {
 IF (^$PARAM1 == "2") {
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 ACCEPT
}
 TIMER KILL_LOCAL
 SETEVENT CHAT OFF
 PLAYANIM NONE
 BEHAVIOR NONE
 SETTARGET NONE
 TELEPORT MARKER_0825
 TIMERlookat 1 2 BEHAVIOR FRIENDLY SETTARGET GOBLIN_BASE_0042
 ACCEPT
}

ON CUSTOM {
 IF (^$PARAM1 == "thief2") {
    IF (§player_in_sight == 0) ACCEPT   
    SPEAK -o [goblin_thief] SENDEVENT ATTACK_PLAYER SELF ""
    ACCEPT
  }
 IF (^$PARAM1 == "GO") {
  BEHAVIOR MOVE_TO
  SETTARGET MARKER_0431
  ACCEPT
 }
 ACCEPT
}
  ON REACHEDTARGET {
 IF (^TARGET == "MARKER_0431") {
  SET §return 0
  BEHAVIOR WANDER_AROUND 200
  SETTARGET NONE
  TIMERgo 1 5 SETTARGET MARKER_0288
  BEHAVIOR MOVE_TO
  ACCEPT
 }
 IF (^TARGET == "MARKER_0288") {
  IF (§return == 1) SETTARGET MARKER_0431 ACCEPT
  BEHAVIOR WANDER_AROUND 200
  SETTARGET NONE
  TIMERgo 1 5 SETTARGET MARKER_0651
  BEHAVIOR MOVE_TO
  ACCEPT
 }
 IF (^TARGET == "MARKER_0651") {
  //IF (§return == 1)
  SETTARGET MARKER_0288 
  SET §return 1
  ACCEPT
 }
 IF (^TARGET == MARKER_0282) {
  BEHAVIOR WANDER_AROUND 200
  SETTARGET NONE
  TIMERgo 1 5 SETTARGET MARKER_0651
  BEHAVIOR MOVE_TO 
  ACCEPT
 }
 ACCEPT
} 

ON CHAT {
 IF (^SPEAKING == 1) ACCEPT
 GOSUB START_CHAT
 SPEAK [Goblin_generic] GOSUB END_CHAT
 ACCEPT
}

//#behavior

// ---------------------------------------------------------------------------------
// BEHAVIOR INCLUDE START ----------------------------------------------------------
// ---------------------------------------------------------------------------------
>>CLEAR_MICE_TARGET
 // if we care about mice : clear current mice target and listen to other mice
 IF ( §care_about_mice == 1 )
 {
  SET £targeted_mice "NOMOUSE"
  SETGROUP MICECARE // listen to other mice
 }
RETURN

>>SAVE_BEHAVIOR
 TIMERcolplayer OFF 
// to avoid TIMERcolplayer to restore the behavior 1 sec later
 IF (§main_behavior_stacked == 0) 
 {
  IF (§frozen == 1)
  { 
// frozen anim -> wake up !
    SET §frozen 0
    PLAYANIM NONE
    PLAYANIM -2 NONE
    PHYSICAL ON
    COLLISION ON
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
  }
  SET §main_behavior_stacked 1
  HEROSAY -d "STACK"
  BEHAVIOR STACK
 }
 ELSE
 { // behavior already saved : clear mice target if one
  GOSUB CLEAR_MICE_TARGET
 }
RETURN

>>RESTORE_BEHAVIOR
 IF (§main_behavior_stacked == 1) 
 {
  GOSUB CLEAR_MICE_TARGET
  HEROSAY -d "UNSTACK"
  BEHAVIOR UNSTACK
  SET §main_behavior_stacked 0
  RETURN
 }
IF (£init_marker != "NONE")
  { 
   BEHAVIOR MOVE_TO
   SETTARGET -a ~£init_marker~
   SETMOVEMODE WALK
   RETURN
  }
HEROSAY -d "go_home"
BEHAVIOR GO_HOME
SETTARGET PLAYER
RETURN

// ---------------------------------------------------------------------------------
// BEHAVIOR INCLUDE END ------------------------------------------------------------
// ---------------------------------------------------------------------------------

//#
//#LocalChat
// ---------------------------------------------------------------------------------
// LocalChat INCLUDE START ---------------------------------------------------------
// ---------------------------------------------------------------------------------
>>START_CHAT
 // save misc reflection mode
 SET §saved_reflection §reflection_mode
 // no more stupid reflections !
 SET §reflection_mode 0
 // fo not change behavior if frozen
 IF ( §frozen == 1 ) RETURN
 // save behavior (if not saved)
 GOSUB SAVE_BEHAVIOR
 // look at player
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
RETURN

>>END_CHAT
 SET_EVENT COLLIDE_NPC ON
 SET §collided_player 0
 // restor behavior only if not in fighting mode
 IF ( §fighting_mode == 0 )
 {
  // restore misc reflection mode
  SET §reflection_mode §saved_reflection
  // if frozen : don't restore behavior
  IF ( §frozen == 1 ) RETURN
  // restore behavior
  GOSUB RESTORE_BEHAVIOR
 }
RETURN
// ---------------------------------------------------------------------------------
// LocalChat INCLUDE END -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#