overlay 16: Cleanup, some documentation

Source: Bulbapedia
This commit is contained in:
tgsm 2023-08-15 21:17:38 -05:00
parent 746d8c5c6a
commit 189a90da93
7 changed files with 247 additions and 233 deletions

View File

@ -143,28 +143,28 @@
.public _s32_div_f
.public gSystem
.public ov16_022014A0
.public ov16_022015B0
.public ov16_022015BC
.public BerryPots_GetPotGrowthStage
.public BerryPots_GetPotBerryId
.public ov16_022015C4
.public ov16_022015E0
.public BerryPots_GetPotMoisture
.public ov16_022015EC
.public ov16_022015F8
.public ov16_02201604
.public ov16_02201610
.public ov16_02201644
.public ov16_02201650
.public ov16_0220165C
.public BerryPots_ResetPotMoisture
.public BerryPots_GetPotMulch
.public BerryPots_SetPotMulch
.public ov16_02201668
.public ov16_02201674
.public ov16_02201760
.public ov16_022017FC
.public ov16_02201820
.public ov16_022018B4
.public ov16_022018C4
.public ov16_022018D4
.public ov16_022018E4
.public ov16_022018F0
.public ov16_0220191C
.public BerryIdToItemId
.public ItemIdToBerryId
.public MulchIdToItemId
.public ItemIdToMulchId
.public GetTotalBerryQuantity
.public GetTotalMulchQuantity
.public ov17_02201BC0
.public ov17_02201C10
.public ov17_02201C78

View File

@ -249,13 +249,13 @@ _02201DA8:
bl ov17_022023B0
ldr r0, [r5, #0xc]
ldr r1, [r5]
bl ov16_022018F0
bl GetTotalBerryQuantity
add r1, r5, #0
add r1, #0x82
strh r0, [r1]
ldr r0, [r5, #0xc]
ldr r1, [r5]
bl ov16_0220191C
bl GetTotalMulchQuantity
add r1, r5, #0
add r1, #0x84
strh r0, [r1]
@ -838,7 +838,7 @@ _0220220C:
mul r0, r1
add r5, r2, r0
ldrb r0, [r2, r0]
bl ov16_022018B4
bl BerryIdToItemId
add r1, r0, #0
ldrb r2, [r5, #5]
ldr r0, [r4, #0xc]
@ -1060,13 +1060,13 @@ ov17_022023B0: ; 0x022023B0
beq _02202438
ldr r0, [r4, #4]
ldrh r0, [r0, #0x16]
bl ov16_022018E4
bl ItemIdToMulchId
add r1, r4, #0
add r1, #0x7c
add r2, r0, #0
ldrb r1, [r1]
ldr r0, [r4, #0x14]
bl ov16_0220165C
bl BerryPots_SetPotMulch
add r0, r4, #0
mov r1, #1
add r0, #0x7b
@ -1080,7 +1080,7 @@ _022023F6:
beq _02202438
ldr r0, [r4, #4]
ldrh r0, [r0, #0x16]
bl ov16_022018C4
bl ItemIdToBerryId
add r1, r4, #0
add r1, #0x7c
add r3, r0, #0
@ -2044,7 +2044,7 @@ ov17_02202B58: ; 0x02202B58
mul r0, r6
add r4, r2, r0
ldr r0, [r5, #0x14]
bl ov16_02201644
bl BerryPots_ResetPotMoisture
add r0, r5, #0
bl ov17_0220387C
add r0, r6, #3
@ -2081,7 +2081,7 @@ ov17_02202B98: ; 0x02202B98
add r4, r6, r7
bl ov16_02201674
ldrb r0, [r6, r7]
bl ov16_022018B4
bl BerryIdToItemId
add r1, r0, #0
ldrb r2, [r4, #5]
ldr r0, [r5, #0xc]
@ -3159,7 +3159,7 @@ ov17_02203460: ; 0x02203460
add r0, r5, r0
add r0, #0x20
ldrb r0, [r0]
bl ov16_022018B4
bl BerryIdToItemId
mov r1, #1
add r4, r0, #0
bl GetItemIndexMapping
@ -3526,7 +3526,7 @@ _0220371E: ; jump table
.short _0220376C - _0220371E - 2 ; case 16
_02203740:
ldrb r0, [r6, #4]
bl ov16_022018D4
bl MulchIdToItemId
add r2, r0, #0
add r0, r4, #0
add r0, #0xa0
@ -3704,13 +3704,13 @@ _02203884:
strb r1, [r0]
ldr r0, [r6, #0x14]
add r1, r4, #0
bl ov16_022015BC
bl BerryPots_GetPotBerryId
add r1, r5, #0
add r1, #0x20
strb r0, [r1]
ldr r0, [r6, #0x14]
add r1, r4, #0
bl ov16_022015B0
bl BerryPots_GetPotGrowthStage
add r1, r5, #0
add r1, #0x21
strb r0, [r1]
@ -3722,13 +3722,13 @@ _02203884:
strb r0, [r1]
ldr r0, [r6, #0x14]
add r1, r4, #0
bl ov16_022015E0
bl BerryPots_GetPotMoisture
add r1, r5, #0
add r1, #0x23
strb r0, [r1]
ldr r0, [r6, #0x14]
add r1, r4, #0
bl ov16_02201650
bl BerryPots_GetPotMulch
add r1, r5, #0
add r1, #0x24
strb r0, [r1]

42
include/overlay_16.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef POKEHEARTGOLD_OVERLAY_16_H
#define POKEHEARTGOLD_OVERLAY_16_H
#include "bag.h"
#include "save_misc_data.h"
#include "overlay_manager.h"
typedef struct UnkStruct_ov16_022014A0 {
u8 defaultGrowthTimeInHours;
u8 defaultDrainRate;
u8 unk2; // yield multiplier?
} UnkStruct_ov16_022014A0; // size: 0x3
UnkStruct_ov16_022014A0 *ov16_022014A0(HeapID heapId);
u8 BerryPots_GetPotGrowthStage(BERRY_POT *berryPots, u32 idx);
u8 BerryPots_GetPotBerryId(BERRY_POT *berryPots, u32 idx);
u32 ov16_022015C4(BERRY_POT *berryPots, u32 idx);
u8 BerryPots_GetPotMoisture(BERRY_POT *berryPots, u32 idx);
u8 ov16_022015EC(BERRY_POT *berryPots, u32 idx);
u16 ov16_022015F8(BERRY_POT *berryPots, u32 idx);
u16 ov16_02201604(BERRY_POT *berryPots, u32 idx);
void ov16_02201610(BERRY_POT *berryPots, u32 idx, UnkStruct_ov16_022014A0 *a2, u8 a3);
void BerryPots_ResetPotMoisture(BERRY_POT *berryPots, u32 idx);
u8 BerryPots_GetPotMulch(BERRY_POT *berryPots, u32 idx);
void BerryPots_SetPotMulch(BERRY_POT *berryPots, u32 idx, u8 mulch);
u16 ov16_02201668(BERRY_POT *berryPots, u32 idx);
u16 ov16_02201674(BERRY_POT *berryPots, u32 idx);
void ov16_02201760(BERRY_POT *berryPots, UnkStruct_ov16_022014A0 *a1, s32 a2);
void ov16_022017FC(struct GF_RTC_DateTime *dest, struct GF_RTC_DateTime src);
void ov16_02201820(struct GF_RTC_DateTime *datetime, RTCDate *date, RTCTime *time);
u16 BerryIdToItemId(u16 berryId);
u16 ItemIdToBerryId(u16 itemId);
u16 MulchIdToItemId(u16 mulchId);
u32 ItemIdToMulchId(u16 itemId);
u16 GetTotalBerryQuantity(Bag *bag, HeapID heapId);
u16 GetTotalMulchQuantity(Bag *bag, HeapID heapId);
BOOL ov16_0220196C(OVY_MANAGER *manager, int *state);
BOOL ov16_022019B8(OVY_MANAGER *manager, int *state);
BOOL ov16_02201A04(OVY_MANAGER *manager, int *state);
#endif

View File

@ -13,16 +13,23 @@ typedef struct APRICORN_TREE {
u16 unk_2;
} APRICORN_TREE;
#define BERRY_POT_GROWTH_STAGE_INVALID 0
#define BERRY_POT_GROWTH_STAGE_PLANTED 1
#define BERRY_POT_GROWTH_STAGE_SPROUTED 2
#define BERRY_POT_GROWTH_STAGE_GROWING 3
#define BERRY_POT_GROWTH_STAGE_BLOOM 4
#define BERRY_POT_GROWTH_STAGE_BERRIES 5
typedef struct BERRY_POT {
u8 unk_0;
u8 unk_1;
u8 berryId;
u8 growthStage;
u16 unk_2;
u16 unk_4;
u16 unk_6;
u8 unk_8;
u8 moistureMaybe;
u8 moisture;
u8 unk_A;
u8 unk_B;
u8 mulch;
} BERRY_POT;
#define MAX_APRICORN_TREE 128

View File

@ -1,128 +1,119 @@
#include "global.h"
#include "bag.h"
#include "filesystem.h"
#include "gf_rtc.h"
#include "save_misc_data.h"
#include "overlay_16.h"
typedef struct UnkStruct_a066 {
u16 unk0;
u8 unk2;
u8 unk3;
u8 unk4;
u8 unk5;
u8 unk6;
u8 unk7;
u8 unk8;
u8 unk9;
u8 unkA;
u8 unkB;
} UnkStruct_a066; // size: 0xc
typedef struct BerryFile {
u16 sizeInMillimeters;
u8 firmness;
u8 unk3; // yield multiplier?
u8 defaultGrowthInterval;
u8 defaultDrainRate;
u8 spiciness;
u8 dryness;
u8 sweetness;
u8 bitterness;
u8 sourness;
u8 smoothness;
} BerryFile; // size: 0xc
typedef struct UnkStruct_ov16_022014A0 {
u8 unk0;
u8 unk1;
u8 unk2;
} UnkStruct_ov16_022014A0; // size: 0x3
static void BerryPot_Clear(BERRY_POT *berryPot);
static u32 ov16_02201514(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1);
static u32 CalculateBerryPotGrowthInterval(UnkStruct_ov16_022014A0 *a0, int berryId, int a2);
static u32 CalculateBerryPotDrainRate(UnkStruct_ov16_022014A0 *a0, int berryId, int a2);
static u32 ov16_02201578(BERRY_POT *berryPot);
static u32 ov16_02201588(BERRY_POT *berryPot);
static u32 ov16_02201598(BERRY_POT *berryPot);
static void ov16_02201688(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1);
static void ov16_022016F4(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1, int a2);
static NARC *GetBerryInfoNarc(HeapID heapId);
static BerryFile *GetBerryFileFromNarc(NARC *narc, s32 fileId, HeapID heapId);
static void FreeBerryInfoNarc(NARC *narc);
static u16 GetBerryAttr(BerryFile *unk, u32 attr);
NARC *ov16_02201840(HeapID heapId);
UnkStruct_a066 *ov16_0220184C(NARC *narc, s32 fileId, HeapID heapId);
void ov16_02201854(NARC *narc);
u16 ov16_0220185C(UnkStruct_a066 *unk, u32 attr);
extern _s32_div_f();
UnkStruct_ov16_022014A0 *ov16_022014A0(HeapID heapId);
UnkStruct_ov16_022014A0 *ov16_022014A0(HeapID heapId) {
UnkStruct_ov16_022014A0 *unk;
NARC *narc;
narc = ov16_02201840(heapId);
narc = GetBerryInfoNarc(heapId);
unk = AllocFromHeap(heapId, NUM_BERRIES * sizeof(UnkStruct_ov16_022014A0));
for (int fileId = 0; fileId < NUM_BERRIES; fileId++) {
UnkStruct_a066 *unk_a066 = ov16_0220184C(narc, fileId, heapId);
unk[fileId].unk0 = ov16_0220185C(unk_a066, 3);
unk[fileId].unk1 = ov16_0220185C(unk_a066, 4);
unk[fileId].unk2 = ov16_0220185C(unk_a066, 2);
BerryFile *berryFile = GetBerryFileFromNarc(narc, fileId, heapId);
unk[fileId].defaultGrowthTimeInHours = GetBerryAttr(berryFile, 3);
unk[fileId].defaultDrainRate = GetBerryAttr(berryFile, 4);
unk[fileId].unk2 = GetBerryAttr(berryFile, 2);
FreeToHeap(unk_a066);
FreeToHeap(berryFile);
}
ov16_02201854(narc);
FreeBerryInfoNarc(narc);
return unk;
}
void ov16_022014FC(BERRY_POT *berryPot);
void ov16_022014FC(BERRY_POT *berryPot) {
berryPot->unk_0 = 0;
berryPot->unk_1 = 0;
static void BerryPot_Clear(BERRY_POT *berryPot) {
berryPot->berryId = 0;
berryPot->growthStage = BERRY_POT_GROWTH_STAGE_INVALID;
berryPot->unk_2 = 0;
berryPot->unk_4 = 0;
berryPot->unk_8 = 0;
berryPot->unk_6 = 0;
berryPot->moistureMaybe = 0;
berryPot->moisture = 0;
berryPot->unk_A = 0;
berryPot->unk_B = 0;
berryPot->mulch = 0;
}
u32 ov16_02201514(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1);
u32 ov16_02201514(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1) {
return berryPot->unk_A * a1[berryPot->unk_0 - 1].unk2;
static u32 ov16_02201514(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1) {
return berryPot->unk_A * a1[berryPot->berryId - 1].unk2;
}
u32 ov16_02201528(UnkStruct_ov16_022014A0 *a0, int a1, int a2);
u32 ov16_02201528(UnkStruct_ov16_022014A0 *a0, int a1, int a2) {
s32 unk = a0[a1 - 1].unk0 * 60;
if (a2 == 1) {
return (unk * 3) / 4;
} else if (a2 == 2) {
unk += (unk / 2);
static u32 CalculateBerryPotGrowthInterval(UnkStruct_ov16_022014A0 *a0, int berryId, int mulch) {
s32 growthTimeInMinutes = a0[berryId - 1].defaultGrowthTimeInHours * 60;
if (mulch == 1) { // Growth mulch
return (growthTimeInMinutes * 3) / 4;
} else if (mulch == 2) { // Damp mulch
growthTimeInMinutes += (growthTimeInMinutes / 2);
}
return unk;
return growthTimeInMinutes;
}
u32 ov16_02201554(UnkStruct_ov16_022014A0 *a0, int a1, int a2);
u32 ov16_02201554(UnkStruct_ov16_022014A0 *a0, int a1, int a2) {
s32 unk = a0[a1 - 1].unk1;
if (a2 == 2) {
return unk / 2;
} else if (a2 == 1) {
unk = unk + unk / 2;
static u32 CalculateBerryPotDrainRate(UnkStruct_ov16_022014A0 *a0, int berryId, int mulch) {
s32 drainRate = a0[berryId - 1].defaultDrainRate;
if (mulch == 2) { // Damp mulch
return drainRate / 2;
} else if (mulch == 1) { // Growth mulch
drainRate += (drainRate / 2);
}
return unk;
return drainRate;
}
u32 ov16_02201578(BERRY_POT *berryPot);
u32 ov16_02201578(BERRY_POT *berryPot) {
return (berryPot->unk_B == 3) ? 6 : 4;
static u32 ov16_02201578(BERRY_POT *berryPot) {
// Stable mulch
return (berryPot->mulch == 3) ? 6 : 4;
}
u32 ov16_02201588(BERRY_POT *berryPot);
u32 ov16_02201588(BERRY_POT *berryPot) {
return (berryPot->unk_B == 4) ? 15 : 10;
static u32 ov16_02201588(BERRY_POT *berryPot) {
// Gooey mulch
return (berryPot->mulch == 4) ? 15 : 10;
}
u32 ov16_02201598(BERRY_POT *berryPot);
u32 ov16_02201598(BERRY_POT *berryPot) {
static u32 ov16_02201598(BERRY_POT *berryPot) {
u32 unk1 = ov16_02201578(berryPot);
u32 unk2 = ov16_02201588(berryPot);
return (unk1 + 3) * unk2 + 1;
}
u8 ov16_022015B0(BERRY_POT *berryPots, u32 idx);
u8 ov16_022015B0(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].unk_1;
u8 BerryPots_GetPotGrowthStage(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].growthStage;
}
u8 ov16_022015BC(BERRY_POT *berryPots, u32 idx);
u8 ov16_022015BC(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].unk_0;
u8 BerryPots_GetPotBerryId(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].berryId;
}
u32 ov16_022015C4(BERRY_POT *berryPots, u32 idx);
u32 ov16_022015C4(BERRY_POT *berryPots, u32 idx) {
s32 moisture = berryPots[idx].moistureMaybe;
s32 moisture = berryPots[idx].moisture;
if (moisture == 0) {
return 0;
} else if (moisture <= 50) {
@ -132,144 +123,131 @@ u32 ov16_022015C4(BERRY_POT *berryPots, u32 idx) {
}
}
u8 ov16_022015E0(BERRY_POT *berryPots, u32 idx);
u8 ov16_022015E0(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].moistureMaybe;
u8 BerryPots_GetPotMoisture(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].moisture;
}
u8 ov16_022015EC(BERRY_POT *berryPots, u32 idx);
u8 ov16_022015EC(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].unk_A;
}
u16 ov16_022015F8(BERRY_POT *berryPots, u32 idx);
u16 ov16_022015F8(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].unk_2;
}
u16 ov16_02201604(BERRY_POT *berryPots, u32 idx);
u16 ov16_02201604(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].unk_4;
}
void ov16_02201610(BERRY_POT *berryPots, u32 idx, UnkStruct_ov16_022014A0 *a2, u8 a3);
void ov16_02201610(BERRY_POT *berryPots, u32 idx, UnkStruct_ov16_022014A0 *a2, u8 a3) {
berryPots[idx].unk_0 = a3;
berryPots[idx].unk_1 = 1;
berryPots[idx].unk_2 = ov16_02201528(a2, a3, berryPots[idx].unk_B);
void ov16_02201610(BERRY_POT *berryPots, u32 idx, UnkStruct_ov16_022014A0 *a2, u8 berryId) {
berryPots[idx].berryId = berryId;
berryPots[idx].growthStage = BERRY_POT_GROWTH_STAGE_PLANTED;
berryPots[idx].unk_2 = CalculateBerryPotGrowthInterval(a2, berryId, berryPots[idx].mulch);
berryPots[idx].unk_4 = 0;
berryPots[idx].unk_8 = 0;
berryPots[idx].unk_6 = 0;
berryPots[idx].moistureMaybe = 100;
berryPots[idx].moisture = 100;
berryPots[idx].unk_A = 5;
}
void ov16_02201644(BERRY_POT *berryPots, u32 idx);
void ov16_02201644(BERRY_POT *berryPots, u32 idx) {
berryPots[idx].moistureMaybe = 100;
void BerryPots_ResetPotMoisture(BERRY_POT *berryPots, u32 idx) {
berryPots[idx].moisture = 100;
}
u8 ov16_02201650(BERRY_POT *berryPots, u32 idx);
u8 ov16_02201650(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].unk_B;
u8 BerryPots_GetPotMulch(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].mulch;
}
void ov16_0220165C(BERRY_POT *berryPots, u32 idx, u8 a2);
void ov16_0220165C(BERRY_POT *berryPots, u32 idx, u8 a2) {
berryPots[idx].unk_B = a2;
void BerryPots_SetPotMulch(BERRY_POT *berryPots, u32 idx, u8 mulch) {
berryPots[idx].mulch = mulch;
}
u16 ov16_02201668(BERRY_POT *berryPots, u32 idx);
u16 ov16_02201668(BERRY_POT *berryPots, u32 idx) {
return berryPots[idx].unk_6;
}
u16 ov16_02201674(BERRY_POT *berryPots, u32 idx);
u16 ov16_02201674(BERRY_POT *berryPots, u32 idx) {
u16 unk = berryPots[idx].unk_6;
ov16_022014FC(&berryPots[idx]);
BerryPot_Clear(&berryPots[idx]);
return unk;
}
void ov16_02201688(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1);
void ov16_02201688(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1) {
switch (berryPot->unk_1) {
case 0:
static void ov16_02201688(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1) {
switch (berryPot->growthStage) {
case BERRY_POT_GROWTH_STAGE_INVALID:
GF_ASSERT(FALSE);
return;
case 1:
case 2:
case 3:
berryPot->unk_1++;
case BERRY_POT_GROWTH_STAGE_PLANTED:
case BERRY_POT_GROWTH_STAGE_SPROUTED:
case BERRY_POT_GROWTH_STAGE_GROWING:
berryPot->growthStage++;
return;
case 4:
case BERRY_POT_GROWTH_STAGE_BLOOM:
berryPot->unk_6 = ov16_02201514(berryPot, a1);
if (berryPot->unk_6 < 2) {
berryPot->unk_6 = 2;
}
berryPot->unk_1++;
berryPot->growthStage++;
return;
case 5:
case BERRY_POT_GROWTH_STAGE_BERRIES:
berryPot->unk_6 = 0;
berryPot->unk_1 = 2;
berryPot->growthStage = BERRY_POT_GROWTH_STAGE_SPROUTED;
berryPot->unk_A = 5;
berryPot->unk_8++;
if (berryPot->unk_8 == ov16_02201588(berryPot)) {
ov16_022014FC(berryPot);
BerryPot_Clear(berryPot);
}
return;
}
}
void ov16_022016F4(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1, int a2);
void ov16_022016F4(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1, int a2) {
if (berryPot->unk_1 == 5) {
static void ov16_022016F4(BERRY_POT *berryPot, UnkStruct_ov16_022014A0 *a1, int a2) {
if (berryPot->growthStage == BERRY_POT_GROWTH_STAGE_BERRIES) {
return;
}
int iVar2 = ov16_02201554(a1, berryPot->unk_0, berryPot->unk_B);
int iVar3 = (a2 + berryPot->unk_4) / 60;
int drainRate = CalculateBerryPotDrainRate(a1, berryPot->berryId, berryPot->mulch);
int r4 = (a2 + berryPot->unk_4) / 60;
berryPot->unk_4 = (a2 + berryPot->unk_4) % 60;
if (iVar3 == 0) {
if (r4 == 0) {
return;
}
if (berryPot->moistureMaybe >= (iVar2 * iVar3)) {
berryPot->moistureMaybe -= (iVar3 * iVar2);
if (berryPot->moisture >= (drainRate * r4)) {
berryPot->moisture -= (r4 * drainRate);
return;
}
if (berryPot->moistureMaybe != 0) {
iVar3 -= (berryPot->moistureMaybe + (iVar2 - 1)) / iVar2;
berryPot->moistureMaybe = 0;
if (berryPot->moisture != 0) {
r4 -= (berryPot->moisture + (drainRate - 1)) / drainRate;
berryPot->moisture = 0;
}
if (berryPot->unk_A > iVar3) {
berryPot->unk_A -= iVar3;
if (berryPot->unk_A > r4) {
berryPot->unk_A -= r4;
return;
}
berryPot->unk_A = 0;
}
void ov16_02201760(BERRY_POT *berryPots, UnkStruct_ov16_022014A0 *a1, s32 a2);
void ov16_02201760(BERRY_POT *berryPots, UnkStruct_ov16_022014A0 *a1, s32 a2) {
for (s32 i = 0; i < 4; i++) {
if (berryPots[i].unk_0 == 0 || berryPots[i].unk_1 == 0) {
for (s32 i = 0; i < MAX_BERRY_POT; i++) {
if (berryPots[i].berryId == 0 || berryPots[i].growthStage == BERRY_POT_GROWTH_STAGE_INVALID) {
continue;
}
s32 growthInterval = ov16_02201528(a1, berryPots[i].unk_0, berryPots[i].unk_B);
s32 iVar4 = ov16_02201598(&berryPots[i]);
s32 growthInterval = CalculateBerryPotGrowthInterval(a1, berryPots[i].berryId, berryPots[i].mulch);
s32 unk = ov16_02201598(&berryPots[i]);
if (a2 >= growthInterval * iVar4) {
ov16_022014FC(&berryPots[i]);
if (a2 >= growthInterval * unk) {
BerryPot_Clear(&berryPots[i]);
continue;
}
s32 a2Tmp = a2;
while (berryPots[i].unk_1 != 0 && a2Tmp != 0) {
while (berryPots[i].growthStage != BERRY_POT_GROWTH_STAGE_INVALID && a2Tmp != 0) {
if (berryPots[i].unk_2 > a2Tmp) {
ov16_022016F4(&berryPots[i], a1, a2Tmp);
berryPots[i].unk_2 -= a2Tmp;
@ -279,69 +257,66 @@ void ov16_02201760(BERRY_POT *berryPots, UnkStruct_ov16_022014A0 *a1, s32 a2) {
ov16_022016F4(&berryPots[i], a1, berryPots[i].unk_2);
ov16_02201688(&berryPots[i], a1);
a2Tmp -= berryPots[i].unk_2;
berryPots[i].unk_2 = ov16_02201528(a1, berryPots[i].unk_0, berryPots[i].unk_B);
if (berryPots[i].unk_1 == 5) {
berryPots[i].unk_2 = CalculateBerryPotGrowthInterval(a1, berryPots[i].berryId, berryPots[i].mulch);
if (berryPots[i].growthStage == BERRY_POT_GROWTH_STAGE_BERRIES) {
berryPots[i].unk_2 *= ov16_02201578(&berryPots[i]);
}
}
}
}
void ov16_022017FC(struct GF_RTC_DateTime *dest, struct GF_RTC_DateTime src);
void ov16_022017FC(struct GF_RTC_DateTime *dest, struct GF_RTC_DateTime src) {
dest->date = src.date;
dest->time = src.time;
}
void ov16_02201820(struct GF_RTC_DateTime *datetime, RTCDate *date, RTCTime *time);
void ov16_02201820(struct GF_RTC_DateTime *datetime, RTCDate *date, RTCTime *time) {
*date = datetime->date;
*time = datetime->time;
}
NARC *ov16_02201840(HeapID heapId) {
static NARC *GetBerryInfoNarc(HeapID heapId) {
return NARC_New(NARC_a_0_6_6, heapId);
}
UnkStruct_a066 *ov16_0220184C(NARC *narc, s32 fileId, HeapID heapId) {
static BerryFile *GetBerryFileFromNarc(NARC *narc, s32 fileId, HeapID heapId) {
return NARC_AllocAndReadWholeMember(narc, fileId, heapId);
}
void ov16_02201854(NARC *narc) {
static void FreeBerryInfoNarc(NARC *narc) {
NARC_Delete(narc);
}
u16 ov16_0220185C(UnkStruct_a066 *unk, u32 attr) {
static u16 GetBerryAttr(BerryFile *unk, u32 attr) {
switch (attr) {
case 0:
return unk->unk0;
return unk->sizeInMillimeters;
case 1:
return unk->unk2;
return unk->firmness;
case 2:
return unk->unk3;
case 3:
return unk->unk4;
return unk->defaultGrowthInterval;
case 4:
return unk->unk5;
return unk->defaultDrainRate;
case 5:
return unk->unk6;
return unk->spiciness;
case 6:
return unk->unk7;
return unk->dryness;
case 7:
return unk->unk8;
return unk->sweetness;
case 8:
return unk->unk9;
return unk->bitterness;
case 9:
return unk->unkA;
return unk->sourness;
case 10:
return unk->unkB;
return unk->smoothness;
default:
return 0;
}
}
u16 ov16_022018B4(u16 berryId);
u16 ov16_022018B4(u16 berryId) {
u16 BerryIdToItemId(u16 berryId) {
if (berryId == 0) {
return ITEM_NONE;
}
@ -349,8 +324,7 @@ u16 ov16_022018B4(u16 berryId) {
return berryId + FIRST_BERRY_IDX - 1;
}
u16 ov16_022018C4(u16 itemId);
u16 ov16_022018C4(u16 itemId) {
u16 ItemIdToBerryId(u16 itemId) {
if (itemId == ITEM_NONE) {
return 0;
}
@ -358,8 +332,7 @@ u16 ov16_022018C4(u16 itemId) {
return itemId - FIRST_BERRY_IDX + 1;
}
u16 ov16_022018D4(u16 mulchId);
u16 ov16_022018D4(u16 mulchId) {
u16 MulchIdToItemId(u16 mulchId) {
if (mulchId == 0) {
return ITEM_NONE;
}
@ -367,8 +340,7 @@ u16 ov16_022018D4(u16 mulchId) {
return mulchId + ITEM_GROWTH_MULCH - 1;
}
u32 ov16_022018E4(u16 itemId);
u32 ov16_022018E4(u16 itemId) {
u32 ItemIdToMulchId(u16 itemId) {
if (itemId == ITEM_NONE) {
return 0;
}
@ -376,9 +348,7 @@ u32 ov16_022018E4(u16 itemId) {
return itemId - ITEM_GROWTH_MULCH + 1;
}
// total berry quantity
u16 ov16_022018F0(Bag *bag, HeapID heapId);
u16 ov16_022018F0(Bag *bag, HeapID heapId) {
u16 GetTotalBerryQuantity(Bag *bag, HeapID heapId) {
s32 i;
u16 total;
for (total = 0, i = 0; i < NUM_BAG_BERRIES; i++) {
@ -387,9 +357,7 @@ u16 ov16_022018F0(Bag *bag, HeapID heapId) {
return total;
}
// total mulch quantity
u16 ov16_0220191C(Bag *bag, HeapID heapId);
u16 ov16_0220191C(Bag *bag, HeapID heapId) {
u16 GetTotalMulchQuantity(Bag *bag, HeapID heapId) {
s32 i;
u16 total;
for (total = 0, i = 0; i < 4; i++) {

View File

@ -1,13 +1,23 @@
#include "global.h"
#include "constants/items.h"
#include "bag_cursor.h"
#include "overlay_manager.h"
#include "overlay_16.h"
#include "unk_0203E348.h"
FS_EXTERN_OVERLAY(OVY_15);
FS_EXTERN_OVERLAY(OVY_17);
static const u8 _02201B60[] = {
extern BOOL ov15_BagApp_Init(OVY_MANAGER*, int*);
extern BOOL ov15_BagApp_Exec(OVY_MANAGER*, int*);
extern BOOL ov15_BagApp_Exit(OVY_MANAGER*, int*);
extern BOOL ov17_02201C10(OVY_MANAGER*, int*);
extern BOOL ov17_02201C78(OVY_MANAGER*, int*);
extern BOOL ov17_02201D04(OVY_MANAGER*, int*);
extern void ov17_02201BC0(void);
static const u8 ov16_02201B60[] = {
POCKET_ITEMS, 0xFF
};
@ -15,10 +25,6 @@ static const u8 ov16_02201B64[] = {
POCKET_BERRIES, 0xFF
};
extern BOOL ov17_02201C10(OVY_MANAGER*, int*);
extern BOOL ov17_02201C78(OVY_MANAGER*, int*);
extern BOOL ov17_02201D04(OVY_MANAGER*, int*);
static const OVY_MGR_TEMPLATE ov16_02201B68 = {
.init = ov17_02201C10,
.exec = ov17_02201C78,
@ -26,12 +32,6 @@ static const OVY_MGR_TEMPLATE ov16_02201B68 = {
.ovy_id = FS_OVERLAY_ID_NONE,
};
extern u8* unused_02201BA0;
extern BOOL ov15_BagApp_Init(OVY_MANAGER*, int*);
extern BOOL ov15_BagApp_Exec(OVY_MANAGER*, int*);
extern BOOL ov15_BagApp_Exit(OVY_MANAGER*, int*);
static const OVY_MGR_TEMPLATE ov16_02201B78 = {
.init = ov15_BagApp_Init,
.exec = ov15_BagApp_Exec,
@ -39,6 +39,8 @@ static const OVY_MGR_TEMPLATE ov16_02201B78 = {
.ovy_id = FS_OVERLAY_ID(OVY_15),
};
extern u8* unused_02201BA0;
typedef struct UnkStruct_ov16_0220196C {
HeapID heapId;
BerryPotsArgs *args;
@ -51,18 +53,15 @@ typedef struct UnkStruct_ov16_0220196C {
BagCursor *cursor2;
} UnkStruct_ov16_0220196C; // size: 0x20
BOOL ov16_02201948(OVY_MANAGER **manager);
BOOL ov16_0220196C(OVY_MANAGER *manager, int *state);
BOOL ov16_022019B8(OVY_MANAGER *manager, int *state);
BOOL ov16_02201A04(OVY_MANAGER *manager, int *state);
void ov16_02201A34(UnkStruct_ov16_0220196C *unk);
void ov16_02201A4C(UnkStruct_ov16_0220196C *unk);
u32 ov16_02201A60(UnkStruct_ov16_0220196C *unk);
u32 ov16_02201A78(UnkStruct_ov16_0220196C *unk);
u32 ov16_02201AA0(UnkStruct_ov16_0220196C *unk);
u32 ov16_02201B24(UnkStruct_ov16_0220196C *unk);
static BOOL ov16_02201948(OVY_MANAGER **manager);
static void ov16_02201A34(UnkStruct_ov16_0220196C *unk);
static void ov16_02201A4C(UnkStruct_ov16_0220196C *unk);
static u32 ov16_02201A60(UnkStruct_ov16_0220196C *unk);
static u32 ov16_02201A78(UnkStruct_ov16_0220196C *unk);
static u32 ov16_02201AA0(UnkStruct_ov16_0220196C *unk);
static u32 ov16_02201B24(UnkStruct_ov16_0220196C *unk);
BOOL ov16_02201948(OVY_MANAGER **manager) {
static BOOL ov16_02201948(OVY_MANAGER **manager) {
if (*manager != NULL && OverlayManager_Run(*manager)) {
OverlayManager_Delete(*manager);
*manager = NULL;
@ -72,8 +71,6 @@ BOOL ov16_02201948(OVY_MANAGER **manager) {
return FALSE;
}
extern void ov17_02201BC0(void);
BOOL ov16_0220196C(OVY_MANAGER *manager, int *state) {
HandleLoadOverlay(FS_OVERLAY_ID(OVY_17), OVY_LOAD_ASYNC);
ov17_02201BC0();
@ -125,22 +122,22 @@ BOOL ov16_02201A04(OVY_MANAGER *manager, int *state) {
return TRUE;
}
void ov16_02201A34(UnkStruct_ov16_0220196C *unk) {
static void ov16_02201A34(UnkStruct_ov16_0220196C *unk) {
unk->cursor1 = BagCursor_New(unk->heapId);
unk->cursor2 = BagCursor_New(unk->heapId);
}
void ov16_02201A4C(UnkStruct_ov16_0220196C *unk) {
static void ov16_02201A4C(UnkStruct_ov16_0220196C *unk) {
FreeToHeap(unk->cursor2);
FreeToHeap(unk->cursor1);
}
u32 ov16_02201A60(UnkStruct_ov16_0220196C *unk) {
static u32 ov16_02201A60(UnkStruct_ov16_0220196C *unk) {
unk->ovyManager = OverlayManager_New(&ov16_02201B68, unk, unk->heapId);
return 1;
}
u32 ov16_02201A78(UnkStruct_ov16_0220196C *unk) {
static u32 ov16_02201A78(UnkStruct_ov16_0220196C *unk) {
if (!ov16_02201948(&unk->ovyManager)) {
return 1;
}
@ -152,14 +149,14 @@ u32 ov16_02201A78(UnkStruct_ov16_0220196C *unk) {
return 4;
}
u32 ov16_02201AA0(UnkStruct_ov16_0220196C *unk) {
static u32 ov16_02201AA0(UnkStruct_ov16_0220196C *unk) {
Bag *bag = Save_Bag_Get(unk->args->savedata);
switch (unk->unk14) {
case 1:
unused_02201BA0 = (u8*)_02201B60;
unused_02201BA0 = (u8*)ov16_02201B60;
unk->bagView = Bag_CreateView(bag, _02201B60, unk->heapId);
unk->bagView = Bag_CreateView(bag, ov16_02201B60, unk->heapId);
sub_0207789C(unk->bagView, unk->args->savedata, 6, unk->cursor2, unk->args->unk4);
break;
case 2:
@ -177,7 +174,7 @@ u32 ov16_02201AA0(UnkStruct_ov16_0220196C *unk) {
return 3;
}
u32 ov16_02201B24(UnkStruct_ov16_0220196C *unk) {
static u32 ov16_02201B24(UnkStruct_ov16_0220196C *unk) {
if (!ov16_02201948(&unk->ovyManager)) {
return 3;
}

View File

@ -6,13 +6,13 @@
#include "msgdata/msg/msg_0295.h"
#include "msgdata/msg/msg_0287.h"
void Save_BerryPots_Init(BERRY_POT *berryPot) {
void Save_BerryPots_Init(BERRY_POT *berryPots) {
int i;
MI_CpuClear8(berryPot, MAX_BERRY_POT * sizeof(BERRY_POT));
MI_CpuClear8(berryPots, MAX_BERRY_POT * sizeof(BERRY_POT));
for (i = 0; i < MAX_BERRY_POT; i++) {
berryPot[i].unk_1 = 0;
berryPot[i].unk_0 = 0;
berryPots[i].growthStage = BERRY_POT_GROWTH_STAGE_INVALID;
berryPots[i].berryId = 0;
}
}