// Kacelbem, the priest
ON INIT {
 SET £helping_buddy "HUMAN_BASE_0048"
 SET £flee_marker "FLEE_MARKER_0013"
 SET §council 0	// Kacelbem is in council
 SET £friend "kingdom"
 SET §reflection_mode 0
 ACCEPT
}

ON INITEND {
 TWEAK HEAD "human_priest_naked_head"
 TWEAK SKIN "npc_Human_priest_akbaa_body" "npc_Human_priest_kacel_body"
 TWEAK SKIN "npc_Human_priest_akbaa_head" "npc_Human_priest_kacel_head"
 LOADANIM ACTION3 "human_misc_invocation"
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0214
 SETNAME [description_priest]
 ACCEPT
}

ON LOAD {
 USEMESH "human_priest\human_priest.teo"
 ACCEPT
}

ON RELOAD {
  IF (#PLAYER_ON_QUEST == 6) {
    TELEPORT MARKER_0201
    BEHAVIOR NONE
    SETTARGET NONE
    SET §reflection_mode 0
    ACCEPT
  }
  IF (#PLAYER_ON_QUEST == 7) {
    SET §reflection_mode 1
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0214
    ACCEPT
  }
 IF (#PLAYER_ON_QUEST > 2) SETNAME [description_kacelbem]
 ACCEPT
}

ON CHAT {
  IF (^SPEAKING == 1) ACCEPT
  IF (#PLAYER_ON_QUEST < 3) {
    GOSUB START_CHAT
    SPEAK -a [Kacelbem_misc_before_guardian] GOSUB END_CHAT
    ACCEPT
  }
  IF (#PLAYER_ON_QUEST > 2) {
    GOSUB START_CHAT
    SPEAK [Kacelbem_misc_after_guardian] GOSUB END_CHAT
    ACCEPT
  }
 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 -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#


ON REACHEDTARGET {
  IF (^TARGET == MARKER_0214) {
    BEHAVIOR WANDER_AROUND 200
    SETTARGET NONE
    ACCEPT
  }
  IF (^TARGET == MARKER_0201) {
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
    ACCEPT
  }
 ACCEPT
}