Document decoration.c

This commit is contained in:
Martin Griffin 2020-02-23 15:46:22 +00:00
parent a85587d8c2
commit 4485d51522
13 changed files with 590 additions and 595 deletions

View File

@ -301,7 +301,7 @@ SecretBase_EventScript_PutAwayDecoration:: @ 8275D2E
end end
SecretBase_EventScript_PutAwayDecorationLoop:: @ 8275D39 SecretBase_EventScript_PutAwayDecorationLoop:: @ 8275D39
special sub_8129708 special PutAwayDecorationIteration
compare VAR_RESULT, 1 compare VAR_RESULT, 1
goto_if_eq SecretBase_EventScript_PutAwayDecorationEnd goto_if_eq SecretBase_EventScript_PutAwayDecorationEnd
addvar VAR_0x8004, 1 addvar VAR_0x8004, 1

View File

@ -31,7 +31,7 @@ gSpecials:: @ 81DBA64
def_special GetObjectEventLocalIdByFlag def_special GetObjectEventLocalIdByFlag
def_special GetSecretBaseTypeInFrontOfPlayer def_special GetSecretBaseTypeInFrontOfPlayer
def_special SetSecretBaseOwnerGfxId def_special SetSecretBaseOwnerGfxId
def_special sub_8129708 def_special PutAwayDecorationIteration
def_special EnterNewlyCreatedSecretBase def_special EnterNewlyCreatedSecretBase
def_special SetBattledOwnerFromResult def_special SetBattledOwnerFromResult
def_special DoSecretBasePCTurnOffEffect def_special DoSecretBasePCTurnOffEffect

View File

Before

Width:  |  Height:  |  Size: 87 B

After

Width:  |  Height:  |  Size: 87 B

View File

@ -52,14 +52,6 @@ struct Decoration
const u16 *tiles; const u16 *tiles;
}; };
struct DecorationPCContext
{
u8 *items;
u8 *pos;
u8 size;
u8 isPlayerRoom;
};
extern const struct Decoration gDecorations[]; extern const struct Decoration gDecorations[];
extern EWRAM_DATA u8 *gCurDecorationItems; extern EWRAM_DATA u8 *gCurDecorationItems;
extern EWRAM_DATA u8 gCurDecorationIndex; extern EWRAM_DATA u8 gCurDecorationIndex;

View File

@ -12,10 +12,10 @@ extern struct DecorationInventory gDecorationInventories[];
void SetDecorationInventoriesPointers(void); void SetDecorationInventoriesPointers(void);
void ClearDecorationInventories(void); void ClearDecorationInventories(void);
s8 GetFirstEmptyDecorSlot(u8 category); s8 GetFirstEmptyDecorSlot(u8 category);
u8 CheckHasDecoration(u8); u8 CheckHasDecoration(u8 decor);
u8 DecorationAdd(u8); u8 DecorationAdd(u8 decor);
u8 DecorationCheckSpace(u8); u8 DecorationCheckSpace(u8 decor);
s8 DecorationRemove(u8); s8 DecorationRemove(u8 decor);
void CondenseDecorationsInCategory(u8 category); void CondenseDecorationsInCategory(u8 category);
u8 GetNumOwnedDecorationsInCategory(u8 category); u8 GetNumOwnedDecorationsInCategory(u8 category);
u8 GetNumOwnedDecorations(void); u8 GetNumOwnedDecorations(void);

View File

@ -637,7 +637,7 @@ struct MauvilleManHipster
struct MauvilleOldManTrader struct MauvilleOldManTrader
{ {
u8 id; u8 id;
u8 decorIds[NUM_TRADER_ITEMS]; u8 decorations[NUM_TRADER_ITEMS];
u8 playerNames[NUM_TRADER_ITEMS][11]; u8 playerNames[NUM_TRADER_ITEMS][11];
u8 alreadyTraded; u8 alreadyTraded;
u8 language[NUM_TRADER_ITEMS]; u8 language[NUM_TRADER_ITEMS];
@ -928,16 +928,16 @@ struct SaveBlock1
/*0x159C*/ u32 gameStats[NUM_GAME_STATS]; /*0x159C*/ u32 gameStats[NUM_GAME_STATS];
/*0x169C*/ struct BerryTree berryTrees[BERRY_TREES_COUNT]; /*0x169C*/ struct BerryTree berryTrees[BERRY_TREES_COUNT];
/*0x1A9C*/ struct SecretBase secretBases[SECRET_BASES_COUNT]; /*0x1A9C*/ struct SecretBase secretBases[SECRET_BASES_COUNT];
/*0x271C*/ u8 playerRoomDecor[DECOR_MAX_PLAYERS_HOUSE]; /*0x271C*/ u8 playerRoomDecorations[DECOR_MAX_PLAYERS_HOUSE];
/*0x2728*/ u8 playerRoomDecorPos[DECOR_MAX_PLAYERS_HOUSE]; /*0x2728*/ u8 playerRoomDecorationPositions[DECOR_MAX_PLAYERS_HOUSE];
/*0x2734*/ u8 decorDesk[10]; /*0x2734*/ u8 decorationDesks[10];
/*0x273E*/ u8 decorChair[10]; /*0x273E*/ u8 decorationChairs[10];
/*0x2748*/ u8 decorPlant[10]; /*0x2748*/ u8 decorationPlants[10];
/*0x2752*/ u8 decorOrnament[30]; /*0x2752*/ u8 decorationOrnaments[30];
/*0x2770*/ u8 decorMat[30]; /*0x2770*/ u8 decorationMats[30];
/*0x278E*/ u8 decorPoster[10]; /*0x278E*/ u8 decorationPosters[10];
/*0x2798*/ u8 decorDoll[40]; /*0x2798*/ u8 decorationDolls[40];
/*0x27C0*/ u8 decorCushion[10]; /*0x27C0*/ u8 decorationCushions[10];
/*0x27CA*/ u8 padding_27CA[2]; /*0x27CA*/ u8 padding_27CA[2];
/*0x27CC*/ TVShow tvShows[TV_SHOWS_COUNT]; /*0x27CC*/ TVShow tvShows[TV_SHOWS_COUNT];
/*0x2B50*/ PokeNews pokeNews[POKE_NEWS_COUNT]; /*0x2B50*/ PokeNews pokeNews[POKE_NEWS_COUNT];

View File

@ -5,7 +5,7 @@
#ifndef GUARD_TRADER_H #ifndef GUARD_TRADER_H
#define GUARD_TRADER_H #define GUARD_TRADER_H
void sub_8133DA0(u8 taskId); void DecorationItemsMenuAction_Trade(u8 taskId);
void ExitTraderMenu(u8 taskId); void ExitTraderMenu(u8 taskId);
void TraderSetup(void); void TraderSetup(void);
void Trader_ResetFlag(void); void Trader_ResetFlag(void);

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -543,23 +543,23 @@ void InitSecretBaseDecorationSprites(void)
objectEventId = 0; objectEventId = 0;
if (!CurMapIsSecretBase()) if (!CurMapIsSecretBase())
{ {
decorations = gSaveBlock1Ptr->playerRoomDecor; decorations = gSaveBlock1Ptr->playerRoomDecorations;
decorationPositions = gSaveBlock1Ptr->playerRoomDecorPos; decorationPositions = gSaveBlock1Ptr->playerRoomDecorationPositions;
numDecorations = 12; numDecorations = DECOR_MAX_PLAYERS_HOUSE;
} }
else else
{ {
u16 secretBaseId = VarGet(VAR_CURRENT_SECRET_BASE); u16 secretBaseId = VarGet(VAR_CURRENT_SECRET_BASE);
decorations = gSaveBlock1Ptr->secretBases[secretBaseId].decorations; decorations = gSaveBlock1Ptr->secretBases[secretBaseId].decorations;
decorationPositions = gSaveBlock1Ptr->secretBases[secretBaseId].decorationPositions; decorationPositions = gSaveBlock1Ptr->secretBases[secretBaseId].decorationPositions;
numDecorations = 16; numDecorations = DECOR_MAX_SECRET_BASE;
} }
for (i = 0; i < numDecorations; i++) for (i = 0; i < numDecorations; i++)
{ {
if (decorations[i] == DECOR_NONE) if (decorations[i] == DECOR_NONE)
continue; continue;
permission = gDecorations[decorations[i]].permission; permission = gDecorations[decorations[i]].permission;
category = gDecorations[decorations[i]].category; category = gDecorations[decorations[i]].category;
if (permission == DECORPERM_SPRITE) if (permission == DECORPERM_SPRITE)

View File

@ -42,7 +42,7 @@ void TraderSetup(void)
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
StringCopy(trader->playerNames[i], sDefaultTraderNames[i]); StringCopy(trader->playerNames[i], sDefaultTraderNames[i]);
trader->decorIds[i] = sDefaultTraderDecorations[i]; trader->decorations[i] = sDefaultTraderDecorations[i];
trader->language[i] = GAME_LANGUAGE; trader->language[i] = GAME_LANGUAGE;
} }
} }
@ -64,10 +64,10 @@ void CreateAvailableDecorationsMenu(u8 taskId)
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
s32 curWidth; s32 curWidth;
if (trader->decorIds[i] > NUM_DECORATIONS) if (trader->decorations[i] > NUM_DECORATIONS)
curWidth = fiveMarksWidth; curWidth = fiveMarksWidth;
else else
curWidth = GetStringWidth(1, gDecorations[trader->decorIds[i]].name, 0); curWidth = GetStringWidth(1, gDecorations[trader->decorations[i]].name, 0);
if (curWidth > windowWidth) if (curWidth > windowWidth)
windowWidth = curWidth; windowWidth = curWidth;
} }
@ -76,10 +76,10 @@ void CreateAvailableDecorationsMenu(u8 taskId)
DrawStdFrameWithCustomTileAndPalette(data[3], FALSE, 0x214, 14); DrawStdFrameWithCustomTileAndPalette(data[3], FALSE, 0x214, 14);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
if (trader->decorIds[i] > NUM_DECORATIONS) if (trader->decorations[i] > NUM_DECORATIONS)
AddTextPrinterParameterized(data[3], 1, gText_FiveMarks, 8, 16 * i + 1, 255, NULL); AddTextPrinterParameterized(data[3], 1, gText_FiveMarks, 8, 16 * i + 1, 255, NULL);
else else
AddTextPrinterParameterized(data[3], 1, gDecorations[trader->decorIds[i]].name, 8, 16 * i + 1, 255, NULL); AddTextPrinterParameterized(data[3], 1, gDecorations[trader->decorations[i]].name, 8, 16 * i + 1, 255, NULL);
} }
AddTextPrinterParameterized(data[3], 1, gText_Exit, 8, 16 * i + 1, 255, NULL); AddTextPrinterParameterized(data[3], 1, gText_Exit, 8, 16 * i + 1, 255, NULL);
InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[3], 5, 0); InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[3], 5, 0);
@ -125,7 +125,7 @@ void Task_HandleGetDecorationMenuInput(u8 taskId)
gSpecialVar_0x8005 = input; gSpecialVar_0x8005 = input;
StringCopy(gStringVar1, trader->playerNames[input]); StringCopy(gStringVar1, trader->playerNames[input]);
ConvertInternationalString(gStringVar1, trader->language[input]); ConvertInternationalString(gStringVar1, trader->language[input]);
Task_BufferDecorSelectionAndCloseWindow(taskId, trader->decorIds[input]); Task_BufferDecorSelectionAndCloseWindow(taskId, trader->decorations[input]);
break; break;
} }
} }
@ -167,7 +167,7 @@ void ScrSpecial_TraderMenuGiveDecoration(void)
CreateTask(ShowDecorationCategoriesWindow, 0); CreateTask(ShowDecorationCategoriesWindow, 0);
} }
void sub_8133DA0(u8 taskId) void DecorationItemsMenuAction_Trade(u8 taskId)
{ {
if (IsSelectedDecorInThePC() == TRUE) if (IsSelectedDecorInThePC() == TRUE)
{ {
@ -197,7 +197,7 @@ void ScrSpecial_TraderDoDecorationTrade(void)
DecorationRemove(gSpecialVar_0x8006); DecorationRemove(gSpecialVar_0x8006);
DecorationAdd(gSpecialVar_0x8004); DecorationAdd(gSpecialVar_0x8004);
StringCopy(trader->playerNames[gSpecialVar_0x8005], gSaveBlock2Ptr->playerName); StringCopy(trader->playerNames[gSpecialVar_0x8005], gSaveBlock2Ptr->playerName);
trader->decorIds[gSpecialVar_0x8005] = gSpecialVar_0x8006; trader->decorations[gSpecialVar_0x8005] = gSpecialVar_0x8006;
trader->language[gSpecialVar_0x8005] = GAME_LANGUAGE; trader->language[gSpecialVar_0x8005] = GAME_LANGUAGE;
trader->alreadyTraded = TRUE; trader->alreadyTraded = TRUE;
} }