ON INIT {
 SET £type goblin_lord
 SET §chatpos 4
 SET £friend "goblin_castle"
 SET £key_carried "Portcullis" 
 SET §fireb 0
 SET §firea 0
 SET_SPEAK_PITCH 1.1
 SETCONTROLLEDZONE FIRETORCH
 SET §fire_angry 0
 SET §first 0
 ACCEPT
}
ON INITEND {
 SET £flee_marker "FLEE_MARKER_0045"
 SET £helping_buddy "GOBLIN_BASE_0035"
 SENDEVENT -ir DURABILITY 100 "39"
 SENDEVENT -ir DURABILITY_ARMOR 100 "42"
 INVENTORY ADD "PROVISIONS\\ROPE\\ROPE"
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 7
 SETWEAPON short_sword
 SET_NPC_STAT damages 8
 ACCEPT
}
ON LOAD {
 USE_MESH "Goblin_lord\\Goblin_lord.teo"
 ACCEPT
}
ON RELOAD {
 SET §fire_angry 0
 ACCEPT
}
ON CONTROLLEDZONE_ENTER {
 IF (§enemy == 1) UNSET_CONTROLLED_ZONE FIRETORCH ACCEPT
 IF (^$PARAM1 == PLAYER) {
  UNSET_CONTROLLED_ZONE FIRETORCH
  SENDEVENT CUSTOM SELF "LIGHT_FIRE1"
  SENDEVENT CUSTOM SELF "LIGHT_FIRE2"
  ACCEPT
 }
 ACCEPT
} 
ON CHAT {
 IF (§enemy == 1) ACCEPT
 IF (^SPEAKING == 1) ACCEPT
  GOSUB START_CHAT
  SPEAK [Goblinlord_warning] GOSUB END_CHAT
 ACCEPT
}

ON CUSTOM {
IF (^$PARAM1 == "Attak_me") {
  BEHAVIOR STACK
  SETEVENT CHAT OFF
  BEHAVIOR -f Move_to
  SETTARGET Goblin_base_0017
  SET §reflection_mode 0
  ACCEPT
 }
 IF (^$PARAM1 == "Stop_attak") {
  BEHAVIOR UNSTACK
  SETEVENT CHAT OFF
  SET §reflection_mode 1
  ACCEPT
 }
 IF (^$PARAM1 == "LIGHT_FIRE1") GOTO LIGHT_FIRE1
 IF (^$PARAM1 == "LIGHT_FIRE2") GOTO LIGHT_FIRE2
 ACCEPT
}
ON REACHEDTARGET {
 IF (^TARGET == NONE) ACCEPT
 IF (^TARGET == MARKER_0651) {
  BEHAVIOR FRIENDLY
  SETTARGET MARKER_0217
  SPELLCAST -SMF 1 IGNIT MARKER_0651  
  TIMERgo 1 1 GOTO WANDER
  ACCEPT
 }
 IF (^TARGET == MARKER_0652) {
  BEHAVIOR FRIENDLY
  SETTARGET MARKER_0218
  SPELLCAST -SMF 1 IGNIT MARKER_0652  
  TIMERgo 1 1 GOTO WANDER
  ACCEPT
 }
 IF (^TARGET == MARKER_0653) {
  SETEVENT CHAT ON
  FORCEANGLE 270
  BEHAVIOR -a FRIENDLY
  SETTARGET PLAYER
  ACCEPT
 }
 ACCEPT
}


>>WANDER
 IF (§fireb == 1) SET §fireb 0
 IF (§firea == 1) SET §firea 0
 IF (§fireb == 2) {
  SET §fireb 1
  BEHAVIOR MOVE_TO
  SETTARGET MARKER_0652
  ACCEPT
 }
 IF (§firea == 2) {
  SET §firea 1
  BEHAVIOR MOVE_TO
  SETTARGET MARKER_0651
  ACCEPT
 }
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0653
ACCEPT



>>LIGHT_FIRE1
IF (§fire_angry == 2) {
 SPEAK [Goblinlord_warning] SENDEVENT ATTACK_PLAYER SELF ""
 ACCEPT
}
IF (§enemy == 1) ACCEPT
IF (§firea != 0) ACCEPT
IF (§fireb >= 1) {
 SET §firea 2 
 ACCEPT
}
SETEVENT CHAT OFF
SET §firea 1
SPEAK [Goblinlord_warning] NOP
BEHAVIOR MOVE_TO
SETTARGET MARKER_0651
IF (§first == 1) INC §fire_angry 1
SET §first 1
ACCEPT

>>LIGHT_FIRE2
IF (§fire_angry == 2) {
 SPEAK [Goblinlord_warning] SENDEVENT ATTACK_PLAYER SELF ""
 ACCEPT
}
IF (§enemy == 1) ACCEPT
IF (§fireb != 0) ACCEPT
IF (§firea => 1) SET §fireb 2 ACCEPT
SETEVENT CHAT OFF
SET §fireb 1
SPEAK [Goblinlord_warning] NOP
BEHAVIOR MOVE_TO
SETTARGET MARKER_0652
INC §fire_angry 1
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 {
 INVENTORY ADD "ARMOR\\HELMET_CHAIN\\HELMET_CHAIN"
  ACCEPT
 }