/*

A note on SHOUT in BG1

Basically, it's really dangerous. Nearly a thousand creatures have it, and it's indiscriminately given to hostiles and to innocents.
BD hacks around this by using alignment as a de facto SPECIFICS.

We handle it in a more principled way by:

- mapping lots of the users of SHOUT onto their own bespoke scripts
- mapping all the remainder, who are people like city guards and merchants, onto a non-specific-keyed help script with a bespoke shout code (119).
- giving 57 as the bespoke Shout shout code
- creating a new innocents-only shout, that responds both to 119 and to 57.
- setting original SHOUT so that it's harmless in any case if a few residual innocents have it

*/

DEFINE_ACTION_FUNCTION help BEGIN

        LAF define_difficulty STR_VAR type=genai RET difficulty_variable END
        LAF build_core_scripts END
        ACTION_IF is_bg1 BEGIN
           LAF install_bg1_help END
           LAF change_other_scripts_BG1 END
        END
        ACTION_IF is_bg2 BEGIN
           LAF change_other_scripts_BG2 END
        END
        LAF innocents_flee END

END

/////////////////////////////////////////////////////////////////////////////////
///   Construct the 100%-help scripts
////////////////////////////////////////////////////////////////////////////////

DEFINE_ACTION_FUNCTION build_core_scripts
BEGIN
  // default scripts

  LAF make_help_script INT_VAR first=57 second=99 STR_VAR normal= ~%tutu_var%shout~ moron=dw#shtmo  END
  LAF make_help_script INT_VAR first=89 second=189 STR_VAR normal=gensht01 moron=dw#genmo  END
  LAF make_help_script INT_VAR first=119 second=129 STR_VAR normal=dw#urbhl END // for guards, innocents who can fight, urbanites etc. Shares help code with Innocent help block
  // standard groupcheck-making scripts - include whining
  LAF make_help_script INT_VAR first=151 second=251 whiner=1 STR_VAR normal=gpshout groupcheck="InMyGroup(LastHeardBy(Myself))" END
  COPY_EXISTING ~gpshout.bcs~ ~override/grpsht01.bcs~
  // non-whining versions of gpshout
  LAF make_help_script INT_VAR first=151 second=251 STR_VAR normal=dw#gpsht moron=dw#gpshm groupcheck="InMyGroup(LastHeardBy(Myself))" END
  // a propagating, whining script that checks groups
  LAF make_help_script INT_VAR first=151 second=151 whiner=1 STR_VAR normal=dw#prshw groupcheck="InMyGroup(LastHeardBy(Myself))" END
  // a propagating, non-whining script that checks groups
  LAF make_help_script INT_VAR first=151 second=151 whiner=0 STR_VAR normal=dw#prsht groupcheck="InMyGroup(LastHeardBy(Myself))" END

  // some specific BG2 scripts
  ACTION_IF is_bg2 BEGIN
     LAF make_help_script INT_VAR first=125 second=225 whiner=1 STR_VAR normal=dw#gphlp groupcheck="InMyGroup(LastHeardBy(Myself))" END
     LAF make_help_script INT_VAR first=115 second=215 whiner=1 STR_VAR normal=gp115 END
     LAF make_help_script INT_VAR first=116 second=216 whiner=1 STR_VAR normal=gp116 END
     LAF make_help_script INT_VAR first=101 second=201 whiner=1 STR_VAR normal=genshtja END
     LAF make_help_script INT_VAR first=199 second=299 STR_VAR normal=drdsht01 END
  END
  // the "macshout" script used in EasyTutu
  ACTION_IF is_tutu BEGIN
     LAF make_help_script INT_VAR first=272 second=273 STR_VAR normal=macshout END
  END



END

/////////////////////////////////////////////////////////////////////////////////
///   Script-assembly program
////////////////////////////////////////////////////////////////////////////////


DEFINE_ACTION_FUNCTION make_help_script
     INT_VAR first=60
             second=160
             whiner=0
     STR_VAR normal=""
             moron=""
             groupcheck=""
BEGIN
     OUTER_SPRINT variables ~666=%first%&777=%second%&groupcheck=%groupcheck%~
     ACTION_IF whiner=1 BEGIN
        OUTER_SPRINT variables ~%variables%&IsWhiner=True~
     END
     ACTION_IF ~%normal%~ STRING_COMPARE ~~ BEGIN
        LAF ssl_to_bcs STR_VAR script="help=>%normal%" variables location= ~ssl~ END
     END
     ACTION_IF ~%moron%~ STRING_COMPARE ~~ BEGIN
         LAF ssl_to_bcs STR_VAR script="help=>%moron%" variables= ~%variables%&NoPropagation=true~ location= ~ssl~ END
     END
END

/////////////////////////////////////////////////////////////////////////////////
///   Systematic assignment of scripts in BG1
////////////////////////////////////////////////////////////////////////////////

DEFINE_ACTION_FUNCTION install_bg1_help BEGIN


// creatures with no need of a help script

   ACTION_FOR_EACH creature IN
        deadban golemf golemf2 fgolem deadban
        gsarch01 gsarch02 elmins hunter fahrin
        phanda torlob arkion borda drelik
        narcil brage carsa degrod faizah vail
        jenkal meilum achen osmadi rance
        cailan galtok gorion3 hafiz halftr
        laskal mrshade repman "%tutu_scriptg%sarch01" "%tutu_scriptg%sarch02"
   BEGIN
      LAF swap_text INT_VAR allow_missing=1 STR_VAR file="%creature%.cre" swaps="shout=>null" END
   END


// Level 1 innocents (no specific)

   LAF install STR_VAR file="dw#innhl.baf" location=baf END
   
   COPY_EXISTING_REGEXP GLOB ".*\.cre" override
      PATCH_TRY
         READ_BYTE 0x273 class
         READ_BYTE 0x234 level
         PATCH_IF (class=155 && level<=1 && INDEX_BUFFER ("shout") >=0) BEGIN

              FOR (i=0x248;i<0x270;i+=8) BEGIN
                 READ_ASCII i script
                 PATCH_IF "%script%" STRING_EQUAL_CASE "shout" BEGIN
                    WRITE_ASCIIE i "dw#innhl"
				 END

			  END
		 END
	  WITH DEFAULT
	 			LPF regexp_warning STR_VAR parent=install_bg1_help END
	  END
    BUT_ONLY

// guards and good guys (no specific)


   LAF edit_creature INT_VAR allow_missing=1 tv=1 STR_VAR creature=~alvanh alyth bardol blane bork crew1 crew2 crew3 crew4 crew5 crew6 crew7 delthy
     gandol halfen halfen2 kieres liia lobar nalin beland belt bill bouncer
     brandi brathl caedmo chimp5 cowh flam flamang flame  flamsco flamwiz
     ffhunt1 ffhunt2 ffhunt3 ffsleep flam10 flam11 flam12 flam2 flam4 flam5 flam5a
     flam5b flam6 flam7 flam8 flam9 flamal  flamc7 flame1
     flame2 flame3 flame4 flamen flamen2 flamgate flamgg flamhusb flampun flamvai
     wasleep watch watch2 watch6 watch9 watchm watchn watchn2 watchn3
     digger bran laryss ivanne
     calaha arkush brage2 ffhunt flam13 housen housen2 housg1 housg2 housg3 housg4
     housg5 housg6 jamie joia jonavi kent laola lowlgu merchg poghm9 watch3
     gantol jardak hick benjy fenten fergus sorrel svlast vai pallon husam2
     elkart fafight friend galile halbaz erdane silvgu agnasi amnis amnis2 amnis3 
     amnis3a amnis3b amnis4 amnise amnise2 amnise3 amnise4 amnise5 amsleep aoln
     arkani3 avery bellam bentan bently berrun bheren bjorni cadder chanth dandal 
     deder3 delsvir dreppi dreppi2 dushai elmin1 emerso fenwic fuller fuller2 furnel 
     gatewa gatewa2 gaxir gazib gellan gerde guarbe guarca guard gurke hentol hull 
     hull2 hurgan landri monk monkd2 monkde monken oopah oublek permid pgond phlydi2 
     poghm10 poghm3 poghm6 poghm8 poghma poghma3 poghma4 poghma5 poghma6 poghma7 
     poghma8 priilm reevor reevor2 sailfin sailjos shaell taerom tamah ulraun unshey 
     verlin volo willia~
     editstring="strip_script=>%tutu_var%shout insert_script_high=>dw#urbhl"
   END


   LAF edit_creature INT_VAR allow_missing=1 STR_VAR creature="%tutu_scriptf%lampun2 %tutu_scriptf%lambrid digger_a digger_b digger_c digger_d digger_e" editstring="strip_script=>%tutu_var%shout insert_script_high=>dw#urbhl" END
   LAF edit_creature INT_VAR tv=1 allow_missing=1 STR_VAR creature="xzar xzar2 xzar4 xzar6 montar montar2 montar4 montar6 khalid khalid2 khalid4 khalid6 jaheir jaheir2 jaheir4 jaheir6 rasaad rasaad2 rasaad4 rasaad6" editstring="strip_script=>%tutu_var%shout insert_script_second=>dw#urbhl" END


// undead (specific=70)

   LAF edit_creature INT_VAR tv=1 STR_VAR creature=~ghoul ghast iskelet skelet skelets zombie~ editstring=~insert_script_high=>dw#gpshm specifics=>70~ END
   LAF edit_creature STR_VAR creature= ~%bg1_skeleton_warrior% %bg1_skeleton_warrior2% %bg1_skeleton_warrior3% %tutu_scripts%kelet_a
                                                       %tutu_scripts%kelet_b %tutu_scripts%kelet_c %tutu_scripts%kelet03
                                                       %tutu_scriptz%ombie_a %tutu_scriptz%ombie_b %tutu_scriptz%ombie_c
                                                       %tutu_scriptz%ombie_d %tutu_scriptz%ombie_e %tutu_scriptg%houllor~
                             editstring=~strip_script=>dw#gpshm insert_script_high=>dw#gpshm specifics=>70~
   END

// gnolls (specific=71)

    LAF edit_creature INT_VAR tv=1 STR_VAR creature=~britik flind gnoll gnoll_a gnoll_b gnoll_c gnoll_d gnoll_e ingot~
                              editstring= ~strip_script=>"%tutu_var%shout %tutu_var%gnollf dw#gpsht" insert_script_high=>dw#gpsht specifics=>71~
    END
    LAF edit_creature STR_VAR creature= ~%tutu_scriptg%nollper~
                              editstring= ~strip_script=>"%tutu_var%gnollf dw#gpsht" insert_script_high=>dw#gpsht specifics=>71~
    END

// hobgoblins (specific=72)

    LAF edit_creature INT_VAR tv=1 STR_VAR creature=~geltik malkax bhobgob hobgob hobjoia zargal baruk hakt ihobgob hobgo5 nevill~
                              editstring= ~strip_script=>"%tutu_var%shout %tutu_var%hobgobf %tutu_var%hobgoba" insert_script_high=>dw#gpsht specifics=>72~
    END
    LAF edit_creature STR_VAR creature= ~%tutu_var%hobgoba %tutu_scripth%obelite %tutu_scripth%obgob_a %tutu_scripth%obgob_b %tutu_scripth%obgob_c %tutu_scripth%obgob_d %tutu_scripth%obgob_e 
                                                        %tutu_scripth%obelite %tutu_scripth%obgoa_a %tutu_scripth%obgoa_b %tutu_scripth%obgoa_c %tutu_scripth%obgoa_d %tutu_scripth%obgoa_e
                                                        %tutu_scripth%obgzhur~
                              editstring= ~strip_script=>"%tutu_var%hobgobf %tutu_var%hobgoba dw#gpsht" insert_script_high=>dw#gpsht specifics=>72~
    END

// kobolds (specific=73)

    LAF edit_creature INT_VAR tv=1 STR_VAR creature=~ikobold kobcomm kobold kobold3 kobold7 kobolda darryl darryl2 larry~
                              editstring= ~strip_script=>"%tutu_var%kobolda %tutu_var%shout %tutu_var%koboldf dw#gpsht" insert_script_high=>dw#gpsht specifics=>73~
    END
    ACTION_FOR_EACH suffix IN  ~_A~ ~_B~ ~_C~ ~_D~ ~_E~ ~AL~ ~FL~ BEGIN
      LAF edit_creature STR_VAR creature= ~%tutu_scriptk%obold%suffix%~
                              editstring= ~strip_script=>"%tutu_var%kobolda %tutu_var%koboldf dw#gpsht" insert_script_high=>dw#gpsht specifics=>73~
      END
    END
    ACTION_FOR_EACH suffix IN  ~_A~ ~_B~ ~_C~ ~_D~ ~_E~ BEGIN
      LAF edit_creature STR_VAR creature= ~%tutu_scriptk%obola%suffix%~
                              editstring= ~strip_script=>"%tutu_var%kobolda %tutu_var%koboldf dw#gpsht" insert_script_high=>dw#gpsht specifics=>73~
      END
    END
    
    // kobolds need combat scripts (if GENAI not installed)
    
    LAF check_label STR_VAR label=dw#genai RET value=value END
    ACTION_IF !value BEGIN
      LAF edit_creature STR_VAR creature= ~%tutu_var%kobold3 %tutu_var%kobold7 %tutu_scriptk%obold_a %tutu_scriptk%obold_b %tutu_scriptk%obold_c %tutu_scriptk%obold_d %tutu_scriptk%obold_e~
                                editstring=~strip_script=>wtasight insert_script_low=>%tutu_scriptw%tasight~
      END

    END



// gibberlings (specific=74)

    COPY_EXISTING ~dw#gpshm.bcs~ ~override/%tutu_var%gibber.bcs~

// basilisks (specific=75)

    LAF edit_creature STR_VAR creature= ~%tutu_var%basilg %tutu_scriptbg%basill %tutu_scriptb%asilmut %tutu_var%mutami~
                              editstring=~strip_script=>"dw#gpshm %tutu_var%shout" insert_script_high=>dw#gpshm specifics=>75~
    END
                              
// wyverns (specific=76)

    LAF edit_creature INT_VAR tv=1 STR_VAR creature=~wyvern wyverba coksmth~ editstring=~strip_script=>dw#gpshm strip_script=>%tutu_var%shout insert_script_high=>dw#gpshm specifics=>76~ END

// tasloi (specific=77)

    LAF edit_creature INT_VAR tv=1 STR_VAR creature=tasloi editstring=~strip_script=>dw#gpsht insert_script_high=>dw#gpsht specifics=>77~ END

// spiders (specific=78)

    LAF edit_creature INT_VAR tv=1 STR_VAR creature=~spidgi spidhu spidsw spidwr etterc etterc1 spidph~
                              editstring=~strip_script=>dw#gpshm insert_script_high=>dw#gpshm specifics=>78~
    END
    LAF edit_creature STR_VAR creature= ~%tutu_scripts%pidland %tutu_scripts%pidphas~
                              editstring=~strip_script=>dw#gpshm insert_script_high=>dw#gpshm specifics=>78~
    END

// wolves (specifics=79)

    LAF edit_creature INT_VAR tv=1 STR_VAR creature=~worg wolfdi wolfdr wolfva worgar~
                              editstring=~strip_script=>dw#gpshm insert_script_high=>dw#gpshm specifics=>79~
    END
    LAF edit_creature STR_VAR creature= ~%tutu_scriptbg%wolf~
                              editstring=~strip_script=>dw#gpshm insert_script_high=>dw#gpshm specifics=>79~
    END

// ogres (specifics=80)

    LAF edit_creature STR_VAR creature= ~%tutu_var%ogre %tutu_var%ogre02 %tutu_scripto%greberz %tutu_scripto%grebjor
                                                        %tutu_scripto%gremiri %tutu_var%ogregr %tutu_scripto%gregr_b %tutu_scripto%gregr_c
                                                        %tutu_scripto%gregr_d %tutu_var%ogreha %tutu_scripto%greha_b %tutu_var%arghai %tutu_scripto%grema02~
                              editstring=~strip_script=>dw#gpsht insert_script_high=>dw#gpsht specifics=>80~
    END
    LAF edit_creature STR_VAR creature= ~%tutu_var%ogres~ editstring=~strip_script=>dw#gpsht strip_script=>%tutu_var%ogres insert_script_high=>dw#gpsht insert_script_high=>%tutu_var%ogres~ END
    
// carrion crawlers (specifics=81)

    LAF edit_creature INT_VAR tv=1 STR_VAR creature=carrio editstring=~strip_script=>dw#gpshm insert_script_high=>dw#gpshm specifics=>81~ END

// werewolves (specifics=82)

    LAF edit_creature STR_VAR creature= ~%tutu_scriptd%aesewlf %tutu_var%werewo~
                              editstring=~strip_script=>dw#gpsht insert_script_high=>dw#gpsht specifics=>82~
    END
    
// wolfweres (specifics=83)

   LAF edit_creature STR_VAR creature= ~%tutu_var%wolfwe %tutu_scriptw%olfwegl %tutu_scriptw%olfwegr %tutu_var%daese %tutu_scriptd%aesewlf~
                              editstring=~strip_script=>dw#gpsht  strip_script=>%tutu_var%shout insert_script_high=>dw#gpsht specifics=>83~
    END

// xvarts (specifics=84; propagates (because of village)

   LAF edit_creature INT_VAR tv=1 STR_VAR creature=~xvart ursa ixvart nexlit xvart2 xvart_a xvart_b xvart_c~ editstring=~strip_script=>dw#prsht insert_script_high=>dw#prsht specifics=>84~ END
   LAF edit_creature STR_VAR creature=~xvartsu~ editstring=~strip_script=>dw#prsht insert_script_high=>dw#prsht specifics=>84~ END

// bandits in camp (specifics=85; propagates; some gnoll bandits only present on EE install)

   LAF edit_creature INT_VAR tv=1 allow_missing=1 STR_VAR creature=~bhobgob hobgobc bandcr credus taugos glart ardeno banditc britik venkt raemon hakt tersus knott flindb gnoll_bb gnoll_eb~ editstring= ~strip_script=>"dw#prsht %tutu_var%shout" insert_script_high=>dw#prsht specifics=>85~ END

// Kelddath and sirines (specifics=86)

   LAF edit_creature STR_VAR creature= ~%tutu_scripts%irine02 %tutu_var%keldda %tutu_var%islsir %tutu_var%sirine %tutu_scripts%irine_a %tutu_scripts%irine_b~
                              editstring=~strip_script=>"%tutu_var%shout dw#gpsht" insert_script_high=>dw#gpsht specifics=>86~
    END

//  The cultists (specifics=87)

   LAF edit_creature INT_VAR tv=1 STR_VAR creature=~cult1 cult2 cult3 cultt1 cultt2 cultt3 cultt4 cultd1 cultd2 cultd3 cultd4 cultd5 cultd6 tracea~
                             editstring=~strip_script=>"%tutu_var%shout cultsht macshout dw#gpsht" insert_script_high=>dw#gpsht specifics=>87~
   END

// dogs (specifics=88)

   LAF edit_creature INT_VAR tv=1 STR_VAR creature=~dogwa dogwi~
                             editstring=~strip_script=>dw#gpshm insert_script_high=>dw#gpshm specifics=>88~
   END

// slythe and krystin (specifics=89)

   LAF edit_creature INT_VAR tv=1 STR_VAR creature=~slythe krysti~
                             editstring=~strip_script=>dw#gpsht insert_script_high=>dw#gpsht specifics=>89~
   END

// Iron Throne, and other bandits (specifics=90)

   LAF edit_creature INT_VAR tv=1 allow_missing=1 STR_VAR
           creature=~brunos rielta tuth kestor aasim alai diyab kysus tazok2 zhalim iron10 iron11
                     iron12 iron13 iron14 iron2 iron3 iron4 iron5 iron6 iron7 iron8 iron9 ironho irongu irongu01 
                     ironme ironm2 ironm3 ironm4 bandit bandita bandic hareis
                     bandcap bandit2 bandit3 bandit4  rahvin gorf wudei haseo shaldr carsto gardus
                     naaman drasus rezdan gentho natash prat sakul bor tam billy canto dribbe teynga jemby zekar
                     nortua emitar3 lakada kaless destus teven tralit gregor dhania dratan pangwa~
           editstring=~strip_script=>"dw#gpsht %tutu_var%shout" insert_script_high=>dw#gpsht specifics=>90~
   END
   
   LAF edit_creature INT_VAR allow_missing=1 STR_VAR 
                             creature="%tutu_scriptb%anditcy %tutu_scripti%rongu02 %tutu_scripti%rongu03 %tutu_scripti%ronguar %tutu_scripti%ronelit"
                             editstring=~strip_script=>"dw#gpsht %tutu_var%shout" insert_script_high=>dw#gpsht specifics=>90~
   END

// misc groups, mutually isolated (specifics=91)
 OUTER_SPRINT editstring ~strip_script=>"dw#gpsht %tutu_var%shout" insert_script_high=>dw#gpsht specifics=>91~
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="vax zal" editstring END // pair of assassins in AR5300
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="alexan delgod sendai%eet_var%" editstring END // amnish adventurers in AR5300
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="denak brenda lasala diana" editstring END // red wizards
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="niemai oulam wheber william" editstring END // Zhentarim necromancers
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="molkar morvin drakar halaca" editstring END // dwarf/gnome assassins
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="lamalh zeela telka maneir" editstring END // amazon assassins
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="bassil zombieb skeletb" editstring END // Bassilus and his undead
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="leaggu1 leaggu2 leaggu3 leaggu4 leaggu5 leaggu6 leaggu7 ulf" editstring END // counting house guards
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="sewerf1 sewerf2 sewerf3 sewerf4 sewerf5 schlum shvert" editstring END // sewerfolk
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="sunin joular maka" editstring END // Sunin's flunkies
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="wiven dirk meakin sath" editstring END // Wiven's flunkies
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="peter kirian lindin baerin" editstring END // Kirian's group
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="tazok2 galdor semaj sarevo" editstring END // final group
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="tenya2 pumberl pumber2 jalant" editstring END // umberlee priests
 LAF edit_creature INT_VAR allow_missing=1 tv=1 STR_VAR creature="aldeth hunter1 hunter2" editstring END // Aldeth and (on BGEE) his hunters
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="gretek pargus wilf nader arlin catura" editstring END // Maulers of Undermountain
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="caldo krumm" editstring END // dryad-molesters
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="delorn ithmee helsha"  editstring END // skyship sorceresses
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="nestor cavene" editstring END // skyship sorceresses
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="gnarl hairto" editstring END // gnarl and hairtooth
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="taxek michae" editstring END // random thieves
 LAF edit_creature INT_VAR tv=1 STR_VAR creature="doomdur"  editstring END // Durlag's doomguard

// thieves' guild (specifics=92)

 LAF edit_creature INT_VAR tv=1 STR_VAR creature="alatos narlen blackl thief rededg denkod"
                           editstring=~strip_script=>"dw#gpsht %tutu_var%shout" insert_script_high=>dw#gpsht specifics=>92~
 END

// druids (specifics=93) (nb, most are solitary, and lack scripts - and careful not to break the Osmadi encounter)

 LAF edit_creature INT_VAR tv=1 allow_missing=1 STR_VAR creature="nestor cavene archdr"
                           editstring=~strip_script=>"dw#gpsht %tutu_var%shout" insert_script_high=>dw#gpsht specifics=>93~
 END



END

/////////////////////////////////////////////////////////////////////////////////
///   Make localised changes in other scripts/creatures (BG1 version)
////////////////////////////////////////////////////////////////////////////////

DEFINE_ACTION_FUNCTION change_other_scripts_BG1 BEGIN

   // messengers shouldn't have help scripts
   
   LAF edit_creature INT_VAR tv=1 STR_VAR creature=~roger wilco~ editstring= ~strip_script=>%tutu_var%shout~ END

   // hobgoblin elites in this area are allied with the ogres

   COPY_EXISTING ~%LonelyPeaks%.are~ ~override~
	REPLACE_TEXTUALLY ~%tutu_scripth%obelite~ ~dw#oghob~

   LAF clone_creature STR_VAR creature= ~%tutu_scripth%obelite=>dw#oghob~ editstring=~specifics=>80~ END

   // hobgoblins in Cloakwood Mines level 3 need to respond to human SHOUTs

   LAF clone_creature STR_VAR creature= ~%tutu_scripth%obelite=>dw#mihoe %tutu_scripth%obgoa_a=>dw#mihoa %tutu_scripth%obgoa_e=>dw#mihob~
                              editstring= ~specifics=>90~
   END

   COPY_EXISTING ~%CloakwoodMines_L3%.are~ ~override~
    REPLACE_TEXTUALLY CASE_INSENSITIVE ~%tutu_scripth%obelite%~ ~dw#mihoe~
    REPLACE_TEXTUALLY CASE_INSENSITIVE ~%tutu_scripth%obgoa_a%~ ~dw#mihoa~
    REPLACE_TEXTUALLY CASE_INSENSITIVE ~%tutu_scripth%obgoa_b%~ ~dw#mihob~

   // one or two creatures should call for help but not respond to others' calls or go hostile on hearing them - they have an item which prevents them responding

   LAF clone_item STR_VAR item=~misc16=>dw#nohlp~ editstring=~droppable=>0~ END
   LAF edit_creature INT_VAR tv=1 STR_VAR creature=~iron3 iron4 iron11 nevill~ editstring=~remove_items=>dw#nohlp add_items=>dw#nohlp~ END

   // Nashkel guards - shoot Nimbul, but in due course go to melee

   LAF install STR_VAR file=~dw#nimso.baf~ location=baf END
   LAF edit_creature INT_VAR tv=1 STR_VAR creature=~amnis bardol~ editstring=~swap_script=>"%tutu_scripts%eeenemy=>dw#nimso"~ END
   
   // a number of commoners don't have wtrunsgt
   
   LAF edit_creature INT_VAR allow_missing=1 STR_VAR creature="FENRUS NOWBAX_A NOWBAX_B NOWBAX_C NOWBAX_D NOWBAX_E READ6 RSCOMN01 RSCOMN02 RSCOMN03 RSCOMN04 SAILAL SAILNED TARIS TRIADO WIRTHI" editstring="insert_script_low=>wtrunsgt" END
   


END

/////////////////////////////////////////////////////////////////////////////////
///   Make localised changes in other scripts (BG2 version)
////////////////////////////////////////////////////////////////////////////////

DEFINE_ACTION_FUNCTION change_other_scripts_BG2 BEGIN

// let's experiment with giving the githyanki indefinite propagation

     LAF make_help_script INT_VAR first=175 second=275 STR_VAR normal=dw#gith1 END
     LAF edit_creature STR_VAR creature=~gith01 gith02 gith03 gith04 gith05 gith06 gorgit gorgith2~ editstring=~swap_script=>"grpsht01=>dw#gith1 gpshout=>dw#gith1"~ END

// spiders

     LAF make_help_script INT_VAR first=76 second=86 STR_VAR moron=dw#sphlp END
     LAF edit_creature STR_VAR creature=~spidgi01 spspid05 spidhu01 spidwr01 spspid07
                                         spidsw01 spidsm01 spidsm02 spspider spidph01
                                         spspid06 spidvo01 etter01~
                               editstring=~insert_script_high=>dw#sphlp~
     END

// avoid problems with the rakshasa

    LAF edit_creature STR_VAR creature=trrak01 editstring=~invert_scripts=>"gpshout=>trrak01"~ END

// succubus alu-fiends need to go hostile properly

   LAF swap_text STR_VAR files=gorsuc01.dlg swaps=~Enemy()=>Shout(151)Enemy()~ END


// CC beastmaster

   MAKE_PATCH
      match=>"actor_resource is_in [GIBMUT01 ICMIN01 CATLEO01 CATJAG01 GLBEAR2 BEARGR COPLION]"
      script_override=>dw#beast
   END
   LAF edit_area STR_VAR area=ar0406 editstring=~patch_actor=>patch_data~ END
<<<<<<<< .../stratagems-inline/dw#beast.baf
IF
  !Global("beastOpenTheDoors","GLOBAL",0)
  !Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
       Enemy()
       Continue()
END

IF
  !See(NearestEnemyOf(Myself))
  !Dead("beast")
  !Global("beastOpenTheDoors","GLOBAL",0)
THEN
    RESPONSE #100
             MoveToObject("beast")
END
>>>>>>>>

        COMPILE ~.../stratagems-inline/dw#beast.baf~

// UB's Suna Seni can go hostile if the ruffians do. Not sure if that's an UB bug, but I'll fix it anyway

        LAF edit_creature STR_VAR creature=suna editstring=~strip_script=>gpshout~ END


// prevent Amnish guards attacking Cowled Wizards

	 LAF clone_item STR_VAR item=~dw#marker_file=>dw#cowle~ editstring=~droppable=>0~ END
         LAF edit_creature STR_VAR creature=~cscowl9 cucow1 cucow2 cucow3 cuwiz1 cuwiz2 cuwiz3 cuwiz4 cuwiz5 cuwiz6 cuwizc cuwizsu~ editstring=~add_items=>dw#cowle~ END
         LAF swap_text STR_VAR files=seeenemy.bcs swaps=~!Class(LastSeenBy(Myself),FLAMING_FIST)=>!Class(LastSeenBy(Myself),FLAMING_FIST)!HasItem("dw#cowle",LastSeenBy(Myself))~ END

// Twisted Rune

        <<<<<<<< .../stratagems-inline/dw#ruhlp.baf
IF
  !Dead("hlshang")  
  !Global("ShangalarMove","AR1008",0)
  !Detect(NearestEnemyOf(Myself))
	!Detect(Player1)
	!Detect(Player2)
	!Detect(Player3)
	!Detect(Player4)
	!Detect(Player5)
	!Detect(Player6)
	THEN
   RESPONSE #100
       MoveToObject(Player1)
END
        >>>>>>>>

        COMPILE ~.../stratagems-inline/dw#ruhlp.baf~
        LAF edit_creature STR_VAR creature=~hlvaxal hlshyr hllayen hlrevan~ editstring=~insert_script_high=>dw#ruhlp~ END

// Ghaunadans
        OUTER_SPRINT ghaun_swap ~otyugh01=>dw#ghoty jelmus01=>ghjmu jelgre01=>dw#ghgre jeloch01=>dw#ghoch jelgra01=>dw#ghgra~
        LAF clone_creature STR_VAR creature= ~%ghaun_swap%~ editstring=~swap_script=>"gensht01=>grpsht01" specifics=>133~ END
        LAF get_area_script STR_VAR area=ar2200 RET script=script END
        LAF swap_text STR_VAR files= ~%script%.bcs~ swaps= ~%ghaun_swap%~ END
        LAF edit_creature STR_VAR creature=~daghaun1 daghaun2 dagmag01~ editstring=~insert_script_high=>grpsht01 specifics=>133~ END

// haegan

   LAF edit_creature STR_VAR creature=haegan editstring=~swap_script=>"haegan=>gpshout"~ END

// the dryads in Chateau Irenicus, who need to be insulated from duergar etc

    LAF edit_creature STR_VAR creature=~idryad01 idryad02 idryad03~ editstring=~specifics=>90 swap_script=>"shout=>grpsht01"~ END

// misc allocations of scripts to creatures

    // shout
    
   LAF edit_creature STR_VAR creature=~duecla01 drofod02 drofod03 drofod04 jael01 jael02 jael03~ editstring=~insert_script_high=>shout~ END

    // gpshout

   LAF edit_creature STR_VAR creature=~werewo01 werewodr weregrdr weregr01 c6were1
                                       gorwowe wolfgr01 wolfwe01 wolfwe02 shawol01
                                       pirsea01 pirsea03~
                             editstring=~insert_script_high=>grpsht01~ 
   END

    // grpsht01 - doesn't seem to occur

    // gensht01

    LAF edit_creature STR_VAR creature=~troll01 skelwa01 skelwa02 skelwa03 skelwa 
                                        mummy mummy01 mumgre01 icgob03 icgob04
                                        icyuan01 icyuan02 icyuan03 icyuan04 icyuan05
                                        obssah02 uddeath uddeath2 udkuo01~
                              editstring=~insert_script_high=>gensht01~
    END

// not technically a script

    LAF edit_creature STR_VAR creature=sahramb3 editstring=~allegiance=>ENEMY~ END

// Hobgoblin leaders need a much more minimal script

   LAF install STR_VAR file=~hglead01.baf~ location=baf END


END

DEFINE_ACTION_FUNCTION innocents_flee BEGIN

   LAF extend INT_VAR allow_missing=1 ssl=1 STR_VAR script="wtrunsgt wdrunsgt _trunsgt _drunsgt" top=fleepc location=ssl END



END
