pokecrystal-board/engine/events/odd_egg.asm

98 lines
2.0 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
_GiveOddEgg:
; 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 HIGH($ffff)
jr nz, .not_done
ld a, e
cp LOW($ffff)
jr z, .done
.not_done
; Break when the random word <= the next probability in de.
2020-04-16 06:30:50 -07:00
ldh a, [hRandomSub]
cp d
jr c, .done
jr z, .ok
jr .next
.ok
2020-04-16 06:30:50 -07:00
ldh a, [hRandomAdd]
cp e
jr c, .done
jr z, .done
.next
inc bc
jr .loop
.done
ld hl, OddEggs
ld a, NICKNAMED_MON_STRUCT_LENGTH
call AddNTimes
; Writes to wOddEgg, wOddEggName, and wOddEggOTName,
; even though OddEggs does not have data for wOddEggOTName
ld de, wOddEgg
2019-01-03 04:30:44 -08:00
ld bc, NICKNAMED_MON_STRUCT_LENGTH + NAME_LENGTH
call CopyBytes
ld a, EGG_TICKET
2018-01-23 14:39:09 -08:00
ld [wCurItem], a
ld a, 1
ld [wItemQuantityChange], a
ld a, -1
2018-01-23 14:39:09 -08:00
ld [wCurItemQuantity], a
ld hl, wNumItems
call TossItem
; load species in wMobileMonSpecies
ld a, EGG
ld [wMobileMonSpecies], a
; load pointer to (wMobileMonSpecies - 1) in wMobileMonSpeciesPointer
ld a, LOW(wMobileMonSpecies - 1)
ld [wMobileMonSpeciesPointer], a
ld a, HIGH(wMobileMonSpecies - 1)
ld [wMobileMonSpeciesPointer + 1], a
; load pointer to wOddEgg in wMobileMonStructPointer
ld a, LOW(wOddEgg)
ld [wMobileMonStructPointer], a
ld a, HIGH(wOddEgg)
ld [wMobileMonStructPointer + 1], a
; load Odd Egg Name in wTempOddEggNickname
ld hl, .Odd
ld de, wTempOddEggNickname
2018-01-20 09:25:55 -08:00
ld bc, MON_NAME_LENGTH
call CopyBytes
; load pointer to wTempOddEggNickname in wMobileMonOTNamePointer
ld a, LOW(wTempOddEggNickname)
ld [wMobileMonOTNamePointer], a
ld a, HIGH(wTempOddEggNickname)
ld [wMobileMonOTNamePointer + 1], a
; load pointer to wOddEggName in wMobileMonNicknamePointer
ld a, LOW(wOddEggName)
ld [wMobileMonNicknamePointer], a
ld a, HIGH(wOddEggName)
ld [wMobileMonNicknamePointer + 1], a
2017-12-24 09:47:30 -08:00
farcall AddMobileMonToParty
ret
.Odd:
db "ODD@@@@@@@@@"
2018-01-25 19:19:24 -08:00
INCLUDE "data/events/odd_eggs.asm"