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

@@ -1799,3 +1799,36 @@ bool8 sub_808F564(struct MapObject *mapObject, struct Sprite *sprite)
}
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;
}