Decomped CanTakeItem()

This commit is contained in:
AnonymousRandomPerson 2022-06-04 23:16:18 -04:00
parent 71dfa1bf8f
commit fd2ed0f93f
5 changed files with 47 additions and 82 deletions

View File

@ -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}

View File

@ -4,5 +4,6 @@
#include "dungeon_entity.h"
void MoveIfPossible(struct DungeonEntity *pokemon, bool8 showRunAwayEffect);
bool8 CanTakeItem(struct DungeonEntity *pokemon);
#endif

View File

@ -279,7 +279,9 @@ enum EntityType
ENTITY_NONE,
ENTITY_POKEMON,
ENTITY_TRAP,
ENTITY_ITEM
ENTITY_ITEM,
ENTITY_UNK_4,
ENTITY_UNK_5,
};
enum MovementFlag

View File

@ -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);

View File

@ -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;
}