diff options
-rw-r--r-- | constants/pokemon_data_constants.asm | 1 | ||||
-rwxr-xr-x | engine/events/lucky_number.asm | 224 | ||||
-rwxr-xr-x | engine/events/pokerus/check_pokerus.asm | 25 | ||||
-rwxr-xr-x | engine/pokemon/caught_data.asm | 130 | ||||
-rw-r--r-- | main.asm | 13 |
5 files changed, 383 insertions, 10 deletions
diff --git a/constants/pokemon_data_constants.asm b/constants/pokemon_data_constants.asm index da0008b1..bdcb83f7 100644 --- a/constants/pokemon_data_constants.asm +++ b/constants/pokemon_data_constants.asm @@ -108,6 +108,7 @@ PARTY_LENGTH EQU 6 ; boxes MONS_PER_BOX EQU 20 NUM_BOXES EQU 14 +NUM_BOXES_JAPANESE EQU 9 ; hall of fame HOF_MON_LENGTH EQU 1 + 2 + 2 + 1 + (MON_NAME_LENGTH - 1) ; species, id, dvs, level, nick diff --git a/engine/events/lucky_number.asm b/engine/events/lucky_number.asm new file mode 100755 index 00000000..2a6991ac --- /dev/null +++ b/engine/events/lucky_number.asm @@ -0,0 +1,224 @@ +CheckForLuckyNumberWinners: + xor a + ld [wScriptVar], a + ld [wTempByteValue], a + ld a, [wPartyCount] + and a + ret z + ld d, a + ld hl, wPartyMon1ID + ld bc, wPartySpecies +.PartyLoop: + ld a, [bc] + inc bc + cp EGG + call nz, .CompareLuckyNumberToMonID + push bc + ld bc, PARTYMON_STRUCT_LENGTH + add hl, bc + pop bc + dec d + jr nz, .PartyLoop + ld a, BANK(sBox) + call OpenSRAM + ld a, [sBoxCount] + and a + jr z, .SkipOpenBox + ld d, a + ld hl, sBoxMon1ID + ld bc, sBoxSpecies +.OpenBoxLoop: + ld a, [bc] + inc bc + cp EGG + jr z, .SkipOpenBoxMon + call .CompareLuckyNumberToMonID + jr nc, .SkipOpenBoxMon + ld a, TRUE + ld [wTempByteValue], a + +.SkipOpenBoxMon: + push bc + ld bc, BOXMON_STRUCT_LENGTH + add hl, bc + pop bc + dec d + jr nz, .OpenBoxLoop + +.SkipOpenBox: + call CloseSRAM + ld c, $0 +.BoxesLoop: + ld a, [wCurBox] + and $f + cp c + jr z, .SkipBox + ld hl, .BoxBankAddresses + ld b, 0 + add hl, bc + add hl, bc + add hl, bc + ld a, [hli] + call OpenSRAM + ld a, [hli] + ld h, [hl] + ld l, a ; hl now contains the address of the loaded box in SRAM + ld a, [hl] + and a + jr z, .SkipBox ; no mons in this box + push bc + ld b, h + ld c, l + inc bc + ld de, sBoxMon1ID - sBox + add hl, de + ld d, a +.BoxNLoop: + ld a, [bc] + inc bc + cp EGG + jr z, .SkipBoxMon + + call .CompareLuckyNumberToMonID ; sets wScriptVar and wCurPartySpecies appropriately + jr nc, .SkipBoxMon + ld a, TRUE + ld [wTempByteValue], a + +.SkipBoxMon: + push bc + ld bc, BOXMON_STRUCT_LENGTH + add hl, bc + pop bc + dec d + jr nz, .BoxNLoop + pop bc + +.SkipBox: + inc c + ld a, c + cp NUM_BOXES_JAPANESE + jr c, .BoxesLoop + + call CloseSRAM + ld a, [wScriptVar] + and a + ret z ; found nothing + + ld a, [wTempByteValue] + and a + push af + ld a, [wCurPartySpecies] + ld [wNamedObjectIndexBuffer], a + call GetPokemonName + ld hl, .LuckyNumberMatchPartyText + pop af + jr z, .print + ld hl, .LuckyNumberMatchPCText + +.print + jp PrintText + +.CompareLuckyNumberToMonID: + push bc + push de + push hl + ld d, h + ld e, l + ld hl, wBuffer1 + lb bc, PRINTNUM_LEADINGZEROS | 2, 5 + call PrintNum + ld hl, wLuckyNumberDigitsBuffer + ld de, wLuckyIDNumber + lb bc, PRINTNUM_LEADINGZEROS | 2, 5 + call PrintNum + ld b, 5 + ld c, 0 + ld hl, wLuckyNumberDigitsBuffer + 4 + ld de, wBuffer1 + 4 +.loop + ld a, [de] + cp [hl] + jr nz, .done + dec de + dec hl + inc c + dec b + jr nz, .loop + +.done + pop hl + push hl + ld de, MON_SPECIES - MON_ID + add hl, de + ld a, [hl] + pop hl + pop de + push af + ld a, c + ld b, 1 + cp 5 + jr z, .okay + ld b, 2 + cp 3 + jr nc, .okay + ld b, 3 + cp 2 + jr nz, .nomatch + +.okay + inc b + ld a, [wScriptVar] + and a + jr z, .bettermatch + cp b + jr c, .nomatch + +.bettermatch + dec b + ld a, b + ld [wScriptVar], a + pop bc + ld a, b + ld [wCurPartySpecies], a + pop bc + scf + ret + +.nomatch + pop bc + pop bc + and a + ret + +.BoxBankAddresses: + dba sBox1 + dba sBox2 + dba sBox3 + dba sBox4 + dba sBox5 + dba sBox6 + dba sBox7 + dba sBox8 + dba sBox9 + dba sBox10 + dba sBox11 + dba sBox12 + dba sBox13 + dba sBox14 + +.LuckyNumberMatchPartyText: + text_far _LuckyNumberMatchPartyText + text_end + +.LuckyNumberMatchPCText: + text_far _LuckyNumberMatchPCText + text_end + +PrintTodaysLuckyNumber: + ld hl, wStringBuffer3 + ld de, wLuckyIDNumber + lb bc, PRINTNUM_LEADINGZEROS | 2, 5 + call PrintNum + ld a, "@" + ld [wStringBuffer3 + 5], a + ret diff --git a/engine/events/pokerus/check_pokerus.asm b/engine/events/pokerus/check_pokerus.asm new file mode 100755 index 00000000..201a3713 --- /dev/null +++ b/engine/events/pokerus/check_pokerus.asm @@ -0,0 +1,25 @@ +_CheckPokerus: +; Return carry if a monster in your party has Pokerus + +; Get number of monsters to iterate over + ld a, [wPartyCount] + and a + jr z, .NoPokerus + ld b, a +; Check each monster in the party for Pokerus + ld hl, wPartyMon1PokerusStatus + ld de, PARTYMON_STRUCT_LENGTH +.Check: + ld a, [hl] + and $0f ; only the bottom nybble is used + jr nz, .HasPokerus +; Next PartyMon + add hl, de + dec b + jr nz, .Check +.NoPokerus: + and a + ret +.HasPokerus: + scf + ret diff --git a/engine/pokemon/caught_data.asm b/engine/pokemon/caught_data.asm new file mode 100755 index 00000000..408e284a --- /dev/null +++ b/engine/pokemon/caught_data.asm @@ -0,0 +1,130 @@ +CheckPartyFullAfterContest: + ld a, [wContestMon] + and a + jp z, .DidntCatchAnything + ld [wCurPartySpecies], a + ld [wCurSpecies], a + call GetBaseData + ld hl, wPartyCount + ld a, [hl] + cp PARTY_LENGTH + jp nc, .TryAddToBox + inc a + ld [hl], a + ld c, a + ld b, 0 + add hl, bc + ld a, [wContestMon] + ld [hli], a + ld [wCurSpecies], a + ld a, -1 + ld [hl], a + ld hl, wPartyMon1Species + ld a, [wPartyCount] + dec a + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld d, h + ld e, l + ld hl, wContestMon + ld bc, PARTYMON_STRUCT_LENGTH + call CopyBytes + ld a, [wPartyCount] + dec a + ld hl, wPartyMonOT + call SkipNames + ld d, h + ld e, l + ld hl, wPlayerName + call CopyBytes + ld a, [wCurPartySpecies] + ld [wNamedObjectIndexBuffer], a + call GetPokemonName + ld hl, wStringBuffer1 + ld de, wMonOrItemNameBuffer + ld bc, MON_NAME_LENGTH + call CopyBytes + call GiveANickname_YesNo + jr c, .Party_SkipNickname + ld a, [wPartyCount] + dec a + ld [wCurPartyMon], a + xor a + ld [wMonType], a + ld de, wMonOrItemNameBuffer + callfar InitNickname + +.Party_SkipNickname: + ld a, [wPartyCount] + dec a + ld hl, wPartyMonNicknames + call SkipNames + ld d, h + ld e, l + ld hl, wMonOrItemNameBuffer + call CopyBytes + xor a + ld [wContestMonSpecies], a + and a + ld [wScriptVar], a + ret + +.TryAddToBox: + ld a, BANK(sBoxCount) + call OpenSRAM + ld hl, sBoxCount + ld a, [hl] + cp MONS_PER_BOX + call CloseSRAM + jr nc, .BoxFull + xor a + ld [wCurPartyMon], a + ld hl, wContestMon + ld de, wBufferMon + ld bc, BOXMON_STRUCT_LENGTH + call CopyBytes + ld hl, wPlayerName + ld de, wBufferMonOT + ld bc, NAME_LENGTH + call CopyBytes + callfar InsertPokemonIntoBox + ld a, [wCurPartySpecies] + ld [wNamedObjectIndexBuffer], a + call GetPokemonName + call GiveANickname_YesNo + ld hl, wStringBuffer1 + jr c, .Box_SkipNickname + ld a, BOXMON + ld [wMonType], a + ld de, wMonOrItemNameBuffer + callfar InitNickname + ld hl, wMonOrItemNameBuffer + +.Box_SkipNickname: + ld a, BANK(sBoxMonNicknames) + call OpenSRAM + ld de, sBoxMonNicknames + ld bc, MON_NAME_LENGTH + call CopyBytes + call CloseSRAM + +.BoxFull: + xor a + ld [wContestMon], a + ld a, BUGCONTEST_BOXED_MON + ld [wScriptVar], a + ret + +.DidntCatchAnything: + ld a, BUGCONTEST_NO_CATCH + ld [wScriptVar], a + ret + +GiveANickname_YesNo: + ld hl, CaughtAskNicknameText + call PrintText + jp YesNoBox + +CaughtAskNicknameText: + text_far _CaughtAskNicknameText + text_end @@ -372,16 +372,9 @@ INCLUDE "engine/pokemon/mail_2.asm" SECTION "bank31_2", ROMX -_CheckPokerus:: - dr $c7a40, $c7a5a -CheckForLuckyNumberWinners:: - dr $c7a5a, $c7bad -PrintTodaysLuckyNumber:: - dr $c7bad, $c7bbf -CheckPartyFullAfterContest:: - dr $c7bbf, $c7cd0 -GiveANickname_YesNo:: - dr $c7cd0, $c7cde +INCLUDE "engine/events/pokerus/check_pokerus.asm" +INCLUDE "engine/events/lucky_number.asm" +INCLUDE "engine/pokemon/caught_data.asm" SECTION "bank32", ROMX |