FieldObjectIsTrainerAndCloseToPlayer

This commit is contained in:
PikalaxALT 2017-09-13 19:13:44 -04:00
parent e26501f130
commit d72231379b
3 changed files with 35 additions and 68 deletions

View File

@ -5,74 +5,6 @@
.text .text
thumb_func_start FieldObjectIsTrainerAndCloseToPlayer
@ bool8 FieldObjectIsTrainerAndCloseToPlayer(struct npc_state *fieldObject)
FieldObjectIsTrainerAndCloseToPlayer: @ 808F58C
push {r4-r7,lr}
sub sp, 0x4
adds r5, r0, 0
movs r0, 0x80
bl TestPlayerAvatarFlags
lsls r0, 24
cmp r0, 0
beq _0808F5F8
ldrb r0, [r5, 0x7]
cmp r0, 0x1
beq _0808F5A8
cmp r0, 0x3
bne _0808F5F8
_0808F5A8:
mov r7, sp
adds r7, 0x2
mov r0, sp
adds r1, r7, 0
bl PlayerGetDestCoords
ldrh r2, [r5, 0x10]
ldrh r4, [r5, 0x12]
ldrb r1, [r5, 0x1D]
subs r3, r2, r1
subs r0, r4, r1
lsls r0, 16
lsrs r5, r0, 16
adds r2, r1, r2
lsls r2, 16
lsrs r2, 16
adds r1, r4
lsls r1, 16
lsrs r6, r1, 16
mov r0, sp
lsls r3, 16
asrs r3, 16
movs r1, 0
ldrsh r4, [r0, r1]
cmp r3, r4
bgt _0808F5F8
lsls r0, r2, 16
asrs r0, 16
cmp r0, r4
blt _0808F5F8
lsls r0, r5, 16
asrs r0, 16
movs r2, 0
ldrsh r1, [r7, r2]
cmp r0, r1
bgt _0808F5F8
lsls r0, r6, 16
asrs r0, 16
cmp r0, r1
bge _0808F5FC
_0808F5F8:
movs r0, 0
b _0808F5FE
_0808F5FC:
movs r0, 0x1
_0808F5FE:
add sp, 0x4
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end FieldObjectIsTrainerAndCloseToPlayer
thumb_func_start sub_808F608 thumb_func_start sub_808F608
sub_808F608: @ 808F608 sub_808F608: @ 808F608
push {r4,lr} push {r4,lr}

View File

@ -8,5 +8,7 @@
void ClearPlayerAvatarInfo(void); void ClearPlayerAvatarInfo(void);
void SetPlayerAvatarExtraStateTransition(u8, u8); void SetPlayerAvatarExtraStateTransition(u8, u8);
u8 GetPlayerAvatarGenderByGraphicsId(u8); u8 GetPlayerAvatarGenderByGraphicsId(u8);
bool8 TestPlayerAvatarFlags(u8);
void PlayerGetDestCoords(s16 *, s16 *);
#endif //POKEEMERALD_FIELD_PLAYER_AVATAR_H #endif //POKEEMERALD_FIELD_PLAYER_AVATAR_H

View File

@ -1799,3 +1799,36 @@ bool8 sub_808F564(struct MapObject *mapObject, struct Sprite *sprite)
} }
return FALSE; return FALSE;
} }
bool8 FieldObjectIsTrainerAndCloseToPlayer(struct MapObject *mapObject)
{
s16 playerX;
s16 playerY;
s16 objX;
s16 objY;
s16 minX;
s16 maxX;
s16 minY;
s16 maxY;
if (!TestPlayerAvatarFlags(0x80))
{
return FALSE;
}
if (mapObject->trainerType != 1 && mapObject->trainerType != 3)
{
return FALSE;
}
PlayerGetDestCoords(&playerX, &playerY);
objX = mapObject->coords2.x;
objY = mapObject->coords2.y;
minX = objX - mapObject->trainerRange_berryTreeId;
minY = objY - mapObject->trainerRange_berryTreeId;
maxX = objX + mapObject->trainerRange_berryTreeId;
maxY = objY + mapObject->trainerRange_berryTreeId;
if (minX > playerX || maxX < playerX || minY > playerY || maxY < playerY)
{
return FALSE;
}
return TRUE;
}