From dbf757be886736e6a0f8f813cc8c0a544124a287 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 8 Mar 2023 11:07:44 -0500 Subject: [PATCH 1/5] Treat map data as const --- include/field_control_avatar.h | 2 +- include/fieldmap.h | 4 ++-- include/global.fieldmap.h | 22 +++++++++++----------- src/event_object_movement.c | 24 ++++++++++++------------ src/field_control_avatar.c | 24 ++++++++++++------------ src/fieldmap.c | 32 ++++++++++++++++---------------- src/item_use.c | 6 +++--- src/overworld.c | 6 +++--- src/trainer_hill.c | 3 ++- 9 files changed, 62 insertions(+), 61 deletions(-) diff --git a/include/field_control_avatar.h b/include/field_control_avatar.h index e02fcd5afe..b259eb53c1 100644 --- a/include/field_control_avatar.h +++ b/include/field_control_avatar.h @@ -32,7 +32,7 @@ bool8 TryDoDiveWarp(struct MapPosition *position, u16 b); int SetCableClubWarp(void); u8 TrySetDiveWarp(void); const u8 *GetInteractedLinkPlayerScript(struct MapPosition *position, u8 metatileBehavior, u8 direction); -u8 *GetCoordEventScriptAtMapPosition(struct MapPosition *position); +const u8 *GetCoordEventScriptAtMapPosition(struct MapPosition *position); void ClearPoisonStepCounter(void); #endif // GUARD_FIELDCONTROLAVATAR_H diff --git a/include/fieldmap.h b/include/fieldmap.h index f2dbefae86..47072bd1be 100644 --- a/include/fieldmap.h +++ b/include/fieldmap.h @@ -48,8 +48,8 @@ void LoadSecondaryTilesetPalette(struct MapLayout const *mapLayout); void CopySecondaryTilesetToVramUsingHeap(struct MapLayout const *mapLayout); void CopyPrimaryTilesetToVram(const struct MapLayout *); void CopySecondaryTilesetToVram(const struct MapLayout *); -struct MapHeader const *const GetMapHeaderFromConnection(struct MapConnection *connection); -struct MapConnection *GetMapConnectionAtPos(s16 x, s16 y); +const struct MapHeader *const GetMapHeaderFromConnection(const struct MapConnection *connection); +const struct MapConnection *GetMapConnectionAtPos(s16 x, s16 y); void MapGridSetMetatileImpassabilityAt(int x, int y, bool32 impassable); // field_region_map.c diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index d8fea5b23c..7461929c3a 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -50,10 +50,10 @@ struct MapLayout { /*0x00*/ s32 width; /*0x04*/ s32 height; - /*0x08*/ u16 *border; - /*0x0C*/ u16 *map; - /*0x10*/ struct Tileset *primaryTileset; - /*0x14*/ struct Tileset *secondaryTileset; + /*0x08*/ const u16 *border; + /*0x0C*/ const u16 *map; + /*0x10*/ const struct Tileset *primaryTileset; + /*0x14*/ const struct Tileset *secondaryTileset; }; struct BackupMapLayout @@ -98,7 +98,7 @@ struct CoordEvent u8 elevation; u16 trigger; u16 index; - u8 *script; + const u8 *script; }; struct BgEvent @@ -107,7 +107,7 @@ struct BgEvent u8 elevation; u8 kind; // The "kind" field determines how to access bgUnion union below. union { - u8 *script; + const u8 *script; struct { u16 item; u16 hiddenItemId; @@ -122,10 +122,10 @@ struct MapEvents u8 warpCount; u8 coordEventCount; u8 bgEventCount; - struct ObjectEventTemplate *objectEvents; - struct WarpEvent *warps; - struct CoordEvent *coordEvents; - struct BgEvent *bgEvents; + const struct ObjectEventTemplate *objectEvents; + const struct WarpEvent *warps; + const struct CoordEvent *coordEvents; + const struct BgEvent *bgEvents; }; struct MapConnection @@ -139,7 +139,7 @@ struct MapConnection struct MapConnections { s32 count; - struct MapConnection *connections; + const struct MapConnection *connections; }; struct MapHeader diff --git a/src/event_object_movement.c b/src/event_object_movement.c index be0c4ce26d..3025e0849a 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -131,9 +131,9 @@ static void SetObjectEventDynamicGraphicsId(struct ObjectEvent *); static void RemoveObjectEventInternal(struct ObjectEvent *); static u16 GetObjectEventFlagIdByObjectEventId(u8); static void UpdateObjectEventVisibility(struct ObjectEvent *, struct Sprite *); -static void MakeSpriteTemplateFromObjectEventTemplate(struct ObjectEventTemplate *, struct SpriteTemplate *, const struct SubspriteTable **); +static void MakeSpriteTemplateFromObjectEventTemplate(const struct ObjectEventTemplate *, struct SpriteTemplate *, const struct SubspriteTable **); static void GetObjectEventMovingCameraOffset(s16 *, s16 *); -static struct ObjectEventTemplate *GetObjectEventTemplateByLocalIdAndMap(u8, u8, u8); +static const struct ObjectEventTemplate *GetObjectEventTemplateByLocalIdAndMap(u8, u8, u8); static void LoadObjectEventPalette(u16); static void RemoveObjectEventIfOutsideView(struct ObjectEvent *); static void SpawnObjectEventOnReturnToField(u8, s16, s16); @@ -147,7 +147,7 @@ static void SpriteCB_CameraObject(struct Sprite *); static void CameraObject_0(struct Sprite *); static void CameraObject_1(struct Sprite *); static void CameraObject_2(struct Sprite *); -static struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8, struct ObjectEventTemplate *, u8); +static const struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8, const struct ObjectEventTemplate *, u8); static void ClearObjectEventMovement(struct ObjectEvent *, struct Sprite *); static void ObjectEventSetSingleMovement(struct ObjectEvent *, struct Sprite *, u8); static void SetSpriteDataForNormalStep(struct Sprite *, u8, u8); @@ -1267,7 +1267,7 @@ static u8 GetObjectEventIdByLocalId(u8 localId) return OBJECT_EVENTS_COUNT; } -static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, u8 mapNum, u8 mapGroup) +static u8 InitObjectEventStateFromTemplate(const struct ObjectEventTemplate *template, u8 mapNum, u8 mapGroup) { struct ObjectEvent *objectEvent; u8 objectEventId; @@ -1398,7 +1398,7 @@ void RemoveAllObjectEventsExceptPlayer(void) } } -static u8 TrySetupObjectEventSprite(struct ObjectEventTemplate *objectEventTemplate, struct SpriteTemplate *spriteTemplate, u8 mapNum, u8 mapGroup, s16 cameraX, s16 cameraY) +static u8 TrySetupObjectEventSprite(const struct ObjectEventTemplate *objectEventTemplate, struct SpriteTemplate *spriteTemplate, u8 mapNum, u8 mapGroup, s16 cameraX, s16 cameraY) { u8 spriteId; u8 paletteSlot; @@ -1458,7 +1458,7 @@ static u8 TrySetupObjectEventSprite(struct ObjectEventTemplate *objectEventTempl return objectEventId; } -static u8 TrySpawnObjectEventTemplate(struct ObjectEventTemplate *objectEventTemplate, u8 mapNum, u8 mapGroup, s16 cameraX, s16 cameraY) +static u8 TrySpawnObjectEventTemplate(const struct ObjectEventTemplate *objectEventTemplate, u8 mapNum, u8 mapGroup, s16 cameraX, s16 cameraY) { u8 objectEventId; struct SpriteTemplate spriteTemplate; @@ -1512,7 +1512,7 @@ u8 SpawnSpecialObjectEventParameterized(u8 graphicsId, u8 movementBehavior, u8 l u8 TrySpawnObjectEvent(u8 localId, u8 mapNum, u8 mapGroup) { - struct ObjectEventTemplate *objectEventTemplate; + const struct ObjectEventTemplate *objectEventTemplate; s16 cameraX, cameraY; objectEventTemplate = GetObjectEventTemplateByLocalIdAndMap(localId, mapNum, mapGroup); @@ -1542,7 +1542,7 @@ static void CopyObjectGraphicsInfoToSpriteTemplate_WithMovementType(u16 graphics CopyObjectGraphicsInfoToSpriteTemplate(graphicsId, sMovementTypeCallbacks[movementType], spriteTemplate, subspriteTables); } -static void MakeSpriteTemplateFromObjectEventTemplate(struct ObjectEventTemplate *objectEventTemplate, struct SpriteTemplate *spriteTemplate, const struct SubspriteTable **subspriteTables) +static void MakeSpriteTemplateFromObjectEventTemplate(const struct ObjectEventTemplate *objectEventTemplate, struct SpriteTemplate *spriteTemplate, const struct SubspriteTable **subspriteTables) { CopyObjectGraphicsInfoToSpriteTemplate_WithMovementType(objectEventTemplate->graphicsId, objectEventTemplate->movementType, spriteTemplate, subspriteTables); } @@ -2374,7 +2374,7 @@ const u8 *GetObjectEventScriptPointerByObjectEventId(u8 objectEventId) static u16 GetObjectEventFlagIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup) { - struct ObjectEventTemplate *obj = GetObjectEventTemplateByLocalIdAndMap(localId, mapNum, mapGroup); + const struct ObjectEventTemplate *obj = GetObjectEventTemplateByLocalIdAndMap(localId, mapNum, mapGroup); #ifdef UBFIX // BUG: The function may return NULL, and attempting to read from NULL may freeze the game using modern compilers. if (obj == NULL) @@ -2421,9 +2421,9 @@ u8 GetObjectEventBerryTreeId(u8 objectEventId) return gObjectEvents[objectEventId].trainerRange_berryTreeId; } -static struct ObjectEventTemplate *GetObjectEventTemplateByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup) +static const struct ObjectEventTemplate *GetObjectEventTemplateByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup) { - struct ObjectEventTemplate *templates; + const struct ObjectEventTemplate *templates; const struct MapHeader *mapHeader; u8 count; @@ -2441,7 +2441,7 @@ static struct ObjectEventTemplate *GetObjectEventTemplateByLocalIdAndMap(u8 loca return FindObjectEventTemplateByLocalId(localId, templates, count); } -static struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8 localId, struct ObjectEventTemplate *templates, u8 count) +static const struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8 localId, const struct ObjectEventTemplate *templates, u8 count) { u8 i; diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 9c526f0f72..3a0c97e8cf 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -60,8 +60,8 @@ static s8 GetWarpEventAtMapPosition(struct MapHeader *, struct MapPosition *); static void SetupWarp(struct MapHeader *, s8, struct MapPosition *); static bool8 TryDoorWarp(struct MapPosition *, u16, u8); static s8 GetWarpEventAtPosition(struct MapHeader *, u16, u16, u8); -static u8 *GetCoordEventScriptAtPosition(struct MapHeader *, u16, u16, u8); -static struct BgEvent *GetBackgroundEventAtPosition(struct MapHeader *, u16, u16, u8); +static const u8 *GetCoordEventScriptAtPosition(struct MapHeader *, u16, u16, u8); +static const struct BgEvent *GetBackgroundEventAtPosition(struct MapHeader *, u16, u16, u8); static bool8 TryStartCoordEventScript(struct MapPosition *); static bool8 TryStartWarpEventScript(struct MapPosition *, u16); static bool8 TryStartMiscWalkingScripts(u16); @@ -315,7 +315,7 @@ static const u8 *GetInteractedObjectEventScript(struct MapPosition *position, u8 static const u8 *GetInteractedBackgroundEventScript(struct MapPosition *position, u8 metatileBehavior, u8 direction) { - struct BgEvent *bgEvent = GetBackgroundEventAtPosition(&gMapHeader, position->x - MAP_OFFSET, position->y - MAP_OFFSET, position->elevation); + const struct BgEvent *bgEvent = GetBackgroundEventAtPosition(&gMapHeader, position->x - MAP_OFFSET, position->y - MAP_OFFSET, position->elevation); if (bgEvent == NULL) return NULL; @@ -497,7 +497,7 @@ static bool8 TryStartStepBasedScript(struct MapPosition *position, u16 metatileB static bool8 TryStartCoordEventScript(struct MapPosition *position) { - u8 *script = GetCoordEventScriptAtPosition(&gMapHeader, position->x - MAP_OFFSET, position->y - MAP_OFFSET, position->elevation); + const u8 *script = GetCoordEventScriptAtPosition(&gMapHeader, position->x - MAP_OFFSET, position->y - MAP_OFFSET, position->elevation); if (script == NULL) return FALSE; @@ -861,7 +861,7 @@ static bool8 TryDoorWarp(struct MapPosition *position, u16 metatileBehavior, u8 static s8 GetWarpEventAtPosition(struct MapHeader *mapHeader, u16 x, u16 y, u8 elevation) { s32 i; - struct WarpEvent *warpEvent = mapHeader->events->warps; + const struct WarpEvent *warpEvent = mapHeader->events->warps; u8 warpCount = mapHeader->events->warpCount; for (i = 0; i < warpCount; i++, warpEvent++) @@ -875,7 +875,7 @@ static s8 GetWarpEventAtPosition(struct MapHeader *mapHeader, u16 x, u16 y, u8 e return WARP_ID_NONE; } -static u8 *TryRunCoordEventScript(struct CoordEvent *coordEvent) +static const u8 *TryRunCoordEventScript(const struct CoordEvent *coordEvent) { if (coordEvent != NULL) { @@ -895,10 +895,10 @@ static u8 *TryRunCoordEventScript(struct CoordEvent *coordEvent) return NULL; } -static u8 *GetCoordEventScriptAtPosition(struct MapHeader *mapHeader, u16 x, u16 y, u8 elevation) +static const u8 *GetCoordEventScriptAtPosition(struct MapHeader *mapHeader, u16 x, u16 y, u8 elevation) { s32 i; - struct CoordEvent *coordEvents = mapHeader->events->coordEvents; + const struct CoordEvent *coordEvents = mapHeader->events->coordEvents; u8 coordEventCount = mapHeader->events->coordEventCount; for (i = 0; i < coordEventCount; i++) @@ -907,7 +907,7 @@ static u8 *GetCoordEventScriptAtPosition(struct MapHeader *mapHeader, u16 x, u16 { if (coordEvents[i].elevation == elevation || coordEvents[i].elevation == 0) { - u8 *script = TryRunCoordEventScript(&coordEvents[i]); + const u8 *script = TryRunCoordEventScript(&coordEvents[i]); if (script != NULL) return script; } @@ -916,15 +916,15 @@ static u8 *GetCoordEventScriptAtPosition(struct MapHeader *mapHeader, u16 x, u16 return NULL; } -u8 *GetCoordEventScriptAtMapPosition(struct MapPosition *position) +const u8 *GetCoordEventScriptAtMapPosition(struct MapPosition *position) { return GetCoordEventScriptAtPosition(&gMapHeader, position->x - MAP_OFFSET, position->y - MAP_OFFSET, position->elevation); } -static struct BgEvent *GetBackgroundEventAtPosition(struct MapHeader *mapHeader, u16 x, u16 y, u8 elevation) +static const struct BgEvent *GetBackgroundEventAtPosition(struct MapHeader *mapHeader, u16 x, u16 y, u8 elevation) { u8 i; - struct BgEvent *bgEvents = mapHeader->events->bgEvents; + const struct BgEvent *bgEvents = mapHeader->events->bgEvents; u8 bgEventCount = mapHeader->events->bgEventCount; for (i = 0; i < bgEventCount; i++) diff --git a/src/fieldmap.c b/src/fieldmap.c index 89d6b602c2..df4db47b53 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -36,7 +36,7 @@ struct BackupMapLayout gBackupMapLayout; static const struct ConnectionFlags sDummyConnectionFlags = {0}; static void InitMapLayoutData(struct MapHeader *mapHeader); -static void InitBackupMapLayoutData(u16 *map, u16 width, u16 height); +static void InitBackupMapLayoutData(const u16 *map, u16 width, u16 height); static void FillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); static void FillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); static void FillWestConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); @@ -44,14 +44,14 @@ static void FillEastConnection(struct MapHeader const *mapHeader, struct MapHead static void InitBackupMapLayoutConnections(struct MapHeader *mapHeader); static void LoadSavedMapView(void); static bool8 SkipCopyingMetatileFromSavedMap(u16 *mapBlock, u16 mapWidth, u8 yMode); -static struct MapConnection *GetIncomingConnection(u8 direction, int x, int y); -static bool8 IsPosInIncomingConnectingMap(u8 direction, int x, int y, struct MapConnection *connection); +static const struct MapConnection *GetIncomingConnection(u8 direction, int x, int y); +static bool8 IsPosInIncomingConnectingMap(u8 direction, int x, int y, const struct MapConnection *connection); static bool8 IsCoordInIncomingConnectingMap(int coord, int srcMax, int destMax, int offset); #define GetBorderBlockAt(x, y)({ \ u16 block; \ int i; \ - u16 *border = gMapHeader.mapLayout->border; \ + const u16 *border = gMapHeader.mapLayout->border; /* Unused, they read it again below */ \ \ i = (x + 1) & 1; \ i += ((y + 1) & 1) * 2; \ @@ -63,7 +63,7 @@ static bool8 IsCoordInIncomingConnectingMap(int coord, int srcMax, int destMax, #define GetMapGridBlockAt(x, y) (AreCoordsWithinMapGridBounds(x, y) ? gBackupMapLayout.map[x + gBackupMapLayout.width * y] : GetBorderBlockAt(x, y)) -struct MapHeader const *const GetMapHeaderFromConnection(struct MapConnection *connection) +const struct MapHeader *const GetMapHeaderFromConnection(const struct MapConnection *connection) { return Overworld_GetMapHeaderByGroupAndId(connection->mapGroup, connection->mapNum); } @@ -116,7 +116,7 @@ static void InitMapLayoutData(struct MapHeader *mapHeader) } } -static void InitBackupMapLayoutData(u16 *map, u16 width, u16 height) +static void InitBackupMapLayoutData(const u16 *map, u16 width, u16 height) { u16 *dest; int y; @@ -133,7 +133,7 @@ static void InitBackupMapLayoutData(u16 *map, u16 width, u16 height) static void InitBackupMapLayoutConnections(struct MapHeader *mapHeader) { int count; - struct MapConnection *connection; + const struct MapConnection *connection; int i; if (mapHeader->connections) @@ -171,7 +171,7 @@ static void InitBackupMapLayoutConnections(struct MapHeader *mapHeader) static void FillConnection(int x, int y, struct MapHeader const *connectedMapHeader, int x2, int y2, int width, int height) { int i; - u16 *src; + const u16 *src; u16 *dest; int mapWidth; @@ -619,7 +619,7 @@ bool32 CanCameraMoveInDirection(int direction) return TRUE; } -static void SetPositionFromConnection(struct MapConnection *connection, int direction, int x, int y) +static void SetPositionFromConnection(const struct MapConnection *connection, int direction, int x, int y) { struct MapHeader const *mapHeader; mapHeader = GetMapHeaderFromConnection(connection); @@ -647,7 +647,7 @@ static void SetPositionFromConnection(struct MapConnection *connection, int dire bool8 CameraMove(int x, int y) { int direction; - struct MapConnection *connection; + const struct MapConnection *connection; int old_x, old_y; gCamera.active = FALSE; direction = GetPostCameraMoveMapBorderId(x, y); @@ -675,11 +675,11 @@ bool8 CameraMove(int x, int y) return gCamera.active; } -static struct MapConnection *GetIncomingConnection(u8 direction, int x, int y) +static const struct MapConnection *GetIncomingConnection(u8 direction, int x, int y) { int count; int i; - struct MapConnection *connection; + const struct MapConnection *connection; const struct MapConnections *connections = gMapHeader.connections; #ifdef UBFIX // UB: Multiple possible null dereferences @@ -696,7 +696,7 @@ static struct MapConnection *GetIncomingConnection(u8 direction, int x, int y) return NULL; } -static bool8 IsPosInIncomingConnectingMap(u8 direction, int x, int y, struct MapConnection *connection) +static bool8 IsPosInIncomingConnectingMap(u8 direction, int x, int y, const struct MapConnection *connection) { struct MapHeader const *mapHeader; mapHeader = GetMapHeaderFromConnection(connection); @@ -737,7 +737,7 @@ static int IsCoordInConnectingMap(int coord, int max) return FALSE; } -static int IsPosInConnectingMap(struct MapConnection *connection, int x, int y) +static int IsPosInConnectingMap(const struct MapConnection *connection, int x, int y) { struct MapHeader const *mapHeader; mapHeader = GetMapHeaderFromConnection(connection); @@ -753,10 +753,10 @@ static int IsPosInConnectingMap(struct MapConnection *connection, int x, int y) return FALSE; } -struct MapConnection *GetMapConnectionAtPos(s16 x, s16 y) +const struct MapConnection *GetMapConnectionAtPos(s16 x, s16 y) { int count; - struct MapConnection *connection; + const struct MapConnection *connection; int i; u8 direction; if (!gMapHeader.connections) diff --git a/src/item_use.c b/src/item_use.c index 41e8884968..8a02827176 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -375,7 +375,7 @@ static bool8 ItemfinderCheckForHiddenItems(const struct MapEvents *events, u8 ta static bool8 IsHiddenItemPresentAtCoords(const struct MapEvents *events, s16 x, s16 y) { u8 bgEventCount = events->bgEventCount; - struct BgEvent *bgEvent = events->bgEvents; + const struct BgEvent *bgEvent = events->bgEvents; int i; for (i = 0; i < bgEventCount; i++) @@ -391,7 +391,7 @@ static bool8 IsHiddenItemPresentAtCoords(const struct MapEvents *events, s16 x, return FALSE; } -static bool8 IsHiddenItemPresentInConnection(struct MapConnection *connection, int x, int y) +static bool8 IsHiddenItemPresentInConnection(const struct MapConnection *connection, int x, int y) { u16 localX, localY; @@ -456,7 +456,7 @@ static void CheckForHiddenItemsInMapConnection(u8 taskId) || var2 > y || y >= height) { - struct MapConnection *conn = GetMapConnectionAtPos(x, y); + const struct MapConnection *conn = GetMapConnectionAtPos(x, y); if (conn && IsHiddenItemPresentInConnection(conn, x, y) == TRUE) SetDistanceOfClosestHiddenItem(taskId, x - playerX, y - playerY); } diff --git a/src/overworld.c b/src/overworld.c index 4f7cccdffb..70b102fd28 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -156,7 +156,7 @@ static void InitMenuBasedScript(const u8 *); static void LoadCableClubPlayer(s32, s32, struct CableClubPlayer *); static bool32 IsCableClubPlayerUnfrozen(struct CableClubPlayer *); static bool32 CanCableClubPlayerPressStart(struct CableClubPlayer *); -static u8 *TryGetTileEventScript(struct CableClubPlayer *); +static const u8 *TryGetTileEventScript(struct CableClubPlayer *); static bool32 PlayerIsAtSouthExit(struct CableClubPlayer *); static const u8 *TryInteractWithPlayer(struct CableClubPlayer *); static u16 KeyInterCB_DeferToRecvQueue(u32); @@ -482,7 +482,7 @@ void LoadObjEventTemplatesFromHeader(void) void LoadSaveblockObjEventScripts(void) { - struct ObjectEventTemplate *mapHeaderObjTemplates = gMapHeader.events->objectEvents; + const struct ObjectEventTemplate *mapHeaderObjTemplates = gMapHeader.events->objectEvents; struct ObjectEventTemplate *savObjTemplates = gSaveBlock1Ptr->objectEventTemplates; s32 i; @@ -2714,7 +2714,7 @@ static bool32 CanCableClubPlayerPressStart(struct CableClubPlayer *player) return FALSE; } -static u8 *TryGetTileEventScript(struct CableClubPlayer *player) +static const u8 *TryGetTileEventScript(struct CableClubPlayer *player) { if (player->movementMode != MOVEMENT_MODE_SCRIPTED) return FACING_NONE; diff --git a/src/trainer_hill.c b/src/trainer_hill.c index 528ee18a48..a74270ec77 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -685,7 +685,8 @@ static u16 GetMetatileForFloor(u8 floorId, u32 x, u32 y, u32 floorWidth) // floo void GenerateTrainerHillFloorLayout(u16 *mapArg) { s32 y, x; - u16 *src, *dst; + const u16 *src; + u16 *dst; u8 mapId = GetCurrentTrainerHillMapId(); if (mapId == TRAINER_HILL_ENTRANCE) From 0c380862d61a9c4eccd9ed4915e12db6e7ca4310 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 13 Mar 2023 15:37:46 -0400 Subject: [PATCH 2/5] Document the trendy saying word group --- data/scripts/mauville_man.inc | 10 ++-- data/specials.inc | 4 +- include/constants/easy_chat.h | 2 +- include/constants/flags.h | 2 +- include/easy_chat.h | 4 +- include/global.h | 6 +-- src/easy_chat.c | 97 +++++++++++++++++++++-------------- src/mauville_old_man.c | 19 +++---- src/mystery_event_script.c | 2 +- 9 files changed, 83 insertions(+), 63 deletions(-) diff --git a/data/scripts/mauville_man.inc b/data/scripts/mauville_man.inc index eda3505bf4..a336360436 100644 --- a/data/scripts/mauville_man.inc +++ b/data/scripts/mauville_man.inc @@ -64,9 +64,9 @@ MauvilleCity_PokemonCenter_1F_EventScript_DeclineWritingLyrics:: MauvilleCity_PokemonCenter_1F_EventScript_Hipster:: lock faceplayer - setflag FLAG_SYS_HIPSTER_MEET + setflag FLAG_UNLOCKED_TRENDY_SAYINGS msgbox MauvilleCity_PokemonCenter_1F_Text_TeachWhatsHipAndHappening, MSGBOX_DEFAULT - special GetHipsterSpokenFlag + special HasHipsterTaughtWord goto_if_eq VAR_RESULT, FALSE, MauvilleCity_PokemonCenter_1F_EventScript_TryTeachWord msgbox MauvilleCity_PokemonCenter_1F_Text_IAlreadyTaughtYou, MSGBOX_DEFAULT release @@ -80,8 +80,8 @@ MauvilleCity_PokemonCenter_1F_EventScript_TryTeachWord:: end MauvilleCity_PokemonCenter_1F_EventScript_TeachWord:: - msgbox MauvilleCity_PokemonCenter_1F_Text_HaveYouHeardOfPhrase, MSGBOX_DEFAULT - special SetHipsterSpokenFlag + msgbox MauvilleCity_PokemonCenter_1F_Text_HaveYouHeardOfWord, MSGBOX_DEFAULT + special SetHipsterTaughtWord release end @@ -969,7 +969,7 @@ MauvilleCity_PokemonCenter_1F_Text_IveGotNothingNewToTeach: .string "what's hip and happening.\p" .string "I've got nothing new to teach you!$" -MauvilleCity_PokemonCenter_1F_Text_HaveYouHeardOfPhrase: +MauvilleCity_PokemonCenter_1F_Text_HaveYouHeardOfWord: .string "Hey, have you heard about\n" .string "“{STR_VAR_1}”?\p" .string "What's it mean? Well…\n" diff --git a/data/specials.inc b/data/specials.inc index a0dbde8683..52b539a805 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -111,8 +111,8 @@ gSpecials:: def_special Script_GetCurrentMauvilleMan def_special HasBardSongBeenChanged def_special SaveBardSongLyrics - def_special GetHipsterSpokenFlag - def_special SetHipsterSpokenFlag + def_special HasHipsterTaughtWord + def_special SetHipsterTaughtWord def_special HipsterTryTeachWord def_special PlayBardSong def_special SetMauvilleOldManObjEventGfx diff --git a/include/constants/easy_chat.h b/include/constants/easy_chat.h index b5875b8814..b1f38941fc 100644 --- a/include/constants/easy_chat.h +++ b/include/constants/easy_chat.h @@ -1095,7 +1095,7 @@ #define EC_WORD_OLD ((EC_GROUP_TRENDY_SAYING << EC_MASK_BITS) | 30) #define EC_WORD_YOUNG ((EC_GROUP_TRENDY_SAYING << EC_MASK_BITS) | 31) #define EC_WORD_UGLY ((EC_GROUP_TRENDY_SAYING << EC_MASK_BITS) | 32) -#define NUM_ADDITIONAL_PHRASES 33 +#define NUM_TRENDY_SAYINGS 33 // Special Berry Masters Wife phrases #define NOT_SPECIAL_PHRASE 0 diff --git a/include/constants/flags.h b/include/constants/flags.h index 99a8377a75..377f18107d 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -1348,7 +1348,7 @@ #define FLAG_UNUSED_0x863 (SYSTEM_FLAGS + 0x3) // Unused Flag #define FLAG_SYS_GAME_CLEAR (SYSTEM_FLAGS + 0x4) #define FLAG_SYS_CHAT_USED (SYSTEM_FLAGS + 0x5) -#define FLAG_SYS_HIPSTER_MEET (SYSTEM_FLAGS + 0x6) +#define FLAG_UNLOCKED_TRENDY_SAYINGS (SYSTEM_FLAGS + 0x6) // Badges #define FLAG_BADGE01_GET (SYSTEM_FLAGS + 0x7) diff --git a/include/easy_chat.h b/include/easy_chat.h index c9ef4428f7..4bcc7389cd 100644 --- a/include/easy_chat.h +++ b/include/easy_chat.h @@ -128,11 +128,11 @@ void InitializeEasyChatWordArray(u16 *words, u16 length); u8 *ConvertEasyChatWordsToString(u8 *dest, const u16 *src, u16 columns, u16 rows); bool8 IsBardWordInvalid(u16 word); u16 GetRandomEasyChatWordFromGroup(u16 group); -u16 GetNewHipsterPhraseToTeach(void); +u16 UnlockRandomTrendySaying(void); u16 EasyChat_GetNumWordsInGroup(u8); u16 GetRandomEasyChatWordFromUnlockedGroup(u16); void DoEasyChatScreen(u8 type, u16 *words, MainCallback callback, u8 displayedPersonType); void InitQuestionnaireWords(void); -void UnlockAdditionalPhrase(u8 additionalPhraseId); +void UnlockTrendySaying(u8 wordIndex); #endif // GUARD_EASYCHAT_H diff --git a/include/global.h b/include/global.h index e0ff9f0c23..9396a95f7a 100644 --- a/include/global.h +++ b/include/global.h @@ -133,7 +133,7 @@ // values that don't appear in the Pokedex. NATIONAL_DEX_COUNT does not include these values. #define NUM_DEX_FLAG_BYTES ROUND_BITS_TO_BYTES(NUM_SPECIES) #define NUM_FLAG_BYTES ROUND_BITS_TO_BYTES(FLAGS_COUNT) -#define NUM_ADDITIONAL_PHRASE_BYTES ROUND_BITS_TO_BYTES(NUM_ADDITIONAL_PHRASES) +#define NUM_TRENDY_SAYING_BYTES ROUND_BITS_TO_BYTES(NUM_TRENDY_SAYINGS) // This produces an error at compile-time if expr is zero. // It looks like file.c:line: size of array `id' is negative @@ -673,7 +673,7 @@ struct MauvilleManGiddy struct MauvilleManHipster { u8 id; - bool8 alreadySpoken; + bool8 taughtWord; u8 language; }; @@ -1031,7 +1031,7 @@ struct SaveBlock1 /*0x2BC8*/ u16 easyChatBattleWon[EASY_CHAT_BATTLE_WORDS_COUNT]; /*0x2BD4*/ u16 easyChatBattleLost[EASY_CHAT_BATTLE_WORDS_COUNT]; /*0x2BE0*/ struct Mail mail[MAIL_COUNT]; - /*0x2E20*/ u8 additionalPhrases[NUM_ADDITIONAL_PHRASE_BYTES]; // bitfield for 33 additional phrases in easy chat system + /*0x2E20*/ u8 unlockedTrendySayings[NUM_TRENDY_SAYING_BYTES]; // Bitfield for unlockable Easy Chat words in EC_GROUP_TRENDY_SAYING /*0x2E25*/ //u8 padding5[3]; /*0x2E28*/ OldMan oldMan; /*0x2e64*/ struct DewfordTrend dewfordTrends[SAVED_TRENDS_COUNT]; diff --git a/src/easy_chat.c b/src/easy_chat.c index d08ea4b33d..35ba633cf4 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -5109,7 +5109,7 @@ static bool8 IsEasyChatGroupUnlocked(u8 groupId) switch (groupId) { case EC_GROUP_TRENDY_SAYING: - return FlagGet(FLAG_SYS_HIPSTER_MEET); + return FlagGet(FLAG_UNLOCKED_TRENDY_SAYINGS); case EC_GROUP_EVENTS: case EC_GROUP_MOVE_1: case EC_GROUP_MOVE_2: @@ -5425,80 +5425,99 @@ void BufferDeepLinkPhrase(void) CopyEasyChatWord(gStringVar2, easyChatWord); } -static bool8 IsAdditionalPhraseUnlocked(u8 additionalPhraseId) +/* + ### Trendy Sayings + + Not to be confused with Dewford Town's "trendy phrase". + + This is a group of easy chat words (EC_GROUP_TRENDY_SAYING) that are normally inaccessible. + They can be unlocked either through Mystery Event (where they're referred to as "rare" words) + or from the "Hipster" variety of the Mauville Old Man. The Hipster can unlock one word each + time he is received via record mixing (and once if he is the player's default Old Man). + + Which words have been unlocked is saved in the unlockedTrendySayings bitfield in SaveBlock1 + + Unlocked trendy saying words are only accessible if the flag FLAG_UNLOCKED_TRENDY_SAYINGS is set. + It's set any time the player talks to the Hipster, but is not apparently set by Mystery Event, + meaning trendy saying words unlocked via Mystery Event may not be available until the player has + talked to the Hipster. +*/ +static bool8 IsTrendySayingUnlocked(u8 wordIndex) { - int byteOffset = additionalPhraseId / 8; - int shift = additionalPhraseId % 8; - return (gSaveBlock1Ptr->additionalPhrases[byteOffset] >> shift) & 1; + int byteOffset = wordIndex / 8; + int shift = wordIndex % 8; + return (gSaveBlock1Ptr->unlockedTrendySayings[byteOffset] >> shift) & 1; } -void UnlockAdditionalPhrase(u8 additionalPhraseId) +void UnlockTrendySaying(u8 wordIndex) { - if (additionalPhraseId < NUM_ADDITIONAL_PHRASES) + if (wordIndex < NUM_TRENDY_SAYINGS) { - int byteOffset = additionalPhraseId / 8; - int shift = additionalPhraseId % 8; - gSaveBlock1Ptr->additionalPhrases[byteOffset] |= 1 << shift; + int byteOffset = wordIndex / 8; + int shift = wordIndex % 8; + gSaveBlock1Ptr->unlockedTrendySayings[byteOffset] |= 1 << shift; } } -static u8 GetNumAdditionalPhrasesUnlocked(void) +static u8 GetNumTrendySayingsUnlocked(void) { u8 i; - u8 numAdditionalPhrasesUnlocked; + u8 numUnlocked; - for (i = 0, numAdditionalPhrasesUnlocked = 0; i < NUM_ADDITIONAL_PHRASES; i++) + for (i = 0, numUnlocked = 0; i < NUM_TRENDY_SAYINGS; i++) { - if (IsAdditionalPhraseUnlocked(i)) - numAdditionalPhrasesUnlocked++; + if (IsTrendySayingUnlocked(i)) + numUnlocked++; } - return numAdditionalPhrasesUnlocked; + return numUnlocked; } -u16 GetNewHipsterPhraseToTeach(void) +u16 UnlockRandomTrendySaying(void) { u16 i; - u16 additionalPhraseId; - u8 numAdditionalPhrasesUnlocked = GetNumAdditionalPhrasesUnlocked(); - if (numAdditionalPhrasesUnlocked == NUM_ADDITIONAL_PHRASES) + u16 numToSkip; + u8 numUnlocked = GetNumTrendySayingsUnlocked(); + if (numUnlocked == NUM_TRENDY_SAYINGS) return EC_EMPTY_WORD; - additionalPhraseId = Random() % (NUM_ADDITIONAL_PHRASES - numAdditionalPhrasesUnlocked); - for (i = 0; i < NUM_ADDITIONAL_PHRASES; i++) + numToSkip = Random() % (NUM_TRENDY_SAYINGS - numUnlocked); + for (i = 0; i < NUM_TRENDY_SAYINGS; i++) { - if (!IsAdditionalPhraseUnlocked(i)) + if (!IsTrendySayingUnlocked(i)) { - if (additionalPhraseId) + if (numToSkip) { - additionalPhraseId--; + // Skip the first n locked words, as determined by the Random call above. + numToSkip--; } else { - UnlockAdditionalPhrase(i); + UnlockTrendySaying(i); return EC_WORD(EC_GROUP_TRENDY_SAYING, i); } } } + // Would only be reached if there are no new words to teach, which is handled at the start. return EC_EMPTY_WORD; } // Unused -u16 GetRandomTaughtHipsterPhrase(void) +static u16 GetRandomUnlockedTrendySaying(void) { u16 i; - u16 additionalPhraseId = GetNumAdditionalPhrasesUnlocked(); - if (additionalPhraseId == 0) + u16 n = GetNumTrendySayingsUnlocked(); + if (n == 0) return EC_EMPTY_WORD; - additionalPhraseId = Random() % additionalPhraseId; - for (i = 0; i < NUM_ADDITIONAL_PHRASES; i++) + n = Random() % n; + for (i = 0; i < NUM_TRENDY_SAYINGS; i++) { - if (IsAdditionalPhraseUnlocked(i)) + if (IsTrendySayingUnlocked(i)) { - if (additionalPhraseId) - additionalPhraseId--; + if (n) + n--; else return EC_WORD(EC_GROUP_TRENDY_SAYING, i); } @@ -5569,10 +5588,10 @@ void InitEasyChatPhrases(void) // Mauville old man data is corrupted, which is initialized directly after // this function is called when starting a new game. for (i = 0; i < 64; i++) - gSaveBlock1Ptr->additionalPhrases[i] = 0; + gSaveBlock1Ptr->unlockedTrendySayings[i] = 0; #else - for (i = 0; i < ARRAY_COUNT(gSaveBlock1Ptr->additionalPhrases); i++) - gSaveBlock1Ptr->additionalPhrases[i] = 0; + for (i = 0; i < ARRAY_COUNT(gSaveBlock1Ptr->unlockedTrendySayings); i++) + gSaveBlock1Ptr->unlockedTrendySayings[i] = 0; #endif } @@ -5611,7 +5630,7 @@ static void SetUnlockedEasyChatGroups(void) sWordData->unlockedGroupIds[sWordData->numUnlockedGroups++] = EC_GROUP_MOVE_2; } - if (FlagGet(FLAG_SYS_HIPSTER_MEET)) + if (FlagGet(FLAG_UNLOCKED_TRENDY_SAYINGS)) sWordData->unlockedGroupIds[sWordData->numUnlockedGroups++] = EC_GROUP_TRENDY_SAYING; if (IsNationalPokedexEnabled()) @@ -5800,7 +5819,7 @@ static bool8 IsEasyChatIndexAndGroupUnlocked(u16 wordIndex, u8 groupId) case EC_GROUP_MOVE_2: return TRUE; case EC_GROUP_TRENDY_SAYING: - return IsAdditionalPhraseUnlocked(wordIndex); + return IsTrendySayingUnlocked(wordIndex); default: return gEasyChatGroups[groupId].wordData.words[wordIndex].enabled; } diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index 689dcf6a16..6075bd5d95 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -88,7 +88,7 @@ static void SetupHipster(void) struct MauvilleManHipster *hipster = &gSaveBlock1Ptr->oldMan.hipster; hipster->id = MAUVILLE_MAN_HIPSTER; - hipster->alreadySpoken = FALSE; + hipster->taughtWord = FALSE; hipster->language = gGameLanguage; } @@ -225,27 +225,28 @@ void PlayBardSong(void) ScriptContext_Stop(); } -void GetHipsterSpokenFlag(void) +void HasHipsterTaughtWord(void) { - gSpecialVar_Result = (&gSaveBlock1Ptr->oldMan.hipster)->alreadySpoken; + gSpecialVar_Result = (&gSaveBlock1Ptr->oldMan.hipster)->taughtWord; } -void SetHipsterSpokenFlag(void) +void SetHipsterTaughtWord(void) { - (&gSaveBlock1Ptr->oldMan.hipster)->alreadySpoken = TRUE; + (&gSaveBlock1Ptr->oldMan.hipster)->taughtWord = TRUE; } void HipsterTryTeachWord(void) { - u16 phrase = GetNewHipsterPhraseToTeach(); + u16 word = UnlockRandomTrendySaying(); - if (phrase == EC_EMPTY_WORD) + if (word == EC_EMPTY_WORD) { + // All words already unlocked gSpecialVar_Result = FALSE; } else { - CopyEasyChatWord(gStringVar1, phrase); + CopyEasyChatWord(gStringVar1, word); gSpecialVar_Result = TRUE; } } @@ -369,7 +370,7 @@ static void ResetBardFlag(void) static void ResetHipsterFlag(void) { - (&gSaveBlock1Ptr->oldMan.hipster)->alreadySpoken = FALSE; + (&gSaveBlock1Ptr->oldMan.hipster)->taughtWord = FALSE; } static void ResetTraderFlag(void) diff --git a/src/mystery_event_script.c b/src/mystery_event_script.c index 124ababa45..b146bbab39 100644 --- a/src/mystery_event_script.c +++ b/src/mystery_event_script.c @@ -293,7 +293,7 @@ bool8 MEScrCmd_givenationaldex(struct ScriptContext *ctx) bool8 MEScrCmd_addrareword(struct ScriptContext *ctx) { - UnlockAdditionalPhrase(ScriptReadByte(ctx)); + UnlockTrendySaying(ScriptReadByte(ctx)); StringExpandPlaceholders(gStringVar4, gText_MysteryEventRareWord); ctx->mStatus = MEVENT_STATUS_SUCCESS; return FALSE; From 492422b6bd268178aa687ca017fe44d67a399546 Mon Sep 17 00:00:00 2001 From: Zunawe Date: Thu, 23 Mar 2023 21:47:26 -0700 Subject: [PATCH 3/5] Fix scanner item flag name --- data/maps/AbandonedShip_CaptainsOffice/scripts.inc | 2 +- data/maps/AbandonedShip_HiddenFloorRooms/map.json | 2 +- include/constants/flags.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/maps/AbandonedShip_CaptainsOffice/scripts.inc b/data/maps/AbandonedShip_CaptainsOffice/scripts.inc index 7c59fec967..78fdc6434a 100644 --- a/data/maps/AbandonedShip_CaptainsOffice/scripts.inc +++ b/data/maps/AbandonedShip_CaptainsOffice/scripts.inc @@ -7,7 +7,7 @@ AbandonedShip_CaptainsOffice_EventScript_CaptSternAide:: goto_if_set FLAG_EXCHANGED_SCANNER, AbandonedShip_CaptainsOffice_EventScript_ThisIsSSCactus checkitem ITEM_SCANNER goto_if_eq VAR_RESULT, TRUE, AbandonedShip_CaptainsOffice_EventScript_CanYouDeliverScanner - goto_if_set FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_4_SCANNER, AbandonedShip_CaptainsOffice_EventScript_ThisIsSSCactus + goto_if_set FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_2_SCANNER, AbandonedShip_CaptainsOffice_EventScript_ThisIsSSCactus msgbox AbandonedShip_CaptainsOffice_Text_NoSuccessFindingScanner, MSGBOX_DEFAULT release end diff --git a/data/maps/AbandonedShip_HiddenFloorRooms/map.json b/data/maps/AbandonedShip_HiddenFloorRooms/map.json index 9c480a1c92..e808250f47 100644 --- a/data/maps/AbandonedShip_HiddenFloorRooms/map.json +++ b/data/maps/AbandonedShip_HiddenFloorRooms/map.json @@ -38,7 +38,7 @@ "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", "script": "AbandonedShip_HiddenFloorRooms_EventScript_ItemScanner", - "flag": "FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_4_SCANNER" + "flag": "FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_2_SCANNER" }, { "graphics_id": "OBJ_EVENT_GFX_ITEM_BALL", diff --git a/include/constants/flags.h b/include/constants/flags.h index 99a8377a75..ed5dd5c68b 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -1123,7 +1123,7 @@ #define FLAG_ITEM_NEW_MAUVILLE_ULTRA_BALL 0x433 #define FLAG_ITEM_NEW_MAUVILLE_ESCAPE_ROPE 0x434 #define FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_6_LUXURY_BALL 0x435 -#define FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_4_SCANNER 0x436 +#define FLAG_ITEM_ABANDONED_SHIP_HIDDEN_FLOOR_ROOM_2_SCANNER 0x436 #define FLAG_ITEM_SCORCHED_SLAB_TM11 0x437 #define FLAG_ITEM_METEOR_FALLS_B1F_2R_TM02 0x438 #define FLAG_ITEM_SHOAL_CAVE_ENTRANCE_BIG_PEARL 0x439 From 4b859ff1e47b482d578f37d5cba7815a86a3ded9 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 31 Mar 2023 00:44:22 -0400 Subject: [PATCH 4/5] Use tilemap file for cable car pylons --- .../cable_car/{pylons.bin => pylon_pole.bin} | 0 graphics/cable_car/pylon_top.bin | Bin 0 -> 20 bytes src/cable_car.c | 65 ++++++++---------- 3 files changed, 27 insertions(+), 38 deletions(-) rename graphics/cable_car/{pylons.bin => pylon_pole.bin} (100%) create mode 100755 graphics/cable_car/pylon_top.bin diff --git a/graphics/cable_car/pylons.bin b/graphics/cable_car/pylon_pole.bin similarity index 100% rename from graphics/cable_car/pylons.bin rename to graphics/cable_car/pylon_pole.bin diff --git a/graphics/cable_car/pylon_top.bin b/graphics/cable_car/pylon_top.bin new file mode 100755 index 0000000000000000000000000000000000000000..44b20744d4383964fb62e47f513541fbc6ad594e GIT binary patch literal 20 bcmZQDU^HMdU^ZYeU^QSfU^n0};4}aL6dnQ& literal 0 HcmV?d00001 diff --git a/src/cable_car.c b/src/cable_car.c index 4eb4c30804..7d18df7b7f 100644 --- a/src/cable_car.c +++ b/src/cable_car.c @@ -27,9 +27,11 @@ #define STATE_END 0xFF -#define TAG_CABLE_CAR 1 -#define TAG_DOOR 2 -#define TAG_CABLE 3 +enum { + TAG_CABLE_CAR = 1, + TAG_DOOR, + TAG_CABLE, +}; struct CableCar { @@ -62,8 +64,8 @@ struct CableCar u16 *groundTilemap; u16 *treesTilemap; u16 *bgMountainsTilemap; - const u16 *pylonHookTilemapEntries; - u8 *pylonStemTilemap; + const u16 *pylonTopTilemap; + u16 *pylonPoleTilemap; }; static EWRAM_DATA struct CableCar *sCableCar = NULL; @@ -129,24 +131,11 @@ static const struct BgTemplate sBgTemplates[4] = { }, }; -static const u8 sGround_Tilemap[] = INCBIN_U8("graphics/cable_car/ground.bin.lz"); -static const u8 sTrees_Tilemap[] = INCBIN_U8("graphics/cable_car/trees.bin.lz"); -static const u8 sBgMountains_Tilemap[] = INCBIN_U8("graphics/cable_car/bg_mountains.bin.lz"); - -static const u16 sPylonHook_TilemapEntries[] = { - 0x3000, - 0x3001, - 0x3002, - 0x3003, - 0x3004, - 0x3005, - 0x3006, - 0x3007, - 0x3008, - 0x3009, -}; - -static const u8 sPylonStems_Tilemap[] = INCBIN_U8("graphics/cable_car/pylons.bin.lz"); +static const u16 sGround_Tilemap[] = INCBIN_U16("graphics/cable_car/ground.bin.lz"); +static const u16 sTrees_Tilemap[] = INCBIN_U16("graphics/cable_car/trees.bin.lz"); +static const u16 sBgMountains_Tilemap[] = INCBIN_U16("graphics/cable_car/bg_mountains.bin.lz"); +static const u16 sPylonTop_Tilemap[] = INCBIN_U16("graphics/cable_car/pylon_top.bin"); +static const u16 sPylonPole_Tilemap[] = INCBIN_U16("graphics/cable_car/pylon_pole.bin.lz"); static const struct CompressedSpriteSheet sSpriteSheets[] = { { gCableCar_Gfx, 0x800, TAG_CABLE_CAR }, @@ -299,8 +288,8 @@ static void CB2_LoadCableCar(void) sCableCar->groundTilemap = malloc_and_decompress(sGround_Tilemap, &sizeOut); sCableCar->treesTilemap = malloc_and_decompress(sTrees_Tilemap, &sizeOut); sCableCar->bgMountainsTilemap = malloc_and_decompress(sBgMountains_Tilemap, &sizeOut); - sCableCar->pylonStemTilemap = malloc_and_decompress(sPylonStems_Tilemap, &sizeOut); - sCableCar->pylonHookTilemapEntries = sPylonHook_TilemapEntries; + sCableCar->pylonPoleTilemap = malloc_and_decompress(sPylonPole_Tilemap, &sizeOut); + sCableCar->pylonTopTilemap = sPylonTop_Tilemap; DecompressAndCopyTileDataToVram(0, gCableCarBg_Gfx, 0, 0, 0); gMain.state++; break; @@ -335,8 +324,8 @@ static void CB2_LoadCableCar(void) case 6: CopyToBgTilemapBufferRect_ChangePalette(1, sCableCar->treesTilemap, 0, 17, 32, 15, 17); CopyToBgTilemapBufferRect_ChangePalette(2, sCableCar->bgMountainsTilemap, 0, 0, 30, 20, 17); - CopyToBgTilemapBufferRect_ChangePalette(3, sCableCar->pylonHookTilemapEntries, 0, 0, 5, 2, 17); - CopyToBgTilemapBufferRect_ChangePalette(3, sCableCar->pylonStemTilemap, 0, 2, 2, 20, 17); + CopyToBgTilemapBufferRect_ChangePalette(3, sCableCar->pylonTopTilemap, 0, 0, 5, 2, 17); + CopyToBgTilemapBufferRect_ChangePalette(3, sCableCar->pylonPoleTilemap, 0, 2, 2, 20, 17); gMain.state++; break; case 7: @@ -404,8 +393,8 @@ static void CB2_EndCableCar(void) UnsetBgTilemapBuffer(2); UnsetBgTilemapBuffer(3); ResetBgsAndClearDma3BusyFlags(0); - sCableCar->pylonHookTilemapEntries = NULL; - FREE_AND_SET_NULL(sCableCar->pylonStemTilemap); + sCableCar->pylonTopTilemap = NULL; + FREE_AND_SET_NULL(sCableCar->pylonPoleTilemap); FREE_AND_SET_NULL(sCableCar->bgMountainsTilemap); FREE_AND_SET_NULL(sCableCar->treesTilemap); FREE_AND_SET_NULL(sCableCar->groundTilemap); @@ -514,8 +503,8 @@ static void Task_AnimateBgGoingUp(u8 taskId) FillBgTilemapBufferRect(3, 0, 2, 0, 1, 2, 17); break; case 16: - CopyToBgTilemapBufferRect_ChangePalette(3, sCableCar->pylonHookTilemapEntries, 0, 0, 5, 2, 17); - CopyToBgTilemapBufferRect_ChangePalette(3, sCableCar->pylonStemTilemap, 0, 2, 2, 30, 17); + CopyToBgTilemapBufferRect_ChangePalette(3, sCableCar->pylonTopTilemap, 0, 0, 5, 2, 17); + CopyToBgTilemapBufferRect_ChangePalette(3, sCableCar->pylonPoleTilemap, 0, 2, 2, 30, 17); sCableCar->bg3VerticalOffset = 64; break; } @@ -542,7 +531,7 @@ static void Task_AnimateBgGoingDown(u8 taskId) switch (sCableCar->bg3HorizontalOffset) { case 176: - CopyToBgTilemapBufferRect_ChangePalette(3, sCableCar->pylonStemTilemap, 0, 2, 2, 30, 17); + CopyToBgTilemapBufferRect_ChangePalette(3, sCableCar->pylonPoleTilemap, 0, 2, 2, 30, 17); break; case 16: FillBgTilemapBufferRect(3, 0, 2, 0, 3, 2, 17); @@ -550,14 +539,14 @@ static void Task_AnimateBgGoingDown(u8 taskId) sCableCar->bg3VerticalOffset = 192; break; case 32: - FillBgTilemapBufferRect(3, sCableCar->pylonHookTilemapEntries[2], 2, 0, 1, 1, 17); - FillBgTilemapBufferRect(3, sCableCar->pylonHookTilemapEntries[3], 3, 0, 1, 1, 17); - FillBgTilemapBufferRect(3, sCableCar->pylonHookTilemapEntries[7], 2, 1, 1, 1, 17); - FillBgTilemapBufferRect(3, sCableCar->pylonHookTilemapEntries[8], 3, 1, 1, 1, 17); + FillBgTilemapBufferRect(3, sCableCar->pylonTopTilemap[2], 2, 0, 1, 1, 17); + FillBgTilemapBufferRect(3, sCableCar->pylonTopTilemap[3], 3, 0, 1, 1, 17); + FillBgTilemapBufferRect(3, sCableCar->pylonTopTilemap[7], 2, 1, 1, 1, 17); + FillBgTilemapBufferRect(3, sCableCar->pylonTopTilemap[8], 3, 1, 1, 1, 17); break; case 40: - FillBgTilemapBufferRect(3, sCableCar->pylonHookTilemapEntries[4], 4, 0, 1, 1, 17); - FillBgTilemapBufferRect(3, sCableCar->pylonHookTilemapEntries[9], 4, 1, 1, 1, 17); + FillBgTilemapBufferRect(3, sCableCar->pylonTopTilemap[4], 4, 0, 1, 1, 17); + FillBgTilemapBufferRect(3, sCableCar->pylonTopTilemap[9], 4, 1, 1, 1, 17); break; } } From 57396026b2f212bbc7c2fa04d230311738d9f8ef Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 31 Mar 2023 14:57:51 -0400 Subject: [PATCH 5/5] Replace NUM_TEXT_PRINTERS with WINDOWS_MAX --- gflib/text.c | 6 +++--- gflib/text.h | 2 -- gflib/window.c | 2 -- gflib/window.h | 2 ++ src/contest.c | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/gflib/text.c b/gflib/text.c index 86dca38291..1bded26b5a 100644 --- a/gflib/text.c +++ b/gflib/text.c @@ -36,7 +36,7 @@ static u32 GetGlyphWidth_Narrow(u16, bool32); static u32 GetGlyphWidth_SmallNarrow(u16, bool32); static EWRAM_DATA struct TextPrinter sTempTextPrinter = {0}; -static EWRAM_DATA struct TextPrinter sTextPrinters[NUM_TEXT_PRINTERS] = {0}; +static EWRAM_DATA struct TextPrinter sTextPrinters[WINDOWS_MAX] = {0}; static u16 sFontHalfRowLookupTable[0x51]; static u16 sLastTextBgColor; @@ -244,7 +244,7 @@ static void SetFontsPointer(const struct FontInfo *fonts) void DeactivateAllTextPrinters(void) { int printer; - for (printer = 0; printer < NUM_TEXT_PRINTERS; ++printer) + for (printer = 0; printer < WINDOWS_MAX; ++printer) sTextPrinters[printer].active = FALSE; } @@ -322,7 +322,7 @@ void RunTextPrinters(void) if (!gDisableTextPrinters) { - for (i = 0; i < NUM_TEXT_PRINTERS; ++i) + for (i = 0; i < WINDOWS_MAX; ++i) { if (sTextPrinters[i].active) { diff --git a/gflib/text.h b/gflib/text.h index a88cb990e1..ff13efa9a8 100644 --- a/gflib/text.h +++ b/gflib/text.h @@ -3,8 +3,6 @@ #include "characters.h" -#define NUM_TEXT_PRINTERS 32 - // Given as a text speed when all the text should be // loaded at once but not copied to vram yet. #define TEXT_SKIP_DRAW 0xFF diff --git a/gflib/window.c b/gflib/window.c index 1621a08842..76e863f10e 100644 --- a/gflib/window.c +++ b/gflib/window.c @@ -9,8 +9,6 @@ u8 gTransparentTileNumber; void *gWindowBgTilemapBuffers[NUM_BACKGROUNDS]; extern u32 gWindowTileAutoAllocEnabled; -#define WINDOWS_MAX 32 - EWRAM_DATA struct Window gWindows[WINDOWS_MAX] = {0}; EWRAM_DATA static struct Window* sWindowPtr = NULL; EWRAM_DATA static u16 sWindowSize = 0; diff --git a/gflib/window.h b/gflib/window.h index 0000dd864d..0f2dff2a8a 100644 --- a/gflib/window.h +++ b/gflib/window.h @@ -1,6 +1,8 @@ #ifndef GUARD_WINDOW_H #define GUARD_WINDOW_H +#define WINDOWS_MAX 32 + #define PIXEL_FILL(num) ((num) | ((num) << 4)) enum { diff --git a/src/contest.c b/src/contest.c index 2c0f66f6bd..8a1847f111 100644 --- a/src/contest.c +++ b/src/contest.c @@ -5503,7 +5503,7 @@ static void ContestBG_FillBoxWithTile(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 wi static bool32 Contest_RunTextPrinters(void) { RunTextPrinters(); - return IsTextPrinterActive(4); + return IsTextPrinterActive(WIN_GENERAL_TEXT); } static void Contest_SetBgCopyFlags(u32 flagIndex)