BACKUP ~tb#tweaks/backup~
AUTHOR ~wal.big.it@libero.it~

NO_IF_EVAL_BUG

AUTO_TRA ~tb#tweaks/%s~

// ASK_EVERY_COMPONENT

ALWAYS
  ACTION_IF FILE_EXISTS ~tb#tweaks/readme-TB#Tweaks-%LANGUAGE%.htm~ THEN BEGIN
    AT_INTERACTIVE_EXIT ~VIEW tb#tweaks/readme-TB#Tweaks-%LANGUAGE%.htm~
  END ELSE BEGIN
    AT_INTERACTIVE_EXIT ~VIEW tb#tweaks/README-TB#Tweaks.htm~
  END
  <<<<<<<< refinements/inlined/tb#damned_files_to_fix.txt
>>>>>>>>


  ACTION_IF NOT FILE_EXISTS_IN_GAME ~tb#removedFitems.txt~ THEN BEGIN
      // if haven't tested ITM files..

    COPY ~refinements/inlined/tb#damned_files_to_fix.txt~ ~override/tb#removedFitems.txt~
      // mark it that we did test them now!
      // also, this file contains the list of not correctly sized files

    COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~
      PATCH_IF (SOURCE_SIZE < 0x72) BEGIN
        SPRINT file ~%SOURCE_FILE%~
        INNER_ACTION BEGIN
          APPEND ~tb#removedFitems.txt~ ~%file%~
          // Finally APPEND evaluates variables innately! T,W (= thanks, Weimer!)
        END
      END
    BUT_ONLY_IF_IT_CHANGES

    APPEND ~tb#removedFitems.txt~ ~THE_END_THE_END_AGAIN~
    // marks EOF for the file

    COPY_EXISTING ~tb#removedFitems.txt~ ~override~
      SPRINT old ~not_the_damned_end~
      // just to set it to something != EOF
      FOR (i = 0;!( ~%old%~ STRING_EQUAL_CASE ~THE_END_THE_END_AGAIN~); i = i + 1) BEGIN
        READ_2DA_ENTRY i 0 0 old
        PATCH_IF !(~%old%~ STRING_EQUAL_CASE ~THE_END_THE_END_AGAIN~) BEGIN
          INNER_ACTION BEGIN
            COPY_EXISTING ~sw1h01.itm~ ~override/%old%~
          END
        END
      END
    BUT_ONLY_IF_IT_CHANGES
  END

  ACTION_IF NOT FILE_EXISTS_IN_GAME ~tb#removedFspells.txt~ THEN BEGIN
      // if haven't tested spl files..

    COPY ~refinements/inlined/tb#damned_files_to_fix.txt~ ~override/tb#removedFspells.txt~
      // mark it that we did test them now!
      // also, this file contains the list of not correctly sized files

    COPY_EXISTING_REGEXP GLOB ~.*\.spl~ ~override~
      PATCH_IF (SOURCE_SIZE < 0x72) BEGIN
        SPRINT file ~%SOURCE_FILE%~
        INNER_ACTION BEGIN
          APPEND ~tb#removedFspells.txt~ ~%file%~
          // Finally APPEND evaluates variables innately! T,W (= thanks, Weimer!)
        END
      END
    BUT_ONLY_IF_IT_CHANGES

    APPEND ~tb#removedFspells.txt~ ~THE_END_THE_END_AGAIN~
    // marks EOF for the file

    COPY_EXISTING ~tb#removedFspells.txt~ ~override~
      SPRINT old ~not_the_damned_end~
      // just to set it to something != EOF
      FOR (i = 0; !(~%old%~ STRING_EQUAL_CASE ~THE_END_THE_END_AGAIN~); i = i + 1) BEGIN
        READ_2DA_ENTRY i 0 0 old
        PATCH_IF !(~%old%~ STRING_EQUAL_CASE ~THE_END_THE_END_AGAIN~) BEGIN
          INNER_ACTION BEGIN
            COPY_EXISTING ~spwi101.spl~ ~override/%old%~
          END
        END
      END
    BUT_ONLY_IF_IT_CHANGES
  END

  ACTION_IF NOT FILE_EXISTS_IN_GAME ~tb#removedFcreatures.txt~ THEN BEGIN
      // if haven't tested cre files..

    COPY ~refinements/inlined/tb#damned_files_to_fix.txt~ ~override/tb#removedFcreatures.txt~
      // mark it that we did test them now!
      // also, this file contains the list of not correctly sized files

    COPY_EXISTING_REGEXP GLOB ~.*\.cre~ ~override~
      PATCH_IF (SOURCE_SIZE < 0x72) BEGIN
        SPRINT file ~%SOURCE_FILE%~
        INNER_ACTION BEGIN
          APPEND ~tb#removedFcreatures.txt~ ~%file%~
          // Finally APPEND evaluates variables innately! T,W (= thanks, Weimer!)
        END
      END
    BUT_ONLY_IF_IT_CHANGES

    APPEND ~tb#removedFcreatures.txt~ ~THE_END_THE_END_AGAIN~
    // marks EOF for the file

    COPY_EXISTING ~tb#removedFcreatures.txt~ ~override~
      SPRINT old ~not_the_damned_end~
      // just to set it to something != EOF
      FOR (i = 0; !(~%old%~ STRING_EQUAL_CASE ~THE_END_THE_END_AGAIN~); i = i + 1) BEGIN
        READ_2DA_ENTRY i 0 0 old
        PATCH_IF !(~%old%~ STRING_EQUAL_CASE ~THE_END_THE_END_AGAIN~) BEGIN
          INNER_ACTION BEGIN
            COPY_EXISTING ~aataqah.cre~ ~override/%old%~
          END
        END
      END
    BUT_ONLY_IF_IT_CHANGES
  END

END  //ALWAYS

DEFINE_ACTION_MACRO ~FASTER_ROMANCES~ BEGIN
  <<<<<<<< faster_romance/macro/fixme.d
    REPLACE_ACTION_TEXT_REGEXP ~\(^aerie$\)\|\(^kalah2$\)~  ~StartDialogueNoSet()~ ~StartDialogueNoSet([PC])~
    REPLACE_ACTION_TEXT ~baerie~   ~MoveGlobal("AR0607","Aerie",\[1034\.1034\],0)~ ~MoveGlobal("AR0607","Aerie",[1034.1034])~
  >>>>>>>>
  
  COMPILE ~faster_romance/macro/fixme.d~

  COPY_EXISTING ~sw1h01.itm~ ~override/tb#faster1.txt~
  COPY_EXISTING ~gtimes.ids~ ~override~
    READ_2DA_ENTRIES_NOW ~_#_#_#gtimes~ 2
  BUT_ONLY_IF_IT_CHANGES
  
  COPY_EXISTING_REGEXP GLOB ~.*\.bcs~ ~override~
  DECOMPILE_BCS_TO_BAF
    FOR (i = 0; i < _#_#_#gtimes; i+=1)
    BEGIN
      READ_2DA_ENTRY_FORMER ~_#_#_#gtimes~ i 0 number
      READ_2DA_ENTRY_FORMER ~_#_#_#gtimes~ i 1 string
      REPLACE_TEXTUALLY ~,%string%)~ ~,%number%)~
    END
    REPLACE_EVALUATE ~RealSetGlobalTimer(\(\"[^"]*\",\"[^"]*\"\),\([^)]*\))~
    BEGIN
      temp = multiply * MATCH2 ** (exponentiation nth_root) / divide
      MATCH2 = temp < MATCH2 ? temp : MATCH2
      SPRINT RESULT ~%MATCH2%~
    END
    ~RealSetGlobalTimer(%MATCH1%,%RESULT%)~
  COMPILE_BAF_TO_BCS
  BUT_ONLY_IF_IT_CHANGES
  IF ~^268OB~

  COPY_EXISTING_REGEXP GLOB ~.*\.dlg~ ~override~
  DECOMPILE_DLG_TO_D
    FOR (i = 0; i < _#_#_#gtimes; i+=1)
    BEGIN
      READ_2DA_ENTRY_FORMER ~_#_#_#gtimes~ i 0 number
      READ_2DA_ENTRY_FORMER ~_#_#_#gtimes~ i 1 string
      REPLACE_TEXTUALLY ~,%string%)~ ~,%number%)~
    END
    REPLACE_EVALUATE ~RealSetGlobalTimer(\(\"[^"]*\",\"[^"]*\"\),\([^)]*\))~
    BEGIN
      temp = multiply * MATCH2 ** (exponentiation nth_root) / divide
      MATCH2 = temp < MATCH2 ? temp : MATCH2
      SPRINT RESULT ~%MATCH2%~
    END
    ~RealSetGlobalTimer(%MATCH1%,%RESULT%)~
  COMPILE_D_TO_DLG
  IF ~RealSetGlobalTimer~
  BUT_ONLY_IF_IT_CHANGES
END

LANGUAGE ~English~
	 ~English~
	 ~tb#tweaks/English/setup.tra~


// deprecated placeholders

// Nature's Beauty
BEGIN @2
DEPRECATED @2

// Imprisonment
BEGIN @2
DEPRECATED @2

// DWIP
BEGIN @2
DEPRECATED @2

// DWIP + Impri
BEGIN @2
DEPRECATED @2

// Unli Wish
BEGIN @2
DEPRECATED @2

// Cheesy Wish
BEGIN @2
DEPRECATED @2

// Improved Difficulty
BEGIN @2
DEPRECATED @2


/* ****************************************
            NATURAL BEAUTY
**************************************** */

BEGIN @1000   //natural beauty
DESIGNATED 100

UNINSTALL "setup-mazzythepaladin.tp2" 3
UNINSTALL ~setup-tb#pack.tp2~ 1

COPY_EXISTING ~sw1h01.itm~ ~override/tb#natbe.txt~
//this file will help other mods detect if component is installed.

COPY_EXISTING "sppr704.spl" "override"
READ_LONG 0x64 "headoffset" ELSE 0
READ_SHORT 0x68 "headcount" ELSE 0
READ_LONG 0x6a "effectsoffset" ELSE 0
WHILE ("%headcount%" > 0) BEGIN
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x28) + 0x1e) "count" ELSE 0
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x28) + 0x20) "effectsindex" ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30) "OPcode" ELSE 0
      SET "patchdone" = 0
      PATCH_IF ((("%OPcode%" = 142) OR ("%OPcode%" = 74)) AND (~%patchdone%~ = 0)) BEGIN    //if it's blindness or Display Portait Icon
      	    WRITE_BYTE (0x0c +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //Duration type = Instant/duration
      	    WRITE_LONG (0x0e + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 2400   //Time = 8 hours
      	    SET "patchdone" = 1
      END
      SET "count" = ("%count%" -1)
   END
   SET "headcount" = "%headcount%" - 1
END




/* ****************************************
           IMPRISONMENT FIX
**************************************** */

BEGIN @2000        //Imprisonment
DESIGNATED 150

UNINSTALL "setup-mazzythepaladin.tp2" 1
UNINSTALL "setup-ztb#pack.tp2" 0

COPY_EXISTING ~sw1h01.itm~ ~override/tb#impri.txt~

COPY ~tb#tweaks/imprisonment~ ~override~

COPY_EXISTING ~intmod.2da~ ~override~
  SET_2DA_ENTRY 25 5 6 1
  SET_2DA_ENTRY 25 4 6 6000
  
<<<<<<<< .../tb#tweaks/inlined/imprisonment/baldur.baf
IF
  Global("tb#imprisonmentcheat","global",1)
  Global("tb#impri","global",1)
  CombatCounterLT(1)
THEN
  RESPONSE #100
    SetGlobalTimer("tb#impri_timer","global",24) // 4 rounds
    SetGlobal("tb#impri","global",2)
END

IF
  Global("tb#imprisonmentcheat","global",1)
  GlobalTimerNotExpired("tb#impri_timer","global")
  CombatCounterGT(0)
  Global("tb#impri","global",2)
THEN
  RESPONSE #100
    SetGlobal("tb#impri","global",1)
END

IF
  Global("tb#imprisonmentcheat","global",1)
  GlobalTimerExpired("tb#impri_timer","global")
  Global("tb#impri","global",2)
  CombatCounterLT(1)
THEN
  RESPONSE #100
    SetGlobal("tb#impri","global",0)
    ActionOverride(Player1,ReallyForceSpell(Myself,WIZARD_FREEDOM))
    ActionOverride(Player2,ReallyForceSpell(Myself,WIZARD_FREEDOM))
    ActionOverride(Player3,ReallyForceSpell(Myself,WIZARD_FREEDOM))
    ActionOverride(Player4,ReallyForceSpell(Myself,WIZARD_FREEDOM))
    ActionOverride(Player5,ReallyForceSpell(Myself,WIZARD_FREEDOM))
    ActionOverride(Player6,ReallyForceSpell(Myself,WIZARD_FREEDOM))
END
>>>>>>>>

EXTEND_TOP ~baldur.bcs~ ~.../tb#tweaks/inlined/imprisonment/baldur.baf~
ACTION_IF (FILE_EXISTS_IN_GAME ~baldur25.bcs~) THEN BEGIN
  EXTEND_TOP ~baldur25.bcs~ ~.../tb#tweaks/inlined/imprisonment/baldur.baf~
END

PRINT @1

 COPY_EXISTING_REGEXP GLOB ~.*\.spl~ ~override~
READ_LONG 0x64 "headoffset"  ELSE 0
READ_SHORT 0x68 "headcount"  ELSE 0
READ_LONG 0x6a "effectsoffset"  ELSE 0
WHILE ("%headcount%" > 0) BEGIN
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x28) + 0x1e) "count"  ELSE 0
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x28) + 0x20) "effectsindex"  ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30) "OPcode"  ELSE 0
      READ_LONG ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30 + 8) "param2"  ELSE 0
      PATCH_IF ("%OPcode%" = 0xd3) BEGIN                 //if it's imprisonment
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x92        //OPcode=cast spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x0a   //parameter1=10
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) "tb#impri"   //Actual spell, a more friendly one :-)
      END
      PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%" = 0xd3)) BEGIN  //if it's protect from imprisonment
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0xce        //OPcode=protect from spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0  //parameter1=strref
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) "tb#impri"   //Spell to be protected from
      END
      SET "count" = ("%count%" -1)
   END
   SET "headcount" = "%headcount%" - 1
END
   READ_SHORT 0x70 "count"  ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ( "%count%" - 1 )* 0x30) "OPcode"  ELSE 0
      READ_LONG ("%effectsoffset%" + ( "%count%" - 1 )* 0x30 + 8) "param2"  ELSE 0
      PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%" = 0xd3)) BEGIN  //if it's protect from imprisonment
      	    WRITE_SHORT ("%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0xce        //OPcode=protect from spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0   //parameter1=strref
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%count%" - 1 )* 0x30)) "tb#impri"   //Spell to be protected from
      END
      SET "count" = ("%count%" -1)
   END
BUT_ONLY_IF_IT_CHANGES


 COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~
READ_LONG 0x64 "headoffset"  ELSE 0
READ_SHORT 0x68 "headcount"  ELSE 0
READ_LONG 0x6a "effectsoffset"  ELSE 0
WHILE ("%headcount%" > 0) BEGIN
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x38) + 0x1e) "count"  ELSE 0
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x38) + 0x20) "effectsindex"  ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30) "OPcode"  ELSE 0
      READ_LONG ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30 + 8) "param2"  ELSE 0
      PATCH_IF ("%OPcode%" = 0xd3) BEGIN                 //if it's imprisonment
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x92        //OPcode=cast spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x0a   //parameter1=0
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) "tb#impri"   //Actual spell, a more friendly one :-)
      END
            PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%" = 0xd3)) BEGIN  //if it's protect from imprisonment
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0xce        //OPcode=protect from spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter1=strref
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) "tb#impri"   //Spell to be protected from
      END
      SET "count" = "%count%" - 1
   END
   SET "headcount" = "%headcount%" - 1
END
   READ_SHORT 0x70 "count"  ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ( "%count%" - 1 )* 0x30) "OPcode"  ELSE 0
      READ_LONG ("%effectsoffset%" + ( "%count%" - 1 )* 0x30 + 8) "param2"  ELSE 0
      PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%" = 0xd3)) BEGIN  //if it's protect from imprisonment
      	    WRITE_SHORT ("%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0xce        //OPcode=protect from spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0   //parameter1=strref
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%count%" - 1 )* 0x30)) "tb#impri"   //Spell to be protected from
      END
      SET "count" = ("%count%" -1)
   END
BUT_ONLY_IF_IT_CHANGES

COPY_EXISTING_REGEXP GLOB ~.*\.cre~ ~override~
READ_BYTE 0x33 "effv"  ELSE 0
READ_LONG 0x02c4 "offseteffs"  ELSE 0
READ_LONG 0x02c8 "counteffs"   ELSE 0
PATCH_IF ("%effv%" = 0) BEGIN  //effects V1, like itms or spells
      WHILE ("%counteffs%" > 0) BEGIN
	    READ_SHORT ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x30)) "OPcode"  ELSE 0
	    READ_LONG ( 4 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x30)) "param1"  ELSE 0
	    READ_LONG ( 8 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x30)) "param2"  ELSE 0
	    PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%"=0xd3)) BEGIN  //if immunity to impri
	    	  WRITE_SHORT ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x30)) 0xce
	    	  WRITE_LONG ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x30) + 4) 0
	    	  WRITE_ASCII ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x30) + 14) "tb#impri"
	    END
      	    SET "counteffs" = "%counteffs%" - 1
      END
END
PATCH_IF ("%effv%" = 1) BEGIN  //effects V2
      WHILE ("%counteffs%" > 0) BEGIN
	    READ_LONG (0x08 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x108)) "OPcode"  ELSE 0
	    READ_LONG ( 0x14 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x108)) "param1"  ELSE 0
	    READ_LONG ( 0x18 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x108)) "param2"  ELSE 0
	    PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%"=0xd3)) BEGIN  //if immunity to impri
	    	  WRITE_SHORT (8 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x108)) 0xce
	    	  WRITE_LONG ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x108) + 0x14) 0
	    	  WRITE_ASCII ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x108) + 0x28) "tb#impri"
	    END
	    SET "counteffs" = "%counteffs%" - 1
      END
END
BUT_ONLY_IF_IT_CHANGES


COPY_EXISTING_REGEXP GLOB ~.*\.eff~ ~override~
	    READ_LONG 0x08  "OPcode"  ELSE 0
	    PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%"=0xd3)) BEGIN  //if immunity to impri
	    	  WRITE_SHORT 8  0xce
	    	  WRITE_LONG 0x14 0
	    	  WRITE_ASCII 0x30 "tb#impri"
	    END
	    PATCH_IF ("%OPcode%" = 0xd3) BEGIN
	    	  WRITE_SHORT 8 0xce
	    	  WRITE_LONG 0x14 0x0a
	    	  WRITE_LONG 0x18 0
	    	  WRITE_ASCII 0x30 "tb#impri"
	    END
BUT_ONLY_IF_IT_CHANGES




/* ****************************************
           PETRIFICATION FIX
**************************************** */

BEGIN @3000
DESIGNATED 200

COPY_EXISTING ~sw1h01.itm~ ~override/tb#petri.txt~

COPY ~tb#tweaks/petrification~ ~override~

<<<<<<<< .../tb#tweaks/inlined/petrification/baldur.baf
IF
  Global("tb#petricheat","global",1)
  Global("tb#petri","global",1)
  CombatCounterLT(1)
THEN
  RESPONSE #100
    SetGlobalTimer("tb#petri_timer","global",24) // 4 rounds
    SetGlobal("tb#petri","global",2)
END

IF
  Global("tb#petri","global",1)
  GlobalTimerNotExpired("tb#petri_timer","global")
  CombatCounterGT(0)
  Global("tb#petri","global",2)
THEN
  RESPONSE #100
    SetGlobal("tb#petri","global",1)
END

IF
  Global("tb#petricheat","global",1)
  GlobalTimerExpired("tb#petri_timer","global")
  Global("tb#petri","global",2)
  CombatCounterLT(1)
THEN
  RESPONSE #100
    SetGlobal("tb#petri","global",0)
    ActionOverride(Player1,ReallyForceSpellRES("tb#unpet",Myself))
    ActionOverride(Player2,ReallyForceSpellRES("tb#unpet",Myself))
    ActionOverride(Player3,ReallyForceSpellRES("tb#unpet",Myself))
    ActionOverride(Player4,ReallyForceSpellRES("tb#unpet",Myself))
    ActionOverride(Player5,ReallyForceSpellRES("tb#unpet",Myself))
    ActionOverride(Player6,ReallyForceSpellRES("tb#unpet",Myself))
END
>>>>>>>>

EXTEND_TOP ~baldur.bcs~ ~.../tb#tweaks/inlined/petrification/baldur.baf~
ACTION_IF (FILE_EXISTS_IN_GAME ~baldur25.bcs~) THEN BEGIN
  EXTEND_TOP ~baldur25.bcs~ ~.../tb#tweaks/inlined/petrification/baldur.baf~
END

PRINT @1

 COPY_EXISTING_REGEXP GLOB ~.*\.spl~ ~override~
READ_LONG 0x64 "headoffset"  ELSE 0
READ_SHORT 0x68 "headcount"  ELSE 0
READ_LONG 0x6a "effectsoffset"  ELSE 0
WHILE ("%headcount%" > 0) BEGIN
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x28) + 0x1e) "count"  ELSE 0
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x28) + 0x20) "effectsindex"  ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30) "OPcode"  ELSE 0
      READ_LONG ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30 + 8) "param2"  ELSE 0
      PATCH_IF ("%OPcode%" = 0x86) BEGIN                 //if it's petrification
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x92        //OPcode=cast spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x0a   //parameter1=10
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) "tb#petri"   //Actual spell, a more friendly one :-)
      END
      PATCH_IF ("%OPcode%" = 0x2b) BEGIN                 //if it's stone to flesh
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x92        //OPcode=cast spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x0a   //parameter1=10
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) "tb#depet"   //Actual spell, a more friendly one :-)
      END
      PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%" = 0x86)) BEGIN  //if it's protect from petrification
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0xce        //OPcode=protect from spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0  //parameter1=strref
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) "tb#petri"   //Spell to be protected from
      END
      SET "count" = ("%count%" -1)
   END
   SET "headcount" = "%headcount%" - 1
END
   READ_SHORT 0x70 "count"  ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ( "%count%" - 1 )* 0x30) "OPcode"  ELSE 0
      READ_LONG ("%effectsoffset%" + ( "%count%" - 1 )* 0x30 + 8) "param2"  ELSE 0
      PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%" = 0x86)) BEGIN  //if it's protect from petrification
      	    WRITE_SHORT ("%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0xce        //OPcode=protect from spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0   //parameter1=strref
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%count%" - 1 )* 0x30)) "tb#petri"   //Spell to be protected from
      END
      SET "count" = ("%count%" -1)
   END
BUT_ONLY_IF_IT_CHANGES


 COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~
READ_LONG 0x64 "headoffset"  ELSE 0
READ_SHORT 0x68 "headcount"  ELSE 0
READ_LONG 0x6a "effectsoffset"  ELSE 0
WHILE ("%headcount%" > 0) BEGIN
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x38) + 0x1e) "count"  ELSE 0
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x38) + 0x20) "effectsindex"  ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30) "OPcode"  ELSE 0
      READ_LONG ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30 + 8) "param2"  ELSE 0
      PATCH_IF ("%OPcode%" = 0x86) BEGIN                 //if it's petrification
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x92        //OPcode=cast spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x0a   //parameter1=0
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) "tb#petri"   //Actual spell, a more friendly one :-)
      END
      PATCH_IF ("%OPcode%" = 0x2b) BEGIN                 //if it's stone to flesh
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x92        //OPcode=cast spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x0a   //parameter1=10
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) "tb#depet"   //Actual spell, a more friendly one :-)
      END
      PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%" = 0x86)) BEGIN  //if it's protect from petrification
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0xce        //OPcode=protect from spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter1=strref
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) "tb#petri"   //Spell to be protected from
      END
      SET "count" = "%count%" - 1
   END
   SET "headcount" = "%headcount%" - 1
END
   READ_SHORT 0x70 "count"  ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ( "%count%" - 1 )* 0x30) "OPcode"  ELSE 0
      READ_LONG ("%effectsoffset%" + ( "%count%" - 1 )* 0x30 + 8) "param2"  ELSE 0
      PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%" = 0x86)) BEGIN  //if it's protect from petrification
      	    WRITE_SHORT ("%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0xce        //OPcode=protect from spell
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0   //parameter1=strref
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%count%" - 1 )* 0x30)) 0   //parameter2=0
      	    WRITE_ASCII (0x14 + "%effectsoffset%" + (("%count%" - 1 )* 0x30)) "tb#petri"   //Spell to be protected from
      END
      SET "count" = ("%count%" -1)
   END
BUT_ONLY_IF_IT_CHANGES

COPY_EXISTING_REGEXP GLOB ~.*\.cre~ ~override~
READ_BYTE 0x33 "effv"  ELSE 0
READ_LONG 0x02c4 "offseteffs"  ELSE 0
READ_LONG 0x02c8 "counteffs"   ELSE 0
PATCH_IF ("%effv%" = 0) BEGIN  //effects V1, like itms or spells
      WHILE ("%counteffs%" > 0) BEGIN
	    READ_SHORT ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x30)) "OPcode"  ELSE 0
	    READ_LONG ( 4 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x30)) "param1"  ELSE 0
	    READ_LONG ( 8 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x30)) "param2"  ELSE 0
	    PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%"=0x86)) BEGIN  //if immunity to petri
	    	  WRITE_SHORT ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x30)) 0xce
	    	  WRITE_LONG ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x30) + 4) 0
	    	  WRITE_ASCII ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x30) + 14) "tb#petri"
	    END
      	    SET "counteffs" = "%counteffs%" - 1
      END
END
PATCH_IF ("%effv%" = 1) BEGIN  //effects V2
      WHILE ("%counteffs%" > 0) BEGIN
	    READ_LONG (0x08 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x108)) "OPcode"  ELSE 0
	    READ_LONG ( 0x14 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x108)) "param1"  ELSE 0
	    READ_LONG ( 0x18 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x108)) "param2"  ELSE 0
	    PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%"=0x86)) BEGIN  //if immunity to petri
	    	  WRITE_SHORT (8 + "%offseteffs%" + (("%counteffs%" - 0 ) * 0x108)) 0xce
	    	  WRITE_LONG ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x108) + 0x14) 0
	    	  WRITE_ASCII ("%offseteffs%" + (("%counteffs%" - 0 ) * 0x108) + 0x28) "tb#petri"
	    END
	    SET "counteffs" = "%counteffs%" - 1
      END
END
BUT_ONLY_IF_IT_CHANGES


COPY_EXISTING_REGEXP GLOB ~.*\.eff~ ~override~
	    READ_LONG 0x08  "OPcode"  ELSE 0
	    PATCH_IF (("%OPcode%" = 0x65) AND ("%param2%"=0x86)) BEGIN  //if immunity to petri
	    	  WRITE_SHORT 8  0xce
	    	  WRITE_LONG 0x14 0
	    	  WRITE_ASCII 0x30 "tb#petri"
	    END
      PATCH_IF ("%OPcode%" = 0x2b) BEGIN                 //if it's stone to flesh
      	    WRITE_SHORT 8 0x92        //OPcode=cast spell
      	    WRITE_LONG 0x14 0x0a   //parameter1=10
      	    WRITE_LONG 0x18 0   //parameter2=0
      	    WRITE_ASCII 0x30 "tb#depet"   //Actual spell, a more friendly one :-)
      END
	    PATCH_IF ("%OPcode%" = 0x86) BEGIN
	    	  WRITE_SHORT 8 0xce
	    	  WRITE_LONG 0x14 0x0a
	    	  WRITE_LONG 0x18 0
	    	  WRITE_ASCII 0x30 "tb#petri"
	    END
BUT_ONLY_IF_IT_CHANGES




/* ****************************************
           DROP WEAPONS IN PANIC
**************************************** */

BEGIN @4000           //Drop Weapons in Panic
DESIGNATED 300
UNINSTALL "setup-mazzythepaladin.tp2" 2
UNINSTALL "setup-ztb#pack.tp2" 1

COPY_EXISTING ~sw1h01.itm~ ~override/tb#dropw.txt~
SET "itemdone" = 0
//this file will help other mods detect if component is installed.

PRINT @1

 COPY_EXISTING_REGEXP GLOB ~.*\.spl~ ~override~
READ_LONG 0x64 "headoffset" ELSE 0
READ_SHORT 0x68 "headcount" ELSE 0
READ_LONG 0x6a "effectsoffset" ELSE 0
WHILE ("%headcount%" > 0) BEGIN
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x28) + 0x1e) "count" ELSE 0
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x28) + 0x20) "effectsindex" ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30) "OPcode" ELSE 0
      PATCH_IF (("%OPcode%" = 0x108) AND (~%patchdone%~ = 0))  BEGIN                 //if it's drop weapons in panic
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x8b        //OPcode=display string
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter1=strref
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      END
      SET "count" = ("%count%" -1)
   END
   SET "headcount" = "%headcount%" - 1
END
BUT_ONLY_IF_IT_CHANGES


 COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~
READ_LONG 0x64 "headoffset" ELSE 0
READ_SHORT 0x68 "headcount" ELSE 0
READ_LONG 0x6a "effectsoffset" ELSE 0
WHILE ("%headcount%" > 0) BEGIN
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x38) + 0x1e) "count" ELSE 0
   READ_SHORT ("%headoffset%" + (("%headcount%" - 1 ) * 0x38) + 0x20) "effectsindex" ELSE 0
   WHILE ("%count%" >0) BEGIN
      READ_SHORT ("%effectsoffset%" + ("%effectsindex%" + "%count%" - 1 )* 0x30) "OPcode" ELSE 0
      PATCH_IF (("%OPcode%" = 0x108)) BEGIN                 //if it's drop weapons in panic
      	    WRITE_SHORT ("%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0x8b        //OPcode=display string
      	    WRITE_LONG (4 +"%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter1=strref
      	    WRITE_LONG (8 + "%effectsoffset%" + (("%effectsindex%" + "%count%" - 1 )* 0x30)) 0   //parameter2=0
      END
      SET "count" = ("%count%" -1)
   END
   SET "headcount" = "%headcount%" - 1
END
BUT_ONLY_IF_IT_CHANGES

COPY_EXISTING_REGEXP GLOB ~.*\.eff~ ~override~
	    READ_LONG 0x08  "OPcode" ELSE 0
	    PATCH_IF (("%OPcode%" = 0x108)) BEGIN
	    	  WRITE_SHORT 8 0x8b
	    	  WRITE_LONG 0x14 0
	    	  WRITE_LONG 0x18 0
	    	  WRITE_LONG 0x3c 0
		  WRITE_LONG 0x38 0
	    END
BUT_ONLY_IF_IT_CHANGES





/* ****************************************
           WISHES FIX
**************************************** */

BEGIN @5000
DESIGNATED 1000
UNINSTALL "setup-ztb#pack.tp2" 3

COPY_EXISTING ~sw1h01.itm~ ~override/tb#unliwish.txt~

COPY_EXISTING ~wish01.cre~ ~override~
WRITE_BYTE 0x275 1
WRITE_BYTE 0x234 25

ACTION_IF FILE_EXISTS ~data/25spells.bif~ THEN BEGIN
COPY_EXISTING ~wish02.cre~ ~override~
WRITE_BYTE 0x275 1
END




/* ****************************************
           CONVENIENT WISHES
**************************************** */

BEGIN @6001
DESIGNATED 1200
SUBCOMPONENT @6000
REQUIRE_FILE ~data/25spells.bif~ @5

AT_UNINSTALL ~echo OUCH!~

COPY_EXISTING ~sw1h01.itm~ ~override/tb#convenientwish.txt~
COMPILE ~tb#tweaks/wish/convtob.d~




/* ****************************************
           CHEESY WISHES - TOB
**************************************** */

BEGIN @7000
DESIGNATED 1250
SUBCOMPONENT @6000
REQUIRE_FILE ~data/25spells.bif~ @5
UNINSTALL "setup-ztb#pack.tp2" 4

COPY_EXISTING ~sw1h01.itm~ ~override/tb#cheesywish.txt~

COMPILE ~tb#tweaks/wish/cheesytob.d~




/* ****************************************
           CHEESY WISHES - SOA
**************************************** */

BEGIN @7001
DESIGNATED 1400
FORBID_FILE ~data/25spells.bif~ @6
UNINSTALL "setup-ztb#pack.tp2" 4

COPY_EXISTING ~sw1h01.itm~ ~override/tb#cheesywish.txt~

COMPILE ~tb#tweaks/wish/cheesysoa.d~



/* ****************************************
           IMPROVED DIFFICULTY SYSTEM
**************************************** */

BEGIN @8000
DESIGNATED 2000

COPY_EXISTING ~sw1h01.itm~ ~override/tb#impdiff.txt~

COMPILE ~tb#tweaks/impdiff/impdiff.d~  //dialogue for the talker, adjust all dialogue

COPY ~tb#tweaks/impdiff/kylie.cre~ ~override/tb#impdi.cre~
SAY NAME1 ~Ggib Eht~
SAY NAME2 ~Ggib Eht~
WRITE_ASCII 0x248 ~SHOUTDLG~ #8
WRITE_ASCII 0x268 ~~ #8
WRITE_ASCII 0x2cc ~TB#DIFF~ #8

COPY_EXISTING_REGEXP GLOB ~.*\.bcs$~ ~override~
DECOMPILE_BCS_TO_BAF
REPLACE_TEXTUALLY ~Difficulty(EASIEST)~ ~Global("RTWMyDifficulty","global",1)~ //checks my var instead of hardcoded difficulty
REPLACE_TEXTUALLY ~Difficulty(EASY)~ ~Global("RTWMyDifficulty","global",2)~
REPLACE_TEXTUALLY ~Difficulty(NORMAL)~ ~Global("RTWMyDifficulty","global",3)~
REPLACE_TEXTUALLY ~Difficulty(HARD)~ ~Global("RTWMyDifficulty","global",4)~
REPLACE_TEXTUALLY ~Difficulty(HARDEST)~ ~Global("RTWMyDifficulty","global",5)~
REPLACE_TEXTUALLY ~DifficultyGT(EASIEST)~ ~GlobalGT("RTWMyDifficulty","global",1)~
REPLACE_TEXTUALLY ~DifficultyGT(EASY)~ ~GlobalGT("RTWMyDifficulty","global",2)~
REPLACE_TEXTUALLY ~DifficultyGT(NORMAL)~ ~GlobalGT("RTWMyDifficulty","global",3)~
REPLACE_TEXTUALLY ~DifficultyGT(HARD)~ ~GlobalGT("RTWMyDifficulty","global",4)~
REPLACE_TEXTUALLY ~DifficultyGT(HARDEST)~ ~GlobalGT("RTWMyDifficulty","global",5)~
REPLACE_TEXTUALLY ~DifficultyLT(EASIEST)~ ~GlobalLT("RTWMyDifficulty","global",1)~
REPLACE_TEXTUALLY ~DifficultyLT(EASY)~ ~GlobalLT("RTWMyDifficulty","global",2)~
REPLACE_TEXTUALLY ~DifficultyLT(NORMAL)~ ~GlobalLT("RTWMyDifficulty","global",3)~
REPLACE_TEXTUALLY ~DifficultyLT(HARD)~ ~GlobalLT("RTWMyDifficulty","global",4)~
REPLACE_TEXTUALLY ~DifficultyLT(HARDEST)~ ~GlobalLT("RTWMyDifficulty","global",5)~
COMPILE_BAF_TO_BCS
IF ~^1659[234] ~
BUT_ONLY_IF_IT_CHANGES

COPY_EXISTING_REGEXP GLOB ~.*\.dlg$~ ~override~
DECOMPILE_DLG_TO_D
REPLACE_TEXTUALLY ~Difficulty(EASIEST)~ ~Global("RTWMyDifficulty","global",1)~ //checks my var instead of hardcoded difficulty
REPLACE_TEXTUALLY ~Difficulty(EASY)~ ~Global("RTWMyDifficulty","global",2)~
REPLACE_TEXTUALLY ~Difficulty(NORMAL)~ ~Global("RTWMyDifficulty","global",3)~
REPLACE_TEXTUALLY ~Difficulty(HARD)~ ~Global("RTWMyDifficulty","global",4)~
REPLACE_TEXTUALLY ~Difficulty(HARDEST)~ ~Global("RTWMyDifficulty","global",5)~
REPLACE_TEXTUALLY ~DifficultyGT(EASIEST)~ ~GlobalGT("RTWMyDifficulty","global",1)~
REPLACE_TEXTUALLY ~DifficultyGT(EASY)~ ~GlobalGT("RTWMyDifficulty","global",2)~
REPLACE_TEXTUALLY ~DifficultyGT(NORMAL)~ ~GlobalGT("RTWMyDifficulty","global",3)~
REPLACE_TEXTUALLY ~DifficultyGT(HARD)~ ~GlobalGT("RTWMyDifficulty","global",4)~
REPLACE_TEXTUALLY ~DifficultyGT(HARDEST)~ ~GlobalGT("RTWMyDifficulty","global",5)~
REPLACE_TEXTUALLY ~DifficultyLT(EASIEST)~ ~GlobalLT("RTWMyDifficulty","global",1)~
REPLACE_TEXTUALLY ~DifficultyLT(EASY)~ ~GlobalLT("RTWMyDifficulty","global",2)~
REPLACE_TEXTUALLY ~DifficultyLT(NORMAL)~ ~GlobalLT("RTWMyDifficulty","global",3)~
REPLACE_TEXTUALLY ~DifficultyLT(HARD)~ ~GlobalLT("RTWMyDifficulty","global",4)~
REPLACE_TEXTUALLY ~DifficultyLT(HARDEST)~ ~GlobalLT("RTWMyDifficulty","global",5)~
COMPILE_D_TO_DLG
IF ~Difficulty\([LG]T\)?~
BUT_ONLY_IF_IT_CHANGES

EXTEND_TOP "baldur.bcs" ~tb#tweaks/impdiff/start.baf~  // spawn Ggib if difficulty level isn't set.
ACTION_IF FILE_EXISTS_IN_GAME ~baldur25.bcs~ THEN BEGIN
EXTEND_TOP "baldur25.bcs" ~tb#tweaks/impdiff/start.baf~
END
EXTEND_TOP "dplayer3.bcs" ~tb#tweaks/impdiff/dplayer.baf~ // spawn Ggib if stroke K.


/* ****************************************
           FASTER ROMANCES
**************************************** */
/* RealSetGlobalTimer(_,_,x) is changed to be
multiply * x ^ (exponentiation / nth_root) / divide 
(but only if the value decreases).

Values for multiply, exponentiation, nth_root and divide are computated 
thanks to an external program written in C, included in the mod distribution,
see the file other/compute_faster_romance.c .
If you want me to add different pairs (not necessarily 3600->x and 36000->x),
it can be done fairly trivially, so ask away. (you can even compile and run
the 'compute_faster_romance' program yourself to find out the values yourself).
*/

BEGIN @9001
SUBCOMPONENT @9000
DESIGNATED 2500
// 3600  -> 3300
// 36000 -> 18000

OUTER_SET multiply = 795
OUTER_SET divide = 1000
OUTER_SET exponentiation = 736
OUTER_SET nth_root = 1000

LAUNCH_ACTION_MACRO ~FASTER_ROMANCES~

BEGIN @9002
SUBCOMPONENT @9000
DESIGNATED 2550
// 3600  -> 3000
// 36000 -> 12000

OUTER_SET multiply = 21689
OUTER_SET divide = 999
OUTER_SET exponentiation = 602
OUTER_SET nth_root = 1000

LAUNCH_ACTION_MACRO ~FASTER_ROMANCES~

BEGIN @9003
SUBCOMPONENT @9000
DESIGNATED 2600
// 3600  -> 2700
// 36000 -> 9000

OUTER_SET multiply = 37581
OUTER_SET divide = 1002
OUTER_SET exponentiation = 523
OUTER_SET nth_root = 1001

LAUNCH_ACTION_MACRO ~FASTER_ROMANCES~

