diff options
Diffstat (limited to 'engine/events')
49 files changed, 3428 insertions, 485 deletions
diff --git a/engine/events/battle_tower/battle_tower.asm b/engine/events/battle_tower/battle_tower.asm new file mode 100755 index 000000000..93b283d27 --- /dev/null +++ b/engine/events/battle_tower/battle_tower.asm @@ -0,0 +1,1669 @@ +Special_BattleTowerRoomMenu: ; 1700b0 +; special + call InitBattleTowerChallengeRAM + farcall _BattleTowerRoomMenu + ret +; 1700ba + +Special_Function1700ba: ; 1700ba + call InitBattleTowerChallengeRAM + farcall Function11811a + ret +; 1700c4 + +Function1700c4: ; 1700c4 + ld a, [rSVBK] + push af + ld a, $3 + ld [rSVBK], a + + call Function17042c + + ld a, $5 + call GetSRAMBank + ld a, $1 + ld [$be45], a + xor a + ld [$be46], a + ld hl, w3_dffc + ld de, $aa41 + ld bc, 4 + call CopyBytes + ld hl, w3_d202Name + ld de, $aa8e + ld bc, 7 * $cc ; length of battle tower struct from japanese games? + call CopyBytes + ld hl, $aa5d ; some sort of count + ld a, [hl] + inc [hl] + inc hl + sla a + sla a + ld e, a + ld d, $0 + add hl, de + ld e, l + ld d, h + ld hl, w3_dffc + ld bc, 4 + call CopyBytes + call CloseSRAM + pop af + ld [rSVBK], a + ret +; 170114 + +Special_Function170114: ; 170114 + call InitBattleTowerChallengeRAM + call .Function170121 + farcall Function11805f + ret +; 170121 + +.Function170121: ; 170121 + ld a, $5 + call GetSRAMBank + ld hl, $a948 + ld de, wMisc + ld bc, $f6 ; 246 + call CopyBytes + call CloseSRAM + call Function170c8b + ret +; 170139 + +Function170139: ; 170139 +; Convert the 4-digit decimal number at 5:aa41 into binary + ld a, $5 + call GetSRAMBank + ld de, $aa41 + ld h, $0 + ld l, h + ld bc, 1000 + call .DecToBin + ld bc, 100 + call .DecToBin + ld bc, 10 + call .DecToBin + ld a, [de] + ld c, a + ld b, $0 + add hl, bc + call CloseSRAM +; Store that number in wMisc + ld a, h + ld [wMisc], a + ld a, l + ld [wMisc + 1], a + ld hl, wBT_OTTempPkmn1DVs + ld a, [PlayerID] + ld [hli], a + ld a, [PlayerID + 1] + ld [hli], a + ld a, [wSecretID] + ld [hli], a + ld a, [wSecretID + 1] + ld [hli], a + ld e, l + ld d, h + ld hl, PlayerName + ld bc, NAME_LENGTH_JAPANESE - 1 + call CopyBytes + ld bc, PlayerID + ld de, wPlayerGender + farcall GetMobileOTTrainerClass + ld de, wBT_OTTempPkmn1CaughtGender + ld a, c + ld [de], a + inc de + ld a, LOW(PartyMons) + ld [wcd49], a + ld a, HIGH(PartyMons) + ld [wcd4a], a + ld a, LOW(PartyMonNicknames) + ld [wcd4b], a + ld a, HIGH(PartyMonNicknames) + ld [wcd4c], a + ld a, 3 +.CopyLoop: + push af + ld a, [wcd49] + ld l, a + ld a, [wcd4a] + ld h, a + ld bc, PARTYMON_STRUCT_LENGTH + call CopyBytes + ld a, l + ld [wcd49], a + ld a, h + ld [wcd4a], a + ld a, [wcd4b] + ld l, a + ld a, [wcd4c] + ld h, a + ld bc, $0006 + call CopyBytes + ld a, l + ld [wcd4b], a + ld a, h + ld [wcd4c], a + pop af + dec a + jr nz, .CopyLoop + ld a, $4 + call GetSRAMBank + ld hl, $a013 + ld bc, $24 + call CopyBytes + call CloseSRAM + ld a, $5 + call GetSRAMBank + ld hl, $a894 + ld bc, NAME_LENGTH_JAPANESE + call CopyBytes + ld hl, wMisc + ld de, $a948 + ld bc, $f6 + call CopyBytes + call CloseSRAM + ret +; 17020c + +.DecToBin: ; 17020c + ld a, [de] + inc de + and a + ret z + +.digit_loop + add hl, bc + dec a + jr nz, .digit_loop + ret +; 170215 + +Special_BattleTowerBattle: ; 170215 + xor a + ld [wBattleTowerBattleEnded], a + call _BattleTowerBattle + ret +; 17021d + +DummySpecial_17021d: ; 17021d + ret +; 17021e + +InitBattleTowerChallengeRAM: ; 17021e + xor a + ld [wBattleTowerBattleEnded], a + ld [wNrOfBeatenBattleTowerTrainers], a + ld [wcf65], a + ld [wcf66], a + ret +; 17022c + +_BattleTowerBattle: ; 17022c +.loop + call .do_dw + call DelayFrame + ld a, [wBattleTowerBattleEnded] + cp $1 + jr nz, .loop + ret +; 17023a + +.do_dw ; 17023a + ld a, [wBattleTowerBattleEnded] + ld e, a + ld d, 0 + ld hl, .dw + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + jp hl +; 170249 + +.dw ; 170249 + dw RunBattleTowerTrainer + dw SkipBattleTowerTrainer +; 17024d + +RunBattleTowerTrainer: ; 17024d + ld a, [Options] + push af + ld hl, Options + set BATTLE_SHIFT, [hl] ; SET MODE + + ld a, [InBattleTowerBattle] + push af + or $1 + ld [InBattleTowerBattle], a + + xor a + ld [wLinkMode], a + farcall Special_StubbedTrainerRankings_Healings + farcall HealParty + call ReadBTTrainerParty + call Clears5_a89a + + predef Predef_StartBattle + + farcall LoadPokemonData + farcall HealParty + ld a, [wBattleResult] + ld [ScriptVar], a + and a + jr nz, .lost + ld a, BANK(sNrOfBeatenBattleTowerTrainers) + call GetSRAMBank + ld a, [sNrOfBeatenBattleTowerTrainers] + ld [wNrOfBeatenBattleTowerTrainers], a + call CloseSRAM + ld hl, StringBuffer3 + ld a, [wNrOfBeatenBattleTowerTrainers] + add "1" + ld [hli], a + ld a, "@" + ld [hl], a + +.lost + pop af + ld [InBattleTowerBattle], a + pop af + ld [Options], a + ld a, $1 + ld [wBattleTowerBattleEnded], a + ret + + +ReadBTTrainerParty: ; 1702b7 +; Initialise the BattleTower-Trainer and his Pkmn + call CopyBTTrainer_FromBT_OT_TowBT_OTTemp + +; Check the nicknames for illegal characters, and replace bad nicknames +; with their species names. + ld de, wBT_OTTempPkmn1Name ; $c643 + ld c, PKMN_NAME_LENGTH + farcall CheckStringForErrors + jr nc, .skip_mon_1 + + ld a, [wBT_OTTempPkmn1] + ld [wNamedObjectIndexBuffer], a + call GetPokemonName + ld l, e + ld h, d + ld de, wBT_OTTempPkmn1Name ; $c643 + ld bc, PKMN_NAME_LENGTH + call CopyBytes + +.skip_mon_1 + ld de, wBT_OTTempPkmn2Name ; $c67e + ld c, PKMN_NAME_LENGTH + farcall CheckStringForErrors + jr nc, .skip_mon_2 + ld a, [wBT_OTTempPkmn2] ; [$c64e] + ld [wNamedObjectIndexBuffer], a + call GetPokemonName + ld l, e + ld h, d + ld de, wBT_OTTempPkmn2Name ; $c67e + ld bc, PKMN_NAME_LENGTH + call CopyBytes + +.skip_mon_2 + ld de, wBT_OTTempPkmn3Name ; $c686 + 51 = $c6b9 + ld c, PKMN_NAME_LENGTH + farcall CheckStringForErrors + jr nc, .skip_mon_3 + ld a, [wBT_OTTempPkmn3] ; [$c689] + ld [wNamedObjectIndexBuffer], a + call GetPokemonName + ld l, e + ld h, d + ld de, wBT_OTTempPkmn3Name ; $c686 + 51 = $c6b9 + ld bc, PKMN_NAME_LENGTH + call CopyBytes + +.skip_mon_3 +; Add the terminator character to each of these names + ld a, "@" + ld [wBT_OTTempPkmn1NameEnd - 1], a ; $c64d + ld [wBT_OTTempPkmn2NameEnd - 1], a ; $c688 + ld [wBT_OTTempPkmn3NameEnd - 1], a ; $c68a + 57 = $c6c3 +; Fix errors in the movesets + call CheckBTMonMovesForErrors +; Repair the trainer name if needed, then copy it to OTPlayerName + ld de, wBT_OTTempName + ld c, NAME_LENGTH - 1 + farcall CheckStringForErrors + jr nc, .trainer_name_okay + ld hl, BT_ChrisName + jr .done_trainer_name + +.trainer_name_okay + ld hl, wBT_OTTempName ; 0xc608 + +.done_trainer_name + ld de, OTPlayerName + ld bc, NAME_LENGTH - 1 + call CopyBytes + ld a, "@" + ld [de], a + + ld hl, wBT_OTTempTrainerClass + ld a, [hli] + ld [OtherTrainerClass], a + ld a, LOW(OTPartyMonNicknames) + ld [BGMapBuffer], a + ld a, HIGH(OTPartyMonNicknames) + ld [BGMapBuffer + 1], a + + ; Copy Pkmn into Memory from the address in hl + ld de, OTPartyMon1Species + ld bc, OTPartyCount + ld a, BATTLETOWER_NROFPKMNS ; Number of Pkmn the BattleTower-Trainer has + ld [bc], a + inc bc +.otpartymon_loop + push af + ld a, [hl] + ld [bc], a + inc bc + push bc + ld bc, PARTYMON_STRUCT_LENGTH + call CopyBytes + push de + ld a, [BGMapBuffer] + ld e, a + ld a, [BGMapBuffer + 1] + ld d, a + ld bc, PKMN_NAME_LENGTH + call CopyBytes + ld a, e + ld [BGMapBuffer], a + ld a, d + ld [BGMapBuffer + 1], a + pop de + pop bc + pop af + dec a + and a + jr nz, .otpartymon_loop + ld a, -1 + ld [bc], a + ret +; 170394 + +ValidateBTParty: ; 170394 +; Check for and fix errors in party data + ld hl, wBT_OTTempPkmn1Species + ld d, BATTLETOWER_NROFPKMNS +.pkmn_loop + push de + push hl + ld b, h + ld c, l + ld a, [hl] + and a +idx = $ff +rept ($ff +- NUM_POKEMON) + jr z, .invalid + cp idx +idx = idx +- 1 +endr + jr nz, .valid + +.invalid + ld a, SMEARGLE + ld [hl], a + +.valid + ld [CurSpecies], a + call GetBaseData + ld a, $5 + call GetSRAMBank + ld a, [$b2fb] ; s5_b2fb ; max level? + call CloseSRAM + ld e, a + ld hl, MON_LEVEL + add hl, bc + ld a, [hl] + cp MIN_LEVEL + ld a, MIN_LEVEL + jr c, .load + ld a, [hl] + cp e + jr c, .dont_load + ld a, e + +.load + ld [hl], a + +.dont_load + ld [CurPartyLevel], a + ld hl, MON_MOVES + add hl, bc + ld d, NUM_MOVES - 1 + ld a, [hli] + and a + jr z, .not_move + cp NUM_ATTACKS + 1 + jr nc, .not_move + jr .valid_move + +.not_move + dec hl + ld a, POUND + ld [hli], a + xor a + ld [hli], a + ld [hli], a + ld [hl], a + jr .done_moves + +.valid_move + ld a, [hl] + cp NUM_ATTACKS + 1 + jr c, .next + ld [hl], $0 + +.next + inc hl + dec d + jr nz, .valid_move + +.done_moves + ld hl, MON_MAXHP + add hl, bc + ld d, h + ld e, l + push hl + push de + ld hl, MON_STAT_EXP - 1 + add hl, bc + ld b, $1 + predef Predef_CalcPkmnStats + pop de + pop hl + dec de + dec de + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + pop hl + ld bc, PARTYMON_STRUCT_LENGTH + PKMN_NAME_LENGTH + add hl, bc + pop de + dec d + jp nz, .pkmn_loop + ret +; 170426 + +BT_ChrisName: ; 170426 + db "CHRIS@" +; 17042c + +Function17042c: ; 17042c + ld hl, w3_d202TrainerData + ld a, BATTLETOWER_NROFTRAINERS +.loop + push af + push hl + ld c, BATTLETOWER_TRAINERDATALENGTH / 2 +.loop2 + ; First byte is a comparison value. + ld a, [hli] + ld b, a + ; Second byte is a lookup index. + ld a, [hli] + and a + jr z, .empty + cp 15 + jr nc, .copy_data + + push hl + ld hl, Unknown_170470 + dec a + ld e, a + ld d, 0 + add hl, de + ld a, [hl] + pop hl + + ; If Unknown_170470[a-1] <= b, overwrite the current trainer's data + ; with Unknown17047e, and exit the inner loop. + cp b + jr c, .copy_data + jr z, .copy_data + jr .next_iteration + +.empty + ; If a == 0 and b >= $fc, overwrite the current trainer's data with + ; Unknown17047e, and exit the inner loop. + ld a, b + cp $fc + jr nc, .copy_data + +.next_iteration + dec c + jr nz, .loop2 + jr .next_trainer + +.copy_data + pop de + push de + ld hl, Unknown_17047e + ld bc, BATTLETOWER_TRAINERDATALENGTH + call CopyBytes + +.next_trainer + pop hl + ld de, BATTLE_TOWER_STRUCT_LENGTH + add hl, de + pop af + dec a + jr nz, .loop + ret +; 170470 + +INCLUDE "data/battle_tower/unknown_levels.asm" + + +CopyBTTrainer_FromBT_OT_TowBT_OTTemp: ; 1704a2 +; copy the BattleTower-Trainer data that lies at 'BT_OTTrainer' to 'wBT_OTTemp' + ld a, [rSVBK] + push af + ld a, BANK(BT_OTTrainer) + ld [rSVBK], a + + ld hl, BT_OTTrainer + ld de, wBT_OTTemp + ld bc, BATTLE_TOWER_STRUCT_LENGTH + call CopyBytes + + pop af + ld [rSVBK], a + + ld a, BANK(sBattleTowerChallengeState) + call GetSRAMBank + ld a, BATTLETOWER_CHALLENGE_IN_PROGESS + ld [sBattleTowerChallengeState], a + ld hl, sNrOfBeatenBattleTowerTrainers + inc [hl] + call CloseSRAM +SkipBattleTowerTrainer: ; 1704c9 + ret +; 1704ca + +Unreferenced_Function1704ca: ; 1704ca + ld a, [$be46] + cp $7 + jr c, .asm_1704d3 + ld a, $6 + +.asm_1704d3 + ld hl, $afce + ld de, -$e0 +.asm_1704d9 + and a + jr z, .asm_1704e0 + add hl, de + dec a + jr .asm_1704d9 + +.asm_1704e0 + ret +; 1704e1 + +UnusedSpecial_Function1704e1: ; 1704e1 + call SpeechTextBox + call FadeToMenu + call InitBattleTowerChallengeRAM + call .JumptableLoop + call CloseSubmenu + ret +; 1704f1 + +.JumptableLoop: ; 1704f1 + call ClearBGPalettes + call ClearSprites + call ClearScreen +.loop + call JoyTextDelay + ld a, [wJumptableIndex] + bit 7, a + jr nz, .done + call .DoJumptable + farcall ReloadMapPart + jr .loop + +.done + ret +; 170510 + +.DoJumptable: ; 170510 + ld a, [wJumptableIndex] + ld e, a + ld d, 0 + ld hl, .dw + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + jp hl +; 17051f + +.dw ; 17051f + dw .Jumptable_0 + dw .Jumptable_1 + dw .Jumptable_2 +; 170525 + +.Jumptable_0: ; 170525 + ld a, $5 + call GetSRAMBank + + ld hl, $a89c + ld de, StringBuffer3 + ld bc, $16 + call CopyBytes + + ld hl, $a8b2 + ld de, wMisc + ld bc, $0096 + call CopyBytes + + call CloseSRAM + hlcoord 1, 1 + ld de, StringBuffer3 + call PlaceString + hlcoord 1, 3 + ld de, .String_Mail + call PlaceString + hlcoord 4, 3 + ld de, StringBuffer4 + call PlaceString + hlcoord 8, 3 + ld de, .String_PastReaders + call PlaceString + call .DrawBorder + call .PlaceTextItems + jr .NextJumptableFunction + + +.Jumptable_1: + call SetPalettes + call .NextJumptableFunction + + +.Jumptable_2: + ld hl, hJoyPressed + ld a, [hl] + and A_BUTTON + jr nz, .pressed_a_or_b + ld a, [hl] + and B_BUTTON + jr nz, .pressed_a_or_b + ld a, [hl] + and D_UP + jr nz, .pressed_up + ld a, [hl] + and D_DOWN + jr nz, .pressed_down + ret + +.pressed_up + ld a, [wNrOfBeatenBattleTowerTrainers] + and a + ret z + sub 15 + ld [wNrOfBeatenBattleTowerTrainers], a + call .PlaceTextItems + ret + +.pressed_down + ld a, [wNrOfBeatenBattleTowerTrainers] + cp 60 + ret z + add 15 + ld [wNrOfBeatenBattleTowerTrainers], a + call .PlaceTextItems + ret + +.pressed_a_or_b + ld hl, wJumptableIndex + set 7, [hl] + ret + +.NextJumptableFunction: + ld hl, wJumptableIndex + inc [hl] + ret +; 1705b7 + +.DrawBorder: ; 1705b7 + hlcoord 0, 4 + ld a, "┌" + ld [hli], a + ld c, SCREEN_WIDTH - 2 +.top_border_loop + ld a, "─" + ld [hli], a + dec c + jr nz, .top_border_loop + ld a, "┐" + ld [hli], a + ld de, SCREEN_WIDTH + ld c, 12 +.left_border_loop + ld a, "│" + ld [hl], a + add hl, de + dec c + jr nz, .left_border_loop + ld a, "└" + ld [hli], a + ld c, SCREEN_WIDTH - 2 +.bottom_border_loop + ld a, "─" + ld [hli], a + dec c + jr nz, .bottom_border_loop + ld a, "┘" + ld [hl], a + ld de, -SCREEN_WIDTH + add hl, de + ld c, 12 +.right_border_loop + ld a, "│" + ld [hl], a + add hl, de + dec c + jr nz, .right_border_loop + ret +; 1705f0 + +.PlaceTextItems: ; 1705f0 + call .ClearBox + call .PlaceUpDownArrows + ld a, $50 + ld [wcd4e], a + ld hl, wMisc + ld a, [wNrOfBeatenBattleTowerTrainers] + ld c, a + xor a + ld b, a + add hl, bc + push hl + pop bc + hlcoord 1, 6 + ld a, 6 +.loop1 + push af + push hl + ld a, 3 +.loop2 + push af + ld de, wcd49 + ld a, [bc] + and a + jr z, .fill_with_e3 +; .copy + ld a, 5 +.loop3a + push af + ld a, [bc] + ld [de], a + inc bc + inc de + pop af + dec a + jr nz, .loop3a + jr .rejoin + +.fill_with_e3 + ld a, 5 +.loop3b + push af + ld a, $e3 + ld [de], a + inc de + inc bc + pop af + dec a + jr nz, .loop3b + +.rejoin + ld de, wcd49 + push bc + call PlaceString + ld de, NAME_LENGTH_JAPANESE + add hl, de + pop bc + pop af + dec a + jr nz, .loop2 + pop hl + ld de, $28 + add hl, de + pop af + dec a + jr nz, .loop1 + ret +; 17064b + +.ClearBox: ; 17064b + hlcoord 1, 5 + xor a + ld b, 12 +.clearbox_row + ld c, SCREEN_WIDTH - 2 +.clearbox_column + ld [hli], a + dec c + jr nz, .clearbox_column + inc hl + inc hl + dec b + jr nz, .clearbox_row + ret +; 17065d + +.PlaceUpDownArrows: ; 17065d + ld a, [wNrOfBeatenBattleTowerTrainers] + and a + jr z, .nope + hlcoord 18, 5 + ld a, "▲" + ld [hl], a + +.nope + ld a, [wNrOfBeatenBattleTowerTrainers] + cp 60 + ret z + hlcoord 18, 16 + ld a, "▼" + ld [hl], a + ret +; 170676 + +.String_Mail: ; 170676 + db "ルーム@" +; 17067a + +.String_PastReaders: ; 17067a + db "れきだいりーダーいちらん@" +; 170687 + +Special_BattleTowerAction: ; 170687 + ld a, [ScriptVar] + ld e, a + ld d, 0 + ld hl, .dw + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + jp hl +; 170696 + + +.dw ; 170696 (5c:4696) + dw BattleTowerAction_CheckExplanationRead ; 0x00 + dw BattleTowerAction_SetExplanationRead ; 0x01 + dw BattleTowerAction_GetChallengeState ; 0x02 + dw BattleTowerAction_SetByteToQuickSaveChallenge ; 0x03 + dw BattleTowerAction_SetByteToCancelChallenge ; 0x04 + dw Function1707ac ; 0x05 + dw Function1707f4 ; 0x06 + dw SaveBattleTowerLevelGroup ; 0x07 + dw LoadBattleTowerLevelGroup ; 0x08 + dw BattleTower_CheckSaveFileExistsAndIsYours ; 0x09 + dw Function1708b1 ; 0x0a + dw CheckMobileEventIndex ; 0x0b + dw Function1708c8 ; 0x0c + dw Function1708f0 ; 0x0d + dw BattleTowerAction_EggTicket ; 0x0e + dw Function1709aa ; 0x0f + dw Function1709bb ; 0x10 + dw Function170a9c ; 0x11 + dw Function170aa0 ; 0x12 + dw Function170aaf ; 0x13 + dw Function170abe ; 0x14 + dw Function170ad7 ; 0x15 + dw Function170807 ; 0x16 + dw Function17081d ; 0x17 + dw BattleTowerAction_LevelCheck ; 0x18 + dw BattleTowerAction_UbersCheck ; 0x19 + dw ResetBattleTowerTrainersSRAM ; 0x1a + dw BattleTower_GiveReward ; 0x1b + dw Function17071b ; 0x1c + dw Function170729 ; 0x1d + dw BattleTower_RandomlyChooseReward ; 0x1e + dw BattleTower_SaveOptions ; 0x1f + + +; Reset the save memory for BattleTower-Trainers (Counter and all 7 TrainerBytes) +ResetBattleTowerTrainersSRAM: ; 1706d6 (5c:46d6) BattleTowerAction $1a + ld a, BANK(sBTTrainers) + call GetSRAMBank + + ld a, $ff + ld hl, sBTTrainers + ld bc, BATTLETOWER_NROFTRAINERS + call ByteFill + + xor a + ld [sNrOfBeatenBattleTowerTrainers], a + + call CloseSRAM + + ret + +BattleTower_GiveReward: ; 1706ee (5c:46ee) BattleTowerAction $1b + ld a, BANK(sBattleTowerReward) + call GetSRAMBank + + ld a, [sBattleTowerReward] + call CloseSRAM + ld [ScriptVar], a + ld hl, NumItems + ld a, [hli] + cp MAX_ITEMS + ret c + ld b, MAX_ITEMS + ld a, [ScriptVar] + ld c, a +.loop + ld a, [hli] + cp c + jr nz, .next + ld a, [hl] + cp 95 + ret c +.next + inc hl + dec b + jr nz, .loop + ld a, POTION + ld [ScriptVar], a + ret + +Function17071b: ; 17071b (5c:471b) BattleTowerAction $1c + ld a, BANK(sBattleTowerChallengeState) + call GetSRAMBank + ld a, BATTLETOWER_WON_CHALLENGE + ld [sBattleTowerChallengeState], a + call CloseSRAM + ret + +Function170729: ; 170729 (5c:4729) BattleTowerAction $1d + ld a, BANK(sBattleTowerChallengeState) + call GetSRAMBank + ld a, BATTLETOWER_RECEIVED_REWARD + ld [sBattleTowerChallengeState], a + call CloseSRAM + ret + +BattleTower_SaveOptions: ; 170737 (5c:4737) BattleTowerAction $1f + farcall SaveOptions + ret + +BattleTower_RandomlyChooseReward: ; 17073e (5c:473e) BattleTowerAction $1e +; Generate a random stat boosting item. +.loop + call Random + ld a, [hRandomAdd] + and $7 + cp 6 + jr c, .okay + sub 6 +.okay + add HP_UP + cp LUCKY_PUNCH + jr z, .loop + push af + ld a, BANK(sBattleTowerReward) + call GetSRAMBank + pop af + ld [sBattleTowerReward], a + call CloseSRAM + ret + +BattleTowerAction_CheckExplanationRead: ; 17075f (5c:475f) BattleTowerAction $00 + call BattleTower_CheckSaveFileExistsAndIsYours + ld a, [ScriptVar] + and a + ret z + + ld a, BANK(sBattleTowerSaveFileFlags) + call GetSRAMBank + ld a, [sBattleTowerSaveFileFlags] + and $2 + ld [ScriptVar], a + call CloseSRAM + ret + +BattleTowerAction_GetChallengeState: ; 170778 (5c:4778) BattleTowerAction $02 + ld hl, sBattleTowerChallengeState + ld a, BANK(sBattleTowerChallengeState) + call GetSRAMBank + ld a, [hl] + ld [ScriptVar], a + call CloseSRAM + ret + +BattleTowerAction_SetExplanationRead: ; 170788 (5c:4788) BattleTowerAction $01 + ld a, BANK(sBattleTowerSaveFileFlags) + call GetSRAMBank + ld a, [sBattleTowerSaveFileFlags] + or $2 + ld [sBattleTowerSaveFileFlags], a + call CloseSRAM + ret + +BattleTowerAction_SetByteToQuickSaveChallenge: ; 170799 (5c:4799) BattleTowerAction $03 + ld c, BATTLETOWER_SAVED_AND_LEFT + jr asm_17079f + +BattleTowerAction_SetByteToCancelChallenge: ; 17079d (5c:479d) BattleTowerAction $04 + ld c, BATTLETOWER_NO_CHALLENGE +asm_17079f: ; 17079f (5c:479f) + ld a, BANK(sBattleTowerChallengeState) + call GetSRAMBank + ld a, c + ld [sBattleTowerChallengeState], a + call CloseSRAM + ret + +Function1707ac: ; 1707ac (5c:47ac) BattleTowerAction $05 + ld a, $5 + call GetSRAMBank + ld a, [$aa8c] + ld b, a + ld a, [$be46] + ld [ScriptVar], a + call CloseSRAM + and a + ret z + ld a, b + cp $2 + jr nc, .asm_1707ef + push bc + call UpdateTime + pop bc + ld a, $5 + call GetSRAMBank + ld a, [$aa8b] + call CloseSRAM + ld c, a + ld a, [CurDay] + sub c + jr c, .asm_1707e5 + cp $8 + jr nc, .asm_1707ef + ld a, b + and a + jr nz, .asm_1707ef + ret +.asm_1707e5 + ld hl, CurDay + ld a, $8c + sub c + add [hl] + cp $8 + ret c +.asm_1707ef + ld a, $8 + ld [ScriptVar], a + +Function1707f4: ; 1707f4 (5c:47f4) BattleTowerAction $06 + ld a, $5 + call GetSRAMBank + xor a + ld [$be46], a + ld [$aa8b], a + ld [$aa8c], a + call CloseSRAM + ret + +Function170807: ; 170807 (5c:4807) BattleTowerAction $16 + call UpdateTime + ld a, $5 + call GetSRAMBank + ld a, [CurDay] + ld [$b2f9], a + xor a + ld [$b2fa], a + call CloseSRAM + ret + +Function17081d: ; 17081d (5c:481d) BattleTowerAction $17 + xor a + ld [ScriptVar], a + ld a, $5 + call GetSRAMBank + ld a, [$b2f9] + ld c, a + ld a, [$b2fa] + ld b, a + call CloseSRAM + cp $2 + jr nc, .asm_170853 + push bc + call UpdateTime + pop bc + ld a, [CurDay] + sub c + jr c, .asm_170849 + cp $b + jr nc, .asm_170853 + ld a, b + and a + jr nz, .asm_170853 + ret + +.asm_170849 + ld hl, CurDay + ld a, 140 + sub c + add [hl] + cp $b + ret c +.asm_170853 + ld a, $1 + ld [ScriptVar], a + ld a, $5 + call GetSRAMBank + xor a + ld [$b2f9], a + ld [$b2fa], a + call CloseSRAM + ret + +SaveBattleTowerLevelGroup: ; 170868 (5c:4868) BattleTowerAction $07 + ld a, BANK(sBTChoiceOfLevelGroup) + call GetSRAMBank + ld a, [rSVBK] + push af + ld a, $3 + ld [rSVBK], a + ld a, [wBTChoiceOfLvlGroup] + ld [sBTChoiceOfLevelGroup], a + pop af + ld [rSVBK], a + call CloseSRAM + ret + +LoadBattleTowerLevelGroup: ; 170881 (5c:4881) BattleTowerAction $08 ; Load level group choice + ld a, BANK(sBTChoiceOfLevelGroup) + call GetSRAMBank + ld a, [rSVBK] + push af + ld a, $3 + ld [rSVBK], a + ld a, [sBTChoiceOfLevelGroup] + ld [wBTChoiceOfLvlGroup], a + pop af + ld [rSVBK], a + call CloseSRAM + ret + +BattleTower_CheckSaveFileExistsAndIsYours: ; 17089a BattleTowerAction $09 + ld a, [wSaveFileExists] + and a + jr z, .nope + farcall CompareLoadedAndSavedPlayerID + jr z, .yes + xor a + jr .nope + +.yes + ld a, $1 + +.nope + ld [ScriptVar], a + ret +; 1708b1 + + +Function1708b1: ; 1708b1 (5c:48b1) BattleTowerAction $0a + xor a + ld [MusicFade], a + call MaxVolume + ret + +CheckMobileEventIndex: ; 1708b9 (5c:48b9) BattleTowerAction $0b something to do with GS Ball + ld a, BANK(sMobileEventIndex) + call GetSRAMBank + ld a, [sMobileEventIndex] + ld [ScriptVar], a + call CloseSRAM + ret + +Function1708c8: ; 1708c8 (5c:48c8) BattleTowerAction $0c + call UpdateTime + ld a, $5 + call GetSRAMBank + ld a, [CurDay] + ld [$aa8b], a + xor a + ld [$aa8c], a + ld a, [$aa5d] + cp $2 + jr nc, .asm_1708ec + ld a, [CurDay] + ld [$aa48], a + ld a, $1 + ld [$aa47], a +.asm_1708ec + call CloseSRAM + ret + +Function1708f0: ; 1708f0 (5c:48f0) BattleTowerAction $0d + xor a + ld [ScriptVar], a + call UpdateTime + ld a, $5 + call GetSRAMBank + ld a, [$aa48] + ld c, a + ld a, [$aa47] + call CloseSRAM + and a + ret z + ld hl, CurDay + ld a, c + cp [hl] + jr nz, Function170923 + ld a, $5 + call GetSRAMBank + ld a, [$aa5d] + call CloseSRAM + cp $5 + ret c + ld a, $1 + ld [ScriptVar], a + ret + + +Function170923: ; 170923 + ld a, $5 + call GetSRAMBank + xor a + ld [$aa48], a + ld [$aa47], a + ld hl, $aa5d + ld bc, $0011 + call ByteFill + call CloseSRAM + ret +; 17093c + + +BattleTowerAction_EggTicket: ; 17093c (5c:493c) BattleTowerAction $0e + xor a + ld [ScriptVar], a + ld a, EGG_TICKET + ld [CurItem], a + ld hl, NumItems + call CheckItem + ret nc + ld a, [PartyCount] + ld b, 0 + ld c, a + ld hl, PartySpecies +.loop + ld a, [hli] + cp EGG + jr nz, .not_egg + push hl + ld hl, PartyMonOT + ld de, NAME_LENGTH_JAPANESE + ld a, b + and a + jr z, .skip +.loop2 + add hl, de + dec a + jr nz, .loop2 +.skip + ld de, String_1709a4 + ld a, NAME_LENGTH_JAPANESE +.compare_loop + push af + ld a, [de] + inc de + cp [hl] + inc hl + jr nz, .different + pop af + dec a + jr nz, .compare_loop +rept 4 + dec hl +endr + ld a, "@" + ld [hli], a + ld [hli], a + pop hl + ld a, EGG_TICKET + ld [CurItem], a + ld a, 1 + ld [wItemQuantityChangeBuffer], a + ld a, -1 + ld [CurItemQuantity], a + ld hl, NumItems + call TossItem + ld a, $1 + ld [ScriptVar], a + ret + +.different + pop af + pop hl +.not_egg + inc b + dec c + jr nz, .loop + ret +; 1709a4 (5c:49a4) + +String_1709a4: ; 1709a4 + db "なぞナゾ@@" + +Function1709aa: ; 1709aa (5c:49aa) BattleTowerAction $0f + ld a, [rSVBK] + push af + ld a, BANK(w3_d090) + ld [rSVBK], a + ld a, [w3_d090] + ld [ScriptVar], a + pop af + ld [rSVBK], a + ret + +Function1709bb: ; 1709bb (5c:49bb) BattleTowerAction $10 + xor a + ld [ScriptVar], a + ld a, $5 + call GetSRAMBank + ld a, [$a800] + call CloseSRAM + cp 6 + jr nc, .invalid + ld e, a + ld d, 0 + ld hl, Jumptable_1709e7 + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + jp hl + +.invalid + ld a, $5 + call GetSRAMBank + xor a + ld [$a800], a + call CloseSRAM + ret +; 1709e7 (5c:49e7) + +Jumptable_1709e7: ; 1709e7 + dw .NoAction + dw .NoAction + dw .DoAction1 + dw .DoAction1 + dw .Action4 + dw .Action5 +; 1709f3 + +.DoAction1: ; 1709f3 + ld a, $5 + call GetSRAMBank + ld a, $1 + ld [$a800], a + call CloseSRAM + +.NoAction: ; 170a00 + ret +; 170a01 + +.Action4: ; 170a01 + ld a, $5 + call GetSRAMBank + ld hl, $b023 + ld de, wMisc + ld bc, $0069 + call CopyBytes + ld a, [$a825] + ld [wcd30], a + ld a, [$a826] + ld [wcd31], a + call CloseSRAM + farcall Function11b6b4 + farcall Function17d0f3 + ld a, $1 + ld [ScriptVar], a + ret +; 170a33 + +.Action5: ; 170a33 + ld a, $0 + call GetSRAMBank + ld hl, wRTC + ld de, wMisc + ld bc, $0004 + call CopyBytes + call CloseSRAM + ld a, $5 + call GetSRAMBank + ld hl, $b08c + ld de, wMisc + ld c, $4 +.compare_loop + ld a, [de] + inc de + cp [hl] + jr nz, .different + inc hl + dec c + jr nz, .compare_loop + call CloseSRAM + ld a, [MapGroup] + ld b, a + ld a, [MapNumber] + ld c, a + call GetMapSceneID + ld a, d + or e + jr z, .no_scene + ld a, [de] + and a + ret nz + +.no_scene + ld a, $1 + ld [ScriptVar], a + ret + +.different + call CloseSRAM + ld a, $5 + call GetSRAMBank + xor a + ld [$a800], a + call CloseSRAM + ld [ScriptVar], a + ld a, [MapGroup] + ld b, a + ld a, [MapNumber] + ld c, a + call GetMapSceneID + ld a, d + or e + jr z, .no_scene_2 + xor a + ld [de], a + +.no_scene_2 + ret +; 170a9c + +Function170a9c: ; 170a9c (5c:4a9c) BattleTowerAction $11 + ld c, $0 + jr asm_170aa2 + +Function170aa0: ; 170aa0 (5c:4aa0) BattleTowerAction $12 + ld c, $1 +asm_170aa2: ; 170aa2 (5c:4aa2) + ld a, $5 + call GetSRAMBank + ld a, c + ld [$aa8d], a + call CloseSRAM + ret + +Function170aaf: ; 170aaf (5c:4aaf) BattleTowerAction $13 + ld a, $5 + call GetSRAMBank + ld a, [$aa8d] + ld [ScriptVar], a + call CloseSRAM + ret + +Function170abe: ; 170abe (5c:4abe) BattleTowerAction $14 + call BattleTower_CheckSaveFileExistsAndIsYours + ld a, [ScriptVar] + and a + ret z + + ld a, BANK(sBattleTowerSaveFileFlags) + call GetSRAMBank + ld a, [sBattleTowerSaveFileFlags] + and $1 + ld [ScriptVar], a + call CloseSRAM + ret + +Function170ad7: ; 170ad7 (5c:4ad7) BattleTowerAction $15 + ld a, BANK(sBattleTowerSaveFileFlags) + call GetSRAMBank + ld a, [sBattleTowerSaveFileFlags] + or $1 + ld [sBattleTowerSaveFileFlags], a + call CloseSRAM + ret + +BattleTowerAction_LevelCheck: ; 170ae8 (5c:4ae8) BattleTowerAction $18 + ld a, $5 + call GetSRAMBank + ld a, [$b2fb] + call CloseSRAM + ld c, 10 + call SimpleDivide + ld a, b + ld [wcd4f], a + xor a + ld [ScriptVar], a + farcall BattleTower_LevelCheck ; level check + ret nc + ld a, $5 + call GetSRAMBank + ld a, [$b2fb] + call CloseSRAM + ld [ScriptVar], a + ret + +BattleTowerAction_UbersCheck: ; 170b16 (5c:4b16) BattleTowerAction $19 + ld a, $5 + call GetSRAMBank + ld a, [$b2fb] + call CloseSRAM + ld c, 10 + call SimpleDivide + ld a, b + ld [wcd4f], a + xor a + ld [ScriptVar], a + farcall BattleTower_UbersCheck + ret nc + ld a, $5 + call GetSRAMBank + ld a, [$b2fb] + call CloseSRAM + ld [ScriptVar], a + ret + +Special_LoadOpponentTrainerAndPokemonWithOTSprite: ; 0x170b44 + farcall Function_LoadOpponentTrainerAndPokemons + ld a, [rSVBK] + push af + ld a, $3 + ld [rSVBK], a + ld hl, BT_OTTrainerClass + ld a, [hl] + dec a + ld c, a + ld b, $0 + pop af + ld [rSVBK], a + ld hl, BTTrainerClassSprites + add hl, bc + ld a, [hl] + ld [wBTTempOTSprite], a + +; Load sprite of the opponent trainer +; because s/he is chosen randomly and appears out of nowhere + ld a, [ScriptVar] + dec a + sla a + ld e, a + sla a + sla a + sla a + ld c, a + ld b, 0 + ld d, 0 + ld hl, MapObjects + add hl, bc + inc hl + ld a, [wBTTempOTSprite] + ld [hl], a + ld hl, UsedSprites + add hl, de + ld [hli], a + ld [hUsedSpriteIndex], a + ld a, [hl] + ld [hUsedSpriteTile], a + farcall GetUsedSprite + ret +; 170b90 + +INCLUDE "data/trainers/sprites.asm" + +DummySpecial_170bd2: ; 170bd2 + ret +; 170bd3 + +Special_CheckForBattleTowerRules: ; 170bd3 + farcall CheckForBattleTowerRules + jr c, .asm_170bde + xor a ; FALSE + jr .asm_170be0 + +.asm_170bde + ld a, TRUE + +.asm_170be0 + ld [ScriptVar], a + ret +; 170be4 diff --git a/engine/events/battle_tower/get_trainer_class.asm b/engine/events/battle_tower/get_trainer_class.asm new file mode 100644 index 000000000..37fe91c56 --- /dev/null +++ b/engine/events/battle_tower/get_trainer_class.asm @@ -0,0 +1,46 @@ +GetMobileOTTrainerClass: ; mobile function + ld h, b + ld l, c + call .GetMobileOTTrainerClass + ld c, a + ret + +.GetMobileOTTrainerClass: ; 4e930 + ld a, [hli] + xor [hl] + ld c, a + jr z, .skip_male_trainers + srl c + srl c +.male_trainer_loop + srl c + ld a, c + cp MaleTrainersEnd - MaleTrainers - 1 + jr nc, .male_trainer_loop + inc c + +.skip_male_trainers + ld a, [de] + cp $1 + ld hl, MaleTrainers + jr nz, .finished + + ld hl, FemaleTrainers + ld a, c + and a + jr z, .finished + +.female_trainer_loop + srl c + ld a, c + cp FemaleTrainersEnd - FemaleTrainers - 1 + jr nc, .female_trainer_loop + inc c + +.finished + ld b, $0 + add hl, bc + ld a, [hl] + ret + +INCLUDE "data/trainers/gendered_trainers.asm" diff --git a/engine/events/battle_tower.asm b/engine/events/battle_tower/load_trainer.asm index a0de6ee84..006e0afa3 100644 --- a/engine/events/battle_tower.asm +++ b/engine/events/battle_tower/load_trainer.asm @@ -26,12 +26,14 @@ Function_LoadOpponentTrainerAndPokemons: ; 1f8000 ld a, [hRandomAdd] add b ld b, a ; b contains the nr of the trainer -if DEF(CRYSTAL11) - and (1 << 7) - 1 - cp 70 +if DEF(_CRYSTAL11) + maskbits BATTLETOWER_NUM_UNIQUE_TRAINERS +- 1 + cp BATTLETOWER_NUM_UNIQUE_TRAINERS else - and (1 << 5) - 1 - cp 21 +; Crystal 1.0 used the wrong constant here, so only the first 21 +; trainers in BattleTowerTrainers can be sampled. + maskbits BATTLETOWER_NUM_UNIQUE_PKMN +- 1 + cp BATTLETOWER_NUM_UNIQUE_PKMN endc jr nc, .resample ld b, a @@ -100,7 +102,7 @@ Function_LoadRandomBattleTowerPkmn: ; 1f8081 .FindARandomBattleTowerPkmn: ; From Which LevelGroup are the Pkmn loaded ; a = 1..10 - ld a, [wBTChoiceOfLvlGroup] ; [$d800] + ld a, [wBTChoiceOfLvlGroup] dec a ld hl, BattleTowerMons ld bc, BattleTowerMons2 - BattleTowerMons1 @@ -113,8 +115,8 @@ Function_LoadRandomBattleTowerPkmn: ; 1f8081 ld a, [hRandomAdd] add b ld b, a - and $1f - cp BATTLETOWER_NRMONSPERLEVELBRACKET + maskbits BATTLETOWER_NUM_UNIQUE_PKMN +- 1 + cp BATTLETOWER_NUM_UNIQUE_PKMN jr nc, .resample ; in register 'a' is the chosen Pkmn of the LevelGroup @@ -207,4 +209,6 @@ Function_LoadRandomBattleTowerPkmn: ; 1f8081 ret ; 1f814e -INCLUDE "data/battle_tower.asm" +INCLUDE "data/battle_tower/classes.asm" + +INCLUDE "data/battle_tower/parties.asm" diff --git a/engine/events/battle_tower_rules.asm b/engine/events/battle_tower/rules.asm index de6022145..8d037951b 100644 --- a/engine/events/battle_tower_rules.asm +++ b/engine/events/battle_tower/rules.asm @@ -213,7 +213,7 @@ BattleTower_ExecuteJumptable: ; 8b25b BattleTower_CheckPartyLengthIs3: ; 8b2bb ld a, [PartyCount] - cp 3 + cp BATTLETOWER_NROFPKMNS ret ; 8b2c1 @@ -235,13 +235,13 @@ BattleTower_CheckPartyHasThreeMonsThatAreNotEggs: ; 8b2c1 cp b ret z ld a, b - cp 3 + cp BATTLETOWER_NROFPKMNS ret ; 8b2da Function_PartyCountEq3: ; 8b2da ld a, [PartyCount] - cp 3 + cp BATTLETOWER_NROFPKMNS ret z scf ret diff --git a/engine/events/battle_tower/trainer_text.asm b/engine/events/battle_tower/trainer_text.asm new file mode 100755 index 000000000..96c91caa9 --- /dev/null +++ b/engine/events/battle_tower/trainer_text.asm @@ -0,0 +1,718 @@ +BattleTowerText:: ; 11c000 +; Print text c for trainer [BT_OTTrainerClass] +; 1: Intro text +; 2: Player lost +; 3: Player won + ld a, [rSVBK] + push af + ld a, BANK(BT_OTTrainerClass) + ld [rSVBK], a +if DEF(_CRYSTAL11) + ld hl, BT_OTTrainerClass +else +; BUG ALERT +; Instead of loading the Trainer Class, this routine +; loads the 6th character in the Trainer's name, then +; uses it to get the gender of the trainer. +; As a consequence, the enemy trainer's dialog will +; always be sampled from the female array. + ld hl, BT_OTName + NAME_LENGTH_JAPANESE - 1 +endc + ld a, [hl] + dec a + ld e, a + ld d, 0 + ld hl, BTTrainerClassGenders + add hl, de + ld a, [hl] + and a + jr nz, .female + ; generate a random number between 0 and 24 + ld a, [hRandomAdd] + and $1f + cp 25 + jr c, .okay0 + sub 25 + +.okay0 + ld hl, BTMaleTrainerTexts + jr .proceed + +.female + ; generate a random number between 0 and 14 + ld a, [hRandomAdd] + and $f + cp 15 + jr c, .okay1 + sub 15 + +.okay1 + ld hl, BTFemaleTrainerTexts + +.proceed + ld b, 0 + dec c + jr nz, .restore + ld [BT_TrainerTextIndex], a + jr .okay2 + +.restore + ld a, [BT_TrainerTextIndex] + +.okay2 + push af + add hl, bc + add hl, bc + ld a, [hli] + ld c, a + ld a, [hl] + ld h, a + ld l, c + pop af + ld c, a + ld b, 0 + add hl, bc + add hl, bc + ld a, [hli] + ld c, a + ld a, [hl] + ld l, c + ld h, a + bccoord 1, 14 + pop af + ld [rSVBK], a + call PlaceHLTextAtBC + ret +; 11c05d + +INCLUDE "mobile/fixed_words.asm" + +INCLUDE "data/trainers/genders.asm" + + +BTMaleTrainerTexts: ; 11f332 + dw .Greetings + dw .PlayerLost + dw .PlayerWon + +.Greetings: ; 11f338 + dw BTGreetingM1 + dw BTGreetingM2 + dw BTGreetingM3 + dw BTGreetingM4 + dw BTGreetingM5 + dw BTGreetingM6 + dw BTGreetingM7 + dw BTGreetingM8 + dw BTGreetingM9 + dw BTGreetingM10 + dw BTGreetingM11 + dw BTGreetingM12 + dw BTGreetingM13 + dw BTGreetingM14 + dw BTGreetingM15 + dw BTGreetingM16 + dw BTGreetingM17 + dw BTGreetingM18 + dw BTGreetingM19 + dw BTGreetingM20 + dw BTGreetingM21 + dw BTGreetingM22 + dw BTGreetingM23 + dw BTGreetingM24 + dw BTGreetingM25 + +.PlayerLost: ; 11f36a + dw BTLossM1 + dw BTLossM2 + dw BTLossM3 + dw BTLossM4 + dw BTLossM5 + dw BTLossM6 + dw BTLossM7 + dw BTLossM8 + dw BTLossM9 + dw BTLossM10 + dw BTLossM11 + dw BTLossM12 + dw BTLossM13 + dw BTLossM14 + dw BTLossM15 + dw BTLossM16 + dw BTLossM17 + dw BTLossM18 + dw BTLossM19 + dw BTLossM20 + dw BTLossM21 + dw BTLossM22 + dw BTLossM23 + dw BTLossM24 + dw BTLossM25 + +.PlayerWon: ; 11f39c + dw BTWinM1 + dw BTWinM2 + dw BTWinM3 + dw BTWinM4 + dw BTWinM5 + dw BTWinM6 + dw BTWinM7 + dw BTWinM8 + dw BTWinM9 + dw BTWinM10 + dw BTWinM11 + dw BTWinM12 + dw BTWinM13 + dw BTWinM14 + dw BTWinM15 + dw BTWinM16 + dw BTWinM17 + dw BTWinM18 + dw BTWinM19 + dw BTWinM20 + dw BTWinM21 + dw BTWinM22 + dw BTWinM23 + dw BTWinM24 + dw BTWinM25 + + +BTFemaleTrainerTexts: + dw .Greetings + dw .PlayerLost + dw .PlayerWon + +.Greetings: ; 11f3d4 + dw BTGreetingF1 + dw BTGreetingF2 + dw BTGreetingF3 + dw BTGreetingF4 + dw BTGreetingF5 + dw BTGreetingF6 + dw BTGreetingF7 + dw BTGreetingF8 + dw BTGreetingF9 + dw BTGreetingF10 + dw BTGreetingF11 + dw BTGreetingF12 + dw BTGreetingF13 + dw BTGreetingF14 + dw BTGreetingF15 + +.PlayerLost: ; 11f3f2 + dw BTLossF1 + dw BTLossF2 + dw BTLossF3 + dw BTLossF4 + dw BTLossF5 + dw BTLossF6 + dw BTLossF7 + dw BTLossF8 + dw BTLossF9 + dw BTLossF10 + dw BTLossF11 + dw BTLossF12 + dw BTLossF13 + dw BTLossF14 + dw BTLossF15 + +.PlayerWon: ; 11f410 + dw BTWinF1 + dw BTWinF2 + dw BTWinF3 + dw BTWinF4 + dw BTWinF5 + dw BTWinF6 + dw BTWinF7 + dw BTWinF8 + dw BTWinF9 + dw BTWinF10 + dw BTWinF11 + dw BTWinF12 + dw BTWinF13 + dw BTWinF14 + dw BTWinF15 + + +BTGreetingM1: ; 0x11f42e + text_jump BattleTowerText_0x1ec000 + db "@" + +BTLossM1: ; 0x11f433 + text_jump BattleTowerText_0x1ec03b + db "@" + +BTWinM1: ; 0x11f438 + text_jump UnknownText_0x1ec060 + db "@" + +BTGreetingM2: ; 0x11f43d + text_jump BattleTowerText_0x1ec080 + db "@" + +BTLossM2: ; 0x11f442 + text_jump UnknownText_0x1ec0a3 + db "@" + +BTWinM2: ; 0x11f447 + text_jump UnknownText_0x1ec0c4 + db "@" + +BTGreetingM3: ; 0x11f44c + text_jump UnknownText_0x1ec0e1 + db "@" + +BTLossM3: ; 0x11f451 + text_jump UnknownText_0x1ec108 + db "@" + +BTWinM3: ; 0x11f456 + text_jump UnknownText_0x1ec12a + db "@" + +BTGreetingM4: ; 0x11f45b + text_jump UnknownText_0x1ec14d + db "@" + +BTLossM4: ; 0x11f460 + text_jump UnknownText_0x1ec16f + db "@" + +BTWinM4: ; 0x11f465 + text_jump UnknownText_0x1ec190 + db "@" + +BTGreetingM5: ; 0x11f46a + text_jump UnknownText_0x1ec1ae + db "@" + +BTLossM5: ; 0x11f46f + text_jump UnknownText_0x1ec1d0 + db "@" + +BTWinM5: ; 0x11f474 + text_jump UnknownText_0x1ec1f4 + db "@" + +BTGreetingM6: ; 0x11f479 + text_jump UnknownText_0x1ec216 + db "@" + +BTLossM6: ; 0x11f47e + text_jump UnknownText_0x1ec238 + db "@" + +BTWinM6: ; 0x11f483 + text_jump UnknownText_0x1ec259 + db "@" + +BTGreetingM7: ; 0x11f488 + text_jump UnknownText_0x1ec27b + db "@" + +BTLossM7: ; 0x11f48d + text_jump UnknownText_0x1ec2a0 + db "@" + +BTWinM7: ; 0x11f492 + text_jump UnknownText_0x1ec2c0 + db "@" + +BTGreetingM8: ; 0x11f497 + text_jump UnknownText_0x1ec2d9 + db "@" + +BTLossM8: ; 0x11f49c + text_jump UnknownText_0x1ec2fe + db "@" + +BTWinM8: ; 0x11f4a1 + text_jump UnknownText_0x1ec320 + db "@" + +BTGreetingM9: ; 0x11f4a6 + text_jump UnknownText_0x1ec33f + db "@" + +BTLossM9: ; 0x11f4ab + text_jump UnknownText_0x1ec36c + db "@" + +BTWinM9: ; 0x11f4b0 + text_jump UnknownText_0x1ec389 + db "@" + +BTGreetingM10: ; 0x11f4b5 + text_jump UnknownText_0x1ec3ad + db "@" + +BTLossM10: ; 0x11f4ba + text_jump UnknownText_0x1ec3c5 + db "@" + +BTWinM10: ; 0x11f4bf + text_jump UnknownText_0x1ec3e5 + db "@" + +BTGreetingM11: ; 0x11f4c4 + text_jump UnknownText_0x1ec402 + db "@" + +BTLossM11: ; 0x11f4c9 + text_jump UnknownText_0x1ec411 + db "@" + +BTWinM11: ; 0x11f4ce + text_jump UnknownText_0x1ec41f + db "@" + +BTGreetingM12: ; 0x11f4d3 + text_jump UnknownText_0x1ec42e + db "@" + +BTLossM12: ; 0x11f4d8 + text_jump UnknownText_0x1ec461 + db "@" + +BTWinM12: ; 0x11f4dd + text_jump UnknownText_0x1ec4a0 + db "@" + +BTGreetingM13: ; 0x11f4e2 + text_jump UnknownText_0x1ec4d6 + db "@" + +BTLossM13: ; 0x11f4e7 + text_jump UnknownText_0x1ec4f5 + db "@" + +BTWinM13: ; 0x11f4ec + text_jump UnknownText_0x1ec512 + db "@" + +BTGreetingM14: ; 0x11f4f1 + text_jump UnknownText_0x1ec532 + db "@" + +BTLossM14: ; 0x11f4f6 + text_jump UnknownText_0x1ec54b + db "@" + +BTWinM14: ; 0x11f4fb + text_jump UnknownText_0x1ec565 + db "@" + +BTGreetingM15: ; 0x11f500 + text_jump UnknownText_0x1ec580 + db "@" + +BTLossM15: ; 0x11f505 + text_jump UnknownText_0x1ec59d + db "@" + +BTWinM15: ; 0x11f50a + text_jump UnknownText_0x1ec5b5 + db "@" + +BTGreetingM16: ; 0x11f50f + text_jump UnknownText_0x1ec5d3 + db "@" + +BTLossM16: ; 0x11f514 + text_jump UnknownText_0x1ec5ee + db "@" + +BTWinM16: ; 0x11f519 + text_jump UnknownText_0x1ec60d + db "@" + +BTGreetingM17: ; 0x11f51e + text_jump UnknownText_0x1ec631 + db "@" + +BTLossM17: ; 0x11f523 + text_jump UnknownText_0x1ec651 + db "@" + +BTWinM17: ; 0x11f528 + text_jump UnknownText_0x1ec68f + db "@" + +BTGreetingM18: ; 0x11f52d + text_jump UnknownText_0x1ec6b1 + db "@" + +BTLossM18: ; 0x11f532 + text_jump UnknownText_0x1ec6d0 + db "@" + +BTWinM18: ; 0x11f537 + text_jump UnknownText_0x1ec708 + db "@" + +BTGreetingM19: ; 0x11f53c + text_jump UnknownText_0x1ec720 + db "@" + +BTLossM19: ; 0x11f541 + text_jump UnknownText_0x1ec73e + db "@" + +BTWinM19: ; 0x11f546 + text_jump UnknownText_0x1ec75b + db "@" + +BTGreetingM20: ; 0x11f54b + text_jump UnknownText_0x1ec77f + db "@" + +BTLossM20: ; 0x11f550 + text_jump UnknownText_0x1ec798 + db "@" + +BTWinM20: ; 0x11f555 + text_jump UnknownText_0x1ec7bb + db "@" + +BTGreetingM21: ; 0x11f55a + text_jump UnknownText_0x1ec7d8 + db "@" + +BTLossM21: ; 0x11f55f + text_jump UnknownText_0x1ec818 + db "@" + +BTWinM21: ; 0x11f564 + text_jump UnknownText_0x1ec837 + db "@" + +BTGreetingM22: ; 0x11f569 + text_jump UnknownText_0x1ec858 + db "@" + +BTLossM22: ; 0x11f56e + text_jump UnknownText_0x1ec876 + db "@" + +BTWinM22: ; 0x11f573 + text_jump UnknownText_0x1ec898 + db "@" + +BTGreetingM23: ; 0x11f578 + text_jump UnknownText_0x1ec8b1 + db "@" + +BTLossM23: ; 0x11f57d + text_jump UnknownText_0x1ec8d5 + db "@" + +BTWinM23: ; 0x11f582 + text_jump UnknownText_0x1ec8f0 + db "@" + +BTGreetingM24: ; 0x11f587 + text_jump UnknownText_0x1ec911 + db "@" + +BTLossM24: ; 0x11f58c + text_jump UnknownText_0x1ec928 + db "@" + +BTWinM24: ; 0x11f591 + text_jump UnknownText_0x1ec949 + db "@" + +BTGreetingM25: ; 0x11f596 + text_jump UnknownText_0x1ec969 + db "@" + +BTLossM25: ; 0x11f59b + text_jump UnknownText_0x1ec986 + db "@" + +BTWinM25: ; 0x11f5a0 + text_jump UnknownText_0x1ec99b + db "@" + + + + +BTGreetingF1: ; 0x11f5a5 + text_jump UnknownText_0x1ec9bd + db "@" + +BTLossF1: ; 0x11f5aa + text_jump UnknownText_0x1ec9d9 + db "@" + +BTWinF1: ; 0x11f5af + text_jump UnknownText_0x1ec9f7 + db "@" + +BTGreetingF2: ; 0x11f5b4 + text_jump UnknownText_0x1eca0a + db "@" + +BTLossF2: ; 0x11f5b9 + text_jump UnknownText_0x1eca2a + db "@" + +BTWinF2: ; 0x11f5be + text_jump UnknownText_0x1eca47 + db "@" + +BTGreetingF3: ; 0x11f5c3 + text_jump UnknownText_0x1eca64 + db "@" + +BTLossF3: ; 0x11f5c8 + text_jump UnknownText_0x1eca82 + db "@" + +BTWinF3: ; 0x11f5cd + text_jump UnknownText_0x1eca9d + db "@" + +BTGreetingF4: ; 0x11f5d2 + text_jump UnknownText_0x1ecabf + db "@" + +BTLossF4: ; 0x11f5d7 + text_jump UnknownText_0x1ecade + db "@" + +BTWinF4: ; 0x11f5dc + text_jump UnknownText_0x1ecafa + db "@" + +BTGreetingF5: ; 0x11f5e1 + text_jump UnknownText_0x1ecb19 + db "@" + +BTLossF5: ; 0x11f5e6 + text_jump UnknownText_0x1ecb37 + db "@" + +BTWinF5: ; 0x11f5eb + text_jump UnknownText_0x1ecb55 + db "@" + +BTGreetingF6: ; 0x11f5f0 + text_jump UnknownText_0x1ecb70 + db "@" + +BTLossF6: ; 0x11f5f5 + text_jump UnknownText_0x1ecb92 + db "@" + +BTWinF6: ; 0x11f5fa + text_jump UnknownText_0x1ecbb6 + db "@" + +BTGreetingF7: ; 0x11f5ff + text_jump UnknownText_0x1ecbd9 + db "@" + +BTLossF7: ; 0x11f604 + text_jump UnknownText_0x1ecbf3 + db "@" + +BTWinF7: ; 0x11f609 + text_jump UnknownText_0x1ecc15 + db "@" + +BTGreetingF8: ; 0x11f60e + text_jump UnknownText_0x1ecc39 + db "@" + +BTLossF8: ; 0x11f613 + text_jump UnknownText_0x1ecc55 + db "@" + +BTWinF8: ; 0x11f618 + text_jump UnknownText_0x1ecc75 + db "@" + +BTGreetingF9: ; 0x11f61d + text_jump UnknownText_0x1ecc92 + db "@" + +BTLossF9: ; 0x11f622 + text_jump UnknownText_0x1ecca7 + db "@" + +BTWinF9: ; 0x11f627 + text_jump UnknownText_0x1eccc1 + db "@" + +BTGreetingF10: ; 0x11f62c + text_jump UnknownText_0x1eccd7 + db "@" + +BTLossF10: ; 0x11f631 + text_jump UnknownText_0x1eccef + db "@" + +BTWinF10: ; 0x11f636 + text_jump UnknownText_0x1ecd0e + db "@" + +BTGreetingF11: ; 0x11f63b + text_jump UnknownText_0x1ecd2b + db "@" + +BTLossF11: ; 0x11f640 + text_jump UnknownText_0x1ecd4d + db "@" + +BTWinF11: ; 0x11f645 + text_jump UnknownText_0x1ecd6b + db "@" + +BTGreetingF12: ; 0x11f64a + text_jump UnknownText_0x1ecd8d + db "@" + +BTLossF12: ; 0x11f64f + text_jump UnknownText_0x1ecdaf + db "@" + +BTWinF12: ; 0x11f654 + text_jump UnknownText_0x1ecdcf + db "@" + +BTGreetingF13: ; 0x11f659 + text_jump UnknownText_0x1ecded + db "@" + +BTLossF13: ; 0x11f65e + text_jump UnknownText_0x1ece0d + db "@" + +BTWinF13: ; 0x11f663 + text_jump UnknownText_0x1ece2a + db "@" + +BTGreetingF14: ; 0x11f668 + text_jump UnknownText_0x1ece4b + db "@" + +BTLossF14: ; 0x11f66d + text_jump UnknownText_0x1ece70 + db "@" + +BTWinF14: ; 0x11f672 + text_jump UnknownText_0x1ece8a + db "@" + +BTGreetingF15: ; 0x11f677 + text_jump UnknownText_0x1ecea8 + db "@" + +BTLossF15: ; 0x11f67c + text_jump UnknownText_0x1ecec9 + db "@" + +BTWinF15: ; 0x11f681 + text_jump UnknownText_0x1ecee8 + db "@" diff --git a/engine/events/buena.asm b/engine/events/buena.asm index 6070895fe..cd0ecc98d 100644 --- a/engine/events/buena.asm +++ b/engine/events/buena.asm @@ -1,4 +1,4 @@ -SpecialBuenasPassword: ; 8af6b +Special_BuenasPassword: ; 8af6b xor a ld [wWhichIndexSet], a ld hl, .MenuDataHeader @@ -17,7 +17,7 @@ SpecialBuenasPassword: ; 8af6b ld a, [MenuSelection] ld c, a ld a, [wBuenasPassword] - and $3 + maskbits NUM_PASSWORDS_PER_CATEGORY +- 1 cp c jr nz, .wrong ld b, $1 @@ -30,8 +30,7 @@ SpecialBuenasPassword: ; 8af6b .MenuDataHeader: ; 0x8afa9 db MENU_BACKUP_TILES ; flags - db 00, 00 ; start coords - db 07, 10 ; end coords + menu_coords 0, 0, 10, 7 dw .MenuData2 db 1 ; default option ; 0x8afb1 @@ -46,8 +45,12 @@ SpecialBuenasPassword: ; 8af6b ; 0x8afb4 .PasswordIndices: ; 8afb8 - db 3 - db 0, 1, 2 + db NUM_PASSWORDS_PER_CATEGORY +x = 0 +rept NUM_PASSWORDS_PER_CATEGORY + db x +x = x + 1 +endr db -1 .PlacePasswordChoices: ; 8afbd @@ -64,7 +67,7 @@ SpecialBuenasPassword: ; 8af6b ret ; 8afd4 -SpecialBuenaPrize: ; 8afd4 +Special_BuenaPrize: ; 8afd4 xor a ld [wMenuScrollPosition], a ld a, $1 @@ -226,8 +229,7 @@ PrintBlueCardBalance: ; 8b097 BlueCardBalanceMenuDataHeader: ; 0x8b0d1 db MENU_BACKUP_TILES ; flags - db 11, 00 ; start coords - db 13, 11 ; end coords + menu_coords 0, 11, 11, 13 ; 8b0d6 Buena_PlacePrizeMenuBox: ; 8b0d6 @@ -238,8 +240,7 @@ Buena_PlacePrizeMenuBox: ; 8b0d6 .menudataheader ; 0x8b0dd db MENU_BACKUP_TILES ; flags - db 00, 00 ; start coords - db 11, 17 ; end coords + menu_coords 0, 0, 17, TEXTBOX_Y - 1 ; 8b0e2 Buena_PrizeMenu: ; 8b0e2 @@ -271,8 +272,7 @@ Buena_PrizeMenu: ; 8b0e2 .MenuDataHeader: ; 0x8b113 db MENU_BACKUP_TILES ; flags - db 01, 01 ; start coords - db 09, 16 ; end coords + menu_coords 1, 1, 16, 9 dw .MenuData2 db 1 ; default option ; 0x8b11b diff --git a/engine/events/buena_menu.asm b/engine/events/buena_menu.asm index b453da783..cf6fecf72 100644 --- a/engine/events/buena_menu.asm +++ b/engine/events/buena_menu.asm @@ -1,4 +1,4 @@ -AskRememberPassword: ; 4ae12 +Special_AskRememberPassword: ; 4ae12 call .DoMenu ld a, $0 jr c, .okay diff --git a/engine/events/bug_contest/contest_2.asm b/engine/events/bug_contest/contest_2.asm index 493c69d0c..7ade44815 100755 --- a/engine/events/bug_contest/contest_2.asm +++ b/engine/events/bug_contest/contest_2.asm @@ -2,7 +2,7 @@ Special_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, 10 ; Number of people to choose from. + ld c, NUM_BUG_CONTESTANTS ld hl, BugCatchingContestantEventFlagTable .loop1 push bc @@ -26,9 +26,9 @@ Special_SelectRandomBugContestContestants: ; 139a8 .next ; Choose a flag at uniform random to be set. call Random - cp 250 + cp $ff / NUM_BUG_CONTESTANTS * NUM_BUG_CONTESTANTS jr nc, .next - ld c, 25 + ld c, $ff / NUM_BUG_CONTESTANTS call SimpleDivide ld e, b ld d, 0 @@ -59,7 +59,7 @@ Special_SelectRandomBugContestContestants: ; 139a8 Special_CheckBugContestContestantFlag: ; 139ed ; Checks the flag of the Bug Catching Contestant whose index is loaded in a. -; Bug: If a >= 10 when this is called, it will read beyond the table. +; Bug: If a >= NUM_BUG_CONTESTANTS when this is called, it will read beyond the table. ld hl, BugCatchingContestantEventFlagTable ld e, a @@ -74,20 +74,9 @@ Special_CheckBugContestContestantFlag: ; 139ed ret ; 139fe -BugCatchingContestantEventFlagTable: ; 139fe - dw EVENT_BUG_CATCHING_CONTESTANT_1A - dw EVENT_BUG_CATCHING_CONTESTANT_2A - dw EVENT_BUG_CATCHING_CONTESTANT_3A - dw EVENT_BUG_CATCHING_CONTESTANT_4A - dw EVENT_BUG_CATCHING_CONTESTANT_5A - dw EVENT_BUG_CATCHING_CONTESTANT_6A - dw EVENT_BUG_CATCHING_CONTESTANT_7A - dw EVENT_BUG_CATCHING_CONTESTANT_8A - dw EVENT_BUG_CATCHING_CONTESTANT_9A - dw EVENT_BUG_CATCHING_CONTESTANT_10A -; 13a12 +INCLUDE "data/bug_contest_flags.asm" -ContestDropOffMons: ; 13a12 +Special_ContestDropOffMons: ; 13a12 ld hl, PartyMon1HP ld a, [hli] or [hl] @@ -101,7 +90,7 @@ ContestDropOffMons: ; 13a12 ld a, [hl] ld [wBugContestSecondPartySpecies], a ; ... and replacing it with the terminator byte - ld [hl], $ff + ld [hl], -1 xor a ld [ScriptVar], a ret @@ -112,13 +101,13 @@ ContestDropOffMons: ; 13a12 ret ; 13a31 -ContestReturnMons: ; 13a31 +Special_ContestReturnMons: ; 13a31 ; Restore the species of the second mon. ld hl, PartySpecies + 1 ld a, [wBugContestSecondPartySpecies] ld [hl], a ; Restore the party count, which must be recomputed. - ld b, $1 + ld b, 1 .loop ld a, [hli] cp -1 diff --git a/engine/events/bug_contest/display_stats.asm b/engine/events/bug_contest/display_stats.asm index d6ad3997e..0e2567c28 100644 --- a/engine/events/bug_contest/display_stats.asm +++ b/engine/events/bug_contest/display_stats.asm @@ -101,7 +101,7 @@ DisplayAlreadyCaughtText: ; cc0c7 text_jump UnknownText_0x1c10dd db "@" -Predef2F: -Predef38: -Predef39: ; cc0d5 +DummyPredef2F: +DummyPredef38: +DummyPredef39: ; cc0d5 ret diff --git a/engine/events/bug_contest/judging.asm b/engine/events/bug_contest/judging.asm index 901ae88fa..8681feb8d 100755 --- a/engine/events/bug_contest/judging.asm +++ b/engine/events/bug_contest/judging.asm @@ -1,6 +1,6 @@ -_BugContestJudging: ; 1369d +_Special_BugContestJudging: ; 1369d call ContestScore - farcall TrainerRankings_BugContestScore + farcall StubbedTrainerRankings_BugContestScore call BugContest_JudgeContestants ld a, [wBugContestThirdPlaceWinnerID] call LoadContestantName @@ -77,9 +77,8 @@ BugContest_ThirdPlaceScoreText: ; 0x1372b ; 0x13730 LoadContestantName: ; 13730 - -; If a = 0, get your name. - dec a +; If a = 1, get your name. + dec a ; BUG_CONTEST_PLAYER jr z, .player ; Find the pointer for the trainer class of the Bug Catching Contestant whose ID is in a. ld c, a @@ -141,11 +140,11 @@ INCLUDE "data/bug_contest_winners.asm" BugContest_GetPlayersResult: ; 13807 ld hl, wBugContestThirdPlaceWinnerID - ld de, -4 - ld b, 3 + ld de, - BUG_CONTESTANT_SIZE + ld b, 3 ; 3rd, 2nd, or 1st .loop ld a, [hl] - cp 1 ; Player + cp BUG_CONTEST_PLAYER jr z, .done add hl, de dec b @@ -159,7 +158,7 @@ BugContest_JudgeContestants: ; 13819 call ClearContestResults call ComputeAIContestantScores ld hl, wBugContestTempWinnerID - ld a, 1 ; Player + ld a, BUG_CONTEST_PLAYER ld [hli], a ld a, [wContestMon] ld [hli], a @@ -190,11 +189,11 @@ DetermineContestWinners: ; 1383e jr c, .not_first_place ld hl, wBugContestSecondPlaceWinnerID ld de, wBugContestThirdPlaceWinnerID - ld bc, 4 + ld bc, BUG_CONTESTANT_SIZE call CopyBytes ld hl, wBugContestFirstPlaceWinnerID ld de, wBugContestSecondPlaceWinnerID - ld bc, 4 + ld bc, BUG_CONTESTANT_SIZE call CopyBytes ld hl, wBugContestFirstPlaceWinnerID call CopyTempContestant @@ -208,7 +207,7 @@ DetermineContestWinners: ; 1383e jr c, .not_second_place ld hl, wBugContestSecondPlaceWinnerID ld de, wBugContestThirdPlaceWinnerID - ld bc, 4 + ld bc, BUG_CONTESTANT_SIZE call CopyBytes ld hl, wBugContestSecondPlaceWinnerID call CopyTempContestant @@ -230,7 +229,7 @@ DetermineContestWinners: ; 1383e CopyTempContestant: ; 138a0 ; Could've just called CopyBytes. ld de, wBugContestTempWinnerID -rept 3 +rept BUG_CONTESTANT_SIZE +- 1 ld a, [de] inc de ld [hli], a @@ -264,6 +263,7 @@ ComputeAIContestantScores: ; 138b0 inc hl inc hl .loop2 + ; 0, 1, or 2 for 1st, 2nd, or 3rd call Random and 3 cp 3 @@ -278,8 +278,9 @@ ComputeAIContestantScores: ; 138b0 ld a, [hli] ld h, [hl] ld l, a + ; randomly perturb score call Random - and 7 + and %111 ld c, a ld b, 0 add hl, bc @@ -294,7 +295,7 @@ ComputeAIContestantScores: ; 138b0 .done inc e ld a, e - cp 10 + cp NUM_BUG_CONTESTANTS jr nz, .loop ret ; 13900 @@ -337,26 +338,26 @@ ContestScore: ; 13900 ; DVs ld a, [wContestMonDVs + 0] ld b, a - and 2 + and %0010 add a add a ld c, a swap b ld a, b - and 2 + and %0010 add a add c ld d, a ld a, [wContestMonDVs + 1] ld b, a - and 2 + and %0010 ld c, a swap b ld a, b - and 2 + and %0010 srl a add c add c diff --git a/engine/events/catch_tutorial.asm b/engine/events/catch_tutorial.asm index b9352ccd6..d91af65fe 100644 --- a/engine/events/catch_tutorial.asm +++ b/engine/events/catch_tutorial.asm @@ -41,7 +41,7 @@ CatchTutorial:: ; 4e554 ld hl, .AutoInput ld a, BANK(.AutoInput) call StartAutoInput - callfar StartBattle + callfar Predef_StartBattle call StopAutoInput pop af diff --git a/engine/events/celebi.asm b/engine/events/celebi.asm index 1139ad3d5..81565c27e 100755 --- a/engine/events/celebi.asm +++ b/engine/events/celebi.asm @@ -1,3 +1,5 @@ +SPECIALCELEBIEVENT_CELEBI EQU $84 + Special_CelebiShrineEvent: ; 4989a call DelayFrame ld a, [VramState] @@ -10,7 +12,7 @@ Special_CelebiShrineEvent: ; 4989a call _InitSpriteAnimStruct ld hl, SPRITEANIMSTRUCT_TILE_ID add hl, bc - ld [hl], $84 + ld [hl], SPECIALCELEBIEVENT_CELEBI ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID add hl, bc ld [hl], SPRITE_ANIM_SEQ_CELEBI @@ -19,7 +21,7 @@ Special_CelebiShrineEvent: ; 4989a ld a, $80 ld [hl], a ld a, 160 ; frame count - ld [wcf64], a + ld [wFrameCounter], a ld d, $0 .loop ld a, [wJumptableIndex] @@ -43,26 +45,26 @@ Special_CelebiShrineEvent: ; 4989a .done pop af ld [VramState], a - call .RefreshPlayerSprite_ClearAllOthers + call .RestorePlayerSprite_DespawnLeaves call CelebiEvent_SetBattleType ret ; 498f9 -.RefreshPlayerSprite_ClearAllOthers: ; 498f9 - ld hl, Sprites + 2 +.RestorePlayerSprite_DespawnLeaves: ; 498f9 + ld hl, Sprite01TileID xor a - ld c, $4 + ld c, 4 .OAMloop: - ld [hli], a - inc hl - inc hl + ld [hli], a ; tile id +rept SPRITEOAMSTRUCT_LENGTH +- 1 inc hl +endr inc a dec c jr nz, .OAMloop - ld hl, Sprites + 4 * 4 - ld bc, 36 * 4 + ld hl, Sprite05 + ld bc, SpritesEnd - Sprite05 xor a call ByteFill ret @@ -76,8 +78,8 @@ LoadCelebiGFX: ; 49912 lb bc, BANK(SpecialCelebiLeafGFX), 4 call Request2bpp ld de, SpecialCelebiGFX - ld hl, vTiles0 tile $84 - lb bc, BANK(SpecialCelebiGFX), $10 + ld hl, vTiles0 tile SPECIALCELEBIEVENT_CELEBI + lb bc, BANK(SpecialCelebiGFX), 4 * 4 call Request2bpp xor a ld [wJumptableIndex], a @@ -86,7 +88,7 @@ LoadCelebiGFX: ; 49912 ; 49935 CelebiEvent_CountDown: ; 49935 - ld hl, wcf64 + ld hl, wFrameCounter ld a, [hl] and a jr z, .done @@ -238,27 +240,27 @@ UpdateCelebiPosition: ; 49aa2 (12:5aa2) CelebiEvent_Cosine: ; 49b3b (12:5b3b) - add $10 - and $3f - cp $20 +; a = d * cos(a * pi/32) + add %010000 + and %111111 + cp %100000 jr nc, .negative - call .SineFunction + call .ApplySineWave ld a, h ret .negative - and $1f - call .SineFunction + and %011111 + call .ApplySineWave ld a, h xor $ff inc a ret - -.SineFunction: ; 49b52 (12:5b52) +.ApplySineWave: ; 49b52 (12:5b52) ld e, a ld a, d - ld d, $0 + ld d, 0 ld hl, .sinewave add hl, de add hl, de @@ -276,7 +278,6 @@ CelebiEvent_Cosine: ; 49b3b (12:5b3b) and a jr nz, .multiply ret - ; 49b6e (12:5b6e) .sinewave ; 49b6e @@ -307,22 +308,22 @@ GetCelebiSpriteTile: ; 49bae .Frame1: - ld a, $84 + ld a, SPECIALCELEBIEVENT_CELEBI jr .load_tile .Frame2: - ld a, $88 + ld a, SPECIALCELEBIEVENT_CELEBI + 4 jr .load_tile .Frame3: - ld a, $8c + ld a, SPECIALCELEBIEVENT_CELEBI + 8 jr .load_tile .Frame4: - ld a, $90 + ld a, SPECIALCELEBIEVENT_CELEBI + 12 .load_tile ld hl, SPRITEANIMSTRUCT_TILE_ID @@ -361,7 +362,7 @@ CelebiEvent_SetBattleType: ; 49bf3 ; 49bf9 -CheckCaughtCelebi: ; 49bf9 +Special_CheckCaughtCelebi: ; 49bf9 ld a, [wBattleResult] bit 6, a jr z, .false diff --git a/engine/events/checkforhiddenitems.asm b/engine/events/checkforhiddenitems.asm new file mode 100644 index 000000000..3c13412d8 --- /dev/null +++ b/engine/events/checkforhiddenitems.asm @@ -0,0 +1,85 @@ +CheckForHiddenItems: ; b8172 +; Checks to see if there are hidden items on the screen that have not yet been found. If it finds one, returns carry. + call GetMapScriptHeaderBank + ld [Buffer1], a +; Get the coordinate of the bottom right corner of the screen, and load it in Buffer3/Buffer4. + ld a, [XCoord] + add SCREEN_WIDTH / 4 + ld [Buffer4], a + ld a, [YCoord] + add SCREEN_HEIGHT / 4 + ld [Buffer3], a +; Get the pointer for the first BG event header in the map... + ld hl, wCurrMapBGEventHeaderPointer + ld a, [hli] + ld h, [hl] + ld l, a +; ... before even checking to see if there are any BG events on this map. + ld a, [wCurrMapBGEventCount] + and a + jr z, .nobgeventitems +; For i = 1:wCurrMapBGEventCount... +.loop +; Store the counter in Buffer2, and store the BG event header pointer in the stack. + ld [Buffer2], a + push hl +; Get the Y coordinate of the BG event. + call .GetFarByte + ld e, a +; Is the Y coordinate of the BG event on the screen? If not, go to the next BG event. + ld a, [Buffer3] + sub e + jr c, .next + cp SCREEN_HEIGHT / 2 + jr nc, .next +; Is the X coordinate of the BG event on the screen? If not, go to the next BG event. + call .GetFarByte + ld d, a + ld a, [Buffer4] + sub d + jr c, .next + cp SCREEN_WIDTH / 2 + jr nc, .next +; Is this BG event a hidden item? If not, go to the next BG event. + call .GetFarByte + cp BGEVENT_ITEM + jr nz, .next +; Has this item already been found? If not, set off the Itemfinder. + ld a, [Buffer1] + call GetFarHalfword + ld a, [Buffer1] + call GetFarHalfword + ld d, h + ld e, l + ld b, CHECK_FLAG + call EventFlagAction + ld a, c + and a + jr z, .itemnearby + +.next +; Restore the BG event header pointer and increment it by the length of a BG event header. + pop hl + ld bc, 5 + add hl, bc +; Restore the BG event counter and decrement it. If it hits zero, there are no hidden items in range. + ld a, [Buffer2] + dec a + jr nz, .loop + +.nobgeventitems + xor a + ret + +.itemnearby + pop hl + scf + ret +; b81e2 + +.GetFarByte: ; b81e2 + ld a, [Buffer1] + call GetFarByte + inc hl + ret +; b81ea diff --git a/engine/events/daycare.asm b/engine/events/daycare.asm index 6395a40fb..6310787ac 100755 --- a/engine/events/daycare.asm +++ b/engine/events/daycare.asm @@ -465,14 +465,14 @@ Special_DayCareManOutside: ; 16936 .Load0: call PrintText - xor a + xor a ; FALSE ld [ScriptVar], a ret .PartyFull: ld hl, .PartyFullText call PrintText - ld a, $1 + ld a, TRUE ld [ScriptVar], a ret ; 16993 @@ -565,7 +565,7 @@ DayCare_GiveEgg: ; 169ac pop hl push bc ld b, $0 - predef CalcPkmnStats + predef Predef_CalcPkmnStats pop bc ld hl, MON_HP add hl, bc @@ -639,7 +639,7 @@ DayCare_InitBreeding: ; 16a3b cp DITTO ld a, $0 jr z, .LoadWhichBreedmonIsTheMother - farcall GetGender + farcall Predef_GetGender ld a, $0 jr z, .LoadWhichBreedmonIsTheMother inc a @@ -684,7 +684,7 @@ DayCare_InitBreeding: ; 16a3b ld de, wEggMonMoves xor a ld [Buffer1], a - predef FillMoves + predef Predef_FillMoves farcall InitEggMoves ld hl, wEggMonID ld a, [PlayerID] @@ -726,7 +726,7 @@ DayCare_InitBreeding: ; 16a3b ld a, TEMPMON ld [MonType], a push hl - farcall GetGender + farcall Predef_GetGender pop hl ld de, wBreedMon1DVs ld bc, wBreedMon2DVs @@ -770,7 +770,7 @@ DayCare_InitBreeding: ; 16a3b call CopyBytes ld hl, wEggMonMoves ld de, wEggMonPP - predef FillPP + predef Predef_FillPP ld hl, wMonOrItemNameBuffer ld de, StringBuffer1 ld bc, NAME_LENGTH diff --git a/engine/events/dratini.asm b/engine/events/dratini.asm index f110b34ab..83732bef2 100644 --- a/engine/events/dratini.asm +++ b/engine/events/dratini.asm @@ -1,4 +1,4 @@ -SpecialDratini: ; 0x8b170 +Special_Dratini: ; 0x8b170 ; if ScriptVar is 0 or 1, change the moveset of the last Dratini in the party. ; 0: give it a special moveset with Extremespeed. ; 1: give it the normal moveset of a level 15 Dratini. diff --git a/engine/events/elevator.asm b/engine/events/elevator.asm index e936976bb..e0426c5bd 100755 --- a/engine/events/elevator.asm +++ b/engine/events/elevator.asm @@ -189,8 +189,7 @@ Elevator_GetCurrentFloorString: ; 1353f Elevator_MenuDataHeader: ; 0x13550 db MENU_BACKUP_TILES ; flags - db 01, 12 ; start coords - db 09, 18 ; end coords + menu_coords 12, 1, 18, 9 dw Elevator_MenuData2 db 1 ; default option ; 0x13558 @@ -200,12 +199,12 @@ Elevator_MenuData2: ; 0x13558 db 4, 0 ; rows, columns db 1 ; horizontal spacing dbw 0, CurElevator - dba GetElevatorFlorStrings + dba GetElevatorFloorStrings dba NULL dba NULL ; 13568 -GetElevatorFlorStrings: ; 13568 +GetElevatorFloorStrings: ; 13568 ld a, [MenuSelection] GetFloorString: ; 1356b push de @@ -220,7 +219,7 @@ FloorToString: ; 13575 push de ld e, a ld d, 0 - ld hl, .floors + ld hl, ElevatorFloorNames add hl, de add hl, de ld a, [hli] @@ -230,54 +229,4 @@ FloorToString: ; 13575 ret ; 13583 -.floors - dw .b4f - dw .b3f - dw .b2f - dw .b1f - dw ._1f - dw ._2f - dw ._3f - dw ._4f - dw ._5f - dw ._6f - dw ._7f - dw ._8f - dw ._9f - dw ._10f - dw ._11f - dw .roof - -.b4f - db "B4F@" -.b3f - db "B3F@" -.b2f - db "B2F@" -.b1f - db "B1F@" -._1f - db "1F@" -._2f - db "2F@" -._3f - db "3F@" -._4f - db "4F@" -._5f - db "5F@" -._6f - db "6F@" -._7f - db "7F@" -._8f - db "8F@" -._9f - db "9F@" -._10f - db "10F@" -._11f - db "11F@" -.roof - db "ROOF@" -; 135db +INCLUDE "data/elevator_floors.asm" diff --git a/engine/events/field_moves.asm b/engine/events/field_moves.asm index a1a2e2e79..3fb1fe9e6 100755 --- a/engine/events/field_moves.asm +++ b/engine/events/field_moves.asm @@ -7,7 +7,7 @@ PlayWhirlpoolSound: ; 8c7d4 ; 8c7e1 BlindingFlash: ; 8c7e1 - farcall FadeOutPalettes + farcall Special_FadeOutPalettes ld hl, wStatusFlags set 2, [hl] ; Flash farcall ReplaceTimeOfDayPals @@ -15,7 +15,7 @@ BlindingFlash: ; 8c7e1 ld b, SCGB_MAPPALS call GetSGBLayout farcall LoadOW_BGPal7 - farcall FadeInPalettes + farcall Special_FadeInPalettes ret ; 8c80a @@ -39,13 +39,13 @@ ShakeHeadbuttTree: ; 8c80a ld [wCurrSpriteOAMAddr], a farcall DoNextFrameForAllSprites call HideHeadbuttTree - ld a, $20 - ld [wcf64], a + ld a, 32 + ld [wFrameCounter], a call WaitSFX ld de, SFX_SANDSTORM call PlaySFX .loop - ld hl, wcf64 + ld hl, wFrameCounter ld a, [hl] and a jr z, .done @@ -62,8 +62,8 @@ ShakeHeadbuttTree: ; 8c80a xor a ld [hBGMapMode], a farcall ClearSpriteAnims - ld hl, Sprites + 36 * 4 - ld bc, SpritesEnd - (Sprites + 36 * 4) + ld hl, Sprite37 + ld bc, SpritesEnd - Sprite37 xor a call ByteFill ld de, Font @@ -188,7 +188,7 @@ Cut_SpawnAnimateTree: ; 8ca23 (23:4a23) add hl, bc ld [hl], $84 ld a, 32 - ld [wcf64], a + ld [wFrameCounter], a ; Cut_StartWaiting ld hl, wJumptableIndex inc [hl] @@ -206,7 +206,7 @@ Cut_SpawnAnimateLeaves: ; 8ca3c (23:4a3c) ld a, $30 call Cut_SpawnLeaf ld a, 32 ; frames - ld [wcf64], a + ld [wFrameCounter], a ; Cut_StartWaiting ld hl, wJumptableIndex inc [hl] @@ -220,7 +220,7 @@ Cut_StartWaiting: ; 8ca5c (23:4a5c) inc [hl] Cut_WaitAnimSFX: ; 8ca64 (23:4a64) - ld hl, wcf64 + ld hl, wFrameCounter ld a, [hl] and a jr z, .finished @@ -336,7 +336,7 @@ FlyFromAnim: ; 8caed add hl, bc ld [hl], SPRITE_ANIM_SEQ_FLY_FROM ld a, 128 - ld [wcf64], a + ld [wFrameCounter], a .loop ld a, [wJumptableIndex] bit 7, a @@ -374,7 +374,7 @@ FlyToAnim: ; 8cb33 add hl, bc ld [hl], 11 * 8 ld a, 64 - ld [wcf64], a + ld [wFrameCounter], a .loop ld a, [wJumptableIndex] bit 7, a @@ -393,19 +393,19 @@ FlyToAnim: ; 8cb33 ret .RestorePlayerSprite_DespawnLeaves: ; 8cb82 (23:4b82) - ld hl, Sprites + 2 ; Tile ID + ld hl, Sprite01TileID xor a - ld c, $4 -.loop2 - ld [hli], a - inc hl - inc hl + ld c, 4 +.OAMloop + ld [hli], a ; tile id +rept SPRITEOAMSTRUCT_LENGTH +- 1 inc hl +endr inc a dec c - jr nz, .loop2 - ld hl, Sprites + 4 * 4 - ld bc, SpritesEnd - (Sprites + 4 * 4) + jr nz, .OAMloop + ld hl, Sprite05 + ld bc, SpritesEnd - Sprite05 xor a call ByteFill ret @@ -431,7 +431,7 @@ FlyFunction_InitGFX: ; 8cb9b (23:4b9b) FlyFunction_FrameTimer: ; 8cbc8 (23:4bc8) call .SpawnLeaf - ld hl, wcf64 + ld hl, wFrameCounter ld a, [hl] and a jr z, .exit diff --git a/engine/events/fish.asm b/engine/events/fish.asm index 9d1ea63ae..05bd7f530 100644 --- a/engine/events/fish.asm +++ b/engine/events/fish.asm @@ -80,7 +80,7 @@ rept 4 endr ld a, [TimeOfDay] - and 3 + maskbits NUM_DAYTIMES +- 1 cp NITE_F jr c, .time_species inc hl diff --git a/engine/events/fruit_trees.asm b/engine/events/fruit_trees.asm index d0b0bac15..44f2315a0 100644 --- a/engine/events/fruit_trees.asm +++ b/engine/events/fruit_trees.asm @@ -2,7 +2,7 @@ FruitTreeScript:: ; 44000 callasm GetCurTreeFruit opentext copybytetovar CurFruit - itemtotext $0, $0 + itemtotext USE_SCRIPT_VAR, MEM_BUFFER_0 writetext FruitBearingTreeText buttonsound callasm TryResetFruitTrees @@ -58,7 +58,7 @@ CheckFruitTree: ; 44055 ; 4405f PickedFruitTree: ; 4405f - farcall TrainerRankings_FruitPicked + farcall StubbedTrainerRankings_FruitPicked ld b, 1 jp GetFruitTreeFlag ; 4406a diff --git a/engine/events/halloffame.asm b/engine/events/halloffame.asm index f1981c2fd..c3e90b597 100755 --- a/engine/events/halloffame.asm +++ b/engine/events/halloffame.asm @@ -42,7 +42,7 @@ RedCredits:: ; 86455 ld [MusicFadeID + 1], a ld a, 10 ld [MusicFade], a - farcall FadeOutPalettes + farcall Special_FadeOutPalettes xor a ld [VramState], a ld [hMapAnims], a @@ -65,7 +65,7 @@ HallOfFame_FadeOutMusic: ; 8648e ld [MusicFadeID + 1], a ld a, 10 ld [MusicFade], a - farcall FadeOutPalettes + farcall Special_FadeOutPalettes xor a ld [VramState], a ld [hMapAnims], a @@ -92,9 +92,9 @@ AnimateHallOfFame: ; 864c3 ld de, MUSIC_HALL_OF_FAME call HallOfFame_PlayMusicDE xor a - ld [wcf64], a + ld [wHallOfFameMonCounter], a .loop - ld a, [wcf64] + ld a, [wHallOfFameMonCounter] cp PARTY_LENGTH jr nc, .done ld hl, wHallOfFameTempMon1 @@ -108,7 +108,7 @@ AnimateHallOfFame: ; 864c3 pop hl call .DisplayNewHallOfFamer jr c, .done - ld hl, wcf64 + ld hl, wHallOfFameMonCounter inc [hl] jr .loop @@ -130,7 +130,7 @@ AnimateHallOfFame: ; 864c3 call WaitBGMap decoord 6, 5 ld c, $6 - predef HOF_AnimateFrontpic + predef HOF_Predef_AnimateFrontpic ld c, 60 call DelayFrames and a @@ -244,18 +244,18 @@ AnimateHOFMonEntrance: ; 865b5 ld a, [hli] ld [TempMonDVs + 1], a ld hl, TempMonDVs - predef GetUnownLetter + predef Predef_GetUnownLetter hlcoord 0, 0 ld bc, SCREEN_WIDTH * SCREEN_HEIGHT ld a, " " call ByteFill ld de, vTiles2 tile $31 - predef GetMonBackpic + predef Predef_GetMonBackpic ld a, $31 ld [hGraphicStartTile], a hlcoord 6, 6 lb bc, 6, 6 - predef PlaceGraphic + predef Predef_PlaceGraphic ld a, $d0 ld [hSCY], a ld a, $90 @@ -321,7 +321,7 @@ _HallOfFamePC: ; 86650 .DisplayTeam: xor a - ld [wcf64], a + ld [wHallOfFameMonCounter], a .next call .DisplayMonAndStrings jr c, .start_button @@ -341,7 +341,7 @@ _HallOfFamePC: ; 86650 jr .loop .a_button - ld hl, wcf64 + ld hl, wHallOfFameMonCounter inc [hl] jr .next @@ -356,7 +356,7 @@ _HallOfFamePC: ; 86650 .DisplayMonAndStrings: ; Print the number of times the player has entered the Hall of Fame. ; If that number is above 200, print "HOF Master!" instead. - ld a, [wcf64] + ld a, [wHallOfFameMonCounter] cp PARTY_LENGTH jr nc, .fail ld hl, wHallOfFameTempMon1 @@ -403,7 +403,7 @@ _HallOfFamePC: ; 86650 call SetPalettes decoord 6, 5 ld c, $6 - predef HOF_AnimateFrontpic + predef HOF_Predef_AnimateFrontpic and a ret @@ -478,7 +478,7 @@ DisplayHOFMon: ; 86748 ld [CurPartySpecies], a ld [wd265], a ld hl, TempMonDVs - predef GetUnownLetter + predef Predef_GetUnownLetter xor a ld [wBoxAlignment], a hlcoord 6, 5 @@ -499,7 +499,7 @@ DisplayHOFMon: ; 86748 call PlaceString ld a, TEMPMON ld [MonType], a - farcall GetGender + farcall Predef_GetGender ld a, " " jr c, .got_gender ld a, "♂" @@ -546,7 +546,7 @@ HOF_AnimatePlayerPic: ; 86810 ld [hGraphicStartTile], a hlcoord 6, 6 lb bc, 6, 6 - predef PlaceGraphic + predef Predef_PlaceGraphic ld a, $d0 ld [hSCY], a ld a, $90 @@ -570,7 +570,7 @@ HOF_AnimatePlayerPic: ; 86810 ld [hGraphicStartTile], a hlcoord 12, 5 lb bc, 7, 7 - predef PlaceGraphic + predef Predef_PlaceGraphic ld a, $c0 ld [hSCX], a call WaitBGMap diff --git a/engine/events/happiness_egg.asm b/engine/events/happiness_egg.asm index a4ae8b7e6..2db54a1a7 100755 --- a/engine/events/happiness_egg.asm +++ b/engine/events/happiness_egg.asm @@ -1,4 +1,4 @@ -GetFirstPokemonHappiness: ; 718d +Special_GetFirstPokemonHappiness: ; 718d ld hl, PartyMon1Happiness ld bc, PARTYMON_STRUCT_LENGTH ld de, PartySpecies @@ -17,11 +17,11 @@ GetFirstPokemonHappiness: ; 718d call GetPokemonName jp CopyPokemonName_Buffer1_Buffer3 -CheckFirstMonIsEgg: ; 71ac +Special_CheckFirstMonIsEgg: ; 71ac ld a, [PartySpecies] ld [wd265], a cp EGG - ld a, $1 + ld a, 1 jr z, .egg xor a diff --git a/engine/events/heal_machine_anim.asm b/engine/events/heal_machine_anim.asm index 493330e58..da3b845e5 100755 --- a/engine/events/heal_machine_anim.asm +++ b/engine/events/heal_machine_anim.asm @@ -1,4 +1,4 @@ -HealMachineAnim: ; 12324 +Special_HealMachineAnim: ; 12324 ; If you have no Pokemon, don't change the buffer. This can lead to some glitchy effects if you have no Pokemon. ld a, [PartyCount] and a @@ -47,6 +47,7 @@ HealMachineAnim: ; 12324 ; 12365 .Pointers: ; 12365 +; entries correspond to HEALMACHINE_* constants dw .Pokecenter dw .ElmLab dw .HallOfFame @@ -73,20 +74,20 @@ HealMachineAnim: ; 12324 call .LoadPalettes ld de, .HealMachineGFX ld hl, vTiles0 tile $7c - lb bc, BANK(.HealMachineGFX), $2 + lb bc, BANK(.HealMachineGFX), 2 call Request2bpp ret ; 12393 .PC_LoadBallsOntoMachine: ; 12393 - ld hl, Sprites + $80 + ld hl, Sprite33 ld de, .PC_ElmsLab_OAM call .PlaceHealingMachineTile call .PlaceHealingMachineTile jr .LoadBallsOntoMachine .HOF_LoadBallsOntoMachine: ; 123a1 - ld hl, Sprites + $80 + ld hl, Sprite33 ld de, .HOF_OAM .LoadBallsOntoMachine: ; 123a7 @@ -160,7 +161,7 @@ INCBIN "gfx/overworld/heal_machine.2bpp" ld hl, .palettes ld de, wOBPals2 palette PAL_OW_TREE ld bc, 1 palettes - ld a, $5 + ld a, BANK(wOBPals2) call FarCopyWRAM ld a, $1 ld [hCGBPalUpdate], a @@ -168,14 +169,11 @@ INCBIN "gfx/overworld/heal_machine.2bpp" ; 12451 .palettes ; 12451 - RGB 31, 31, 31 - RGB 31, 19, 10 - RGB 31, 07, 01 - RGB 00, 00, 00 +INCLUDE "gfx/overworld/heal_machine.pal" ; 12459 .FlashPalettes8Times: ; 12459 - ld c, $8 + ld c, 8 .palette_loop push bc call .FlashPalettes @@ -198,7 +196,7 @@ INCBIN "gfx/overworld/heal_machine.2bpp" .go ld a, [rSVBK] push af - ld a, $5 + ld a, BANK(wOBPals2) ld [rSVBK], a ld hl, wOBPals2 palette PAL_OW_TREE @@ -249,17 +247,17 @@ INCBIN "gfx/overworld/heal_machine.2bpp" ld a, [de] add c inc de - ld [hli], a + ld [hli], a ; y ld a, [de] add b inc de - ld [hli], a + ld [hli], a ; x ld a, [de] inc de - ld [hli], a + ld [hli], a ; tile id ld a, [de] inc de - ld [hli], a + ld [hli], a ; attributes pop bc ret ; 124c1 diff --git a/engine/events/kurt.asm b/engine/events/kurt.asm index 4f3343dd1..13bde6f7e 100644 --- a/engine/events/kurt.asm +++ b/engine/events/kurt.asm @@ -76,7 +76,7 @@ Kurt_SelectApricorn: ; 88055 jr nz, .done .nope - xor a + xor a ; FALSE .done ld c, a @@ -85,13 +85,12 @@ Kurt_SelectApricorn: ; 88055 .MenuDataHeader: ; 0x88086 db MENU_BACKUP_TILES ; flags - db 01, 01 ; start coords - db 10, 13 ; end coords + menu_coords 1, 1, 13, 10 dw .MenuData2 db 1 ; default option ; 0x8808e - db 0 + db 0 ; XXX .MenuData2: ; 0x8808f db SCROLLINGMENU_DISPLAY_ARROWS ; flags @@ -160,8 +159,7 @@ Kurt_SelectQuantity: ; 880c2 .MenuDataHeader: ; 0x8810d db MENU_BACKUP_TILES ; flags - db 09, 06 ; start coords - db 12, 19 ; end coords + menu_coords 6, 9, SCREEN_WIDTH - 1, 12 dw NULL db -1 ; default option db 0 diff --git a/engine/events/lucky_number.asm b/engine/events/lucky_number.asm index 4488cfcc9..a172fc431 100644 --- a/engine/events/lucky_number.asm +++ b/engine/events/lucky_number.asm @@ -103,7 +103,7 @@ Special_CheckForLuckyNumberWinners: ; 4d87a ld a, [ScriptVar] and a ret z ; found nothing - farcall TrainerRankings_LuckyNumberShow + farcall StubbedTrainerRankings_LuckyNumberShow ld a, [wFoundMatchingIDInParty] and a push af diff --git a/engine/events/magikarp.asm b/engine/events/magikarp.asm index 68e8baad7..6588295b8 100644 --- a/engine/events/magikarp.asm +++ b/engine/events/magikarp.asm @@ -28,7 +28,7 @@ Special_CheckMagikarpLength: ; fbb32 ld c, l call CalcMagikarpLength call PrintMagikarpLength - farcall TrainerRankings_MagikarpLength + farcall StubbedTrainerRankings_MagikarpLength ld hl, .MeasureItText call PrintText @@ -52,22 +52,22 @@ Special_CheckMagikarpLength: ; fbb32 ld hl, PartyMonOT call SkipNames call CopyBytes - ld a, 3 + ld a, MAGIKARPLENGTH_BEAT_RECORD ld [ScriptVar], a ret .not_long_enough - ld a, 2 + ld a, MAGIKARPLENGTH_TOO_SHORT ld [ScriptVar], a ret .declined - ld a, 1 + ld a, MAGIKARPLENGTH_REFUSED ld [ScriptVar], a ret .not_magikarp - xor a + xor a ; MAGIKARPLENGTH_NOT_MAGIKARP ld [ScriptVar], a ret ; fbba9 diff --git a/engine/events/magnet_train.asm b/engine/events/magnet_train.asm index c85642ab8..c2ff36135 100755 --- a/engine/events/magnet_train.asm +++ b/engine/events/magnet_train.asm @@ -16,7 +16,7 @@ Special_MagnetTrain: ; 8cc04 ld h, a ld a, [rSVBK] push af - ld a, $5 + ld a, BANK(wMagnetTrain) ld [rSVBK], a ld a, h @@ -86,20 +86,20 @@ Special_MagnetTrain: ; 8cc04 MagnetTrain_UpdateLYOverrides: ; 8cc99 ld hl, LYOverridesBackup ld c, $2f - ld a, [wcf64] + ld a, [wMagnetTrainOffset] add a ld [hSCX], a call .loadloop ld c, $30 - ld a, [wcf65] + ld a, [wMagnetTrainPosition] call .loadloop ld c, $31 - ld a, [wcf64] + ld a, [wMagnetTrainOffset] add a call .loadloop ld a, [wMagnetTrainDirection] ld d, a - ld hl, wcf64 + ld hl, wMagnetTrainOffset ld a, [hl] add d add d @@ -129,7 +129,7 @@ MagntTrain_LoadGFX_PlayMusic: ; 8ccc9 ld [hSCY], a ld a, [rSVBK] push af - ld a, $1 + ld a, BANK(wPlayerGender) ld [rSVBK], a farcall GetPlayerIcon pop af @@ -147,11 +147,11 @@ MagntTrain_LoadGFX_PlayMusic: ; 8ccc9 call MagnetTrain_InitLYOverrides ld hl, wJumptableIndex xor a - ld [hli], a + ld [hli], a ; wJumptableIndex ld a, [wMagnetTrainInitPosition] - ld [hli], a - ld [hli], a - ld [hli], a + ld [hli], a ; wMagnetTrainOffset + ld [hli], a ; wMagnetTrainPosition + ld [hli], a ; wMagnetTrainWaitCounter ld de, MUSIC_MAGNET_TRAIN call PlayMusic2 ret @@ -220,8 +220,7 @@ GetMagnetTrainBGTiles: ; 8cd74 ; 8cd82 MagnetTrainBGTiles: ; 8cd82 -; Alternating tiles for each line -; of the Magnet Train tilemap. +; Alternating tiles for each line of the Magnet Train tilemap. db $4c, $4d ; bush db $5c, $5d ; bush db $4c, $4d ; bush @@ -263,25 +262,25 @@ SetMagnetTrainPals: ; 8cdc3 ; bushes hlbgcoord 0, 0 ld bc, 4 * BG_MAP_WIDTH - ld a, $2 + ld a, PAL_BG_GREEN call ByteFill ; train hlbgcoord 0, 4 ld bc, 10 * BG_MAP_WIDTH - xor a + xor a ; PAL_BG_GRAY call ByteFill ; more bushes hlbgcoord 0, 14 ld bc, 4 * BG_MAP_WIDTH - ld a, $2 + ld a, PAL_BG_GREEN call ByteFill ; train window hlbgcoord 7, 8 ld bc, 6 - ld a, $4 + ld a, PAL_BG_YELLOW call ByteFill ld a, $0 @@ -325,7 +324,7 @@ MagnetTrain_Jumptable: ; 8cdf7 ld b, SPRITE_ANIM_INDEX_MAGNET_TRAIN_RED ld a, [rSVBK] push af - ld a, $1 + ld a, BANK(wPlayerGender) ld [rSVBK], a ld a, [wPlayerGender] bit 0, a @@ -342,13 +341,13 @@ MagnetTrain_Jumptable: ; 8cdf7 ld [hl], $0 call .Next ld a, $80 - ld [wcf66], a + ld [wMagnetTrainWaitCounter], a ret ; 8ce47 .MoveTrain1: ; 8ce47 ld hl, wMagnetTrainHoldPosition - ld a, [wcf65] + ld a, [wMagnetTrainPosition] cp [hl] jr z, .PrepareToHoldTrain ld e, a @@ -356,7 +355,7 @@ MagnetTrain_Jumptable: ; 8cdf7 xor $ff inc a add e - ld [wcf65], a + ld [wMagnetTrainPosition], a ld hl, wGlobalAnimXOffset ld a, [wMagnetTrainDirection] add [hl] @@ -366,12 +365,12 @@ MagnetTrain_Jumptable: ; 8cdf7 .PrepareToHoldTrain: call .Next ld a, $80 - ld [wcf66], a + ld [wMagnetTrainWaitCounter], a ret ; 8ce6d .WaitScene: ; 8ce6d - ld hl, wcf66 + ld hl, wMagnetTrainWaitCounter ld a, [hl] and a jr z, .DoneWaiting @@ -385,7 +384,7 @@ MagnetTrain_Jumptable: ; 8cdf7 .MoveTrain2: ; 8ce7a ld hl, wMagnetTrainFinalPosition - ld a, [wcf65] + ld a, [wMagnetTrainPosition] cp [hl] jr z, .PrepareToFinishAnim ld e, a @@ -396,7 +395,7 @@ MagnetTrain_Jumptable: ; 8cdf7 ld a, e add d add d - ld [wcf65], a + ld [wMagnetTrainPosition], a ld hl, wGlobalAnimXOffset ld a, [wMagnetTrainDirection] ld d, a @@ -429,14 +428,14 @@ MagnetTrain_Jumptable_FirstRunThrough: ; 8ceae call DelayFrame ld a, [rSVBK] push af - ld a, $1 + ld a, BANK(wEnvironment) ld [rSVBK], a ld a, [TimeOfDayPal] push af ld a, [wEnvironment] push af ld a, [TimeOfDay] - and $3 + maskbits NUM_DAYTIMES +- 1 ld [TimeOfDayPal], a ld a, $1 ld [wEnvironment], a @@ -459,23 +458,11 @@ MagnetTrain_Jumptable_FirstRunThrough: ; 8ceae ; 8ceff MagnetTrainTilemap1: - db $1f, $05, $06, $0a, $0a - db $0a, $09, $0a, $0a, $0a - db $0a, $0a, $0a, $09, $0a - db $0a, $0a, $0b, $0c, $1f + db $1f, $05, $06, $0a, $0a, $0a, $09, $0a, $0a, $0a, $0a, $0a, $0a, $09, $0a, $0a, $0a, $0b, $0c, $1f MagnetTrainTilemap2: - db $14, $15, $16, $1a, $1a - db $1a, $19, $1a, $1a, $1a - db $1a, $1a, $1a, $19, $1a - db $1a, $1a, $1b, $1c, $1d + db $14, $15, $16, $1a, $1a, $1a, $19, $1a, $1a, $1a, $1a, $1a, $1a, $19, $1a, $1a, $1a, $1b, $1c, $1d MagnetTrainTilemap3: - db $24, $25, $26, $27, $07 - db $2f, $29, $28, $28, $28 - db $28, $28, $28, $29, $07 - db $2f, $2a, $2b, $2c, $2d + db $24, $25, $26, $27, $07, $2f, $29, $28, $28, $28, $28, $28, $28, $29, $07, $2f, $2a, $2b, $2c, $2d MagnetTrainTilemap4: - db $20, $1f, $2e, $1f, $17 - db $00, $2e, $1f, $1f, $1f - db $1f, $1f, $1f, $2e, $17 - db $00, $1f, $2e, $1f, $0f + db $20, $1f, $2e, $1f, $17, $00, $2e, $1f, $1f, $1f, $1f, $1f, $1f, $2e, $17, $00, $1f, $2e, $1f, $0f ; 8cf4f diff --git a/engine/events/map_name_sign.asm b/engine/events/map_name_sign.asm new file mode 100644 index 000000000..b20d74ee4 --- /dev/null +++ b/engine/events/map_name_sign.asm @@ -0,0 +1,274 @@ +MAP_NAME_SIGN_START EQU $60 + +ReturnFromMapSetupScript:: ; b8000 + xor a + ld [hBGMapMode], a + farcall .inefficient_farcall ; this is a waste of 6 ROM bytes and 6 stack bytes + ret +; b800a + +; should have just been a fallthrough +.inefficient_farcall ; b800a + ld a, [MapGroup] + ld b, a + ld a, [MapNumber] + ld c, a + call GetWorldMapLocation + ld [wCurrentLandmark], a + call .CheckNationalParkGate + jr z, .nationalparkgate + + call GetMapEnvironment + cp GATE + jr nz, .not_gate + +.nationalparkgate + ld a, -1 + ld [wCurrentLandmark], a + +.not_gate + ld hl, wEnteredMapFromContinue + bit 1, [hl] + res 1, [hl] + jr nz, .dont_do_map_sign + + call .CheckMovingWithinLandmark + jr z, .dont_do_map_sign + ld a, [wCurrentLandmark] + ld [wPreviousLandmark], a + + call .CheckSpecialMap + jr z, .dont_do_map_sign + +; Display for 60 frames + ld a, 60 + ld [wLandmarkSignTimer], a + call LoadMapNameSignGFX + call InitMapNameFrame + farcall HDMATransfer_OnlyTopFourRows + ret + +.dont_do_map_sign + ld a, [wCurrentLandmark] + ld [wPreviousLandmark], a + ld a, $90 + ld [rWY], a + ld [hWY], a + xor a + ld [hLCDCPointer], a + ret +; b8064 + +.CheckMovingWithinLandmark: ; b8064 + ld a, [wCurrentLandmark] + ld c, a + ld a, [wPreviousLandmark] + cp c + ret z + cp SPECIAL_MAP + ret +; b8070 + +.CheckSpecialMap: ; b8070 +; These landmarks do not get pop-up signs. + cp -1 + ret z + cp SPECIAL_MAP + ret z + cp RADIO_TOWER + ret z + cp LAV_RADIO_TOWER + ret z + cp UNDERGROUND_PATH + ret z + cp INDIGO_PLATEAU + ret z + cp POWER_PLANT + ret z + ld a, $1 + and a + ret +; b8089 + +.CheckNationalParkGate: ; b8089 + ld a, [MapGroup] + cp GROUP_ROUTE_35_NATIONAL_PARK_GATE + ret nz + ld a, [MapNumber] + cp MAP_ROUTE_35_NATIONAL_PARK_GATE + ret z + cp MAP_ROUTE_36_NATIONAL_PARK_GATE + ret +; b8098 + + +PlaceMapNameSign:: ; b8098 (2e:4098) + ld hl, wLandmarkSignTimer + ld a, [hl] + and a + jr z, .disappear + dec [hl] + cp 60 + ret z + cp 59 + jr nz, .skip2 + call InitMapNameFrame + call PlaceMapNameCenterAlign + farcall HDMATransfer_OnlyTopFourRows +.skip2 + ld a, $80 + ld a, $70 + ld [rWY], a + ld [hWY], a + ret + +.disappear + ld a, $90 + ld [rWY], a + ld [hWY], a + xor a + ld [hLCDCPointer], a + ret + + +LoadMapNameSignGFX: ; b80c6 + ld de, MapEntryFrameGFX + ld hl, vTiles2 tile MAP_NAME_SIGN_START + lb bc, BANK(MapEntryFrameGFX), 14 + call Get2bpp + ret +; b80d3 + +InitMapNameFrame: ; b80d3 + hlcoord 0, 0 + ld b, 2 + ld c, 18 + call InitMapSignAttrMap + call PlaceMapNameFrame + ret +; b80e1 + + +PlaceMapNameCenterAlign: ; b80e1 (2e:40e1) + ld a, [wCurrentLandmark] + ld e, a + farcall GetLandmarkName + call .GetNameLength + ld a, SCREEN_WIDTH + sub c + srl a + ld b, $0 + ld c, a + hlcoord 0, 2 + add hl, bc + ld de, StringBuffer1 + call PlaceString + ret + +.GetNameLength: ; b8101 (2e:4101) + ld c, 0 + push hl + ld hl, StringBuffer1 +.loop + ld a, [hli] + cp "@" + jr z, .stop + cp "%" + jr z, .loop + inc c + jr .loop +.stop + pop hl + ret + + +InitMapSignAttrMap: ; b8115 + ld de, AttrMap - TileMap + add hl, de + inc b + inc b + inc c + inc c + ld a, PAL_BG_TEXT | PRIORITY +.loop + push bc + push hl +.inner_loop + ld [hli], a + dec c + jr nz, .inner_loop + pop hl + ld de, SCREEN_WIDTH + add hl, de + pop bc + dec b + jr nz, .loop + ret +; b812f + +PlaceMapNameFrame: ; b812f + hlcoord 0, 0 + ; top left + ld a, MAP_NAME_SIGN_START + 1 + ld [hli], a + ; top row + ld a, MAP_NAME_SIGN_START + 2 + call .FillTopBottom + ; top right + ld a, MAP_NAME_SIGN_START + 4 + ld [hli], a + ; left, first line + ld a, MAP_NAME_SIGN_START + 5 + ld [hli], a + ; first line + call .FillMiddle + ; right, first line + ld a, MAP_NAME_SIGN_START + 11 + ld [hli], a + ; left, second line + ld a, MAP_NAME_SIGN_START + 6 + ld [hli], a + ; second line + call .FillMiddle + ; right, second line + ld a, MAP_NAME_SIGN_START + 12 + ld [hli], a + ; bottom left + ld a, MAP_NAME_SIGN_START + 7 + ld [hli], a + ; bottom + ld a, MAP_NAME_SIGN_START + 8 + call .FillTopBottom + ; bottom right + ld a, MAP_NAME_SIGN_START + 10 + ld [hl], a + ret +; b815b + +.FillMiddle: ; b815b + ld c, SCREEN_WIDTH - 2 + ld a, MAP_NAME_SIGN_START + 13 +.loop + ld [hli], a + dec c + jr nz, .loop + ret +; b8164 + +.FillTopBottom: ; b8164 + ld c, 5 + jr .enterloop + +.continueloop + ld [hli], a + ld [hli], a + +.enterloop + inc a + ld [hli], a + ld [hli], a + dec a + dec c + jr nz, .continueloop + ret +; b8172 diff --git a/engine/events/misc_scripts.asm b/engine/events/misc_scripts.asm index 97372a57a..73ed89143 100755 --- a/engine/events/misc_scripts.asm +++ b/engine/events/misc_scripts.asm @@ -2,7 +2,7 @@ Script_AbortBugContest: ; 0x122c1 checkflag ENGINE_BUG_CONTEST_TIMER iffalse .finish setflag ENGINE_DAILY_BUG_CONTEST - special ContestReturnMons + special Special_ContestReturnMons .finish end diff --git a/engine/events/misc_scripts_2.asm b/engine/events/misc_scripts_2.asm index c4c51d5e6..29416a9e5 100644 --- a/engine/events/misc_scripts_2.asm +++ b/engine/events/misc_scripts_2.asm @@ -13,7 +13,7 @@ RepelWoreOffScript:: ; 0x13619 HiddenItemScript:: ; 0x13625 opentext copybytetovar EngineBuffer3 - itemtotext 0, 0 + itemtotext USE_SCRIPT_VAR, MEM_BUFFER_0 writetext .found_text giveitem ITEM_FROM_MEM iffalse .bag_full diff --git a/engine/events/mom.asm b/engine/events/mom.asm index 061c12f8f..c7e1cd6e9 100644 --- a/engine/events/mom.asm +++ b/engine/events/mom.asm @@ -146,7 +146,7 @@ Special_BankOfMom: ; 16218 ld [hli], a ld [hl], a ld a, $5 - ld [wcf64], a + ld [wMomBankDigitCursorPosition], a call LoadStandardMenuDataHeader call Mom_SetUpDepositMenu call Mom_Wait10Frames @@ -213,7 +213,7 @@ Special_BankOfMom: ; 16218 ld [hli], a ld [hl], a ld a, $5 - ld [wcf64], a + ld [wMomBankDigitCursorPosition], a call LoadStandardMenuDataHeader call Mom_SetUpWithdrawMenu call Mom_Wait10Frames @@ -729,8 +729,7 @@ Mom_HeldString: ; 166b0 MenuDataHeader_0x166b5: ; 0x166b5 db MENU_BACKUP_TILES ; flags - db 00, 00 ; start coords - db 10, 10 ; end coords + menu_coords 0, 0, 10, 10 dw MenuData2_0x166bd db 1 ; default option ; 0x166bd diff --git a/engine/events/mom_phone.asm b/engine/events/mom_phone.asm index bef7d5688..50496e663 100755 --- a/engine/events/mom_phone.asm +++ b/engine/events/mom_phone.asm @@ -217,7 +217,7 @@ endr INCLUDE "data/items/mom_phone.asm" - db 0, 0, 0 ; XXX + db 0, 0, 0 ; unused _MomText_HiHowAreYou: ; 0xfd1b1 ; Hi, ! How are you? @@ -255,10 +255,10 @@ _MomText_ItsInRoom: ; 0xfd1ca db "@" ; 0xfd1cf - db 0 ; XXX + db 0 ; unused -Predef3A: ; fd1d0 +DummyPredef3A: ; fd1d0 ret ; fd1d1 - ret ; XXX + ret ; unused diff --git a/engine/events/move_deleter.asm b/engine/events/move_deleter.asm index 95fc0f1d8..3e06113ae 100644 --- a/engine/events/move_deleter.asm +++ b/engine/events/move_deleter.asm @@ -1,4 +1,4 @@ -MoveDeletion: +Special_MoveDeletion: ld hl, .IntroText call PrintText call YesNoBox diff --git a/engine/events/move_tutor.asm b/engine/events/move_tutor.asm index 5082364e0..8bb29f9ae 100644 --- a/engine/events/move_tutor.asm +++ b/engine/events/move_tutor.asm @@ -22,7 +22,7 @@ Special_MoveTutor: ; 4925b .enter_loop call CheckCanLearnMoveTutorMove jr nc, .loop - xor a + xor a ; FALSE ld [ScriptVar], a jr .quit @@ -35,10 +35,11 @@ Special_MoveTutor: ; 4925b .GetMoveTutorMove: ; 492a5 ld a, [ScriptVar] - cp 1 + cp MOVETUTOR_FLAMETHROWER jr z, .flamethrower - cp 2 + cp MOVETUTOR_THUNDERBOLT jr z, .thunderbolt + ; MOVETUTOR_ICE_BEAM ld a, ICE_BEAM ret @@ -54,7 +55,7 @@ CheckCanLearnMoveTutorMove: ; 492b9 ld hl, .MenuDataHeader call LoadMenuDataHeader - predef CanLearnTMHMMove + predef Predef_CanLearnTMHMMove push bc ld a, [CurPartyMon] @@ -78,7 +79,7 @@ CheckCanLearnMoveTutorMove: ; 492b9 callfar KnowsMove jr c, .didnt_learn - predef LearnMove + predef Predef_LearnMove ld a, b and a jr z, .didnt_learn @@ -99,5 +100,4 @@ CheckCanLearnMoveTutorMove: ; 492b9 .MenuDataHeader: ; 0x4930a db MENU_BACKUP_TILES ; flags - db 12, 00 ; start coords - db 17, 19 ; end coords + menu_coords 0, 12, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1 diff --git a/engine/events/overworld.asm b/engine/events/overworld.asm index 17ec54bb1..c9e0a5fe5 100755 --- a/engine/events/overworld.asm +++ b/engine/events/overworld.asm @@ -427,7 +427,7 @@ UsedSurfScript: ; c986 end .empty_fn ; c9a2 - farcall TrainerRankings_Surf + farcall StubbedTrainerRankings_Surf ret UsedSurfText: ; c9a9 @@ -623,7 +623,7 @@ FlyFunction: ; ca3b special UpdateTimePals callasm FlyFromAnim farscall Script_AbortBugContest - special WarpToSpawnPoint + special Special_WarpToSpawnPoint callasm DelayLoadingNewSprites writecode VAR_MOVEMENT, PLAYER_NORMAL newloadmap MAPSETUP_FLY @@ -700,7 +700,7 @@ Script_UsedWaterfall: ; 0xcb20 ld a, [PlayerStandingTile] call CheckWaterfallTile ret z - farcall TrainerRankings_Waterfall + farcall StubbedTrainerRankings_Waterfall ld a, $1 ld [ScriptVar], a ret @@ -871,7 +871,7 @@ dig_incave playsound SFX_WARP_TO applymovement PLAYER, .DigOut farscall Script_AbortBugContest - special WarpToSpawnPoint + special Special_WarpToSpawnPoint writecode VAR_MOVEMENT, PLAYER_NORMAL newloadmap MAPSETUP_DOOR playsound SFX_WARP_FROM @@ -958,7 +958,7 @@ TeleportFunction: ; cc61 playsound SFX_WARP_TO applymovement PLAYER, .TeleportFrom farscall Script_AbortBugContest - special WarpToSpawnPoint + special Special_WarpToSpawnPoint writecode VAR_MOVEMENT, PLAYER_NORMAL newloadmap MAPSETUP_TELEPORT playsound SFX_WARP_FROM @@ -986,7 +986,7 @@ StrengthFunction: ; cce5 jr c, .Failed jr .UseStrength -.AlreadyUsing: ; unreferenced +.Unreferenced_AlreadyUsing: ld hl, .JumpText call MenuTextBoxBackup ld a, $80 @@ -1749,7 +1749,7 @@ Script_GetOnBike_Register: ; 0xd14e special ReplaceKrisSprite end -; XXX +; unused nop ret diff --git a/engine/events/poisonstep.asm b/engine/events/poisonstep.asm index 00c7477bc..366ad1c03 100755 --- a/engine/events/poisonstep.asm +++ b/engine/events/poisonstep.asm @@ -104,7 +104,7 @@ DoPoisonStep:: ; 505da ld de, SFX_POISON call PlaySFX ld b, $2 - predef LoadPoisonBGPals + predef Predef_LoadPoisonBGPals call DelayFrame ret ; 50669 @@ -145,7 +145,7 @@ DoPoisonStep:: ; 505da ld a, [PartyCount] cp [hl] jr nz, .party_loop - predef CheckPlayerPartyForFitPkmn + predef Predef_CheckPlayerPartyForFitPkmn ld a, d ld [ScriptVar], a ret diff --git a/engine/events/poisonstep_pals.asm b/engine/events/poisonstep_pals.asm index 498ae8f18..326629138 100644 --- a/engine/events/poisonstep_pals.asm +++ b/engine/events/poisonstep_pals.asm @@ -1,4 +1,4 @@ -LoadPoisonBGPals: ; cbcdd +Predef_LoadPoisonBGPals: ; cbcdd call .LoadPals ld a, [hCGB] and a @@ -10,8 +10,8 @@ LoadPoisonBGPals: ; cbcdd and a jr nz, .cgb ld a, [TimeOfDayPal] - and $3 - cp $3 + maskbits NUM_DAYTIMES +- 1 + cp DARKNESS_F ld a, %00000000 jr z, .convert_pals ld a, %10101010 @@ -26,12 +26,11 @@ LoadPoisonBGPals: ; cbcdd .cgb ld a, [rSVBK] push af - ld a, $5 + ld a, BANK(wBGPals2) ld [rSVBK], a ld hl, wBGPals2 ld c, 4 palettes .loop -; RGB 28, 21, 31 ld a, LOW(palred 28 + palgreen 21 + palblue 31) ld [hli], a ld a, HIGH(palred 28 + palgreen 21 + palblue 31) diff --git a/engine/events/poke_seer.asm b/engine/events/poke_seer.asm index d6e335298..c7e6bd5ee 100644 --- a/engine/events/poke_seer.asm +++ b/engine/events/poke_seer.asm @@ -15,12 +15,12 @@ const SEERACTION_CANT_TELL_2 const SEERACTION_LEVEL_ONLY -SpecialPokeSeer: ; 4f0bc +Special_PokeSeer: ; 4f0bc ld a, SEER_INTRO call PrintSeerText call JoyWaitAorB - ld b, $6 + ld b, PARTY_LENGTH farcall SelectMonFromParty jr c, .cancel @@ -163,11 +163,11 @@ GetCaughtLevel: ; 4f18c call ByteFill ; caught level - ; Limited to between 1 and 63 for some reason. + ; Limited to between 1 and 63 since it's a 6-bit quantity. ld a, [wSeerCaughtData] - and $3f + and CAUGHT_LEVEL_MASK jr z, .unknown - cp 1 ; hatched from an egg + cp CAUGHT_EGG_LEVEL ; egg marker value jr nz, .print ld a, EGG_LEVEL ; egg hatch level @@ -193,7 +193,7 @@ GetCaughtLevel: ; 4f18c GetCaughtTime: ; 4f1c5 ld a, [wSeerCaughtData] - and $c0 + and CAUGHT_TIME_MASK jr z, .none rlca @@ -233,11 +233,11 @@ UnknownCaughtData: ; 4f1f8 GetCaughtLocation: ; 4f20a ld a, [wSeerCaughtGender] - and $7f + and CAUGHT_LOCATION_MASK jr z, .Unknown - cp $7f + cp EVENT_LOCATION jr z, .event - cp $7e + cp GIFT_LOCATION jr z, .fail ld e, a farcall GetLandmarkName @@ -440,22 +440,22 @@ GetCaughtGender: ; 4f301 add hl, bc ld a, [hl] - and $7f + and CAUGHT_LOCATION_MASK jr z, .genderless - cp $7f + cp EVENT_LOCATION jr z, .genderless ld a, [hl] - and $80 + and CAUGHT_GENDER_MASK jr nz, .male - ld c, 1 + ld c, CAUGHT_BY_GIRL ret .male - ld c, 2 + ld c, CAUGHT_BY_BOY ret .genderless - ld c, 0 + ld c, CAUGHT_BY_UNKNOWN ret ; 4f31c diff --git a/engine/events/pokecenter_pc.asm b/engine/events/pokecenter_pc.asm index 5d2dd35df..61d7346df 100755 --- a/engine/events/pokecenter_pc.asm +++ b/engine/events/pokecenter_pc.asm @@ -1,4 +1,4 @@ -PokemonCenterPC: ; 1559a +Special_PokemonCenterPC: ; 1559a call PC_CheckPartyForPokemon ret c call PC_PlayBootSound @@ -28,8 +28,7 @@ PokemonCenterPC: ; 1559a .TopMenu: db MENU_BACKUP_TILES | MENU_NO_CLICK_SFX ; flags - db 00, 00 ; start coords - db 12, 15 ; end coords + menu_coords 0, 0, 15, 12 dw .MenuData2 db 1 ; default option @@ -354,7 +353,7 @@ KrisWithdrawItemMenu: ; 0x157d1 ld [CurItemQuantity], a ld hl, PCItems call TossItem - predef PartyMonItemName + predef Predef_PartyMonItemName ld hl, .WithdrewText call MenuTextBox xor a @@ -421,7 +420,7 @@ KrisDepositItemMenu: ; 0x1588b farcall DepositSellInitPackBuffers .loop farcall DepositSellPack - ld a, [wcf66] + ld a, [wPackUsedItem] and a jr z, .close call .TryDepositItem @@ -518,7 +517,7 @@ KrisDepositItemMenu: ; 0x1588b ld [CurItemQuantity], a ld hl, NumItems call TossItem - predef PartyMonItemName + predef Predef_PartyMonItemName ld hl, .DepositText call PrintText ret @@ -620,9 +619,8 @@ PCItemsJoypad: ; 0x15985 ret .PCItemsMenuData: - db MENU_BACKUP_TILES - db 1, 4 ; start coords - db 10, 18 ; end coords + db MENU_BACKUP_TILES ; flags + menu_coords 4, 1, 18, 10 dw .MenuData2 db 1 ; default option diff --git a/engine/events/pokepic.asm b/engine/events/pokepic.asm index 854e73d01..1a433cb25 100755 --- a/engine/events/pokepic.asm +++ b/engine/events/pokepic.asm @@ -12,7 +12,7 @@ Pokepic:: ; 244e3 ld [CurSpecies], a call GetBaseData ld de, vTiles1 - predef GetMonFrontpic + predef Predef_GetMonFrontpic ld a, [wMenuBorderTopCoord] inc a ld b, a @@ -23,7 +23,7 @@ Pokepic:: ; 244e3 ld a, $80 ld [hGraphicStartTile], a lb bc, 7, 7 - predef PlaceGraphic + predef Predef_PlaceGraphic call WaitBGMap ret @@ -43,7 +43,6 @@ ClosePokepic:: ; 24528 PokepicMenuDataHeader: ; 0x24547 db MENU_BACKUP_TILES ; flags - db 04, 06 ; start coords - db 13, 14 ; end coords + menu_coords 6, 4, 14, 13 dw NULL db 1 ; default option diff --git a/engine/events/print_photo.asm b/engine/events/print_photo.asm index 06b01bbcf..54aa1892d 100755 --- a/engine/events/print_photo.asm +++ b/engine/events/print_photo.asm @@ -1,4 +1,4 @@ -PhotoStudio: ; 16dc7 +Special_PhotoStudio: ; 16dc7 ld hl, .Text_AskWhichMon call PrintText farcall SelectMonFromParty diff --git a/engine/events/print_unown.asm b/engine/events/print_unown.asm index 72248a67b..41f2bab9c 100644 --- a/engine/events/print_unown.asm +++ b/engine/events/print_unown.asm @@ -140,13 +140,13 @@ UnownPrinter: ; 16be4 xor a ld [wBoxAlignment], a ld de, vTiles2 - predef GetMonFrontpic + predef Predef_GetMonFrontpic call .Load2bppToSRAM hlcoord 1, 6 xor a ld [hGraphicStartTile], a lb bc, 7, 7 - predef PlaceGraphic + predef Predef_PlaceGraphic ld de, vTiles2 tile $31 farcall RotateUnownFrontpic ret @@ -154,7 +154,7 @@ UnownPrinter: ; 16be4 .Load2bppToSRAM: ; 16cff ld a, [rSVBK] push af - ld a, $6 + ld a, BANK(wDecompressScratch) ld [rSVBK], a ld a, BANK(sScratch) @@ -178,7 +178,7 @@ UnownPrinter: ; 16be4 hlcoord 1, 9 ld de, UnownDexVacantString call PlaceString - xor a + xor a ; sScratch call GetSRAMBank ld hl, sScratch ld bc, $31 tiles @@ -228,6 +228,6 @@ PlaceUnownPrinterFrontpic: ; 16dac ld a, $31 ld [hGraphicStartTile], a lb bc, 7, 7 - predef PlaceGraphic + predef Predef_PlaceGraphic ret ; 16dc7 diff --git a/engine/events/print_unown_2.asm b/engine/events/print_unown_2.asm index c932ded38..1e0b90fc5 100644 --- a/engine/events/print_unown_2.asm +++ b/engine/events/print_unown_2.asm @@ -1,7 +1,7 @@ RotateUnownFrontpic: ; e0000 ; something to do with Unown printer push de - xor a + xor a ; sScratch call GetSRAMBank ld hl, sScratch ld bc, 0 diff --git a/engine/events/prof_oaks_pc.asm b/engine/events/prof_oaks_pc.asm index 69949940b..ae84a43a5 100755 --- a/engine/events/prof_oaks_pc.asm +++ b/engine/events/prof_oaks_pc.asm @@ -3,7 +3,7 @@ ProfOaksPC: ; 0x265d3 call MenuTextBox call YesNoBox jr c, .shutdown - call ProfOaksPCBoot ; player chose "yes"? + call Special_ProfOaksPCBoot ; player chose "yes"? .shutdown ld hl, OakPCText4 call PrintText @@ -11,7 +11,7 @@ ProfOaksPC: ; 0x265d3 call ExitMenu ret -ProfOaksPCBoot ; 0x265ee +Special_ProfOaksPCBoot ; 0x265ee ld hl, OakPCText2 call PrintText call Rate diff --git a/engine/events/sacred_ash.asm b/engine/events/sacred_ash.asm index cc46eac9f..65ed83438 100755 --- a/engine/events/sacred_ash.asm +++ b/engine/events/sacred_ash.asm @@ -52,12 +52,12 @@ SacredAshScript: ; 0x50821 special HealParty reloadmappart playsound SFX_WARP_TO - special FadeOutPalettes - special FadeInPalettes - special FadeOutPalettes - special FadeInPalettes - special FadeOutPalettes - special FadeInPalettes + special Special_FadeOutPalettes + special Special_FadeInPalettes + special Special_FadeOutPalettes + special Special_FadeInPalettes + special Special_FadeOutPalettes + special Special_FadeInPalettes waitsfx writetext UnknownText_0x50845 playsound SFX_CAUGHT_MON diff --git a/engine/events/special.asm b/engine/events/special.asm index 939db4a25..62e0a620e 100755 --- a/engine/events/special.asm +++ b/engine/events/special.asm @@ -1,4 +1,6 @@ -SpecialGiveShuckle: ; 7305 +MANIA_OT_ID EQU 00518 + +Special_GiveShuckle: ; 7305 ; Adding to the party. xor a @@ -10,7 +12,7 @@ SpecialGiveShuckle: ; 7305 ld a, 15 ld [CurPartyLevel], a - predef TryAddMonToParty + predef Predef_TryAddMonToParty jr nc, .NotGiven ; Caught data. @@ -32,9 +34,9 @@ SpecialGiveShuckle: ; 7305 ; OT ID. ld hl, PartyMon1ID call AddNTimes - ld a, $2 + ld a, HIGH(MANIA_OT_ID) ld [hli], a - ld [hl], $6 + ld [hl], LOW(MANIA_OT_ID) ; Nickname. ld a, [PartyCount] @@ -54,8 +56,7 @@ SpecialGiveShuckle: ; 7305 ; Engine flag for this event. ld hl, wDailyFlags - set 5, [hl] -; setflag ENGINE_SHUCKLE_GIVEN + set 5, [hl] ; ENGINE_SHUCKLE_GIVEN ld a, 1 ld [ScriptVar], a ret @@ -70,7 +71,7 @@ SpecialShuckleOT: SpecialShuckleNick: db "SHUCKIE@" -SpecialReturnShuckle: ; 737e +Special_ReturnShuckle: ; 737e farcall SelectMonFromParty jr c, .refused @@ -85,10 +86,10 @@ SpecialReturnShuckle: ; 737e ; OT ID ld a, [hli] - cp HIGH(00518) + cp HIGH(MANIA_OT_ID) jr nz, .DontReturn ld a, [hl] - cp LOW(00518) + cp LOW(MANIA_OT_ID) jr nz, .DontReturn ; OT @@ -115,28 +116,28 @@ SpecialReturnShuckle: ; 737e call AddNTimes ld a, [hl] cp 150 - ld a, $3 + ld a, SHUCKIE_HAPPY jr nc, .HappyToStayWithYou xor a ; take from pc ld [wPokemonWithdrawDepositParameter], a callfar RemoveMonFromPartyOrBox - ld a, $2 + ld a, SHUCKIE_RETURNED .HappyToStayWithYou: ld [ScriptVar], a ret .refused - ld a, $1 + ld a, SHUCKIE_REFUSED ld [ScriptVar], a ret .DontReturn: - xor a + xor a ; SHUCKIE_WRONG_MON ld [ScriptVar], a ret .fainted - ld a, $4 + ld a, SHUCKIE_FAINTED ld [ScriptVar], a ret @@ -230,6 +231,5 @@ CopyPokemonName_Buffer1_Buffer3: ; 746e ld bc, PKMN_NAME_LENGTH jp CopyBytes -Predef1: ; 747a -; not used +DummyPredef1: ; 747a ret diff --git a/engine/events/std_scripts.asm b/engine/events/std_scripts.asm index 315e80d17..216ce0058 100644 --- a/engine/events/std_scripts.asm +++ b/engine/events/std_scripts.asm @@ -1,4 +1,5 @@ StdScripts:: +; entries correspond to constants/std_constants.asm dba PokecenterNurseScript dba DifficultBookshelfScript dba PictureBookshelfScript @@ -107,13 +108,13 @@ PokecenterNurseScript: farwritetext NurseTakePokemonText pause 20 - special TrainerRankings_Healings + special Special_StubbedTrainerRankings_Healings spriteface LAST_TALKED, LEFT pause 10 special HealParty playmusic MUSIC_NONE - writebyte 0 ; Machine is at a Pokemon Center - special HealMachineAnim + writebyte HEALMACHINE_POKECENTER + special Special_HealMachineAnim pause 30 special RestartMapMusic spriteface LAST_TALKED, DOWN @@ -123,7 +124,7 @@ PokecenterNurseScript: iftrue .no checkflag ENGINE_POKERUS ; nurse already talked about pokerus iftrue .no - special SpecialCheckPokerus + special Special_CheckPokerus iftrue .pokerus .no @@ -203,7 +204,7 @@ HomepageScript: Radio1Script: opentext writebyte MAPRADIO_POKEMON_CHANNEL - special MapRadio + special Special_MapRadio closetext end @@ -211,7 +212,7 @@ Radio2Script: ; Lucky Channel opentext writebyte MAPRADIO_LUCKY_CHANNEL - special MapRadio + special Special_MapRadio closetext end @@ -220,7 +221,7 @@ TrashCanScript: ; 0xbc1a5 PCScript: opentext - special PokemonCenterPC + special Special_PokemonCenterPC closetext end @@ -250,25 +251,25 @@ DayToTextScript: if_equal THURSDAY, .Thursday if_equal FRIDAY, .Friday if_equal SATURDAY, .Saturday - stringtotext .SundayText, 0 + stringtotext .SundayText, MEM_BUFFER_0 end .Monday: - stringtotext .MondayText, 0 + stringtotext .MondayText, MEM_BUFFER_0 end .Tuesday: - stringtotext .TuesdayText, 0 + stringtotext .TuesdayText, MEM_BUFFER_0 end .Wednesday: - stringtotext .WednesdayText, 0 + stringtotext .WednesdayText, MEM_BUFFER_0 end .Thursday: - stringtotext .ThursdayText, 0 + stringtotext .ThursdayText, MEM_BUFFER_0 end .Friday: - stringtotext .FridayText, 0 + stringtotext .FridayText, MEM_BUFFER_0 end .Saturday: - stringtotext .SaturdayText, 0 + stringtotext .SaturdayText, MEM_BUFFER_0 end .SundayText: db "SUNDAY@" @@ -297,7 +298,7 @@ RadioTowerRocketsScript: clearevent EVENT_USED_THE_CARD_KEY_IN_THE_RADIO_TOWER setevent EVENT_MAHOGANY_TOWN_POKEFAN_M_BLOCKS_EAST specialphonecall SPECIALCALL_WEIRDBROADCAST - setmapscene MAHOGANY_TOWN, $1 + setmapscene MAHOGANY_TOWN, 1 end BugContestResultsWarpScript: @@ -306,7 +307,7 @@ BugContestResultsWarpScript: setevent EVENT_ROUTE_36_NATIONAL_PARK_GATE_OFFICER_CONTEST_DAY clearevent EVENT_ROUTE_36_NATIONAL_PARK_GATE_OFFICER_NOT_CONTEST_DAY setevent EVENT_WARPED_FROM_ROUTE_35_NATIONAL_PARK_GATE - warp ROUTE_36_NATIONAL_PARK_GATE, $0, $4 + warp ROUTE_36_NATIONAL_PARK_GATE, 0, 4 applymovement PLAYER, Movement_ContestResults_WalkAfterWarp BugContestResultsScript: @@ -319,8 +320,8 @@ BugContestResultsScript: opentext farwritetext ContestResults_ReadyToJudgeText waitbutton - special BugContestJudging - RAM2MEM $0 + special Special_BugContestJudging + vartomem MEM_BUFFER_0 if_equal 1, BugContestResults_FirstPlace if_equal 2, BugContestResults_SecondPlace if_equal 3, BugContestResults_ThirdPlace @@ -345,17 +346,18 @@ BugContestResults_FinishUp iffalse BugContestResults_DidNotLeaveMons farwritetext ContestResults_ReturnPartyText waitbutton - special ContestReturnMons + special Special_ContestReturnMons BugContestResults_DidNotLeaveMons - special CheckPartyFullAfterContest - if_equal $0, BugContestResults_CleanUp - if_equal $2, BugContestResults_CleanUp + special Special_CheckPartyFullAfterContest + if_equal BUGCONTEST_CAUGHT_MON, BugContestResults_CleanUp + if_equal BUGCONTEST_NO_CATCH, BugContestResults_CleanUp + ; BUGCONTEST_BOXED_MON farwritetext ContestResults_PartyFullText waitbutton BugContestResults_CleanUp closetext - setscene $0 - setmapscene ROUTE_35_NATIONAL_PARK_GATE, $0 + setscene 0 + setmapscene ROUTE_35_NATIONAL_PARK_GATE, 0 setevent EVENT_BUG_CATCHING_CONTESTANT_1A setevent EVENT_BUG_CATCHING_CONTESTANT_2A setevent EVENT_BUG_CATCHING_CONTESTANT_3A @@ -383,7 +385,7 @@ BugContestResults_CleanUp BugContestResults_FirstPlace ; 0xbc31e setevent EVENT_GAVE_KURT_APRICORNS - itemtotext SUN_STONE, $1 + itemtotext SUN_STONE, MEM_BUFFER_1 farwritetext ContestResults_PlayerWonAPrizeText waitbutton verbosegiveitem SUN_STONE @@ -392,7 +394,7 @@ BugContestResults_FirstPlace ; 0xbc31e ; 0xbc332 BugContestResults_SecondPlace ; 0xbc332 - itemtotext EVERSTONE, $1 + itemtotext EVERSTONE, MEM_BUFFER_1 farwritetext ContestResults_PlayerWonAPrizeText waitbutton verbosegiveitem EVERSTONE @@ -401,7 +403,7 @@ BugContestResults_SecondPlace ; 0xbc332 ; 0xbc343 BugContestResults_ThirdPlace ; 0xbc343 - itemtotext GOLD_BERRY, $1 + itemtotext GOLD_BERRY, MEM_BUFFER_1 farwritetext ContestResults_PlayerWonAPrizeText waitbutton verbosegiveitem GOLD_BERRY @@ -620,7 +622,7 @@ InitializeEventsScript: return AskNumber1MScript: - special RandomPhoneMon + special Special_RandomPhoneMon checkcode VAR_CALLERID if_equal PHONE_SCHOOLBOY_JACK, .Jack if_equal PHONE_SAILOR_HUEY, .Huey @@ -705,7 +707,7 @@ AskNumber1MScript: end AskNumber2MScript: - special RandomPhoneMon + special Special_RandomPhoneMon checkcode VAR_CALLERID if_equal PHONE_SCHOOLBOY_JACK, .Jack if_equal PHONE_SAILOR_HUEY, .Huey @@ -1758,7 +1760,7 @@ RematchGiftFScript: end GymStatue1Script: - mapnametotext $0 + mapnametotext MEM_BUFFER_0 opentext farwritetext GymStatue_CityGymText waitbutton @@ -1766,7 +1768,7 @@ GymStatue1Script: end GymStatue2Script: - mapnametotext $0 + mapnametotext MEM_BUFFER_0 opentext farwritetext GymStatue_CityGymText buttonsound @@ -1812,18 +1814,18 @@ CoinVendor_IntroScript: ; 0xbcde0 loadmenudata .MenuDataHeader verticalmenu closewindow - if_equal $1, .Buy50 - if_equal $2, .Buy500 + if_equal 1, .Buy50 + if_equal 2, .Buy500 jump .Cancel ; 0xbcdf7 .Buy50: ; 0xbcdf7 - checkcoins 9949 - if_equal $0, .CoinCaseFull - checkmoney $0, 1000 - if_equal $2, .NotEnoughMoney + checkcoins MAX_COINS - 50 + if_equal HAVE_MORE, .CoinCaseFull + checkmoney YOUR_MONEY, 1000 + if_equal HAVE_LESS, .NotEnoughMoney givecoins 50 - takemoney $0, 1000 + takemoney YOUR_MONEY, 1000 waitsfx playsound SFX_TRANSACTION farwritetext CoinVendor_Buy50CoinsText @@ -1832,12 +1834,12 @@ CoinVendor_IntroScript: ; 0xbcde0 ; 0xbce1b .Buy500: ; 0xbce1b - checkcoins 9499 - if_equal $0, .CoinCaseFull - checkmoney $0, 10000 - if_equal $2, .NotEnoughMoney + checkcoins MAX_COINS - 500 + if_equal HAVE_MORE, .CoinCaseFull + checkmoney YOUR_MONEY, 10000 + if_equal HAVE_LESS, .NotEnoughMoney givecoins 500 - takemoney $0, 10000 + takemoney YOUR_MONEY, 10000 waitsfx playsound SFX_TRANSACTION farwritetext CoinVendor_Buy500CoinsText @@ -1869,8 +1871,7 @@ CoinVendor_IntroScript: ; 0xbcde0 .MenuDataHeader: db MENU_BACKUP_TILES ; flags - db 04, 00 ; start coords - db 11, 15 ; end coords + menu_coords 0, 4, 15, TEXTBOX_Y - 1 dw .MenuData2 db 1 ; default option @@ -1886,7 +1887,7 @@ CoinVendor_IntroScript: ; 0xbcde0 HappinessCheckScript: faceplayer opentext - special GetFirstPokemonHappiness + special Special_GetFirstPokemonHappiness if_less_than 50, .Unhappy if_less_than 150, .KindaHappy farwritetext HappinessText3 diff --git a/engine/events/treemons.asm b/engine/events/treemons.asm new file mode 100755 index 000000000..780fef2cc --- /dev/null +++ b/engine/events/treemons.asm @@ -0,0 +1,285 @@ +TreeMonEncounter: ; b81ea + farcall StubbedTrainerRankings_TreeEncounters + + xor a + ld [TempWildMonSpecies], a + ld [CurPartyLevel], a + + ld hl, TreeMonMaps + call GetTreeMonSet + jr nc, .no_battle + + call GetTreeMons + jr nc, .no_battle + + call GetTreeMon + jr nc, .no_battle + + ld a, BATTLETYPE_TREE + ld [BattleType], a + ld a, 1 + ld [ScriptVar], a + ret + +.no_battle + xor a + ld [ScriptVar], a + ret +; b8219 + +RockMonEncounter: ; b8219 + + xor a + ld [TempWildMonSpecies], a + ld [CurPartyLevel], a + + ld hl, RockMonMaps + call GetTreeMonSet + jr nc, .no_battle + + call GetTreeMons + jr nc, .no_battle + + ; 40% chance of an encounter + ld a, 10 + call RandomRange + cp 4 + jr nc, .no_battle + + call SelectTreeMon + jr nc, .no_battle + + ret + +.no_battle + xor a + ret +; b823e + + db $05 ; ???? + +GetTreeMonSet: ; b823f +; Return carry and treemon set in a +; if the current map is in table hl. + ld a, [MapNumber] + ld e, a + ld a, [MapGroup] + ld d, a +.loop + ld a, [hli] + cp -1 + jr z, .not_in_table + + cp d + jr nz, .skip2 + + ld a, [hli] + cp e + jr nz, .skip1 + + jr .in_table + +.skip2 + inc hl +.skip1 + inc hl + jr .loop + +.not_in_table + xor a + ret + +.in_table + ld a, [hl] + scf + ret +; b825e + +INCLUDE "data/wild/treemon_maps.asm" + +GetTreeMons: ; b82d2 +; Return the address of TreeMon table a in hl. +; Return nc if table a doesn't exist. + + cp NUM_TREEMON_SETS + jr nc, .quit + + and a + jr z, .quit + + ld e, a + ld d, 0 + ld hl, TreeMons + add hl, de + add hl, de + + ld a, [hli] + ld h, [hl] + ld l, a + + scf + ret + +.quit + xor a + ret +; b82e8 + +INCLUDE "data/wild/treemons.asm" + +GetTreeMon: ; b83e5 + push hl + call GetTreeScore + pop hl + and a ; TREEMON_SCORE_BAD + jr z, .bad + cp TREEMON_SCORE_GOOD + jr z, .good + cp TREEMON_SCORE_RARE + jr z, .rare + ret + +.bad + ; 10% chance of an encounter + ld a, 10 + call RandomRange + and a + jr nz, NoTreeMon + jr SelectTreeMon + +.good + ; 50% chance of an encounter + ld a, 10 + call RandomRange + cp 5 + jr nc, NoTreeMon + jr SelectTreeMon + +.rare + ; 80% chance of an encounter + ld a, 10 + call RandomRange + cp 8 + jr nc, NoTreeMon + jr .skip +.skip + ld a, [hli] + cp -1 + jr nz, .skip + call SelectTreeMon + ret +; b841f + +SelectTreeMon: ; b841f +; Read a TreeMons table and pick one monster at random. + + ld a, 100 + call RandomRange +.loop + sub [hl] + jr c, .ok + inc hl + inc hl + inc hl + jr .loop + +.ok + ld a, [hli] + cp -1 + jr z, NoTreeMon + + ld a, [hli] + ld [TempWildMonSpecies], a + ld a, [hl] + ld [CurPartyLevel], a + scf + ret + +NoTreeMon: ; b843b + xor a + ld [TempWildMonSpecies], a + ld [CurPartyLevel], a + ret +; b8443 + +GetTreeScore: ; b8443 + call .CoordScore + ld [Buffer1], a + call .OTIDScore + ld [Buffer2], a + ld c, a + ld a, [Buffer1] + sub c + jr z, .rare + jr nc, .ok + add 10 +.ok + cp 5 + jr c, .good + +.bad + xor a ; TREEMON_SCORE_BAD + ret + +.good + ld a, TREEMON_SCORE_GOOD + ret + +.rare + ld a, TREEMON_SCORE_RARE + ret +; b8466 + +.CoordScore: ; b8466 + call GetFacingTileCoord + ld hl, 0 + ld c, e + ld b, 0 + ld a, d + + and a + jr z, .next +.loop + add hl, bc + dec a + jr nz, .loop +.next + + add hl, bc + ld c, d + add hl, bc + + ld a, h + ld [hDividend], a + ld a, l + ld [hDividend + 1], a + ld a, 5 + ld [hDivisor], a + ld b, 2 + call Divide + + ld a, [hQuotient + 1] + ld [hDividend], a + ld a, [hQuotient + 2] + ld [hDividend + 1], a + ld a, 10 + ld [hDivisor], a + ld b, 2 + call Divide + + ld a, [hQuotient + 3] + ret +; b849d + +.OTIDScore: ; b849d + ld a, [PlayerID] + ld [hDividend], a + ld a, [PlayerID + 1] + ld [hDividend + 1], a + ld a, 10 + ld [hDivisor], a + ld b, 2 + call Divide + ld a, [hQuotient + 3] + ret +; b84b3 diff --git a/engine/events/crystal_unown.asm b/engine/events/unown_walls.asm index 54196498b..af7e80bf0 100644 --- a/engine/events/crystal_unown.asm +++ b/engine/events/unown_walls.asm @@ -1,4 +1,4 @@ -SpecialHoOhChamber: ; 0x8addb +Special_HoOhChamber: ; 0x8addb ld hl, PartySpecies ld a, [hl] cp HO_OH ; is Ho-oh the first Pokémon in the party? @@ -11,7 +11,7 @@ SpecialHoOhChamber: ; 0x8addb ret ; 0x8adef -SpecialOmanyteChamber: ; 8adef +Special_OmanyteChamber: ; 8adef call GetSecondaryMapHeaderPointer ld de, EVENT_WALL_OPENED_IN_OMANYTE_CHAMBER ld b, CHECK_FLAG @@ -105,7 +105,7 @@ SpecialKabutoChamber: ; 8ae4e Special_DisplayUnownWords: ; 8ae68 ld a, [ScriptVar] - ld hl, .MenuDataHeaders_UnownWalls + ld hl, MenuDataHeaders_UnownWalls and a jr z, .load @@ -131,21 +131,21 @@ Special_DisplayUnownWords: ; 8ae68 add hl, de ld a, [ScriptVar] ld c, a - ld de, .UnownText + ld de, UnownWalls and a jr z, .copy .loop2 ld a, [de] inc de - cp $ff + cp -1 jr nz, .loop2 dec c jr nz, .loop2 .copy - call .CopyWord + call _DisplayUnownWords_CopyWord ld bc, AttrMap - TileMap add hl, bc - call .FillAttr + call _DisplayUnownWords_FillAttr call WaitBGMap2 call JoyWaitAorB call PlayClickSFX @@ -153,66 +153,9 @@ Special_DisplayUnownWords: ; 8ae68 ret ; 8aebc -unownwall: MACRO -rept _NARG -if \1 == "-" -x = $64 -else -if \1 >= "Y" -x = 2 * (\1 - "Y") + $60 -else -if \1 >= "Q" -x = 2 * (\1 - "Q") + $40 -else -if \1 >= "I" -x = 2 * (\1 - "I") + $20 -else -x = 2 * (\1 - "A") -endc -endc -endc -endc - db x -shift -endr - db $ff -ENDM - -.UnownText: ; 8aebc -;.UnownText_Escape: - ; db $08, $44, $04, $00, $2e, $08, $ff - unownwall "E", "S", "C", "A", "P", "E" -;.UnownText_Light: - ; db $26, $20, $0c, $0e, $46, $ff - unownwall "L", "I", "G", "H", "T" -;.UnownText_Water: - ; db $4c, $00, $46, $08, $42, $ff - unownwall "W", "A", "T", "E", "R" -;.UnownText_Ho_Oh: - ; db $0e, $2c, $64, $2c, $0e, $ff - unownwall "H", "O", "-", "O", "H" -; 8aed5 - -.MenuDataHeaders_UnownWalls: ; 0x8aed5 -;.MenuDataHeader_Escape: - db MENU_BACKUP_TILES ; flags - db 04, 03 ; start coords - db 09, 16 ; end coords -;.MenuDataHeader_Light: - db MENU_BACKUP_TILES ; flags - db 04, 04 ; start coords - db 09, 15 ; end coords -;.MenuDataHeader_Water: - db MENU_BACKUP_TILES ; flags - db 04, 04 ; start coords - db 09, 15 ; end coords -;.MenuDataHeader_Ho_Oh: - db MENU_BACKUP_TILES ; flags - db 04, 04 ; start coords - db 09, 15 ; end coords -; 8aee9 +INCLUDE "data/unown_walls.asm" -.FillAttr: ; 8aee9 +_DisplayUnownWords_FillAttr: ; 8aee9 ld a, [de] cp $ff ret z @@ -226,7 +169,7 @@ ENDM inc hl inc hl inc de - jr .FillAttr + jr _DisplayUnownWords_FillAttr ; 8aefd .PlaceSquare: ; 8aefd @@ -242,7 +185,7 @@ ENDM ret ; 8af09 -.CopyWord: ; 8af09 +_DisplayUnownWords_CopyWord: ; 8af09 push hl push de .word_loop diff --git a/engine/events/whiteout.asm b/engine/events/whiteout.asm index a9d6f900e..aa629682f 100755 --- a/engine/events/whiteout.asm +++ b/engine/events/whiteout.asm @@ -4,13 +4,13 @@ Script_BattleWhiteout:: ; 0x124c1 ; 0x124c8 Script_OverworldWhiteout:: ; 0x124c8 - refreshscreen $0 + refreshscreen callasm OverworldBGMap Script_Whiteout: ; 0x124ce writetext .WhitedOutText waitbutton - special FadeOutPalettes + special Special_FadeOutPalettes pause 40 special HealParty checkflag ENGINE_BUG_CONTEST_TIMER @@ -18,7 +18,7 @@ Script_Whiteout: ; 0x124ce callasm HalveMoney callasm GetWhiteoutSpawn farscall Script_AbortBugContest - special WarpToSpawnPoint + special Special_WarpToSpawnPoint newloadmap MAPSETUP_WARP end_all @@ -49,7 +49,7 @@ BattleBGMap: ; 1250a ; 12513 HalveMoney: ; 12513 - farcall TrainerRankings_WhiteOuts + farcall StubbedTrainerRankings_WhiteOuts ; Halve the player's money. ld hl, Money |