diff options
author | Cheng Hann Gan <chenghanngan.us@gmail.com> | 2021-12-09 13:56:12 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-09 10:56:12 -0800 |
commit | a34c9ab91b553fcb1f72b94eb912b94bea58885b (patch) | |
tree | a31d0805938a56d1552f952db6ec6ab2defdebe5 /src | |
parent | 4fc272fea6bc7332fae031ebeb12362cff1c35de (diff) |
AI decomp + type cleanup (#82)
* Decomped SetAction()
* Changed MapTile.tileType to u16 bit field
* Decomped FindStraightThrowableTargets()
* Cleaned up CannotAttack()
* Cleaned up some externs
* Converted dungeon action to substruct
Diffstat (limited to 'src')
-rw-r--r-- | src/code_80521D0_1.c | 16 | ||||
-rw-r--r-- | src/code_8057824_1.c | 2 | ||||
-rw-r--r-- | src/code_806CD90.c | 9 | ||||
-rw-r--r-- | src/code_80869E4.c | 2 | ||||
-rw-r--r-- | src/dungeon_action.c | 10 | ||||
-rw-r--r-- | src/dungeon_ai_items.c | 120 | ||||
-rw-r--r-- | src/dungeon_capabilities_1.c | 32 | ||||
-rw-r--r-- | src/dungeon_movement.c | 50 | ||||
-rw-r--r-- | src/dungeon_util.c | 2 | ||||
-rw-r--r-- | src/dungeon_util_1.c | 17 |
10 files changed, 159 insertions, 101 deletions
diff --git a/src/code_80521D0_1.c b/src/code_80521D0_1.c index 0ed02f1..433194d 100644 --- a/src/code_80521D0_1.c +++ b/src/code_80521D0_1.c @@ -209,9 +209,9 @@ void sub_808BCE4(void) struct MapTile *puVar1; puVar1 = GetMapEntity(gDungeonGlobalData->unkE23C, gDungeonGlobalData->unkE23E); - puVar1->MapTileUnion.tileFlags_u16 &= 0xfffc; - puVar1->MapTileUnion.tileFlags_u16 |= TILE_TYPE_MAP_EDGE; - puVar1->MapTileUnion.tileFlags_u16 &= 0xfdff; + puVar1->tileType &= ~(TILE_TYPE_FLOOR | TILE_TYPE_UNK_1); + puVar1->tileType |= TILE_TYPE_MAP_EDGE; + puVar1->tileType &= ~TILE_TYPE_STAIRS; sub_8049884(); sub_8049B8C(); sub_8049ED4(); @@ -223,10 +223,10 @@ void sub_808BD38(void) struct MapTile *puVar1; puVar1 = GetMapEntity(gDungeonGlobalData->unkE23C, gDungeonGlobalData->unkE23E); - puVar1->MapTileUnion.tileFlags_u16 &= 0xfffc; - puVar1->MapTileUnion.tileFlags_u16 |= TILE_TYPE_FLOOR; - puVar1->MapTileUnion.tileFlags_u16 &= 0xffef; - puVar1->MapTileUnion.tileFlags_u16 |= TILE_TYPE_STAIRS; + puVar1->tileType &= ~(TILE_TYPE_FLOOR | TILE_TYPE_UNK_1); + puVar1->tileType |= TILE_TYPE_FLOOR; + puVar1->tileType &= ~TILE_TYPE_MAP_EDGE; + puVar1->tileType |= TILE_TYPE_STAIRS; puVar1->unk8 = 1; sub_8049884(); sub_8049B8C(); @@ -1114,7 +1114,7 @@ void sub_808C998(void) void sub_808C9B0(struct DungeonEntity *param_1) { - param_1->entityData->facingDir = DIRECTION_NORTH; + param_1->entityData->action.facingDir = DIRECTION_NORTH; sub_806CE68(param_1, DIRECTION_NORTH); } diff --git a/src/code_8057824_1.c b/src/code_8057824_1.c index f79299a..5409061 100644 --- a/src/code_8057824_1.c +++ b/src/code_8057824_1.c @@ -3364,7 +3364,7 @@ void sub_808B1CC(u8 r0) void SetupRegiFacingDirection(struct DungeonEntity *r0) { - r0->entityData->facingDir = DIRECTION_NORTH; + r0->entityData->action.facingDir = DIRECTION_NORTH; sub_806CE68(r0, DIRECTION_NORTH); } diff --git a/src/code_806CD90.c b/src/code_806CD90.c index 30ca41d..e11f253 100644 --- a/src/code_806CD90.c +++ b/src/code_806CD90.c @@ -1,14 +1,13 @@ #include "global.h" -#include "dungeon_global_data.h" -#include "dungeon_entity.h" #include "constants/direction.h" +#include "dungeon_entity.h" +#include "dungeon_global_data.h" +#include "dungeon_util.h" extern struct DungeonGlobalData *gDungeonGlobalData; extern u8 sub_806CEBC(struct DungeonEntity *); -extern bool8 EntityExists(struct DungeonEntity *); extern void sub_806CCB4(struct DungeonEntity *, u8); -extern u32 GetEntityType(struct DungeonEntity *); void sub_806CD90(void) { @@ -57,7 +56,7 @@ void sub_806CE34(struct DungeonEntity *r0, u32 newDir) r0->unk6A = sub_806CEBC(r0); if(newDir < NUM_DIRECTIONS) { - r0->entityData->facingDir = newDir & DIRECTION_MASK; + r0->entityData->action.facingDir = newDir & DIRECTION_MASK; r0->facingDir = newDir & DIRECTION_MASK; } } diff --git a/src/code_80869E4.c b/src/code_80869E4.c index d7ebaf5..30bae49 100644 --- a/src/code_80869E4.c +++ b/src/code_80869E4.c @@ -479,7 +479,7 @@ void SpriteLookAroundEffect(struct DungeonEntity *r0) s8 r4; s8 r3; - r4 = sub_8002984(r0->entityData->facingDir, 4); + r4 = sub_8002984(r0->entityData->action.facingDir, 4); sub_80869E4(r0, 4, 2, r4); diff --git a/src/dungeon_action.c b/src/dungeon_action.c new file mode 100644 index 0000000..6d8fcb3 --- /dev/null +++ b/src/dungeon_action.c @@ -0,0 +1,10 @@ +#include "global.h" +#include "dungeon_action.h" +#include "dungeon_entity.h" + +void SetAction(struct DungeonActionContainer *actionPointer, u16 action) +{ + actionPointer->action = action; + actionPointer->actionUseIndex = 0; + actionPointer->unkC = 0; +} diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 7a348f1..48b675a 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -1,40 +1,53 @@ #include "global.h" -#include "dungeon_ai_items.h" #include "constants/direction.h" #include "constants/dungeon_action.h" #include "constants/iq_skill.h" +#include "dungeon_action.h" +#include "dungeon_ai_items.h" #include "dungeon_capabilities.h" #include "dungeon_capabilities_1.h" +#include "dungeon_entity.h" #include "dungeon_global_data.h" +#include "dungeon_pokemon_attributes_1.h" +#include "dungeon_util.h" #include "item.h" #include "team_inventory.h" #define NUM_POTENTIAL_ROCK_TARGETS 20 #define GROUND_ITEM_TOOLBOX_INDEX 0x80 #define HELD_ITEM_TOOLBOX_INDEX 0x81 -#define ITEM_TARGET_ALLY 1 << 1 -extern void SetAction(u16*, u16); -extern void FindStraightThrowableTargets(struct DungeonEntity*, s32 thrownAIFlag, struct ItemSlot*, bool8 ignoreRollChance); +enum ItemTargetFlag +{ + ITEM_TARGET_OTHER = 1 << 0, + ITEM_TARGET_ALLY = 1 << 1 +}; + +enum TargetCapability +{ + TARGET_CAPABILITY_CANNOT_ATTACK, + TARGET_CAPABILITY_CAN_TARGET, + TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET +}; + extern bool8 RollPercentChance(u32); -extern void FindRockItemTargets(struct DungeonEntity*, struct ItemSlot*, s16*[], bool8 ignoreRollChance); +extern void FindRockItemTargets(struct DungeonEntity*, struct ItemSlot*, s16*[], bool8); extern s32 DungeonRandomCapped(s32); extern s32 CalculateFacingDir(s16*, s16*); -extern bool8 HasIQSkill(struct DungeonEntity*, u8); extern struct MapTile* GetMapTileAtPosition(s16, s16); -extern u32 GetEntityType(struct DungeonEntity*); -extern struct ItemSlot* GetItemData(struct DungeonEntity*); extern u32 EvaluateItem(struct DungeonEntity*, struct ItemSlot*, u8); extern bool8 ToolboxEnabled(struct DungeonEntityData*); extern void sub_8077274(struct DungeonEntity *, struct DungeonEntity *); -extern bool8 EntityExists(struct DungeonEntity *); +extern bool8 CanTarget(struct DungeonEntity*, struct DungeonEntity*, bool8, bool8); +extern bool8 CanSee(struct DungeonEntity*, struct DungeonEntity*); +extern void TargetThrownItem(struct DungeonEntity*, struct DungeonEntity*, struct ItemSlot*, u8, bool8); extern s32 gNumPotentialTargets; extern u32 gPotentialTargetWeights[NUM_DIRECTIONS]; extern u32 gPotentialTargetDirections[NUM_DIRECTIONS]; +extern bool8 gTargetAhead[NUM_DIRECTIONS]; extern struct TeamInventory *gTeamInventory_203B460; - extern struct DungeonGlobalData *gDungeonGlobalData; void sub_807360C(struct DungeonEntity *pokemon) @@ -49,7 +62,7 @@ void sub_807360C(struct DungeonEntity *pokemon) { if(entity->entityData->unk152 != 0) { - entity->entityData->unk152 = 0; + entity->entityData->unk152 = 0; sub_8077274(entity, entity); } } @@ -91,10 +104,10 @@ void DecideUseItem(struct DungeonEntity *pokemon) if (RollPercentChance(gPotentialTargetWeights[targetIndex])) { SetAction(&pokemonData->action, DUNGEON_ACTION_THROW_ITEM_AI); - pokemonData->actionUseIndex = selectedToolboxIndex; - pokemonData->lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->lastItemThrowPositionY = pokemon->posWorldY; - pokemonData->facingDir = gPotentialTargetDirections[targetIndex] & DIRECTION_MASK; + pokemonData->action.actionUseIndex = selectedToolboxIndex; + pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; + pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; + pokemonData->action.facingDir = gPotentialTargetDirections[targetIndex] & DIRECTION_MASK; break; } } @@ -115,10 +128,10 @@ void DecideUseItem(struct DungeonEntity *pokemon) { u32 chosenTargetIndex = DungeonRandomCapped(gNumPotentialTargets); SetAction(&pokemonData->action, DUNGEON_ACTION_THROW_ITEM_AI); - pokemonData->actionUseIndex = selectedToolboxIndex; - pokemonData->lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->lastItemThrowPositionY = pokemon->posWorldY; - pokemonData->facingDir = CalculateFacingDir(&pokemon->posWorldX, (s16 *) (&potentialTargetPositions[chosenTargetIndex])) & DIRECTION_MASK; + pokemonData->action.actionUseIndex = selectedToolboxIndex; + pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; + pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; + pokemonData->action.facingDir = CalculateFacingDir(&pokemon->posWorldX, (s16 *) (&potentialTargetPositions[chosenTargetIndex])) & DIRECTION_MASK; pokemonData->itemTargetPosition = potentialTargetPositions[chosenTargetIndex]; } } @@ -128,9 +141,9 @@ void DecideUseItem(struct DungeonEntity *pokemon) if (itemTypeCompare < ITEM_TYPE_HOLD_ITEM - 2) { SetAction(&pokemonData->action, DUNGEON_ACTION_CONSUME_ITEM_AI); - pokemonData->actionUseIndex = selectedToolboxIndex; - pokemonData->lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->lastItemThrowPositionY = pokemon->posWorldY; + pokemonData->action.actionUseIndex = selectedToolboxIndex; + pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; + pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; } else { @@ -200,9 +213,9 @@ void DecideUseItem(struct DungeonEntity *pokemon) { SetAction(&pokemonData->action, DUNGEON_ACTION_CONSUME_ITEM_AI); } - pokemonData->actionUseIndex = selectedToolboxIndex; - pokemonData->lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->lastItemThrowPositionY = pokemon->posWorldY; + pokemonData->action.actionUseIndex = selectedToolboxIndex; + pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; + pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; return; } } @@ -234,10 +247,10 @@ void DecideUseItem(struct DungeonEntity *pokemon) { u32 chosenTargetIndex = DungeonRandomCapped(gNumPotentialTargets); SetAction(&pokemonData->action, DUNGEON_ACTION_THROW_ITEM_AI); - pokemonData->actionUseIndex = selectedToolboxIndex; - pokemonData->lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->lastItemThrowPositionY = pokemon->posWorldY; - pokemonData->facingDir = CalculateFacingDir(&pokemon->posWorldX, (s16 *) (&potentialTargetPositions[chosenTargetIndex])) & DIRECTION_MASK; + pokemonData->action.actionUseIndex = selectedToolboxIndex; + pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; + pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; + pokemonData->action.facingDir = CalculateFacingDir(&pokemon->posWorldX, (s16 *) (&potentialTargetPositions[chosenTargetIndex])) & DIRECTION_MASK; pokemonData->itemTargetPosition = potentialTargetPositions[chosenTargetIndex]; return; } @@ -251,10 +264,10 @@ void DecideUseItem(struct DungeonEntity *pokemon) if (RollPercentChance(potentialTargetWeights[targetIndex])) { SetAction(&pokemonData->action, DUNGEON_ACTION_THROW_ITEM_AI); - pokemonData->actionUseIndex = selectedToolboxIndex; - pokemonData->lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->lastItemThrowPositionY = pokemon->posWorldY; - pokemonData->facingDir = gPotentialTargetDirections[targetIndex] & DIRECTION_MASK; + pokemonData->action.actionUseIndex = selectedToolboxIndex; + pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; + pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; + pokemonData->action.facingDir = gPotentialTargetDirections[targetIndex] & DIRECTION_MASK; return; } } @@ -265,3 +278,44 @@ void DecideUseItem(struct DungeonEntity *pokemon) } } } + +void FindStraightThrowableTargets(struct DungeonEntity* pokemon, s32 thrownAIFlag, struct ItemSlot* item, bool8 ignoreRollChance) +{ + s32 i; + gNumPotentialTargets = 0; + for (i = 0; i < NUM_DIRECTIONS; i++) + { + gTargetAhead[i] = FALSE; + } + for (i = 0; i < DUNGEON_MAX_POKEMON; i++) + { + struct DungeonEntity* targetPokemon = gDungeonGlobalData->allPokemon[i]; + if (EntityExists(targetPokemon) && pokemon != targetPokemon) + { + u8 targetingFlags; + if (thrownAIFlag == ITEM_AI_FLAG_TARGET_ALLY) + { + if (CanTarget(pokemon, targetPokemon, FALSE, FALSE) == TARGET_CAPABILITY_CANNOT_ATTACK) + { + targetingFlags = ITEM_TARGET_OTHER | ITEM_TARGET_ALLY; + } + else + { + continue; + } + } + else if (CanTarget(pokemon, targetPokemon, FALSE, TRUE) == TARGET_CAPABILITY_CAN_TARGET) + { + targetingFlags = ITEM_TARGET_OTHER; + } + else + { + continue; + } + if (CanSee(pokemon, targetPokemon)) + { + TargetThrownItem(pokemon, targetPokemon, item, targetingFlags, ignoreRollChance); + } + } + } +} diff --git a/src/dungeon_capabilities_1.c b/src/dungeon_capabilities_1.c index 869e2f3..721bdcb 100644 --- a/src/dungeon_capabilities_1.c +++ b/src/dungeon_capabilities_1.c @@ -55,24 +55,22 @@ bool8 CannotAct(struct DungeonEntity *pokemon) return FALSE; } -bool8 CannotAttack(struct DungeonEntity *pokemon, u8 param_2) +bool8 CannotAttack(struct DungeonEntity *pokemon, bool8 skipSleep) { - struct DungeonEntityData *iVar3; - - iVar3 = pokemon->entityData; - if ((((((param_2 != '\0') || - (iVar3->sleepStatus == SLEEP_STATUS_SLEEPLESS)) || - (iVar3->sleepStatus == SLEEP_STATUS_YAWNING)) || - (iVar3->sleepStatus == SLEEP_STATUS_NONE)) && - ((((iVar3->immobilizeStatus != IMMOBILIZE_STATUS_FROZEN && - (iVar3->immobilizeStatus != IMMOBILIZE_STATUS_WRAPPED_AROUND_FOE)) && - ((iVar3->immobilizeStatus != IMMOBILIZE_STATUS_WRAPPED_BY_FOE && - ((iVar3->immobilizeStatus != IMMOBILIZE_STATUS_PETRIFIED && - (iVar3->volatileStatus != VOLATILE_STATUS_CRINGING)))))) && - (iVar3->volatileStatus != VOLATILE_STATUS_PAUSED)))) && - (((iVar3->volatileStatus != VOLATILE_STATUS_INFATUATED && - iVar3->nonVolatileStatus != NON_VOLATILE_STATUS_PARALYZED)) && - !ShouldAvoidEnemies(pokemon))) { + struct DungeonEntityData *pokemonData = pokemon->entityData; + if ((skipSleep || + pokemonData->sleepStatus == SLEEP_STATUS_SLEEPLESS || + pokemonData->sleepStatus == SLEEP_STATUS_YAWNING || + pokemonData->sleepStatus == SLEEP_STATUS_NONE) && + pokemonData->immobilizeStatus != IMMOBILIZE_STATUS_FROZEN && + pokemonData->immobilizeStatus != IMMOBILIZE_STATUS_WRAPPED_AROUND_FOE && + pokemonData->immobilizeStatus != IMMOBILIZE_STATUS_WRAPPED_BY_FOE && + pokemonData->immobilizeStatus != IMMOBILIZE_STATUS_PETRIFIED && + pokemonData->volatileStatus != VOLATILE_STATUS_CRINGING && + pokemonData->volatileStatus != VOLATILE_STATUS_PAUSED && + pokemonData->volatileStatus != VOLATILE_STATUS_INFATUATED && + pokemonData->nonVolatileStatus != NON_VOLATILE_STATUS_PARALYZED && + !ShouldAvoidEnemies(pokemon)) { return FALSE; } return TRUE; diff --git a/src/dungeon_movement.c b/src/dungeon_movement.c index 5525f28..6bb225e 100644 --- a/src/dungeon_movement.c +++ b/src/dungeon_movement.c @@ -5,9 +5,14 @@ #include "constants/direction.h" #include "constants/iq_skill.h" #include "constants/status.h" -#include "dungeon_global_data.h" +#include "dungeon_ai_items.h" #include "dungeon_capabilities_1.h" +#include "dungeon_global_data.h" +#include "dungeon_pokemon_attributes_1.h" +#include "dungeon_util.h" +#include "dungeon_util_1.h" #include "map.h" +#include "pokemon.h" extern char gAvailablePokemonNames[]; extern char *gPtrCouldntBeUsedMessage; @@ -15,30 +20,21 @@ extern char *gPtrItsaMonsterHouseMessage; extern struct DungeonGlobalData *gDungeonGlobalData; extern void SendImmobilizeEndMessage(struct DungeonEntity*, struct DungeonEntity*); -extern bool8 IsMovingClient(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); extern u8 sub_8044B28(void); -struct MapTile *sub_8045128(struct DungeonEntity *entity); extern void sub_807AB38(struct DungeonEntity *, u32); extern void sub_8041888(u32); extern u8 sub_803F428(s16 *); extern void sub_803E708(u32, u32); extern struct DungeonEntity *GetLeaderEntity(); -struct ItemSlot *GetItemData(struct DungeonEntity *entity); -u8 *GetTrapData(struct DungeonEntity *entity); -u32 GetEntityType(struct DungeonEntity *entity); extern void TargetTileInFront(struct DungeonEntity *); u32 sub_8075818(struct DungeonEntity *entity) @@ -55,7 +51,7 @@ u32 sub_8075818(struct DungeonEntity *entity) { tile = sub_8045128(entity); if(HasIQSkill(entity, IQ_SKILL_SUPER_MOBILE)) - if(!(tile->MapTileUnion.tileFlags_u16 & 3)) + if(!(tile->tileType & (TILE_TYPE_FLOOR | TILE_TYPE_UNK_1))) return 1; subEntity = tile->mapObject; if(subEntity != NULL) @@ -68,7 +64,7 @@ u32 sub_8075818(struct DungeonEntity *entity) case 5: break; case ENTITY_TRAP: - trapData = GetTrapData(subEntity); + trapData = (u8*) GetTrapData(subEntity); r1 = 0; if(trapData[1] == 0) { @@ -99,7 +95,7 @@ flag_check: { if(!(entityData->heldItem.itemFlags & ITEM_FLAG_EXISTS)) { - if(!(tile->MapTileUnion.tileFlags_u16 & 3)) + if(!(tile->tileType & (TILE_TYPE_FLOOR | TILE_TYPE_UNK_1))) { if(entityData->isEnemy) break; @@ -140,7 +136,7 @@ void sub_8075900(struct DungeonEntity *pokemon, u8 r1) { if(!gDungeonGlobalData->monsterHouseActive) { - if((sub_8045128(pokemon)->MapTileUnion.tileFlags_u16 & TILE_TYPE_MONSTER_HOUSE)) + if((sub_8045128(pokemon)->tileType & TILE_TYPE_MONSTER_HOUSE)) { // It's a monster house! SendMessage(GetLeaderEntity(), gPtrItsaMonsterHouseMessage); @@ -163,7 +159,7 @@ void DecideAction(struct DungeonEntity *pokemon) { if (pokemonData->immobilizeStatus == IMMOBILIZE_STATUS_PETRIFIED) { - SendImmobilizeEndMessage(pokemon, pokemon); + SendImmobilizeEndMessage(pokemon, pokemon); } } else @@ -181,7 +177,7 @@ void DecideAction(struct DungeonEntity *pokemon) return; } DecideUseItem(pokemon); - if (pokemonData->action != DUNGEON_ACTION_NONE) + if (pokemonData->action.action != DUNGEON_ACTION_NONE) { return; } @@ -210,29 +206,29 @@ void DecideAction(struct DungeonEntity *pokemon) } } } - ResetAction(&pokemonData->action); + ResetAction(&pokemonData->action.action); if (pokemonData->clientType == CLIENT_TYPE_CLIENT) { - SetWalkAction(&pokemonData->action, pokemonData->entityID); - pokemonData->facingDir = DungeonRandomCapped(8); + SetWalkAction(&pokemonData->action.action, pokemonData->entityID); + pokemonData->action.facingDir = DungeonRandomCapped(8); pokemonData->targetPositionX = pokemon->posWorldX; pokemonData->targetPositionY = pokemon->posWorldY - 1; } else { DecideUseItem(pokemon); - if (pokemonData->action == DUNGEON_ACTION_NONE) + if (pokemonData->action.action == DUNGEON_ACTION_NONE) { if (!HasIQSkill(pokemon, IQ_SKILL_DEDICATED_TRAVELER)) { DecideAttack(pokemon); - if (pokemonData->action != DUNGEON_ACTION_NONE) + if (pokemonData->action.action != DUNGEON_ACTION_NONE) { return; } if (pokemonData->volatileStatus == VOLATILE_STATUS_CONFUSED) { - SetWalkAction(&pokemonData->action, pokemonData->entityID); + SetWalkAction(&pokemonData->action.action, pokemonData->entityID); } else { @@ -247,7 +243,7 @@ void DecideAction(struct DungeonEntity *pokemon) { if (pokemonData->volatileStatus == VOLATILE_STATUS_CONFUSED) { - SetWalkAction(&pokemonData->action, pokemonData->entityID); + SetWalkAction(&pokemonData->action.action, pokemonData->entityID); } else { @@ -255,12 +251,12 @@ void DecideAction(struct DungeonEntity *pokemon) { MoveIfPossible(pokemon, TRUE); } - if (pokemonData->action > DUNGEON_ACTION_WAIT) + if (pokemonData->action.action > DUNGEON_ACTION_WAIT) { return; } DecideAttack(pokemon); - if (pokemonData->action <= DUNGEON_ACTION_WAIT) + if (pokemonData->action.action <= DUNGEON_ACTION_WAIT) { return; } @@ -281,11 +277,11 @@ void sub_8075BA4(struct DungeonEntity *param_1,char param_2) struct DungeonEntityData * iVar2 = param_1->entityData; if ((param_2 != '\0') && (iVar2->volatileStatus == VOLATILE_STATUS_COWERING)) { - iVar2->facingDir = (iVar2->facingDir + 4) & DIRECTION_MASK; + iVar2->action.facingDir = (iVar2->action.facingDir + 4) & DIRECTION_MASK; TargetTileInFront(param_1); } else if (iVar2->volatileStatus == VOLATILE_STATUS_CONFUSED) { - iVar2->facingDir = DungeonRandomCapped(NUM_DIRECTIONS); + iVar2->action.facingDir = DungeonRandomCapped(NUM_DIRECTIONS); TargetTileInFront(param_1); } } diff --git a/src/dungeon_util.c b/src/dungeon_util.c index f717212..5943d4b 100644 --- a/src/dungeon_util.c +++ b/src/dungeon_util.c @@ -2,7 +2,7 @@ #include "dungeon_util.h" extern struct MapTile* GetMapTileAtPosition(s16, s16); -extern struct MapTile *GetMapEntity(s16, s16); +extern struct MapTile* GetMapEntity(s16, s16); bool8 EntityExists(struct DungeonEntity *entity) { diff --git a/src/dungeon_util_1.c b/src/dungeon_util_1.c index 51ec765..32cc3ff 100644 --- a/src/dungeon_util_1.c +++ b/src/dungeon_util_1.c @@ -1,11 +1,12 @@ #include "global.h" -#include "constants/direction.h" #include "dungeon_util_1.h" + +#include "constants/direction.h" #include "dungeon_global_data.h" +#include "dungeon_util.h" #include "random.h" extern struct DungeonGlobalData *gDungeonGlobalData; -extern bool8 EntityExists(struct DungeonEntity *); extern void sub_806CE68(struct DungeonEntity *, s32); extern s32 sub_803F994(void); @@ -16,7 +17,7 @@ extern void sub_803E46C(u32); void sub_8085860(s32 x, s32 y) { - + sub_803F4A0(0); sub_803F878(x * 0x1800 + 0xc00, y * 0x1800 + 0x1000); } @@ -33,7 +34,7 @@ void sub_80858AC(s32 *param_1, s32 param_2) s32 iVar2; s32 iVar3; s32 iVar4; - + iVar1 = sub_803F994(); iVar2 = sub_803F9B0(); iVar3 = (param_1[0] - iVar1) / param_2; @@ -54,7 +55,7 @@ void sub_80858AC(s32 *param_1, s32 param_2) void SetFacingDirection(struct DungeonEntity *pokemon, s32 direction) { - pokemon->entityData->facingDir = direction & DIRECTION_MASK; + pokemon->entityData->action.facingDir = direction & DIRECTION_MASK; sub_806CE68(pokemon, direction); } @@ -73,7 +74,7 @@ void sub_8085930(s32 direction) } else { - entity->entityData->facingDir = direction & DIRECTION_MASK; + entity->entityData->action.facingDir = direction & DIRECTION_MASK; sub_806CE68(entity, direction); } } @@ -91,7 +92,7 @@ void sub_8085930(s32 direction) } else { - entity->entityData->facingDir = direction & DIRECTION_MASK; + entity->entityData->action.facingDir = direction & DIRECTION_MASK; sub_806CE68(entity, direction); } } @@ -114,7 +115,7 @@ void sub_80859F0(s32 direction) } else { - entity->entityData->facingDir = direction & DIRECTION_MASK; + entity->entityData->action.facingDir = direction & DIRECTION_MASK; sub_806CE68(entity, direction); } } |