/* 
For anyone interested in using these: check out BG1 NPC instead. They'll have more 
examples and the most updated version of these libraries. These are also modified
libraries in that I remove the GAME_IS checks from the individual libraries, since
I do the game checks here instead. 

I mainly use these for the handful of times I need to patch specific BG areas or their 
scripts; this is why I can do things like use the BGEE vars for oBG, which is something
no one should really do.  

BG1 NPC also has additional libraries for dream scripts, fluid states, and all sorts of
other goodies for proper content support which I don't need for Tweaks. 
*/

ACTION_IF !game_includes_bg1 THEN BEGIN // I feel like these come up enough in BG&BG2 components to define them

	OUTER_SPRINT "tutu_var" ""
	OUTER_SPRINT "tutu_scriptbg" ""//BGT 'BG' prefix
	OUTER_SPRINT "eet_var" ""
  
END ELSE BEGIN

  ACTION_IF tutu_gen    BEGIN INCLUDE ~cdtweaks/lib/g3_tutu_cpmvars.tpa~  END ELSE       // tutu
  ACTION_IF game_is_bgt BEGIN INCLUDE ~cdtweaks/lib/g3_bgt_cpmvars.tpa~   END ELSE       // bgt
  ACTION_IF game_is_eet BEGIN INCLUDE ~eet/other/cpmvars/eet_cpmvars.tpa~ END ELSE BEGIN // eet
                              INCLUDE ~cdtweaks/lib/g3_bgee_cpmvars.tpa~  END            // use this for bgee AND obg

  DEFINE_ACTION_FUNCTION cd_extend_bg_area_script
  
    INT_VAR extend_top = 0
    STR_VAR area       = ""
            script     = ""
            tra_file   = ""
  BEGIN
            
    // make sure we have area scripts assigned
    COPY_EXISTING ~%area%.are~ ~override~
      READ_ASCII 0x94 a_script
      PATCH_IF ("%script%" STRING_COMPARE_CASE ~~ = 0) BEGIN // if blank
        PATCH_IF GAME_IS ~tutu tutu_totsc~ BEGIN // if Tutu
          WRITE_ASCIIE 0x95 ~%SOURCE_RES%~ #7
          WRITE_ASCII  0x94 ~_ar~
        END ELSE BEGIN // bgt
          WRITE_ASCIIE 0x94 ~%SOURCE_RES%~ #8
        END
        READ_ASCII 0x94 a_script
      END
      BUT_ONLY
    
<<<<<<<< ./inlined-macro/cd_extend_bg_area_script.tpa
EXTEND_BOTTOM ~%a_script%.bcs~ ~%script%.baf~ EVALUATE_BUFFER USING ~%tra_file%~ 
>>>>>>>>
  
    ACTION_IF extend_top = 1 THEN BEGIN
  
      COPY ~./inlined-macro/cd_extend_bg_area_script.tpa~ ~./inlined-macro/cd_extend_bg_area_script.tpa~
        REPLACE_TEXTUALLY ~^EXTEND_BOTTOM~ ~EXTEND_TOP~
  
    END
    
    ACTION_IF ("%tra_file%" STRING_COMPARE_CASE "" = 0) THEN BEGIN
  
      COPY ~./inlined-macro/cd_extend_bg_area_script.tpa~ ~./inlined-macro/cd_extend_bg_area_script.tpa~
        REPLACE_TEXTUALLY ~ EVALUATE_BUFFER USING ~ ~ EVALUATE_BUFFER // USING ~
  
    END
    
    REINCLUDE ~./inlined-macro/cd_extend_bg_area_script.tpa~
  
  END

END