2018-06-24 14:09:41 +00:00
|
|
|
_BugContestJudging:
|
2015-11-11 21:11:08 +00:00
|
|
|
call ContestScore
|
2018-01-02 19:00:14 +00:00
|
|
|
farcall StubbedTrainerRankings_BugContestScore
|
2015-12-19 01:07:09 +00:00
|
|
|
call BugContest_JudgeContestants
|
2017-12-24 18:46:34 +00:00
|
|
|
ld a, [wBugContestThirdPlaceWinnerID]
|
2015-11-11 21:11:08 +00:00
|
|
|
call LoadContestantName
|
2015-11-24 02:19:53 +00:00
|
|
|
ld a, [wBugContestThirdPlaceMon]
|
2020-12-23 21:29:30 +00:00
|
|
|
ld [wNamedObjectIndex], a
|
2015-11-11 21:11:08 +00:00
|
|
|
call GetPokemonName
|
2019-10-20 22:24:17 +00:00
|
|
|
ld hl, ContestJudging_ThirdPlaceText
|
2015-11-11 21:11:08 +00:00
|
|
|
call PrintText
|
2017-12-24 18:46:34 +00:00
|
|
|
ld a, [wBugContestSecondPlaceWinnerID]
|
2015-11-11 21:11:08 +00:00
|
|
|
call LoadContestantName
|
2015-11-24 02:19:53 +00:00
|
|
|
ld a, [wBugContestSecondPlaceMon]
|
2020-12-23 21:29:30 +00:00
|
|
|
ld [wNamedObjectIndex], a
|
2015-11-11 21:11:08 +00:00
|
|
|
call GetPokemonName
|
2019-10-20 22:24:17 +00:00
|
|
|
ld hl, ContestJudging_SecondPlaceText
|
2015-11-11 21:11:08 +00:00
|
|
|
call PrintText
|
2017-12-24 18:46:34 +00:00
|
|
|
ld a, [wBugContestFirstPlaceWinnerID]
|
2015-11-11 21:11:08 +00:00
|
|
|
call LoadContestantName
|
2015-11-24 02:19:53 +00:00
|
|
|
ld a, [wBugContestFirstPlaceMon]
|
2020-12-23 21:29:30 +00:00
|
|
|
ld [wNamedObjectIndex], a
|
2015-11-11 21:11:08 +00:00
|
|
|
call GetPokemonName
|
2019-10-20 22:24:17 +00:00
|
|
|
ld hl, ContestJudging_FirstPlaceText
|
2015-11-11 21:11:08 +00:00
|
|
|
call PrintText
|
2015-12-19 01:07:09 +00:00
|
|
|
jp BugContest_GetPlayersResult
|
2015-11-11 21:11:08 +00:00
|
|
|
|
2019-10-20 22:24:17 +00:00
|
|
|
ContestJudging_FirstPlaceText:
|
|
|
|
text_far _ContestJudging_FirstPlaceText
|
2018-11-17 18:33:03 +00:00
|
|
|
text_asm
|
2015-11-11 21:11:08 +00:00
|
|
|
ld de, SFX_1ST_PLACE
|
|
|
|
call PlaySFX
|
|
|
|
call WaitSFX
|
2019-10-20 22:24:17 +00:00
|
|
|
ld hl, ContestJudging_FirstPlaceScoreText
|
2015-11-11 21:11:08 +00:00
|
|
|
ret
|
|
|
|
|
2019-10-20 22:24:17 +00:00
|
|
|
ContestJudging_FirstPlaceScoreText:
|
|
|
|
text_far _ContestJudging_FirstPlaceScoreText
|
2018-11-17 18:33:03 +00:00
|
|
|
text_end
|
2015-11-11 21:11:08 +00:00
|
|
|
|
2019-10-20 22:24:17 +00:00
|
|
|
ContestJudging_SecondPlaceText:
|
2015-11-11 21:11:08 +00:00
|
|
|
; Placing second was @ , who caught a @ !@ @
|
2019-10-20 22:24:17 +00:00
|
|
|
text_far _ContestJudging_SecondPlaceText
|
2018-11-17 18:33:03 +00:00
|
|
|
text_asm
|
2015-11-11 21:11:08 +00:00
|
|
|
ld de, SFX_2ND_PLACE
|
|
|
|
call PlaySFX
|
|
|
|
call WaitSFX
|
2019-10-20 22:24:17 +00:00
|
|
|
ld hl, ContestJudging_SecondPlaceScoreText
|
2015-11-11 21:11:08 +00:00
|
|
|
ret
|
|
|
|
|
2019-10-20 22:24:17 +00:00
|
|
|
ContestJudging_SecondPlaceScoreText:
|
|
|
|
text_far _ContestJudging_SecondPlaceScoreText
|
2018-11-17 18:33:03 +00:00
|
|
|
text_end
|
2015-11-11 21:11:08 +00:00
|
|
|
|
2019-10-20 22:24:17 +00:00
|
|
|
ContestJudging_ThirdPlaceText:
|
2015-11-11 21:11:08 +00:00
|
|
|
; Placing third was @ , who caught a @ !@ @
|
2019-10-20 22:24:17 +00:00
|
|
|
text_far _ContestJudging_ThirdPlaceText
|
2018-11-17 18:33:03 +00:00
|
|
|
text_asm
|
2015-11-11 21:11:08 +00:00
|
|
|
ld de, SFX_3RD_PLACE
|
|
|
|
call PlaySFX
|
|
|
|
call WaitSFX
|
2019-10-20 22:24:17 +00:00
|
|
|
ld hl, ContestJudging_ThirdPlaceScoreText
|
2015-11-11 21:11:08 +00:00
|
|
|
ret
|
|
|
|
|
2019-10-20 22:24:17 +00:00
|
|
|
ContestJudging_ThirdPlaceScoreText:
|
|
|
|
text_far _ContestJudging_ThirdPlaceScoreText
|
2018-11-17 18:33:03 +00:00
|
|
|
text_end
|
2015-11-11 21:11:08 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
LoadContestantName:
|
2018-01-11 17:00:01 +00:00
|
|
|
; If a = 1, get your name.
|
2020-10-27 02:24:38 +00:00
|
|
|
assert BUG_CONTEST_PLAYER == 1
|
|
|
|
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
|
2016-05-04 15:46:23 +00:00
|
|
|
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.
|
2017-12-24 17:47:30 +00:00
|
|
|
callfar GetTrainerClassName
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wStringBuffer1
|
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
|
2017-12-24 17:47:30 +00:00
|
|
|
callfar GetTrainerName
|
2015-11-24 02:19:53 +00:00
|
|
|
; Append the name to wBugContestWinnerName.
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wStringBuffer1
|
2015-11-11 21:11:08 +00:00
|
|
|
pop de
|
|
|
|
ld bc, NAME_LENGTH - 1
|
|
|
|
jp CopyBytes
|
|
|
|
|
2015-11-24 02:19:53 +00:00
|
|
|
.player
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wPlayerName
|
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
|
|
|
|
|
2018-01-26 03:19:24 +00:00
|
|
|
INCLUDE "data/events/bug_contest_winners.asm"
|
2015-11-11 21:11:08 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
BugContest_GetPlayersResult:
|
2017-12-24 18:46:34 +00:00
|
|
|
ld hl, wBugContestThirdPlaceWinnerID
|
2020-04-18 21:31:51 +00:00
|
|
|
ld de, -BUG_CONTESTANT_SIZE
|
2018-01-11 17:00:01 +00:00
|
|
|
ld b, 3 ; 3rd, 2nd, or 1st
|
2015-11-11 21:11:08 +00:00
|
|
|
.loop
|
|
|
|
ld a, [hl]
|
2018-01-11 17:00:01 +00:00
|
|
|
cp BUG_CONTEST_PLAYER
|
2015-11-11 21:11:08 +00:00
|
|
|
jr z, .done
|
|
|
|
add hl, de
|
|
|
|
dec b
|
|
|
|
jr nz, .loop
|
|
|
|
|
|
|
|
.done
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
BugContest_JudgeContestants:
|
2015-11-24 02:19:53 +00:00
|
|
|
call ClearContestResults
|
|
|
|
call ComputeAIContestantScores
|
2017-12-24 18:46:34 +00:00
|
|
|
ld hl, wBugContestTempWinnerID
|
2018-01-11 17:00:01 +00:00
|
|
|
ld a, BUG_CONTEST_PLAYER
|
2015-11-11 21:11:08 +00:00
|
|
|
ld [hli], a
|
|
|
|
ld a, [wContestMon]
|
|
|
|
ld [hli], a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hProduct]
|
2015-11-11 21:11:08 +00:00
|
|
|
ld [hli], a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh 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
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
ClearContestResults:
|
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
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
DetermineContestWinners:
|
2015-11-24 02:19:53 +00:00
|
|
|
ld de, wBugContestTempScore
|
|
|
|
ld hl, wBugContestFirstPlaceScore
|
2015-11-11 21:11:08 +00:00
|
|
|
ld c, 2
|
2018-07-23 04:25:53 +00:00
|
|
|
call CompareBytes
|
2015-11-24 02:19:53 +00:00
|
|
|
jr c, .not_first_place
|
2017-12-24 18:46:34 +00:00
|
|
|
ld hl, wBugContestSecondPlaceWinnerID
|
|
|
|
ld de, wBugContestThirdPlaceWinnerID
|
2018-01-11 17:00:01 +00:00
|
|
|
ld bc, BUG_CONTESTANT_SIZE
|
2015-11-11 21:11:08 +00:00
|
|
|
call CopyBytes
|
2017-12-24 18:46:34 +00:00
|
|
|
ld hl, wBugContestFirstPlaceWinnerID
|
|
|
|
ld de, wBugContestSecondPlaceWinnerID
|
2018-01-11 17:00:01 +00:00
|
|
|
ld bc, BUG_CONTESTANT_SIZE
|
2015-11-11 21:11:08 +00:00
|
|
|
call CopyBytes
|
2017-12-24 18:46:34 +00:00
|
|
|
ld hl, wBugContestFirstPlaceWinnerID
|
2015-11-24 02:19:53 +00:00
|
|
|
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
|
2018-07-23 04:25:53 +00:00
|
|
|
call CompareBytes
|
2015-11-24 02:19:53 +00:00
|
|
|
jr c, .not_second_place
|
2017-12-24 18:46:34 +00:00
|
|
|
ld hl, wBugContestSecondPlaceWinnerID
|
|
|
|
ld de, wBugContestThirdPlaceWinnerID
|
2018-01-11 17:00:01 +00:00
|
|
|
ld bc, BUG_CONTESTANT_SIZE
|
2015-11-11 21:11:08 +00:00
|
|
|
call CopyBytes
|
2017-12-24 18:46:34 +00:00
|
|
|
ld hl, wBugContestSecondPlaceWinnerID
|
2015-11-24 02:19:53 +00:00
|
|
|
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
|
2018-07-23 04:25:53 +00:00
|
|
|
call CompareBytes
|
2015-11-11 21:11:08 +00:00
|
|
|
jr c, .done
|
2017-12-24 18:46:34 +00:00
|
|
|
ld hl, wBugContestThirdPlaceWinnerID
|
2015-11-24 02:19:53 +00:00
|
|
|
call CopyTempContestant
|
2015-11-11 21:11:08 +00:00
|
|
|
|
|
|
|
.done
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CopyTempContestant:
|
2015-11-24 02:19:53 +00:00
|
|
|
; Could've just called CopyBytes.
|
2017-12-24 18:46:34 +00:00
|
|
|
ld de, wBugContestTempWinnerID
|
2020-03-21 18:01:05 +00:00
|
|
|
rept BUG_CONTESTANT_SIZE - 1
|
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
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
ComputeAIContestantScores:
|
2015-11-11 21:11:08 +00:00
|
|
|
ld e, 0
|
|
|
|
.loop
|
|
|
|
push de
|
2018-01-24 16:17:05 +00:00
|
|
|
call CheckBugContestContestantFlag
|
2015-11-11 21:11:08 +00:00
|
|
|
pop de
|
|
|
|
jr nz, .done
|
|
|
|
ld a, e
|
|
|
|
inc a
|
2016-05-04 15:46:23 +00:00
|
|
|
inc a
|
2017-12-24 18:46:34 +00:00
|
|
|
ld [wBugContestTempWinnerID], a
|
2015-11-11 21:11:08 +00:00
|
|
|
dec a
|
|
|
|
ld c, a
|
|
|
|
ld b, 0
|
|
|
|
ld hl, BugContestantPointers
|
|
|
|
add hl, bc
|
2016-05-04 15:46:23 +00:00
|
|
|
add hl, bc
|
2015-11-11 21:11:08 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
inc hl
|
2016-05-04 15:46:23 +00:00
|
|
|
inc hl
|
2015-11-11 21:11:08 +00:00
|
|
|
.loop2
|
2018-01-11 17:00:01 +00:00
|
|
|
; 0, 1, or 2 for 1st, 2nd, or 3rd
|
2015-11-11 21:11:08 +00:00
|
|
|
call Random
|
|
|
|
and 3
|
|
|
|
cp 3
|
|
|
|
jr z, .loop2
|
|
|
|
ld c, a
|
|
|
|
ld b, 0
|
|
|
|
add hl, bc
|
2016-05-10 16:31:49 +00:00
|
|
|
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
|
2018-01-11 17:00:01 +00:00
|
|
|
; randomly perturb score
|
2015-11-11 21:11:08 +00:00
|
|
|
call Random
|
2018-01-11 17:00:01 +00:00
|
|
|
and %111
|
2015-11-11 21:11:08 +00:00
|
|
|
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
|
2018-01-11 17:00:01 +00:00
|
|
|
cp NUM_BUG_CONTESTANTS
|
2015-11-11 21:11:08 +00:00
|
|
|
jr nz, .loop
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
ContestScore:
|
2015-11-11 21:11:08 +00:00
|
|
|
; Determine the player's score in the Bug Catching Contest.
|
|
|
|
|
|
|
|
xor a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hProduct], a
|
|
|
|
ldh [hMultiplicand], a
|
2015-11-11 21:11:08 +00:00
|
|
|
|
|
|
|
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
|
2018-01-11 17:00:01 +00:00
|
|
|
and %0010
|
2015-11-11 21:11:08 +00:00
|
|
|
add a
|
2016-05-04 15:46:23 +00:00
|
|
|
add a
|
2015-11-11 21:11:08 +00:00
|
|
|
ld c, a
|
|
|
|
|
|
|
|
swap b
|
|
|
|
ld a, b
|
2018-01-11 17:00:01 +00:00
|
|
|
and %0010
|
2015-11-11 21:11:08 +00:00
|
|
|
add a
|
|
|
|
add c
|
|
|
|
ld d, a
|
|
|
|
|
|
|
|
ld a, [wContestMonDVs + 1]
|
|
|
|
ld b, a
|
2018-01-11 17:00:01 +00:00
|
|
|
and %0010
|
2015-11-11 21:11:08 +00:00
|
|
|
ld c, a
|
|
|
|
|
|
|
|
swap b
|
|
|
|
ld a, b
|
2018-01-11 17:00:01 +00:00
|
|
|
and %0010
|
2015-11-11 21:11:08 +00:00
|
|
|
srl a
|
|
|
|
add c
|
2016-05-04 15:46:23 +00:00
|
|
|
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
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.AddContestStat:
|
2015-11-11 21:11:08 +00:00
|
|
|
ld hl, hMultiplicand
|
|
|
|
add [hl]
|
|
|
|
ld [hl], a
|
|
|
|
ret nc
|
|
|
|
dec hl
|
|
|
|
inc [hl]
|
|
|
|
ret
|