Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; this has been made over the routine that loads an enemy Pokemon
- ; had to find a point to break the routine where
- ; 1: stats had already been loaded into RAM
- ; 2: working with registers bc, de, and hl was not a problem (for convenience)
- #org 3EB10
- jp Main ; jumps to the new stuff
- #org 3FE88
- Main:
- ld a,(D22D)
- cp a, 2 ; are we in a trainer battle?
- jp z, ApplyStatBoosts ; if so the stat boosts are applied, otherwise fallthrough
- #org 3FE90
- Original:
- ; original routine stuff, that is, original 3EB10-3EB37
- ld hl,D073
- ld de,C616
- ld bc,000B
- call Label3026
- ld a,(D204)
- dec a
- ld c,a
- ld b,01
- ld hl,DEB9
- ld a,03
- call Label2D83
- ld hl,D21A
- ld de,C6C1
- ld bc,000A
- call Label3026
- ret ; the original routine finishes at this point
- ApplyStatBoosts:
- ; [1,32]: no boost
- ; [33,34]: boost = level/16 = 2
- ; [35,54]: boost = level/16 + level/32
- ; [55,73]: boost = level/8
- ; [74,77]: boost = level/8 + level/16
- ; [78,100]: boost = level/4
- ld hl,D21B ; point to the first stat LSB (attack)
- ld c,5 ; there are five stats
- ld a,(D143) ; get enemy's level
- level78to100:
- cp a,4E
- jr c,level74to77 ; if not between 78 and 100, skip
- ld d,2 ; level will be halved twice
- call boost ; boost the stats
- jr Original ; we are done
- level74to77:
- cp a,4A
- jr c,level55to73
- ld d,3
- call boost ; level/(2^3) = level/8
- ld hl,D21B
- ld c,5
- ld d,4
- call boost ; level/(2^4) = level/16 --> level/8 + level/16
- jr Original ;
- level55to73:
- cp a,37
- jr c,level36to54
- ld d,3
- call boost
- jr Original
- level35to54:
- cp a,23
- jr c,level33to34
- ld d,4
- call boost
- ld hl,D21B
- ld c,5
- ld d,5
- call boost
- jr Original
- level33to34:
- cp a,21
- jr c,level0to32
- ld d,4
- call boost ; fallthrough
- level0to32:
- jr Original ; no boost if level<33
- #org 3EB13
- boost:
- ld a,(D143) ; get enemy's level (a gets overwritten on every loop)
- ld b,a
- ld e,d ; save d for later
- halve: ; halve level d times
- srl b
- dec d
- jr nz,halve
- ld a,(hl) ; a = attack LSB before boost has been applied
- add a,b
- ld (hl),a ; load a+b into the stat
- jr nc,finish ; overflow check
- dec hl ; if overflow, add 0x100 to the stat
- inc (hl) ; inc MSB
- inc hl ; point to LSB again
- finish:
- inc hl
- inc hl ; point to the next stat LSB
- dec c ; one less stat left
- ld d,e
- jr nz,boost ; loop if not done
- ret ; otherwise return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement