From c98fb2c11272680a20b9cfb9efe2ce482d3779dd Mon Sep 17 00:00:00 2001 From: Cheng Hann Gan Date: Fri, 22 Oct 2021 13:20:01 -0400 Subject: Decomped DecideAction() (#66) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Decomped DecideAction() * Defined dungeon Pokémon array sizes --- src/code_8040094.c | 4 +- src/code_8048480.c | 4 +- src/code_80521D0.c | 2 +- src/code_80521D0_1.c | 8 +-- src/code_8057824_1.c | 12 ++-- src/dungeon_engine.c | 11 ---- src/dungeon_movement.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++ src/dungeon_util.c | 11 ++++ 8 files changed, 175 insertions(+), 26 deletions(-) delete mode 100644 src/dungeon_engine.c create mode 100644 src/dungeon_movement.c create mode 100644 src/dungeon_util.c (limited to 'src') diff --git a/src/code_8040094.c b/src/code_8040094.c index d220844..608bbf4 100644 --- a/src/code_8040094.c +++ b/src/code_8040094.c @@ -21,7 +21,7 @@ extern void sub_8011860(void); extern void sub_803F580(u32); extern void sub_8049ED4(); extern void sub_8040A84(); -extern void sub_80522A8(u32, const char *); +extern void SendMessage(u32, const char *); extern const char *gUnknown_80FD040; // It became brighter on the floor @@ -56,7 +56,7 @@ void sub_804002C(u32 param_1) sub_803F580(0); sub_8049ED4(); sub_8040A84(); - sub_80522A8(param_1, gUnknown_80FD040); + SendMessage(param_1, gUnknown_80FD040); } void sub_8040094(u8 r0) diff --git a/src/code_8048480.c b/src/code_8048480.c index 675751e..f8f9155 100644 --- a/src/code_8048480.c +++ b/src/code_8048480.c @@ -18,7 +18,7 @@ extern void sub_8072008(struct DungeonEntity *r0, struct DungeonEntity *r1, u32 extern void sub_8076D10(struct DungeonEntity *r0, struct DungeonEntity *r1); extern void LevelDownTarget(struct DungeonEntity *r0, struct DungeonEntity *r1, u32 r2); -extern void sub_8045B94(u8 *r0, struct DungeonEntity *r1, u32); +extern void SetMessageArgument(u8 *r0, struct DungeonEntity *r1, u32); extern void sub_807A290(struct DungeonEntity *r0, struct DungeonEntity *r1); extern void sub_80522F4(struct DungeonEntity *r0, struct DungeonEntity *r1, u32); extern void RestoreVisionTarget(struct DungeonEntity *r0, struct DungeonEntity *r1); @@ -140,7 +140,7 @@ void sub_80484E8(struct DungeonEntity *r0, struct DungeonEntity *r1) sub_807A290(r0, r1); else { - sub_8045B94(gAvailablePokemonNames, r1, 0); + SetMessageArgument(gAvailablePokemonNames, r1, 0); // Pointer to "But nothing happened!" sub_80522F4(r0, r1, gUnknown_80FB580); } diff --git a/src/code_80521D0.c b/src/code_80521D0.c index 914b02d..8be49f8 100644 --- a/src/code_80521D0.c +++ b/src/code_80521D0.c @@ -11,7 +11,7 @@ void sub_805229C(void) return sub_80526D0(0x50); } -void sub_80522A8(u32 r0, u32 r1) +void SendMessage(u32 r0, u32 r1) { if (sub_8045888(r0) != 0){ sub_80523A8(r0, r1, 1); diff --git a/src/code_80521D0_1.c b/src/code_80521D0_1.c index b29dc9a..482e3ba 100644 --- a/src/code_80521D0_1.c +++ b/src/code_80521D0_1.c @@ -94,7 +94,7 @@ extern void sub_8085918(struct DungeonEntity *, u32); extern void sub_806CE68(struct DungeonEntity *r0, u32); extern void sub_8052910(u32 *); extern void sub_803E708(u32, u32); -extern u8 entityExists(struct DungeonEntity *); +extern u8 EntityExists(struct DungeonEntity *); extern u8 HasRecruitedMon(u32); extern u8 sub_806FD18(struct DungeonEntity *); extern u8 sub_8083E74(u32); @@ -130,7 +130,7 @@ void sub_808C02C(); extern void sub_80861B8(struct DungeonEntity *, u32, u32); void nullsub_99(); -extern u32 sub_8084100(s32); +extern u32 DungeonRandomCapped(s32); extern bool8 *gFriendAreas; extern void sub_8049884(); @@ -271,7 +271,7 @@ u8 JirachiFriendAreaSearch(void) } else { // Randomly pick 1 - friendAreaIndex = sub_8084100(numUnlockableAreas); + friendAreaIndex = DungeonRandomCapped(numUnlockableAreas); return friendAreas[friendAreaIndex]; } } @@ -1102,7 +1102,7 @@ void sub_808C948(struct DungeonEntity *param_1, u8 param_2) flag = FALSE; for(iVar3 = 0; iVar3 < 0x10; iVar3++){ iVar2 = gDungeonGlobalData->wildPokemon[iVar3]; - if ((iVar2 != param_1) && (entityExists(iVar2) != 0)) { + if ((iVar2 != param_1) && (EntityExists(iVar2) != 0)) { flag = TRUE; break; } diff --git a/src/code_8057824_1.c b/src/code_8057824_1.c index 3426921..4dfc978 100644 --- a/src/code_8057824_1.c +++ b/src/code_8057824_1.c @@ -254,7 +254,7 @@ extern void sub_806CE68(struct DungeonEntity *, u32); extern void sub_8052D44(u8 *, struct DungeonEntity *, struct DungeonEntity *); extern void sub_8097FD0(u32); -extern void sub_8045B94(u8 *, struct DungeonEntity *, u32); +extern void SetMessageArgument(u8 *, struct DungeonEntity *, u32); extern struct DungeonEntity *sub_8083600(); extern void sub_80421C0(struct DungeonEntity *, u32); extern void sub_8046D20(); @@ -313,7 +313,7 @@ void sub_808919C(); void sub_8088D30(void); extern void sub_8083F14(); -extern u8 entityExists(struct DungeonEntity *); +extern u8 EntityExists(struct DungeonEntity *); extern u8 sub_8086AE4(u32); @@ -1985,7 +1985,7 @@ void sub_8089788(struct DungeonEntity *param_1, u8 param_2, s32 param_3) for(iVar3 = 0; iVar3 < 0x10; iVar3++) { iVar2 = gDungeonGlobalData->wildPokemon[iVar3]; - if ((entityExists(iVar2) != '\0') && (iVar2 != param_1) && (iVar2->entityData->clientFlags == param_2)) { + if ((EntityExists(iVar2) != '\0') && (iVar2 != param_1) && (iVar2->entityData->clientType == param_2)) { return; } } @@ -3168,7 +3168,7 @@ void sub_808AFB0(char param_1) sub_8052D44(auStack12,uVar3,0); if ((sub_8098100(0x22) == 0) && (param_1 == 0x2E) && (sub_8098100(0x1d) == 0) && (sub_80860A8(ITEM_ID_ROCK_PART) != 0)) { sub_8097FD0(0x1d); - sub_8045B94(gAvailablePokemonNames,sub_8083600(),0); + SetMessageArgument(gAvailablePokemonNames,sub_8083600(),0); // $m0 obatined the Rock Part that Regirock was guarding sub_8052910(&gUnknown_81050B4); sub_80421C0(0,0xd4); @@ -3186,7 +3186,7 @@ void sub_808B030(char param_1) sub_8052D44(auStack12,uVar3,0); if ((sub_8098100(0x22) == 0) && (param_1 == 0x2F) && (sub_8098100(0x1d) == 0) && (sub_80860A8(ITEM_ID_ICE_PART) != 0)) { sub_8097FD0(0x1d); - sub_8045B94(gAvailablePokemonNames,sub_8083600(),0); + SetMessageArgument(gAvailablePokemonNames,sub_8083600(),0); // $m0 obatined the Ice Part that Regice was guarding sub_8052910(&gUnknown_810517C); sub_80421C0(0,0xd4); @@ -3204,7 +3204,7 @@ void sub_808B0B0(char param_1) sub_8052D44(auStack12,uVar3,0); if ((sub_8098100(0x22) == 0) && (param_1 == 0x30) && (sub_8098100(0x1d) == 0) && (sub_80860A8(ITEM_ID_STEEL_PART) != 0)) { sub_8097FD0(0x1d); - sub_8045B94(gAvailablePokemonNames, sub_8083600(), 0); + SetMessageArgument(gAvailablePokemonNames, sub_8083600(), 0); // $m0 obatined the Steel Part that Registeel was guarding sub_8052910(&gUnknown_8105244); sub_80421C0(0,0xd4); diff --git a/src/dungeon_engine.c b/src/dungeon_engine.c deleted file mode 100644 index 8689b91..0000000 --- a/src/dungeon_engine.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "global.h" -#include "dungeon_engine.h" - -bool8 entityExists(struct DungeonEntity *entity) -{ - if (!entity) - { - return FALSE; - } - return entity->entityType != ENTITY_NONE; -} diff --git a/src/dungeon_movement.c b/src/dungeon_movement.c new file mode 100644 index 0000000..b17e232 --- /dev/null +++ b/src/dungeon_movement.c @@ -0,0 +1,149 @@ +#include "global.h" +#include "dungeon_movement.h" + +#include "constants/dungeon_action.h" +#include "constants/iq_skill.h" +#include "constants/status.h" +#include "dungeon_global_data.h" +#include "map.h" + +extern char gAvailablePokemonNames[]; +extern char *gPtrCouldntBeUsedMessage; +extern struct DungeonGlobalData *gDungeonGlobalData; + +extern void SendImmobilizeEndMessage(struct DungeonEntity*, struct DungeonEntity*); +extern bool8 IsMovingClient(struct DungeonEntity*); +extern bool8 CannotUseItems(struct DungeonEntity*); +extern void SetMessageArgument(char[], struct DungeonEntity*, u32); +extern void SendMessage(struct DungeonEntity*, char*); +extern void DecideUseItem(struct DungeonEntity*); +extern bool8 HasStatusAffectingActions(struct DungeonEntity*); +extern bool8 EntityExists(struct DungeonEntity*); +extern bool8 CanSee(struct DungeonEntity*, struct DungeonEntity*); +extern void ResetAction(u16*); +extern void SetWalkAction(u16*, s16); +extern s32 DungeonRandomCapped(s32); +extern bool8 HasIQSkill(struct DungeonEntity*, u8); +extern void DecideAttack(struct DungeonEntity*); +extern bool8 GetIsMoving(s16); +extern void MoveIfPossible(struct DungeonEntity*, bool8); + +void DecideAction(struct DungeonEntity *pokemon) +{ + struct DungeonEntityData *pokemonData = pokemon->entityData; + if ((pokemonData->flags & MOVEMENT_FLAG_SWAPPED_PLACES_PETRIFIED) != 0) + { + if (pokemonData->immobilizeStatus == IMMOBILIZE_STATUS_PETRIFIED) + { + SendImmobilizeEndMessage(pokemon, pokemon); + } + } + else + { + pokemonData->targetingDecoy = TARGETING_DECOY_NONE; + if (pokemonData->clientType == CLIENT_TYPE_NONE || IsMovingClient(pokemon)) + { + if (pokemonData->clientType != CLIENT_TYPE_CLIENT && pokemonData->useHeldItem) + { + if (CannotUseItems(pokemon)) + { + pokemonData->useHeldItem = FALSE; + SetMessageArgument(gAvailablePokemonNames, pokemon, 0); + SendMessage(pokemon, gPtrCouldntBeUsedMessage); + return; + } + DecideUseItem(pokemon); + if (pokemonData->action != DUNGEON_ACTION_NONE) + { + return; + } + } + if (!HasStatusAffectingActions(pokemon)) + { + if (gDungeonGlobalData->decoyActive) + { + s32 i; + struct DungeonEntity *target; + for (i = 0; i < DUNGEON_MAX_POKEMON; i++) + { + target = gDungeonGlobalData->allPokemon[i]; + if (EntityExists(target) && + target->entityData->waitingStatus == WAITING_STATUS_DECOY && + CanSee(pokemon, target)) + { + bool8 enemyDecoy = target->entityData->enemyDecoy; + u8 targetingDecoy = TARGETING_DECOY_TEAM; + if (enemyDecoy) + { + targetingDecoy = TARGETING_DECOY_WILD; + } + pokemonData->targetingDecoy = targetingDecoy; + break; + } + } + } + ResetAction(&pokemonData->action); + if (pokemonData->clientType == CLIENT_TYPE_CLIENT) + { + SetWalkAction(&pokemonData->action, pokemonData->entityID); + pokemonData->facingDir = DungeonRandomCapped(8); + pokemonData->targetPositionX = pokemon->posWorldX; + pokemonData->targetPositionY = pokemon->posWorldY - 1; + } + else + { + DecideUseItem(pokemon); + if (pokemonData->action == DUNGEON_ACTION_NONE) + { + if (!HasIQSkill(pokemon, IQ_SKILL_DEDICATED_TRAVELER)) + { + DecideAttack(pokemon); + if (pokemonData->action != DUNGEON_ACTION_NONE) + { + return; + } + if (pokemonData->volatileStatus == VOLATILE_STATUS_CONFUSED) + { + SetWalkAction(&pokemonData->action, pokemonData->entityID); + } + else + { + if (!GetIsMoving(pokemonData->entityID)) + { + return; + } + MoveIfPossible(pokemon, TRUE); + } + } + else + { + if (pokemonData->volatileStatus == VOLATILE_STATUS_CONFUSED) + { + SetWalkAction(&pokemonData->action, pokemonData->entityID); + } + else + { + if (GetIsMoving(pokemonData->entityID)) + { + MoveIfPossible(pokemon, TRUE); + } + if (pokemonData->action > DUNGEON_ACTION_WAIT) + { + return; + } + DecideAttack(pokemon); + if (pokemonData->action <= DUNGEON_ACTION_WAIT) + { + return; + } + pokemonData->notAdjacentToTarget = FALSE; + pokemonData->movingIntoTarget = FALSE; + pokemonData->waiting = FALSE; + } + } + } + } + } + } + } +} diff --git a/src/dungeon_util.c b/src/dungeon_util.c new file mode 100644 index 0000000..60b796f --- /dev/null +++ b/src/dungeon_util.c @@ -0,0 +1,11 @@ +#include "global.h" +#include "dungeon_util.h" + +bool8 EntityExists(struct DungeonEntity *entity) +{ + if (!entity) + { + return FALSE; + } + return entity->entityType != ENTITY_NONE; +} -- cgit v1.2.3