mirror of
https://github.com/pret/pmd-sky.git
synced 2026-03-21 17:25:15 -05:00
Combine item_util_1 and item_util_2
This commit is contained in:
parent
9367cfc659
commit
7035e32400
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef PMDSKY_ITEM_UTIL_1_H
|
||||
#define PMDSKY_ITEM_UTIL_1_H
|
||||
|
||||
#include "item.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef EUROPE
|
||||
|
|
@ -8,7 +9,6 @@ void SprintfStatic__0200E808_EU(char* buf, const char* fmt, ...);
|
|||
#endif
|
||||
|
||||
u8 GetExclusiveItemType(s16 item_id);
|
||||
s16 GetExclusiveItemOffsetEnsureValid(s16 item_id);
|
||||
|
||||
// Checks if an item is valid given its ID.
|
||||
// In particular, checks if the "is valid" flag is set on its item_p.bin entry.
|
||||
|
|
@ -16,4 +16,26 @@ bool8 IsItemValid(s16 item_id);
|
|||
|
||||
s16 GetExclusiveItemParameter(s16 item_id);
|
||||
|
||||
// Returns the category of the specified item
|
||||
enum item_category GetItemCategory(s16 item_id);
|
||||
|
||||
u8* GetItemName(s16 item_id);
|
||||
void GetItemNameFormatted(char* name, s16 item_id, s32 arg2, s32 arg3);
|
||||
u16 GetItemBuyPrice(s16 item_id);
|
||||
u16 GetItemSellPrice(s16 item_id);
|
||||
u8 GetItemSpriteId(s16 item_id);
|
||||
u8 GetItemPaletteId(s16 item_id);
|
||||
u8 GetItemActionName(s16 item_id);
|
||||
u8 GetThrownItemQuantityLimit(s16 item_id, u8 arg1);
|
||||
s16 GetItemMoveId(s16 item_id);
|
||||
|
||||
// Returns a boolean indicating whether the item is consumable, throwable at an ally, or throwable at an enemy, depending on item_flag.
|
||||
// The table used for this is inaccessible in the code, as it is loaded from a file in the ROM at runtime.
|
||||
// Bit 7 in the table corresponds to ITEM_FLAG_CONSUMABLE, bit 6 to ITEM_FLAG_THROWABLE_AT_ALLY, and bit 5 to ITEM_FLAG_THROWABLE_AT_ENEMY.
|
||||
//
|
||||
// item_id: item_id enum
|
||||
// flag: item_flag enum. Function will test a different allowed AI action depending on the value.
|
||||
// return: bool
|
||||
bool8 TestItemAiFlag(s16 item_id, s32 flag);
|
||||
|
||||
#endif //PMDSKY_ITEM_UTIL_1_H
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
#ifndef PMDSKY_ITEM_UTIL_2_H
|
||||
#define PMDSKY_ITEM_UTIL_2_H
|
||||
|
||||
#include "item.h"
|
||||
|
||||
// Returns the category of the specified item
|
||||
enum item_category GetItemCategory(s16 item_id);
|
||||
// Checks if the given item ID is valid (using IsItemValid). If so, return the given item ID. Otherwise, return ITEM_PLAIN_SEED.
|
||||
s16 EnsureValidItem(s16 item_id);
|
||||
|
||||
u8* GetItemName(s16 item_id);
|
||||
void GetItemNameFormatted(char* name, s16 item_id, s32 arg2, s32 arg3);
|
||||
u16 GetItemBuyPrice(s16 item_id);
|
||||
u16 GetItemSellPrice(s16 item_id);
|
||||
u8 GetItemSpriteId(s16 item_id);
|
||||
u8 GetItemPaletteId(s16 item_id);
|
||||
u8 GetItemActionName(s16 item_id);
|
||||
u8 GetThrownItemQuantityLimit(s16 item_id, u8 arg1);
|
||||
s16 GetItemMoveId(s16 item_id);
|
||||
|
||||
// Returns a boolean indicating whether the item is consumable, throwable at an ally, or throwable at an enemy, depending on item_flag.
|
||||
// The table used for this is inaccessible in the code, as it is loaded from a file in the ROM at runtime.
|
||||
// Bit 7 in the table corresponds to ITEM_FLAG_CONSUMABLE, bit 6 to ITEM_FLAG_THROWABLE_AT_ALLY, and bit 5 to ITEM_FLAG_THROWABLE_AT_ENEMY.
|
||||
//
|
||||
// item_id: item_id enum
|
||||
// flag: item_flag enum. Function will test a different allowed AI action depending on the value.
|
||||
// return: bool
|
||||
bool8 TestItemAiFlag(s16 item_id, s32 flag);
|
||||
|
||||
#endif //PMDSKY_ITEM_UTIL_2_H
|
||||
1
main.lsf
1
main.lsf
|
|
@ -40,7 +40,6 @@ Static main
|
|||
Object src/item_util_4.o
|
||||
Object asm/main_0200CAFC.o
|
||||
Object src/item_util_1.o
|
||||
Object src/item_util_2.o
|
||||
Object asm/main_0200EB30.o
|
||||
Object src/main_0200ECFC.o
|
||||
Object asm/main_0200ED1C.o
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#include "dungeon_util_static.h"
|
||||
#include "item.h"
|
||||
#include "item_util.h"
|
||||
#include "item_util_2.h"
|
||||
#include "item_util_1.h"
|
||||
#include "overlay_29_022E1610.h"
|
||||
#include "position_util.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "item_util.h"
|
||||
#include "item_util_2.h"
|
||||
#include "item_util_1.h"
|
||||
|
||||
enum item_category GetItemCategoryVeneer(s16 item_id)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,11 +1,29 @@
|
|||
#include "debug.h"
|
||||
#include "item_util_1.h"
|
||||
#include "main_0202593C.h"
|
||||
#include "item.h"
|
||||
#include "item_util_1.h"
|
||||
|
||||
#ifdef EUROPE
|
||||
#define ITEM_NAME_OFFSET 0x1A78
|
||||
#elif JAPAN
|
||||
#define ITEM_NAME_OFFSET 0x0D93
|
||||
#else
|
||||
#define ITEM_NAME_OFFSET 0x1A76
|
||||
#endif
|
||||
|
||||
extern struct item_tables ITEM_DATA_TABLE_PTRS;
|
||||
extern const char ITEM_NAME_FORMAT_YELLOW;
|
||||
extern const char ITEM_NAME_FORMAT_INDIGO;
|
||||
extern const char ITEM_NAME_FORMAT_PLAIN;
|
||||
extern const char ITEM_NAME_FORMAT_CREAM;
|
||||
|
||||
extern u8* strcpy(u8*, u8*);
|
||||
extern s32 vsprintf(u8* str, const u8* format, va_list ap);
|
||||
|
||||
static s16 GetExclusiveItemOffsetEnsureValid(s16 item_id);
|
||||
static s16 EnsureValidItem(s16 item_id);
|
||||
static void SprintfStatic(char*, const char*, ...);
|
||||
|
||||
#ifdef EUROPE
|
||||
void SprintfStatic__0200E808_EU(char* buf, const char* fmt, ...)
|
||||
{
|
||||
|
|
@ -20,7 +38,7 @@ u8 GetExclusiveItemType(s16 item_id) {
|
|||
return ITEM_DATA_TABLE_PTRS.exclusive_data[item_id].type;
|
||||
}
|
||||
|
||||
s16 GetExclusiveItemOffsetEnsureValid(s16 item_id) {
|
||||
static s16 GetExclusiveItemOffsetEnsureValid(s16 item_id) {
|
||||
if (item_id < ITEM_PRISM_RUFF || item_id >= NUM_ITEM_IDS) {
|
||||
return ITEM_PLAIN_SEED;
|
||||
}
|
||||
|
|
@ -42,3 +60,137 @@ s16 GetExclusiveItemParameter(s16 item_id) {
|
|||
item_id = GetExclusiveItemOffsetEnsureValid(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.exclusive_data[item_id].unk2;
|
||||
}
|
||||
|
||||
enum item_category GetItemCategory(s16 item_id)
|
||||
{
|
||||
s16 valid_item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[valid_item_id].category;
|
||||
}
|
||||
|
||||
static s16 EnsureValidItem(s16 item_id)
|
||||
{
|
||||
if (item_id <= 0 || item_id >= NUM_ITEM_IDS)
|
||||
return ITEM_PLAIN_SEED;
|
||||
|
||||
if (!IsItemValid(item_id))
|
||||
return ITEM_PLAIN_SEED;
|
||||
|
||||
return item_id;
|
||||
}
|
||||
|
||||
u8* GetItemName(s16 item_id) {
|
||||
u32 valid_item_id = EnsureValidItem(item_id);
|
||||
return StringFromId((u16)(valid_item_id + ITEM_NAME_OFFSET));
|
||||
}
|
||||
|
||||
#ifdef EUROPE
|
||||
#define GET_ITEM_NAME_FORMATTED_SPRINTF SprintfStatic__0200E808_EU
|
||||
#else
|
||||
#define GET_ITEM_NAME_FORMATTED_SPRINTF SprintfStatic
|
||||
#endif
|
||||
void GetItemNameFormatted(char* name, s16 item_id, s32 flag1, s32 flag2)
|
||||
{
|
||||
enum item_category category;
|
||||
|
||||
u8* raw_name = StringFromId((u16) (EnsureValidItem(item_id) + ITEM_NAME_OFFSET));
|
||||
|
||||
category = ITEM_DATA_TABLE_PTRS.data[EnsureValidItem(item_id)].category;
|
||||
if ((flag2 != 0) || ((u8)(category + 0xF4) <= 2)) {
|
||||
if (flag1 != 0) {
|
||||
GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_YELLOW, raw_name);
|
||||
return;
|
||||
}
|
||||
strcpy(name, raw_name);
|
||||
return;
|
||||
}
|
||||
if (category == CATEGORY_EXCLUSIVE_ITEMS) {
|
||||
if (flag1 != 0) {
|
||||
GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_INDIGO, raw_name);
|
||||
return;
|
||||
}
|
||||
GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_PLAIN, raw_name);
|
||||
return;
|
||||
}
|
||||
if (flag1 != 0) {
|
||||
GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_CREAM, raw_name);
|
||||
return;
|
||||
|
||||
}
|
||||
GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_PLAIN, raw_name);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef EUROPE
|
||||
static void SprintfStatic(char* buf, const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsprintf(buf, fmt, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
u16 GetItemBuyPrice(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].buy_price;
|
||||
}
|
||||
|
||||
u16 GetItemSellPrice(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].sell_price;
|
||||
}
|
||||
|
||||
u8 GetItemSpriteId(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].sprite_id;
|
||||
}
|
||||
|
||||
u8 GetItemPaletteId(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].palette_id;
|
||||
}
|
||||
|
||||
u8 GetItemActionName(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].action_name;
|
||||
}
|
||||
|
||||
u8 GetThrownItemQuantityLimit(s16 item_id, u8 arg1)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].quantity_limit[arg1];
|
||||
}
|
||||
|
||||
s16 GetItemMoveId(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].move_id;
|
||||
}
|
||||
|
||||
bool8 TestItemAiFlag(s16 item_id, s32 flag)
|
||||
{
|
||||
if (flag == 0)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
if (ITEM_DATA_TABLE_PTRS.data[item_id].flags & ITEM_DATA_FLAG_THROWABLE_AT_ENEMY)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (flag == 1)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
if (ITEM_DATA_TABLE_PTRS.data[item_id].flags & ITEM_DATA_FLAG_THROWABLE_AT_ALLY)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
item_id = EnsureValidItem(item_id);
|
||||
if (ITEM_DATA_TABLE_PTRS.data[item_id].flags & ITEM_DATA_FLAG_CONSUMABLE)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,162 +0,0 @@
|
|||
#include "debug.h"
|
||||
#include "item_util_2.h"
|
||||
#include "item_util_1.h"
|
||||
#include "main_0202593C.h"
|
||||
|
||||
extern struct item_tables ITEM_DATA_TABLE_PTRS;
|
||||
extern const char ITEM_NAME_FORMAT_YELLOW;
|
||||
extern const char ITEM_NAME_FORMAT_INDIGO;
|
||||
extern const char ITEM_NAME_FORMAT_PLAIN;
|
||||
extern const char ITEM_NAME_FORMAT_CREAM;
|
||||
|
||||
// extern char* SprintfStatic__0200E808_EU(char*, const char*, ...);
|
||||
extern u8* strcpy(u8*, u8*);
|
||||
extern s32 vsprintf(u8* str, const u8* format, va_list ap);
|
||||
|
||||
static void SprintfStatic(char*, const char*, ...);
|
||||
|
||||
enum item_category GetItemCategory(s16 item_id)
|
||||
{
|
||||
s16 valid_item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[valid_item_id].category;
|
||||
}
|
||||
|
||||
s16 EnsureValidItem(s16 item_id)
|
||||
{
|
||||
if (item_id <= 0 || item_id >= NUM_ITEM_IDS)
|
||||
return ITEM_PLAIN_SEED;
|
||||
|
||||
if (!IsItemValid(item_id))
|
||||
return ITEM_PLAIN_SEED;
|
||||
|
||||
return item_id;
|
||||
}
|
||||
|
||||
u8* GetItemName(s16 item_id) {
|
||||
u32 valid_item_id = EnsureValidItem(item_id);
|
||||
#ifdef EUROPE
|
||||
return StringFromId((u16)(valid_item_id + 0x1A78));
|
||||
#elif JAPAN
|
||||
return StringFromId((u16)(valid_item_id + 0x0D93));
|
||||
#else
|
||||
return StringFromId((u16)(valid_item_id + 0x1A76));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef EUROPE
|
||||
#define GET_ITEM_NAME_FORMATTED_SPRINTF SprintfStatic__0200E808_EU
|
||||
#else
|
||||
#define GET_ITEM_NAME_FORMATTED_SPRINTF SprintfStatic
|
||||
#endif
|
||||
void GetItemNameFormatted(char* name, s16 item_id, s32 flag1, s32 flag2)
|
||||
{
|
||||
enum item_category category;
|
||||
|
||||
#ifdef EUROPE
|
||||
u8* raw_name = StringFromId((u16) (EnsureValidItem(item_id) + 0x1A78));
|
||||
#elif JAPAN
|
||||
u8* raw_name = StringFromId((u16) (EnsureValidItem(item_id) + 0x0D93));
|
||||
#else
|
||||
u8* raw_name = StringFromId((u16) (EnsureValidItem(item_id) + 0x1A76));
|
||||
#endif
|
||||
|
||||
category = ITEM_DATA_TABLE_PTRS.data[EnsureValidItem(item_id)].category;
|
||||
if ((flag2 != 0) || ((u8)(category + 0xF4) <= 2)) {
|
||||
if (flag1 != 0) {
|
||||
GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_YELLOW, raw_name);
|
||||
return;
|
||||
}
|
||||
strcpy(name, raw_name);
|
||||
return;
|
||||
}
|
||||
if (category == CATEGORY_EXCLUSIVE_ITEMS) {
|
||||
if (flag1 != 0) {
|
||||
GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_INDIGO, raw_name);
|
||||
return;
|
||||
}
|
||||
GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_PLAIN, raw_name);
|
||||
return;
|
||||
}
|
||||
if (flag1 != 0) {
|
||||
GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_CREAM, raw_name);
|
||||
return;
|
||||
|
||||
}
|
||||
GET_ITEM_NAME_FORMATTED_SPRINTF(name, &ITEM_NAME_FORMAT_PLAIN, raw_name);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef EUROPE
|
||||
static void SprintfStatic(char* buf, const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsprintf(buf, fmt, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
u16 GetItemBuyPrice(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].buy_price;
|
||||
}
|
||||
|
||||
u16 GetItemSellPrice(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].sell_price;
|
||||
}
|
||||
|
||||
u8 GetItemSpriteId(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].sprite_id;
|
||||
}
|
||||
|
||||
u8 GetItemPaletteId(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].palette_id;
|
||||
}
|
||||
|
||||
u8 GetItemActionName(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].action_name;
|
||||
}
|
||||
|
||||
u8 GetThrownItemQuantityLimit(s16 item_id, u8 arg1)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].quantity_limit[arg1];
|
||||
}
|
||||
|
||||
s16 GetItemMoveId(s16 item_id)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
return ITEM_DATA_TABLE_PTRS.data[item_id].move_id;
|
||||
}
|
||||
|
||||
bool8 TestItemAiFlag(s16 item_id, s32 flag)
|
||||
{
|
||||
if (flag == 0)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
if (ITEM_DATA_TABLE_PTRS.data[item_id].flags & ITEM_DATA_FLAG_THROWABLE_AT_ENEMY)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (flag == 1)
|
||||
{
|
||||
item_id = EnsureValidItem(item_id);
|
||||
if (ITEM_DATA_TABLE_PTRS.data[item_id].flags & ITEM_DATA_FLAG_THROWABLE_AT_ALLY)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
item_id = EnsureValidItem(item_id);
|
||||
if (ITEM_DATA_TABLE_PTRS.data[item_id].flags & ITEM_DATA_FLAG_CONSUMABLE)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user