diff options
Diffstat (limited to 'src/event_object_movement.c')
-rw-r--r-- | src/event_object_movement.c | 126 |
1 files changed, 53 insertions, 73 deletions
diff --git a/src/event_object_movement.c b/src/event_object_movement.c index ba62db10d..3e5362de4 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -6,6 +6,7 @@ #include "event_data.h" #include "event_object_movement.h" #include "event_scripts.h" +#include "faraway_island.h" #include "field_camera.h" #include "field_effect.h" #include "field_effect_helpers.h" @@ -15,7 +16,6 @@ #include "metatile_behavior.h" #include "overworld.h" #include "palette.h" -#include "pokenav.h" #include "random.h" #include "sprite.h" #include "task.h" @@ -1534,10 +1534,10 @@ static u8 TrySetupEventObjectSprite(struct EventObjectTemplate *eventObjectTempl paletteSlot -= 16; sub_808EAB0(graphicsInfo->paletteTag1, paletteSlot); } + if (eventObject->movementType == MOVEMENT_TYPE_INVISIBLE) - { eventObject->invisible = TRUE; - } + *(u16 *)&spriteTemplate->paletteTag = 0xFFFF; spriteId = CreateSprite(spriteTemplate, 0, 0, 0); if (spriteId == MAX_SPRITES) @@ -1545,6 +1545,7 @@ static u8 TrySetupEventObjectSprite(struct EventObjectTemplate *eventObjectTempl gEventObjects[eventObjectId].active = FALSE; return EVENT_OBJECTS_COUNT; } + sprite = &gSprites[spriteId]; sub_8092FF0(eventObject->currentCoords.x + cameraX, eventObject->currentCoords.y + cameraY, &sprite->pos1.x, &sprite->pos1.y); sprite->centerToCornerVecX = -(graphicsInfo->width >> 1); @@ -1557,15 +1558,14 @@ static u8 TrySetupEventObjectSprite(struct EventObjectTemplate *eventObjectTempl eventObject->spriteId = spriteId; eventObject->inanimate = graphicsInfo->inanimate; if (!eventObject->inanimate) - { StartSpriteAnim(sprite, GetFaceDirectionAnimNum(eventObject->facingDirection)); - } + SetObjectSubpriorityByZCoord(eventObject->previousElevation, sprite, 1); UpdateEventObjectVisibility(eventObject, sprite); return eventObjectId; } -static u8 TrySpawnEventObject(struct EventObjectTemplate *eventObjectTemplate, u8 mapNum, u8 mapGroup, s16 cameraX, s16 cameraY) +static u8 TrySpawnEventObjectTemplate(struct EventObjectTemplate *eventObjectTemplate, u8 mapNum, u8 mapGroup, s16 cameraX, s16 cameraY) { u8 eventObjectId; struct SpriteTemplate spriteTemplate; @@ -1579,14 +1579,12 @@ static u8 TrySpawnEventObject(struct EventObjectTemplate *eventObjectTemplate, u spriteTemplate.images = &spriteFrameImage; eventObjectId = TrySetupEventObjectSprite(eventObjectTemplate, &spriteTemplate, mapNum, mapGroup, cameraX, cameraY); if (eventObjectId == EVENT_OBJECTS_COUNT) - { return EVENT_OBJECTS_COUNT; - } + gSprites[gEventObjects[eventObjectId].spriteId].images = graphicsInfo->images; - if (subspriteTables != NULL) - { + if (subspriteTables) SetSubspriteTables(&gSprites[gEventObjects[eventObjectId].spriteId], subspriteTables); - } + return eventObjectId; } @@ -1596,7 +1594,7 @@ u8 SpawnSpecialEventObject(struct EventObjectTemplate *eventObjectTemplate) s16 cameraY; GetEventObjectMovingCameraOffset(&cameraX, &cameraY); - return TrySpawnEventObject(eventObjectTemplate, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, cameraX, cameraY); + return TrySpawnEventObjectTemplate(eventObjectTemplate, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, cameraX, cameraY); } u8 SpawnSpecialEventObjectParameterized(u8 graphicsId, u8 movementBehavior, u8 localId, s16 x, s16 y, u8 z) @@ -1619,19 +1617,17 @@ u8 SpawnSpecialEventObjectParameterized(u8 graphicsId, u8 movementBehavior, u8 l return SpawnSpecialEventObject(&eventObjectTemplate); } -u8 show_sprite(u8 localId, u8 mapNum, u8 mapGroup) +u8 TrySpawnEventObject(u8 localId, u8 mapNum, u8 mapGroup) { struct EventObjectTemplate *eventObjectTemplate; - s16 cameraX; - s16 cameraY; + s16 cameraX, cameraY; eventObjectTemplate = GetEventObjectTemplateByLocalIdAndMap(localId, mapNum, mapGroup); - if (eventObjectTemplate == NULL) - { + if (!eventObjectTemplate) return EVENT_OBJECTS_COUNT; - } + GetEventObjectMovingCameraOffset(&cameraX, &cameraY); - return TrySpawnEventObject(eventObjectTemplate, mapNum, mapGroup, cameraX, cameraY); + return TrySpawnEventObjectTemplate(eventObjectTemplate, mapNum, mapGroup, cameraX, cameraY); } static void MakeObjectTemplateFromEventObjectGraphicsInfo(u16 graphicsId, void (*callback)(struct Sprite *), struct SpriteTemplate *spriteTemplate, const struct SubspriteTable **subspriteTables) @@ -1765,7 +1761,7 @@ void TrySpawnEventObjects(s16 cameraX, s16 cameraY) if (top <= npcY && bottom >= npcY && left <= npcX && right >= npcX && !FlagGet(template->flagId)) - TrySpawnEventObject(template, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, cameraX, cameraY); + TrySpawnEventObjectTemplate(template, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, cameraX, cameraY); } } } @@ -1949,7 +1945,7 @@ void EventObjectSetGraphicsId(struct EventObject *eventObject, u8 graphicsId) sprite->oam.paletteNum = paletteSlot; eventObject->inanimate = graphicsInfo->inanimate; eventObject->graphicsId = graphicsId; - sub_8093038(eventObject->currentCoords.x, eventObject->currentCoords.y, &sprite->pos1.x, &sprite->pos1.y); + SetSpritePosToMapCoords(eventObject->currentCoords.x, eventObject->currentCoords.y, &sprite->pos1.x, &sprite->pos1.y); sprite->centerToCornerVecX = -(graphicsInfo->width >> 1); sprite->centerToCornerVecY = -(graphicsInfo->height >> 1); sprite->pos1.x += 8; @@ -2245,7 +2241,7 @@ static void SetEventObjectCoords(struct EventObject *eventObject, s16 x, s16 y) eventObject->currentCoords.y = y; } -void sub_808EB08(struct EventObject *eventObject, s16 x, s16 y) +void MoveEventObjectToMapCoords(struct EventObject *eventObject, s16 x, s16 y) { struct Sprite *sprite; const struct EventObjectGraphicsInfo *graphicsInfo; @@ -2253,27 +2249,24 @@ void sub_808EB08(struct EventObject *eventObject, s16 x, s16 y) sprite = &gSprites[eventObject->spriteId]; graphicsInfo = GetEventObjectGraphicsInfo(eventObject->graphicsId); SetEventObjectCoords(eventObject, x, y); - sub_8093038(eventObject->currentCoords.x, eventObject->currentCoords.y, &sprite->pos1.x, &sprite->pos1.y); + SetSpritePosToMapCoords(eventObject->currentCoords.x, eventObject->currentCoords.y, &sprite->pos1.x, &sprite->pos1.y); sprite->centerToCornerVecX = -(graphicsInfo->width >> 1); sprite->centerToCornerVecY = -(graphicsInfo->height >> 1); sprite->pos1.x += 8; sprite->pos1.y += 16 + sprite->centerToCornerVecY; sub_808E38C(eventObject); if (eventObject->trackedByCamera) - { CameraObjectReset1(); - } } -void sub_808EBA8(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s16 y) +void TryMoveEventObjectToMapCoords(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s16 y) { u8 eventObjectId; - if (!TryGetEventObjectIdByLocalIdAndMap(localId, mapNum, mapGroup, &eventObjectId)) { x += 7; y += 7; - sub_808EB08(&gEventObjects[eventObjectId], x, y); + MoveEventObjectToMapCoords(&gEventObjects[eventObjectId], x, y); } } @@ -2604,15 +2597,13 @@ void OverrideTemplateCoordsForEventObject(const struct EventObject *eventObject) } } -void OverrideMovementTypeForEventObject(const struct EventObject *eventObject, const u8 *script) +static void OverrideEventObjectTemplateScript(const struct EventObject *eventObject, const u8 *script) { struct EventObjectTemplate *eventObjectTemplate; eventObjectTemplate = GetBaseTemplateForEventObject(eventObject); - if (eventObjectTemplate != NULL) - { + if (eventObjectTemplate) eventObjectTemplate->script = script; - } } void TryOverrideTemplateCoordsForEventObject(const struct EventObject *eventObject, u8 movementType) @@ -2626,30 +2617,26 @@ void TryOverrideTemplateCoordsForEventObject(const struct EventObject *eventObje } } -void sub_808F254(u8 localId, u8 mapNum, u8 mapGroup) +void TryOverrideEventObjectTemplateCoords(u8 localId, u8 mapNum, u8 mapGroup) { u8 eventObjectId; - if (!TryGetEventObjectIdByLocalIdAndMap(localId, mapNum, mapGroup, &eventObjectId)) - { OverrideTemplateCoordsForEventObject(&gEventObjects[eventObjectId]); - } } -void sub_808F28C(u8 localId, u8 mapNum, u8 mapGroup, u8 decorCat) +void OverrideSecretBaseDecorationSpriteScript(u8 localId, u8 mapNum, u8 mapGroup, u8 decorationCategory) { u8 eventObjectId; - if (!TryGetEventObjectIdByLocalIdAndMap(localId, mapNum, mapGroup, &eventObjectId)) { - switch (decorCat) + switch (decorationCategory) { - case DECORCAT_DOLL: - OverrideMovementTypeForEventObject(&gEventObjects[eventObjectId], EventScript_SecretPower1); - break; - case DECORCAT_CUSHION: - OverrideMovementTypeForEventObject(&gEventObjects[eventObjectId], EventScript_SecretPower2); - break; + case DECORCAT_DOLL: + OverrideEventObjectTemplateScript(&gEventObjects[eventObjectId], SecretBase_EventScript_DollInteract); + break; + case DECORCAT_CUSHION: + OverrideEventObjectTemplateScript(&gEventObjects[eventObjectId], SecretBase_EventScript_CushionInteract); + break; } } } @@ -4414,8 +4401,8 @@ bool8 CopyablePlayerMovement_GoSpeed0(struct EventObject *eventObject, struct Sp direction = playerDirection; if (EventObjectIsFarawayIslandMew(eventObject)) { - direction = sub_81D427C(); - if (direction == 0) + direction = GetMewMoveDirection(); + if (direction == DIR_NONE) { direction = playerDirection; direction = state_to_direction(gInitialMovementTypeFacingDirections[eventObject->movementType], eventObject->directionSequenceIndex, direction); @@ -5024,44 +5011,37 @@ static void MoveCoordsInDirection(u32 dir, s16 *x, s16 *y, s16 deltaX, s16 delta *y -= dy2; } -void sub_8092FF0(s16 x, s16 y, s16 *dest_x, s16 *dest_y) +void sub_8092FF0(s16 x, s16 y, s16 *destX, s16 *destY) { - *dest_x = (x - gSaveBlock1Ptr->pos.x) << 4; - *dest_y = (y - gSaveBlock1Ptr->pos.y) << 4; - *dest_x -= gTotalCameraPixelOffsetX; - *dest_y -= gTotalCameraPixelOffsetY; + *destX = (x - gSaveBlock1Ptr->pos.x) << 4; + *destY = (y - gSaveBlock1Ptr->pos.y) << 4; + *destX -= gTotalCameraPixelOffsetX; + *destY -= gTotalCameraPixelOffsetY; } -void sub_8093038(s16 x, s16 y, s16 *dest_x, s16 *dest_y) +void SetSpritePosToMapCoords(s16 mapX, s16 mapY, s16 *destX, s16 *destY) { - s16 dx; - s16 dy; - - dx = -gTotalCameraPixelOffsetX - gFieldCamera.x; - dy = -gTotalCameraPixelOffsetY - gFieldCamera.y; + s16 dx = -gTotalCameraPixelOffsetX - gFieldCamera.x; + s16 dy = -gTotalCameraPixelOffsetY - gFieldCamera.y; if (gFieldCamera.x > 0) - { - dx += 0x10; - } + dx += 1 << 4; + if (gFieldCamera.x < 0) - { - dx -= 0x10; - } + dx -= 1 << 4; + if (gFieldCamera.y > 0) - { - dy += 0x10; - } + dy += 1 << 4; + if (gFieldCamera.y < 0) - { - dy -= 0x10; - } - *dest_x = ((x - gSaveBlock1Ptr->pos.x) << 4) + dx; - *dest_y = ((y - gSaveBlock1Ptr->pos.y) << 4) + dy; + dy -= 1 << 4; + + *destX = ((mapX - gSaveBlock1Ptr->pos.x) << 4) + dx; + *destY = ((mapY - gSaveBlock1Ptr->pos.y) << 4) + dy; } void sub_80930E0(s16 *x, s16 *y, s16 dx, s16 dy) { - sub_8093038(*x, *y, x, y); + SetSpritePosToMapCoords(*x, *y, x, y); *x += dx; *y += dy; } |