pokecrystal-board/engine/odd_eggs.asm
2017-12-24 12:47:30 -05:00

97 lines
2.0 KiB
NASM

GiveOddEgg: ; 1fb4b6
; Figure out which egg to give.
; Compare a random word to
; probabilities out of 0xffff.
call Random
ld hl, OddEggProbabilities
ld c, 0
ld b, c
.loop
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
; Break on $ffff.
ld a, d
cp $ffff / $100
jr nz, .not_done
ld a, e
cp $ffff % $100
jr z, .done
.not_done
; Break when [hRandom] <= de.
ld a, [hRandom + 1]
cp d
jr c, .done
jr z, .ok
jr .next
.ok
ld a, [hRandom + 0]
cp e
jr c, .done
jr z, .done
.next
inc bc
jr .loop
.done
ld hl, OddEggs
ld a, OddEgg2 - OddEgg1
call AddNTimes
ld de, OddEggSpecies
ld bc, PARTYMON_STRUCT_LENGTH + 2 * PKMN_NAME_LENGTH
call CopyBytes
ld a, EGG_TICKET
ld [CurItem], a
ld a, 1
ld [wItemQuantityChangeBuffer], a
ld a, -1
ld [CurItemQuantity], a
ld hl, NumItems
call TossItem
; load species in wcd2a
ld a, EGG
ld [wMobileMonSpeciesBuffer], a
; load pointer to (wMobileMonSpeciesBuffer - 1) in wMobileMonSpeciesPointerBuffer
ld a, (wMobileMonSpeciesBuffer - 1) % $100
ld [wMobileMonSpeciesPointerBuffer], a
ld a, (wMobileMonSpeciesBuffer - 1) / $100
ld [wMobileMonSpeciesPointerBuffer + 1], a
; load pointer to OddEggSpecies in wMobileMonStructurePointerBuffer
ld a, OddEggSpecies % $100
ld [wMobileMonStructurePointerBuffer], a
ld a, OddEggSpecies / $100
ld [wMobileMonStructurePointerBuffer + 1], a
; load Odd Egg Name in wTempOddEggNickname
ld hl, .Odd
ld de, wTempOddEggNickname
ld bc, PKMN_NAME_LENGTH
call CopyBytes
; load pointer to wTempOddEggNickname in wMobileMonOTNamePointerBuffer
ld a, wTempOddEggNickname % $100
ld [wMobileMonOTNamePointerBuffer], a
ld a, wTempOddEggNickname / $100
ld [wMobileMonOTNamePointerBuffer + 1], a
; load pointer to wOddEggName in wMobileMonNicknamePointerBuffer
ld a, wOddEggName % $100
ld [wMobileMonNicknamePointerBuffer], a
ld a, wOddEggName / $100
ld [wMobileMonNicknamePointerBuffer + 1], a
farcall AddMobileMonToParty
ret
; 1fb546
.Odd:
db "ODD@@@@@@@@@"
INCLUDE "data/odd_eggs.asm"