Skip to content

Commit

Permalink
zip poffin structs into poffin.h change func names
Browse files Browse the repository at this point in the history
  • Loading branch information
fakuzatsu committed Jan 18, 2025
1 parent c399b54 commit 2b21d7b
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 87 deletions.
3 changes: 1 addition & 2 deletions include/overlay082/struct_ov82_0223B164.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#ifndef POKEPLATINUM_STRUCT_OV82_0223B164_H
#define POKEPLATINUM_STRUCT_OV82_0223B164_H

#include "struct_decls/poffin_case_decl.h"

#include "bag.h"
#include "game_options.h"
#include "journal.h"
#include "poffin.h"
#include "savedata.h"
#include "trainer_info.h"

Expand Down
4 changes: 2 additions & 2 deletions include/overlay083/ov83_0223F7F4.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef POKEPLATINUM_OV83_0223F7F4_H
#define POKEPLATINUM_OV83_0223F7F4_H

#include "struct_defs/poffin.h"

#include "overlay083/struct_ov83_0223F820.h"
#include "overlay083/struct_ov83_0223F88C.h"
#include "overlay083/struct_ov83_0223F8AC.h"
Expand All @@ -14,6 +12,8 @@
#include "overlay083/struct_ov83_0223FDB0_sub1.h"
#include "overlay083/struct_ov83_0223FE50.h"

#include "poffin.h"

s32 ov83_0223F7F4(int param0, int param1, int param2, int param3, int param4, int param5);
void ov83_0223F820(UnkStruct_ov83_0223F820 *param0);
void ov83_0223F83C(UnkStruct_ov83_0223F820 *param0);
Expand Down
3 changes: 1 addition & 2 deletions include/overlay083/struct_ov83_0223FE50.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#ifndef POKEPLATINUM_STRUCT_OV83_0223FE50_H
#define POKEPLATINUM_STRUCT_OV83_0223FE50_H

#include "struct_defs/poffin.h"

#include "overlay083/struct_ov83_0223D2E8.h"
#include "overlay083/struct_ov83_0223DB4C.h"
#include "overlay083/struct_ov83_0223DB4C_sub1.h"
#include "overlay083/struct_ov83_022401AC.h"

#include "poffin.h"
#include "trainer_info.h"

typedef struct {
Expand Down
31 changes: 24 additions & 7 deletions include/poffin.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
#ifndef POKEPLATINUM_POFFIN_H
#define POKEPLATINUM_POFFIN_H

#include "struct_decls/poffin_case_decl.h"
#include "struct_defs/poffin.h"

#include "savedata.h"

#define POFFIN_NONE 0xFFFF
#define MAX_POFFINS 100

typedef struct {
union {
struct {
u8 flavor;
u8 spiciness;
u8 dryness;
u8 sweetness;
u8 bitterness;
u8 sourness;
u8 val1_06;
u8 dummy;
};
u8 attributes[8];
};
} Poffin;

typedef struct PoffinCase {
Poffin slot[MAX_POFFINS];
} PoffinCase;

typedef enum {
POFFIN_ATTRIBUTEID_FLAVOR,
POFFIN_ATTRIBUTEID_SPICINESS,
Expand All @@ -20,11 +37,11 @@ typedef enum {
POFFIN_ATTRIBUTEID_NUM
} PoffinAttributeID;

int Poffin_sizeof(void);
int Poffin_SizeOf(void);
BOOL Poffin_HasValidFlavor(Poffin *poffin);
void Poffin_clear(Poffin *poffin);
Poffin *Poffin_malloc(int heapID);
void Poffin_copy(Poffin *src, Poffin *dest);
void Poffin_Clear(Poffin *poffin);
Poffin *Poffin_New(int heapID);
void Poffin_Copy(Poffin *src, Poffin *dest);
u8 Poffin_GetAttribute(Poffin *poffin, PoffinAttributeID attributeID);
int sub_0202A9E4(Poffin *poffin, u8 *param1, u8 param2, BOOL isFoul);
void Poffin_StoreAttributesToArray(Poffin *poffin, u8 *dest);
Expand Down
6 changes: 0 additions & 6 deletions include/struct_decls/poffin_case_decl.h

This file was deleted.

20 changes: 0 additions & 20 deletions include/struct_defs/poffin.h

This file was deleted.

10 changes: 0 additions & 10 deletions include/struct_defs/poffin_case.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/struct_defs/struct_0203D9B8.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef POKEPLATINUM_STRUCT_0203D9B8_H
#define POKEPLATINUM_STRUCT_0203D9B8_H

#include "struct_decls/poffin_case_decl.h"
#include "struct_decls/struct_party_decl.h"
#include "struct_defs/struct_020989DC.h"

#include "bag.h"
#include "game_options.h"
#include "poffin.h"
#include "trainer_info.h"

typedef struct {
Expand Down
3 changes: 1 addition & 2 deletions include/struct_defs/struct_02098DE8.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef POKEPLATINUM_STRUCT_02098DE8_H
#define POKEPLATINUM_STRUCT_02098DE8_H

#include "struct_defs/poffin.h"

#include "poffin.h"
#include "pokemon.h"

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion include/unk_020989DC.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef POKEPLATINUM_UNK_020989DC_H
#define POKEPLATINUM_UNK_020989DC_H

#include "struct_defs/poffin.h"
#include "struct_defs/struct_0203D9B8.h"

#include "enums.h"
#include "poffin.h"
#include "pokemon.h"
#include "savedata.h"

Expand Down
7 changes: 3 additions & 4 deletions src/overlay083/ov83_0223B5A0.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "struct_decls/struct_0202440C_decl.h"
#include "struct_decls/struct_0202B370_decl.h"
#include "struct_defs/poffin.h"

#include "overlay004/ov4_021D0D80.h"
#include "overlay083/ov83_0223C958.h"
Expand Down Expand Up @@ -598,9 +597,9 @@ static int ov83_0223BCEC(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78
break;
case 4:
if (ov83_0223D570(param1->unk_148C) == 0) {
v0 = Poffin_malloc(param1->unk_00);
v0 = Poffin_New(param1->unk_00);
ov83_0223FFD4(&param1->unk_34C, v0, &param1->unk_1494, param1->unk_1488, param1->unk_00);
v1 = ov83_0223D508(28, v0, Poffin_sizeof(), param1->unk_148C);
v1 = ov83_0223D508(28, v0, Poffin_SizeOf(), param1->unk_148C);
Heap_FreeToHeap(v0);

if (v1 == 1) {
Expand Down Expand Up @@ -1058,7 +1057,7 @@ static void ov83_0223C82C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B7
{
int v0;

param1->unk_1494.unk_100 = Poffin_malloc(param1->unk_00);
param1->unk_1494.unk_100 = Poffin_New(param1->unk_00);
param1->unk_1494.unk_144 = ov83_0223D570(param1->unk_148C);

for (v0 = 0; v0 < 4; v0++) {
Expand Down
2 changes: 1 addition & 1 deletion src/overlay083/ov83_0223D144.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static const CommCmdTable Unk_ov83_02240390[] = {
{ ov83_0223D258, ov83_0223D4B8, NULL },
{ ov83_0223D2E8, ov83_0223D4BC, NULL },
{ ov83_0223D3D8, ov83_0223D4C0, NULL },
{ ov83_0223D3F8, Poffin_sizeof, NULL },
{ ov83_0223D3F8, Poffin_SizeOf, NULL },
{ ov83_0223D410, ov83_0223D4B0, NULL },
{ ov83_0223D430, ov83_0223D4B0, NULL },
{ ov83_0223D354, ov83_0223D4C4, NULL },
Expand Down
2 changes: 0 additions & 2 deletions src/overlay083/ov83_0223F7F4.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <nitro.h>
#include <string.h>

#include "struct_defs/poffin.h"

#include "overlay083/struct_ov83_0223DB4C_sub1.h"
#include "overlay083/struct_ov83_0223F820.h"
#include "overlay083/struct_ov83_0223F88C.h"
Expand Down
41 changes: 19 additions & 22 deletions src/poffin.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
#include <nitro.h>
#include <string.h>

#include "struct_defs/poffin.h"
#include "struct_defs/poffin_case.h"

#include "heap.h"
#include "math.h"
#include "savedata.h"

#define FLAVOR_NONE 30

int Poffin_sizeof(void)
int Poffin_SizeOf(void)
{
return sizeof(Poffin);
}
Expand All @@ -26,7 +23,7 @@ BOOL Poffin_HasValidFlavor(Poffin *poffin)
return TRUE;
}

void Poffin_clear(Poffin *poffin)
void Poffin_Clear(Poffin *poffin)
{
poffin->flavor = FLAVOR_NONE;
poffin->spiciness = 0;
Expand All @@ -38,17 +35,17 @@ void Poffin_clear(Poffin *poffin)
poffin->dummy = 0;
}

Poffin *Poffin_malloc(int heapID)
Poffin *Poffin_New(int heapID)
{
Poffin *poffin;

poffin = Heap_AllocFromHeapAtEnd(heapID, sizeof(Poffin));
Poffin_clear(poffin);
Poffin_Clear(poffin);

return poffin;
}

void Poffin_copy(Poffin *src, Poffin *dest)
void Poffin_Copy(Poffin *src, Poffin *dest)
{
dest->flavor = src->flavor;
dest->spiciness = src->spiciness;
Expand Down Expand Up @@ -81,7 +78,7 @@ u8 Poffin_GetAttribute(Poffin *poffin, PoffinAttributeID attributeID)
}
}

static void MakePoffinFoul(Poffin *poffin, u8 param1)
static void Poffin_MakeFoul(Poffin *poffin, u8 param1)
{
int v0;
u8 v1;
Expand Down Expand Up @@ -112,7 +109,7 @@ int sub_0202A9E4(Poffin *poffin, u8 *param1, u8 param2, BOOL isFoul)
v4 = 27;

if (isFoul) {
MakePoffinFoul(poffin, param2);
Poffin_MakeFoul(poffin, param2);
return v4;
}

Expand All @@ -128,7 +125,7 @@ int sub_0202A9E4(Poffin *poffin, u8 *param1, u8 param2, BOOL isFoul)

switch (v1) {
case 0:
MakePoffinFoul(poffin, param2);
Poffin_MakeFoul(poffin, param2);
return v4;
case 1:
v4 = v2[0] * 5 + v2[0];
Expand Down Expand Up @@ -241,7 +238,7 @@ void Poffin_Init(PoffinCase *poffinCase)
int i;

for (i = 0; i < MAX_POFFINS; i++) {
Poffin_clear(&poffinCase->slot[i]);
Poffin_Clear(&poffinCase->slot[i]);
}
}

Expand All @@ -266,7 +263,7 @@ u16 Poffin_AddToCase(PoffinCase *poffinCase, Poffin *poffin)
return slotId;
}

Poffin_copy(poffin, &poffinCase->slot[slotId]);
Poffin_Copy(poffin, &poffinCase->slot[slotId]);
return slotId;
}

Expand All @@ -276,7 +273,7 @@ BOOL Poffin_ClearCaseSlot(PoffinCase *poffinCase, u16 slot)
return FALSE;
}

Poffin_clear(&poffinCase->slot[slot]);
Poffin_Clear(&poffinCase->slot[slot]);
return TRUE;
}

Expand Down Expand Up @@ -313,14 +310,14 @@ void Poffin_CompactCase(PoffinCase *poffinCase)

if (nextValidSlotNum == POFFIN_NONE) {
break;
} // skips rest of execution, reached end of poffin case
}

targetSlotNum = nextValidSlotNum;
nextValidSlotNum = targetSlotNum - emptySlotNum;

for (; targetSlotNum < remainingSlots; emptySlotNum++, targetSlotNum++) {
Poffin_copy(&poffinCase->slot[targetSlotNum], &poffinCase->slot[emptySlotNum]);
Poffin_clear(&poffinCase->slot[targetSlotNum]);
Poffin_Copy(&poffinCase->slot[targetSlotNum], &poffinCase->slot[emptySlotNum]);
Poffin_Clear(&poffinCase->slot[targetSlotNum]);
}

remainingSlots -= nextValidSlotNum;
Expand All @@ -330,26 +327,26 @@ void Poffin_CompactCase(PoffinCase *poffinCase)
void Poffin_CopyToCaseSlot(PoffinCase *poffinCase, u16 destSlot, Poffin *poffin)
{
if (destSlot >= MAX_POFFINS) {
Poffin_clear(poffin);
Poffin_Clear(poffin);
return;
}

Poffin_copy(&poffinCase->slot[destSlot], poffin);
Poffin_Copy(&poffinCase->slot[destSlot], poffin);
return;
}

Poffin *Poffin_AllocateForCaseSlot(PoffinCase *poffinCase, u16 destSlot, int heapID)
{
Poffin *poffin;

poffin = Poffin_malloc(heapID);
poffin = Poffin_New(heapID);

if (destSlot >= MAX_POFFINS) {
Poffin_clear(poffin);
Poffin_Clear(poffin);
return NULL;
}

Poffin_copy(&poffinCase->slot[destSlot], poffin);
Poffin_Copy(&poffinCase->slot[destSlot], poffin);
return poffin;
}

Expand Down
4 changes: 1 addition & 3 deletions src/scrcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "consts/journal.h"
#include "consts/scrcmd.h"

#include "struct_decls/poffin_case_decl.h"
#include "struct_decls/pokedexdata_decl.h"
#include "struct_decls/struct_02014EC4_decl.h"
#include "struct_decls/struct_0202440C_decl.h"
Expand All @@ -33,7 +32,6 @@
#include "struct_decls/struct_020797DC_decl.h"
#include "struct_decls/struct_party_decl.h"
#include "struct_defs/choose_starter_data.h"
#include "struct_defs/poffin.h"
#include "struct_defs/struct_0202D7B0.h"
#include "struct_defs/struct_0202DF8C.h"
#include "struct_defs/struct_0203D8AC.h"
Expand Down Expand Up @@ -7383,7 +7381,7 @@ static BOOL ScrCmd_289(ScriptContext *ctx)
}

v4 = ScriptContext_GetVar(ctx);
v0 = Poffin_malloc(4);
v0 = Poffin_New(4);
v1 = sub_0202A9E4(v0, v3, v4, 0);
v2 = Poffin_GetSavedataBlock(ctx->fieldSystem->saveData);
v5 = Poffin_AddToCase(v2, v0);
Expand Down
Loading

0 comments on commit 2b21d7b

Please sign in to comment.