diff --git a/audio.asm b/audio.asm index 8bc175fa..fc186894 100644 --- a/audio.asm +++ b/audio.asm @@ -377,9 +377,10 @@ PlayBattleMusic:: ld a, MUSIC_GYM_LEADER_BATTLE jr .playSong .notGymLeaderBattle + ld a, [wIsTrainerBattle] + and a + jr z, .wildBattle ld a, [wCurOpponent] - cp 200 - jr c, .wildBattle cp OPP_SONY3 jr z, .finalBattle cp OPP_LANCE diff --git a/constants/sprite_constants.asm b/constants/sprite_constants.asm index f70bfdcf..739516c3 100755 --- a/constants/sprite_constants.asm +++ b/constants/sprite_constants.asm @@ -101,6 +101,8 @@ const_value = 1 ITEM EQU $80 TRAINER EQU $40 +OW_POKEMON EQU $80 + BOULDER_MOVEMENT_BYTE_2 EQU $10 ; sprite facing directions diff --git a/data/mapObjects/powerplant.asm b/data/mapObjects/powerplant.asm index 402f899f..13db59be 100755 --- a/data/mapObjects/powerplant.asm +++ b/data/mapObjects/powerplant.asm @@ -9,15 +9,15 @@ PowerPlantObject: db 0 ; signs db 14 ; objects - object SPRITE_BALL, 9, 20, STAY, NONE, 1, VOLTORB, 40 - object SPRITE_BALL, 32, 18, STAY, NONE, 2, VOLTORB, 40 - object SPRITE_BALL, 21, 25, STAY, NONE, 3, VOLTORB, 40 - object SPRITE_BALL, 25, 18, STAY, NONE, 4, ELECTRODE, 43 - object SPRITE_BALL, 23, 34, STAY, NONE, 5, VOLTORB, 40 - object SPRITE_BALL, 26, 28, STAY, NONE, 6, VOLTORB, 40 - object SPRITE_BALL, 21, 14, STAY, NONE, 7, ELECTRODE, 43 - object SPRITE_BALL, 37, 32, STAY, NONE, 8, VOLTORB, 40 - object SPRITE_BIRD, 4, 9, STAY, UP, 9, ZAPDOS, 50 + object SPRITE_BALL, 9, 20, STAY, NONE, 1, VOLTORB, 40 | OW_POKEMON + object SPRITE_BALL, 32, 18, STAY, NONE, 2, VOLTORB, 40 | OW_POKEMON + object SPRITE_BALL, 21, 25, STAY, NONE, 3, VOLTORB, 40 | OW_POKEMON + object SPRITE_BALL, 25, 18, STAY, NONE, 4, ELECTRODE, 43 | OW_POKEMON + object SPRITE_BALL, 23, 34, STAY, NONE, 5, VOLTORB, 40 | OW_POKEMON + object SPRITE_BALL, 26, 28, STAY, NONE, 6, VOLTORB, 40 | OW_POKEMON + object SPRITE_BALL, 21, 14, STAY, NONE, 7, ELECTRODE, 43 | OW_POKEMON + object SPRITE_BALL, 37, 32, STAY, NONE, 8, VOLTORB, 40 | OW_POKEMON + object SPRITE_BIRD, 4, 9, STAY, UP, 9, ZAPDOS, 50 | OW_POKEMON object SPRITE_BALL, 7, 25, STAY, NONE, 10, CARBOS object SPRITE_BALL, 28, 3, STAY, NONE, 11, HP_UP object SPRITE_BALL, 34, 3, STAY, NONE, 12, RARE_CANDY diff --git a/data/mapObjects/seafoamislands5.asm b/data/mapObjects/seafoamislands5.asm index 9bd82887..1f6931fb 100755 --- a/data/mapObjects/seafoamislands5.asm +++ b/data/mapObjects/seafoamislands5.asm @@ -14,7 +14,7 @@ SeafoamIslands5Object: db 3 ; objects object SPRITE_BOULDER, 4, 15, STAY, NONE, 1 ; person object SPRITE_BOULDER, 5, 15, STAY, NONE, 2 ; person - object SPRITE_BIRD, 6, 1, STAY, DOWN, 3, ARTICUNO, 50 + object SPRITE_BIRD, 6, 1, STAY, DOWN, 3, ARTICUNO, 50 | OW_POKEMON ; warp-to warp_to 20, 17, SEAFOAM_ISLANDS_5_WIDTH ; SEAFOAM_ISLANDS_4 diff --git a/data/mapObjects/unknowndungeon3.asm b/data/mapObjects/unknowndungeon3.asm index d44ba254..61d51ec5 100755 --- a/data/mapObjects/unknowndungeon3.asm +++ b/data/mapObjects/unknowndungeon3.asm @@ -7,7 +7,7 @@ UnknownDungeon3Object: db 0 ; signs db 3 ; objects - object SPRITE_SLOWBRO, 27, 13, STAY, DOWN, 1, MEWTWO, 70 + object SPRITE_SLOWBRO, 27, 13, STAY, DOWN, 1, MEWTWO, 70 | OW_POKEMON object SPRITE_BALL, 16, 9, STAY, NONE, 2, ULTRA_BALL object SPRITE_BALL, 18, 1, STAY, NONE, 3, MAX_REVIVE diff --git a/data/mapObjects/victoryroad2.asm b/data/mapObjects/victoryroad2.asm index ffa95749..e6c9f06b 100755 --- a/data/mapObjects/victoryroad2.asm +++ b/data/mapObjects/victoryroad2.asm @@ -18,7 +18,7 @@ VictoryRoad2Object: object SPRITE_BLACK_HAIR_BOY_1, 19, 8, STAY, DOWN, 3, OPP_TAMER, 5 object SPRITE_BLACK_HAIR_BOY_2, 4, 2, STAY, DOWN, 4, OPP_POKEMANIAC, 6 object SPRITE_BLACK_HAIR_BOY_2, 26, 3, STAY, LEFT, 5, OPP_JUGGLER, 5 - object SPRITE_BIRD, 11, 5, STAY, UP, 6, MOLTRES, 50 + object SPRITE_BIRD, 11, 5, STAY, UP, 6, MOLTRES, 50 | OW_POKEMON object SPRITE_BALL, 27, 5, STAY, NONE, 7, TM_17 object SPRITE_BALL, 18, 9, STAY, NONE, 8, FULL_HEAL object SPRITE_BALL, 9, 11, STAY, NONE, 9, TM_05 diff --git a/engine/battle/battle_transitions.asm b/engine/battle/battle_transitions.asm index 985a1eb2..505e588d 100644 --- a/engine/battle/battle_transitions.asm +++ b/engine/battle/battle_transitions.asm @@ -81,9 +81,9 @@ BattleTransitions: dw BattleTransition_Split ; %111 GetBattleTransitionID_WildOrTrainer: - ld a, [wCurOpponent] - cp 200 - jr nc, .trainer + ld a, [wIsTrainerBattle] + and a + jr nz, .trainer res 0, c ret .trainer diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 09b35022..433ec679 100755 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -1037,6 +1037,12 @@ TrainerBattleVictory: ; win money ld hl, MoneyForWinningText call PrintText + + xor a + ld [wIsTrainerBattle], a + ld a, 1 + ld [wWasTrainerBattle], a + ld de, wPlayerMoney + 2 ld hl, wAmountMoneyWon + 2 ld c, $3 @@ -1224,6 +1230,8 @@ ChooseNextMon: ; called when player is out of usable mons. ; prints appropriate lose message, sets carry flag if player blacked out (special case for initial rival fight) HandlePlayerBlackOut: + xor a + ld [wIsTrainerBattle], a ld a, [wLinkState] cp LINK_STATE_BATTLING jr z, .notSony1Battle @@ -6939,9 +6947,11 @@ InitBattleCommon: push af res 1, [hl] callab InitBattleVariables + ld a, [wIsTrainerBattle] + and a + jp z, InitWildBattle ld a, [wEnemyMonSpecies2] sub 200 - jp c, InitWildBattle ld [wTrainerClass], a call GetTrainerInformation callab ReadTrainer diff --git a/engine/battle/wild_encounters.asm b/engine/battle/wild_encounters.asm index 5caff19e..2b729a96 100644 --- a/engine/battle/wild_encounters.asm +++ b/engine/battle/wild_encounters.asm @@ -120,6 +120,7 @@ TryDoWildEncounter: ld [wcf91], a ld [wEnemyMonSpecies2], a xor a + ld [wIsTrainerBattle], a ret WildMonEncounterSlotChances: diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm index f5630e05..5a80966c 100644 --- a/engine/overworld/movement.asm +++ b/engine/overworld/movement.asm @@ -118,6 +118,9 @@ UpdateNPCSprite: ld hl, wMapSpriteData add l ld l, a + jr nc, .nc + inc h +.nc ld a, [hl] ; read movement byte 2 ld [wCurSpriteMovement2], a ld h, $c1 diff --git a/engine/pokedex_rating.asm b/engine/pokedex_rating.asm index aff9769e..cd255a70 100755 --- a/engine/pokedex_rating.asm +++ b/engine/pokedex_rating.asm @@ -86,7 +86,7 @@ DexRatingsTable: dw PokedexRatingText_44242 db 150 dw PokedexRatingText_44247 - db 152 + db NUM_POKEMON + 1 ; 152 originally, prevent reading past the end of the list looking for an entry dw PokedexRatingText_4424c PokedexRatingText_44201: diff --git a/home.asm b/home.asm index a248fc36..fd6440b2 100644 --- a/home.asm +++ b/home.asm @@ -1487,6 +1487,8 @@ DisplayListMenuIDLoop:: ld [wd0b5], a ld a, BANK(ItemNames) ld [wPredefBank], a + ld a, ITEM_NAME + ld [wNameListType], a call GetName jr .storeChosenEntry .pokemonList @@ -2364,16 +2366,20 @@ EndTrainerBattle:: res 0, [hl] ; player is no longer engaged by any trainer ld a, [wIsInBattle] cp $ff - jp z, ResetButtonPressedAndMapScript + jr z, EndTrainerBattleWhiteout ld a, $2 call ReadTrainerHeaderInfo ld a, [wTrainerHeaderFlagBit] ld c, a ld b, FLAG_SET call TrainerFlagAction ; flag trainer as fought - ld a, [wEnemyMonOrTrainerClass] - cp 200 - jr nc, .skipRemoveSprite ; test if trainer was fought (in that case skip removing the corresponding sprite) + ld a, [wWasTrainerBattle] + and a + jr nz, .skipRemoveSprite ; test if trainer was fought (in that case skip removing the corresponding sprite) + ld a, [wCurMap] + cp POKEMONTOWER_7 + jr z, .skipRemoveSprite ; the tower 7f scripts call EndTrainerBattle manually after + ; wIsTrainerBattle has been unset ld hl, wMissableObjectList ld de, $2 ld a, [wSpriteIndex] @@ -2383,11 +2389,19 @@ EndTrainerBattle:: ld [wMissableObjectIndex], a ; load corresponding missable object index and remove it predef HideObject .skipRemoveSprite + xor a + ld [wWasTrainerBattle], a ld hl, wd730 bit 4, [hl] res 4, [hl] ret nz +EndTrainerBattleWhiteout: + xor a + ld [wIsTrainerBattle], a + ld [wWasTrainerBattle], a + ; fallthrough to original routine + ResetButtonPressedAndMapScript:: xor a ld [wJoyIgnore], a @@ -2406,12 +2420,14 @@ InitBattleEnemyParameters:: ld a, [wEngagedTrainerClass] ld [wCurOpponent], a ld [wEnemyMonOrTrainerClass], a - cp 200 + ld a, [wIsTrainerBattle] + and a + jr z, .noTrainer ld a, [wEngagedTrainerSet] - jr c, .noTrainer ld [wTrainerNo], a ret .noTrainer + ld a, [wEngagedTrainerSet] ld [wCurEnemyLVL], a ret @@ -2507,7 +2523,17 @@ EngageMapTrainer:: ld a, [hli] ; load trainer class ld [wEngagedTrainerClass], a ld a, [hl] ; load trainer mon set + bit 7, a + jr nz, .pokemon ld [wEngagedTrainerSet], a + ld a, 1 + ld [wIsTrainerBattle], a + jp PlayTrainerMusic +.pokemon + and $7F + ld [wEngagedTrainerSet], a + xor a + ld [wIsTrainerBattle], a jp PlayTrainerMusic PrintEndBattleText:: @@ -3213,14 +3239,21 @@ GetName:: ; [wPredefBank] = bank of list ; ; returns pointer to name in de + ld a, [wNameListType] + cp ITEM_NAME ld a, [wd0b5] ld [wd11e], a + jr nz, .noItem ; TM names are separate from item names. - ; BUG: This applies to all names instead of just items. + ; Only call this code if we are looking up an Item name + ; This originally applied to all name lists, not just items + ; This caused issues such as new moves having the wrong name + ; This also caused name issues upon evolution with Pokemon in the TM/HM ID range cp HM_01 jp nc, GetMachineName +.noItem ld a, [H_LOADEDROMBANK] push af push hl diff --git a/home/copy.asm b/home/copy.asm index be9c8c0c..2e6e1e9a 100644 --- a/home/copy.asm +++ b/home/copy.asm @@ -22,3 +22,18 @@ CopyData:: or b jr nz, CopyData ret + +FarCopyData2:: +; Identical to FarCopyData, but uses hROMBankTemp +; as temp space instead of wBuffer. + ld [hROMBankTemp], a + ld a, [H_LOADEDROMBANK] + push af + ld a, [hROMBankTemp] + ld [H_LOADEDROMBANK], a + ld [MBC1RomBank], a + call CopyData + pop af + ld [H_LOADEDROMBANK], a + ld [MBC1RomBank], a + ret diff --git a/home/copy2.asm b/home/copy2.asm index d4f35668..51fe1912 100644 --- a/home/copy2.asm +++ b/home/copy2.asm @@ -1,18 +1,3 @@ -FarCopyData2:: -; Identical to FarCopyData, but uses hROMBankTemp -; as temp space instead of wBuffer. - ld [hROMBankTemp], a - ld a, [H_LOADEDROMBANK] - push af - ld a, [hROMBankTemp] - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a - call CopyData - pop af - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a - ret - FarCopyData3:: ; Copy bc bytes from a:de to hl. ld [hROMBankTemp], a diff --git a/scripts/ceruleancity.asm b/scripts/ceruleancity.asm index 555e75f1..2cef6d1c 100755 --- a/scripts/ceruleancity.asm +++ b/scripts/ceruleancity.asm @@ -152,6 +152,8 @@ CeruleanCityScript1: ld a, $9 .done ld [wTrainerNo], a + ld a, 1 + ld [wIsTrainerBattle], a xor a ld [hJoyHeld], a @@ -164,6 +166,8 @@ CeruleanCityScript2: ld a, [wIsInBattle] cp $ff jp z, CeruleanCityScript_1948c + xor a + ld [wIsTrainerBattle], a call CeruleanCityScript_1955d ld a, $f0 ld [wJoyIgnore], a diff --git a/scripts/gary.asm b/scripts/gary.asm index 1fe65fb0..6edf5026 100755 --- a/scripts/gary.asm +++ b/scripts/gary.asm @@ -82,6 +82,8 @@ GaryScript2: ld a, $3 .saveTrainerId ld [wTrainerNo], a + ld a, 1 + ld [wIsTrainerBattle], a xor a ld [hJoyHeld], a @@ -93,6 +95,8 @@ GaryScript3: ld a, [wIsInBattle] cp $ff jp z, ResetGaryScript + xor a + ld [wIsTrainerBattle], a call UpdateSprites SetEvent EVENT_BEAT_CHAMPION_RIVAL ld a, $f0 diff --git a/scripts/oakslab.asm b/scripts/oakslab.asm index aa84fab9..6421526c 100755 --- a/scripts/oakslab.asm +++ b/scripts/oakslab.asm @@ -381,6 +381,8 @@ OaksLabScript11: ret nz ; define which team rival uses, and fight it + ld a, 1 + ld [wIsTrainerBattle], a ld a, OPP_SONY1 ld [wCurOpponent], a ld a, [wRivalStarter] @@ -415,6 +417,8 @@ OaksLabScript11: ret OaksLabScript12: + xor a + ld [wIsTrainerBattle], a ld a, $f0 ld [wJoyIgnore], a ld a, PLAYER_DIR_UP diff --git a/scripts/pokemontower2.asm b/scripts/pokemontower2.asm index 383b175d..f9e6ec2a 100755 --- a/scripts/pokemontower2.asm +++ b/scripts/pokemontower2.asm @@ -62,6 +62,8 @@ PokemonTower2Script1: ld a, [wIsInBattle] cp $ff jp z, PokemonTower2Script_604fe + xor a + ld [wIsTrainerBattle], a ld a, $f0 ld [wJoyIgnore], a SetEvent EVENT_BEAT_POKEMON_TOWER_RIVAL @@ -160,6 +162,8 @@ PokemonTower2Text1: ld a, $6 .done ld [wTrainerNo], a + ld a, 1 + ld [wIsTrainerBattle], a ld a, $1 ld [wPokemonTower2CurScript], a diff --git a/scripts/route12.asm b/scripts/route12.asm index 07b5833b..0d056699 100755 --- a/scripts/route12.asm +++ b/scripts/route12.asm @@ -33,6 +33,8 @@ Route12Script0: ld [wCurOpponent], a ld a, 30 ld [wCurEnemyLVL], a + xor a + ld [wIsTrainerBattle], a ld a, HS_ROUTE_12_SNORLAX ld [wMissableObjectIndex], a predef HideObject diff --git a/scripts/route16.asm b/scripts/route16.asm index 20431608..4b1bef4e 100755 --- a/scripts/route16.asm +++ b/scripts/route16.asm @@ -33,6 +33,8 @@ Route16Script0: ld [wCurOpponent], a ld a, 30 ld [wCurEnemyLVL], a + xor a + ld [wIsTrainerBattle], a ld a, HS_ROUTE_16_SNORLAX ld [wMissableObjectIndex], a predef HideObject diff --git a/scripts/route22.asm b/scripts/route22.asm index 86c3768b..00b38ac0 100755 --- a/scripts/route22.asm +++ b/scripts/route22.asm @@ -33,6 +33,8 @@ Route22Script_50ed6: .asm_50ee1 ld a, [hl] ld [wTrainerNo], a + ld a, 1 + ld [wIsTrainerBattle], a ret Route22MoveRivalSprite: @@ -149,6 +151,8 @@ Route22Script2: ld a, [wIsInBattle] cp $ff jp z, Route22Script_50ece + xor a + ld [wIsTrainerBattle], a ld a, [wSpriteStateData1 + 9] and a ; cp SPRITE_FACING_DOWN jr nz, .notDown @@ -304,6 +308,8 @@ Route22Script5: ld a, [wIsInBattle] cp $ff jp z, Route22Script_50ece + xor a + ld [wIsTrainerBattle], a ld a, $2 ld [H_SPRITEINDEX], a ld a, [wcf0d] diff --git a/scripts/silphco7.asm b/scripts/silphco7.asm index b211c8a9..66418108 100755 --- a/scripts/silphco7.asm +++ b/scripts/silphco7.asm @@ -199,6 +199,8 @@ SilphCo7Script3: ld a, $9 .asm_51cc0 ld [wTrainerNo], a + ld a, 1 + ld [wIsTrainerBattle], a ld a, $4 jp SilphCo7Text_51c10 @@ -206,6 +208,8 @@ SilphCo7Script4: ld a, [wIsInBattle] cp $ff jp z, SilphCo7Text_51c0c + xor a + ld [wIsTrainerBattle], a ld a, $f0 ld [wJoyIgnore], a SetEvent EVENT_BEAT_SILPH_CO_RIVAL diff --git a/scripts/ssanne2.asm b/scripts/ssanne2.asm index 654b881a..82e83913 100755 --- a/scripts/ssanne2.asm +++ b/scripts/ssanne2.asm @@ -115,6 +115,8 @@ SSAnne2Script1: ld a, $3 .done ld [wTrainerNo], a + ld a, 1 + ld [wIsTrainerBattle], a call SSAnne2Script_61416 ld a, $2 @@ -125,6 +127,8 @@ SSAnne2Script2: ld a, [wIsInBattle] cp $ff jp z, SSAnne2Script_613ab + xor a + ld [wIsTrainerBattle], a call SSAnne2Script_61416 ld a, $f0 ld [wJoyIgnore], a diff --git a/wram.asm b/wram.asm index ea87ba95..b0e46ab3 100755 --- a/wram.asm +++ b/wram.asm @@ -2284,7 +2284,11 @@ wPseudoItemID:: ; d152 wUnusedD153:: ; d153 ds 1 - ds 2 +wIsTrainerBattle:: + ds 1 + +wWasTrainerBattle:: + ds 1 wEvoStoneItemID:: ; d156 ds 1