Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Made over HalveMoney routine at 0x12513
- ; Instead of halving current money upon losing
- ; substract 4*(l^2) from current money
- ; where l is the level of the highest leveled Pokemon in the party
- ld hl,DCFE ; pokemon 1 level
- ld de,0030 ; pokemon n level - pokemon n-1 level
- ld a,(DCD7) ; party count
- ld b,a
- ; get highest level from party
- loop:
- cp (hl)
- jr nc, .keepold
- ld a,(hl)
- .keepold
- add hl,de
- dec b
- jr nz,loop
- ; get level^2 * 4
- ld (FF00+B6),a ; highest level into hMultiplicand
- ld (FF00+B7),a ; highest level into hMultiplier
- xor a
- ld (FF00+B4),a ; hMultiplicand
- ld (FF00+B5),a ; hMultiplicand
- call Multiply_3119 ; level^2 at FFB5-FFB6
- ld a,4
- ld (FF00+B7),a
- call Multiply_3119 ; level^2 * 4 at FFB5-FFB6
- ; substract it from money
- ld hl, Money+2 ; lowest byte
- ld a,(FF00+B6)
- ld b,a
- ld a,(hl)
- sub b
- ld (hld),a
- ld a,(FF00+B5)
- ld b,a
- ld a,(hl) ; middle byte
- sbc b
- ld (hld),a
- ld b,0
- ld a,(hl) ; highest byte
- sbc b
- ld (hl),a
- ret nc
- ; prevent underflow
- xor a
- ld (hli),a
- ld (hli),a
- ld (hl),a
- ret
- ; *************************************************************************************************************************************
- ; asm_3ffaa
- ; multiply exp about to gain by enemy's level and divide by player's level (maximum factor is 2/1)
- ; only as long as enemy's level is the highest of the two (never disfavors the player)
- ; output result at ff00 + b5 and ff00 + b6
- ; (D213) = EnemyMonLevel
- ; (D109) = CurPartyMon
- call z, DoubleExp ; this is what we overwrote with jp 7FAA (2nd part of Lucky Egg check)
- ; (ff00+B5) = hMultiplicandMiddleByte = (at this point) ExpHighByte
- ; (ff00+B6) = hMultiplicandLowByte = (at this point) ExpLowByte
- push af
- push bc
- push de
- push hl
- ld a,(D109)
- ld hl,DCCE ; PartyMon1Level - 30
- ld bc,0030
- inc a
- .loop
- ; make hl point to level of CurPartyMon
- add hl,bc
- dec a
- jr nz, .loop
- ld b,(hl) ; level of CurPartyMon into b
- ld a,(D213) ; EnemyMonLevel into a
- cp b
- jr c, .finish ; do nothing if player's level is higher than enemy's level
- sla b ; level of CurPartyMon * 2 into b
- cp b
- jr nc, .double ; if enemy's level is at least twice as high as player's level, exp is only doubled
- ld (ff00+B7),a ; EnemyMonLevel into hMultiplier
- xor a
- ld (ff00+B4),a ; just in case...
- call Multiply ; returns Experience * EnemyMonLevel at hProduct = hDividend
- ld a,(hl) ;
- ld (ff00+B7),a ; level of CurPartyMon into hDivisor
- ld b,4
- call Divide ; returns Experience * EnemyMonLevel / level of CurPartyMon at hQuotient
- ; ff00 + B4 should always contain 00, so there's nothing else to do
- .finish
- pop hl
- pop de
- pop bc
- pop af
- jp 6EF8 ; go back to where we jumped from
- .double
- ld a,2
- ld (ff00+B7),a
- call Multiply ; double experience
- jr .finish
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement