diff --git a/include/constants/battle_pyramid.h b/include/constants/battle_pyramid.h index 1be3c11157..ebb7538823 100644 --- a/include/constants/battle_pyramid.h +++ b/include/constants/battle_pyramid.h @@ -4,9 +4,6 @@ #define TOTAL_ROUNDS 20 #define PICKUP_ITEMS_PER_ROUND 10 -#define FLOOR_WALKABLE_METATILE 0x28D -#define FLOOR_EXIT_METATILE 0x28E - #define HINT_EXIT_DIRECTION 0 #define HINT_REMAINING_ITEMS 1 #define HINT_REMAINING_TRAINERS 2 diff --git a/include/constants/metatile_labels.h b/include/constants/metatile_labels.h index 6159bf6cb4..b4ee3eacf5 100644 --- a/include/constants/metatile_labels.h +++ b/include/constants/metatile_labels.h @@ -788,4 +788,8 @@ #define METATILE_SecretBase_SpikesMat_BottomMid 0x32A #define METATILE_SecretBase_SpikesMat_BottomRight 0x32B +// gTileset_BattlePyramid +#define METATILE_BattlePyramid_Floor 0x28D +#define METATILE_BattlePyramid_Exit 0x28E + #endif // GUARD_METATILE_LABELS_H diff --git a/include/fieldmap.h b/include/fieldmap.h index 5bcbe20ea6..28da8da2a3 100644 --- a/include/fieldmap.h +++ b/include/fieldmap.h @@ -9,6 +9,14 @@ #define NUM_PALS_TOTAL 13 #define MAX_MAP_DATA_SIZE 0x2800 +// Map coordinates are offset by 7 when using the map +// buffer because it needs to load sufficient border +// metatiles to fill the player's view (the player has +// 7 metatiles of view horizontally in either direction). +#define MAP_OFFSET 7 +#define MAP_OFFSET_W (MAP_OFFSET * 2 + 1) +#define MAP_OFFSET_H (MAP_OFFSET * 2) + #include "main.h" extern struct BackupMapLayout gBackupMapLayout; diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 169dc69c5d..e334e75d56 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -34,6 +34,7 @@ #include "constants/items.h" #include "constants/layouts.h" #include "constants/maps.h" +#include "constants/metatile_labels.h" #include "constants/moves.h" #include "constants/trainers.h" @@ -1235,16 +1236,16 @@ static u8 GetPostBattleDirectionHintTextIndex(int *hintType, u8 minDistanceForEx int x, y; u8 textIndex = 0; u16 *map = gBackupMapLayout.map; - map += gBackupMapLayout.width * 7 + 7; + map += gBackupMapLayout.width * 7 + MAP_OFFSET; for (y = 0; y < 32; map += 47, y++) { for (x = 0; x < 32; x++) { - if ((map[x] & METATILE_ID_MASK) == FLOOR_EXIT_METATILE) + if ((map[x] & METATILE_ID_MASK) == METATILE_BattlePyramid_Exit) { - x += 7 - gObjectEvents[gSelectedObjectEvent].initialCoords.x; - y += 7 - gObjectEvents[gSelectedObjectEvent].initialCoords.y; + x += MAP_OFFSET - gObjectEvents[gSelectedObjectEvent].initialCoords.x; + y += MAP_OFFSET - gObjectEvents[gSelectedObjectEvent].initialCoords.y; if (x >= minDistanceForExitHint || x <= -minDistanceForExitHint || y >= minDistanceForExitHint @@ -1537,17 +1538,17 @@ void GenerateBattlePyramidFloorLayout(u16 *backupMapData, bool8 setPlayerPositio const u16 *layoutMap = mapLayout->map; gBackupMapLayout.map = backupMapData; - gBackupMapLayout.width = mapLayout->width * 4 + 15; - gBackupMapLayout.height = mapLayout->height * 4 + 14; + gBackupMapLayout.width = mapLayout->width * 4 + MAP_OFFSET_W; + gBackupMapLayout.height = mapLayout->height * 4 + MAP_OFFSET_H; map = backupMapData; - yOffset = ((i / 4 * mapLayout->height) + 7) * gBackupMapLayout.width; - xOffset = (i % 4 * mapLayout->width) + 7; + yOffset = ((i / 4 * mapLayout->height) + MAP_OFFSET) * gBackupMapLayout.width; + xOffset = (i % 4 * mapLayout->width) + MAP_OFFSET; map += yOffset + xOffset; for (y = 0; y < mapLayout->height; y++) { for (x = 0; x < mapLayout->width; x++) { - if ((layoutMap[x] & METATILE_ID_MASK) != FLOOR_EXIT_METATILE) + if ((layoutMap[x] & METATILE_ID_MASK) != METATILE_BattlePyramid_Exit) { map[x] = layoutMap[x]; } @@ -1558,14 +1559,14 @@ void GenerateBattlePyramidFloorLayout(u16 *backupMapData, bool8 setPlayerPositio gSaveBlock1Ptr->pos.x = (mapLayout->width * (i % 4)) + x; gSaveBlock1Ptr->pos.y = (mapLayout->height * (i / 4)) + y; } - map[x] = (layoutMap[x] & 0xFC00) | FLOOR_WALKABLE_METATILE; + map[x] = (layoutMap[x] & (METATILE_ELEVATION_MASK | METATILE_COLLISION_MASK)) | METATILE_BattlePyramid_Floor; } else { map[x] = layoutMap[x]; } } - map += 15 + (mapLayout->width * 4); + map += MAP_OFFSET_W + (mapLayout->width * 4); layoutMap += mapLayout->width; } } diff --git a/src/braille_puzzles.c b/src/braille_puzzles.c index aa6664f356..d8410988dd 100644 --- a/src/braille_puzzles.c +++ b/src/braille_puzzles.c @@ -85,12 +85,12 @@ bool8 ShouldDoBrailleDigEffect(void) void DoBrailleDigEffect(void) { - MapGridSetMetatileIdAt(16, 8, METATILE_Cave_SealedChamberEntrance_TopLeft); - MapGridSetMetatileIdAt(17, 8, METATILE_Cave_SealedChamberEntrance_TopMid); - MapGridSetMetatileIdAt(18, 8, METATILE_Cave_SealedChamberEntrance_TopRight); - MapGridSetMetatileIdAt(16, 9, METATILE_Cave_SealedChamberEntrance_BottomLeft | METATILE_COLLISION_MASK); - MapGridSetMetatileIdAt(17, 9, METATILE_Cave_SealedChamberEntrance_BottomMid); - MapGridSetMetatileIdAt(18, 9, METATILE_Cave_SealedChamberEntrance_BottomRight | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt( 9 + MAP_OFFSET, 1 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_TopLeft); + MapGridSetMetatileIdAt(10 + MAP_OFFSET, 1 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_TopMid); + MapGridSetMetatileIdAt(11 + MAP_OFFSET, 1 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_TopRight); + MapGridSetMetatileIdAt( 9 + MAP_OFFSET, 2 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_BottomLeft | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(10 + MAP_OFFSET, 2 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_BottomMid); + MapGridSetMetatileIdAt(11 + MAP_OFFSET, 2 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_BottomRight | METATILE_COLLISION_MASK); DrawWholeMapView(); PlaySE(SE_BANG); FlagSet(FLAG_SYS_BRAILLE_DIG); @@ -112,84 +112,8 @@ bool8 CheckRelicanthWailord(void) } // THEORY: this was caused by block commenting out all of the older R/S braille functions but leaving the call to it itself, which creates the nullsub. -// the code is shown below to show what this might look like. void ShouldDoBrailleRegirockEffectOld(void) { - /* - if (!FlagGet(FLAG_SYS_REGIROCK_PUZZLE_COMPLETED) && (gSaveBlock1.location.mapGroup == MAP_GROUP_DESERT_RUINS && gSaveBlock1.location.mapNum == MAP_ID_DESERT_RUINS)) - { - if (gSaveBlock1.pos.x == 10 && gSaveBlock1.pos.y == 23) - return TRUE; - else if (gSaveBlock1.pos.x == 9 && gSaveBlock1.pos.y == 23) - return TRUE; - else if (gSaveBlock1.pos.x == 11 && gSaveBlock1.pos.y == 23) - return TRUE; - } - - return FALSE; -} - -void DoBrailleRegirockEffect(void) -{ - FieldEffectActiveListRemove(FLDEFF_USE_STRENGTH); - MapGridSetMetatileIdAt(14, 26, 554); - MapGridSetMetatileIdAt(15, 26, 555); - MapGridSetMetatileIdAt(16, 26, 556); - MapGridSetMetatileIdAt(14, 27, 3634); - MapGridSetMetatileIdAt(15, 27, 563); - MapGridSetMetatileIdAt(16, 27, 3636); - DrawWholeMapView(); - PlaySE(SE_BANG); - FlagSet(FLAG_SYS_REGIROCK_PUZZLE_COMPLETED); - ScriptContext2_Disable(); -} - -bool8 ShouldDoBrailleRegisteelEffect(void) -{ - if (!FlagGet(FLAG_SYS_REGISTEEL_PUZZLE_COMPLETED) && (gSaveBlock1.location.mapGroup == MAP_GROUP_ANCIENT_TOMB && gSaveBlock1.location.mapNum == MAP_ID_ANCIENT_TOMB)) - { - if (gSaveBlock1.pos.x == 8 && gSaveBlock1.pos.y == 25) - return TRUE; - } - - return FALSE; -} - -void DoBrailleRegisteelEffect(void) -{ - gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; - FieldEffectStart(FLDEFF_USE_TOMB_PUZZLE_EFFECT); -} - -bool8 FldEff_UseFlyAncientTomb(void) -{ - u8 taskId = CreateFieldMoveTask(); - - gTasks[taskId].data[8] = (u32)UseRegisteelHm_Callback >> 16; - gTasks[taskId].data[9] = (u32)UseRegisteelHm_Callback; - return FALSE; -} - -void UseRegisteelHm_Callback(void) -{ - FieldEffectActiveListRemove(FLDEFF_USE_TOMB_PUZZLE_EFFECT); - UseFlyAncientTomb_Finish(); -} - -void UseFlyAncientTomb_Finish(void) -{ - MapGridSetMetatileIdAt(14, 26, 554); - MapGridSetMetatileIdAt(15, 26, 555); - MapGridSetMetatileIdAt(16, 26, 556); - MapGridSetMetatileIdAt(14, 27, 3634); - MapGridSetMetatileIdAt(15, 27, 563); - MapGridSetMetatileIdAt(16, 27, 3636); - DrawWholeMapView(); - PlaySE(SE_BANG); - FlagSet(FLAG_SYS_REGISTEEL_PUZZLE_COMPLETED); - ScriptContext2_Disable(); -} - */ } void DoSealedChamberShakingEffect1(void) @@ -278,12 +202,12 @@ void UseRegirockHm_Callback(void) void DoBrailleRegirockEffect(void) { - MapGridSetMetatileIdAt(14, 26, METATILE_Cave_SealedChamberEntrance_TopLeft); - MapGridSetMetatileIdAt(15, 26, METATILE_Cave_SealedChamberEntrance_TopMid); - MapGridSetMetatileIdAt(16, 26, METATILE_Cave_SealedChamberEntrance_TopRight); - MapGridSetMetatileIdAt(14, 27, METATILE_Cave_SealedChamberEntrance_BottomLeft | METATILE_COLLISION_MASK); - MapGridSetMetatileIdAt(15, 27, METATILE_Cave_SealedChamberEntrance_BottomMid); - MapGridSetMetatileIdAt(16, 27, METATILE_Cave_SealedChamberEntrance_BottomRight | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(7 + MAP_OFFSET, 19 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_TopLeft); + MapGridSetMetatileIdAt(8 + MAP_OFFSET, 19 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_TopMid); + MapGridSetMetatileIdAt(9 + MAP_OFFSET, 19 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_TopRight); + MapGridSetMetatileIdAt(7 + MAP_OFFSET, 20 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_BottomLeft | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(8 + MAP_OFFSET, 20 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_BottomMid); + MapGridSetMetatileIdAt(9 + MAP_OFFSET, 20 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_BottomRight | METATILE_COLLISION_MASK); DrawWholeMapView(); PlaySE(SE_BANG); FlagSet(FLAG_SYS_REGIROCK_PUZZLE_COMPLETED); @@ -317,12 +241,12 @@ void UseRegisteelHm_Callback(void) void DoBrailleRegisteelEffect(void) { - MapGridSetMetatileIdAt(14, 26, METATILE_Cave_SealedChamberEntrance_TopLeft); - MapGridSetMetatileIdAt(15, 26, METATILE_Cave_SealedChamberEntrance_TopMid); - MapGridSetMetatileIdAt(16, 26, METATILE_Cave_SealedChamberEntrance_TopRight); - MapGridSetMetatileIdAt(14, 27, METATILE_Cave_SealedChamberEntrance_BottomLeft | METATILE_COLLISION_MASK); - MapGridSetMetatileIdAt(15, 27, METATILE_Cave_SealedChamberEntrance_BottomMid); - MapGridSetMetatileIdAt(16, 27, METATILE_Cave_SealedChamberEntrance_BottomRight | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(7 + MAP_OFFSET, 19 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_TopLeft); + MapGridSetMetatileIdAt(8 + MAP_OFFSET, 19 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_TopMid); + MapGridSetMetatileIdAt(9 + MAP_OFFSET, 19 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_TopRight); + MapGridSetMetatileIdAt(7 + MAP_OFFSET, 20 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_BottomLeft | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(8 + MAP_OFFSET, 20 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_BottomMid); + MapGridSetMetatileIdAt(9 + MAP_OFFSET, 20 + MAP_OFFSET, METATILE_Cave_SealedChamberEntrance_BottomRight | METATILE_COLLISION_MASK); DrawWholeMapView(); PlaySE(SE_BANG); FlagSet(FLAG_SYS_REGISTEEL_PUZZLE_COMPLETED); @@ -332,78 +256,6 @@ void DoBrailleRegisteelEffect(void) // theory: another commented out DoBrailleWait and Task_BrailleWait. void DoBrailleWait(void) { - /* - if (!FlagGet(FLAG_SYS_BRAILLE_REGICE_COMPLETED)) - CreateTask(Task_BrailleWait, 0x50); -} - -void Task_BrailleWait(u8 taskId) -{ - s16 *data = gTasks[taskId].data; - - switch (data[0]) - { - case 0: - data[1] = 7200; - data[0] = 1; - break; - case 1: - if (BrailleWait_CheckButtonPress() != FALSE) - { - MenuZeroFillScreen(); - PlaySE(SE_SELECT); - data[0] = 2; - } - else - { - data[1] = data[1] - 1; - if (data[1] == 0) - { - MenuZeroFillScreen(); - data[0] = 3; - data[1] = 30; - } - } - break; - case 2: - if (BrailleWait_CheckButtonPress() == FALSE) - { - data[1] = data[1] - 1; - if (data[1] == 0) - data[0] = 4; - break; - } - sub_8064E2C(); - DestroyTask(taskId); - ScriptContext2_Disable(); - break; - case 3: - data[1] = data[1] - 1; - if (data[1] == 0) - data[0] = 4; - break; - case 4: - sub_8064E2C(); - ScriptContext1_SetupScript(S_OpenRegiceChamber); - DestroyTask(taskId); - break; - } -} - -bool32 BrailleWait_CheckButtonPress(void) -{ - u16 keyMask = A_BUTTON | B_BUTTON | START_BUTTON | SELECT_BUTTON | DPAD_ANY; - - if (gSaveBlock2.optionsButtonMode == OPTIONS_BUTTON_MODE_LR) - keyMask |= L_BUTTON | R_BUTTON; - if (gSaveBlock2.optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) - keyMask |= L_BUTTON; - - if (gMain.newKeys & keyMask) - return TRUE; - else - return FALSE; - */ } // this used to be FldEff_UseFlyAncientTomb . why did GF merge the 2 functions? diff --git a/src/decoration.c b/src/decoration.c index 131f6e502d..838b5cb66a 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -1481,7 +1481,7 @@ static bool8 IsNonBlockNonElevated(u8 behaviorAt, u16 behaviorBy) static bool8 IsntInitialPosition(u8 taskId, s16 x, s16 y, u16 behaviorBy) { - if (x == gTasks[taskId].tInitialX + 7 && y == gTasks[taskId].tInitialY + 7 && behaviorBy != 0) + if (x == gTasks[taskId].tInitialX + MAP_OFFSET && y == gTasks[taskId].tInitialY + MAP_OFFSET && behaviorBy != 0) return FALSE; return TRUE; } @@ -1532,7 +1532,7 @@ static bool8 CanPlaceDecoration(u8 taskId, const struct Decoration *decoration) return FALSE; behaviorAt = GetObjectEventIdByXYZ(curX, curY, 0); - if (behaviorAt != 0 && behaviorAt != 16) + if (behaviorAt != 0 && behaviorAt != OBJECT_EVENTS_COUNT) return FALSE; } } @@ -1552,7 +1552,7 @@ static bool8 CanPlaceDecoration(u8 taskId, const struct Decoration *decoration) if (!IsntInitialPosition(taskId, curX, curY, behaviorBy)) return FALSE; - if (GetObjectEventIdByXYZ(curX, curY, 0) != 16) + if (GetObjectEventIdByXYZ(curX, curY, 0) != OBJECT_EVENTS_COUNT) return FALSE; } } @@ -1570,7 +1570,7 @@ static bool8 CanPlaceDecoration(u8 taskId, const struct Decoration *decoration) return FALSE; behaviorAt = GetObjectEventIdByXYZ(curX, curY, 0); - if (behaviorAt != 0 && behaviorAt != 16) + if (behaviorAt != 0 && behaviorAt != OBJECT_EVENTS_COUNT) return FALSE; } break; @@ -1606,7 +1606,7 @@ static bool8 CanPlaceDecoration(u8 taskId, const struct Decoration *decoration) return FALSE; } - if (GetObjectEventIdByXYZ(curX, curY, 0) != 16) + if (GetObjectEventIdByXYZ(curX, curY, 0) != OBJECT_EVENTS_COUNT) return FALSE; } break; @@ -1645,8 +1645,8 @@ static void PlaceDecoration(u8 taskId) } else { - sCurDecorMapX = gTasks[taskId].tCursorX - 7; - sCurDecorMapY = gTasks[taskId].tCursorY - 7; + sCurDecorMapX = gTasks[taskId].tCursorX - MAP_OFFSET; + sCurDecorMapY = gTasks[taskId].tCursorY - MAP_OFFSET; ScriptContext1_SetupScript(SecretBase_EventScript_SetDecoration); } @@ -1666,7 +1666,7 @@ static void PlaceDecoration_(u8 taskId) if (sDecorationContext.items[i] == DECOR_NONE) { sDecorationContext.items[i] = gCurDecorationItems[gCurDecorationIndex]; - sDecorationContext.pos[i] = ((gTasks[taskId].tCursorX - 7) << 4) + (gTasks[taskId].tCursorY - 7); + sDecorationContext.pos[i] = ((gTasks[taskId].tCursorX - MAP_OFFSET) << 4) + (gTasks[taskId].tCursorY - MAP_OFFSET); break; } } @@ -2223,7 +2223,7 @@ static void ClearRearrangementNonSprites(void) { for (x = 0; x < sDecorRearrangementDataBuffer[i].width; x++) { - MapGridSetMetatileEntryAt(posX + 7 + x, posY + 7 - y, gMapHeader.mapLayout->map[posX + x + gMapHeader.mapLayout->width * (posY - y)] | 0x3000); + MapGridSetMetatileEntryAt(posX + MAP_OFFSET + x, posY + MAP_OFFSET - y, gMapHeader.mapLayout->map[posX + x + gMapHeader.mapLayout->width * (posY - y)] | 0x3000); } } @@ -2461,12 +2461,12 @@ static bool8 DecorationIsUnderCursor(u8 taskId, u8 idx, struct DecorRearrangemen u8 yOff; u8 ht; - x = gTasks[taskId].tCursorX - 7; - y = gTasks[taskId].tCursorY - 7; + x = gTasks[taskId].tCursorX - MAP_OFFSET; + y = gTasks[taskId].tCursorY - MAP_OFFSET; xOff = sDecorationContext.pos[idx] >> 4; yOff = sDecorationContext.pos[idx] & 0x0F; ht = data->height; - if (sDecorationContext.items[idx] == DECOR_SAND_ORNAMENT && MapGridGetMetatileIdAt(xOff + 7, yOff + 7) == METATILE_SecretBase_SandOrnament_BrokenBase) + if (sDecorationContext.items[idx] == DECOR_SAND_ORNAMENT && MapGridGetMetatileIdAt(xOff + MAP_OFFSET, yOff + MAP_OFFSET) == METATILE_SecretBase_SandOrnament_BrokenBase) ht--; if (x >= xOff && x < xOff + data->width && y > yOff - ht && y <= yOff) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index ba4f384199..2a606f72a7 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1242,8 +1242,8 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, return OBJECT_EVENTS_COUNT; objectEvent = &gObjectEvents[objectEventId]; ClearObjectEvent(objectEvent); - x = template->x + 7; - y = template->y + 7; + x = template->x + MAP_OFFSET; + y = template->y + MAP_OFFSET; objectEvent->active = TRUE; objectEvent->triggerGroundEffectsOnMove = TRUE; objectEvent->graphicsId = template->graphicsId; @@ -1469,8 +1469,8 @@ u8 SpawnSpecialObjectEventParameterized(u8 graphicsId, u8 movementBehavior, u8 l { struct ObjectEventTemplate objectEventTemplate; - x -= 7; - y -= 7; + x -= MAP_OFFSET; + y -= MAP_OFFSET; objectEventTemplate.localId = localId; objectEventTemplate.graphicsId = graphicsId; objectEventTemplate.inConnection = 0; @@ -1560,8 +1560,8 @@ u8 CreateObjectSprite(u8 graphicsId, u8 objectEventId, s16 x, s16 y, u8 z, u8 di graphicsInfo = GetObjectEventGraphicsInfo(graphicsId); MakeObjectTemplateFromObjectEventGraphicsInfo(graphicsId, UpdateObjectEventSprite, &spriteTemplate, &subspriteTables); *(u16 *)&spriteTemplate.paletteTag = TAG_NONE; - x += 7; - y += 7; + x += MAP_OFFSET; + y += MAP_OFFSET; SetSpritePosToOffsetMapCoords(&x, &y, 8, 16); spriteId = CreateSpriteAtEnd(&spriteTemplate, x, y, 0); if (spriteId != MAX_SPRITES) @@ -1606,9 +1606,9 @@ void TrySpawnObjectEvents(s16 cameraX, s16 cameraY) if (gMapHeader.events != NULL) { s16 left = gSaveBlock1Ptr->pos.x - 2; - s16 right = gSaveBlock1Ptr->pos.x + 17; + s16 right = gSaveBlock1Ptr->pos.x + MAP_OFFSET_W + 2; s16 top = gSaveBlock1Ptr->pos.y; - s16 bottom = gSaveBlock1Ptr->pos.y + 16; + s16 bottom = gSaveBlock1Ptr->pos.y + MAP_OFFSET_H + 2; if (InBattlePyramid()) objectCount = GetNumBattlePyramidObjectEvents(); @@ -1620,8 +1620,8 @@ void TrySpawnObjectEvents(s16 cameraX, s16 cameraY) for (i = 0; i < objectCount; i++) { struct ObjectEventTemplate *template = &gSaveBlock1Ptr->objectEventTemplates[i]; - s16 npcX = template->x + 7; - s16 npcY = template->y + 7; + s16 npcX = template->x + MAP_OFFSET; + s16 npcY = template->y + MAP_OFFSET; if (top <= npcY && bottom >= npcY && left <= npcX && right >= npcX && !FlagGet(template->flagId)) @@ -2120,8 +2120,8 @@ void TryMoveObjectEventToMapCoords(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s1 u8 objectEventId; if (!TryGetObjectEventIdByLocalIdAndMap(localId, mapNum, mapGroup, &objectEventId)) { - x += 7; - y += 7; + x += MAP_OFFSET; + y += MAP_OFFSET; MoveObjectEventToMapCoords(&gObjectEvents[objectEventId], x, y); } } @@ -2470,8 +2470,8 @@ void OverrideTemplateCoordsForObjectEvent(const struct ObjectEvent *objectEvent) objectEventTemplate = GetBaseTemplateForObjectEvent(objectEvent); if (objectEventTemplate != NULL) { - objectEventTemplate->x = objectEvent->currentCoords.x - 7; - objectEventTemplate->y = objectEvent->currentCoords.y - 7; + objectEventTemplate->x = objectEvent->currentCoords.x - MAP_OFFSET; + objectEventTemplate->y = objectEvent->currentCoords.y - MAP_OFFSET; } } diff --git a/src/faraway_island.c b/src/faraway_island.c index 51ab8def44..3927d9ad54 100755 --- a/src/faraway_island.c +++ b/src/faraway_island.c @@ -29,10 +29,10 @@ extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[]; static const s16 sFarawayIslandRockCoords[4][2] = { - {14 + 7, 9 + 7}, - {18 + 7, 9 + 7}, - { 9 + 7, 10 + 7}, - {13 + 7, 13 + 7}, + {14 + MAP_OFFSET, 9 + MAP_OFFSET}, + {18 + MAP_OFFSET, 9 + MAP_OFFSET}, + { 9 + MAP_OFFSET, 10 + MAP_OFFSET}, + {13 + MAP_OFFSET, 13 + MAP_OFFSET}, }; static u8 GetMewObjectEventId(void) diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 6ec280fd0d..10f8d49bb1 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -316,7 +316,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 - 7, position->y - 7, position->height); + struct BgEvent *bgEvent = GetBackgroundEventAtPosition(&gMapHeader, position->x - MAP_OFFSET, position->y - MAP_OFFSET, position->height); if (bgEvent == NULL) return NULL; @@ -498,7 +498,7 @@ static bool8 TryStartStepBasedScript(struct MapPosition *position, u16 metatileB static bool8 TryStartCoordEventScript(struct MapPosition *position) { - u8 *script = GetCoordEventScriptAtPosition(&gMapHeader, position->x - 7, position->y - 7, position->height); + u8 *script = GetCoordEventScriptAtPosition(&gMapHeader, position->x - MAP_OFFSET, position->y - MAP_OFFSET, position->height); if (script == NULL) return FALSE; @@ -785,7 +785,7 @@ static bool8 IsArrowWarpMetatileBehavior(u16 metatileBehavior, u8 direction) static s8 GetWarpEventAtMapPosition(struct MapHeader *mapHeader, struct MapPosition *position) { - return GetWarpEventAtPosition(mapHeader, position->x - 7, position->y - 7, position->height); + return GetWarpEventAtPosition(mapHeader, position->x - MAP_OFFSET, position->y - MAP_OFFSET, position->height); } static void SetupWarp(struct MapHeader *unused, s8 warpEventId, struct MapPosition *position) @@ -920,7 +920,7 @@ static u8 *GetCoordEventScriptAtPosition(struct MapHeader *mapHeader, u16 x, u16 u8 *GetCoordEventScriptAtMapPosition(struct MapPosition *position) { - return GetCoordEventScriptAtPosition(&gMapHeader, position->x - 7, position->y - 7, position->height); + return GetCoordEventScriptAtPosition(&gMapHeader, position->x - MAP_OFFSET, position->y - MAP_OFFSET, position->height); } static struct BgEvent *GetBackgroundEventAtPosition(struct MapHeader *mapHeader, u16 x, u16 y, u8 elevation) @@ -944,7 +944,7 @@ bool8 TryDoDiveWarp(struct MapPosition *position, u16 metatileBehavior) { if (gMapHeader.mapType == MAP_TYPE_UNDERWATER && !MetatileBehavior_IsUnableToEmerge(metatileBehavior)) { - if (SetDiveWarpEmerge(position->x - 7, position->y - 7)) + if (SetDiveWarpEmerge(position->x - MAP_OFFSET, position->y - MAP_OFFSET)) { StoreInitialPlayerAvatarState(); DoDiveWarp(); @@ -954,7 +954,7 @@ bool8 TryDoDiveWarp(struct MapPosition *position, u16 metatileBehavior) } else if (MetatileBehavior_IsDiveable(metatileBehavior) == TRUE) { - if (SetDiveWarpDive(position->x - 7, position->y - 7)) + if (SetDiveWarpDive(position->x - MAP_OFFSET, position->y - MAP_OFFSET)) { StoreInitialPlayerAvatarState(); DoDiveWarp(); @@ -974,12 +974,12 @@ u8 TrySetDiveWarp(void) metatileBehavior = MapGridGetMetatileBehaviorAt(x, y); if (gMapHeader.mapType == MAP_TYPE_UNDERWATER && !MetatileBehavior_IsUnableToEmerge(metatileBehavior)) { - if (SetDiveWarpEmerge(x - 7, y - 7) == TRUE) + if (SetDiveWarpEmerge(x - MAP_OFFSET, y - MAP_OFFSET) == TRUE) return 1; } else if (MetatileBehavior_IsDiveable(metatileBehavior) == TRUE) { - if (SetDiveWarpDive(x - 7, y - 7) == TRUE) + if (SetDiveWarpDive(x - MAP_OFFSET, y - MAP_OFFSET) == TRUE) return 2; } return 0; diff --git a/src/field_door.c b/src/field_door.c index 3f2034ea6c..f53e83d7a6 100644 --- a/src/field_door.c +++ b/src/field_door.c @@ -346,14 +346,14 @@ static void DrawDoor(const struct DoorGraphics *gfx, const struct DoorAnimFrame { DrawClosedDoorTiles(gfx, x, y); if (ShouldUseMultiCorridorDoor()) - DrawClosedDoorTiles(gfx, gSpecialVar_0x8004 + 7, gSpecialVar_0x8005 + 7); + DrawClosedDoorTiles(gfx, gSpecialVar_0x8004 + MAP_OFFSET, gSpecialVar_0x8005 + MAP_OFFSET); } else { CopyDoorTilesToVram(gfx, frame); DrawCurrentDoorAnimFrame(gfx, x, y, gfx->palette); if (ShouldUseMultiCorridorDoor()) - DrawCurrentDoorAnimFrame(gfx, gSpecialVar_0x8004 + 7, gSpecialVar_0x8005 + 7, gfx->palette); + DrawCurrentDoorAnimFrame(gfx, gSpecialVar_0x8004 + MAP_OFFSET, gSpecialVar_0x8005 + MAP_OFFSET, gfx->palette); } } diff --git a/src/field_effect.c b/src/field_effect.c index 90d43c8099..88f8065d3f 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -3830,11 +3830,11 @@ bool8 FldEff_MoveDeoxysRock(struct Sprite* sprite) int xPos, yPos; u8 taskId; object = &gObjectEvents[objectEventIdBuffer]; - xPos = object->currentCoords.x - 7; - yPos = object->currentCoords.y - 7; + xPos = object->currentCoords.x - MAP_OFFSET; + yPos = object->currentCoords.y - MAP_OFFSET; xPos = (gFieldEffectArguments[3] - xPos) * 16; yPos = (gFieldEffectArguments[4] - yPos) * 16; - ShiftObjectEventCoords(object, gFieldEffectArguments[3] + 7, gFieldEffectArguments[4] + 7); + ShiftObjectEventCoords(object, gFieldEffectArguments[3] + MAP_OFFSET, gFieldEffectArguments[4] + MAP_OFFSET); taskId = CreateTask(Task_MoveDeoxysRock, 80); gTasks[taskId].data[1] = object->spriteId; gTasks[taskId].data[2] = gSprites[object->spriteId].x + xPos; diff --git a/src/field_effect_helpers.c b/src/field_effect_helpers.c index bcc02efe96..0a0e465a87 100755 --- a/src/field_effect_helpers.c +++ b/src/field_effect_helpers.c @@ -1416,8 +1416,8 @@ u32 FldEff_Sparkle(void) { u8 spriteId; - gFieldEffectArguments[0] += 7; - gFieldEffectArguments[1] += 7; + gFieldEffectArguments[0] += MAP_OFFSET; + gFieldEffectArguments[1] += MAP_OFFSET; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SMALL_SPARKLE], gFieldEffectArguments[0], gFieldEffectArguments[1], 0x52); if (spriteId != MAX_SPRITES) diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index 617dd8ea3e..51e49629c4 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -1368,8 +1368,8 @@ void InitPlayerAvatar(s16 x, s16 y, u8 direction, u8 gender) playerObjEventTemplate.localId = OBJ_EVENT_ID_PLAYER; playerObjEventTemplate.graphicsId = GetPlayerAvatarGraphicsIdByStateIdAndGender(PLAYER_AVATAR_STATE_NORMAL, gender); - playerObjEventTemplate.x = x - 7; - playerObjEventTemplate.y = y - 7; + playerObjEventTemplate.x = x - MAP_OFFSET; + playerObjEventTemplate.y = y - MAP_OFFSET; playerObjEventTemplate.elevation = 0; playerObjEventTemplate.movementType = MOVEMENT_TYPE_PLAYER; playerObjEventTemplate.movementRangeX = 0; diff --git a/src/field_special_scene.c b/src/field_special_scene.c index cb2d0e9016..39e5d66980 100644 --- a/src/field_special_scene.c +++ b/src/field_special_scene.c @@ -215,9 +215,9 @@ void Task_HandleTruckSequence(u8 taskId) data[1]++; if (data[1] == 120) { - MapGridSetMetatileIdAt(11, 8, METATILE_InsideOfTruck_ExitLight_Top); - MapGridSetMetatileIdAt(11, 9, METATILE_InsideOfTruck_ExitLight_Mid); - MapGridSetMetatileIdAt(11, 10, METATILE_InsideOfTruck_ExitLight_Bottom); + MapGridSetMetatileIdAt(4 + MAP_OFFSET, 1 + MAP_OFFSET, METATILE_InsideOfTruck_ExitLight_Top); + MapGridSetMetatileIdAt(4 + MAP_OFFSET, 2 + MAP_OFFSET, METATILE_InsideOfTruck_ExitLight_Mid); + MapGridSetMetatileIdAt(4 + MAP_OFFSET, 3 + MAP_OFFSET, METATILE_InsideOfTruck_ExitLight_Bottom); DrawWholeMapView(); PlaySE(SE_TRUCK_DOOR); DestroyTask(taskId); @@ -229,9 +229,9 @@ void Task_HandleTruckSequence(u8 taskId) void ExecuteTruckSequence(void) { - MapGridSetMetatileIdAt(11, 8, METATILE_InsideOfTruck_DoorClosedFloor_Top); - MapGridSetMetatileIdAt(11, 9, METATILE_InsideOfTruck_DoorClosedFloor_Mid); - MapGridSetMetatileIdAt(11, 10, METATILE_InsideOfTruck_DoorClosedFloor_Bottom); + MapGridSetMetatileIdAt(4 + MAP_OFFSET, 1 + MAP_OFFSET, METATILE_InsideOfTruck_DoorClosedFloor_Top); + MapGridSetMetatileIdAt(4 + MAP_OFFSET, 2 + MAP_OFFSET, METATILE_InsideOfTruck_DoorClosedFloor_Mid); + MapGridSetMetatileIdAt(4 + MAP_OFFSET, 3 + MAP_OFFSET, METATILE_InsideOfTruck_DoorClosedFloor_Bottom); DrawWholeMapView(); ScriptContext2_Enable(); CpuFastFill(0, gPlttBufferFaded, 0x400); diff --git a/src/field_specials.c b/src/field_specials.c index e19f02c09e..c3bd629466 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -586,7 +586,7 @@ void SpawnLinkPartnerObjectEvent(void) linkSpriteId = OBJ_EVENT_GFX_RIVAL_MAY_NORMAL; break; } - SpawnSpecialObjectEventParameterized(linkSpriteId, movementTypes[j], 240 - i, coordOffsets[j][0] + x + 7, coordOffsets[j][1] + y + 7, 0); + SpawnSpecialObjectEventParameterized(linkSpriteId, movementTypes[j], 240 - i, coordOffsets[j][0] + x + MAP_OFFSET, coordOffsets[j][1] + y + MAP_OFFSET, 0); LoadLinkPartnerObjectEventSpritePalette(linkSpriteId, 240 - i, i); j++; if (j == MAX_LINK_PLAYERS) @@ -633,13 +633,12 @@ static void LoadLinkPartnerObjectEventSpritePalette(u8 graphicsId, u8 localEvent } } -// NOTE: Coordinates are +7, +7 from actual in-map coordinates static const struct UCoords8 sMauvilleGymSwitchCoords[] = { - { 7, 22}, - {11, 19}, - {10, 16}, - {15, 16} + { 0 + MAP_OFFSET, 15 + MAP_OFFSET}, + { 4 + MAP_OFFSET, 12 + MAP_OFFSET}, + { 3 + MAP_OFFSET, 9 + MAP_OFFSET}, + { 8 + MAP_OFFSET, 9 + MAP_OFFSET} }; // Presses the stepped-on switch and raises the rest @@ -659,10 +658,10 @@ void MauvilleGymPressSwitch(void) void MauvilleGymSetDefaultBarriers(void) { int x, y; - // All switches/barriers are within these coord ranges -7 - for (y = 12; y < 24; y++) + // All switches/barriers are within these coord ranges + for (y = 5 + MAP_OFFSET; y < 17 + MAP_OFFSET; y++) { - for (x = 7; x < 16; x++) + for (x = 0 + MAP_OFFSET; x < 9 + MAP_OFFSET; x++) { switch (MapGridGetMetatileIdAt(x, y)) { @@ -759,9 +758,9 @@ void MauvilleGymDeactivatePuzzle(void) MapGridSetMetatileIdAt(switchCoords->x, switchCoords->y, METATILE_MauvilleGym_PressedSwitch); switchCoords++; } - for (y = 12; y < 24; y++) + for (y = 5 + MAP_OFFSET; y < 17 + MAP_OFFSET; y++) { - for (x = 7; x < 16; x++) + for (x = 0 + MAP_OFFSET; x < 9 + MAP_OFFSET; x++) { switch (MapGridGetMetatileIdAt(x, y)) { @@ -902,8 +901,8 @@ static void PetalburgGymSetDoorMetatiles(u8 roomNumber, u16 metatileId) } for (i = 0; i < nDoors; i++) { - MapGridSetMetatileIdAt(doorCoordsX[i] + 7, doorCoordsY[i] + 7, metatileId | METATILE_COLLISION_MASK); - MapGridSetMetatileIdAt(doorCoordsX[i] + 7, doorCoordsY[i] + 8, (metatileId + 8) | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(doorCoordsX[i] + MAP_OFFSET, doorCoordsY[i] + MAP_OFFSET, metatileId | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(doorCoordsX[i] + MAP_OFFSET, doorCoordsY[i] + MAP_OFFSET + 1, (metatileId + 8) | METATILE_COLLISION_MASK); } DrawWholeMapView(); } @@ -1115,7 +1114,7 @@ static void PCTurnOnEffect_1(s16 isPcTurnedOn, s8 dx, s8 dy) tileId = METATILE_BrendansMaysHouse_MayPC_On; } } - MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + dx + 7, gSaveBlock1Ptr->pos.y + dy + 7, tileId | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + dx + MAP_OFFSET, gSaveBlock1Ptr->pos.y + dy + MAP_OFFSET, tileId | METATILE_COLLISION_MASK); } void DoPCTurnOffEffect(void) @@ -1156,7 +1155,7 @@ static void PCTurnOffEffect(void) { tileId = METATILE_BrendansMaysHouse_MayPC_Off; } - MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + dx + 7, gSaveBlock1Ptr->pos.y + dy + 7, tileId | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + dx + MAP_OFFSET, gSaveBlock1Ptr->pos.y + dy + MAP_OFFSET, tileId | METATILE_COLLISION_MASK); DrawWholeMapView(); } @@ -1189,13 +1188,13 @@ static void LotteryCornerComputerEffect(struct Task *task) task->data[3] = 0; if (task->data[4] != 0) { - MapGridSetMetatileIdAt(18, 8, METATILE_Shop_Laptop1_Normal | METATILE_COLLISION_MASK); - MapGridSetMetatileIdAt(18, 9, METATILE_Shop_Laptop2_Normal | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(11 + MAP_OFFSET, 1 + MAP_OFFSET, METATILE_Shop_Laptop1_Normal | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(11 + MAP_OFFSET, 2 + MAP_OFFSET, METATILE_Shop_Laptop2_Normal | METATILE_COLLISION_MASK); } else { - MapGridSetMetatileIdAt(18, 8, METATILE_Shop_Laptop1_Flash | METATILE_COLLISION_MASK); - MapGridSetMetatileIdAt(18, 9, METATILE_Shop_Laptop2_Flash | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(11 + MAP_OFFSET, 1 + MAP_OFFSET, METATILE_Shop_Laptop1_Flash | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(11 + MAP_OFFSET, 2 + MAP_OFFSET, METATILE_Shop_Laptop2_Flash | METATILE_COLLISION_MASK); } DrawWholeMapView(); task->data[4] ^= 1; @@ -1209,8 +1208,8 @@ static void LotteryCornerComputerEffect(struct Task *task) void EndLotteryCornerComputerEffect(void) { - MapGridSetMetatileIdAt(18, 8, METATILE_Shop_Laptop1_Normal | METATILE_COLLISION_MASK); - MapGridSetMetatileIdAt(18, 9, METATILE_Shop_Laptop2_Normal | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(11 + MAP_OFFSET, 1 + MAP_OFFSET, METATILE_Shop_Laptop1_Normal | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(11 + MAP_OFFSET, 2 + MAP_OFFSET, METATILE_Shop_Laptop2_Normal | METATILE_COLLISION_MASK); DrawWholeMapView(); } @@ -1298,7 +1297,12 @@ void IsGrassTypeInParty(void) void SpawnCameraObject(void) { - u8 obj = SpawnSpecialObjectEventParameterized(OBJ_EVENT_GFX_BOY_1, MOVEMENT_TYPE_FACE_DOWN, OBJ_EVENT_ID_CAMERA, gSaveBlock1Ptr->pos.x + 7, gSaveBlock1Ptr->pos.y + 7, 3); + u8 obj = SpawnSpecialObjectEventParameterized(OBJ_EVENT_GFX_BOY_1, + MOVEMENT_TYPE_FACE_DOWN, + OBJ_EVENT_ID_CAMERA, + gSaveBlock1Ptr->pos.x + MAP_OFFSET, + gSaveBlock1Ptr->pos.y + MAP_OFFSET, + 3); gObjectEvents[obj].invisible = TRUE; CameraObjectSetFollowedSpriteId(gObjectEvents[obj].spriteId); } @@ -1949,23 +1953,15 @@ static void Task_MoveElevatorWindowLights(u8 taskId) if (data[2] == FALSE) { for (y = 0; y < 3; y++) - { for (x = 0; x < 3; x++) - { - MapGridSetMetatileIdAt(x + 8, y + 7, sElevatorWindowTiles_Ascending[y][data[0] % 3] | METATILE_COLLISION_MASK); - } - } + MapGridSetMetatileIdAt(x + MAP_OFFSET + 1, y + MAP_OFFSET, sElevatorWindowTiles_Ascending[y][data[0] % 3] | METATILE_COLLISION_MASK); } // descending else { for (y = 0; y < 3; y++) - { for (x = 0; x < 3; x++) - { - MapGridSetMetatileIdAt(x + 8, y + 7, sElevatorWindowTiles_Descending[y][data[0] % 3] | METATILE_COLLISION_MASK); - } - } + MapGridSetMetatileIdAt(x + MAP_OFFSET + 1, y + MAP_OFFSET, sElevatorWindowTiles_Descending[y][data[0] % 3] | METATILE_COLLISION_MASK); } DrawWholeMapView(); data[1] = 0; diff --git a/src/field_tasks.c b/src/field_tasks.c index 676a9cfc7b..187270f7a8 100644 --- a/src/field_tasks.c +++ b/src/field_tasks.c @@ -529,7 +529,7 @@ void SetSootopolisGymCrackedIceMetatiles(void) for (y = 0; y < height; y++) { if (IsIcePuzzleCoordVisited(x, y) == TRUE) - MapGridSetMetatileIdAt(x + 7, y + 7, METATILE_SootopolisGym_Ice_Cracked); + MapGridSetMetatileIdAt(x + MAP_OFFSET, y + MAP_OFFSET, METATILE_SootopolisGym_Ice_Cracked); } } } @@ -586,7 +586,7 @@ static void SootopolisGymIcePerStepCallback(u8 taskId) PlaySE(SE_ICE_CRACK); MapGridSetMetatileIdAt(x, y, METATILE_SootopolisGym_Ice_Cracked); CurrentMapDrawMetatileAt(x, y); - MarkIcePuzzleCoordVisited(x - 7, y - 7); + MarkIcePuzzleCoordVisited(x - MAP_OFFSET, y - MAP_OFFSET); data[1] = 1; } break; @@ -689,7 +689,7 @@ static void SetMuddySlopeMetatile(s16 *data, s16 x, s16 y) { u16 tile; if ((--data[0]) == 0) - tile = 0xe8; + tile = METATILE_General_MuddySlope_Frame0; else tile = sMuddySlopeMetatiles[data[0] / 8]; diff --git a/src/field_weather_effect.c b/src/field_weather_effect.c index 7321587339..27ade478f0 100644 --- a/src/field_weather_effect.c +++ b/src/field_weather_effect.c @@ -1,6 +1,7 @@ #include "global.h" #include "battle_anim.h" #include "event_object_movement.h" +#include "fieldmap.h" #include "field_weather.h" #include "overworld.h" #include "random.h" @@ -189,7 +190,7 @@ static void CreateCloudSprites(void) { gWeatherPtr->sprites.s1.cloudSprites[i] = &gSprites[spriteId]; sprite = gWeatherPtr->sprites.s1.cloudSprites[i]; - SetSpritePosToMapCoords(sCloudSpriteMapCoords[i].x + 7, sCloudSpriteMapCoords[i].y + 7, &sprite->x, &sprite->y); + SetSpritePosToMapCoords(sCloudSpriteMapCoords[i].x + MAP_OFFSET, sCloudSpriteMapCoords[i].y + MAP_OFFSET, &sprite->x, &sprite->y); sprite->coordOffsetEnabled = TRUE; } else diff --git a/src/fieldmap.c b/src/fieldmap.c index e437ea7fc2..aff72c4c68 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -105,9 +105,9 @@ static void InitMapLayoutData(struct MapHeader *mapHeader) mapLayout = mapHeader->mapLayout; CpuFastFill16(METATILE_ID_UNDEFINED, gBackupMapData, sizeof(gBackupMapData)); gBackupMapLayout.map = gBackupMapData; - width = mapLayout->width + 15; + width = mapLayout->width + MAP_OFFSET_W; gBackupMapLayout.width = width; - height = mapLayout->height + 14; + height = mapLayout->height + MAP_OFFSET_H; gBackupMapLayout.height = height; if (width * height <= MAX_MAP_DATA_SIZE) { @@ -121,11 +121,11 @@ static void InitBackupMapLayoutData(u16 *map, u16 width, u16 height) u16 *dest; int y; dest = gBackupMapLayout.map; - dest += gBackupMapLayout.width * 7 + 7; + dest += gBackupMapLayout.width * 7 + MAP_OFFSET; for (y = 0; y < height; y++) { CpuCopy16(map, dest, width * 2); - dest += width + 15; + dest += width + MAP_OFFSET_W; map += width; } } @@ -197,8 +197,8 @@ static void FillSouthConnection(struct MapHeader const *mapHeader, struct MapHea if (connectedMapHeader) { cWidth = connectedMapHeader->mapLayout->width; - x = offset + 7; - y = mapHeader->mapLayout->height + 7; + x = offset + MAP_OFFSET; + y = mapHeader->mapLayout->height + MAP_OFFSET; if (x < 0) { x2 = -x; @@ -222,7 +222,7 @@ static void FillSouthConnection(struct MapHeader const *mapHeader, struct MapHea x, y, connectedMapHeader, x2, /*y2*/ 0, - width, /*height*/ 7); + width, /*height*/ MAP_OFFSET); } } @@ -237,8 +237,8 @@ static void FillNorthConnection(struct MapHeader const *mapHeader, struct MapHea { cWidth = connectedMapHeader->mapLayout->width; cHeight = connectedMapHeader->mapLayout->height; - x = offset + 7; - y2 = cHeight - 7; + x = offset + MAP_OFFSET; + y2 = cHeight - MAP_OFFSET; if (x < 0) { x2 = -x; @@ -262,7 +262,7 @@ static void FillNorthConnection(struct MapHeader const *mapHeader, struct MapHea x, /*y*/ 0, connectedMapHeader, x2, y2, - width, /*height*/ 7); + width, /*height*/ MAP_OFFSET); } } @@ -277,8 +277,8 @@ static void FillWestConnection(struct MapHeader const *mapHeader, struct MapHead { cWidth = connectedMapHeader->mapLayout->width; cHeight = connectedMapHeader->mapLayout->height; - y = offset + 7; - x2 = cWidth - 7; + y = offset + MAP_OFFSET; + x2 = cWidth - MAP_OFFSET; if (y < 0) { y2 = -y; @@ -301,7 +301,7 @@ static void FillWestConnection(struct MapHeader const *mapHeader, struct MapHead /*x*/ 0, y, connectedMapHeader, x2, y2, - /*width*/ 7, height); + /*width*/ MAP_OFFSET, height); } } @@ -314,8 +314,8 @@ static void FillEastConnection(struct MapHeader const *mapHeader, struct MapHead if (connectedMapHeader) { cHeight = connectedMapHeader->mapLayout->height; - x = mapHeader->mapLayout->width + 7; - y = offset + 7; + x = mapHeader->mapLayout->width + MAP_OFFSET; + y = offset + MAP_OFFSET; if (y < 0) { y2 = -y; @@ -338,7 +338,7 @@ static void FillEastConnection(struct MapHeader const *mapHeader, struct MapHead x, y, connectedMapHeader, /*x2*/ 0, y2, - /*width*/ 8, height); + /*width*/ MAP_OFFSET + 1, height); } } @@ -433,9 +433,9 @@ void SaveMapView(void) width = gBackupMapLayout.width; x = gSaveBlock1Ptr->pos.x; y = gSaveBlock1Ptr->pos.y; - for (i = y; i < y + 14; i++) + for (i = y; i < y + MAP_OFFSET_H; i++) { - for (j = x; j < x + 15; j++) + for (j = x; j < x + MAP_OFFSET_W; j++) *mapView++ = gBackupMapData[width * i + j]; } } @@ -480,28 +480,28 @@ static void LoadSavedMapView(void) width = gBackupMapLayout.width; x = gSaveBlock1Ptr->pos.x; y = gSaveBlock1Ptr->pos.y; - for (i = y; i < y + 14; i++) + for (i = y; i < y + MAP_OFFSET_H; i++) { if (i == y && i != 0) yMode = 0; - else if (i == y + 13 && i != gMapHeader.mapLayout->height - 1) + else if (i == y + MAP_OFFSET_H - 1 && i != gMapHeader.mapLayout->height - 1) yMode = 1; else yMode = 0xFF; - for (j = x; j < x + 15; j++) + for (j = x; j < x + MAP_OFFSET_W; j++) { if (!SkipCopyingMetatileFromSavedMap(&gBackupMapData[j + width * i], width, yMode)) gBackupMapData[j + width * i] = *mapView; mapView++; } } - for (j = x; j < x + 15; j++) + for (j = x; j < x + MAP_OFFSET_W; j++) { if (y != 0) FixLongGrassMetatilesWindowTop(j, y - 1); if (i < gMapHeader.mapLayout->height - 1) - FixLongGrassMetatilesWindowBottom(j, y + 13); + FixLongGrassMetatilesWindowBottom(j, y + MAP_OFFSET_H - 1); } ClearSavedMapView(); } @@ -524,25 +524,25 @@ static void MoveMapViewToBackup(u8 direction) r8 = 0; x0 = gSaveBlock1Ptr->pos.x; y0 = gSaveBlock1Ptr->pos.y; - x2 = 15; - y2 = 14; + x2 = MAP_OFFSET_W; + y2 = MAP_OFFSET_H; switch (direction) { case CONNECTION_NORTH: y0 += 1; - y2 = 13; + y2 = MAP_OFFSET_H - 1; break; case CONNECTION_SOUTH: r8 = 1; - y2 = 13; + y2 = MAP_OFFSET_H - 1; break; case CONNECTION_WEST: x0 += 1; - x2 = 14; + x2 = MAP_OFFSET_W - 1; break; case CONNECTION_EAST: r9 = 1; - x2 = 14; + x2 = MAP_OFFSET_W - 1; break; } for (y = 0; y < y2; y++) @@ -552,7 +552,7 @@ static void MoveMapViewToBackup(u8 direction) for (x = 0; x < x2; x++) { desti = width * (y + y0); - srci = (y + r8) * 15 + r9; + srci = (y + r8) * MAP_OFFSET_W + r9; src = &mapView[srci + i]; dest = &gBackupMapData[x0 + desti + j]; *dest = *src; @@ -568,28 +568,28 @@ int GetMapBorderIdAt(int x, int y) if (MapGridGetTileAt(x, y) == METATILE_ID_UNDEFINED) return CONNECTION_INVALID; - if (x >= (gBackupMapLayout.width - 8)) + if (x >= (gBackupMapLayout.width - (MAP_OFFSET + 1))) { if (!gMapConnectionFlags.east) return CONNECTION_INVALID; return CONNECTION_EAST; } - else if (x < 7) + else if (x < MAP_OFFSET) { if (!gMapConnectionFlags.west) return CONNECTION_INVALID; return CONNECTION_WEST; } - else if (y >= (gBackupMapLayout.height - 7)) + else if (y >= (gBackupMapLayout.height - MAP_OFFSET)) { if (!gMapConnectionFlags.south) return CONNECTION_INVALID; return CONNECTION_SOUTH; } - else if (y < 7) + else if (y < MAP_OFFSET) { if (!gMapConnectionFlags.north) return CONNECTION_INVALID; @@ -604,14 +604,14 @@ int GetMapBorderIdAt(int x, int y) int GetPostCameraMoveMapBorderId(int x, int y) { - return GetMapBorderIdAt(gSaveBlock1Ptr->pos.x + 7 + x, gSaveBlock1Ptr->pos.y + 7 + y); + return GetMapBorderIdAt(gSaveBlock1Ptr->pos.x + MAP_OFFSET + x, gSaveBlock1Ptr->pos.y + MAP_OFFSET + y); } bool32 CanCameraMoveInDirection(int direction) { int x, y; - x = gSaveBlock1Ptr->pos.x + 7 + gDirectionToVectors[direction].x; - y = gSaveBlock1Ptr->pos.y + 7 + gDirectionToVectors[direction].y; + x = gSaveBlock1Ptr->pos.x + MAP_OFFSET + gDirectionToVectors[direction].x; + y = gSaveBlock1Ptr->pos.y + MAP_OFFSET + gDirectionToVectors[direction].y; if (GetMapBorderIdAt(x, y) == CONNECTION_INVALID) return FALSE; @@ -771,14 +771,14 @@ struct MapConnection *GetConnectionAtCoords(s16 x, s16 y) { direction = connection->direction; if ((direction == CONNECTION_DIVE || direction == CONNECTION_EMERGE) - || (direction == CONNECTION_NORTH && y > 6) - || (direction == CONNECTION_SOUTH && y < gMapHeader.mapLayout->height + 7) - || (direction == CONNECTION_WEST && x > 6) - || (direction == CONNECTION_EAST && x < gMapHeader.mapLayout->width + 7)) + || (direction == CONNECTION_NORTH && y > MAP_OFFSET - 1) + || (direction == CONNECTION_SOUTH && y < gMapHeader.mapLayout->height + MAP_OFFSET) + || (direction == CONNECTION_WEST && x > MAP_OFFSET - 1) + || (direction == CONNECTION_EAST && x < gMapHeader.mapLayout->width + MAP_OFFSET)) { continue; } - if (IsPosInConnectingMap(connection, x - 7, y - 7) == TRUE) + if (IsPosInConnectingMap(connection, x - MAP_OFFSET, y - MAP_OFFSET) == TRUE) { return connection; } @@ -789,14 +789,14 @@ struct MapConnection *GetConnectionAtCoords(s16 x, s16 y) void SetCameraFocusCoords(u16 x, u16 y) { - gSaveBlock1Ptr->pos.x = x - 7; - gSaveBlock1Ptr->pos.y = y - 7; + gSaveBlock1Ptr->pos.x = x - MAP_OFFSET; + gSaveBlock1Ptr->pos.y = y - MAP_OFFSET; } void GetCameraFocusCoords(u16 *x, u16 *y) { - *x = gSaveBlock1Ptr->pos.x + 7; - *y = gSaveBlock1Ptr->pos.y + 7; + *x = gSaveBlock1Ptr->pos.x + MAP_OFFSET; + *y = gSaveBlock1Ptr->pos.y + MAP_OFFSET; } // Unused diff --git a/src/item_use.c b/src/item_use.c index c350d9d0b8..0a31816083 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -353,12 +353,14 @@ static bool8 ItemfinderCheckForHiddenItems(const struct MapEvents *events, u8 ta // Check if there are any hidden items on the current map that haven't been picked up if (events->bgEvents[i].kind == BG_EVENT_HIDDEN_ITEM && !FlagGet(events->bgEvents[i].bgUnion.hiddenItem.hiddenItemId + FLAG_HIDDEN_ITEMS_START)) { - itemX = (u16)events->bgEvents[i].x + 7; + itemX = (u16)events->bgEvents[i].x + MAP_OFFSET; distanceX = itemX - playerX; - itemY = (u16)events->bgEvents[i].y + 7; + itemY = (u16)events->bgEvents[i].y + MAP_OFFSET; distanceY = itemY - playerY; - if ((u16)(distanceX + 7) < 15 && (distanceY >= -5) && (distanceY < 6)) + // Player can see 7 metatiles on either side horizontally + // and 5 metatiles on either side vertically + if (distanceX >= -7 && distanceX <= 7 && distanceY >= -5 && distanceY <= 5) SetDistanceOfClosestHiddenItem(taskId, distanceX, distanceY); } } @@ -402,27 +404,27 @@ static bool8 IsHiddenItemPresentInConnection(struct MapConnection *connection, i { // same weird temp variable behavior seen in IsHiddenItemPresentAtCoords case 2: - localOffset = connection->offset + 7; + localOffset = connection->offset + MAP_OFFSET; localX = x - localOffset; - localLength = mapHeader->mapLayout->height - 7; + localLength = mapHeader->mapLayout->height - MAP_OFFSET; localY = localLength + y; // additions are reversed for some reason break; case 1: - localOffset = connection->offset + 7; + localOffset = connection->offset + MAP_OFFSET; localX = x - localOffset; - localLength = gMapHeader.mapLayout->height + 7; + localLength = gMapHeader.mapLayout->height + MAP_OFFSET; localY = y - localLength; break; case 3: - localLength = mapHeader->mapLayout->width - 7; + localLength = mapHeader->mapLayout->width - MAP_OFFSET; localX = localLength + x; // additions are reversed for some reason - localOffset = connection->offset + 7; + localOffset = connection->offset + MAP_OFFSET; localY = y - localOffset; break; case 4: - localLength = gMapHeader.mapLayout->width + 7; + localLength = gMapHeader.mapLayout->width + MAP_OFFSET; localX = x - localLength; - localOffset = connection->offset + 7; + localOffset = connection->offset + MAP_OFFSET; localY = y - localOffset; break; default: @@ -435,14 +437,16 @@ static void CheckForHiddenItemsInMapConnection(u8 taskId) { s16 playerX, playerY; s16 x, y; - s16 width = gMapHeader.mapLayout->width + 7; - s16 height = gMapHeader.mapLayout->height + 7; + s16 width = gMapHeader.mapLayout->width + MAP_OFFSET; + s16 height = gMapHeader.mapLayout->height + MAP_OFFSET; - s16 var1 = 7; - s16 var2 = 7; + s16 var1 = MAP_OFFSET; + s16 var2 = MAP_OFFSET; PlayerGetDestCoords(&playerX, &playerY); + // Player can see 7 metatiles on either side horizontally + // and 5 metatiles on either side vertically for (x = playerX - 7; x <= playerX + 7; x++) { for (y = playerY - 5; y <= playerY + 5; y++) diff --git a/src/mirage_tower.c b/src/mirage_tower.c index 65aae72552..7fc883ca18 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -479,7 +479,9 @@ static void SetInvisibleMirageTowerMetatiles(void) { u8 i; for (i = 0; i < ARRAY_COUNT(sInvisibleMirageTowerMetatiles); i++) - MapGridSetMetatileIdAt(sInvisibleMirageTowerMetatiles[i].x + 7, sInvisibleMirageTowerMetatiles[i].y + 7, sInvisibleMirageTowerMetatiles[i].metatileId); + MapGridSetMetatileIdAt(sInvisibleMirageTowerMetatiles[i].x + MAP_OFFSET, + sInvisibleMirageTowerMetatiles[i].y + MAP_OFFSET, + sInvisibleMirageTowerMetatiles[i].metatileId); DrawWholeMapView(); } diff --git a/src/overworld.c b/src/overworld.c index cfe8489cef..71cfeaac9c 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -683,7 +683,7 @@ void UpdateEscapeWarp(s16 x, s16 y) u8 currMapType = GetCurrentMapType(); u8 destMapType = GetMapTypeByGroupAndId(sWarpDestination.mapGroup, sWarpDestination.mapNum); if (IsMapTypeOutdoors(currMapType) && IsMapTypeOutdoors(destMapType) != TRUE) - SetEscapeWarp(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x - 7, y - 6); + SetEscapeWarp(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x - MAP_OFFSET, y - MAP_OFFSET + 1); } void SetEscapeWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) @@ -957,7 +957,7 @@ static u8 GetAdjustedInitialDirection(struct InitialPlayerAvatarState *playerStr static u16 GetCenterScreenMetatileBehavior(void) { - return MapGridGetMetatileBehaviorAt(gSaveBlock1Ptr->pos.x + 7, gSaveBlock1Ptr->pos.y + 7); + return MapGridGetMetatileBehaviorAt(gSaveBlock1Ptr->pos.x + MAP_OFFSET, gSaveBlock1Ptr->pos.y + MAP_OFFSET); } bool32 Overworld_IsBikingAllowed(void) diff --git a/src/rotating_gate.c b/src/rotating_gate.c index 997404c271..ea2eec1261 100644 --- a/src/rotating_gate.c +++ b/src/rotating_gate.c @@ -711,14 +711,14 @@ static void RotatingGate_CreateGatesWithinViewport(s16 deltaX, s16 deltaY) // Calculate the bounding box of the camera // Same as RotatingGate_DestroyGatesOutsideViewport s16 x = gSaveBlock1Ptr->pos.x - 2; - s16 x2 = gSaveBlock1Ptr->pos.x + 0x11; + s16 x2 = gSaveBlock1Ptr->pos.x + MAP_OFFSET_W + 2; s16 y = gSaveBlock1Ptr->pos.y - 2; - s16 y2 = gSaveBlock1Ptr->pos.y + 0xe; + s16 y2 = gSaveBlock1Ptr->pos.y + MAP_OFFSET_H; for (i = 0; i < gRotatingGate_PuzzleCount; i++) { - s16 x3 = gRotatingGate_PuzzleConfig[i].x + 7; - s16 y3 = gRotatingGate_PuzzleConfig[i].y + 7; + s16 x3 = gRotatingGate_PuzzleConfig[i].x + MAP_OFFSET; + s16 y3 = gRotatingGate_PuzzleConfig[i].y + MAP_OFFSET; if (y <= y3 && y2 >= y3 && x <= x3 && x2 >= x3 && gRotatingGate_GateSpriteIds[i] == MAX_SPRITES) @@ -748,8 +748,8 @@ static u8 RotatingGate_CreateGate(u8 gateId, s16 deltaX, s16 deltaY) if (spriteId == MAX_SPRITES) return MAX_SPRITES; - x = gate->x + 7; - y = gate->y + 7; + x = gate->x + MAP_OFFSET; + y = gate->y + MAP_OFFSET; sprite = &gSprites[spriteId]; sprite->data[0] = gateId; @@ -803,15 +803,15 @@ static void RotatingGate_HideGatesOutsideViewport(struct Sprite *sprite) x = sprite->x + sprite->x2 + sprite->centerToCornerVecX + gSpriteCoordOffsetX; y = sprite->y + sprite->y2 + sprite->centerToCornerVecY + gSpriteCoordOffsetY; - x2 = x + 0x40; // Dimensions of the rotating gate - y2 = y + 0x40; + x2 = x + 64; // Dimensions of the rotating gate + y2 = y + 64; - if ((s16)x > DISPLAY_WIDTH + 0x10 - 1 || x2 < -0x10) + if ((s16)x > DISPLAY_WIDTH + 16 - 1 || x2 < -16) { sprite->invisible = TRUE; } - if ((s16)y > DISPLAY_HEIGHT + 0x10 - 1 || y2 < -0x10) + if ((s16)y > DISPLAY_HEIGHT + 16 - 1 || y2 < -16) { sprite->invisible = TRUE; } @@ -828,14 +828,14 @@ static void RotatingGate_DestroyGatesOutsideViewport(void) // Same as RotatingGate_CreateGatesWithinViewport s16 x = gSaveBlock1Ptr->pos.x - 2; - s16 x2 = gSaveBlock1Ptr->pos.x + 0x11; + s16 x2 = gSaveBlock1Ptr->pos.x + MAP_OFFSET_W + 2; s16 y = gSaveBlock1Ptr->pos.y - 2; - s16 y2 = gSaveBlock1Ptr->pos.y + 0xe; + s16 y2 = gSaveBlock1Ptr->pos.y + MAP_OFFSET_H; for (i = 0; i < gRotatingGate_PuzzleCount; i++) { - s16 xGate = gRotatingGate_PuzzleConfig[i].x + 7; - s16 yGate = gRotatingGate_PuzzleConfig[i].y + 7; + s16 xGate = gRotatingGate_PuzzleConfig[i].x + MAP_OFFSET; + s16 yGate = gRotatingGate_PuzzleConfig[i].y + MAP_OFFSET; if (gRotatingGate_GateSpriteIds[i] == MAX_SPRITES) continue; @@ -868,8 +868,8 @@ static s32 RotatingGate_CanRotate(u8 gateId, s32 rotationDirection) orientation = RotatingGate_GetGateOrientation(gateId); shape = gRotatingGate_PuzzleConfig[gateId].shape; - x = gRotatingGate_PuzzleConfig[gateId].x + 7; - y = gRotatingGate_PuzzleConfig[gateId].y + 7; + x = gRotatingGate_PuzzleConfig[gateId].x + MAP_OFFSET; + y = gRotatingGate_PuzzleConfig[gateId].y + MAP_OFFSET; // Loop through the gate's "arms" clockwise (north, south, east, west) for (i = GATE_ARM_NORTH; i <= GATE_ARM_WEST; i++) @@ -964,8 +964,8 @@ bool8 CheckForRotatingGatePuzzleCollision(u8 direction, s16 x, s16 y) return FALSE; for (i = 0; i < gRotatingGate_PuzzleCount; i++) { - s16 gateX = gRotatingGate_PuzzleConfig[i].x + 7; - s16 gateY = gRotatingGate_PuzzleConfig[i].y + 7; + s16 gateX = gRotatingGate_PuzzleConfig[i].x + MAP_OFFSET; + s16 gateY = gRotatingGate_PuzzleConfig[i].y + MAP_OFFSET; if (gateX - 2 <= x && x <= gateX + 1 && gateY - 2 <= y && y <= gateY + 1) { @@ -1002,8 +1002,8 @@ bool8 CheckForRotatingGatePuzzleCollisionWithoutAnimation(u8 direction, s16 x, s return FALSE; for (i = 0; i < gRotatingGate_PuzzleCount; i++) { - s16 gateX = gRotatingGate_PuzzleConfig[i].x + 7; - s16 gateY = gRotatingGate_PuzzleConfig[i].y + 7; + s16 gateX = gRotatingGate_PuzzleConfig[i].x + MAP_OFFSET; + s16 gateY = gRotatingGate_PuzzleConfig[i].y + MAP_OFFSET; if (gateX - 2 <= x && x <= gateX + 1 && gateY - 2 <= y && y <= gateY + 1) { diff --git a/src/rotating_tile_puzzle.c b/src/rotating_tile_puzzle.c index a3bee41808..56be9736f5 100644 --- a/src/rotating_tile_puzzle.c +++ b/src/rotating_tile_puzzle.c @@ -119,8 +119,8 @@ u16 MoveRotatingTileObjects(u8 puzzleNumber) { s32 puzzleTileStart; u8 puzzleTileNum; - s16 x = objectEvents[i].x + 7; - s16 y = objectEvents[i].y + 7; + s16 x = objectEvents[i].x + MAP_OFFSET; + s16 y = objectEvents[i].y + MAP_OFFSET; u16 metatile = MapGridGetMetatileIdAt(x, y); if (!sRotatingTilePuzzle->isTrickHouse) @@ -211,8 +211,8 @@ void TurnRotatingTileObjects(void) s32 rotation; s8 tileDifference; u8 objectEventId; - s16 x = objectEvents[sRotatingTilePuzzle->objects[i].eventTemplateId].x + 7; - s16 y = objectEvents[sRotatingTilePuzzle->objects[i].eventTemplateId].y + 7; + s16 x = objectEvents[sRotatingTilePuzzle->objects[i].eventTemplateId].x + MAP_OFFSET; + s16 y = objectEvents[sRotatingTilePuzzle->objects[i].eventTemplateId].y + MAP_OFFSET; u16 metatile = MapGridGetMetatileIdAt(x, y); // NOTE: The following 2 assignments and if else could all be replaced with rotation = ROTATE_COUNTERCLOCKWISE @@ -322,8 +322,8 @@ static void TurnUnsavedRotatingTileObject(u8 eventTemplateId, u8 puzzleTileNum) s32 puzzleTileStart; u16 movementType; struct ObjectEventTemplate *objectEvents = gSaveBlock1Ptr->objectEventTemplates; - s16 x = objectEvents[eventTemplateId].x + 7; - s16 y = objectEvents[eventTemplateId].y + 7; + s16 x = objectEvents[eventTemplateId].x + MAP_OFFSET; + s16 y = objectEvents[eventTemplateId].y + MAP_OFFSET; u16 metatile = MapGridGetMetatileIdAt(x, y); if (!sRotatingTilePuzzle->isTrickHouse) diff --git a/src/scrcmd.c b/src/scrcmd.c index dfda7b3a2d..de0ec7c263 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -791,9 +791,9 @@ bool8 ScrCmd_warphole(struct ScriptContext *ctx) PlayerGetDestCoords(&x, &y); if (mapGroup == 0xFF && mapNum == 0xFF) - SetWarpDestinationToFixedHoleWarp(x - 7, y - 7); + SetWarpDestinationToFixedHoleWarp(x - MAP_OFFSET, y - MAP_OFFSET); else - SetWarpDestination(mapGroup, mapNum, -1, x - 7, y - 7); + SetWarpDestination(mapGroup, mapNum, -1, x - MAP_OFFSET, y - MAP_OFFSET); DoFallWarp(); ResetInitialPlayerAvatarState(); return TRUE; @@ -2043,8 +2043,8 @@ bool8 ScrCmd_setmetatile(struct ScriptContext *ctx) u16 tileId = VarGet(ScriptReadHalfword(ctx)); u16 isImpassable = VarGet(ScriptReadHalfword(ctx)); - x += 7; - y += 7; + x += MAP_OFFSET; + y += MAP_OFFSET; if (!isImpassable) MapGridSetMetatileIdAt(x, y, tileId); else @@ -2057,8 +2057,8 @@ bool8 ScrCmd_opendoor(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - x += 7; - y += 7; + x += MAP_OFFSET; + y += MAP_OFFSET; PlaySE(GetDoorSoundEffect(x, y)); FieldAnimateDoorOpen(x, y); return FALSE; @@ -2069,8 +2069,8 @@ bool8 ScrCmd_closedoor(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - x += 7; - y += 7; + x += MAP_OFFSET; + y += MAP_OFFSET; FieldAnimateDoorClose(x, y); return FALSE; } @@ -2094,8 +2094,8 @@ bool8 ScrCmd_setdooropen(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - x += 7; - y += 7; + x += MAP_OFFSET; + y += MAP_OFFSET; FieldSetDoorOpened(x, y); return FALSE; } @@ -2105,8 +2105,8 @@ bool8 ScrCmd_setdoorclosed(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - x += 7; - y += 7; + x += MAP_OFFSET; + y += MAP_OFFSET; FieldSetDoorClosed(x, y); return FALSE; } diff --git a/src/secret_base.c b/src/secret_base.c index 0a1472e311..e728f34884 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -390,8 +390,8 @@ void SetOccupiedSecretBaseEntranceMetatiles(struct MapEvents const *events) { if (gSaveBlock1Ptr->secretBases[j].secretBaseId == events->bgEvents[bgId].bgUnion.secretBaseId) { - s16 x = events->bgEvents[bgId].x + 7; - s16 y = events->bgEvents[bgId].y + 7; + s16 x = events->bgEvents[bgId].x + MAP_OFFSET; + s16 y = events->bgEvents[bgId].y + MAP_OFFSET; s16 tile_id = MapGridGetMetatileIdAt(x, y); for (i = 0; i < ARRAY_COUNT(sSecretBaseEntranceMetatiles); i++) { @@ -474,8 +474,8 @@ static void EnterNewlyCreatedSecretBase_StartFadeIn(void) ScriptContext2_Enable(); HideMapNamePopUpWindow(); FindMetatileIdMapCoords(&x, &y, METATILE_SecretBase_PC); - x += 7; - y += 7; + x += MAP_OFFSET; + y += MAP_OFFSET; MapGridSetMetatileIdAt(x, y, METATILE_SecretBase_PC | METATILE_COLLISION_MASK); CurrentMapDrawMetatileAt(x, y); FadeInFromBlack(); @@ -530,20 +530,20 @@ void InitSecretBaseAppearance(bool8 hidePC) for (x = 0; x < DECOR_MAX_SECRET_BASE; x++) { if (decorations[x] > 0 && decorations[x] <= NUM_DECORATIONS && gDecorations[decorations[x]].permission != DECORPERM_SPRITE) - ShowDecorationOnMap((decorPos[x] >> 4) + 7, (decorPos[x] & 0xF) + 7, decorations[x]); + ShowDecorationOnMap((decorPos[x] >> 4) + MAP_OFFSET, (decorPos[x] & 0xF) + MAP_OFFSET, decorations[x]); } if (secretBaseIdx != 0) { // Another player's secret base. Change PC type to the "Register" PC. FindMetatileIdMapCoords(&x, &y, METATILE_SecretBase_PC); - MapGridSetMetatileIdAt(x + 7, y + 7, METATILE_SecretBase_RegisterPC | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(x + MAP_OFFSET, y + MAP_OFFSET, METATILE_SecretBase_RegisterPC | METATILE_COLLISION_MASK); } else if (hidePC == TRUE && VarGet(VAR_SECRET_BASE_INITIALIZED) == 1) { // Change PC to regular ground tile. FindMetatileIdMapCoords(&x, &y, METATILE_SecretBase_PC); - MapGridSetMetatileIdAt(x + 7, y + 7, METATILE_SecretBase_Ground | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(x + MAP_OFFSET, y + MAP_OFFSET, METATILE_SecretBase_Ground | METATILE_COLLISION_MASK); } } } @@ -594,7 +594,7 @@ void InitSecretBaseDecorationSprites(void) gSpecialVar_0x8006 = decorationPositions[i] >> 4; gSpecialVar_0x8007 = decorationPositions[i] & 0xF; - metatileBehavior = MapGridGetMetatileBehaviorAt(gSpecialVar_0x8006 + 7, gSpecialVar_0x8007 + 7); + metatileBehavior = MapGridGetMetatileBehaviorAt(gSpecialVar_0x8006 + MAP_OFFSET, gSpecialVar_0x8007 + MAP_OFFSET); if (MetatileBehavior_HoldsSmallDecoration(metatileBehavior) == TRUE || MetatileBehavior_HoldsLargeDecoration(metatileBehavior) == TRUE) { @@ -660,7 +660,9 @@ void SetCurSecretBaseIdFromPosition(const struct MapPosition *position, const st s16 i; for (i = 0; i < events->bgEventCount; i++) { - if (events->bgEvents[i].kind == BG_EVENT_SECRET_BASE && position->x == events->bgEvents[i].x + 7 && position->y == events->bgEvents[i].y + 7) + if (events->bgEvents[i].kind == BG_EVENT_SECRET_BASE + && position->x == events->bgEvents[i].x + MAP_OFFSET + && position->y == events->bgEvents[i].y + MAP_OFFSET) { sCurSecretBaseId = events->bgEvents[i].bgUnion.secretBaseId; break; @@ -830,12 +832,14 @@ static void ClosePlayerSecretBaseEntrance(void) if (events->bgEvents[i].kind == BG_EVENT_SECRET_BASE && gSaveBlock1Ptr->secretBases[0].secretBaseId == events->bgEvents[i].bgUnion.secretBaseId) { - metatileId = MapGridGetMetatileIdAt(events->bgEvents[i].x + 7, events->bgEvents[i].y + 7); + metatileId = MapGridGetMetatileIdAt(events->bgEvents[i].x + MAP_OFFSET, events->bgEvents[i].y + MAP_OFFSET); for (j = 0; j < ARRAY_COUNT(sSecretBaseEntranceMetatiles); j++) { if (sSecretBaseEntranceMetatiles[j].openMetatileId == metatileId) { - MapGridSetMetatileIdAt(events->bgEvents[i].x + 7, events->bgEvents[i].y + 7, sSecretBaseEntranceMetatiles[j].closedMetatileId | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(events->bgEvents[i].x + MAP_OFFSET, + events->bgEvents[i].y + MAP_OFFSET, + sSecretBaseEntranceMetatiles[j].closedMetatileId | METATILE_COLLISION_MASK); break; } } diff --git a/src/union_room.c b/src/union_room.c index 03f7fc02b5..fb1604879b 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -11,6 +11,7 @@ #include "easy_chat.h" #include "event_data.h" #include "event_object_lock.h" +#include "fieldmap.h" #include "field_control_avatar.h" #include "field_player_avatar.h" #include "field_screen_effect.h" @@ -3989,10 +3990,10 @@ static bool32 IsPlayerFacingTradingBoard(void) s16 x, y; GetXYCoordsOneStepInFrontOfPlayer(&x, &y); - if (x != 2 + 7) + if (x != 2 + MAP_OFFSET) return FALSE; - if (y != 1 + 7) + if (y != 1 + MAP_OFFSET) return FALSE; if (gPlayerAvatar.tileTransitionState == T_TILE_CENTER || gPlayerAvatar.tileTransitionState == T_NOT_MOVING) diff --git a/src/union_room_player_avatar.c b/src/union_room_player_avatar.c index ff6c90b255..77eee6e4aa 100644 --- a/src/union_room_player_avatar.c +++ b/src/union_room_player_avatar.c @@ -125,14 +125,14 @@ static u8 GetUnionRoomPlayerGraphicsId(u32 gender, u32 id) static void GetUnionRoomPlayerFacingCoords(u32 playerIdx, u32 direction, s32 * x, s32 * y) { - *x = sUnionRoomPlayerCoords[playerIdx][0] + sFacingDirectionOffsets[direction][0] + 7; - *y = sUnionRoomPlayerCoords[playerIdx][1] + sFacingDirectionOffsets[direction][1] + 7; + *x = sUnionRoomPlayerCoords[playerIdx][0] + sFacingDirectionOffsets[direction][0] + MAP_OFFSET; + *y = sUnionRoomPlayerCoords[playerIdx][1] + sFacingDirectionOffsets[direction][1] + MAP_OFFSET; } static bool32 IsUnionRoomPlayerFacingTileAt(u32 playerIdx, u32 direction, s32 x, s32 y) { - if ((sUnionRoomPlayerCoords[playerIdx][0] + sFacingDirectionOffsets[direction][0] + 7 == x) - && (sUnionRoomPlayerCoords[playerIdx][1] + sFacingDirectionOffsets[direction][1] + 7 == y)) + if ((sUnionRoomPlayerCoords[playerIdx][0] + sFacingDirectionOffsets[direction][0] + MAP_OFFSET == x) + && (sUnionRoomPlayerCoords[playerIdx][1] + sFacingDirectionOffsets[direction][1] + MAP_OFFSET == y)) return TRUE; else return FALSE; diff --git a/src/wild_encounter.c b/src/wild_encounter.c index 8bcb176055..32316c1195 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -70,7 +70,7 @@ static u16 GetRoute119WaterTileNum(s16 x, s16 y, u8 section) { for (xCur = 0; xCur < gMapHeader.mapLayout->width; xCur++) { - u8 tileBehaviorId = MapGridGetMetatileBehaviorAt(xCur + 7, yCur + 7); + u8 tileBehaviorId = MapGridGetMetatileBehaviorAt(xCur + MAP_OFFSET, yCur + MAP_OFFSET); if (MetatileBehavior_IsSurfableAndNotWaterfall(tileBehaviorId) == TRUE) { tileNum++; @@ -95,8 +95,8 @@ static bool8 CheckFeebas(void) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE119)) { GetXYCoordsOneStepInFrontOfPlayer(&x, &y); - x -= 7; - y -= 7; + x -= MAP_OFFSET; + y -= MAP_OFFSET; if (y >= gRoute119WaterTileData[3 * 0 + 0] && y <= gRoute119WaterTileData[3 * 0 + 1]) route119Section = 0;