// Sister Chinkashh
ON INIT {
 SETSCALE 90
 SET £friend "kingdom"
 INVENTORY ADD "MAGIC\\POTION_MANA\\POTION_MANA"
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0070"
 INVENTORY ADD_FROM_SCENE "bookgreu_0001"
 INVENTORY ADD_FROM_SCENE "RUNE_AAM_0044"
 INVENTORY ADD_FROM_SCENE "RUNE_AAM_0045"
 SET §carlo_rituals 0
 SET §king_slap 1		//attention, cette variable fonctionne a l'envers
 SET §out 0			// Used to know if npc is in room
 SET §talked2greu 0
 SET §talked_krahoz 0
 SET §talked_falan 0
 SET §need_superweapon 0
 SET §dialogue_troll 0
 ACCEPT
}

ON INITEND {
 SETGROUP CINE1
 SET_CONTROLLED_ZONE LIBRARY_ENTER
 ACCEPT
}

ON RELOAD {
  IF (#ALIA_DESTINY > 0) {
    SET §reflection_mode 0
    BEHAVIOR NONE
    SETTARGET NONE
    OBJECT_HIDE SELF ON
    DESTROY SELF
    ACCEPT
  }
  IF (#PLAYER_ON_QUEST == 6) {
    SET §reflection_mode 0
    OBJECT_HIDE SELF ON
    ACCEPT
  }
  IF (#PLAYER_ON_QUEST == 7) {
    SET §reflection_mode 1
    OBJECT_HIDE SELF OFF
    ACCEPT
  }
  IF (#STATUE_TOUCHED > 0) SET §carlo_rituals 1
 ACCEPT
}

//*******************************************************

ON CHANGESTATUS {
  IF (^$PARAM1 == "2") {
    SET §out 1
    TELEPORT MARKER_0311
    SET §reflection_mode 0
    BEHAVIOR FRIENDLY
    SETTARGET human_base_0082 //king
    ACCEPT
  }
  IF (^$PARAM1 == "2end") {
    SET §out 0
    TELEPORT MARKER_0102
    SET §reflection_mode 1 
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER // dans la biblio
    ACCEPT
  }
  IF (^$PARAM1 == "4") { //slap cinematic
    SET §reflection_mode 0
    SET_CONTROLLED_ZONE SNAKE_SLAP
    TELEPORT MARKER_0455
    SET §king_slap 0
    BEHAVIOR FRIENDLY
    SETTARGET human_base_0082 //king
    ACCEPT
  }
  IF (^$PARAM1 == "4end") {
    SET §reflection_mode 1
    UNSET_CONTROLLED_ZONE SNAKE_SLAP
    TELEPORT -i
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER // dans la biblio
    ACCEPT
  }
 ACCEPT
}

//*******************************************************

ON CONTROLLEDZONE_ENTER {
  IF (^$PARAM1 != "PLAYER") ACCEPT
  IF (^$PARAM2 == SNAKE_SLAP) {
    UNSET_CONTROLLED_ZONE SNAKE_SLAP
    IF (§enemy == 0) SENDEVENT CINEMATIC human_base_0082 ""
    ACCEPT
  }
 IF (§out == 1) ACCEPT
 UNSET_CONTROLLED_ZONE LIBRARY_ENTER
 SENDEVENT CLOSE LIGHT_DOOR_0091 ""
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 TELEPORT -p MARKER_0101
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 TIMERlookat -m 1 10 PLAYERLOOKAT SELF
 SETNAME [description_chinkashh]
 SPEAK -c ZOOM 180 10 170 10 250 100 [chinkashh_greetings_player] GOTO CONTROLS_BACK
 ACCEPT
}

>>CONTROLS_BACK
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 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 (^SPEAKING == 1) ACCEPT
  IF (#PLAYER_ON_QUEST > 1) {
    IF (§carlo_rituals == 0) GOTO DIALOGUE1
  }
  IF (§king_slap == 0) GOTO DIALOGUE2
  IF (#PLAYER_ON_QUEST > 4) {
    IF (§talked_krahoz == 0) GOTO DIALOGUE5
  }
>>krahoz_zohark
  IF (#need_superweapon == 1) {
    IF (§need_superweapon == 0) GOTO DIALOGUE4
  }
  IF (#talked2greu == 2) {
    IF (§talked2greu == 0) GOTO DIALOGUE3
  }
  IF (#FALAN_KEY == 1) {
    IF (§talked_falan == 0) GOTO DIALOGUE_FALAN
  }
  IF (#PLAYER_ON_QUEST == 1) {
    IF (#TROLL_QUEST > 0) GOTO LASUITE
    IF (§dialogue_troll == 1) GOTO LASUITE
    GOTO DIALOGUE_TROLL
    ACCEPT
  }
>>LASUITE
 GOSUB START_CHAT
 SPEAK [chinkashh_library_misc] GOSUB END_CHAT
 ACCEPT
}

//*******************************************************

ON CUSTOM {
  IF (^$PARAM1 == "TALK1") {
    SPEAK [chinkashh_council_cant_believe] SENDEVENT CUSTOM HUMAN_BASE_0081 "TALK4" //felnor
    ACCEPT
  }
  IF (^$PARAM1 == "TALK_QUAKE1") {
    SENDEVENT -g CINE1 LOOKME ""
    SPEAK -oc ZOOM 200 280 160 280 200 200 [chinkashh_warmeet2] SENDEVENT CUSTOM HUMAN_BASE_0082 "TALK_QUAKE3" //king
    ACCEPT
  }
  IF (^$PARAM1 == "FALAN") {
    SET §talked_falan 1
    ACCEPT
  }
 ACCEPT
}

//*******************************************************

//  If Carlo has talked about rituals.  //

>>DIALOGUE1
 TELEPORT MARKER_0102
 TELEPORT -p MARKER_0101
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 TIMERlookat -m 1 10 PLAYERLOOKAT SELF
 SET §carlo_rituals 1
 SENDEVENT ACTIVATE CAMERA_0140 ""
 SPEAK -p [player_pentagram_on_floor] GOTO DIALOGUE1_2
 ACCEPT

>>DIALOGUE1_2
 CAMERAACTIVATE NONE
 SPEAK -c ZOOM 200 160 160 160 180 180 [chinkashh_it_protects] GOTO DIALOGUE1_3
 ACCEPT

>>DIALOGUE1_3
 SPEAK -pc ZOOM 170 160 170 160 150 150 [player_what_can_u_tell] GOTO DIALOGUE1_4
 ACCEPT

>>DIALOGUE1_4
 SPEAK -c ZOOM 140 380 140 20 160 160 [chinkashh_these_rituals] GOTO DIALOGUE1_5
 ACCEPT

>>DIALOGUE1_5
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 ACCEPT

//  If player has seen king slaped.  //

>>DIALOGUE2
 TELEPORT MARKER_0102
 SET #SHUT_UP 1
 TELEPORT -p MARKER_0101
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 TIMERlookat -m 1 10 PLAYERLOOKAT SELF
 SET §king_slap 1
 SPEAK -opc SIDE_R SELF 5 5 50 60 5 [player_the_king_earlier] GOTO DIALOGUE2_1
 ACCEPT

>>DIALOGUE2_1
 SPEAK -c SIDE_L PLAYER 5 100 90 90 0 [chinkashh_not_related] GOTO DIALOGUE2_2
 ACCEPT

>>DIALOGUE2_2
 SPEAK -opc KEEP [player_does_king_hold] GOTO DIALOGUE2_3
 ACCEPT

>>DIALOGUE2_3
 SPEAK -c SIDE_L PLAYER 5 5 150 100 0 [chinkashh_the_treaty] GOTO DIALOGUE2_4
 ACCEPT

>>DIALOGUE2_4
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET #SHUT_UP 0
 ACCEPT

//  Player knows about Greu's gift.  //

>>DIALOGUE3
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 PLAYER_LOOKAT SELF
 SET §talked2greu 1
 SPEAK -p [player_book_outside] GOTO DIALOGUE3_1
 ACCEPT

>>DIALOGUE3_1
 SPEAK [chinkashh_sure_book] GOTO DIALOGUE3_2
 ACCEPT

>>DIALOGUE3_2
 INVENTORY PLAYERADDFROMSCENE "bookgreu_0001" 
 PLAY system
 HEROSAY [system_object_received]
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 ACCEPT

//  Player looking for ultimate weapon book.  //
>>DIALOGUE4
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 PLAYER_LOOKAT SELF
 SET §need_superweapon 1
 SPEAK -p [player_book_ultimate_weapon] GOTO DIALOGUE4_2
 ACCEPT

>>DIALOGUE4_2
 SPEAK [chinkashh_sorry_dont] GOTO DIALOGUE4_3
 ACCEPT

>>DIALOGUE4_3
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 ACCEPT

//  Player looking for Krahoz & Zohark.  //
>>DIALOGUE5
 IF (#need_zohark == 2) {
   IF (#need_krahoz == 2) {
     GOTO krahoz_zohark
   }
 } 
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 PLAYER_LOOKAT SELF
 SET §talked_krahoz 1
 SPEAK -p [player_chinkashh_quest09] GOTO DIALOGUE5_2
 ACCEPT

>>DIALOGUE5_2
 SPEAK [chinkashh_quest09] GOTO DIALOGUE5_3
 ACCEPT

>>DIALOGUE5_3
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 ACCEPT

//  Player looking for king of troll.  //

>>DIALOGUE_TROLL
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 PLAYER_LOOKAT SELF
 SPEAK -p [player_chinkashh_quest04] GOTO DIALOGUE_TROLL2
 ACCEPT

>>DIALOGUE_TROLL2
 SET #TROLLPOG_IDed 1
 SPEAK [chinkashh_quest04] GOTO DIALOGUE_TROLL3
 ACCEPT

>>DIALOGUE_TROLL3
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET §dialogue_troll 1
 ACCEPT

//  Player investigating Falan's murder.  //

>>DIALOGUE_FALAN
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 PLAYER_LOOKAT SELF
 SPEAK -p [player_chinkashh_quest05] GOTO DIALOGUE_FALAN2
 ACCEPT

>>DIALOGUE_FALAN2
 SPEAK [chinkashh_quest05] GOTO DIALOGUE_FALAN3
 ACCEPT

>>DIALOGUE_FALAN3
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET §talked_falan 1
 ACCEPT