2018-06-24 07:09:41 -07:00
|
|
|
CalcLevel:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wTempMonSpecies]
|
|
|
|
ld [wCurSpecies], a
|
2017-12-15 17:10:54 -08:00
|
|
|
call GetBaseData
|
|
|
|
ld d, 1
|
|
|
|
.next_level
|
|
|
|
inc d
|
|
|
|
ld a, d
|
2017-12-25 12:46:24 -08:00
|
|
|
cp LOW(MAX_LEVEL + 1)
|
2017-12-15 17:10:54 -08:00
|
|
|
jr z, .got_level
|
|
|
|
call CalcExpAtLevel
|
|
|
|
push hl
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wTempMonExp + 2
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 3]
|
2017-12-15 17:10:54 -08:00
|
|
|
ld c, a
|
|
|
|
ld a, [hld]
|
|
|
|
sub c
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 2]
|
2017-12-15 17:10:54 -08:00
|
|
|
ld c, a
|
|
|
|
ld a, [hld]
|
|
|
|
sbc c
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 1]
|
2017-12-15 17:10:54 -08:00
|
|
|
ld c, a
|
|
|
|
ld a, [hl]
|
|
|
|
sbc c
|
|
|
|
pop hl
|
|
|
|
jr nc, .next_level
|
|
|
|
|
|
|
|
.got_level
|
|
|
|
dec d
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CalcExpAtLevel:
|
2017-12-15 17:10:54 -08:00
|
|
|
; (a/b)*n**3 + c*n**2 + d*n - e
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wBaseGrowthRate]
|
2017-12-15 17:10:54 -08:00
|
|
|
add a
|
|
|
|
add a
|
|
|
|
ld c, a
|
|
|
|
ld b, 0
|
|
|
|
ld hl, GrowthRates
|
|
|
|
add hl, bc
|
|
|
|
; Cube the level
|
|
|
|
call .LevelSquared
|
|
|
|
ld a, d
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplier], a
|
2017-12-15 17:10:54 -08:00
|
|
|
call Multiply
|
|
|
|
|
|
|
|
; Multiply by a
|
|
|
|
ld a, [hl]
|
|
|
|
and $f0
|
|
|
|
swap a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplier], a
|
2017-12-15 17:10:54 -08:00
|
|
|
call Multiply
|
|
|
|
; Divide by b
|
|
|
|
ld a, [hli]
|
|
|
|
and $f
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDivisor], a
|
2017-12-15 17:10:54 -08:00
|
|
|
ld b, 4
|
|
|
|
call Divide
|
|
|
|
; Push the cubic term to the stack
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hQuotient + 1]
|
2017-12-15 17:10:54 -08:00
|
|
|
push af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hQuotient + 2]
|
2017-12-15 17:10:54 -08:00
|
|
|
push af
|
2018-08-26 10:49:38 -07:00
|
|
|
ldh a, [hQuotient + 3]
|
|
|
|
push af
|
2017-12-15 17:10:54 -08:00
|
|
|
; Square the level and multiply by the lower 7 bits of c
|
|
|
|
call .LevelSquared
|
|
|
|
ld a, [hl]
|
|
|
|
and $7f
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplier], a
|
2017-12-15 17:10:54 -08:00
|
|
|
call Multiply
|
|
|
|
; Push the absolute value of the quadratic term to the stack
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 1]
|
2017-12-15 17:10:54 -08:00
|
|
|
push af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 2]
|
2017-12-15 17:10:54 -08:00
|
|
|
push af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 3]
|
2017-12-15 17:10:54 -08:00
|
|
|
push af
|
|
|
|
ld a, [hli]
|
|
|
|
push af
|
|
|
|
; Multiply the level by d
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 0], a
|
|
|
|
ldh [hMultiplicand + 1], a
|
2017-12-15 17:10:54 -08:00
|
|
|
ld a, d
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 2], a
|
2017-12-15 17:10:54 -08:00
|
|
|
ld a, [hli]
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplier], a
|
2017-12-15 17:10:54 -08:00
|
|
|
call Multiply
|
|
|
|
; Subtract e
|
|
|
|
ld b, [hl]
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 3]
|
2017-12-15 17:10:54 -08:00
|
|
|
sub b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 2], a
|
2017-12-15 17:10:54 -08:00
|
|
|
ld b, $0
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 2]
|
2017-12-15 17:10:54 -08:00
|
|
|
sbc b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 1], a
|
|
|
|
ldh a, [hProduct + 1]
|
2017-12-15 17:10:54 -08:00
|
|
|
sbc b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand], a
|
2017-12-15 17:10:54 -08:00
|
|
|
; If bit 7 of c is set, c is negative; otherwise, it's positive
|
|
|
|
pop af
|
|
|
|
and $80
|
|
|
|
jr nz, .subtract
|
|
|
|
; Add c*n**2 to (d*n - e)
|
|
|
|
pop bc
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 3]
|
2017-12-15 17:10:54 -08:00
|
|
|
add b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 2], a
|
2017-12-15 17:10:54 -08:00
|
|
|
pop bc
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 2]
|
2017-12-15 17:10:54 -08:00
|
|
|
adc b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 1], a
|
2017-12-15 17:10:54 -08:00
|
|
|
pop bc
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 1]
|
2017-12-15 17:10:54 -08:00
|
|
|
adc b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand], a
|
2017-12-15 17:10:54 -08:00
|
|
|
jr .done_quadratic
|
|
|
|
|
|
|
|
.subtract
|
|
|
|
; Subtract c*n**2 from (d*n - e)
|
|
|
|
pop bc
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 3]
|
2017-12-15 17:10:54 -08:00
|
|
|
sub b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 2], a
|
2017-12-15 17:10:54 -08:00
|
|
|
pop bc
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 2]
|
2017-12-15 17:10:54 -08:00
|
|
|
sbc b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 1], a
|
2017-12-15 17:10:54 -08:00
|
|
|
pop bc
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 1]
|
2017-12-15 17:10:54 -08:00
|
|
|
sbc b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand], a
|
2017-12-15 17:10:54 -08:00
|
|
|
|
|
|
|
.done_quadratic
|
|
|
|
; Add (a/b)*n**3 to (d*n - e +/- c*n**2)
|
|
|
|
pop bc
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 3]
|
2017-12-15 17:10:54 -08:00
|
|
|
add b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 2], a
|
2017-12-15 17:10:54 -08:00
|
|
|
pop bc
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 2]
|
2017-12-15 17:10:54 -08:00
|
|
|
adc b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 1], a
|
2017-12-15 17:10:54 -08:00
|
|
|
pop bc
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hProduct + 1]
|
2017-12-15 17:10:54 -08:00
|
|
|
adc b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand], a
|
2017-12-15 17:10:54 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.LevelSquared:
|
2017-12-15 17:10:54 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 0], a
|
|
|
|
ldh [hMultiplicand + 1], a
|
2017-12-15 17:10:54 -08:00
|
|
|
ld a, d
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 2], a
|
|
|
|
ldh [hMultiplier], a
|
2017-12-15 17:10:54 -08:00
|
|
|
jp Multiply
|
|
|
|
|
|
|
|
INCLUDE "data/growth_rates.asm"
|