--- ajantisbg2/setup-ajantisbg2.tp2	2015-06-14 14:07:50.000000000 -0400
+++ Fixpack/ajantisbg2/setup-ajantisbg2.tp2	2016-11-27 01:43:23.512014200 -0500
@@ -4,90 +4,74 @@
 
 //MODDER
 
-VERSION ~13~
+VERSION ~v13 BWP Fix~
 
 README ~AjantisBG2/documentation/readme.%LANGUAGE%.txt~ ~AjantisBG2/documentation/readme.english.txt~
 
+AUTO_TRA ~AjantisBG2/Tra/%s~
 
-AUTO_TRA ~AjantisBG2\Tra\autotra\%s~
+ALWAYS
+  ACTION_IF GAME_IS ~eet~ BEGIN
+    OUTER_SET bg2_chapter = 12
+  END ELSE BEGIN
+    OUTER_SET bg2_chapter = 0
+  END
+  OUTER_FOR (i=1; i<=10; i=i+1) BEGIN
+    OUTER_SET bg2_chapter = bg2_chapter + 1
+    OUTER_SPRINT name_source ~bg2_chapter_%i%~
+    OUTER_SET EVAL ~%name_source%~ = bg2_chapter
+  END
 
+  //CamDawgs CD_STATE_NOTVALID zum Checken der Dialogfähigkeit eines Char
+  //Thank you very much, CamDawg!
+  APPEND ~STATE.IDS~ ~0x80101FEF CD_STATE_NOTVALID~ // adds custom IsValidForPartyDialogue state
+              UNLESS ~CD_STATE_NOTVALID~
 
+  APPEND ~ACTION.IDS~ ~160 ApplySpellRES(S:RES*,O:Target)~
+               UNLESS ~160 ApplySpellRES(S:RES\*,O:Target)~
 
-ALWAYS
+  APPEND ~TRIGGER.IDS~ ~0x40D5 ActuallyInCombat()~
+                UNLESS ~0x40D5 ActuallyInCombat()~
+
+  INCLUDE ~AjantisBG2/lib/extra_regexp_vars.tph~
 
 /* romance timer for tob */
 OUTER_SET ROMANCE_TIMER = 1200
 
-ACTION_IF GAME_IS ~bg2 tob bg2ee~ AND NOT GAME_IS ~bgt~ THEN BEGIN
-OUTER_SPRINT ~IMOENJ~ ~imoenj~
-OUTER_SPRINT ~ImoenDV~ ~imoen~
-END
-
-ACTION_IF GAME_IS ~bgt~ THEN BEGIN
+  ACTION_IF GAME_IS ~bgt eet~ THEN BEGIN
 OUTER_SPRINT ~IMOENJ~ ~imoen2j~
 OUTER_SPRINT ~ImoenDV~ ~imoen2~
+  END ELSE BEGIN // ACTION_IF GAME_IS ~bg2 tob bg2ee~ AND NOT GAME_IS ~bgt eet~ THEN BEGIN
+    OUTER_SPRINT ~IMOENJ~ ~imoenj~
+    OUTER_SPRINT ~ImoenDV~ ~imoen~
 END
 
-
-  /*
-   * Copies tra files into the autotra-folder (to leave the originals untouched)
-   */
-  DEFINE_ACTION_FUNCTION autotra_workaround BEGIN
-    COPY ~AjantisBG2/tra/english~  ~AjantisBG2/tra/autotra/%LANGUAGE%~
-    COPY ~AjantisBG2/tra/%LANGUAGE%~  ~AjantisBG2/tra/autotra/%LANGUAGE%~
+  ACTION_IF "%WEIDU_OS%" STRING_EQUAL_CASE ~win32~ BEGIN // HANDLE_CHARSETS doesn't work with iconv_path containing spaces
+    AT_NOW ~if not exist "iconv" move "BiG World Fixpack\_utils\iconv" "iconv"~
   END
-
-  LAF autotra_workaround END
-
-
-//ACTION_DEFINE_ARRAY fl#noconvert BEGIN setup END
-
-//ACTION_DEFINE_ARRAY fl#reload BEGIN Setup-AjantisBG2.tra END
-
-  LAF HANDLE_CHARSETS
+  // any tra files used in LANGUAGE need to be reloaded after UTF-8 conversion
+  ACTION_DEFINE_ARRAY fl#reload BEGIN Setup-AjantisBG2 END
+  ACTION_DEFINE_ARRAY fl#noconvert BEGIN END
+  LAF HANDLE_CHARSETS // does nothing unless Enhanced Edition, and creates a mark file so it will only run once
     INT_VAR
-      infer_charset = 1
+      infer_charsets = 1
     STR_VAR
-      tra_path = EVAL ~AjantisBG2\Tra\autotra~
+      tra_path = EVAL ~AjantisBG2/Tra~
       noconvert_array = fl#noconvert
       reload_array = fl#reload
+	  iconv_path = ~iconv~ // provided by BiG World Fixpack
   END
 
-
-
-    //TRAs declared in LANGUAGE must be reloaded
-  LOAD_TRA ~AjantisBG2/tra/autotra/%LANGUAGE%/Setup-AjantisBG2.tra~
-
-
-
-
-//CamDawgs CD_STATE_NOTVALID zum Checken der Dialogfähigkeit eines Char
-//Thank you very much, CamDawg!
-APPEND ~STATE.IDS~ // adds custom IsValidForPartyDialogue state
- ~0x80101FEF CD_STATE_NOTVALID~
- UNLESS ~CD_STATE_NOTVALID~
-
-INCLUDE ~AjantisBG2/lib/extra_regexp_vars.tph~
-
-APPEND ~ACTION.IDS~ ~160 ApplySpellRES(S:RES*,O:Target)~
-             UNLESS ~160 ApplySpellRES(S:RES\*,O:Target)~
-
-APPEND ~TRIGGER.IDS~ ~0x40D5 ActuallyInCombat()~
-              UNLESS ~0x40D5 ActuallyInCombat()~
-
-
-
-
 END
 
 
 LANGUAGE ~Deutsch~
          ~german~   
-         ~AjantisBG2\Tra\autotra\german\Setup-AjantisBG2.tra~
+         ~AjantisBG2/Tra/german/Setup-AjantisBG2.tra~
 
 LANGUAGE ~English~
          ~english~  
-         ~AjantisBG2\Tra\autotra\english\Setup-AjantisBG2.tra~ 
+         ~AjantisBG2/Tra/english/Setup-AjantisBG2.tra~ 
  
 
 BEGIN @0
@@ -264,16 +248,16 @@
 
 COMPILE ~AjantisBG2\Dialogues\PC_Romance_conflicts.d~ //first, do not move
 
-COMPILE ~AjantisBG2\Dialogues\C#Ajan_pr.d~
+COMPILE EVALUATE_BUFFER ~AjantisBG2\Dialogues\C#Ajan_pr.d~
 	~AjantisBG2\Dialogues\C#Ajan_andere_pr.d~
 COMPILE ~AjantisBG2\Dialogues\C#AjanP_pr.d~
-COMPILE ~AjantisBG2\Dialogues\C#AjanJ_pr.d~
-COMPILE ~AjantisBG2\Dialogues\C#Orden.d~ 
+COMPILE EVALUATE_BUFFER ~AjantisBG2\Dialogues\C#AjanJ_pr.d~
+COMPILE EVALUATE_BUFFER ~AjantisBG2\Dialogues\C#Orden.d~ 
 COMPILE ~AjantisBG2\Dialogues\C#KNIG05_pr.d~
 COMPILE ~AjantisBG2\Dialogues\C#KNIG06_d_pr.d~
 COMPILE ~AjantisBG2\Dialogues\C#Windspeerritter.d~
 
-COMPILE ~AjantisBG2\Dialogues\Ajantis_Friendshippath.d~
+COMPILE EVALUATE_BUFFER ~AjantisBG2\Dialogues\Ajantis_Friendshippath.d~
 
 COMPILE ~AjantisBG2\Dialogues\Ajantis_Keldorn_pr.d~
 COMPILE ~AjantisBG2\Dialogues\Ajantis_Anomen.d~ 
@@ -306,7 +290,7 @@
 COMPILE ~AjantisBG2\Dialogues\Romance_nighttalks.d~
 COMPILE ~AjantisBG2\Dialogues\Romance_BodhiAbduction.d~
 COMPILE ~AjantisBG2\Dialogues\Romance_Underdark.d~
-COMPILE ~AjantisBG2\Dialogues\Romance.d~
+COMPILE EVALUATE_BUFFER ~AjantisBG2\Dialogues\Romance.d~
 COMPILE ~AjantisBG2\Dialogues\Romance_IniFlirts.d~
 COMPILE ~AjantisBG2\Dialogues\Ajantis_NBRomance.d~
 COMPILE ~AjantisBG2\Dialogues\AjantisEilaWindspear.d~
@@ -326,7 +310,7 @@
 
 //ToB content
 
-  ACTION_IF GAME_IS ~tob bg2ee~ THEN BEGIN 
+  ACTION_IF GAME_IS ~tob bg2ee eet~ THEN BEGIN 
 
 COMPILE EVALUATE_BUFFER ~AjantisBG2\tob\scripts\C#Ajan25.baf~
 
@@ -337,7 +321,7 @@
 
 COMPILE ~AjantisBG2\tob\dialogue\c#ajan25.d~
 COMPILE ~AjantisBG2\tob\dialogue\c#aja25j.d~
-USING ~AjantisBG2\tra\autotra\%s\c#ajanj_pr.tra~
+USING ~AjantisBG2/Tra/%LANGUAGE%/c#ajanj_pr.tra~
 
 COMPILE ~AjantisBG2\tob\dialogue\tob_romance_core.d~
 COMPILE ~AjantisBG2\tob\dialogue\tob_romance_scene.d~
@@ -350,8 +334,8 @@
 COMPILE ~AjantisBG2\tob\dialogue\tob_ajantis_npc.d~
 COMPILE ~AjantisBG2\tob\dialogue\tob_ajantis_banter.d~
 
-COMPILE ~AjantisBG2\tob\dialogue\tob_ict.d~
-USING ~AjantisBG2\tra\autotra\%s\c#ajanj_pr.tra~
+COMPILE EVALUATE_BUFFER ~AjantisBG2\tob\dialogue\tob_ict.d~
+USING ~AjantisBG2/Tra/%LANGUAGE%/c#ajanj_pr.tra~
 
 
 COMPILE ~AjantisBG2\tob\dialogue\cespenar_add.d~
@@ -427,8 +405,7 @@
   SAY NAME1 @75
   SAY NAME2 @76
   SAY UNIDENTIFIED_DESC @77
-
-SAY IDENTIFIED_DESC @904
+  SAY DESC @904
 
 
 COPY ~AjantisBG2\tob/Items/C#AJSHL3.ITM~ ~override~
@@ -444,19 +421,20 @@
 
 
 //The PID, to be compiled at last 
-COMPILE ~AjantisBG2\Dialogues\C#AjanJ_PID.d~ 
+COMPILE EVALUATE_BUFFER ~AjantisBG2\Dialogues\C#AjanJ_PID.d~ 
 
-ACTION_IF GAME_IS ~tob bg2ee~ THEN BEGIN 
+ACTION_IF GAME_IS ~tob bg2ee eet~ THEN BEGIN 
 COMPILE ~AjantisBG2\tob\dialogue\tob_pid.d~
-USING ~AjantisBG2\tra\autotra\%s\c#ajanj_pid.tra~
+  USING ~AjantisBG2/Tra/%LANGUAGE%/c#ajanj_pid.tra~
 END
 
 
 //Replacing the dead bodies in the Windspear hills, so they can be taken away
 COPY_EXISTING ~AR1200.bcs~ ~override~ 
-DECOMPILE_BCS_TO_BAF
-REPLACE_TEXTUALLY ~CreateCreatureAtLocation("LOCpalkni01","GLOBAL","deadb01")[%tab% %lnl%%mnl%%wnl%]+CreateCreatureAtLocation("LOCpalkni02","GLOBAL","deadb01")[%tab% %lnl%%mnl%%wnl%]+CreateCreatureAtLocation("LOCpalkni03","GLOBAL","deadb01")[%tab% %lnl%%mnl%%wnl%]+CreateCreatureAtLocation("LOCpalkni04","GLOBAL","deadb01")[%tab% %lnl%%mnl%%wnl%]+CreateCreatureAtLocation("LOCpalkni05","GLOBAL","deadb01")~ ~SetGlobal("C#AjantisRitterLeichen","GLOBAL",1) CreateCreatureAtLocation("LOCpalkni01","GLOBAL","C#dkn01") CreateCreatureAtLocation("LOCpalkni02","GLOBAL","C#dkn02") CreateCreatureAtLocation("LOCpalkni03","GLOBAL","C#dkn03") CreateCreatureAtLocation("LOCpalkni04","GLOBAL","C#dkn04") CreateCreatureAtLocation("LOCpalkni05","GLOBAL","C#dkn05")~
-COMPILE_BAF_TO_BCS
+  DECOMPILE_AND_PATCH BEGIN
+    REPLACE_TEXTUALLY ~CreateCreatureAtLocation("LOCpalkni01","GLOBAL","deadb01")[%tab% %lnl%%mnl%%wnl%]+CreateCreatureAtLocation("LOCpalkni02","GLOBAL","deadb01")[%tab% %lnl%%mnl%%wnl%]+CreateCreatureAtLocation("LOCpalkni03","GLOBAL","deadb01")[%tab% %lnl%%mnl%%wnl%]+CreateCreatureAtLocation("LOCpalkni04","GLOBAL","deadb01")[%tab% %lnl%%mnl%%wnl%]+CreateCreatureAtLocation("LOCpalkni05","GLOBAL","deadb01")~
+	                  ~SetGlobal("C#AjantisRitterLeichen","GLOBAL",1) CreateCreatureAtLocation("LOCpalkni01","GLOBAL","C#dkn01") CreateCreatureAtLocation("LOCpalkni02","GLOBAL","C#dkn02") CreateCreatureAtLocation("LOCpalkni03","GLOBAL","C#dkn03") CreateCreatureAtLocation("LOCpalkni04","GLOBAL","C#dkn04") CreateCreatureAtLocation("LOCpalkni05","GLOBAL","C#dkn05")~
+  END
 BUT_ONLY_IF_IT_CHANGES
 
 
@@ -655,15 +633,13 @@
   SAY NAME1 @75
   SAY NAME2 @76
   SAY UNIDENTIFIED_DESC @77
-
-SAY IDENTIFIED_DESC @78
+  SAY DESC @78
 
 COPY ~AjantisBG2/Items/C#AJ012A.ITM~ ~override/C#AJ012A.ITM~
   SAY NAME1 @75
   SAY NAME2 @76
   SAY UNIDENTIFIED_DESC @77
-
-SAY IDENTIFIED_DESC @79
+  SAY DESC @79
 
 COPY ~AjantisBG2/Items/C#AJCHBE.ITM~ ~override/C#AJCHBE.ITM~
   SAY NAME1 @80
@@ -728,7 +702,7 @@
 
 COPY ~AjantisBG2/Areas~ ~override~
 
-ACTION_IF GAME_IS BG2EE THEN BEGIN
+ACTION_IF GAME_IS ~BG2EE eet~ THEN BEGIN
   COPY ~AjantisBG2/BAMs_ee~ ~override~
 END
 
@@ -1133,8 +1093,7 @@
 SAY REACT_TO_DIE_GENERAL @62  
 SAY BIO @63
 
-ACTION_IF GAME_IS ~tob bg2ee~ THEN BEGIN
-
+  ACTION_IF GAME_IS ~tob bg2ee eet~ THEN BEGIN
 COPY 	~AjantisBG2\Creatures\Paladin\c#ajatob.cre~ ~override\c#ajatob.cre~
 SAY NAME1 @33
 SAY NAME2 @33
@@ -1223,8 +1180,7 @@
 SAY REACT_TO_DIE_GENERAL @62  
 SAY BIO @63
 
-ACTION_IF GAME_IS ~tob bg2ee~ THEN BEGIN
-
+  ACTION_IF GAME_IS ~tob bg2ee eet~ THEN BEGIN
 COPY 	~AjantisBG2\Creatures\Knight\c#ajatob.cre~ ~override\c#ajatob.cre~
 SAY NAME1 @33
 SAY NAME2 @33
@@ -1271,14 +1225,14 @@
 
 
 
-COMPILE ~AjantisBG2\Scripts\C#Ajan.baf~  
+COMPILE ~AjantisBG2\Scripts\C#Ajan.baf~ EVALUATE_BUFFER
 EXTEND_BOTTOM ~C#Ajan.bcs~ ~AjantisBG2\Scripts\Romance_conflicts.baf~
 EXTEND_BOTTOM ~C#Ajan.bcs~ ~AjantisBG2\Scripts\Romance_core.baf~ EVALUATE_BUFFER
-EXTEND_BOTTOM ~C#Ajan.bcs~ ~AjantisBG2\Scripts\Romance_add.baf~
+EXTEND_BOTTOM ~C#Ajan.bcs~ ~AjantisBG2\Scripts\Romance_add.baf~ EVALUATE_BUFFER
 EXTEND_BOTTOM ~C#Ajan.bcs~ ~AjantisBG2\Scripts\Ajantis_NBRomance_baf.baf~ EVALUATE_BUFFER
 EXTEND_BOTTOM ~C#Ajan.bcs~ ~AjantisBG2\Scripts\Ajantis_friendship.baf~ EVALUATE_BUFFER
 EXTEND_BOTTOM ~C#Ajan.bcs~ ~AjantisBG2\Scripts\Ajantis_NPCbanter.baf~
-EXTEND_BOTTOM ~C#Ajan.bcs~ ~AjantisBG2\Scripts\AjantisEilaWindspear_baf.baf~
+EXTEND_BOTTOM ~C#Ajan.bcs~ ~AjantisBG2\Scripts\AjantisEilaWindspear_baf.baf~ EVALUATE_BUFFER
 
 COMPILE ~AjantisBG2\Scripts\C#AjanD.baf~  
 EXTEND_BOTTOM ~C#AjanD.bcs~ ~AjantisBG2\Scripts\NBRom_Restbanter.BAF~ EVALUATE_BUFFER
@@ -1412,22 +1366,21 @@
 
 
 //Portrait
-COPY ~AjantisBG2/DefaultPortrait~ ~override~
-
-ACTION_IF GAME_IS ~bg2ee~ THEN BEGIN
+ACTION_IF GAME_IS ~bg2ee eet~ THEN BEGIN
 COPY ~AjantisBG2/DefaultPortrait/ee~ ~override~
+END ELSE BEGIN
+  COPY ~AjantisBG2/DefaultPortrait~ ~override~
 END
 
 //BGII:EE - ADD_JOURNAL
 
-
-ADD_JOURNAL @10003 @10004 @10005 @10006 @10007 @10008 @10009 @10010 @10011 @10012 @10013 @10014 @10015 @10016 @10017 @10018 @10019 @10020 @10021 @10022 @10023 @10024 @10025 @10026 @10027 @10028 @10029 @10030 @10041 @10042 @10043 @10044 @10045 @10046 @10047 @10048 USING ~AjantisBG2\tra\autotra\%LANGUAGE%/Setup-AjantisBG2.tra~
+ADD_JOURNAL @10003 @10004 @10005 @10006 @10007 @10008 @10009 @10010 @10011 @10012 @10013 @10014 @10015 @10016 @10017 @10018 @10019 @10020 @10021 @10022 @10023 @10024 @10025 @10026 @10027 @10028 @10029 @10030 @10041 @10042 @10043 @10044 @10045 @10046 @10047 @10048
 
 /* The Final Battle with Bodhi. */
-ADD_JOURNAL EXISTING TITLE (#74337) @10008 @10009 USING ~AjantisBG2\tra\autotra\%LANGUAGE%/Setup-AjantisBG2.tra~
+ADD_JOURNAL EXISTING TITLE (#74337) @10008 @10009
 
 /* Journey to the Windspear Hills. */
-ADD_JOURNAL EXISTING TITLE (#74363) @10000 @10001 @10002 USING ~AjantisBG2\tra\autotra\%LANGUAGE%/Setup-AjantisBG2.tra~
+ADD_JOURNAL EXISTING TITLE (#74363) @10000 @10001 @10002
 
 
 
@@ -1474,4 +1427,22 @@
  //   sox_path = ~AjantisBG2/sound~
 END
 
-
+ACTION_IF GAME_IS ~eet~ BEGIN
+  INCLUDE ~EET/other/EET_functions.tph~
+  LAF ~EET_NPC_TRANSITION~
+    INT_VAR
+      type = 2
+      clean_ToB = 1
+    STR_VAR
+      dv = "C#Ajantis"
+      override_SoA = "C#AJAN"
+      override_ToB = "C#AJAN25"
+      dialog_ToB = "C#AJAN25"
+      traFile = EVAL "AjantisBG2/tra/%LANGUAGE%/c#ajanj_pr.tra"
+      string = "@749" //Bring me Ajantis, the paladin and knight
+      stringPosDV = "Alora"
+      clean_ToB_DV = "Ajantis"
+  END
+END ELSE BEGIN
+  COMPILE ~ajantisbg2/tob/dialogue/FATESP.d~ USING ~AjantisBG2/tra/%LANGUAGE%/c#ajanj_pr.tra~
+END
