shithub: pokered

ref: 7911bc130943392a9aa901139c924aa9658e015f
dir: /engine/battle/15.asm/

View raw version
GainExperience: ; 5524f (15:524f)
	ld a, [W_ISLINKBATTLE] ; $d12b
	cp $4
	ret z
	call Func_5546c
	ld hl, W_PARTYMON1_NUM ; $d16b (aliases: W_PARTYMON1DATA)
	xor a
	ld [wWhichPokemon], a ; $cf92

Func_5525f: ; 5525f (15:525f)
	inc hl
	ld a, [hli]
	or [hl]
	jp z, Func_55436
	push hl
	ld hl, W_PLAYERMONSALIVEFLAGS
	ld a, [wWhichPokemon] ; $cf92
	ld c, a
	ld b, $2
	ld a, $10
	call Predef ; indirect jump to HandleBitArray (f666 (3:7666))
	ld a, c
	and a
	pop hl
	jp z, Func_55436
	ld de, $10
	add hl, de
	ld d, h
	ld e, l
	ld hl, $d002
	ld c, $5
.asm_55285
	ld a, [hli]
	ld b, a
	ld a, [de]
	add b
	ld [de], a
	jr nc, .asm_5529a
	dec de
	ld a, [de]
	inc a
	jr z, .asm_55295
	ld [de], a
	inc de
	jr .asm_5529a
.asm_55295
	ld a, $ff
	ld [de], a
	inc de
	ld [de], a
.asm_5529a
	dec c
	jr z, .asm_552a1
	inc de
	inc de
	jr .asm_55285
.asm_552a1
	xor a
	ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND)
	ld [$ff97], a
	ld a, [$d008]
	ld [$ff98], a
	ld a, [W_ENEMYMONLEVEL] ; $cff3
	ld [H_REMAINDER], a ; $ff99 (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
	call Multiply
	ld a, $7
	ld [H_REMAINDER], a ; $ff99 (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
	ld b, $4
	call Divide
	ld hl, $fff2
	add hl, de
	ld b, [hl]
	inc hl
	ld a, [wPlayerID] ; $d359
	cp b
	jr nz, .asm_552d1
	ld b, [hl]
	ld a, [wPlayerID + 1] ; $d35a
	cp b
	ld a, $0
	jr z, .asm_552d6
.asm_552d1
	call Func_5549f
	ld a, $1
.asm_552d6
	ld [$cf4d], a
	ld a, [W_ISINBATTLE] ; $d057
	dec a
	call nz, Func_5549f
	inc hl
	inc hl
	inc hl
	ld b, [hl]
	ld a, [$ff98]
	ld [$cf4c], a
	add b
	ld [hld], a
	ld b, [hl]
	ld a, [$ff97]
	ld [$cf4b], a
	adc b
	ld [hl], a
	jr nc, .asm_552f8
	dec hl
	inc [hl]
	inc hl
.asm_552f8
	inc hl
	push hl
	ld a, [wWhichPokemon] ; $cf92
	ld c, a
	ld b, $0
	ld hl, W_PARTYMON1 ; $d164
	add hl, bc
	ld a, [hl]
	ld [$d0b5], a
	call GetMonHeader
	ld d, $64
	callab CalcExperience
	ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND)
	ld b, a
	ld a, [$ff97]
	ld c, a
	ld a, [$ff98]
	ld d, a
	pop hl
	ld a, [hld]
	sub d
	ld a, [hld]
	sbc c
	ld a, [hl]
	sbc b
	jr c, .asm_5532e
	ld a, b
	ld [hli], a
	ld a, c
	ld [hli], a
	ld a, d
	ld [hld], a
	dec hl
.asm_5532e
	push hl
	ld a, [wWhichPokemon] ; $cf92
	ld hl, W_PARTYMON1NAME ; $d2b5
	call GetPartyMonName
	ld hl, GainedText
	call PrintText
	xor a
	ld [$cc49], a
	call LoadMonData
	pop hl
	ld bc, $13
	add hl, bc
	push hl
	callba Func_58f43
	pop hl
	ld a, [hl]
	cp d
	jp z, Func_55436
	ld a, [W_CURENEMYLVL] ; $d127
	push af
	push hl
	ld a, d
	ld [W_CURENEMYLVL], a ; $d127
	ld [hl], a
	ld bc, $ffdf
	add hl, bc
	ld a, [hl]
	ld [$d0b5], a
	ld [$d11e], a
	call GetMonHeader
	ld bc, $23
	add hl, bc
	push hl
	ld a, [hld]
	ld c, a
	ld b, [hl]
	push bc
	ld d, h
	ld e, l
	ld bc, $ffee
	add hl, bc
	ld b, $1
	call CalcStats
	pop bc
	pop hl
	ld a, [hld]
	sub c
	ld c, a
	ld a, [hl]
	sbc b
	ld b, a
	ld de, $ffe0
	add hl, de
	ld a, [hl]
	add c
	ld [hld], a
	ld a, [hl]
	adc b
	ld [hl], a
	ld a, [wPlayerMonNumber] ; $cc2f
	ld b, a
	ld a, [wWhichPokemon] ; $cf92
	cp b
	jr nz, .asm_553f7
	ld de, W_PLAYERMONCURHP ; $d015
	ld a, [hli]
	ld [de], a
	inc de
	ld a, [hl]
	ld [de], a
	ld bc, $1f
	add hl, bc
	push hl
	ld de, W_PLAYERMONLEVEL ; $d022
	ld bc, $b
	call CopyData
	pop hl
	ld a, [W_PLAYERBATTSTATUS3] ; $d064
	bit 3, a
	jr nz, .asm_553c8
	ld de, $cd0f
	ld bc, $b
	call CopyData
.asm_553c8
	xor a
	ld [$d11e], a
	callab Func_3ed99
	callab Func_3ed1a
	callab Func_3ee19
	callab Func_3cd60
	callab Func_3ee94
	call SaveScreenTilesToBuffer1
.asm_553f7
	ld hl, GrewLevelText
	call PrintText
	xor a
	ld [$cc49], a
	call LoadMonData
	ld d, $1
	callab PrintStatsBox
	call WaitForTextScrollButtonPress
	call LoadScreenTilesFromBuffer1
	xor a
	ld [$cc49], a
	ld a, [$d0b5]
	ld [$d11e], a
	ld a, $1a
	call Predef ; indirect jump to Func_3af5b (3af5b (e:6f5b))
	ld hl, $ccd3
	ld a, [wWhichPokemon] ; $cf92
	ld c, a
	ld b, $1
	ld a, $10
	call Predef ; indirect jump to HandleBitArray (f666 (3:7666))
	pop hl
	pop af
	ld [W_CURENEMYLVL], a ; $d127

Func_55436: ; 55436 (15:5436)
	ld a, [W_NUMINPARTY] ; $d163
	ld b, a
	ld a, [wWhichPokemon] ; $cf92
	inc a
	cp b
	jr z, .asm_55450
	ld [wWhichPokemon], a ; $cf92
	ld bc, $2c
	ld hl, W_PARTYMON1_NUM ; $d16b (aliases: W_PARTYMON1DATA)
	call AddNTimes
	jp Func_5525f
.asm_55450
	ld hl, W_PLAYERMONSALIVEFLAGS
	xor a
	ld [hl], a
	ld a, [wPlayerMonNumber] ; $cc2f
	ld c, a
	ld b, $1
	push bc
	ld a, $10
	call Predef ; indirect jump to HandleBitArray (f666 (3:7666))
	ld hl, $ccf5
	xor a
	ld [hl], a
	pop bc
	ld a, $10
	jp Predef ; indirect jump to HandleBitArray (f666 (3:7666))

Func_5546c: ; 5546c (15:546c)
	ld a, [W_PLAYERMONSALIVEFLAGS]
	ld b, a
	xor a
	ld c, $8
	ld d, $0
.asm_55475
	xor a
	srl b
	adc d
	ld d, a
	dec c
	jr nz, .asm_55475
	cp $2
	ret c
	ld [$d11e], a
	ld hl, $d002
	ld c, $7
.asm_55488
	xor a
	ld [H_DIVIDEND], a ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
	ld a, [hl]
	ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND)
	ld a, [$d11e]
	ld [H_REMAINDER], a ; $ff99 (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
	ld b, $2
	call Divide
	ld a, [$ff98]
	ld [hli], a
	dec c
	jr nz, .asm_55488
	ret

Func_5549f: ; 5549f (15:549f)
	ld a, [$ff97]
	ld b, a
	ld a, [$ff98]
	ld c, a
	srl b
	rr c
	add c
	ld [$ff98], a
	ld a, [$ff97]
	adc b
	ld [$ff97], a
	ret

GainedText: ; 554b2 (15:54b2)
	TX_FAR _GainedText
	db $08 ; asm
	ld a, [$cc5b]
	ld hl, WithExpAllText
	and a
	ret nz
	ld hl, ExpPointsText
	ld a, [$cf4d]
	and a
	ret z
	ld hl, BoostedText
	ret

WithExpAllText: ; 554cb (15:54cb)
	TX_FAR _WithExpAllText
	db $08 ; asm
	ld hl, ExpPointsText
	ret

BoostedText: ; 554d4 (15:54d4)
	TX_FAR _BoostedText

ExpPointsText: ; 554d8 (15:54d8)
	TX_FAR _ExpPointsText
	db "@"

GrewLevelText: ; 554dd (15:54dd)
	TX_FAR _GrewLevelText
	db $0b
	db "@"