diff --git a/asm/code_807AEBC.s b/asm/code_807AF58.s similarity index 91% rename from asm/code_807AEBC.s rename to asm/code_807AF58.s index e613c6505..35b1b5e55 100644 --- a/asm/code_807AEBC.s +++ b/asm/code_807AF58.s @@ -4,83 +4,7 @@ .syntax unified .text - - thumb_func_start CanTakeItem -CanTakeItem: - push {r4-r6,lr} - adds r4, r0, 0 - ldr r5, [r4, 0x70] - bl EntityExists - lsls r0, 24 - cmp r0, 0 - beq _0807AF50 - adds r0, r4, 0 - bl CannotUseItems - lsls r0, 24 - cmp r0, 0 - bne _0807AF50 - adds r0, r4, 0 - bl GetMapTileForDungeonEntity_2 - adds r6, r0, 0 - ldr r4, [r6, 0x14] - cmp r4, 0 - beq _0807AF50 - adds r0, r4, 0 - bl GetEntityType - cmp r0, 0x5 - bhi _0807AF50 - lsls r0, 2 - ldr r1, _0807AEFC - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_0807AEFC: .4byte _0807AF00 - .align 2, 0 -_0807AF00: - .4byte _0807AF50 - .4byte _0807AF50 - .4byte _0807AF50 - .4byte _0807AF18 - .4byte _0807AF50 - .4byte _0807AF50 -_0807AF18: - ldrb r0, [r5, 0x7] - cmp r0, 0 - bne _0807AF50 - adds r0, r5, 0 - adds r0, 0x60 - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _0807AF50 - ldrh r1, [r6] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0 - bne _0807AF3C - ldrb r0, [r5, 0x6] - cmp r0, 0 - bne _0807AF50 -_0807AF3C: - adds r0, r4, 0 - bl GetItemData - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _0807AF50 - movs r0, 0x1 - b _0807AF52 -_0807AF50: - movs r0, 0 -_0807AF52: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end CanTakeItem - + thumb_func_start ChooseTargetPosition ChooseTargetPosition: push {r4-r7,lr} diff --git a/include/dungeon_ai_movement.h b/include/dungeon_ai_movement.h index 71caca652..1717cbaff 100644 --- a/include/dungeon_ai_movement.h +++ b/include/dungeon_ai_movement.h @@ -4,5 +4,6 @@ #include "dungeon_entity.h" void MoveIfPossible(struct DungeonEntity *pokemon, bool8 showRunAwayEffect); +bool8 CanTakeItem(struct DungeonEntity *pokemon); #endif diff --git a/include/dungeon_entity.h b/include/dungeon_entity.h index 32a0f5e18..074ec8571 100644 --- a/include/dungeon_entity.h +++ b/include/dungeon_entity.h @@ -279,7 +279,9 @@ enum EntityType ENTITY_NONE, ENTITY_POKEMON, ENTITY_TRAP, - ENTITY_ITEM + ENTITY_ITEM, + ENTITY_UNK_4, + ENTITY_UNK_5, }; enum MovementFlag diff --git a/ld_script.txt b/ld_script.txt index b046898f9..ad694ec40 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -247,7 +247,7 @@ SECTIONS { src/status.o(.text); asm/code_8077274.o(.text); src/dungeon_ai_movement.o(.text); - asm/code_807AEBC.o(.text); + asm/code_807AF58.o(.text); src/dungeon_ai_movement_1.o(.text); asm/code_807BB78.o(.text); src/dungeon_ai_attack.o(.text); diff --git a/src/dungeon_ai_movement.c b/src/dungeon_ai_movement.c index a9f7a2f0b..a2dc02fb1 100644 --- a/src/dungeon_ai_movement.c +++ b/src/dungeon_ai_movement.c @@ -5,13 +5,15 @@ #include "constants/dungeon_action.h" #include "constants/tactic.h" #include "dungeon_action.h" -#include "dungeon_pokemon_attributes.h" -#include "dungeon_random.h" #include "dungeon_ai_movement_1.h" #include "dungeon_ai_targeting.h" +#include "dungeon_capabilities_1.h" +#include "dungeon_pokemon_attributes.h" +#include "dungeon_random.h" +#include "dungeon_util.h" +#include "map.h" #include "number_util.h" -extern bool8 CanTakeItem(struct DungeonEntity *pokemon); extern bool8 ChooseTargetPosition(struct DungeonEntity *pokemon); extern void DecideMovement(struct DungeonEntity *pokemon, bool8 showRunAwayEffect); @@ -72,3 +74,39 @@ void MoveIfPossible(struct DungeonEntity *pokemon, bool8 showRunAwayEffect) } } } + +bool8 CanTakeItem(struct DungeonEntity *pokemon) +{ + struct DungeonEntityData *pokemonData = pokemon->entityData; + struct MapTile *mapTile; + struct DungeonEntity *mapObject; + if (!EntityExists(pokemon) || CannotUseItems(pokemon)) + { + return FALSE; + } + mapTile = GetMapTileForDungeonEntity_2(pokemon); + mapObject = mapTile->mapObject; + if (mapObject == NULL) + { + return FALSE; + } + switch (GetEntityType(mapObject)) + { + case ENTITY_NONE: + case ENTITY_POKEMON: + case ENTITY_TRAP: + case ENTITY_UNK_4: + case ENTITY_UNK_5: + break; + case ENTITY_ITEM: + if (!pokemonData->isLeader && + !(pokemonData->heldItem.itemFlags & ITEM_FLAG_EXISTS) && + ((mapTile->tileType & (TILE_TYPE_FLOOR | TILE_TYPE_LIQUID)) || !pokemonData->isEnemy) && + !(GetItemData(mapObject)->itemFlags & ITEM_FLAG_FOR_SALE)) + { + return TRUE; + } + break; + } + return FALSE; +}