mirror of
https://github.com/pret/pmd-red.git
synced 2026-07-14 15:52:11 -05:00
272 lines
6.4 KiB
C
272 lines
6.4 KiB
C
#include "global.h"
|
|
#include "constants/dungeon_action.h"
|
|
#include "dungeon_map_access.h"
|
|
#include "dungeon_util.h"
|
|
#include "dungeon_generation.h"
|
|
#include "code_8044CC8.h"
|
|
#include "items.h"
|
|
|
|
// size: 0x8
|
|
typedef struct ItemText
|
|
{
|
|
u8 *desc;
|
|
u8 *useText;
|
|
} ItemText;
|
|
|
|
// size: 0x8
|
|
typedef struct unkStr_80F7C54
|
|
{
|
|
s32 unk0;
|
|
u8 *text;
|
|
} unkStr_80F7C54;
|
|
|
|
|
|
|
|
EWRAM_DATA unkStruct_202EE44 gDungeonSubMenu[10] = {0};
|
|
|
|
extern s32 gDungeonSubMenuItemsCount;
|
|
|
|
extern const ItemText gActions[];
|
|
extern u16 gUnknown_80F6964[NUM_ITEM_CATEGORIES];
|
|
extern u8 gUnknown_80F697C[];
|
|
extern u8 *gUnknown_80F7C50[10];
|
|
extern const unkStr_80F7C54 gUnknown_80F7C54[65];
|
|
extern u8 *gUnknown_80F91EC[];
|
|
extern bool8 sub_8045888(Entity *);
|
|
extern u8 GetFloorType(void);
|
|
void sub_80460F8(DungeonPos *, Item *, u32);
|
|
bool8 sub_80461C8(DungeonPos *, u32);
|
|
|
|
Item * sub_8044CC8(Entity *param_1, ActionParameter *param_2, UNUSED s32 a3)
|
|
{
|
|
const Tile *tile;
|
|
Item *item;
|
|
EntityInfo *info;
|
|
|
|
if ((u8)(param_2->actionUseIndex - 1) < INVENTORY_SIZE) {
|
|
item = &gTeamInventoryRef->teamItems[param_2->actionUseIndex - 1];
|
|
}
|
|
else if (param_2->actionUseIndex == 0x80) {
|
|
tile = GetTile((param_2->itemPos).x,(param_2->itemPos).y);
|
|
item = GetItemData(tile->object);
|
|
}
|
|
else {
|
|
if (param_2->actionUseIndex == 0x81) {
|
|
info = GetEntInfo(param_1);
|
|
}
|
|
else {
|
|
u8 id = param_2->actionUseIndex - 0x90;
|
|
if (3 < id) {
|
|
return NULL;
|
|
}
|
|
info = GetEntInfo(gDungeon->teamPokemon[param_2->actionUseIndex - 0x90]);
|
|
}
|
|
item = &info->heldItem;
|
|
}
|
|
return item;
|
|
}
|
|
|
|
bool8 sub_8044D40(ActionContainer *param_1,s32 index)
|
|
{
|
|
Item *item;
|
|
ActionParameter *puVar1;
|
|
|
|
puVar1 = ¶m_1->actionParameters[index];
|
|
if ((u8)(puVar1->actionUseIndex - 1) < INVENTORY_SIZE) {
|
|
item = &gTeamInventoryRef->teamItems[puVar1->actionUseIndex - 1];
|
|
item->id = ITEM_NOTHING;
|
|
item->quantity = 0;
|
|
item->flags = 0;
|
|
FillInventoryGaps();
|
|
}
|
|
else {
|
|
if (puVar1->actionUseIndex != 0x80) {
|
|
return FALSE;
|
|
}
|
|
sub_80461C8(&puVar1->itemPos,1);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
Item *sub_8044D90(Entity *entity, s32 index, s32 unused)
|
|
{
|
|
EntityInfo *info = GetEntInfo(entity);
|
|
return sub_8044CC8(entity, &info->action.actionParameters[index], unused);
|
|
}
|
|
|
|
Entity *sub_8044DA4(Entity *entity, s32 index)
|
|
{
|
|
EntityInfo *info = GetEntInfo(entity);
|
|
return gDungeon->teamPokemon[info->action.actionParameters[index].actionUseIndex];
|
|
}
|
|
|
|
u16 sub_8044DC8(Item *param_1)
|
|
{
|
|
if (param_1->id == ITEM_SWITCH_BOX) {
|
|
return 0x35;
|
|
}
|
|
else {
|
|
return gUnknown_80F6964[GetItemCategory(param_1->id)];
|
|
}
|
|
}
|
|
|
|
void sub_8044DF0(Entity *entity, s32 index, u32 unused)
|
|
{
|
|
Item *item;
|
|
EntityInfo *info;
|
|
|
|
info = GetEntInfo(entity);
|
|
item = sub_8044D90(entity,index,unused);
|
|
if ((info->action).actionParameters[0].actionUseIndex == 0x80) {
|
|
sub_80461C8(&(info->action).actionParameters[0].itemPos,1);
|
|
}
|
|
else {
|
|
item->id = ITEM_NOTHING;
|
|
item->quantity = 0;
|
|
item->flags = 0;
|
|
FillInventoryGaps();
|
|
}
|
|
}
|
|
|
|
|
|
void sub_8044E24(Entity *entity,int index,u32 unused)
|
|
{
|
|
Item *itemPtr;
|
|
EntityInfo *info;
|
|
DungeonPos *pos;
|
|
Item item;
|
|
|
|
itemPtr = sub_8044D90(entity,index,unused);
|
|
info = GetEntInfo(entity);
|
|
if (!IsHMItem(itemPtr->id)) {
|
|
if (GetItemCategory(itemPtr->id) == CATEGORY_TMS_HMS) {
|
|
if (info->action.actionParameters[index].actionUseIndex == 0x80) {
|
|
item = *itemPtr;
|
|
pos = &info->action.actionParameters[index].itemPos;
|
|
sub_80461C8(pos,1);
|
|
item.quantity = itemPtr->id - 125;
|
|
item.id = ITEM_TM_USED_TM;
|
|
sub_80460F8(pos,&item,1);
|
|
}
|
|
else {
|
|
itemPtr->quantity = itemPtr->id - 125;
|
|
itemPtr->id = ITEM_TM_USED_TM;
|
|
}
|
|
}
|
|
else {
|
|
sub_8044DF0(entity,index,unused);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Similar to sub_8044BA8
|
|
u8 *GetDungeonSubMenuItemString(s32 param_1)
|
|
{
|
|
u16 actionId = gDungeonSubMenu[param_1].actionId;
|
|
|
|
if (actionId == ACTION_STAIRS && GetFloorType() == FLOOR_TYPE_RESCUE) {
|
|
return *gUnknown_80F91EC;
|
|
}
|
|
else {
|
|
if (!AreStringsDifferent(gUnknown_80F7C50[actionId << 1], gUnknown_80F697C)) {
|
|
return gActions[GetItemActionType(gDungeonSubMenu[param_1].unk2)].useText;
|
|
}
|
|
else {
|
|
return gUnknown_80F7C50[actionId << 1];
|
|
}
|
|
}
|
|
}
|
|
|
|
bool8 CanSubMenuItemBeChosen(s32 itemId)
|
|
{
|
|
if (itemId < 0)
|
|
return FALSE;
|
|
else
|
|
return gDungeonSubMenu[itemId].canBeChosen;
|
|
}
|
|
|
|
void sub_8044F5C(u16 param_1, u8 param_2)
|
|
{
|
|
int index;
|
|
|
|
if (gDungeonSubMenuItemsCount < 10) {
|
|
for(index = 0; index < gDungeonSubMenuItemsCount; index++)
|
|
{
|
|
if (gDungeonSubMenu[index].actionId == param_1) {
|
|
return;
|
|
}
|
|
}
|
|
gDungeonSubMenu[gDungeonSubMenuItemsCount].actionId = param_1;
|
|
gDungeonSubMenu[gDungeonSubMenuItemsCount].unk2 = param_2;
|
|
gDungeonSubMenu[gDungeonSubMenuItemsCount].canBeChosen = TRUE;
|
|
gDungeonSubMenuItemsCount++;
|
|
}
|
|
}
|
|
|
|
s32 sub_8044FB4(u16 param_1)
|
|
{
|
|
int index;
|
|
|
|
for(index = 0; index < gDungeonSubMenuItemsCount; index++)
|
|
{
|
|
if (gDungeonSubMenu[index].actionId == param_1) {
|
|
return index;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void sub_8044FF0(u16 param_1)
|
|
{
|
|
int index;
|
|
|
|
for(index = 0; index < gDungeonSubMenuItemsCount; index++)
|
|
{
|
|
if (gDungeonSubMenu[index].actionId == param_1) {
|
|
gDungeonSubMenu[index].canBeChosen = FALSE;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool8 IsNotAttacking(Entity *param_1, bool8 param_2)
|
|
{
|
|
EntityInfo *info;
|
|
u16 *action;
|
|
|
|
info = GetEntInfo(param_1);
|
|
action = &(info->action).action;
|
|
if ((param_2 == 0) || (sub_8045888(param_1)))
|
|
{
|
|
if(*action == ACTION_NOTHING)
|
|
return TRUE;
|
|
if (*action == ACTION_WALK)
|
|
return TRUE;
|
|
if (*action == ACTION_PASS_TURN)
|
|
return TRUE;
|
|
if (*action == ACTION_UNK5)
|
|
return TRUE;
|
|
return FALSE;
|
|
}
|
|
else {
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
void sub_8045064(void)
|
|
{
|
|
s32 i, j;
|
|
|
|
for (i = 0; i < gDungeonSubMenuItemsCount; i++) {
|
|
for (j = i + 1; j < gDungeonSubMenuItemsCount; j++) {
|
|
unkStruct_202EE44 temp;
|
|
unkStruct_202EE44 *iPtr = &gDungeonSubMenu[i];
|
|
unkStruct_202EE44 *jPtr = &gDungeonSubMenu[j];
|
|
|
|
if (gUnknown_80F7C54[iPtr->actionId].unk0 > gUnknown_80F7C54[jPtr->actionId].unk0) {
|
|
SWAP(*iPtr, *jPtr, temp);
|
|
}
|
|
}
|
|
}
|
|
}
|