2018-06-24 07:09:41 -07:00
|
|
|
SelectRandomBugContestContestants:
|
2015-11-11 13:11:08 -08:00
|
|
|
; Select five random people to participate in the current contest.
|
|
|
|
|
|
|
|
; First we have to make sure that any old data is cleared away.
|
2018-01-11 09:00:01 -08:00
|
|
|
ld c, NUM_BUG_CONTESTANTS
|
2015-11-11 13:11:08 -08:00
|
|
|
ld hl, BugCatchingContestantEventFlagTable
|
|
|
|
.loop1
|
|
|
|
push bc
|
|
|
|
push hl
|
|
|
|
ld e, [hl]
|
|
|
|
inc hl
|
|
|
|
ld d, [hl]
|
|
|
|
ld b, RESET_FLAG
|
|
|
|
call EventFlagAction
|
|
|
|
pop hl
|
|
|
|
inc hl
|
2016-05-04 08:46:23 -07:00
|
|
|
inc hl
|
2015-11-11 13:11:08 -08:00
|
|
|
pop bc
|
|
|
|
dec c
|
|
|
|
jr nz, .loop1
|
|
|
|
|
|
|
|
; Now that that's out of the way, we can get on to the good stuff.
|
|
|
|
ld c, 5
|
|
|
|
.loop2
|
|
|
|
push bc
|
|
|
|
.next
|
|
|
|
; Choose a flag at uniform random to be set.
|
|
|
|
call Random
|
2018-01-11 09:00:01 -08:00
|
|
|
cp $ff / NUM_BUG_CONTESTANTS * NUM_BUG_CONTESTANTS
|
2015-11-11 13:11:08 -08:00
|
|
|
jr nc, .next
|
2018-01-11 09:00:01 -08:00
|
|
|
ld c, $ff / NUM_BUG_CONTESTANTS
|
2015-11-11 13:11:08 -08:00
|
|
|
call SimpleDivide
|
|
|
|
ld e, b
|
|
|
|
ld d, 0
|
|
|
|
ld hl, BugCatchingContestantEventFlagTable
|
|
|
|
add hl, de
|
2016-05-04 08:46:23 -07:00
|
|
|
add hl, de
|
2015-11-11 13:11:08 -08:00
|
|
|
ld e, [hl]
|
|
|
|
inc hl
|
|
|
|
ld d, [hl]
|
|
|
|
push de
|
|
|
|
; If we've already set it, it doesn't count.
|
|
|
|
ld b, CHECK_FLAG
|
|
|
|
call EventFlagAction
|
|
|
|
pop de
|
|
|
|
ld a, c
|
|
|
|
and a
|
|
|
|
jr nz, .next
|
|
|
|
; Set the flag. This will cause that sprite to not be visible in the contest.
|
|
|
|
ld b, SET_FLAG
|
|
|
|
call EventFlagAction
|
|
|
|
pop bc
|
|
|
|
; Check if we're done. If so, return. Otherwise, choose the next victim.
|
|
|
|
dec c
|
|
|
|
jr nz, .loop2
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckBugContestContestantFlag:
|
2015-11-11 13:11:08 -08:00
|
|
|
; Checks the flag of the Bug Catching Contestant whose index is loaded in a.
|
|
|
|
|
2018-01-26 11:36:59 -08:00
|
|
|
; Bug: If a >= NUM_BUG_CONTESTANTS when this is called,
|
|
|
|
; it will read beyond the table.
|
2015-11-11 13:11:08 -08:00
|
|
|
|
|
|
|
ld hl, BugCatchingContestantEventFlagTable
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
|
|
|
add hl, de
|
2016-05-04 08:46:23 -07:00
|
|
|
add hl, de
|
2015-11-11 13:11:08 -08:00
|
|
|
ld e, [hl]
|
|
|
|
inc hl
|
|
|
|
ld d, [hl]
|
|
|
|
ld b, CHECK_FLAG
|
|
|
|
call EventFlagAction
|
|
|
|
ret
|
|
|
|
|
2018-01-25 19:19:24 -08:00
|
|
|
INCLUDE "data/events/bug_contest_flags.asm"
|
2015-11-11 13:11:08 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ContestDropOffMons:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMon1HP
|
2015-11-11 13:11:08 -08:00
|
|
|
ld a, [hli]
|
|
|
|
or [hl]
|
|
|
|
jr z, .fainted
|
|
|
|
; Mask the rest of your party by setting the count to 1...
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyCount
|
2015-11-11 13:11:08 -08:00
|
|
|
ld a, 1
|
|
|
|
ld [hli], a
|
|
|
|
inc hl
|
|
|
|
; ... backing up the second mon index somewhere...
|
|
|
|
ld a, [hl]
|
|
|
|
ld [wBugContestSecondPartySpecies], a
|
|
|
|
; ... and replacing it with the terminator byte
|
2018-01-11 09:00:01 -08:00
|
|
|
ld [hl], -1
|
2015-11-11 13:11:08 -08:00
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wScriptVar], a
|
2015-11-11 13:11:08 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.fainted
|
|
|
|
ld a, $1
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wScriptVar], a
|
2015-11-11 13:11:08 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ContestReturnMons:
|
2015-11-11 13:11:08 -08:00
|
|
|
; Restore the species of the second mon.
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartySpecies + 1
|
2015-11-11 13:11:08 -08:00
|
|
|
ld a, [wBugContestSecondPartySpecies]
|
|
|
|
ld [hl], a
|
|
|
|
; Restore the party count, which must be recomputed.
|
2018-01-11 09:00:01 -08:00
|
|
|
ld b, 1
|
2015-11-11 13:11:08 -08:00
|
|
|
.loop
|
|
|
|
ld a, [hli]
|
2015-12-18 17:07:09 -08:00
|
|
|
cp -1
|
2015-11-11 13:11:08 -08:00
|
|
|
jr z, .done
|
|
|
|
inc b
|
|
|
|
jr .loop
|
|
|
|
|
|
|
|
.done
|
|
|
|
ld a, b
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wPartyCount], a
|
2015-11-11 13:11:08 -08:00
|
|
|
ret
|