summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSeth Barberee <seth.barberee@gmail.com>2022-01-20 15:26:19 -0800
committerGitHub <noreply@github.com>2022-01-20 15:26:19 -0800
commit408fe77d7b9440d7eb5d46eda5f920572d516d67 (patch)
tree38953616b74da130bd832635bed1c605d4b0e322 /src
parent3cdde2a92a187d437dc7d24273177b59ab5b9511 (diff)
parentc5cd6e137fbad180a21ec24a50fde76633db0c20 (diff)
Merge pull request #93 from AnonymousRandomPerson/master
More AI decomp
Diffstat (limited to 'src')
-rw-r--r--src/code_8040094.c10
-rw-r--r--src/code_80521D0.c22
-rw-r--r--src/code_80983D8.c52
-rw-r--r--src/dungeon_action.c17
-rw-r--r--src/dungeon_ai_item_weight.c5
-rw-r--r--src/dungeon_ai_items.c2
-rw-r--r--src/dungeon_movement.c16
-rw-r--r--src/friend_list_menu.c2
-rw-r--r--src/position_util.c65
-rw-r--r--src/status_checks.c102
-rw-r--r--src/status_checks_1.c55
11 files changed, 268 insertions, 80 deletions
diff --git a/src/code_8040094.c b/src/code_8040094.c
index c834602..c0e7eac 100644
--- a/src/code_8040094.c
+++ b/src/code_8040094.c
@@ -1,7 +1,10 @@
#include "global.h"
-#include "play_time.h"
-#include "file_system.h"
+
+#include "code_80521D0.h"
+#include "dungeon_entity.h"
#include "dungeon_global_data.h"
+#include "file_system.h"
+#include "play_time.h"
extern s32 gUnknown_80F6568[];
extern u8 gUnknown_202EE01;
@@ -20,14 +23,13 @@ extern void sub_8011860(void);
extern void sub_803F580(u32);
extern void sub_8049ED4();
extern void sub_8040A84();
-extern void SendMessage(u32, const char *);
extern const char *gUnknown_80FD040; // It became brighter on the floor
extern struct MapTile *GetMapEntity(u32, u32);
// Luminous Orb???
-void HandleLuminousOrbAction(u32 param_1)
+void HandleLuminousOrbAction(struct DungeonEntity *param_1)
{
struct MapTile *mapTile;
int XCoord;
diff --git a/src/code_80521D0.c b/src/code_80521D0.c
index 272991d..4867acf 100644
--- a/src/code_80521D0.c
+++ b/src/code_80521D0.c
@@ -1,9 +1,9 @@
#include "global.h"
-#include "dungeon_entity.h"
+#include "code_80521D0.h"
extern void sub_80526D0(u8 r0);
extern u8 sub_8045888(struct DungeonEntity *r0);
-extern void sub_80523A8(struct DungeonEntity *r0, u32 r1, u8 r2);
+extern void sub_80523A8(struct DungeonEntity *r0, const char r1[], u8 r2);
extern u8 sub_8052DC0(struct DungeonEntity *);
extern u8 sub_803F428(u32);
@@ -12,26 +12,26 @@ void sub_805229C(void)
return sub_80526D0(0x50);
}
-void SendMessage(struct DungeonEntity *r0, u32 r1)
+void SendMessage(struct DungeonEntity *pokemon, const char message[])
{
- if (sub_8045888(r0) != 0){
- sub_80523A8(r0, r1, 1);
+ if (sub_8045888(pokemon) != 0){
+ sub_80523A8(pokemon, message, 1);
}
}
-void sub_80522C8(struct DungeonEntity *r0, u32 r1)
+void sub_80522C8(struct DungeonEntity *r0, const char r1[])
{
if (sub_8045888(r0) != 0){
sub_80523A8(r0, r1, 0);
}
}
-void sub_80522E8(struct DungeonEntity *r0, u32 r1)
+void sub_80522E8(struct DungeonEntity *r0, const char r1[])
{
sub_80523A8(r0, r1, 0);
}
-void sub_80522F4(struct DungeonEntity *r0, struct DungeonEntity *r1, u32 r2)
+void sub_80522F4(struct DungeonEntity *r0, struct DungeonEntity *r1, const char r2[])
{
u8 temp;
u32 temp_reg;
@@ -49,7 +49,7 @@ void sub_80522F4(struct DungeonEntity *r0, struct DungeonEntity *r1, u32 r2)
}
}
-void sub_805232C(struct DungeonEntity *r0, struct DungeonEntity *r1, u32 r2)
+void sub_805232C(struct DungeonEntity *r0, struct DungeonEntity *r1, const char r2[])
{
u8 temp;
u32 temp_reg;
@@ -67,7 +67,7 @@ void sub_805232C(struct DungeonEntity *r0, struct DungeonEntity *r1, u32 r2)
}
}
-void sub_8052364(struct DungeonEntity *r0, u32 r1, u32 r2)
+void sub_8052364(struct DungeonEntity *r0, u32 r1, const char r2[])
{
u8 temp;
u32 temp_reg;
@@ -85,7 +85,7 @@ void sub_8052364(struct DungeonEntity *r0, u32 r1, u32 r2)
}
}
-void sub_805239C(struct DungeonEntity *r0, u32 r1)
+void sub_805239C(struct DungeonEntity *r0, const char r1[])
{
sub_80523A8(r0, r1, 1);
}
diff --git a/src/code_80983D8.c b/src/code_80983D8.c
deleted file mode 100644
index 25c57d2..0000000
--- a/src/code_80983D8.c
+++ /dev/null
@@ -1,52 +0,0 @@
-#include "global.h"
-
-extern u32 gUnknown_8115E94[5][3]; // NOTE: Factor of two difference in array sizes
-
-s32 CalculateFacingDir(short *param_1,short *param_2)
-{
- s32 uVar1;
- s32 uVar2;
- s32 uVar3;
-
- uVar3 = param_2[0] - param_1[0];
- uVar2 = param_2[1] - param_1[1];
- if ((uVar3 == 0) && (uVar2 == 0)) {
- uVar1 = 0;
- }
- else {
- if (0 < uVar3) {
- uVar3 = 1;
- }
- if (0 < uVar2) {
- uVar2 = 1;
- }
- if (-1 >= uVar3) {
- uVar3 = -1;
- }
- if (-1 >= uVar2) {
- uVar2 = -1;
- }
- uVar1 = gUnknown_8115E94[(uVar2 + 1)][(uVar3 + 1)];
- }
- return uVar1;
-}
-
-s32 GetMaxPositionDifference(short param_1[],short param_2[])
-{
- s32 diff_index1;
- s32 diff_index0;
-
- diff_index0 = param_1[0] - param_2[0];
- if (diff_index0 < 0) {
- diff_index0 = -diff_index0;
- }
- diff_index1 = param_1[1] - param_2[1];
- if (diff_index1 < 0) {
- diff_index1 = -diff_index1;
- }
- if (diff_index1 < diff_index0) {
- diff_index1 = diff_index0;
- }
- return diff_index1;
-}
-
diff --git a/src/dungeon_action.c b/src/dungeon_action.c
index 6d8fcb3..9034e4c 100644
--- a/src/dungeon_action.c
+++ b/src/dungeon_action.c
@@ -1,6 +1,9 @@
#include "global.h"
#include "dungeon_action.h"
+
+#include "constants/dungeon_action.h"
#include "dungeon_entity.h"
+#include "pokemon.h"
void SetAction(struct DungeonActionContainer *actionPointer, u16 action)
{
@@ -8,3 +11,17 @@ void SetAction(struct DungeonActionContainer *actionPointer, u16 action)
actionPointer->actionUseIndex = 0;
actionPointer->unkC = 0;
}
+
+void SetWalkAction(struct DungeonActionContainer *actionPointer, s16 species)
+{
+ if (GetIsMoving(species))
+ {
+ actionPointer->action = DUNGEON_ACTION_WALK;
+ }
+ else
+ {
+ actionPointer->action = DUNGEON_ACTION_WAIT;
+ }
+ actionPointer->actionUseIndex = 0;
+ actionPointer->unkC = 0;
+}
diff --git a/src/dungeon_ai_item_weight.c b/src/dungeon_ai_item_weight.c
index 2f497cc..6c9669b 100644
--- a/src/dungeon_ai_item_weight.c
+++ b/src/dungeon_ai_item_weight.c
@@ -9,8 +9,7 @@
#include "dungeon_util.h"
#include "moves.h"
#include "number_util.h"
-
-extern bool8 HasNegativeStatus(struct DungeonEntity*);
+#include "status_checks_1.h"
u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32 itemTargetFlags)
{
@@ -96,7 +95,7 @@ u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32
}
}
}
- if (itemWeight > 98)
+ if (itemWeight >= 99)
{
itemWeight = 99;
}
diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c
index 8751eb1..d515ebb 100644
--- a/src/dungeon_ai_items.c
+++ b/src/dungeon_ai_items.c
@@ -22,6 +22,7 @@
#include "dungeon_visibility.h"
#include "item.h"
#include "position.h"
+#include "position_util.h"
#include "team_inventory.h"
#define NUM_POTENTIAL_ROCK_TARGETS 20
@@ -35,7 +36,6 @@ enum ItemTargetFlag
ITEM_TARGET_ALLY = 1 << 1
};
-extern s32 CalculateFacingDir(struct Position*, struct Position*);
extern void sub_8077274(struct DungeonEntity *, struct DungeonEntity *);
extern s32 gNumPotentialTargets;
diff --git a/src/dungeon_movement.c b/src/dungeon_movement.c
index bcf6163..d342262 100644
--- a/src/dungeon_movement.c
+++ b/src/dungeon_movement.c
@@ -6,6 +6,8 @@
#include "constants/iq_skill.h"
#include "constants/status.h"
#include "constants/targeting.h"
+#include "code_80521D0.h"
+#include "dungeon_action.h"
#include "dungeon_ai_items.h"
#include "dungeon_capabilities_1.h"
#include "dungeon_global_data.h"
@@ -16,6 +18,7 @@
#include "dungeon_visibility.h"
#include "map.h"
#include "pokemon.h"
+#include "status_checks.h"
extern char gAvailablePokemonNames[];
extern char *gPtrCouldntBeUsedMessage;
@@ -23,10 +26,7 @@ extern char *gPtrItsaMonsterHouseMessage;
extern void SendImmobilizeEndMessage(struct DungeonEntity*, struct DungeonEntity*);
extern void SetMessageArgument(char[], struct DungeonEntity*, u32);
-extern void SendMessage(struct DungeonEntity*, char*);
-extern bool8 HasStatusAffectingActions(struct DungeonEntity*);
extern void ResetAction(u16*);
-extern void SetWalkAction(u16*, s16);
extern void DecideAttack(struct DungeonEntity*);
extern void MoveIfPossible(struct DungeonEntity*, bool8);
extern u8 sub_8044B28(void);
@@ -155,7 +155,7 @@ void sub_8075900(struct DungeonEntity *pokemon, u8 r1)
void DecideAction(struct DungeonEntity *pokemon)
{
struct DungeonEntityData *pokemonData = pokemon->entityData;
- if ((pokemonData->flags & MOVEMENT_FLAG_SWAPPED_PLACES_PETRIFIED) != 0)
+ if (pokemonData->flags & MOVEMENT_FLAG_SWAPPED_PLACES_PETRIFIED)
{
if (pokemonData->immobilizeStatus == IMMOBILIZE_STATUS_PETRIFIED)
{
@@ -209,8 +209,8 @@ void DecideAction(struct DungeonEntity *pokemon)
ResetAction(&pokemonData->action.action);
if (pokemonData->clientType == CLIENT_TYPE_CLIENT)
{
- SetWalkAction(&pokemonData->action.action, pokemonData->entityID);
- pokemonData->action.facingDir = DungeonRandomCapped(8);
+ SetWalkAction(&pokemonData->action, pokemonData->entityID);
+ pokemonData->action.facingDir = DungeonRandomCapped(NUM_DIRECTIONS);
pokemonData->targetPosition.x = pokemon->posWorld.x;
pokemonData->targetPosition.y = pokemon->posWorld.y - 1;
}
@@ -228,7 +228,7 @@ void DecideAction(struct DungeonEntity *pokemon)
}
if (pokemonData->volatileStatus == VOLATILE_STATUS_CONFUSED)
{
- SetWalkAction(&pokemonData->action.action, pokemonData->entityID);
+ SetWalkAction(&pokemonData->action, pokemonData->entityID);
}
else
{
@@ -243,7 +243,7 @@ void DecideAction(struct DungeonEntity *pokemon)
{
if (pokemonData->volatileStatus == VOLATILE_STATUS_CONFUSED)
{
- SetWalkAction(&pokemonData->action.action, pokemonData->entityID);
+ SetWalkAction(&pokemonData->action, pokemonData->entityID);
}
else
{
diff --git a/src/friend_list_menu.c b/src/friend_list_menu.c
index 7dbc441..50b8c02 100644
--- a/src/friend_list_menu.c
+++ b/src/friend_list_menu.c
@@ -208,7 +208,7 @@ void sub_8026C14(void)
struct unkStruct_8090F58 temp;
int menuAction;
struct ItemSlot slot;
-
+
menuAction = 0;
sub_801A6E8(0);
if ((sub_8012FD8(&gUnknown_203B2B8->unkCC) == '\0') && (sub_8013114(&gUnknown_203B2B8->unkCC,&menuAction), menuAction != 1)) {
diff --git a/src/position_util.c b/src/position_util.c
new file mode 100644
index 0000000..26a8c51
--- /dev/null
+++ b/src/position_util.c
@@ -0,0 +1,65 @@
+#include "global.h"
+#include "position_util.h"
+
+#include "constants/direction.h"
+
+const s32 gFacingDirMapping[3][3] = {
+ {DIRECTION_NORTHWEST, DIRECTION_NORTH, DIRECTION_NORTHEAST},
+ {DIRECTION_WEST, DIRECTION_SOUTH, DIRECTION_EAST},
+ {DIRECTION_SOUTHWEST, DIRECTION_SOUTH, DIRECTION_SOUTHEAST}
+};
+
+s32 CalculateFacingDir(struct Position *originPos, struct Position *targetPos)
+{
+ s32 facingDir;
+ s32 yDiff;
+ s32 xDiff;
+
+ xDiff = targetPos->x - originPos->x;
+ yDiff = targetPos->y - originPos->y;
+ if (xDiff == 0 && yDiff == 0)
+ {
+ facingDir = DIRECTION_SOUTH;
+ }
+ else
+ {
+ if (xDiff > 0)
+ {
+ xDiff = 1;
+ }
+ if (yDiff > 0)
+ {
+ yDiff = 1;
+ }
+ if (xDiff <= -1)
+ {
+ xDiff = -1;
+ }
+ if (yDiff <= -1)
+ {
+ yDiff = -1;
+ }
+ facingDir = gFacingDirMapping[yDiff + 1][xDiff + 1];
+ }
+ return facingDir;
+}
+
+s32 GetMaxPositionDifference(short param_1[],short param_2[])
+{
+ s32 diff_index1;
+ s32 diff_index0;
+
+ diff_index0 = param_1[0] - param_2[0];
+ if (diff_index0 < 0) {
+ diff_index0 = -diff_index0;
+ }
+ diff_index1 = param_1[1] - param_2[1];
+ if (diff_index1 < 0) {
+ diff_index1 = -diff_index1;
+ }
+ if (diff_index1 < diff_index0) {
+ diff_index1 = diff_index0;
+ }
+ return diff_index1;
+}
+
diff --git a/src/status_checks.c b/src/status_checks.c
new file mode 100644
index 0000000..ed39e99
--- /dev/null
+++ b/src/status_checks.c
@@ -0,0 +1,102 @@
+#include "global.h"
+#include "status_checks.h"
+
+#include "constants/direction.h"
+#include "constants/dungeon_action.h"
+#include "constants/status.h"
+#include "code_80521D0.h"
+#include "dungeon_action.h"
+#include "dungeon_random.h"
+
+extern char *gPtrFrozenMessage;
+extern char *gPtrWrappedAroundMessage;
+extern char *gPtrWrappedByMessage;
+extern char *gPtrBideMessage;
+extern char *gPtrPausedMessage;
+extern char *gPtrInfatuatedMessage;
+extern char gAvailablePokemonNames[];
+
+extern void SetMessageArgument(char[], struct DungeonEntity*, u32);
+extern bool8 CanMoveForward2(struct DungeonEntity*, u8);
+extern void DecideAttack(struct DungeonEntity*);
+
+bool8 HasStatusAffectingActions(struct DungeonEntity *pokemon)
+{
+ struct DungeonEntityData *pokemonData = pokemon->entityData;
+ SetMessageArgument(gAvailablePokemonNames, pokemon, 0);
+ SetAction(&pokemonData->action, DUNGEON_ACTION_WAIT);
+ switch (pokemonData->sleepStatus)
+ {
+ case SLEEP_STATUS_NIGHTMARE:
+ case SLEEP_STATUS_SLEEP:
+ case SLEEP_STATUS_NAPPING:
+ return TRUE;
+ }
+ switch (pokemonData->immobilizeStatus)
+ {
+ case IMMOBILIZE_STATUS_FROZEN:
+ SendMessage(pokemon, gPtrFrozenMessage);
+ return TRUE;
+ case IMMOBILIZE_STATUS_WRAPPED_AROUND_FOE:
+ SendMessage(pokemon, gPtrWrappedAroundMessage);
+ return TRUE;
+ case IMMOBILIZE_STATUS_WRAPPED_BY_FOE:
+ SendMessage(pokemon, gPtrWrappedByMessage);
+ return TRUE;
+ case IMMOBILIZE_STATUS_PETRIFIED:
+ return TRUE;
+ }
+ switch (pokemonData->volatileStatus)
+ {
+ case VOLATILE_STATUS_PAUSED:
+ SendMessage(pokemon, gPtrPausedMessage);
+ return TRUE;
+ case VOLATILE_STATUS_INFATUATED:
+ SendMessage(pokemon, gPtrInfatuatedMessage);
+ return TRUE;
+ }
+ if (pokemonData->chargingStatus == CHARGING_STATUS_BIDE)
+ {
+ SendMessage(pokemon, gPtrBideMessage);
+ return TRUE;
+ }
+ if (pokemonData->waitingStatus == WAITING_STATUS_DECOY)
+ {
+ SetWalkAction(&pokemonData->action, pokemonData->entityID);
+ pokemonData->action.facingDir = DungeonRandomCapped(NUM_DIRECTIONS);
+ pokemonData->targetPosition.x = pokemon->posWorld.x;
+ pokemonData->targetPosition.y = pokemon->posWorld.y - 1;
+ return TRUE;
+ }
+ if (pokemonData->shopkeeperMode == SHOPKEEPER_FRIENDLY)
+ {
+ return TRUE;
+ }
+ if (pokemonData->eyesightStatus == EYESIGHT_STATUS_BLINKER)
+ {
+ if (!CanMoveForward2(pokemon, pokemonData->action.facingDir))
+ {
+ if (DungeonRandomCapped(2) != 0)
+ {
+ pokemonData->action.facingDir = DungeonRandomCapped(NUM_DIRECTIONS);
+ pokemonData->action.facingDir = pokemonData->action.facingDir & DIRECTION_MASK;
+ goto walk;
+ }
+ }
+ else
+ {
+ walk:
+ SetWalkAction(&pokemonData->action, pokemonData->entityID);
+ return TRUE;
+ }
+ DecideAttack(pokemon);
+ return TRUE;
+ }
+ if (pokemonData->eyesightStatus == EYESIGHT_STATUS_CROSS_EYED)
+ {
+ SetWalkAction(&pokemonData->action, pokemonData->entityID);
+ pokemonData->action.facingDir = DungeonRandomCapped(NUM_DIRECTIONS);
+ return TRUE;
+ }
+ return FALSE;
+}
diff --git a/src/status_checks_1.c b/src/status_checks_1.c
new file mode 100644
index 0000000..9d0bfe8
--- /dev/null
+++ b/src/status_checks_1.c
@@ -0,0 +1,55 @@
+#include "global.h"
+#include "status_checks_1.h"
+
+#include "constants/status.h"
+
+bool8 HasNegativeStatus(struct DungeonEntity *pokemon)
+{
+ struct DungeonEntityData *pokemonData = pokemon->entityData;
+ s32 i;
+ if (pokemonData->sleepStatus == SLEEP_STATUS_SLEEP ||
+ pokemonData->sleepStatus == SLEEP_STATUS_NIGHTMARE ||
+ pokemonData->sleepStatus == SLEEP_STATUS_YAWNING ||
+ pokemonData->nonVolatileStatus != NON_VOLATILE_STATUS_NONE ||
+ (pokemonData->immobilizeStatus != IMMOBILIZE_STATUS_INGRAIN && pokemonData->immobilizeStatus != IMMOBILIZE_STATUS_NONE) ||
+ pokemonData->volatileStatus != VOLATILE_STATUS_NONE ||
+ pokemonData->waitingStatus == WAITING_STATUS_CURSED ||
+ pokemonData->waitingStatus == WAITING_STATUS_DECOY ||
+ pokemonData->linkedStatus == LINKED_STATUS_LEECH_SEED ||
+ pokemonData->moveStatus == MOVE_STATUS_WHIFFER ||
+ pokemonData->eyesightStatus == EYESIGHT_STATUS_BLINKER ||
+ pokemonData->eyesightStatus == EYESIGHT_STATUS_CROSS_EYED ||
+ pokemonData->muzzledStatus == MUZZLED_STATUS_MUZZLED ||
+ pokemonData->exposedStatus ||
+ pokemonData->perishSongTimer != 0)
+ {
+ return TRUE;
+ }
+ for (i = 0; i < MAX_MON_MOVES; i++)
+ {
+ struct PokemonMove *moves = pokemonData->moves;
+ if (moves[i].moveFlags & MOVE_FLAG_EXISTS && moves[i].sealed & TRUE)
+ {
+ return TRUE;
+ }
+ }
+ for (i = 0; i < NUM_SPEED_TURN_COUNTERS; i++)
+ {
+ if (pokemonData->slowTurnsLeft[i] != 0)
+ {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+bool8 IsSleeping(struct DungeonEntity *pokemon)
+{
+ if (pokemon->entityData->sleepStatus != SLEEP_STATUS_SLEEP &&
+ pokemon->entityData->sleepStatus != SLEEP_STATUS_NAPPING &&
+ pokemon->entityData->sleepStatus != SLEEP_STATUS_NIGHTMARE)
+ {
+ return FALSE;
+ }
+ return TRUE;
+}