From b24fd7abbdb3786d148463bbeefeec400e65bf5d Mon Sep 17 00:00:00 2001 From: Nathan <39394314+MrKumaPants@users.noreply.github.com> Date: Mon, 15 Sep 2025 14:10:17 -0500 Subject: [PATCH] Document Berry patch management, graphics, and scripting commands (#765) --- asm/macros/scrcmd.inc | 34 +- generated/game_records.txt | 2 +- generated/trainer_score_events.txt | 2 +- include/berry_patch_graphics.h | 20 + include/berry_patch_manager.h | 44 ++ include/constants/items.h | 8 + include/constants/scrcmd.h | 3 + include/field/field_system_sub2_t.h | 4 +- include/item_use_functions.h | 4 +- include/map_object.h | 2 +- include/overlay005/berry_graphics_data.h | 10 + include/overlay005/berry_graphics_table.h | 8 + include/overlay005/const_ov5_021FB67C.h | 8 - include/overlay005/struct_ov5_021FB67C.h | 10 - include/scrcmd_berry.h | 16 + .../struct_decls/berry_patch_manager_decl.h | 6 + include/struct_decls/struct_02055CBC_decl.h | 6 - include/unk_0204B64C.h | 16 - include/unk_02055C50.h | 27 - include/unk_020677F4.h | 20 - include/unk_0206CCB0.h | 1 + platinum.us/main.lsf | 6 +- res/field/scripts/scripts_unk_0413.s | 28 +- src/applications/bag/main.c | 2 +- src/berry_patch_graphics.c | 229 +++++++++ src/berry_patch_manager.c | 450 +++++++++++++++++ src/berry_patches.c | 2 +- src/game_records.c | 4 +- src/item_use_functions.c | 16 +- src/map_object.c | 16 +- src/meson.build | 6 +- src/overlay005/fieldmap.c | 8 +- src/overlay005/ov5_021EB1A0.c | 4 +- src/overlay005/ov5_021ECE40.c | 32 +- src/overlay005/ov5_021F17B8.c | 25 +- src/overlay005/ov5_021F204C.c | 48 +- src/overlay005/ov5_021F2D20.c | 2 +- src/overlay005/ov5_021F3284.c | 2 +- src/overlay005/ov5_021F37A8.c | 2 +- src/overlay005/ov5_021F3A50.c | 2 +- src/overlay005/ov5_021F6454.c | 16 +- src/overlay005/ov5_021FAF40.c | 48 +- src/scrcmd.c | 20 +- src/scrcmd_berry.c | 111 ++++ src/unk_0204B64C.c | 111 ---- src/unk_020559DC.c | 4 +- src/unk_02055C50.c | 472 ------------------ src/unk_020677F4.c | 233 --------- src/unk_0206CCB0.c | 16 +- src/unk_020EDBAC.c | 8 +- 50 files changed, 1088 insertions(+), 1086 deletions(-) create mode 100644 include/berry_patch_graphics.h create mode 100644 include/berry_patch_manager.h create mode 100644 include/overlay005/berry_graphics_data.h create mode 100644 include/overlay005/berry_graphics_table.h delete mode 100644 include/overlay005/const_ov5_021FB67C.h delete mode 100644 include/overlay005/struct_ov5_021FB67C.h create mode 100644 include/scrcmd_berry.h create mode 100644 include/struct_decls/berry_patch_manager_decl.h delete mode 100644 include/struct_decls/struct_02055CBC_decl.h delete mode 100644 include/unk_0204B64C.h delete mode 100644 include/unk_02055C50.h delete mode 100644 include/unk_020677F4.h create mode 100644 src/berry_patch_graphics.c create mode 100644 src/berry_patch_manager.c create mode 100644 src/scrcmd_berry.c delete mode 100644 src/unk_0204B64C.c delete mode 100644 src/unk_02055C50.c delete mode 100644 src/unk_020677F4.c diff --git a/asm/macros/scrcmd.inc b/asm/macros/scrcmd.inc index 4d20f9d4d8..0a342c1bf6 100644 --- a/asm/macros/scrcmd.inc +++ b/asm/macros/scrcmd.inc @@ -2139,47 +2139,47 @@ .short \nature .endm - .macro ScrCmd_17D arg0 + .macro GetBerryGrowthStage destVar .short 381 - .short \arg0 + .short \destVar .endm - .macro ScrCmd_17E arg0 + .macro GetBerryItemID destVar .short 382 - .short \arg0 + .short \destVar .endm - .macro ScrCmd_17F arg0 + .macro GetBerryMulchType destVar .short 383 - .short \arg0 + .short \destVar .endm - .macro ScrCmd_180 arg0 + .macro GetBerryMoisture destVar .short 384 - .short \arg0 + .short \destVar .endm - .macro ScrCmd_181 arg0 + .macro GetBerryYield destVar .short 385 - .short \arg0 + .short \destVar .endm - .macro ScrCmd_182 arg0 + .macro SetBerryMulch mulchItemID .short 386 - .short \arg0 + .short \mulchItemID .endm - .macro ScrCmd_183 arg0 + .macro PlantBerry berryItemID .short 387 - .short \arg0 + .short \berryItemID .endm - .macro ScrCmd_184 arg0 + .macro SetBerryWateringState direction .short 388 - .short \arg0 + .short \direction .endm - .macro ScrCmd_185 + .macro HarvestBerry .short 389 .endm diff --git a/generated/game_records.txt b/generated/game_records.txt index bb9493ed01..12ef6ccbe4 100644 --- a/generated/game_records.txt +++ b/generated/game_records.txt @@ -2,7 +2,7 @@ RECORD_UNK_000 RECORD_TRAINER_SCORE RECORD_UNK_002 RECORD_UNK_003 -RECORD_UNK_004 +RECORD_BERRIES_PLANTED RECORD_UNK_005 RECORD_UNK_006 RECORD_WILD_BATTLES_FOUGHT diff --git a/generated/trainer_score_events.txt b/generated/trainer_score_events.txt index a14cf130bf..8452d72d8e 100644 --- a/generated/trainer_score_events.txt +++ b/generated/trainer_score_events.txt @@ -1,4 +1,4 @@ -TRAINER_SCORE_EVENT_UNK_00 +TRAINER_SCORE_EVENT_BERRY_HARVESTED TRAINER_SCORE_EVENT_HONEY_USED TRAINER_SCORE_EVENT_UNK_02 TRAINER_SCORE_EVENT_UNK_03 diff --git a/include/berry_patch_graphics.h b/include/berry_patch_graphics.h new file mode 100644 index 0000000000..3a8e4fdd67 --- /dev/null +++ b/include/berry_patch_graphics.h @@ -0,0 +1,20 @@ +#ifndef POKEPLATINUM_BERRY_PATCH_GRAPHICS_H +#define POKEPLATINUM_BERRY_PATCH_GRAPHICS_H + +#include "struct_decls/struct_020216E0_decl.h" +#include "struct_decls/struct_02061AB4_decl.h" + +BOOL BerryPatchGraphics_IsBerryPatch(int graphicsID); +int BerryPatchGraphics_GetCurrentGraphicsResourceID(const MapObject *mapObject); +void BerryPatchGraphics_MarkForUpdate(MapObject *mapObject); +void BerryPatchGraphics_NewData(MapObject *mapObject); +void BerryPatchGraphics_UpdateGrowthStage(MapObject *mapObject); +void BerryPatchGraphics_NoOp(MapObject *mapObject); +void BerryPatchGraphics_NewGraphics(MapObject *mapObject); +void BerryPatchGraphics_UpdateGraphics(MapObject *mapObject); +void BerryPatchGraphics_FreeGraphics(MapObject *mapObject); +void BerryPatchGraphics_PauseGraphics(MapObject *mapObject); +void BerryPatchGraphics_ResumeGraphics(MapObject *mapObject); +UnkStruct_020216E0 *BerryPatchGraphics_GetGraphicsObject(MapObject *mapObject); + +#endif // POKEPLATINUM_BERRY_PATCH_GRAPHICS_H diff --git a/include/berry_patch_manager.h b/include/berry_patch_manager.h new file mode 100644 index 0000000000..0c09a069bf --- /dev/null +++ b/include/berry_patch_manager.h @@ -0,0 +1,44 @@ +#ifndef POKEPLATINUM_BERRY_PATCH_MANAGER_H +#define POKEPLATINUM_BERRY_PATCH_MANAGER_H + +#include "constants/heap.h" + +#include "struct_decls/berry_patch_manager_decl.h" +#include "struct_decls/struct_02061AB4_decl.h" + +#include "field/field_system_decl.h" + +enum BerryWateringState { + BERRY_WATERING_STATE_INIT = 0, // Initial state - setting up watering mode + BERRY_WATERING_STATE_WATERING, // Watering the current patch + BERRY_WATERING_STATE_INPUT, // Waiting for player input (movement keys) + BERRY_WATERING_STATE_ANIMATION, // Playing watering animation + BERRY_WATERING_STATE_CLEANUP, // Cleaning up and exiting watering mode +}; + +enum BerryPatchFlags { + BERRY_PATCH_FLAG_INVALID = 0x0, // Not a berry patch or NULL + BERRY_PATCH_FLAG_EMPTY = 0x1, // Patch is empty, can plant + BERRY_PATCH_FLAG_CAN_MULCH = 0x2, // Patch can have mulch applied + BERRY_PATCH_FLAG_HAS_BERRY = 0x4, // Patch has berry growing +}; + +BerryPatchManager *BerryPatchManager_New(FieldSystem *fieldSystem, enum HeapID heapID); +void BerryPatchManager_Free(BerryPatchManager *manager); +void BerryPatches_ElapseTime(FieldSystem *fieldSystem, int minutes); +void BerryPatches_UpdateGrowthStates(FieldSystem *fieldSystem); +BOOL BerryPatches_HarvestBerry(FieldSystem *fieldSystem, MapObject *mapObject); +void BerryPatches_SetMulchType(FieldSystem *fieldSystem, MapObject *mapObject, u16 mulchItemID); +void BerryPatches_PlantBerry(FieldSystem *fieldSystem, MapObject *mapObject, u16 berryItemID); +void BerryPatches_ResetMoisture(FieldSystem *fieldSystem, MapObject *mapObject); +int BerryPatches_GetGrowthStage(const FieldSystem *fieldSystem, const MapObject *mapObject); +int BerryPatches_GetBerryID(const FieldSystem *fieldSystem, const MapObject *mapObject); +u16 BerryPatches_GetItemID(const FieldSystem *fieldSystem, const MapObject *mapObject); +u16 BerryPatches_GetMulchItemID(const FieldSystem *fieldSystem, const MapObject *mapObject); +int BerryPatches_GetMoisture(const FieldSystem *fieldSystem, const MapObject *mapObject); +int BerryPatches_GetYield(const FieldSystem *fieldSystem, const MapObject *mapObject); +u32 BerryPatches_GetPatchFlags(const FieldSystem *fieldSystem, const MapObject *mapObject); +void BerryPatches_StartWatering(FieldSystem *fieldSystem); +void BerryPatches_EndWatering(FieldSystem *fieldSystem); + +#endif // POKEPLATINUM_BERRY_PATCH_MANAGER_H diff --git a/include/constants/items.h b/include/constants/items.h index dcb6bbc269..b37633e443 100644 --- a/include/constants/items.h +++ b/include/constants/items.h @@ -59,6 +59,14 @@ #define BERRY_ID(__name) (ITEM_##__name##_BERRY - FIRST_BERRY_IDX) #define BERRY_ID_NONE 0xFF +#define BERRY_TAG_NONE 0 + +#define FIRST_MULCH_IDX ITEM_GROWTH_MULCH +#define LAST_MULCH_IDX ITEM_GOOEY_MULCH +#define NUM_MULCHS (LAST_MULCH_IDX - FIRST_MULCH_IDX + 1) +#define MULCH_ID(__name) (ITEM_##__name##_MULCH - FIRST_MULCH_IDX) +#define MULCH_ID_NONE 0xFF + #define FIRST_TMHM_IDX ITEM_TM01 #define LAST_TMHM_IDX ITEM_HM08 #define TMHM_ID(__tmhm) (ITEM_##__tmhm - FIRST_TMHM_IDX) diff --git a/include/constants/scrcmd.h b/include/constants/scrcmd.h index 2392615920..eec568f801 100644 --- a/include/constants/scrcmd.h +++ b/include/constants/scrcmd.h @@ -4,6 +4,9 @@ #include "generated/accessories.h" #include "generated/backdrops.h" +#define BERRY_WATERING_START 0 +#define BERRY_WATERING_END 1 + #define MENU_YES 0 #define MENU_NO 1 #define MENU_CANCEL -2 diff --git a/include/field/field_system_sub2_t.h b/include/field/field_system_sub2_t.h index fec611278d..654a9f2fff 100644 --- a/include/field/field_system_sub2_t.h +++ b/include/field/field_system_sub2_t.h @@ -1,7 +1,7 @@ #ifndef POKEPLATINUM_FIELD_SYSTEM_SUB2_T_H #define POKEPLATINUM_FIELD_SYSTEM_SUB2_T_H -#include "struct_decls/struct_02055CBC_decl.h" +#include "struct_decls/berry_patch_manager_decl.h" #include "applications/poketch/poketch_system.h" #include "overlay005/hblank_system.h" @@ -18,7 +18,7 @@ struct FieldSystem_sub2_t { UnkStruct_ov5_021D5EF8 *unk_0C; UnkStruct_ov5_021D5CB0 *unk_10; PoketchSystem *poketchSys; - UnkStruct_02055CBC *unk_18; + BerryPatchManager *berryPatchManager; HBlankSystem *hBlankSystem; UnkStruct_ov5_021EF4F8 *unk_20; void *dynamicMapFeaturesData; diff --git a/include/item_use_functions.h b/include/item_use_functions.h index a5b11716e7..56711cb16a 100644 --- a/include/item_use_functions.h +++ b/include/item_use_functions.h @@ -21,7 +21,7 @@ typedef struct ItemUseContext { int playerState; u16 facingTileBehavior; // behavior of the tile the player is facing u16 currTileBehavior; - u16 unk_10; + u16 berryPatchFlags; u8 padding_12[2]; PlayerAvatar *playerAvatar; FieldSystem *fieldSystem; @@ -64,7 +64,7 @@ typedef struct UnkStruct_02068EFC { u32 GetItemUseFunction(u16 param0, u16 param1); void sub_0206842C(FieldSystem *fieldSystem, ItemUseContext *param1); -BOOL sub_02068B50(const ItemUseContext *param0); +BOOL BerryPatch_IsEmpty(const ItemUseContext *usageContext); BOOL sub_02069238(FieldSystem *fieldSystem); #endif // POKEPLATINUM_ITEM_USE_FUNCTIONS_H diff --git a/include/map_object.h b/include/map_object.h index d2df342588..08db92c684 100644 --- a/include/map_object.h +++ b/include/map_object.h @@ -111,7 +111,7 @@ void sub_02062914(MapObject *mapObj, int param1); int sub_02062918(const MapObject *mapObj); void MapObject_SetGraphicsID(MapObject *mapObj, u32 graphicsID); u32 MapObject_GetGraphicsID(const MapObject *mapObj); -u32 sub_02062924(const MapObject *mapObj); +u32 MapObject_GetEffectiveGraphicsID(const MapObject *mapObj); void MapObject_SetMovementType(MapObject *mapObj, u32 movementType); u32 MapObject_GetMovementType(const MapObject *mapObj); void MapObject_SetTrainerType(MapObject *mapObj, u32 trainerType); diff --git a/include/overlay005/berry_graphics_data.h b/include/overlay005/berry_graphics_data.h new file mode 100644 index 0000000000..3a8c602d1c --- /dev/null +++ b/include/overlay005/berry_graphics_data.h @@ -0,0 +1,10 @@ +#ifndef POKEPLATINUM_BERRY_GRAPHICS_DATA_H +#define POKEPLATINUM_BERRY_GRAPHICS_DATA_H + +typedef struct BerryGraphicsData { + u32 growingResourceID; + u32 bloomingResourceID; + u32 fruitResourceID; +} BerryGraphicsData; + +#endif // POKEPLATINUM_BERRY_GRAPHICS_DATA_H diff --git a/include/overlay005/berry_graphics_table.h b/include/overlay005/berry_graphics_table.h new file mode 100644 index 0000000000..ec4030532a --- /dev/null +++ b/include/overlay005/berry_graphics_table.h @@ -0,0 +1,8 @@ +#ifndef POKEPLATINUM_BERRY_GRAPHICS_TABLE_H +#define POKEPLATINUM_BERRY_GRAPHICS_TABLE_H + +#include "overlay005/berry_graphics_data.h" + +extern const BerryGraphicsData gBerryGraphicsTable[]; + +#endif // POKEPLATINUM_BERRY_GRAPHICS_TABLE_H diff --git a/include/overlay005/const_ov5_021FB67C.h b/include/overlay005/const_ov5_021FB67C.h deleted file mode 100644 index 5aa351a89b..0000000000 --- a/include/overlay005/const_ov5_021FB67C.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef POKEPLATINUM_CONST_OV5_021FB67C_H -#define POKEPLATINUM_CONST_OV5_021FB67C_H - -#include "overlay005/struct_ov5_021FB67C.h" - -extern const UnkStruct_ov5_021FB67C Unk_ov5_021FB67C[]; - -#endif // POKEPLATINUM_CONST_OV5_021FB67C_H diff --git a/include/overlay005/struct_ov5_021FB67C.h b/include/overlay005/struct_ov5_021FB67C.h deleted file mode 100644 index ff6ad231fa..0000000000 --- a/include/overlay005/struct_ov5_021FB67C.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV5_021FB67C_H -#define POKEPLATINUM_STRUCT_OV5_021FB67C_H - -typedef struct { - u32 unk_00; - u32 unk_04; - u32 unk_08; -} UnkStruct_ov5_021FB67C; - -#endif // POKEPLATINUM_STRUCT_OV5_021FB67C_H diff --git a/include/scrcmd_berry.h b/include/scrcmd_berry.h new file mode 100644 index 0000000000..7ab066d2b9 --- /dev/null +++ b/include/scrcmd_berry.h @@ -0,0 +1,16 @@ +#ifndef POKEPLATINUM_SCRCMD_BERRY_H +#define POKEPLATINUM_SCRCMD_BERRY_H + +#include "field_script_context.h" + +BOOL ScrCmd_GetBerryGrowthStage(ScriptContext *ctx); +BOOL ScrCmd_GetBerryItemID(ScriptContext *ctx); +BOOL ScrCmd_GetBerryMulchType(ScriptContext *ctx); +BOOL ScrCmd_GetBerryMoisture(ScriptContext *ctx); +BOOL ScrCmd_GetBerryYield(ScriptContext *ctx); +BOOL ScrCmd_SetBerryMulch(ScriptContext *ctx); +BOOL ScrCmd_PlantBerry(ScriptContext *ctx); +BOOL ScrCmd_SetBerryWateringState(ScriptContext *ctx); +BOOL ScrCmd_HarvestBerry(ScriptContext *ctx); + +#endif // POKEPLATINUM_SCRCMD_BERRY_H diff --git a/include/struct_decls/berry_patch_manager_decl.h b/include/struct_decls/berry_patch_manager_decl.h new file mode 100644 index 0000000000..9225d1145a --- /dev/null +++ b/include/struct_decls/berry_patch_manager_decl.h @@ -0,0 +1,6 @@ +#ifndef POKEPLATINUM_BERRY_PATCH_MANAGER_DECL_H +#define POKEPLATINUM_BERRY_PATCH_MANAGER_DECL_H + +typedef struct BerryPatchManager BerryPatchManager; + +#endif // POKEPLATINUM_BERRY_PATCH_MANAGER_DECL_H diff --git a/include/struct_decls/struct_02055CBC_decl.h b/include/struct_decls/struct_02055CBC_decl.h deleted file mode 100644 index bcf7b99a72..0000000000 --- a/include/struct_decls/struct_02055CBC_decl.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_02055CBC_DECL_H -#define POKEPLATINUM_STRUCT_02055CBC_DECL_H - -typedef struct UnkStruct_02055CBC_t UnkStruct_02055CBC; - -#endif // POKEPLATINUM_STRUCT_02055CBC_DECL_H diff --git a/include/unk_0204B64C.h b/include/unk_0204B64C.h deleted file mode 100644 index 7491f2baf4..0000000000 --- a/include/unk_0204B64C.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef POKEPLATINUM_UNK_0204B64C_H -#define POKEPLATINUM_UNK_0204B64C_H - -#include "field_script_context.h" - -BOOL ScrCmd_17D(ScriptContext *param0); -BOOL ScrCmd_17E(ScriptContext *param0); -BOOL ScrCmd_17F(ScriptContext *param0); -BOOL ScrCmd_180(ScriptContext *param0); -BOOL ScrCmd_181(ScriptContext *param0); -BOOL ScrCmd_182(ScriptContext *param0); -BOOL ScrCmd_183(ScriptContext *param0); -BOOL ScrCmd_184(ScriptContext *param0); -BOOL ScrCmd_185(ScriptContext *param0); - -#endif // POKEPLATINUM_UNK_0204B64C_H diff --git a/include/unk_02055C50.h b/include/unk_02055C50.h deleted file mode 100644 index 225a3471d9..0000000000 --- a/include/unk_02055C50.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef POKEPLATINUM_UNK_02055C50_H -#define POKEPLATINUM_UNK_02055C50_H - -#include "struct_decls/struct_02055CBC_decl.h" -#include "struct_decls/struct_02061AB4_decl.h" - -#include "field/field_system_decl.h" - -UnkStruct_02055CBC *sub_02055C8C(FieldSystem *fieldSystem, int heapID); -void sub_02055CBC(UnkStruct_02055CBC *param0); -void sub_02055CD4(FieldSystem *fieldSystem, int param1); -void sub_02055D94(FieldSystem *fieldSystem); -BOOL sub_02055E00(FieldSystem *fieldSystem, MapObject *param1); -void sub_02055E80(FieldSystem *fieldSystem, MapObject *param1, u16 param2); -void sub_02055EAC(FieldSystem *fieldSystem, MapObject *param1, u16 param2); -void sub_02055EE0(FieldSystem *fieldSystem, MapObject *param1); -int sub_02055F00(const FieldSystem *fieldSystem, const MapObject *param1); -int sub_02055F20(const FieldSystem *fieldSystem, const MapObject *param1); -u16 sub_02055F40(const FieldSystem *fieldSystem, const MapObject *param1); -u16 sub_02055F64(const FieldSystem *fieldSystem, const MapObject *param1); -int sub_02055F88(const FieldSystem *fieldSystem, const MapObject *param1); -int sub_02055FA8(const FieldSystem *fieldSystem, const MapObject *param1); -u32 sub_02055FC8(const FieldSystem *fieldSystem, const MapObject *param1); -void sub_020562AC(FieldSystem *fieldSystem); -void sub_020562D8(FieldSystem *fieldSystem); - -#endif // POKEPLATINUM_UNK_02055C50_H diff --git a/include/unk_020677F4.h b/include/unk_020677F4.h deleted file mode 100644 index 497b08a3b1..0000000000 --- a/include/unk_020677F4.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef POKEPLATINUM_UNK_020677F4_H -#define POKEPLATINUM_UNK_020677F4_H - -#include "struct_decls/struct_020216E0_decl.h" -#include "struct_decls/struct_02061AB4_decl.h" - -int sub_020677F4(int param0); -int sub_02067800(const MapObject *param0); -void sub_02067834(MapObject *param0); -void sub_02067840(MapObject *param0); -void sub_02067850(MapObject *param0); -void sub_0206786C(MapObject *param0); -void sub_02067870(MapObject *param0); -void sub_02067890(MapObject *param0); -void sub_02067950(MapObject *param0); -void sub_02067968(MapObject *param0); -void sub_02067998(MapObject *param0); -UnkStruct_020216E0 *sub_02067A58(MapObject *param0); - -#endif // POKEPLATINUM_UNK_020677F4_H diff --git a/include/unk_0206CCB0.h b/include/unk_0206CCB0.h index 57064879c4..84992929e9 100644 --- a/include/unk_0206CCB0.h +++ b/include/unk_0206CCB0.h @@ -16,6 +16,7 @@ int sub_0206CD00(int param0, FieldSystem *fieldSystem, StringTemplate *param2, U BOOL sub_0206CD2C(int param0, FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param2); void sub_0206CF14(TVBroadcast *broadcast, Pokemon *param1, int param2, int param3, int param4); void sub_0206CF48(TVBroadcast *broadcast, Pokemon *param1, int heapID); +void TVBroadcast_RecordBerryHarvest(FieldSystem *fieldSystem, u16 berryItemID, u8 yieldRating, u16 yieldAmount); void sub_0206CF9C(TVBroadcast *broadcast, int param1); void sub_0206CFB4(TVBroadcast *broadcast, int param1); void sub_0206CFCC(TVBroadcast *broadcast, int param1); diff --git a/platinum.us/main.lsf b/platinum.us/main.lsf index 79b80c2fb1..45268317f7 100644 --- a/platinum.us/main.lsf +++ b/platinum.us/main.lsf @@ -195,7 +195,7 @@ Static main Object main.nef.p/src_unk_020494DC.c.o Object main.nef.p/src_unk_02049D08.c.o Object main.nef.p/src_unk_0204AEE8.c.o - Object main.nef.p/src_unk_0204B64C.c.o + Object main.nef.p/src_scrcmd_berry.c.o Object main.nef.p/src_scrcmd_mystery_gift.c.o Object main.nef.p/src_scrcmd_catching_show.c.o Object main.nef.p/src_scrcmd_coins.c.o @@ -233,7 +233,7 @@ Static main Object main.nef.p/src_overworld_map_history.c.o Object main.nef.p/src_field_transition.c.o Object main.nef.p/src_unk_020559DC.c.o - Object main.nef.p/src_unk_02055C50.c.o + Object main.nef.p/src_berry_patch_manager.c.o Object main.nef.p/src_catching_show.c.o Object main.nef.p/src_poketch.c.o Object main.nef.p/src_unk_02056B30.c.o @@ -257,7 +257,7 @@ Static main Object main.nef.p/src_unk_0206450C.c.o Object main.nef.p/src_unk_020655F4.c.o Object main.nef.p/src_unk_020673B8.c.o - Object main.nef.p/src_unk_020677F4.c.o + Object main.nef.p/src_berry_patch_graphics.c.o Object main.nef.p/src_unk_02067A84.c.o Object main.nef.p/src_dynamic_map_features.c.o Object main.nef.p/src_item_use_functions.c.o diff --git a/res/field/scripts/scripts_unk_0413.s b/res/field/scripts/scripts_unk_0413.s index 936cda6c9a..c6706aae45 100644 --- a/res/field/scripts/scripts_unk_0413.s +++ b/res/field/scripts/scripts_unk_0413.s @@ -12,9 +12,9 @@ _0012: PlayFanfare SEQ_SE_CONFIRM LockAll FacePlayer - ScrCmd_17E VAR_0x8000 - ScrCmd_181 VAR_0x8001 - ScrCmd_17D VAR_RESULT + GetBerryItemID VAR_0x8000 + GetBerryYield VAR_0x8001 + GetBerryGrowthStage VAR_RESULT SetVar VAR_0x8008, VAR_RESULT GoToIfEq VAR_0x8008, 0, _033E GoToIfEq VAR_0x8008, 1, _0082 @@ -112,10 +112,10 @@ _01F2: ShowYesNoMenu VAR_RESULT GoToIfEq VAR_RESULT, MENU_NO, _053A CloseMessage - ScrCmd_184 0 + SetBerryWateringState BERRY_WATERING_START Message 20 WaitABXPadPress - ScrCmd_184 1 + SetBerryWateringState BERRY_WATERING_END GoTo _053A _021B: @@ -144,7 +144,7 @@ _0289: _0291: PlaySound SEQ_KINOMI WaitSound - ScrCmd_185 + HarvestBerry BufferPlayerName 0 GoToIfGt VAR_0x8001, 1, _02B4 BufferItemName 1, VAR_0x8000 @@ -191,11 +191,11 @@ _0336: GoTo _053A _033E: - ScrCmd_17F VAR_RESULT + GetBerryMulchType VAR_RESULT GoToIfEq VAR_RESULT, 0, _0374 ScrCmd_17A 4, VAR_RESULT GoToIfEq VAR_RESULT, 0, _054B - ScrCmd_17F VAR_RESULT + GetBerryMulchType VAR_RESULT BufferItemName 0, VAR_RESULT Message 1 GoTo _04DA @@ -250,7 +250,7 @@ _042D: _049D: RemoveItem VAR_0x8005, 1, VAR_0x8004 - ScrCmd_182 VAR_0x8005 + SetBerryMulch VAR_0x8005 ScrCmd_17A 4, VAR_RESULT GoToIfEq VAR_RESULT, 0, _04CA BufferItemName 0, VAR_0x8005 @@ -281,7 +281,7 @@ _04EE: Message 12 WaitABXPadPress RemoveItem VAR_RESULT, 1, VAR_0x8004 - ScrCmd_183 VAR_RESULT + PlantBerry VAR_RESULT GoTo _053A _053A: @@ -296,7 +296,7 @@ _0540: GoTo _053A _054B: - ScrCmd_17F VAR_RESULT + GetBerryMulchType VAR_RESULT BufferItemName 0, VAR_RESULT Message 29 WaitABXPadPress @@ -311,16 +311,16 @@ _055F: WaitABXPadPress CloseMessage RemoveItem VAR_0x8000, 1, VAR_0x8004 - ScrCmd_183 VAR_0x8000 + PlantBerry VAR_0x8000 ReleaseAll End _0583: LockAll - ScrCmd_184 0 + SetBerryWateringState BERRY_WATERING_START Message 20 WaitABXPadPress - ScrCmd_184 1 + SetBerryWateringState BERRY_WATERING_END CloseMessage ReleaseAll End diff --git a/src/applications/bag/main.c b/src/applications/bag/main.c index 94b45a5c9d..31bc2b620a 100644 --- a/src/applications/bag/main.c +++ b/src/applications/bag/main.c @@ -1966,7 +1966,7 @@ static void MakeItemActionsMenu(BagController *controller) itemActions[itemActionsIdx] = ITEM_ACTION_CHECK; } else if (controller->bagCtx->selectedItem == ITEM_POFFIN_CASE) { itemActions[itemActionsIdx] = ITEM_ACTION_OPEN; - } else if (controller->bagCtx->accessiblePockets[controller->bagCtx->currPocketIdx].pocketType == POCKET_BERRIES && sub_02068B50(controller->bagCtx->itemUseCtx) == TRUE) { + } else if (controller->bagCtx->accessiblePockets[controller->bagCtx->currPocketIdx].pocketType == POCKET_BERRIES && BerryPatch_IsEmpty(controller->bagCtx->itemUseCtx) == TRUE) { itemActions[itemActionsIdx] = ITEM_ACTION_PLANT; } else { itemActions[itemActionsIdx] = ITEM_ACTION_USE; diff --git a/src/berry_patch_graphics.c b/src/berry_patch_graphics.c new file mode 100644 index 0000000000..7ea2619ab4 --- /dev/null +++ b/src/berry_patch_graphics.c @@ -0,0 +1,229 @@ +#include "berry_patch_graphics.h" + +#include +#include + +#include "struct_decls/struct_020216E0_decl.h" +#include "struct_decls/struct_02061AB4_decl.h" + +#include "overlay005/berry_graphics_data.h" +#include "overlay005/berry_graphics_table.h" +#include "overlay005/ov5_021ECC20.h" +#include "overlay005/ov5_021ECE40.h" +#include "overlay005/ov5_021F204C.h" +#include "overlay005/struct_ov5_021ED01C.h" + +#include "berry_patch_manager.h" +#include "berry_patches.h" +#include "map_header_data.h" +#include "map_object.h" +#include "unk_02020AEC.h" + +typedef struct BerryPatchData { + u16 growthStage; + u16 needsUpdate; +} BerryPatchData; + +typedef struct BerryPatchGraphics { + int graphicsResourceID; + enum BerryGrowthStage lastGrowthStage; + UnkStruct_020216E0 *graphicsObject; + UnkStruct_ov5_021ED01C graphicsState; +} BerryPatchGraphics; + +static int BerryPatchGraphics_GetGraphicsResourceID(int berryID, enum BerryGrowthStage growthStage); + +BOOL BerryPatchGraphics_IsBerryPatch(int graphicsID) +{ + if (graphicsID == 100) { + return TRUE; + } + + return FALSE; +} + +int BerryPatchGraphics_GetCurrentGraphicsResourceID(const MapObject *mapObject) +{ + BerryPatchData *patchData = sub_02062A78((MapObject *)mapObject); + + if (patchData->growthStage == BERRY_GROWTH_STAGE_NONE) { + return 0xffff; + } + + if (sub_02062DFC(mapObject) == 1) { + BerryPatchGraphics *graphicsData = sub_02062AF0((MapObject *)mapObject); + + if (graphicsData->lastGrowthStage != BERRY_GROWTH_STAGE_NONE) { + return graphicsData->graphicsResourceID; + } + } + + return 0xffff; +} + +void BerryPatchGraphics_MarkForUpdate(MapObject *mapObject) +{ + BerryPatchData *patchData = sub_02062A78(mapObject); + patchData->needsUpdate = TRUE; +} + +void BerryPatchGraphics_NewData(MapObject *mapObject) +{ + BerryPatchData *patchData = sub_02062A54(mapObject, sizeof(BerryPatchData)); + patchData->growthStage = BERRY_GROWTH_STAGE_NONE; +} + +void BerryPatchGraphics_UpdateGrowthStage(MapObject *mapObject) +{ + BerryPatchData *patchData = sub_02062A78(mapObject); + patchData->growthStage = BerryPatches_GetGrowthStage(MapObject_FieldSystem(mapObject), mapObject); +} + +void BerryPatchGraphics_NoOp(MapObject *mapObject) +{ + return; +} + +void BerryPatchGraphics_NewGraphics(MapObject *mapObject) +{ + BerryPatchGraphics *graphicsData = sub_02062ACC(mapObject, sizeof(BerryPatchGraphics)); + + graphicsData->graphicsResourceID = 0xffff; + graphicsData->lastGrowthStage = BERRY_GROWTH_STAGE_NONE; + + ov5_021F20D4(mapObject); +} + +void BerryPatchGraphics_UpdateGraphics(MapObject *mapObject) +{ + BerryPatchData *patchData = sub_02062A78(mapObject); + BerryPatchGraphics *graphicsData = sub_02062AF0(mapObject); + u32 currentGrowthStage = BerryPatches_GetGrowthStage(MapObject_FieldSystem(mapObject), mapObject); + + if (ov5_021EDD94(mapObject) == 1) { + return; + } + + if (currentGrowthStage != graphicsData->lastGrowthStage) { + ov5_021ECFD8(mapObject, &graphicsData->graphicsObject, graphicsData->graphicsResourceID); + + graphicsData->graphicsResourceID = BerryPatchGraphics_GetGraphicsResourceID( + BerryPatches_GetBerryID(MapObject_FieldSystem(mapObject), mapObject), currentGrowthStage); + + if (graphicsData->graphicsResourceID != 0xffff) { + if (graphicsData->lastGrowthStage != BERRY_GROWTH_STAGE_NONE) { + ov5_021F22BC(mapObject); + } + + ov5_021ECEB4(mapObject, &graphicsData->graphicsObject, graphicsData->graphicsResourceID); + } else { + if (graphicsData->lastGrowthStage != BERRY_GROWTH_STAGE_NONE && patchData->needsUpdate == FALSE) { + ov5_021F22BC(mapObject); + } + } + + patchData->needsUpdate = FALSE; + } + + graphicsData->lastGrowthStage = currentGrowthStage; + + if (ov5_021EDD94(mapObject) == 1) { + return; + } + + if (graphicsData->graphicsObject != NULL) { + ov5_021EDEB4(mapObject, graphicsData->graphicsObject); + + if (ov5_021ECD38(mapObject) == 0) { + sub_02021368(graphicsData->graphicsObject, FX32_ONE ); + } + + ov5_021EDED8(mapObject, graphicsData->graphicsObject); + } +} + +void BerryPatchGraphics_FreeGraphics(MapObject *mapObject) +{ + BerryPatchGraphics *graphicsData = sub_02062AF0(mapObject); + ov5_021ECFD8(mapObject, &graphicsData->graphicsObject, graphicsData->graphicsResourceID); +} + +void BerryPatchGraphics_PauseGraphics(MapObject *mapObject) +{ + BerryPatchGraphics *graphicsData = sub_02062AF0(mapObject); + + if (graphicsData->graphicsObject != NULL) { + ov5_021ED01C(graphicsData->graphicsObject, &graphicsData->graphicsState); + } + + ov5_021ECFD8(mapObject, &graphicsData->graphicsObject, graphicsData->graphicsResourceID); + MapObject_SetStatusFlagOn(mapObject, MAP_OBJ_STATUS_21); +} + +void BerryPatchGraphics_ResumeGraphics(MapObject *mapObject) +{ + BerryPatchGraphics *graphicsData = sub_02062AF0(mapObject); + + if (ov5_021EDD94(mapObject) == 1) { + return; + } + + if (graphicsData->graphicsObject == NULL) { + if (graphicsData->graphicsResourceID != 0xffff) { + ov5_021ECEB4(mapObject, &graphicsData->graphicsObject, graphicsData->graphicsResourceID); + } else { + MapObject_SetStatusFlagOff(mapObject, MAP_OBJ_STATUS_21); + } + + ov5_021F20D4(mapObject); + } + + if (graphicsData->graphicsObject != NULL) { + ov5_021ED03C(graphicsData->graphicsObject, &graphicsData->graphicsState); + ov5_021EDEB4(mapObject, graphicsData->graphicsObject); + MapObject_SetStatusFlagOff(mapObject, MAP_OBJ_STATUS_21); + } +} + +static int BerryPatchGraphics_GetGraphicsResourceID(int berryID, enum BerryGrowthStage growthStage) +{ + switch (growthStage) { + case BERRY_GROWTH_STAGE_NONE: + return 0xffff; + case BERRY_GROWTH_STAGE_PLANTED: + return 0xffff; + default: + berryID--; + + const BerryGraphicsData *graphicsData = &gBerryGraphicsTable[berryID]; + + switch (growthStage) { + case BERRY_GROWTH_STAGE_SPROUTED: + return 4096; + case BERRY_GROWTH_STAGE_GROWING: + return graphicsData->growingResourceID; + case BERRY_GROWTH_STAGE_BLOOMING: + return graphicsData->bloomingResourceID; + case BERRY_GROWTH_STAGE_FRUIT: + return graphicsData->fruitResourceID; + } + } + + GF_ASSERT(FALSE); + return 0xffff; +} + +UnkStruct_020216E0 *BerryPatchGraphics_GetGraphicsObject(MapObject *mapObject) +{ + UnkStruct_020216E0 *graphicsObject = NULL; + + GF_ASSERT(BerryPatchGraphics_IsBerryPatch(MapObject_GetGraphicsID(mapObject))); + + if (sub_02062D4C(mapObject) == 1) { + BerryPatchGraphics *graphicsData = sub_02062AF0(mapObject); + + graphicsObject = graphicsData->graphicsObject; + } + + return graphicsObject; +} diff --git a/src/berry_patch_manager.c b/src/berry_patch_manager.c new file mode 100644 index 0000000000..9e86d06d80 --- /dev/null +++ b/src/berry_patch_manager.c @@ -0,0 +1,450 @@ +#include "berry_patch_manager.h" + +#include +#include + +#include "constants/items.h" + +#include "struct_decls/berry_patch_manager_decl.h" +#include "struct_decls/struct_02061AB4_decl.h" + +#include "field/field_system.h" +#include "field/field_system_sub2_t.h" +#include "overlay005/map_object_anim_cmd.h" +#include "overlay005/ov5_021DF440.h" +#include "overlay005/ov5_021DFB54.h" +#include "overlay005/struct_ov5_021DF47C_decl.h" + +#include "bag.h" +#include "berry_patch_graphics.h" +#include "berry_patches.h" +#include "easy3d.h" +#include "field_task.h" +#include "gfx_box_test.h" +#include "heap.h" +#include "location.h" +#include "map_object.h" +#include "player_avatar.h" +#include "savedata_misc.h" +#include "sys_task_manager.h" +#include "system.h" +#include "terrain_collision_manager.h" +#include "unk_020655F4.h" +#include "unk_0206CCB0.h" + +struct BerryPatchManager { + int heapID; + BerryGrowthData *growthData; + NNSG3dRenderObj renderObj; + NNSG3dResMdl *model; + NNSG3dResFileHeader *resource; +}; + +typedef struct BerryWateringTask { + enum BerryWateringState state; + enum FaceDirection direction; + int timer; + SysTask *animationTask; +} BerryWateringTask; + +static void BerryPatchManager_Init3DRendering(FieldSystem *fieldSystem, BerryPatchManager *manager); +static void BerryPatchManager_Cleanup3DRendering(BerryPatchManager *manager); + +static u16 BerryPatches_ConvertTagNumberToItemID(int tagNumber) +{ + if (tagNumber == BERRY_TAG_NONE) { + return ITEM_NONE; + } + + return tagNumber + FIRST_BERRY_IDX - 1; +} + +static u16 BerryPatches_ConvertItemIDToTagNumber(int itemID) +{ + if (itemID == ITEM_NONE) { + return BERRY_TAG_NONE; + } + + return itemID - FIRST_BERRY_IDX + 1; +} + +static u16 BerryPatches_ConvertMulchTypeToItemID(enum MulchType mulchType) +{ + if (mulchType == MULCH_TYPE_NONE) { + return ITEM_NONE; + } + + return mulchType + FIRST_MULCH_IDX - 1; +} + +static enum MulchType BerryPatches_ConvertItemIDToMulchType(int itemID) +{ + if (itemID == ITEM_NONE) { + return MULCH_TYPE_NONE; + } + + return itemID - FIRST_MULCH_IDX + 1; +} + +BerryPatchManager *BerryPatchManager_New(FieldSystem *fieldSystem, enum HeapID heapID) +{ + BerryPatchManager *manager = Heap_Alloc(heapID, sizeof(BerryPatchManager)); + MI_CpuClear8(manager, sizeof(BerryPatchManager)); + + manager->heapID = heapID; + manager->growthData = BerryGrowthData_Init(heapID); + + BerryPatchManager_Init3DRendering(fieldSystem, manager); + return manager; +} + +void BerryPatchManager_Free(BerryPatchManager *manager) +{ + BerryPatchManager_Cleanup3DRendering(manager); + Heap_Free(manager->growthData); + Heap_Free(manager); +} + +void BerryPatches_ElapseTime(FieldSystem *fieldSystem, int minutes) +{ + if (fieldSystem->unk_04 == NULL) { + BerryGrowthData *growthData = BerryGrowthData_Init(HEAP_ID_FIELD2); + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + BerryPatches_ElapseMinutes(berryPatches, growthData, minutes); + Heap_Free(growthData); + } else { + BerryGrowthData *growthData = fieldSystem->unk_04->berryPatchManager->growthData; + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + BerryPatches_ElapseMinutes(berryPatches, growthData, minutes); + } +} + +static void BerryPatchManager_Init3DRendering(FieldSystem *fieldSystem, BerryPatchManager *manager) +{ + UnkStruct_ov5_021DF47C *renderManager = fieldSystem->unk_40; + u32 resourceSize = ov5_021DF5A8(renderManager, 17); + + manager->resource = Heap_Alloc(manager->heapID, resourceSize); + + ov5_021DF5B4(renderManager, 17, manager->resource); + Easy3D_InitRenderObjFromResource(&manager->renderObj, &manager->model, &manager->resource); +} + +static void BerryPatchManager_Cleanup3DRendering(BerryPatchManager *manager) +{ + ov5_021DF554(manager->resource); +} + +static BOOL BerryPatches_IsInView(FieldSystem *fieldSystem, const VecFx32 *position) +{ + const VecFx32 scale = { FX32_ONE, FX32_ONE, FX32_ONE }; + MtxFx33 transform; + + MTX_Identity33(&transform); + + return GFXBoxTest_IsModelInView(fieldSystem->unk_04->berryPatchManager->model, position, &transform, &scale) != FALSE; +} + +void BerryPatches_UpdateGrowthStates(FieldSystem *fieldSystem) +{ + int objectIndex = 0; + MapObject *mapObject; + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + + while (sub_020625B0(fieldSystem->mapObjMan, &mapObject, &objectIndex, 1 << 0) == 1) { + if (BerryPatchGraphics_IsBerryPatch(MapObject_GetGraphicsID(mapObject)) == TRUE && BerryPatches_IsInView(fieldSystem, MapObject_GetPos(mapObject))) { + int patchID = MapObject_GetDataAt(mapObject, 0); + BerryPatches_SetIsPatchGrowing(berryPatches, patchID, TRUE); + } + } +} + +BOOL BerryPatches_HarvestBerry(FieldSystem *fieldSystem, MapObject *mapObject) +{ + int patchID, yieldAmount, berryID; + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + + patchID = MapObject_GetDataAt(mapObject, 0); + berryID = BerryPatches_GetPatchBerryID(berryPatches, patchID); + yieldAmount = BerryPatches_GetPatchYield(berryPatches, patchID); + + TVBroadcast_RecordBerryHarvest(fieldSystem, BerryPatches_ConvertTagNumberToItemID(berryID), BerryPatches_GetPatchYieldRating(berryPatches, patchID), yieldAmount); + BerryPatches_HarvestPatch(berryPatches, patchID); + BerryPatchGraphics_MarkForUpdate(mapObject); + + return Bag_TryAddItem(SaveData_GetBag(fieldSystem->saveData), BerryPatches_ConvertTagNumberToItemID(berryID), yieldAmount, HEAP_ID_FIELD1); +} + +void BerryPatches_SetMulchType(FieldSystem *fieldSystem, MapObject *mapObject, u16 mulchItemID) +{ + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + int patchID = MapObject_GetDataAt(mapObject, 0); + BerryPatches_SetPatchMulchType(berryPatches, patchID, BerryPatches_ConvertItemIDToMulchType(mulchItemID)); +} + +void BerryPatches_PlantBerry(FieldSystem *fieldSystem, MapObject *mapObject, u16 berryItemID) +{ + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + int patchID = MapObject_GetDataAt(mapObject, 0); + BerryPatches_PlantInPatch(berryPatches, patchID, fieldSystem->unk_04->berryPatchManager->growthData, BerryPatches_ConvertItemIDToTagNumber(berryItemID)); +} + +void BerryPatches_ResetMoisture(FieldSystem *fieldSystem, MapObject *mapObject) +{ + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + int patchID = MapObject_GetDataAt(mapObject, 0); + BerryPatches_ResetPatchMoisture(berryPatches, patchID); +} + +int BerryPatches_GetGrowthStage(const FieldSystem *fieldSystem, const MapObject *mapObject) +{ + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + int patchID = MapObject_GetDataAt(mapObject, 0); + return BerryPatches_GetPatchGrowthStage(berryPatches, patchID); +} + +int BerryPatches_GetBerryID(const FieldSystem *fieldSystem, const MapObject *mapObject) +{ + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + int patchID = MapObject_GetDataAt(mapObject, 0); + return BerryPatches_GetPatchBerryID(berryPatches, patchID); +} + +u16 BerryPatches_GetItemID(const FieldSystem *fieldSystem, const MapObject *mapObject) +{ + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + int patchID = MapObject_GetDataAt(mapObject, 0); + return BerryPatches_ConvertTagNumberToItemID(BerryPatches_GetPatchBerryID(berryPatches, patchID)); +} + +u16 BerryPatches_GetMulchItemID(const FieldSystem *fieldSystem, const MapObject *mapObject) +{ + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + int patchID = MapObject_GetDataAt(mapObject, 0); + return BerryPatches_ConvertMulchTypeToItemID(BerryPatches_GetPatchMulchType(berryPatches, patchID)); +} + +int BerryPatches_GetMoisture(const FieldSystem *fieldSystem, const MapObject *mapObject) +{ + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + int patchID = MapObject_GetDataAt(mapObject, 0); + return BerryPatches_GetPatchMoisture(berryPatches, patchID); +} + +int BerryPatches_GetYield(const FieldSystem *fieldSystem, const MapObject *mapObject) +{ + BerryPatch *berryPatches = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); + int patchID = MapObject_GetDataAt(mapObject, 0); + return BerryPatches_GetPatchYield(berryPatches, patchID); +} + +u32 BerryPatches_GetPatchFlags(const FieldSystem *fieldSystem, const MapObject *mapObject) +{ + u32 patchFlags = 0; + + if ((mapObject == NULL) || (MapObject_GetGraphicsID(mapObject) != 100)) { + return BERRY_PATCH_FLAG_INVALID; + } + + switch (BerryPatches_GetGrowthStage(fieldSystem, mapObject)) { + case BERRY_GROWTH_STAGE_NONE: + patchFlags |= BERRY_PATCH_FLAG_EMPTY; + + if (BerryPatches_GetMulchItemID(fieldSystem, mapObject) == ITEM_NONE) { + patchFlags |= BERRY_PATCH_FLAG_CAN_MULCH; + } + break; + default: + patchFlags |= BERRY_PATCH_FLAG_HAS_BERRY; + break; + } + + return patchFlags; +} + +// Animation sequence for watering berries while facing left +static const MapObjectAnimCmd BerryWatering_LeftAnimation[] = { + { 10, 1 }, // Play animation frame 10 for 1 frame + { 0xfe, 0 } // End of animation sequence +}; + +// Animation sequence for watering berries while facing right +static const MapObjectAnimCmd BerryWatering_RightAnimation[] = { + { 11, 1 }, // Play animation frame 11 for 1 frame + { 0xfe, 0 } // End of animation sequence +}; + +static BOOL BerryPatches_CheckCollision(FieldSystem *fieldSystem, BerryWateringTask *task, enum FaceDirection direction) +{ + int playerX = Player_GetXPos(fieldSystem->playerAvatar); + int playerZ = Player_GetZPos(fieldSystem->playerAvatar); + + if (direction == FACE_LEFT) { + playerX--; + } else if (direction == FACE_RIGHT) { + playerX++; + } else if (direction == FACE_UP) { + playerZ--; + } else if (direction == FACE_DOWN) { + playerZ++; + } else { + GF_ASSERT(FALSE); + } + + if (TerrainCollisionManager_CheckCollision(fieldSystem, playerX, playerZ)) { + return TRUE; + } + + return sub_0206326C(fieldSystem->mapObjMan, playerX, playerZ, 0) != NULL; +} + +static MapObject *BerryPatches_GetAdjacentObject(FieldSystem *fieldSystem, enum FaceDirection direction) +{ + int playerX = Player_GetXPos(fieldSystem->playerAvatar); + int playerZ = Player_GetZPos(fieldSystem->playerAvatar); + playerZ -= 1; + + if (direction == FACE_LEFT) { + playerX -= 1; + } else if (direction == FACE_RIGHT) { + playerX += 1; + } + + return sub_0206326C(fieldSystem->mapObjMan, playerX, playerZ, 0); +} + +static MapObject *BerryPatches_GetTargetPatch(FieldSystem *fieldSystem, BerryWateringTask *task) +{ + int playerX = Player_GetXPos(fieldSystem->playerAvatar); + int playerZ = Player_GetZPos(fieldSystem->playerAvatar); + + if (task->direction == FACE_UP) { + playerZ -= 1; + } else if (task->direction == FACE_DOWN) { + playerZ += 1; + } else { + GF_ASSERT(FALSE); + } + + return sub_0206326C(fieldSystem->mapObjMan, playerX, playerZ, 0); +} + +static BOOL BerryPatches_IsBerryPatch(MapObject *mapObject) +{ + return MapObject_GetGraphicsID(mapObject) == 100; +} + +static void BerryPatches_WaterPatch(FieldSystem *fieldSystem, BerryWateringTask *task) +{ + MapObject *targetPatch = BerryPatches_GetTargetPatch(fieldSystem, task); + + if (targetPatch != NULL) { + BerryPatches_ResetMoisture(fieldSystem, targetPatch); + } +} + +static void BerryPatches_StartAnimation(FieldSystem *fieldSystem, BerryWateringTask *task, const MapObjectAnimCmd *animationCmd) +{ + MapObject *playerObject = Player_MapObject(fieldSystem->playerAvatar); + task->animationTask = MapObject_StartAnimation(playerObject, animationCmd); +} + +static BOOL BerryPatches_TaskMain(FieldTask *taskManager) +{ + FieldSystem *fieldSystem = FieldTask_GetFieldSystem(taskManager); + BerryWateringTask *task = FieldTask_GetEnv(taskManager); + + switch (task->state) { + case BERRY_WATERING_STATE_INIT: + PlayerAvatar_SetTransitionState(fieldSystem->playerAvatar, PLAYER_TRANSITION_WATER_BERRIES); + PlayerAvatar_RequestChangeState(fieldSystem->playerAvatar); + MapObject_SetPauseMovementOff(Player_MapObject(fieldSystem->playerAvatar)); + task->state = BERRY_WATERING_STATE_WATERING; + break; + case BERRY_WATERING_STATE_WATERING: + BerryPatches_WaterPatch(fieldSystem, task); + task->timer = 0; + task->state = BERRY_WATERING_STATE_INPUT; + case BERRY_WATERING_STATE_INPUT: + if (gSystem.heldKeys & PAD_KEY_LEFT) { + MapObject *adjacentObject = BerryPatches_GetAdjacentObject(fieldSystem, FACE_LEFT); + + if ((adjacentObject == NULL) || !BerryPatches_IsBerryPatch(adjacentObject)) { + task->state = BERRY_WATERING_STATE_CLEANUP; + break; + } else if (!BerryPatches_CheckCollision(fieldSystem, task, FACE_LEFT)) { + BerryPatches_StartAnimation(fieldSystem, task, BerryWatering_LeftAnimation); + task->state = BERRY_WATERING_STATE_ANIMATION; + break; + } + } else if (gSystem.heldKeys & PAD_KEY_RIGHT) { + MapObject *adjacentObject = BerryPatches_GetAdjacentObject(fieldSystem, FACE_RIGHT); + + if ((adjacentObject == NULL) || !BerryPatches_IsBerryPatch(adjacentObject)) { + task->state = BERRY_WATERING_STATE_CLEANUP; + break; + } else if (!BerryPatches_CheckCollision(fieldSystem, task, FACE_RIGHT)) { + BerryPatches_StartAnimation(fieldSystem, task, BerryWatering_RightAnimation); + task->state = BERRY_WATERING_STATE_ANIMATION; + break; + } + } else if ((gSystem.heldKeys & PAD_KEY_UP) && (task->direction == FACE_DOWN)) { + Player_SetDir(fieldSystem->playerAvatar, FACE_UP); + task->state = BERRY_WATERING_STATE_CLEANUP; + break; + } else if ((gSystem.heldKeys & PAD_KEY_DOWN) && (task->direction == FACE_UP)) { + task->state = BERRY_WATERING_STATE_CLEANUP; + break; + } + + task->timer++; + + if (task->timer > 30 * 3) { + Player_SetDir(fieldSystem->playerAvatar, task->direction); + task->state = BERRY_WATERING_STATE_CLEANUP; + } + break; + case BERRY_WATERING_STATE_ANIMATION: + if (MapObject_HasAnimationEnded(task->animationTask)) { + MapObject *targetPatch; + + MapObject_FinishAnimation(task->animationTask); + targetPatch = BerryPatches_GetTargetPatch(fieldSystem, task); + + if ((targetPatch != NULL) && BerryPatches_IsBerryPatch(targetPatch)) { + task->state = BERRY_WATERING_STATE_WATERING; + } else { + Player_SetDir(fieldSystem->playerAvatar, task->direction); + task->state = BERRY_WATERING_STATE_CLEANUP; + } + } + break; + case BERRY_WATERING_STATE_CLEANUP: + Player_SetDir(fieldSystem->playerAvatar, task->direction); + MapObject_SetPauseMovementOn(Player_MapObject(fieldSystem->playerAvatar)); + Heap_Free(task); + return TRUE; + } + + return FALSE; +} + +void BerryPatches_StartWatering(FieldSystem *fieldSystem) +{ + BerryWateringTask *task = Heap_Alloc(HEAP_ID_FIELD3, sizeof(BerryWateringTask)); + + task->state = BERRY_WATERING_STATE_INIT; + task->animationTask = NULL; + task->direction = PlayerAvatar_GetDir(fieldSystem->playerAvatar); + + FieldTask_InitCall(fieldSystem->task, BerryPatches_TaskMain, task); +} + +void BerryPatches_EndWatering(FieldSystem *fieldSystem) +{ + int playerState = PlayerAvatar_GetPlayerState(fieldSystem->playerAvatar); + u32 transitionState = Player_ConvertStateToTransition(playerState); + + PlayerAvatar_SetTransitionState(fieldSystem->playerAvatar, transitionState); + PlayerAvatar_RequestChangeState(fieldSystem->playerAvatar); +} diff --git a/src/berry_patches.c b/src/berry_patches.c index 59764fb884..92b867477f 100644 --- a/src/berry_patches.c +++ b/src/berry_patches.c @@ -80,7 +80,7 @@ static void ZeroBerryPatch(BerryPatch *berryPatch) berryPatch->yield = 0; berryPatch->moistureRating = 0; berryPatch->yieldRating = 0; - berryPatch->mulchType = 0; + berryPatch->mulchType = MULCH_TYPE_NONE; berryPatch->isGrowing = FALSE; } diff --git a/src/game_records.c b/src/game_records.c index b076928300..dcc2070ae1 100644 --- a/src/game_records.c +++ b/src/game_records.c @@ -91,7 +91,7 @@ static u8 sUsesHighLimit[MAX_RECORDS] = { [RECORD_TRAINER_SCORE] = TRUE, [RECORD_UNK_002] = TRUE, [RECORD_UNK_003] = FALSE, - [RECORD_UNK_004] = TRUE, + [RECORD_BERRIES_PLANTED] = TRUE, [RECORD_UNK_005] = TRUE, [RECORD_UNK_006] = TRUE, [RECORD_WILD_BATTLES_FOUGHT] = TRUE, @@ -258,7 +258,7 @@ static u32 GetRecordLimit(int id) } static const u16 sTrainerScoreIncrements[MAX_TRAINER_SCORE_EVENTS] = { - [TRAINER_SCORE_EVENT_UNK_00] = 1, + [TRAINER_SCORE_EVENT_BERRY_HARVESTED] = 1, [TRAINER_SCORE_EVENT_HONEY_USED] = 1, [TRAINER_SCORE_EVENT_UNK_02] = 1, [TRAINER_SCORE_EVENT_UNK_03] = 1, diff --git a/src/item_use_functions.c b/src/item_use_functions.c index 5436ba86e8..9bd06918eb 100644 --- a/src/item_use_functions.c +++ b/src/item_use_functions.c @@ -25,6 +25,7 @@ #include "bag.h" #include "bag_context.h" +#include "berry_patch_manager.h" #include "bg_window.h" #include "field_map_change.h" #include "field_message.h" @@ -58,7 +59,6 @@ #include "unk_0203C954.h" #include "unk_0203D1B8.h" #include "unk_020553DC.h" -#include "unk_02055C50.h" #include "unk_0205F180.h" #include "unk_0206B9D8.h" #include "unk_020989DC.h" @@ -218,7 +218,7 @@ void sub_0206842C(FieldSystem *fieldSystem, ItemUseContext *usageContext) usageContext->facingTileBehavior = TerrainCollisionManager_GetTileBehavior(fieldSystem, playerXCoordinate, playerZCoordinate); sub_0203C9D4(fieldSystem, &v3); - usageContext->unk_10 = sub_02055FC8(fieldSystem, v3); + usageContext->berryPatchFlags = BerryPatches_GetPatchFlags(fieldSystem, v3); usageContext->playerAvatar = fieldSystem->playerAvatar; } @@ -235,7 +235,7 @@ static void sub_020684D0(FieldSystem *fieldSystem, ItemUseContext *usageContext) usageContext->facingTileBehavior = PlayerAvatar_GetDistortionTileBehaviour(fieldSystem->playerAvatar, v0); } - usageContext->unk_10 = sub_02055FC8(fieldSystem, NULL); + usageContext->berryPatchFlags = BerryPatches_GetPatchFlags(fieldSystem, NULL); usageContext->playerAvatar = fieldSystem->playerAvatar; } @@ -582,16 +582,16 @@ static void UseBerryFromMenu(ItemMenuUseContext *usageContext, const ItemUseCont fieldSystem = FieldTask_GetFieldSystem(usageContext->fieldTask); v1 = FieldTask_GetEnv(usageContext->fieldTask); - if (additionalContext->unk_10 & 0x1) { + if (additionalContext->berryPatchFlags & BERRY_PATCH_FLAG_EMPTY) { sub_02068540(usageContext, additionalContext, 2801); } else { UseHealingItemFromMenu(usageContext, additionalContext); } } -BOOL sub_02068B50(const ItemUseContext *usageContext) +BOOL BerryPatch_IsEmpty(const ItemUseContext *usageContext) { - if (usageContext->unk_10 & 0x1) { + if (usageContext->berryPatchFlags & BERRY_PATCH_FLAG_EMPTY) { return TRUE; } @@ -699,7 +699,7 @@ static u32 CanUseSprayDuck(const ItemUseContext *usageContext) return 2; } - if (usageContext->unk_10 & 0x4) { + if (usageContext->berryPatchFlags & BERRY_PATCH_FLAG_HAS_BERRY) { return 0; } else { return -1; @@ -713,7 +713,7 @@ static void UseMulchFromMenu(ItemMenuUseContext *usageContext, const ItemUseCont static u32 CanUseMulch(const ItemUseContext *usageContext) { - if (usageContext->unk_10 & 0x2) { + if (usageContext->berryPatchFlags & BERRY_PATCH_FLAG_CAN_MULCH) { return 0; } else { return -1; diff --git a/src/map_object.c b/src/map_object.c index 273647d159..848ae40604 100644 --- a/src/map_object.c +++ b/src/map_object.c @@ -25,6 +25,7 @@ #include "overlay005/struct_ov5_021FB0F0.h" #include "overlay005/struct_ov5_021FB97C.h" +#include "berry_patch_graphics.h" #include "heap.h" #include "map_header_data.h" #include "map_object_move.h" @@ -33,7 +34,6 @@ #include "sys_task.h" #include "sys_task_manager.h" #include "unk_020655F4.h" -#include "unk_020677F4.h" #include "unk_020EDBAC.h" typedef struct MapObjectMan { @@ -1017,7 +1017,7 @@ int sub_020627B4(const MapObject *mapObj, int param1, int param2, int param3) return 0; } - int v0 = sub_02062924(mapObj); + int v0 = MapObject_GetEffectiveGraphicsID(mapObj); if (v0 != param1) { return 0; @@ -1236,12 +1236,12 @@ u32 MapObject_GetGraphicsID(const MapObject *mapObj) return mapObj->graphicsID; } -u32 sub_02062924(const MapObject *mapObj) +u32 MapObject_GetEffectiveGraphicsID(const MapObject *mapObj) { u32 graphicsID = MapObject_GetGraphicsID(mapObj); - if (sub_020677F4(graphicsID) == TRUE) { - graphicsID = sub_02067800(mapObj); + if (BerryPatchGraphics_IsBerryPatch(graphicsID) == TRUE) { + graphicsID = BerryPatchGraphics_GetCurrentGraphicsResourceID(mapObj); } return graphicsID; @@ -1980,15 +1980,15 @@ int MapObject_IsDynamicHeightCalculationEnabled(const MapObject *mapObj) void sub_02062FC4(MapObject *mapObj, int param1) { if (param1 == TRUE) { - sub_020628F0(mapObj, (1 << 2)); + sub_020628F0(mapObj, 1 << 2); } else { - sub_020628F8(mapObj, (1 << 2)); + sub_020628F8(mapObj, 1 << 2); } } int sub_02062FDC(const MapObject *mapObj) { - if (sub_02062904(mapObj, (1 << 2))) { + if (sub_02062904(mapObj, 1 << 2)) { return TRUE; } diff --git a/src/meson.build b/src/meson.build index b7e9fe511e..4749562df2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -183,7 +183,7 @@ pokeplatinum_c = files( 'unk_020494DC.c', 'unk_02049D08.c', 'unk_0204AEE8.c', - 'unk_0204B64C.c', + 'scrcmd_berry.c', 'scrcmd_mystery_gift.c', 'scrcmd_catching_show.c', 'scrcmd_coins.c', @@ -220,7 +220,7 @@ pokeplatinum_c = files( 'overworld_map_history.c', 'field_transition.c', 'unk_020559DC.c', - 'unk_02055C50.c', + 'berry_patch_manager.c', 'catching_show.c', 'poketch.c', 'unk_02056B30.c', @@ -243,7 +243,7 @@ pokeplatinum_c = files( 'unk_0206450C.c', 'unk_020655F4.c', 'unk_020673B8.c', - 'unk_020677F4.c', + 'berry_patch_graphics.c', 'unk_02067A84.c', 'dynamic_map_features.c', 'item_use_functions.c', diff --git a/src/overlay005/fieldmap.c b/src/overlay005/fieldmap.c index 02106debbb..acc14dc895 100644 --- a/src/overlay005/fieldmap.c +++ b/src/overlay005/fieldmap.c @@ -47,6 +47,7 @@ #include "overlay005/struct_ov5_021ED0A4.h" #include "overlay009/ov9_02249960.h" +#include "berry_patch_manager.h" #include "bg_window.h" #include "camera.h" #include "char_transfer.h" @@ -83,7 +84,6 @@ #include "unk_0202419C.h" #include "unk_020553DC.h" #include "unk_020559DC.h" -#include "unk_02055C50.h" #include "vram_transfer.h" #define FIELD_MAP_INIT_STATE_RESET 0 @@ -250,7 +250,7 @@ static BOOL FieldMap_Main(ApplicationManager *appMan, int *param1) FieldSystem *fieldSystem = ApplicationManager_Args(appMan); if (FieldSystem_UpdateLocationToPlayerPosition(fieldSystem)) { - sub_02055D94(fieldSystem); + BerryPatches_UpdateGrowthStates(fieldSystem); ov5_021D13B4(fieldSystem); FieldSystem_SendPoketchEvent(fieldSystem, POKETCH_EVENT_PLAYER_MOVED, 1); @@ -323,7 +323,7 @@ static BOOL FieldMap_Exit(ApplicationManager *appMan, int *param1) ov5_021EF4F8(fieldSystem->unk_04->unk_20); HBlankSystem_Delete(fieldSystem->unk_04->hBlankSystem); - sub_02055CBC(fieldSystem->unk_04->unk_18); + BerryPatchManager_Free(fieldSystem->unk_04->berryPatchManager); ov5_021D57D8(&fieldSystem->unk_48); ModelAttributes_Free(&fieldSystem->areaModelAttrs); ov5_021D1570(); @@ -879,7 +879,7 @@ static void ov5_021D1878(FieldSystem *fieldSystem) sub_02062C3C(fieldSystem->mapObjMan); LandDataManager_TrackTarget(PlayerAvatar_PosVector(fieldSystem->playerAvatar), fieldSystem->landDataMan); - fieldSystem->unk_04->unk_18 = sub_02055C8C(fieldSystem, HEAP_ID_FIELD1); + fieldSystem->unk_04->berryPatchManager = BerryPatchManager_New(fieldSystem, HEAP_ID_FIELD1); } static void ov5_021D1968(FieldSystem *fieldSystem) diff --git a/src/overlay005/ov5_021EB1A0.c b/src/overlay005/ov5_021EB1A0.c index 0b36b9812a..d2ecc8f1a2 100644 --- a/src/overlay005/ov5_021EB1A0.c +++ b/src/overlay005/ov5_021EB1A0.c @@ -1561,7 +1561,7 @@ void ov5_021EC734(MapObject *mapObj) { VecFx32 v0; UnkStruct_ov5_021EC760 *v1 = sub_02062ACC(mapObj, (sizeof(UnkStruct_ov5_021EC760))); - ov5_021EC700(sub_02062924(mapObj), &v0); + ov5_021EC700(MapObject_GetEffectiveGraphicsID(mapObj), &v0); v1->unk_00 = ov5_021F121C(mapObj, &v0); } @@ -1594,7 +1594,7 @@ void ov5_021EC790(MapObject *mapObj) { VecFx32 v0; UnkStruct_ov5_021EC760 *v1 = sub_02062AF0(mapObj); - ov5_021EC700(sub_02062924(mapObj), &v0); + ov5_021EC700(MapObject_GetEffectiveGraphicsID(mapObj), &v0); v1->unk_00 = ov5_021F121C(mapObj, &v0); } diff --git a/src/overlay005/ov5_021ECE40.c b/src/overlay005/ov5_021ECE40.c index 41067c22f8..f39d6dc717 100644 --- a/src/overlay005/ov5_021ECE40.c +++ b/src/overlay005/ov5_021ECE40.c @@ -40,6 +40,7 @@ #include "overlay005/struct_ov5_021F06D8_decl.h" #include "overlay101/struct_ov101_021D5D90_decl.h" +#include "berry_patch_graphics.h" #include "enums.h" #include "heap.h" #include "map_object.h" @@ -51,7 +52,6 @@ #include "sys_task_manager.h" #include "unk_02020AEC.h" #include "unk_0202414C.h" -#include "unk_020677F4.h" #include "unk_020711EC.h" typedef enum { @@ -271,8 +271,8 @@ void ov5_021ECFA4(const MapObject *param0, UnkStruct_020216E0 **param1) if ((*param1) != NULL) { int v0 = MapObject_GetGraphicsID(param0); - if (sub_020677F4(v0) == 1) { - v0 = sub_02067800(param0); + if (BerryPatchGraphics_IsBerryPatch(v0) == 1) { + v0 = BerryPatchGraphics_GetCurrentGraphicsResourceID(param0); } ov5_021ECF70(param0, param1, v0); @@ -467,8 +467,8 @@ static int ov5_021ED1C8(const MapObjectManager *param0, const MapObject *param1, if (sub_02062CF8(v2) == 1) { v1 = MapObject_GetGraphicsID(v2); - if (sub_020677F4(v1) == 1) { - v1 = sub_02067800(v2); + if (BerryPatchGraphics_IsBerryPatch(v1) == 1) { + v1 = BerryPatchGraphics_GetCurrentGraphicsResourceID(v2); } if ((v1 != 0xffff) && (v1 == param2)) { @@ -592,7 +592,7 @@ static UnkEnum_ov5_021ED334 ov5_021ED3A4(UnkStruct_ov5_021ED0A4 *param0, int par static void ov5_021ED3B8(UnkStruct_ov5_021ED0A4 *param0, const int *param1) { while ((*param1) != 0xffff) { - ov5_021ED390(param0, (*param1)); + ov5_021ED390(param0, *param1); param1++; } } @@ -616,7 +616,7 @@ static void ov5_021ED40C(UnkStruct_ov5_021ED0A4 *param0, int param1) static void ov5_021ED43C(UnkStruct_ov5_021ED0A4 *param0, const int *param1) { while ((*param1) != 0xffff) { - ov5_021ED3DC(param0, (*param1)); + ov5_021ED3DC(param0, *param1); param1++; } } @@ -640,7 +640,7 @@ static void ov5_021ED490(UnkStruct_ov5_021ED0A4 *param0, int param1) static void ov5_021ED4C0(UnkStruct_ov5_021ED0A4 *param0, const int *param1) { while ((*param1) != 0xffff) { - ov5_021ED460(param0, (*param1)); + ov5_021ED460(param0, *param1); param1++; } } @@ -775,7 +775,7 @@ static void ov5_021ED63C(MapObjectManager *param0, UnkStruct_ov5_021ED0A4 *param do { if ((*v1) != 0xffff) { - if (ov5_021EDAB4(param0, (*v1), NULL) == 0) { + if (ov5_021EDAB4(param0, *v1, NULL) == 0) { ov5_021F0740(param1->unk_F8, *v1); *v1 = 0xffff; } @@ -856,7 +856,7 @@ static void ov5_021ED778(MapObjectManager *param0, UnkStruct_ov5_021ED0A4 *param do { if ((*v1) != 0xffff) { - if (ov5_021EDB3C(param0, (*v1), NULL) == 0) { + if (ov5_021EDB3C(param0, *v1, NULL) == 0) { ov5_021F0740(param1->unk_FC, *v1); *v1 = 0xffff; } @@ -1055,8 +1055,8 @@ static int ov5_021EDA54(const MapObjectManager *param0, int param1, const MapObj v1 = MapObject_GetGraphicsID(v2); - if (sub_020677F4(v1) == 1) { - v1 = sub_02067800(v2); + if (BerryPatchGraphics_IsBerryPatch(v1) == 1) { + v1 = BerryPatchGraphics_GetCurrentGraphicsResourceID(v2); } if (v1 == param1) { @@ -1091,8 +1091,8 @@ static int ov5_021EDAB4(const MapObjectManager *param0, int param1, const MapObj } } - if (sub_020677F4(v0) == 1) { - v0 = sub_02067800(v2); + if (BerryPatchGraphics_IsBerryPatch(v0) == 1) { + v0 = BerryPatchGraphics_GetCurrentGraphicsResourceID(v2); } if (v0 != 0xffff) { @@ -1129,8 +1129,8 @@ static int ov5_021EDB3C(const MapObjectManager *param0, int param1, const MapObj v0 = MapObject_GetGraphicsID(v2); - if (sub_020677F4(v0) == 1) { - v0 = sub_02067800(v2); + if (BerryPatchGraphics_IsBerryPatch(v0) == 1) { + v0 = BerryPatchGraphics_GetCurrentGraphicsResourceID(v2); } if (v0 != 0xffff) { diff --git a/src/overlay005/ov5_021F17B8.c b/src/overlay005/ov5_021F17B8.c index 00e94e46e1..f14030b6a5 100644 --- a/src/overlay005/ov5_021F17B8.c +++ b/src/overlay005/ov5_021F17B8.c @@ -16,10 +16,10 @@ #include "overlay101/struct_ov101_021D5D90_decl.h" #include "overlay101/struct_ov101_021D86B0.h" +#include "berry_patch_graphics.h" #include "map_object.h" #include "map_object_move.h" #include "unk_02020AEC.h" -#include "unk_020677F4.h" #include "unk_020711EC.h" typedef struct { @@ -71,7 +71,7 @@ static const UnkStruct_ov101_021D86B0 Unk_ov5_02200338; void *ov5_021F17B8(UnkStruct_ov5_021DF47C *param0) { - UnkStruct_ov5_021F17E4 *v0 = ov5_021DF53C(param0, (sizeof(UnkStruct_ov5_021F17E4)), 0, 0); + UnkStruct_ov5_021F17E4 *v0 = ov5_021DF53C(param0, sizeof(UnkStruct_ov5_021F17E4), 0, 0); v0->unk_00 = param0; ov5_021F17E4(v0); @@ -129,8 +129,8 @@ static int ov5_021F184C(UnkStruct_ov101_021D5D90 *param0, void *param1) v1->unk_04 = sub_02062918(v1->unk_14.unk_0C); v1->unk_08 = MapObject_GetGraphicsID(v1->unk_14.unk_0C); - if (sub_020677F4(v1->unk_08) == 1) { - v1->unk_08 = sub_02067800(v1->unk_14.unk_0C); + if (BerryPatchGraphics_IsBerryPatch(v1->unk_08) == 1) { + v1->unk_08 = BerryPatchGraphics_GetCurrentGraphicsResourceID(v1->unk_14.unk_0C); } v1->unk_28.x = FX32_ONE; @@ -165,8 +165,8 @@ static void ov5_021F18E0(UnkStruct_ov101_021D5D90 *param0, void *param1) MapObject *v2 = v1->unk_14.unk_0C; v0 = MapObject_GetGraphicsID(v2); - if (sub_020677F4(v0) == 1) { - v0 = sub_02067800(v1->unk_14.unk_0C); + if (BerryPatchGraphics_IsBerryPatch(v0) == 1) { + v0 = BerryPatchGraphics_GetCurrentGraphicsResourceID(v1->unk_14.unk_0C); } if ((v1->unk_08 != v0) || (sub_02062764(v2, v1->unk_00, v1->unk_04) == 0) || (sub_02062F64(v2) == 0)) { @@ -206,8 +206,8 @@ static void ov5_021F1978(UnkStruct_ov101_021D5D90 *param0, void *param1) { int v2 = MapObject_GetGraphicsID(v1); - if (sub_020677F4(v2) == 1) { - v2 = sub_02067800(v0->unk_14.unk_0C); + if (BerryPatchGraphics_IsBerryPatch(v2) == 1) { + v2 = BerryPatchGraphics_GetCurrentGraphicsResourceID(v0->unk_14.unk_0C); } if ((v0->unk_08 != v2) || (sub_02062764(v1, v0->unk_00, v0->unk_04) == 0) || (sub_02062F64(v1) == 0)) { @@ -257,8 +257,7 @@ static void ov5_021F1A24(UnkStruct_ov5_021F1A24 *param0, MapObject *param1, VecF fx32 v1, v2; fx32 v3[3] = { (FX32_ONE * 12), - (FX32_ONE * 16), - (FX32_ONE * 12) + FX32_ONE * 16, (FX32_ONE * 12) }; sub_02063078(param1, param2); @@ -339,9 +338,9 @@ static void ov5_021F1B4C(UnkStruct_ov5_021F1AD8 *param0, VecFx32 *param1) VecFx32 v1; fx32 v2; fx32 v3[3] = { - (FX32_ONE * 12), - (FX32_ONE * 16), - (FX32_ONE * 12) + FX32_ONE * 12, + FX32_ONE * 16, + FX32_ONE * 12, }; *param1 = param0->unk_50; diff --git a/src/overlay005/ov5_021F204C.c b/src/overlay005/ov5_021F204C.c index 603a12b4a8..4e2c920328 100644 --- a/src/overlay005/ov5_021F204C.c +++ b/src/overlay005/ov5_021F204C.c @@ -15,9 +15,9 @@ #include "overlay101/struct_ov101_021D5D90_decl.h" #include "overlay101/struct_ov101_021D86B0.h" +#include "berry_patch_manager.h" #include "map_object.h" #include "unk_02020AEC.h" -#include "unk_02055C50.h" #include "unk_020711EC.h" #include "unk_02073838.h" @@ -77,7 +77,7 @@ const UnkStruct_020217F4 Unk_ov5_0220044C[]; void *ov5_021F204C(UnkStruct_ov5_021DF47C *param0) { - UnkStruct_ov5_021F2078 *v0 = ov5_021DF53C(param0, (sizeof(UnkStruct_ov5_021F2078)), 0, 0); + UnkStruct_ov5_021F2078 *v0 = ov5_021DF53C(param0, sizeof(UnkStruct_ov5_021F2078), 0, 0); v0->unk_00 = param0; ov5_021F2078(v0); @@ -155,45 +155,45 @@ static void ov5_021F2144(UnkStruct_ov101_021D5D90 *param0, void *param1) return; } -static void ov5_021F2148(UnkStruct_ov101_021D5D90 *param0, void *param1) +static void BerryPatchGraphicsEffect_Update(UnkStruct_ov101_021D5D90 *effectTask, void *effectData) { - UnkStruct_ov5_021F2118 *v0 = param1; - MapObject *v1 = v0->unk_10.unk_08; + UnkStruct_ov5_021F2118 *berryPatchEffect = effectData; + MapObject *mapObject = berryPatchEffect->unk_10.unk_08; - if (sub_02062764(v1, v0->unk_00, v0->unk_04) == 0) { - ov5_021DF74C(param0); + if (sub_02062764(mapObject, berryPatchEffect->unk_00, berryPatchEffect->unk_04) == 0) { + ov5_021DF74C(effectTask); return; } - v0->unk_08 = 0; + berryPatchEffect->unk_08 = 0; - if ((MapObject_CheckStatusFlag(v1, MAP_OBJ_STATUS_HIDE) == 1) || (!sub_02055F00(MapObject_FieldSystem(v1), v1))) { - v0->unk_08 = 1; + if ((MapObject_CheckStatusFlag(mapObject, MAP_OBJ_STATUS_HIDE) == 1) || (!BerryPatches_GetGrowthStage(MapObject_FieldSystem(mapObject), mapObject))) { + berryPatchEffect->unk_08 = 1; return; } { - v0->unk_0C = sub_02055F88(MapObject_FieldSystem(v1), v1); + berryPatchEffect->unk_0C = BerryPatches_GetMoisture(MapObject_FieldSystem(mapObject), mapObject); } { - VecFx32 v2; + VecFx32 mapObjectPosition; - MapObject_GetPosPtr(v1, &v2); - sub_020715D4(param0, &v2); + MapObject_GetPosPtr(mapObject, &mapObjectPosition); + sub_020715D4(effectTask, &mapObjectPosition); } } -static void ov5_021F21B8(UnkStruct_ov101_021D5D90 *param0, void *param1) +static void BerryPatchGraphicsEffect_Render(UnkStruct_ov101_021D5D90 *effectTask, void *effectData) { - UnkStruct_ov5_021F2118 *v0 = param1; + UnkStruct_ov5_021F2118 *berryPatchEffect = effectData; - if (v0->unk_08 != 1) { - VecFx32 v1; + if (berryPatchEffect->unk_08 != 1) { + VecFx32 effectPosition; - sub_020715E4(param0, &v1); - v1.z += (FX32_ONE * 0); - sub_02073BB4(&v0->unk_10.unk_04->unk_04[v0->unk_0C], &v1); + sub_020715E4(effectTask, &effectPosition); + effectPosition.z += (FX32_ONE * 0); + sub_02073BB4(&berryPatchEffect->unk_10.unk_04->unk_04[berryPatchEffect->unk_0C], &effectPosition); } } @@ -201,13 +201,13 @@ static const UnkStruct_ov101_021D86B0 Unk_ov5_02200438 = { sizeof(UnkStruct_ov5_021F2118), ov5_021F2118, ov5_021F2144, - ov5_021F2148, - ov5_021F21B8 + BerryPatchGraphicsEffect_Update, + BerryPatchGraphicsEffect_Render }; void *ov5_021F21E0(UnkStruct_ov5_021DF47C *param0) { - UnkStruct_ov5_021F2204 *v0 = ov5_021DF53C(param0, (sizeof(UnkStruct_ov5_021F2204)), 0, 0); + UnkStruct_ov5_021F2204 *v0 = ov5_021DF53C(param0, sizeof(UnkStruct_ov5_021F2204), 0, 0); v0->unk_08 = param0; return v0; diff --git a/src/overlay005/ov5_021F2D20.c b/src/overlay005/ov5_021F2D20.c index a8863ec0df..cc61557eda 100644 --- a/src/overlay005/ov5_021F2D20.c +++ b/src/overlay005/ov5_021F2D20.c @@ -181,7 +181,7 @@ static int ov5_021F2F0C(UnkStruct_ov101_021D5D90 *param0, void *param1) v4 = sub_020715BC(param0); v3->unk_18 = *v4; - v3->unk_04 = sub_02062924(v3->unk_18.unk_18); + v3->unk_04 = MapObject_GetEffectiveGraphicsID(v3->unk_18.unk_18); v3->unk_08 = MapObject_GetLocalID(v3->unk_18.unk_18); v3->unk_0C = sub_02062918(v3->unk_18.unk_18); diff --git a/src/overlay005/ov5_021F3284.c b/src/overlay005/ov5_021F3284.c index cfff9be5f5..08cab5f618 100644 --- a/src/overlay005/ov5_021F3284.c +++ b/src/overlay005/ov5_021F3284.c @@ -108,7 +108,7 @@ static int ov5_021F336C(UnkStruct_ov101_021D5D90 *param0, void *param1) v2 = sub_020715BC(param0); v1->unk_14 = *v2; - v1->unk_04 = sub_02062924(v1->unk_14.unk_0C); + v1->unk_04 = MapObject_GetEffectiveGraphicsID(v1->unk_14.unk_0C); v1->unk_08 = MapObject_GetLocalID(v1->unk_14.unk_0C); v1->unk_0C = sub_02062918(v1->unk_14.unk_0C); diff --git a/src/overlay005/ov5_021F37A8.c b/src/overlay005/ov5_021F37A8.c index be80c33fb9..60a026af47 100644 --- a/src/overlay005/ov5_021F37A8.c +++ b/src/overlay005/ov5_021F37A8.c @@ -117,7 +117,7 @@ static int ov5_021F38AC(UnkStruct_ov101_021D5D90 *param0, void *param1) v4 = sub_020715BC(param0); v3->unk_18 = *v4; - v3->unk_04 = sub_02062924(v3->unk_18.unk_18); + v3->unk_04 = MapObject_GetEffectiveGraphicsID(v3->unk_18.unk_18); v3->unk_08 = MapObject_GetLocalID(v3->unk_18.unk_18); v3->unk_0C = sub_02062918(v3->unk_18.unk_18); diff --git a/src/overlay005/ov5_021F3A50.c b/src/overlay005/ov5_021F3A50.c index 1c89bab949..930b0461bf 100644 --- a/src/overlay005/ov5_021F3A50.c +++ b/src/overlay005/ov5_021F3A50.c @@ -117,7 +117,7 @@ static int ov5_021F3B54(UnkStruct_ov101_021D5D90 *param0, void *param1) v4 = sub_020715BC(param0); v3->unk_18 = *v4; - v3->unk_04 = sub_02062924(v3->unk_18.unk_18); + v3->unk_04 = MapObject_GetEffectiveGraphicsID(v3->unk_18.unk_18); v3->unk_08 = MapObject_GetLocalID(v3->unk_18.unk_18); v3->unk_0C = sub_02062918(v3->unk_18.unk_18); diff --git a/src/overlay005/ov5_021F6454.c b/src/overlay005/ov5_021F6454.c index 37a305300c..4e6610c447 100644 --- a/src/overlay005/ov5_021F6454.c +++ b/src/overlay005/ov5_021F6454.c @@ -19,6 +19,7 @@ #include "overlay005/struct_ov5_021F6704_decl.h" #include "bag.h" +#include "berry_patch_graphics.h" #include "bg_window.h" #include "field_script_context.h" #include "font.h" @@ -52,7 +53,6 @@ #include "unk_02030880.h" #include "unk_02038F8C.h" #include "unk_0205DFC4.h" -#include "unk_020677F4.h" #include "vars_flags.h" #include "res/text/bank/battle_tower.h" @@ -240,7 +240,7 @@ static void ov5_021F6624(FieldSystem *fieldSystem, UnkStruct_ov5_021F6704 *param } for (v0 = 0; v0 < 120; v0++) { - param1->unk_1C[v0] = Strbuf_Init((40 * 2), HEAP_ID_FIELD1); + param1->unk_1C[v0] = Strbuf_Init(40 * 2, HEAP_ID_FIELD1); } *param1->unk_210 = 0xeeee; @@ -294,7 +294,7 @@ static void ov5_021F6830(UnkStruct_ov5_021F6704 *param0, u32 param1, u32 param2, void *v1; { - Strbuf *v2 = Strbuf_Init((40 * 2), HEAP_ID_FIELD1); + Strbuf *v2 = Strbuf_Init(40 * 2, HEAP_ID_FIELD1); MessageLoader_GetStrbuf(param0->unk_1FC, param1, v2); StringTemplate_Format(param0->unk_200, param0->unk_1C[param0->unk_20B], v2); @@ -855,7 +855,7 @@ BOOL ScrCmd_30F(ScriptContext *param0) } break; case 17: - if (GameRecords_GetRecordValue(v1, RECORD_UNK_004) < 50) { + if (GameRecords_GetRecordValue(v1, RECORD_BERRIES_PLANTED) < 50) { *v4 = 0; } break; @@ -982,15 +982,15 @@ BOOL ScrCmd_32D(ScriptContext *ctx) MapObject_GetPosPtr(v7, &v1); v1.y = v0; MapObject_SetPos(v7, &v1); - MapObject_SetY(v7, (((v0) >> 3) / FX32_ONE)); + MapObject_SetY(v7, ((v0) >> 3) / FX32_ONE ); } v2 = ov5_021EB1A0(v7); - if ((v2 == NULL) && sub_020677F4(MapObject_GetGraphicsID(v7))) { + if ((v2 == NULL) && BerryPatchGraphics_IsBerryPatch(MapObject_GetGraphicsID(v7))) { if (sub_02062D4C(v7)) { sub_02062B68(v7); - v2 = sub_02067A58(v7); + v2 = BerryPatchGraphics_GetGraphicsObject(v7); } } @@ -1032,7 +1032,7 @@ static void ov5_021F7654(MapObject *param0, int param1) v0.y = (((param1) << 4) * FX32_ONE); MapObject_SetPos(param0, &v0); - MapObject_SetY(param0, ((param1) * 2)); + MapObject_SetY(param0, (param1) * 2); v1 = ov5_021EB1A0(param0); diff --git a/src/overlay005/ov5_021FAF40.c b/src/overlay005/ov5_021FAF40.c index 983ebde28d..081a03d4be 100644 --- a/src/overlay005/ov5_021FAF40.c +++ b/src/overlay005/ov5_021FAF40.c @@ -3,6 +3,8 @@ #include "struct_defs/struct_020217F4.h" +#include "overlay005/berry_graphics_data.h" +#include "overlay005/berry_graphics_table.h" #include "overlay005/const_ov5_021FAF40.h" #include "overlay005/const_ov5_021FAF48.h" #include "overlay005/const_ov5_021FAF50.h" @@ -10,7 +12,6 @@ #include "overlay005/const_ov5_021FB484.h" #include "overlay005/const_ov5_021FB51C.h" #include "overlay005/const_ov5_021FB5BC.h" -#include "overlay005/const_ov5_021FB67C.h" #include "overlay005/const_ov5_021FB97C.h" #include "overlay005/const_ov5_021FC194.h" #include "overlay005/const_ov5_021FC9B4.h" @@ -23,10 +24,9 @@ #include "overlay005/struct_ov5_021ED2D0.h" #include "overlay005/struct_ov5_021EDD04.h" #include "overlay005/struct_ov5_021FB0F0.h" -#include "overlay005/struct_ov5_021FB67C.h" #include "overlay005/struct_ov5_021FB97C.h" -#include "unk_020677F4.h" +#include "berry_patch_graphics.h" static const UnkStruct_ov5_021FB0F0 Unk_ov5_021FB0F0 = { ov5_021EBA0C, @@ -140,12 +140,12 @@ static const UnkStruct_ov5_021FB0F0 Unk_ov5_021FB000 = { ov5_021EC790 }; -static const UnkStruct_ov5_021FB0F0 Unk_ov5_021FAF74 = { - sub_02067870, - sub_02067890, - sub_02067950, - sub_02067968, - sub_02067998 +static const UnkStruct_ov5_021FB0F0 BerryPatchRenderer = { + BerryPatchGraphics_NewGraphics, + BerryPatchGraphics_UpdateGraphics, + BerryPatchGraphics_FreeGraphics, + BerryPatchGraphics_PauseGraphics, + BerryPatchGraphics_ResumeGraphics }; static const UnkStruct_ov5_021FB0F0 Unk_ov5_021FB078 = { @@ -313,7 +313,7 @@ const UnkStruct_ov5_021FB97C Unk_ov5_021FB97C[] = { { 0x61, &Unk_ov5_021FB0F0 }, { 0x62, &Unk_ov5_021FAF88 }, { 0x63, &Unk_ov5_021FAFD8 }, - { 0x64, &Unk_ov5_021FAF74 }, + { 0x64, &BerryPatchRenderer }, { 0x76, &Unk_ov5_021FB050 }, { 0x78, &Unk_ov5_021FAFD8 }, { 0x79, &Unk_ov5_021FAFD8 }, @@ -1845,7 +1845,7 @@ const UnkStruct_ov5_021ECD10 Unk_ov5_021FC194[] = { { 0xffff, 0x0, 0x0, 0x0, 0x0, 0x0 } }; -const UnkStruct_ov5_021FB67C Unk_ov5_021FB67C[] = { +const BerryGraphicsData gBerryGraphicsTable[] = { { 0x1001, 0x1002, 0x1003 }, { 0x1004, 0x1005, 0x1006 }, { 0x1007, 0x1008, 0x1009 }, @@ -1861,7 +1861,7 @@ const UnkStruct_ov5_021FB67C Unk_ov5_021FB67C[] = { { 0x1025, 0x1026, 0x1027 }, { 0x1028, 0x1029, 0x102A }, { 0x102B, 0x102C, 0x102D }, - { 0x102E, (0x1000 + 0x2f), 0x1030 }, + { 0x102E, 0x1000 + 0x2f, 0x1030 }, { 0x1031, 0x1032, 0x1033 }, { 0x1034, 0x1035, 0x1036 }, { 0x1037, 0x1038, 0x1039 }, @@ -1877,7 +1877,7 @@ const UnkStruct_ov5_021FB67C Unk_ov5_021FB67C[] = { { 0x1055, 0x1056, 0x1057 }, { 0x1058, 0x1059, 0x105A }, { 0x105B, 0x105C, 0x105D }, - { 0x105E, (0x1000 + 0x5f), 0x1060 }, + { 0x105E, 0x1000 + 0x5f, 0x1060 }, { 0x1061, 0x1062, 0x1063 }, { 0x1064, 0x1065, 0x1066 }, { 0x1067, 0x1068, 0x1069 }, @@ -1893,7 +1893,7 @@ const UnkStruct_ov5_021FB67C Unk_ov5_021FB67C[] = { { 0x1085, 0x1086, 0x1087 }, { 0x1088, 0x1089, 0x108A }, { 0x108B, 0x108C, 0x108D }, - { 0x108E, (0x1000 + 0x8f), 0x1090 }, + { 0x108E, 0x1000 + 0x8f, 0x1090 }, { 0x1091, 0x1092, 0x1093 }, { 0x1094, 0x1095, 0x1096 }, { 0x1097, 0x1098, 0x1099 }, @@ -1909,7 +1909,7 @@ const UnkStruct_ov5_021FB67C Unk_ov5_021FB67C[] = { { 0x10B5, 0x10B6, 0x10B7 }, { 0x10B8, 0x10B9, 0x10BA }, { 0x10BB, 0x10BC, 0x10BD }, - { 0x10BE, (0x1000 + 0xbf), 0x10C0 } + { 0x10BE, 0x1000 + 0xbf, 0x10C0 } }; const UnkStruct_ov5_021EC700 Unk_ov5_021FB51C[] = { @@ -1918,7 +1918,7 @@ const UnkStruct_ov5_021EC700 Unk_ov5_021FB51C[] = { { 0x0, 0x0, - ((FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2)), + (FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2), }, }, { @@ -1926,7 +1926,7 @@ const UnkStruct_ov5_021EC700 Unk_ov5_021FB51C[] = { { 0x0, 0x0, - ((FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2)), + (FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2), }, }, { @@ -1934,7 +1934,7 @@ const UnkStruct_ov5_021EC700 Unk_ov5_021FB51C[] = { { 0x0, 0x0, - ((FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2)), + (FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2), }, }, { @@ -1942,7 +1942,7 @@ const UnkStruct_ov5_021EC700 Unk_ov5_021FB51C[] = { { 0x0, 0x0, - ((FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2)), + (FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2), }, }, { @@ -1950,7 +1950,7 @@ const UnkStruct_ov5_021EC700 Unk_ov5_021FB51C[] = { { 0x0, 0x0, - ((FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2)), + (FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2), }, }, { @@ -1958,7 +1958,7 @@ const UnkStruct_ov5_021EC700 Unk_ov5_021FB51C[] = { { 0x0, 0x0, - ((FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2)), + (FX32_ONE * 6) - (FX32_ONE * 6) - (FX32_ONE * 2), }, }, { @@ -1966,7 +1966,7 @@ const UnkStruct_ov5_021EC700 Unk_ov5_021FB51C[] = { { 0x0, 0x0, - ((FX32_ONE * 6) - (FX32_ONE * 6)), + (FX32_ONE * 6) - (FX32_ONE * 6), }, }, { @@ -1974,7 +1974,7 @@ const UnkStruct_ov5_021EC700 Unk_ov5_021FB51C[] = { { 0x0, 0x0, - ((FX32_ONE * 6) - (FX32_ONE * 6)), + (FX32_ONE * 6) - (FX32_ONE * 6), }, }, { @@ -1982,7 +1982,7 @@ const UnkStruct_ov5_021EC700 Unk_ov5_021FB51C[] = { { 0x0, 0x0, - ((FX32_ONE * 6) - (FX32_ONE * 6)), + (FX32_ONE * 6) - (FX32_ONE * 6), }, }, { diff --git a/src/scrcmd.c b/src/scrcmd.c index 91af9e547e..1f2b0c9653 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -144,6 +144,7 @@ #include "save_player.h" #include "savedata.h" #include "scrcmd_amity_square.h" +#include "scrcmd_berry.h" #include "scrcmd_catching_show.h" #include "scrcmd_coins.h" #include "scrcmd_daycare.h" @@ -192,7 +193,6 @@ #include "unk_02048DD8.h" #include "unk_020494DC.h" #include "unk_0204AEE8.h" -#include "unk_0204B64C.h" #include "unk_0204E240.h" #include "unk_0204EDA4.h" #include "unk_0204F04C.h" @@ -1150,15 +1150,15 @@ const ScrCmdFunc Unk_020EAC58[] = { ScrCmd_17A, ScrCmd_BufferBerryName, ScrCmd_BufferNatureName, - ScrCmd_17D, - ScrCmd_17E, - ScrCmd_17F, - ScrCmd_180, - ScrCmd_181, - ScrCmd_182, - ScrCmd_183, - ScrCmd_184, - ScrCmd_185, + ScrCmd_GetBerryGrowthStage, + ScrCmd_GetBerryItemID, + ScrCmd_GetBerryMulchType, + ScrCmd_GetBerryMoisture, + ScrCmd_GetBerryYield, + ScrCmd_SetBerryMulch, + ScrCmd_PlantBerry, + ScrCmd_SetBerryWateringState, + ScrCmd_HarvestBerry, ScrCmd_SetObjectEventPos, ScrCmd_SetPosition, ScrCmd_SetObjectEventMovementType, diff --git a/src/scrcmd_berry.c b/src/scrcmd_berry.c new file mode 100644 index 0000000000..430d3bd478 --- /dev/null +++ b/src/scrcmd_berry.c @@ -0,0 +1,111 @@ +#include "scrcmd_berry.h" + +#include +#include + +#include "constants/scrcmd.h" +#include "generated/game_records.h" +#include "generated/trainer_score_events.h" + +#include "struct_decls/struct_02061AB4_decl.h" + +#include "berry_patch_manager.h" +#include "field_script_context.h" +#include "game_records.h" +#include "inlines.h" +#include "script_manager.h" + +BOOL ScrCmd_GetBerryGrowthStage(ScriptContext *ctx) +{ + MapObject **targetObject; + u16 *varPointer = ScriptContext_GetVarPointer(ctx); + + targetObject = FieldSystem_GetScriptMemberPtr(ctx->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); + *varPointer = BerryPatches_GetGrowthStage(ctx->fieldSystem, *targetObject); + + return FALSE; +} + +BOOL ScrCmd_GetBerryItemID(ScriptContext *ctx) +{ + MapObject **targetObject = FieldSystem_GetScriptMemberPtr(ctx->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); + u16 *varPointer = ScriptContext_GetVarPointer(ctx); + + *varPointer = BerryPatches_GetItemID(ctx->fieldSystem, *targetObject); + return FALSE; +} + +BOOL ScrCmd_GetBerryMulchType(ScriptContext *ctx) +{ + MapObject **targetObject = FieldSystem_GetScriptMemberPtr(ctx->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); + u16 *varPointer = ScriptContext_GetVarPointer(ctx); + + *varPointer = BerryPatches_GetMulchItemID(ctx->fieldSystem, *targetObject); + return FALSE; +} + +BOOL ScrCmd_GetBerryMoisture(ScriptContext *ctx) +{ + MapObject **targetObject = FieldSystem_GetScriptMemberPtr(ctx->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); + u16 *varPointer = ScriptContext_GetVarPointer(ctx); + + *varPointer = BerryPatches_GetMoisture(ctx->fieldSystem, *targetObject); + return FALSE; +} + +BOOL ScrCmd_GetBerryYield(ScriptContext *ctx) +{ + MapObject **targetObject = FieldSystem_GetScriptMemberPtr(ctx->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); + u16 *varPointer = ScriptContext_GetVarPointer(ctx); + + *varPointer = BerryPatches_GetYield(ctx->fieldSystem, *targetObject); + return FALSE; +} + +BOOL ScrCmd_SetBerryMulch(ScriptContext *ctx) +{ + MapObject **targetObject = FieldSystem_GetScriptMemberPtr(ctx->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); + u16 mulchItemID = ScriptContext_GetVar(ctx); + + BerryPatches_SetMulchType(ctx->fieldSystem, *targetObject, mulchItemID); + return FALSE; +} + +BOOL ScrCmd_PlantBerry(ScriptContext *ctx) +{ + MapObject **targetObject = FieldSystem_GetScriptMemberPtr(ctx->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); + GameRecords *gameRecords = SaveData_GetGameRecords(ctx->fieldSystem->saveData); + u16 berryItemID = ScriptContext_GetVar(ctx); + + BerryPatches_PlantBerry(ctx->fieldSystem, *targetObject, berryItemID); + GameRecords_IncrementRecordValue(gameRecords, RECORD_BERRIES_PLANTED); + + return FALSE; +} + +BOOL ScrCmd_SetBerryWateringState(ScriptContext *ctx) +{ + switch (ScriptContext_ReadHalfWord(ctx)) { + case BERRY_WATERING_START: + BerryPatches_StartWatering(ctx->fieldSystem); + break; + case BERRY_WATERING_END: + BerryPatches_EndWatering(ctx->fieldSystem); + break; + default: + GF_ASSERT(FALSE); + } + + return TRUE; +} + +BOOL ScrCmd_HarvestBerry(ScriptContext *ctx) +{ + GameRecords *gameRecords = SaveData_GetGameRecords(ctx->fieldSystem->saveData); + MapObject **targetObject = FieldSystem_GetScriptMemberPtr(ctx->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); + + BerryPatches_HarvestBerry(ctx->fieldSystem, *targetObject); + GameRecords_IncrementTrainerScore(gameRecords, TRAINER_SCORE_EVENT_BERRY_HARVESTED); + + return FALSE; +} diff --git a/src/unk_0204B64C.c b/src/unk_0204B64C.c deleted file mode 100644 index 603a5eef29..0000000000 --- a/src/unk_0204B64C.c +++ /dev/null @@ -1,111 +0,0 @@ -#include "unk_0204B64C.h" - -#include -#include - -#include "generated/game_records.h" -#include "generated/trainer_score_events.h" - -#include "struct_decls/struct_02061AB4_decl.h" - -#include "field_script_context.h" -#include "game_records.h" -#include "inlines.h" -#include "script_manager.h" -#include "unk_02055C50.h" - -BOOL ScrCmd_17D(ScriptContext *param0) -{ - MapObject **v0; - u16 *v1 = ScriptContext_GetVarPointer(param0); - - v0 = FieldSystem_GetScriptMemberPtr(param0->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); - *v1 = sub_02055F00(param0->fieldSystem, *v0); - - return 0; -} - -BOOL ScrCmd_17E(ScriptContext *param0) -{ - MapObject **v0 = FieldSystem_GetScriptMemberPtr(param0->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); - u16 *v1 = ScriptContext_GetVarPointer(param0); - - *v1 = sub_02055F40(param0->fieldSystem, *v0); - return 0; -} - -BOOL ScrCmd_17F(ScriptContext *param0) -{ - MapObject **v0 = FieldSystem_GetScriptMemberPtr(param0->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); - u16 *v1 = ScriptContext_GetVarPointer(param0); - - *v1 = sub_02055F64(param0->fieldSystem, *v0); - return 0; -} - -BOOL ScrCmd_180(ScriptContext *param0) -{ - MapObject **v0 = FieldSystem_GetScriptMemberPtr(param0->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); - u16 *v1 = ScriptContext_GetVarPointer(param0); - - *v1 = sub_02055F88(param0->fieldSystem, *v0); - return 0; -} - -BOOL ScrCmd_181(ScriptContext *param0) -{ - MapObject **v0 = FieldSystem_GetScriptMemberPtr(param0->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); - u16 *v1 = ScriptContext_GetVarPointer(param0); - - *v1 = sub_02055FA8(param0->fieldSystem, *v0); - return 0; -} - -BOOL ScrCmd_182(ScriptContext *param0) -{ - MapObject **v0 = FieldSystem_GetScriptMemberPtr(param0->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); - u16 v1 = ScriptContext_GetVar(param0); - - sub_02055E80(param0->fieldSystem, *v0, v1); - return 0; -} - -BOOL ScrCmd_183(ScriptContext *param0) -{ - MapObject **v0 = FieldSystem_GetScriptMemberPtr(param0->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); - GameRecords *v1 = SaveData_GetGameRecords(param0->fieldSystem->saveData); - u16 v2 = ScriptContext_GetVar(param0); - - sub_02055EAC(param0->fieldSystem, *v0, v2); - GameRecords_IncrementRecordValue(v1, RECORD_UNK_004); - - return 0; -} - -BOOL ScrCmd_184(ScriptContext *param0) -{ - switch (ScriptContext_ReadHalfWord(param0)) { - case 0: - sub_020562AC(param0->fieldSystem); - break; - case 1: - sub_020562D8(param0->fieldSystem); - break; - default: - GF_ASSERT(0); - } - - return 1; -} - -BOOL ScrCmd_185(ScriptContext *param0) -{ - u16 v0; - GameRecords *v1 = SaveData_GetGameRecords(param0->fieldSystem->saveData); - MapObject **v2 = FieldSystem_GetScriptMemberPtr(param0->fieldSystem, SCRIPT_MANAGER_TARGET_OBJECT); - - sub_02055E00(param0->fieldSystem, *v2); - GameRecords_IncrementTrainerScore(v1, TRAINER_SCORE_EVENT_UNK_00); - - return 0; -} diff --git a/src/unk_020559DC.c b/src/unk_020559DC.c index 7da59825b4..b74f6af5d0 100644 --- a/src/unk_020559DC.c +++ b/src/unk_020559DC.c @@ -8,6 +8,7 @@ #include "field/field_system.h" #include "savedata/save_table.h" +#include "berry_patch_manager.h" #include "field_system.h" #include "inlines.h" #include "party.h" @@ -22,7 +23,6 @@ #include "unk_0202854C.h" #include "unk_0202C858.h" #include "unk_0202E2CC.h" -#include "unk_02055C50.h" #include "unk_0206B9D8.h" #include "unk_0206CCB0.h" #include "vars_flags.h" @@ -129,7 +129,7 @@ static void sub_02055AC0(FieldSystem *fieldSystem, s32 daysPassed) static void sub_02055B64(FieldSystem *fieldSystem, s32 param1, const RTCTime *rtcTime) { - sub_02055CD4(fieldSystem, param1); + BerryPatches_ElapseTime(fieldSystem, param1); SpecialEncounter_DecrementHoneyTreeTimers(fieldSystem->saveData, param1); sub_02028758(fieldSystem->saveData, param1, FieldSystem_HasPenalty(fieldSystem)); diff --git a/src/unk_02055C50.c b/src/unk_02055C50.c deleted file mode 100644 index f0eff3b316..0000000000 --- a/src/unk_02055C50.c +++ /dev/null @@ -1,472 +0,0 @@ -#include "unk_02055C50.h" - -#include -#include - -#include "struct_decls/struct_02055CBC_decl.h" -#include "struct_decls/struct_02061AB4_decl.h" - -#include "field/field_system.h" -#include "field/field_system_sub2_t.h" -#include "overlay005/map_object_anim_cmd.h" -#include "overlay005/ov5_021DF440.h" -#include "overlay005/ov5_021DFB54.h" -#include "overlay005/struct_ov5_021DF47C_decl.h" - -#include "bag.h" -#include "berry_patches.h" -#include "easy3d.h" -#include "field_task.h" -#include "gfx_box_test.h" -#include "heap.h" -#include "map_object.h" -#include "player_avatar.h" -#include "savedata_misc.h" -#include "sys_task_manager.h" -#include "system.h" -#include "terrain_collision_manager.h" -#include "unk_020655F4.h" -#include "unk_020677F4.h" -#include "unk_0206CCB0.h" - -struct UnkStruct_02055CBC_t { - int heapID; - BerryGrowthData *unk_04; - NNSG3dRenderObj unk_08; - NNSG3dResMdl *unk_5C; - NNSG3dResFileHeader *unk_60; -}; - -typedef struct { - int unk_00; - int unk_04; - int unk_08; - SysTask *unk_0C; -} UnkStruct_020562AC; - -static void sub_02055D14(FieldSystem *fieldSystem, UnkStruct_02055CBC *param1); -static void sub_02055D48(UnkStruct_02055CBC *param0); - -static u16 sub_02055C50(int param0) -{ - if (param0 == 0) { - return 0; - } - - return param0 + 149 - 1; -} - -static u16 sub_02055C60(int param0) -{ - if (param0 == 0) { - return 0; - } - - return param0 - 149 + 1; -} - -static u16 sub_02055C70(int param0) -{ - if (param0 == 0) { - return 0; - } - - return param0 + 95 - 1; -} - -static int sub_02055C80(int param0) -{ - if (param0 == 0) { - return 0; - } - - return param0 - 95 + 1; -} - -UnkStruct_02055CBC *sub_02055C8C(FieldSystem *fieldSystem, int heapID) -{ - UnkStruct_02055CBC *v0 = Heap_Alloc(heapID, sizeof(UnkStruct_02055CBC)); - MI_CpuClear8(v0, sizeof(UnkStruct_02055CBC)); - - v0->heapID = heapID; - v0->unk_04 = BerryGrowthData_Init(heapID); - - sub_02055D14(fieldSystem, v0); - return v0; -} - -void sub_02055CBC(UnkStruct_02055CBC *param0) -{ - sub_02055D48(param0); - Heap_Free(param0->unk_04); - Heap_Free(param0); -} - -void sub_02055CD4(FieldSystem *fieldSystem, int param1) -{ - BerryPatch *v0; - BerryGrowthData *v1; - - if (fieldSystem->unk_04 == NULL) { - v1 = BerryGrowthData_Init(11); - v0 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - BerryPatches_ElapseMinutes(v0, v1, param1); - Heap_Free(v1); - } else { - v1 = fieldSystem->unk_04->unk_18->unk_04; - v0 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - BerryPatches_ElapseMinutes(v0, v1, param1); - } -} - -static void sub_02055D14(FieldSystem *fieldSystem, UnkStruct_02055CBC *param1) -{ - UnkStruct_ov5_021DF47C *v0 = fieldSystem->unk_40; - u32 v1 = ov5_021DF5A8(v0, 17); - - param1->unk_60 = Heap_Alloc(param1->heapID, v1); - - ov5_021DF5B4(v0, 17, param1->unk_60); - Easy3D_InitRenderObjFromResource(¶m1->unk_08, ¶m1->unk_5C, ¶m1->unk_60); -} - -static void sub_02055D48(UnkStruct_02055CBC *param0) -{ - ov5_021DF554(param0->unk_60); -} - -static BOOL sub_02055D54(FieldSystem *fieldSystem, const VecFx32 *param1) -{ - const VecFx32 v0 = { FX32_ONE, FX32_ONE, FX32_ONE }; - MtxFx33 v1; - - MTX_Identity33(&v1); - - if (GFXBoxTest_IsModelInView(fieldSystem->unk_04->unk_18->unk_5C, param1, &v1, &v0) != 0) { - return 1; - } else { - return 0; - } -} - -void sub_02055D94(FieldSystem *fieldSystem) -{ - int v0 = 0; - MapObject *v1; - BerryPatch *v2 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - while (sub_020625B0(fieldSystem->mapObjMan, &v1, &v0, (1 << 0)) == 1) { - if (sub_020677F4(MapObject_GetGraphicsID(v1)) == 1) { - if (sub_02055D54(fieldSystem, MapObject_GetPos(v1))) { - int v3 = MapObject_GetDataAt(v1, 0); - BerryPatches_SetIsPatchGrowing(v2, v3, 1); - } - } - } -} - -BOOL sub_02055E00(FieldSystem *fieldSystem, MapObject *param1) -{ - int v0, v1, v2; - BerryPatch *v3 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - v0 = MapObject_GetDataAt(param1, 0); - v2 = BerryPatches_GetPatchBerryID(v3, v0); - v1 = BerryPatches_GetPatchYield(v3, v0); - - sub_0206D914(fieldSystem, sub_02055C50(v2), BerryPatches_GetPatchYieldRating(v3, v0), v1); - BerryPatches_HarvestPatch(v3, v0); - sub_02067834(param1); - - return Bag_TryAddItem(SaveData_GetBag(fieldSystem->saveData), sub_02055C50(v2), v1, HEAP_ID_FIELD1); -} - -void sub_02055E80(FieldSystem *fieldSystem, MapObject *param1, u16 param2) -{ - int v0; - BerryPatch *v1 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - v0 = MapObject_GetDataAt(param1, 0); - BerryPatches_SetPatchMulchType(v1, v0, sub_02055C80(param2)); -} - -void sub_02055EAC(FieldSystem *fieldSystem, MapObject *param1, u16 param2) -{ - int v0; - BerryPatch *v1 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - v0 = MapObject_GetDataAt(param1, 0); - BerryPatches_PlantInPatch(v1, v0, fieldSystem->unk_04->unk_18->unk_04, sub_02055C60(param2)); -} - -void sub_02055EE0(FieldSystem *fieldSystem, MapObject *param1) -{ - int v0; - BerryPatch *v1 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - v0 = MapObject_GetDataAt(param1, 0); - BerryPatches_ResetPatchMoisture(v1, v0); -} - -int sub_02055F00(const FieldSystem *fieldSystem, const MapObject *param1) -{ - int v0; - BerryPatch *v1 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - v0 = MapObject_GetDataAt(param1, 0); - return BerryPatches_GetPatchGrowthStage(v1, v0); -} - -int sub_02055F20(const FieldSystem *fieldSystem, const MapObject *param1) -{ - int v0; - BerryPatch *v1 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - v0 = MapObject_GetDataAt(param1, 0); - return BerryPatches_GetPatchBerryID(v1, v0); -} - -u16 sub_02055F40(const FieldSystem *fieldSystem, const MapObject *param1) -{ - int v0; - BerryPatch *v1 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - v0 = MapObject_GetDataAt(param1, 0); - return sub_02055C50(BerryPatches_GetPatchBerryID(v1, v0)); -} - -u16 sub_02055F64(const FieldSystem *fieldSystem, const MapObject *param1) -{ - int v0; - BerryPatch *v1 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - v0 = MapObject_GetDataAt(param1, 0); - return sub_02055C70(BerryPatches_GetPatchMulchType(v1, v0)); -} - -int sub_02055F88(const FieldSystem *fieldSystem, const MapObject *param1) -{ - int v0; - BerryPatch *v1 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - v0 = MapObject_GetDataAt(param1, 0); - return BerryPatches_GetPatchMoisture(v1, v0); -} - -int sub_02055FA8(const FieldSystem *fieldSystem, const MapObject *param1) -{ - int v0; - BerryPatch *v1 = MiscSaveBlock_GetBerryPatches(fieldSystem->saveData); - - v0 = MapObject_GetDataAt(param1, 0); - return BerryPatches_GetPatchYield(v1, v0); -} - -u32 sub_02055FC8(const FieldSystem *fieldSystem, const MapObject *param1) -{ - u32 v0 = 0; - - if ((param1 == NULL) || (MapObject_GetGraphicsID(param1) != 0x64)) { - return 0x0; - } - - switch (sub_02055F00(fieldSystem, param1)) { - case 0: - v0 |= 0x1; - - if (sub_02055F64(fieldSystem, param1) == 0) { - v0 |= 0x2; - } - break; - default: - v0 |= 0x4; - break; - } - - return v0; -} - -static const MapObjectAnimCmd Unk_020EC51C[] = { - { 0xA, 0x1 }, - { 0xfe, 0x0 } -}; - -static const MapObjectAnimCmd Unk_020EC524[] = { - { 0xB, 0x1 }, - { 0xfe, 0x0 } -}; - -static BOOL sub_02056010(FieldSystem *fieldSystem, UnkStruct_020562AC *param1, int param2) -{ - int v0 = Player_GetXPos(fieldSystem->playerAvatar); - int v1 = Player_GetZPos(fieldSystem->playerAvatar); - - if (param2 == 2) { - v0--; - } else if (param2 == 3) { - v0++; - } else if (param2 == 0) { - v1--; - } else if (param2 == 1) { - v1++; - } else { - GF_ASSERT(0); - } - - if (TerrainCollisionManager_CheckCollision(fieldSystem, v0, v1)) { - return 1; - } - - return sub_0206326C(fieldSystem->mapObjMan, v0, v1, 0) != NULL; -} - -static MapObject *sub_02056074(FieldSystem *fieldSystem, int param1) -{ - int v0 = Player_GetXPos(fieldSystem->playerAvatar); - int v1 = Player_GetZPos(fieldSystem->playerAvatar); - v1 -= 1; - - if (param1 == 2) { - v0 -= 1; - } else if (param1 == 3) { - v0 += 1; - } - - return sub_0206326C(fieldSystem->mapObjMan, v0, v1, 0); -} - -static MapObject *sub_020560A8(FieldSystem *fieldSystem, UnkStruct_020562AC *param1) -{ - int v0 = Player_GetXPos(fieldSystem->playerAvatar); - int v1 = Player_GetZPos(fieldSystem->playerAvatar); - - if (param1->unk_04 == 0) { - v1 -= 1; - } else if (param1->unk_04 == 1) { - v1 += 1; - } else { - GF_ASSERT(0); - } - - return sub_0206326C(fieldSystem->mapObjMan, v0, v1, 0); -} - -static BOOL sub_020560E4(MapObject *mapObj) -{ - return MapObject_GetGraphicsID(mapObj) == 0x64; -} - -static void sub_020560F8(FieldSystem *fieldSystem, UnkStruct_020562AC *param1) -{ - MapObject *v0 = sub_020560A8(fieldSystem, param1); - - if (v0 != NULL) { - sub_02055EE0(fieldSystem, v0); - } -} - -static void sub_0205610C(FieldSystem *fieldSystem, UnkStruct_020562AC *param1, const MapObjectAnimCmd *param2) -{ - MapObject *v0 = Player_MapObject(fieldSystem->playerAvatar); - param1->unk_0C = MapObject_StartAnimation(v0, param2); -} - -static BOOL sub_02056124(FieldTask *taskMan) -{ - FieldSystem *v0 = FieldTask_GetFieldSystem(taskMan); - UnkStruct_020562AC *v1 = FieldTask_GetEnv(taskMan); - - switch (v1->unk_00) { - case 0: - PlayerAvatar_SetTransitionState(v0->playerAvatar, PLAYER_TRANSITION_WATER_BERRIES); - PlayerAvatar_RequestChangeState(v0->playerAvatar); - MapObject_SetPauseMovementOff(Player_MapObject(v0->playerAvatar)); - v1->unk_00 = 1; - break; - case 1: - sub_020560F8(v0, v1); - v1->unk_08 = 0; - v1->unk_00 = 2; - case 2: - if (gSystem.heldKeys & PAD_KEY_LEFT) { - MapObject *v2 = sub_02056074(v0, 2); - - if ((v2 == NULL) || !sub_020560E4(v2)) { - v1->unk_00 = 4; - break; - } else if (!sub_02056010(v0, v1, 2)) { - sub_0205610C(v0, v1, Unk_020EC51C); - v1->unk_00 = 3; - break; - } - } else if (gSystem.heldKeys & PAD_KEY_RIGHT) { - MapObject *v2 = sub_02056074(v0, 3); - - if ((v2 == NULL) || !sub_020560E4(v2)) { - v1->unk_00 = 4; - break; - } else if (!sub_02056010(v0, v1, 3)) { - sub_0205610C(v0, v1, Unk_020EC524); - v1->unk_00 = 3; - break; - } - } else if ((gSystem.heldKeys & PAD_KEY_UP) && (v1->unk_04 == 1)) { - Player_SetDir(v0->playerAvatar, 0); - v1->unk_00 = 4; - break; - } else if ((gSystem.heldKeys & PAD_KEY_DOWN) && (v1->unk_04 == 0)) { - v1->unk_00 = 4; - break; - } - - v1->unk_08++; - - if (v1->unk_08 > 30 * 3) { - Player_SetDir(v0->playerAvatar, v1->unk_04); - v1->unk_00 = 4; - } - break; - case 3: - if (MapObject_HasAnimationEnded(v1->unk_0C)) { - MapObject *v3; - - MapObject_FinishAnimation(v1->unk_0C); - v3 = sub_020560A8(v0, v1); - - if ((v3 != NULL) && sub_020560E4(v3)) { - v1->unk_00 = 1; - } else { - Player_SetDir(v0->playerAvatar, v1->unk_04); - v1->unk_00 = 4; - } - } - break; - case 4: - Player_SetDir(v0->playerAvatar, v1->unk_04); - MapObject_SetPauseMovementOn(Player_MapObject(v0->playerAvatar)); - Heap_Free(v1); - return 1; - } - - return 0; -} - -void sub_020562AC(FieldSystem *fieldSystem) -{ - UnkStruct_020562AC *v0 = Heap_Alloc(HEAP_ID_FIELD3, sizeof(UnkStruct_020562AC)); - - v0->unk_00 = 0; - v0->unk_0C = NULL; - v0->unk_04 = PlayerAvatar_GetDir(fieldSystem->playerAvatar); - - FieldTask_InitCall(fieldSystem->task, sub_02056124, v0); -} - -void sub_020562D8(FieldSystem *fieldSystem) -{ - int v0 = PlayerAvatar_GetPlayerState(fieldSystem->playerAvatar); - u32 v1 = Player_ConvertStateToTransition(v0); - - PlayerAvatar_SetTransitionState(fieldSystem->playerAvatar, v1); - PlayerAvatar_RequestChangeState(fieldSystem->playerAvatar); -} diff --git a/src/unk_020677F4.c b/src/unk_020677F4.c deleted file mode 100644 index 4f22e519b7..0000000000 --- a/src/unk_020677F4.c +++ /dev/null @@ -1,233 +0,0 @@ -#include "unk_020677F4.h" - -#include -#include - -#include "struct_decls/struct_020216E0_decl.h" -#include "struct_decls/struct_02061AB4_decl.h" - -#include "overlay005/const_ov5_021FB67C.h" -#include "overlay005/ov5_021ECC20.h" -#include "overlay005/ov5_021ECE40.h" -#include "overlay005/ov5_021F204C.h" -#include "overlay005/struct_ov5_021ED01C.h" -#include "overlay005/struct_ov5_021FB67C.h" - -#include "map_header_data.h" -#include "map_object.h" -#include "unk_02020AEC.h" -#include "unk_02055C50.h" - -typedef struct { - u16 unk_00; - u16 unk_02; -} UnkStruct_02067800; - -typedef struct { - int unk_00; - int unk_04; - UnkStruct_020216E0 *unk_08; - UnkStruct_ov5_021ED01C unk_0C; -} UnkStruct_02067870; - -static int sub_020679FC(int param0, int param1); - -int sub_020677F4(int param0) -{ - if (param0 == 0x64) { - return 1; - } - - return 0; -} - -int sub_02067800(const MapObject *param0) -{ - { - UnkStruct_02067800 *v0 = sub_02062A78((MapObject *)param0); - - if (v0->unk_00 == 0) { - return 0xffff; - } - } - - if (sub_02062DFC(param0) == 1) { - UnkStruct_02067870 *v1 = sub_02062AF0((MapObject *)param0); - - if (v1->unk_04 != 0) { - return v1->unk_00; - } - } - - return 0xffff; -} - -void sub_02067834(MapObject *param0) -{ - UnkStruct_02067800 *v0 = sub_02062A78(param0); - v0->unk_02 = 1; -} - -void sub_02067840(MapObject *param0) -{ - UnkStruct_02067800 *v0 = sub_02062A54(param0, (sizeof(UnkStruct_02067800))); - v0->unk_00 = 0; -} - -void sub_02067850(MapObject *param0) -{ - UnkStruct_02067800 *v0 = sub_02062A78(param0); - v0->unk_00 = sub_02055F00(MapObject_FieldSystem(param0), param0); -} - -void sub_0206786C(MapObject *param0) -{ - return; -} - -void sub_02067870(MapObject *param0) -{ - UnkStruct_02067870 *v0 = sub_02062ACC(param0, (sizeof(UnkStruct_02067870))); - - v0->unk_00 = 0xffff; - v0->unk_04 = 0; - - ov5_021F20D4(param0); -} - -void sub_02067890(MapObject *param0) -{ - UnkStruct_02067800 *v0 = sub_02062A78(param0); - UnkStruct_02067870 *v1 = sub_02062AF0(param0); - u32 v2 = sub_02055F00(MapObject_FieldSystem(param0), param0); - - if (ov5_021EDD94(param0) == 1) { - return; - } - - if (v2 != v1->unk_04) { - ov5_021ECFD8(param0, &v1->unk_08, v1->unk_00); - - v1->unk_00 = sub_020679FC( - sub_02055F20(MapObject_FieldSystem(param0), param0), v2); - - if (v1->unk_00 != 0xffff) { - if (v1->unk_04 != 0) { - ov5_021F22BC(param0); - } - - ov5_021ECEB4(param0, &v1->unk_08, v1->unk_00); - } else { - if ((v1->unk_04 != 0) && (v0->unk_02 == 0)) { - ov5_021F22BC(param0); - } - } - - v0->unk_02 = 0; - } - - v1->unk_04 = v2; - - if (ov5_021EDD94(param0) == 1) { - return; - } - - if (v1->unk_08 != NULL) { - ov5_021EDEB4(param0, v1->unk_08); - - if (ov5_021ECD38(param0) == 0) { - sub_02021368(v1->unk_08, (FX32_ONE)); - } - - ov5_021EDED8(param0, v1->unk_08); - } -} - -void sub_02067950(MapObject *param0) -{ - UnkStruct_02067870 *v0 = sub_02062AF0(param0); - ov5_021ECFD8(param0, &v0->unk_08, v0->unk_00); -} - -void sub_02067968(MapObject *param0) -{ - UnkStruct_02067870 *v0 = sub_02062AF0(param0); - - if (v0->unk_08 != NULL) { - ov5_021ED01C(v0->unk_08, &v0->unk_0C); - } - - ov5_021ECFD8(param0, &v0->unk_08, v0->unk_00); - MapObject_SetStatusFlagOn(param0, MAP_OBJ_STATUS_21); -} - -void sub_02067998(MapObject *param0) -{ - UnkStruct_02067870 *v0 = sub_02062AF0(param0); - - if (ov5_021EDD94(param0) == 1) { - return; - } - - if (v0->unk_08 == NULL) { - if (v0->unk_00 != 0xffff) { - ov5_021ECEB4(param0, &v0->unk_08, v0->unk_00); - } else { - MapObject_SetStatusFlagOff(param0, MAP_OBJ_STATUS_21); - } - - ov5_021F20D4(param0); - } - - if (v0->unk_08 != NULL) { - ov5_021ED03C(v0->unk_08, &v0->unk_0C); - ov5_021EDEB4(param0, v0->unk_08); - MapObject_SetStatusFlagOff(param0, MAP_OBJ_STATUS_21); - } -} - -static int sub_020679FC(int param0, int param1) -{ - switch (param1) { - case 0: - return 0xffff; - case 1: - return 0xffff; - default: { - param0--; - - { - const UnkStruct_ov5_021FB67C *v0 = &Unk_ov5_021FB67C[param0]; - - switch (param1) { - case 2: - return 0x1000 + 0x0; - case 3: - return v0->unk_00; - case 4: - return v0->unk_04; - case 5: - return v0->unk_08; - } - } - } - } - - GF_ASSERT(FALSE); - return 0xffff; -} - -UnkStruct_020216E0 *sub_02067A58(MapObject *param0) -{ - UnkStruct_020216E0 *v0 = NULL; - - GF_ASSERT(sub_020677F4(MapObject_GetGraphicsID(param0))); - - if (sub_02062D4C(param0) == 1) { - UnkStruct_02067870 *v1 = sub_02062AF0(param0); - - v0 = v1->unk_08; - } - - return v0; -} diff --git a/src/unk_0206CCB0.c b/src/unk_0206CCB0.c index 84731446e7..930a2a3f69 100644 --- a/src/unk_0206CCB0.c +++ b/src/unk_0206CCB0.c @@ -1100,20 +1100,20 @@ static BOOL sub_0206D910(FieldSystem *fieldSystem, UnkStruct_ov6_022465F4 *param return 0; } -void sub_0206D914(FieldSystem *fieldSystem, u16 param1, u8 param2, u16 param3) +void TVBroadcast_RecordBerryHarvest(FieldSystem *fieldSystem, u16 berryItemID, u8 yieldRating, u16 yieldAmount) { UnkUnion_0206D1B8 v0; UnkStruct_0206D94C *v1 = &v0.val13; - v1->unk_00 = param1; - v1->unk_02 = param2; - v1->unk_04 = param3; + v1->unk_00 = berryItemID; + v1->unk_02 = yieldRating; + v1->unk_04 = yieldAmount; - if (param2 == 5) { + if (yieldRating == 5) { (void)0; - } else if (param2 == 4) { + } else if (yieldRating == 4) { sub_0206CD70(fieldSystem, 2, 18, v1); - } else if (param2 == 0) { + } else if (yieldRating == 0) { sub_0206CD70(fieldSystem, 2, 19, v1); } } @@ -2829,7 +2829,7 @@ static int sub_0206F160(FieldSystem *fieldSystem, StringTemplate *param1, UnkStr pokemon = Party_GetPokemonBySlotIndex(party, SaveData_GetFirstNonEggInParty(fieldSystem->saveData)); sub_0206CE74(param1, 0, Pokemon_GetValue(pokemon, MON_DATA_SPECIES, NULL), Pokemon_GetValue(pokemon, MON_DATA_GENDER, NULL), TrainerInfo_RegionCode(trainerInfo), TrainerInfo_GameCode(trainerInfo)); - StringTemplate_SetContestAccessoryName(param1, 1, (LCRNG_Next() % 100)); + StringTemplate_SetContestAccessoryName(param1, 1, LCRNG_Next() % 100); v1 = (LCRNG_Next() % (NATIONAL_DEX_COUNT - 2) + 1); diff --git a/src/unk_020EDBAC.c b/src/unk_020EDBAC.c index 911ee81aff..40c643cc9c 100644 --- a/src/unk_020EDBAC.c +++ b/src/unk_020EDBAC.c @@ -6,10 +6,10 @@ #include "struct_decls/struct_02061AB4_decl.h" #include "struct_defs/struct_020EDF0C.h" +#include "berry_patch_graphics.h" #include "map_object.h" #include "unk_0206450C.h" #include "unk_020655F4.h" -#include "unk_020677F4.h" #include "unk_02069BE0.h" static const UnkStruct_020EDF0C Unk_020EDF0C = { @@ -406,9 +406,9 @@ static const UnkStruct_020EDF0C Unk_020EDE1C = { static const UnkStruct_020EDF0C Unk_020EDE30 = { 0x2f, - sub_02067840, - sub_02067850, - sub_0206786C, + BerryPatchGraphics_NewData, + BerryPatchGraphics_UpdateGrowthStage, + BerryPatchGraphics_NoOp, sub_020633EC };