BACKUP ~march_mod/backup~

AUTHOR ~sheele, tipun~

VERSION ~v 0.1~

ALWAYS
	INCLUDE ~%MOD_FOLDER%/lib/init.tph~
END

LANGUAGE ~Russian~
	     ~ru_RU~
	     ~march_mod/lang/ru_RU/setup.tra~

BEGIN @1
REQUIRE_PREDICATE GAME_IS ~totsc bgt bgee eet~ @2 //

OUTER_SPRINT ~tilde~ "~"

MKDIR ~%MOD_FOLDER%/compile_new~

APPEND ~STATE.IDS~ ~0x80101FEF CD_STATE_NOTVALID~ UNLESS ~CD_STATE_NOTVALID~
APPEND ~GTIMES.IDS~ ~7200 ONE_DAY~                UNLESS ~ONE_DAY~

OUTER_SPRINT SHPROST1_D ~~
/*COPY_EXISTING ~PROST1.DLG~ ~%MOD_FOLDER%/res/SHPROST1.D~ DECOMPILE_DLG_TO_D
COPY ~%MOD_FOLDER%/res/SHPROST1.D~ ~%MOD_FOLDER%/res/SHPROST1.D~
	SET f_size = BUFFER_LENGTH - 1
	//SET f_sz = f_size
	/*SET w = 1
	SET f_sz = INDEX_BUFFER(~BEGIN[ %TAB%]+8~)
	PATCH_IF ( f_sz >= 0 ) BEGIN
		SET f_sza = RINDEX_BUFFER(~^IF~ f_sz)
		PATCH_IF ( f_sza >= 0 ) BEGIN
			DELETE_BYTES f_sza ( f_size - f_sza )
		END
	END*/
	FOR ( i = 0 ; i < 8 ; ++i ) BEGIN
		SET f_sz = INDEX_BUFFER(~BEGIN[ %TAB%]+%i%~)
		PATCH_IF ( f_sz >= 0 ) BEGIN
			SET f_sza = INDEX_BUFFER(~SAY[ %TAB%]+#~ f_sz)
			SET f_szb = INDEX_BUFFER(~%LNL%~ f_sza)
			READ_ASCII f_sza txt ( f_szb - f_sza )
			SET num = 0 - 1
			INNER_PATCH_SAVE txt ~%txt%~ BEGIN
				REPLACE_EVALUATE
				~SAY[ %TAB%]#\([0-9]+\)~
				BEGIN
					SET num = MATCH1
				END
				~%num%~
			END
			PATCH_IF ( num >= 0 ) BEGIN
				SET r_num = i + 1
				SPRINT ~SHPROST1_D~ ~%SHPROST1_D%IF %tilde%RandomNum(8,%r_num%)%tilde% THEN BEGIN %i%%LNL%SAY #%num%%LNL%IF %tilde%%tilde% THEN EXIT%LNL%END%LNL%%LNL%~
			END
		END
	END
	REPLACE_TEXTUALLY ~PROST1~ ~SHPROST1~*/
COPY_EXISTING ~PROST1.DLG~ ~override~
	READ_LONG 0x008 states
	READ_LONG 0x00c states_off
	PATCH_IF ( states > 0 ) BEGIN
		PATCH_IF ( states >= 8 ) BEGIN SET nums = 8 END ELSE BEGIN SET nums = states END
		FOR ( i = 0 ; i < nums ; ++i ) BEGIN
			READ_LONG states_off + i * 0x10 num
			SET r_num = i + 1
			SPRINT ~SHPROST1_D~ ~%SHPROST1_D%IF %tilde%RandomNum(8,%r_num%)%tilde% THEN BEGIN %i%%LNL%SAY #%num%%LNL%IF %tilde%%tilde% THEN EXIT%LNL%END%LNL%%LNL%~
		END
	END
	BUT_ONLY_IF_IT_CHANGES
<<<<<<<< SHPROST1.D
BEGIN SHPROST1

%SHPROST1_D%
>>>>>>>>
COPY ~SHPROST1.D~ ~%MOD_FOLDER%/res~ EVALUATE_BUFFER
COMPILE ~%MOD_FOLDER%/res/SHPROST1.D~

COPY_EXISTING ~PROSBA_B.cre~ ~override/SHPROSBB.cre~
              ~PROSBA_C.cre~ ~override/SHPROSBC.cre~
    PATCH_IF NOT GAME_IS ~totsc~ BEGIN
	    WRITE_ASCII  0x260 ~~ (8)
	    WRITE_ASCII  0x268 ~SHPROSBB~ (8)
    END
	WRITE_ASCIIE 0x280 ~%DEST_RES%~ (32)
	WRITE_ASCII  0x2cc ~SHPROST1~ (8)
COPY_EXISTING ~%beregost_area%.are~ ~override~
	LPF ALTER_AREA_ACTOR_EX
		INT_VAR
			match_pos_x = 1615
			match_pos_y = 2777
			match_orientation = 0
		STR_VAR
			match_cre_file = "PROSBA_B"
			cre_file = "SHPROSBB"
	END
	LPF ALTER_AREA_ACTOR_EX
		INT_VAR
			match_pos_x = 1538
			match_pos_y = 2850
			match_orientation = 12
		STR_VAR
			match_cre_file = "PROSBA_C"
			cre_file = "SHPROSBC"
	END
COPY_EXISTING ~PRSBAX_A.cre~ ~override/SHPROSWB.cre~
	WRITE_LONG  0x028 50704
    PATCH_IF NOT GAME_IS ~totsc~ BEGIN
	    WRITE_ASCII  0x260 ~~ (8)
	    WRITE_ASCII  0x268 ~SHPROSBB~ (8)
    END
	WRITE_ASCII 0x280 ~SHPROSBB~ (32)
	WRITE_ASCII 0x2cc ~SHPROST1~ (8)
COPY_EXISTING ~PRSBAX_B.cre~ ~override/SHPROSWC.cre~
	WRITE_LONG  0x028 50704
    PATCH_IF NOT GAME_IS ~totsc~ BEGIN
	    WRITE_ASCII  0x260 ~~ (8)
	    WRITE_ASCII  0x268 ~SHPROSBB~ (8)
    END
	WRITE_ASCII 0x280 ~SHPROSBC~ (32)
	WRITE_ASCII 0x2cc ~SHPROST1~ (8)
COPY_EXISTING ~%baldur_east%.are~ ~override~
	LPF ALTER_AREA_ACTOR_EX
		INT_VAR
			match_pos_x = 2497
			match_pos_y = 2732
			match_orientation = 0
		STR_VAR
			match_cre_file = "PRSBAX_A"
			cre_file = "SHPROSWB"
	END
	LPF ALTER_AREA_ACTOR_EX
		INT_VAR
			match_pos_x = 2360
			match_pos_y = 2673
			match_orientation = 14
		STR_VAR
			match_cre_file = "PRSBAX_B"
			cre_file = "SHPROSWC"
	END
ACTION_IF NOT GAME_IS ~totsc~ BEGIN
	ACTION_IF GAME_IS ~bgee eet~ BEGIN
		OUTER_SPRINT SavedLoc_timer ~~
		OUTER_SPRINT NearLoc ~!NearSavedLocation(Myself,"LOCALSSavedLoc",20)~
	END ELSE BEGIN
		OUTER_SPRINT SavedLoc_timer ~SetGlobalTimer("SavedLoc_timer","LOCALS",15)~
		OUTER_SPRINT NearLoc ~GlobalTimerExpired("SavedLoc_timer","LOCALS")~
	END
	//COPY ~%MOD_FOLDER%/res/near_location.baf~ ~%MOD_FOLDER%/compile_new/SHPROSBB.baf~ EVALUATE_BUFFER
	COPY_EXISTING ~WDRUNSGT.bcs~ ~override/SHPROSBB.bcs~
		DECOMPILE_AND_PATCH BEGIN
			LPF GET_SCRIPT_BLOCK STR_VAR search_regexp = "RandomWalk()" RET scr_block = script_block start_offset end_offset END
			PATCH_IF ( start_offset >= 0 ) BEGIN
				DELETE_BYTES start_offset end_offset - start_offset
			END
		END
	EXTEND_BOTTOM ~SHPROSBB.bcs~ ~%MOD_FOLDER%/res/near_location.baf~ EVALUATE_BUFFER
<<<<<<<< script.baf
%LNL%%scr_block%
>>>>>>>>
	EXTEND_BOTTOM ~SHPROSBB.bcs~ ~script.baf~ EVALUATE_BUFFER
END

//Scripts Extend
EXTEND_TOP ~%garrick_scr%.bcs~ ~%MOD_FOLDER%/res/beregodt_garrick.baf~ EVALUATE_BUFFER
//Script compile new
OUTER_SPRINT ~prost_bers~ ~SHPROSBB~
OUTER_SPRINT ~prost_ber~ ~SHPROSBB~
OUTER_SPRINT ~x_pos~ ~1615~
OUTER_SPRINT ~y_pos~ ~2777~
OUTER_SPRINT ~face~ ~0~
EXTEND_TOP ~%beregost_area%.bcs~ ~%MOD_FOLDER%/res/exists_prost.baf~ EVALUATE_BUFFER
OUTER_SPRINT quote ~"~

OUTER_SPRINT ~x1p~ ~1425~ OUTER_SPRINT ~y1p~ ~2685~ OUTER_SPRINT ~x2p~ ~1430~ OUTER_SPRINT ~y2p~ ~2705~
OUTER_SPRINT ~s_name~ EVAL ~%garrick_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL08~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%A.baf~ EVALUATE_BUFFER
OUTER_SPRINT ~s_name~ EVAL ~%kagain_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%A.baf~ EVALUATE_BUFFER
OUTER_SPRINT ~s_name~ EVAL ~%coran_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL09~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%A.baf~ EVALUATE_BUFFER
ACTION_IF (~%com_ee_open%~ STR_EQ ~~) BEGIN
	OUTER_SPRINT ~s_name~ EVAL ~%dorn_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
	COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%A.baf~ EVALUATE_BUFFER
END
OUTER_SPRINT quote ~~
OUTER_SPRINT ~s_name~ ~PLAYER1~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/SHPlay1A.baf~ EVALUATE_BUFFER

OUTER_SPRINT ~prost_ber~ ~SHPROSWB~
OUTER_SPRINT ~x_pos~ ~2497~
OUTER_SPRINT ~y_pos~ ~2732~
OUTER_SPRINT ~face~ ~0~
EXTEND_TOP ~%baldur_east%.bcs~ ~%MOD_FOLDER%/res/exists_prost.baf~ EVALUATE_BUFFER
OUTER_SPRINT quote ~"~

OUTER_SPRINT ~x1p~ ~1795~ OUTER_SPRINT ~y1p~ ~2467~ OUTER_SPRINT ~x2p~ ~1770~ OUTER_SPRINT ~y2p~ ~2515~
OUTER_SPRINT ~s_name~ EVAL ~%garrick_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL08~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%X.baf~ EVALUATE_BUFFER
OUTER_SPRINT ~s_name~ EVAL ~%kagain_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%X.baf~ EVALUATE_BUFFER
OUTER_SPRINT ~s_name~ EVAL ~%coran_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL09~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%X.baf~ EVALUATE_BUFFER
ACTION_IF (~%com_ee_open%~ STR_EQ ~~) BEGIN
	OUTER_SPRINT ~s_name~ EVAL ~%dorn_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
	COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%X.baf~ EVALUATE_BUFFER
END
OUTER_SPRINT quote ~~
OUTER_SPRINT ~s_name~ ~PLAYER1~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/SHPlay1X.baf~ EVALUATE_BUFFER

OUTER_SPRINT ~prost_bers~ ~SHPROSBC~
OUTER_SPRINT ~prost_ber~ ~SHPROSBC~
OUTER_SPRINT ~x_pos~ ~1538~
OUTER_SPRINT ~y_pos~ ~2850~
OUTER_SPRINT ~face~ ~12~
EXTEND_TOP ~%beregost_area%.bcs~ ~%MOD_FOLDER%/res/exists_prost.baf~ EVALUATE_BUFFER
OUTER_SPRINT quote ~"~

OUTER_SPRINT ~x1p~ ~1425~ OUTER_SPRINT ~y1p~ ~2685~ OUTER_SPRINT ~x2p~ ~1430~ OUTER_SPRINT ~y2p~ ~2705~
OUTER_SPRINT ~s_name~ EVAL ~%garrick_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL08~

COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%B.baf~ EVALUATE_BUFFER
OUTER_SPRINT ~s_name~ EVAL ~%kagain_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%B.baf~ EVALUATE_BUFFER
OUTER_SPRINT ~s_name~ EVAL ~%coran_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL09~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%B.baf~ EVALUATE_BUFFER
ACTION_IF (~%com_ee_open%~ STR_EQ ~~) BEGIN
	OUTER_SPRINT ~s_name~ EVAL ~%dorn_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
	COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%B.baf~ EVALUATE_BUFFER
END
OUTER_SPRINT quote ~~
OUTER_SPRINT ~s_name~ ~PLAYER1~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/SHPlay1B.baf~ EVALUATE_BUFFER

OUTER_SPRINT ~prost_ber~ ~SHPROSWC~
OUTER_SPRINT ~x_pos~ ~2360~
OUTER_SPRINT ~y_pos~ ~2673~
OUTER_SPRINT ~face~ ~14~
EXTEND_TOP ~%baldur_east%.bcs~ ~%MOD_FOLDER%/res/exists_prost.baf~ EVALUATE_BUFFER
OUTER_SPRINT quote ~"~

OUTER_SPRINT ~x1p~ ~1795~ OUTER_SPRINT ~y1p~ ~2467~ OUTER_SPRINT ~x2p~ ~1770~ OUTER_SPRINT ~y2p~ ~2515~
OUTER_SPRINT ~s_name~ EVAL ~%garrick_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL08~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%Y.baf~ EVALUATE_BUFFER
OUTER_SPRINT ~s_name~ EVAL ~%kagain_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%Y.baf~ EVALUATE_BUFFER
OUTER_SPRINT ~s_name~ EVAL ~%coran_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL09~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%Y.baf~ EVALUATE_BUFFER
ACTION_IF (~%com_ee_open%~ STR_EQ ~~) BEGIN
	OUTER_SPRINT ~s_name~ EVAL ~%dorn_sn%~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
	COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/%s_name%Y.baf~ EVALUATE_BUFFER
END
OUTER_SPRINT quote ~~
OUTER_SPRINT ~s_name~ ~PLAYER1~ OUTER_SPRINT ~s_spell~ ~SHSPL07~
COPY ~%MOD_FOLDER%/res/beregost_prost_cutscene.baf~ ~%MOD_FOLDER%/compile_new/SHPlay1Y.baf~ EVALUATE_BUFFER

OUTER_SPRINT orcnt ~4~
ACTION_IF (~%com_ee_open%~ STR_EQ ~~) BEGIN OUTER_SPRINT orcnt ~5~ END
COPY ~%MOD_FOLDER%/res/reset_ber_prost.baf~ ~%MOD_FOLDER%/res/reset_ber_prost.baf~ EVALUATE_BUFFER
EXTEND_TOP ~%beregost_area%.bcs~ ~%MOD_FOLDER%/res/reset_ber_prost.baf~ EVALUATE_BUFFER
EXTEND_TOP ~%baldur_east%.bcs~ ~%MOD_FOLDER%/res/reset_ber_prost.baf~ EVALUATE_BUFFER

COMPILE ~%MOD_FOLDER%/compile_new~

//create garrick's noble
EXTEND_TOP ~%baldur_west%.bcs~ ~%MOD_FOLDER%/res/baldur_w_garric.baf~ EVALUATE_BUFFER
COMPILE ~%MOD_FOLDER%/res/SHGRNOBL.baf~ EVALUATE_BUFFER

//Dialogs
COPY ~%MOD_FOLDER%/res/dialog.d~ ~%MOD_FOLDER%/res/dialog.d~ EVALUATE_BUFFER
COMPILE ~%MOD_FOLDER%/res/dialog.d~ EVALUATE_BUFFER

/* spells */
//SHSPL07, SHSPL08, SHSPL09
ACTION_DEFINE_ASSOCIATIVE_ARRAY CURE_SPL BEGIN
	~SHSPL07~ => 7
	~SHSPL08~ => 8
	~SHSPL09~ => 9
END
ACTION_PHP_EACH CURE_SPL AS spl => val BEGIN
CREATE SPL ~%spl%~
	WRITE_LONG   0x18 50380800
	WRITE_SHORT  0x1c 4      // Spell type = innate
	WRITE_LONG   0x34 1      // Spell level
	WRITE_LONG   0x64 0x72   // abilities offset
	WRITE_SHORT  0x68 1      // # abilities
	WRITE_LONG   0x6a 0x9a   // effects offset
	INSERT_BYTES 0x72 0x28   // space for ability
	// creating ability structure
	WRITE_SHORT  0x72 1      // type = melee
	WRITE_SHORT  0x74 4      // location = innate
	WRITE_BYTE   0x7e 1      // target = living creature
	WRITE_SHORT  0x80 1      // range
	WRITE_SHORT  0x82 1      // min. level
	WRITE_SHORT  0x84 1      // casting speed
	WRITE_SHORT  0x8e 1      // damage type
	WRITE_SHORT  0x94 1      // # charges
	WRITE_SHORT  0x98 1      // projectile = none
	LPF ADD_SPELL_EFFECT
		INT_VAR
			opcode        = 18
			target        = 1
			power         = 4
			parameter1    = val
			resist_dispel = 2
			duration      = 60
	END
	LPF ADD_SPELL_EFFECT
		INT_VAR
			opcode        = 93
			target        = 3
			power         = 4
			parameter2    = 1
			timing        = 1
			resist_dispel = 2
	END
END
/* creature */
CREATE CRE ~SHGRNOBL~
	WRITE_LONG  0x008 9418
	WRITE_LONG  0x00c 9418
	WRITE_LONG  0x010 83886081
	WRITE_LONG  0x014 11
	WRITE_LONG  0x01c 120
	WRITE_SHORT 0x024 5
	WRITE_SHORT 0x026 5
	WRITE_LONG  0x028 51712
	WRITE_BYTE  0x02c 27
	WRITE_BYTE  0x02d 46
	WRITE_BYTE  0x02e 55
	WRITE_BYTE  0x02f 12
	WRITE_BYTE  0x030 55
	WRITE_BYTE  0x031 20
	WRITE_BYTE  0x032 0
	WRITE_BYTE  0x033 1
	WRITE_SHORT 0x046 10
	WRITE_SHORT 0x048 10
	WRITE_BYTE  0x052 20
	WRITE_BYTE  0x053 1
	FOR ( i = 0x054 ; i < 0x059 ; ++i ) BEGIN
		WRITE_BYTE i  20
	END
	FOR ( i = 0x0a4 ; i < 0x234 ; i = i + 4 ) BEGIN
		WRITE_LONG i minus
	END
	WRITE_LONG  0x0a4 4876
	WRITE_LONG  0x0ec 12554
	WRITE_LONG  0x0f0 12555
	WRITE_LONG  0x10c 4876
	WRITE_LONG  0x198 13529
	WRITE_LONG  0x19c 13527
	FOR ( i = 0x234 ; i < 0x238 ; ++i ) BEGIN
		WRITE_BYTE i 1
	END
	FOR ( i = 0x238 ; i < 0x23f ; ++i ) BEGIN
		PATCH_IF ( i != 0x239 ) BEGIN WRITE_LONG i 9 END
	END
	WRITE_BYTE  0x23f 10
	WRITE_BYTE  0x240 7
	WRITE_BYTE  0x241 255
	WRITE_SHORT 0x242 60
	WRITE_LONG  0x244 0
	WRITE_ASCII 0x248 ~SHOUT~ (8)
	WRITE_ASCII 0x250 ~RUNENEMY~ (8)
	WRITE_ASCII 0x258 ~SHGRNOBL~ (8)
	WRITE_ASCII 0x268 ~WTRUNSGT~ (8)
	WRITE_BYTE  0x270 128
	WRITE_BYTE  0x271 1
	WRITE_BYTE  0x272 1
	WRITE_BYTE  0x273 155
	WRITE_BYTE  0x275 1
	WRITE_BYTE  0x27b 18
	WRITE_BYTE  0x27c minus
	WRITE_BYTE  0x27e minus
	WRITE_ASCII 0x280 ~SHGRNOBL~ (32)
	WRITE_ASCII 0x2cc ~SHGRNOBL~ (8)
	

/** снятие усталости */






