// Carlo in city

ON INIT {
 SET £helping_buddy "HUMAN_BASE_0054"
 SET £flee_marker "FLEE_MARKER_0006"
 SET §crypt_done 0
 INVENTORY ADD_FROM_SCENE "KEY_CRYPT_0003"
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0026"
 INVENTORY ADD_FROM_SCENE "note_0025"
 INVENTORY ADDMULTI "Jewelry\Gold_coin\Gold_coin" 43
 INVENTORY ADD "ARMOR\\CHEST_PLATE\\CHEST_PLATE"
 INVENTORY ADD "ARMOR\\LEGGING_CHAIN\\LEGGING_CHAIN"
 INVENTORY ADD "ARMOR\\HELMET_PLATE\\HELMET_PLATE"
 INVENTORY ADD "WEAPONS\\ARROWS\\ARROWS"
 INVENTORY ADD "WEAPONS\\BOW\\BOW"
 SET §reflection_mode 0
 SET §introduce 0		// Used to check Carlo doesn't say the same thing 
 SET £friend "kingdom"
 ACCEPT
}

ON INITEND {
 SET_XP_VALUE 600
 LOADANIM ACTION2 "human_normal_sit_cycle"
 LOADANIM ACTION3 "human_normal_sit_out"
 TWEAK ALL "human_chainmail"
 TWEAK HEAD "human_villager_head2"
 TWEAK SKIN "npc_human_chainmail_body" "npc_human_armoredmail_guard_body"
 SETWEAPON SABRE
 SENDEVENT -ir DURABILITY 100 "95"
 SET_NPC_STAT damages 30
 SET_NPC_STAT aimtime 400
 PLAYANIM -l ACTION2
 SET §frozen 1
 PHYSICAL OFF
 ACCEPT
}

ON RELOAD {
  TELEPORT -i
  IF (#PLAYER_ON_QUEST == 4) OBJECT_HIDE SELF ON
  IF (#PLAYER_ON_QUEST == 5) OBJECT_HIDE SELF OFF
  IF (#PLAYER_ON_QUEST == 6) {
    SET §reflection_mode 0
    OBJECT_HIDE SELF YES
    ACCEPT
  }
  IF (#PLAYER_ON_QUEST == 7) {
    SET §reflection_mode 1
    OBJECT_HIDE SELF NO
    TELEPORT MARKER_0212
    BEHAVIOR WANDER_AROUND 400
    SETTARGET NONE
    ACCEPT
  }
  IF (#PLAYER_ON_QUEST > 2) {
    TELEPORT MARKER_0898
    SET §frozen 0
    PLAYANIM NONE
    BEHAVIOR NONE
    SETTARGET NONE
    PHYSICAL ON
    TIMERpatrol 1 20 GOTO NEXT
    ACCEPT
  } 
 IF (#PLAYER_ON_QUEST > 0) SET §chatpos 1
 IF (#TROLL_QUEST > 0) SET §chatpos 1
 ACCEPT
}

>>NEXT
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0212
 ACCEPT

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0212) {
    BEHAVIOR WANDER_AROUND 200
    SETTARGET NONE
    ACCEPT
  }
 ACCEPT
}

ON COMBINE {
 IF (^SPEAKING == 1) {
   SPEAK -p [player_not_now] NOP
   ACCEPT
 }
 IF (^$PARAM1 == "BOOK_0026") GOTO DIALOGUE_DIARY
 IF (^$PARAM1 ISIN "NOTE_0026NOTE_0027NOTE_0028") GOTO DIALOGUE_DIARY
// IF (^$PARAM1 == "note_0008") GOTO DIALOGUE_DIARY
 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 > 6) {
    GOSUB START_CHAT
    SPEAK [carlo_sorry_no_time_misc] GOSUB END_CHAT
    ACCEPT
  }      
  IF (§chatpos == 0) {
    IF (#TALKED_2ORTIERN_POST == 1) {
      GOTO dialogue1_1
      ACCEPT
    }
	IF (#TALKED_2ORTIERN_CAVE == 1) {
      GOTO dialogue1_1
      ACCEPT
    }
    IF (§introduce == 1) {
      GOSUB START_CHAT
      SPEAK [carlo_sorry_no_time_misc] GOSUB END_CHAT
      ACCEPT
    }   
   GOTO SHORT_INTRODUCE
   ACCEPT
  }
  IF (#need_shield == 1) {
   IF (§crypt_done == 0) {
    GOTO dialogue4_1
    ACCEPT
   }
  }
  IF (#carlo_rituals == 1) GOTO dialogue3_1
  IF (§chatpos == 1) {
    IF (#PLAYER_ON_QUEST > 0) {
      IF (§introduce == 1) {
        SET §chatpos 2
        GOSUB START_CHAT
        SPEAK [carlo_sorry_no_time_misc] GOSUB END_CHAT
        ACCEPT
      }      
     GOTO dialogue2_1
     ACCEPT
    }
   GOSUB START_CHAT
   SPEAK [carlo_find_king_misc] GOSUB END_CHAT
   ACCEPT
  }
  IF (§chatpos == 2) {
    GOSUB START_CHAT
    SPEAK [carlo_sorry_no_time_misc] GOSUB END_CHAT
    ACCEPT
  }
 ACCEPT
}

ON HIDE {
 IF (^$PARAM1 == "HIDE") OBJECT_HIDE SELF OFF
 IF (^$PARAM1 == "SHOW") OBJECT_HIDE SELF ON
 ACCEPT
}

>>SHORT_INTRODUCE
 SET #SHUT_UP 1
 TELEPORT -p MARKER_0144
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 TIMERlookat -m 1 10 PLAYERLOOKAT ME
 GOSUB START_CHAT
 SPEAK [carlo_hello_stranger] GOTO dialogue2_1
 ACCEPT

>>dialogue1_1
 SET #SHUT_UP 1
 SET #CARLO_INTRODUCED 1
 TELEPORT -p MARKER_0144
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 TIMERlookat -m 1 10 GOTO dialogue1_1b
 ACCEPT

>>dialogue1_1b
 PLAYERLOOKAT ME
 SPEAK -pc ZOOM 190 90 190 90 150 140 [player_greetings_carlo] GOTO dialogue1_2
 ACCEPT

>>dialogue1_2
 SETNAME [description_carlo]
 IF (§introduce == 1) GOTO dialogue1_3
 SPEAK -c KEEP [carlo_hello_stranger] GOTO dialogue1_3
 ACCEPT

>>dialogue1_3
 SPEAK -c ZOOM 180 140 180 90 150 150 [carlo_hello_stranger2] GOTO dialogue1_4
 ACCEPT

>>dialogue1_4
 PLAY "system"
 MAPMARKER 169 110 1 [addmarker_human_throne_room]
 HEROSAY [system_map_updated]
 SET §chatpos 1
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET #SHUT_UP 1
 TIMERleave 1 5 GOTO dialogue1_5
 ACCEPT

>>dialogue1_5
 IF (§enemy == 1) ACCEPT
 PHYSICAL ON
 SET §frozen 0
 PLAYANIM -e ACTION3 PLAYANIM WAIT
 TIMERphy 1 4 GOTO GO_AWAY
 ACCEPT

>>GO_AWAY
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0212
 ACCEPT

//// Player has talked to the king ////

>>dialogue2_1
  IF (#TALKED_2ORTIERN > 0) {
   SET #SHUT_UP 1
//   TELEPORT -p MARKER_0144
   SET_PLAYER_CONTROLS OFF
   CINEMASCOPE -s ON
   PLAYER_INTERFACE -s HIDE
   TIMERlookat -m 1 10 PLAYERLOOKAT ME
   GOSUB START_CHAT
  }
 SET #SHUT_UP 1
//   TELEPORT -p MARKER_0144
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 TIMERlookat -m 1 10 PLAYERLOOKAT ME
 GOSUB START_CHAT
 SPEAK -c SIDE_R PLAYER 5 5 90 90 0 [carlo_excuse_me] GOTO dialogue2_2
 ACCEPT

>>dialogue2_2
 SPEAK -pc SIDE_L SELF 5 5 80 80 5 [player_are_the_goblins] GOTO dialogue2_3
 ACCEPT

>>dialogue2_3
 SPEAK -c SIDE_R PLAYER 5 100 90 90 0 [carlo_not_really] GOTO dialogue2_4
 ACCEPT

>>dialogue2_4
 SPEAK -p [player_what_about_ylside] GOTO dialogue2_5
 ACCEPT

>>dialogue2_5
 SPEAK [carlo_know_nothing] GOTO dialogue2_6
 ACCEPT

>>dialogue2_6
 IF (#TALKED_2ORTIERN > 0) SET §chatpos 2
 IF (#TALKED_2ORTIERN == 0) SET §introduce 1
 GOSUB END_CHAT
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 ACCEPT

//// Player knows about the rituals ////

>>dialogue3_1
 GOSUB START_CHAT
 SPEAK -p [player_any_news_misc] SPEAK [carlo_no_am_shaggar] GOSUB END_CHAT
 ACCEPT

//// Player needs to enter the crypt ////

>>dialogue4_1
 TIMERpatrol OFF
 GOSUB START_CHAT
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 SPEAK -p [player_need_enter_crypt] GOTO dialogue4_2
 ACCEPT

>>dialogue4_2
 SET §crypt_done 1
 INVENTORY PLAYERADDFROMSCENE "KEY_CRYPT_0003"
 SPEAK [carlo_here_the_key] GOTO dialogue4_3
 ACCEPT

>>dialogue4_3
 PLAY "system"
 HEROSAY [system_object_received]
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 GOSUB END_CHAT
 TIMERpatrol 1 10 GOTO NEXT
 ACCEPT

//  Player shows Calpale's diary to Carlo  //

>>DIALOGUE_DIARY
 TIMERpatrol OFF
 SET #SHUT_UP 1
 GOSUB START_CHAT
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 PLAYER_LOOKAT SELF
 SPEAK -pc CCCTALKER_R SELF 80 40 [player_carlo_murderer] GOTO DIALOGUE_DIARY02
 ACCEPT

>>DIALOGUE_DIARY02
 SPEAK -c KEEP [carlo_damn] GOTO DIALOGUE_DIARY03
 ACCEPT

>>DIALOGUE_DIARY03
 SPEAK -pc CCCLISTENER_L SELF 40 40 [player_carlo_accusation] GOTO DIALOGUE_DIARY04
 ACCEPT

>>DIALOGUE_DIARY04
 SPEAK -c CCCLISTENER_R PLAYER 40 40 [carlo_yes] GOTO DIALOGUE_DIARY05
 ACCEPT

>>DIALOGUE_DIARY05
 SPEAK -pc CCCTALKER_R SELF 40 40 [player_carlo_best_solution] GOTO DIALOGUE_DIARY06
 ACCEPT

>>DIALOGUE_DIARY06
 SPEAK -c CCCTALKER_L PLAYER 40 40 [carlo_dont_know] GOTO DIALOGUE_DIARY07
 ACCEPT

>>DIALOGUE_DIARY07
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0044
 WORLD_FADE OUT 2500 0 0 0
 SET #carlo_in_jail 1
 TIMERfade 1 3 GOTO FADE_IN
 GOSUB START_CHAT
 ACCEPT

>>FADE_IN
 WORLD_FADE IN 2500
 INVENTORY PLAYERADDFROMSCENE "note_0025"
 PLAY "system"
 HEROSAY [system_object_received]
 QUEST [system_Quest_log_Florence_done]
 HEROSAY [system_questbook_updated]
 ADD_XP 1250
 SET #QUEEN_QUEST 2
 SET #SHUT_UP 0
 OBJECT_HIDE SELF YES
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 DESTROY ME
 ACCEPT
 
ON GAME_READY {
 IF (#carlo_in_jail == 2) DESTROY ME
 ACCEPT
}