Move event_object_movement_helpers into event_object_movement

This commit is contained in:
Marcus Huderle 2018-06-11 10:34:51 -05:00
parent 73327f0d44
commit eb8dbff4a7
5 changed files with 727 additions and 739 deletions

View File

@ -101,12 +101,12 @@ gUnknown_08505438:: @ 8505438
.4byte FieldObjectCB_WalkInPlace4
.4byte FieldObjectCB_WalkInPlace4
gUnknown_0850557C:: @ 850557C
gRangedMovementTypes:: @ 850557C
.byte 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
.byte 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
gUnknown_085055CD:: @ 85055CD
gInitialMovementTypeFacingDirections:: @ 85055CD
.byte 0x01, 0x01, 0x01, 0x02, 0x01, 0x03, 0x04, 0x02, 0x01, 0x03, 0x04, 0x01, 0x01, 0x01, 0x03, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x02, 0x01, 0x03, 0x04, 0x02, 0x04, 0x01
.byte 0x03, 0x02, 0x03, 0x01, 0x04, 0x03, 0x02, 0x04, 0x01, 0x04, 0x02, 0x03, 0x01, 0x02, 0x01, 0x03, 0x04, 0x02, 0x01, 0x03, 0x04, 0x02, 0x01, 0x03, 0x04, 0x01, 0x01, 0x02, 0x01, 0x03, 0x04, 0x01
.byte 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x01, 0x02, 0x03, 0x04

View File

@ -81,14 +81,12 @@ struct MapObjectTemplate
/*0x06*/ s16 y;
/*0x08*/ u8 elevation;
/*0x09*/ u8 movementType;
/*0x0A*/ u8 unkA_0:4;
u8 unkA_4:4;
///*0x0B*/ u8 fillerB[1];
/*0x0C*/ u16 unkC;
/*0x0E*/ u16 unkE;
/*0x0A*/ u8 movementRangeX:4;
u8 movementRangeY:4;
/*0x0C*/ u16 trainerType;
/*0x0E*/ u16 trainerRange_berryTreeId;
/*0x10*/ const u8 *script;
/*0x14*/ u16 flagId;
/*0x16*/ u8 filler_16[2];
}; /*size = 0x18*/
struct WarpEvent

View File

@ -93,7 +93,6 @@ SECTIONS {
src/field_door.o(.text);
asm/field_player_avatar.o(.text);
src/event_object_movement.o(.text);
src/event_object_movement_helpers.o(.text);
src/field_message_box.o(.text);
src/map_obj_lock.o(.text);
src/text_window.o(.text);

View File

@ -23,6 +23,7 @@
#include "decoration.h"
#include "event_object_movement.h"
#include "pokenav.h"
#include "util.h"
#define NUM_FIELD_MAP_OBJECT_TEMPLATES 0x51
@ -110,7 +111,7 @@ u8 GetJumpLedgeAnimId(u32);
void sub_8092F88(u32, s16 *, s16 *, s16, s16);
bool8 FieldObjectExecRegularAnim(struct MapObject *, struct Sprite *);
void SetFieldObjectStepTimer(struct Sprite *, s16);
static void SetFieldObjectStepTimer(struct Sprite *, s16);
bool8 RunFieldObjectStepTimer(struct Sprite *);
bool8 npc_block_way__next_tile(struct MapObject *, u8);
static u32 state_to_direction(u8, u32, u32);
@ -129,8 +130,8 @@ static void npc_update_obj_anim_flag(struct MapObject *, struct Sprite *);
// ROM data
extern void (*const gUnknown_08505438[NUM_FIELD_MAP_OBJECT_TEMPLATES])(struct Sprite *);
extern const u8 gUnknown_0850557C[NUM_FIELD_MAP_OBJECT_TEMPLATES];
extern const u8 gUnknown_085055CD[NUM_FIELD_MAP_OBJECT_TEMPLATES];
extern const u8 gRangedMovementTypes[NUM_FIELD_MAP_OBJECT_TEMPLATES];
extern const u8 gInitialMovementTypeFacingDirections[NUM_FIELD_MAP_OBJECT_TEMPLATES];
extern const struct MapObjectGraphicsInfo *const gMauvilleOldManGraphicsInfoPointers[7];
extern const struct MapObjectGraphicsInfo *const gFieldObjectGraphicsInfoPointers[0xEF];
extern u8 (*const gUnknown_0850D714[11])(s16, s16, s16, s16);
@ -175,6 +176,18 @@ extern u8 (*const gUnknown_0850DEE8[5])(u8);
extern const s16 gUnknown_0850DFBC[3];
extern const s16 gUnknown_0850DFC2[3];
typedef void (*SpriteStepFunc)(struct Sprite *sprite, u8 dir);
extern s16 gUnknown_0850E768[];
extern SpriteStepFunc *const gUnknown_0850E754[];
extern const s8 gUnknown_0850E772[];
extern const s8 gUnknown_0850E7BA[];
extern const s8 *const gUnknown_0850E834[];
extern s16 gUnknown_0850E840[];
extern u8 gUnknown_0850E846[];
extern s16 gUnknown_0850E84A[];
extern u8 gUnknown_0850E850[];
static void FieldObjectUpdateMetatileBehaviors(struct MapObject*);
/*static*/ void GetAllGroundEffectFlags_OnBeginStep(struct MapObject*, u32*);
/*static*/ void GetGroundEffectFlags_Reflection(struct MapObject*, u32*);
@ -202,6 +215,8 @@ static void DoTracksGroundEffect_BikeTireTracks(struct MapObject*, struct Sprite
static void DoGroundEffects_OnSpawn(struct MapObject*, struct Sprite*);
static void DoGroundEffects_OnBeginStep(struct MapObject*, struct Sprite*);
static void DoGroundEffects_OnFinishStep(struct MapObject*, struct Sprite*);
static void sub_8097D68(struct Sprite*);
static void sub_8097FE4(u8);
// Code
@ -359,15 +374,15 @@ static u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *template, u
mapObject->currentElevation = template->elevation;
mapObject->previousElevation = template->elevation;
// For some reason, 0x0F is placed in r9, to be used later
mapObject->range.as_nybbles.x = template->unkA_0;
mapObject->range.as_nybbles.y = template->unkA_4;
mapObject->trainerType = template->unkC;
mapObject->trainerRange_berryTreeId = template->unkE;
mapObject->previousMovementDirection = gUnknown_085055CD[template->movementType];
mapObject->range.as_nybbles.x = template->movementRangeX;
mapObject->range.as_nybbles.y = template->movementRangeY;
mapObject->trainerType = template->trainerType;
mapObject->trainerRange_berryTreeId = template->trainerRange_berryTreeId;
mapObject->previousMovementDirection = gInitialMovementTypeFacingDirections[template->movementType];
FieldObjectSetDirection(mapObject, mapObject->previousMovementDirection);
FieldObjectHandleDynamicGraphicsId(mapObject);
if (gUnknown_0850557C[mapObject->movementType])
if (gRangedMovementTypes[mapObject->movementType])
{
if ((mapObject->range.as_nybbles.x) == 0)
{
@ -478,7 +493,7 @@ static NAKED u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *templ
"\tstrb r0, [r4, 0x7]\n"
"\tldrh r0, [r5, 0xE]\n"
"\tstrb r0, [r4, 0x1D]\n"
"\tldr r1, =gUnknown_085055CD\n"
"\tldr r1, =gInitialMovementTypeFacingDirections\n"
"\tldrb r0, [r5, 0x9]\n"
"\tadds r0, r1\n"
"\tldrb r1, [r0]\n"
@ -490,7 +505,7 @@ static NAKED u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *templ
"\tbl FieldObjectSetDirection\n"
"\tadds r0, r4, 0\n"
"\tbl FieldObjectHandleDynamicGraphicsId\n"
"\tldr r1, =gUnknown_0850557C\n"
"\tldr r1, =gRangedMovementTypes\n"
"\tldrb r0, [r4, 0x6]\n"
"\tadds r0, r1\n"
"\tldrb r0, [r0]\n"
@ -744,10 +759,10 @@ u8 SpawnSpecialFieldObjectParametrized(u8 graphicsId, u8 movementBehavior, u8 lo
mapObjectTemplate.y = y;
mapObjectTemplate.elevation = z;
mapObjectTemplate.movementType = movementBehavior;
mapObjectTemplate.unkA_0 = 0;
mapObjectTemplate.unkA_4 = 0;
mapObjectTemplate.unkC = 0;
mapObjectTemplate.unkE = 0;
mapObjectTemplate.movementRangeX = 0;
mapObjectTemplate.movementRangeY = 0;
mapObjectTemplate.trainerType = 0;
mapObjectTemplate.trainerRange_berryTreeId = 0;
return SpawnSpecialFieldObject(&mapObjectTemplate);
}
@ -3125,7 +3140,7 @@ bool8 sub_8090F30 (struct MapObject *mapObject, struct Sprite *sprite)
{
u8 direction;
direction = gUnknown_085055CD[mapObject->movementType];
direction = gInitialMovementTypeFacingDirections[mapObject->movementType];
if (mapObject->directionSequenceIndex)
{
direction = GetOppositeDirection(direction);
@ -3284,7 +3299,7 @@ bool8 sub_8091F48(struct MapObject *mapObject, struct Sprite *sprite, u8 playerD
bool8 sub_8091F4C(struct MapObject *mapObject, struct Sprite *sprite, u8 playerDirection, bool8 tileCB(u8))
{
FieldObjectSetRegularAnim(mapObject, sprite, GetFaceDirectionAnimId(state_to_direction(gUnknown_085055CD[mapObject->movementType], mapObject->directionSequenceIndex, playerDirection)));
FieldObjectSetRegularAnim(mapObject, sprite, GetFaceDirectionAnimId(state_to_direction(gInitialMovementTypeFacingDirections[mapObject->movementType], mapObject->directionSequenceIndex, playerDirection)));
mapObject->singleMovementActive = TRUE;
sprite->data[1] = 2;
return TRUE;
@ -3303,7 +3318,7 @@ bool8 sub_8091F94(struct MapObject *mapObject, struct Sprite *sprite, u8 playerD
if (direction == 0)
{
direction = playerDirection;
direction = state_to_direction(gUnknown_085055CD[mapObject->movementType], mapObject->directionSequenceIndex, direction);
direction = state_to_direction(gInitialMovementTypeFacingDirections[mapObject->movementType], mapObject->directionSequenceIndex, direction);
FieldObjectMoveDestCoords(mapObject, direction, &x, &y);
FieldObjectSetRegularAnim(mapObject, sprite, GetFaceDirectionAnimId(direction));
mapObject->singleMovementActive = TRUE;
@ -3313,7 +3328,7 @@ bool8 sub_8091F94(struct MapObject *mapObject, struct Sprite *sprite, u8 playerD
}
else
{
direction = state_to_direction(gUnknown_085055CD[mapObject->movementType], mapObject->directionSequenceIndex, direction);
direction = state_to_direction(gInitialMovementTypeFacingDirections[mapObject->movementType], mapObject->directionSequenceIndex, direction);
}
FieldObjectMoveDestCoords(mapObject, direction, &x, &y);
FieldObjectSetRegularAnim(mapObject, sprite, GetGoSpeed0AnimId(direction));
@ -3333,7 +3348,7 @@ bool8 sub_80920A4(struct MapObject *mapObject, struct Sprite *sprite, u8 playerD
s16 y;
direction = playerDirection;
direction = state_to_direction(gUnknown_085055CD[mapObject->movementType], mapObject->directionSequenceIndex, direction);
direction = state_to_direction(gInitialMovementTypeFacingDirections[mapObject->movementType], mapObject->directionSequenceIndex, direction);
FieldObjectMoveDestCoords(mapObject, direction, &x, &y);
FieldObjectSetRegularAnim(mapObject, sprite, GetGoSpeed1AnimId(direction));
if (npc_block_way(mapObject, x, y, direction) || (tileCB != NULL && !tileCB(MapGridGetMetatileBehaviorAt(x, y))))
@ -3352,7 +3367,7 @@ bool8 sub_809215C(struct MapObject *mapObject, struct Sprite *sprite, u8 playerD
s16 y;
direction = playerDirection;
direction = state_to_direction(gUnknown_085055CD[mapObject->movementType], mapObject->directionSequenceIndex, direction);
direction = state_to_direction(gInitialMovementTypeFacingDirections[mapObject->movementType], mapObject->directionSequenceIndex, direction);
FieldObjectMoveDestCoords(mapObject, direction, &x, &y);
FieldObjectSetRegularAnim(mapObject, sprite, GetGoSpeed3AnimId(direction));
if (npc_block_way(mapObject, x, y, direction) || (tileCB != NULL && !tileCB(MapGridGetMetatileBehaviorAt(x, y))))
@ -3371,7 +3386,7 @@ bool8 sub_8092214(struct MapObject *mapObject, struct Sprite *sprite, u8 playerD
s16 y;
direction = playerDirection;
direction = state_to_direction(gUnknown_085055CD[mapObject->movementType], mapObject->directionSequenceIndex, direction);
direction = state_to_direction(gInitialMovementTypeFacingDirections[mapObject->movementType], mapObject->directionSequenceIndex, direction);
FieldObjectMoveDestCoords(mapObject, direction, &x, &y);
FieldObjectSetRegularAnim(mapObject, sprite, sub_8093438(direction));
if (npc_block_way(mapObject, x, y, direction) || (tileCB != NULL && !tileCB(MapGridGetMetatileBehaviorAt(x, y))))
@ -3388,7 +3403,7 @@ bool8 cph_IM_DIFFERENT(struct MapObject *mapObject, struct Sprite *sprite, u8 pl
u32 direction;
direction = playerDirection;
direction = state_to_direction(gUnknown_085055CD[mapObject->movementType], mapObject->directionSequenceIndex, direction);
direction = state_to_direction(gInitialMovementTypeFacingDirections[mapObject->movementType], mapObject->directionSequenceIndex, direction);
FieldObjectSetRegularAnim(mapObject, sprite, sub_80934BC(direction));
mapObject->singleMovementActive = TRUE;
sprite->data[1] = 2;
@ -3402,7 +3417,7 @@ bool8 sub_8092314(struct MapObject *mapObject, struct Sprite *sprite, u8 playerD
s16 y;
direction = playerDirection;
direction = state_to_direction(gUnknown_085055CD[mapObject->movementType], mapObject->directionSequenceIndex, direction);
direction = state_to_direction(gInitialMovementTypeFacingDirections[mapObject->movementType], mapObject->directionSequenceIndex, direction);
FieldObjectMoveDestCoords(mapObject, direction, &x, &y);
FieldObjectSetRegularAnim(mapObject, sprite, sub_8093514(direction));
if (npc_block_way(mapObject, x, y, direction) || (tileCB != NULL && !tileCB(MapGridGetMetatileBehaviorAt(x, y))))
@ -3421,7 +3436,7 @@ bool8 oac_hopping(struct MapObject *mapObject, struct Sprite *sprite, u8 playerD
s16 y;
direction = playerDirection;
direction = state_to_direction(gUnknown_085055CD[mapObject->movementType], mapObject->directionSequenceIndex, direction);
direction = state_to_direction(gInitialMovementTypeFacingDirections[mapObject->movementType], mapObject->directionSequenceIndex, direction);
x = mapObject->currentCoords.x;
y = mapObject->currentCoords.y;
sub_8092F88(direction, &x, &y, 2, 2);
@ -4669,7 +4684,7 @@ maybe_shadow_1_macro(sub_80953E0, maybe_shadow_1, sub_80941E0, DIR_EAST, 0, 2)
bool8 sub_8095438(struct MapObject *mapObject, struct Sprite *sprite)
{
an_look_any(mapObject, sprite, gUnknown_085055CD[mapObject->movementType]);
an_look_any(mapObject, sprite, gInitialMovementTypeFacingDirections[mapObject->movementType]);
return TRUE;
}
@ -5894,3 +5909,683 @@ static void DoGroundEffects_OnFinishStep(struct MapObject *eventObj, struct Spri
eventObj->landingJump = 0;
}
}
bool8 FreezeMapObject(struct MapObject *mapObject)
{
if (mapObject->heldMovementActive || mapObject->frozen)
{
return TRUE;
}
else
{
mapObject->frozen = 1;
mapObject->spriteAnimPausedBackup = gSprites[mapObject->spriteId].animPaused;
mapObject->spriteAffineAnimPausedBackup = gSprites[mapObject->spriteId].affineAnimPaused;
gSprites[mapObject->spriteId].animPaused = 1;
gSprites[mapObject->spriteId].affineAnimPaused = 1;
return FALSE;
}
}
void FreezeMapObjects(void)
{
u8 i;
for (i = 0; i < MAP_OBJECTS_COUNT; i++)
if (gMapObjects[i].active && i != gPlayerAvatar.mapObjectId)
FreezeMapObject(&gMapObjects[i]);
}
void FreezeMapObjectsExceptOne(u8 a1)
{
u8 i;
for (i = 0; i < MAP_OBJECTS_COUNT; i++)
if (i != a1 && gMapObjects[i].active && i != gPlayerAvatar.mapObjectId)
FreezeMapObject(&gMapObjects[i]);
}
void npc_sync_anim_pause_bits(struct MapObject *mapObject)
{
if (mapObject->active && mapObject->frozen)
{
mapObject->frozen = 0;
gSprites[mapObject->spriteId].animPaused = mapObject->spriteAnimPausedBackup;
gSprites[mapObject->spriteId].affineAnimPaused = mapObject->spriteAffineAnimPausedBackup;
}
}
void UnfreezeMapObjects(void)
{
u8 i;
for (i = 0; i < MAP_OBJECTS_COUNT; i++)
if (gMapObjects[i].active)
npc_sync_anim_pause_bits(&gMapObjects[i]);
}
void little_step(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += gUnknown_0850DB7C[dir].x;
sprite->pos1.y += gUnknown_0850DB7C[dir].y;
}
void double_little_steps(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 2 * (u16) gUnknown_0850DB7C[dir].x;
sprite->pos1.y += 2 * (u16) gUnknown_0850DB7C[dir].y;
}
void triple_little_steps(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 2 * (u16) gUnknown_0850DB7C[dir].x + (u16) gUnknown_0850DB7C[dir].x;
sprite->pos1.y += 2 * (u16) gUnknown_0850DB7C[dir].y + (u16) gUnknown_0850DB7C[dir].y;
}
void quad_little_steps(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 4 * (u16) gUnknown_0850DB7C[dir].x;
sprite->pos1.y += 4 * (u16) gUnknown_0850DB7C[dir].y;
}
void oct_little_steps(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 8 * (u16) gUnknown_0850DB7C[dir].x;
sprite->pos1.y += 8 * (u16) gUnknown_0850DB7C[dir].y;
}
void oamt_npc_ministep_reset(struct Sprite *sprite, u8 a2, u8 a3)
{
sprite->data[3] = a2;
sprite->data[4] = a3;
sprite->data[5] = 0;
}
bool8 obj_npc_ministep(struct Sprite *sprite)
{
if (sprite->data[5] >= gUnknown_0850E768[sprite->data[4]])
return FALSE;
gUnknown_0850E754[sprite->data[4]][sprite->data[5]](sprite, sprite->data[3]);
sprite->data[5]++;
if (sprite->data[5] < gUnknown_0850E768[sprite->data[4]])
return FALSE;
return TRUE;
}
void sub_80976DC(struct Sprite *sprite, u8 a2)
{
sprite->data[3] = a2;
sprite->data[4] = 0;
sprite->data[5] = 0;
}
bool8 sub_80976EC(struct Sprite *sprite)
{
if (!(sprite->data[4] & 1))
{
little_step(sprite, sprite->data[3]);
sprite->data[5]++;
}
sprite->data[4]++;
if (sprite->data[5] > 15)
return TRUE;
else
return FALSE;
}
// new helper added here in the middle. Perhaps Game Freak kept these organized in alphebetical order or some other heirarchy?
s16 sub_8097728(s16 a1)
{
return gUnknown_0850E7BA[a1];
}
s16 sub_809773C(s16 a1)
{
return gUnknown_0850E772[a1];
}
void sub_8097750(struct Sprite *sprite)
{
sprite->data[6] = 0;
sprite->data[7] = 0;
}
bool8 sub_8097758(struct Sprite *sprite)
{
bool8 result = FALSE;
switch(sprite->data[7])
{
case 0:
sprite->pos2.x += sub_809773C(sprite->data[6]);
sprite->pos2.y += sub_8097728(sprite->data[6]);
break;
case 1:
sprite->pos2.x -= sub_809773C(0x47 - sprite->data[6]);
sprite->pos2.y += sub_8097728(0x47 - sprite->data[6]);
break;
case 2:
sprite->pos2.x -= sub_809773C(sprite->data[6]);
sprite->pos2.y += sub_8097728(sprite->data[6]);
break;
case 3:
sprite->pos2.x += sub_809773C(0x47 - sprite->data[6]);
sprite->pos2.y += sub_8097728(0x47 - sprite->data[6]);
break;
}
if(++sprite->data[6] == 0x48)
{
sprite->data[6] = 0;
sprite->data[7]++;
}
if(sprite->data[7] == 0x4)
{
sprite->pos2.y = 0;
sprite->pos2.x = 0;
result = TRUE;
}
return result;
}
s16 sub_8097820(s16 a1, u8 a2)
{
return gUnknown_0850E834[a2][a1];
}
void sub_809783C(struct Sprite *sprite, u8 a2, u8 a3, u8 a4)
{
sprite->data[3] = a2;
sprite->data[4] = a3;
sprite->data[5] = a4;
sprite->data[6] = 0;
}
u8 sub_809785C(struct Sprite *sprite)
{
s16 v5[3];
u8 v6[3];
u8 v2;
memcpy(v5, gUnknown_0850E840, 6); // TODO: get rid of memcpy
memcpy(v6, gUnknown_0850E846, 3);
v2 = 0;
if (sprite->data[4])
little_step(sprite, sprite->data[3]);
sprite->pos2.y = sub_8097820(sprite->data[6] >> v6[sprite->data[4]], sprite->data[5]);
sprite->data[6]++;
if (sprite->data[6] == (v5[sprite->data[4]] >> 1))
v2 = 1;
if (sprite->data[6] >= v5[sprite->data[4]])
{
sprite->pos2.y = 0;
v2 = -1;
}
return v2;
}
u8 sub_80978E4(struct Sprite *sprite)
{
s16 v5[3];
u8 v6[3];
u8 v2;
memcpy(v5, gUnknown_0850E84A, 6);
memcpy(v6, gUnknown_0850E850, 3);
v2 = 0;
if (sprite->data[4] && !(sprite->data[6] & 1))
little_step(sprite, sprite->data[3]);
sprite->pos2.y = sub_8097820(sprite->data[6] >> v6[sprite->data[4]], sprite->data[5]);
sprite->data[6]++;
if (sprite->data[6] == (v5[sprite->data[4]] >> 1))
v2 = 1;
if (sprite->data[6] >= v5[sprite->data[4]])
{
sprite->pos2.y = 0;
v2 = -1;
}
return v2;
}
void SetFieldObjectStepTimer(struct Sprite *sprite, s16 timer)
{
sprite->data[3] = timer;
}
bool8 RunFieldObjectStepTimer(struct Sprite *sprite)
{
sprite->data[3]--;
if (sprite->data[3] == 0)
return TRUE;
else
return FALSE;
}
void obj_anim_image_set_and_seek(struct Sprite *sprite, u8 a2, u8 a3)
{
sprite->animNum = a2;
sprite->animPaused = 0 ;
SeekSpriteAnim(sprite, a3);
}
bool8 sub_80979BC(struct Sprite *sprite)
{
if (sprite->animEnded)
return TRUE;
else
return FALSE;
}
void sub_80979D4(struct Sprite *sprite, bool8 invisible)
{
u16 x, y;
s16 x2, y2;
sprite->invisible = invisible;
if (sprite->coordOffsetEnabled)
{
x = sprite->pos1.x + sprite->pos2.x + sprite->centerToCornerVecX + gSpriteCoordOffsetX;
y = sprite->pos1.y + sprite->pos2.y + sprite->centerToCornerVecY + gSpriteCoordOffsetY;
}
else
{
x = sprite->pos1.x + sprite->pos2.x + sprite->centerToCornerVecX;
y = sprite->pos1.y + sprite->pos2.y + sprite->centerToCornerVecY;
}
x2 = x - (sprite->centerToCornerVecX >> 1);
y2 = y - (sprite->centerToCornerVecY >> 1);
if ((s16)x > 255 || x2 < -16)
sprite->invisible = 1;
if ((s16)y > 175 || y2 < -16)
sprite->invisible = 1;
}
void sub_8097AC8(struct Sprite *sprite)
{
sub_8097D68(sprite);
SetObjectSubpriorityByZCoord(sprite->data[1], sprite, 1);
sub_80979D4(sprite, sprite->data[2]);
}
void sub_8097AF0(void)
{
int i;
for(i = 0; i < MAX_SPRITES; i++)
{
struct Sprite *sprite = &gSprites[i];
if(sprite->inUse && sprite->callback == sub_8097AC8)
DestroySprite(sprite);
}
}
int sub_8097B2C(u8 var) // this should return a u8, because all that call this shifts to u8, but it wont match because it doesnt shift u8 at the end.
{
int i;
for(i = 0; i < MAX_SPRITES; i++)
{
struct Sprite *sprite = &gSprites[i];
if(sprite->inUse && sprite->callback == sub_8097AC8 && (u8)sprite->data[0] == var)
return i;
}
return MAX_SPRITES;
}
void sub_8097B78(u8 var1, u8 var2)
{
u8 spriteId = sub_8097B2C(var1);
if(spriteId != MAX_SPRITES)
StartSpriteAnim(&gSprites[spriteId], FieldObjectDirectionToImageAnimId(var2));
}
void sub_8097BB4(u8 var1, u8 var2)
{
int spriteId = sub_8097B2C(var1);
if(spriteId != MAX_SPRITES)
{
struct Sprite *sprite = &gSprites[spriteId];
const struct MapObjectGraphicsInfo *gfxInfo = GetFieldObjectGraphicsInfo(var2);
u16 tileNum = sprite->oam.tileNum;
sprite->oam = *gfxInfo->oam;
sprite->oam.tileNum = tileNum;
sprite->oam.paletteNum = gfxInfo->paletteSlot;
sprite->images = gfxInfo->images;
if(gfxInfo->subspriteTables == NULL)
{
sprite->subspriteTables = NULL;
sprite->subspriteTableNum = 0;
sprite->subspriteMode = 0;
}
else
{
SetSubspriteTables(sprite, gfxInfo->subspriteTables);
sprite->subspriteMode = 2;
}
StartSpriteAnim(sprite, 0);
}
}
void sub_8097C44(u8 var, bool32 var2)
{
u8 spriteId = sub_8097B2C(var);
if(spriteId == MAX_SPRITES)
return;
if(var2)
gSprites[spriteId].data[2] = 1;
else
gSprites[spriteId].data[2] = 0;
}
bool32 sub_8097C8C(u8 var)
{
u8 spriteId = sub_8097B2C(var);
if(spriteId == MAX_SPRITES)
return FALSE;
return (gSprites[spriteId].data[2] == TRUE);
}
void sub_8097CC4(u8 var1, u8 var2)
{
u8 spriteId = sub_8097B2C(var1);
if(spriteId != MAX_SPRITES)
{
gSprites[spriteId].data[3] = var2;
gSprites[spriteId].data[4] = 0;
}
}
void sub_8097CF4(struct Sprite *sprite)
{
switch(sprite->data[4])
{
case 0:
sprite->pos2.y = 0;
sprite->data[4]++;
case 1:
sprite->pos2.y -= 8;
if(sprite->pos2.y == -160)
{
sprite->pos2.y = 0;
sprite->data[2] = 1;
sprite->data[3] = 0;
sprite->data[4] = 0;
}
}
}
void sub_8097D30(struct Sprite *sprite)
{
switch(sprite->data[4])
{
case 0:
sprite->pos2.y = -160;
sprite->data[4]++;
case 1:
sprite->pos2.y += 8;
if(sprite->pos2.y == 0)
{
sprite->data[3] = 0;
sprite->data[4] = 0;
}
}
}
static void sub_8097D68(struct Sprite *sprite)
{
switch(sprite->data[3])
{
case 1:
sub_8097D30(sprite);
break;
case 2:
sub_8097CF4(sprite);
break;
case 0:
break;
default:
sprite->data[3] = 0;
break;
}
}
bool32 sub_8097D9C(u8 var)
{
u8 spriteId = sub_8097B2C(var);
if(spriteId == MAX_SPRITES)
return FALSE;
if(gSprites[spriteId].data[3] != FALSE)
return TRUE;
return FALSE;
}
u32 StartFieldEffectForEventObject(u8 fieldEffectId, struct MapObject *mapObject)
{
FieldObjectGetLocalIdAndMap(mapObject, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]);
return FieldEffectStart(fieldEffectId);
}
void DoShadowFieldEffect(struct MapObject *mapObject)
{
if (!mapObject->hasShadow)
{
mapObject->hasShadow = 1;
StartFieldEffectForEventObject(FLDEFF_SHADOW, mapObject);
}
}
void DoRippleFieldEffect(struct MapObject *mapObject, struct Sprite *sprite)
{
const struct MapObjectGraphicsInfo *gfxInfo = GetFieldObjectGraphicsInfo(mapObject->graphicsId);
gFieldEffectArguments[0] = sprite->pos1.x;
gFieldEffectArguments[1] = sprite->pos1.y + (gfxInfo->height >> 1) - 2;
gFieldEffectArguments[2] = 151;
gFieldEffectArguments[3] = 3;
FieldEffectStart(FLDEFF_RIPPLE);
}
bool32 sub_8097E50(struct MapObject *mapObject, struct Sprite *sprite)
{
u32 one;
bool32 ableToStore = FALSE;
if (gUnknown_020375B8 == NULL)
{
gUnknown_020375B8 = AllocZeroed(0x14);
gUnknown_020375B8[0] = mapObject->localId;
// needed to match
gUnknown_020375B8[16] = (one = 1);
ableToStore = one;
}
else
{
u8 i;
u8 firstFreeSlot;
bool32 found;
for (firstFreeSlot = 16, found = FALSE, i = 0; i < 16; i++)
{
if (firstFreeSlot == 16 && gUnknown_020375B8[i] == 0)
firstFreeSlot = i;
if (gUnknown_020375B8[i] == mapObject->localId)
{
found = TRUE;
break;
}
}
if (!found && firstFreeSlot != 16)
{
gUnknown_020375B8[firstFreeSlot] = mapObject->localId;
gUnknown_020375B8[16]++;
ableToStore = TRUE;
}
}
if (ableToStore == TRUE)
{
mapObject->inanimate = TRUE;
mapObject->facingDirectionLocked = TRUE;
}
sprite->data[2] = 1;
return TRUE;
}
bool32 sub_8097EF0(struct MapObject *mapObject, struct Sprite *sprite)
{
bool32 ableToStore;
u8 id;
sprite->data[2] = 1;
if (gUnknown_020375B8 != NULL)
{
ableToStore = FALSE;
id = sub_8097F78(mapObject);
if (id != 16)
{
gUnknown_020375B8[id] = 0;
gUnknown_020375B8[16]--;
ableToStore = TRUE;
}
if (gUnknown_020375B8[16] == 0)
FREE_AND_SET_NULL(gUnknown_020375B8);
if (ableToStore == TRUE)
{
mapObject->inanimate = GetFieldObjectGraphicsInfo(mapObject->graphicsId)->inanimate;
mapObject->facingDirectionLocked = 0;
sprite->animPaused = 0;
}
}
return TRUE;
}
u8 sub_8097F78(struct MapObject *mapObject)
{
u8 i;
for(i = 0; i < MAP_OBJECTS_COUNT; i++)
{
if(gUnknown_020375B8[i] == mapObject->localId)
return i;
}
return MAP_OBJECTS_COUNT;
}
void sub_8097FA4(struct MapObject *mapObject)
{
u8 taskId = CreateTask(sub_8097FE4, 0xFF);
struct Task *task = &gTasks[taskId];
StoreWordInTwoHalfwords(&task->data[0], (u32)mapObject);
mapObject->warpArrowSpriteId = taskId;
task->data[3] = 0xFFFF;
}
static void sub_8097FE4(u8 taskId)
{
struct MapObject *mapObject;
struct Sprite *sprite;
struct Task *task = &gTasks[taskId];
LoadWordFromTwoHalfwords(&task->data[0], (u32 *)&mapObject); // load the map object pointer.
sprite = &gSprites[mapObject->spriteId];
if(!(task->data[2] & 0x3))
sprite->pos2.y += task->data[3];
if(!(task->data[2] & 0xF))
task->data[3] = -task->data[3];
task->data[2]++;
}
void sub_8098044(u8 taskId)
{
u32 word;
struct Task *task = &gTasks[taskId];
LoadWordFromTwoHalfwords(&task->data[0], &word); // huh??? why does it load a word that never gets used???
DestroyTask(taskId);
}
void sub_8098074(u8 var1, u8 var2)
{
u8 i;
for(i = 0; i < MAP_OBJECTS_COUNT; i++)
{
if(i != var1 && i != var2 &&
gMapObjects[i].active && i != gPlayerAvatar.mapObjectId)
FreezeMapObject(&gMapObjects[i]);
}
}
bool32 sub_80980C0(struct MapObject *mapObject, struct Sprite *sprite)
{
sprite->pos2.y = 0;
sprite->data[2]++;
return FALSE;
}
bool32 sub_80980D0(struct MapObject *mapObject, struct Sprite *sprite)
{
sprite->pos2.y -= 8;
if(sprite->pos2.y == -160)
sprite->data[2]++;
return FALSE;
}
bool32 sub_80980F4(struct MapObject *mapObject, struct Sprite *sprite)
{
sprite->pos2.y = -160;
sprite->data[2]++;
return FALSE;
}
bool32 sub_8098108(struct MapObject *mapObject, struct Sprite *sprite)
{
sprite->pos2.y += 8;
if(!sprite->pos2.y)
sprite->data[2]++;
return FALSE;
}
// though this function returns TRUE without doing anything, this header is required due to being in an array of functions which needs it.
bool32 sub_8098124(struct MapObject *mapObject, struct Sprite *sprite)
{
return TRUE;
}

View File

@ -1,704 +0,0 @@
#include "global.h"
#include "event_object_movement.h"
#include "field_effect.h"
#include "event_object_movement_helpers.h"
#include "malloc.h"
#include "task.h"
#include "util.h"
typedef void (*SpriteStepFunc)(struct Sprite *sprite, u8 dir);
extern const struct Coords16 gUnknown_0850DB7C[4];
extern s16 gUnknown_0850E768[];
extern SpriteStepFunc *const gUnknown_0850E754[];
extern const s8 gUnknown_0850E772[];
extern const s8 gUnknown_0850E7BA[];
extern const s8 *const gUnknown_0850E834[];
extern s16 gUnknown_0850E840[];
extern u8 gUnknown_0850E846[];
extern s16 gUnknown_0850E84A[];
extern u8 gUnknown_0850E850[];
void sub_8097D68(struct Sprite *sprite);
void sub_8097FE4(u8);
bool8 FreezeMapObject(struct MapObject *mapObject)
{
if (mapObject->heldMovementActive || mapObject->frozen)
{
return TRUE;
}
else
{
mapObject->frozen = 1;
mapObject->spriteAnimPausedBackup = gSprites[mapObject->spriteId].animPaused;
mapObject->spriteAffineAnimPausedBackup = gSprites[mapObject->spriteId].affineAnimPaused;
gSprites[mapObject->spriteId].animPaused = 1;
gSprites[mapObject->spriteId].affineAnimPaused = 1;
return FALSE;
}
}
void FreezeMapObjects(void)
{
u8 i;
for (i = 0; i < MAP_OBJECTS_COUNT; i++)
if (gMapObjects[i].active && i != gPlayerAvatar.mapObjectId)
FreezeMapObject(&gMapObjects[i]);
}
void FreezeMapObjectsExceptOne(u8 a1)
{
u8 i;
for (i = 0; i < MAP_OBJECTS_COUNT; i++)
if (i != a1 && gMapObjects[i].active && i != gPlayerAvatar.mapObjectId)
FreezeMapObject(&gMapObjects[i]);
}
void npc_sync_anim_pause_bits(struct MapObject *mapObject)
{
if (mapObject->active && mapObject->frozen)
{
mapObject->frozen = 0;
gSprites[mapObject->spriteId].animPaused = mapObject->spriteAnimPausedBackup;
gSprites[mapObject->spriteId].affineAnimPaused = mapObject->spriteAffineAnimPausedBackup;
}
}
void UnfreezeMapObjects(void)
{
u8 i;
for (i = 0; i < MAP_OBJECTS_COUNT; i++)
if (gMapObjects[i].active)
npc_sync_anim_pause_bits(&gMapObjects[i]);
}
void little_step(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += gUnknown_0850DB7C[dir].x;
sprite->pos1.y += gUnknown_0850DB7C[dir].y;
}
void double_little_steps(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 2 * (u16) gUnknown_0850DB7C[dir].x;
sprite->pos1.y += 2 * (u16) gUnknown_0850DB7C[dir].y;
}
void triple_little_steps(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 2 * (u16) gUnknown_0850DB7C[dir].x + (u16) gUnknown_0850DB7C[dir].x;
sprite->pos1.y += 2 * (u16) gUnknown_0850DB7C[dir].y + (u16) gUnknown_0850DB7C[dir].y;
}
void quad_little_steps(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 4 * (u16) gUnknown_0850DB7C[dir].x;
sprite->pos1.y += 4 * (u16) gUnknown_0850DB7C[dir].y;
}
void oct_little_steps(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 8 * (u16) gUnknown_0850DB7C[dir].x;
sprite->pos1.y += 8 * (u16) gUnknown_0850DB7C[dir].y;
}
void oamt_npc_ministep_reset(struct Sprite *sprite, u8 a2, u8 a3)
{
sprite->data[3] = a2;
sprite->data[4] = a3;
sprite->data[5] = 0;
}
bool8 obj_npc_ministep(struct Sprite *sprite)
{
if (sprite->data[5] >= gUnknown_0850E768[sprite->data[4]])
return FALSE;
gUnknown_0850E754[sprite->data[4]][sprite->data[5]](sprite, sprite->data[3]);
sprite->data[5]++;
if (sprite->data[5] < gUnknown_0850E768[sprite->data[4]])
return FALSE;
return TRUE;
}
void sub_80976DC(struct Sprite *sprite, u8 a2)
{
sprite->data[3] = a2;
sprite->data[4] = 0;
sprite->data[5] = 0;
}
bool8 sub_80976EC(struct Sprite *sprite)
{
if (!(sprite->data[4] & 1))
{
little_step(sprite, sprite->data[3]);
sprite->data[5]++;
}
sprite->data[4]++;
if (sprite->data[5] > 15)
return TRUE;
else
return FALSE;
}
// new helper added here in the middle. Perhaps Game Freak kept these organized in alphebetical order or some other heirarchy?
s16 sub_8097728(s16 a1)
{
return gUnknown_0850E7BA[a1];
}
s16 sub_809773C(s16 a1)
{
return gUnknown_0850E772[a1];
}
void sub_8097750(struct Sprite *sprite)
{
sprite->data[6] = 0;
sprite->data[7] = 0;
}
bool8 sub_8097758(struct Sprite *sprite)
{
bool8 result = FALSE;
switch(sprite->data[7])
{
case 0:
sprite->pos2.x += sub_809773C(sprite->data[6]);
sprite->pos2.y += sub_8097728(sprite->data[6]);
break;
case 1:
sprite->pos2.x -= sub_809773C(0x47 - sprite->data[6]);
sprite->pos2.y += sub_8097728(0x47 - sprite->data[6]);
break;
case 2:
sprite->pos2.x -= sub_809773C(sprite->data[6]);
sprite->pos2.y += sub_8097728(sprite->data[6]);
break;
case 3:
sprite->pos2.x += sub_809773C(0x47 - sprite->data[6]);
sprite->pos2.y += sub_8097728(0x47 - sprite->data[6]);
break;
}
if(++sprite->data[6] == 0x48)
{
sprite->data[6] = 0;
sprite->data[7]++;
}
if(sprite->data[7] == 0x4)
{
sprite->pos2.y = 0;
sprite->pos2.x = 0;
result = TRUE;
}
return result;
}
s16 sub_8097820(s16 a1, u8 a2)
{
return gUnknown_0850E834[a2][a1];
}
void sub_809783C(struct Sprite *sprite, u8 a2, u8 a3, u8 a4)
{
sprite->data[3] = a2;
sprite->data[4] = a3;
sprite->data[5] = a4;
sprite->data[6] = 0;
}
u8 sub_809785C(struct Sprite *sprite)
{
s16 v5[3];
u8 v6[3];
u8 v2;
memcpy(v5, gUnknown_0850E840, 6); // TODO: get rid of memcpy
memcpy(v6, gUnknown_0850E846, 3);
v2 = 0;
if (sprite->data[4])
little_step(sprite, sprite->data[3]);
sprite->pos2.y = sub_8097820(sprite->data[6] >> v6[sprite->data[4]], sprite->data[5]);
sprite->data[6]++;
if (sprite->data[6] == (v5[sprite->data[4]] >> 1))
v2 = 1;
if (sprite->data[6] >= v5[sprite->data[4]])
{
sprite->pos2.y = 0;
v2 = -1;
}
return v2;
}
u8 sub_80978E4(struct Sprite *sprite)
{
s16 v5[3];
u8 v6[3];
u8 v2;
memcpy(v5, gUnknown_0850E84A, 6);
memcpy(v6, gUnknown_0850E850, 3);
v2 = 0;
if (sprite->data[4] && !(sprite->data[6] & 1))
little_step(sprite, sprite->data[3]);
sprite->pos2.y = sub_8097820(sprite->data[6] >> v6[sprite->data[4]], sprite->data[5]);
sprite->data[6]++;
if (sprite->data[6] == (v5[sprite->data[4]] >> 1))
v2 = 1;
if (sprite->data[6] >= v5[sprite->data[4]])
{
sprite->pos2.y = 0;
v2 = -1;
}
return v2;
}
void SetFieldObjectStepTimer(struct Sprite *sprite, u16 timer)
{
sprite->data[3] = timer;
}
bool8 RunFieldObjectStepTimer(struct Sprite *sprite)
{
sprite->data[3]--;
if (sprite->data[3] == 0)
return TRUE;
else
return FALSE;
}
void obj_anim_image_set_and_seek(struct Sprite *sprite, u8 a2, u8 a3)
{
sprite->animNum = a2;
sprite->animPaused = 0 ;
SeekSpriteAnim(sprite, a3);
}
bool8 sub_80979BC(struct Sprite *sprite)
{
if (sprite->animEnded)
return TRUE;
else
return FALSE;
}
void sub_80979D4(struct Sprite *sprite, bool8 invisible)
{
u16 x, y;
s16 x2, y2;
sprite->invisible = invisible;
if (sprite->coordOffsetEnabled)
{
x = sprite->pos1.x + sprite->pos2.x + sprite->centerToCornerVecX + gSpriteCoordOffsetX;
y = sprite->pos1.y + sprite->pos2.y + sprite->centerToCornerVecY + gSpriteCoordOffsetY;
}
else
{
x = sprite->pos1.x + sprite->pos2.x + sprite->centerToCornerVecX;
y = sprite->pos1.y + sprite->pos2.y + sprite->centerToCornerVecY;
}
x2 = x - (sprite->centerToCornerVecX >> 1);
y2 = y - (sprite->centerToCornerVecY >> 1);
if ((s16)x > 255 || x2 < -16)
sprite->invisible = 1;
if ((s16)y > 175 || y2 < -16)
sprite->invisible = 1;
}
void sub_8097AC8(struct Sprite *sprite)
{
sub_8097D68(sprite);
SetObjectSubpriorityByZCoord(sprite->data[1], sprite, 1);
sub_80979D4(sprite, sprite->data[2]);
}
void sub_8097AF0(void)
{
int i;
for(i = 0; i < MAX_SPRITES; i++)
{
struct Sprite *sprite = &gSprites[i];
if(sprite->inUse && sprite->callback == sub_8097AC8)
DestroySprite(sprite);
}
}
int sub_8097B2C(u8 var) // this should return a u8, because all that call this shifts to u8, but it wont match because it doesnt shift u8 at the end.
{
int i;
for(i = 0; i < MAX_SPRITES; i++)
{
struct Sprite *sprite = &gSprites[i];
if(sprite->inUse && sprite->callback == sub_8097AC8 && (u8)sprite->data[0] == var)
return i;
}
return MAX_SPRITES;
}
void sub_8097B78(u8 var1, u8 var2)
{
u8 spriteId = sub_8097B2C(var1);
if(spriteId != MAX_SPRITES)
StartSpriteAnim(&gSprites[spriteId], FieldObjectDirectionToImageAnimId(var2));
}
void sub_8097BB4(u8 var1, u8 var2)
{
int spriteId = sub_8097B2C(var1);
if(spriteId != MAX_SPRITES)
{
struct Sprite *sprite = &gSprites[spriteId];
const struct MapObjectGraphicsInfo *gfxInfo = GetFieldObjectGraphicsInfo(var2);
u16 tileNum = sprite->oam.tileNum;
sprite->oam = *gfxInfo->oam;
sprite->oam.tileNum = tileNum;
sprite->oam.paletteNum = gfxInfo->paletteSlot;
sprite->images = gfxInfo->images;
if(gfxInfo->subspriteTables == NULL)
{
sprite->subspriteTables = NULL;
sprite->subspriteTableNum = 0;
sprite->subspriteMode = 0;
}
else
{
SetSubspriteTables(sprite, gfxInfo->subspriteTables);
sprite->subspriteMode = 2;
}
StartSpriteAnim(sprite, 0);
}
}
void sub_8097C44(u8 var, bool32 var2)
{
u8 spriteId = sub_8097B2C(var);
if(spriteId == MAX_SPRITES)
return;
if(var2)
gSprites[spriteId].data[2] = 1;
else
gSprites[spriteId].data[2] = 0;
}
bool32 sub_8097C8C(u8 var)
{
u8 spriteId = sub_8097B2C(var);
if(spriteId == MAX_SPRITES)
return FALSE;
return (gSprites[spriteId].data[2] == TRUE);
}
void sub_8097CC4(u8 var1, u8 var2)
{
u8 spriteId = sub_8097B2C(var1);
if(spriteId != MAX_SPRITES)
{
gSprites[spriteId].data[3] = var2;
gSprites[spriteId].data[4] = 0;
}
}
void sub_8097CF4(struct Sprite *sprite)
{
switch(sprite->data[4])
{
case 0:
sprite->pos2.y = 0;
sprite->data[4]++;
case 1:
sprite->pos2.y -= 8;
if(sprite->pos2.y == -160)
{
sprite->pos2.y = 0;
sprite->data[2] = 1;
sprite->data[3] = 0;
sprite->data[4] = 0;
}
}
}
void sub_8097D30(struct Sprite *sprite)
{
switch(sprite->data[4])
{
case 0:
sprite->pos2.y = -160;
sprite->data[4]++;
case 1:
sprite->pos2.y += 8;
if(sprite->pos2.y == 0)
{
sprite->data[3] = 0;
sprite->data[4] = 0;
}
}
}
void sub_8097D68(struct Sprite *sprite)
{
switch(sprite->data[3])
{
case 1:
sub_8097D30(sprite);
break;
case 2:
sub_8097CF4(sprite);
break;
case 0:
break;
default:
sprite->data[3] = 0;
break;
}
}
bool32 sub_8097D9C(u8 var)
{
u8 spriteId = sub_8097B2C(var);
if(spriteId == MAX_SPRITES)
return FALSE;
if(gSprites[spriteId].data[3] != FALSE)
return TRUE;
return FALSE;
}
u32 StartFieldEffectForEventObject(u8 fieldEffectId, struct MapObject *mapObject)
{
FieldObjectGetLocalIdAndMap(mapObject, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]);
return FieldEffectStart(fieldEffectId);
}
void DoShadowFieldEffect(struct MapObject *mapObject)
{
if (!mapObject->hasShadow)
{
mapObject->hasShadow = 1;
StartFieldEffectForEventObject(FLDEFF_SHADOW, mapObject);
}
}
void DoRippleFieldEffect(struct MapObject *mapObject, struct Sprite *sprite)
{
const struct MapObjectGraphicsInfo *gfxInfo = GetFieldObjectGraphicsInfo(mapObject->graphicsId);
gFieldEffectArguments[0] = sprite->pos1.x;
gFieldEffectArguments[1] = sprite->pos1.y + (gfxInfo->height >> 1) - 2;
gFieldEffectArguments[2] = 151;
gFieldEffectArguments[3] = 3;
FieldEffectStart(FLDEFF_RIPPLE);
}
bool32 sub_8097E50(struct MapObject *mapObject, struct Sprite *sprite)
{
u32 one;
bool32 ableToStore = FALSE;
if (gUnknown_020375B8 == NULL)
{
gUnknown_020375B8 = AllocZeroed(0x14);
gUnknown_020375B8[0] = mapObject->localId;
// needed to match
gUnknown_020375B8[16] = (one = 1);
ableToStore = one;
}
else
{
u8 i;
u8 firstFreeSlot;
bool32 found;
for (firstFreeSlot = 16, found = FALSE, i = 0; i < 16; i++)
{
if (firstFreeSlot == 16 && gUnknown_020375B8[i] == 0)
firstFreeSlot = i;
if (gUnknown_020375B8[i] == mapObject->localId)
{
found = TRUE;
break;
}
}
if (!found && firstFreeSlot != 16)
{
gUnknown_020375B8[firstFreeSlot] = mapObject->localId;
gUnknown_020375B8[16]++;
ableToStore = TRUE;
}
}
if (ableToStore == TRUE)
{
mapObject->inanimate = TRUE;
mapObject->facingDirectionLocked = TRUE;
}
sprite->data[2] = 1;
return TRUE;
}
bool32 sub_8097EF0(struct MapObject *mapObject, struct Sprite *sprite)
{
bool32 ableToStore;
u8 id;
sprite->data[2] = 1;
if (gUnknown_020375B8 != NULL)
{
ableToStore = FALSE;
id = sub_8097F78(mapObject);
if (id != 16)
{
gUnknown_020375B8[id] = 0;
gUnknown_020375B8[16]--;
ableToStore = TRUE;
}
if (gUnknown_020375B8[16] == 0)
FREE_AND_SET_NULL(gUnknown_020375B8);
if (ableToStore == TRUE)
{
mapObject->inanimate = GetFieldObjectGraphicsInfo(mapObject->graphicsId)->inanimate;
mapObject->facingDirectionLocked = 0;
sprite->animPaused = 0;
}
}
return TRUE;
}
u8 sub_8097F78(struct MapObject *mapObject)
{
u8 i;
for(i = 0; i < MAP_OBJECTS_COUNT; i++)
{
if(gUnknown_020375B8[i] == mapObject->localId)
return i;
}
return MAP_OBJECTS_COUNT;
}
void sub_8097FA4(struct MapObject *mapObject)
{
u8 taskId = CreateTask(sub_8097FE4, 0xFF);
struct Task *task = &gTasks[taskId];
StoreWordInTwoHalfwords(&task->data[0], (u32)mapObject);
mapObject->warpArrowSpriteId = taskId;
task->data[3] = 0xFFFF;
}
void sub_8097FE4(u8 taskId)
{
struct MapObject *mapObject;
struct Sprite *sprite;
struct Task *task = &gTasks[taskId];
LoadWordFromTwoHalfwords(&task->data[0], (u32 *)&mapObject); // load the map object pointer.
sprite = &gSprites[mapObject->spriteId];
if(!(task->data[2] & 0x3))
sprite->pos2.y += task->data[3];
if(!(task->data[2] & 0xF))
task->data[3] = -task->data[3];
task->data[2]++;
}
void sub_8098044(u8 taskId)
{
u32 word;
struct Task *task = &gTasks[taskId];
LoadWordFromTwoHalfwords(&task->data[0], &word); // huh??? why does it load a word that never gets used???
DestroyTask(taskId);
}
void sub_8098074(u8 var1, u8 var2)
{
u8 i;
for(i = 0; i < MAP_OBJECTS_COUNT; i++)
{
if(i != var1 && i != var2 &&
gMapObjects[i].active && i != gPlayerAvatar.mapObjectId)
FreezeMapObject(&gMapObjects[i]);
}
}
bool32 sub_80980C0(struct MapObject *mapObject, struct Sprite *sprite)
{
sprite->pos2.y = 0;
sprite->data[2]++;
return FALSE;
}
bool32 sub_80980D0(struct MapObject *mapObject, struct Sprite *sprite)
{
sprite->pos2.y -= 8;
if(sprite->pos2.y == -160)
sprite->data[2]++;
return FALSE;
}
bool32 sub_80980F4(struct MapObject *mapObject, struct Sprite *sprite)
{
sprite->pos2.y = -160;
sprite->data[2]++;
return FALSE;
}
bool32 sub_8098108(struct MapObject *mapObject, struct Sprite *sprite)
{
sprite->pos2.y += 8;
if(!sprite->pos2.y)
sprite->data[2]++;
return FALSE;
}
// though this function returns TRUE without doing anything, this header is required due to being in an array of functions which needs it.
bool32 sub_8098124(struct MapObject *mapObject, struct Sprite *sprite)
{
return TRUE;
}