Skip to content

Commit

Permalink
Document berry_data.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Nomura-RH committed Jul 30, 2023
1 parent d7f2733 commit 4e58427
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 165 deletions.
80 changes: 80 additions & 0 deletions include/berry_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef POKEPLATINUM_BERRY_DATA_H
#define POKEPLATINUM_BERRY_DATA_H

#include "struct_decls/struct_02006C24_decl.h"
#include "struct_decls/struct_02023790_decl.h"
#include "struct_decls/struct_berry_data_decl.h"

/*
* Constructs a new NARC which contains an open FSFile to the berry data archive.
*
* @param heapID: ID of the heap to alloc from
*
* @returns: Pointer to the newly-allocated NARC
*/
NARC * BerryData_NARC_ctor(u32 heapID);

BerryData * sub_020973A8(NARC * param0, u32 param1, u32 param2);

/*
* Closes the wrapped FSFile and returns the NARC allocation to the heap from whence it came.
*
* @param narc: Pointer to the NARC
*/
void BerryData_NARC_dtor(NARC * narc);

/*
* Creates a new buffer large enough to hold the data of the specified
* NARC member in 'nuts_data.narc', then reads the data.
*
* @param index: Index of the NARC member within 'nuts_data.narc' which contains the berry's data
* @param heapID: ID of the heap to alloc from
*
* @returns: Pointer to the allocated buffer which contains the data that was read.
*/
BerryData * BerryData_LoadDataByNarcMemberIndex(u32 index, u32 heapID);

/*
* Creates a new buffer large enough to hold the data of the
* specified berry, then reads the data from nuts_data.narc
*
* @param itemID: Item ID of the berry for which to read the data
* @param heapID: ID of the heap to alloc from
*
* @returns: Pointer to the allocated buffer which contains the data that was read.
*/
BerryData * BerryData_LoadDataByItemID(u32 itemID, u32 heapID);

/*
* Retrieves the value of the specified attribute from a BerryData buffer
*
* @param berryData: Pointer to the buffer holding the berry data
* @param attributeID: ID of the attribute to retrieve the value for
*
* @returns: The value of the specified attribute
*/
u32 BerryData_GetAttribute(BerryData * berryData, u32 attributeID);

/*
* Creates a new string buffer large enough to hold the
* name of the specified berry, then reads the string.
*
* @param index: Index of the NARC member within 'nuts_data.narc' which contains the berry's data
* @param heapID: ID of the heap to alloc from
*
* @returns: Pointer to the allocated buffer which contains the string that was read.
*/
Strbuf* BerryData_AllocAndGetName(u16 index, u32 heapID);

/*
* Creates a new string buffer large enough to hold the
* description of the specified berry, then reads the string.
*
* @param index: Index of the NARC member within 'nuts_data.narc' which contains the berry's data
* @param heapID: ID of the heap to alloc from
*
* @returns: Pointer to the allocated buffer which contains the string that was read.
*/
Strbuf* BerryData_AllocAndGetDescription(u16 index, u16 heapID);

#endif // POKEPLATINUM_BERRY_DATA_H
6 changes: 0 additions & 6 deletions include/struct_decls/struct_020973A8_decl.h

This file was deleted.

6 changes: 6 additions & 0 deletions include/struct_decls/struct_berry_data_decl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef POKEPLATINUM_STRUCT_BERRY_DATA_DECL_H
#define POKEPLATINUM_STRUCT_BERRY_DATA_DECL_H

typedef struct BerryData BerryData;

#endif // POKEPLATINUM_STRUCT_BERRY_DATA_DECL_H
17 changes: 0 additions & 17 deletions include/unk_0209739C.h

This file was deleted.

2 changes: 1 addition & 1 deletion platinum.us/main.lsf
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Static main
Object main.nef.p/src_unk_020961E8.c.o
Object main.nef.p/src_unk_02096420.c.o
Object main.nef.p/src_unk_020972FC.c.o
Object main.nef.p/src_unk_0209739C.c.o
Object main.nef.p/src_berry_data.c.o
Object main.nef.p/src_unk_0209747C.c.o
Object main.nef.p/src_unk_02097624.c.o
Object main.nef.p/src_unk_02097B18.c.o
Expand Down
103 changes: 103 additions & 0 deletions src/berry_data.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include <nitro.h>
#include <string.h>

#include "struct_decls/struct_02006C24_decl.h"
#include "struct_decls/struct_0200B144_decl.h"
#include "struct_decls/struct_02023790_decl.h"

#include "narc.h"
#include "unk_0200AC5C.h"
#include "berry_data.h"

typedef struct BerryData {
u16 size;
u8 firmness;
u8 yieldCategory;
u8 stageDuration;
u8 moistureDrainRate;
u8 spiciness;
u8 dryness;
u8 sweetness;
u8 bitterness;
u8 sourness;
u8 smoothness;
} BerryData;

NARC * BerryData_NARC_ctor (u32 heapID)
{
return NARC_ctor(68, heapID);
}

BerryData * sub_020973A8 (NARC * param0, u32 param1, u32 param2)
{
return NARC_AllocAndReadWholeMember(param0, 0 + param1, param2);
}

void BerryData_NARC_dtor (NARC * narc)
{
NARC_dtor(narc);
}

BerryData * BerryData_LoadDataByNarcMemberIndex (u32 index, u32 heapID)
{
return NARC_AllocAndReadWholeMemberByIndexPair(68, 0 + index, heapID);
}

BerryData * BerryData_LoadDataByItemID (u32 itemID, u32 heapID)
{
return BerryData_LoadDataByNarcMemberIndex(itemID - 149, heapID);
}

u32 BerryData_GetAttribute (BerryData * berryData, u32 attributeID)
{
switch (attributeID) {
case 0:
return berryData->size;
case 1:
return berryData->firmness;
case 2:
return berryData->yieldCategory;
case 3:
return berryData->stageDuration;
case 4:
return berryData->moistureDrainRate;
case 5:
return berryData->spiciness;
case 6:
return berryData->dryness;
case 7:
return berryData->sweetness;
case 8:
return berryData->bitterness;
case 9:
return berryData->sourness;
case 10:
return berryData->smoothness;
}

return 0;
}

Strbuf* BerryData_AllocAndGetName (u16 berryID, u32 heapID)
{
UnkStruct_0200B144 * v0;
Strbuf* v1;

v0 = sub_0200B144(1, 26, 424, heapID);
v1 = sub_0200B1EC(v0, berryID);

sub_0200B190(v0);
return v1;
}

Strbuf* BerryData_AllocAndGetDescription (u16 berryID, u16 heapID)
{
UnkStruct_0200B144 * v0;
Strbuf* v1;

v0 = sub_0200B144(1, 26, 423, heapID);
v1 = sub_0200B1EC(v0, berryID);

sub_0200B190(v0);
return v1;
}
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pokeplatinum_c = files(
'unk_020961E8.c',
'unk_02096420.c',
'unk_020972FC.c',
'unk_0209739C.c',
'berry_data.c',
'unk_0209747C.c',
'unk_02097624.c',
'unk_02097B18.c',
Expand Down
12 changes: 6 additions & 6 deletions src/overlay083/ov83_0223F7F4.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "data_021BF67C.h"

#include "struct_decls/struct_020973A8_decl.h"
#include "struct_decls/struct_berry_data_decl.h"

#include "struct_defs/struct_0202A93C.h"
#include "overlay083/struct_ov83_0223DB4C_sub1.h"
Expand All @@ -23,7 +23,7 @@
#include "unk_0201D15C.h"
#include "unk_0201E3BC.h"
#include "poffin.h"
#include "unk_0209739C.h"
#include "berry_data.h"
#include "overlay083/ov83_0223F7F4.h"

s32 ov83_0223F7F4 (int param0, int param1, int param2, int param3, int param4, int param5)
Expand Down Expand Up @@ -669,7 +669,7 @@ static int ov83_0223FFA8 (u32 param0, u32 param1)

void ov83_0223FFD4 (UnkStruct_ov83_0223FDB0 * param0, Poffin * param1, const UnkStruct_ov83_0223FE50 * param2, u32 param3, u32 param4)
{
UnkStruct_020973A8 * v0;
BerryData * v0;
int v1, v2;
const UnkStruct_ov83_0223DB4C_sub1 * v3 = param2->unk_34.unk_00;
s32 v4[5] = {0, 0, 0, 0, 0};
Expand All @@ -691,7 +691,7 @@ void ov83_0223FFD4 (UnkStruct_ov83_0223FDB0 * param0, Poffin * param1, const Unk

for (v1 = 0; v1 < param3; v1++) {
v17 = param2->unk_130[v1];
v0 = sub_020973C8(v3[v17].unk_00, param4);
v0 = BerryData_LoadDataByItemID(v3[v17].unk_00, param4);

v8 = 0;

Expand All @@ -708,10 +708,10 @@ void ov83_0223FFD4 (UnkStruct_ov83_0223FDB0 * param0, Poffin * param1, const Unk
}

for (v2 = 0; v2 < 5; v2++) {
v4[v2] += sub_020973D4(v0, 5 + v2);
v4[v2] += BerryData_GetAttribute(v0, 5 + v2);
}

v5 += sub_020973D4(v0, 10);
v5 += BerryData_GetAttribute(v0, 10);

Heap_FreeToHeap(v0);
}
Expand Down
Loading

0 comments on commit 4e58427

Please sign in to comment.