// Ortiern in Outpost

ON INIT {
 SET §healed 0		// indicates Ortiern has been healed
 SET §helped 0
 SET §dead 0
 SET §debut 0		// Used to check if npc has more than 1 life point
 SET £friend "NONE"
 SET §refuse 0
 ACCEPT
}

ON INITEND {
 SENDEVENT -ir DURABILITY 100 "82"
 SET §reflection_mode 0
 SET_CONTROLLED_ZONE "ORTIERN_ZONE"
 LOADANIM ACTION2 "human_guard_wounded_cycle"
 TWEAK LOWER "human_chainmail"
 TWEAK SKIN "npc_human_chainmail_body" "npc_human_chainmail_guard_body_blood"
 TWEAK SKIN "npc_human_base_hero_head" "npc_human_base_Ortiern_head"
 PHYSICAL OFF
 PLAYANIM -l ACTION2
 SET §frozen 1
 SET §cine 0
 ACCEPT
}

ON RELOAD {
  IF (#PLAYER_ON_QUEST > 4) {
    IF (§dead == 1) ACCEPT
    IF (£friend != "NONE") SETGROUP -r £friend
    SET £friend "NONE"
    DESTROY SELF
    ACCEPT
  }
  IF (#TROLL_QUEST > 1) {
    IF (§dead == 1) GOTO NEWCAPTAIN
	IF (§healed == 1) ACCEPT
    SET §healed 1
    UNSET_CONTROLLED_ZONE "ORTIERN_ZONE"
    IF ( £friend != "NONE" ) SETGROUP -r £friend
    TWEAK SKIN "npc_human_chainmail_guard_body_blood" "npc_human_armoredmail_guard_body"
    SET £friend "human_kingdom"
    SET_GROUP £friend
	SETWEAPON LONG_SWORD_CIPRIAN
    LOADANIM DIE "Human_death"
	LOADANIM WALK "human_normal_walk_guard"
    LOADANIM WAIT "Human_normal_wait"
	PLAYANIM NONE
	TELEPORT MARKER_0480
    BEHAVIOR WANDER_AROUND 300
    SET_NPC_STAT life 50
    SET §debut 1
    PHYSICAL ON
    SETTARGET NONE
    SET §chatpos 1
    SET §frozen 0
    ACCEPT
  }
  IF (#ORTIERN_DEAD_CAVE == 1) {
    DESTROY SELF
    ACCEPT
  }
  IF (#TALKED_2ORTIERN_CAVE == 1) {
    UNSET_CONTROLLED_ZONE "ORTIERN_ZONE"
	SETNAME [description_Ortiern]
	LOADANIM DIE "Human_death"
	LOADANIM WALK "human_kultar_walk_wounded"
    LOADANIM WAIT "human_kultar_wait_wounded"
	PLAYANIM NONE
    ACCEPT
  }
  IF (#TALKED_2ORTIERN_POST == 1) {
    IF (§helped == 0) ACCEPT
	UNSET_CONTROLLED_ZONE "ORTIERN_ZONE"
	LOADANIM DIE "Human_death"
	LOADANIM WALK "human_kultar_walk_wounded"
    LOADANIM WAIT "human_kultar_wait_wounded"
	PLAYANIM NONE
    ACCEPT
  }
  IF (#TALKED_2ORTIERN_POST == 1) {
    IF (§helped == 1) ACCEPT
    UNSET_CONTROLLED_ZONE "ORTIERN_ZONE"
    ACCEPT
  }
  IF (#PLAYER_ON_QUEST == 0) {
    IF (§cinematic_loaded == 1) ACCEPT
    INVENTORY ADDFROMSCENE "gem_dealer_badge_0003"
	SET_NPC_STAT life 1
    LOADANIM DIE "human_guard_wounded_die"
    SET §cinematic_loaded 1
    ACCEPT
  }
 ACCEPT
}

ON GAME_READY {
 SETGORE OFF
 IF (#PLAYER_ON_QUEST > 0) ACCEPT
 IF (§cine == 1) ACCEPT
 CINE -p ylside
 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 DIE {
 SET §dead 1
 SET #ORTIERN_DEAD_POST 1
 ACCEPT
}

ON OUCH {
 IF (§debut == 1) ACCEPT
 FORCEDEATH SELF
 ACCEPT
}

ON CONTROLLEDZONE_ENTER {
 IF (^$PARAM1 != PLAYER) ACCEPT
 UNSET_CONTROLLED_ZONE ORTIERN_ZONE
 SENDEVENT URDEAD HUMAN_BASE_0076 ""
 SET #SHUT_UP 1
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 SENDEVENT CINEMATIC CAMERA_0085 "START"
 SETNAME [description_Ortiern]
 SPEAK -o [Ortiern_welcome] SENDEVENT CINEMATIC CAMERA_0085 "ANSWER"
 ACCEPT
}

ON CHAT {
  IF (^SPEAKING == 1) ACCEPT
  IF (§enemy == 1) ACCEPT
  IF (§chatpos == 0) {
    SPEAK [Ortiern_repeat_briefing] NOP
    REFUSE
  }
  IF (§chatpos == 1) {
    GOSUB START_CHAT
    SPEAK [Ortiern_misc_hi] GOSUB END_CHAT
    REFUSE
  }
  IF (§chatpos == 2) {
    GOSUB START_CHAT
    SPEAK [Human_guard_hello_to_others] GOSUB END_CHAT
    REFUSE
  }
 ACCEPT
}

ON COMBINE {
 IF (^$PARAM1 ISCLASS POTION_LIFE) {
  IF (§helped == 1) ACCEPT
  SENDEVENT EMPTY ^$PARAM1 ""
  SPELLCAST -msf 1 HEAL HUMAN_BASE_0030
  SET §helped 1
  SPEAK [Ortiern_misc_hi2] NOP
  ADD_XP 80
  ACCEPT
 }
 ACCEPT
}

ON CUSTOM {
  IF (^$PARAM1 == "TALK01") {
    SPEAK [Ortiern_briefing1] SENDEVENT CUSTOM CAMERA_0088 "TALK01"
    ACCEPT
  }
  IF (^$PARAM1 == "TALK02") {
    WORLDFADE OUT 800 0 0 0
    SET §cine 1
    TIMERcine -m 1 800 CINE ylside
    ACCEPT
  }
  IF (^$PARAM1 == "TALK03") {
    SPEAK [Ortiern_briefing3] SENDEVENT CUSTOM CAMERA_0091 "TALK03"
    ACCEPT
  }
  IF (^$PARAM1 == "TALK04") {
    SPEAK [Ortiern_briefing4] SENDEVENT CUSTOM CAMERA_0091 "TALK04"
    ACCEPT
  }
  IF (^$PARAM1 == "TALK05") {
    SPEAK [Ortiern_briefing5] SENDEVENT CUSTOM CAMERA_0091 "TALK05"
    ACCEPT
  }
  IF (^$PARAM1 == "TALK06") {
    SPEAK [Ortiern_briefing6] GOTO NEXT_STEP 
    ACCEPT
  }
  IF (^$PARAM1 == "ATTACK_YLSIDE") {
    SET §refuse 1
    SETEVENT CHAT OFF
    WEAPON ON
    BEHAVIOR -f MOVE_TO
    SETTARGET -a HUMAN_BASE_0069
    SETMOVEMODE RUN
    ACCEPT
  }
 ACCEPT
}

>>NEXT_STEP
 SET #TALKED_2ORTIERN_POST 1
 IF (^DEMO == 1) {
   GOTO NEXT_STEP_BIS
   ACCEPT
 }
 SENDEVENT CUSTOM CAMERA_0090 "END" 
 MAPMARKER 276 390 3 [addmarker_human_access]
 HEROSAY [system_map_updated]
 INVENTORY PLAYERADDFROMSCENE "gem_dealer_badge_0003" 
 HEROSAY [system_object_received]
 SET #SHUT_UP 0
 ACCEPT

>>NEXT_STEP_BIS
 SENDEVENT CUSTOM CAMERA_0090 "END" 
 MAPMARKER 348 22 1 [addmarker_human_access]
 HEROSAY [system_map_updated]
 INVENTORY PLAYERADDFROMSCENE "gem_dealer_badge_0003" 
 HEROSAY [system_object_received]
 SET #SHUT_UP 0
 ACCEPT

ON CINE_END {
 IF (#PLAYER_ON_QUEST > 1) ACCEPT
 WORLDFADE IN 800
 SENDEVENT CUSTOM CAMERA_0091 "TALK02"
 ACCEPT
}

ON COLLIDE_NPC {
 IF (§refuse == 1) REFUSE
 ACCEPT
}

ON TARGET_DEATH {
  IF (^SENDER == "HUMAN_BASE_0069") {
    SET §refuse 0
    SETEVENT CHAT ON
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0480
    ACCEPT
  }
 ACCEPT
}

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0480) {
    BEHAVIOR WANDER_AROUND 300
    SETTARGET NONE
    ACCEPT
  }
 ACCEPT
}

>>NEWCAPTAIN
 REVIVE
 TWEAK HEAD "human_kultar"
 TWEAK LOWER "human_chainmail"
 TWEAK SKIN "npc_human_base_kultar_head" "npc_human_cm_hero_head"
 TWEAK SKIN "npc_human_chainmail_body" "npc_human_armoredmail_guard_body"
 UNSET_CONTROLLED_ZONE "ORTIERN_ZONE"
 IF ( £friend != "NONE" ) SETGROUP -r £friend
 SET £friend "human_kingdom"
 SET_GROUP £friend
 SETNAME [description_captain]
 SETWEAPON LONG_SWORD_CIPRIAN
 LOADANIM DIE "Human_death"
 LOADANIM WALK "human_normal_walk_guard"
 LOADANIM WAIT "Human_normal_wait"
 PLAYANIM NONE
 TELEPORT MARKER_0480
 BEHAVIOR WANDER_AROUND 300
 SET_NPC_STAT life 50
 SET §debut 1
 PHYSICAL ON
 SETEVENT CHAT ON
 SETTARGET NONE
 SET §chatpos 2
 SET §frozen 0
 ACCEPT