diff options
| author | YamaArashi <shadow962@live.com> | 2016-12-29 13:13:07 -0800 | 
|---|---|---|
| committer | YamaArashi <shadow962@live.com> | 2016-12-29 13:13:07 -0800 | 
| commit | b42f5c0f7fc9ac0161a6b6e2d764911ef375d040 (patch) | |
| tree | 295e46c51b25e9e85f35f9e7a7e26395b40b77be | |
| parent | 0edc7cbd88b31a6e57608810182781b6cf31b85a (diff) | |
use BUGFIX ifdefs
| -rw-r--r-- | include/config.h | 15 | ||||
| -rw-r--r-- | include/global.h | 5 | ||||
| -rw-r--r-- | src/rtc.c | 10 | ||||
| -rw-r--r-- | src/trainer_see.c | 37 | 
4 files changed, 40 insertions, 27 deletions
| diff --git a/include/config.h b/include/config.h new file mode 100644 index 000000000..251cbc6c2 --- /dev/null +++ b/include/config.h @@ -0,0 +1,15 @@ +#ifndef GUARD_CONFIG_H +#define GUARD_CONFIG_H + +#ifndef REVISION +#define REVISION 0 +#endif + +#if REVISION == 2 +#define BUGFIX_BERRY +#endif + +// European editions of Ruby/Sapphire and all editions of Emerald have this fix. +// #define BUGFIX_TRAINERAPPROACH + +#endif // GUARD_CONFIG_H diff --git a/include/global.h b/include/global.h index d23204760..66b6b6b50 100644 --- a/include/global.h +++ b/include/global.h @@ -2,10 +2,7 @@  #define GUARD_GLOBAL_H  #include "gba/gba.h" - -#ifndef REVISION -#define REVISION 0 -#endif +#include "config.h"  // Prevent cross-jump optimization.  #define BLOCK_CROSS_JUMP asm(""); @@ -63,9 +63,8 @@ u16 ConvertDateToDayCount(u8 year, u8 month, u8 day)      s32 i;      u16 dayCount = 0; -#if (REVISION < 2) -    // Revisions 0 and 1 don't add days for the year 2000, -    // causing the berry glitch. +#ifndef BUGFIX_BERRY +    // The berry glitch was caused by not adding days for the year 2000.      for (i = year - 1; i > 0; i--)      {          dayCount += 365; @@ -74,8 +73,7 @@ u16 ConvertDateToDayCount(u8 year, u8 month, u8 day)              dayCount++;      }  #else -    // Revision 2 has "i >= 0" as the condition instead of "i > 0", -    // which fixes the issue. +    // The fix was to use "i >= 0" as the condition instead of "i > 0".      for (i = year - 1; i >= 0; i--)      {          dayCount += 365; @@ -83,7 +81,7 @@ u16 ConvertDateToDayCount(u8 year, u8 month, u8 day)          if (IsLeapYear(i) == TRUE)              dayCount++;      } -#endif +#endif // BUGFIX_BERRY      for (i = 0; i < month - 1; i++)          dayCount += sNumDaysInMonths[i]; diff --git a/src/trainer_see.c b/src/trainer_see.c index 969bc94c1..2b4ecbcc1 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -20,7 +20,7 @@ extern u32 gUnknown_0202FF84[];  bool8 CheckTrainers(void)  {      u8 i; -     +      for(i = 0; i < 16; i++)      {          if ( gMapObjects[i].active ) @@ -60,7 +60,7 @@ bool8 TrainerCanApproachPlayer(struct MapObject *trainerObj)      s16 x, y;      u8 i;      u8 playerCoord; -     +      PlayerGetDestCoords(&x, &y);      if ( trainerObj->trainerType == 1 ) // trainers that don't spin      { @@ -119,6 +119,12 @@ bool8 IsTrainerInRangeEast(struct MapObject *trainerObj, s16 vision, s16 x, s16          return FALSE;  } +#ifdef BUGFIX_TRAINERAPPROACH +#define COLLISION_MASK ~1 +#else +#define COLLISION_MASK 1 +#endif +  bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject2 *trainerObj, u8 playerCoord, u8 direction)  {      s16 x, y; @@ -127,21 +133,18 @@ bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject2 *trainerObj, u8 playerC      u8 i;      u8 var; -    if ( !playerCoord ) +    if (!playerCoord)          return FALSE;      x = trainerObj->coords2.x;      y = trainerObj->coords2.y; -    for(i = 0; i <= playerCoord - 1;) +    for (i = 0; i <= playerCoord - 1; i++, MoveCoords(direction, &x, &y))      {          var = sub_8060024((struct MapObject *)trainerObj, x, y, direction); -        if (var != 0 && (var & 1) != 0 ) +        if (var && (var & COLLISION_MASK))              return FALSE; - -        i++; -        MoveCoords(direction, &x, &y);      }      // preserve mapobj_unk_19 before clearing. @@ -154,7 +157,7 @@ bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject2 *trainerObj, u8 playerC      trainerObj->mapobj_unk_19 = unk19_temp;      trainerObj->mapobj_unk_19b = unk19b_temp; -    if ( var == 4 ) +    if (var == 4)          return playerCoord;      return FALSE; @@ -173,7 +176,7 @@ void sub_80842FC(TaskFunc func)  {      TaskFunc func2 = RunTrainerSeeFuncList;      u8 taskId = FindTaskIdByFunc(func2); -     +      SetTaskFuncWithFollowupFunc(taskId, RunTrainerSeeFuncList, func);      gTasks[taskId].data[0] = 1;      func2(taskId); @@ -201,7 +204,7 @@ s8 sub_8084398(u8 taskId, struct Task *task, struct MapObject *trainerObj)      FieldObjectGetLocalIdAndMap(trainerObj, (u8 *)&gUnknown_0202FF84[0], (u8 *)&gUnknown_0202FF84[1], (u8 *)&gUnknown_0202FF84[2]);      FieldEffectStart(0); -     +      direction = GetFaceDirectionAnimId(trainerObj->mapobj_unk_18);      FieldObjectSetSpecialAnim(trainerObj, direction); @@ -267,17 +270,17 @@ s8 sub_8084478(u8 taskId, struct Task *task, struct MapObject *trainerObj)  s8 sub_8084534(u8 taskId, struct Task *task, struct MapObject *trainerObj) // technically only 1 parameter, but needs all 3 for TrainerSeeFuncList call.  {      struct MapObject *playerObj = &gMapObjects[gPlayerAvatar.mapObjectId]; -     +      if ( !FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(playerObj)          || FieldObjectClearAnimIfSpecialAnimFinished(playerObj) )      SwitchTaskToFollowupFunc(taskId); -     +      return 0;  }  s8 sub_8084578(u8 taskId, struct Task *task, struct MapObject *trainerObj)  { -    if(!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj)  +    if(!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj)          || FieldObjectClearAnimIfSpecialAnimFinished(trainerObj))      {          FieldObjectSetSpecialAnim(trainerObj, 0x59); @@ -290,13 +293,13 @@ s8 sub_80845AC(u8 taskId, struct Task *task, struct MapObject *trainerObj)  {      if ( FieldObjectClearAnimIfSpecialAnimFinished(trainerObj) )          task->data[0] = 3; -     +      return 0;  }  s8 sub_80845C8(u8 taskId, struct Task *task, struct MapObject *trainerObj)  { -    if(!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj)  +    if(!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj)          || FieldObjectClearAnimIfSpecialAnimFinished(trainerObj))      {          FieldObjectSetSpecialAnim(trainerObj, 0x3E); @@ -327,7 +330,7 @@ s8 sub_8084654(u8 taskId, struct Task *task, struct MapObject *trainerObj)      {          trainerObj->mapobj_bit_26 = 0;          trainerObj->mapobj_bit_2 = 1; -         +          sprite = &gSprites[trainerObj->spriteId];          sprite->oam.priority = 2;          FieldObjectClearAnimIfSpecialAnimFinished(trainerObj); | 
