summaryrefslogtreecommitdiff
path: root/src/trainer_see.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/trainer_see.c')
-rw-r--r--src/trainer_see.c226
1 files changed, 224 insertions, 2 deletions
diff --git a/src/trainer_see.c b/src/trainer_see.c
index b30f27347..b396d26e7 100644
--- a/src/trainer_see.c
+++ b/src/trainer_see.c
@@ -1,15 +1,158 @@
#include "global.h"
#include "trainer_see.h"
#include "battle_setup.h"
+#include "pokemon.h"
+#include "sprite.h"
+#include "field_map_obj.h"
+#include "pokenav.h"
+#include "task.h"
extern u8 gApproachingTrainerId;
extern u8 gNoOfApproachingTrainers;
extern u8 gUnknown_030060AC;
extern u16 gUnknown_03006080;
+extern bool8 InBattlePyramid(void);
+extern bool32 InTrainerHill(void);
+extern bool8 GetBattlePyramidTrainerFlag(u8 mapObjectId);
+extern bool8 GetTrainerHillTrainerFlag(u8 mapObjectId);
+
// this file's functions
-u8 CheckIfTrainerWantsBattle(u8 mapObjectId);
+static u8 CheckTrainer(u8 mapObjectId);
+u8 GetTrainerApproachDistance(struct MapObject *trainerObj);
+void TrainerApproachPlayer(struct MapObject *trainerObj, u8 radius);
+
+u8 GetTrainerApproachDistanceSouth(struct MapObject *trainerObj, s16 range, s16 x, s16 y);
+u8 GetTrainerApproachDistanceNorth(struct MapObject *trainerObj, s16 range, s16 x, s16 y);
+u8 GetTrainerApproachDistanceWest(struct MapObject *trainerObj, s16 range, s16 x, s16 y);
+u8 GetTrainerApproachDistanceEast(struct MapObject *trainerObj, s16 range, s16 x, s16 y);
+
+bool8 sub_80B4178(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B417C(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B41C0(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B4200(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B425C(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B4318(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B435C(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B4390(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B43AC(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B43E0(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B4438(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B44AC(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+
+bool8 sub_80B43AC(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B43E0(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B4438(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+bool8 sub_80B44AC(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+
+void objc_exclamation_mark_probably(struct Sprite *sprite);
+
+// const rom data
+const u8 gEmotion_ExclamationMarkGfx[] = INCBIN_U8("graphics/misc/emotion_exclamation.4bpp");
+const u8 gEmotion_QuestionMarkGfx[] = INCBIN_U8("graphics/misc/emotion_question.4bpp");
+const u8 gEmotion_HeartGfx[] = INCBIN_U8("graphics/misc/emotion_heart.4bpp");
+
+u8 (*const sDirectionalApproachDistanceFuncs[])(struct MapObject *trainerObj, s16 range, s16 x, s16 y) =
+{
+ GetTrainerApproachDistanceSouth,
+ GetTrainerApproachDistanceNorth,
+ GetTrainerApproachDistanceWest,
+ GetTrainerApproachDistanceEast,
+};
+
+bool8 (*const gTrainerSeeFuncList[])(u8 taskId, struct Task *task, struct MapObject *trainerObj) =
+{
+ sub_80B4178,
+ sub_80B417C,
+ sub_80B41C0,
+ sub_80B4200,
+ sub_80B425C,
+ sub_80B4318,
+ sub_80B435C,
+ sub_80B4390,
+ sub_80B43AC,
+ sub_80B43E0,
+ sub_80B4438,
+ sub_80B44AC
+};
+
+bool8 (*const gTrainerSeeFuncList2[])(u8 taskId, struct Task *task, struct MapObject *trainerObj) =
+{
+ sub_80B43AC,
+ sub_80B43E0,
+ sub_80B4438,
+ sub_80B44AC,
+};
+
+const struct OamData gOamData_855077C =
+{
+ .y = 0,
+ .affineMode = 0,
+ .objMode = 0,
+ .mosaic = 0,
+ .bpp = 0,
+ .shape = 0,
+ .x = 0,
+ .matrixNum = 0,
+ .size = 1,
+ .tileNum = 0,
+ .priority = 1,
+ .paletteNum = 0,
+ .affineParam = 0,
+};
+
+const struct SpriteFrameImage gSpriteImageTable_8550784[] =
+{
+ {gEmotion_ExclamationMarkGfx, 0x80},
+ {gEmotion_QuestionMarkGfx, 0x80}
+};
+const struct SpriteFrameImage gSpriteImageTable_8550794[] =
+{
+ {gEmotion_HeartGfx, 0x80}
+};
+
+const union AnimCmd gSpriteAnim_855079C[] =
+{
+ ANIMCMD_FRAME(0, 60),
+ ANIMCMD_END
+};
+
+const union AnimCmd gSpriteAnim_85507A4[] =
+{
+ ANIMCMD_FRAME(1, 60),
+ ANIMCMD_END
+};
+
+const union AnimCmd *const gSpriteAnimTable_85507AC[] =
+{
+ gSpriteAnim_855079C,
+ gSpriteAnim_85507A4
+};
+
+const struct SpriteTemplate gSpriteTemplate_85507B4 =
+{
+ .tileTag = 0xffff,
+ .paletteTag = 0xffff,
+ .oam = &gOamData_855077C,
+ .anims = gSpriteAnimTable_85507AC,
+ .images = gSpriteImageTable_8550784,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = objc_exclamation_mark_probably
+};
+
+const struct SpriteTemplate gSpriteTemplate_85507CC =
+{
+ .tileTag = 0xffff,
+ .paletteTag = 0x1004,
+ .oam = &gOamData_855077C,
+ .anims = gSpriteAnimTable_85507AC,
+ .images = gSpriteImageTable_8550794,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = objc_exclamation_mark_probably
+};
+
+// code
bool8 CheckForTrainersWantingBattle(void)
{
u8 i;
@@ -26,7 +169,7 @@ bool8 CheckForTrainersWantingBattle(void)
if (gMapObjects[i].trainerType != 1 && gMapObjects[i].trainerType != 3)
continue;
- retVal = CheckIfTrainerWantsBattle(i);
+ retVal = CheckTrainer(i);
if (retVal == 2)
break; // two trainers have been found
@@ -66,3 +209,82 @@ bool8 CheckForTrainersWantingBattle(void)
return FALSE;
}
}
+
+static u8 CheckTrainer(u8 mapObjectId)
+{
+ const u8 *scriptPtr;
+ u8 ret = 1;
+ u8 approachDistance;
+
+ if (InTrainerHill() == TRUE)
+ scriptPtr = sub_81D62AC();
+ else
+ scriptPtr = GetFieldObjectScriptPointerByFieldObjectId(mapObjectId);
+
+ if (InBattlePyramid())
+ {
+ if (GetBattlePyramidTrainerFlag(mapObjectId))
+ return 0;
+ }
+ else if (InTrainerHill() == TRUE)
+ {
+ if (GetTrainerHillTrainerFlag(mapObjectId))
+ return 0;
+ }
+ else
+ {
+ if (GetTrainerFlagFromScriptPointer(scriptPtr))
+ return 0;
+ }
+
+ approachDistance = GetTrainerApproachDistance(&gMapObjects[mapObjectId]);
+
+ if (approachDistance != 0)
+ {
+ if (scriptPtr[1] == TRAINER_BATTLE_DOUBLE
+ || scriptPtr[1] == TRAINER_BATTLE_REMATCH_DOUBLE
+ || scriptPtr[1] == TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE)
+ {
+ if (GetMonsStateToDoubles_2() != 0)
+ return 0;
+
+ ret = 2;
+ }
+
+ gApproachingTrainers[gNoOfApproachingTrainers].mapObjectId = mapObjectId;
+ gApproachingTrainers[gNoOfApproachingTrainers].trainerScriptPtr = scriptPtr;
+ gApproachingTrainers[gNoOfApproachingTrainers].radius = approachDistance;
+ TrainerApproachPlayer(&gMapObjects[mapObjectId], approachDistance - 1);
+ gNoOfApproachingTrainers++;
+
+ return ret;
+ }
+
+ return 0;
+}
+
+/*
+u8 GetTrainerApproachDistance(struct MapObject *trainerObj)
+{
+ s16 x, y;
+ u8 i;
+ u8 approachDistance;
+
+ PlayerGetDestCoords(&x, &y);
+ if (trainerObj->trainerType == 1) // can only see in one direction
+ {
+ approachDistance = sDirectionalApproachDistanceFuncs[trainerObj->mapobj_unk_18 - 1](trainerObj, trainerObj->trainerRange_berryTreeId, x, y);
+ return CheckPathBetweenTrainerAndPlayer((struct MapObject2 *)trainerObj, approachDistance, trainerObj->mapobj_unk_18);
+ }
+ else // can see in all directions
+ {
+ for (i = 0; i < 4; i++)
+ {
+ approachDistance = sDirectionalApproachDistanceFuncs[i](trainerObj, trainerObj->trainerRange_berryTreeId, x, y);
+ if (CheckPathBetweenTrainerAndPlayer((struct MapObject2 *)trainerObj, approachDistance, i + 1)) // directions are 1-4 instead of 0-3. south north west east
+ return approachDistance;
+ }
+ }
+ return 0;
+}
+*/