pokecrystal/event/bug_contest/judging.asm

396 lines
6.7 KiB
NASM
Raw Normal View History

2015-11-11 21:11:08 +00:00
_BugContestJudging: ; 1369d
call ContestScore
callba TrainerRankings_BugContestScore
2015-12-19 01:07:09 +00:00
call BugContest_JudgeContestants
2015-11-24 02:19:53 +00:00
ld a, [wBugContestThirdPlacePersonID]
2015-11-11 21:11:08 +00:00
call LoadContestantName
2015-11-24 02:19:53 +00:00
ld a, [wBugContestThirdPlaceMon]
ld [wNamedObjectIndexBuffer], a
2015-11-11 21:11:08 +00:00
call GetPokemonName
ld hl, BugContest_ThirdPlaceText
call PrintText
2015-11-24 02:19:53 +00:00
ld a, [wBugContestSecondPlacePersonID]
2015-11-11 21:11:08 +00:00
call LoadContestantName
2015-11-24 02:19:53 +00:00
ld a, [wBugContestSecondPlaceMon]
ld [wNamedObjectIndexBuffer], a
2015-11-11 21:11:08 +00:00
call GetPokemonName
ld hl, BugContest_SecondPlaceText
call PrintText
2015-11-24 02:19:53 +00:00
ld a, [wBugContestFirstPlacePersonID]
2015-11-11 21:11:08 +00:00
call LoadContestantName
2015-11-24 02:19:53 +00:00
ld a, [wBugContestFirstPlaceMon]
ld [wNamedObjectIndexBuffer], a
2015-11-11 21:11:08 +00:00
call GetPokemonName
ld hl, BugContest_FirstPlaceText
call PrintText
2015-12-19 01:07:09 +00:00
jp BugContest_GetPlayersResult
2015-11-11 21:11:08 +00:00
; 136eb
BugContest_FirstPlaceText: ; 0x136eb
text_jump ContestJudging_FirstPlaceText
start_asm
ld de, SFX_1ST_PLACE
call PlaySFX
call WaitSFX
ld hl, BugContest_FirstPlaceScoreText
ret
; 136fd
BugContest_FirstPlaceScoreText: ; 0x136fd
; The winning score was @ points!
text_jump ContestJudging_FirstPlaceScoreText
db "@"
; 0x13702
BugContest_SecondPlaceText: ; 0x13702
; Placing second was @ , who caught a @ !@ @
text_jump ContestJudging_SecondPlaceText
start_asm
ld de, SFX_2ND_PLACE
call PlaySFX
call WaitSFX
ld hl, BugContest_SecondPlaceScoreText
ret
; 13714
BugContest_SecondPlaceScoreText: ; 0x13714
; The score was @ points!
text_jump ContestJudging_SecondPlaceScoreText
db "@"
; 0x13719
BugContest_ThirdPlaceText: ; 0x13719
; Placing third was @ , who caught a @ !@ @
text_jump ContestJudging_ThirdPlaceText
start_asm
ld de, SFX_3RD_PLACE
call PlaySFX
call WaitSFX
ld hl, BugContest_ThirdPlaceScoreText
ret
; 1372b
BugContest_ThirdPlaceScoreText: ; 0x1372b
; The score was @ points!
text_jump ContestJudging_ThirdPlaceScoreText
db "@"
; 0x13730
LoadContestantName: ; 13730
; If a = 0, get your name.
dec a
2015-11-24 02:19:53 +00:00
jr z, .player
2015-11-11 21:11:08 +00:00
; Find the pointer for the trainer class of the Bug Catching Contestant whose ID is in a.
ld c, a
ld b, 0
ld hl, BugContestantPointers
add hl, bc
add hl, bc
2015-11-11 21:11:08 +00:00
ld a, [hli]
ld h, [hl]
ld l, a
; Copy the Trainer Class to c.
ld a, [hli]
ld c, a
; Save hl and bc for later.
push hl
push bc
2015-11-24 02:19:53 +00:00
; Get the Trainer Class name and copy it into wBugContestWinnerName.
2015-11-11 21:11:08 +00:00
callab GetTrainerClassName
ld hl, StringBuffer1
2015-11-24 02:19:53 +00:00
ld de, wBugContestWinnerName
2015-11-11 21:11:08 +00:00
ld bc, TRAINER_CLASS_NAME_LENGTH
call CopyBytes
2015-11-24 02:19:53 +00:00
ld hl, wBugContestWinnerName
2015-11-11 21:11:08 +00:00
; Delete the trailing terminator and replace it with a space.
.next
ld a, [hli]
cp "@"
jr nz, .next
dec hl
ld [hl], " "
inc hl
ld d, h
ld e, l
; Restore the Trainer Class ID and Trainer ID pointer. Save de for later.
pop bc
pop hl
push de
; Get the name of the trainer with class c and ID b.
ld a, [hl]
ld b, a
callab GetTrainerName
2015-11-24 02:19:53 +00:00
; Append the name to wBugContestWinnerName.
2015-11-11 21:11:08 +00:00
ld hl, StringBuffer1
pop de
ld bc, NAME_LENGTH - 1
jp CopyBytes
2015-11-24 02:19:53 +00:00
.player
2015-11-11 21:11:08 +00:00
ld hl, PlayerName
2015-11-24 02:19:53 +00:00
ld de, wBugContestWinnerName
2015-11-11 21:11:08 +00:00
ld bc, NAME_LENGTH
jp CopyBytes
; 13783
INCLUDE "data/bug_contest_winners.asm"
2015-11-11 21:11:08 +00:00
; 13807
2015-12-19 01:07:09 +00:00
BugContest_GetPlayersResult: ; 13807
2015-11-24 02:19:53 +00:00
ld hl, wBugContestThirdPlacePersonID
2015-11-11 21:11:08 +00:00
ld de, -4
ld b, 3
.loop
ld a, [hl]
2015-12-19 01:07:09 +00:00
cp 1 ; Player
2015-11-11 21:11:08 +00:00
jr z, .done
add hl, de
dec b
jr nz, .loop
.done
ret
; 13819
2015-12-19 01:07:09 +00:00
BugContest_JudgeContestants: ; 13819
2015-11-24 02:19:53 +00:00
call ClearContestResults
call ComputeAIContestantScores
ld hl, wBugContestTempPersonID
2015-12-19 01:07:09 +00:00
ld a, 1 ; Player
2015-11-11 21:11:08 +00:00
ld [hli], a
ld a, [wContestMon]
ld [hli], a
ld a, [hProduct]
ld [hli], a
2015-12-19 01:07:09 +00:00
ld a, [hProduct + 1]
2015-11-11 21:11:08 +00:00
ld [hl], a
2015-11-24 02:19:53 +00:00
call DetermineContestWinners
2015-11-11 21:11:08 +00:00
ret
; 13833
2015-11-24 02:19:53 +00:00
ClearContestResults: ; 13833
2015-12-19 01:07:09 +00:00
ld hl, wBugContestResults
ld b, wBugContestWinnersEnd - wBugContestResults
2015-11-11 21:11:08 +00:00
xor a
.loop
ld [hli], a
dec b
jr nz, .loop
ret
; 1383e
2015-11-24 02:19:53 +00:00
DetermineContestWinners: ; 1383e
ld de, wBugContestTempScore
ld hl, wBugContestFirstPlaceScore
2015-11-11 21:11:08 +00:00
ld c, 2
call StringCmp
2015-11-24 02:19:53 +00:00
jr c, .not_first_place
ld hl, wBugContestSecondPlacePersonID
ld de, wBugContestThirdPlacePersonID
2015-11-11 21:11:08 +00:00
ld bc, 4
call CopyBytes
2015-11-24 02:19:53 +00:00
ld hl, wBugContestFirstPlacePersonID
ld de, wBugContestSecondPlacePersonID
2015-11-11 21:11:08 +00:00
ld bc, 4
call CopyBytes
2015-11-24 02:19:53 +00:00
ld hl, wBugContestFirstPlacePersonID
call CopyTempContestant
2015-11-11 21:11:08 +00:00
jr .done
2015-11-24 02:19:53 +00:00
.not_first_place
ld de, wBugContestTempScore
ld hl, wBugContestSecondPlaceScore
2015-11-11 21:11:08 +00:00
ld c, 2
call StringCmp
2015-11-24 02:19:53 +00:00
jr c, .not_second_place
ld hl, wBugContestSecondPlacePersonID
ld de, wBugContestThirdPlacePersonID
2015-11-11 21:11:08 +00:00
ld bc, 4
call CopyBytes
2015-11-24 02:19:53 +00:00
ld hl, wBugContestSecondPlacePersonID
call CopyTempContestant
2015-11-11 21:11:08 +00:00
jr .done
2015-11-24 02:19:53 +00:00
.not_second_place
ld de, wBugContestTempScore
ld hl, wBugContestThirdPlaceScore
2015-11-11 21:11:08 +00:00
ld c, 2
call StringCmp
jr c, .done
2015-11-24 02:19:53 +00:00
ld hl, wBugContestThirdPlacePersonID
call CopyTempContestant
2015-11-11 21:11:08 +00:00
.done
ret
; 138a0
2015-11-24 02:19:53 +00:00
CopyTempContestant: ; 138a0
; Could've just called CopyBytes.
ld de, wBugContestTempPersonID
rept 3
2015-11-11 21:11:08 +00:00
ld a, [de]
inc de
ld [hli], a
2015-11-24 02:19:53 +00:00
endr
2015-11-11 21:11:08 +00:00
ld a, [de]
inc de
ld [hl], a
ret
; 138b0
2015-11-24 02:19:53 +00:00
ComputeAIContestantScores: ; 138b0
2015-11-11 21:11:08 +00:00
ld e, 0
.loop
push de
call Special_CheckBugContestContestantFlag
pop de
jr nz, .done
ld a, e
inc a
inc a
2015-11-24 02:19:53 +00:00
ld [wBugContestTempPersonID], a
2015-11-11 21:11:08 +00:00
dec a
ld c, a
ld b, 0
ld hl, BugContestantPointers
add hl, bc
add hl, bc
2015-11-11 21:11:08 +00:00
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
inc hl
2015-11-11 21:11:08 +00:00
.loop2
call Random
and 3
cp 3
jr z, .loop2
ld c, a
ld b, 0
add hl, bc
add hl, bc
add hl, bc
2015-11-11 21:11:08 +00:00
ld a, [hli]
2015-11-24 02:19:53 +00:00
ld [wBugContestTempMon], a
2015-11-11 21:11:08 +00:00
ld a, [hli]
ld h, [hl]
ld l, a
call Random
and 7
ld c, a
ld b, 0
add hl, bc
ld a, h
2015-11-24 02:19:53 +00:00
ld [wBugContestTempScore], a
2015-11-11 21:11:08 +00:00
ld a, l
2015-11-24 02:19:53 +00:00
ld [wBugContestTempScore + 1], a
2015-11-11 21:11:08 +00:00
push de
2015-11-24 02:19:53 +00:00
call DetermineContestWinners
2015-11-11 21:11:08 +00:00
pop de
.done
inc e
ld a, e
cp 10
jr nz, .loop
ret
; 13900
ContestScore: ; 13900
; Determine the player's score in the Bug Catching Contest.
xor a
ld [hProduct], a
ld [hMultiplicand], a
ld a, [wContestMonSpecies] ; Species
and a
jr z, .done
; Tally the following:
; Max HP * 4
ld a, [wContestMonMaxHP + 1]
call .AddContestStat
ld a, [wContestMonMaxHP + 1]
call .AddContestStat
ld a, [wContestMonMaxHP + 1]
call .AddContestStat
ld a, [wContestMonMaxHP + 1]
call .AddContestStat
; Stats
ld a, [wContestMonAttack + 1]
call .AddContestStat
ld a, [wContestMonDefense + 1]
call .AddContestStat
ld a, [wContestMonSpeed + 1]
call .AddContestStat
ld a, [wContestMonSpclAtk + 1]
call .AddContestStat
ld a, [wContestMonSpclDef + 1]
call .AddContestStat
; DVs
ld a, [wContestMonDVs + 0]
ld b, a
and 2
add a
add a
2015-11-11 21:11:08 +00:00
ld c, a
swap b
ld a, b
and 2
add a
add c
ld d, a
ld a, [wContestMonDVs + 1]
ld b, a
and 2
ld c, a
swap b
ld a, b
and 2
srl a
add c
add c
add d
2015-11-11 21:11:08 +00:00
add d
call .AddContestStat
; Remaining HP / 8
ld a, [wContestMonHP + 1]
srl a
srl a
srl a
call .AddContestStat
; Whether it's holding an item
ld a, [wContestMonItem]
and a
jr z, .done
ld a, 1
call .AddContestStat
.done
ret
; 1397f
.AddContestStat: ; 1397f
ld hl, hMultiplicand
add [hl]
ld [hl], a
ret nc
dec hl
inc [hl]
ret
; 13988