Document decoration.c
This commit is contained in:
+28
-58
@@ -1,71 +1,51 @@
|
||||
|
||||
// Includes
|
||||
#include "global.h"
|
||||
#include "constants/decorations.h"
|
||||
#include "decoration.h"
|
||||
#include "decoration_inventory.h"
|
||||
|
||||
// Static type declarations
|
||||
|
||||
// Static RAM declarations
|
||||
|
||||
EWRAM_DATA struct DecorationInventory gDecorationInventories[8] = {};
|
||||
|
||||
// Static ROM declarations
|
||||
|
||||
// .rodata
|
||||
|
||||
// .text
|
||||
EWRAM_DATA struct DecorationInventory gDecorationInventories[DECORCAT_COUNT] = {};
|
||||
|
||||
#define SET_DECOR_INV(i, ptr) {\
|
||||
gDecorationInventories[i].items = ptr;\
|
||||
gDecorationInventories[i].size = sizeof(ptr);\
|
||||
gDecorationInventories[i].size = ARRAY_COUNT(ptr);\
|
||||
}
|
||||
|
||||
void SetDecorationInventoriesPointers(void)
|
||||
{
|
||||
SET_DECOR_INV(0, gSaveBlock1Ptr->decorDesk);
|
||||
SET_DECOR_INV(1, gSaveBlock1Ptr->decorChair);
|
||||
SET_DECOR_INV(2, gSaveBlock1Ptr->decorPlant);
|
||||
SET_DECOR_INV(3, gSaveBlock1Ptr->decorOrnament);
|
||||
SET_DECOR_INV(4, gSaveBlock1Ptr->decorMat);
|
||||
SET_DECOR_INV(5, gSaveBlock1Ptr->decorPoster);
|
||||
SET_DECOR_INV(6, gSaveBlock1Ptr->decorDoll);
|
||||
SET_DECOR_INV(7, gSaveBlock1Ptr->decorCushion);
|
||||
SET_DECOR_INV(DECORCAT_DESK, gSaveBlock1Ptr->decorationDesks);
|
||||
SET_DECOR_INV(DECORCAT_CHAIR, gSaveBlock1Ptr->decorationChairs);
|
||||
SET_DECOR_INV(DECORCAT_PLANT, gSaveBlock1Ptr->decorationPlants);
|
||||
SET_DECOR_INV(DECORCAT_ORNAMENT, gSaveBlock1Ptr->decorationOrnaments);
|
||||
SET_DECOR_INV(DECORCAT_MAT, gSaveBlock1Ptr->decorationMats);
|
||||
SET_DECOR_INV(DECORCAT_POSTER, gSaveBlock1Ptr->decorationPosters);
|
||||
SET_DECOR_INV(DECORCAT_DOLL, gSaveBlock1Ptr->decorationDolls);
|
||||
SET_DECOR_INV(DECORCAT_CUSHION, gSaveBlock1Ptr->decorationCushions);
|
||||
InitDecorationContextItems();
|
||||
}
|
||||
|
||||
static void ClearDecorationInventory(u8 idx)
|
||||
static void ClearDecorationInventory(u8 category)
|
||||
{
|
||||
u8 i;
|
||||
|
||||
for (i = 0; i < gDecorationInventories[idx].size; i ++)
|
||||
{
|
||||
gDecorationInventories[idx].items[i] = DECOR_NONE;
|
||||
}
|
||||
for (i = 0; i < gDecorationInventories[category].size; i ++)
|
||||
gDecorationInventories[category].items[i] = DECOR_NONE;
|
||||
}
|
||||
|
||||
void ClearDecorationInventories(void)
|
||||
{
|
||||
u8 idx;
|
||||
|
||||
for (idx = 0; idx < 8; idx ++)
|
||||
{
|
||||
ClearDecorationInventory(idx);
|
||||
}
|
||||
u8 category;
|
||||
for (category = 0; category < 8; category++)
|
||||
ClearDecorationInventory(category);
|
||||
}
|
||||
|
||||
s8 GetFirstEmptyDecorSlot(u8 idx)
|
||||
s8 GetFirstEmptyDecorSlot(u8 category)
|
||||
{
|
||||
s8 i;
|
||||
|
||||
for (i = 0; i < (s8)gDecorationInventories[idx].size; i ++)
|
||||
for (i = 0; i < (s8)gDecorationInventories[category].size; i++)
|
||||
{
|
||||
if (gDecorationInventories[idx].items[i] == DECOR_NONE)
|
||||
{
|
||||
if (gDecorationInventories[category].items[i] == DECOR_NONE)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -78,10 +58,9 @@ bool8 CheckHasDecoration(u8 decor)
|
||||
for (i = 0; i < gDecorationInventories[category].size; i ++)
|
||||
{
|
||||
if (gDecorationInventories[category].items[i] == decor)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -91,15 +70,11 @@ bool8 DecorationAdd(u8 decor)
|
||||
s8 idx;
|
||||
|
||||
if (decor == DECOR_NONE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
category = gDecorations[decor].category;
|
||||
idx = GetFirstEmptyDecorSlot(category);
|
||||
if (idx == -1)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
gDecorationInventories[category].items[idx] = decor;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -107,13 +82,9 @@ bool8 DecorationAdd(u8 decor)
|
||||
bool8 DecorationCheckSpace(u8 decor)
|
||||
{
|
||||
if (decor == DECOR_NONE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (GetFirstEmptyDecorSlot(gDecorations[decor].category) == -1)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -124,9 +95,8 @@ s8 DecorationRemove(u8 decor)
|
||||
|
||||
i = 0;
|
||||
if (decor == DECOR_NONE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < gDecorationInventories[gDecorations[decor].category].size; i ++)
|
||||
{
|
||||
category = gDecorations[decor].category;
|
||||
@@ -137,6 +107,7 @@ s8 DecorationRemove(u8 decor)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -160,19 +131,18 @@ void CondenseDecorationsInCategory(u8 category)
|
||||
}
|
||||
}
|
||||
|
||||
u8 GetNumOwnedDecorationsInCategory(u8 idx)
|
||||
u8 GetNumOwnedDecorationsInCategory(u8 category)
|
||||
{
|
||||
u8 i;
|
||||
u8 ct;
|
||||
|
||||
ct = 0;
|
||||
for (i = 0; i < gDecorationInventories[idx].size; i ++)
|
||||
for (i = 0; i < gDecorationInventories[category].size; i++)
|
||||
{
|
||||
if (gDecorationInventories[idx].items[i] != DECOR_NONE)
|
||||
{
|
||||
ct ++;
|
||||
}
|
||||
if (gDecorationInventories[category].items[i] != DECOR_NONE)
|
||||
ct++;
|
||||
}
|
||||
|
||||
return ct;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user