sub_807EFFC

This commit is contained in:
DizzyEggg
2024-12-05 11:46:08 +01:00
parent b6e4f986ea
commit 22d0b41247
2 changed files with 241 additions and 694 deletions

View File

@@ -5,13 +5,19 @@
#include "dungeon.h"
#include "dungeon_config.h"
#include "dungeon_leader.h"
#include "dungeon_music.h"
#include "dungeon_util.h"
#include "pokemon.h"
#include "structs/map.h"
#include "dungeon_message.h"
#include "dungeon_pokemon_attributes.h"
#include "string_format.h"
#include "dungeon_movement.h"
#include "dungeon_capabilities.h"
#include "dungeon_map_access.h"
#include "position_util.h"
#include "code_806CD90.h"
#include "code_807CD9C.h"
#include "code_805D8C8.h"
#include "constants/ability.h"
#include "constants/monster.h"
@@ -19,21 +25,39 @@
extern u8 gUnknown_203B40D;
extern OpenedFile *gUnknown_202ECA0;
extern void sub_804178C(u32);
extern void sub_804178C(u32);
extern bool8 sub_80461C8(DungeonPos *, u32);
extern void sub_80429D8(Entity *r0);
extern s32 GetMonsterApparentID(Entity *pokemon, s32 id);
void sub_803E874(bool8 r10, s32 r9);
void GetWeatherName(u8 *dst, u8 weatherId);
extern void sub_803E874(bool8 r10, s32 r9);
extern void GetWeatherName(u8 *dst, u8 weatherId);
extern s32 CalculateStatusTurns(Entity *target, const s16 *turnRange, bool8 factorCurerSkills);
extern void sub_80838EC(u8 *a);
extern bool8 sub_8044B28(void);
extern void sub_80460F8(DungeonPos *, Item *, u32);
void sub_807E7FC(bool8 arg0);
void sub_807EFFC(bool8 arg0);
s32 sub_807F19C(bool8 arg0);
void sub_807E8F0(Entity *pokemon);
bool8 sub_807EF48(void);
void sub_807F33C(void);
extern const u8 *gWeatherNames[];
extern const u8 *const gUnknown_80FC5E0;
extern const u8 *const gUnknown_80FA778;
extern const u8 *const gUnknown_80FA758;
extern const u8 *const gUnknown_80FE674;
extern const u8 *const gUnknown_80FE65C;
extern const u8 *const gUnknown_80FE63C;
extern const u8 *const gUnknown_80FE5F0;
extern const u8 *const gUnknown_80FAD8C;
extern const u8 *const gUnknown_80FADB0;
extern const u8 *const gUnknown_80FE5C0;
extern const u8 *const gUnknown_80FE4F4;
// Note: gUnknown_202ECA0 file's 2d array is read as 1d array in functions below, be careful!
void sub_807E698(bool8 arg0)
@@ -185,10 +209,6 @@ void sub_807E8F0(Entity *pokemon)
}
}
extern const u8 *gWeatherNames[];
extern const u8 *const gUnknown_80FAD8C;
extern const u8 *const gUnknown_80FADB0;
void GetWeatherName(u8 *buffer, u8 weather)
{
strcpy(buffer, gWeatherNames[weather]);
@@ -266,3 +286,217 @@ bool8 sub_807EAA0(bool8 arg0, bool8 arg1)
return ret;
}
void sub_807EC28(bool8 arg0)
{
Entity *leader;
EntityInfo *leaderInfo;
u32 var_34;
bool32 isShopTile;
if (sub_8044B28())
return;
leader = GetLeader();
leaderInfo = GetEntInfo(leader);
var_34 = gDungeon->unk644.unk54;
isShopTile = (GetTileAtEntitySafe(leader)->terrainType & TERRAIN_TYPE_SHOP) != 0;
gDungeon->unk644.unk54 = isShopTile;
gDungeon->unk644.unk55 = isShopTile;
if (gDungeon->unk644.unk2A || gDungeon->unk644.unk50 == 0)
return;
if (leaderInfo->invisibleClassStatus.status == STATUS_INVISIBLE) {
gDungeon->unk644.unk54 = 0;
gDungeon->unk644.unk55 = 0;
}
else {
s32 i;
struct MonDialogueSpriteInfo dialogueInfo;
bool8 var_30 = FALSE;
bool8 var_2C;
bool8 var_28;
for (i = 0; i < DUNGEON_MAX_WILD_POKEMON; i++) {
Entity *wildMon = gDungeon->wildPokemon[i];
if (EntityExists(wildMon)) {
EntityInfo *wildMonInfo = GetEntInfo(wildMon);
if (wildMonInfo->shopkeeper == SHOPKEEPER_MODE_SHOPKEEPER && sub_8070BC0(wildMon) && GetEntityRoom(leader) == GetEntityRoom(wildMon)) {
var_30 = TRUE;
}
}
}
dialogueInfo.species = MONSTER_KECLEON;
dialogueInfo.spriteId = 0;
if (var_34 == 0) {
if (isShopTile == TRUE) {
if (var_30) {
DisplayDungeonMessage(&dialogueInfo, gUnknown_80FE674, TRUE); // Ah welcome!
}
return;
}
}
else {
if (isShopTile == TRUE) {
return;
}
}
if ((var_34 != 1 || isShopTile) && !arg0) {
return;
}
var_2C = FALSE;
var_28 = FALSE;
if (sub_807EF48()) {
var_28 = TRUE;
for (i = 0; i < DUNGEON_MAX_WILD_POKEMON; i++) {
Entity *wildMon = gDungeon->wildPokemon[i];
if (EntityExists(wildMon)
&& GetEntInfo(wildMon)->shopkeeper == SHOPKEEPER_MODE_SHOPKEEPER
&& sub_8070BC0(wildMon)
&& GetEntityRoom(leader) == GetEntityRoom(wildMon))
{
var_2C = TRUE;
if (abs(leader->pos.x - wildMon->pos.x) >= 2 || abs(leader->pos.y - wildMon->pos.y) >= 2) {
s32 x, y;
DungeonPos pos;
for (x = -1; x < 2; x++) {
for (y = -1; y < 2; y++) {
pos.x = leader->pos.x + x;
pos.y = leader->pos.y + y;
if (GetTile(pos.x, pos.y)->room != CORRIDOR_ROOM) {
if (!sub_80703A0(wildMon, &pos)) {
WarpTarget(leader, wildMon, 3, &pos);
goto LOOP_BREAK; // Used to break out of the nested loops
}
}
}
}
LOOP_BREAK:
}
if (sub_8070BC0(leader)) {
sub_806CE34(leader, GetDirectionTowardsPosition(&leader->pos, &wildMon->pos));
}
else {
var_2C = FALSE;
}
sub_806CE68(wildMon, GetDirectionTowardsPosition(&wildMon->pos, &leader->pos));
break;
}
}
}
if (var_28 && !var_2C) {
if (gDungeon->unk644.unk50 > gDungeon->unk644.unk48) {
sub_807F33C();
}
}
else if (var_28 && !var_30) {
if (gDungeon->unk644.unk50 > gDungeon->unk644.unk48) {
sub_807F33C();
}
}
else {
sub_807EFFC(var_2C);
if (sub_807F19C(var_2C)) {
sub_807F33C();
}
else if (var_34 == 1 && !isShopTile && var_30) {
DisplayDungeonMessage(&dialogueInfo, gUnknown_80FE65C, TRUE); // I await your next visit
}
}
}
}
bool8 sub_807EF48(void)
{
if ((gDungeon->unk644.unk50 - gDungeon->unk644.unk48) > 0) {
return TRUE;
}
if (gDungeon->unk644.unk4C != 0) {
return TRUE;
}
return FALSE;
}
void sub_807EF84(void)
{
s32 val;
struct MonDialogueSpriteInfo dialogueInfo;
dialogueInfo.species = MONSTER_KECLEON;
dialogueInfo.spriteId = 0;
sub_807EFFC(1);
val = sub_807F19C(1);
if (val != 0) {
Tile *tile = GetTileAtEntitySafe(GetLeader());
if (tile->terrainType & TERRAIN_TYPE_SHOP) {
if (val != 2) {
DisplayDungeonMessage(&dialogueInfo, gUnknown_80FE63C, 1); // This is very disappointing, please return any items before you leave.
}
}
else {
sub_807F33C();
}
}
else {
DisplayDungeonMessage(&dialogueInfo, gUnknown_80FE5F0, 1); // Looking forward to seeing you again!
}
}
void sub_807EFFC(bool8 arg0)
{
struct MonDialogueSpriteInfo dialogueInfo;
if (gDungeon->unk644.unk4C == 0)
return;
dialogueInfo.species = MONSTER_KECLEON;
dialogueInfo.spriteId = 0;
if (!arg0)
return;
gFormatArgs[0] = gDungeon->unk644.unk4C;
if (DisplayDungeonYesNoMessage(&dialogueInfo, gUnknown_80FE5C0, TRUE) == 1) { // For the merch you have left, I shall pay X. Is that acceptable?
s32 x, y;
DungeonPos pos;
s32 local_24;
PlaySoundEffect(0x14c);
AddToTeamMoney(gDungeon->unk644.unk4C);
local_24 = gDungeon->unk644.unk48;
for (x = gDungeon->kecleonShopPos.minX; x <= gDungeon->kecleonShopPos.maxX; x++) {
for (y = gDungeon->kecleonShopPos.minY; y <= gDungeon->kecleonShopPos.maxY; y++) {
const Tile *tile;
pos.y = y;
pos.x = x;
tile = GetTile(x,y);
if (tile->terrainType & TERRAIN_TYPE_SHOP && tile->object != NULL && GetEntityType(tile->object) == ENTITY_ITEM) {
Item *itemPtr = GetItemData(tile->object);
if (!ItemInShop(itemPtr)) {
Item item = *itemPtr;
sub_80461C8(&pos, 1);
if (CanSellItem(item.id)) {
item.flags |= ITEM_FLAG_IN_SHOP;
}
sub_80460F8(&pos, &item, 1);
}
}
}
}
gDungeon->unk644.unk50 += (gDungeon->unk644.unk48 - local_24);
DisplayDungeonMessage(&dialogueInfo, gUnknown_80FE4F4, 1); // Your patronage is valued
}
}
//