ON INIT {
 SET £type "human_guard_kingdom"
 SET £friend "kingdom"
 SET £KEY_CARRIED "portcullis"
 SET §chatpos 1			// In order to be agreessive toward player
 SET §zone 0			// To define what zone he should be controlling
 SET §going_forward 1
 ACCEPT
}

ON INITEND {
 TWEAK SKIN "npc_human_chainmail_body" "npc_human_armoredmail_guard_body"
 TWEAK SKIN "npc_human_chainmail_hero_head" "npc_human_chainmail_guard_head2"
 SET_CONTROLLED_ZONE "FORBIDEN2_IN"
 SET £init_marker "MARKER_0648"
 SENDEVENT -ir DURABILITY 100 "92"
 ACCEPT
}

ON GAME_READY {
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 ACCEPT
}

ON CHANGESTATUS {
  IF (^$PARAM1 == "2") {
    SET §chatpos 0
    UNSET_CONTROLLED_ZONE "FORBIDEN2_IN"
    SENDEVENT CUSTOM HUMAN_BASE_0041 "TAKE_CONTROL"
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0328
    ACCEPT
  }
 ACCEPT
}

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0328) {
    IF (§going_forward == 0) SET §going_forward 1
    SETTARGET MARKER_0106
    ACCEPT
  }
  IF (^TARGET == MARKER_0106) {
    IF (§going_forward == 1) SETTARGET MARKER_0105 ACCEPT
    SETTARGET MARKER_0328  
    ACCEPT
  }
  IF (^TARGET == MARKER_0105) {
    IF (§going_forward == 1) SETTARGET MARKER_0327 ACCEPT
    SETTARGET MARKER_0106
    ACCEPT
  }
  IF (^TARGET == MARKER_0327) {
    SETTARGET MARKER_0105
    IF (§going_forward == 1) SET §going_forward 0
    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 CHAT {
  IF (§enemy == 1) ACCEPT
  IF (^SPEAKING == 1) ACCEPT
  IF (§chatpos == 1) {
    GOSUB START_CHAT
    SPEAK [Human_guard_bedrooms] GOSUB END_CHAT
    ACCEPT
  }
 ACCEPT
}

ON CONTROLLEDZONE_ENTER {
  IF (§enemy == 1) ACCEPT
  IF (^$PARAM1 != PLAYER) ACCEPT
  IF (§zone == 0) {	// the player enter forbiden zone
    SET §zone 1
    UNSET_CONTROLLED_ZONE "FORBIDEN2_IN"
    SET_CONTROLLED_ZONE "FORBIDEN2_OUT"
    SPEAK -a [Human_guard_bedrooms] GOTO THREAT
    ACCEPT
  }
  IF (§zone == 1) {
    SET §zone 0
    UNSET_CONTROLLED_ZONE "FORBIDEN2_OUT"
    SET_CONTROLLED_ZONE "FORBIDEN2_IN"
    TIMERthreat OFF
    TIMERatt OFF
    ACCEPT
  }
 ACCEPT
}

>>THREAT
 TIMERthreat 1 6 GOTO PASCOOL
 ACCEPT

>>PASCOOL
 IF (§zone == 0) ACCEPT
 SPEAK -a [Human_guard_bedrooms_aggressive] TIMERatt 1 3 GOTO PASCOOL2
 ACCEPT

>>PASCOOL2
 IF (§zone == 0) ACCEPT
 SET §zone 3
 SENDEVENT ATTACK_PLAYER SELF ""
 SENDEVENT -g £friend PLAYER_ENEMY ""
 ACCEPT