ref: b1dc88b7281e0486cb952c8f8c62dab705eb4b9d
parent: 40eae001a168502782338340db9f47216ae850f4
author: PikalaxALT <PikalaxALT@gmail.com>
date: Tue Nov 3 07:36:33 EST 2015
Experience and level calculations
--- a/battle/core.asm
+++ b/battle/core.asm
@@ -7543,7 +7543,7 @@
call GetBaseData
push bc
ld d, MAX_LEVEL
- callab Function50e47
+ callab CalcExpAtLevel
pop bc
ld hl, $000a
add hl, bc
@@ -7572,7 +7572,7 @@
xor a ; PARTYMON
ld [MonType], a
predef CopyPkmnToTempMon
- callab Function50e1b
+ callab CalcLevel
pop bc
ld hl, PartyMon1Level - PartyMon1
add hl, bc
@@ -7864,7 +7864,7 @@
.asm_3f186
ld d, MAX_LEVEL
- callab Function50e47
+ callab CalcExpAtLevel
ld a, [hMultiplicand]
ld b, a
ld a, [$ffb5]
@@ -7887,7 +7887,7 @@
ld [hld], a
.asm_3f1a8
- callab Function50e1b
+ callab CalcLevel
ld a, d
pop bc
pop de
@@ -8235,7 +8235,7 @@
push de
ld d, b
push de
- callab Function50e47
+ callab CalcExpAtLevel
pop de
ld hl, hMultiplicand
ld a, [hli]
@@ -8245,7 +8245,7 @@
ld a, [hl]
push af
inc d
- callab Function50e47
+ callab CalcExpAtLevel
ld hl, $ffb6
ld a, [hl]
ld [$ffba], a
--- a/engine/pack.asm
+++ b/engine/pack.asm
@@ -1407,11 +1407,11 @@
call DisableLCD
ld hl, PackMenuGFX
ld de, VTiles2
- ld bc, $0600
+ ld bc, $60 tiles
ld a, BANK(PackMenuGFX)
call FarCopyBytes
hlcoord 0, 1
- ld bc, 220
+ ld bc, 11 * SCREEN_WIDTH
ld a, $24
call ByteFill
hlcoord 5, 1
@@ -1419,12 +1419,12 @@
call ClearBox
hlcoord 0, 0
ld a, $28
- ld c, $14
-.asm_1098a
+ ld c, SCREEN_WIDTH
+.loop
ld [hli], a
inc a
dec c
- jr nz, .asm_1098a
+ jr nz, .loop
call DrawPocketName
call Function109a5
hlcoord 0, 12
--- a/gfx/overworld/sprite_headers.asm
+++ b/gfx/overworld/sprite_headers.asm
@@ -5,7 +5,7 @@
sprite_header: MACRO
dw \1
- db \2 * $40, BANK(\1)
+ db \2 * 4 tiles, BANK(\1)
db \3, \4
ENDM
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -1382,7 +1382,7 @@
ld [CurPartyLevel], a
push de
ld d, a
- callba Function50e47
+ callba CalcExpAtLevel
pop de
ld a, PartyMon1Exp - PartyMon1
--- a/macros.asm
+++ b/macros.asm
@@ -175,4 +175,5 @@
endr
ENDM
+tiles EQUS "* $10"
tile EQUS "+ $10 *"
--- a/main.asm
+++ b/main.asm
@@ -8068,7 +8068,7 @@
push de
ld a, [CurPartyLevel]
ld d, a
- callab Function50e47
+ callab CalcExpAtLevel
pop de
ld a, [hMultiplicand]
ld [de], a
@@ -8527,7 +8527,7 @@
add $2
ld [MonType], a
predef CopyPkmnToTempMon
- callab Function50e1b
+ callab CalcLevel
ld a, d
ld [CurPartyLevel], a
pop hl
@@ -8777,7 +8777,7 @@
callba HealPartyMon
ld a, [CurPartyLevel]
ld d, a
- callab Function50e47
+ callab CalcExpAtLevel
pop bc
ld hl, $0008
add hl, bc
@@ -8892,7 +8892,7 @@
push de
ld a, [CurPartyLevel]
ld d, a
- callab Function50e47
+ callab CalcExpAtLevel
pop de
ld a, [hMultiplicand]
ld [de], a
@@ -10134,7 +10134,7 @@
ld de, TempMon
ld bc, $0020
call CopyBytes
- callab Function50e1b
+ callab CalcLevel
ld a, [wBreedMon1Level]
ld b, a
ld a, d
@@ -10149,7 +10149,7 @@
ld de, TempMon
ld bc, $0020
call CopyBytes
- callab Function50e1b
+ callab CalcLevel
ld a, [wBreedMon2Level]
ld b, a
ld a, d
@@ -16891,7 +16891,7 @@
emote_header: MACRO
dw \1
- db \2 * $10, BANK(\1)
+ db \2 tiles, BANK(\1)
dw \3
ENDM
@@ -20345,7 +20345,7 @@
ld [hl], a
ld a, [CurPartyLevel]
ld d, a
- callab Function50e47
+ callab CalcExpAtLevel
ld hl, wEggMonExp
ld a, [hMultiplicand]
ld [hli], a
@@ -44560,7 +44560,7 @@
jr z, .asm_4e111
inc a
ld d, a
- callba Function50e47
+ callba CalcExpAtLevel
rept 2
ld hl, TempMonExp + 2
endr
@@ -48102,35 +48102,35 @@
; 50e1b
-Function50e1b: ; 50e1b
+CalcLevel: ; 50e1b
ld a, [TempMonSpecies]
ld [CurSpecies], a
call GetBaseData
ld d, 1
-.asm_50e26
+.next_level
inc d
ld a, d
cp (MAX_LEVEL + 1) % $100
- jr z, .asm_50e45
- call Function50e47
+ jr z, .got_level
+ call CalcExpAtLevel
push hl
ld hl, TempMonExp + 2
- ld a, [hMultiplicand + 2]
+ ld a, [hProduct + 3]
ld c, a
ld a, [hld]
sub c
- ld a, [hMultiplicand + 1]
+ ld a, [hProduct + 2]
ld c, a
ld a, [hld]
sbc c
- ld a, [hMultiplicand + 0]
+ ld a, [hProduct + 1]
ld c, a
ld a, [hl]
sbc c
pop hl
- jr nc, .asm_50e26
+ jr nc, .next_level
-.asm_50e45
+.got_level
dec d
ret
; 50e47
@@ -48137,8 +48137,8 @@
-Function50e47: ; 50e47
-
+CalcExpAtLevel: ; 50e47
+; (a/b)*n**3 + c*n**2 + d*n - e
ld a, [BaseGrowthRate]
rept 2
add a
@@ -48147,23 +48147,25 @@
ld b, 0
ld hl, GrowthRates
add hl, bc
- call Function50eed
+; Cube the level
+ call .LevelSquared
ld a, d
ld [hMultiplier], a
call Multiply
+; Multiply by a
ld a, [hl]
and $f0
swap a
ld [hMultiplier], a
call Multiply
-
+; Divide by b
ld a, [hli]
and $f
ld [hDivisor], a
- ld b, $4
+ ld b, 4
call Divide
-
+; Push the cubic term to the stack
ld a, [hQuotient + 0]
push af
ld a, [hQuotient + 1]
@@ -48170,13 +48172,13 @@
push af
ld a, [hQuotient + 2]
push af
-
- call Function50eed
+; Square the level and multiply by the lower 7 bits of c
+ call .LevelSquared
ld a, [hl]
and $7f
ld [hMultiplier], a
call Multiply
-
+; Push the absolute value of the quadratic term to the stack
ld a, [hProduct + 1]
push af
ld a, [hProduct + 2]
@@ -48185,7 +48187,7 @@
push af
ld a, [hli]
push af
-
+; Multiply the level by d
xor a
ld [hMultiplicand + 0], a
ld [hMultiplicand + 1], a
@@ -48194,68 +48196,70 @@
ld a, [hli]
ld [hMultiplier], a
call Multiply
-
+; Subtract e
ld b, [hl]
ld a, [hProduct + 3]
sub b
- ld [$ffb6], a
+ ld [hMultiplicand + 2], a
ld b, $0
ld a, [hProduct + 2]
sbc b
- ld [$ffb5], a
+ ld [hMultiplicand + 1], a
ld a, [hProduct + 1]
sbc b
ld [hMultiplicand], a
-
+; If bit 7 of c is set, c is negative; otherwise, it's positive
pop af
and $80
- jr nz, .asm_50ec8
-
+ jr nz, .subtract
+; Add c*n**2 to (d*n - e)
pop bc
- ld a, [$ffb6]
+ ld a, [hProduct + 3]
add b
- ld [$ffb6], a
+ ld [hMultiplicand + 2], a
pop bc
- ld a, [$ffb5]
+ ld a, [hProduct + 2]
adc b
- ld [$ffb5], a
+ ld [hMultiplicand + 1], a
pop bc
- ld a, [hMultiplicand]
+ ld a, [hProduct + 1]
adc b
ld [hMultiplicand], a
- jr .asm_50eda
+ jr .done_quadratic
-.asm_50ec8
+.subtract
+; Subtract c*n**2 from (d*n - e)
pop bc
- ld a, [$ffb6]
+ ld a, [hProduct + 3]
sub b
- ld [$ffb6], a
+ ld [hMultiplicand + 2], a
pop bc
- ld a, [$ffb5]
+ ld a, [hProduct + 2]
sbc b
- ld [$ffb5], a
+ ld [hMultiplicand + 1], a
pop bc
- ld a, [hMultiplicand]
+ ld a, [hProduct + 1]
sbc b
ld [hMultiplicand], a
-.asm_50eda
+.done_quadratic
+; Add (a/b)*n**3 to (d*n - e +/- c*n**2)
pop bc
- ld a, [$ffb6]
+ ld a, [hProduct + 3]
add b
- ld [$ffb6], a
+ ld [hMultiplicand + 2], a
pop bc
- ld a, [$ffb5]
+ ld a, [hProduct + 2]
adc b
- ld [$ffb5], a
+ ld [hMultiplicand + 1], a
pop bc
- ld a, [hMultiplicand]
+ ld a, [hProduct + 1]
adc b
ld [hMultiplicand], a
ret
; 50eed
-Function50eed: ; 50eed
+.LevelSquared: ; 50eed
xor a
ld [hMultiplicand + 0], a
ld [hMultiplicand + 1], a