From b7b1d609d035ab7f125808fb653e972546b05a6a Mon Sep 17 00:00:00 2001 From: Slawter666 <38655737+Slawter666@users.noreply.github.com> Date: Wed, 17 Oct 2018 13:52:26 +0100 Subject: [PATCH] More synchronisation --- include/berry.h | 29 +++++++---- include/event_object_movement.h | 2 +- include/fldeff_teleport.h | 7 --- include/global.fieldmap.h | 4 +- include/global.h | 26 +++++----- src/berry.c | 87 +++++++++++++++++++-------------- src/bike.c | 4 +- src/event_object_movement.c | 75 +++++++++++++--------------- src/field_specials.c | 2 +- src/fldeff_sweetscent.c | 30 ++++++------ src/fldeff_teleport.c | 18 +++---- src/hof_pc.c | 2 - 12 files changed, 146 insertions(+), 140 deletions(-) delete mode 100644 include/fldeff_teleport.h diff --git a/include/berry.h b/include/berry.h index 1a8b7fa25..cfd66c61e 100644 --- a/include/berry.h +++ b/include/berry.h @@ -1,6 +1,13 @@ #ifndef GUARD_BERRY_H #define GUARD_BERRY_H +#define BERRY_NONE 0 +#define FIRST_BERRY ITEM_CHERI_BERRY +#define LAST_BERRY ITEM_ENIGMA_BERRY + +#define GETBERRYID(berry) ((berry - FIRST_BERRY) + 1) +#define GETITEMID(berry) ((berry + FIRST_BERRY) - 1) + enum { BERRY_FIRMNESS_UNKNOWN, @@ -21,6 +28,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 +47,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 +54,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 8a66d140c..98395593b 100644 --- a/include/event_object_movement.h +++ b/include/event_object_movement.h @@ -75,7 +75,7 @@ struct PairedPalettes struct LockedAnimEventObjects { - u8 eventObjectIds[NUM_EVENT_OBJECTS]; + u8 eventObjectIds[EVENT_OBJECTS_COUNT]; u8 count; }; 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 3f0b61ea7..055f29f40 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, @@ -313,7 +311,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 027065481..f77b3159e 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 diff --git a/src/berry.c b/src/berry.c index ea216b61c..ce2a29901 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 == GETBERRYID(ITEM_ENIGMA_BERRY) && IsEnigmaBerryValid()) return (struct Berry*)(&gSaveBlock1Ptr->enigmaBerry.berry); else { - if (berry == 0 || berry > 0x2B) - berry = 1; + if (berry == BERRY_NONE || berry > GETBERRYID(LAST_BERRY)) + berry = GETBERRYID(FIRST_BERRY); 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 1fa4eb301..742b2a6bb 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/event_object_movement.c b/src/event_object_movement.c index 201f5ff08..d97bdbcd1 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1079,7 +1079,7 @@ 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]); } @@ -1109,7 +1109,7 @@ static void CreateReflectionEffectSprites(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; @@ -1130,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; @@ -1139,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; @@ -1151,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. @@ -1184,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); @@ -1414,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) @@ -1426,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 @@ -1441,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; } @@ -1473,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]); @@ -1490,8 +1490,8 @@ static u8 TrySetupEventObjectSprite(struct EventObjectTemplate *eventObjectTempl 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); @@ -1509,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; } @@ -1518,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); @@ -1554,9 +1554,9 @@ static u8 TrySpawnEventObject(struct EventObjectTemplate *eventObjectTemplate, u 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) @@ -1604,7 +1604,7 @@ 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); @@ -1759,7 +1759,7 @@ void RemoveEventObjectsOutsideView(void) 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++) { @@ -1778,21 +1778,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); } @@ -1802,7 +1797,7 @@ 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) { @@ -2060,7 +2055,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; @@ -2283,7 +2278,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) { @@ -2301,7 +2296,7 @@ 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) { @@ -2311,7 +2306,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) @@ -4952,7 +4947,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) @@ -5333,7 +5328,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; } diff --git a/src/field_specials.c b/src/field_specials.c index a2bd567d0..c9feeabda 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]; 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);