summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/field_map_obj.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/field_map_obj.c b/src/field_map_obj.c
index 90b2f0302..f86e544a8 100755
--- a/src/field_map_obj.c
+++ b/src/field_map_obj.c
@@ -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;
+}