Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple roamers #4762

Merged
merged 7 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/constants/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#define GIFT_RIBBONS_COUNT 11
#define SAVED_TRENDS_COUNT 5
#define PYRAMID_BAG_ITEMS_COUNT 10
#define ROAMER_COUNT 1 // Number of maximum concurrent active roamers

// Number of facilities for Ranking Hall.
// 7 facilities for single mode + tower double mode + tower multi mode.
Expand Down
16 changes: 8 additions & 8 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,14 @@ struct Roamer
/*0x08*/ u16 species;
/*0x0A*/ u16 hp;
/*0x0C*/ u8 level;
/*0x0D*/ u8 status;
/*0x0E*/ u8 cool;
/*0x0F*/ u8 beauty;
/*0x10*/ u8 cute;
/*0x11*/ u8 smart;
/*0x12*/ u8 tough;
/*0x0D*/ u16 status;
/*0x0F*/ u8 cool;
/*0x10*/ u8 beauty;
/*0x11*/ u8 cute;
/*0x12*/ u8 smart;
/*0x13*/ bool8 active;
/*0x14*/ u8 filler[0x8];
/*0x14*/ u8 tough;
/*0x15*/ u8 filler[0x7];
};

struct RamScriptData
Expand Down Expand Up @@ -1057,7 +1057,7 @@ struct SaveBlock1
/*0x31A8*/ u8 giftRibbons[GIFT_RIBBONS_COUNT];
/*0x31B3*/ struct ExternalEventData externalEventData;
/*0x31C7*/ struct ExternalEventFlags externalEventFlags;
/*0x31DC*/ struct Roamer roamer;
/*0x31DC*/ struct Roamer roamer[ROAMER_COUNT];
Bassoonian marked this conversation as resolved.
Show resolved Hide resolved
#if FREE_ENIGMA_BERRY == FALSE
/*0x31F8*/ struct EnigmaBerry enigmaBerry;
#endif //FREE_ENIGMA_BERRY
Expand Down
20 changes: 12 additions & 8 deletions include/roamer.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#ifndef GUARD_ROAMER_H
#define GUARD_ROAMER_H

void ClearRoamerData(void);
void ClearRoamerLocationData(void);
void DeactivateAllRoamers(void);
void InitRoamer(void);
void UpdateLocationHistoryForRoamer(void);
void RoamerMoveToOtherLocationSet(void);
void RoamerMove(void);
bool8 IsRoamerAt(u8 mapGroup, u8 mapNum);
void CreateRoamerMonInstance(void);
void RoamerMoveToOtherLocationSet(u32 roamerIndex);
void RoamerMove(u32 roamerIndex);
bool8 IsRoamerAt(u32 roamerIndex, u8 mapGroup, u8 mapNum);
void CreateRoamerMonInstance(u32 roamerIndex);
u8 TryStartRoamerEncounter(void);
void UpdateRoamerHPStatus(struct Pokemon *mon);
void SetRoamerInactive(void);
void GetRoamerLocation(u8 *mapGroup, u8 *mapNum);
void SetRoamerInactive(u32 roamerIndex);
void GetRoamerLocation(u32 roamerIndex, u8 *mapGroup, u8 *mapNum);
bool8 TryAddRoamer(u16 species, u8 level);
void MoveAllRoamersToOtherLocationSets(void);
void MoveAllRoamers(void);

extern u8 gEncounteredRoamerIndex;

#endif // GUARD_ROAMER_H
2 changes: 1 addition & 1 deletion src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5655,7 +5655,7 @@ static void ReturnFromBattleToOverworld(void)
#else
if ((gBattleOutcome == B_OUTCOME_WON) || gBattleOutcome == B_OUTCOME_CAUGHT) // Bug: When Roar is used by roamer, gBattleOutcome is B_OUTCOME_PLAYER_TELEPORTED (5).
#endif // & with B_OUTCOME_WON (1) will return TRUE and deactivates the roamer.
SetRoamerInactive();
SetRoamerInactive(gEncounteredRoamerIndex);
}

m4aSongNumStop(SE_LOW_HEALTH);
Expand Down
3 changes: 1 addition & 2 deletions src/new_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ void NewGameInitData(void)
gPlayerPartyCount = 0;
ZeroPlayerPartyMons();
ResetPokemonStorageSystem();
ClearRoamerData();
ClearRoamerLocationData();
DeactivateAllRoamers();
gSaveBlock1Ptr->registeredItem = ITEM_NONE;
ClearBag();
NewGameInitPCItems();
Expand Down
6 changes: 3 additions & 3 deletions src/overworld.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ static void UpdateMiscOverworldStates(void)
ChooseAmbientCrySpecies();
ResetCyclingRoadChallengeData();
UpdateLocationHistoryForRoamer();
RoamerMoveToOtherLocationSet();
MoveAllRoamersToOtherLocationSets();
}

void ResetGameStats(void)
Expand Down Expand Up @@ -847,7 +847,7 @@ if (I_VS_SEEKER_CHARGING != 0)

InitSecondaryTilesetAnimation();
UpdateLocationHistoryForRoamer();
RoamerMove();
MoveAllRoamers();
DoCurrentWeather();
ResetFieldTasksArgs();
RunOnResumeMapScript();
Expand Down Expand Up @@ -906,7 +906,7 @@ if (I_VS_SEEKER_CHARGING != 0)
Overworld_ClearSavedMusic();
RunOnTransitionMapScript();
UpdateLocationHistoryForRoamer();
RoamerMoveToOtherLocationSet();
MoveAllRoamersToOtherLocationSets();
if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PYRAMID_FLOOR)
InitBattlePyramidMap(FALSE);
else if (InTrainerHill())
Expand Down
99 changes: 47 additions & 52 deletions src/pokedex_area_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,72 +252,67 @@ static void FindMapsWithMon(u16 species)
if (sPokedexAreaScreen->alteringCaveId >= NUM_ALTERING_CAVE_TABLES)
sPokedexAreaScreen->alteringCaveId = 0;

roamer = &gSaveBlock1Ptr->roamer;
if (species != roamer->species)
{
sPokedexAreaScreen->numOverworldAreas = 0;
sPokedexAreaScreen->numSpecialAreas = 0;
sPokedexAreaScreen->numOverworldAreas = 0;
sPokedexAreaScreen->numSpecialAreas = 0;

// Check if this species should be hidden from the area map.
// This only applies to Wynaut, to hide the encounters on Mirage Island.
for (i = 0; i < ARRAY_COUNT(sSpeciesHiddenFromAreaScreen); i++)
{
if (sSpeciesHiddenFromAreaScreen[i] == species)
return;
}
// Check if this species should be hidden from the area map.
// This only applies to Wynaut, to hide the encounters on Mirage Island.
for (i = 0; i < ARRAY_COUNT(sSpeciesHiddenFromAreaScreen); i++)
{
if (sSpeciesHiddenFromAreaScreen[i] == species)
return;
}

// Add Pokémon with special encounter circumstances (i.e. not listed
// in the regular wild encounter table) to the area map.
// This only applies to Feebas on Route 119, but it was clearly set
// up to allow handling others.
for (i = 0; sFeebasData[i][0] != NUM_SPECIES; i++)
// Add Pokémon with special encounter circumstances (i.e. not listed
// in the regular wild encounter table) to the area map.
// This only applies to Feebas on Route 119, but it was clearly set
// up to allow handling others.
for (i = 0; sFeebasData[i][0] != NUM_SPECIES; i++)
{
if (species == sFeebasData[i][0])
{
if (species == sFeebasData[i][0])
switch (sFeebasData[i][1])
{
switch (sFeebasData[i][1])
{
case MAP_GROUP_TOWNS_AND_ROUTES:
SetAreaHasMon(sFeebasData[i][1], sFeebasData[i][2]);
break;
case MAP_GROUP_DUNGEONS:
case MAP_GROUP_SPECIAL_AREA:
SetSpecialMapHasMon(sFeebasData[i][1], sFeebasData[i][2]);
break;
}
case MAP_GROUP_TOWNS_AND_ROUTES:
SetAreaHasMon(sFeebasData[i][1], sFeebasData[i][2]);
break;
case MAP_GROUP_DUNGEONS:
case MAP_GROUP_SPECIAL_AREA:
SetSpecialMapHasMon(sFeebasData[i][1], sFeebasData[i][2]);
break;
}
}
}

// Add regular species to the area map
for (i = 0; gWildMonHeaders[i].mapGroup != MAP_GROUP(UNDEFINED); i++)
// Add regular species to the area map
for (i = 0; gWildMonHeaders[i].mapGroup != MAP_GROUP(UNDEFINED); i++)
{
if (MapHasSpecies(&gWildMonHeaders[i], species))
{
if (MapHasSpecies(&gWildMonHeaders[i], species))
switch (gWildMonHeaders[i].mapGroup)
{
switch (gWildMonHeaders[i].mapGroup)
{
case MAP_GROUP_TOWNS_AND_ROUTES:
SetAreaHasMon(gWildMonHeaders[i].mapGroup, gWildMonHeaders[i].mapNum);
break;
case MAP_GROUP_DUNGEONS:
case MAP_GROUP_SPECIAL_AREA:
SetSpecialMapHasMon(gWildMonHeaders[i].mapGroup, gWildMonHeaders[i].mapNum);
break;
}
case MAP_GROUP_TOWNS_AND_ROUTES:
SetAreaHasMon(gWildMonHeaders[i].mapGroup, gWildMonHeaders[i].mapNum);
break;
case MAP_GROUP_DUNGEONS:
case MAP_GROUP_SPECIAL_AREA:
SetSpecialMapHasMon(gWildMonHeaders[i].mapGroup, gWildMonHeaders[i].mapNum);
break;
}
}
}
else

// Add roamers to the area map
for (i = 0; i < ROAMER_COUNT; i++)
{
// This is the roamer's species, show where the roamer is currently
sPokedexAreaScreen->numSpecialAreas = 0;
if (roamer->active)
{
GetRoamerLocation(&sPokedexAreaScreen->overworldAreasWithMons[0].mapGroup, &sPokedexAreaScreen->overworldAreasWithMons[0].mapNum);
sPokedexAreaScreen->overworldAreasWithMons[0].regionMapSectionId = Overworld_GetMapHeaderByGroupAndId(sPokedexAreaScreen->overworldAreasWithMons[0].mapGroup, sPokedexAreaScreen->overworldAreasWithMons[0].mapNum)->regionMapSectionId;
sPokedexAreaScreen->numOverworldAreas = 1;
}
else
roamer = &gSaveBlock1Ptr->roamer[i];
if (species == roamer->species && roamer->active)
{
sPokedexAreaScreen->numOverworldAreas = 0;
// This is a roamer's species, show where this roamer is currently
struct OverworldArea *roamerLocation = &sPokedexAreaScreen->overworldAreasWithMons[sPokedexAreaScreen->numOverworldAreas];
GetRoamerLocation(i, &roamerLocation->mapGroup, &roamerLocation->mapNum);
roamerLocation->regionMapSectionId = Overworld_GetMapHeaderByGroupAndId(roamerLocation->mapGroup, roamerLocation->mapNum)->regionMapSectionId;
sPokedexAreaScreen->numOverworldAreas++;
}
}
}
Expand Down
Loading
Loading