Clean up metatile_behavior

This commit is contained in:
GriffinR 2021-10-18 12:20:35 -04:00
parent 7590bacec1
commit b31bddddca
8 changed files with 106 additions and 61 deletions

View File

@ -113,22 +113,22 @@
#define MB_WATER_SOUTH_ARROW_WARP 0x6D
#define MB_DEEP_SOUTH_WARP 0x6E
#define MB_UNUSED_6F 0x6F
#define MB_WARP_OR_BRIDGE 0x70
#define MB_UNUSED_71 0x71
#define MB_ROUTE120_NORTH_BRIDGE_1 0x72
#define MB_ROUTE120_NORTH_BRIDGE_2 0x73
#define MB_BRIDGE_OVER_OCEAN 0x70
#define MB_BRIDGE_OVER_POND_LOW 0x71
#define MB_BRIDGE_OVER_POND_MED 0x72
#define MB_BRIDGE_OVER_POND_HIGH 0x73
#define MB_PACIFIDLOG_VERTICAL_LOG_1 0x74
#define MB_PACIFIDLOG_VERTICAL_LOG_2 0x75
#define MB_PACIFIDLOG_HORIZONTAL_LOG_1 0x76
#define MB_PACIFIDLOG_HORIZONTAL_LOG_2 0x77
#define MB_FORTREE_BRIDGE 0x78
#define MB_UNUSED_79 0x79
#define MB_ROUTE120_SOUTH_BRIDGE_1 0x7A
#define MB_ROUTE120_SOUTH_BRIDGE_2 0x7B
#define MB_ROUTE120_NORTH_BRIDGE_3 0x7C
#define MB_ROUTE120_NORTH_BRIDGE_4 0x7D
#define MB_UNUSED_7E 0x7E
#define MB_ROUTE110_BRIDGE 0x7F
#define MB_BRIDGE_OVER_POND_MED_EDGE_1 0x7A
#define MB_BRIDGE_OVER_POND_MED_EDGE_2 0x7B
#define MB_BRIDGE_OVER_POND_HIGH_EDGE_1 0x7C
#define MB_BRIDGE_OVER_POND_HIGH_EDGE_2 0x7D
#define MB_UNUSED_BRIDGE_1 0x7E
#define MB_UNUSED_BRIDGE_2 0x7F
#define MB_COUNTER 0x80
#define MB_UNUSED_81 0x81
#define MB_UNUSED_82 0x82

View File

@ -1,6 +1,14 @@
#ifndef GUARD_METATILE_BEHAVIOR_H
#define GUARD_METATILE_BEHAVIOR_H
// Return values for MetatileBehavior_GetBridgeType
enum {
BRIDGE_TYPE_OCEAN, // For log bridges over 'ocean' style water (Routes 110/119 use this).
BRIDGE_TYPE_POND_LOW,
BRIDGE_TYPE_POND_MED,
BRIDGE_TYPE_POND_HIGH,
};
bool8 MetatileBehavior_IsATile(u8);
bool8 MetatileBehavior_IsEncounterTile(u8);
bool8 MetatileBehavior_IsJumpEast(u8);
@ -76,9 +84,9 @@ bool8 MetatileBehavior_IsLongGrass(u8);
bool8 MetatileBehavior_IsBerryTreeSoil(u8);
bool8 MetatileBehavior_IsAshGrass(u8);
bool8 MetatileBehavior_IsFootprints(u8);
bool8 MetatileBehavior_IsBridge(u8);
bool8 MetatileBehavior_IsBridgeOverWater(u8);
u8 MetatileBehavior_GetBridgeType(u8);
u8 MetatileBehavior_8089510(u8);
bool8 MetatileBehavior_IsBridgeOverWaterNoEdge(u8);
bool8 MetatileBehavior_IsLandWildEncounter(u8);
bool8 MetatileBehavior_IsWaterWildEncounter(u8);
bool8 MetatileBehavior_IsIndoorEncounter(u8);
@ -115,7 +123,7 @@ bool8 MetatileBehavior_IsSecretBaseSpinMat(u8);
bool8 MetatileBehavior_IsLavaridgeB1FWarp(u8);
bool8 MetatileBehavior_IsLavaridge1FWarp(u8);
bool8 MetatileBehavior_IsAquaHideoutWarp(u8);
bool8 MetatileBehavior_IsWarpOrBridge(u8);
bool8 MetatileBehavior_IsBridgeOverOcean(u8);
bool8 MetatileBehavior_IsMossdeepGymWarp(u8);
bool8 MetatileBehavior_IsSurfableFishableWater(u8);
bool8 MetatileBehavior_IsMtPyreHole(u8);

View File

@ -674,9 +674,11 @@ u8 BattleSetup_GetTerrainId(void)
return BATTLE_TERRAIN_MOUNTAIN;
if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING))
{
if (MetatileBehavior_GetBridgeType(tileBehavior))
// Is BRIDGE_TYPE_POND_*?
if (MetatileBehavior_GetBridgeType(tileBehavior) != BRIDGE_TYPE_OCEAN)
return BATTLE_TERRAIN_POND;
if (MetatileBehavior_IsBridge(tileBehavior) == TRUE)
if (MetatileBehavior_IsBridgeOverWater(tileBehavior) == TRUE)
return BATTLE_TERRAIN_WATER;
}
if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE113) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE113))

View File

@ -729,9 +729,9 @@ static bool8 TryStartWarpEventScript(struct MapPosition *position, u16 metatileB
DoTeleportTileWarp();
return TRUE;
}
if (MetatileBehavior_IsWarpOrBridge(metatileBehavior) == TRUE)
if (MetatileBehavior_IsBridgeOverOcean(metatileBehavior) == TRUE)
{
// Maybe unused? This MB is used by log bridges, but there's never a warp event on them
// Maybe unused? This MB is used by log bridges, but there's never a warp event on them.
DoSpinExitWarp();
return TRUE;
}
@ -762,7 +762,7 @@ static bool8 IsWarpMetatileBehavior(u16 metatileBehavior)
&& MetatileBehavior_IsAquaHideoutWarp(metatileBehavior) != TRUE
&& MetatileBehavior_IsMtPyreHole(metatileBehavior) != TRUE
&& MetatileBehavior_IsMossdeepGymWarp(metatileBehavior) != TRUE
&& MetatileBehavior_IsWarpOrBridge(metatileBehavior) != TRUE)
&& MetatileBehavior_IsBridgeOverOcean(metatileBehavior) != TRUE)
return FALSE;
return TRUE;
}

View File

@ -71,9 +71,15 @@ static s16 GetReflectionVerticalOffset(struct ObjectEvent *objectEvent)
static void LoadObjectReflectionPalette(struct ObjectEvent *objectEvent, struct Sprite *reflectionSprite)
{
u8 bridgeType;
u16 bridgeReflectionVerticalOffsets[] = { 12, 28, 44 };
u16 bridgeReflectionVerticalOffsets[] = {
[BRIDGE_TYPE_POND_LOW - 1] = 12,
[BRIDGE_TYPE_POND_MED - 1] = 28,
[BRIDGE_TYPE_POND_HIGH - 1] = 44
};
reflectionSprite->sReflectionVerticalOffset = 0;
if (!GetObjectEventGraphicsInfo(objectEvent->graphicsId)->disableReflectionPaletteLoad && ((bridgeType = MetatileBehavior_GetBridgeType(objectEvent->previousMetatileBehavior)) || (bridgeType = MetatileBehavior_GetBridgeType(objectEvent->currentMetatileBehavior))))
if (!GetObjectEventGraphicsInfo(objectEvent->graphicsId)->disableReflectionPaletteLoad
&& ((bridgeType = MetatileBehavior_GetBridgeType(objectEvent->previousMetatileBehavior))
|| (bridgeType = MetatileBehavior_GetBridgeType(objectEvent->currentMetatileBehavior))))
{
reflectionSprite->sReflectionVerticalOffset = bridgeReflectionVerticalOffsets[bridgeType - 1];
LoadObjectHighBridgeReflectionPalette(objectEvent, reflectionSprite->oam.paletteNum);

View File

@ -249,7 +249,7 @@ static bool32 CanFish(void)
{
if (MetatileBehavior_IsSurfableWaterOrUnderwater(tileBehavior) && !MapGridIsImpassableAt(x, y))
return TRUE;
if (MetatileBehavior_8089510(tileBehavior) == TRUE)
if (MetatileBehavior_IsBridgeOverWaterNoEdge(tileBehavior) == TRUE)
return TRUE;
}

View File

@ -122,22 +122,22 @@ static const u8 sTileBitAttributes[] =
[MB_WATER_SOUTH_ARROW_WARP] = TILE_ATTRIBUTES(TRUE, TRUE, FALSE),
[MB_DEEP_SOUTH_WARP] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_UNUSED_6F] = TILE_ATTRIBUTES(TRUE, TRUE, FALSE),
[MB_WARP_OR_BRIDGE] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
[MB_UNUSED_71] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_ROUTE120_NORTH_BRIDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_ROUTE120_NORTH_BRIDGE_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_BRIDGE_OVER_OCEAN] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
[MB_BRIDGE_OVER_POND_LOW] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_BRIDGE_OVER_POND_MED] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_BRIDGE_OVER_POND_HIGH] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_PACIFIDLOG_VERTICAL_LOG_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_PACIFIDLOG_VERTICAL_LOG_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_PACIFIDLOG_HORIZONTAL_LOG_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_PACIFIDLOG_HORIZONTAL_LOG_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_FORTREE_BRIDGE] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_UNUSED_79] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
[MB_ROUTE120_SOUTH_BRIDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_ROUTE120_SOUTH_BRIDGE_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_ROUTE120_NORTH_BRIDGE_3] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_ROUTE120_NORTH_BRIDGE_4] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_UNUSED_7E] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_ROUTE110_BRIDGE] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_BRIDGE_OVER_POND_MED_EDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_BRIDGE_OVER_POND_MED_EDGE_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_BRIDGE_OVER_POND_HIGH_EDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_BRIDGE_OVER_POND_HIGH_EDGE_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_UNUSED_BRIDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_UNUSED_BRIDGE_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_COUNTER] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
[MB_UNUSED_81] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
[MB_UNUSED_82] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
@ -833,7 +833,9 @@ bool8 MetatileBehavior_IsPlayerRoomPCOn(u8 metatileBehavior)
bool8 MetatileBehavior_HasRipples(u8 metatileBehavior)
{
if (metatileBehavior == MB_POND_WATER || metatileBehavior == MB_PUDDLE || metatileBehavior == MB_SOOTOPOLIS_DEEP_WATER)
if (metatileBehavior == MB_POND_WATER
|| metatileBehavior == MB_PUDDLE
|| metatileBehavior == MB_SOOTOPOLIS_DEEP_WATER)
return TRUE;
else
return FALSE;
@ -888,10 +890,19 @@ bool8 MetatileBehavior_IsFootprints(u8 metatileBehavior)
return FALSE;
}
bool8 MetatileBehavior_IsBridge(u8 metatileBehavior)
// For the sections of log bridges that span water / water's edge.
// Note that the rest of the metatiles for these bridges use MB_NORMAL.
// This is used to allow encounters on the water below the bridge.
bool8 MetatileBehavior_IsBridgeOverWater(u8 metatileBehavior)
{
if ((metatileBehavior == MB_WARP_OR_BRIDGE || metatileBehavior == MB_UNUSED_71 || metatileBehavior == MB_ROUTE120_NORTH_BRIDGE_1 || metatileBehavior == MB_ROUTE120_NORTH_BRIDGE_2)
|| (metatileBehavior == MB_ROUTE120_NORTH_BRIDGE_3 || metatileBehavior == MB_ROUTE120_NORTH_BRIDGE_4 || metatileBehavior == MB_UNUSED_7E || metatileBehavior == MB_ROUTE110_BRIDGE))
if ((metatileBehavior == MB_BRIDGE_OVER_OCEAN
|| metatileBehavior == MB_BRIDGE_OVER_POND_LOW
|| metatileBehavior == MB_BRIDGE_OVER_POND_MED
|| metatileBehavior == MB_BRIDGE_OVER_POND_HIGH)
|| (metatileBehavior == MB_BRIDGE_OVER_POND_HIGH_EDGE_1
|| metatileBehavior == MB_BRIDGE_OVER_POND_HIGH_EDGE_2
|| metatileBehavior == MB_UNUSED_BRIDGE_1
|| metatileBehavior == MB_UNUSED_BRIDGE_2))
return TRUE;
else
return FALSE;
@ -899,34 +910,39 @@ bool8 MetatileBehavior_IsBridge(u8 metatileBehavior)
u8 MetatileBehavior_GetBridgeType(u8 metatileBehavior)
{
u8 result = metatileBehavior - MB_WARP_OR_BRIDGE;
if (result < 4)
return result;
// MB_BRIDGE_OVER_OCEAN --> BRIDGE_TYPE_OCEAN (Routes 110/119)
// MB_BRIDGE_OVER_POND_LOW --> BRIDGE_TYPE_POND_LOW (Unused)
// MB_BRIDGE_OVER_POND_MED --> BRIDGE_TYPE_POND_MED (Route 120, south)
// MB_BRIDGE_OVER_POND_HIGH --> BRIDGE_TYPE_POND_HIGH (Route 120, north)
if (metatileBehavior >= MB_BRIDGE_OVER_OCEAN
&& metatileBehavior <= MB_BRIDGE_OVER_POND_HIGH)
return metatileBehavior - MB_BRIDGE_OVER_OCEAN;
result = metatileBehavior - MB_ROUTE120_SOUTH_BRIDGE_1;
if (result < 2)
return 2;
if (metatileBehavior >= MB_BRIDGE_OVER_POND_MED_EDGE_1
&& metatileBehavior <= MB_BRIDGE_OVER_POND_MED_EDGE_2)
return BRIDGE_TYPE_POND_MED;
result = metatileBehavior - MB_ROUTE120_NORTH_BRIDGE_3;
if (result < 2)
return 3;
if (metatileBehavior >= MB_BRIDGE_OVER_POND_HIGH_EDGE_1
&& metatileBehavior <= MB_BRIDGE_OVER_POND_HIGH_EDGE_2)
return BRIDGE_TYPE_POND_HIGH;
return 0;
return BRIDGE_TYPE_OCEAN;
}
u8 MetatileBehavior_8089510(u8 metatileBehavior)
// Used to allow fishing below the bridge metatiles.
bool8 MetatileBehavior_IsBridgeOverWaterNoEdge(u8 metatileBehavior)
{
u8 result = metatileBehavior - MB_WARP_OR_BRIDGE;
if (result < 4)
return 1;
if (metatileBehavior >= MB_BRIDGE_OVER_OCEAN
&& metatileBehavior <= MB_BRIDGE_OVER_POND_HIGH)
return TRUE;
else
return 0;
return FALSE;
}
bool8 MetatileBehavior_IsLandWildEncounter(u8 metatileBehavior)
{
if (MetatileBehavior_IsSurfableWaterOrUnderwater(metatileBehavior) == FALSE && MetatileBehavior_IsEncounterTile(metatileBehavior) == TRUE)
if (MetatileBehavior_IsSurfableWaterOrUnderwater(metatileBehavior) == FALSE
&& MetatileBehavior_IsEncounterTile(metatileBehavior) == TRUE)
return TRUE;
else
return FALSE;
@ -934,7 +950,8 @@ bool8 MetatileBehavior_IsLandWildEncounter(u8 metatileBehavior)
bool8 MetatileBehavior_IsWaterWildEncounter(u8 metatileBehavior)
{
if (MetatileBehavior_IsSurfableWaterOrUnderwater(metatileBehavior) == TRUE && MetatileBehavior_IsEncounterTile(metatileBehavior) == TRUE)
if (MetatileBehavior_IsSurfableWaterOrUnderwater(metatileBehavior) == TRUE
&& MetatileBehavior_IsEncounterTile(metatileBehavior) == TRUE)
return TRUE;
else
return FALSE;
@ -1148,8 +1165,10 @@ bool8 MetatileBehavior_IsPacifidlogHorizontalLog2(u8 metatileBehavior)
bool8 MetatileBehavior_IsPacifidlogLog(u8 metatileBehavior)
{
if (metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_1 || metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_2
|| metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_1 || metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_2)
if (metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_1
|| metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_2
|| metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_1
|| metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_2)
return TRUE;
else
return FALSE;
@ -1243,9 +1262,13 @@ bool8 MetatileBehavior_IsAquaHideoutWarp(u8 metatileBehavior)
return FALSE;
}
bool8 MetatileBehavior_IsWarpOrBridge(u8 metatileBehavior)
// Very odd, used to initiate a teleport-style warp.
// No warp events seem to be on a metatile of this kind, and it's
// used by log bridges over ocean-style water, which wouldn't make
// sense to have a warp like this.
bool8 MetatileBehavior_IsBridgeOverOcean(u8 metatileBehavior)
{
if (metatileBehavior == MB_WARP_OR_BRIDGE)
if (metatileBehavior == MB_BRIDGE_OVER_OCEAN)
return TRUE;
else
return FALSE;
@ -1262,9 +1285,15 @@ bool8 MetatileBehavior_IsMossdeepGymWarp(u8 metatileBehavior)
bool8 MetatileBehavior_IsSurfableFishableWater(u8 metatileBehavior)
{
if (metatileBehavior == MB_POND_WATER || metatileBehavior == MB_OCEAN_WATER || metatileBehavior == MB_SEMI_DEEP_WATER || metatileBehavior == MB_DEEP_WATER
|| metatileBehavior == MB_SOOTOPOLIS_DEEP_WATER || (metatileBehavior == MB_EASTWARD_CURRENT || metatileBehavior == MB_WESTWARD_CURRENT
|| metatileBehavior == MB_NORTHWARD_CURRENT || metatileBehavior == MB_SOUTHWARD_CURRENT))
if (metatileBehavior == MB_POND_WATER
|| metatileBehavior == MB_OCEAN_WATER
|| metatileBehavior == MB_SEMI_DEEP_WATER
|| metatileBehavior == MB_DEEP_WATER
|| metatileBehavior == MB_SOOTOPOLIS_DEEP_WATER
|| (metatileBehavior == MB_EASTWARD_CURRENT
|| metatileBehavior == MB_WESTWARD_CURRENT
|| metatileBehavior == MB_NORTHWARD_CURRENT
|| metatileBehavior == MB_SOUTHWARD_CURRENT))
return TRUE;
else
return FALSE;

View File

@ -613,7 +613,7 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi
}
}
else if (MetatileBehavior_IsWaterWildEncounter(currMetaTileBehavior) == TRUE
|| (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING) && MetatileBehavior_IsBridge(currMetaTileBehavior) == TRUE))
|| (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING) && MetatileBehavior_IsBridgeOverWater(currMetaTileBehavior) == TRUE))
{
if (AreLegendariesInSootopolisPreventingEncounters() == TRUE)
return FALSE;