2018-06-24 14:09:41 +00:00
|
|
|
DetermineLinkBattleResult:
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall UpdateEnemyMonInParty
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wPartyMon1HP
|
2016-05-04 15:46:23 +00:00
|
|
|
call .CountMonsRemaining
|
|
|
|
push bc
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wOTPartyMon1HP
|
2016-05-04 15:46:23 +00:00
|
|
|
call .CountMonsRemaining
|
|
|
|
ld a, c
|
|
|
|
pop bc
|
|
|
|
cp c
|
|
|
|
jr z, .even_number_of_mons_remaining
|
|
|
|
jr c, .defeat
|
|
|
|
jr .victory
|
|
|
|
|
|
|
|
.even_number_of_mons_remaining
|
|
|
|
call .BothSides_CheckNumberMonsAtFullHealth
|
|
|
|
jr z, .drawn
|
|
|
|
ld a, e
|
|
|
|
cp $1
|
|
|
|
jr z, .victory
|
|
|
|
cp $2
|
|
|
|
jr z, .defeat
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wPartyMon1HP
|
2016-05-04 15:46:23 +00:00
|
|
|
call .CalcPercentHPRemaining
|
|
|
|
push de
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wOTPartyMon1HP
|
2016-05-04 15:46:23 +00:00
|
|
|
call .CalcPercentHPRemaining
|
|
|
|
pop hl
|
|
|
|
ld a, d
|
|
|
|
cp h
|
|
|
|
jr c, .victory
|
|
|
|
jr z, .compare_lo
|
|
|
|
jr .defeat
|
|
|
|
|
|
|
|
.compare_lo
|
|
|
|
ld a, e
|
|
|
|
cp l
|
|
|
|
jr z, .drawn
|
|
|
|
jr nc, .defeat
|
|
|
|
|
|
|
|
.victory
|
|
|
|
ld a, [wBattleResult]
|
|
|
|
and $f0
|
2018-04-05 15:44:02 +00:00
|
|
|
ld [wBattleResult], a ; WIN
|
2016-05-04 15:46:23 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
.defeat
|
|
|
|
ld a, [wBattleResult]
|
|
|
|
and $f0
|
2018-04-05 15:44:02 +00:00
|
|
|
add LOSE
|
2016-05-04 15:46:23 +00:00
|
|
|
ld [wBattleResult], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.drawn
|
|
|
|
ld a, [wBattleResult]
|
|
|
|
and $f0
|
2018-04-05 15:44:02 +00:00
|
|
|
add DRAW
|
2016-05-04 15:46:23 +00:00
|
|
|
ld [wBattleResult], a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.CountMonsRemaining:
|
2016-05-04 15:46:23 +00:00
|
|
|
ld c, 0
|
|
|
|
ld b, 3
|
|
|
|
ld de, PARTYMON_STRUCT_LENGTH - 1
|
|
|
|
.loop
|
|
|
|
ld a, [hli]
|
|
|
|
or [hl]
|
|
|
|
jr nz, .not_fainted
|
|
|
|
inc c
|
|
|
|
|
|
|
|
.not_fainted
|
|
|
|
add hl, de
|
|
|
|
dec b
|
|
|
|
jr nz, .loop
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.CalcPercentHPRemaining:
|
2016-05-04 15:46:23 +00:00
|
|
|
ld de, 0
|
|
|
|
ld c, $3
|
|
|
|
.loop2
|
|
|
|
ld a, [hli]
|
|
|
|
or [hl]
|
|
|
|
jr z, .next
|
|
|
|
dec hl
|
|
|
|
xor a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hDividend + 0], a
|
2016-05-04 15:46:23 +00:00
|
|
|
ld a, [hli]
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hDividend + 1], a
|
2016-05-04 15:46:23 +00:00
|
|
|
ld a, [hli]
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hDividend + 2], a
|
2016-05-04 15:46:23 +00:00
|
|
|
xor a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hDividend + 3], a
|
2016-05-04 15:46:23 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld b, a
|
|
|
|
ld a, [hld]
|
|
|
|
srl b
|
|
|
|
rr a
|
|
|
|
srl b
|
|
|
|
rr a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hDivisor], a
|
2016-05-04 15:46:23 +00:00
|
|
|
ld b, $4
|
|
|
|
call Divide
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hQuotient + 2]
|
2016-05-04 15:46:23 +00:00
|
|
|
add e
|
|
|
|
ld e, a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hQuotient + 1]
|
2016-05-04 15:46:23 +00:00
|
|
|
adc d
|
|
|
|
ld d, a
|
|
|
|
dec hl
|
|
|
|
|
|
|
|
.next
|
|
|
|
push de
|
|
|
|
ld de, $2f
|
|
|
|
add hl, de
|
|
|
|
pop de
|
|
|
|
dec c
|
|
|
|
jr nz, .loop2
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.BothSides_CheckNumberMonsAtFullHealth:
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wPartyMon1HP
|
2016-05-04 15:46:23 +00:00
|
|
|
call .CheckFaintedOrFullHealth
|
|
|
|
jr nz, .finish ; we have a pokemon that's neither fainted nor at full health
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wOTPartyMon1HP
|
2016-05-04 15:46:23 +00:00
|
|
|
call .CheckFaintedOrFullHealth
|
2018-04-05 15:44:02 +00:00
|
|
|
ld e, $1 ; victory
|
2016-05-04 15:46:23 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
.finish
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wOTPartyMon1HP
|
2016-05-04 15:46:23 +00:00
|
|
|
call .CheckFaintedOrFullHealth
|
2018-04-05 15:44:02 +00:00
|
|
|
ld e, $0 ; drawn
|
2016-05-04 15:46:23 +00:00
|
|
|
ret nz ; we both have pokemon that are neither fainted nor at full health
|
2018-04-05 15:44:02 +00:00
|
|
|
ld e, $2 ; defeat
|
|
|
|
ld a, $1 ; not drawn
|
2016-05-04 15:46:23 +00:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.CheckFaintedOrFullHealth:
|
2016-05-04 15:46:23 +00:00
|
|
|
ld d, 3
|
|
|
|
.loop3
|
|
|
|
ld a, [hli]
|
|
|
|
ld b, a
|
|
|
|
ld a, [hli]
|
|
|
|
ld c, a
|
|
|
|
or b
|
|
|
|
jr z, .fainted_or_full_health
|
|
|
|
ld a, [hli]
|
|
|
|
cp b
|
|
|
|
ret nz
|
|
|
|
ld a, [hld]
|
|
|
|
cp c
|
|
|
|
ret nz
|
|
|
|
|
|
|
|
.fainted_or_full_health
|
|
|
|
push de
|
|
|
|
ld de, PARTYMON_STRUCT_LENGTH - 2
|
|
|
|
add hl, de
|
|
|
|
pop de
|
|
|
|
dec d
|
|
|
|
jr nz, .loop3
|
|
|
|
ret
|