diff --git a/data/field_ground_effect.s b/data/field_ground_effect.s deleted file mode 100644 index d3dbceedb..000000000 --- a/data/field_ground_effect.s +++ /dev/null @@ -1,72 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - - .align 2 -gUnknown_08376040:: @ 8376040 - .4byte MetatileBehavior_IsJumpSouth - .4byte MetatileBehavior_IsJumpNorth - .4byte MetatileBehavior_IsJumpWest - .4byte MetatileBehavior_IsJumpEast - -gUnknown_08376050:: @ 8376050 - .byte 0x73, 0x73, 0x53, 0x73, 0x53, 0x73, 0x53, 0x73, 0x53, 0x73, 0x53, 0x73, 0x53, 0x00, 0x00, 0x73 - -@ Each byte corresponds to a sprite priority for a field object. -@ This is directly the inverse of gFieldObjectPriorities_08376070. -gFieldObjectPriorities_08376060:: @ 8376060 - .byte 2, 2, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0, 0, 2 - -@ Each byte corresponds to a sprite priority for a field object. -@ This is the inverse of gFieldObjectPriorities_08376060. -@ 1 = Above player sprite -@ 2 = Below player sprite -gFieldObjectPriorities_08376070:: @ 8376070 - .byte 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 0, 0, 1 - - .align 2 -gUnknown_08376080:: @ 8376080 - .4byte nullsub_50 - .4byte DoTracksGroundEffect_Footprints - .4byte DoTracksGroundEffect_BikeTireTracks - -@ First byte is a Field Effect script id. (gFieldEffectScriptPointers) -@ Last three bytes are unknown. -gSandFootprints_FieldEffectData:: @ 837608C - .byte 0xD, 0x0, 0x18, 0x0 - -@ Specifies which bike track shape to show next. -@ For example, when the bike turns from up to right, it will show -@ a track that curves to the right. -@ Each 4-byte row corresponds to the initial direction of the bike, and -@ each byte in that row is for the next direction of the bike in the order -@ of down, up, left, right. -gBikeTireTracks_Transitions:: @ 8376090 - .byte 1, 2, 7, 8 - .byte 1, 2, 6, 5 - .byte 5, 8, 3, 4 - .byte 6, 7, 3, 4 - - .align 2 -gUnknown_083760A0:: @ 83760A0 - .4byte GroundEffect_SpawnOnTallGrass - .4byte sub_8063E94 - .4byte sub_8063EE0 - .4byte sub_8063F2C - .4byte GroundEffect_WaterReflection - .4byte GroundEffect_IceReflection - .4byte GroundEffect_FlowingWater - .4byte sub_8063FA0 - .4byte sub_8063FCC - .4byte GroundEffect_Ripple - .4byte GroundEffect_StepOnPuddle - .4byte GroundEffect_SandPile - .4byte GroundEffect_JumpOnTallGrass - .4byte GroundEffect_JumpOnLongGrass - .4byte GroundEffect_JumpOnShallowWater - .4byte GroundEffect_JumpOnWater - .4byte GroundEffect_JumpLandingDust - .4byte GroundEffect_ShortGrass - .4byte GroundEffect_HotSprings - .4byte GroundEffect_Seaweed diff --git a/ld_script.txt b/ld_script.txt index 231951647..89753bc0e 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -351,7 +351,6 @@ SECTIONS { src/field_player_avatar.o(.rodata); src/field_map_obj.o(.rodata); src/field_ground_effect.o(.rodata); - data/field_ground_effect.o(.rodata); data/field_map_obj_helpers.o(.rodata); data/text_window.o(.rodata); src/script.o(.rodata); diff --git a/src/field_ground_effect.c b/src/field_ground_effect.c index 79729471c..1a06b80f6 100644 --- a/src/field_ground_effect.c +++ b/src/field_ground_effect.c @@ -6,15 +6,122 @@ #include "fieldmap.h" #include "metatile_behavior.h" -extern u32 gUnknown_08376008[]; -extern u8 (*gUnknown_08376040[4])(u32 a); -extern const u8 gFieldObjectPriorities_08376070[]; -extern const u8 gFieldObjectPriorities_08376060[]; -extern const u8 gUnknown_08376050[]; -extern void (*gUnknown_08376080[3])(struct MapObject *mapObj, struct Sprite *sprite, u8 a); -extern const u8 gSandFootprints_FieldEffectData[4]; -extern const u8 gBikeTireTracks_Transitions[4][4]; -extern void (*gUnknown_083760A0[0x14])(struct MapObject *mapObj, struct Sprite *sprite); +void nullsub_50(struct MapObject *mapObj, struct Sprite *sprite, u8); +void DoTracksGroundEffect_Footprints(struct MapObject *mapObj, struct Sprite *sprite, u8); +void DoTracksGroundEffect_BikeTireTracks(struct MapObject *mapObj, struct Sprite *sprite, u8); +void GroundEffect_SpawnOnTallGrass(struct MapObject *mapObj, struct Sprite *sprite); +void sub_8063E94(struct MapObject *mapObj, struct Sprite *sprite); +void sub_8063EE0(struct MapObject *mapObj, struct Sprite *sprite); +void sub_8063F2C(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_WaterReflection(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_IceReflection(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_FlowingWater(struct MapObject *mapObj, struct Sprite *sprite); +void sub_8063FA0(struct MapObject *mapObj, struct Sprite *sprite); +void sub_8063FCC(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_Ripple(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_StepOnPuddle(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_SandPile(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_JumpOnTallGrass(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_JumpOnLongGrass(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_JumpOnShallowWater(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_JumpOnWater(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_JumpLandingDust(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_ShortGrass(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_HotSprings(struct MapObject *mapObj, struct Sprite *sprite); +void GroundEffect_Seaweed(struct MapObject *mapObj, struct Sprite *sprite); + +static const u32 sReflectionFlags[2] = { 0x00000020, 0x00000010 }; + +typedef bool8 (*MetatileFunc)(u8); + +static const MetatileFunc metatileFuncs[] = { + MetatileBehavior_IsTallGrass, + MetatileBehavior_IsLongGrass, + MetatileBehavior_IsPuddle, + MetatileBehavior_IsSurfableWaterOrUnderwater, + MetatileBehavior_IsShallowFlowingWater, + MetatileBehavior_IsATile, +}; + +static const u32 jumpLandingFlags[] = { + 0x00001000, // Landing in tall grass + 0x00002000, // Landing in long grass + 0x00004000, // Landing on puddle + 0x00008000, // Landing on surfable water or underwater + 0x00004000, // Landing on shallow flowing water + 0x00010000, // Landing on any other type of ground +}; + +bool8 (*const gUnknown_08376040[])(u8) = { + MetatileBehavior_IsJumpSouth, + MetatileBehavior_IsJumpNorth, + MetatileBehavior_IsJumpWest, + MetatileBehavior_IsJumpEast, +}; + +const u8 gUnknown_08376050[] = { + 0x73, 0x73, 0x53, 0x73, 0x53, 0x73, 0x53, 0x73, 0x53, 0x73, 0x53, 0x73, 0x53, 0x00, 0x00, 0x73 +}; + +// Each byte corresponds to a sprite priority for a field object. +// This is directly the inverse of gFieldObjectPriorities_08376070. +const u8 gFieldObjectPriorities_08376060[] = { + 2, 2, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0, 0, 2 +}; + +// Each byte corresponds to a sprite priority for a field object. +// This is the inverse of gFieldObjectPriorities_08376060. +// 1 = Above player sprite +// 2 = Below player sprite +const u8 gFieldObjectPriorities_08376070[] = { + 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 0, 0, 1, +}; + +void (*const gUnknown_08376080[3])(struct MapObject *mapObj, struct Sprite *sprite, u8 a) = { + nullsub_50, + DoTracksGroundEffect_Footprints, + DoTracksGroundEffect_BikeTireTracks, +}; + +// First byte is a Field Effect script id. (gFieldEffectScriptPointers) +// Last three bytes are unknown. +const u8 gSandFootprints_FieldEffectData[4] = { 0xD, 0x0, 0x18, 0x0 }; + +// Specifies which bike track shape to show next. +// For example, when the bike turns from up to right, it will show +// a track that curves to the right. +// Each 4-byte row corresponds to the initial direction of the bike, and +// each byte in that row is for the next direction of the bike in the order +// of down, up, left, right. +const u8 gBikeTireTracks_Transitions[4][4] = { + 1, 2, 7, 8, + 1, 2, 6, 5, + 5, 8, 3, 4, + 6, 7, 3, 4, +}; + +void (*const gUnknown_083760A0[0x14])(struct MapObject *mapObj, struct Sprite *sprite) = { + GroundEffect_SpawnOnTallGrass, + sub_8063E94, + sub_8063EE0, + sub_8063F2C, + GroundEffect_WaterReflection, + GroundEffect_IceReflection, + GroundEffect_FlowingWater, + sub_8063FA0, + sub_8063FCC, + GroundEffect_Ripple, + GroundEffect_StepOnPuddle, + GroundEffect_SandPile, + GroundEffect_JumpOnTallGrass, + GroundEffect_JumpOnLongGrass, + GroundEffect_JumpOnShallowWater, + GroundEffect_JumpOnWater, + GroundEffect_JumpLandingDust, + GroundEffect_ShortGrass, + GroundEffect_HotSprings, + GroundEffect_Seaweed +}; #define NUM_GROUND_EFFECTS (sizeof(gUnknown_083760A0) / sizeof(gUnknown_083760A0[0])) @@ -65,8 +172,18 @@ void FieldObjectUpdateMetatileBehaviors(struct MapObject *mapObj) void GetGroundEffectFlags_Reflection(struct MapObject *mapObj, u32 *flags) { - u32 reflectionFlags[2] = { 0x00000020, 0x00000010 }; - u8 type = FieldObjectCheckForReflectiveSurface(mapObj); + u32 reflectionFlags[2]; + u32 a; u32 b; + u8 type; + + // Declaring sReflectionFlags inside the function is a neater match than + // this. + b = sReflectionFlags[1]; + a = sReflectionFlags[0]; + reflectionFlags[0] = a; + reflectionFlags[1] = b; + + type = FieldObjectCheckForReflectiveSurface(mapObj); if (type) { @@ -217,25 +334,7 @@ void GetGroundEffectFlags_Seaweed(struct MapObject *mapObj, u32 *flags) void GetGroundEffectFlags_JumpLanding(struct MapObject *mapObj, u32 *flags) { - typedef bool8 (*MetatileFunc)(u8); - static const MetatileFunc metatileFuncs[] = { - MetatileBehavior_IsTallGrass, - MetatileBehavior_IsLongGrass, - MetatileBehavior_IsPuddle, - MetatileBehavior_IsSurfableWaterOrUnderwater, - MetatileBehavior_IsShallowFlowingWater, - MetatileBehavior_IsATile, - }; - - static const u32 jumpLandingFlags[] = { - 0x00001000, // Landing in tall grass - 0x00002000, // Landing in long grass - 0x00004000, // Landing on puddle - 0x00008000, // Landing on surfable water or underwater - 0x00004000, // Landing on shallow flowing water - 0x00010000, // Landing on any other type of ground - }; if (mapObj->mapobj_bit_5 && !mapObj->mapobj_bit_25) { @@ -632,7 +731,7 @@ void GroundEffect_SpawnOnTallGrass(struct MapObject *mapObj, struct Sprite *spri FieldEffectStart(4); } -void sub_8063E94(struct MapObject *mapObj) +void sub_8063E94(struct MapObject *mapObj, struct Sprite *sprite) { u8 *ptr; @@ -651,7 +750,7 @@ void sub_8063E94(struct MapObject *mapObj) FieldEffectStart(4); } -void sub_8063EE0(struct MapObject *mapObj) +void sub_8063EE0(struct MapObject *mapObj, struct Sprite *sprite) { u8 *ptr; @@ -670,7 +769,7 @@ void sub_8063EE0(struct MapObject *mapObj) FieldEffectStart(17); } -void sub_8063F2C(struct MapObject *mapObj) +void sub_8063F2C(struct MapObject *mapObj, struct Sprite *sprite) { u8 *ptr; @@ -699,7 +798,7 @@ void GroundEffect_IceReflection(struct MapObject *mapObj, struct Sprite *sprite) SetUpReflection(mapObj, sprite, 1); } -void GroundEffect_FlowingWater(struct MapObject *mapObj) +void GroundEffect_FlowingWater(struct MapObject *mapObj, struct Sprite *sprite) { oe_exec_and_other_stuff(FLDEFF_FEET_IN_FLOWING_WATER, mapObj); } @@ -906,3 +1005,5 @@ void DoGroundEffects_OnFinishStep(struct MapObject *mapObj, struct Sprite *sprit mapObj->mapobj_bit_5 = 0; } } + +