diff --git a/src/dexnav.c b/src/dexnav.c index 61b7b78ba0..55e328bf83 100644 --- a/src/dexnav.c +++ b/src/dexnav.c @@ -398,7 +398,7 @@ static const struct SpriteTemplate sSearchIconSpriteTemplate = .callback = SpriteCallbackDummy, }; -static const struct SpriteTemplate sOwnedIconTemplate = +static const struct SpriteTemplate sOwnedIconTemplate = { .tileTag = OWNED_ICON_TAG, .paletteTag = 0xFFFF, //held item pal @@ -409,7 +409,7 @@ static const struct SpriteTemplate sOwnedIconTemplate = .callback = SpriteCallbackDummy, }; -static const struct SpriteTemplate sHiddenMonIconTemplate = +static const struct SpriteTemplate sHiddenMonIconTemplate = { .tileTag = HIDDEN_MON_ICON_TAG, .paletteTag = 0xFFFF, //held item pal @@ -446,7 +446,7 @@ static void DrawDexNavSearchMonIcon(u16 species, u8 *dst, bool8 owned) spriteId = CreateMonIcon(species, SpriteCB_MonIcon, SPECIES_ICON_X - 6, GetSearchWindowY() + 8, 0, 0xFFFFFFFF); gSprites[spriteId].oam.priority = 0; *dst = spriteId; - + if (owned) sDexNavSearchDataPtr->ownedIconSpriteId = CreateSprite(&sOwnedIconTemplate, SPECIES_ICON_X + 6, GetSearchWindowY() + 4, 0); } @@ -455,19 +455,19 @@ static void AddSearchWindow(u8 width) { struct WindowTemplate template; u16 y = 16; - + if (sDexNavSearchDataPtr->tileY > (gSaveBlock1Ptr->pos.y + 7)) y = 1; //draw at top if chosen tile is below LoadDexNavWindowGfx(sDexNavSearchDataPtr->windowId, 0x1d5, 14 * 16); - + SetWindowTemplateFields(&template, 0, 1, y, width, 3, 14, 8); - + sDexNavSearchDataPtr->windowId = AddWindow(&template); FillWindowPixelBuffer(sDexNavSearchDataPtr->windowId, PIXEL_FILL(1)); PutWindowTilemap(sDexNavSearchDataPtr->windowId); CopyWindowToVram(sDexNavSearchDataPtr->windowId, 3); - + DrawStdFrameWithCustomTileAndPalette(sDexNavSearchDataPtr->windowId, TRUE, 0x214, 14); } @@ -509,13 +509,13 @@ static void AddSearchWindowText(u16 species, u8 proximity, u8 searchLevel, bool8 StringExpandPlaceholders(gStringVar4, sText_EggMove); AddTextPrinterParameterized3(windowId, 0, WINDOW_MOVE_NAME_X, 0, sSearchFontColor, TEXT_SKIP_DRAW, gStringVar4); } - + if (searchLevel > 2) - { + { // ability name StringCopy(gStringVar1, gAbilitiesInfo[GetAbilityBySpecies(species, sDexNavSearchDataPtr->abilityNum)].name); AddTextPrinterParameterized3(windowId, 0, WINDOW_COL_1 + 16, 12, sSearchFontColor, TEXT_SKIP_DRAW, gStringVar1); - + // item name if (sDexNavSearchDataPtr->heldItem) { @@ -542,7 +542,7 @@ static void AddSearchWindowText(u16 species, u8 proximity, u8 searchLevel, bool8 static void DrawSearchWindow(u16 species, u8 potential, bool8 hidden) { u8 searchLevel = sDexNavSearchDataPtr->searchLevel; - + AddSearchWindow(SEARCH_WINDOW_WIDTH); AddSearchWindowText(species, sDexNavSearchDataPtr->proximity, searchLevel, hidden); } @@ -552,7 +552,7 @@ static void DrawSearchWindow(u16 species, u8 potential, bool8 hidden) static void RemoveDexNavWindowAndGfx(void) { u32 i; - + // try remove sprites if (sDexNavSearchDataPtr->iconSpriteId != MAX_SPRITES) DestroySprite(&gSprites[sDexNavSearchDataPtr->iconSpriteId]); @@ -564,13 +564,13 @@ static void RemoveDexNavWindowAndGfx(void) DestroySprite(&gSprites[sDexNavSearchDataPtr->ownedIconSpriteId]); if (sDexNavSearchDataPtr->exclamationSpriteId != MAX_SPRITES) DestroySprite(&gSprites[sDexNavSearchDataPtr->exclamationSpriteId]); - + for (i = 0; i < NELEMS(sDexNavSearchDataPtr->starSpriteIds); i++) { if (sDexNavSearchDataPtr->starSpriteIds[i] != MAX_SPRITES) DestroySprite(&gSprites[sDexNavSearchDataPtr->starSpriteIds[i]]); } - + FreeSpriteTilesByTag(HELD_ITEM_TAG); FreeSpriteTilesByTag(OWNED_ICON_TAG); FreeSpriteTilesByTag(HIDDEN_SEARCH_TAG); @@ -578,7 +578,7 @@ static void RemoveDexNavWindowAndGfx(void) FreeSpriteTilesByTag(LIT_STAR_TILE_TAG); FreeSpritePaletteByTag(HELD_ITEM_TAG); SafeFreeMonIconPalette(sDexNavSearchDataPtr->species); - + // remove window ClearStdWindowAndFrameToTransparent(sDexNavSearchDataPtr->windowId, FALSE); CopyWindowToVram(sDexNavSearchDataPtr->windowId, 3); @@ -620,7 +620,7 @@ static bool8 DexNavPickTile(u8 environment, u8 areaX, u8 areaY, bool8 smallScan) u8 *yPos = AllocZeroed((botX - topX) * (botY - topY) * sizeof(u8)); u32 iter = 0; bool32 ret = FALSE; - + // loop through every tile in area and evaluate while (topY < botY) { @@ -633,14 +633,14 @@ static bool8 DexNavPickTile(u8 environment, u8 areaX, u8 areaY, bool8 smallScan) tileBuffer = SNEAKING_PROXIMITY + 3; else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_DASH)) tileBuffer = SNEAKING_PROXIMITY + 1; - + if (GetPlayerDistance(topX, topY) <= tileBuffer) { // tile too close to player topX++; continue; } - + for (i = 0; i < OBJECT_EVENTS_COUNT; i++) { if (gObjectEvents[i].currentCoords.x == topX && gObjectEvents[i].currentCoords.y == topY) @@ -650,13 +650,13 @@ static bool8 DexNavPickTile(u8 environment, u8 areaX, u8 areaY, bool8 smallScan) break; } } - + if (nextIter) { topX++; continue; } - + weight = 0; // initiliaze weight switch (environment) { @@ -668,7 +668,7 @@ static bool8 DexNavPickTile(u8 environment, u8 areaX, u8 areaY, bool8 smallScan) // inside (cave) if (IsElevationMismatchAt(gObjectEvents[gPlayerAvatar.spriteId].currentElevation, topX, topY)) break; //occurs at same z coord - + scale = 440 - (smallScan * 200) - (GetPlayerDistance(topX, topY) / 2) - (2 * (topX + topY)); weight = ((Random() % scale) < 1) && !MapGridGetCollisionAt(topX, topY); } @@ -693,21 +693,21 @@ static bool8 DexNavPickTile(u8 environment, u8 areaX, u8 areaY, bool8 smallScan) default: break; } - + if (weight > 0) { xPos[iter] = topX; yPos[iter] = topY; iter++; } - + topX++; } - + topY++; topX = gSaveBlock1Ptr->pos.x - SCANSTART_X + (smallScan * 5); } - + if (iter > 0) { i = Random() % iter; @@ -715,7 +715,7 @@ static bool8 DexNavPickTile(u8 environment, u8 areaX, u8 areaY, bool8 smallScan) sDexNavSearchDataPtr->tileY = yPos[i]; ret = TRUE; } - + Free(xPos); Free(yPos); @@ -727,7 +727,7 @@ static bool8 TryStartHiddenMonFieldEffect(u8 environment, u8 xSize, u8 ySize, bo { u8 currMapType = GetCurrentMapType(); u8 fldEffId = 0; - + if (DexNavPickTile(environment, xSize, ySize, smallScan)) { u8 metatileBehaviour = MapGridGetMetatileBehaviorAt(sDexNavSearchDataPtr->tileX, sDexNavSearchDataPtr->tileY); @@ -770,7 +770,7 @@ static bool8 TryStartHiddenMonFieldEffect(u8 environment, u8 xSize, u8 ySize, bo default: return FALSE; } - + if (fldEffId != 0) { gFieldEffectArguments[0] = sDexNavSearchDataPtr->tileX; @@ -780,7 +780,7 @@ static bool8 TryStartHiddenMonFieldEffect(u8 environment, u8 xSize, u8 ySize, bo sDexNavSearchDataPtr->fldEffSpriteId = FieldEffectStart(fldEffId); if (sDexNavSearchDataPtr->fldEffSpriteId == MAX_SPRITES) return FALSE; - + sDexNavSearchDataPtr->fldEffId = fldEffId; return TRUE; } @@ -827,7 +827,7 @@ static u8 GetSearchLevel(u16 dexNum) static void Task_SetUpDexNavSearch(u8 taskId) { struct Task *task = &gTasks[taskId]; - + u16 species = sDexNavSearchDataPtr->species; u8 searchLevel = GetSearchLevel(SpeciesToNationalPokedexNum(species)); @@ -839,15 +839,15 @@ static void Task_SetUpDexNavSearch(u8 taskId) sDexNavSearchDataPtr->starSpriteIds[1] = MAX_SPRITES; sDexNavSearchDataPtr->starSpriteIds[2] = MAX_SPRITES; sDexNavSearchDataPtr->ownedIconSpriteId = MAX_SPRITES; - sDexNavSearchDataPtr->exclamationSpriteId = MAX_SPRITES; + sDexNavSearchDataPtr->exclamationSpriteId = MAX_SPRITES; sDexNavSearchDataPtr->searchLevel = searchLevel; - + DexNavGenerateMoveset(species, searchLevel, sDexNavSearchDataPtr->monLevel, &sDexNavSearchDataPtr->moves[0]); sDexNavSearchDataPtr->heldItem = DexNavGenerateHeldItem(species, searchLevel); sDexNavSearchDataPtr->abilityNum = DexNavGetAbilityNum(species, searchLevel); sDexNavSearchDataPtr->potential = DexNavGeneratePotential(searchLevel); DexNavProximityUpdate(); - + LoadSearchIconData(); if (sDexNavSearchDataPtr->hiddenSearch) { @@ -858,7 +858,7 @@ static void Task_SetUpDexNavSearch(u8 taskId) DexNavDrawIcons(); DexNavUpdateSearchWindow(sDexNavSearchDataPtr->proximity, searchLevel); } - + FlagSet(DN_FLAG_SEARCHING); gPlayerAvatar.creeping = TRUE; //initialize as true in case mon appears beside you task->tProximity = gSprites[gPlayerAvatar.spriteId].x; @@ -872,7 +872,7 @@ static void DexNavSearchBail(u8 taskId, const u8 *script) TRY_FREE_AND_SET_NULL(sDexNavSearchDataPtr); FreeMonIconPalettes(); ScriptContext_SetupScript(script); - DestroyTask(taskId); + DestroyTask(taskId); } static void Task_InitDexNavSearch(u8 taskId) @@ -880,32 +880,32 @@ static void Task_InitDexNavSearch(u8 taskId) struct Task *task = &gTasks[taskId]; u16 species = task->tSpecies; u8 environment = task->tEnvironment; - + sDexNavSearchDataPtr = AllocZeroed(sizeof(struct DexNavSearch)); if (sDexNavSearchDataPtr == NULL) { DexNavSearchBail(taskId, EventScript_NotFoundNearby); return; } - + // assign non-objects to struct sDexNavSearchDataPtr->species = species; sDexNavSearchDataPtr->environment = environment; //updated in DexNavTryGenerateMonLevel if hidden mon sDexNavSearchDataPtr->isHiddenMon = (environment == ENCOUNTER_TYPE_HIDDEN) ? TRUE : FALSE; sDexNavSearchDataPtr->monLevel = DexNavTryGenerateMonLevel(species, environment); - + if (GetFlashLevel() > 0) { DexNavSearchBail(taskId, EventScript_TooDark); return; } - + if (sDexNavSearchDataPtr->monLevel == MON_LEVEL_NONEXISTENT || !TryStartHiddenMonFieldEffect(sDexNavSearchDataPtr->environment, 12, 12, FALSE)) { DexNavSearchBail(taskId, EventScript_NotFoundNearby); return; } - + sDexNavSearchDataPtr->hiddenSearch = FALSE; task->tRevealed = TRUE; //search window revealed task->func = Task_SetUpDexNavSearch; @@ -915,13 +915,13 @@ static void DexNavDrawPotentialStars(u8 potential, u8* dst) { u8 spriteId; u32 i; - + for (i = 0; i < NELEMS(sDexNavSearchDataPtr->starSpriteIds); i++) { spriteId = MAX_SPRITES; if (potential > i) spriteId = CreateSprite(&sPotentialStarTemplate, SPECIES_ICON_X - 20, GetSearchWindowY() + 4 + (i * 8), 0); - + dst[i] = spriteId; if (spriteId != MAX_SPRITES) gSprites[spriteId].invisible = TRUE; @@ -938,7 +938,7 @@ static void DexNavUpdateDirectionArrow(void) u16 deltaY = abs(tileY - playerY); const u8 *str; u8 windowId = sDexNavSearchDataPtr->windowId; - + FillWindowPixelRect(windowId, PIXEL_FILL(1), SEARCH_ARROW_X, SEARCH_ARROW_Y, 12, 12); if (deltaX <= 1 && deltaY <= 1) { @@ -958,7 +958,7 @@ static void DexNavUpdateDirectionArrow(void) else str = sText_ArrowDown; //player above } - + AddTextPrinterParameterized3(windowId, 1, SEARCH_ARROW_X, SEARCH_ARROW_Y, sSearchFontColor, TEXT_SKIP_DRAW, str); CopyWindowToVram(windowId, 2); } @@ -966,7 +966,7 @@ static void DexNavUpdateDirectionArrow(void) static void DexNavDrawIcons(void) { u16 species = sDexNavSearchDataPtr->species; - + DrawSearchWindow(species, sDexNavSearchDataPtr->potential, FALSE); DrawDexNavSearchMonIcon(species, &sDexNavSearchDataPtr->iconSpriteId, GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_CAUGHT)); DrawDexNavSearchHeldItem(&sDexNavSearchDataPtr->itemSpriteId); @@ -981,10 +981,10 @@ bool8 TryStartDexNavSearch(void) { u8 taskId; u16 val = VarGet(DN_VAR_SPECIES); - + if (FlagGet(DN_FLAG_SEARCHING) || (val & DEXNAV_MASK_SPECIES) == SPECIES_NONE) return FALSE; - + HideMapNamePopUpWindow(); ChangeBgY_ScreenOff(0, 0, 0); taskId = CreateTask(Task_InitDexNavSearch, 0); @@ -1024,26 +1024,26 @@ static void Task_RevealHiddenMon(u8 taskId) { struct Task *task = &gTasks[taskId]; u16 species = sDexNavSearchDataPtr->species; - + // remove owned icon if it exists if (sDexNavSearchDataPtr->ownedIconSpriteId != MAX_SPRITES) { DestroySprite(&gSprites[sDexNavSearchDataPtr->ownedIconSpriteId]); sDexNavSearchDataPtr->ownedIconSpriteId = MAX_SPRITES; } - + // remove exclamation if it exists if (sDexNavSearchDataPtr->exclamationSpriteId != MAX_SPRITES) { DestroySprite(&gSprites[sDexNavSearchDataPtr->exclamationSpriteId]); sDexNavSearchDataPtr->exclamationSpriteId = MAX_SPRITES; } - - + + if (!GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_SEEN)) { u8 index; - + //if not seen, hide name and whiteout mon DrawSearchWindow(species, sDexNavSearchDataPtr->potential, TRUE); DrawDexNavSearchMonIcon(species, &sDexNavSearchDataPtr->iconSpriteId, FALSE); @@ -1058,7 +1058,7 @@ static void Task_RevealHiddenMon(u8 taskId) DrawSearchWindow(species, sDexNavSearchDataPtr->potential, FALSE); DrawDexNavSearchMonIcon(species, &sDexNavSearchDataPtr->iconSpriteId, GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_CAUGHT)); } - + DexNavUpdateDirectionArrow(); task->func = Task_DexNavSearch; task->tFrameCount = 0; //restart search clock @@ -1067,7 +1067,7 @@ static void Task_RevealHiddenMon(u8 taskId) static void Task_DexNavSearch(u8 taskId) { struct Task *task = &gTasks[taskId]; - + if (sDexNavSearchDataPtr->proximity > MAX_PROXIMITY) { // out of range if (sDexNavSearchDataPtr->hiddenSearch && !task->tRevealed) @@ -1076,7 +1076,7 @@ static void Task_DexNavSearch(u8 taskId) EndDexNavSearchSetupScript(EventScript_LostSignal, taskId); return; } - + if (sDexNavSearchDataPtr->proximity <= CREEPING_PROXIMITY && !gPlayerAvatar.creeping && task->tFrameCount > 60) { //should be creeping but player walks normally if (sDexNavSearchDataPtr->hiddenSearch && !task->tRevealed) @@ -1085,20 +1085,20 @@ static void Task_DexNavSearch(u8 taskId) EndDexNavSearchSetupScript(EventScript_MovedTooFast, taskId); return; } - - if (sDexNavSearchDataPtr->proximity <= SNEAKING_PROXIMITY && TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_DASH | PLAYER_AVATAR_FLAG_BIKE)) + + if (sDexNavSearchDataPtr->proximity <= SNEAKING_PROXIMITY && TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_DASH | PLAYER_AVATAR_FLAG_BIKE)) { // running/biking too close //always do event script, even if player hasn't revealed a hidden mon. It's assumed they would be creeping towards it EndDexNavSearchSetupScript(EventScript_MovedTooFast, taskId); return; } - + if (ArePlayerFieldControlsLocked() == TRUE) { // check if script just executed EndDexNavSearch(taskId); return; } - + if (gTasks[taskId].tFrameCount > DEXNAV_TIMEOUT * 60) { // player took too long if (sDexNavSearchDataPtr->hiddenSearch && !task->tRevealed) @@ -1107,11 +1107,11 @@ static void Task_DexNavSearch(u8 taskId) EndDexNavSearchSetupScript(EventScript_PokemonGotAway, taskId); return; } - + if (sDexNavSearchDataPtr->proximity < 1) { gDexNavBattle = TRUE; - CreateDexNavWildMon(sDexNavSearchDataPtr->species, sDexNavSearchDataPtr->potential, sDexNavSearchDataPtr->monLevel, + CreateDexNavWildMon(sDexNavSearchDataPtr->species, sDexNavSearchDataPtr->potential, sDexNavSearchDataPtr->monLevel, sDexNavSearchDataPtr->abilityNum, sDexNavSearchDataPtr->heldItem, sDexNavSearchDataPtr->moves); FlagClear(DN_FLAG_SEARCHING); @@ -1120,7 +1120,7 @@ static void Task_DexNavSearch(u8 taskId) DestroyTask(taskId); return; } - + if (sDexNavSearchDataPtr->hiddenSearch && !task->tRevealed && (JOY_NEW(R_BUTTON) || (sDexNavSearchDataPtr->proximity < CREEPING_PROXIMITY))) { @@ -1141,13 +1141,13 @@ static void Task_DexNavSearch(u8 taskId) && task->tRevealed) { FieldEffectStop(&gSprites[sDexNavSearchDataPtr->fldEffSpriteId], sDexNavSearchDataPtr->fldEffId); - + if (!TryStartHiddenMonFieldEffect(sDexNavSearchDataPtr->environment, 10, 10, TRUE)) { EndDexNavSearchSetupScript(EventScript_PokemonGotAway, taskId); return; } - + sDexNavSearchDataPtr->movementCount++; } @@ -1157,10 +1157,10 @@ static void Task_DexNavSearch(u8 taskId) //player has moved if (task->tRevealed) //update search window info only if hidden mon has been revealed (always true for search mode) DexNavUpdateSearchWindow(sDexNavSearchDataPtr->proximity, sDexNavSearchDataPtr->searchLevel); - + task->tProximity = sDexNavSearchDataPtr->proximity; } - + task->tFrameCount++; } @@ -1170,12 +1170,12 @@ static void DexNavUpdateSearchWindow(u8 proximity, u8 searchLevel) if (sDexNavSearchDataPtr->hiddenSearch && !GetSetPokedexFlag(SpeciesToNationalPokedexNum(sDexNavSearchDataPtr->species), FLAG_GET_SEEN)) hideName = TRUE; //if a detector mode hidden search and player hasn't seen the mon, hide info - + FillWindowPixelBuffer(sDexNavSearchDataPtr->windowId, PIXEL_FILL(1)); //clear window AddSearchWindowText(sDexNavSearchDataPtr->species, proximity, searchLevel, hideName); - + DexNavUpdateDirectionArrow(); - + //init hidden sprites if (sDexNavSearchDataPtr->itemSpriteId != MAX_SPRITES) gSprites[sDexNavSearchDataPtr->itemSpriteId].invisible = TRUE; @@ -1185,7 +1185,7 @@ static void DexNavUpdateSearchWindow(u8 proximity, u8 searchLevel) gSprites[sDexNavSearchDataPtr->starSpriteIds[1]].invisible = TRUE; if (sDexNavSearchDataPtr->starSpriteIds[2] != MAX_SPRITES) gSprites[sDexNavSearchDataPtr->starSpriteIds[2]].invisible = TRUE; - + if (proximity <= SNEAKING_PROXIMITY) { if (searchLevel > 2 && sDexNavSearchDataPtr->heldItem) @@ -1194,7 +1194,7 @@ static void DexNavUpdateSearchWindow(u8 proximity, u8 searchLevel) if (sDexNavSearchDataPtr->itemSpriteId != MAX_SPRITES) gSprites[sDexNavSearchDataPtr->itemSpriteId].invisible = FALSE; } - + if (searchLevel > 4) { if (sDexNavSearchDataPtr->starSpriteIds[0] != MAX_SPRITES) @@ -1218,9 +1218,9 @@ static void CreateDexNavWildMon(u16 species, u8 potential, u8 level, u8 abilityN u8 iv[3] = {NUM_STATS}; u8 i; u8 perfectIv = 31; - + CreateWildMon(species, level); // shiny rate bonus handled in CreateBoxMon - + // Pick random, unique IVs to set to 31. The number of perfect IVs that are assigned is equal to the potential iv[0] = Random() % NUM_STATS; // choose 1st perfect stat do { @@ -1228,17 +1228,17 @@ static void CreateDexNavWildMon(u16 species, u8 potential, u8 level, u8 abilityN iv[2] = Random() % NUM_STATS; } while ((iv[1] == iv[0]) // unique 2nd perfect stat || (iv[2] == iv[0] || iv[2] == iv[1])); // unique 3rd perfect stat - + if (potential > 2 && iv[2] != NUM_STATS) SetMonData(mon, MON_DATA_HP_IV + iv[2], &perfectIv); if (potential > 1 && iv[1] != NUM_STATS) SetMonData(mon, MON_DATA_HP_IV + iv[1], &perfectIv); if (potential > 0 && iv[0] != NUM_STATS) SetMonData(mon, MON_DATA_HP_IV + iv[0], &perfectIv); - + //Set ability SetMonData(mon, MON_DATA_ABILITY_NUM, &abilityNum); - + // Set Held Item if (item) SetMonData(mon, MON_DATA_HELD_ITEM, &item); @@ -1259,7 +1259,7 @@ static u8 DexNavTryGenerateMonLevel(u16 species, u8 environment) if (levelBase == MON_LEVEL_NONEXISTENT) return MON_LEVEL_NONEXISTENT; //species not found in the area - + if (Random() % 100 < 4) levelBonus += 10; //4% chance of having a +10 level @@ -1315,7 +1315,7 @@ static void DexNavGenerateMoveset(u16 species, u8 searchLevel, u8 encounterLevel for (i = 0; i < MAX_MON_MOVES; i++) moveDst[i] = GetMonData(&gEnemyParty[0], MON_DATA_MOVE1 + i, NULL); - // set first move slot to a random egg move if search level is good enough + // set first move slot to a random egg move if search level is good enough if (genMove) { u8 numEggMoves = GetEggMoves(&gEnemyParty[0], eggMoveBuffer); @@ -1330,7 +1330,7 @@ static u16 DexNavGenerateHeldItem(u16 species, u8 searchLevel) u8 searchLevelInfluence = searchLevel >> 1; u16 item1 = gSpeciesInfo[species].itemCommon; u16 item2 = gSpeciesInfo[species].itemRare; - + // if both are the same, 100% to hold if (item1 == item2) return item1; @@ -1357,7 +1357,7 @@ static u8 DexNavGetAbilityNum(u16 species, u8 searchLevel) bool8 genAbility = FALSE; u16 randVal = Random() % 100; u8 abilityNum = 0; - + if (searchLevel < 5) { #if (SEARCHLEVEL0_ABILITYCHANCE != 0) @@ -1400,7 +1400,7 @@ static u8 DexNavGetAbilityNum(u16 species, u8 searchLevel) genAbility = TRUE; #endif } - + if (genAbility && gSpeciesInfo[species].abilities[2] != ABILITY_NONE && GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_CAUGHT)) @@ -1416,7 +1416,7 @@ static u8 DexNavGetAbilityNum(u16 species, u8 searchLevel) else abilityNum = 0; } - + return abilityNum; } @@ -1424,7 +1424,7 @@ static u8 DexNavGeneratePotential(u8 searchLevel) { u8 genChance = 0; int randVal = Random() % 100; - + if (searchLevel < 5) { genChance = SEARCHLEVEL0_ONESTAR + SEARCHLEVEL0_TWOSTAR + SEARCHLEVEL0_THREESTAR; @@ -1509,7 +1509,7 @@ static u8 DexNavGeneratePotential(u8 searchLevel) return 3; } } - + return 0; // No potential } @@ -1522,7 +1522,7 @@ static u8 GetEncounterLevelFromMapData(u16 species, u8 environment) u8 min = 100; u8 max = 0; u8 i; - + switch (environment) { case ENCOUNTER_TYPE_LAND: // grass @@ -1554,7 +1554,7 @@ static u8 GetEncounterLevelFromMapData(u16 species, u8 environment) case ENCOUNTER_TYPE_HIDDEN: if (hiddenMonsInfo == NULL) return MON_LEVEL_NONEXISTENT; - + for (i = 0; i < HIDDEN_WILD_COUNT; i++) { if (hiddenMonsInfo->wildPokemon[i].species == species) @@ -1563,7 +1563,7 @@ static u8 GetEncounterLevelFromMapData(u16 species, u8 environment) max = (max > hiddenMonsInfo->wildPokemon[i].maxLevel) ? max : hiddenMonsInfo->wildPokemon[i].maxLevel; } } - + // use encounter rate to signify is hidden pokemon are on land or in water if (hiddenMonsInfo->encounterRate == 1) sDexNavSearchDataPtr->environment = ENCOUNTER_TYPE_WATER; @@ -1591,7 +1591,7 @@ static const struct BgTemplate sDexNavMenuBgTemplates[2] = .charBaseIndex = 0, .mapBaseIndex = 31, .priority = 0 - }, + }, { .bg = 1, .charBaseIndex = 3, @@ -1623,7 +1623,7 @@ static bool8 DexNav_InitBgs(void) sBg1TilemapBuffer = Alloc(0x800); if (sBg1TilemapBuffer == NULL) return FALSE; - + memset(sBg1TilemapBuffer, 0, 0x800); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sDexNavMenuBgTemplates, NELEMS(sDexNavMenuBgTemplates)); @@ -1660,14 +1660,14 @@ static bool8 DexNav_LoadGraphics(void) sDexNavUiDataPtr->state = 0; return TRUE; } - + return FALSE; } static void UpdateCursorPosition(void) { u16 x, y; - + switch (sDexNavUiDataPtr->cursorRow) { case ROW_WATER: @@ -1693,10 +1693,10 @@ static void UpdateCursorPosition(void) default: return; } - + gSprites[sDexNavUiDataPtr->cursorSpriteId].x = x; gSprites[sDexNavUiDataPtr->cursorSpriteId].y = y; - + PrintCurrentSpeciesInfo(); } @@ -1704,17 +1704,17 @@ static void CreateSelectionCursor(void) { u8 spriteId; struct CompressedSpriteSheet spriteSheet; - + spriteSheet.data = sSelectionCursorGfx; spriteSheet.size = 0x200; spriteSheet.tag = SELECTION_CURSOR_TAG; LoadCompressedSpriteSheet(&spriteSheet); - + LoadPalette(sSelectionCursorPal, (16 * sSelectionCursorOam.paletteNum) + 0x100, 32); - - spriteId = CreateSprite(&sSelectionCursorSpriteTemplate, 12, 32, 0); + + spriteId = CreateSprite(&sSelectionCursorSpriteTemplate, 12, 32, 0); //gSprites[spriteId].data[1] = -1; - + sDexNavUiDataPtr->cursorSpriteId = spriteId; UpdateCursorPosition(); } @@ -1729,9 +1729,9 @@ static bool8 CapturedAllLandMons(u16 headerId) u16 i, species; int count = 0; const struct WildPokemonInfo* landMonsInfo = gWildMonHeaders[headerId].landMonsInfo; - + if (landMonsInfo != NULL) - { + { for (i = 0; i < LAND_WILD_COUNT; ++i) { species = landMonsInfo->wildPokemon[i].species; @@ -1739,7 +1739,7 @@ static bool8 CapturedAllLandMons(u16 headerId) { if (!GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_CAUGHT)) break; - + count++; } } @@ -1793,7 +1793,7 @@ static bool8 CapturedAllHiddenMons(u16 headerId) u16 species; u8 count = 0; const struct WildPokemonInfo* hiddenMonsInfo = gWildMonHeaders[headerId].hiddenMonsInfo; - + if (hiddenMonsInfo != NULL) { for (i = 0; i < HIDDEN_WILD_COUNT; ++i) @@ -1821,7 +1821,7 @@ static bool8 CapturedAllHiddenMons(u16 headerId) static void DexNavLoadCapturedAllSymbols(void) { u16 headerId = GetCurrentMapWildMonHeaderId(); - + LoadCompressedSpriteSheetUsingHeap(&sCapturedAllPokemonSpriteSheet); if (CapturedAllLandMons(headerId)) @@ -1829,7 +1829,7 @@ static void DexNavLoadCapturedAllSymbols(void) if (CapturedAllWaterMons(headerId)) CreateSprite(&sCaptureAllMonsSpriteTemplate, 139, 17, 0); - + if (CapturedAllHiddenMons(headerId)) CreateSprite(&sCaptureAllMonsSpriteTemplate, 114, 123, 0); } @@ -1852,7 +1852,7 @@ static void DexNavGuiFreeResources(void) static void CB1_InitDexNavSearch(void) { u8 taskId; - + if (!gPaletteFade.active && !ArePlayerFieldControlsLocked() && gMain.callback2 == CB2_Overworld) { SetMainCallback1(CB1_Overworld); @@ -1897,7 +1897,7 @@ static bool8 SpeciesInArray(u16 species, u8 section) { u32 i; u16 dexNum = SpeciesToNationalPokedexNum(species); - + switch (section) { case 0: //land @@ -1924,7 +1924,7 @@ static bool8 SpeciesInArray(u16 species, u8 section) default: break; } - + return FALSE; } @@ -1940,12 +1940,12 @@ static void DexNavLoadEncounterData(void) const struct WildPokemonInfo* landMonsInfo = gWildMonHeaders[headerId].landMonsInfo; const struct WildPokemonInfo* waterMonsInfo = gWildMonHeaders[headerId].waterMonsInfo; const struct WildPokemonInfo* hiddenMonsInfo = gWildMonHeaders[headerId].hiddenMonsInfo; - + // nop struct data memset(sDexNavUiDataPtr->landSpecies, 0, sizeof(sDexNavUiDataPtr->landSpecies)); memset(sDexNavUiDataPtr->waterSpecies, 0, sizeof(sDexNavUiDataPtr->waterSpecies)); memset(sDexNavUiDataPtr->hiddenSpecies, 0, sizeof(sDexNavUiDataPtr->hiddenSpecies)); - + // land mons if (landMonsInfo != NULL && landMonsInfo->encounterRate != 0) { @@ -1967,7 +1967,7 @@ static void DexNavLoadEncounterData(void) sDexNavUiDataPtr->waterSpecies[waterIndex++] = waterMonsInfo->wildPokemon[i].species; } } - + // hidden mons if (hiddenMonsInfo != NULL) // no encounter rate check since 0 means land, 1 means water encounters { @@ -1995,24 +1995,24 @@ static void DrawSpeciesIcons(void) s16 x, y; u32 i; u16 species; - + LoadCompressedSpriteSheetUsingHeap(&sNoDataIconSpriteSheet); for (i = 0; i < LAND_WILD_COUNT; i++) { species = sDexNavUiDataPtr->landSpecies[i]; - x = 20 + (24 * (i % 6)); - y = ROW_LAND_TOP_ICON_Y + (i > 5 ? 28 : 0); + x = ROW_LAND_ICON_X + (24 * (i % COL_LAND_COUNT)); + y = ROW_LAND_TOP_ICON_Y + (i > COL_LAND_MAX ? 28 : 0); TryDrawIconInSlot(species, x, y); } - + for (i = 0; i < WATER_WILD_COUNT; i++) { species = sDexNavUiDataPtr->waterSpecies[i]; - x = 30 + 24 * i; + x = ROW_WATER_ICON_X + 24 * i; y = ROW_WATER_ICON_Y; TryDrawIconInSlot(species, x, y); } - + for (i = 0; i < HIDDEN_WILD_COUNT; i++) { species = sDexNavUiDataPtr->hiddenSpecies[i]; @@ -2030,7 +2030,7 @@ static void DrawSpeciesIcons(void) static u16 DexNavGetSpecies(void) { u16 species; - + switch (sDexNavUiDataPtr->cursorRow) { case ROW_WATER: @@ -2051,10 +2051,10 @@ static u16 DexNavGetSpecies(void) default: return SPECIES_NONE; } - + if (!GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_SEEN)) return SPECIES_NONE; - + return species; } @@ -2092,7 +2092,7 @@ static const u8 sMoveTypeToOamPaletteNum[NUMBER_OF_MON_TYPES] = static void SetTypeIconPosAndPal(u8 typeId, u8 x, u8 y, u8 spriteArrayId) { struct Sprite *sprite; - + sprite = &gSprites[sDexNavUiDataPtr->typeIconSpriteIds[spriteArrayId]]; StartSpriteAnim(sprite, typeId); sprite->oam.paletteNum = sMoveTypeToOamPaletteNum[typeId]; @@ -2106,25 +2106,25 @@ static void PrintCurrentSpeciesInfo(void) u16 species = DexNavGetSpecies(); u16 dexNum = SpeciesToNationalPokedexNum(species); u8 type1, type2; - + if (!GetSetPokedexFlag(dexNum, FLAG_GET_SEEN)) species = SPECIES_NONE; // clear windows FillWindowPixelBuffer(WINDOW_INFO, PIXEL_FILL(TEXT_COLOR_TRANSPARENT)); - + //species name if (species == SPECIES_NONE) AddTextPrinterParameterized3(WINDOW_INFO, 0, 0, SPECIES_INFO_Y, sFontColor_Black, 0, sText_DexNav_NoInfo); else AddTextPrinterParameterized3(WINDOW_INFO, 0, 0, SPECIES_INFO_Y, sFontColor_Black, 0, GetSpeciesName(species)); - + //type icon(s) type1 = gSpeciesInfo[species].types[0]; type2 = gSpeciesInfo[species].types[1]; if (species == SPECIES_NONE) type1 = type2 = TYPE_MYSTERY; - + if (type1 == type2) { SetTypeIconPosAndPal(type1, 186, 69, 0); @@ -2135,7 +2135,7 @@ static void PrintCurrentSpeciesInfo(void) SetTypeIconPosAndPal(type1, 168, 69, 0); SetTypeIconPosAndPal(type2, 168 + 33, 69, 1); } - + //search level if (species == SPECIES_NONE) { @@ -2146,7 +2146,7 @@ static void PrintCurrentSpeciesInfo(void) ConvertIntToDecimalStringN(gStringVar4, GetSearchLevel(dexNum), 0, 4); AddTextPrinterParameterized3(WINDOW_INFO, 0, 0, SEARCH_LEVEL_Y, sFontColor_Black, 0, gStringVar4); } - + //hidden ability if (species == SPECIES_NONE) { @@ -2163,11 +2163,11 @@ static void PrintCurrentSpeciesInfo(void) { AddTextPrinterParameterized3(WINDOW_INFO, 0, 0, HA_INFO_Y, sFontColor_Black, 0, sText_DexNav_CaptureToSee); } - + //current chain ConvertIntToDecimalStringN(gStringVar1, gSaveBlock3Ptr->dexNavChain, STR_CONV_MODE_LEFT_ALIGN, 3); AddTextPrinterParameterized3(WINDOW_INFO, 0, 0, CHAIN_BONUS_Y, sFontColor_Black, 0, gStringVar1); - + CopyWindowToVram(WINDOW_INFO, 3); PutWindowTilemap(WINDOW_INFO); } @@ -2195,7 +2195,7 @@ static void PrintSearchableSpecies(u16 species) StringExpandPlaceholders(gStringVar4, sText_DexNav_SearchForRegisteredSpecies); AddTextPrinterParameterized3(WINDOW_REGISTERED, 1, 0, 0, sFontColor_White, TEXT_SKIP_DRAW, gStringVar4); } - + PrintMapName(); } @@ -2208,8 +2208,8 @@ static void CreateTypeIconSprites(void) for (i = 0; i < 2; i++) { if (sDexNavUiDataPtr->typeIconSpriteIds[i] == 0xFF) - sDexNavUiDataPtr->typeIconSpriteIds[i] = CreateSprite(&gSpriteTemplate_MoveTypes, 10, 10, 2); - + sDexNavUiDataPtr->typeIconSpriteIds[i] = CreateSprite(&gSpriteTemplate_MoveTypes, 10, 10, 2); + SetSpriteInvisibility(i, TRUE); } } @@ -2217,7 +2217,7 @@ static void CreateTypeIconSprites(void) static bool8 DexNav_DoGfxSetup(void) { u8 taskId; - + switch (gMain.state) { case 0: @@ -2299,7 +2299,7 @@ static bool8 DexNav_DoGfxSetup(void) SetMainCallback2(DexNav_MainCB); return TRUE; } - + return FALSE; } @@ -2316,7 +2316,7 @@ static void DexNavGuiInit(MainCallback callback) SetMainCallback2(callback); return; } - + sDexNavUiDataPtr->state = 0; sDexNavUiDataPtr->savedCallback = callback; SetMainCallback2(DexNav_RunSetup); @@ -2347,10 +2347,10 @@ static void Task_DexNavMain(u8 taskId) { struct Task *task = &gTasks[taskId]; u16 species; - + if (IsSEPlaying()) return; - + if (JOY_NEW(B_BUTTON)) { PlaySE(SE_POKENAV_OFF); @@ -2369,10 +2369,10 @@ static void Task_DexNavMain(u8 taskId) { if (sDexNavUiDataPtr->cursorRow == ROW_LAND_TOP && sDexNavUiDataPtr->cursorCol == COL_LAND_MAX) sDexNavUiDataPtr->cursorCol = COL_WATER_MAX; - + sDexNavUiDataPtr->cursorRow--; } - + PlaySE(SE_RG_BAG_CURSOR); UpdateCursorPosition(); } @@ -2386,14 +2386,14 @@ static void Task_DexNavMain(u8 taskId) { if (sDexNavUiDataPtr->cursorCol >= COL_HIDDEN_COUNT) sDexNavUiDataPtr->cursorCol = COL_HIDDEN_MAX; - + sDexNavUiDataPtr->cursorRow++; } else { sDexNavUiDataPtr->cursorRow++; } - + PlaySE(SE_RG_BAG_CURSOR); UpdateCursorPosition(); } @@ -2418,7 +2418,7 @@ static void Task_DexNavMain(u8 taskId) { sDexNavUiDataPtr->cursorCol--; } - + PlaySE(SE_RG_BAG_CURSOR); UpdateCursorPosition(); } @@ -2445,7 +2445,7 @@ static void Task_DexNavMain(u8 taskId) sDexNavUiDataPtr->cursorCol++; break; } - + PlaySE(SE_RG_BAG_CURSOR); UpdateCursorPosition(); } @@ -2453,13 +2453,13 @@ static void Task_DexNavMain(u8 taskId) { // check selection is valid. Play sound if invalid species = DexNavGetSpecies(); - + if (species != SPECIES_NONE) - { + { PrintSearchableSpecies(species); //PlaySE(SE_DEX_SEARCH); PlayCry_Script(species, 0); - + // create value to store in a var VarSet(DN_VAR_SPECIES, ((sDexNavUiDataPtr->environment << 14) | species)); } @@ -2493,7 +2493,7 @@ static void Task_DexNavMain(u8 taskId) bool8 TryFindHiddenPokemon(void) { u16 *stepPtr = GetVarPointer(DN_VAR_STEP_COUNTER); - + if (DEXNAV_ENABLED == 0 || !FlagGet(DN_FLAG_DETECTOR_MODE) || FlagGet(DN_FLAG_SEARCHING) @@ -2503,7 +2503,7 @@ bool8 TryFindHiddenPokemon(void) (*stepPtr) = 0; return FALSE; } - + (*stepPtr)++; (*stepPtr) %= HIDDEN_MON_STEP_COUNT; if ((*stepPtr) == 0 && (Random() % 100 < HIDDEN_MON_SEARCH_RATE)) @@ -2516,12 +2516,12 @@ bool8 TryFindHiddenPokemon(void) u8 taskId; const struct WildPokemonInfo* hiddenMonsInfo = gWildMonHeaders[headerId].hiddenMonsInfo; bool8 isHiddenMon = FALSE; - + // while you can still technically find hidden pokemon if there are not hidden-only pokemon on a map, // this prevents any potential lagging on maps you dont want hidden pokemon to appear on if (hiddenMonsInfo == NULL) return FALSE; - + // encounter rate signifies surfing (1) or land mons (0)! // again, for simplicity switch (hiddenMonsInfo->encounterRate) @@ -2571,12 +2571,12 @@ bool8 TryFindHiddenPokemon(void) default: return FALSE; } - + if (species == SPECIES_NONE) return FALSE; - + sDexNavSearchDataPtr = AllocZeroed(sizeof(struct DexNavSearch)); - + // init search data sDexNavSearchDataPtr->isHiddenMon = isHiddenMon; sDexNavSearchDataPtr->species = species; @@ -2600,7 +2600,7 @@ bool8 TryFindHiddenPokemon(void) gFieldEffectArguments[3] = 2; ObjectEventGetLocalIdAndMap(&gObjectEvents[gPlayerAvatar.objectEventId], &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]); FieldEffectStart(FLDEFF_EXCLAMATION_MARK_ICON); - + PlayCry_Script(species, 0); taskId = CreateTask(Task_SetUpDexNavSearch, 0); gTasks[taskId].tSpecies = sDexNavSearchDataPtr->species; @@ -2610,14 +2610,14 @@ bool8 TryFindHiddenPokemon(void) ChangeBgY_ScreenOff(0, 0, 0); return FALSE; // we dont actually want to enable the script context or the game will freeze } - + return FALSE; } static void DrawSearchIcon(void) { - struct CompressedSpriteSheet spriteSheet; - + struct CompressedSpriteSheet spriteSheet; + spriteSheet.data = sHiddenSearchIconGfx; spriteSheet.size = 0x200; spriteSheet.tag = SELECTION_CURSOR_TAG; @@ -2632,7 +2632,7 @@ static void DrawHiddenSearchWindow(u8 width) { AddSearchWindow(width); AddTextPrinterParameterized3(sDexNavSearchDataPtr->windowId, 0, SPECIES_ICON_X + 4, 0, sSearchFontColor, TEXT_SKIP_DRAW, sText_ThreeQmarks); - + ConvertIntToDecimalStringN(gStringVar1, sDexNavSearchDataPtr->searchLevel, STR_CONV_MODE_LEFT_ALIGN, 2); StringExpandPlaceholders(gStringVar4, sText_SearchLevel); AddTextPrinterParameterized3(sDexNavSearchDataPtr->windowId, 0, SPECIES_ICON_X + 4, 12, sSearchFontColor, TEXT_SKIP_DRAW, gStringVar4); @@ -2642,13 +2642,13 @@ static void DrawHiddenSearchWindow(u8 width) static void DexNavDrawHiddenIcons(void) { u16 species = sDexNavSearchDataPtr->species; - + DrawHiddenSearchWindow(12); DrawSearchIcon(); - + if (GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_CAUGHT)) sDexNavSearchDataPtr->ownedIconSpriteId = CreateSprite(&sOwnedIconTemplate, SPECIES_ICON_X + 6, GetSearchWindowY() + 2, 0); - + if (sDexNavSearchDataPtr->isHiddenMon) sDexNavSearchDataPtr->exclamationSpriteId = CreateSprite(&sHiddenMonIconTemplate, SPECIES_ICON_X + 34, GetSearchWindowY() + 8, 0); } @@ -2660,7 +2660,7 @@ u32 CalculateDexNavShinyRolls(void) { u32 chainBonus, rndBonus; u8 chain = gSaveBlock3Ptr->dexNavChain; - + chainBonus = (chain >= 100) ? 10 : (chain >= 50) ? 5 : 0; rndBonus = (Random() % 100 < 4) ? 4 : 0; return chainBonus + rndBonus; diff --git a/src/start_menu.c b/src/start_menu.c index a49b7c6d8a..72a420e90e 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -329,13 +329,13 @@ static void AddStartMenuAction(u8 action) } static void BuildNormalStartMenu(void) -{ +{ if (FlagGet(FLAG_SYS_POKEDEX_GET) == TRUE) AddStartMenuAction(MENU_ACTION_POKEDEX); - + if (DN_FLAG_DEXNAV_GET != 0 && FlagGet(DN_FLAG_DEXNAV_GET)) AddStartMenuAction(MENU_ACTION_DEXNAV); - + if (FlagGet(FLAG_SYS_POKEMON_GET) == TRUE) AddStartMenuAction(MENU_ACTION_POKEMON); @@ -644,7 +644,7 @@ static bool8 HandleStartMenuInput(void) if (sCurrentStartMenuActions[sStartMenuCursorPos] == MENU_ACTION_DEXNAV && MapHasNoEncounterData()) return FALSE; - + gMenuCallback = sStartMenuItems[sCurrentStartMenuActions[sStartMenuCursorPos]].func.u8_void; if (gMenuCallback != StartMenuSaveCallback