Jump to content

Photo

Adding conditionals to .cre .bcs .dlg patching


9 replies to this topic

#1 agris

agris
  • Members
  • 93 posts
  • Gender:Male
  • Location:the frigid north

Posted 09 November 2018 - 08:41 AM

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, 09 November 2018 - 08:41 AM.


#2 CamDawg

CamDawg

    ALL GLORY TO THE HYPNOTOAD

  • Gibberling Poobah
  • 9763 posts
  • Gender:Not Telling

Posted 09 November 2018 - 09:13 AM

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.


Why is this Hypnotoad video so popu... ALL GLORY TO THE HYPNOTOAD.


#3 agris

agris
  • Members
  • 93 posts
  • Gender:Male
  • Location:the frigid north

Posted 12 November 2018 - 08:55 AM

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

Attached Files



#4 CamDawg

CamDawg

    ALL GLORY TO THE HYPNOTOAD

  • Gibberling Poobah
  • 9763 posts
  • Gender:Not Telling

Posted 12 November 2018 - 09:02 AM

Pretty sure that WRITE_LONG is case-sensitive.


Why is this Hypnotoad video so popu... ALL GLORY TO THE HYPNOTOAD.


#5 Gwendolyne

Gwendolyne
  • Members
  • 222 posts
  • Gender:Male
  • Location:France

Posted 12 November 2018 - 03:26 PM

 

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, 12 November 2018 - 03:26 PM.

CARPE DIEM...



In progress : Menace sur le Royaume de Diamant Éternel

#6 CamDawg

CamDawg

    ALL GLORY TO THE HYPNOTOAD

  • Gibberling Poobah
  • 9763 posts
  • Gender:Not Telling

Posted 12 November 2018 - 03:54 PM

Show-off. :p

 

Thanks Gwendolyne. :)


Why is this Hypnotoad video so popu... ALL GLORY TO THE HYPNOTOAD.


#7 agris

agris
  • Members
  • 93 posts
  • Gender:Male
  • Location:the frigid north

Posted 12 November 2018 - 04:00 PM

I figured it out, thanks :)



#8 agris

agris
  • Members
  • 93 posts
  • Gender:Male
  • Location:the frigid north

Posted 14 November 2018 - 01:22 PM

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


#9 Mike1072

Mike1072
  • Gibberling Poobah
  • 2541 posts
  • Gender:Male
  • Location:Canada

Posted 14 November 2018 - 02:01 PM

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



#10 agris

agris
  • Members
  • 93 posts
  • Gender:Male
  • Location:the frigid north

Posted 14 November 2018 - 03:10 PM

Integer division.

Thanks Mike, I'm a perfect example of how well matlab 'teaches' one to code...



Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users