Skip to content

Increase the total amount of money that can be won from trainer battles

mattcit edited this page May 2, 2024 · 1 revision

The maximum amount of money you can win from a trainer battle is 9999 (actually only 9900 unless the enemy's last Pokemon is over level 100). This can be increased to 999999 by editing the following file:

Make the following changes:

.LastLoop
; update wAmountMoneyWon addresses (money to win) based on enemy's level
	ld hl, wTrainerBaseMoney + 1
-	ld c, 2 ; wAmountMoneyWon is a 3-byte number
+	ld c, 3 ; wAmountMoneyWon is a 3-byte number
	push bc
	predef AddBCDPredef
	pop bc
	inc de
	inc de
+	inc de ; increment de one more time to prevent the previous memory address (wEscapedFromBattle) from being affected
	dec b
	jr nz, .LastLoop ; repeat wCurEnemyLVL times
	ret

That's it. This will allow wAmountMoneyWon to be a 6 digit number (3 bytes) instead of a 4 digit number (2 bytes).

This will not actually change the amount of money won for any trainer battles in the game though. To change the amount of money won from a trainer battle, edit the following file:

Look for the trainer class you want to change. You can now use a 6 digit number for the trainer's base money.

Note: the last two digits are always ignored by the calculation, but they are required.

-pic_money BugCatcherPic,   1000
+pic_money BugCatcherPic,   999900

The calculation for wAmountMoneyWon is:

trainer base money * level of enemy's last Pokemon

So for example, if you make the change above to the Bug Catcher class, and the player beats a Bug Catcher whose last Pokemon is level 11, the amount money won would be:

9999 * 11 = 109,989

Full Explanation

The problem with the code in /engine/battle/read_trainer_party.asm is the line ld c, 2. The AddBCD routine uses the value in register c to determine the length (in bytes) of the number that's being added to (whatever address is loaded into register de). In this case, the number that's being added to is wAmountMoneyWon, which is a 3 byte memory address. So because the value in register c is set to 2, the AddBCD routine will only add to the last 2 bytes (4 digits) of wAmountMoneyWon. That means that the maximum value for wAmountMoneyWon can only be 009999.

By changing the value of register c to 3, the AddBCD routine can add to all 3 bytes of wAmountMoneyWon, which increases the maximum value to 999999.

After changing the value of register c to 3, you have to add another inc de line because the AddBCD routine shifts the memory address in de down by one every loop. Changing the value of register c to 3 means that AddBCD is doing one extra loop, so it will leave the memory address in de down 3 from where it started (the last byte of wAmountMoneyWon. If you only inc de two times after calling AddBCD, you'll be one memory address too low and on the next loop AddBCD will alter the memory address right before wAmountMoneyWon (which is wEscapedFromBattle). Changing the value in that memory address will instantly leave the battle (as if the player used a Poke Doll, Whirlwind etc).

It's hard to say if this was a mistake by the programmers, or if this was how wAmountMoneyWon was intended to be calculated. The trainer base money value is a 3 byte bcd3, but the wTrainerBaseMoney memory address where those values are loaded into is only a 2 byte address, which seems odd.

Clone this wiki locally