diff --git a/asm/field_screen.s b/asm/field_screen.s index c11aef1b4..8a97644ac 100644 --- a/asm/field_screen.s +++ b/asm/field_screen.s @@ -7851,7 +7851,7 @@ palette_bg_faded_fill_black: @ 80AF020 thumb_func_start pal_fill_for_maplights pal_fill_for_maplights: @ 80AF040 push {r4,lr} - bl get_map_light_from_warp0 + bl GetLastUsedWarpMapType adds r4, r0, 0 lsls r4, 24 lsrs r4, 24 diff --git a/asm/fldeff_80F9BCC.s b/asm/fldeff_80F9BCC.s index 3cfbe215a..a361faa32 100644 --- a/asm/fldeff_80F9BCC.s +++ b/asm/fldeff_80F9BCC.s @@ -2262,8 +2262,8 @@ _080FAEA2: bx r0 thumb_func_end task50_overworld_poison_effect - thumb_func_start overworld_poison_effect -overworld_poison_effect: @ 80FAEA8 + thumb_func_start FldeffPoison_Start +FldeffPoison_Start: @ 80FAEA8 push {lr} movs r0, 0x4F bl PlaySE @@ -2273,7 +2273,7 @@ overworld_poison_effect: @ 80FAEA8 pop {r0} bx r0 .pool - thumb_func_end overworld_poison_effect + thumb_func_end FldeffPoison_Start thumb_func_start FieldPoisonEffectIsRunning FieldPoisonEffectIsRunning: @ 80FAEC0 diff --git a/common_syms/field_camera.txt b/common_syms/field_camera.txt index 615026aee..02301ce23 100644 --- a/common_syms/field_camera.txt +++ b/common_syms/field_camera.txt @@ -1,3 +1,3 @@ -gUnknown_03005DD0 -gUnknown_03005DE8 -gUnknown_03005DEC +gFieldCamera +gTotalCameraPixelOffsetY +gTotalCameraPixelOffsetX diff --git a/data/event_scripts.s b/data/event_scripts.s index 8fb50a92b..c2926ce92 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -3325,7 +3325,7 @@ EventScript_2736B3:: @ 82736B3 EventScript_Poison:: @ 82736BC lockall - special sub_80F972C + special ExecuteWhiteOut waitstate compare VAR_RESULT, 1 goto_eq EventScript_2736D9 diff --git a/data/specials.inc b/data/specials.inc index 5c1653d49..a06b98b3d 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -210,7 +210,7 @@ gSpecials:: @ 81DBA64 def_special ShowLinkBattleRecords def_special IsEnoughForCostInVar0x8005 def_special SubtractMoneyFromVar0x8005 - def_special sub_80F972C + def_special ExecuteWhiteOut def_special sp0C8_whiteout_maybe def_special RotatingGate_InitPuzzle def_special RotatingGate_InitPuzzleAndGraphics diff --git a/include/berry.h b/include/berry.h index 1a8b7fa25..bef56ae41 100644 --- a/include/berry.h +++ b/include/berry.h @@ -1,6 +1,8 @@ #ifndef GUARD_BERRY_H #define GUARD_BERRY_H +#define BERRY_NONE 0 + enum { BERRY_FIRMNESS_UNKNOWN, @@ -21,6 +23,17 @@ enum FLAVOR_COUNT }; +enum +{ + BERRY_STAGE_NO_BERRY, // there is no tree planted and the soil is completely flat. + BERRY_STAGE_PLANTED, + BERRY_STAGE_SPROUTED, + BERRY_STAGE_TALLER, + BERRY_STAGE_FLOWERING, + BERRY_STAGE_BERRIES, + BERRY_STAGE_SPARKLING = 0xFF, +}; + #define NUM_BERRIES 44 extern const u8 *const gBerryTreeEventObjectGraphicsIdTablePointers[]; @@ -29,7 +42,6 @@ extern const u8 *const gBerryTreePaletteSlotTablePointers[]; void ClearEnigmaBerries(void); void SetEnigmaBerry(u8 *src); -u32 GetEnigmaBerryChecksum(struct EnigmaBerry *enigmaBerry); bool32 IsEnigmaBerryValid(void); const struct Berry *GetBerryInfo(u8 berry); struct BerryTree *GetBerryTreeInfo(u8 id); @@ -37,28 +49,20 @@ bool32 EventObjectInteractionWaterBerryTree(void); bool8 IsPlayerFacingPlantedBerryTree(void); bool8 TryToWaterBerryTree(void); void ClearBerryTrees(void); -bool32 BerryTreeGrow(struct BerryTree *tree); void BerryTreeTimeUpdate(s32 minutes); void PlantBerryTree(u8 id, u8 berry, u8 stage, bool8 sparkle); void RemoveBerryTree(u8 id); u8 GetBerryTypeByBerryTreeId(u8 id); u8 GetStageByBerryTreeId(u8); u8 ItemIdToBerryType(u16 item); -u16 BerryTypeToItemId(u16 berry); void GetBerryNameByBerryType(u8 berry, u8 *string); void ResetBerryTreeSparkleFlag(u8 id); -u8 BerryTreeGetNumStagesWatered(struct BerryTree *tree); -u8 GetNumStagesWateredByBerryTreeId(u8 id); -u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water); -u8 CalcBerryYield(struct BerryTree *tree); -u8 GetBerryCountByBerryTreeId(u8 id); -u16 GetStageDurationByBerryType(u8); void Bag_ChooseBerry(void); void EventObjectInteractionGetBerryTreeData(void); void EventObjectInteractionPlantBerryTree(void); void EventObjectInteractionPickBerryTree(void); void EventObjectInteractionRemoveBerryTree(void); -u8 PlayerHasBerries(void); +bool8 PlayerHasBerries(void); void ResetBerryTreeSparkleFlags(void); extern const struct Berry gBerries[]; diff --git a/include/event_object_movement.h b/include/event_object_movement.h index 6d38d072d..6515791c3 100644 --- a/include/event_object_movement.h +++ b/include/event_object_movement.h @@ -75,14 +75,14 @@ struct PairedPalettes struct LockedAnimEventObjects { - u8 eventObjectIds[NUM_EVENT_OBJECTS]; + u8 eventObjectIds[EVENT_OBJECTS_COUNT]; u8 count; }; extern const struct SpriteFrameImage gEventObjectPicTable_PechaBerryTree[]; extern const u8 gReflectionEffectPaletteMap[]; -void sub_808D438(void); +void ResetEventObjects(void); u8 GetMoveDirectionAnimNum(u8); u8 GetEventObjectIdByLocalIdAndMap(u8, u8, u8); bool8 TryGetEventObjectIdByLocalIdAndMap(u8, u8, u8, u8 *); @@ -180,9 +180,7 @@ u8 ZCoordToPriority(u8); void EventObjectUpdateZCoord(struct EventObject *pObject); void SetObjectSubpriorityByZCoord(u8, struct Sprite *, u8); bool8 IsZCoordMismatchAt(u8, s16, s16); -void UpdateEventObjectSpriteSubpriorityAndVisibility(struct Sprite *); void UnfreezeEventObject(struct EventObject *); -void oamt_npc_ministep_reset(struct Sprite *, u8, u8); u8 FindLockedEventObjectIndex(struct EventObject *); bool8 obj_npc_ministep(struct Sprite *sprite); bool8 sub_80976EC(struct Sprite *sprite); diff --git a/include/field_camera.h b/include/field_camera.h index fcc19ce9a..fdc4c5450 100644 --- a/include/field_camera.h +++ b/include/field_camera.h @@ -7,16 +7,16 @@ struct CameraObject { void (*callback)(struct CameraObject *); u32 spriteId; - s32 unk8; - s32 unkC; + s32 movementSpeedX; + s32 movementSpeedY; s32 x; s32 y; }; // Exported RAM declarations -extern struct CameraObject gUnknown_03005DD0; -extern u16 gUnknown_03005DEC; -extern u16 gUnknown_03005DE8; +extern struct CameraObject gFieldCamera; +extern u16 gTotalCameraPixelOffsetX; +extern u16 gTotalCameraPixelOffsetY; // Exported ROM declarations void DrawWholeMapView(void); diff --git a/include/field_control_avatar.h b/include/field_control_avatar.h index 536f218a3..24adbe4b3 100644 --- a/include/field_control_avatar.h +++ b/include/field_control_avatar.h @@ -25,7 +25,7 @@ struct FieldInput void FieldClearPlayerInput(struct FieldInput *pStruct); void FieldGetPlayerInput(struct FieldInput *pStruct, u16 keys, u16 heldKeys); -int sub_809C014(struct FieldInput *pStruct); +int ProcessPlayerFieldInput(struct FieldInput *pStruct); u8 *sub_80682A8(struct MapPosition *, u8, u8); void overworld_poison_timer_set(void); void RestartWildEncounterImmunitySteps(void); diff --git a/include/field_effect.h b/include/field_effect.h index 3fa39aae0..2881a2cd7 100644 --- a/include/field_effect.h +++ b/include/field_effect.h @@ -179,8 +179,8 @@ bool8 sub_80B7B94(struct Task *, struct EventObject *, struct Sprite *); bool8 sub_80B7BCC(struct Task *, struct EventObject *, struct Sprite *); bool8 sub_80B7BF4(struct Task *, struct EventObject *, struct Sprite *); -void sub_80B7D14(struct Task *); -void sub_80B7D34(struct Task *); +static void EscapeRopeFieldEffect_Step0(struct Task *); +static void EscapeRopeFieldEffect_Step1(struct Task *); void sub_80B7EC4(struct Task *); void sub_80B7EE8(struct Task *); diff --git a/include/field_effect_helpers.h b/include/field_effect_helpers.h index 223350042..6022467e4 100644 --- a/include/field_effect_helpers.h +++ b/include/field_effect_helpers.h @@ -18,7 +18,7 @@ u8 FindTallGrassFieldEffectSpriteId(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s void sub_8155F80(struct Sprite*); void UpdateShadowFieldEffect(struct Sprite*); void UpdateTallGrassFieldEffect(struct Sprite*); -void sub_81561D0(struct Sprite*); +void WaitFieldEffectSpriteAnim(struct Sprite*); void UpdateAshFieldEffect(struct Sprite*); void UpdateSurfBlobFieldEffect(struct Sprite*); void sub_8156194(struct Sprite*); diff --git a/include/field_poison.h b/include/field_poison.h index 6a1ba17f2..a23a93ca5 100644 --- a/include/field_poison.h +++ b/include/field_poison.h @@ -13,7 +13,7 @@ enum { FLDPSN_FNT }; -void sub_80F972C(void); -int DoPoisonFieldEffect(void); +void ExecuteWhiteOut(void); +s32 DoPoisonFieldEffect(void); #endif //GUARD_FIELD_POISON_H diff --git a/include/fldeff_80F9BCC.h b/include/fldeff_80F9BCC.h index 87a20d290..027bb4273 100644 --- a/include/fldeff_80F9BCC.h +++ b/include/fldeff_80F9BCC.h @@ -11,7 +11,7 @@ void sub_80FA5E4(s16 id, s16 x, s16 y); void sub_80FA794(s16 x, s16 y); void CreateRecordMixingSprite(void); void DestroyRecordMixingSprite(void); -void overworld_poison_effect(void); +void FldeffPoison_Start(void); void sub_80FA970(s16); void sub_80FA9D0(void); bool8 sub_80FADE4(u16, u8); diff --git a/include/fldeff_teleport.h b/include/fldeff_teleport.h deleted file mode 100644 index 71fb64ad2..000000000 --- a/include/fldeff_teleport.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef GUARD_FLDEFF_TELEPORT_H -#define GUARD_FLDEFF_TELEPORT_H - -void hm_teleport_run_dp02scr(void); -void sub_817C94C(void); - -#endif // GUARD_FLDEFF_TELEPORT_H diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index bb120c62c..f6273e80d 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -1,8 +1,6 @@ #ifndef GUARD_GLOBAL_FIELDMAP_H #define GUARD_GLOBAL_FIELDMAP_H -#define NUM_EVENT_OBJECTS 16 - enum { CONNECTION_SOUTH = 1, @@ -228,14 +226,14 @@ struct EventObjectGraphicsInfo /*0x20*/ const union AffineAnimCmd *const *affineAnims; }; -#define PLAYER_AVATAR_FLAG_ON_FOOT (1 << 0) -#define PLAYER_AVATAR_FLAG_MACH_BIKE (1 << 1) -#define PLAYER_AVATAR_FLAG_ACRO_BIKE (1 << 2) -#define PLAYER_AVATAR_FLAG_SURFING (1 << 3) +#define PLAYER_AVATAR_FLAG_ON_FOOT (1 << 0) +#define PLAYER_AVATAR_FLAG_MACH_BIKE (1 << 1) +#define PLAYER_AVATAR_FLAG_ACRO_BIKE (1 << 2) +#define PLAYER_AVATAR_FLAG_SURFING (1 << 3) #define PLAYER_AVATAR_FLAG_UNDERWATER (1 << 4) -#define PLAYER_AVATAR_FLAG_5 (1 << 5) -#define PLAYER_AVATAR_FLAG_6 (1 << 6) -#define PLAYER_AVATAR_FLAG_DASH (1 << 7) +#define PLAYER_AVATAR_FLAG_5 (1 << 5) +#define PLAYER_AVATAR_FLAG_6 (1 << 6) +#define PLAYER_AVATAR_FLAG_DASH (1 << 7) enum { @@ -311,7 +309,7 @@ struct Camera s32 y; }; -extern struct EventObject gEventObjects[NUM_EVENT_OBJECTS]; +extern struct EventObject gEventObjects[EVENT_OBJECTS_COUNT]; extern u8 gSelectedEventObject; extern struct MapHeader gMapHeader; extern struct PlayerAvatar gPlayerAvatar; diff --git a/include/global.h b/include/global.h index c2b139e7a..216805f5c 100644 --- a/include/global.h +++ b/include/global.h @@ -119,22 +119,22 @@ enum LanguageId #define GAME_LANGUAGE (LANGUAGE_ENGLISH) // capacities of various saveblock objects -#define DAYCARE_MON_COUNT 2 -#define POKEBLOCKS_COUNT 40 -#define EVENT_OBJECTS_COUNT 16 +#define DAYCARE_MON_COUNT 2 +#define POKEBLOCKS_COUNT 40 +#define EVENT_OBJECTS_COUNT 16 #define BERRY_TREES_COUNT 128 #define FLAGS_COUNT 300 #define VARS_COUNT 256 -#define MAIL_COUNT 16 -#define SECRET_BASES_COUNT 20 -#define TV_SHOWS_COUNT 25 -#define POKE_NEWS_COUNT 16 -#define PC_ITEMS_COUNT 50 -#define BAG_ITEMS_COUNT 30 -#define BAG_KEYITEMS_COUNT 30 -#define BAG_POKEBALLS_COUNT 16 -#define BAG_TMHM_COUNT 64 -#define BAG_BERRIES_COUNT 46 +#define MAIL_COUNT 16 +#define SECRET_BASES_COUNT 20 +#define TV_SHOWS_COUNT 25 +#define POKE_NEWS_COUNT 16 +#define PC_ITEMS_COUNT 50 +#define BAG_ITEMS_COUNT 30 +#define BAG_KEYITEMS_COUNT 30 +#define BAG_POKEBALLS_COUNT 16 +#define BAG_TMHM_COUNT 64 +#define BAG_BERRIES_COUNT 46 #define PYRAMID_BAG_ITEMS_COUNT 10 #define HALL_FACILITIES_COUNT 9 // 7 facilities for single mode + tower double mode + tower multi mode. diff --git a/include/metatile_behavior.h b/include/metatile_behavior.h index 8301a22f2..e18639faf 100644 --- a/include/metatile_behavior.h +++ b/include/metatile_behavior.h @@ -77,7 +77,7 @@ bool8 MetatileBehavior_IsBerryTreeSoil(u8); bool8 MetatileBehavior_IsAshGrass(u8); bool8 MetatileBehavior_IsFootprints(u8); bool8 MetatileBehavior_IsBridge(u8); -u8 MetatileBehavior_GetBridgeSth(u8); +u8 MetatileBehavior_GetBridgeType(u8); u8 MetatileBehavior_8089510(u8); bool8 MetatileBehavior_IsLandWildEncounter(u8); bool8 MetatileBehavior_IsWaterWildEncounter(u8); diff --git a/include/overworld.h b/include/overworld.h index 3dce20ab2..6b38a8782 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -47,13 +47,13 @@ void Overworld_SetEventObjTemplateMovementType(u8 localId, u8 movementType); const struct MapLayout *GetMapLayout(void); void ApplyCurrentWarp(void); void set_warp2_warp3_to_neg_1(void); -void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); -bool32 IsDummyWarp(struct WarpData *warp); +static void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); +static bool32 IsDummyWarp(struct WarpData *warp); struct MapHeader const *const Overworld_GetMapHeaderByGroupAndId(u16 mapGroup, u16 mapNum); struct MapHeader const *const GetDestinationWarpMapHeader(void); -void LoadCurrentMapData(void); -void LoadSaveblockMapHeader(void); -void SetPlayerCoordsFromWarp(void); +static void LoadCurrentMapData(void); +static void LoadSaveblockMapHeader(void); +static void SetPlayerCoordsFromWarp(void); void WarpIntoMap(void); void Overworld_SetWarpDestination(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void warp1_set_2(s8 mapGroup, s8 mapNum, s8 warpId); @@ -67,7 +67,7 @@ void sub_8084D5C(s16 a1, s16 a2); void sub_8084DD4(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void sub_8084E14(void); void SetFixedDiveWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); -void SetFixedDiveWarpAsDestination(void); +static void SetFixedDiveWarpAsDestination(void); void SetFixedHoleWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void SetFixedHoleWarpAsDestination(s16 x, s16 y); void warp1_set_to_sav1w(void); @@ -75,7 +75,7 @@ void sub_8084F2C(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void sub_8084F6C(u8 a1); void sub_8084FAC(void); const struct MapConnection *GetMapConnection(u8 dir); -bool8 SetDiveWarp(u8 dir, u16 x, u16 y); +static bool8 SetDiveWarp(u8 dir, u16 x, u16 y); bool8 SetDiveWarpEmerge(u16 x, u16 y); bool8 SetDiveWarpDive(u16 x, u16 y); void mliX_load_map(u8 mapGroup, u8 mapNum); @@ -105,7 +105,7 @@ void UpdateAmbientCry(s16 *state, u16 *delayCounter); u8 GetMapTypeByGroupAndId(s8 mapGroup, s8 mapNum); u8 GetMapTypeByWarpData(struct WarpData *warp); u8 Overworld_GetMapTypeOfSaveblockLocation(void); -u8 get_map_light_from_warp0(void); +u8 GetLastUsedWarpMapType(void); bool8 is_map_type_1_2_3_5_or_6(u8 mapType); bool8 Overworld_MapTypeAllowsTeleportAndFly(u8 mapType); bool8 Overworld_MapTypeIsIndoors(u8 mapType); diff --git a/src/battle_setup.c b/src/battle_setup.c index c18176706..6465db00f 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -664,7 +664,7 @@ u8 BattleSetup_GetTerrainId(void) return BATTLE_TERRAIN_MOUNTAIN; if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING)) { - if (MetatileBehavior_GetBridgeSth(tileBehavior)) + if (MetatileBehavior_GetBridgeType(tileBehavior)) return BATTLE_TERRAIN_POND; if (MetatileBehavior_IsBridge(tileBehavior) == TRUE) return BATTLE_TERRAIN_WATER; diff --git a/src/berry.c b/src/berry.c index 66cf91409..7cd28d69f 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1,12 +1,13 @@ #include "global.h" #include "berry.h" -#include "main.h" -#include "item.h" -#include "constants/items.h" -#include "text.h" -#include "random.h" #include "event_data.h" #include "fieldmap.h" +#include "item.h" +#include "main.h" +#include "random.h" +#include "text.h" +#include "constants/event_object_movement_constants.h" +#include "constants/items.h" extern u8 EventObjectGetBerryTreeId(u8 eventObjectId); extern void sub_8092EF0(u8 mapId, u8 mapNumber, u8 mapGroup); @@ -18,6 +19,17 @@ extern u16 gSpecialVar_ItemId; extern const u8 BerryTreeScript[]; +static u32 GetEnigmaBerryChecksum(struct EnigmaBerry *enigmaBerry); +static bool32 BerryTreeGrow(struct BerryTree *tree); +static u16 BerryTypeToItemId(u16 berry); +static u8 BerryTreeGetNumStagesWatered(struct BerryTree *tree); +static u8 GetNumStagesWateredByBerryTreeId(u8 id); +static u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water); +static u8 CalcBerryYield(struct BerryTree *tree); +static u8 GetBerryCountByBerryTreeId(u8 id); +static u16 GetStageDurationByBerryType(u8); + +//.rodata static const u8 sBerryDescriptionPart1_Cheri[] = _("Blooms with delicate pretty flowers."); static const u8 sBerryDescriptionPart2_Cheri[] = _("The bright red BERRY is very spicy."); static const u8 sBerryDescriptionPart1_Chesto[] = _("The BERRY’s thick skin and fruit are"); @@ -845,6 +857,7 @@ const struct UnkStruct_0858AB24 gUnknown_0858AB24[] = { const struct BerryTree gBlankBerryTree = {}; +//.text // unused void ClearEnigmaBerries(void) { @@ -860,7 +873,7 @@ void SetEnigmaBerry(u8 *src) dest[i] = src[i]; } -u32 GetEnigmaBerryChecksum(struct EnigmaBerry *enigmaBerry) +static u32 GetEnigmaBerryChecksum(struct EnigmaBerry *enigmaBerry) { u32 i; u32 checksum; @@ -889,12 +902,12 @@ bool32 IsEnigmaBerryValid(void) const struct Berry *GetBerryInfo(u8 berry) { - if (berry == 0x2B && IsEnigmaBerryValid()) + if (berry == ITEM_TO_BERRY(ITEM_ENIGMA_BERRY) && IsEnigmaBerryValid()) return (struct Berry*)(&gSaveBlock1Ptr->enigmaBerry.berry); else { - if (berry == 0 || berry > 0x2B) - berry = 1; + if (berry == BERRY_NONE || berry > ITEM_TO_BERRY(LAST_BERRY_INDEX)) + berry = ITEM_TO_BERRY(FIRST_BERRY_INDEX); return &gBerries[berry - 1]; } } @@ -910,16 +923,16 @@ bool32 EventObjectInteractionWaterBerryTree(void) switch (tree->stage) { - case 1: + case BERRY_STAGE_PLANTED: tree->watered1 = TRUE; break; - case 2: + case BERRY_STAGE_SPROUTED: tree->watered2 = TRUE; break; - case 3: + case BERRY_STAGE_TALLER: tree->watered3 = TRUE; break; - case 4: + case BERRY_STAGE_FLOWERING: tree->watered4 = TRUE; break; default: @@ -953,28 +966,28 @@ void ClearBerryTrees(void) gSaveBlock1Ptr->berryTrees[i] = gBlankBerryTree; } -bool32 BerryTreeGrow(struct BerryTree *tree) +static bool32 BerryTreeGrow(struct BerryTree *tree) { if (tree->growthSparkle) return FALSE; switch (tree->stage) { - case 0: + case BERRY_STAGE_NO_BERRY: return FALSE; - case 4: + case BERRY_STAGE_FLOWERING: tree->berryYield = CalcBerryYield(tree); - case 1: - case 2: - case 3: + case BERRY_STAGE_PLANTED: + case BERRY_STAGE_SPROUTED: + case BERRY_STAGE_TALLER: tree->stage++; break; - case 5: + case BERRY_STAGE_BERRIES: tree->watered1 = 0; tree->watered2 = 0; tree->watered3 = 0; tree->watered4 = 0; tree->berryYield = 0; - tree->stage = 2; + tree->stage = BERRY_STAGE_SPROUTED; if (++tree->regrowthCount == 10) *tree = gBlankBerryTree; break; @@ -1012,7 +1025,7 @@ void BerryTreeTimeUpdate(s32 minutes) tree->minutesUntilNextStage = GetStageDurationByBerryType(tree->berry); if (!BerryTreeGrow(tree)) break; - if (tree->stage == 5) + if (tree->stage == BERRY_STAGE_BERRIES) tree->minutesUntilNextStage *= 4; } } @@ -1028,7 +1041,7 @@ void PlantBerryTree(u8 id, u8 berry, u8 stage, bool8 sparkle) tree->berry = berry; tree->minutesUntilNextStage = GetStageDurationByBerryType(berry); tree->stage = stage; - if (stage == 5) + if (stage == BERRY_STAGE_BERRIES) { tree->berryYield = CalcBerryYield(tree); tree->minutesUntilNextStage *= 4; @@ -1064,7 +1077,7 @@ u8 ItemIdToBerryType(u16 item) return ITEM_TO_BERRY(item); } -u16 BerryTypeToItemId(u16 berry) +static u16 BerryTypeToItemId(u16 berry) { u16 item = berry - 1; @@ -1087,10 +1100,10 @@ void GetBerryCountStringByBerryType(u8 berry, u8* dest, u32 berryCount) void ResetBerryTreeSparkleFlag(u8 id) { - GetBerryTreeInfo(id)->growthSparkle = 0; + GetBerryTreeInfo(id)->growthSparkle = FALSE; } -u8 BerryTreeGetNumStagesWatered(struct BerryTree *tree) +static u8 BerryTreeGetNumStagesWatered(struct BerryTree *tree) { u8 count = 0; @@ -1105,12 +1118,12 @@ u8 BerryTreeGetNumStagesWatered(struct BerryTree *tree) return count; } -u8 GetNumStagesWateredByBerryTreeId(u8 id) +static u8 GetNumStagesWateredByBerryTreeId(u8 id) { return BerryTreeGetNumStagesWatered(GetBerryTreeInfo(id)); } -u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) +static u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) { u32 randMin; u32 randMax; @@ -1133,7 +1146,7 @@ u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) } } -u8 CalcBerryYield(struct BerryTree *tree) +static u8 CalcBerryYield(struct BerryTree *tree) { const struct Berry *berry = GetBerryInfo(tree->berry); u8 min = berry->minYield; @@ -1142,12 +1155,12 @@ u8 CalcBerryYield(struct BerryTree *tree) return CalcBerryYieldInternal(max, min, BerryTreeGetNumStagesWatered(tree)); } -u8 GetBerryCountByBerryTreeId(u8 id) +static u8 GetBerryCountByBerryTreeId(u8 id) { return gSaveBlock1Ptr->berryTrees[id].berryYield; } -u16 GetStageDurationByBerryType(u8 berry) +static u16 GetStageDurationByBerryType(u8 berry) { return GetBerryInfo(berry)->stageDuration * 60; } @@ -1156,18 +1169,18 @@ void EventObjectInteractionGetBerryTreeData(void) { u8 id; u8 berry; - u8 unk; + u8 localId; u8 group; u8 num; id = EventObjectGetBerryTreeId(gSelectedEventObject); berry = GetBerryTypeByBerryTreeId(id); ResetBerryTreeSparkleFlag(id); - unk = gSpecialVar_LastTalked; + localId = gSpecialVar_LastTalked; num = gSaveBlock1Ptr->location.mapNum; group = gSaveBlock1Ptr->location.mapGroup; - if (IsBerryTreeSparkling(unk, num, group)) - gSpecialVar_0x8004 = 0xFF; + if (IsBerryTreeSparkling(localId, num, group)) + gSpecialVar_0x8004 = BERRY_STAGE_SPARKLING; else gSpecialVar_0x8004 = GetStageByBerryTreeId(id); gSpecialVar_0x8005 = GetNumStagesWateredByBerryTreeId(id); @@ -1216,7 +1229,7 @@ void EventObjectInteractionRemoveBerryTree(void) sub_8092EF0(gSpecialVar_LastTalked, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); } -u8 PlayerHasBerries(void) +bool8 PlayerHasBerries(void) { return IsBagPocketNonEmpty(POCKET_BERRIES); } @@ -1238,7 +1251,7 @@ void ResetBerryTreeSparkleFlags(void) bottom = top + 8; for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { - if (gEventObjects[i].active && gEventObjects[i].movementType == 12) + if (gEventObjects[i].active && gEventObjects[i].movementType == MOVEMENT_TYPE_BERRY_TREE_GROWTH) { cam_left = gEventObjects[i].currentCoords.x; cam_top = gEventObjects[i].currentCoords.y; diff --git a/src/bike.c b/src/bike.c index 8ad771f51..b9d247c5d 100644 --- a/src/bike.c +++ b/src/bike.c @@ -3,13 +3,13 @@ #include "event_object_movement.h" #include "field_player_avatar.h" #include "fieldmap.h" -#include "constants/flags.h" #include "global.fieldmap.h" #include "metatile_behavior.h" #include "overworld.h" -#include "constants/songs.h" #include "sound.h" +#include "constants/flags.h" #include "constants/map_types.h" +#include "constants/songs.h" extern bool8 gBikeCyclingChallenge; extern u8 gBikeCollisions; diff --git a/src/data/field_event_obj/field_effect_objects.h b/src/data/field_event_obj/field_effect_objects.h index 33fe66fe2..82fde1769 100755 --- a/src/data/field_event_obj/field_effect_objects.h +++ b/src/data/field_event_obj/field_effect_objects.h @@ -91,7 +91,7 @@ const union AnimCmd *const gFieldEffectObjectImageAnimTable_Ripple[] = gFieldEffectObjectImageAnim_850CAE0, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_Ripple = {0xFFFF, 0x1005, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_Ripple, gFieldEffectObjectPicTable_Ripple, gDummySpriteAffineAnimTable, sub_81561D0}; +const struct SpriteTemplate gFieldEffectObjectTemplate_Ripple = {0xFFFF, 0x1005, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_Ripple, gFieldEffectObjectPicTable_Ripple, gDummySpriteAffineAnimTable, WaitFieldEffectSpriteAnim}; const struct SpriteFrameImage gFieldEffectObjectPicTable_Ash[] = { overworld_frame(gFieldEffectObjectPic_Ash, 2, 2, 0), @@ -124,25 +124,25 @@ const struct SpriteFrameImage gFieldEffectObjectPicTable_SurfBlob[] = { overworld_frame(gFieldEffectObjectPic_SurfBlob, 4, 4, 2), }; -const union AnimCmd gFieldEffectObjectImageAnim_850CB94[] = +const union AnimCmd gSurfBlobAnim_FaceSouth[] = { ANIMCMD_FRAME(0, 1), ANIMCMD_JUMP(0), }; -const union AnimCmd gFieldEffectObjectImageAnim_850CB9C[] = +const union AnimCmd gSurfBlobAnim_FaceNorth[] = { ANIMCMD_FRAME(1, 1), ANIMCMD_JUMP(0), }; -const union AnimCmd gFieldEffectObjectImageAnim_850CBA4[] = +const union AnimCmd gSurfBlobAnim_FaceWest[] = { ANIMCMD_FRAME(2, 1), ANIMCMD_JUMP(0), }; -const union AnimCmd gFieldEffectObjectImageAnim_850CBAC[] = +const union AnimCmd gSurfBlobAnim_FaceEast[] = { ANIMCMD_FRAME(2, 1, .hFlip = TRUE), ANIMCMD_JUMP(0), @@ -150,10 +150,10 @@ const union AnimCmd gFieldEffectObjectImageAnim_850CBAC[] = const union AnimCmd *const gFieldEffectObjectImageAnimTable_SurfBlob[] = { - gFieldEffectObjectImageAnim_850CB94, - gFieldEffectObjectImageAnim_850CB9C, - gFieldEffectObjectImageAnim_850CBA4, - gFieldEffectObjectImageAnim_850CBAC, + gSurfBlobAnim_FaceSouth, + gSurfBlobAnim_FaceNorth, + gSurfBlobAnim_FaceWest, + gSurfBlobAnim_FaceEast, }; const struct SpriteTemplate gFieldEffectObjectTemplate_SurfBlob = {0xFFFF, 0xFFFF, &gEventObjectBaseOam_32x32, gFieldEffectObjectImageAnimTable_SurfBlob, gFieldEffectObjectPicTable_SurfBlob, gDummySpriteAffineAnimTable, UpdateSurfBlobFieldEffect}; @@ -562,7 +562,7 @@ const union AnimCmd *const gFieldEffectObjectImageAnimTable_Unknown17[] = gFieldEffectObjectImageAnim_850D05C, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_Unknown17 = {0xFFFF, 0x1005, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_Unknown17, gFieldEffectObjectPicTable_Unknown17, gDummySpriteAffineAnimTable, sub_81561D0}; +const struct SpriteTemplate gFieldEffectObjectTemplate_Unknown17 = {0xFFFF, 0x1005, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_Unknown17, gFieldEffectObjectPicTable_Unknown17, gDummySpriteAffineAnimTable, WaitFieldEffectSpriteAnim}; const struct SpriteFrameImage gFieldEffectObjectPicTable_Unknown18[] = { overworld_frame(gFieldEffectObjectPic_Unknown18, 2, 2, 0), @@ -587,7 +587,7 @@ const union AnimCmd *const gFieldEffectObjectImageAnimTable_Unknown18[] = gFieldEffectObjectImageAnim_850D0C0, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_Unknown18 = {0xFFFF, 0x1005, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_Unknown18, gFieldEffectObjectPicTable_Unknown18, gDummySpriteAffineAnimTable, sub_81561D0}; +const struct SpriteTemplate gFieldEffectObjectTemplate_Unknown18 = {0xFFFF, 0x1005, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_Unknown18, gFieldEffectObjectPicTable_Unknown18, gDummySpriteAffineAnimTable, WaitFieldEffectSpriteAnim}; const struct SpriteFrameImage gFieldEffectObjectPicTable_Unknown19[] = { overworld_frame(gFieldEffectObjectPic_Unknown19, 2, 2, 0), @@ -610,7 +610,7 @@ const union AnimCmd *const gFieldEffectObjectImageAnimTable_Unknown19[] = gFieldEffectObjectImageAnim_850D118, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_Unknown19 = {0xFFFF, 0x1004, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_Unknown19, gFieldEffectObjectPicTable_Unknown19, gDummySpriteAffineAnimTable, sub_81561D0}; +const struct SpriteTemplate gFieldEffectObjectTemplate_Unknown19 = {0xFFFF, 0x1004, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_Unknown19, gFieldEffectObjectPicTable_Unknown19, gDummySpriteAffineAnimTable, WaitFieldEffectSpriteAnim}; const struct SpriteFrameImage gFieldEffectObjectPicTable_Unknown29[] = { overworld_frame(gFieldEffectObjectPic_Unknown29, 2, 1, 0), @@ -656,7 +656,7 @@ const union AnimCmd *const gFieldEffectObjectImageAnimTable_Unknown20[] = gFieldEffectObjectImageAnim_850D1AC, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_Unknown20 = {0xFFFF, 0x1004, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_Unknown20, gFieldEffectObjectPicTable_Unknown20, gDummySpriteAffineAnimTable, sub_81561D0}; +const struct SpriteTemplate gFieldEffectObjectTemplate_Unknown20 = {0xFFFF, 0x1004, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_Unknown20, gFieldEffectObjectPicTable_Unknown20, gDummySpriteAffineAnimTable, WaitFieldEffectSpriteAnim}; const union AffineAnimCmd gFieldEffectObjectRotScalAnim_850D1E4[] = { @@ -733,7 +733,7 @@ const union AnimCmd *const gFieldEffectObjectImageAnimTable_BerryTreeGrowthSpark gFieldEffectObjectImageAnim_850D2D4, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_BerryTreeGrowthSparkle = {0xFFFF, 0xFFFF, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_BerryTreeGrowthSparkle, gFieldEffectObjectPicTable_BerryTreeGrowthSparkle, gDummySpriteAffineAnimTable, sub_81561D0}; +const struct SpriteTemplate gFieldEffectObjectTemplate_BerryTreeGrowthSparkle = {0xFFFF, 0xFFFF, &gEventObjectBaseOam_16x16, gFieldEffectObjectImageAnimTable_BerryTreeGrowthSparkle, gFieldEffectObjectPicTable_BerryTreeGrowthSparkle, gDummySpriteAffineAnimTable, WaitFieldEffectSpriteAnim}; const struct SpriteFrameImage gFieldEffectObjectPicTable_TreeDisguise[] = { overworld_frame(gFieldEffectObjectPic_TreeDisguise, 2, 4, 0), diff --git a/src/decoration.c b/src/decoration.c index de85df968..eb85b4f5c 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -1347,12 +1347,12 @@ void sub_8128060(u8 taskId) void ConfigureCameraObjectForPlacingDecoration(struct PlaceDecorationGraphicsDataBuffer *data, u8 decor) { - sDecor_CameraSpriteObjectIdx1 = gSprites[gUnknown_03005DD0.spriteId].data[0]; - gUnknown_03005DD0.spriteId = gpu_pal_decompress_alloc_tag_and_upload(data, decor); - gSprites[gUnknown_03005DD0.spriteId].oam.priority = 1; - gSprites[gUnknown_03005DD0.spriteId].callback = sub_81292D0; - gSprites[gUnknown_03005DD0.spriteId].pos1.x = gUnknown_085A7250[data->decoration->shape].x; - gSprites[gUnknown_03005DD0.spriteId].pos1.y = gUnknown_085A7250[data->decoration->shape].y; + sDecor_CameraSpriteObjectIdx1 = gSprites[gFieldCamera.spriteId].data[0]; + gFieldCamera.spriteId = gpu_pal_decompress_alloc_tag_and_upload(data, decor); + gSprites[gFieldCamera.spriteId].oam.priority = 1; + gSprites[gFieldCamera.spriteId].callback = sub_81292D0; + gSprites[gFieldCamera.spriteId].pos1.x = gUnknown_085A7250[data->decoration->shape].x; + gSprites[gFieldCamera.spriteId].pos1.y = gUnknown_085A7250[data->decoration->shape].y; } void SetUpPlacingDecorationPlayerAvatar(u8 taskId, struct PlaceDecorationGraphicsDataBuffer *data) @@ -1374,7 +1374,7 @@ void SetUpPlacingDecorationPlayerAvatar(u8 taskId, struct PlaceDecorationGraphic } gSprites[sDecor_CameraSpriteObjectIdx2].oam.priority = 1; DestroySprite(&gSprites[sDecor_CameraSpriteObjectIdx1]); - sDecor_CameraSpriteObjectIdx1 = gUnknown_03005DD0.spriteId; + sDecor_CameraSpriteObjectIdx1 = gFieldCamera.spriteId; } void sub_812826C(u8 taskId) @@ -2293,9 +2293,9 @@ bool8 sub_81299AC(u8 taskId) void SetUpPuttingAwayDecorationPlayerAvatar(void) { GetPlayerFacingDirection(); - sDecor_CameraSpriteObjectIdx1 = gSprites[gUnknown_03005DD0.spriteId].data[0]; + sDecor_CameraSpriteObjectIdx1 = gSprites[gFieldCamera.spriteId].data[0]; sub_812A39C(); - gUnknown_03005DD0.spriteId = CreateSprite(&gUnknown_085A7404, 0x78, 0x50, 0); + gFieldCamera.spriteId = CreateSprite(&gUnknown_085A7404, 0x78, 0x50, 0); if (gSaveBlock2Ptr->playerGender == MALE) { sDecor_CameraSpriteObjectIdx2 = AddPseudoEventObject(0xC1, SpriteCallbackDummy, 0x88, 0x48, 0); @@ -2306,7 +2306,7 @@ void SetUpPuttingAwayDecorationPlayerAvatar(void) } gSprites[sDecor_CameraSpriteObjectIdx2].oam.priority = 1; DestroySprite(&gSprites[sDecor_CameraSpriteObjectIdx1]); - sDecor_CameraSpriteObjectIdx1 = gUnknown_03005DD0.spriteId; + sDecor_CameraSpriteObjectIdx1 = gFieldCamera.spriteId; gSprites[sDecor_CameraSpriteObjectIdx1].oam.priority = 1; } diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 57f72b284..048b02d2d 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -42,7 +42,7 @@ static bool8 IsCoordOutsideEventObjectMovementRange(struct EventObject *, s16, s static bool8 IsMetatileDirectionallyImpassable(struct EventObject *, s16, s16, u8); static bool8 DoesObjectCollideWithObjectAt(struct EventObject *, s16, s16); static void sub_8096530(struct EventObject *, struct Sprite *); -static void npc_update_obj_anim_flag(struct EventObject *, struct Sprite *); +static void UpdateEventObjSpriteVisibility(struct EventObject *, struct Sprite *); static void EventObjectUpdateMetatileBehaviors(struct EventObject*); static void GetGroundEffectFlags_Reflection(struct EventObject*, u32*); static void GetGroundEffectFlags_TallGrassOnSpawn(struct EventObject*, u32*); @@ -73,7 +73,7 @@ static void sub_8097D68(struct Sprite*); static void ApplyLevitateMovement(u8); static bool8 MovementType_Disguise_Callback(struct EventObject *, struct Sprite *); static bool8 MovementType_Hidden_Callback(struct EventObject *, struct Sprite *); -static void sub_808D450(void); +static void CreateReflectionEffectSprites(void); static u8 GetEventObjectIdByLocalId(u8); static u8 GetEventObjectIdByLocalIdAndMapInternal(u8, u8, u8); static bool8 GetAvailableEventObjectId(u16, u8, u8, u8 *); @@ -84,7 +84,7 @@ static void UpdateEventObjectVisibility(struct EventObject *, struct Sprite *); static void MakeObjectTemplateFromEventObjectTemplate(struct EventObjectTemplate *, struct SpriteTemplate *, const struct SubspriteTable **); static void GetEventObjectMovingCameraOffset(s16 *, s16 *); static struct EventObjectTemplate *GetEventObjectTemplateByLocalIdAndMap(u8, u8, u8); -static void sub_808E894(u16); +static void LoadEventObjectPalette(u16); static void RemoveEventObjectIfOutsideView(struct EventObject *); static void sub_808E1B8(u8, s16, s16); static void SetPlayerAvatarEventObjectIdAndObjectId(u8, u8); @@ -100,6 +100,8 @@ static void CameraObject_2(struct Sprite *); static struct EventObjectTemplate *FindEventObjectTemplateByLocalId(u8 localId, struct EventObjectTemplate *templates, u8 count); static void ClearEventObjectMovement(struct EventObject *, struct Sprite *); static void EventObjectSetSingleMovement(struct EventObject *, struct Sprite *, u8); +static void oamt_npc_ministep_reset(struct Sprite *, u8, u8); +static void UpdateEventObjectSpriteSubpriorityAndVisibility(struct Sprite *); const u8 gReflectionEffectPaletteMap[] = {1, 1, 6, 7, 8, 9, 6, 7, 8, 9, 11, 11, 0, 0, 0, 0}; @@ -625,7 +627,6 @@ const u16 gObjectPaletteTags3[] = { EVENT_OBJ_PAL_TAG_7, }; - const u16 *const gObjectPaletteTagSets[] = { gObjectPaletteTags0, gObjectPaletteTags1, @@ -1078,19 +1079,19 @@ static void ClearAllEventObjects(void) { u8 i; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) ClearEventObject(&gEventObjects[i]); } -void sub_808D438(void) +void ResetEventObjects(void) { ClearLinkPlayerEventObjects(); ClearAllEventObjects(); ClearPlayerAvatarInfo(); - sub_808D450(); + CreateReflectionEffectSprites(); } -static void sub_808D450(void) +static void CreateReflectionEffectSprites(void) { u8 spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[21], 0, 0, 31); gSprites[spriteId].oam.affineMode = 1; @@ -1108,7 +1109,7 @@ static void sub_808D450(void) u8 GetFirstInactiveEventObjectId(void) { u8 i; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { if (!gEventObjects[i].active) break; @@ -1119,7 +1120,7 @@ u8 GetFirstInactiveEventObjectId(void) u8 GetEventObjectIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroupId) { - if (localId < 0xff) + if (localId < 0xFF) { return GetEventObjectIdByLocalIdAndMapInternal(localId, mapNum, mapGroupId); } @@ -1129,7 +1130,7 @@ u8 GetEventObjectIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroupId) bool8 TryGetEventObjectIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroupId, u8 *eventObjectId) { *eventObjectId = GetEventObjectIdByLocalIdAndMap(localId, mapNum, mapGroupId); - if (*eventObjectId == NUM_EVENT_OBJECTS) + if (*eventObjectId == EVENT_OBJECTS_COUNT) return TRUE; else return FALSE; @@ -1138,7 +1139,7 @@ bool8 TryGetEventObjectIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroupId, u u8 GetEventObjectIdByXY(s16 x, s16 y) { u8 i; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { if (gEventObjects[i].active && gEventObjects[i].currentCoords.x == x && gEventObjects[i].currentCoords.y == y) break; @@ -1150,25 +1151,25 @@ u8 GetEventObjectIdByXY(s16 x, s16 y) static u8 GetEventObjectIdByLocalIdAndMapInternal(u8 localId, u8 mapNum, u8 mapGroupId) { u8 i; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { if (gEventObjects[i].active && gEventObjects[i].localId == localId && gEventObjects[i].mapNum == mapNum && gEventObjects[i].mapGroup == mapGroupId) return i; } - return NUM_EVENT_OBJECTS; + return EVENT_OBJECTS_COUNT; } static u8 GetEventObjectIdByLocalId(u8 localId) { u8 i; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { if (gEventObjects[i].active && gEventObjects[i].localId == localId) return i; } - return NUM_EVENT_OBJECTS; + return EVENT_OBJECTS_COUNT; } // This function has the same nonmatching quirk as in Ruby/Sapphire. @@ -1183,7 +1184,7 @@ static u8 InitEventObjectStateFromTemplate(struct EventObjectTemplate *template, // mapNum and mapGroup are in the wrong registers (r7/r6 instead of r6/r7) if (GetAvailableEventObjectId(template->localId, mapNum, mapGroup, &eventObjectId)) { - return NUM_EVENT_OBJECTS; + return EVENT_OBJECTS_COUNT; } eventObject = &gEventObjects[eventObjectId]; ClearEventObject(eventObject); @@ -1387,24 +1388,24 @@ static NAKED u8 InitEventObjectStateFromTemplate(struct EventObjectTemplate *tem u8 Unref_TryInitLocalEventObject(u8 localId) { u8 i; - u8 nObjects; + u8 eventObjectCount; struct EventObjectTemplate *template; if (gMapHeader.events != NULL) { if (InBattlePyramid()) { - nObjects = sub_81AAA40(); + eventObjectCount = sub_81AAA40(); } else if (InTrainerHill()) { - nObjects = 2; + eventObjectCount = 2; } else { - nObjects = gMapHeader.events->eventObjectCount; + eventObjectCount = gMapHeader.events->eventObjectCount; } - for (i = 0; i < nObjects; i++) + for (i = 0; i < eventObjectCount; i++) { template = &gSaveBlock1Ptr->eventObjectTemplates[i]; if (template->localId == localId && !FlagGet(template->flagId)) @@ -1413,7 +1414,7 @@ u8 Unref_TryInitLocalEventObject(u8 localId) } } } - return NUM_EVENT_OBJECTS; + return EVENT_OBJECTS_COUNT; } static bool8 GetAvailableEventObjectId(u16 localId, u8 mapNum, u8 mapGroup, u8 *eventObjectId) @@ -1425,14 +1426,14 @@ static bool8 GetAvailableEventObjectId(u16 localId, u8 mapNum, u8 mapGroup, u8 * { u8 i = 0; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { if (!gEventObjects[i].active) break; if (gEventObjects[i].localId == localId && gEventObjects[i].mapNum == mapNum && gEventObjects[i].mapGroup == mapGroup) return TRUE; } - if (i >= NUM_EVENT_OBJECTS) + if (i >= EVENT_OBJECTS_COUNT) return TRUE; *eventObjectId = i; do @@ -1440,7 +1441,7 @@ static bool8 GetAvailableEventObjectId(u16 localId, u8 mapNum, u8 mapGroup, u8 * if (gEventObjects[i].active && gEventObjects[i].localId == localId && gEventObjects[i].mapNum == mapNum && gEventObjects[i].mapGroup == mapGroup) return TRUE; i++; - } while (i < NUM_EVENT_OBJECTS); + } while (i < EVENT_OBJECTS_COUNT); return FALSE; } @@ -1472,7 +1473,7 @@ void RemoveAllEventObjectsExceptPlayer(void) { u8 i; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { if (i != gPlayerAvatar.eventObjectId) RemoveEventObject(&gEventObjects[i]); @@ -1481,16 +1482,16 @@ void RemoveAllEventObjectsExceptPlayer(void) static u8 TrySetupEventObjectSprite(struct EventObjectTemplate *eventObjectTemplate, struct SpriteTemplate *spriteTemplate, u8 mapNum, u8 mapGroup, s16 cameraX, s16 cameraY) { + u8 spriteId; + u8 paletteSlot; + u8 eventObjectId; + struct Sprite *sprite; struct EventObject *eventObject; const struct EventObjectGraphicsInfo *graphicsInfo; - struct Sprite *sprite; - u8 eventObjectId; - u8 paletteSlot; - u8 spriteId; eventObjectId = InitEventObjectStateFromTemplate(eventObjectTemplate, mapNum, mapGroup); - if (eventObjectId == NUM_EVENT_OBJECTS) - return NUM_EVENT_OBJECTS; + if (eventObjectId == EVENT_OBJECTS_COUNT) + return EVENT_OBJECTS_COUNT; eventObject = &gEventObjects[eventObjectId]; graphicsInfo = GetEventObjectGraphicsInfo(eventObject->graphicsId); @@ -1508,7 +1509,7 @@ static u8 TrySetupEventObjectSprite(struct EventObjectTemplate *eventObjectTempl paletteSlot -= 16; sub_808EAB0(graphicsInfo->paletteTag1, paletteSlot); } - if (eventObject->movementType == 0x4c) + if (eventObject->movementType == MOVEMENT_TYPE_INVISIBLE) { eventObject->invisible = TRUE; } @@ -1517,7 +1518,7 @@ static u8 TrySetupEventObjectSprite(struct EventObjectTemplate *eventObjectTempl if (spriteId == MAX_SPRITES) { gEventObjects[eventObjectId].active = FALSE; - return NUM_EVENT_OBJECTS; + return EVENT_OBJECTS_COUNT; } sprite = &gSprites[spriteId]; sub_8092FF0(eventObject->currentCoords.x + cameraX, eventObject->currentCoords.y + cameraY, &sprite->pos1.x, &sprite->pos1.y); @@ -1541,21 +1542,20 @@ static u8 TrySetupEventObjectSprite(struct EventObjectTemplate *eventObjectTempl static u8 TrySpawnEventObject(struct EventObjectTemplate *eventObjectTemplate, u8 mapNum, u8 mapGroup, s16 cameraX, s16 cameraY) { - const struct EventObjectGraphicsInfo *graphicsInfo; - struct SpriteTemplate spriteTemplate; - const struct SubspriteTable *subspriteTables; - struct SpriteFrameImage spriteFrameImage; u8 eventObjectId; + struct SpriteTemplate spriteTemplate; + struct SpriteFrameImage spriteFrameImage; + const struct EventObjectGraphicsInfo *graphicsInfo; + const struct SubspriteTable *subspriteTables = NULL; - subspriteTables = NULL; graphicsInfo = GetEventObjectGraphicsInfo(eventObjectTemplate->graphicsId); MakeObjectTemplateFromEventObjectTemplate(eventObjectTemplate, &spriteTemplate, &subspriteTables); spriteFrameImage.size = graphicsInfo->size; spriteTemplate.images = &spriteFrameImage; eventObjectId = TrySetupEventObjectSprite(eventObjectTemplate, &spriteTemplate, mapNum, mapGroup, cameraX, cameraY); - if (eventObjectId == NUM_EVENT_OBJECTS) + if (eventObjectId == EVENT_OBJECTS_COUNT) { - return NUM_EVENT_OBJECTS; + return EVENT_OBJECTS_COUNT; } gSprites[gEventObjects[eventObjectId].spriteId].images = graphicsInfo->images; if (subspriteTables != NULL) @@ -1603,29 +1603,29 @@ u8 show_sprite(u8 localId, u8 mapNum, u8 mapGroup) eventObjectTemplate = GetEventObjectTemplateByLocalIdAndMap(localId, mapNum, mapGroup); if (eventObjectTemplate == NULL) { - return NUM_EVENT_OBJECTS; + return EVENT_OBJECTS_COUNT; } GetEventObjectMovingCameraOffset(&cameraX, &cameraY); return TrySpawnEventObject(eventObjectTemplate, mapNum, mapGroup, cameraX, cameraY); } -static void MakeObjectTemplateFromEventObjectGraphicsInfo(u16 graphicsId, void (*callback)(struct Sprite *), struct SpriteTemplate *sprTemplate, const struct SubspriteTable **subspriteTables) +static void MakeObjectTemplateFromEventObjectGraphicsInfo(u16 graphicsId, void (*callback)(struct Sprite *), struct SpriteTemplate *spriteTemplate, const struct SubspriteTable **subspriteTables) { - const struct EventObjectGraphicsInfo *gfxInfo = GetEventObjectGraphicsInfo(graphicsId); + const struct EventObjectGraphicsInfo *graphicsInfo = GetEventObjectGraphicsInfo(graphicsId); - sprTemplate->tileTag = gfxInfo->tileTag; - sprTemplate->paletteTag = gfxInfo->paletteTag1; - sprTemplate->oam = gfxInfo->oam; - sprTemplate->anims = gfxInfo->anims; - sprTemplate->images = gfxInfo->images; - sprTemplate->affineAnims = gfxInfo->affineAnims; - sprTemplate->callback = callback; - *subspriteTables = gfxInfo->subspriteTables; + spriteTemplate->tileTag = graphicsInfo->tileTag; + spriteTemplate->paletteTag = graphicsInfo->paletteTag1; + spriteTemplate->oam = graphicsInfo->oam; + spriteTemplate->anims = graphicsInfo->anims; + spriteTemplate->images = graphicsInfo->images; + spriteTemplate->affineAnims = graphicsInfo->affineAnims; + spriteTemplate->callback = callback; + *subspriteTables = graphicsInfo->subspriteTables; } -static void MakeObjectTemplateFromEventObjectGraphicsInfoWithCallbackIndex(u16 graphicsId, u16 callbackIndex, struct SpriteTemplate *sprTemplate, const struct SubspriteTable **subspriteTables) +static void MakeObjectTemplateFromEventObjectGraphicsInfoWithCallbackIndex(u16 graphicsId, u16 callbackIndex, struct SpriteTemplate *spriteTemplate, const struct SubspriteTable **subspriteTables) { - MakeObjectTemplateFromEventObjectGraphicsInfo(graphicsId, sMovementTypeCallbacks[callbackIndex], sprTemplate, subspriteTables); + MakeObjectTemplateFromEventObjectGraphicsInfo(graphicsId, sMovementTypeCallbacks[callbackIndex], spriteTemplate, subspriteTables); } static void MakeObjectTemplateFromEventObjectTemplate(struct EventObjectTemplate *eventObjectTemplate, struct SpriteTemplate *spriteTemplate, const struct SubspriteTable **subspriteTables) @@ -1638,37 +1638,37 @@ u8 AddPseudoEventObject(u16 graphicsId, void (*callback)(struct Sprite *), s16 x struct SpriteTemplate *spriteTemplate; const struct SubspriteTable *subspriteTables; struct Sprite *sprite; - u8 spriteIdx; + u8 spriteId; spriteTemplate = malloc(sizeof(struct SpriteTemplate)); MakeObjectTemplateFromEventObjectGraphicsInfo(graphicsId, callback, spriteTemplate, &subspriteTables); - if (spriteTemplate->paletteTag != 0xffff) + if (spriteTemplate->paletteTag != 0xFFFF) { - sub_808E894(spriteTemplate->paletteTag); + LoadEventObjectPalette(spriteTemplate->paletteTag); } - spriteIdx = CreateSprite(spriteTemplate, x, y, subpriority); + spriteId = CreateSprite(spriteTemplate, x, y, subpriority); free(spriteTemplate); - if (spriteIdx != MAX_SPRITES && subspriteTables != NULL) + if (spriteId != MAX_SPRITES && subspriteTables != NULL) { - sprite = &gSprites[spriteIdx]; + sprite = &gSprites[spriteId]; SetSubspriteTables(sprite, subspriteTables); sprite->subspriteMode = 2; } - return spriteIdx; + return spriteId; } u8 sprite_new(u8 graphicsId, u8 a1, s16 x, s16 y, u8 z, u8 direction) { - const struct EventObjectGraphicsInfo *graphicsInfo; - struct SpriteTemplate spriteTemplate; - const struct SubspriteTable *subspriteTables; u8 spriteId; struct Sprite *sprite; + struct SpriteTemplate spriteTemplate; + const struct SubspriteTable *subspriteTables; + const struct EventObjectGraphicsInfo *graphicsInfo; graphicsInfo = GetEventObjectGraphicsInfo(graphicsId); MakeObjectTemplateFromEventObjectGraphicsInfo(graphicsId, UpdateEventObjectSpriteSubpriorityAndVisibility, &spriteTemplate, &subspriteTables); - *(u16 *)&spriteTemplate.paletteTag = 0xffff; + *(u16 *)&spriteTemplate.paletteTag = 0xFFFF; x += 7; y += 7; sub_80930E0(&x, &y, 8, 16); @@ -1710,20 +1710,14 @@ u8 sprite_new(u8 graphicsId, u8 a1, s16 x, s16 y, u8 z, u8 direction) void TrySpawnEventObjects(s16 cameraX, s16 cameraY) { u8 i; - s16 left; - s16 right; - s16 top; - s16 bottom; u8 objectCount; - s16 npcX; - s16 npcY; if (gMapHeader.events != NULL) { - left = gSaveBlock1Ptr->pos.x - 2; - right = gSaveBlock1Ptr->pos.x + 17; - top = gSaveBlock1Ptr->pos.y; - bottom = gSaveBlock1Ptr->pos.y + 16; + s16 left = gSaveBlock1Ptr->pos.x - 2; + s16 right = gSaveBlock1Ptr->pos.x + 17; + s16 top = gSaveBlock1Ptr->pos.y; + s16 bottom = gSaveBlock1Ptr->pos.y + 16; if (InBattlePyramid()) { @@ -1741,8 +1735,8 @@ void TrySpawnEventObjects(s16 cameraX, s16 cameraY) for (i = 0; i < objectCount; i++) { struct EventObjectTemplate *template = &gSaveBlock1Ptr->eventObjectTemplates[i]; - npcX = template->x + 7; - npcY = template->y + 7; + s16 npcX = template->x + 7; + s16 npcY = template->y + 7; if (top <= npcY && bottom >= npcY && left <= npcX && right >= npcX && !FlagGet(template->flagId)) @@ -1753,12 +1747,10 @@ void TrySpawnEventObjects(s16 cameraX, s16 cameraY) void RemoveEventObjectsOutsideView(void) { - u8 i; - u8 j; + u8 i, j; bool8 isActiveLinkPlayer; - struct EventObject *eventObject; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { for (j = 0, isActiveLinkPlayer = FALSE; j < ARRAY_COUNT(gLinkPlayerEventObjects); j++) { @@ -1767,7 +1759,7 @@ void RemoveEventObjectsOutsideView(void) } if (!isActiveLinkPlayer) { - eventObject = &gEventObjects[i]; + struct EventObject *eventObject = &gEventObjects[i]; if (eventObject->active && !eventObject->isPlayer) RemoveEventObjectIfOutsideView(eventObject); @@ -1777,21 +1769,16 @@ void RemoveEventObjectsOutsideView(void) static void RemoveEventObjectIfOutsideView(struct EventObject *eventObject) { - s16 left; - s16 right; - s16 top; - s16 bottom; - - left = gSaveBlock1Ptr->pos.x - 2; - right = gSaveBlock1Ptr->pos.x + 17; - top = gSaveBlock1Ptr->pos.y; - bottom = gSaveBlock1Ptr->pos.y + 16; + s16 left = gSaveBlock1Ptr->pos.x - 2; + s16 right = gSaveBlock1Ptr->pos.x + 17; + s16 top = gSaveBlock1Ptr->pos.y; + s16 bottom = gSaveBlock1Ptr->pos.y + 16; if (eventObject->currentCoords.x >= left && eventObject->currentCoords.x <= right - && eventObject->currentCoords.y >= top && eventObject->currentCoords.y <= bottom) + && eventObject->currentCoords.y >= top && eventObject->currentCoords.y <= bottom) return; if (eventObject->initialCoords.x >= left && eventObject->initialCoords.x <= right - && eventObject->initialCoords.y >= top && eventObject->initialCoords.y <= bottom) + && eventObject->initialCoords.y >= top && eventObject->initialCoords.y <= bottom) return; RemoveEventObject(eventObject); } @@ -1801,26 +1788,26 @@ void sub_808E16C(s16 x, s16 y) u8 i; ClearPlayerAvatarInfo(); - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { if (gEventObjects[i].active) { sub_808E1B8(i, x, y); } } - sub_808D450(); + CreateReflectionEffectSprites(); } static void sub_808E1B8(u8 eventObjectId, s16 x, s16 y) { u8 spriteId; u8 paletteSlot; + struct Sprite *sprite; struct EventObject *eventObject; + struct SpriteTemplate spriteTemplate; + struct SpriteFrameImage spriteFrameImage; const struct SubspriteTable *subspriteTables; const struct EventObjectGraphicsInfo *graphicsInfo; - struct SpriteFrameImage spriteFrameImage; - struct SpriteTemplate spriteTemplate; - struct Sprite *sprite; #define i spriteId for (i = 0; i < ARRAY_COUNT(gLinkPlayerEventObjects); i++) @@ -1838,7 +1825,7 @@ static void sub_808E1B8(u8 eventObjectId, s16 x, s16 y) spriteFrameImage.size = graphicsInfo->size; MakeObjectTemplateFromEventObjectGraphicsInfoWithCallbackIndex(eventObject->graphicsId, eventObject->movementType, &spriteTemplate, &subspriteTables); spriteTemplate.images = &spriteFrameImage; - *(u16 *)&spriteTemplate.paletteTag = 0xffff; + *(u16 *)&spriteTemplate.paletteTag = 0xFFFF; paletteSlot = graphicsInfo->paletteSlot; if (paletteSlot == 0) { @@ -1853,7 +1840,7 @@ static void sub_808E1B8(u8 eventObjectId, s16 x, s16 y) paletteSlot -= 16; sub_808EAB0(graphicsInfo->paletteTag1, paletteSlot); } - *(u16 *)&spriteTemplate.paletteTag = 0xffff; + *(u16 *)&spriteTemplate.paletteTag = 0xFFFF; spriteId = CreateSprite(&spriteTemplate, 0, 0, 0); if (spriteId != MAX_SPRITES) { @@ -1864,7 +1851,7 @@ static void sub_808E1B8(u8 eventObjectId, s16 x, s16 y) sprite->pos1.x += 8; sprite->pos1.y += 16 + sprite->centerToCornerVecY; sprite->images = graphicsInfo->images; - if (eventObject->movementType == 0x0b) + if (eventObject->movementType == MOVEMENT_TYPE_PLAYER) { SetPlayerAvatarEventObjectIdAndObjectId(eventObjectId, spriteId); eventObject->warpArrowSpriteId = CreateWarpArrowSprite(); @@ -1877,7 +1864,7 @@ static void sub_808E1B8(u8 eventObjectId, s16 x, s16 y) sprite->coordOffsetEnabled = TRUE; sprite->data[0] = eventObjectId; eventObject->spriteId = spriteId; - if (!eventObject->inanimate && eventObject->movementType != 0x0b) + if (!eventObject->inanimate && eventObject->movementType != MOVEMENT_TYPE_PLAYER) { StartSpriteAnim(sprite, GetFaceDirectionAnimNum(eventObject->facingDirection)); } @@ -1888,7 +1875,7 @@ static void sub_808E1B8(u8 eventObjectId, s16 x, s16 y) static void sub_808E38C(struct EventObject *eventObject) { - eventObject->singleMovementActive = 0; + eventObject->singleMovementActive = FALSE; eventObject->triggerGroundEffectsOnMove = TRUE; eventObject->hasShadow = FALSE; eventObject->hasReflection = FALSE; @@ -1983,7 +1970,7 @@ void PlayerObjectTurn(struct PlayerAvatar *playerAvatar, u8 direction) EventObjectTurn(&gEventObjects[playerAvatar->eventObjectId], direction); } -/*static*/ void get_berry_tree_graphics(struct EventObject *eventObject, struct Sprite *sprite) +static void get_berry_tree_graphics(struct EventObject *eventObject, struct Sprite *sprite) { u8 berryStage; u8 berryId; @@ -1996,7 +1983,7 @@ void PlayerObjectTurn(struct PlayerAvatar *playerAvatar, u8 direction) eventObject->invisible = FALSE; sprite->invisible = FALSE; berryId = GetBerryTypeByBerryTreeId(eventObject->trainerRange_berryTreeId) - 1; - berryStage -= 1; + berryStage--; if (berryId >= NUM_BERRIES) { berryId = 0; @@ -2059,7 +2046,7 @@ void sub_808E75C(s16 x, s16 y) struct EventObject *eventObject; eventObjectId = GetEventObjectIdByXY(x, y); - if (eventObjectId != NUM_EVENT_OBJECTS) + if (eventObjectId != EVENT_OBJECTS_COUNT) { eventObject = &gEventObjects[eventObjectId]; eventObject->triggerGroundEffectsOnMove = TRUE; @@ -2113,42 +2100,40 @@ void FreeAndReserveObjectSpritePalettes(void) gReservedSpritePaletteCount = 12; } -static void sub_808E894(u16 paletteTag) +static void LoadEventObjectPalette(u16 paletteTag) { - u16 paletteSlot; + u16 i = FindEventObjectPaletteIndexByTag(paletteTag); - paletteSlot = FindEventObjectPaletteIndexByTag(paletteTag); - if (paletteSlot != EVENT_OBJ_PAL_TAG_NONE) // always true + if (i != EVENT_OBJ_PAL_TAG_NONE) // always true { - sub_808E8F4(&sEventObjectSpritePalettes[paletteSlot]); + sub_808E8F4(&sEventObjectSpritePalettes[i]); } } -void sub_808E8C0(u16 *paletteTags) +void Unused_LoadEventObjectPaletteSet(u16 *paletteTags) { u8 i; for (i = 0; paletteTags[i] != EVENT_OBJ_PAL_TAG_NONE; i++) { - sub_808E894(paletteTags[i]); + LoadEventObjectPalette(paletteTags[i]); } } static u8 sub_808E8F4(const struct SpritePalette *spritePalette) { - if (IndexOfSpritePaletteTag(spritePalette->tag) != 0xff) + if (IndexOfSpritePaletteTag(spritePalette->tag) != 0xFF) { - return 0xff; + return 0xFF; } return LoadSpritePalette(spritePalette); } void PatchObjectPalette(u16 paletteTag, u8 paletteSlot) { - u16 paletteIdx; + u8 paletteIndex = FindEventObjectPaletteIndexByTag(paletteTag); - paletteIdx = FindEventObjectPaletteIndexByTag(paletteTag); - LoadPalette(sEventObjectSpritePalettes[paletteIdx].data, 16 * paletteSlot + 256, 0x20); + LoadPalette(sEventObjectSpritePalettes[paletteIndex].data, 16 * paletteSlot + 0x100, 0x20); } void PatchObjectPaletteRange(const u16 *paletteTags, u8 minSlot, u8 maxSlot) @@ -2172,7 +2157,7 @@ static u8 FindEventObjectPaletteIndexByTag(u16 tag) return i; } } - return 0xff; + return 0xFF; } void LoadPlayerObjectReflectionPalette(u16 tag, u8 slot) @@ -2227,7 +2212,7 @@ void ShiftEventObjectCoords(struct EventObject *eventObject, s16 x, s16 y) eventObject->currentCoords.y = y; } -/*static*/ void SetEventObjectCoords(struct EventObject *eventObject, s16 x, s16 y) +static void SetEventObjectCoords(struct EventObject *eventObject, s16 x, s16 y) { eventObject->previousCoords.x = x; eventObject->previousCoords.y = y; @@ -2282,7 +2267,7 @@ void UpdateEventObjectCoordsForCameraUpdate(void) { dx = gCamera.x; dy = gCamera.y; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { if (gEventObjects[i].active) { @@ -2300,7 +2285,8 @@ void UpdateEventObjectCoordsForCameraUpdate(void) u8 GetEventObjectIdByXYZ(u16 x, u16 y, u8 z) { u8 i; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { if (gEventObjects[i].active) { @@ -2310,7 +2296,7 @@ u8 GetEventObjectIdByXYZ(u16 x, u16 y, u8 z) } } } - return NUM_EVENT_OBJECTS; + return EVENT_OBJECTS_COUNT; } static bool8 EventObjectDoesZCoordMatch(struct EventObject *eventObject, u8 z) @@ -2331,9 +2317,8 @@ void UpdateEventObjectsForCameraUpdate(s16 x, s16 y) u8 AddCameraObject(u8 linkedSpriteId) { - u8 spriteId; + u8 spriteId = CreateSprite(&gCameraSpriteTemplate, 0, 0, 4); - spriteId = CreateSprite(&gCameraSpriteTemplate, 0, 0, 4); gSprites[spriteId].invisible = TRUE; gSprites[spriteId].data[0] = linkedSpriteId; return spriteId; @@ -2358,11 +2343,9 @@ static void CameraObject_0(struct Sprite *sprite) static void CameraObject_1(struct Sprite *sprite) { - s16 x; - s16 y; + s16 x = gSprites[sprite->data[0]].pos1.x; + s16 y = gSprites[sprite->data[0]].pos1.y; - y = gSprites[sprite->data[0]].pos1.y; - x = gSprites[sprite->data[0]].pos1.x; sprite->data[2] = x - sprite->pos1.x; sprite->data[3] = y - sprite->pos1.y; sprite->pos1.x = x; @@ -2379,13 +2362,13 @@ static void CameraObject_2(struct Sprite *sprite) static struct Sprite *FindCameraObject(void) { - u8 spriteId; + u8 i; - for (spriteId = 0; spriteId < MAX_SPRITES; spriteId++) + for (i = 0; i < MAX_SPRITES; i++) { - if (gSprites[spriteId].inUse && gSprites[spriteId].callback == ObjectCB_CameraObject) + if (gSprites[i].inUse && gSprites[i].callback == ObjectCB_CameraObject) { - return &gSprites[spriteId]; + return &gSprites[i]; } } return NULL; @@ -2454,7 +2437,7 @@ u8 CreateCopySpriteAt(struct Sprite *sprite, s16 x, s16 y, u8 subpriority) { s16 i; - for (i = MAX_SPRITES - 1; i > -1; i --) + for (i = MAX_SPRITES - 1; i > -1; i--) { if (!gSprites[i].inUse) { @@ -2978,10 +2961,8 @@ u8 GetLimitedVectorDirection_SouthWestEast(s16 dx, s16 dy, s16 absdx, s16 absdy) u8 TryGetTrainerEncounterDirection(struct EventObject *eventObject, u8 movementType) { - s16 dx; - s16 dy; - s16 absdx; - s16 absdy; + s16 dx, dy; + s16 absdx, absdy; if (!EventObjectIsTrainerAndCloseToPlayer(eventObject)) { @@ -4449,7 +4430,7 @@ bool8 CopyablePlayerMovement_GoSpeed1(struct EventObject *eventObject, struct Sp { EventObjectSetSingleMovement(eventObject, sprite, GetFaceDirectionMovementAction(direction)); } - eventObject->singleMovementActive = 1; + eventObject->singleMovementActive = TRUE; sprite->data[1] = 2; return TRUE; } @@ -4468,7 +4449,7 @@ bool8 CopyablePlayerMovement_GoSpeed2(struct EventObject *eventObject, struct Sp { EventObjectSetSingleMovement(eventObject, sprite, GetFaceDirectionMovementAction(direction)); } - eventObject->singleMovementActive = 1; + eventObject->singleMovementActive = TRUE; sprite->data[1] = 2; return TRUE; } @@ -4487,7 +4468,7 @@ bool8 CopyablePlayerMovement_Slide(struct EventObject *eventObject, struct Sprit { EventObjectSetSingleMovement(eventObject, sprite, GetFaceDirectionMovementAction(direction)); } - eventObject->singleMovementActive = 1; + eventObject->singleMovementActive = TRUE; sprite->data[1] = 2; return TRUE; } @@ -4499,7 +4480,7 @@ bool8 cph_IM_DIFFERENT(struct EventObject *eventObject, struct Sprite *sprite, u direction = playerDirection; direction = state_to_direction(gInitialMovementTypeFacingDirections[eventObject->movementType], eventObject->directionSequenceIndex, direction); EventObjectSetSingleMovement(eventObject, sprite, GetJumpInPlaceMovementAction(direction)); - eventObject->singleMovementActive = 1; + eventObject->singleMovementActive = TRUE; sprite->data[1] = 2; return TRUE; } @@ -4518,7 +4499,7 @@ bool8 CopyablePlayerMovement_GoSpeed4(struct EventObject *eventObject, struct Sp { EventObjectSetSingleMovement(eventObject, sprite, GetFaceDirectionMovementAction(direction)); } - eventObject->singleMovementActive = 1; + eventObject->singleMovementActive = TRUE; sprite->data[1] = 2; return TRUE; } @@ -4539,7 +4520,7 @@ bool8 CopyablePlayerMovement_Jump(struct EventObject *eventObject, struct Sprite { EventObjectSetSingleMovement(eventObject, sprite, GetFaceDirectionMovementAction(direction)); } - eventObject->singleMovementActive = 1; + eventObject->singleMovementActive = TRUE; sprite->data[1] = 2; return TRUE; } @@ -4951,7 +4932,7 @@ static bool8 DoesObjectCollideWithObjectAt(struct EventObject *eventObject, s16 u8 i; struct EventObject *curObject; - for (i = 0; i < NUM_EVENT_OBJECTS; i++) + for (i = 0; i < EVENT_OBJECTS_COUNT; i++) { curObject = &gEventObjects[i]; if (curObject->active && curObject != eventObject) @@ -5022,8 +5003,8 @@ void sub_8092FF0(s16 x, s16 y, s16 *dest_x, s16 *dest_y) { *dest_x = (x - gSaveBlock1Ptr->pos.x) << 4; *dest_y = (y - gSaveBlock1Ptr->pos.y) << 4; - *dest_x -= gUnknown_03005DEC; - *dest_y -= gUnknown_03005DE8; + *dest_x -= gTotalCameraPixelOffsetX; + *dest_y -= gTotalCameraPixelOffsetY; } void sub_8093038(s16 x, s16 y, s16 *dest_x, s16 *dest_y) @@ -5031,21 +5012,21 @@ void sub_8093038(s16 x, s16 y, s16 *dest_x, s16 *dest_y) s16 dx; s16 dy; - dx = -gUnknown_03005DEC - gUnknown_03005DD0.x; - dy = -gUnknown_03005DE8 - gUnknown_03005DD0.y; - if (gUnknown_03005DD0.x > 0) + dx = -gTotalCameraPixelOffsetX - gFieldCamera.x; + dy = -gTotalCameraPixelOffsetY - gFieldCamera.y; + if (gFieldCamera.x > 0) { dx += 0x10; } - if (gUnknown_03005DD0.x < 0) + if (gFieldCamera.x < 0) { dx -= 0x10; } - if (gUnknown_03005DD0.y > 0) + if (gFieldCamera.y > 0) { dy += 0x10; } - if (gUnknown_03005DD0.y < 0) + if (gFieldCamera.y < 0) { dy -= 0x10; } @@ -5064,19 +5045,19 @@ static void GetEventObjectMovingCameraOffset(s16 *x, s16 *y) { *x = 0; *y = 0; - if (gUnknown_03005DD0.x > 0) + if (gFieldCamera.x > 0) { (*x)++; } - if (gUnknown_03005DD0.x < 0) + if (gFieldCamera.x < 0) { (*x) --; } - if (gUnknown_03005DD0.y > 0) + if (gFieldCamera.y > 0) { (*y)++; } - if (gUnknown_03005DD0.y < 0) + if (gFieldCamera.y < 0) { (*y) --; } @@ -5332,7 +5313,7 @@ void npc_apply_direction(struct EventObject *eventObject, struct Sprite *sprite, ShiftEventObjectCoords(eventObject, x, y); oamt_npc_ministep_reset(sprite, direction, speed); sprite->animPaused = FALSE; - if (gLockedAnimEventObjects != NULL && FindLockedEventObjectIndex(eventObject) != NUM_EVENT_OBJECTS) + if (gLockedAnimEventObjects != NULL && FindLockedEventObjectIndex(eventObject) != EVENT_OBJECTS_COUNT) { sprite->animPaused = TRUE; } @@ -7435,7 +7416,7 @@ bool8 MovementAction_AcroWheelieMoveLeft_Step1(struct EventObject *eventObject, bool8 MovementAction_AcroWheelieMoveRight_Step0(struct EventObject *eventObject, struct Sprite *sprite) { - sub_8096200(eventObject, sprite, DIR_EAST, 1); + sub_8096200(eventObject, sprite, DIR_EAST, 1); return MovementAction_AcroWheelieMoveRight_Step1(eventObject, sprite); } @@ -7490,7 +7471,7 @@ bool8 MovementAction_AcroEndWheelieMoveUp_Step1(struct EventObject *eventObject, bool8 MovementAction_AcroEndWheelieMoveLeft_Step0(struct EventObject *eventObject, struct Sprite *sprite) { - sub_8096330(eventObject, sprite, DIR_WEST, 1); + sub_8096330(eventObject, sprite, DIR_WEST, 1); return MovementAction_AcroEndWheelieMoveLeft_Step1(eventObject, sprite); } @@ -7506,7 +7487,7 @@ bool8 MovementAction_AcroEndWheelieMoveLeft_Step1(struct EventObject *eventObjec bool8 MovementAction_AcroEndWheelieMoveRight_Step0(struct EventObject *eventObject, struct Sprite *sprite) { - sub_8096330(eventObject, sprite, DIR_EAST, 1); + sub_8096330(eventObject, sprite, DIR_EAST, 1); return MovementAction_AcroEndWheelieMoveRight_Step1(eventObject, sprite); } @@ -7578,15 +7559,13 @@ static void TryEnableEventObjectAnim(struct EventObject *eventObject, struct Spr static void UpdateEventObjectVisibility(struct EventObject *eventObject, struct Sprite *sprite) { sub_8096530(eventObject, sprite); - npc_update_obj_anim_flag(eventObject, sprite); + UpdateEventObjSpriteVisibility(eventObject, sprite); } static void sub_8096530(struct EventObject *eventObject, struct Sprite *sprite) { - u16 x; - u16 y; - u16 x2; - u16 y2; + u16 x, y; + u16 x2, y2; const struct EventObjectGraphicsInfo *graphicsInfo; eventObject->offScreen = FALSE; @@ -7615,7 +7594,7 @@ static void sub_8096530(struct EventObject *eventObject, struct Sprite *sprite) } } -static void npc_update_obj_anim_flag(struct EventObject *eventObject, struct Sprite *sprite) +static void UpdateEventObjSpriteVisibility(struct EventObject *eventObject, struct Sprite *sprite) { sprite->invisible = FALSE; if (eventObject->invisible || eventObject->offScreen) @@ -7624,7 +7603,7 @@ static void npc_update_obj_anim_flag(struct EventObject *eventObject, struct Spr } } -/*static*/ void GetAllGroundEffectFlags_OnSpawn(struct EventObject *eventObj, u32 *flags) +static void GetAllGroundEffectFlags_OnSpawn(struct EventObject *eventObj, u32 *flags) { EventObjectUpdateMetatileBehaviors(eventObj); GetGroundEffectFlags_Reflection(eventObj, flags); @@ -7650,7 +7629,7 @@ static void GetAllGroundEffectFlags_OnBeginStep(struct EventObject *eventObj, u3 GetGroundEffectFlags_HotSprings(eventObj, flags); } -/*static*/ void GetAllGroundEffectFlags_OnFinishStep(struct EventObject *eventObj, u32 *flags) +static void GetAllGroundEffectFlags_OnFinishStep(struct EventObject *eventObj, u32 *flags) { EventObjectUpdateMetatileBehaviors(eventObj); GetGroundEffectFlags_ShallowFlowingWater(eventObj, flags); @@ -7930,7 +7909,7 @@ u8 GetLedgeJumpDirection(s16 x, s16 y, u8 z) return 0; } -void EventObjectSetSpriteOamTableForLongGrass(struct EventObject *eventObj, struct Sprite *sprite) +static void SetEventObjectSpriteOamTableForLongGrass(struct EventObject *eventObj, struct Sprite *sprite) { if (eventObj->disableCoveringGroundEffects) return; @@ -7983,7 +7962,7 @@ static const u8 sEventObjectPriorities_08376070[] = { 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 0, 0, 1, }; -void EventObjectUpdateZCoordAndPriority(struct EventObject *eventObj, struct Sprite *sprite) +void UpdateEventObjectZCoordAndPriority(struct EventObject *eventObj, struct Sprite *sprite) { if (eventObj->fixedPriority) return; @@ -8206,7 +8185,11 @@ void GroundEffect_JumpOnTallGrass(struct EventObject *eventObj, struct Sprite *s FieldEffectStart(FLDEFF_JUMP_TALL_GRASS); spriteId = FindTallGrassFieldEffectSpriteId( - eventObj->localId, eventObj->mapNum, eventObj->mapGroup, eventObj->currentCoords.x, eventObj->currentCoords.y); + eventObj->localId, + eventObj->mapNum, + eventObj->mapGroup, + eventObj->currentCoords.x, + eventObj->currentCoords.y); if (spriteId == MAX_SPRITES) GroundEffect_SpawnOnTallGrass(eventObj, sprite); @@ -8288,7 +8271,7 @@ static void (*const sGroundEffectFuncs[])(struct EventObject *eventObj, struct S GroundEffect_Seaweed }; -/*static*/ void DoFlaggedGroundEffects(struct EventObject *eventObj, struct Sprite *sprite, u32 flags) +static void DoFlaggedGroundEffects(struct EventObject *eventObj, struct Sprite *sprite, u32 flags) { u8 i; @@ -8329,9 +8312,9 @@ static void DoGroundEffects_OnSpawn(struct EventObject *eventObj, struct Sprite if (eventObj->triggerGroundEffectsOnMove) { flags = 0; - EventObjectUpdateZCoordAndPriority(eventObj, sprite); + UpdateEventObjectZCoordAndPriority(eventObj, sprite); GetAllGroundEffectFlags_OnSpawn(eventObj, &flags); - EventObjectSetSpriteOamTableForLongGrass(eventObj, sprite); + SetEventObjectSpriteOamTableForLongGrass(eventObj, sprite); DoFlaggedGroundEffects(eventObj, sprite, flags); eventObj->triggerGroundEffectsOnMove = 0; eventObj->disableCoveringGroundEffects = 0; @@ -8345,9 +8328,9 @@ static void DoGroundEffects_OnBeginStep(struct EventObject *eventObj, struct Spr if (eventObj->triggerGroundEffectsOnMove) { flags = 0; - EventObjectUpdateZCoordAndPriority(eventObj, sprite); + UpdateEventObjectZCoordAndPriority(eventObj, sprite); GetAllGroundEffectFlags_OnBeginStep(eventObj, &flags); - EventObjectSetSpriteOamTableForLongGrass(eventObj, sprite); + SetEventObjectSpriteOamTableForLongGrass(eventObj, sprite); filters_out_some_ground_effects(eventObj, &flags); DoFlaggedGroundEffects(eventObj, sprite, flags); eventObj->triggerGroundEffectsOnMove = 0; @@ -8362,9 +8345,9 @@ static void DoGroundEffects_OnFinishStep(struct EventObject *eventObj, struct Sp if (eventObj->triggerGroundEffectsOnStop) { flags = 0; - EventObjectUpdateZCoordAndPriority(eventObj, sprite); + UpdateEventObjectZCoordAndPriority(eventObj, sprite); GetAllGroundEffectFlags_OnFinishStep(eventObj, &flags); - EventObjectSetSpriteOamTableForLongGrass(eventObj, sprite); + SetEventObjectSpriteOamTableForLongGrass(eventObj, sprite); FilterOutStepOnPuddleGroundEffectIfJumping(eventObj, &flags); DoFlaggedGroundEffects(eventObj, sprite, flags); eventObj->triggerGroundEffectsOnStop = 0; @@ -8397,11 +8380,11 @@ void FreezeEventObjects(void) FreezeEventObject(&gEventObjects[i]); } -void FreezeEventObjectsExceptOne(u8 a1) +void FreezeEventObjectsExceptOne(u8 eventObjectId) { u8 i; for (i = 0; i < EVENT_OBJECTS_COUNT; i++) - if (i != a1 && gEventObjects[i].active && i != gPlayerAvatar.eventObjectId) + if (i != eventObjectId && gEventObjects[i].active && i != gPlayerAvatar.eventObjectId) FreezeEventObject(&gEventObjects[i]); } @@ -8423,44 +8406,44 @@ void UnfreezeEventObjects(void) UnfreezeEventObject(&gEventObjects[i]); } -void Step1(struct Sprite *sprite, u8 dir) +static void Step1(struct Sprite *sprite, u8 dir) { sprite->pos1.x += sDirectionToVectors[dir].x; sprite->pos1.y += sDirectionToVectors[dir].y; } -void Step2(struct Sprite *sprite, u8 dir) +static void Step2(struct Sprite *sprite, u8 dir) { sprite->pos1.x += 2 * (u16) sDirectionToVectors[dir].x; sprite->pos1.y += 2 * (u16) sDirectionToVectors[dir].y; } -void Step3(struct Sprite *sprite, u8 dir) +static void Step3(struct Sprite *sprite, u8 dir) { sprite->pos1.x += 2 * (u16) sDirectionToVectors[dir].x + (u16) sDirectionToVectors[dir].x; sprite->pos1.y += 2 * (u16) sDirectionToVectors[dir].y + (u16) sDirectionToVectors[dir].y; } -void Step4(struct Sprite *sprite, u8 dir) +static void Step4(struct Sprite *sprite, u8 dir) { sprite->pos1.x += 4 * (u16) sDirectionToVectors[dir].x; sprite->pos1.y += 4 * (u16) sDirectionToVectors[dir].y; } -void Step8(struct Sprite *sprite, u8 dir) +static void Step8(struct Sprite *sprite, u8 dir) { sprite->pos1.x += 8 * (u16) sDirectionToVectors[dir].x; sprite->pos1.y += 8 * (u16) sDirectionToVectors[dir].y; } -void oamt_npc_ministep_reset(struct Sprite *sprite, u8 a2, u8 a3) +static void oamt_npc_ministep_reset(struct Sprite *sprite, u8 direction, u8 a3) { - sprite->data[3] = a2; + sprite->data[3] = direction; sprite->data[4] = a3; sprite->data[5] = 0; } -typedef void (*SpriteStepFunc)(struct Sprite *sprite, u8 dir); +typedef void (*SpriteStepFunc)(struct Sprite *sprite, u8 direction); static const SpriteStepFunc gUnknown_0850E6C4[] = { Step1, @@ -8540,9 +8523,9 @@ bool8 obj_npc_ministep(struct Sprite *sprite) return TRUE; } -void sub_80976DC(struct Sprite *sprite, u8 a2) +void sub_80976DC(struct Sprite *sprite, u8 direction) { - sprite->data[3] = a2; + sprite->data[3] = direction; sprite->data[4] = 0; sprite->data[5] = 0; } @@ -8563,7 +8546,7 @@ bool8 sub_80976EC(struct Sprite *sprite) return FALSE; } -const s8 gUnknown_0850E772[] = { +static const s8 gUnknown_0850E772[] = { 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 1, 1, @@ -8575,7 +8558,7 @@ const s8 gUnknown_0850E772[] = { 0, 1, 0, 0, 0, 0, 0, 0, }; -const s8 gUnknown_0850E7BA[] = { +static const s8 gUnknown_0850E7BA[] = { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, @@ -8745,7 +8728,7 @@ u8 sub_80978E4(struct Sprite *sprite) return v2; } -void SetMovementDelay(struct Sprite *sprite, s16 timer) +static void SetMovementDelay(struct Sprite *sprite, s16 timer) { sprite->data[3] = timer; } @@ -8760,11 +8743,11 @@ static bool8 WaitForMovementDelay(struct Sprite *sprite) return FALSE; } -void SetAndStartSpriteAnim(struct Sprite *sprite, u8 a2, u8 a3) +void SetAndStartSpriteAnim(struct Sprite *sprite, u8 animNum, u8 animCmdIndex) { - sprite->animNum = a2; - sprite->animPaused = 0 ; - SeekSpriteAnim(sprite, a3); + sprite->animNum = animNum; + sprite->animPaused = FALSE; + SeekSpriteAnim(sprite, animCmdIndex); } bool8 SpriteAnimEnded(struct Sprite *sprite) @@ -8802,7 +8785,7 @@ void UpdateEventObjectSpriteVisibility(struct Sprite *sprite, bool8 invisible) sprite->invisible = TRUE; } -void UpdateEventObjectSpriteSubpriorityAndVisibility(struct Sprite *sprite) +static void UpdateEventObjectSpriteSubpriorityAndVisibility(struct Sprite *sprite) { sub_8097D68(sprite); SetObjectSubpriorityByZCoord(sprite->data[1], sprite, 1); @@ -8849,15 +8832,15 @@ void sub_8097BB4(u8 var1, u8 graphicsId) if(spriteId != MAX_SPRITES) { struct Sprite *sprite = &gSprites[spriteId]; - const struct EventObjectGraphicsInfo *gfxInfo = GetEventObjectGraphicsInfo(graphicsId); + const struct EventObjectGraphicsInfo *graphicsInfo = GetEventObjectGraphicsInfo(graphicsId); u16 tileNum = sprite->oam.tileNum; - sprite->oam = *gfxInfo->oam; + sprite->oam = *graphicsInfo->oam; sprite->oam.tileNum = tileNum; - sprite->oam.paletteNum = gfxInfo->paletteSlot; - sprite->images = gfxInfo->images; + sprite->oam.paletteNum = graphicsInfo->paletteSlot; + sprite->images = graphicsInfo->images; - if(gfxInfo->subspriteTables == NULL) + if(graphicsInfo->subspriteTables == NULL) { sprite->subspriteTables = NULL; sprite->subspriteTableNum = 0; @@ -8865,7 +8848,7 @@ void sub_8097BB4(u8 var1, u8 graphicsId) } else { - SetSubspriteTables(sprite, gfxInfo->subspriteTables); + SetSubspriteTables(sprite, graphicsInfo->subspriteTables); sprite->subspriteMode = 2; } StartSpriteAnim(sprite, 0); @@ -8990,9 +8973,9 @@ void DoShadowFieldEffect(struct EventObject *eventObject) static void DoRippleFieldEffect(struct EventObject *eventObject, struct Sprite *sprite) { - const struct EventObjectGraphicsInfo *gfxInfo = GetEventObjectGraphicsInfo(eventObject->graphicsId); + const struct EventObjectGraphicsInfo *graphicsInfo = GetEventObjectGraphicsInfo(eventObject->graphicsId); gFieldEffectArguments[0] = sprite->pos1.x; - gFieldEffectArguments[1] = sprite->pos1.y + (gfxInfo->height >> 1) - 2; + gFieldEffectArguments[1] = sprite->pos1.y + (graphicsInfo->height >> 1) - 2; gFieldEffectArguments[2] = 151; gFieldEffectArguments[3] = 3; FieldEffectStart(FLDEFF_RIPPLE); diff --git a/src/field_camera.c b/src/field_camera.c index e8900e06a..b976cf2ff 100644 --- a/src/field_camera.c +++ b/src/field_camera.c @@ -15,71 +15,71 @@ EWRAM_DATA bool8 gUnusedBikeCameraAheadPanback = FALSE; // Static type declarations -struct FieldCameraUnknownStruct +struct FieldCameraOffset { - u8 unk0; - u8 unk1; - u8 unk2; - u8 unk3; - bool8 unk4; + u8 xPixelOffset; + u8 yPixelOffset; + u8 xTileOffset; + u8 yTileOffset; + bool8 copyBGToVRAM; }; // static functions -static void RedrawMapSliceNorth(struct FieldCameraUnknownStruct *a, const struct MapLayout *mapLayout); -static void RedrawMapSliceSouth(struct FieldCameraUnknownStruct *a, const struct MapLayout *mapLayout); -static void RedrawMapSliceEast(struct FieldCameraUnknownStruct *a, const struct MapLayout *mapLayout); -static void RedrawMapSliceWest(struct FieldCameraUnknownStruct *a, const struct MapLayout *mapLayout); -static s32 MapPosToBgTilemapOffset(struct FieldCameraUnknownStruct *a, s32 x, s32 y); +static void RedrawMapSliceNorth(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout); +static void RedrawMapSliceSouth(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout); +static void RedrawMapSliceEast(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout); +static void RedrawMapSliceWest(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout); +static s32 MapPosToBgTilemapOffset(struct FieldCameraOffset *a, s32 x, s32 y); static void DrawWholeMapViewInternal(int x, int y, const struct MapLayout *mapLayout); static void DrawMetatileAt(const struct MapLayout *mapLayout, u16, int, int); static void DrawMetatile(s32 a, u16 *b, u16 c); static void CameraPanningCB_PanAhead(void); // IWRAM bss vars -static IWRAM_DATA struct FieldCameraUnknownStruct gUnknown_03000E20; -static IWRAM_DATA s16 gUnknown_03000E28; -static IWRAM_DATA s16 gUnknown_03000E2A; +static IWRAM_DATA struct FieldCameraOffset sFieldCameraOffset; +static IWRAM_DATA s16 sHorizontalCameraPan; +static IWRAM_DATA s16 sVerticalCameraPan; static IWRAM_DATA u8 gUnknown_03000E2C; -static IWRAM_DATA void (*gUnknown_03000E30)(void); +static IWRAM_DATA void (*sFieldCameraPanningCallback)(void); -struct CameraObject gUnknown_03005DD0; -u16 gUnknown_03005DE8; -u16 gUnknown_03005DEC; +struct CameraObject gFieldCamera; +u16 gTotalCameraPixelOffsetY; +u16 gTotalCameraPixelOffsetX; // text -static void move_tilemap_camera_to_upper_left_corner_(struct FieldCameraUnknownStruct *a) +static void move_tilemap_camera_to_upper_left_corner_(struct FieldCameraOffset *cameraOffset) { - a->unk2 = 0; - a->unk3 = 0; - a->unk0 = 0; - a->unk1 = 0; - a->unk4 = TRUE; + cameraOffset->xTileOffset = 0; + cameraOffset->yTileOffset = 0; + cameraOffset->xPixelOffset = 0; + cameraOffset->yPixelOffset = 0; + cameraOffset->copyBGToVRAM = TRUE; } -static void tilemap_move_something(struct FieldCameraUnknownStruct *a, u32 b, u32 c) +static void tilemap_move_something(struct FieldCameraOffset *cameraOffset, u32 b, u32 c) { - a->unk2 += b; - a->unk2 %= 32; - a->unk3 += c; - a->unk3 %= 32; + cameraOffset->xTileOffset += b; + cameraOffset->xTileOffset %= 32; + cameraOffset->yTileOffset += c; + cameraOffset->yTileOffset %= 32; } -static void coords8_add(struct FieldCameraUnknownStruct *a, u32 b, u32 c) +static void coords8_add(struct FieldCameraOffset *cameraOffset, u32 b, u32 c) { - a->unk0 += b; - a->unk1 += c; + cameraOffset->xPixelOffset += b; + cameraOffset->yPixelOffset += c; } void move_tilemap_camera_to_upper_left_corner(void) { - move_tilemap_camera_to_upper_left_corner_(&gUnknown_03000E20); + move_tilemap_camera_to_upper_left_corner_(&sFieldCameraOffset); } void FieldUpdateBgTilemapScroll(void) { u32 r4, r5; - r5 = gUnknown_03000E20.unk0 + gUnknown_03000E28; - r4 = gUnknown_03000E2A + gUnknown_03000E20.unk1 + 8; + r5 = sFieldCameraOffset.xPixelOffset + sHorizontalCameraPan; + r4 = sVerticalCameraPan + sFieldCameraOffset.yPixelOffset + 8; SetGpuReg(REG_OFFSET_BG1HOFS, r5); SetGpuReg(REG_OFFSET_BG1VOFS, r4); @@ -91,14 +91,14 @@ void FieldUpdateBgTilemapScroll(void) void sub_8089C08(s16 *a, s16 *b) { - *a = gUnknown_03000E20.unk0 + gUnknown_03000E28; - *b = gUnknown_03000E20.unk1 + gUnknown_03000E2A + 8; + *a = sFieldCameraOffset.xPixelOffset + sHorizontalCameraPan; + *b = sFieldCameraOffset.yPixelOffset + sVerticalCameraPan + 8; } void DrawWholeMapView(void) { DrawWholeMapViewInternal(gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y, gMapHeader.mapLayout); - gUnknown_03000E20.unk4 = TRUE; + sFieldCameraOffset.copyBGToVRAM = TRUE; } static void DrawWholeMapViewInternal(int x, int y, const struct MapLayout *mapLayout) @@ -110,13 +110,13 @@ static void DrawWholeMapViewInternal(int x, int y, const struct MapLayout *mapLa for (i = 0; i < 32; i += 2) { - temp = gUnknown_03000E20.unk3 + i; + temp = sFieldCameraOffset.yTileOffset + i; if (temp >= 32) temp -= 32; r6 = temp * 32; for (j = 0; j < 32; j += 2) { - temp = gUnknown_03000E20.unk2 + j; + temp = sFieldCameraOffset.xTileOffset + j; if (temp >= 32) temp -= 32; DrawMetatileAt(mapLayout, r6 + temp, x + j / 2, y + i / 2); @@ -124,112 +124,112 @@ static void DrawWholeMapViewInternal(int x, int y, const struct MapLayout *mapLa } } -static void RedrawMapSlicesForCameraUpdate(struct FieldCameraUnknownStruct *a, int x, int y) +static void RedrawMapSlicesForCameraUpdate(struct FieldCameraOffset *cameraOffset, int x, int y) { const struct MapLayout *mapLayout = gMapHeader.mapLayout; if (x > 0) - RedrawMapSliceWest(a, mapLayout); + RedrawMapSliceWest(cameraOffset, mapLayout); if (x < 0) - RedrawMapSliceEast(a, mapLayout); + RedrawMapSliceEast(cameraOffset, mapLayout); if (y > 0) - RedrawMapSliceNorth(a, mapLayout); + RedrawMapSliceNorth(cameraOffset, mapLayout); if (y < 0) - RedrawMapSliceSouth(a, mapLayout); - a->unk4 = TRUE; + RedrawMapSliceSouth(cameraOffset, mapLayout); + cameraOffset->copyBGToVRAM = TRUE; } -static void RedrawMapSliceNorth(struct FieldCameraUnknownStruct *a, const struct MapLayout *mapLayout) +static void RedrawMapSliceNorth(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout) { u8 i; u8 temp; u32 r7; - temp = a->unk3 + 28; + temp = cameraOffset->yTileOffset + 28; if (temp >= 32) temp -= 32; r7 = temp * 32; for (i = 0; i < 32; i += 2) { - temp = a->unk2 + i; + temp = cameraOffset->xTileOffset + i; if (temp >= 32) temp -= 32; DrawMetatileAt(mapLayout, r7 + temp, gSaveBlock1Ptr->pos.x + i / 2, gSaveBlock1Ptr->pos.y + 14); } } -static void RedrawMapSliceSouth(struct FieldCameraUnknownStruct *a, const struct MapLayout *mapLayout) +static void RedrawMapSliceSouth(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout) { u8 i; u8 temp; - u32 r7 = a->unk3 * 32; + u32 r7 = cameraOffset->yTileOffset * 32; for (i = 0; i < 32; i += 2) { - temp = a->unk2 + i; + temp = cameraOffset->xTileOffset + i; if (temp >= 32) temp -= 32; DrawMetatileAt(mapLayout, r7 + temp, gSaveBlock1Ptr->pos.x + i / 2, gSaveBlock1Ptr->pos.y); } } -static void RedrawMapSliceEast(struct FieldCameraUnknownStruct *a, const struct MapLayout *mapLayout) +static void RedrawMapSliceEast(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout) { u8 i; u8 temp; - u32 r6 = a->unk2; + u32 r6 = cameraOffset->xTileOffset; for (i = 0; i < 32; i += 2) { - temp = a->unk3 + i; + temp = cameraOffset->yTileOffset + i; if (temp >= 32) temp -= 32; DrawMetatileAt(mapLayout, temp * 32 + r6, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y + i / 2); } } -static void RedrawMapSliceWest(struct FieldCameraUnknownStruct *a, const struct MapLayout *mapLayout) +static void RedrawMapSliceWest(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout) { u8 i; u8 temp; - u8 r5 = a->unk2 + 28; + u8 r5 = cameraOffset->xTileOffset + 28; if (r5 >= 32) r5 -= 32; for (i = 0; i < 32; i += 2) { - temp = a->unk3 + i; + temp = cameraOffset->yTileOffset + i; if (temp >= 32) temp -= 32; DrawMetatileAt(mapLayout, temp * 32 + r5, gSaveBlock1Ptr->pos.x + 14, gSaveBlock1Ptr->pos.y + i / 2); } } -void CurrentMapDrawMetatileAt(int a, int b) +void CurrentMapDrawMetatileAt(int x, int y) { - int offset = MapPosToBgTilemapOffset(&gUnknown_03000E20, a, b); + int offset = MapPosToBgTilemapOffset(&sFieldCameraOffset, x, y); if (offset >= 0) { - DrawMetatileAt(gMapHeader.mapLayout, offset, a, b); - gUnknown_03000E20.unk4 = TRUE; + DrawMetatileAt(gMapHeader.mapLayout, offset, x, y); + sFieldCameraOffset.copyBGToVRAM = TRUE; } } void DrawDoorMetatileAt(int x, int y, u16 *arr) { - int offset = MapPosToBgTilemapOffset(&gUnknown_03000E20, x, y); + int offset = MapPosToBgTilemapOffset(&sFieldCameraOffset, x, y); if (offset >= 0) { DrawMetatile(1, arr, offset); - gUnknown_03000E20.unk4 = TRUE; + sFieldCameraOffset.copyBGToVRAM = TRUE; } } -static void DrawMetatileAt(const struct MapLayout *mapLayout, u16 b, int c, int d) +static void DrawMetatileAt(const struct MapLayout *mapLayout, u16 offset, int x, int y) { - u16 metatileId = MapGridGetMetatileIdAt(c, d); + u16 metatileId = MapGridGetMetatileIdAt(x, y); u16 *metatiles; if (metatileId > NUM_METATILES_TOTAL) @@ -241,60 +241,69 @@ static void DrawMetatileAt(const struct MapLayout *mapLayout, u16 b, int c, int metatiles = mapLayout->secondaryTileset->metatiles; metatileId -= NUM_METATILES_IN_PRIMARY; } - DrawMetatile(MapGridGetMetatileLayerTypeAt(c, d), metatiles + metatileId * 8, b); + DrawMetatile(MapGridGetMetatileLayerTypeAt(x, y), metatiles + metatileId * 8, offset); } -static void DrawMetatile(s32 a, u16 *b, u16 c) +static void DrawMetatile(s32 metatileLayerType, u16 *metatiles, u16 offset) { - switch (a) + switch (metatileLayerType) { - case 2: - gBGTilemapBuffers3[c] = b[0]; - gBGTilemapBuffers3[c + 1] = b[1]; - gBGTilemapBuffers3[c + 0x20] = b[2]; - gBGTilemapBuffers3[c + 0x21] = b[3]; + case 2: // LAYER_TYPE_ + // Draw metatile's bottom layer to the bottom background layer. + gBGTilemapBuffers3[offset] = metatiles[0]; + gBGTilemapBuffers3[offset + 1] = metatiles[1]; + gBGTilemapBuffers3[offset + 0x20] = metatiles[2]; + gBGTilemapBuffers3[offset + 0x21] = metatiles[3]; - gBGTilemapBuffers1[c] = 0; - gBGTilemapBuffers1[c + 1] = 0; - gBGTilemapBuffers1[c + 0x20] = 0; - gBGTilemapBuffers1[c + 0x21] = 0; + // Draw transparent tiles to the middle background layer. + gBGTilemapBuffers1[offset] = 0; + gBGTilemapBuffers1[offset + 1] = 0; + gBGTilemapBuffers1[offset + 0x20] = 0; + gBGTilemapBuffers1[offset + 0x21] = 0; - gBGTilemapBuffers2[c] = b[4]; - gBGTilemapBuffers2[c + 1] = b[5]; - gBGTilemapBuffers2[c + 0x20] = b[6]; - gBGTilemapBuffers2[c + 0x21] = b[7]; + // Draw metatile's top layer to the top background layer. + gBGTilemapBuffers2[offset] = metatiles[4]; + gBGTilemapBuffers2[offset + 1] = metatiles[5]; + gBGTilemapBuffers2[offset + 0x20] = metatiles[6]; + gBGTilemapBuffers2[offset + 0x21] = metatiles[7]; break; - case 1: - gBGTilemapBuffers3[c] = b[0]; - gBGTilemapBuffers3[c + 1] = b[1]; - gBGTilemapBuffers3[c + 0x20] = b[2]; - gBGTilemapBuffers3[c + 0x21] = b[3]; + case 1: // LAYER_TYPE_COVERED_BY_OBJECTS + // Draw metatile's bottom layer to the bottom background layer. + gBGTilemapBuffers3[offset] = metatiles[0]; + gBGTilemapBuffers3[offset + 1] = metatiles[1]; + gBGTilemapBuffers3[offset + 0x20] = metatiles[2]; + gBGTilemapBuffers3[offset + 0x21] = metatiles[3]; - gBGTilemapBuffers1[c] = b[4]; - gBGTilemapBuffers1[c + 1] = b[5]; - gBGTilemapBuffers1[c + 0x20] = b[6]; - gBGTilemapBuffers1[c + 0x21] = b[7]; + // Draw metatile's top layer to the middle background layer. + gBGTilemapBuffers1[offset] = metatiles[4]; + gBGTilemapBuffers1[offset + 1] = metatiles[5]; + gBGTilemapBuffers1[offset + 0x20] = metatiles[6]; + gBGTilemapBuffers1[offset + 0x21] = metatiles[7]; - gBGTilemapBuffers2[c] = 0; - gBGTilemapBuffers2[c + 1] = 0; - gBGTilemapBuffers2[c + 0x20] = 0; - gBGTilemapBuffers2[c + 0x21] = 0; + // Draw transparent tiles to the top background layer. + gBGTilemapBuffers2[offset] = 0; + gBGTilemapBuffers2[offset + 1] = 0; + gBGTilemapBuffers2[offset + 0x20] = 0; + gBGTilemapBuffers2[offset + 0x21] = 0; break; - case 0: - gBGTilemapBuffers3[c] = 0x3014; - gBGTilemapBuffers3[c + 1] = 0x3014; - gBGTilemapBuffers3[c + 0x20] = 0x3014; - gBGTilemapBuffers3[c + 0x21] = 0x3014; + case 0: // LAYER_TYPE_NORMAL + // Draw garbage to the bottom background layer. + gBGTilemapBuffers3[offset] = 0x3014; + gBGTilemapBuffers3[offset + 1] = 0x3014; + gBGTilemapBuffers3[offset + 0x20] = 0x3014; + gBGTilemapBuffers3[offset + 0x21] = 0x3014; - gBGTilemapBuffers1[c] = b[0]; - gBGTilemapBuffers1[c + 1] = b[1]; - gBGTilemapBuffers1[c + 0x20] = b[2]; - gBGTilemapBuffers1[c + 0x21] = b[3]; + // Draw metatile's bottom layer to the middle background layer. + gBGTilemapBuffers1[offset] = metatiles[0]; + gBGTilemapBuffers1[offset + 1] = metatiles[1]; + gBGTilemapBuffers1[offset + 0x20] = metatiles[2]; + gBGTilemapBuffers1[offset + 0x21] = metatiles[3]; - gBGTilemapBuffers2[c] = b[4]; - gBGTilemapBuffers2[c + 1] = b[5]; - gBGTilemapBuffers2[c + 0x20] = b[6]; - gBGTilemapBuffers2[c + 0x21] = b[7]; + // Draw metatile's top layer to the top background layer, which covers event object sprites. + gBGTilemapBuffers2[offset] = metatiles[4]; + gBGTilemapBuffers2[offset + 1] = metatiles[5]; + gBGTilemapBuffers2[offset + 0x20] = metatiles[6]; + gBGTilemapBuffers2[offset + 0x21] = metatiles[7]; break; } schedule_bg_copy_tilemap_to_vram(1); @@ -302,51 +311,51 @@ static void DrawMetatile(s32 a, u16 *b, u16 c) schedule_bg_copy_tilemap_to_vram(3); } -static s32 MapPosToBgTilemapOffset(struct FieldCameraUnknownStruct *a, s32 x, s32 y) +static s32 MapPosToBgTilemapOffset(struct FieldCameraOffset *cameraOffset, s32 x, s32 y) { x -= gSaveBlock1Ptr->pos.x; x *= 2; if (x >= 32 || x < 0) return -1; - x = x + a->unk2; + x = x + cameraOffset->xTileOffset; if (x >= 32) x -= 32; y = (y - gSaveBlock1Ptr->pos.y) * 2; if (y >= 32 || y < 0) return -1; - y = y + a->unk3; + y = y + cameraOffset->yTileOffset; if (y >= 32) y -= 32; return y * 32 + x; } -static void CameraUpdateCallback(struct CameraObject *a) +static void CameraUpdateCallback(struct CameraObject *fieldCamera) { - if (a->spriteId != 0) + if (fieldCamera->spriteId != 0) { - a->unk8 = gSprites[a->spriteId].data[2]; - a->unkC = gSprites[a->spriteId].data[3]; + fieldCamera->movementSpeedX = gSprites[fieldCamera->spriteId].data[2]; + fieldCamera->movementSpeedY = gSprites[fieldCamera->spriteId].data[3]; } } void ResetCameraUpdateInfo(void) { - gUnknown_03005DD0.unk8 = 0; - gUnknown_03005DD0.unkC = 0; - gUnknown_03005DD0.x = 0; - gUnknown_03005DD0.y = 0; - gUnknown_03005DD0.spriteId = 0; - gUnknown_03005DD0.callback = NULL; + gFieldCamera.movementSpeedX = 0; + gFieldCamera.movementSpeedY = 0; + gFieldCamera.x = 0; + gFieldCamera.y = 0; + gFieldCamera.spriteId = 0; + gFieldCamera.callback = NULL; } -u32 InitCameraUpdateCallback(u8 a) +u32 InitCameraUpdateCallback(u8 trackedSpriteId) { - if (gUnknown_03005DD0.spriteId != 0) - DestroySprite(&gSprites[gUnknown_03005DD0.spriteId]); - gUnknown_03005DD0.spriteId = AddCameraObject(a); - gUnknown_03005DD0.callback = CameraUpdateCallback; + if (gFieldCamera.spriteId != 0) + DestroySprite(&gSprites[gFieldCamera.spriteId]); + gFieldCamera.spriteId = AddCameraObject(trackedSpriteId); + gFieldCamera.callback = CameraUpdateCallback; return 0; } @@ -354,54 +363,54 @@ void CameraUpdate(void) { int deltaX; int deltaY; - int r0; - int r1; - int r7; - int r8; + int curMovementOffsetY; + int curMovementOffsetX; + int movementSpeedX; + int movementSpeedY; - if (gUnknown_03005DD0.callback != NULL) - gUnknown_03005DD0.callback(&gUnknown_03005DD0); - r7 = gUnknown_03005DD0.unk8; - r8 = gUnknown_03005DD0.unkC; + if (gFieldCamera.callback != NULL) + gFieldCamera.callback(&gFieldCamera); + movementSpeedX = gFieldCamera.movementSpeedX; + movementSpeedY = gFieldCamera.movementSpeedY; deltaX = 0; deltaY = 0; - r1 = gUnknown_03005DD0.x; - r0 = gUnknown_03005DD0.y; + curMovementOffsetX = gFieldCamera.x; + curMovementOffsetY = gFieldCamera.y; - if (r1 == 0 && r7 != 0) + if (curMovementOffsetX == 0 && movementSpeedX != 0) { - if (r7 > 0) + if (movementSpeedX > 0) deltaX = 1; else deltaX = -1; } - if (r0 == 0 && r8 != 0) + if (curMovementOffsetY == 0 && movementSpeedY != 0) { - if (r8 > 0) + if (movementSpeedY > 0) deltaY = 1; else deltaY = -1; } - if (r1 != 0 && r1 == -r7) + if (curMovementOffsetX != 0 && curMovementOffsetX == -movementSpeedX) { - if (r7 > 0) + if (movementSpeedX > 0) deltaX = 1; else deltaX = -1; } - if (r0 != 0 && r0 == -r8) + if (curMovementOffsetY != 0 && curMovementOffsetY == -movementSpeedY) { - if (r8 > 0) + if (movementSpeedY > 0) deltaX = 1; else deltaX = -1; } - gUnknown_03005DD0.x += r7; - gUnknown_03005DD0.x = gUnknown_03005DD0.x - 16 * (gUnknown_03005DD0.x / 16); - gUnknown_03005DD0.y += r8; - gUnknown_03005DD0.y = gUnknown_03005DD0.y - 16 * (gUnknown_03005DD0.y / 16); + gFieldCamera.x += movementSpeedX; + gFieldCamera.x = gFieldCamera.x - 16 * (gFieldCamera.x / 16); + gFieldCamera.y += movementSpeedY; + gFieldCamera.y = gFieldCamera.y - 16 * (gFieldCamera.y / 16); if (deltaX != 0 || deltaY != 0) { @@ -409,50 +418,50 @@ void CameraUpdate(void) UpdateEventObjectsForCameraUpdate(deltaX, deltaY); RotatingGatePuzzleCameraUpdate(deltaX, deltaY); ResetBerryTreeSparkleFlags(); - tilemap_move_something(&gUnknown_03000E20, deltaX * 2, deltaY * 2); - RedrawMapSlicesForCameraUpdate(&gUnknown_03000E20, deltaX * 2, deltaY * 2); + tilemap_move_something(&sFieldCameraOffset, deltaX * 2, deltaY * 2); + RedrawMapSlicesForCameraUpdate(&sFieldCameraOffset, deltaX * 2, deltaY * 2); } - coords8_add(&gUnknown_03000E20, r7, r8); - gUnknown_03005DEC -= r7; - gUnknown_03005DE8 -= r8; + coords8_add(&sFieldCameraOffset, movementSpeedX, movementSpeedY); + gTotalCameraPixelOffsetX -= movementSpeedX; + gTotalCameraPixelOffsetY -= movementSpeedY; } -void camera_move_and_redraw(int a, int b) //unused +void MoveCameraAndRedrawMap(int deltaX, int deltaY) //unused { - CameraMove(a, b); - UpdateEventObjectsForCameraUpdate(a, b); + CameraMove(deltaX, deltaY); + UpdateEventObjectsForCameraUpdate(deltaX, deltaY); DrawWholeMapView(); - gUnknown_03005DEC -= a * 16; - gUnknown_03005DE8 -= b * 16; + gTotalCameraPixelOffsetX -= deltaX * 16; + gTotalCameraPixelOffsetY -= deltaY * 16; } void SetCameraPanningCallback(void (*a)(void)) { - gUnknown_03000E30 = a; + sFieldCameraPanningCallback = a; } void SetCameraPanning(s16 a, s16 b) { - gUnknown_03000E28 = a; - gUnknown_03000E2A = b + 32; + sHorizontalCameraPan = a; + sVerticalCameraPan = b + 32; } void InstallCameraPanAheadCallback(void) { - gUnknown_03000E30 = CameraPanningCB_PanAhead; + sFieldCameraPanningCallback = CameraPanningCB_PanAhead; gUnknown_03000E2C = 0; - gUnknown_03000E28 = 0; - gUnknown_03000E2A = 32; + sHorizontalCameraPan = 0; + sVerticalCameraPan = 32; } void UpdateCameraPanning(void) { - if (gUnknown_03000E30 != NULL) - gUnknown_03000E30(); + if (sFieldCameraPanningCallback != NULL) + sFieldCameraPanningCallback(); //Update sprite offset of overworld objects - gSpriteCoordOffsetX = gUnknown_03005DEC - gUnknown_03000E28; - gSpriteCoordOffsetY = gUnknown_03005DE8 - gUnknown_03000E2A - 8; + gSpriteCoordOffsetX = gTotalCameraPixelOffsetX - sHorizontalCameraPan; + gSpriteCoordOffsetY = gTotalCameraPixelOffsetY - sVerticalCameraPan - 8; } static void CameraPanningCB_PanAhead(void) @@ -480,22 +489,21 @@ static void CameraPanningCB_PanAhead(void) var = GetPlayerMovementDirection(); if (var == 2) { - if (gUnknown_03000E2A > -8) - gUnknown_03000E2A -= 2; + if (sVerticalCameraPan > -8) + sVerticalCameraPan -= 2; } else if (var == 1) { - if (gUnknown_03000E2A < 72) - gUnknown_03000E2A += 2; + if (sVerticalCameraPan < 72) + sVerticalCameraPan += 2; } - else if (gUnknown_03000E2A < 32) + else if (sVerticalCameraPan < 32) { - gUnknown_03000E2A += 2; + sVerticalCameraPan += 2; } - else if (gUnknown_03000E2A > 32) + else if (sVerticalCameraPan > 32) { - gUnknown_03000E2A -= 2; + sVerticalCameraPan -= 2; } } } - diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 738826020..3451ad22d 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -179,7 +179,7 @@ void FieldGetPlayerInput(struct FieldInput *input, u16 newKeys, u16 heldKeys) input->dpadDirection = DIR_EAST; } -int sub_809C014(struct FieldInput *input) +int ProcessPlayerFieldInput(struct FieldInput *input) { struct MapPosition position; u8 playerDirection; diff --git a/src/field_effect.c b/src/field_effect.c index 467acb367..594d75c95 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -1,10 +1,9 @@ #include "global.h" -#include "field_effect.h" -#include "trainer_pokemon_sprites.h" #include "decompress.h" -#include "field_camera.h" -#include "field_effect_helpers.h" #include "event_object_movement.h" +#include "field_camera.h" +#include "field_effect.h" +#include "field_effect_helpers.h" #include "field_player_avatar.h" #include "field_screen.h" #include "field_weather.h" @@ -22,8 +21,10 @@ #include "sound.h" #include "sprite.h" #include "task.h" +#include "trainer_pokemon_sprites.h" #include "trig.h" #include "util.h" +#include "constants/event_object_movement_constants.h" #include "constants/rgb.h" #include "constants/songs.h" @@ -322,9 +323,9 @@ bool8 (*const gUnknown_0855C460[])(struct Task *, struct EventObject *, struct S sub_80B7BF4, }; -void (*const gUnknown_0855C474[])(struct Task *) = { - sub_80B7D14, - sub_80B7D34, +void (*const gEscapeRopeFieldEffectFuncs[])(struct Task *) = { + EscapeRopeFieldEffect_Step0, + EscapeRopeFieldEffect_Step1, }; // .text @@ -1686,7 +1687,7 @@ bool8 sub_80B7478(struct Task *task, struct EventObject *eventObject) return FALSE; } -void Task_Dive(u8); +static void Task_Dive(u8); extern int dive_warp(struct MapPosition *, u16); bool8 FldEff_UseDive(void) @@ -1999,7 +2000,7 @@ bool8 sub_80B7BCC(struct Task *task, struct EventObject *eventObject, struct Spr return FALSE; } -void sub_80B7CE4(u8); +static void DoEscapeRopeFieldEffect(u8); void mapldr_080859D4(void); bool8 sub_80B7BF4(struct Task *task, struct EventObject *eventObject, struct Sprite *sprite) @@ -2032,29 +2033,29 @@ void sub_80B7CAC(struct Sprite *sprite) } } -void sub_80B7CC8(void) +void StartEscapeRopeFieldEffect(void) { ScriptContext2_Enable(); FreezeEventObjects(); - CreateTask(sub_80B7CE4, 0x50); + CreateTask(DoEscapeRopeFieldEffect, 0x50); } -void sub_80B7CE4(u8 taskId) +static void DoEscapeRopeFieldEffect(u8 taskId) { - gUnknown_0855C474[gTasks[taskId].data[0]](&gTasks[taskId]); + gEscapeRopeFieldEffectFuncs[gTasks[taskId].data[0]](&gTasks[taskId]); } -void sub_80B7D14(struct Task *task) +static void EscapeRopeFieldEffect_Step0(struct Task *task) { task->data[0]++; task->data[14] = 64; task->data[15] = GetPlayerFacingDirection(); } -void sub_80B7D34(struct Task *task) +static void EscapeRopeFieldEffect_Step1(struct Task *task) { struct EventObject *eventObject; - u8 spinDirections[5] = {1, 3, 4, 2, 1}; + u8 spinDirections[5] = {DIR_SOUTH, DIR_WEST, DIR_EAST, DIR_NORTH, DIR_SOUTH}; if (task->data[14] != 0 && (--task->data[14]) == 0) { music_something(); @@ -2070,7 +2071,7 @@ void sub_80B7D34(struct Task *task) WarpIntoMap(); gFieldCallback = mapldr_080859D4; SetMainCallback2(CB2_LoadMap); - DestroyTask(FindTaskIdByFunc(sub_80B7CE4)); + DestroyTask(FindTaskIdByFunc(DoEscapeRopeFieldEffect)); } else if (task->data[1] == 0 || (--task->data[1]) == 0) { EventObjectSetHeldMovement(eventObject, GetFaceDirectionMovementAction(spinDirections[eventObject->facingDirection])); @@ -2905,7 +2906,7 @@ void sub_80B8E14(struct Task *task) if (!EventObjectIsMovementOverridden(eventObject) || EventObjectClearHeldMovementIfFinished(eventObject)) { sub_808C114(); - EventObjectSetHeldMovement(eventObject, 0x39); + EventObjectSetHeldMovement(eventObject, MOVEMENT_ACTION_START_ANIM_IN_DIRECTION); task->data[0]++; } } @@ -3210,7 +3211,7 @@ void sub_80B9204(struct Task *task) gPlayerAvatar.preventStep = TRUE; SetPlayerAvatarStateMask(1); sub_808C114(); - EventObjectSetHeldMovement(eventObject, 0x39); + EventObjectSetHeldMovement(eventObject, MOVEMENT_ACTION_START_ANIM_IN_DIRECTION); task->data[0]++; } } @@ -3250,7 +3251,7 @@ void sub_80B92F8(struct Task *task) task->data[0]++; task->data[2] = 16; SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ON_FOOT); - EventObjectSetHeldMovement(&gEventObjects[gPlayerAvatar.eventObjectId], 0x02); + EventObjectSetHeldMovement(&gEventObjects[gPlayerAvatar.eventObjectId], MOVEMENT_ACTION_FACE_LEFT); } } @@ -3275,7 +3276,7 @@ void sub_80B9390(struct Task *task) EventObjectSetGraphicsId(eventObject, GetPlayerAvatarGraphicsIdByStateId(0x03)); StartSpriteAnim(&gSprites[eventObject->spriteId], 0x16); eventObject->inanimate = 1; - EventObjectSetHeldMovement(eventObject, 0x48); + EventObjectSetHeldMovement(eventObject, MOVEMENT_ACTION_JUMP_IN_PLACE_LEFT); if (task->data[15] & 0x08) { DestroySprite(&gSprites[eventObject->fieldEffectSpriteId]); @@ -3585,7 +3586,7 @@ void sub_80B9978(struct Task *task) sprite->pos2.y = 0; sprite->coordOffsetEnabled = 1; sub_808C114(); - EventObjectSetHeldMovement(eventObject, 0x39); + EventObjectSetHeldMovement(eventObject, MOVEMENT_ACTION_START_ANIM_IN_DIRECTION); task->data[0]++; } } @@ -3791,8 +3792,8 @@ const struct SpriteTemplate gUnknown_0855C5EC = { void sub_80B9D24(struct Sprite* sprite) { int i; - int xPos = (s16)gUnknown_03005DEC + sprite->pos1.x + sprite->pos2.x; - int yPos = (s16)gUnknown_03005DE8 + sprite->pos1.y + sprite->pos2.y - 4; + int xPos = (s16)gTotalCameraPixelOffsetX + sprite->pos1.x + sprite->pos2.x; + int yPos = (s16)gTotalCameraPixelOffsetY + sprite->pos1.y + sprite->pos2.y - 4; for (i = 0; i < 4; i++) { diff --git a/src/field_effect_helpers.c b/src/field_effect_helpers.c index 3534e0a71..6f4aaabed 100755 --- a/src/field_effect_helpers.c +++ b/src/field_effect_helpers.c @@ -14,22 +14,22 @@ #define EVENT_OBJ_PAL_TAG_NONE 0x11FF // duplicate of define in event_object_movement.c -void UpdateObjectReflectionSprite(struct Sprite *); -void LoadObjectReflectionPalette(struct EventObject *eventObject, struct Sprite *sprite); -void LoadObjectHighBridgeReflectionPalette(struct EventObject *, u8); -void LoadObjectRegularReflectionPalette(struct EventObject *, u8); -void sub_81561FC(struct Sprite *, u8, u8); -void FadeFootprintsTireTracks_Step0(struct Sprite *); -void FadeFootprintsTireTracks_Step1(struct Sprite *); -void UpdateFeetInFlowingWaterFieldEffect(struct Sprite *); -void UpdateAshFieldEffect_Step0(struct Sprite *); -void UpdateAshFieldEffect_Step1(struct Sprite *); -void UpdateAshFieldEffect_Step2(struct Sprite *); -void sub_81556B0(struct EventObject *, struct Sprite *); -void sub_81556E8(struct EventObject *, struct Sprite *); -void sub_815577C(struct EventObject *, struct Sprite *, struct Sprite *); -void sub_8155850(struct Sprite *); -u32 ShowDisguiseFieldEffect(u8, u8, u8); +static void UpdateObjectReflectionSprite(struct Sprite *); +static void LoadObjectReflectionPalette(struct EventObject *eventObject, struct Sprite *sprite); +static void LoadObjectHighBridgeReflectionPalette(struct EventObject *, u8); +static void LoadObjectRegularReflectionPalette(struct EventObject *, u8); +static void sub_81561FC(struct Sprite *, u8, u8); +static void FadeFootprintsTireTracks_Step0(struct Sprite *); +static void FadeFootprintsTireTracks_Step1(struct Sprite *); +static void UpdateFeetInFlowingWaterFieldEffect(struct Sprite *); +static void UpdateAshFieldEffect_Step0(struct Sprite *); +static void UpdateAshFieldEffect_Step1(struct Sprite *); +static void UpdateAshFieldEffect_Step2(struct Sprite *); +static void SynchroniseSurfAnim(struct EventObject *, struct Sprite *); +static void sub_81556E8(struct EventObject *, struct Sprite *); +static void CreateBobbingEffect(struct EventObject *, struct Sprite *, struct Sprite *); +static void sub_8155850(struct Sprite *); +static u32 ShowDisguiseFieldEffect(u8, u8, u8); void SetUpReflection(struct EventObject *eventObject, struct Sprite *sprite, bool8 stillReflection) { @@ -59,12 +59,12 @@ static s16 GetReflectionVerticalOffset(struct EventObject *eventObject) return GetEventObjectGraphicsInfo(eventObject->graphicsId)->height - 2; } -void LoadObjectReflectionPalette(struct EventObject *eventObject, struct Sprite *sprite) +static void LoadObjectReflectionPalette(struct EventObject *eventObject, struct Sprite *sprite) { u8 bridgeType; u16 bridgeReflectionVerticalOffsets[] = { 12, 28, 44 }; sprite->data[2] = 0; - if (!GetEventObjectGraphicsInfo(eventObject->graphicsId)->disableReflectionPaletteLoad && ((bridgeType = MetatileBehavior_GetBridgeSth(eventObject->previousMetatileBehavior)) || (bridgeType = MetatileBehavior_GetBridgeSth(eventObject->currentMetatileBehavior)))) + if (!GetEventObjectGraphicsInfo(eventObject->graphicsId)->disableReflectionPaletteLoad && ((bridgeType = MetatileBehavior_GetBridgeType(eventObject->previousMetatileBehavior)) || (bridgeType = MetatileBehavior_GetBridgeType(eventObject->currentMetatileBehavior)))) { sprite->data[2] = bridgeReflectionVerticalOffsets[bridgeType - 1]; LoadObjectHighBridgeReflectionPalette(eventObject, sprite->oam.paletteNum); @@ -75,7 +75,7 @@ void LoadObjectReflectionPalette(struct EventObject *eventObject, struct Sprite } } -void LoadObjectRegularReflectionPalette(struct EventObject *eventObject, u8 paletteIndex) +static void LoadObjectRegularReflectionPalette(struct EventObject *eventObject, u8 paletteIndex) { const struct EventObjectGraphicsInfo *graphicsInfo; @@ -100,7 +100,7 @@ void LoadObjectRegularReflectionPalette(struct EventObject *eventObject, u8 pale // When walking on a bridge high above water (Route 120), the reflection is a solid dark blue color. // This is so the sprite blends in with the dark water metatile underneath the bridge. -void LoadObjectHighBridgeReflectionPalette(struct EventObject *eventObject, u8 paletteNum) +static void LoadObjectHighBridgeReflectionPalette(struct EventObject *eventObject, u8 paletteNum) { const struct EventObjectGraphicsInfo *graphicsInfo; @@ -112,7 +112,7 @@ void LoadObjectHighBridgeReflectionPalette(struct EventObject *eventObject, u8 p } } -void UpdateObjectReflectionSprite(struct Sprite *reflectionSprite) +static void UpdateObjectReflectionSprite(struct Sprite *reflectionSprite) { struct EventObject *eventObject; struct Sprite *mainSprite; @@ -579,7 +579,7 @@ void UpdateFootprintsTireTracksFieldEffect(struct Sprite *sprite) gFadeFootprintsTireTracksFuncs[sprite->data[0]](sprite); } -void FadeFootprintsTireTracks_Step0(struct Sprite *sprite) +static void FadeFootprintsTireTracks_Step0(struct Sprite *sprite) { // Wait 40 frames before the flickering starts. if (++sprite->data[1] > 40) @@ -588,7 +588,7 @@ void FadeFootprintsTireTracks_Step0(struct Sprite *sprite) UpdateEventObjectSpriteVisibility(sprite, FALSE); } -void FadeFootprintsTireTracks_Step1(struct Sprite *sprite) +static void FadeFootprintsTireTracks_Step1(struct Sprite *sprite) { sprite->invisible ^= 1; sprite->data[1]++; @@ -708,7 +708,7 @@ u32 FldEff_FeetInFlowingWater(void) return 0; } -void UpdateFeetInFlowingWaterFieldEffect(struct Sprite *sprite) +static void UpdateFeetInFlowingWaterFieldEffect(struct Sprite *sprite) { u8 eventObjectId; struct Sprite *linkedSprite; @@ -913,7 +913,7 @@ void UpdateAshFieldEffect(struct Sprite *sprite) gAshFieldEffectFuncs[sprite->data[0]](sprite); } -void UpdateAshFieldEffect_Step0(struct Sprite *sprite) +static void UpdateAshFieldEffect_Step0(struct Sprite *sprite) { sprite->invisible = TRUE; sprite->animPaused = TRUE; @@ -921,7 +921,7 @@ void UpdateAshFieldEffect_Step0(struct Sprite *sprite) sprite->data[0] = 1; } -void UpdateAshFieldEffect_Step1(struct Sprite *sprite) +static void UpdateAshFieldEffect_Step1(struct Sprite *sprite) { sprite->invisible = FALSE; sprite->animPaused = FALSE; @@ -931,7 +931,7 @@ void UpdateAshFieldEffect_Step1(struct Sprite *sprite) sprite->data[0] = 2; } -void UpdateAshFieldEffect_Step2(struct Sprite *sprite) +static void UpdateAshFieldEffect_Step2(struct Sprite *sprite) { UpdateEventObjectSpriteVisibility(sprite, FALSE); if (sprite->animEnded) @@ -975,17 +975,17 @@ void sub_8155604(u8 spriteId, u8 value, s16 data1) gSprites[spriteId].data[1] = data1; } -u8 sub_8155638(struct Sprite *sprite) +static u8 sub_8155638(struct Sprite *sprite) { return sprite->data[0] & 0xF; } -u8 sub_8155640(struct Sprite *sprite) +static u8 sub_8155640(struct Sprite *sprite) { return (sprite->data[0] & 0xF0) >> 4; } -u8 sub_815564C(struct Sprite *sprite) +static u8 sub_815564C(struct Sprite *sprite) { return (sprite->data[0] & 0xF00) >> 8; } @@ -997,13 +997,13 @@ void UpdateSurfBlobFieldEffect(struct Sprite *sprite) eventObject = &gEventObjects[sprite->data[2]]; linkedSprite = &gSprites[eventObject->spriteId]; - sub_81556B0(eventObject, sprite); + SynchroniseSurfAnim(eventObject, sprite); sub_81556E8(eventObject, sprite); - sub_815577C(eventObject, linkedSprite, sprite); + CreateBobbingEffect(eventObject, linkedSprite, sprite); sprite->oam.priority = linkedSprite->oam.priority; } -void sub_81556B0(struct EventObject *eventObject, struct Sprite *sprite) +static void SynchroniseSurfAnim(struct EventObject *eventObject, struct Sprite *sprite) { u8 surfBlobDirectionAnims[] = { 0, // DIR_NONE @@ -1126,7 +1126,7 @@ _08155770:\n\ } #endif -void sub_815577C(struct EventObject *eventObject, struct Sprite *linkedSprite, struct Sprite *sprite) +static void CreateBobbingEffect(struct EventObject *eventObject, struct Sprite *linkedSprite, struct Sprite *sprite) { u16 unk_085CDC6A[] = {3, 7}; u8 v0 = sub_8155638(sprite); @@ -1166,7 +1166,7 @@ u8 sub_8155800(u8 oldSpriteId) return spriteId; } -void sub_8155850(struct Sprite *sprite) +static void sub_8155850(struct Sprite *sprite) { struct Sprite *oldSprite; @@ -1320,7 +1320,7 @@ u32 ShowSandDisguiseFieldEffect(void) return ShowDisguiseFieldEffect(FLDEFF_SAND_DISGUISE, 28, 2); } -u32 ShowDisguiseFieldEffect(u8 fldEff, u8 templateIdx, u8 paletteNum) +static u32 ShowDisguiseFieldEffect(u8 fldEff, u8 templateIdx, u8 paletteNum) { u8 spriteId; struct Sprite *sprite; @@ -1619,7 +1619,7 @@ void sub_8156194(struct Sprite *sprite) } } -void sub_81561D0(struct Sprite *sprite) +void WaitFieldEffectSpriteAnim(struct Sprite *sprite) { if (sprite->animEnded) FieldEffectStop(sprite, sprite->data[0]); @@ -1628,7 +1628,7 @@ void sub_81561D0(struct Sprite *sprite) } #ifdef NONMATCHING -void sub_81561FC(struct Sprite *sprite /*r6*/, u8 z, u8 offset) +static void sub_81561FC(struct Sprite *sprite /*r6*/, u8 z, u8 offset) { u8 i; s16 xlo; diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index cb2beacee..df714d7db 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -32,7 +32,7 @@ #include "constants/species.h" static EWRAM_DATA u8 gUnknown_0203734C = 0; -EWRAM_DATA struct EventObject gEventObjects[NUM_EVENT_OBJECTS] = {}; +EWRAM_DATA struct EventObject gEventObjects[EVENT_OBJECTS_COUNT] = {}; EWRAM_DATA struct PlayerAvatar gPlayerAvatar = {}; static void StartStrengthAnim(u8, u8); @@ -123,7 +123,7 @@ static u8 Fishing14(struct Task *task); static u8 Fishing15(struct Task *task); static u8 Fishing16(struct Task *task); -static bool8 (*const gUnknown_084973FC[])(u8) = +static bool8 (*const sForcedMovementTestFuncs[])(u8) = { MetatileBehavior_IsTrickHouseSlipperyFloor, MetatileBehavior_IsIce_2, @@ -145,7 +145,7 @@ static bool8 (*const gUnknown_084973FC[])(u8) = MetatileBehavior_IsMuddySlope, }; -static bool8 (*const gUnknown_08497444[])(void) = +static bool8 (*const sForcedMovementFuncs[])(void) = { ForcedMovement_None, ForcedMovement_Slip, @@ -285,12 +285,12 @@ static bool8 (*const sPlayerAvatarSecretBaseMatSpin[])(struct Task *, struct Eve // .text void MovementType_Player(struct Sprite *sprite) { - UpdateEventObjectCurrentMovement(&gEventObjects[sprite->data[0]], sprite, EventObjectCB2_NoMovement2); + UpdateEventObjectCurrentMovement(&gEventObjects[sprite->data[0]], sprite, EventObjectCB2_NoMovement2); } static u8 EventObjectCB2_NoMovement2(void) { - return 0; + return 0; } void player_step(u8 direction, u16 newKeys, u16 heldKeys) @@ -380,7 +380,7 @@ static void PlayerAllowForcedMovementIfMovingSameDirection(void) static bool8 TryDoMetatileBehaviorForcedMovement(void) { - return gUnknown_08497444[GetForcedMovementByMetatileBehavior()](); + return sForcedMovementFuncs[GetForcedMovementByMetatileBehavior()](); } static u8 GetForcedMovementByMetatileBehavior(void) @@ -393,7 +393,7 @@ static u8 GetForcedMovementByMetatileBehavior(void) for (i = 0; i < 18; i++) { - if (gUnknown_084973FC[i](metatileBehavior)) + if (sForcedMovementTestFuncs[i](metatileBehavior)) return i + 1; } } @@ -622,7 +622,7 @@ static void PlayerNotOnBikeMoving(u8 direction, u16 heldKeys) if (gPlayerAvatar.flags & PLAYER_AVATAR_FLAG_SURFING) { - // speed 2 is fast, same speed as running + // speed 2 is fast, same speed as running PlayerGoSpeed2(direction); return; } @@ -1700,7 +1700,7 @@ static bool8 (*const sFishingStateFuncs[])(struct Task *) = }; static void Task_Fishing(u8 taskId); -static void sub_808CF78(void); +static void AlignFishingAnimationFrames(void); #define tStep data[0] #define tFrameCounter data[1] @@ -1759,7 +1759,7 @@ static bool8 Fishing2(struct Task *task) static bool8 Fishing3(struct Task *task) { - sub_808CF78(); + AlignFishingAnimationFrames(); // Wait one second task->tFrameCounter++; @@ -1791,7 +1791,7 @@ static bool8 Fishing5(struct Task *task) { const u8 dot[] = _("·"); - sub_808CF78(); + AlignFishingAnimationFrames(); task->tFrameCounter++; if (gMain.newKeys & A_BUTTON) { @@ -1827,7 +1827,7 @@ static bool8 Fishing6(struct Task *task) { bool8 bite; - sub_808CF78(); + AlignFishingAnimationFrames(); task->tStep++; bite = FALSE; @@ -1872,7 +1872,7 @@ static bool8 Fishing6(struct Task *task) // Oh! A Bite! static bool8 Fishing7(struct Task *task) { - sub_808CF78(); + AlignFishingAnimationFrames(); AddTextPrinterParameterized(0, 1, gText_OhABite, 0, 17, 0, NULL); task->tStep++; task->tFrameCounter = 0; @@ -1884,7 +1884,7 @@ static bool8 Fishing8(struct Task *task) { const s16 reelTimeouts[3] = {36, 33, 30}; - sub_808CF78(); + AlignFishingAnimationFrames(); task->tFrameCounter++; if (task->tFrameCounter >= reelTimeouts[task->tFishingRod]) task->tStep = FISHING_GOT_AWAY; @@ -1903,7 +1903,7 @@ static bool8 Fishing9(struct Task *task) {70, 30} }; - sub_808CF78(); + AlignFishingAnimationFrames(); task->tStep++; if (task->tRoundsPlayed < task->tMinRoundsRequired) { @@ -1922,7 +1922,7 @@ static bool8 Fishing9(struct Task *task) static bool8 Fishing10(struct Task *task) { - sub_808CF78(); + AlignFishingAnimationFrames(); FillWindowPixelBuffer(0, 0x11); AddTextPrinterParameterized2(0, 1, gText_PokemonOnHook, 1, 0, 2, 1, 3); task->tStep++; @@ -1933,7 +1933,7 @@ static bool8 Fishing10(struct Task *task) static bool8 Fishing11(struct Task *task) { if (task->tFrameCounter == 0) - sub_808CF78(); + AlignFishingAnimationFrames(); RunTextPrinters(); @@ -1969,7 +1969,7 @@ static bool8 Fishing11(struct Task *task) // Not even a nibble static bool8 Fishing12(struct Task *task) { - sub_808CF78(); + AlignFishingAnimationFrames(); StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFishingNoCatchDirectionAnimNum(GetPlayerFacingDirection())); FillWindowPixelBuffer(0, 0x11); AddTextPrinterParameterized2(0, 1, gText_NotEvenANibble, 1, 0, 2, 1, 3); @@ -1980,7 +1980,7 @@ static bool8 Fishing12(struct Task *task) // It got away static bool8 Fishing13(struct Task *task) { - sub_808CF78(); + AlignFishingAnimationFrames(); StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFishingNoCatchDirectionAnimNum(GetPlayerFacingDirection())); FillWindowPixelBuffer(0, 0x11); AddTextPrinterParameterized2(0, 1, gText_ItGotAway, 1, 0, 2, 1, 3); @@ -1991,14 +1991,14 @@ static bool8 Fishing13(struct Task *task) // Wait one second static bool8 Fishing14(struct Task *task) { - sub_808CF78(); + AlignFishingAnimationFrames(); task->tStep++; return FALSE; } static bool8 Fishing15(struct Task *task) { - sub_808CF78(); + AlignFishingAnimationFrames(); if (gSprites[gPlayerAvatar.spriteId].animEnded) { struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; @@ -2033,7 +2033,7 @@ static bool8 Fishing16(struct Task *task) #undef tFrameCounter #undef tFishingRod -static void sub_808CF78(void) +static void AlignFishingAnimationFrames(void) { struct Sprite *playerSprite = &gSprites[gPlayerAvatar.spriteId]; u8 animCmdIndex; @@ -2114,7 +2114,7 @@ static void sub_808D094(u8 taskId) data[3] -= data[2]; data[2] += 3; sprite->pos1.y = data[3] >> 4; - if (sprite->pos1.y + (s16)gUnknown_03005DE8 < -32) + if (sprite->pos1.y + (s16)gTotalCameraPixelOffsetY < -32) { data[0]++; } diff --git a/src/field_poison.c b/src/field_poison.c index e2fd994fc..fd7aeb7e4 100644 --- a/src/field_poison.c +++ b/src/field_poison.c @@ -1,22 +1,22 @@ #include "global.h" -#include "string_util.h" -#include "party_menu.h" -#include "constants/species.h" -#include "task.h" -#include "field_message_box.h" -#include "strings.h" -#include "rom_818CFC8.h" -#include "frontier_util.h" -#include "pokenav.h" -#include "event_data.h" -#include "script.h" #include "battle.h" -#include "fldeff_80F9BCC.h" +#include "event_data.h" +#include "field_message_box.h" #include "field_poison.h" +#include "fldeff_80F9BCC.h" +#include "frontier_util.h" +#include "party_menu.h" +#include "pokenav.h" +#include "rom_818CFC8.h" +#include "script.h" +#include "string_util.h" +#include "strings.h" +#include "task.h" +#include "constants/species.h" extern bool8 InBattlePike(void); -static bool32 sub_80F9568(struct Pokemon *pokemon) +static bool32 IsMonValidSpecies(struct Pokemon *pokemon) { u16 species = GetMonData(pokemon, MON_DATA_SPECIES2); if (species == SPECIES_NONE || species == SPECIES_EGG) @@ -26,14 +26,14 @@ static bool32 sub_80F9568(struct Pokemon *pokemon) return TRUE; } -static bool32 sub_80F958C(void) +static bool32 AllMonsFainted(void) { int i; - struct Pokemon *pokemon; + struct Pokemon *pokemon = gPlayerParty; - for (pokemon = gPlayerParty, i = 0; i < PARTY_SIZE; i++, pokemon++) + for (i = 0; i < PARTY_SIZE; i++, pokemon++) { - if (sub_80F9568(pokemon) && GetMonData(pokemon, MON_DATA_HP) != 0) + if (IsMonValidSpecies(pokemon) && GetMonData(pokemon, MON_DATA_HP) != 0) { return FALSE; } @@ -41,27 +41,28 @@ static bool32 sub_80F958C(void) return TRUE; } -static void sub_80F95C0(u8 partyIdx) +static void FaintFromFieldPoison(u8 partyIdx) { struct Pokemon *pokemon = gPlayerParty + partyIdx; - unsigned int status = STATUS1_NONE; + u32 status = STATUS1_NONE; + AdjustFriendship(pokemon, 0x07); SetMonData(pokemon, MON_DATA_STATUS, &status); GetMonData(pokemon, MON_DATA_NICKNAME, gStringVar1); StringGetEnd10(gStringVar1); } -static bool32 sub_80F960C(u8 partyIdx) +static bool32 MonFaintedFromPoison(u8 partyIdx) { struct Pokemon *pokemon = gPlayerParty + partyIdx; - if (sub_80F9568(pokemon) && GetMonData(pokemon, MON_DATA_HP) == 0 && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN) + if (IsMonValidSpecies(pokemon) && GetMonData(pokemon, MON_DATA_HP) == 0 && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN) { return TRUE; } return FALSE; } -static void sub_80F9654(u8 taskId) +static void Task_WhiteOut(u8 taskId) { s16 *data = gTasks[taskId].data; switch (data[0]) @@ -69,9 +70,9 @@ static void sub_80F9654(u8 taskId) case 0: for (; data[1] < PARTY_SIZE; data[1]++) { - if (sub_80F960C(data[1])) + if (MonFaintedFromPoison(data[1])) { - sub_80F95C0(data[1]); + FaintFromFieldPoison(data[1]); ShowFieldMessage(gText_PkmnFainted3); data[0]++; return; @@ -86,7 +87,7 @@ static void sub_80F9654(u8 taskId) } break; case 2: - if (sub_80F958C()) + if (AllMonsFainted()) { if (InBattlePyramid() | InBattlePike() || sub_81D5C18()) { @@ -107,19 +108,19 @@ static void sub_80F9654(u8 taskId) } } -void sub_80F972C(void) +void ExecuteWhiteOut(void) { - CreateTask(sub_80F9654, 80); + CreateTask(Task_WhiteOut, 80); ScriptContext1_Stop(); } -int DoPoisonFieldEffect(void) +s32 DoPoisonFieldEffect(void) { int i; - unsigned int hp; + u32 hp; struct Pokemon *pokemon = gPlayerParty; - unsigned int numPoisoned = 0; - unsigned int numFainted = 0; + u32 numPoisoned = 0; + u32 numFainted = 0; for (i = 0; i < PARTY_SIZE; i++) { if (GetMonData(pokemon, MON_DATA_SANITY_BIT2) && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN) @@ -136,7 +137,7 @@ int DoPoisonFieldEffect(void) } if (numFainted != 0 || numPoisoned != 0) { - overworld_poison_effect(); + FldeffPoison_Start(); } if (numFainted != 0) { diff --git a/src/field_specials.c b/src/field_specials.c index 522cbdf94..1834f3523 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -595,7 +595,7 @@ static void LoadLinkPartnerEventObjectSpritePalette(u8 graphicsId, u8 localEvent graphicsId == EVENT_OBJ_GFX_RIVAL_MAY_NORMAL) { u8 obj = GetEventObjectIdByLocalIdAndMap(localEventId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); - if (obj != NUM_EVENT_OBJECTS) + if (obj != EVENT_OBJECTS_COUNT) { u8 spriteId = gEventObjects[obj].spriteId; struct Sprite *sprite = &gSprites[spriteId]; @@ -1513,7 +1513,7 @@ bool8 FoundBlackGlasses(void) void SetRoute119Weather(void) { - if (is_map_type_1_2_3_5_or_6(get_map_light_from_warp0()) != TRUE) + if (is_map_type_1_2_3_5_or_6(GetLastUsedWarpMapType()) != TRUE) { SetSav1Weather(20); } @@ -1521,7 +1521,7 @@ void SetRoute119Weather(void) void SetRoute123Weather(void) { - if (is_map_type_1_2_3_5_or_6(get_map_light_from_warp0()) != TRUE) + if (is_map_type_1_2_3_5_or_6(GetLastUsedWarpMapType()) != TRUE) { SetSav1Weather(21); } diff --git a/src/fldeff_flash.c b/src/fldeff_flash.c index 0c6fdd8b8..fe219422d 100644 --- a/src/fldeff_flash.c +++ b/src/fldeff_flash.c @@ -156,7 +156,7 @@ void c2_change_map(void) static bool8 sub_8137304(void) { u8 i; - u8 v0 = get_map_light_from_warp0(); + u8 v0 = GetLastUsedWarpMapType(); u8 v1 = Overworld_GetMapTypeOfSaveblockLocation(); for (i = 0; gUnknown_085B27C8[i].unk0; i++) diff --git a/src/fldeff_sweetscent.c b/src/fldeff_sweetscent.c index f592ed532..ca95af382 100644 --- a/src/fldeff_sweetscent.c +++ b/src/fldeff_sweetscent.c @@ -1,6 +1,4 @@ #include "global.h" -#include "constants/rgb.h" -#include "constants/songs.h" #include "event_data.h" #include "event_scripts.h" #include "field_effect.h" @@ -14,22 +12,24 @@ #include "sprite.h" #include "task.h" #include "wild_encounter.h" +#include "constants/rgb.h" +#include "constants/songs.h" -void hm2_sweet_scent(void); -void sub_8159F5C(void); -void sub_8159FEC(u8 taskId); -void sub_815A090(u8 taskId); +static void FieldCallback_SweetScent(void); +static void StartSweetScentFieldEffect(void); +static void TrySweetScentEncounter(u8 taskId); +static void FailSweetScentEncounter(u8 taskId); void sub_81BE6B8(void); void sub_81BE72C(void); bool8 SetUpFieldMove_SweetScent(void) { gFieldCallback2 = FieldCallback_PrepareFadeInFromMenu; - gPostMenuFieldCallback = hm2_sweet_scent; + gPostMenuFieldCallback = FieldCallback_SweetScent; return TRUE; } -void hm2_sweet_scent(void) +static void FieldCallback_SweetScent(void) { FieldEffectStart(FLDEFF_SWEET_SCENT); gFieldEffectArguments[0] = GetCursorSelectionMonId(); @@ -41,12 +41,12 @@ bool8 FldEff_SweetScent(void) sub_80AC3D0(); taskId = oei_task_add(); - gTasks[taskId].data[8] = (u32)sub_8159F5C >> 16; - gTasks[taskId].data[9] = (u32)sub_8159F5C; + gTasks[taskId].data[8] = (u32)StartSweetScentFieldEffect >> 16; + gTasks[taskId].data[9] = (u32)StartSweetScentFieldEffect; return FALSE; } -void sub_8159F5C(void) +static void StartSweetScentFieldEffect(void) { u8 taskId; @@ -54,12 +54,12 @@ void sub_8159F5C(void) CpuFastSet(gPlttBufferUnfaded, gPaletteDecompressionBuffer, 0x100); CpuFastSet(gPlttBufferFaded, gPlttBufferUnfaded, 0x100); BeginNormalPaletteFade(~(1 << (gSprites[GetPlayerAvatarObjectId()].oam.paletteNum + 16)), 4, 0, 8, RGB_RED); - taskId = CreateTask(sub_8159FEC, 0); + taskId = CreateTask(TrySweetScentEncounter, 0); gTasks[taskId].data[0] = 0; FieldEffectActiveListRemove(FLDEFF_SWEET_SCENT); } -void sub_8159FEC(u8 taskId) +static void TrySweetScentEncounter(u8 taskId) { if (!gPaletteFade.active) { @@ -74,7 +74,7 @@ void sub_8159FEC(u8 taskId) } else { - gTasks[taskId].func = sub_815A090; + gTasks[taskId].func = FailSweetScentEncounter; BeginNormalPaletteFade(~(1 << (gSprites[GetPlayerAvatarObjectId()].oam.paletteNum + 16)), 4, 8, 0, RGB_RED); sub_81BE6B8(); } @@ -86,7 +86,7 @@ void sub_8159FEC(u8 taskId) } } -void sub_815A090(u8 taskId) +static void FailSweetScentEncounter(u8 taskId) { if (!gPaletteFade.active) { diff --git a/src/fldeff_teleport.c b/src/fldeff_teleport.c index e82a26cd1..ebf9aa38a 100644 --- a/src/fldeff_teleport.c +++ b/src/fldeff_teleport.c @@ -1,5 +1,4 @@ #include "global.h" -#include "fldeff_teleport.h" #include "field_effect.h" #include "field_player_avatar.h" #include "party_menu.h" @@ -7,18 +6,21 @@ #include "rom6.h" #include "task.h" +static void FieldCallback_Teleport(void); +static void StartTeleportFieldEffect(void); + bool8 SetUpFieldMove_Teleport(void) { if (Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType) == TRUE) { gFieldCallback2 = FieldCallback_PrepareFadeInFromMenu; - gPostMenuFieldCallback = hm_teleport_run_dp02scr; + gPostMenuFieldCallback = FieldCallback_Teleport; return TRUE; } return FALSE; } -void hm_teleport_run_dp02scr(void) +static void FieldCallback_Teleport(void) { Overworld_ResetStateAfterTeleport(); FieldEffectStart(FLDEFF_USE_TELEPORT); @@ -28,16 +30,14 @@ void hm_teleport_run_dp02scr(void) bool8 FldEff_UseTeleport(void) { u8 taskId = oei_task_add(); - gTasks[taskId].data[8] = (u32)sub_817C94C >> 16; - gTasks[taskId].data[9] = (u32)sub_817C94C; - SetPlayerAvatarTransitionFlags(1); + gTasks[taskId].data[8] = (u32)StartTeleportFieldEffect >> 16; + gTasks[taskId].data[9] = (u32)StartTeleportFieldEffect; + SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ON_FOOT); return FALSE; } -void sub_817C94C(void) +static void StartTeleportFieldEffect(void) { FieldEffectActiveListRemove(FLDEFF_USE_TELEPORT); CreateTeleportFieldEffectTask(); } - - diff --git a/src/hof_pc.c b/src/hof_pc.c index 44b929337..2cea5540a 100644 --- a/src/hof_pc.c +++ b/src/hof_pc.c @@ -7,8 +7,6 @@ #include "script_menu.h" #include "task.h" -extern void (*gUnknown_0300485C)(void); - extern void Overworld_PlaySpecialMapMusic(void); extern bool16 ScrSpecial_CreatePCMenu(void); extern void ScriptMenu_DisplayPCStartupPrompt(void); diff --git a/src/item_use.c b/src/item_use.c index 2a1c7883c..4ab9f6e23 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -58,7 +58,7 @@ extern void sub_81C5924(void); extern void sub_81C59BC(void); extern void sub_81AB9A8(u8); extern void sub_81ABA88(u8); -extern void sub_80B7CC8(void); +extern void StartEscapeRopeFieldEffect(void); extern u8* sub_806CF78(u16); extern void sub_81B89F0(void); extern u8 GetItemEffectType(u16); @@ -890,7 +890,7 @@ void ItemUseOutOfBattle_BlackWhiteFlute(u8 taskId) void task08_080A1C44(u8 taskId) { ResetInitialPlayerAvatarState(); - sub_80B7CC8(); + StartEscapeRopeFieldEffect(); DestroyTask(taskId); } diff --git a/src/metatile_behavior.c b/src/metatile_behavior.c index dd594f075..2bae89ecf 100644 --- a/src/metatile_behavior.c +++ b/src/metatile_behavior.c @@ -897,7 +897,7 @@ bool8 MetatileBehavior_IsBridge(u8 metatileBehavior) return FALSE; } -u8 MetatileBehavior_GetBridgeSth(u8 metatileBehavior) +u8 MetatileBehavior_GetBridgeType(u8 metatileBehavior) { u8 result = metatileBehavior - MB_WARP_OR_BRIDGE; if (result < 4) diff --git a/src/overworld.c b/src/overworld.c index 4787a4344..69ac9c822 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -585,7 +585,7 @@ void set_warp2_warp3_to_neg_1(void) gFixedHoleWarp = sDummyWarpData; } -void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +static void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { warp->mapGroup = mapGroup; warp->mapNum = mapNum; @@ -594,7 +594,7 @@ void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, warp->y = y; } -bool32 IsDummyWarp(struct WarpData *warp) +static bool32 IsDummyWarp(struct WarpData *warp) { if (warp->mapGroup != -1) return FALSE; @@ -620,7 +620,7 @@ struct MapHeader const *const GetDestinationWarpMapHeader(void) return Overworld_GetMapHeaderByGroupAndId(sWarpDestination.mapGroup, sWarpDestination.mapNum); } -void LoadCurrentMapData(void) +static void LoadCurrentMapData(void) { sLastMapSectionId = gMapHeader.regionMapSectionId; gMapHeader = *Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum); @@ -628,13 +628,13 @@ void LoadCurrentMapData(void) gMapHeader.mapLayout = GetMapLayout(); } -void LoadSaveblockMapHeader(void) +static void LoadSaveblockMapHeader(void) { gMapHeader = *Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum); gMapHeader.mapLayout = GetMapLayout(); } -void SetPlayerCoordsFromWarp(void) +static void SetPlayerCoordsFromWarp(void) { if (gSaveBlock1Ptr->location.warpId >= 0 && gSaveBlock1Ptr->location.warpId < gMapHeader.events->warpCount) { @@ -729,7 +729,7 @@ void SetFixedDiveWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) SetWarpData(&gFixedDiveWarp, mapGroup, mapNum, warpId, x, y); } -void SetFixedDiveWarpAsDestination(void) +static void SetFixedDiveWarpAsDestination(void) { sWarpDestination = gFixedDiveWarp; } @@ -785,7 +785,7 @@ const struct MapConnection *GetMapConnection(u8 dir) return NULL; } -bool8 SetDiveWarp(u8 dir, u16 x, u16 y) +static bool8 SetDiveWarp(u8 dir, u16 x, u16 y) { const struct MapConnection *connection = GetMapConnection(dir); @@ -905,8 +905,8 @@ static void mli0_load_map(u32 a1) void ResetInitialPlayerAvatarState(void) { - gInitialPlayerAvatarState.direction = 1; - gInitialPlayerAvatarState.transitionFlags = 1; + gInitialPlayerAvatarState.direction = DIR_SOUTH; + gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_ON_FOOT; } void StoreInitialPlayerAvatarState(void) @@ -914,15 +914,15 @@ void StoreInitialPlayerAvatarState(void) gInitialPlayerAvatarState.direction = GetPlayerFacingDirection(); if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE)) - gInitialPlayerAvatarState.transitionFlags = 2; + gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_MACH_BIKE; else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE)) - gInitialPlayerAvatarState.transitionFlags = 4; + gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_ACRO_BIKE; else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING)) - gInitialPlayerAvatarState.transitionFlags = 8; + gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_SURFING; else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_UNDERWATER)) - gInitialPlayerAvatarState.transitionFlags = 16; + gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_UNDERWATER; else - gInitialPlayerAvatarState.transitionFlags = 1; + gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_ON_FOOT; } static struct InitialPlayerAvatarState *GetInitialPlayerAvatarState(void) @@ -940,44 +940,44 @@ static struct InitialPlayerAvatarState *GetInitialPlayerAvatarState(void) static u8 GetAdjustedInitialTransitionFlags(struct InitialPlayerAvatarState *playerStruct, u16 metatileBehavior, u8 mapType) { if (mapType != MAP_TYPE_INDOOR && FlagGet(FLAG_SYS_CRUISE_MODE)) - return 1; + return PLAYER_AVATAR_FLAG_ON_FOOT; else if (mapType == MAP_TYPE_UNDERWATER) - return 16; + return PLAYER_AVATAR_FLAG_UNDERWATER; else if (MetatileBehavior_IsSurfableWaterOrUnderwater(metatileBehavior) == TRUE) - return 8; + return PLAYER_AVATAR_FLAG_SURFING; else if (Overworld_IsBikingAllowed() != TRUE) - return 1; - else if (playerStruct->transitionFlags == 2) - return 2; - else if (playerStruct->transitionFlags != 4) - return 1; + return PLAYER_AVATAR_FLAG_ON_FOOT; + else if (playerStruct->transitionFlags == PLAYER_AVATAR_FLAG_MACH_BIKE) + return PLAYER_AVATAR_FLAG_MACH_BIKE; + else if (playerStruct->transitionFlags != PLAYER_AVATAR_FLAG_ACRO_BIKE) + return PLAYER_AVATAR_FLAG_ON_FOOT; else - return 4; + return PLAYER_AVATAR_FLAG_ACRO_BIKE; } static u8 GetAdjustedInitialDirection(struct InitialPlayerAvatarState *playerStruct, u8 transitionFlags, u16 metatileBehavior, u8 mapType) { if (FlagGet(FLAG_SYS_CRUISE_MODE) && mapType == MAP_TYPE_6) - return 4; + return DIR_EAST; else if (MetatileBehavior_IsDeepSouthWarp(metatileBehavior) == TRUE) - return 2; + return DIR_NORTH; else if (MetatileBehavior_IsNonAnimDoor(metatileBehavior) == TRUE || MetatileBehavior_IsDoor(metatileBehavior) == TRUE) - return 1; + return DIR_SOUTH; else if (MetatileBehavior_IsSouthArrowWarp(metatileBehavior) == TRUE) - return 2; + return DIR_NORTH; else if (MetatileBehavior_IsNorthArrowWarp(metatileBehavior) == TRUE) - return 1; + return DIR_SOUTH; else if (MetatileBehavior_IsWestArrowWarp(metatileBehavior) == TRUE) - return 4; + return DIR_EAST; else if (MetatileBehavior_IsEastArrowWarp(metatileBehavior) == TRUE) - return 3; - else if ((playerStruct->transitionFlags == 16 && transitionFlags == 8) - || (playerStruct->transitionFlags == 8 && transitionFlags == 16)) + return DIR_WEST; + else if ((playerStruct->transitionFlags == PLAYER_AVATAR_FLAG_UNDERWATER && transitionFlags == PLAYER_AVATAR_FLAG_SURFING) + || (playerStruct->transitionFlags == PLAYER_AVATAR_FLAG_SURFING && transitionFlags == PLAYER_AVATAR_FLAG_UNDERWATER )) return playerStruct->direction; else if (MetatileBehavior_IsLadder(metatileBehavior) == TRUE) return playerStruct->direction; else - return 1; + return DIR_SOUTH; } static u16 GetCenterScreenMetatileBehavior(void) @@ -1357,7 +1357,7 @@ u8 Overworld_GetMapTypeOfSaveblockLocation(void) return GetMapTypeByWarpData(&gSaveBlock1Ptr->location); } -u8 get_map_light_from_warp0(void) +u8 GetLastUsedWarpMapType(void) { return GetMapTypeByWarpData(&gLastUsedWarp); } @@ -1458,7 +1458,7 @@ static void DoCB1_Overworld(u16 newKeys, u16 heldKeys) FieldGetPlayerInput(&inputStruct, newKeys, heldKeys); if (!ScriptContext2_IsEnabled()) { - if (sub_809C014(&inputStruct) == 1) + if (ProcessPlayerFieldInput(&inputStruct) == 1) { ScriptContext2_Enable(); HideMapNamePopUpWindow(); @@ -2166,9 +2166,9 @@ static void sub_8086988(u32 a1) static void sub_80869DC(void) { - gUnknown_03005DEC = 0; - gUnknown_03005DE8 = 0; - sub_808D438(); + gTotalCameraPixelOffsetX = 0; + gTotalCameraPixelOffsetY = 0; + ResetEventObjects(); TrySpawnEventObjects(0, 0); mapheader_run_first_tag4_script_list_match(); } @@ -2178,9 +2178,9 @@ static void mli4_mapscripts_and_other(void) s16 x, y; struct InitialPlayerAvatarState *player; - gUnknown_03005DEC = 0; - gUnknown_03005DE8 = 0; - sub_808D438(); + gTotalCameraPixelOffsetX = 0; + gTotalCameraPixelOffsetY = 0; + ResetEventObjects(); sav1_camera_get_focus_coords(&x, &y); player = GetInitialPlayerAvatarState(); InitPlayerAvatar(x, y, player->direction, gSaveBlock2Ptr->playerGender); diff --git a/src/rom6.c b/src/rom6.c index cc146fc94..712ac76e0 100644 --- a/src/rom6.c +++ b/src/rom6.c @@ -1,21 +1,22 @@ #include "global.h" -#include "constants/event_objects.h" -#include "constants/songs.h" -#include "rom6.h" #include "braille_puzzles.h" #include "event_data.h" +#include "event_object_movement.h" #include "event_scripts.h" #include "field_effect.h" -#include "event_object_movement.h" #include "field_player_avatar.h" #include "item_use.h" -#include "party_menu.h" #include "overworld.h" +#include "party_menu.h" +#include "rom6.h" #include "script.h" #include "sound.h" #include "sprite.h" #include "task.h" +#include "constants/event_object_movement_constants.h" +#include "constants/event_objects.h" #include "constants/map_types.h" +#include "constants/songs.h" // static functions static void task08_080C9820(u8 taskId); @@ -31,14 +32,14 @@ static void sub_8135780(void); extern struct MapPosition gPlayerFacingPosition; // text -bool8 CheckObjectGraphicsInFrontOfPlayer(u8 a) +bool8 CheckObjectGraphicsInFrontOfPlayer(u8 graphicsId) { u8 eventObjId; GetXYCoordsOneStepInFrontOfPlayer(&gPlayerFacingPosition.x, &gPlayerFacingPosition.y); gPlayerFacingPosition.height = PlayerGetZCoord(); eventObjId = GetEventObjectIdByXYZ(gPlayerFacingPosition.x, gPlayerFacingPosition.y, gPlayerFacingPosition.height); - if (gEventObjects[eventObjId].graphicsId != a) + if (gEventObjects[eventObjId].graphicsId != graphicsId) { return FALSE; } @@ -73,7 +74,7 @@ static void task08_080C9820(u8 taskId) else { sub_808C114(); - EventObjectSetHeldMovement(&gEventObjects[eventObjId], 0x39); + EventObjectSetHeldMovement(&gEventObjects[eventObjId], MOVEMENT_ACTION_START_ANIM_IN_DIRECTION); gTasks[taskId].func = sub_813552C; } } @@ -90,7 +91,7 @@ static void sub_813552C(u8 taskId) static void sub_8135578(u8 taskId) { - if (!FieldEffectActiveListContains(6)) + if (!FieldEffectActiveListContains(FLDEFF_FIELD_MOVE_SHOW_MON)) { gFieldEffectArguments[1] = GetPlayerFacingDirection(); if (gFieldEffectArguments[1] == 1) @@ -189,7 +190,7 @@ bool8 FldEff_UseDig(void) gTasks[taskId].data[8] = (u32)sub_8135780 >> 16; gTasks[taskId].data[9] = (u32)sub_8135780; if (!ShouldDoBrailleDigEffect()) - SetPlayerAvatarTransitionFlags(1); + SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ON_FOOT); return FALSE; } diff --git a/src/time_events.c b/src/time_events.c index 1f46e7705..9702d321f 100644 --- a/src/time_events.c +++ b/src/time_events.c @@ -81,7 +81,7 @@ void UpdateShoalTideFlag(void) 1, // 23 }; - if (is_map_type_1_2_3_5_or_6(get_map_light_from_warp0())) + if (is_map_type_1_2_3_5_or_6(GetLastUsedWarpMapType())) { RtcCalcLocalTime(); if (tide[gLocalTime.hours]) diff --git a/src/wallclock.c b/src/wallclock.c index 60a5fae07..e2e03ecba 100644 --- a/src/wallclock.c +++ b/src/wallclock.c @@ -1,37 +1,24 @@ #include "global.h" -#include "main.h" -#include "palette.h" -#include "gpu_regs.h" #include "bg.h" -#include "rtc.h" #include "clock.h" -#include "wallclock.h" -#include "event_data.h" -#include "graphics.h" -#include "text.h" -#include "window.h" -#include "text_window.h" -#include "menu.h" -#include "scanline_effect.h" -#include "task.h" -#include "strings.h" -#include "sound.h" -#include "constants/songs.h" -#include "trig.h" #include "decompress.h" - -// static types - -#define tMinuteHandAngle data[0] -#define tHourHandAngle data[1] -#define tHours data[2] -#define tMinutes data[3] -#define tMvmtDir data[4] -#define tPeriod data[5] -#define tMvmtSpeed data[6] - -#define TAG_GFX_WALL_CLOCK_HAND 0x1000 -#define TAG_PAL_WALL_CLOCK_HAND 0x1000 +#include "event_data.h" +#include "gpu_regs.h" +#include "graphics.h" +#include "main.h" +#include "menu.h" +#include "palette.h" +#include "rtc.h" +#include "scanline_effect.h" +#include "sound.h" +#include "strings.h" +#include "task.h" +#include "text.h" +#include "text_window.h" +#include "trig.h" +#include "wallclock.h" +#include "window.h" +#include "constants/songs.h" // static declarations @@ -46,15 +33,39 @@ static void Task_ViewClock1(u8 taskId); static void Task_ViewClock2(u8 taskId); static void Task_ViewClock3(u8 taskId); static void Task_ViewClock4(u8 taskId); -static u16 CalcNewMinHandAngle(u16 a0, u8 command, u8 a2); -static bool32 AdvanceClock(u8 taskId, u8 command); -static void UpdateClockPeriod(u8 taskId, u8 command); +static u16 CalcNewMinHandAngle(u16 angle, u8 direction, u8 speed); +static bool32 AdvanceClock(u8 taskId, u8 direction); +static void UpdateClockPeriod(u8 taskId, u8 direction); static void InitClockWithRtc(u8 taskId); static void SpriteCB_MinuteHand(struct Sprite *sprite); static void SpriteCB_HourHand(struct Sprite *sprite); static void SpriteCB_AMIndicator(struct Sprite *sprite); static void SpriteCB_PMIndicator(struct Sprite *sprite); +#define tMinuteHandAngle data[0] +#define tHourHandAngle data[1] +#define tHours data[2] +#define tMinutes data[3] +#define tMvmtDir data[4] +#define tPeriod data[5] +#define tMvmtSpeed data[6] + +#define TAG_GFX_WALL_CLOCK_HAND 0x1000 +#define TAG_PAL_WALL_CLOCK_HAND 0x1000 + +enum +{ + PERIOD_AM, + PERIOD_PM, +}; + +enum +{ + MVMT_NONE, + MVMT_BACKWARD, + MVMT_FORWARD, +}; + // rodata static const u32 sUnknown_085B1F58[] = INCBIN_U32("graphics/wallclock/graphics_85b1f58.4bpp.lz"); @@ -122,17 +133,17 @@ static const struct SpritePalette gUnknown_085B2218[] = { {} }; static const struct OamData Unknown_085B2230 = { - .y = 0xa0, + .y = 160, .size = 3, - .priority = 1 + .priority = 1, }; static const union AnimCmd Unknown_085B2238[] = { ANIMCMD_FRAME(0, 30), - ANIMCMD_END + ANIMCMD_END, }; static const union AnimCmd Unknown_085B2240[] = { ANIMCMD_FRAME(64, 30), - ANIMCMD_END + ANIMCMD_END, }; static const union AnimCmd *const gUnknown_085B2248[] = { Unknown_085B2238 @@ -148,7 +159,7 @@ static const struct SpriteTemplate gUnknown_085B2250 = .anims = gUnknown_085B2248, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCB_MinuteHand + .callback = SpriteCB_MinuteHand, }; static const struct SpriteTemplate gUnknown_085B2268 = { @@ -158,20 +169,20 @@ static const struct SpriteTemplate gUnknown_085B2268 = .anims = gUnknown_085B224C, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCB_HourHand + .callback = SpriteCB_HourHand, }; static const struct OamData Unknown_085B2280 = { - .y = 0xa0, + .y = 160, .size = 1, - .priority = 3 + .priority = 3, }; static const union AnimCmd Unknown_085B2288[] = { - ANIMCMD_FRAME(0x84, 30), - ANIMCMD_END + ANIMCMD_FRAME(132, 30), + ANIMCMD_END, }; static const union AnimCmd Unknown_085B2290[] = { - ANIMCMD_FRAME(0x80, 30), - ANIMCMD_END + ANIMCMD_FRAME(128, 30), + ANIMCMD_END, }; static const union AnimCmd *const gUnknown_085B2298[] = { Unknown_085B2288 @@ -648,21 +659,21 @@ void CB2_StartWallClock(void) gTasks[taskId].tMinuteHandAngle = 0; gTasks[taskId].tHourHandAngle = 300; - spriteId = CreateSprite(&gUnknown_085B2250, 0x78, 0x50, 1); + spriteId = CreateSprite(&gUnknown_085B2250, 120, 80, 1); gSprites[spriteId].data[0] = taskId; gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL; gSprites[spriteId].oam.matrixNum = 0; - spriteId = CreateSprite(&gUnknown_085B2268, 0x78, 0x50, 0); + spriteId = CreateSprite(&gUnknown_085B2268, 120, 80, 0); gSprites[spriteId].data[0] = taskId; gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL; gSprites[spriteId].oam.matrixNum = 1; - spriteId = CreateSprite(&gUnknown_085B22A0, 0x78, 0x50, 2); + spriteId = CreateSprite(&gUnknown_085B22A0, 120, 80, 2); gSprites[spriteId].data[0] = taskId; gSprites[spriteId].data[1] = 45; - spriteId = CreateSprite(&gUnknown_085B22B8, 0x78, 0x50, 2); + spriteId = CreateSprite(&gUnknown_085B22B8, 120, 80, 2); gSprites[spriteId].data[0] = taskId; gSprites[spriteId].data[1] = 90; @@ -696,21 +707,21 @@ void CB2_ViewWallClock(void) angle2 = 135; } - spriteId = CreateSprite(&gUnknown_085B2250, 0x78, 0x50, 1); + spriteId = CreateSprite(&gUnknown_085B2250, 120, 80, 1); gSprites[spriteId].data[0] = taskId; gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL; gSprites[spriteId].oam.matrixNum = 0; - spriteId = CreateSprite(&gUnknown_085B2268, 0x78, 0x50, 0); + spriteId = CreateSprite(&gUnknown_085B2268, 120, 80, 0); gSprites[spriteId].data[0] = taskId; gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL; gSprites[spriteId].oam.matrixNum = 1; - spriteId = CreateSprite(&gUnknown_085B22A0, 0x78, 0x50, 2); + spriteId = CreateSprite(&gUnknown_085B22A0, 120, 80, 2); gSprites[spriteId].data[0] = taskId; gSprites[spriteId].data[1] = angle1; - spriteId = CreateSprite(&gUnknown_085B22B8, 0x78, 0x50, 2); + spriteId = CreateSprite(&gUnknown_085B22B8, 120, 80, 2); gSprites[spriteId].data[0] = taskId; gSprites[spriteId].data[1] = angle2; @@ -757,11 +768,11 @@ static void Task_SetClock2(u8 taskId) gTasks[taskId].tMvmtDir = 0; if (gMain.heldKeys & DPAD_LEFT) { - gTasks[taskId].tMvmtDir = 1; + gTasks[taskId].tMvmtDir = MVMT_BACKWARD; } if (gMain.heldKeys & DPAD_RIGHT) { - gTasks[taskId].tMvmtDir = 2; + gTasks[taskId].tMvmtDir = MVMT_FORWARD; } if (gTasks[taskId].tMvmtDir != 0) { @@ -794,12 +805,12 @@ static void Task_SetClock4(u8 taskId) { switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case 0: + case 0: //YES PlaySE(SE_SELECT); gTasks[taskId].func = Task_SetClock5; break; - case 1: - case -1: + case 1: //B button + case -1: //NO PlaySE(SE_SELECT); sub_8198070(0, FALSE); ClearWindowTilemap(0); @@ -855,45 +866,49 @@ static void Task_ViewClock4(u8 taskId) } } -static u8 CalcMinHandDelta(u16 a0) +static u8 CalcMinHandDelta(u16 speed) { - if (a0 > 60) + if (speed > 60) { return 6; } - if (a0 > 30) + if (speed > 30) { return 3; } - if (a0 > 10) + if (speed > 10) { return 2; } return 1; } -static u16 CalcNewMinHandAngle(u16 a0, u8 command, u8 a2) +static u16 CalcNewMinHandAngle(u16 angle, u8 direction, u8 speed) { - u8 r1 = CalcMinHandDelta(a2); - switch (command) + u8 delta = CalcMinHandDelta(speed); + switch (direction) { - case 1: - if (a0) a0 -= r1; - else a0 = 360 - r1; + case MVMT_BACKWARD: + if (angle) + angle -= delta ; + else + angle = 360 - delta ; break; - case 2: - if (a0 < 360 - r1) a0 += r1; - else a0 = 0; + case MVMT_FORWARD: + if (angle < 360 - delta ) + angle += delta ; + else + angle = 0; break; } - return a0; + return angle; } -static bool32 AdvanceClock(u8 taskId, u8 command) +static bool32 AdvanceClock(u8 taskId, u8 direction) { - switch (command) + switch (direction) { - case 1: + case MVMT_BACKWARD: if (gTasks[taskId].tMinutes > 0) { gTasks[taskId].tMinutes--; @@ -909,10 +924,10 @@ static bool32 AdvanceClock(u8 taskId, u8 command) { gTasks[taskId].tHours = 23; } - UpdateClockPeriod(taskId, command); + UpdateClockPeriod(taskId, direction); } break; - case 2: + case MVMT_FORWARD: if (gTasks[taskId].tMinutes < 59) { gTasks[taskId].tMinutes++; @@ -928,37 +943,37 @@ static bool32 AdvanceClock(u8 taskId, u8 command) { gTasks[taskId].tHours = 0; } - UpdateClockPeriod(taskId, command); + UpdateClockPeriod(taskId, direction); } break; } return FALSE; } -static void UpdateClockPeriod(u8 taskId, u8 command) +static void UpdateClockPeriod(u8 taskId, u8 direction) { u8 hours = gTasks[taskId].tHours; - switch (command) + switch (direction) { - case 1: + case MVMT_BACKWARD: switch (hours) { case 11: - gTasks[taskId].tPeriod = FALSE; + gTasks[taskId].tPeriod = PERIOD_AM; break; case 23: - gTasks[taskId].tPeriod = TRUE; + gTasks[taskId].tPeriod = PERIOD_PM; break; } break; - case 2: + case MVMT_FORWARD: switch (hours) { case 0: - gTasks[taskId].tPeriod = FALSE; + gTasks[taskId].tPeriod = PERIOD_AM; break; case 12: - gTasks[taskId].tPeriod = TRUE; + gTasks[taskId].tPeriod = PERIOD_PM; break; } break; @@ -974,11 +989,11 @@ static void InitClockWithRtc(u8 taskId) gTasks[taskId].tHourHandAngle = (gTasks[taskId].tHours % 12) * 30 + (gTasks[taskId].tMinutes / 10) * 5; if (gLocalTime.hours < 12) { - gTasks[taskId].tPeriod = FALSE; + gTasks[taskId].tPeriod = PERIOD_AM; } else { - gTasks[taskId].tPeriod = TRUE; + gTasks[taskId].tPeriod = PERIOD_PM; } } @@ -987,8 +1002,7 @@ static void SpriteCB_MinuteHand(struct Sprite *sprite) u16 angle = gTasks[sprite->data[0]].tMinuteHandAngle; s16 sin = Sin2(angle) / 16; s16 cos = Cos2(angle) / 16; - u16 xhat; - u16 yhat; + u16 xhat, yhat; SetOamMatrix(0, cos, sin, -sin, cos); xhat = sClockHandCoords[angle][0]; @@ -1011,8 +1025,7 @@ static void SpriteCB_HourHand(struct Sprite *sprite) u16 angle = gTasks[sprite->data[0]].tHourHandAngle; s16 sin = Sin2(angle) / 16; s16 cos = Cos2(angle) / 16; - u16 xhat; - u16 yhat; + u16 xhat, yhat; SetOamMatrix(1, cos, sin, -sin, cos); xhat = sClockHandCoords[angle][0];