Document and cleanup some decoration code

This commit is contained in:
Marcus Huderle 2019-04-06 12:41:55 -05:00 committed by huderlem
parent 6a14cd418e
commit fe12f2f4b3
12 changed files with 1020 additions and 1080 deletions

View File

@ -1,7 +1,8 @@
#ifndef GUARD_DECORATION_H
#define GUARD_DECORATION_H
enum DecorPerm {
enum DecorationPermission
{
/*
* The nomenclature here describes collision and placement permissions, in that order.
*/
@ -9,13 +10,11 @@ enum DecorPerm {
DECORPERM_PASS_FLOOR,
DECORPERM_BEHIND_FLOOR,
DECORPERM_NA_WALL,
DECORPERM_SPRITE
DECORPERM_SPRITE,
};
enum DecorShape {
/*
* Width-x-height
*/
enum DecorationShape
{
DECORSHAPE_1x1,
DECORSHAPE_2x1,
DECORSHAPE_3x1, // unused
@ -25,53 +24,52 @@ enum DecorShape {
DECORSHAPE_1x3, // unused
DECORSHAPE_2x4,
DECORSHAPE_3x3,
DECORSHAPE_3x2
DECORSHAPE_3x2,
};
enum DecorCat {
/*
* In which category you can find the decoration in the PC.
*/
/*0*/ DECORCAT_DESK,
/*1*/ DECORCAT_CHAIR,
/*2*/ DECORCAT_PLANT,
/*3*/ DECORCAT_ORNAMENT,
/*4*/ DECORCAT_MAT,
/*5*/ DECORCAT_POSTER,
/*6*/ DECORCAT_DOLL,
/*7*/ DECORCAT_CUSHION
enum DecorationCategory
{
DECORCAT_DESK,
DECORCAT_CHAIR,
DECORCAT_PLANT,
DECORCAT_ORNAMENT,
DECORCAT_MAT,
DECORCAT_POSTER,
DECORCAT_DOLL,
DECORCAT_CUSHION,
DECORCAT_COUNT,
};
struct Decoration
{
/*0x00*/ u8 id;
/*0x01*/ u8 name[16];
/*0x11*/ u8 permission;
/*0x12*/ u8 shape;
/*0x13*/ u8 category;
/*0x14*/ u16 price;
/*0x18*/ const u8 *description;
/*0x1c*/ const u16 *tiles;
u8 id;
u8 name[16];
u8 permission;
u8 shape;
u8 category;
u16 price;
const u8 *description;
const u16 *tiles;
};
struct DecorPCPointers
struct DecorationPCContext
{
/* 0x00 */ u8 *items;
/* 0x04 */ u8 *pos;
/* 0x08 */ u8 size;
/* 0x09 */ u8 isPlayerRoom;
u8 *items;
u8 *pos;
u8 size;
u8 isPlayerRoom;
};
extern const struct Decoration gDecorations[];
extern EWRAM_DATA u8 *gCurDecorInventoryItems;
extern EWRAM_DATA u8 *gCurDecorationItems;
extern EWRAM_DATA u8 gCurDecorationIndex;
void sub_8126968(void);
void sub_8126AD8(u8 taskId);
void InitDecorationContextItems(void);
void DoSecretBaseDecorationMenu(u8 taskId);
void ShowDecorationOnMap(u16 mapX, u16 mapY, u16 decor);
void sub_8126B2C(u8 taskId);
void sub_8127208(u8 taskId);
void sub_8127250(u8 *dest, u8 decorCat);
void DoPlayerRoomDecorationMenu(u8 taskId);
void ShowDecorationCategoriesWindow(u8 taskId);
void CopyDecorationCategoryName(u8 *dest, u8 decorCat);
bool8 IsSelectedDecorInThePC(void);
u8 AddDecorationIconObject(u8 decor, s16 x, s16 y, u8 priority, u16 tilesTag, u16 paletteTag);

View File

@ -11,13 +11,13 @@ extern struct DecorationInventory gDecorationInventories[];
void SetDecorationInventoriesPointers(void);
void ClearDecorationInventories(void);
s8 GetFirstEmptyDecorSlot(u8 idx);
s8 GetFirstEmptyDecorSlot(u8 category);
u8 CheckHasDecoration(u8);
u8 DecorationAdd(u8);
u8 DecorationCheckSpace(u8);
s8 DecorationRemove(u8);
void CondenseDecorationCategoryN(u8);
u8 CountDecorationCategoryN(u8 idx);
u8 CountDecorations(void);
void CondenseDecorationsInCategory(u8 category);
u8 GetNumOwnedDecorationsInCategory(u8 category);
u8 GetNumOwnedDecorations(void);
#endif // GUARD_DECORATION_INVENTORY_H

View File

@ -107,8 +107,8 @@ struct OamData
#define SPRITE_SIZE_16x32 ((ST_OAM_SIZE_2 << 2) | (ST_OAM_V_RECTANGLE))
#define SPRITE_SIZE_32x64 ((ST_OAM_SIZE_3 << 2) | (ST_OAM_V_RECTANGLE))
#define SPRITE_SIZE(dim) (SPRITE_SIZE_##dim >> 2)
#define SPRITE_SHAPE(dim) (SPRITE_SIZE_##dim & 0xFF)
#define SPRITE_SIZE(dim) ((SPRITE_SIZE_##dim >> 2) & 0x03)
#define SPRITE_SHAPE(dim) (SPRITE_SIZE_##dim & 0x03)
struct BgAffineSrcData
{

View File

@ -30,7 +30,7 @@ bool8 itemid_80BF6D8_mail_related(u16 itemId);
bool8 sub_81221AC(void);
bool8 sub_81221EC(void);
void sub_812220C(struct ItemSlot *slots, u8 count, u8 *arg2, u8 *usedSlotsCount, u8 maxUsedSlotsCount);
void sub_812225C(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3);
void sub_812225C(u16 *scrollOffset, u16 *cursorPos, u8 maxShownItems, u8 numItems);
void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4);
void LoadListMenuArrowsGfx(void);
void sub_8122344(u8 *spriteIds, u8 count);

View File

@ -6,7 +6,7 @@
#define GUARD_TRADER_H
void sub_8133DA0(u8 taskId);
void sub_8133E1C(u8 taskId);
void ExitTraderMenu(u8 taskId);
void TraderSetup(void);
void Trader_ResetFlag(void);

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,7 @@ void SetDecorationInventoriesPointers(void)
SET_DECOR_INV(5, gSaveBlock1Ptr->decorPoster);
SET_DECOR_INV(6, gSaveBlock1Ptr->decorDoll);
SET_DECOR_INV(7, gSaveBlock1Ptr->decorCushion);
sub_8126968();
InitDecorationContextItems();
}
static void ClearDecorationInventory(u8 idx)
@ -120,7 +120,7 @@ bool8 DecorationCheckSpace(u8 decor)
s8 DecorationRemove(u8 decor)
{
u8 i;
u8 idx;
u8 category;
i = 0;
if (decor == DECOR_NONE)
@ -129,38 +129,38 @@ s8 DecorationRemove(u8 decor)
}
for (i = 0; i < gDecorationInventories[gDecorations[decor].category].size; i ++)
{
idx = gDecorations[decor].category;
if (gDecorationInventories[idx].items[i] == decor)
category = gDecorations[decor].category;
if (gDecorationInventories[category].items[i] == decor)
{
gDecorationInventories[idx].items[i] = DECOR_NONE;
CondenseDecorationCategoryN(idx);
gDecorationInventories[category].items[i] = DECOR_NONE;
CondenseDecorationsInCategory(category);
return 1;
}
}
return 0;
}
void CondenseDecorationCategoryN(u8 idx)
void CondenseDecorationsInCategory(u8 category)
{
u8 i;
u8 j;
u8 tmp;
for (i = 0; i < gDecorationInventories[idx].size; i ++)
for (i = 0; i < gDecorationInventories[category].size; i ++)
{
for (j = i + 1; j < gDecorationInventories[idx].size; j ++)
for (j = i + 1; j < gDecorationInventories[category].size; j ++)
{
if (gDecorationInventories[idx].items[j] != DECOR_NONE && (gDecorationInventories[idx].items[i] == DECOR_NONE || gDecorationInventories[idx].items[i] > gDecorationInventories[idx].items[j]))
if (gDecorationInventories[category].items[j] != DECOR_NONE && (gDecorationInventories[category].items[i] == DECOR_NONE || gDecorationInventories[category].items[i] > gDecorationInventories[category].items[j]))
{
tmp = gDecorationInventories[idx].items[i];
gDecorationInventories[idx].items[i] = gDecorationInventories[idx].items[j];
gDecorationInventories[idx].items[j] = tmp;
tmp = gDecorationInventories[category].items[i];
gDecorationInventories[category].items[i] = gDecorationInventories[category].items[j];
gDecorationInventories[category].items[j] = tmp;
}
}
}
}
u8 CountDecorationCategoryN(u8 idx)
u8 GetNumOwnedDecorationsInCategory(u8 idx)
{
u8 i;
u8 ct;
@ -176,15 +176,14 @@ u8 CountDecorationCategoryN(u8 idx)
return ct;
}
u8 CountDecorations(void)
u8 GetNumOwnedDecorations(void)
{
u8 idx;
u8 ct;
u8 category;
u8 count;
ct = 0;
for (idx = 0; idx < 8; idx ++)
{
ct += CountDecorationCategoryN(idx);
}
return ct;
count = 0;
for (category = 0; category < DECORCAT_COUNT; category++)
count += GetNumOwnedDecorationsInCategory(category);
return count;
}

View File

@ -344,17 +344,17 @@ void sub_812220C(struct ItemSlot *slots, u8 count, u8 *arg2, u8 *usedSlotsCount,
*arg2 = (*usedSlotsCount);
}
void sub_812225C(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3)
void sub_812225C(u16 *scrollOffset, u16 *cursorPos, u8 maxShownItems, u8 numItems)
{
if ((*arg0) != 0 && (*arg0) + arg2 > arg3)
(*arg0) = arg3 - arg2;
if (*scrollOffset != 0 && *scrollOffset + maxShownItems > numItems)
*scrollOffset = numItems - maxShownItems;
if ((*arg0) + (*arg1) >= arg3)
if (*scrollOffset + *cursorPos >= numItems)
{
if (arg3 == 0)
(*arg1) = 0;
if (numItems == 0)
*cursorPos = 0;
else
(*arg1) = arg3 - 1;
*cursorPos = numItems - 1;
}
}

View File

@ -412,9 +412,9 @@ static void PlayerPC_Mailbox(u8 taskId)
}
}
static void PlayerPC_Decoration(u8 var)
static void PlayerPC_Decoration(u8 taskId)
{
sub_8126B2C(var); //DoPlayerPCDecoration(var);
DoPlayerRoomDecorationMenu(taskId);
}
static void PlayerPC_TurnOff(u8 taskId)

View File

@ -854,7 +854,7 @@ void GetCurSecretBaseRegistrationValidity(void)
{
if (IsSecretBaseRegistered(VarGet(VAR_CURRENT_SECRET_BASE)) == TRUE)
gSpecialVar_Result = 1;
else if (GetNumRegisteredSecretBases() > 9)
else if (GetNumRegisteredSecretBases() >= 10)
gSpecialVar_Result = 2;
else
gSpecialVar_Result = 0;
@ -868,7 +868,7 @@ void ToggleCurSecretBaseRegistry(void)
void ShowSecretBaseDecorationMenu(void)
{
CreateTask(sub_8126AD8, 0);
CreateTask(DoSecretBaseDecorationMenu, 0);
}
void ShowSecretBaseRegistryMenu(void)

View File

@ -142,7 +142,7 @@ void ScrSpecial_DoesPlayerHaveNoDecorations(void)
for (i = 0; i < 8; i++)
{
if (CountDecorationCategoryN(i))
if (GetNumOwnedDecorationsInCategory(i))
{
gSpecialVar_Result = FALSE;
return;
@ -157,21 +157,21 @@ void ScrSpecial_IsDecorationFull(void)
if (gDecorations[gSpecialVar_0x8004].category != gDecorations[gSpecialVar_0x8006].category
&& GetFirstEmptyDecorSlot(gDecorations[gSpecialVar_0x8004].category) == -1)
{
sub_8127250(gStringVar2, gDecorations[gSpecialVar_0x8004].category);
CopyDecorationCategoryName(gStringVar2, gDecorations[gSpecialVar_0x8004].category);
gSpecialVar_Result = TRUE;
}
}
void ScrSpecial_TraderMenuGiveDecoration(void)
{
CreateTask(sub_8127208, 0);
CreateTask(ShowDecorationCategoriesWindow, 0);
}
void sub_8133DA0(u8 taskId)
{
if (IsSelectedDecorInThePC() == TRUE)
{
gSpecialVar_0x8006 = gCurDecorInventoryItems[gCurDecorationIndex];
gSpecialVar_0x8006 = gCurDecorationItems[gCurDecorationIndex];
StringCopy(gStringVar3, gDecorations[gSpecialVar_0x8004].name);
StringCopy(gStringVar2, gDecorations[gSpecialVar_0x8006].name);
}
@ -183,7 +183,7 @@ void sub_8133DA0(u8 taskId)
EnableBothScriptContexts();
}
void sub_8133E1C(u8 taskId)
void ExitTraderMenu(u8 taskId)
{
gSpecialVar_0x8006 = 0;
DestroyTask(taskId);