From 8fbf711e09207e7ebf93488a403877aff2c209a1 Mon Sep 17 00:00:00 2001 From: scbroede <32247405+scbroede@users.noreply.github.com> Date: Wed, 18 Mar 2026 10:05:03 -0400 Subject: [PATCH] unify coordinate structs (#1010) --- include/coordinates.h | 23 +++++++- include/underground/defs.h | 10 ---- include/underground/manager.h | 9 ++-- include/underground/mining.h | 3 +- include/underground/pc.h | 6 ++- include/underground/secret_bases.h | 3 +- include/underground/spheres.h | 8 +-- include/underground/traps.h | 5 +- src/overlay005/ov5_021F6454.c | 54 +++++++++---------- .../trainer_card_sprites.c | 10 ++-- src/underground/manager.c | 47 ++++++++-------- src/underground/mining.c | 3 +- src/underground/pc.c | 5 +- src/underground/secret_bases.c | 3 +- src/underground/spheres.c | 9 ++-- src/underground/top_screen.c | 15 ++---- src/underground/traps.c | 32 +++++------ src/unk_02099500.c | 2 +- 18 files changed, 123 insertions(+), 124 deletions(-) diff --git a/include/coordinates.h b/include/coordinates.h index addd349f9a..775c49bc72 100644 --- a/include/coordinates.h +++ b/include/coordinates.h @@ -3,12 +3,31 @@ typedef struct CoordinatesS16 { s16 x; - s16 y; + union { + s16 y; + s16 z; + }; } CoordinatesS16; typedef struct CoordinatesU16 { u16 x; - u16 y; + union { + u16 y; + u16 z; + }; } CoordinatesU16; +typedef struct CoordinatesInt { + int x; + union { + int y; + int z; + }; +} CoordinatesInt; + +typedef struct CoordinatesFX32 { + fx32 x; + fx32 y; +} CoordinatesFX32; + #endif // POKEPLATINUM_COORDINATES_H diff --git a/include/underground/defs.h b/include/underground/defs.h index 641175bd3d..ef27b95ada 100644 --- a/include/underground/defs.h +++ b/include/underground/defs.h @@ -34,16 +34,6 @@ #define MAX_GOOD_WIDTH 3 #define MAX_GOOD_DEPTH 3 -typedef struct Coordinates { - u16 x; - u16 z; -} Coordinates; - -typedef struct Coordinates2D { - u16 x; - u16 y; -} Coordinates2D; - typedef struct SpherePrice { u8 sphereType; u8 minSize; diff --git a/include/underground/manager.h b/include/underground/manager.h index 5fdaf1bb49..ef9406d5f4 100644 --- a/include/underground/manager.h +++ b/include/underground/manager.h @@ -5,6 +5,7 @@ #include "underground/defs.h" #include "underground/text_printer.h" +#include "coordinates.h" #include "savedata.h" #include "string_gf.h" #include "sys_task_manager.h" @@ -68,7 +69,7 @@ enum MapMarkerAnim { #define MAX_RADAR_BLIPS 16 -typedef Coordinates *(*CoordinatesGetter)(Coordinates *, int); +typedef CoordinatesU16 *(*GetCoordinatesFunc)(CoordinatesU16 *coordinates, int index); UndergroundTextPrinter *UndergroundMan_GetCommonTextPrinter(void); UndergroundTextPrinter *UndergroundMan_GetCaptureFlagTextPrinter(void); @@ -83,9 +84,9 @@ BOOL UndergroundMan_CheckForTouchInput(void); void UndergroundMan_ProcessTouchInput(int netID, int unused1, void *data, void *unused3); void UndergroundMan_ProcessTouchRadarTrapResults(int unused0, int size, void *data, void *unused3); void UndergroundMan_ProcessTouchRadarMiningSpotResults(int unused0, int size, void *data, void *unused3); -int UndergroundMan_CalcCoordsIndexGet(Coordinates *coordinates); -int UndergroundMan_CalcCoordsIndexInsert(Coordinates *coordinates); -void UndergroundMan_InitCoordsOrderingState(int orderedArrayLength, CoordinatesGetter coordinatesGetter); +int UndergroundMan_CalcCoordsIndexGet(CoordinatesU16 *coordinates); +int UndergroundMan_CalcCoordsIndexInsert(CoordinatesU16 *coordinates); +void UndergroundMan_InitCoordsOrderingState(int orderedArrayLength, GetCoordinatesFunc getCoordsFunc); void UndergroundMan_OpenMenu(void); void UndergroundMan_ProgressInteractCooldown(void); void UndergroundMan_ProcessInteract(u8 flags); diff --git a/include/underground/mining.h b/include/underground/mining.h index 556ce944f7..c85e794f5b 100644 --- a/include/underground/mining.h +++ b/include/underground/mining.h @@ -6,6 +6,7 @@ #include "field/field_system_decl.h" #include "underground/defs.h" +#include "coordinates.h" #include "string_gf.h" void MiningEnv_Init(void *dest, FieldSystem *fieldSystem); @@ -13,7 +14,7 @@ int MiningEnv_Size(void); void Mining_Dummy(void); void Mining_Dummy2(void); void MiningEnv_Free(void); -BOOL Mining_CheckForMiningSpotInteract(int netID, Coordinates *coordinates); +BOOL Mining_CheckForMiningSpotInteract(int netID, CoordinatesU16 *coordinates); void Mining_SpawnMiningSpotNearBuriedSphere(int buriedSphereX, int buriedSphereZ, MATHRandContext16 *rand); void Mining_SendRadarResults(void); void Mining_ProcessMiningSpotInteract(int unused0, int unused1, void *data, void *unused3); diff --git a/include/underground/pc.h b/include/underground/pc.h index 499f68dfaf..35b0e88300 100644 --- a/include/underground/pc.h +++ b/include/underground/pc.h @@ -4,8 +4,10 @@ #include "underground/defs.h" #include "underground/menus.h" -int UndergroundPC_GetPCOwnerNetIDAtCoordinates(Coordinates *coordinates, int dir); -BOOL UndergroundPC_TryUsePC(int netID, Coordinates *coordinates); +#include "coordinates.h" + +int UndergroundPC_GetPCOwnerNetIDAtCoordinates(CoordinatesU16 *coordinates, int dir); +BOOL UndergroundPC_TryUsePC(int netID, CoordinatesU16 *coordinates); void UndergroundPC_ProcessPCInteraction(int unused0, int unused1, void *data, void *data2); int CommPacketSizeOf_PCInteraction(void); void UndergroundPC_ProcessTakeFlagAttempt(int unused0, int unused1, void *data, void *unused3); diff --git a/include/underground/secret_bases.h b/include/underground/secret_bases.h index c00e550733..ce90c1a051 100644 --- a/include/underground/secret_bases.h +++ b/include/underground/secret_bases.h @@ -6,6 +6,7 @@ #include "field/field_system_decl.h" #include "underground/defs.h" +#include "coordinates.h" #include "savedata.h" #include "string_gf.h" #include "underground.h" @@ -64,7 +65,7 @@ int SecretBases_PrintBaseDecorationMessage(int bankEntry); void SecretBases_EraseBaseDecorationMessageBox(void); void SecretBases_SetGoodNameForPrinter(enum Good goodID); void SecretBases_SetTwoDigitNumberWithIndexForPrinter(int num, int index); -BOOL SecretBases_CheckForInteractableGood(int netID, Coordinates *coordinates); +BOOL SecretBases_CheckForInteractableGood(int netID, CoordinatesU16 *coordinates); void SecretBases_ProcessGoodInteractionEvent(int unused0, int unused1, void *data, void *unused3); int CommPacketSizeOf_GoodInteractionEvent(void); void SecretBases_QueueObtainedFlagMessage(int netID, int flagOwnerNetID); diff --git a/include/underground/spheres.h b/include/underground/spheres.h index 51ea07e5b7..c336127678 100644 --- a/include/underground/spheres.h +++ b/include/underground/spheres.h @@ -7,6 +7,7 @@ #include "field/field_system_decl.h" +#include "coordinates.h" #include "string_gf.h" typedef struct TouchRadarSearchContext { @@ -14,11 +15,6 @@ typedef struct TouchRadarSearchContext { u16 radius; } TouchRadarSearchContext; -typedef struct TouchRadarCoordinates { - s16 x; - s16 z; -} TouchRadarCoordinates; - void SpheresEnv_Init(void *dest, FieldSystem *fieldSystem); int SpheresEnv_Size(void); void Spheres_DisableBuriedSphereSparkles(void); @@ -27,7 +23,7 @@ void SpheresEnv_Free(void); void Spheres_AdvanceBuriedSphereSparkleTimer(void); void Spheres_ProcessRetrieveBuriedSphereRequest(int unused, int unused2, void *src, void *unused3); void TouchRadarSearch_Init(TouchRadarSearchContext *ctx, int radius); -BOOL TouchRadarSearch_GetNextCoords(TouchRadarSearchContext *ctx, TouchRadarCoordinates *out); +BOOL TouchRadarSearch_GetNextCoords(TouchRadarSearchContext *ctx, CoordinatesS16 *out); void Spheres_TryBurySphere(enum SphereType sphereType, int sphereSize, int x, int z); BOOL Spheres_IsMiningItemSphere(int miningItemID); BOOL Spheres_IsBuriedSphereAtCoordinates(int x, int z); diff --git a/include/underground/traps.h b/include/underground/traps.h index 85595b74f9..8c4b98f68b 100644 --- a/include/underground/traps.h +++ b/include/underground/traps.h @@ -9,6 +9,7 @@ #include "underground/defs.h" #include "bg_window.h" +#include "coordinates.h" #include "string_gf.h" void TrapsEnv_Init(void *dest, FieldSystem *fieldSystem); @@ -34,8 +35,8 @@ void Traps_ReceiveLoadTrapsResult(int unused0, int unused1, void *data, void *un int CommPacketSizeOf_LoadTrapsResult(void); BOOL Traps_HaveLinksReceivedPlacedTraps(void); void Traps_ClearLinksReceivedPlacedTraps(void); -int CommPacketSizeOf_Coordinates(void); -BOOL Traps_TryDisengageTrap(int netID, Coordinates *unused, u8 flags); +int CommPacketSizeOf_CoordinatesU16(void); +BOOL Traps_TryDisengageTrap(int netID, CoordinatesU16 *unused, u8 flags); int CommPacketSizeOf_TriggeredTrap(void); void Traps_ProcessDisengagedTrap(int unused0, int unused1, void *data, void *unused3); BOOL Traps_IsTrapAtCoordinates(int x, int z); diff --git a/src/overlay005/ov5_021F6454.c b/src/overlay005/ov5_021F6454.c index ed3df41f0e..737e9e74c3 100644 --- a/src/overlay005/ov5_021F6454.c +++ b/src/overlay005/ov5_021F6454.c @@ -24,6 +24,7 @@ #include "berry_patch_graphics.h" #include "bg_window.h" #include "billboard.h" +#include "coordinates.h" #include "field_script_context.h" #include "font.h" #include "game_records.h" @@ -62,11 +63,6 @@ #define MAX_LIST_ENTRIES 120 -typedef struct RegiDotCoordinates { - s16 x; - s16 z; -} RegiDotCoordinates; - typedef struct BattleHallRecordSelector { FieldSystem *fieldSystem; SysTask *task; @@ -846,34 +842,34 @@ BOOL ScrCmd_Dummy316(ScriptContext *ctx) return TRUE; } -static const RegiDotCoordinates sDotCoordinatesIronRuins[] = { - { 4, 7 }, - { 5, 5 }, - { 5, 9 }, - { 7, 7 }, - { 9, 5 }, - { 9, 9 }, - { 10, 7 } +static const CoordinatesS16 sDotCoordinatesIronRuins[] = { + { .x = 4, .z = 7 }, + { .x = 5, .z = 5 }, + { .x = 5, .z = 9 }, + { .x = 7, .z = 7 }, + { .x = 9, .z = 5 }, + { .x = 9, .z = 9 }, + { .x = 10, .z = 7 } }; -static const RegiDotCoordinates sDotCoordinatesIcebergRuins[] = { - { 3, 7 }, - { 5, 7 }, - { 7, 5 }, - { 7, 7 }, - { 7, 9 }, - { 9, 7 }, - { 11, 7 } +static const CoordinatesS16 sDotCoordinatesIcebergRuins[] = { + { .x = 3, .z = 7 }, + { .x = 5, .z = 7 }, + { .x = 7, .z = 5 }, + { .x = 7, .z = 7 }, + { .x = 7, .z = 9 }, + { .x = 9, .z = 7 }, + { .x = 11, .z = 7 } }; -static const RegiDotCoordinates sDotCoordinatesRockPeakRuins[] = { - { 5, 5 }, - { 5, 7 }, - { 5, 9 }, - { 7, 7 }, - { 9, 5 }, - { 9, 7 }, - { 9, 9 } +static const CoordinatesS16 sDotCoordinatesRockPeakRuins[] = { + { .x = 5, .z = 5 }, + { .x = 5, .z = 7 }, + { .x = 5, .z = 9 }, + { .x = 7, .z = 7 }, + { .x = 9, .z = 5 }, + { .x = 9, .z = 7 }, + { .x = 9, .z = 9 } }; BOOL ScrCmd_ActivateRegiRuinsDot(ScriptContext *ctx) diff --git a/src/trainer_card_screen/trainer_card_sprites.c b/src/trainer_card_screen/trainer_card_sprites.c index 6854092805..4c98a624d7 100644 --- a/src/trainer_card_screen/trainer_card_sprites.c +++ b/src/trainer_card_screen/trainer_card_sprites.c @@ -7,6 +7,7 @@ #include "badges.h" #include "char_transfer.h" +#include "coordinates.h" #include "gx_layers.h" #include "heap.h" #include "narc.h" @@ -17,11 +18,6 @@ #include "sprite_transfer.h" #include "sprite_util.h" -typedef struct Coordinates { - int x; - int y; -} Coordinates; - static const u8 sSpriteResourceCapacities[4] = { [SPRITE_RESOURCE_CHAR] = 1, [SPRITE_RESOURCE_PLTT] = 2, @@ -29,7 +25,7 @@ static const u8 sSpriteResourceCapacities[4] = { [SPRITE_RESOURCE_ANIM] = 1 }; -static const Coordinates sBadgeCoordinates[] = { +static const CoordinatesInt sBadgeCoordinates[] = { [BADGE_ID_COAL] = { .x = 24, .y = 40 }, [BADGE_ID_FOREST] = { .x = 80, .y = 40 }, [BADGE_ID_COBBLE] = { .x = 136, .y = 40 }, @@ -40,7 +36,7 @@ static const Coordinates sBadgeCoordinates[] = { [BADGE_ID_BEACON] = { .x = 192, .y = 72 } }; -static const Coordinates sSparkleCoordinates[] = { +static const CoordinatesInt sSparkleCoordinates[] = { [BADGE_ID_COAL] = { .x = 24, .y = 40 }, [BADGE_ID_FOREST] = { .x = 80, .y = 40 }, [BADGE_ID_COBBLE] = { .x = 136, .y = 40 }, diff --git a/src/underground/manager.c b/src/underground/manager.c index 7770faf0b8..cd69d7bc91 100644 --- a/src/underground/manager.c +++ b/src/underground/manager.c @@ -27,6 +27,7 @@ #include "comm_player_manager.h" #include "communication_information.h" #include "communication_system.h" +#include "coordinates.h" #include "field_system.h" #include "game_options.h" #include "graphics.h" @@ -71,8 +72,8 @@ typedef struct UndergroundManager { FieldSystem *fieldSystem; u8 padding[4]; SysTask *sysTask; - Coordinates2D touchCoordinates; - Coordinates touchedTileCoords; + CoordinatesU16 touchCoordinates; + CoordinatesU16 touchedTileCoords; StoredListMenuPos storedPositions[MAX_STORED_MENU_POSITIONS]; u16 storedPositionKey; u8 linksTalkedTo[MAX_CONNECTED_PLAYERS]; @@ -82,7 +83,7 @@ typedef struct UndergroundManager { u8 touchRadarTrapResults[MAX_TOUCH_RADAR_RESULTS_OF_TYPE]; u8 touchRadarMiningSpotResults[MAX_TOUCH_RADAR_RESULTS_OF_TYPE]; u8 touchRadarBuriedSphereResults[MAX_TOUCH_RADAR_RESULTS_OF_TYPE]; - CoordinatesGetter coordinatesGetter; + GetCoordinatesFunc getCoordsFunc; UndergroundTextPrinter *commonTextPrinter; UndergroundTextPrinter *captureFlagTextPrinter; UndergroundTextPrinter *miscTextPrinter; @@ -311,7 +312,7 @@ static BOOL UndergroundMan_GetQueuedPlayerMessage(String *dest) // doesn't check for everything that could be at the coordinates BOOL UndergroundMan_AreCoordinatesOccupied(int x, int z) { - Coordinates coordinates = { + CoordinatesU16 coordinates = { .x = x, .z = z }; @@ -358,7 +359,7 @@ BOOL UndergroundMan_CheckForTouchInput(void) pos = ov5_GetPositionFromTouchCoordinates(gSystem.touchX, gSystem.touchY, sUndergroundMan->fieldSystem->unk_8C); int x, z; LandData_ObjectPosToTilePos(pos.x, pos.z, &x, &z); - Coordinates touchedTileCoords = { + CoordinatesU16 touchedTileCoords = { .x = x, .z = z }; @@ -368,7 +369,7 @@ BOOL UndergroundMan_CheckForTouchInput(void) sUndergroundMan->touchedTileCoords.x = x; sUndergroundMan->touchedTileCoords.z = z; - CommSys_SendData(48, &touchedTileCoords, sizeof(Coordinates)); + CommSys_SendData(48, &touchedTileCoords, sizeof(CoordinatesU16)); return TRUE; } @@ -378,7 +379,7 @@ BOOL UndergroundMan_CheckForTouchInput(void) return FALSE; } -static int UndergroundMan_TouchRadarSearch(u8 *out, TouchRadarItemCheckFunc isItemAtCoords, Coordinates *touchedTileCoords) +static int UndergroundMan_TouchRadarSearch(u8 *out, TouchRadarItemCheckFunc isItemAtCoords, CoordinatesU16 *touchedTileCoords) { int index = 1; @@ -388,7 +389,7 @@ static int UndergroundMan_TouchRadarSearch(u8 *out, TouchRadarItemCheckFunc isIt TouchRadarSearchContext ctx; TouchRadarSearch_Init(&ctx, TOUCH_RADAR_RADIUS); - TouchRadarCoordinates radarCoords; + CoordinatesS16 radarCoords; while (TouchRadarSearch_GetNextCoords(&ctx, &radarCoords)) { int x = touchedTileCoords->x + radarCoords.x; int z = touchedTileCoords->z + radarCoords.z; @@ -408,7 +409,7 @@ static int UndergroundMan_TouchRadarSearch(u8 *out, TouchRadarItemCheckFunc isIt return index; } -static void UndergroundMan_StartTouchRadar(int netID, Coordinates *touchedTileCoords) +static void UndergroundMan_StartTouchRadar(int netID, CoordinatesU16 *touchedTileCoords) { u8 buffer[MAX_TOUCH_RADAR_RESULTS_OF_TYPE + 1]; int size = 1; @@ -424,7 +425,7 @@ static void UndergroundMan_StartTouchRadar(int netID, Coordinates *touchedTileCo void UndergroundMan_ProcessTouchInput(int netID, int unused1, void *data, void *unused3) { - Coordinates *touchedTileCoords = data; + CoordinatesU16 *touchedTileCoords = data; if (!CommPlayerMan_IsMovementEnabled(netID)) { return; @@ -469,7 +470,7 @@ void UndergroundMan_ProcessTouchRadarMiningSpotResults(int unused0, int size, vo TouchRadar_StartTask(sUndergroundMan->fieldSystem, sUndergroundMan->touchedTileCoords.x, sUndergroundMan->touchedTileCoords.z, sUndergroundMan->touchCoordinates.x, sUndergroundMan->touchCoordinates.y, sUndergroundMan->touchRadarTrapResults, sUndergroundMan->touchRadarTrapResultCount, sUndergroundMan->touchRadarMiningSpotResults, sUndergroundMan->touchRadarMiningSpotResultCount, sUndergroundMan->touchRadarBuriedSphereResults, sUndergroundMan->touchRadarBuriedSphereResultCount); } -static int UndergroundMan_GetOrderedCoordinatesValue(Coordinates *coordinates) +static int UndergroundMan_GetOrderedCoordinatesValue(CoordinatesU16 *coordinates) { int x = 0, z = 0; @@ -483,45 +484,45 @@ static int UndergroundMan_GetOrderedCoordinatesValue(Coordinates *coordinates) return (z * MAP_MATRIX_MAX_WIDTH * MAP_TILES_COUNT_X) + x; } -int UndergroundMan_CalcCoordsIndexGet(Coordinates *coordinates) +int UndergroundMan_CalcCoordsIndexGet(CoordinatesU16 *coordinates) { int index = 0; int max = sUndergroundMan->orderedArrayLength - 1; int orderedValue = UndergroundMan_GetOrderedCoordinatesValue(coordinates); - Coordinates _; - CoordinatesGetter getCoordinates = sUndergroundMan->coordinatesGetter; + CoordinatesU16 _; + GetCoordinatesFunc getCoordsFunc = sUndergroundMan->getCoordsFunc; while (index < max) { int midpoint = (index + max) / 2; - if (UndergroundMan_GetOrderedCoordinatesValue(getCoordinates(&_, midpoint)) < orderedValue) { + if (UndergroundMan_GetOrderedCoordinatesValue(getCoordsFunc(&_, midpoint)) < orderedValue) { index = midpoint + 1; } else { max = midpoint; } } - if (UndergroundMan_GetOrderedCoordinatesValue(getCoordinates(&_, index)) == orderedValue) { + if (UndergroundMan_GetOrderedCoordinatesValue(getCoordsFunc(&_, index)) == orderedValue) { return index; } return -1; } -int UndergroundMan_CalcCoordsIndexInsert(Coordinates *coordinates) +int UndergroundMan_CalcCoordsIndexInsert(CoordinatesU16 *coordinates) { int index = 0; int max = sUndergroundMan->orderedArrayLength - 2; int orderedValue = UndergroundMan_GetOrderedCoordinatesValue(coordinates); - Coordinates _; - CoordinatesGetter getCoordinates = sUndergroundMan->coordinatesGetter; + CoordinatesU16 _; + GetCoordinatesFunc getCoordsFunc = sUndergroundMan->getCoordsFunc; max++; // why? while (index < max) { int midpoint = (index + max) / 2; - if (UndergroundMan_GetOrderedCoordinatesValue(getCoordinates(&_, midpoint)) < orderedValue) { + if (UndergroundMan_GetOrderedCoordinatesValue(getCoordsFunc(&_, midpoint)) < orderedValue) { index = midpoint + 1; } else { max = midpoint; @@ -531,9 +532,9 @@ int UndergroundMan_CalcCoordsIndexInsert(Coordinates *coordinates) return index; } -void UndergroundMan_InitCoordsOrderingState(int orderedArrayLength, CoordinatesGetter coordinatesGetter) +void UndergroundMan_InitCoordsOrderingState(int orderedArrayLength, GetCoordinatesFunc getCoordsFunc) { - sUndergroundMan->coordinatesGetter = coordinatesGetter; + sUndergroundMan->getCoordsFunc = getCoordsFunc; sUndergroundMan->orderedArrayLength = orderedArrayLength; } @@ -595,7 +596,7 @@ void UndergroundMan_ProcessInteractEvent(int netID, int unused1, void *data, voi { TalkEvent talkEvent; InteractEvent *event = data; - Coordinates coordinates; + CoordinatesU16 coordinates; u8 netIDBuffer = netID; coordinates.x = CommPlayer_GetXInFrontOfPlayerServer(netID); coordinates.z = CommPlayer_GetZInFrontOfPlayerServer(netID); diff --git a/src/underground/mining.c b/src/underground/mining.c index 3975303168..be3867b9be 100644 --- a/src/underground/mining.c +++ b/src/underground/mining.c @@ -27,6 +27,7 @@ #include "comm_player_manager.h" #include "communication_information.h" #include "communication_system.h" +#include "coordinates.h" #include "field_system.h" #include "field_task.h" #include "game_records.h" @@ -803,7 +804,7 @@ void MiningEnv_Free(void) } } -BOOL Mining_CheckForMiningSpotInteract(int netID, Coordinates *coordinates) +BOOL Mining_CheckForMiningSpotInteract(int netID, CoordinatesU16 *coordinates) { MiningSpot *miningSpot = Mining_GetMiningSpotAtCoordinates(coordinates->x, coordinates->z); u8 buffer = netID; diff --git a/src/underground/pc.c b/src/underground/pc.c index 4dcf2e48a7..325ea106b9 100644 --- a/src/underground/pc.c +++ b/src/underground/pc.c @@ -26,6 +26,7 @@ #include "comm_player_manager.h" #include "communication_information.h" #include "communication_system.h" +#include "coordinates.h" #include "field_system.h" #include "field_task.h" #include "heap.h" @@ -142,7 +143,7 @@ static const WindowTemplate sYesNoWindowTemplate = { .baseTile = BASE_TILE_YES_NO_MENU }; -int UndergroundPC_GetPCOwnerNetIDAtCoordinates(Coordinates *coordinates, int dir) +int UndergroundPC_GetPCOwnerNetIDAtCoordinates(CoordinatesU16 *coordinates, int dir) { int netID; int x = coordinates->x; @@ -176,7 +177,7 @@ int UndergroundPC_GetPCOwnerNetIDAtCoordinates(Coordinates *coordinates, int dir return NETID_NONE; } -BOOL UndergroundPC_TryUsePC(int netID, Coordinates *coordinates) +BOOL UndergroundPC_TryUsePC(int netID, CoordinatesU16 *coordinates) { int pcNetID = UndergroundPC_GetPCOwnerNetIDAtCoordinates(coordinates, CommPlayer_DirServer(netID)); diff --git a/src/underground/secret_bases.c b/src/underground/secret_bases.c index f0c952783a..71be86be8e 100644 --- a/src/underground/secret_bases.c +++ b/src/underground/secret_bases.c @@ -30,6 +30,7 @@ #include "comm_player_manager.h" #include "communication_information.h" #include "communication_system.h" +#include "coordinates.h" #include "field_map_change.h" #include "field_system.h" #include "field_task.h" @@ -2303,7 +2304,7 @@ static enum Good SecretBases_GetGoodWithCollisionAtCoordinates(SecretBase *secre return UG_GOOD_NONE; } -BOOL SecretBases_CheckForInteractableGood(int netID, Coordinates *coordinates) +BOOL SecretBases_CheckForInteractableGood(int netID, CoordinatesU16 *coordinates) { int x = coordinates->x; int z = coordinates->z; diff --git a/src/underground/spheres.c b/src/underground/spheres.c index 29a5ea68ec..3834e5188a 100644 --- a/src/underground/spheres.c +++ b/src/underground/spheres.c @@ -15,6 +15,7 @@ #include "comm_player_manager.h" #include "communication_system.h" +#include "coordinates.h" #include "field_system.h" #include "game_records.h" #include "heap.h" @@ -158,7 +159,7 @@ void Spheres_AdvanceBuriedSphereSparkleTimer(void) } } -static Coordinates *Spheres_GetCoordinatesOfBuriedSphereAtOrderedIndex(Coordinates *coordinates, int index) +static CoordinatesU16 *Spheres_GetCoordinatesOfBuriedSphereAtOrderedIndex(CoordinatesU16 *coordinates, int index) { if (spheresEnv->buriedSpheresByCoordinates[index] == NULL) { return NULL; @@ -172,7 +173,7 @@ static Coordinates *Spheres_GetCoordinatesOfBuriedSphereAtOrderedIndex(Coordinat static void Spheres_AddBuriedSphereToCoordinatesOrdering(BuriedSphere *sphere) { - Coordinates coordinates = { + CoordinatesU16 coordinates = { .x = sphere->x, .z = sphere->z }; @@ -221,7 +222,7 @@ static BuriedSphere *Spheres_Dummy(BuriedSphere *sphere) static BuriedSphere *Spheres_GetBuriedSphereAtCoordinates(int x, int z) { - Coordinates coordinates = { + CoordinatesU16 coordinates = { .x = x, .z = z }; @@ -286,7 +287,7 @@ void TouchRadarSearch_Init(TouchRadarSearchContext *ctx, int radius) ctx->iterator = 0; } -BOOL TouchRadarSearch_GetNextCoords(TouchRadarSearchContext *ctx, TouchRadarCoordinates *out) +BOOL TouchRadarSearch_GetNextCoords(TouchRadarSearchContext *ctx, CoordinatesS16 *out) { int i; int iterator = ctx->iterator; diff --git a/src/underground/top_screen.c b/src/underground/top_screen.c index fa808ff30d..698b61fb36 100644 --- a/src/underground/top_screen.c +++ b/src/underground/top_screen.c @@ -71,11 +71,6 @@ typedef struct MessageQueue { charcode_t tempStringChars[TEMP_STRING_SIZE]; } MessageQueue; -typedef struct PlayerCoordinates { - int x; - int z; -} PlayerCoordinates; - typedef struct PlayerMarkerData { int x; int z; @@ -91,7 +86,7 @@ typedef struct OtherMarkerData { struct UndergroundTopScreenContext_t { int state; - PlayerCoordinates playerCoords[MAX_CONNECTED_PLAYERS]; + CoordinatesInt playerCoords[MAX_CONNECTED_PLAYERS]; PlayerMarkerData playerMarkers[MAX_CONNECTED_PLAYERS]; OtherMarkerData otherMarkers[MAX_RADAR_BLIPS + 1]; FieldSystem *parent; @@ -114,8 +109,8 @@ static int positionsDummy[MAX_CONNECTED_PLAYERS][2]; static void UndergroundTopScreen_InitBackgrounds(BgConfig *bgConfig, Window *window); static void UndergroundMap_InitSpriteResources(UndergroundTopScreenContext *ctx); -static void UndergroundMap_FetchPlayerPositions(PlayerAvatar *const playerAvatar, PlayerCoordinates playerCoords[], PlayerMarkerData markerData[]); -static void UndergroundMap_InitPlayerPositions(PlayerCoordinates playerCoords[], PlayerMarkerData markerData[]); +static void UndergroundMap_FetchPlayerPositions(PlayerAvatar *const playerAvatar, CoordinatesInt playerCoords[], PlayerMarkerData markerData[]); +static void UndergroundMap_InitPlayerPositions(CoordinatesInt playerCoords[], PlayerMarkerData markerData[]); static void UndergroundMap_DrawPlayerMarkers(PlayerMarkerData markerData[], Sprite *sprites[]); static void UndergroundTopScreen_FreeBackgrounds(BgConfig *bgConfig); static void UndergroundTopScreen_HandleMessageQueue(BgConfig *unused, Window *window, int *printerID, int *state, int *timer, MessageQueue *queue); @@ -251,7 +246,7 @@ static void UndergroundTopScreen_Task(SysTask *sysTask, void *data) } } -static void UndergroundMap_InitPlayerPositions(PlayerCoordinates playerCoords[], PlayerMarkerData markerData[]) +static void UndergroundMap_InitPlayerPositions(CoordinatesInt playerCoords[], PlayerMarkerData markerData[]) { for (int netID = 0; netID < MAX_CONNECTED_PLAYERS; netID++) { playerCoords[netID].x = 0; @@ -265,7 +260,7 @@ static void UndergroundMap_InitPlayerPositions(PlayerCoordinates playerCoords[], } } -static void UndergroundMap_FetchPlayerPositions(PlayerAvatar *const playerAvatar, PlayerCoordinates playerCoords[], PlayerMarkerData markerData[]) +static void UndergroundMap_FetchPlayerPositions(PlayerAvatar *const playerAvatar, CoordinatesInt playerCoords[], PlayerMarkerData markerData[]) { for (int netID = 0; netID < MAX_CONNECTED_PLAYERS; netID++) { playerCoords[netID].x = CommPlayer_GetXIfActive(netID); diff --git a/src/underground/traps.c b/src/underground/traps.c index 05f80bf48c..e9bb874b75 100644 --- a/src/underground/traps.c +++ b/src/underground/traps.c @@ -27,6 +27,7 @@ #include "comm_player_manager.h" #include "communication_information.h" #include "communication_system.h" +#include "coordinates.h" #include "field_system.h" #include "field_task.h" #include "game_records.h" @@ -121,11 +122,6 @@ typedef struct TrapRadarResult { u8 netID; } TrapRadarResult; -typedef struct fx32Coordinates { - fx32 x; - fx32 y; -} fx32Coordinates; - typedef struct TrapRadarContext { TrapRadarResult results[MAX_PLACED_TRAPS + MAX_SPAWNED_TRAPS]; u8 index; @@ -182,7 +178,7 @@ typedef struct LeafTrapContext { int state; int printerID; u16 leafAngleIdx[MAX_TRAP_EFFECT_SPRITES]; - Coordinates2D leafCoords[MAX_TRAP_EFFECT_SPRITES]; + CoordinatesU16 leafCoords[MAX_TRAP_EFFECT_SPRITES]; u8 micBlowIntensities[40]; u8 micBlowDelay[MAX_TRAP_EFFECT_SPRITES]; u8 blowIntensityIndex; @@ -242,7 +238,7 @@ typedef struct BubbleTrapContext { int printerID; u8 bubbleSizes[MAX_BUBBLES]; u16 bubbleAngleIdx[MAX_BUBBLES]; - fx32Coordinates bubbleCoords[MAX_BUBBLES]; + CoordinatesFX32 bubbleCoords[MAX_BUBBLES]; BOOL isBubblePopped[MAX_BUBBLES]; u16 bubbleScaleTimer[MAX_BUBBLES]; u8 timer; @@ -1016,7 +1012,7 @@ int CommPacketSizeOf_AllTrapsPlacedPlayer(void) return sizeof(BuriedTrap) * MAX_PLACED_TRAPS; } -static Coordinates *Traps_GetCoordinatesOfBuriedTrapAtOrderedIndex(Coordinates *coordinates, int index) +static CoordinatesU16 *Traps_GetCoordinatesOfBuriedTrapAtOrderedIndex(CoordinatesU16 *coordinates, int index) { if (trapsEnv->buriedTrapsByCoordinates[index] == NULL) { return NULL; @@ -1030,7 +1026,7 @@ static Coordinates *Traps_GetCoordinatesOfBuriedTrapAtOrderedIndex(Coordinates * static void Traps_AddBuriedTrapToCoordinatesOrdering(BuriedTrap *trap) { - Coordinates coordinates = { + CoordinatesU16 coordinates = { .x = trap->x, .z = trap->z }; @@ -1480,12 +1476,12 @@ void Traps_ClearLinksReceivedPlacedTraps(void) trapsEnv->linksReceivedPlacedTraps = FALSE; } -int CommPacketSizeOf_Coordinates(void) +int CommPacketSizeOf_CoordinatesU16(void) { - return sizeof(Coordinates); + return sizeof(CoordinatesU16); } -BOOL Traps_TryDisengageTrap(int netID, Coordinates *unused, u8 flags) +BOOL Traps_TryDisengageTrap(int netID, CoordinatesU16 *unused, u8 flags) { Underground *underground = SaveData_GetUnderground(FieldSystem_GetSaveData(trapsEnv->fieldSystem)); @@ -1594,7 +1590,7 @@ static int Traps_GetBuriedTrapSetterNetID(BuriedTrap *trap) static BuriedTrap *Traps_GetTrapAtCoordinates(int x, int z) { - Coordinates coordinates = { + CoordinatesU16 coordinates = { .x = x, .z = z }; @@ -2372,7 +2368,7 @@ static void Traps_EndSmokeTrapEffectClient(int netID, BOOL allowToolStepBack) } // returns true when less than 13 tiles of smoke remain -static BOOL Traps_ProcessSmoke(Coordinates2D *touchCoordinates, BgConfig *bgConfig, SmokeTrapContext *ctx) +static BOOL Traps_ProcessSmoke(CoordinatesU16 *touchCoordinates, BgConfig *bgConfig, SmokeTrapContext *ctx) { int smokeTilesLeft = 0; u8 *tilemap = Bg_GetTilemapBuffer(bgConfig, BG_LAYER_MAIN_2); @@ -2514,10 +2510,10 @@ static void Traps_SmokeTrapClientTask(SysTask *sysTask, void *data) break; case SMOKE_TRAP_STATE_MAIN: if (gSystem.touchHeld) { - Coordinates2D touchCoordinates; - - touchCoordinates.x = gSystem.touchX; - touchCoordinates.y = gSystem.touchY; + CoordinatesU16 touchCoordinates = { + .x = gSystem.touchX, + .y = gSystem.touchY + }; if (Traps_ProcessSmoke(&touchCoordinates, ctx->bgConfig, ctx)) { if (ctx->isTool) { diff --git a/src/unk_02099500.c b/src/unk_02099500.c index 51fb486fa4..9432af2003 100644 --- a/src/unk_02099500.c +++ b/src/unk_02099500.c @@ -72,7 +72,7 @@ static const CommCmdTable Unk_020F68A4[] = { { Traps_ProcessTriggeredTrapBits, CommPacketSizeOf_NetId, NULL }, { Traps_QueueSendTrapRadarResults, CommPacketSizeOf_Nothing, NULL }, { Traps_ReceiveTrapRadarResults, CommPacketSizeOf_TrapRadarResult, NULL }, - { UndergroundMan_ProcessTouchInput, CommPacketSizeOf_Coordinates, NULL }, + { UndergroundMan_ProcessTouchInput, CommPacketSizeOf_CoordinatesU16, NULL }, { UndergroundMan_ProcessTouchRadarTrapResults, CommPacketSizeOf_Variable, NULL }, { UndergroundMan_ProcessTouchRadarMiningSpotResults, CommPacketSizeOf_Variable, NULL }, // 50 { Traps_ProcessDisengagedTrap, CommPacketSizeOf_TriggeredTrap, NULL },