Correct ground effect flag names for reflections & document sprite data usage

This commit is contained in:
SphericalIce
2021-01-19 23:21:50 +00:00
parent 2dfaba9472
commit 6dd973012b
3 changed files with 48 additions and 30 deletions
+10 -2
View File
@@ -16,14 +16,22 @@ enum SpinnerRunnerFollowPatterns
RUNFOLLOW_SOUTH_EAST_WEST RUNFOLLOW_SOUTH_EAST_WEST
}; };
enum ReflectionTypes
{
REFL_TYPE_NONE,
REFL_TYPE_ICE,
REFL_TYPE_WATER
};
#define NUM_REFLECTION_TYPES 2
#define FIGURE_8_LENGTH 72 #define FIGURE_8_LENGTH 72
#define GROUND_EFFECT_FLAG_TALL_GRASS_ON_SPAWN (1 << 0) #define GROUND_EFFECT_FLAG_TALL_GRASS_ON_SPAWN (1 << 0)
#define GROUND_EFFECT_FLAG_TALL_GRASS_ON_MOVE (1 << 1) #define GROUND_EFFECT_FLAG_TALL_GRASS_ON_MOVE (1 << 1)
#define GROUND_EFFECT_FLAG_LONG_GRASS_ON_SPAWN (1 << 2) #define GROUND_EFFECT_FLAG_LONG_GRASS_ON_SPAWN (1 << 2)
#define GROUND_EFFECT_FLAG_LONG_GRASS_ON_MOVE (1 << 3) #define GROUND_EFFECT_FLAG_LONG_GRASS_ON_MOVE (1 << 3)
#define GROUND_EFFECT_FLAG_ICE_REFLECTION (1 << 4) #define GROUND_EFFECT_FLAG_WATER_REFLECTION (1 << 4)
#define GROUND_EFFECT_FLAG_REFLECTION (1 << 5) #define GROUND_EFFECT_FLAG_ICE_REFLECTION (1 << 5)
#define GROUND_EFFECT_FLAG_SHALLOW_FLOWING_WATER (1 << 6) #define GROUND_EFFECT_FLAG_SHALLOW_FLOWING_WATER (1 << 6)
#define GROUND_EFFECT_FLAG_SAND (1 << 7) #define GROUND_EFFECT_FLAG_SAND (1 << 7)
#define GROUND_EFFECT_FLAG_DEEP_SAND (1 << 8) #define GROUND_EFFECT_FLAG_DEEP_SAND (1 << 8)
+16 -14
View File
@@ -87,7 +87,7 @@ static void GetGroundEffectFlags_Puddle(struct ObjectEvent*, u32*);
static void GetGroundEffectFlags_Ripple(struct ObjectEvent*, u32*); static void GetGroundEffectFlags_Ripple(struct ObjectEvent*, u32*);
static void GetGroundEffectFlags_Seaweed(struct ObjectEvent*, u32*); static void GetGroundEffectFlags_Seaweed(struct ObjectEvent*, u32*);
static void GetGroundEffectFlags_JumpLanding(struct ObjectEvent*, u32*); static void GetGroundEffectFlags_JumpLanding(struct ObjectEvent*, u32*);
static u8 ObjectEventCheckForReflectiveSurface(struct ObjectEvent*); static u8 GetObjEventReflectionType(struct ObjectEvent*);
static u8 GetReflectionTypeByMetatileBehavior(u32); static u8 GetReflectionTypeByMetatileBehavior(u32);
static void InitObjectPriorityByZCoord(struct Sprite *sprite, u8 z); static void InitObjectPriorityByZCoord(struct Sprite *sprite, u8 z);
static void ObjectEventUpdateSubpriority(struct ObjectEvent*, struct Sprite*); static void ObjectEventUpdateSubpriority(struct ObjectEvent*, struct Sprite*);
@@ -7514,21 +7514,23 @@ static void ObjectEventUpdateMetatileBehaviors(struct ObjectEvent *objEvent)
static void GetGroundEffectFlags_Reflection(struct ObjectEvent *objEvent, u32 *flags) static void GetGroundEffectFlags_Reflection(struct ObjectEvent *objEvent, u32 *flags)
{ {
u32 reflectionFlags[2] = { GROUND_EFFECT_FLAG_REFLECTION, GROUND_EFFECT_FLAG_ICE_REFLECTION }; u32 reflectionFlags[NUM_REFLECTION_TYPES] = {
u8 type = ObjectEventCheckForReflectiveSurface(objEvent); [REFL_TYPE_ICE - 1] = GROUND_EFFECT_FLAG_ICE_REFLECTION,
[REFL_TYPE_WATER - 1] = GROUND_EFFECT_FLAG_WATER_REFLECTION
};
u8 reflType = GetObjEventReflectionType(objEvent);
if (type) if (reflType)
{ {
if (!objEvent->hasReflection) if (!objEvent->hasReflection)
{ {
objEvent->hasReflection = 0; objEvent->hasReflection |= TRUE;
objEvent->hasReflection = 1; *flags |= reflectionFlags[reflType - 1];
*flags |= reflectionFlags[type - 1];
} }
} }
else else
{ {
objEvent->hasReflection = 0; objEvent->hasReflection = FALSE;
} }
} }
@@ -7701,7 +7703,7 @@ static void GetGroundEffectFlags_JumpLanding(struct ObjectEvent *objEvent, u32 *
} }
} }
static u8 ObjectEventCheckForReflectiveSurface(struct ObjectEvent *objEvent) static u8 GetObjEventReflectionType(struct ObjectEvent *objEvent)
{ {
const struct ObjectEventGraphicsInfo *info = GetObjectEventGraphicsInfo(objEvent->graphicsId); const struct ObjectEventGraphicsInfo *info = GetObjectEventGraphicsInfo(objEvent->graphicsId);
@@ -7740,11 +7742,11 @@ static u8 ObjectEventCheckForReflectiveSurface(struct ObjectEvent *objEvent)
static u8 GetReflectionTypeByMetatileBehavior(u32 behavior) static u8 GetReflectionTypeByMetatileBehavior(u32 behavior)
{ {
if (MetatileBehavior_IsIce(behavior)) if (MetatileBehavior_IsIce(behavior))
return 1; return REFL_TYPE_ICE;
else if (MetatileBehavior_IsReflective(behavior)) else if (MetatileBehavior_IsReflective(behavior))
return 2; return REFL_TYPE_WATER;
else else
return 0; return REFL_TYPE_NONE;
} }
u8 GetLedgeJumpDirection(s16 x, s16 y, u8 z) u8 GetLedgeJumpDirection(s16 x, s16 y, u8 z)
@@ -8117,8 +8119,8 @@ static void (*const sGroundEffectFuncs[])(struct ObjectEvent *objEvent, struct S
GroundEffect_StepOnTallGrass, // GROUND_EFFECT_FLAG_TALL_GRASS_ON_MOVE GroundEffect_StepOnTallGrass, // GROUND_EFFECT_FLAG_TALL_GRASS_ON_MOVE
GroundEffect_SpawnOnLongGrass, // GROUND_EFFECT_FLAG_LONG_GRASS_ON_SPAWN GroundEffect_SpawnOnLongGrass, // GROUND_EFFECT_FLAG_LONG_GRASS_ON_SPAWN
GroundEffect_StepOnLongGrass, // GROUND_EFFECT_FLAG_LONG_GRASS_ON_MOVE GroundEffect_StepOnLongGrass, // GROUND_EFFECT_FLAG_LONG_GRASS_ON_MOVE
GroundEffect_WaterReflection, // GROUND_EFFECT_FLAG_ICE_REFLECTION GroundEffect_WaterReflection, // GROUND_EFFECT_FLAG_WATER_REFLECTION
GroundEffect_IceReflection, // GROUND_EFFECT_FLAG_REFLECTION GroundEffect_IceReflection, // GROUND_EFFECT_FLAG_ICE_REFLECTION
GroundEffect_FlowingWater, // GROUND_EFFECT_FLAG_SHALLOW_FLOWING_WATER GroundEffect_FlowingWater, // GROUND_EFFECT_FLAG_SHALLOW_FLOWING_WATER
GroundEffect_SandTracks, // GROUND_EFFECT_FLAG_SAND GroundEffect_SandTracks, // GROUND_EFFECT_FLAG_SAND
GroundEffect_DeepSandTracks, // GROUND_EFFECT_FLAG_DEEP_SAND GroundEffect_DeepSandTracks, // GROUND_EFFECT_FLAG_DEEP_SAND
+22 -14
View File
@@ -32,6 +32,11 @@ static void CreateBobbingEffect(struct ObjectEvent *, struct Sprite *, struct Sp
static void sub_8155850(struct Sprite *); static void sub_8155850(struct Sprite *);
static u32 ShowDisguiseFieldEffect(u8, u8, u8); static u32 ShowDisguiseFieldEffect(u8, u8, u8);
#define sReflectionObjEventId data[0]
#define sReflectionObjEventLocalId data[1]
#define sReflectionVerticalOffset data[2]
#define sIsStillReflection data[7]
void SetUpReflection(struct ObjectEvent *objectEvent, struct Sprite *sprite, bool8 stillReflection) void SetUpReflection(struct ObjectEvent *objectEvent, struct Sprite *sprite, bool8 stillReflection)
{ {
struct Sprite *reflectionSprite; struct Sprite *reflectionSprite;
@@ -46,9 +51,9 @@ void SetUpReflection(struct ObjectEvent *objectEvent, struct Sprite *sprite, boo
reflectionSprite->affineAnims = gDummySpriteAffineAnimTable; reflectionSprite->affineAnims = gDummySpriteAffineAnimTable;
reflectionSprite->affineAnimBeginning = TRUE; reflectionSprite->affineAnimBeginning = TRUE;
reflectionSprite->subspriteMode = SUBSPRITES_OFF; reflectionSprite->subspriteMode = SUBSPRITES_OFF;
reflectionSprite->data[0] = sprite->data[0]; reflectionSprite->sReflectionObjEventId = sprite->data[0];
reflectionSprite->data[1] = objectEvent->localId; reflectionSprite->sReflectionObjEventLocalId = objectEvent->localId;
reflectionSprite->data[7] = stillReflection; reflectionSprite->sIsStillReflection = stillReflection;
LoadObjectReflectionPalette(objectEvent, reflectionSprite); LoadObjectReflectionPalette(objectEvent, reflectionSprite);
if (!stillReflection) if (!stillReflection)
@@ -60,19 +65,19 @@ static s16 GetReflectionVerticalOffset(struct ObjectEvent *objectEvent)
return GetObjectEventGraphicsInfo(objectEvent->graphicsId)->height - 2; return GetObjectEventGraphicsInfo(objectEvent->graphicsId)->height - 2;
} }
static void LoadObjectReflectionPalette(struct ObjectEvent *objectEvent, struct Sprite *sprite) static void LoadObjectReflectionPalette(struct ObjectEvent *objectEvent, struct Sprite *reflectionSprite)
{ {
u8 bridgeType; u8 bridgeType;
u16 bridgeReflectionVerticalOffsets[] = { 12, 28, 44 }; u16 bridgeReflectionVerticalOffsets[] = { 12, 28, 44 };
sprite->data[2] = 0; 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))))
{ {
sprite->data[2] = bridgeReflectionVerticalOffsets[bridgeType - 1]; reflectionSprite->sReflectionVerticalOffset = bridgeReflectionVerticalOffsets[bridgeType - 1];
LoadObjectHighBridgeReflectionPalette(objectEvent, sprite->oam.paletteNum); LoadObjectHighBridgeReflectionPalette(objectEvent, reflectionSprite->oam.paletteNum);
} }
else else
{ {
LoadObjectRegularReflectionPalette(objectEvent, sprite->oam.paletteNum); LoadObjectRegularReflectionPalette(objectEvent, reflectionSprite->oam.paletteNum);
} }
} }
@@ -118,9 +123,9 @@ static void UpdateObjectReflectionSprite(struct Sprite *reflectionSprite)
struct ObjectEvent *objectEvent; struct ObjectEvent *objectEvent;
struct Sprite *mainSprite; struct Sprite *mainSprite;
objectEvent = &gObjectEvents[reflectionSprite->data[0]]; objectEvent = &gObjectEvents[reflectionSprite->sReflectionObjEventId];
mainSprite = &gSprites[objectEvent->spriteId]; mainSprite = &gSprites[objectEvent->spriteId];
if (!objectEvent->active || !objectEvent->hasReflection || objectEvent->localId != reflectionSprite->data[1]) if (!objectEvent->active || !objectEvent->hasReflection || objectEvent->localId != reflectionSprite->sReflectionObjEventLocalId)
{ {
reflectionSprite->inUse = FALSE; reflectionSprite->inUse = FALSE;
} }
@@ -135,8 +140,7 @@ static void UpdateObjectReflectionSprite(struct Sprite *reflectionSprite)
reflectionSprite->subspriteTableNum = mainSprite->subspriteTableNum; reflectionSprite->subspriteTableNum = mainSprite->subspriteTableNum;
reflectionSprite->invisible = mainSprite->invisible; reflectionSprite->invisible = mainSprite->invisible;
reflectionSprite->pos1.x = mainSprite->pos1.x; reflectionSprite->pos1.x = mainSprite->pos1.x;
// reflectionSprite->data[2] holds an additional vertical offset, used by the high bridges on Route 120 reflectionSprite->pos1.y = mainSprite->pos1.y + GetReflectionVerticalOffset(objectEvent) + reflectionSprite->sReflectionVerticalOffset;
reflectionSprite->pos1.y = mainSprite->pos1.y + GetReflectionVerticalOffset(objectEvent) + reflectionSprite->data[2];
reflectionSprite->centerToCornerVecX = mainSprite->centerToCornerVecX; reflectionSprite->centerToCornerVecX = mainSprite->centerToCornerVecX;
reflectionSprite->centerToCornerVecY = mainSprite->centerToCornerVecY; reflectionSprite->centerToCornerVecY = mainSprite->centerToCornerVecY;
reflectionSprite->pos2.x = mainSprite->pos2.x; reflectionSprite->pos2.x = mainSprite->pos2.x;
@@ -146,8 +150,7 @@ static void UpdateObjectReflectionSprite(struct Sprite *reflectionSprite)
if (objectEvent->hideReflection == TRUE) if (objectEvent->hideReflection == TRUE)
reflectionSprite->invisible = TRUE; reflectionSprite->invisible = TRUE;
// Check if the reflection is not still. if (reflectionSprite->sIsStillReflection == FALSE)
if (reflectionSprite->data[7] == FALSE)
{ {
// Sets the reflection sprite's rot/scale matrix to the appropriate // Sets the reflection sprite's rot/scale matrix to the appropriate
// matrix based on whether or not the main sprite is horizontally flipped. // matrix based on whether or not the main sprite is horizontally flipped.
@@ -159,6 +162,11 @@ static void UpdateObjectReflectionSprite(struct Sprite *reflectionSprite)
} }
} }
#undef sReflectionObjEventId
#undef sReflectionObjEventLocalId
#undef sReflectionVerticalOffset
#undef sIsStillReflection
extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[]; extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[];
u8 CreateWarpArrowSprite(void) u8 CreateWarpArrowSprite(void)