diff --git a/src/code_8048480.c b/src/code_8048480.c index 5b74c459c..18379e717 100644 --- a/src/code_8048480.c +++ b/src/code_8048480.c @@ -546,7 +546,8 @@ void CheriBerryItemAction(Entity *pokemon, Entity *target) void PechaBerryItemAction(Entity *pokemon, Entity *target) { - if((u8)(GetEntInfo(target)->nonVolatile.nonVolatileStatus - 2) <= 1) + EntityInfo *entInfo = GetEntInfo(target); + if(entInfo->nonVolatile.nonVolatileStatus == STATUS_POISONED || entInfo->nonVolatile.nonVolatileStatus == STATUS_BADLY_POISONED) SendNonVolatileEndMessage(pokemon, target); else // Pointer to "But nothing happened!" diff --git a/src/code_8066D04.c b/src/code_8066D04.c index 3bf9b6233..a618531a9 100644 --- a/src/code_8066D04.c +++ b/src/code_8066D04.c @@ -191,20 +191,18 @@ void HandleTakeItemAction(Entity *param_1) { Entity *entity; EntityInfo *info; - EntityInfo *info2; Item *heldItem; Item item; entity = sub_8044DA4(param_1,0); - info = entity->axObj.info; // GetEntInfo doesn't work here, probably fixable - info2 = entity->axObj.info; + info = GetEntInfo(entity); heldItem = &info->heldItem; - if ((gTeamInventoryRef->teamItems[ITEM_POWER_BAND].flags & ITEM_FLAG_EXISTS)) { + if (ItemExists(&gTeamInventoryRef->teamItems[ITEM_POWER_BAND])) { TryDisplayDungeonLoggableMessage(param_1,*gUnknown_80F8D60); } else { - if ((heldItem->flags & ITEM_FLAG_STICKY)) { + if (ItemSticky(heldItem)) { sub_8045BF8(gFormatBuffer_Items[0],heldItem); TryDisplayDungeonLoggableMessage(param_1,*gUnknown_80F8BE0); } @@ -214,9 +212,7 @@ void HandleTakeItemAction(Entity *param_1) item.flags &= ~(ITEM_FLAG_SET); sub_8045BF8(gFormatBuffer_Items[0],&item); SetMessageArgument(gFormatBuffer_Monsters[0],entity,0); - heldItem->id = ITEM_NOTHING; - heldItem->quantity = 0; - heldItem->flags = 0; + ZeroOutItem(heldItem); AddItemToInventory(&item); PlaySoundEffect(0x14d); TryDisplayDungeonLoggableMessage(param_1,*gUnknown_80F8D7C); @@ -224,8 +220,8 @@ void HandleTakeItemAction(Entity *param_1) if (sub_80706A4(entity,&entity->pos) != 0) { sub_807D148(param_1,entity,0,0); } - if (!info2->isTeamLeader) { - info2->flags = info2->flags | MOVEMENT_FLAG_UNK_14; + if (!info->isTeamLeader) { + info->flags |= MOVEMENT_FLAG_UNK_14; } sub_807AB38(param_1,gDungeon->unk3A08); } diff --git a/src/dungeon_capabilities.c b/src/dungeon_capabilities.c index 76089b363..f7b9c2ba3 100644 --- a/src/dungeon_capabilities.c +++ b/src/dungeon_capabilities.c @@ -22,17 +22,16 @@ const u8 gDirectionBitMasks_1[] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80}; // These functions could use better names if someone figures out a clear pattern/reasoning. bool8 CheckVariousStatuses2(Entity *pokemon, bool8 checkBlinker) { - EntityInfo *pokemonInfo = pokemon->axObj.info; // GetEntInfo doesn't work here + EntityInfo *pokemonInfo = GetEntInfo(pokemon); - if ((checkBlinker && pokemonInfo->eyesightStatus.eyesightStatus == STATUS_BLINKER) - || pokemonInfo->sleep.sleep == STATUS_SLEEP - || pokemonInfo->sleep.sleep == STATUS_NAPPING - || pokemonInfo->sleep.sleep == STATUS_NIGHTMARE - || pokemonInfo->volatileStatus.volatileStatus == STATUS_PAUSED - || pokemonInfo->volatileStatus.volatileStatus == STATUS_INFATUATED - || pokemonInfo->immobilize.immobilizeStatus == STATUS_PETRIFIED) + if ((checkBlinker && pokemonInfo->eyesightStatus.eyesightStatus == STATUS_BLINKER)) + return TRUE; + if (pokemonInfo->sleep.sleep == STATUS_SLEEP || pokemonInfo->sleep.sleep == STATUS_NAPPING || pokemonInfo->sleep.sleep == STATUS_NIGHTMARE) + return TRUE; + if (pokemonInfo->volatileStatus.volatileStatus == STATUS_PAUSED || pokemonInfo->volatileStatus.volatileStatus == STATUS_INFATUATED) + return TRUE; + if (pokemonInfo->immobilize.immobilizeStatus == STATUS_PETRIFIED) return TRUE; - if (pokemonInfo->terrifiedTurns != 0) return TRUE; @@ -96,14 +95,12 @@ bool8 CheckVariousConditions(Entity *pokemon) bool8 CheckVariousStatuses(Entity *pokemon) { - EntityInfo *pokemonInfo = pokemon->axObj.info; // GetEntInfo doesn't work here + EntityInfo *pokemonInfo = GetEntInfo(pokemon); - if ((pokemonInfo->sleep.sleep != STATUS_SLEEPLESS - && pokemonInfo->sleep.sleep != STATUS_NONE) - || pokemonInfo->immobilize.immobilizeStatus == STATUS_FROZEN - || pokemonInfo->immobilize.immobilizeStatus == STATUS_PETRIFIED) + if ((pokemonInfo->sleep.sleep != STATUS_SLEEPLESS && pokemonInfo->sleep.sleep != STATUS_NONE)) + return TRUE; + if (pokemonInfo->immobilize.immobilizeStatus == STATUS_FROZEN || pokemonInfo->immobilize.immobilizeStatus == STATUS_PETRIFIED) return TRUE; - if (pokemonInfo->charging.chargingStatus == STATUS_BIDE) return TRUE; diff --git a/src/dungeon_movement.c b/src/dungeon_movement.c index ffc907629..9a199d3ad 100644 --- a/src/dungeon_movement.c +++ b/src/dungeon_movement.c @@ -68,15 +68,18 @@ u8 sub_807034C(s16 id, struct Tile *tile) u8 sub_80703A0(Entity *pokemon, Position *pos) { - u8 crossableTerrain; struct Tile *tile; + u8 crossableTerrain; u16 tileFlags; EntityInfo *entityInfo; - entityInfo = pokemon->axObj.info; // GetEntInfo doesn't work here, replacing uses of entityInfo with a call *almost* works + entityInfo = GetEntInfo(pokemon); tile = GetTile(pos->x,pos->y); - if ((pos->x >= 0) && (pos->y >= 0) && (DUNGEON_MAX_SIZE_X > pos->x) && - (DUNGEON_MAX_SIZE_Y > pos->y) && (tile->monster == NULL) && ((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) { + if (pos->x < 0 || pos->y < 0) + return TRUE; + if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) + return TRUE; + if (tile->monster == NULL && ((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) { if ((IsCurrentFixedRoomBossFight()) || ((entityInfo->transformStatus.transformStatus != STATUS_MOBILE && (!HasHeldItem(pokemon, ITEM_MOBILE_SCARF))))) { crossableTerrain = GetCrossableTerrain(entityInfo->id); tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); @@ -99,7 +102,10 @@ u8 sub_80703A0(Entity *pokemon, Position *pos) case CROSSABLE_TERRAIN_CREVICE: if(tileFlags != 0) return FALSE; } - } else return FALSE; + } + else { + return FALSE; + } } return TRUE; } @@ -129,11 +135,13 @@ bool8 sub_807049C(Entity *pokemon, Position *pos) u16 tileFlags; EntityInfo *entityInfo; - entityInfo = pokemon->axObj.info; // GetEntInfo doesn't work here - tile = GetTile(pos->x, pos->y); - if ((pos->x >= 0) && (pos->y >= 0) && (DUNGEON_MAX_SIZE_X > pos->x) && - (DUNGEON_MAX_SIZE_Y > pos->y && ((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) && - (tile->monster == NULL || (GetEntityType(tile->monster) == ENTITY_MONSTER))) { + entityInfo = GetEntInfo(pokemon); + tile = GetTile(pos->x,pos->y); + if (pos->x < 0 || pos->y < 0) + return TRUE; + if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) + return TRUE; + if (((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0) && (tile->monster == NULL || (GetEntityType(tile->monster) == ENTITY_MONSTER))) { if (IsCurrentFixedRoomBossFight() || (entityInfo->transformStatus.transformStatus != STATUS_MOBILE && !HasHeldItem(pokemon, ITEM_MOBILE_SCARF))) { crossableTerrain = GetCrossableTerrain(entityInfo->id); tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); @@ -177,10 +185,12 @@ bool8 sub_8070564(Entity *pokemon, Position *pos) #endif entityInfo = GetEntInfo(pokemon); - tile = GetTile(pos->x, pos->y); - if ((pos->x >= 0) && (pos->y >= 0) && (DUNGEON_MAX_SIZE_X > pos->x) && - (DUNGEON_MAX_SIZE_Y > pos->y && ((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) && - (tile->monster == NULL || (GetEntityType(tile->monster) == ENTITY_MONSTER))) { + tile = GetTile(pos->x,pos->y); + if (pos->x < 0 || pos->y < 0) + return TRUE; + if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) + return TRUE; + if ((((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) && (tile->monster == NULL || (GetEntityType(tile->monster) == ENTITY_MONSTER))) { crossableTerrain2 = crossableTerrain = GetCrossableTerrain(entityInfo->id); tileFlags_0 = tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); switch(crossableTerrain) @@ -213,11 +223,13 @@ bool8 sub_80705F0(Entity *pokemon, Position *pos) u16 tileFlags; EntityInfo *entityInfo; - entityInfo = pokemon->axObj.info; // GetEntInfo doesn't work here - tile = GetTile(pos->x, pos->y); - if ((pos->x >= 0) && (pos->y >= 0) && (DUNGEON_MAX_SIZE_X > pos->x) && - (DUNGEON_MAX_SIZE_Y > pos->y && ((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) && - ((tile->monster == NULL) || ((GetEntityType(tile->monster) == ENTITY_MONSTER)))) { + entityInfo = GetEntInfo(pokemon); + tile = GetTile(pos->x,pos->y); + if (pos->x < 0 || pos->y < 0) + return TRUE; + if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) + return TRUE; + if (((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0) && (tile->monster == NULL || (GetEntityType(tile->monster) == ENTITY_MONSTER))) { if (IsCurrentFixedRoomBossFight() || (entityInfo->transformStatus.transformStatus != STATUS_MOBILE && !HasHeldItem(pokemon, ITEM_MOBILE_SCARF))) { crossableTerrain = GetCrossableTerrain(entityInfo->id); tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); @@ -251,11 +263,14 @@ bool8 sub_80706A4(Entity *pokemon, Position *pos) u16 tileFlags; EntityInfo *entityInfo; - entityInfo = pokemon->axObj.info; // GetEntInfo doesn't work here - tile = GetTile(pos->x, pos->y); - if ((pos->x >= 0) && (pos->y >= 0) && (DUNGEON_MAX_SIZE_X > pos->x) && - (DUNGEON_MAX_SIZE_Y > pos->y && ((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) && - ((tile->monster == NULL) || ((GetEntityType(tile->monster) == ENTITY_MONSTER) && (GetEntInfo(tile->monster) == entityInfo)))) { + entityInfo = GetEntInfo(pokemon); + tile = GetTile(pos->x,pos->y); + if (pos->x < 0 || pos->y < 0) + return TRUE; + if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) + return TRUE; + if ((((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) + && (tile->monster == NULL || ((GetEntityType(tile->monster) == ENTITY_MONSTER) && (GetEntInfo(tile->monster) == entityInfo)))) { if (IsCurrentFixedRoomBossFight() || (entityInfo->transformStatus.transformStatus != STATUS_MOBILE && !HasHeldItem(pokemon, ITEM_MOBILE_SCARF))) { crossableTerrain = GetCrossableTerrain(entityInfo->id); tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); diff --git a/src/move_actions.c b/src/move_actions.c index 3dcd3cc96..10e706752 100644 --- a/src/move_actions.c +++ b/src/move_actions.c @@ -848,9 +848,11 @@ bool8 sub_8058270(Entity *pokemon, Entity *target, Move *move, u32 param_4) { bool8 flag; u32 r3; + EntityInfo *targetInfo; r3 = 1; - if((u8)(GetEntInfo(target)->charging.chargingStatus - 7) <= 1) + targetInfo = GetEntInfo(target); + if(targetInfo->charging.chargingStatus == STATUS_FLYING || targetInfo->charging.chargingStatus == STATUS_BOUNCING) r3 = 2; flag = HandleDamagingMove(pokemon,target,move,r3 << 8,param_4) ? TRUE : FALSE; return flag;