Merge pull request #1312 from sphericalice/pokeemerald

Fix misnamed ground effect flags & document reflections
This commit is contained in:
GriffinR 2021-01-20 18:50:31 -05:00 committed by GitHub
commit 3ceb43177d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 56 deletions

View file

@ -16,14 +16,22 @@ enum SpinnerRunnerFollowPatterns
RUNFOLLOW_SOUTH_EAST_WEST
};
enum ReflectionTypes
{
REFL_TYPE_NONE,
REFL_TYPE_ICE,
REFL_TYPE_WATER,
NUM_REFLECTION_TYPES
};
#define FIGURE_8_LENGTH 72
#define GROUND_EFFECT_FLAG_TALL_GRASS_ON_SPAWN (1 << 0)
#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_MOVE (1 << 3)
#define GROUND_EFFECT_FLAG_ICE_REFLECTION (1 << 4)
#define GROUND_EFFECT_FLAG_REFLECTION (1 << 5)
#define GROUND_EFFECT_FLAG_WATER_REFLECTION (1 << 4)
#define GROUND_EFFECT_FLAG_ICE_REFLECTION (1 << 5)
#define GROUND_EFFECT_FLAG_SHALLOW_FLOWING_WATER (1 << 6)
#define GROUND_EFFECT_FLAG_SAND (1 << 7)
#define GROUND_EFFECT_FLAG_DEEP_SAND (1 << 8)
@ -414,10 +422,10 @@ u8 MovementType_RunInPlace_Step0(struct ObjectEvent *, struct Sprite *);
u8 MovementType_Invisible_Step0(struct ObjectEvent *, struct Sprite *);
u8 MovementType_Invisible_Step1(struct ObjectEvent *, struct Sprite *);
u8 MovementType_Invisible_Step2(struct ObjectEvent *, struct Sprite *);
void SetObjectEventSpriteInvisibility(u8 var, bool32 var2);
bool32 IsObjectEventSpriteInvisible(u8 var);
void SetObjectEventSpriteGraphics(u8 var1, u8 graphicsId);
void SetObjectEventSpriteAnim(u8 var1, u8 var2);
bool32 IsObjectEventSpriteAnimating(u8 var);
void SetObjectEventSpriteInvisibility(u8 objectEventId, bool32 invisible);
bool32 IsObjectEventSpriteInvisible(u8 objectEventId);
void SetObjectEventSpriteGraphics(u8 objectEventId, u8 graphicsId);
void SetObjectEventSpriteAnim(u8 objectEventId, u8 animNum);
bool32 IsObjectEventSpriteAnimating(u8 objectEventId);
#endif //GUARD_EVENT_OBJECT_MOVEMENT_H

View file

@ -87,7 +87,7 @@ static void GetGroundEffectFlags_Puddle(struct ObjectEvent*, u32*);
static void GetGroundEffectFlags_Ripple(struct ObjectEvent*, u32*);
static void GetGroundEffectFlags_Seaweed(struct ObjectEvent*, u32*);
static void GetGroundEffectFlags_JumpLanding(struct ObjectEvent*, u32*);
static u8 ObjectEventCheckForReflectiveSurface(struct ObjectEvent*);
static u8 ObjectEventGetNearbyReflectionType(struct ObjectEvent*);
static u8 GetReflectionTypeByMetatileBehavior(u32);
static void InitObjectPriorityByZCoord(struct Sprite *sprite, u8 z);
static void ObjectEventUpdateSubpriority(struct ObjectEvent*, struct Sprite*);
@ -7513,21 +7513,23 @@ static void ObjectEventUpdateMetatileBehaviors(struct ObjectEvent *objEvent)
static void GetGroundEffectFlags_Reflection(struct ObjectEvent *objEvent, u32 *flags)
{
u32 reflectionFlags[2] = { GROUND_EFFECT_FLAG_REFLECTION, GROUND_EFFECT_FLAG_ICE_REFLECTION };
u8 type = ObjectEventCheckForReflectiveSurface(objEvent);
u32 reflectionFlags[NUM_REFLECTION_TYPES - 1] = {
[REFL_TYPE_ICE - 1] = GROUND_EFFECT_FLAG_ICE_REFLECTION,
[REFL_TYPE_WATER - 1] = GROUND_EFFECT_FLAG_WATER_REFLECTION
};
u8 reflType = ObjectEventGetNearbyReflectionType(objEvent);
if (type)
if (reflType)
{
if (!objEvent->hasReflection)
if (objEvent->hasReflection == 0)
{
objEvent->hasReflection = 0;
objEvent->hasReflection = 1;
*flags |= reflectionFlags[type - 1];
objEvent->hasReflection++;
*flags |= reflectionFlags[reflType - 1];
}
}
else
{
objEvent->hasReflection = 0;
objEvent->hasReflection = FALSE;
}
}
@ -7700,26 +7702,24 @@ static void GetGroundEffectFlags_JumpLanding(struct ObjectEvent *objEvent, u32 *
}
}
static u8 ObjectEventCheckForReflectiveSurface(struct ObjectEvent *objEvent)
#define RETURN_REFLECTION_TYPE_AT(x, y) \
b = MapGridGetMetatileBehaviorAt(x, y); \
result = GetReflectionTypeByMetatileBehavior(b); \
if (result != REFL_TYPE_NONE) \
return result;
static u8 ObjectEventGetNearbyReflectionType(struct ObjectEvent *objEvent)
{
const struct ObjectEventGraphicsInfo *info = GetObjectEventGraphicsInfo(objEvent->graphicsId);
// ceil div by tile width?
s16 width = (info->width + 8) >> 4;
s16 height = (info->height + 8) >> 4;
s16 i;
s16 j;
u8 result;
u8 b;
s16 one;
s16 i, j;
u8 result, b; // used by RETURN_REFLECTION_TYPE_AT
s16 one = 1;
#define RETURN_REFLECTION_TYPE_AT(x, y) \
b = MapGridGetMetatileBehaviorAt(x, y); \
result = GetReflectionTypeByMetatileBehavior(b); \
if (result != 0) \
return result;
for (i = 0, one = 1; i < height; i++)
for (i = 0; i < height; i++)
{
RETURN_REFLECTION_TYPE_AT(objEvent->currentCoords.x, objEvent->currentCoords.y + one + i)
RETURN_REFLECTION_TYPE_AT(objEvent->previousCoords.x, objEvent->previousCoords.y + one + i)
@ -7731,19 +7731,20 @@ static u8 ObjectEventCheckForReflectiveSurface(struct ObjectEvent *objEvent)
RETURN_REFLECTION_TYPE_AT(objEvent->previousCoords.x - j, objEvent->previousCoords.y + one + i)
}
}
return 0;
return REFL_TYPE_NONE;
}
#undef RETURN_REFLECTION_TYPE_AT
}
static u8 GetReflectionTypeByMetatileBehavior(u32 behavior)
{
if (MetatileBehavior_IsIce(behavior))
return 1;
return REFL_TYPE_ICE;
else if (MetatileBehavior_IsReflective(behavior))
return 2;
return REFL_TYPE_WATER;
else
return 0;
return REFL_TYPE_NONE;
}
u8 GetLedgeJumpDirection(s16 x, s16 y, u8 z)
@ -7944,12 +7945,12 @@ void GroundEffect_StepOnLongGrass(struct ObjectEvent *objEvent, struct Sprite *s
void GroundEffect_WaterReflection(struct ObjectEvent *objEvent, struct Sprite *sprite)
{
SetUpReflection(objEvent, sprite, 0);
SetUpReflection(objEvent, sprite, FALSE);
}
void GroundEffect_IceReflection(struct ObjectEvent *objEvent, struct Sprite *sprite)
{
SetUpReflection(objEvent, sprite, 1);
SetUpReflection(objEvent, sprite, TRUE);
}
void GroundEffect_FlowingWater(struct ObjectEvent *objEvent, struct Sprite *sprite)
@ -8116,8 +8117,8 @@ static void (*const sGroundEffectFuncs[])(struct ObjectEvent *objEvent, struct S
GroundEffect_StepOnTallGrass, // GROUND_EFFECT_FLAG_TALL_GRASS_ON_MOVE
GroundEffect_SpawnOnLongGrass, // GROUND_EFFECT_FLAG_LONG_GRASS_ON_SPAWN
GroundEffect_StepOnLongGrass, // GROUND_EFFECT_FLAG_LONG_GRASS_ON_MOVE
GroundEffect_WaterReflection, // GROUND_EFFECT_FLAG_ICE_REFLECTION
GroundEffect_IceReflection, // GROUND_EFFECT_FLAG_REFLECTION
GroundEffect_WaterReflection, // GROUND_EFFECT_FLAG_WATER_REFLECTION
GroundEffect_IceReflection, // GROUND_EFFECT_FLAG_ICE_REFLECTION
GroundEffect_FlowingWater, // GROUND_EFFECT_FLAG_SHALLOW_FLOWING_WATER
GroundEffect_SandTracks, // GROUND_EFFECT_FLAG_SAND
GroundEffect_DeepSandTracks, // GROUND_EFFECT_FLAG_DEEP_SAND
@ -8648,14 +8649,14 @@ static void DestroyObjectEventSprites(void)
}
}
static int GetObjectEventSpriteId(u8 var) // this should return a u8, because all that call this shifts to u8, but it wont match because it doesnt shift u8 at the end.
static int GetObjectEventSpriteId(u8 objectEventId) // this should return a u8, because all that call this shifts to u8, but it wont match because it doesnt shift u8 at the end.
{
int i;
for (i = 0; i < MAX_SPRITES; i++)
{
struct Sprite *sprite = &gSprites[i];
if(sprite->inUse && sprite->callback == UpdateObjectEventSprite && (u8)sprite->data[0] == var)
if (sprite->inUse && sprite->callback == UpdateObjectEventSprite && (u8)sprite->data[0] == objectEventId)
return i;
}
return MAX_SPRITES;
@ -8787,9 +8788,9 @@ static void UpdateObjectEventSpritePosition(struct Sprite *sprite)
}
}
bool32 IsObjectEventSpriteAnimating(u8 var)
bool32 IsObjectEventSpriteAnimating(u8 objectEventId)
{
u8 spriteId = GetObjectEventSpriteId(var);
u8 spriteId = GetObjectEventSpriteId(objectEventId);
if (spriteId == MAX_SPRITES)
return FALSE;

View file

@ -32,6 +32,11 @@ static void CreateBobbingEffect(struct ObjectEvent *, struct Sprite *, struct Sp
static void sub_8155850(struct Sprite *);
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)
{
struct Sprite *reflectionSprite;
@ -46,9 +51,9 @@ void SetUpReflection(struct ObjectEvent *objectEvent, struct Sprite *sprite, boo
reflectionSprite->affineAnims = gDummySpriteAffineAnimTable;
reflectionSprite->affineAnimBeginning = TRUE;
reflectionSprite->subspriteMode = SUBSPRITES_OFF;
reflectionSprite->data[0] = sprite->data[0];
reflectionSprite->data[1] = objectEvent->localId;
reflectionSprite->data[7] = stillReflection;
reflectionSprite->sReflectionObjEventId = sprite->data[0];
reflectionSprite->sReflectionObjEventLocalId = objectEvent->localId;
reflectionSprite->sIsStillReflection = stillReflection;
LoadObjectReflectionPalette(objectEvent, reflectionSprite);
if (!stillReflection)
@ -60,19 +65,19 @@ static s16 GetReflectionVerticalOffset(struct ObjectEvent *objectEvent)
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;
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))))
{
sprite->data[2] = bridgeReflectionVerticalOffsets[bridgeType - 1];
LoadObjectHighBridgeReflectionPalette(objectEvent, sprite->oam.paletteNum);
reflectionSprite->sReflectionVerticalOffset = bridgeReflectionVerticalOffsets[bridgeType - 1];
LoadObjectHighBridgeReflectionPalette(objectEvent, reflectionSprite->oam.paletteNum);
}
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 Sprite *mainSprite;
objectEvent = &gObjectEvents[reflectionSprite->data[0]];
objectEvent = &gObjectEvents[reflectionSprite->sReflectionObjEventId];
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;
}
@ -135,8 +140,7 @@ static void UpdateObjectReflectionSprite(struct Sprite *reflectionSprite)
reflectionSprite->subspriteTableNum = mainSprite->subspriteTableNum;
reflectionSprite->invisible = mainSprite->invisible;
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->data[2];
reflectionSprite->pos1.y = mainSprite->pos1.y + GetReflectionVerticalOffset(objectEvent) + reflectionSprite->sReflectionVerticalOffset;
reflectionSprite->centerToCornerVecX = mainSprite->centerToCornerVecX;
reflectionSprite->centerToCornerVecY = mainSprite->centerToCornerVecY;
reflectionSprite->pos2.x = mainSprite->pos2.x;
@ -146,8 +150,7 @@ static void UpdateObjectReflectionSprite(struct Sprite *reflectionSprite)
if (objectEvent->hideReflection == TRUE)
reflectionSprite->invisible = TRUE;
// Check if the reflection is not still.
if (reflectionSprite->data[7] == FALSE)
if (reflectionSprite->sIsStillReflection == FALSE)
{
// Sets the reflection sprite's rot/scale matrix to the appropriate
// 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[];
u8 CreateWarpArrowSprite(void)