mirror of
https://github.com/pret/pokefirered.git
synced 2026-05-27 10:43:05 -05:00
Merge pull request #467 from GriffinRichards/sync-fieldmap
Sync fieldmap.c
This commit is contained in:
commit
6eaeceb3ef
|
|
@ -25,24 +25,22 @@ void GetCameraCoords(u16*, u16*);
|
|||
bool8 MapGridIsImpassableAt(s32, s32);
|
||||
s32 GetMapBorderIdAt(s32, s32);
|
||||
bool32 CanCameraMoveInDirection(s32);
|
||||
u32 GetBehaviorByMetatileIdAndMapLayout(const struct MapLayout *mapLayout, u16 metatile, u8 attr);
|
||||
const struct MapHeader * mapconnection_get_mapheader(struct MapConnection * connection);
|
||||
const struct MapHeader * GetMapHeaderFromConnection(struct MapConnection * connection);
|
||||
struct MapConnection * GetMapConnectionAtPos(s16 x, s16 y);
|
||||
void Fieldmap_ApplyGlobalTintToPaletteSlot(u8 slot, u8 count);
|
||||
|
||||
void save_serialize_map(void);
|
||||
u32 GetMetatileAttributeFromRawMetatileBehavior(u32 original, u8 bit);
|
||||
u32 MapGridGetMetatileAttributeAt(s16 x, s16 y, u8 attr);
|
||||
void SaveMapView(void);
|
||||
u32 ExtractMetatileAttribute(u32 attributes, u8 attributeType);
|
||||
u32 MapGridGetMetatileAttributeAt(s16 x, s16 y, u8 attributeType);
|
||||
void MapGridSetMetatileImpassabilityAt(s32 x, s32 y, bool32 arg2);
|
||||
bool8 CameraMove(s32 x, s32 y);
|
||||
void copy_map_tileset1_tileset2_to_vram(struct MapLayout const * mapLayout);
|
||||
void apply_map_tileset1_tileset2_palette(struct MapLayout const * mapLayout);
|
||||
void CopyMapTilesetsToVram(struct MapLayout const * mapLayout);
|
||||
void LoadMapTilesetPalettes(struct MapLayout const * mapLayout);
|
||||
void InitMap(void);
|
||||
void copy_map_tileset2_to_vram_2(const struct MapLayout * mapLayout);
|
||||
void apply_map_tileset2_palette(const struct MapLayout * mapLayout);
|
||||
void CopySecondaryTilesetToVramUsingHeap(const struct MapLayout * mapLayout);
|
||||
void LoadSecondaryTilesetPalette(const struct MapLayout * mapLayout);
|
||||
void InitMapFromSavedGame(void);
|
||||
void copy_map_tileset1_to_vram(const struct MapLayout *mapLayout);
|
||||
void copy_map_tileset2_to_vram(const struct MapLayout *mapLayout);
|
||||
void CopyPrimaryTilesetToVram(const struct MapLayout *mapLayout);
|
||||
void CopySecondaryTilesetToVram(const struct MapLayout *mapLayout);
|
||||
void GetCameraFocusCoords(u16 *x, u16 *y);
|
||||
void SetCameraFocusCoords(u16 x, u16 y);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#define OBJECT_EVENTS_COUNT 16
|
||||
|
||||
#define METATILE_BEHAVIOR_MASK 0x00FF
|
||||
#define METATILE_COLLISION_MASK 0x0C00
|
||||
#define METATILE_ID_MASK 0x03FF
|
||||
#define METATILE_ID_UNDEFINED 0x03FF
|
||||
|
|
@ -42,7 +43,9 @@ enum
|
|||
|
||||
enum
|
||||
{
|
||||
CONNECTION_SOUTH = 1,
|
||||
CONNECTION_INVALID = -1,
|
||||
CONNECTION_NONE,
|
||||
CONNECTION_SOUTH,
|
||||
CONNECTION_NORTH,
|
||||
CONNECTION_WEST,
|
||||
CONNECTION_EAST,
|
||||
|
|
|
|||
|
|
@ -4883,7 +4883,7 @@ u8 GetCollisionAtCoords(struct ObjectEvent *objectEvent, s16 x, s16 y, u32 dir)
|
|||
u8 direction = dir;
|
||||
if (IsCoordOutsideObjectEventMovementRange(objectEvent, x, y))
|
||||
return COLLISION_OUTSIDE_RANGE;
|
||||
else if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(objectEvent, x, y, direction))
|
||||
else if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == CONNECTION_INVALID || IsMetatileDirectionallyImpassable(objectEvent, x, y, direction))
|
||||
return COLLISION_IMPASSABLE;
|
||||
else if (objectEvent->trackedByCamera && !CanCameraMoveInDirection(direction))
|
||||
return COLLISION_IMPASSABLE;
|
||||
|
|
@ -4900,7 +4900,7 @@ u8 GetCollisionFlagsAtCoords(struct ObjectEvent *objectEvent, s16 x, s16 y, u8 d
|
|||
|
||||
if (IsCoordOutsideObjectEventMovementRange(objectEvent, x, y))
|
||||
flags |= 1;
|
||||
if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(objectEvent, x, y, direction) || (objectEvent->trackedByCamera && !CanCameraMoveInDirection(direction)))
|
||||
if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == CONNECTION_INVALID || IsMetatileDirectionallyImpassable(objectEvent, x, y, direction) || (objectEvent->trackedByCamera && !CanCameraMoveInDirection(direction)))
|
||||
flags |= 2;
|
||||
if (IsZCoordMismatchAt(objectEvent->currentElevation, x, y))
|
||||
flags |= 4;
|
||||
|
|
|
|||
538
src/fieldmap.c
538
src/fieldmap.c
|
|
@ -14,17 +14,40 @@ struct ConnectionFlags
|
|||
u8 east:1;
|
||||
};
|
||||
|
||||
static void InitMapLayoutData(struct MapHeader *mapHeader);
|
||||
static void map_copy_with_padding(u16 *map, u16 width, u16 height);
|
||||
static void mapheader_copy_mapdata_of_adjacent_maps(struct MapHeader *mapHeader);
|
||||
static void fillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset);
|
||||
static void fillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset);
|
||||
static void fillWestConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset);
|
||||
static void fillEastConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset);
|
||||
static void InitMapLayoutData(struct MapHeader *);
|
||||
static void InitBackupMapLayoutData(u16 *, u16, u16);
|
||||
static void InitBackupMapLayoutConnections(struct MapHeader *);
|
||||
static void FillSouthConnection(struct MapHeader const *, struct MapHeader const *, s32);
|
||||
static void FillNorthConnection(struct MapHeader const *, struct MapHeader const *, s32);
|
||||
static void FillWestConnection(struct MapHeader const *, struct MapHeader const *, s32);
|
||||
static void FillEastConnection(struct MapHeader const *, struct MapHeader const *, s32);
|
||||
static void LoadSavedMapView(void);
|
||||
static struct MapConnection *sub_8059600(u8 direction, s32 x, s32 y);
|
||||
static bool8 sub_8059658(u8 direction, s32 x, s32 y, struct MapConnection *connection);
|
||||
static bool8 sub_80596BC(s32 x, s32 src_width, s32 dest_width, s32 offset);
|
||||
static struct MapConnection *GetIncomingConnection(u8, s32, s32);
|
||||
static bool8 IsPosInIncomingConnectingMap(u8, s32, s32, struct MapConnection *);
|
||||
static bool8 IsCoordInIncomingConnectingMap(s32, s32, s32, s32);
|
||||
static u32 GetAttributeByMetatileIdAndMapLayout(const struct MapLayout *, u16, u8);
|
||||
|
||||
#define MapGridGetBorderTileAt(x, y) ({ \
|
||||
u16 block; \
|
||||
s32 xprime; \
|
||||
s32 yprime; \
|
||||
\
|
||||
const struct MapLayout *mapLayout = gMapHeader.mapLayout; \
|
||||
\
|
||||
xprime = x - 7; \
|
||||
xprime += 8 * mapLayout->borderWidth; \
|
||||
xprime %= mapLayout->borderWidth; \
|
||||
\
|
||||
yprime = y - 7; \
|
||||
yprime += 8 * mapLayout->borderHeight; \
|
||||
yprime %= mapLayout->borderHeight; \
|
||||
\
|
||||
block = mapLayout->border[xprime + yprime * mapLayout->borderWidth] | METATILE_COLLISION_MASK; \
|
||||
})
|
||||
|
||||
#define AreCoordsWithinMapGridBounds(x, y) (x >= 0 && x < VMap.Xsize && y >= 0 && y < VMap.Ysize)
|
||||
|
||||
#define MapGridGetTileAt(x, y) (AreCoordsWithinMapGridBounds(x, y) ? VMap.map[x + VMap.Xsize * y] : MapGridGetBorderTileAt(x, y))
|
||||
|
||||
struct BackupMapLayout VMap;
|
||||
EWRAM_DATA u16 gBackupMapData[VIRTUAL_MAP_SIZE] = {};
|
||||
|
|
@ -57,7 +80,7 @@ static const u8 sMetatileAttrShifts[METATILE_ATTRIBUTE_COUNT] = {
|
|||
[METATILE_ATTRIBUTE_7] = 31
|
||||
};
|
||||
|
||||
const struct MapHeader * mapconnection_get_mapheader(struct MapConnection * connection)
|
||||
const struct MapHeader * GetMapHeaderFromConnection(struct MapConnection * connection)
|
||||
{
|
||||
return Overworld_GetMapHeaderByGroupAndId(connection->mapGroup, connection->mapNum);
|
||||
}
|
||||
|
|
@ -78,16 +101,16 @@ void InitMapFromSavedGame(void)
|
|||
static void InitMapLayoutData(struct MapHeader * mapHeader)
|
||||
{
|
||||
const struct MapLayout * mapLayout = mapHeader->mapLayout;
|
||||
CpuFastFill(0x03FF03FF, gBackupMapData, sizeof(gBackupMapData));
|
||||
CpuFastFill(METATILE_ID_UNDEFINED << 16 | METATILE_ID_UNDEFINED, gBackupMapData, sizeof(gBackupMapData));
|
||||
VMap.map = gBackupMapData;
|
||||
VMap.Xsize = mapLayout->width + 15;
|
||||
VMap.Ysize = mapLayout->height + 14;
|
||||
AGB_ASSERT_EX(VMap.Xsize * VMap.Ysize <= VIRTUAL_MAP_SIZE, ABSPATH("fieldmap.c"), 158);
|
||||
map_copy_with_padding(mapLayout->map, mapLayout->width, mapLayout->height);
|
||||
mapheader_copy_mapdata_of_adjacent_maps(mapHeader);
|
||||
InitBackupMapLayoutData(mapLayout->map, mapLayout->width, mapLayout->height);
|
||||
InitBackupMapLayoutConnections(mapHeader);
|
||||
}
|
||||
|
||||
static void map_copy_with_padding(u16 *map, u16 width, u16 height)
|
||||
static void InitBackupMapLayoutData(u16 *map, u16 width, u16 height)
|
||||
{
|
||||
s32 y;
|
||||
u16 *dest = VMap.map;
|
||||
|
|
@ -101,7 +124,7 @@ static void map_copy_with_padding(u16 *map, u16 width, u16 height)
|
|||
}
|
||||
}
|
||||
|
||||
static void mapheader_copy_mapdata_of_adjacent_maps(struct MapHeader *mapHeader)
|
||||
static void InitBackupMapLayoutConnections(struct MapHeader *mapHeader)
|
||||
{
|
||||
s32 count;
|
||||
struct MapConnection *connection;
|
||||
|
|
@ -118,36 +141,34 @@ static void mapheader_copy_mapdata_of_adjacent_maps(struct MapHeader *mapHeader)
|
|||
{
|
||||
count = mapHeader->connections->count;
|
||||
connection = mapHeader->connections->connections;
|
||||
// Emerald puts this line here instead:
|
||||
// gMapConnectionFlags = sDummyConnectionFlags;
|
||||
for (i = 0; i < count; i++, connection++)
|
||||
{
|
||||
struct MapHeader const *cMap = mapconnection_get_mapheader(connection);
|
||||
struct MapHeader const *cMap = GetMapHeaderFromConnection(connection);
|
||||
u32 offset = connection->offset;
|
||||
switch (connection->direction)
|
||||
{
|
||||
case CONNECTION_SOUTH:
|
||||
fillSouthConnection(mapHeader, cMap, offset);
|
||||
gMapConnectionFlags.south = 1;
|
||||
break;
|
||||
case CONNECTION_NORTH:
|
||||
fillNorthConnection(mapHeader, cMap, offset);
|
||||
gMapConnectionFlags.north = 1;
|
||||
break;
|
||||
case CONNECTION_WEST:
|
||||
fillWestConnection(mapHeader, cMap, offset);
|
||||
gMapConnectionFlags.west = 1;
|
||||
break;
|
||||
case CONNECTION_EAST:
|
||||
fillEastConnection(mapHeader, cMap, offset);
|
||||
gMapConnectionFlags.east = 1;
|
||||
break;
|
||||
case CONNECTION_SOUTH:
|
||||
FillSouthConnection(mapHeader, cMap, offset);
|
||||
gMapConnectionFlags.south = TRUE;
|
||||
break;
|
||||
case CONNECTION_NORTH:
|
||||
FillNorthConnection(mapHeader, cMap, offset);
|
||||
gMapConnectionFlags.north = TRUE;
|
||||
break;
|
||||
case CONNECTION_WEST:
|
||||
FillWestConnection(mapHeader, cMap, offset);
|
||||
gMapConnectionFlags.west = TRUE;
|
||||
break;
|
||||
case CONNECTION_EAST:
|
||||
FillEastConnection(mapHeader, cMap, offset);
|
||||
gMapConnectionFlags.east = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void sub_8058B54(s32 x, s32 y, const struct MapHeader *connectedMapHeader, s32 x2, s32 y2, s32 width, s32 height)
|
||||
static void FillConnection(s32 x, s32 y, const struct MapHeader *connectedMapHeader, s32 x2, s32 y2, s32 width, s32 height)
|
||||
{
|
||||
s32 i;
|
||||
u16 *src;
|
||||
|
|
@ -166,7 +187,7 @@ static void sub_8058B54(s32 x, s32 y, const struct MapHeader *connectedMapHeader
|
|||
}
|
||||
}
|
||||
|
||||
static void fillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset)
|
||||
static void FillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset)
|
||||
{
|
||||
s32 x, y;
|
||||
s32 x2;
|
||||
|
|
@ -183,29 +204,21 @@ static void fillSouthConnection(struct MapHeader const *mapHeader, struct MapHea
|
|||
x2 = -x;
|
||||
x += cWidth;
|
||||
if (x < VMap.Xsize)
|
||||
{
|
||||
width = x;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = VMap.Xsize;
|
||||
}
|
||||
x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
x2 = 0;
|
||||
if (x + cWidth < VMap.Xsize)
|
||||
{
|
||||
width = cWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = VMap.Xsize - x;
|
||||
}
|
||||
}
|
||||
|
||||
sub_8058B54(
|
||||
FillConnection(
|
||||
x, y,
|
||||
connectedMapHeader,
|
||||
x2, /*y2*/ 0,
|
||||
|
|
@ -213,7 +226,7 @@ static void fillSouthConnection(struct MapHeader const *mapHeader, struct MapHea
|
|||
}
|
||||
}
|
||||
|
||||
static void fillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset)
|
||||
static void FillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset)
|
||||
{
|
||||
s32 x;
|
||||
s32 x2, y2;
|
||||
|
|
@ -231,29 +244,21 @@ static void fillNorthConnection(struct MapHeader const *mapHeader, struct MapHea
|
|||
x2 = -x;
|
||||
x += cWidth;
|
||||
if (x < VMap.Xsize)
|
||||
{
|
||||
width = x;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = VMap.Xsize;
|
||||
}
|
||||
x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
x2 = 0;
|
||||
if (x + cWidth < VMap.Xsize)
|
||||
{
|
||||
width = cWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = VMap.Xsize - x;
|
||||
}
|
||||
}
|
||||
|
||||
sub_8058B54(
|
||||
FillConnection(
|
||||
x, /*y*/ 0,
|
||||
connectedMapHeader,
|
||||
x2, y2,
|
||||
|
|
@ -262,7 +267,7 @@ static void fillNorthConnection(struct MapHeader const *mapHeader, struct MapHea
|
|||
}
|
||||
}
|
||||
|
||||
static void fillWestConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset)
|
||||
static void FillWestConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset)
|
||||
{
|
||||
s32 y;
|
||||
s32 x2, y2;
|
||||
|
|
@ -278,29 +283,21 @@ static void fillWestConnection(struct MapHeader const *mapHeader, struct MapHead
|
|||
{
|
||||
y2 = -y;
|
||||
if (y + cHeight < VMap.Ysize)
|
||||
{
|
||||
height = y + cHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
height = VMap.Ysize;
|
||||
}
|
||||
y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
y2 = 0;
|
||||
if (y + cHeight < VMap.Ysize)
|
||||
{
|
||||
height = cHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
height = VMap.Ysize - y;
|
||||
}
|
||||
}
|
||||
|
||||
sub_8058B54(
|
||||
FillConnection(
|
||||
/*x*/ 0, y,
|
||||
connectedMapHeader,
|
||||
x2, y2,
|
||||
|
|
@ -308,7 +305,7 @@ static void fillWestConnection(struct MapHeader const *mapHeader, struct MapHead
|
|||
}
|
||||
}
|
||||
|
||||
static void fillEastConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset)
|
||||
static void FillEastConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset)
|
||||
{
|
||||
s32 x, y;
|
||||
s32 y2;
|
||||
|
|
@ -323,29 +320,21 @@ static void fillEastConnection(struct MapHeader const *mapHeader, struct MapHead
|
|||
{
|
||||
y2 = -y;
|
||||
if (y + cHeight < VMap.Ysize)
|
||||
{
|
||||
height = y + cHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
height = VMap.Ysize;
|
||||
}
|
||||
y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
y2 = 0;
|
||||
if (y + cHeight < VMap.Ysize)
|
||||
{
|
||||
height = cHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
height = VMap.Ysize - y;
|
||||
}
|
||||
}
|
||||
|
||||
sub_8058B54(
|
||||
FillConnection(
|
||||
x, y,
|
||||
connectedMapHeader,
|
||||
/*x2*/ 0, y2,
|
||||
|
|
@ -353,87 +342,48 @@ static void fillEastConnection(struct MapHeader const *mapHeader, struct MapHead
|
|||
}
|
||||
}
|
||||
|
||||
union Block
|
||||
{
|
||||
struct
|
||||
{
|
||||
u16 block:10;
|
||||
u16 collision:2;
|
||||
u16 elevation:4;
|
||||
} block;
|
||||
u16 value;
|
||||
};
|
||||
|
||||
#define MapGridGetBorderTileAt(x, y) ({ \
|
||||
u16 block; \
|
||||
s32 xprime; \
|
||||
s32 yprime; \
|
||||
\
|
||||
const struct MapLayout *mapLayout = gMapHeader.mapLayout; \
|
||||
\
|
||||
xprime = x - 7; \
|
||||
xprime += 8 * mapLayout->borderWidth; \
|
||||
xprime %= mapLayout->borderWidth; \
|
||||
\
|
||||
yprime = y - 7; \
|
||||
yprime += 8 * mapLayout->borderHeight; \
|
||||
yprime %= mapLayout->borderHeight; \
|
||||
\
|
||||
block = mapLayout->border[xprime + yprime * mapLayout->borderWidth] | METATILE_COLLISION_MASK; \
|
||||
})
|
||||
|
||||
#define AreCoordsWithinMapGridBounds(x, y) (x >= 0 && x < VMap.Xsize && y >= 0 && y < VMap.Ysize)
|
||||
|
||||
#define MapGridGetTileAt(x, y) (AreCoordsWithinMapGridBounds(x, y) ? VMap.map[x + VMap.Xsize * y] : MapGridGetBorderTileAt(x, y))
|
||||
|
||||
u8 MapGridGetZCoordAt(s32 x, s32 y)
|
||||
{
|
||||
u16 block = MapGridGetTileAt(x, y);
|
||||
|
||||
if (block == 0x3ff)
|
||||
{
|
||||
if (block == METATILE_ID_UNDEFINED)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return block >> 12;
|
||||
return block >> METATILE_ELEVATION_SHIFT;
|
||||
}
|
||||
|
||||
u8 MapGridIsImpassableAt(s32 x, s32 y)
|
||||
{
|
||||
|
||||
u16 block = MapGridGetTileAt(x, y);
|
||||
|
||||
if (block == 0x3ff)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (block == METATILE_ID_UNDEFINED)
|
||||
return TRUE;
|
||||
|
||||
return (block & 0xc00) >> 10;
|
||||
return (block & METATILE_COLLISION_MASK) >> METATILE_COLLISION_SHIFT;
|
||||
}
|
||||
|
||||
u32 MapGridGetMetatileIdAt(s32 x, s32 y)
|
||||
{
|
||||
u16 block = MapGridGetTileAt(x, y);
|
||||
|
||||
if (block == 0x3FF)
|
||||
{
|
||||
return MapGridGetBorderTileAt(x, y) & 0x3FF;
|
||||
}
|
||||
return block & 0x3FF;
|
||||
if (block == METATILE_ID_UNDEFINED)
|
||||
return MapGridGetBorderTileAt(x, y) & METATILE_ID_MASK;
|
||||
|
||||
return block & METATILE_ID_MASK;
|
||||
}
|
||||
|
||||
u32 GetMetatileAttributeFromRawMetatileBehavior(u32 original, u8 bit)
|
||||
u32 ExtractMetatileAttribute(u32 attributes, u8 attributeType)
|
||||
{
|
||||
if (bit >= METATILE_ATTRIBUTE_COUNT)
|
||||
return original;
|
||||
if (attributeType >= METATILE_ATTRIBUTE_COUNT)
|
||||
return attributes;
|
||||
|
||||
return (original & sMetatileAttrMasks[bit]) >> sMetatileAttrShifts[bit];
|
||||
return (attributes & sMetatileAttrMasks[attributeType]) >> sMetatileAttrShifts[attributeType];
|
||||
}
|
||||
|
||||
u32 MapGridGetMetatileAttributeAt(s16 x, s16 y, u8 attr)
|
||||
u32 MapGridGetMetatileAttributeAt(s16 x, s16 y, u8 attributeType)
|
||||
{
|
||||
u16 metatileId = MapGridGetMetatileIdAt(x, y);
|
||||
return GetBehaviorByMetatileIdAndMapLayout(gMapHeader.mapLayout, metatileId, attr);
|
||||
return GetAttributeByMetatileIdAndMapLayout(gMapHeader.mapLayout, metatileId, attributeType);
|
||||
}
|
||||
|
||||
u32 MapGridGetMetatileBehaviorAt(s16 x, s16 y)
|
||||
|
|
@ -449,54 +399,47 @@ u8 MapGridGetMetatileLayerTypeAt(s16 x, s16 y)
|
|||
void MapGridSetMetatileIdAt(s32 x, s32 y, u16 metatile)
|
||||
{
|
||||
s32 i;
|
||||
if (x >= 0 && x < VMap.Xsize
|
||||
&& y >= 0 && y < VMap.Ysize)
|
||||
if (AreCoordsWithinMapGridBounds(x, y))
|
||||
{
|
||||
i = x + y * VMap.Xsize;
|
||||
VMap.map[i] = (VMap.map[i] & 0xf000) | (metatile & 0xfff);
|
||||
VMap.map[i] = (VMap.map[i] & METATILE_ELEVATION_MASK) | (metatile & ~METATILE_ELEVATION_MASK);
|
||||
}
|
||||
}
|
||||
|
||||
void MapGridSetMetatileEntryAt(s32 x, s32 y, u16 metatile)
|
||||
{
|
||||
s32 i;
|
||||
if (x >= 0 && x < VMap.Xsize
|
||||
&& y >= 0 && y < VMap.Ysize)
|
||||
if (AreCoordsWithinMapGridBounds(x, y))
|
||||
{
|
||||
i = x + VMap.Xsize * y;
|
||||
VMap.map[i] = metatile;
|
||||
}
|
||||
}
|
||||
|
||||
void MapGridSetMetatileImpassabilityAt(s32 x, s32 y, bool32 arg2)
|
||||
void MapGridSetMetatileImpassabilityAt(s32 x, s32 y, bool32 impassable)
|
||||
{
|
||||
if (x >= 0 && x < VMap.Xsize
|
||||
&& y >= 0 && y < VMap.Ysize)
|
||||
if (AreCoordsWithinMapGridBounds(x, y))
|
||||
{
|
||||
if (arg2)
|
||||
{
|
||||
VMap.map[x + VMap.Xsize * y] |= 0x0C00;
|
||||
}
|
||||
if (impassable)
|
||||
VMap.map[x + VMap.Xsize * y] |= METATILE_COLLISION_MASK;
|
||||
else
|
||||
{
|
||||
VMap.map[x + VMap.Xsize * y] &= ~0x0C00;
|
||||
}
|
||||
VMap.map[x + VMap.Xsize * y] &= ~METATILE_COLLISION_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
u32 GetBehaviorByMetatileIdAndMapLayout(const struct MapLayout *mapLayout, u16 metatile, u8 attr)
|
||||
static u32 GetAttributeByMetatileIdAndMapLayout(const struct MapLayout *mapLayout, u16 metatile, u8 attributeType)
|
||||
{
|
||||
u32 * attributes;
|
||||
|
||||
if (metatile < NUM_METATILES_IN_PRIMARY)
|
||||
{
|
||||
attributes = mapLayout->primaryTileset->metatileAttributes;
|
||||
return GetMetatileAttributeFromRawMetatileBehavior(attributes[metatile], attr);
|
||||
return ExtractMetatileAttribute(attributes[metatile], attributeType);
|
||||
}
|
||||
else if (metatile < 0x400)
|
||||
else if (metatile < NUM_METATILES_TOTAL)
|
||||
{
|
||||
attributes = mapLayout->secondaryTileset->metatileAttributes;
|
||||
return GetMetatileAttributeFromRawMetatileBehavior(attributes[metatile - NUM_METATILES_IN_PRIMARY], attr);
|
||||
return ExtractMetatileAttribute(attributes[metatile - NUM_METATILES_IN_PRIMARY], attributeType);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -504,7 +447,7 @@ u32 GetBehaviorByMetatileIdAndMapLayout(const struct MapLayout *mapLayout, u16 m
|
|||
}
|
||||
}
|
||||
|
||||
void save_serialize_map(void)
|
||||
void SaveMapView(void)
|
||||
{
|
||||
s32 i, j;
|
||||
s32 x, y;
|
||||
|
|
@ -517,9 +460,7 @@ void save_serialize_map(void)
|
|||
for (i = y; i < y + 14; i++)
|
||||
{
|
||||
for (j = x; j < x + 15; j++)
|
||||
{
|
||||
*mapView++ = gBackupMapData[width * i + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -536,6 +477,7 @@ static bool32 SavedMapViewIsEmpty(void)
|
|||
for (i = 0; i < NELEMS(gSaveBlock2Ptr->mapView); i++)
|
||||
marker |= gSaveBlock2Ptr->mapView[i];
|
||||
#endif
|
||||
|
||||
if (marker == 0)
|
||||
return TRUE;
|
||||
else
|
||||
|
|
@ -571,7 +513,7 @@ static void LoadSavedMapView(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void sub_8059250(u8 a1)
|
||||
static void MoveMapViewToBackup(u8 direction)
|
||||
{
|
||||
s32 width;
|
||||
u16 *mapView;
|
||||
|
|
@ -590,24 +532,24 @@ static void sub_8059250(u8 a1)
|
|||
y0 = gSaveBlock1Ptr->pos.y;
|
||||
x2 = 15;
|
||||
y2 = 14;
|
||||
switch (a1)
|
||||
switch (direction)
|
||||
{
|
||||
case CONNECTION_NORTH:
|
||||
y0 += 1;
|
||||
y2 = 13;
|
||||
break;
|
||||
case CONNECTION_SOUTH:
|
||||
r8 = 1;
|
||||
y2 = 13;
|
||||
break;
|
||||
case CONNECTION_WEST:
|
||||
x0 += 1;
|
||||
x2 = 14;
|
||||
break;
|
||||
case CONNECTION_EAST:
|
||||
r9 = 1;
|
||||
x2 = 14;
|
||||
break;
|
||||
case CONNECTION_NORTH:
|
||||
y0 += 1;
|
||||
y2 = 13;
|
||||
break;
|
||||
case CONNECTION_SOUTH:
|
||||
r8 = 1;
|
||||
y2 = 13;
|
||||
break;
|
||||
case CONNECTION_WEST:
|
||||
x0 += 1;
|
||||
x2 = 14;
|
||||
break;
|
||||
case CONNECTION_EAST:
|
||||
r9 = 1;
|
||||
x2 = 14;
|
||||
break;
|
||||
}
|
||||
for (y = 0; y < y2; y++)
|
||||
{
|
||||
|
|
@ -629,206 +571,187 @@ static void sub_8059250(u8 a1)
|
|||
|
||||
s32 GetMapBorderIdAt(s32 x, s32 y)
|
||||
{
|
||||
if (MapGridGetTileAt(x, y) == 0x3FF)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (MapGridGetTileAt(x, y) == METATILE_ID_UNDEFINED)
|
||||
return CONNECTION_INVALID;
|
||||
|
||||
if (x >= VMap.Xsize - 8)
|
||||
{
|
||||
if (!gMapConnectionFlags.east)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return CONNECTION_INVALID;
|
||||
|
||||
return CONNECTION_EAST;
|
||||
}
|
||||
|
||||
if (x < 7)
|
||||
{
|
||||
if (!gMapConnectionFlags.west)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return CONNECTION_INVALID;
|
||||
|
||||
return CONNECTION_WEST;
|
||||
}
|
||||
|
||||
if (y >= VMap.Ysize - 7)
|
||||
{
|
||||
if (!gMapConnectionFlags.south)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return CONNECTION_INVALID;
|
||||
|
||||
return CONNECTION_SOUTH;
|
||||
}
|
||||
|
||||
if (y < 7)
|
||||
{
|
||||
if (!gMapConnectionFlags.north)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return CONNECTION_INVALID;
|
||||
|
||||
return CONNECTION_NORTH;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return CONNECTION_NONE;
|
||||
}
|
||||
|
||||
static s32 GetPostCameraMoveMapBorderId(s32 x, s32 y)
|
||||
{
|
||||
return GetMapBorderIdAt(7 + gSaveBlock1Ptr->pos.x + x, 7 + gSaveBlock1Ptr->pos.y + y);
|
||||
return GetMapBorderIdAt(gSaveBlock1Ptr->pos.x + 7 + x, gSaveBlock1Ptr->pos.y + 7 + y);
|
||||
}
|
||||
|
||||
bool32 CanCameraMoveInDirection(s32 direction)
|
||||
{
|
||||
s32 x, y;
|
||||
|
||||
x = gSaveBlock1Ptr->pos.x + 7 + gDirectionToVectors[direction].x;
|
||||
y = gSaveBlock1Ptr->pos.y + 7 + gDirectionToVectors[direction].y;
|
||||
if (GetMapBorderIdAt(x, y) == -1)
|
||||
{
|
||||
|
||||
if (GetMapBorderIdAt(x, y) == CONNECTION_INVALID)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void sub_80594AC(struct MapConnection *connection, int direction, s32 x, s32 y)
|
||||
static void SetPositionFromConnection(struct MapConnection *connection, int direction, s32 x, s32 y)
|
||||
{
|
||||
struct MapHeader const *mapHeader;
|
||||
mapHeader = mapconnection_get_mapheader(connection);
|
||||
mapHeader = GetMapHeaderFromConnection(connection);
|
||||
switch (direction)
|
||||
{
|
||||
case CONNECTION_EAST:
|
||||
gSaveBlock1Ptr->pos.x = -x;
|
||||
gSaveBlock1Ptr->pos.y -= connection->offset;
|
||||
break;
|
||||
case CONNECTION_WEST:
|
||||
gSaveBlock1Ptr->pos.x = mapHeader->mapLayout->width;
|
||||
gSaveBlock1Ptr->pos.y -= connection->offset;
|
||||
break;
|
||||
case CONNECTION_SOUTH:
|
||||
gSaveBlock1Ptr->pos.x -= connection->offset;
|
||||
gSaveBlock1Ptr->pos.y = -y;
|
||||
break;
|
||||
case CONNECTION_NORTH:
|
||||
gSaveBlock1Ptr->pos.x -= connection->offset;
|
||||
gSaveBlock1Ptr->pos.y = mapHeader->mapLayout->height;
|
||||
break;
|
||||
case CONNECTION_EAST:
|
||||
gSaveBlock1Ptr->pos.x = -x;
|
||||
gSaveBlock1Ptr->pos.y -= connection->offset;
|
||||
break;
|
||||
case CONNECTION_WEST:
|
||||
gSaveBlock1Ptr->pos.x = mapHeader->mapLayout->width;
|
||||
gSaveBlock1Ptr->pos.y -= connection->offset;
|
||||
break;
|
||||
case CONNECTION_SOUTH:
|
||||
gSaveBlock1Ptr->pos.x -= connection->offset;
|
||||
gSaveBlock1Ptr->pos.y = -y;
|
||||
break;
|
||||
case CONNECTION_NORTH:
|
||||
gSaveBlock1Ptr->pos.x -= connection->offset;
|
||||
gSaveBlock1Ptr->pos.y = mapHeader->mapLayout->height;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool8 CameraMove(s32 x, s32 y)
|
||||
{
|
||||
u32 direction;
|
||||
s32 direction;
|
||||
struct MapConnection *connection;
|
||||
s32 old_x, old_y;
|
||||
gCamera.active = FALSE;
|
||||
direction = GetPostCameraMoveMapBorderId(x, y);
|
||||
if (direction + 1 <= 1)
|
||||
if (direction == CONNECTION_NONE || direction == CONNECTION_INVALID)
|
||||
{
|
||||
gSaveBlock1Ptr->pos.x += x;
|
||||
gSaveBlock1Ptr->pos.y += y;
|
||||
}
|
||||
else
|
||||
{
|
||||
save_serialize_map();
|
||||
SaveMapView();
|
||||
old_x = gSaveBlock1Ptr->pos.x;
|
||||
old_y = gSaveBlock1Ptr->pos.y;
|
||||
connection = sub_8059600(direction, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y);
|
||||
sub_80594AC(connection, direction, x, y);
|
||||
connection = GetIncomingConnection(direction, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y);
|
||||
SetPositionFromConnection(connection, direction, x, y);
|
||||
LoadMapFromCameraTransition(connection->mapGroup, connection->mapNum);
|
||||
gCamera.active = TRUE;
|
||||
gCamera.x = old_x - gSaveBlock1Ptr->pos.x;
|
||||
gCamera.y = old_y - gSaveBlock1Ptr->pos.y;
|
||||
gSaveBlock1Ptr->pos.x += x;
|
||||
gSaveBlock1Ptr->pos.y += y;
|
||||
sub_8059250(direction);
|
||||
MoveMapViewToBackup(direction);
|
||||
}
|
||||
return gCamera.active;
|
||||
}
|
||||
|
||||
struct MapConnection *sub_8059600(u8 direction, s32 x, s32 y)
|
||||
struct MapConnection *GetIncomingConnection(u8 direction, s32 x, s32 y)
|
||||
{
|
||||
s32 count;
|
||||
struct MapConnection *connection;
|
||||
const struct MapConnections *connections = gMapHeader.connections;
|
||||
s32 i;
|
||||
// UB: Multiple possible null dereferences
|
||||
#ifdef UBFIX
|
||||
if (connections != NULL)
|
||||
{
|
||||
count = connections->count;
|
||||
connection = connections->connections;
|
||||
if (connection != NULL)
|
||||
{
|
||||
for (i = 0; i < count; i++, connection++)
|
||||
{
|
||||
if (connection->direction == direction && sub_8059658(direction, x, y, connection) == TRUE)
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
#ifdef UBFIX // UB: Multiple possible null dereferences
|
||||
if (connections == NULL || connections->connections == NULL)
|
||||
return NULL;
|
||||
#endif
|
||||
count = connections->count;
|
||||
connection = connections->connections;
|
||||
for (i = 0; i < count; i++, connection++)
|
||||
{
|
||||
if (connection->direction == direction && sub_8059658(direction, x, y, connection) == TRUE)
|
||||
if (connection->direction == direction && IsPosInIncomingConnectingMap(direction, x, y, connection) == TRUE)
|
||||
return connection;
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
static bool8 sub_8059658(u8 direction, s32 x, s32 y, struct MapConnection *connection)
|
||||
static bool8 IsPosInIncomingConnectingMap(u8 direction, s32 x, s32 y, struct MapConnection *connection)
|
||||
{
|
||||
struct MapHeader const *mapHeader;
|
||||
mapHeader = mapconnection_get_mapheader(connection);
|
||||
mapHeader = GetMapHeaderFromConnection(connection);
|
||||
switch (direction)
|
||||
{
|
||||
case CONNECTION_SOUTH:
|
||||
case CONNECTION_NORTH:
|
||||
return sub_80596BC(x, gMapHeader.mapLayout->width, mapHeader->mapLayout->width, connection->offset);
|
||||
case CONNECTION_WEST:
|
||||
case CONNECTION_EAST:
|
||||
return sub_80596BC(y, gMapHeader.mapLayout->height, mapHeader->mapLayout->height, connection->offset);
|
||||
case CONNECTION_SOUTH:
|
||||
case CONNECTION_NORTH:
|
||||
return IsCoordInIncomingConnectingMap(x, gMapHeader.mapLayout->width, mapHeader->mapLayout->width, connection->offset);
|
||||
case CONNECTION_WEST:
|
||||
case CONNECTION_EAST:
|
||||
return IsCoordInIncomingConnectingMap(y, gMapHeader.mapLayout->height, mapHeader->mapLayout->height, connection->offset);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static bool8 sub_80596BC(s32 x, s32 src_width, s32 dest_width, s32 offset)
|
||||
static bool8 IsCoordInIncomingConnectingMap(s32 coord, s32 srcMax, s32 destMax, s32 offset)
|
||||
{
|
||||
s32 offset2 = max(offset, 0);
|
||||
|
||||
if (dest_width + offset < src_width)
|
||||
src_width = dest_width + offset;
|
||||
if (destMax + offset < srcMax)
|
||||
srcMax = destMax + offset;
|
||||
|
||||
if (offset2 <= x && x <= src_width)
|
||||
if (offset2 <= coord && coord <= srcMax)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static bool32 sub_80596E8(s32 x, s32 width)
|
||||
static bool32 IsCoordInConnectingMap(s32 coord, s32 max)
|
||||
{
|
||||
if (x >= 0 && x < width)
|
||||
if (coord >= 0 && coord < max)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static s32 sub_80596FC(struct MapConnection *connection, s32 x, s32 y)
|
||||
static s32 IsPosInConnectingMap(struct MapConnection *connection, s32 x, s32 y)
|
||||
{
|
||||
struct MapHeader const *mapHeader;
|
||||
mapHeader = mapconnection_get_mapheader(connection);
|
||||
mapHeader = GetMapHeaderFromConnection(connection);
|
||||
switch (connection->direction)
|
||||
{
|
||||
case CONNECTION_SOUTH:
|
||||
case CONNECTION_NORTH:
|
||||
return sub_80596E8(x - connection->offset, mapHeader->mapLayout->width);
|
||||
case CONNECTION_WEST:
|
||||
case CONNECTION_EAST:
|
||||
return sub_80596E8(y - connection->offset, mapHeader->mapLayout->height);
|
||||
case CONNECTION_SOUTH:
|
||||
case CONNECTION_NORTH:
|
||||
return IsCoordInConnectingMap(x - connection->offset, mapHeader->mapLayout->width);
|
||||
case CONNECTION_WEST:
|
||||
case CONNECTION_EAST:
|
||||
return IsCoordInConnectingMap(y - connection->offset, mapHeader->mapLayout->height);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -858,10 +781,9 @@ struct MapConnection *GetMapConnectionAtPos(s16 x, s16 y)
|
|||
{
|
||||
continue;
|
||||
}
|
||||
if (sub_80596FC(connection, x - 7, y - 7) == TRUE)
|
||||
{
|
||||
|
||||
if (IsPosInConnectingMap(connection, x - 7, y - 7) == TRUE)
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
|
@ -879,6 +801,7 @@ void GetCameraFocusCoords(u16 *x, u16 *y)
|
|||
*y = gSaveBlock1Ptr->pos.y + 7;
|
||||
}
|
||||
|
||||
// Unused
|
||||
static void SetCameraCoords(u16 x, u16 y)
|
||||
{
|
||||
gSaveBlock1Ptr->pos.x = x;
|
||||
|
|
@ -890,7 +813,8 @@ void GetCameraCoords(u16 *x, u16 *y)
|
|||
*x = gSaveBlock1Ptr->pos.x;
|
||||
*y = gSaveBlock1Ptr->pos.y;
|
||||
}
|
||||
static void copy_tileset_patterns_to_vram(struct Tileset const *tileset, u16 numTiles, u16 offset)
|
||||
|
||||
static void CopyTilesetToVram(struct Tileset const *tileset, u16 numTiles, u16 offset)
|
||||
{
|
||||
if (tileset)
|
||||
{
|
||||
|
|
@ -901,7 +825,7 @@ static void copy_tileset_patterns_to_vram(struct Tileset const *tileset, u16 num
|
|||
}
|
||||
}
|
||||
|
||||
static void copy_tileset_patterns_to_vram2(struct Tileset const *tileset, u16 numTiles, u16 offset)
|
||||
static void CopyTilesetToVramUsingHeap(struct Tileset const *tileset, u16 numTiles, u16 offset)
|
||||
{
|
||||
if (tileset)
|
||||
{
|
||||
|
|
@ -916,20 +840,20 @@ static void Fieldmap_ApplyGlobalTintToPaletteEntries(u16 offset, u16 size)
|
|||
{
|
||||
switch (gGlobalFieldTintMode)
|
||||
{
|
||||
case QL_TINT_NONE:
|
||||
return;
|
||||
case QL_TINT_GRAYSCALE:
|
||||
TintPalette_GrayScale(gPlttBufferUnfaded + offset, size);
|
||||
break;
|
||||
case QL_TINT_SEPIA:
|
||||
TintPalette_SepiaTone(gPlttBufferUnfaded + offset, size);
|
||||
break;
|
||||
case QL_TINT_BACKUP_GRAYSCALE:
|
||||
QuestLog_BackUpPalette(offset, size);
|
||||
TintPalette_GrayScale(gPlttBufferUnfaded + offset, size);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
case QL_TINT_NONE:
|
||||
return;
|
||||
case QL_TINT_GRAYSCALE:
|
||||
TintPalette_GrayScale(gPlttBufferUnfaded + offset, size);
|
||||
break;
|
||||
case QL_TINT_SEPIA:
|
||||
TintPalette_SepiaTone(gPlttBufferUnfaded + offset, size);
|
||||
break;
|
||||
case QL_TINT_BACKUP_GRAYSCALE:
|
||||
QuestLog_BackUpPalette(offset, size);
|
||||
TintPalette_GrayScale(gPlttBufferUnfaded + offset, size);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
CpuCopy16(gPlttBufferUnfaded + offset, gPlttBufferFaded + offset, size * sizeof(u16));
|
||||
}
|
||||
|
|
@ -938,25 +862,25 @@ void Fieldmap_ApplyGlobalTintToPaletteSlot(u8 slot, u8 count)
|
|||
{
|
||||
switch (gGlobalFieldTintMode)
|
||||
{
|
||||
case QL_TINT_NONE:
|
||||
return;
|
||||
case QL_TINT_GRAYSCALE:
|
||||
TintPalette_GrayScale(gPlttBufferUnfaded + slot * 16, count * 16);
|
||||
break;
|
||||
case QL_TINT_SEPIA:
|
||||
TintPalette_SepiaTone(gPlttBufferUnfaded + slot * 16, count * 16);
|
||||
break;
|
||||
case QL_TINT_BACKUP_GRAYSCALE:
|
||||
QuestLog_BackUpPalette(slot * 16, count * 16);
|
||||
TintPalette_GrayScale(gPlttBufferUnfaded + slot * 16, count * 16);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
case QL_TINT_NONE:
|
||||
return;
|
||||
case QL_TINT_GRAYSCALE:
|
||||
TintPalette_GrayScale(gPlttBufferUnfaded + slot * 16, count * 16);
|
||||
break;
|
||||
case QL_TINT_SEPIA:
|
||||
TintPalette_SepiaTone(gPlttBufferUnfaded + slot * 16, count * 16);
|
||||
break;
|
||||
case QL_TINT_BACKUP_GRAYSCALE:
|
||||
QuestLog_BackUpPalette(slot * 16, count * 16);
|
||||
TintPalette_GrayScale(gPlttBufferUnfaded + slot * 16, count * 16);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
CpuFastCopy(gPlttBufferUnfaded + slot * 16, gPlttBufferFaded + slot * 16, count * 16 * sizeof(u16));
|
||||
}
|
||||
|
||||
static void apply_map_tileset_palette(struct Tileset const *tileset, u16 destOffset, u16 size)
|
||||
static void LoadTilesetPalette(struct Tileset const *tileset, u16 destOffset, u16 size)
|
||||
{
|
||||
u16 black = RGB_BLACK;
|
||||
|
||||
|
|
@ -981,45 +905,45 @@ static void apply_map_tileset_palette(struct Tileset const *tileset, u16 destOff
|
|||
}
|
||||
}
|
||||
|
||||
void copy_map_tileset1_to_vram(const struct MapLayout *mapLayout)
|
||||
void CopyPrimaryTilesetToVram(const struct MapLayout *mapLayout)
|
||||
{
|
||||
copy_tileset_patterns_to_vram(mapLayout->primaryTileset, NUM_TILES_IN_PRIMARY, 0);
|
||||
CopyTilesetToVram(mapLayout->primaryTileset, NUM_TILES_IN_PRIMARY, 0);
|
||||
}
|
||||
|
||||
void copy_map_tileset2_to_vram(const struct MapLayout *mapLayout)
|
||||
void CopySecondaryTilesetToVram(const struct MapLayout *mapLayout)
|
||||
{
|
||||
copy_tileset_patterns_to_vram(mapLayout->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY);
|
||||
CopyTilesetToVram(mapLayout->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY);
|
||||
}
|
||||
|
||||
void copy_map_tileset2_to_vram_2(const struct MapLayout *mapLayout)
|
||||
void CopySecondaryTilesetToVramUsingHeap(const struct MapLayout *mapLayout)
|
||||
{
|
||||
copy_tileset_patterns_to_vram2(mapLayout->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY);
|
||||
CopyTilesetToVramUsingHeap(mapLayout->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY);
|
||||
}
|
||||
|
||||
void apply_map_tileset1_palette(const struct MapLayout *mapLayout)
|
||||
static void LoadPrimaryTilesetPalette(const struct MapLayout *mapLayout)
|
||||
{
|
||||
apply_map_tileset_palette(mapLayout->primaryTileset, 0, NUM_PALS_IN_PRIMARY * 16 * 2);
|
||||
LoadTilesetPalette(mapLayout->primaryTileset, 0, NUM_PALS_IN_PRIMARY * 16 * 2);
|
||||
}
|
||||
|
||||
void apply_map_tileset2_palette(const struct MapLayout *mapLayout)
|
||||
void LoadSecondaryTilesetPalette(const struct MapLayout *mapLayout)
|
||||
{
|
||||
apply_map_tileset_palette(mapLayout->secondaryTileset, NUM_PALS_IN_PRIMARY * 16, (NUM_PALS_TOTAL - NUM_PALS_IN_PRIMARY) * 16 * 2);
|
||||
LoadTilesetPalette(mapLayout->secondaryTileset, NUM_PALS_IN_PRIMARY * 16, (NUM_PALS_TOTAL - NUM_PALS_IN_PRIMARY) * 16 * 2);
|
||||
}
|
||||
|
||||
void copy_map_tileset1_tileset2_to_vram(struct MapLayout const *mapLayout)
|
||||
void CopyMapTilesetsToVram(struct MapLayout const *mapLayout)
|
||||
{
|
||||
if (mapLayout)
|
||||
{
|
||||
copy_tileset_patterns_to_vram2(mapLayout->primaryTileset, NUM_TILES_IN_PRIMARY, 0);
|
||||
copy_tileset_patterns_to_vram2(mapLayout->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY);
|
||||
CopyTilesetToVramUsingHeap(mapLayout->primaryTileset, NUM_TILES_IN_PRIMARY, 0);
|
||||
CopyTilesetToVramUsingHeap(mapLayout->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY);
|
||||
}
|
||||
}
|
||||
|
||||
void apply_map_tileset1_tileset2_palette(struct MapLayout const *mapLayout)
|
||||
void LoadMapTilesetPalettes(struct MapLayout const *mapLayout)
|
||||
{
|
||||
if (mapLayout)
|
||||
{
|
||||
apply_map_tileset1_palette(mapLayout);
|
||||
apply_map_tileset2_palette(mapLayout);
|
||||
LoadPrimaryTilesetPalette(mapLayout);
|
||||
LoadSecondaryTilesetPalette(mapLayout);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -316,30 +316,30 @@ static bool8 HiddenItemInConnectedMapAtPos(struct MapConnection * connection, s3
|
|||
u32 localOffset;
|
||||
s32 localLength;
|
||||
|
||||
mapHeader = mapconnection_get_mapheader(connection);
|
||||
mapHeader = GetMapHeaderFromConnection(connection);
|
||||
|
||||
switch (connection->direction)
|
||||
{
|
||||
// same weird temp variable behavior seen in HiddenItemAtPos
|
||||
case 2:
|
||||
case CONNECTION_NORTH:
|
||||
localOffset = connection->offset + 7;
|
||||
localX = x - localOffset;
|
||||
localLength = mapHeader->mapLayout->height - 7;
|
||||
localY = localLength + y; // additions are reversed for some reason
|
||||
break;
|
||||
case 1:
|
||||
case CONNECTION_SOUTH:
|
||||
localOffset = connection->offset + 7;
|
||||
localX = x - localOffset;
|
||||
localLength = gMapHeader.mapLayout->height + 7;
|
||||
localY = y - localLength;
|
||||
break;
|
||||
case 3:
|
||||
case CONNECTION_WEST:
|
||||
localLength = mapHeader->mapLayout->width - 7;
|
||||
localX = localLength + x; // additions are reversed for some reason
|
||||
localOffset = connection->offset + 7;
|
||||
localY = y - localOffset;
|
||||
break;
|
||||
case 4:
|
||||
case CONNECTION_EAST:
|
||||
localLength = gMapHeader.mapLayout->width + 7;
|
||||
localX = x - localLength;
|
||||
localOffset = connection->offset + 7;
|
||||
|
|
|
|||
|
|
@ -477,8 +477,8 @@ void Overworld_SetObjEventTemplateMovementType(u8 localId, u8 movementType)
|
|||
static void mapdata_load_assets_to_gpu_and_full_redraw(void)
|
||||
{
|
||||
move_tilemap_camera_to_upper_left_corner();
|
||||
copy_map_tileset1_tileset2_to_vram(gMapHeader.mapLayout);
|
||||
apply_map_tileset1_tileset2_palette(gMapHeader.mapLayout);
|
||||
CopyMapTilesetsToVram(gMapHeader.mapLayout);
|
||||
LoadMapTilesetPalettes(gMapHeader.mapLayout);
|
||||
DrawWholeMapView();
|
||||
InitTilesetAnimations();
|
||||
}
|
||||
|
|
@ -766,8 +766,8 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum)
|
|||
RunOnTransitionMapScript();
|
||||
TryRegenerateRenewableHiddenItems();
|
||||
InitMap();
|
||||
copy_map_tileset2_to_vram_2(gMapHeader.mapLayout);
|
||||
apply_map_tileset2_palette(gMapHeader.mapLayout);
|
||||
CopySecondaryTilesetToVramUsingHeap(gMapHeader.mapLayout);
|
||||
LoadSecondaryTilesetPalette(gMapHeader.mapLayout);
|
||||
for (paletteIndex = 7; paletteIndex < 13; paletteIndex++)
|
||||
ApplyWeatherGammaShiftToPal(paletteIndex);
|
||||
InitSecondaryTilesetAnimation();
|
||||
|
|
@ -1796,17 +1796,17 @@ static bool32 map_loading_iteration_3(u8 *state)
|
|||
(*state)++;
|
||||
break;
|
||||
case 6:
|
||||
copy_map_tileset1_to_vram(gMapHeader.mapLayout);
|
||||
CopyPrimaryTilesetToVram(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
break;
|
||||
case 7:
|
||||
copy_map_tileset2_to_vram(gMapHeader.mapLayout);
|
||||
CopySecondaryTilesetToVram(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
break;
|
||||
case 8:
|
||||
if (FreeTempTileDataBuffersIfPossible() != TRUE)
|
||||
{
|
||||
apply_map_tileset1_tileset2_palette(gMapHeader.mapLayout);
|
||||
LoadMapTilesetPalettes(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1881,17 +1881,17 @@ static bool32 load_map_stuff(u8 *state, bool32 a1)
|
|||
(*state)++;
|
||||
break;
|
||||
case 7:
|
||||
copy_map_tileset1_to_vram(gMapHeader.mapLayout);
|
||||
CopyPrimaryTilesetToVram(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
break;
|
||||
case 8:
|
||||
copy_map_tileset2_to_vram(gMapHeader.mapLayout);
|
||||
CopySecondaryTilesetToVram(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
break;
|
||||
case 9:
|
||||
if (FreeTempTileDataBuffersIfPossible() != TRUE)
|
||||
{
|
||||
apply_map_tileset1_tileset2_palette(gMapHeader.mapLayout);
|
||||
LoadMapTilesetPalettes(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1986,17 +1986,17 @@ static bool32 map_loading_iteration_2_link(u8 *state)
|
|||
(*state)++;
|
||||
break;
|
||||
case 5:
|
||||
copy_map_tileset1_to_vram(gMapHeader.mapLayout);
|
||||
CopyPrimaryTilesetToVram(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
break;
|
||||
case 6:
|
||||
copy_map_tileset2_to_vram(gMapHeader.mapLayout);
|
||||
CopySecondaryTilesetToVram(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
break;
|
||||
case 7:
|
||||
if (FreeTempTileDataBuffersIfPossible() != TRUE)
|
||||
{
|
||||
apply_map_tileset1_tileset2_palette(gMapHeader.mapLayout);
|
||||
LoadMapTilesetPalettes(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
}
|
||||
break;
|
||||
|
|
@ -2281,17 +2281,17 @@ static bool32 LoadMap_QLPlayback(u8 *state)
|
|||
(*state)++;
|
||||
break;
|
||||
case 6:
|
||||
copy_map_tileset1_to_vram(gMapHeader.mapLayout);
|
||||
CopyPrimaryTilesetToVram(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
break;
|
||||
case 7:
|
||||
copy_map_tileset2_to_vram(gMapHeader.mapLayout);
|
||||
CopySecondaryTilesetToVram(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
break;
|
||||
case 8:
|
||||
if (FreeTempTileDataBuffersIfPossible() != TRUE)
|
||||
{
|
||||
apply_map_tileset1_tileset2_palette(gMapHeader.mapLayout);
|
||||
LoadMapTilesetPalettes(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
}
|
||||
break;
|
||||
|
|
@ -2450,17 +2450,17 @@ static bool8 MapLdr_Credits(void)
|
|||
(*state)++;
|
||||
break;
|
||||
case 4:
|
||||
copy_map_tileset1_to_vram(gMapHeader.mapLayout);
|
||||
CopyPrimaryTilesetToVram(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
break;
|
||||
case 5:
|
||||
copy_map_tileset2_to_vram(gMapHeader.mapLayout);
|
||||
CopySecondaryTilesetToVram(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
break;
|
||||
case 6:
|
||||
if (FreeTempTileDataBuffersIfPossible() != TRUE)
|
||||
{
|
||||
apply_map_tileset1_tileset2_palette(gMapHeader.mapLayout);
|
||||
LoadMapTilesetPalettes(gMapHeader.mapLayout);
|
||||
(*state)++;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -859,7 +859,7 @@ void Task_LinkSave(u8 taskId)
|
|||
case 2:
|
||||
if (IsLinkTaskFinished())
|
||||
{
|
||||
save_serialize_map();
|
||||
SaveMapView();
|
||||
gTasks[taskId].data[0] = 3;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -596,7 +596,7 @@ static bool8 StartCB_Save2(void)
|
|||
|
||||
static void StartMenu_PrepareForSave(void)
|
||||
{
|
||||
save_serialize_map();
|
||||
SaveMapView();
|
||||
sSaveDialogCB = SaveDialogCB_PrintAskSaveText;
|
||||
sSaveDialogIsPrinting = FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -365,11 +365,11 @@ bool8 StandardWildEncounter(u32 currMetatileAttrs, u16 previousMetatileBehavior)
|
|||
headerId = GetCurrentMapWildMonHeaderId();
|
||||
if (headerId != 0xFFFF)
|
||||
{
|
||||
if (GetMetatileAttributeFromRawMetatileBehavior(currMetatileAttrs, METATILE_ATTRIBUTE_ENCOUNTER_TYPE) == TILE_ENCOUNTER_LAND)
|
||||
if (ExtractMetatileAttribute(currMetatileAttrs, METATILE_ATTRIBUTE_ENCOUNTER_TYPE) == TILE_ENCOUNTER_LAND)
|
||||
{
|
||||
if (gWildMonHeaders[headerId].landMonsInfo == NULL)
|
||||
return FALSE;
|
||||
else if (previousMetatileBehavior != GetMetatileAttributeFromRawMetatileBehavior(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR) && !DoGlobalWildEncounterDiceRoll())
|
||||
else if (previousMetatileBehavior != ExtractMetatileAttribute(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR) && !DoGlobalWildEncounterDiceRoll())
|
||||
return FALSE;
|
||||
if (DoWildEncounterRateTest(gWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE)
|
||||
{
|
||||
|
|
@ -403,12 +403,12 @@ bool8 StandardWildEncounter(u32 currMetatileAttrs, u16 previousMetatileBehavior)
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (GetMetatileAttributeFromRawMetatileBehavior(currMetatileAttrs, METATILE_ATTRIBUTE_ENCOUNTER_TYPE) == TILE_ENCOUNTER_WATER
|
||||
|| (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING) && MetatileBehavior_IsBridge(GetMetatileAttributeFromRawMetatileBehavior(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR)) == TRUE))
|
||||
else if (ExtractMetatileAttribute(currMetatileAttrs, METATILE_ATTRIBUTE_ENCOUNTER_TYPE) == TILE_ENCOUNTER_WATER
|
||||
|| (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING) && MetatileBehavior_IsBridge(ExtractMetatileAttribute(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR)) == TRUE))
|
||||
{
|
||||
if (gWildMonHeaders[headerId].waterMonsInfo == NULL)
|
||||
return FALSE;
|
||||
else if (previousMetatileBehavior != GetMetatileAttributeFromRawMetatileBehavior(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR) && !DoGlobalWildEncounterDiceRoll())
|
||||
else if (previousMetatileBehavior != ExtractMetatileAttribute(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR) && !DoGlobalWildEncounterDiceRoll())
|
||||
return FALSE;
|
||||
else if (DoWildEncounterRateTest(gWildMonHeaders[headerId].waterMonsInfo->encounterRate, FALSE) != TRUE)
|
||||
{
|
||||
|
|
@ -709,7 +709,7 @@ void ResetEncounterRateModifiers(void)
|
|||
|
||||
static bool8 HandleWildEncounterCooldown(u32 currMetatileAttrs)
|
||||
{
|
||||
u8 encounterType = GetMetatileAttributeFromRawMetatileBehavior(currMetatileAttrs, METATILE_ATTRIBUTE_ENCOUNTER_TYPE);
|
||||
u8 encounterType = ExtractMetatileAttribute(currMetatileAttrs, METATILE_ATTRIBUTE_ENCOUNTER_TYPE);
|
||||
u32 minSteps;
|
||||
u32 encRate;
|
||||
if (encounterType == TILE_ENCOUNTER_NONE)
|
||||
|
|
@ -761,19 +761,19 @@ bool8 TryStandardWildEncounter(u32 currMetatileAttrs)
|
|||
{
|
||||
if (!HandleWildEncounterCooldown(currMetatileAttrs))
|
||||
{
|
||||
sWildEncounterData.prevMetatileBehavior = GetMetatileAttributeFromRawMetatileBehavior(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR);
|
||||
sWildEncounterData.prevMetatileBehavior = ExtractMetatileAttribute(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR);
|
||||
return FALSE;
|
||||
}
|
||||
else if (StandardWildEncounter(currMetatileAttrs, sWildEncounterData.prevMetatileBehavior) == TRUE)
|
||||
{
|
||||
sWildEncounterData.encounterRateBuff = 0;
|
||||
sWildEncounterData.stepsSinceLastEncounter = 0;
|
||||
sWildEncounterData.prevMetatileBehavior = GetMetatileAttributeFromRawMetatileBehavior(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR);
|
||||
sWildEncounterData.prevMetatileBehavior = ExtractMetatileAttribute(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
sWildEncounterData.prevMetatileBehavior = GetMetatileAttributeFromRawMetatileBehavior(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR);
|
||||
sWildEncounterData.prevMetatileBehavior = ExtractMetatileAttribute(currMetatileAttrs, METATILE_ATTRIBUTE_BEHAVIOR);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user