pokecrystal-board/engine/events/bug_contest/contest_2.asm
Rangi 32ed487a47 Merge branch 'master' of https://github.com/pret/pokecrystal
# Conflicts:
#	audio/engine.asm
#	constants/gfx_constants.asm
#	constants/map_data_constants.asm
#	constants/pokemon_data_constants.asm
#	constants/sprite_constants.asm
#	constants/wram_constants.asm
#	data/maps/data.asm
#	engine/battle/ai/scoring.asm
#	engine/battle/core.asm
#	engine/battle/effect_commands.asm
#	engine/battle/misc.asm
#	engine/battle_anims/getpokeballwobble.asm
#	engine/breeding.asm
#	engine/buy_sell_toss.asm
#	engine/decorations.asm
#	engine/events/battle_tower/battle_tower.asm
#	engine/events/battle_tower/rules.asm
#	engine/events/buena.asm
#	engine/events/bug_contest/contest_2.asm
#	engine/events/daycare.asm
#	engine/events/dratini.asm
#	engine/events/halloffame.asm
#	engine/events/happiness_egg.asm
#	engine/events/kurt.asm
#	engine/events/lucky_number.asm
#	engine/events/magnet_train.asm
#	engine/events/overworld.asm
#	engine/events/pokerus/pokerus.asm
#	engine/events/print_unown.asm
#	engine/events/print_unown_2.asm
#	engine/events/unown_walls.asm
#	engine/item_effects.asm
#	engine/link.asm
#	engine/mon_menu.asm
#	engine/player_object.asm
#	engine/routines/playslowcry.asm
#	engine/scripting.asm
#	engine/search.asm
#	engine/search2.asm
#	engine/specials.asm
#	engine/start_menu.asm
#	engine/timeset.asm
#	home/battle_vars.asm
#	home/map.asm
#	maps/GoldenrodUndergroundSwitchRoomEntrances.asm
#	maps/IlexForest.asm
#	maps/KrissHouse2F.asm
#	maps/Route39Barn.asm
#	mobile/mobile_12_2.asm
#	mobile/mobile_40.asm
#	mobile/mobile_5f.asm
#	wram.asm
2018-02-03 19:42:56 -05:00

124 lines
2.3 KiB
NASM
Executable File

SelectRandomBugContestContestants: ; 139a8
; Select five random people to participate in the current contest.
; First we have to make sure that any old data is cleared away.
ld c, NUM_BUG_CONTESTANTS
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
inc hl
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
cp $ff / NUM_BUG_CONTESTANTS * NUM_BUG_CONTESTANTS
jr nc, .next
ld c, $ff / NUM_BUG_CONTESTANTS
call SimpleDivide
ld e, b
ld d, 0
ld hl, BugCatchingContestantEventFlagTable
add hl, de
add hl, de
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
; 139ed
CheckBugContestContestantFlag: ; 139ed
; Checks the flag of the Bug Catching Contestant whose index is loaded in a.
; Bug: If a >= NUM_BUG_CONTESTANTS when this is called,
; it will read beyond the table.
ld hl, BugCatchingContestantEventFlagTable
ld e, a
ld d, 0
add hl, de
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
ld b, CHECK_FLAG
call EventFlagAction
ret
; 139fe
INCLUDE "data/events/bug_contest_flags.asm"
ContestDropOffMons: ; 13a12
ld hl, wPartyMon1HP
ld a, [hli]
or [hl]
jr z, .fainted
; Mask the rest of your party by setting the count to 1...
ld hl, wPartyCount
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
ld [hl], -1
xor a
ld [wScriptVar], a
ret
.fainted
ld a, $1
ld [wScriptVar], a
ret
; 13a31
ContestReturnMons: ; 13a31
; Restore the species of the second mon.
ld hl, wPartySpecies + 1
ld a, [wBugContestSecondPartySpecies]
ld [hl], a
; Restore the party count, which must be recomputed.
ld b, 1
.loop
ld a, [hli]
cp -1
jr z, .done
inc b
jr .loop
.done
ld a, b
ld [wPartyCount], a
ret
; 13a47