Generate local IDs from map.json files

This commit is contained in:
GriffinR
2024-10-11 21:30:52 -04:00
parent 6518f1e3ff
commit 9f31b0fe90
146 changed files with 878 additions and 833 deletions

View File

@@ -1023,7 +1023,7 @@ static void HidePyramidItem(void)
break;
}
i++;
if (events[i].localId == 0)
if (events[i].localId == LOCALID_NONE)
break;
}
}
@@ -1934,7 +1934,7 @@ u8 GetNumBattlePyramidObjectEvents(void)
for (i = 0; i < OBJECT_EVENTS_COUNT; i++)
{
if (events[i].localId == 0)
if (events[i].localId == LOCALID_NONE)
break;
}

View File

@@ -39,6 +39,7 @@
#include "data.h"
#include "constants/battle_frontier.h"
#include "constants/battle_setup.h"
#include "constants/event_objects.h"
#include "constants/game_stat.h"
#include "constants/items.h"
#include "constants/songs.h"
@@ -1092,7 +1093,7 @@ static void TrainerBattleLoadArgs(const struct TrainerBattleParameter *specs, co
void SetMapVarsToTrainer(void)
{
if (sTrainerObjectEventLocalId != 0)
if (sTrainerObjectEventLocalId != LOCALID_NONE)
{
gSpecialVar_LastTalked = sTrainerObjectEventLocalId;
gSelectedObjectEvent = GetObjectEventIdByLocalIdAndMap(sTrainerObjectEventLocalId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup);

View File

@@ -2306,13 +2306,13 @@ void GetNpcContestantLocalId(void)
switch (contestant)
{
case 0:
localId = 3;
localId = LOCALID_CONTESTANT_1;
break;
case 1:
localId = 4;
localId = LOCALID_CONTESTANT_2;
break;
case 2:
localId = 5;
localId = LOCALID_CONTESTANT_3;
break;
default: // Invalid
localId = 100;
@@ -2512,7 +2512,12 @@ void LoadLinkContestPlayerPalettes(void)
u8 objectEventId;
int version;
struct Sprite *sprite;
static const u8 sContestantLocalIds[CONTESTANT_COUNT] = { 3, 4, 5, 14 };
static const u8 sContestantLocalIds[CONTESTANT_COUNT] = {
LOCALID_CONTESTANT_1,
LOCALID_CONTESTANT_2,
LOCALID_CONTESTANT_3,
LOCALID_CONTESTANT_4,
};
gReservedSpritePaletteCount = 12;
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)

View File

@@ -30,6 +30,17 @@
#include "constants/trainer_types.h"
#include "constants/union_room.h"
#define SPECIAL_LOCALIDS_START (min(OBJ_EVENT_ID_CAMERA, \
min(OBJ_EVENT_ID_PLAYER, \
LOCALID_BERRY_BLENDER_PLAYER_END - MAX_RFU_PLAYERS + 1)))
// The object event templates on a map cannot use the special IDs listed above or they can behave unexpectedly.
// For more details on these special IDs see their definitions in 'include/constants/event_objects.h'.
// OBJECT_EVENT_TEMPLATES_COUNT should always be low enough that it doesn't overlap with these IDs.
#if OBJECT_EVENT_TEMPLATES_COUNT >= SPECIAL_LOCALIDS_START
#error "OBJECT_EVENT_TEMPLATES_COUNT is too large. Object event local IDs may overlap with reserved IDs."
#endif
// this file was known as evobjmv.c in Game Freak's original source
enum {
@@ -8814,7 +8825,7 @@ u8 MovementAction_LockAnim_Step0(struct ObjectEvent *objectEvent, struct Sprite
bool32 found = FALSE;
for (i = 0; i < OBJECT_EVENTS_COUNT; i++)
{
if (firstFreeSlot == OBJECT_EVENTS_COUNT && sLockedAnimObjectEvents->localIds[i] == 0)
if (firstFreeSlot == OBJECT_EVENTS_COUNT && sLockedAnimObjectEvents->localIds[i] == LOCALID_NONE)
firstFreeSlot = i;
if (sLockedAnimObjectEvents->localIds[i] == objectEvent->localId)
@@ -8854,7 +8865,7 @@ u8 MovementAction_UnlockAnim_Step0(struct ObjectEvent *objectEvent, struct Sprit
index = FindLockedObjectEventIndex(objectEvent);
if (index != OBJECT_EVENTS_COUNT)
{
sLockedAnimObjectEvents->localIds[index] = 0;
sLockedAnimObjectEvents->localIds[index] = LOCALID_NONE;
sLockedAnimObjectEvents->count--;
ableToStore = TRUE;
}

View File

@@ -137,7 +137,7 @@ int ProcessPlayerFieldInput(struct FieldInput *input)
u8 playerDirection;
u16 metatileBehavior;
gSpecialVar_LastTalked = 0;
gSpecialVar_LastTalked = LOCALID_NONE;
gSelectedObjectEvent = 0;
playerDirection = GetPlayerFacingDirection();

View File

@@ -777,7 +777,7 @@ bool8 IsPlayerCollidingWithFarawayIslandMew(u8 direction)
playerY = object->currentCoords.y;
MoveCoords(direction, &playerX, &playerY);
mewObjectId = GetObjectEventIdByLocalIdAndMap(1, MAP_NUM(MAP_FARAWAY_ISLAND_INTERIOR), MAP_GROUP(MAP_FARAWAY_ISLAND_INTERIOR));
mewObjectId = GetObjectEventIdByLocalIdAndMap(LOCALID_FARAWAY_ISLAND_MEW, MAP_NUM(MAP_FARAWAY_ISLAND_INTERIOR), MAP_GROUP(MAP_FARAWAY_ISLAND_INTERIOR));
if (mewObjectId == OBJECT_EVENTS_COUNT)
return FALSE;

View File

@@ -563,8 +563,8 @@ void SpawnLinkPartnerObjectEvent(void)
linkSpriteId = OBJ_EVENT_GFX_RIVAL_MAY_NORMAL;
break;
}
SpawnSpecialObjectEventParameterized(linkSpriteId, movementTypes[j], 240 - i, coordOffsets[j][0] + x + MAP_OFFSET, coordOffsets[j][1] + y + MAP_OFFSET, 0);
LoadLinkPartnerObjectEventSpritePalette(linkSpriteId, 240 - i, i);
SpawnSpecialObjectEventParameterized(linkSpriteId, movementTypes[j], LOCALID_BERRY_BLENDER_PLAYER_END - i, coordOffsets[j][0] + x + MAP_OFFSET, coordOffsets[j][1] + y + MAP_OFFSET, 0);
LoadLinkPartnerObjectEventSpritePalette(linkSpriteId, LOCALID_BERRY_BLENDER_PLAYER_END - i, i);
j++;
if (j == MAX_LINK_PLAYERS)
j = 0;

View File

@@ -109,7 +109,7 @@ u16 MoveRotatingTileObjects(u8 puzzleNumber)
{
u8 i;
struct ObjectEventTemplate *objectEvents = gSaveBlock1Ptr->objectEventTemplates;
u16 localId = 0;
u16 localId = LOCALID_NONE;
for (i = 0; i < OBJECT_EVENT_TEMPLATES_COUNT; i++)
{

View File

@@ -1020,7 +1020,7 @@ bool8 ScrCmd_waitmovement(struct ScriptContext *ctx)
{
u16 localId = VarGet(ScriptReadHalfword(ctx));
if (localId != 0)
if (localId != LOCALID_NONE)
sMovingNpcId = localId;
sMovingNpcMapGroup = gSaveBlock1Ptr->location.mapGroup;
sMovingNpcMapNum = gSaveBlock1Ptr->location.mapNum;
@@ -1034,7 +1034,7 @@ bool8 ScrCmd_waitmovementat(struct ScriptContext *ctx)
u8 mapGroup;
u8 mapNum;
if (localId != 0)
if (localId != LOCALID_NONE)
sMovingNpcId = localId;
mapGroup = ScriptReadByte(ctx);
mapNum = ScriptReadByte(ctx);

View File

@@ -378,7 +378,7 @@ void ClearRamScript(void)
CpuFill32(0, &gSaveBlock1Ptr->ramScript, sizeof(struct RamScript));
}
bool8 InitRamScript(const u8 *script, u16 scriptSize, u8 mapGroup, u8 mapNum, u8 objectId)
bool8 InitRamScript(const u8 *script, u16 scriptSize, u8 mapGroup, u8 mapNum, u8 localId)
{
struct RamScriptData *scriptData = &gSaveBlock1Ptr->ramScript.data;
@@ -390,13 +390,13 @@ bool8 InitRamScript(const u8 *script, u16 scriptSize, u8 mapGroup, u8 mapNum, u8
scriptData->magic = RAM_SCRIPT_MAGIC;
scriptData->mapGroup = mapGroup;
scriptData->mapNum = mapNum;
scriptData->objectId = objectId;
scriptData->localId = localId;
memcpy(scriptData->script, script, scriptSize);
gSaveBlock1Ptr->ramScript.checksum = CalculateRamScriptChecksum();
return TRUE;
}
const u8 *GetRamScript(u8 objectId, const u8 *script)
const u8 *GetRamScript(u8 localId, const u8 *script)
{
struct RamScriptData *scriptData = &gSaveBlock1Ptr->ramScript.data;
gRamScriptRetAddr = NULL;
@@ -406,7 +406,7 @@ const u8 *GetRamScript(u8 objectId, const u8 *script)
return script;
if (scriptData->mapNum != gSaveBlock1Ptr->location.mapNum)
return script;
if (scriptData->objectId != objectId)
if (scriptData->localId != localId)
return script;
if (CalculateRamScriptChecksum() != gSaveBlock1Ptr->ramScript.checksum)
{
@@ -431,7 +431,7 @@ bool32 ValidateSavedRamScript(void)
return FALSE;
if (scriptData->mapNum != MAP_NUM(MAP_UNDEFINED))
return FALSE;
if (scriptData->objectId != NO_OBJECT)
if (scriptData->localId != NO_OBJECT)
return FALSE;
if (CalculateRamScriptChecksum() != gSaveBlock1Ptr->ramScript.checksum)
return FALSE;
@@ -449,7 +449,7 @@ u8 *GetSavedRamScriptIfValid(void)
return NULL;
if (scriptData->mapNum != MAP_NUM(MAP_UNDEFINED))
return NULL;
if (scriptData->objectId != NO_OBJECT)
if (scriptData->localId != NO_OBJECT)
return NULL;
if (CalculateRamScriptChecksum() != gSaveBlock1Ptr->ramScript.checksum)
{

View File

@@ -366,13 +366,13 @@ static void FreeDataStruct(void)
TRY_FREE_AND_SET_NULL(sHillData);
}
void CopyTrainerHillTrainerText(u8 which, u16 trainerId)
void CopyTrainerHillTrainerText(u8 which, u16 localId)
{
u8 id, floorId;
SetUpDataStruct();
floorId = GetFloorId();
id = trainerId - 1;
id = localId - 1;
switch (which)
{

View File

@@ -992,6 +992,7 @@ static void TakeGabbyAndTyOffTheAir(void)
gSaveBlock1Ptr->gabbyAndTyData.onAir = FALSE;
}
// See gabby_and_ty.inc for details
u8 GabbyAndTyGetBattleNum(void)
{
if (gSaveBlock1Ptr->gabbyAndTyData.battleNum > 5)
@@ -1033,41 +1034,42 @@ u8 GabbyAndTyGetLastBattleTrivia(void)
return 0;
}
// See gabby_and_ty.inc for details
void GetGabbyAndTyLocalIds(void)
{
switch (GabbyAndTyGetBattleNum())
{
case 1:
gSpecialVar_0x8004 = 14;
gSpecialVar_0x8005 = 13;
gSpecialVar_0x8004 = LOCALID_ROUTE111_GABBY_1;
gSpecialVar_0x8005 = LOCALID_ROUTE111_TY_1;
break;
case 2:
gSpecialVar_0x8004 = 5;
gSpecialVar_0x8005 = 6;
gSpecialVar_0x8004 = LOCALID_ROUTE118_GABBY_1;
gSpecialVar_0x8005 = LOCALID_ROUTE118_TY_1;
break;
case 3:
gSpecialVar_0x8004 = 18;
gSpecialVar_0x8005 = 17;
gSpecialVar_0x8004 = LOCALID_ROUTE120_GABBY_1;
gSpecialVar_0x8005 = LOCALID_ROUTE120_TY_1;
break;
case 4:
gSpecialVar_0x8004 = 21;
gSpecialVar_0x8005 = 22;
gSpecialVar_0x8004 = LOCALID_ROUTE111_GABBY_2;
gSpecialVar_0x8005 = LOCALID_ROUTE111_TY_2;
break;
case 5:
gSpecialVar_0x8004 = 8;
gSpecialVar_0x8005 = 9;
gSpecialVar_0x8004 = LOCALID_ROUTE118_GABBY_2;
gSpecialVar_0x8005 = LOCALID_ROUTE118_TY_2;
break;
case 6:
gSpecialVar_0x8004 = 19;
gSpecialVar_0x8005 = 20;
gSpecialVar_0x8004 = LOCALID_ROUTE120_GABBY_2;
gSpecialVar_0x8005 = LOCALID_ROUTE120_TY_2;
break;
case 7:
gSpecialVar_0x8004 = 23;
gSpecialVar_0x8005 = 24;
gSpecialVar_0x8004 = LOCALID_ROUTE111_GABBY_3;
gSpecialVar_0x8005 = LOCALID_ROUTE111_TY_3;
break;
case 8:
gSpecialVar_0x8004 = 10;
gSpecialVar_0x8005 = 11;
gSpecialVar_0x8004 = LOCALID_ROUTE118_GABBY_3;
gSpecialVar_0x8005 = LOCALID_ROUTE118_TY_3;
break;
}
}