pokecrystal-board/engine/events/odd_egg.asm
Andrew Cook 0f5540740b
Some Mobile code labeling and removed magic numbers (#993)
* Macro loop for EmptyAllSRAMBanks

* Many things labeled and magic numbers removed

* Conform to the style guide

* Rename URLs in mobile_46

* MOBILEAPI_19 -> MOBILEAPI_TELEPHONESTATUS

* Update engine/menus/empty_sram.asm

Co-authored-by: Rangi <35663410+Rangi42@users.noreply.github.com>

* Update ram/wram.asm

Co-authored-by: Rangi <35663410+Rangi42@users.noreply.github.com>

* Update mobile/mobile_46.asm

Co-authored-by: Rangi <35663410+Rangi42@users.noreply.github.com>

* Update mobile/mobile_46.asm

Co-authored-by: Rangi <35663410+Rangi42@users.noreply.github.com>

* Remove underscore from Set*DownloadURL symbols

* Begin Labeling TradeCornerHoldMon routines

* Add wMobileMon party_struct

* Add TRADE_CORNER_REQUEST_LENGTH constant

* Name battle tower action functions

* Label trade corner send/receive buffer

* Label the saved copy of the trade corner pokemon

also fix mailmsg_jp

* So many copies of decodeBase64Character

* Label another buffer

* Fix Alignment and use MOBILE_EMAIL_LENGTH

* `Function11ad8a` -> `MobileIncJumptableIndex`

* Apply Rangi Suggestions pass 1

Co-Authored-By: Rangi <35663410+Rangi42@users.noreply.github.com>

* Apply Suggestions 2

Co-authored-by: Rangi <35663410+Rangi42@users.noreply.github.com>
Co-authored-by: vulcandth <vulcandth@gmail.com>
2022-09-14 19:49:58 -05:00

97 lines
1.9 KiB
NASM

_GiveOddEgg:
; Figure out which egg to give.
; Compare a random word to probabilities out of $ffff.
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.
ldh a, [hRandomSub]
cp d
jr c, .done
jr z, .ok
jr .next
.ok
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 wOddEggOT,
; even though OddEggs does not have data for wOddEggOT
ld de, wOddEgg
ld bc, NICKNAMED_MON_STRUCT_LENGTH + NAME_LENGTH
call CopyBytes
ld a, EGG_TICKET
ld [wCurItem], a
ld a, 1
ld [wItemQuantityChange], a
ld a, -1
ld [wCurItemQuantity], a
ld hl, wNumItems
call TossItem
; load species in wMobileMonSpecies
ld a, EGG
ld [wMobileMonMiscSpecies], a
; load pointer to (wMobileMonSpecies - 1) in wMobileMonSpeciesPointer
ld a, LOW(wMobileMonMiscSpecies - 1)
ld [wMobileMonSpeciesPointer], a
ld a, HIGH(wMobileMonMiscSpecies - 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
ld bc, MON_NAME_LENGTH
call CopyBytes
; load pointer to wTempOddEggNickname in wMobileMonOTPointer
ld a, LOW(wTempOddEggNickname)
ld [wMobileMonOTPointer], a
ld a, HIGH(wTempOddEggNickname)
ld [wMobileMonOTPointer + 1], a
; load pointer to wOddEggName in wMobileMonNicknamePointer
ld a, LOW(wOddEggName)
ld [wMobileMonNicknamePointer], a
ld a, HIGH(wOddEggName)
ld [wMobileMonNicknamePointer + 1], a
farcall AddMobileMonToParty
ret
.Odd:
db "ODD@@@@@@@@@"
INCLUDE "data/events/odd_eggs.asm"