Jump to content

Adding conditionals to .cre .bcs .dlg patching


agris

Recommended Posts

I would like to modify DEF JAM v7 such that creature and quest XP is only reduced if the non-reduced values are over a certain threshold, such as only creature's worth over 1335 xp have their xp reduced, and quests over 20001 xp. This is preserve the early-game level curve in BG1. I will be reducing both by 25%, so those thresholds correspond to 1000 and 15000 xp, respectively.

Looking at setup-xpmod.tp2, the relevant files to modify are creature_xp.tph and quest_xp.tph.

creature_xp.tph:

INCLUDE ~xpmod/functions/round_xp.tph~

DEFINE_ACTION_FUNCTION adjust_creature_xp
	INT_VAR
	percentage_modifier =	100
BEGIN
	COPY_EXISTING_REGEXP ~.+\.cre~ ~override~
		SET xp = LONG_AT (0x0014) * percentage_modifier / 100
		LAUNCH_PATCH_FUNCTION round_xp
			INT_VAR
			xp
			RET
			xp = round_xp
		END
		WRITE_LONG 0x14 xp
	BUT_ONLY_IF_IT_CHANGES
END

If I'm reading this correctly, "xp" is the new, reduced value. So if I add "PATCH_IF (xp > 1000)" such that the tph reads

INCLUDE ~xpmod/functions/round_xp.tph~

DEFINE_ACTION_FUNCTION adjust_creature_xp
	INT_VAR
	percentage_modifier =	100
BEGIN
	COPY_EXISTING_REGEXP ~.+\.cre~ ~override~
                PATCH_IF (xp > 1000)
                BEGIN
			SET xp = LONG_AT (0x0014) * percentage_modifier / 100
			LAUNCH_PATCH_FUNCTION round_xp
				INT_VAR
				xp
				RET
				xp = round_xp
			END
		        WRITE_LONG 0x14 xp
		END
	BUT_ONLY_IF_IT_CHANGES
END

That should enforce the threshold I want, correct? Only creatures with XP values of 1335 or greater will have >1000 XP after a 25% reduction.

Is the PATCH_IF nested in the correct location, and are the new BEGIN/END blocks required for this to work?

Edited by agris
Link to comment

The problem is that xp is not yet set when you do that check so WeiDU will throw an error or use the xp value from the previous crerature. Change that

 

PATCH_IF (xp > 1000)

 

to

 

PATCH_IF (LONG_AT (0x0014) > 1000) BEGIN

 

And yeah, PATCH_IF needs a BEGIN/END.

Link to comment

The problem is that xp is not yet set when you do that check so WeiDU will throw an error or use the xp value from the previous crerature. Change that

 

PATCH_IF (xp > 1000)

 

to

 

PATCH_IF (LONG_AT (0x0014) > 1000) BEGIN

 

And yeah, PATCH_IF needs a BEGIN/END.

Hey @CamDawg, I'm getting a parse error on line 17 of this code. I think it's related to my BEGIN/END blocks, but I'm not positive. The assumptions are that there is a 25% reduction in XP that only kicks in for creatures over 1500 XP, and there's a smoothing function that gradually reduces XP from 1000 to 1500 XP.

INCLUDE ~xpmod/functions/round_xp.tph~

DEFINE_ACTION_FUNCTION adjust_creature_xp
	INT_VAR
	percentage_modifier =	100
BEGIN
	COPY_EXISTING_REGEXP ~.+\.cre~ ~override~
               PATCH_IF (LONG_AT (0x0014) > 1000) && (LONG_AT (0x0014) < 1499)
               BEGIN
                        SET xp = LONG_AT (0x0014) * 0.0005 + 1.5
                        LAUNCH_PATCH_FUNCTION round_xp
                         	INT_VAR
                         	xp
                         	RET
                         	xp = round_xp
               		END
               		WRITE_long 0x14 xp
               END
        BUT_ONLY_IF_IT_CHANGES
END

BEGIN
	COPY_EXISTING_REGEXP ~.+\.cre~ ~override~
               PATCH_IF (LONG_AT (0x0014) > 1499)
               BEGIN
                        SET xp = LONG_AT (0x0014) * percentage_modifier / 100
                        LAUNCH_PATCH_FUNCTION round_xp
                         	INT_VAR
                         	xp
                         	RET
                         	xp = round_xp
               		END
               		WRITE_long 0x14 xp
               END
        BUT_ONLY_IF_IT_CHANGES
END

SETUP-XPMOD.DEBUG

Link to comment

 

The problem is that xp is not yet set when you do that check so WeiDU will throw an error or use the xp value from the previous crerature. Change that

 

PATCH_IF (xp > 1000)

 

to

 

PATCH_IF (LONG_AT (0x0014) > 1000) BEGIN

 

And yeah, PATCH_IF needs a BEGIN/END.

Hey @CamDawg, I'm getting a parse error on line 17 of this code. I think it's related to my BEGIN/END blocks, but I'm not positive. The assumptions are that there is a 25% reduction in XP that only kicks in for creatures over 1500 XP, and there's a smoothing function that gradually reduces XP from 1000 to 1500 XP.

INCLUDE ~xpmod/functions/round_xp.tph~

DEFINE_ACTION_FUNCTION adjust_creature_xp
	INT_VAR
	percentage_modifier =	100
BEGIN
	COPY_EXISTING_REGEXP ~.+\.cre~ ~override~
               PATCH_IF (LONG_AT (0x0014) > 1000) && (LONG_AT (0x0014) < 1499)
               BEGIN
                        SET xp = LONG_AT (0x0014) * 0.0005 + 1.5
                        LAUNCH_PATCH_FUNCTION round_xp
                         	INT_VAR
                         	xp
                         	RET
                         	xp = round_xp
               		END
               		WRITE_long 0x14 xp
               END
        BUT_ONLY_IF_IT_CHANGES
END

BEGIN
	COPY_EXISTING_REGEXP ~.+\.cre~ ~override~
               PATCH_IF (LONG_AT (0x0014) > 1499)
               BEGIN
                        SET xp = LONG_AT (0x0014) * percentage_modifier / 100
                        LAUNCH_PATCH_FUNCTION round_xp
                         	INT_VAR
                         	xp
                         	RET
                         	xp = round_xp
               		END
               		WRITE_long 0x14 xp
               END
        BUT_ONLY_IF_IT_CHANGES
END

 

The first red END (line #20) is the END of DEFINE_ACTION_FUNCTION.

WeiDU does not understand the next bloc beginning with BEGIN

Edited by Gwendolyne
Link to comment

I spoke too soon. This executes without any error, but the PATCH_IF block with my smoothing function for 1000 - 1500 XP doesn't have any effect. Only the second PATCH_IF, for creatures over 1500 XP, is executing.

INCLUDE ~xpmod/functions/round_xp.tph~

DEFINE_ACTION_FUNCTION adjust_creature_xp
	INT_VAR
	percentage_modifier =	100
BEGIN
	COPY_EXISTING_REGEXP ~.+\.cre~ ~override~
               PATCH_IF ((LONG_AT (0x0014) > 1000) && (LONG_AT (0x0014) < 1501))
               BEGIN
                        SET xp = LONG_AT (0x0014) * ((1 - 2) * (LONG_AT (0x0014) / 2000) + (3 / 2))
                        LAUNCH_PATCH_FUNCTION round_xp
                         	INT_VAR
                         	xp
                         	RET
                         	xp = round_xp
               		END
               		WRITE_LONG 0x14 xp
               END
               PATCH_IF (LONG_AT (0x0014) > 1500)
               BEGIN
                        SET xp = LONG_AT (0x0014) * percentage_modifier / 100
                        LAUNCH_PATCH_FUNCTION round_xp
                         	INT_VAR
                         	xp
                         	RET
                         	xp = round_xp
               		END
               		WRITE_LONG 0x14 xp
               END
        BUT_ONLY_IF_IT_CHANGES
END
Link to comment

SET xp = LONG_AT (0x0014) * ((1 - 2) * (LONG_AT (0x0014) / 2000) + (3 / 2))

Integer division.

 

-1 * 1250 / 2000 = 0.

3 / 2 = 1.

1250 * (0 + 1) = 1250

 

For greater precision, multiply your values and divide them at the end.

 

-1 * 1250 * 1000 / 2000 = -625

3 * 1000 / 2 = 1500

1250 * (-625 + 1500) / 1000 = 1093

Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...