From a61f7ea2a1913df28ea4f3ecd71c57fa4e5bbf5c Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Wed, 29 Dec 2021 23:33:22 -0600 Subject: Decomped HasItem() --- src/dungeon_items.c | 21 +++++++++++++++++++++ src/dungeon_pokemon_attributes_1.c | 8 ++++---- 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/dungeon_items.c (limited to 'src') diff --git a/src/dungeon_items.c b/src/dungeon_items.c new file mode 100644 index 0000000..5614e9b --- /dev/null +++ b/src/dungeon_items.c @@ -0,0 +1,21 @@ +#include "global.h" +#include "dungeon_items.h" + +bool8 HasItem(struct DungeonEntity *pokemon, u8 itemIndex) +{ + // Weird assignment to fix a regswap. + struct DungeonEntityData *entityData = entityData = pokemon->entityData; + if (!(entityData->heldItem.itemFlags & ITEM_FLAG_EXISTS)) + { + return FALSE; + } + if (entityData->heldItem.itemFlags & ITEM_FLAG_STICKY) + { + return FALSE; + } + if (entityData->heldItem.itemIndex != itemIndex) + { + return FALSE; + } + return TRUE; +} diff --git a/src/dungeon_pokemon_attributes_1.c b/src/dungeon_pokemon_attributes_1.c index a5d6acf..f3829b2 100644 --- a/src/dungeon_pokemon_attributes_1.c +++ b/src/dungeon_pokemon_attributes_1.c @@ -1,19 +1,19 @@ #include "global.h" -#include "dungeon_global_data.h" #include "dungeon_pokemon_attributes_1.h" -#include "dungeon_util.h" -#include "pokemon.h" #include "constants/dungeon.h" #include "constants/iq_skill.h" #include "constants/move_id.h" #include "constants/status.h" #include "constants/tactic.h" +#include "dungeon_global_data.h" +#include "dungeon_items.h" +#include "dungeon_util.h" +#include "pokemon.h" #include "pokemon_3.h" extern s16 gItemMasterMinWildLevel; -extern u8 HasItem(struct DungeonEntity *, u32); extern bool8 IsIQSkillSet(u8 *, u32); extern void SetIQSkill(u8 *param_1, u32 skillIndex); -- cgit v1.2.3 From c30cf5c6da8283330bc352d58acc037739cd8b72 Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Tue, 4 Jan 2022 00:00:31 -0600 Subject: Decomped EvaluateItem() --- src/dungeon_ai_item_weight.c | 442 +++++++++++++++++++++++++++++++++++++++++++ src/dungeon_ai_items.c | 2 +- src/dungeon_items.c | 8 +- src/items.c | 4 +- src/moves.c | 4 +- 5 files changed, 451 insertions(+), 9 deletions(-) create mode 100644 src/dungeon_ai_item_weight.c (limited to 'src') diff --git a/src/dungeon_ai_item_weight.c b/src/dungeon_ai_item_weight.c new file mode 100644 index 0000000..438c064 --- /dev/null +++ b/src/dungeon_ai_item_weight.c @@ -0,0 +1,442 @@ +#include "global.h" +#include "dungeon_ai_item_weight.h" + +#include "constants/status.h" +#include "dungeon_pokemon_attributes_1.h" +#include "moves.h" + +extern s32 GetBellyRoundedUp(u32); +extern bool8 CanTargetAdjacentPokemon(struct DungeonEntity*); +extern bool8 HasNegativeStatus(struct DungeonEntity*); + +u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32 itemTargetFlags) +{ + struct DungeonEntityData *pokemonData = targetPokemon->entityData; + s32 itemWeight = 0; + bool8 targetOther = itemTargetFlags & 1; + u16 targetAlly = (itemTargetFlags >> 1) & 1; + s32 i; + struct PokemonMove *move; + struct PokemonMove *move2; + switch (item->itemIndex) + { + case ITEM_ID_STICK: + case ITEM_ID_IRON_THORN: + case ITEM_ID_SILVER_SPIKE: + case ITEM_ID_GOLD_FANG: + case ITEM_ID_CACNEA_SPIKE: + case ITEM_ID_CORSOLA_TWIG: + case ITEM_ID_GRAVELEROCK: + case ITEM_ID_GEO_PEBBLE: + if (targetOther) + { + itemWeight = 70; + } + break; + case ITEM_ID_DIET_RIBBON: + if (targetOther && GetBellyRoundedUp(pokemonData->belly) > 0) + { + return 50; + } + else + { + itemWeight = 0; + } + break; + case ITEM_ID_WHIFF_SPECS: + case ITEM_ID_NO_AIM_SCOPE: + if (targetOther) + { + return 50; + } + else + { + itemWeight = 0; + } + break; + case ITEM_ID_ORAN_BERRY: + case ITEM_ID_SITRUS_BERRY: + if (pokemonData->HP < pokemonData->maxHP && pokemonData->HP <= pokemonData->maxHP / 4) + { + if (!targetOther) + { + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 100; + } + else + { + itemWeight = 50; + } + } + else + { + itemWeight = 50; + } + } + break; + case ITEM_ID_MAX_ELIXIR: + itemWeight = 0; + move = pokemonData->moves; + move2 = move; + for (i = 0; i < MAX_MON_MOVES; move++, move2++, i++) + { + if (move->moveFlags & MOVE_FLAG_EXISTS) + { + if (move->pp == 0) + { + itemWeight += 30; + } + if (move->pp != GetMoveMaxPP(move2)) + { + itemWeight += 6; + } + } + } + if (itemWeight > 98) + { + itemWeight = 99; + } + break; + case ITEM_ID_HEAL_SEED: + if (HasNegativeStatus(targetPokemon)) + { + itemWeight = 80; + } + else + { + itemWeight = 0; + } + break; + case ITEM_ID_PROTEIN: + if (pokemonData->attack > 249) + { + itemWeight = 0; + } + else + { + itemWeight = 100; + } + break; + case ITEM_ID_CALCIUM: + if (pokemonData->specialAttack > 249) + { + itemWeight = 0; + } + else + { + itemWeight = 100; + } + break; + case ITEM_ID_IRON: + if (pokemonData->defense > 249) + { + itemWeight = 0; + } + else + { + itemWeight = 100; + } + break; + case ITEM_ID_ZINC: + if (pokemonData->specialDefense > 249) + { + itemWeight = 0; + } + else + { + itemWeight = 100; + } + break; + case ITEM_ID_LIFE_SEED: + if (!targetOther) + { + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 10; + } + else + { + itemWeight = 100; + } + } + else + { + itemWeight = 0; + } + break; + case ITEM_ID_EYEDROP_SEED: + if (!CanSeeInvisible(targetPokemon)) + { + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 80; + } + else + { + itemWeight = 5; + } + } + else + { + return 0; + } + break; + case ITEM_ID_QUICK_SEED: + if (targetPokemon->entityData->movementSpeed <= 3) + { + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 80; + } + else + { + itemWeight = 5; + } + } + else + { + return 0; + } + break; + case ITEM_ID_ALLURE_SEED: + if (pokemonData->eyesightStatus != EYESIGHT_STATUS_CROSS_EYED) + { + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 80; + } + else + { + itemWeight = 5; + } + } + else + { + return 0; + } + break; + case ITEM_ID_CHERI_BERRY: + if (pokemonData->nonVolatileStatus != NON_VOLATILE_STATUS_PARALYZED) + { + return 0; + } + else if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 80; + } + else + { + itemWeight = 30; + } + break; + case ITEM_ID_TOTTER_SEED: + if (pokemonData->volatileStatus != VOLATILE_STATUS_CONFUSED) + { + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 80; + } + else + { + itemWeight = 15; + } + } + else + { + return 0; + } + break; + case ITEM_ID_PECHA_BERRY: + if (pokemonData->nonVolatileStatus != NON_VOLATILE_STATUS_POISONED && + pokemonData->nonVolatileStatus != NON_VOLATILE_STATUS_BADLY_POISONED) + { + return 0; + } + else if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 100; + } + else + { + itemWeight = 50; + } + break; + case ITEM_ID_BLINKER_SEED: + if (pokemonData->eyesightStatus != EYESIGHT_STATUS_BLINKER) + { + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 80; + } + else + { + itemWeight = 5; + } + } + else + { + return 0; + } + break; + case ITEM_ID_WARP_SEED: + if (!targetAlly) + { + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 40; + } + else + { + itemWeight = 5; + } + } + else if (pokemonData->HP < pokemonData->maxHP && pokemonData->HP < 20) + { + if (!targetOther) + { + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 100; + } + else + { + itemWeight = 50; + } + } + else + { + itemWeight = 50; + } + } + break; + case ITEM_ID_PATSY_BAND: + itemWeight = 40; + break; + case ITEM_ID_SLEEP_SEED: + if (pokemonData->sleepStatus != SLEEP_STATUS_SLEEP && + pokemonData->sleepStatus != SLEEP_STATUS_NAPPING && + pokemonData->sleepStatus != SLEEP_STATUS_NIGHTMARE) + { + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 80; + } + else + { + itemWeight = 5; + } + } + else + { + return 0; + } + break; + case ITEM_ID_CHESTO_BERRY: + if (pokemonData->sleepStatus != SLEEP_STATUS_SLEEPLESS) + { + itemWeight = 5; + } + else + { + return 0; + } + break; + case ITEM_ID_JOY_SEED: + if (pokemonData->level < 99) + { + itemWeight = 80; + } + else + { + itemWeight = 0; + } + break; + case ITEM_ID_GINSENG: + itemWeight = 80; + break; + case ITEM_ID_RAWST_BERRY: + if (pokemonData->nonVolatileStatus == NON_VOLATILE_STATUS_BURNED) + { + return 50; + } + else + { + itemWeight = 0; + } + break; + case ITEM_ID_HUNGER_SEED: + if (GetBellyRoundedUp(pokemonData->belly) > 0) + { + return 50; + } + else + { + itemWeight = 0; + } + break; + case ITEM_ID_DOOM_SEED: + if (pokemonData->level > 1) + { + itemWeight = 80; + } + else + { + itemWeight = 0; + } + break; + case ITEM_ID_STUN_SEED: + if (pokemonData->immobilizeStatus == IMMOBILIZE_STATUS_PETRIFIED) + { + return 0; + } + else if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 80; + } + else + { + itemWeight = 5; + } + break; + case ITEM_ID_BLAST_SEED: + if (CanTargetAdjacentPokemon(targetPokemon)) + { + itemWeight = 80; + } + else + { + itemWeight = 30; + } + break; + case ITEM_ID_APPLE: + case ITEM_ID_BIG_APPLE: + case ITEM_ID_HUGE_APPLE: + if (GetBellyRoundedUp(pokemonData->belly) < 10) + { + return 100; + } + else + { + itemWeight = 0; + } + break; + case ITEM_ID_GRIMY_FOOD: + itemWeight = 30; + break; + case ITEM_ID_ROLLCALL_ORB: + move = pokemonData->moves; // Fixes a regswap. + if (targetOther) + { + itemWeight = 0; + } + else + { + itemWeight = 20; + } + break; + default: + itemWeight = 0; + } + return itemWeight; +} diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 56e4447..8751eb1 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -8,6 +8,7 @@ #include "dungeon_action.h" #include "dungeon_ai_1.h" #include "dungeon_ai_attack.h" +#include "dungeon_ai_item_weight.h" #include "dungeon_ai_items.h" #include "dungeon_capabilities.h" #include "dungeon_capabilities_1.h" @@ -35,7 +36,6 @@ enum ItemTargetFlag }; extern s32 CalculateFacingDir(struct Position*, struct Position*); -extern u32 EvaluateItem(struct DungeonEntity*, struct ItemSlot*, u32); extern void sub_8077274(struct DungeonEntity *, struct DungeonEntity *); extern s32 gNumPotentialTargets; diff --git a/src/dungeon_items.c b/src/dungeon_items.c index 5614e9b..bfaab53 100644 --- a/src/dungeon_items.c +++ b/src/dungeon_items.c @@ -4,16 +4,16 @@ bool8 HasItem(struct DungeonEntity *pokemon, u8 itemIndex) { // Weird assignment to fix a regswap. - struct DungeonEntityData *entityData = entityData = pokemon->entityData; - if (!(entityData->heldItem.itemFlags & ITEM_FLAG_EXISTS)) + struct DungeonEntityData *pokemonData = pokemonData = pokemon->entityData; + if (!(pokemonData->heldItem.itemFlags & ITEM_FLAG_EXISTS)) { return FALSE; } - if (entityData->heldItem.itemFlags & ITEM_FLAG_STICKY) + if (pokemonData->heldItem.itemFlags & ITEM_FLAG_STICKY) { return FALSE; } - if (entityData->heldItem.itemIndex != itemIndex) + if (pokemonData->heldItem.itemIndex != itemIndex) { return FALSE; } diff --git a/src/items.c b/src/items.c index ff79822..a19b71b 100644 --- a/src/items.c +++ b/src/items.c @@ -1,6 +1,7 @@ #include "global.h" #include "file_system.h" #include "item.h" +#include "moves.h" #include "team_inventory.h" #include "random.h" #include "pokemon.h" @@ -42,7 +43,6 @@ extern void InitPokemonMove(void*, u16); // first arg is some struct extern void sub_80078A4(u32, u32, u32, u32, u32); extern u32 GetMoveType(void*); extern u8* GetUnformattedTypeString(s16); -extern u32 GetMoveMaxPP(void*); extern void sub_80073E0(u32); extern void xxx_format_and_draw(u32, u32, u8 *, u32, u32); extern s32 sub_8091E94(s32 a1, s32 a2, s32 a3); @@ -698,7 +698,7 @@ u32 sub_80913E0(struct ItemSlot* slot, u32 a2, struct subStruct_203B240 ** a3) xxx_format_and_draw(8, 24, GetItemDescription(slot->itemIndex), a2, 0); if (GetItemType(slot->itemIndex) == ITEM_TYPE_TM) { - u8* buffer8 = buffer88 + 0x50; // field in struct + struct PokemonMove *buffer8 = (struct PokemonMove*) (buffer88 + 0x50); // field in struct u16 move = GetItemMove(slot->itemIndex); u8 moves_data; u8* typestring; diff --git a/src/moves.c b/src/moves.c index e5998db..f2e334c 100644 --- a/src/moves.c +++ b/src/moves.c @@ -1,6 +1,7 @@ #include "global.h" +#include "moves.h" + #include "file_system.h" -#include "constants/move.h" #include "constants/move_id.h" struct MoveDataFile @@ -36,7 +37,6 @@ extern u8 gUnknown_810992C[]; extern void sub_8093F10(struct PokemonMove *, struct PokemonMove *); extern void sub_80928C0(u8 *, struct PokemonMove *, struct unkStruct_80928C0 *); -extern u32 GetMoveMaxPP(struct PokemonMove*); bool8 DoesMoveCharge(u16 move); extern void ExpandPlaceholdersBuffer(u8 *, u8 *, ...); -- cgit v1.2.3 From 2fa42b2987c9623b0bbfae37eba9569ceb69930b Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Tue, 4 Jan 2022 23:34:35 -0600 Subject: Moved some constants from data to source --- src/charge_move.c | 15 ++++++++++++++- src/data/adjacent_tile_offsets.h | 17 +++++++++++++++++ src/dungeon_ai_1.c | 33 ++++++++++++++++++++++++++++++++- src/dungeon_ai_attack.c | 3 +-- src/dungeon_pokemon_attributes_1.c | 5 ++--- 5 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 src/data/adjacent_tile_offsets.h (limited to 'src') diff --git a/src/charge_move.c b/src/charge_move.c index c17db2b..7fe358c 100644 --- a/src/charge_move.c +++ b/src/charge_move.c @@ -4,7 +4,20 @@ #include "constants/status.h" #include "dungeon_util.h" -extern u32 gMultiTurnChargingStatuses[]; +const u32 gMultiTurnChargingStatuses[10] = { + CHARGING_STATUS_SOLARBEAM, + CHARGING_STATUS_SKY_ATTACK, + CHARGING_STATUS_RAZOR_WIND, + CHARGING_STATUS_FOCUS_PUNCH, + CHARGING_STATUS_SKULL_BASH, + CHARGING_STATUS_FLY, + CHARGING_STATUS_BOUNCE, + CHARGING_STATUS_DIVE, + CHARGING_STATUS_DIG, + CHARGING_STATUS_NONE +}; + +ALIGNED(4) const char chargingStatusFill[] = "pksdir0"; bool8 IsCharging(struct DungeonEntity *pokemon, bool8 checkCharge) { diff --git a/src/data/adjacent_tile_offsets.h b/src/data/adjacent_tile_offsets.h new file mode 100644 index 0000000..e96b771 --- /dev/null +++ b/src/data/adjacent_tile_offsets.h @@ -0,0 +1,17 @@ +#ifndef GUARD_CONSTANTS_ADJACENT_TILE_OFFSETS_H +#define GUARD_CONSTANTS_ADJACENT_TILE_OFFSETS_H + +#include "position.h" + +const struct Position gAdjacentTileOffsets[8] = { + {0, 1}, + {1, 1}, + {1, 0}, + {1, -1}, + {0, -1}, + {-1, -1}, + {-1, 0}, + {-1, 1} +}; + +#endif \ No newline at end of file diff --git a/src/dungeon_ai_1.c b/src/dungeon_ai_1.c index 1d177c7..4550c83 100644 --- a/src/dungeon_ai_1.c +++ b/src/dungeon_ai_1.c @@ -5,7 +5,38 @@ #include "constants/targeting.h" #include "dungeon_pokemon_attributes_1.h" -extern bool8 gTargetingData[3][2][2][2]; +const u8 gTargetingData[3][2][2][2] = { + { + { + {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, + {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} + }, + { + {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, + {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} + } + }, + { + { + {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, + {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} + }, + { + {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET}, + {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET} + } + }, + { + { + {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET}, + {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET} + }, + { + {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, + {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} + } + } +}; u8 CanTarget(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, bool8 ignoreInvisible, bool8 checkPetrified) { diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index 48ccdfe..eaefbd9 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -2,12 +2,11 @@ #include "dungeon_ai_attack.h" #include "constants/iq_skill.h" +#include "data/adjacent_tile_offsets.h" #include "dungeon_global_data.h" #include "dungeon_map_access.h" #include "dungeon_pokemon_attributes_1.h" -extern struct Position gAdjacentTileOffsets[8]; - bool8 IsTargetStraightAhead(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, s32 facingDir, s32 maxRange) { s32 posDiffX = pokemon->posWorld.x - targetPokemon->posWorld.x; diff --git a/src/dungeon_pokemon_attributes_1.c b/src/dungeon_pokemon_attributes_1.c index f3829b2..93d8d4a 100644 --- a/src/dungeon_pokemon_attributes_1.c +++ b/src/dungeon_pokemon_attributes_1.c @@ -12,8 +12,7 @@ #include "pokemon.h" #include "pokemon_3.h" -extern s16 gItemMasterMinWildLevel; - +const s16 gItemMasterMinWildLevel[] = {16}; extern bool8 IsIQSkillSet(u8 *, u32); extern void SetIQSkill(u8 *param_1, u32 skillIndex); @@ -73,7 +72,7 @@ void LoadIQSkills(struct DungeonEntity *pokemon) SetIQSkill(iVar2, IQ_SKILL_ITEM_CATCHER); if (pokemonData->isBoss) SetIQSkill(iVar2, IQ_SKILL_SELF_CURER); - if (pokemonData->level >= gItemMasterMinWildLevel) + if (pokemonData->level >= *gItemMasterMinWildLevel) SetIQSkill(iVar2, IQ_SKILL_ITEM_MASTER); pokemonData->tactic = TACTIC_GO_AFTER_FOES; } -- cgit v1.2.3 From 05768ae71decc1539bd7f6e2c6d371b8c619cb24 Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Thu, 6 Jan 2022 23:11:38 -0600 Subject: Decomped RoundUpFixedPoint() --- src/dungeon_ai_item_weight.c | 8 ++++---- src/number_util.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/number_util.c (limited to 'src') diff --git a/src/dungeon_ai_item_weight.c b/src/dungeon_ai_item_weight.c index 438c064..175b0c2 100644 --- a/src/dungeon_ai_item_weight.c +++ b/src/dungeon_ai_item_weight.c @@ -4,8 +4,8 @@ #include "constants/status.h" #include "dungeon_pokemon_attributes_1.h" #include "moves.h" +#include "number_util.h" -extern s32 GetBellyRoundedUp(u32); extern bool8 CanTargetAdjacentPokemon(struct DungeonEntity*); extern bool8 HasNegativeStatus(struct DungeonEntity*); @@ -34,7 +34,7 @@ u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32 } break; case ITEM_ID_DIET_RIBBON: - if (targetOther && GetBellyRoundedUp(pokemonData->belly) > 0) + if (targetOther && RoundUpFixedPoint(pokemonData->belly) > 0) { return 50; } @@ -366,7 +366,7 @@ u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32 } break; case ITEM_ID_HUNGER_SEED: - if (GetBellyRoundedUp(pokemonData->belly) > 0) + if (RoundUpFixedPoint(pokemonData->belly) > 0) { return 50; } @@ -412,7 +412,7 @@ u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32 case ITEM_ID_APPLE: case ITEM_ID_BIG_APPLE: case ITEM_ID_HUGE_APPLE: - if (GetBellyRoundedUp(pokemonData->belly) < 10) + if (RoundUpFixedPoint(pokemonData->belly) < 10) { return 100; } diff --git a/src/number_util.c b/src/number_util.c new file mode 100644 index 0000000..97005cd --- /dev/null +++ b/src/number_util.c @@ -0,0 +1,22 @@ +#include "global.h" +#include "number_util.h" + +s32 RoundUpFixedPoint(s32 fixedPointNumber) +{ + if ((s16) fixedPointNumber == 0) + { + if (fixedPointNumber >> 16 == 0) + { + return 0; + } + return 1; + } + else if (fixedPointNumber >> 16 != 0) + { + return (s16) fixedPointNumber + 1; + } + else + { + return (s16) fixedPointNumber; + } +} -- cgit v1.2.3 From 42bcb068b61656f083009816b927207393a35b10 Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Fri, 7 Jan 2022 01:45:35 -0600 Subject: Decomped CanTargetAdjacentPokemon() --- src/data/adjacent_tile_offsets.h | 17 ----------------- src/dungeon_ai_attack.c | 2 +- src/dungeon_ai_item_weight.c | 21 ++++++++++++++++++++- src/dungeon_util.c | 11 +++++++++++ 4 files changed, 32 insertions(+), 19 deletions(-) delete mode 100644 src/data/adjacent_tile_offsets.h (limited to 'src') diff --git a/src/data/adjacent_tile_offsets.h b/src/data/adjacent_tile_offsets.h deleted file mode 100644 index e96b771..0000000 --- a/src/data/adjacent_tile_offsets.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef GUARD_CONSTANTS_ADJACENT_TILE_OFFSETS_H -#define GUARD_CONSTANTS_ADJACENT_TILE_OFFSETS_H - -#include "position.h" - -const struct Position gAdjacentTileOffsets[8] = { - {0, 1}, - {1, 1}, - {1, 0}, - {1, -1}, - {0, -1}, - {-1, -1}, - {-1, 0}, - {-1, 1} -}; - -#endif \ No newline at end of file diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index eaefbd9..5794038 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -2,10 +2,10 @@ #include "dungeon_ai_attack.h" #include "constants/iq_skill.h" -#include "data/adjacent_tile_offsets.h" #include "dungeon_global_data.h" #include "dungeon_map_access.h" #include "dungeon_pokemon_attributes_1.h" +#include "dungeon_util.h" bool8 IsTargetStraightAhead(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, s32 facingDir, s32 maxRange) { diff --git a/src/dungeon_ai_item_weight.c b/src/dungeon_ai_item_weight.c index 175b0c2..2f497cc 100644 --- a/src/dungeon_ai_item_weight.c +++ b/src/dungeon_ai_item_weight.c @@ -2,11 +2,14 @@ #include "dungeon_ai_item_weight.h" #include "constants/status.h" +#include "constants/targeting.h" +#include "dungeon_ai_1.h" +#include "dungeon_map_access.h" #include "dungeon_pokemon_attributes_1.h" +#include "dungeon_util.h" #include "moves.h" #include "number_util.h" -extern bool8 CanTargetAdjacentPokemon(struct DungeonEntity*); extern bool8 HasNegativeStatus(struct DungeonEntity*); u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32 itemTargetFlags) @@ -440,3 +443,19 @@ u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32 } return itemWeight; } + +bool8 CanTargetAdjacentPokemon(struct DungeonEntity *pokemon) +{ + s32 facingDir; + for (facingDir = 0; facingDir < NUM_DIRECTIONS; facingDir++) + { + struct MapTile *mapTile = GetMapTileAtPosition(pokemon->posWorld.x + gAdjacentTileOffsets[facingDir].x, pokemon->posWorld.y + gAdjacentTileOffsets[facingDir].y); + struct DungeonEntity *adjacentPokemon = mapTile->pokemon; + if (adjacentPokemon != NULL && GetEntityType(adjacentPokemon) != ENTITY_NONE && + CanTarget(pokemon, adjacentPokemon, FALSE, TRUE) == TARGET_CAPABILITY_CAN_TARGET) + { + return TRUE; + } + } + return FALSE; +} diff --git a/src/dungeon_util.c b/src/dungeon_util.c index 3594274..5b6bd5a 100644 --- a/src/dungeon_util.c +++ b/src/dungeon_util.c @@ -3,6 +3,17 @@ #include "dungeon_map_access.h" +const struct Position gAdjacentTileOffsets[NUM_DIRECTIONS] = { + {0, 1}, + {1, 1}, + {1, 0}, + {1, -1}, + {0, -1}, + {-1, -1}, + {-1, 0}, + {-1, 1} +}; + extern struct MapTile* GetMapEntity(s16, s16); bool8 EntityExists(struct DungeonEntity *entity) -- cgit v1.2.3