diff options
Diffstat (limited to 'src/bike.c')
-rw-r--r-- | src/bike.c | 143 |
1 files changed, 72 insertions, 71 deletions
diff --git a/src/bike.c b/src/bike.c index e827707cd..6ffd479f7 100644 --- a/src/bike.c +++ b/src/bike.c @@ -1,6 +1,6 @@ #include "global.h" #include "bike.h" -#include "field_map_obj.h" +#include "event_object_movement.h" #include "field_player_avatar.h" #include "fieldmap.h" #include "constants/flags.h" @@ -9,6 +9,7 @@ #include "overworld.h" #include "constants/songs.h" #include "sound.h" +#include "constants/map_types.h" extern bool8 gBikeCyclingChallenge; extern u8 gBikeCollisions; @@ -56,7 +57,7 @@ static void Bike_UpdateDirTimerHistory(u8); static void Bike_UpdateABStartSelectHistory(u8); static u8 Bike_DPadToDirection(u16); static u8 get_some_collision(u8); -static u8 Bike_CheckCollisionTryAdvanceCollisionCount(struct MapObject *, s16, s16, u8, u8); +static u8 Bike_CheckCollisionTryAdvanceCollisionCount(struct EventObject *, s16, s16, u8, u8); static bool8 IsRunningDisallowedByMetatile(u8); static void Bike_TryAdvanceCyclingRoadCollisions(); static u8 CanBikeFaceDirOnMetatile(u8, u8); @@ -152,7 +153,7 @@ static void MovePlayerOnMachBike(u8 direction, u16 newKeys, u16 heldKeys) static u8 GetMachBikeTransition(u8 *dirTraveling) { // if the dir updated before this function, get the relevent new direction to check later. - u8 direction = player_get_direction_upper_nybble(); + u8 direction = GetPlayerMovementDirection(); // is the player standing still? if (*dirTraveling == 0) @@ -196,31 +197,31 @@ static void MachBikeTransition_FaceDirection(u8 direction) static void MachBikeTransition_TurnDirection(u8 direction) { - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E)) + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior)) { PlayerTurnInPlace(direction); Bike_SetBikeStill(); } else { - MachBikeTransition_FaceDirection(playerMapObj->mapobj_unk_18); + MachBikeTransition_FaceDirection(playerEventObj->facingDirection); } } static void MachBikeTransition_TrySpeedUp(u8 direction) { - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; u8 collision; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == FALSE) + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == FALSE) { // we cannot go forward, so either slow down or, if we are stopped, idle face direction. if (gPlayerAvatar.bikeSpeed) - MachBikeTransition_TrySlowDown(playerMapObj->placeholder18); + MachBikeTransition_TrySlowDown(playerEventObj->movementDirection); else - MachBikeTransition_FaceDirection(playerMapObj->placeholder18); + MachBikeTransition_FaceDirection(playerEventObj->movementDirection); } else { @@ -296,7 +297,7 @@ static u8 CheckMovementInputAcroBike(u8 *newDirection, u16 newKeys, u16 heldKeys static u8 AcroBikeHandleInputNormal(u8 *newDirection, u16 newKeys, u16 heldKeys) { - u8 direction = player_get_direction_upper_nybble(); + u8 direction = GetPlayerMovementDirection(); gPlayerAvatar.bikeFrameCounter = 0; if (*newDirection == DIR_NONE) @@ -349,7 +350,7 @@ static u8 AcroBikeHandleInputTurning(u8 *newDirection, u16 newKeys, u16 heldKeys Bike_SetBikeStill(); return ACRO_TRANS_TURN_DIRECTION; } - direction = player_get_direction_upper_nybble(); + direction = GetPlayerMovementDirection(); if (*newDirection == AcroBike_GetJumpDirection()) { Bike_SetBikeStill(); // Bike_SetBikeStill sets speed to standing, but the next line immediately overrides it. could have just reset acroBikeState to 0 here instead of wasting a jump. @@ -376,10 +377,10 @@ static u8 AcroBikeHandleInputTurning(u8 *newDirection, u16 newKeys, u16 heldKeys static u8 AcroBikeHandleInputWheelieStanding(u8 *newDirection, u16 newKeys, u16 heldKeys) { u8 direction; - struct MapObject *playerMapObj; + struct EventObject *playerEventObj; - direction = player_get_direction_upper_nybble(); - playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + direction = GetPlayerMovementDirection(); + playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; gPlayerAvatar.runningState = NOT_MOVING; if (heldKeys & B_BUTTON) @@ -388,7 +389,7 @@ static u8 AcroBikeHandleInputWheelieStanding(u8 *newDirection, u16 newKeys, u16 { // B button was released. gPlayerAvatar.bikeFrameCounter = 0; - if (!MetatileBehavior_IsBumpySlope(playerMapObj->mapobj_unk_1E)) + if (!MetatileBehavior_IsBumpySlope(playerEventObj->currentMetatileBehavior)) { // Go back to normal on flat ground *newDirection = direction; @@ -423,15 +424,15 @@ static u8 AcroBikeHandleInputWheelieStanding(u8 *newDirection, u16 newKeys, u16 static u8 AcroBikeHandleInputBunnyHop(u8 *newDirection, u16 newKeys, u16 heldKeys) { u8 direction; - struct MapObject *playerMapObj; + struct EventObject *playerEventObj; - direction = player_get_direction_upper_nybble(); - playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + direction = GetPlayerMovementDirection(); + playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; if (!(heldKeys & B_BUTTON)) { // B button was released Bike_SetBikeStill(); - if (MetatileBehavior_IsBumpySlope(playerMapObj->mapobj_unk_1E)) + if (MetatileBehavior_IsBumpySlope(playerEventObj->currentMetatileBehavior)) { // even though B was released, dont undo the wheelie on the bumpy slope. gPlayerAvatar.acroBikeState = ACRO_STATE_WHEELIE_STANDING; @@ -470,15 +471,15 @@ static u8 AcroBikeHandleInputBunnyHop(u8 *newDirection, u16 newKeys, u16 heldKey static u8 AcroBikeHandleInputWheelieMoving(u8 *newDirection, u16 newKeys, u16 heldKeys) { u8 direction; - struct MapObject *playerMapObj; + struct EventObject *playerEventObj; - direction = player_get_direction_lower_nybble(); - playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + direction = GetPlayerFacingDirection(); + playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; if (!(heldKeys & B_BUTTON)) { // we were moving on a wheelie, but we let go while moving. reset bike still status Bike_SetBikeStill(); - if (!MetatileBehavior_IsBumpySlope(playerMapObj->mapobj_unk_1E)) + if (!MetatileBehavior_IsBumpySlope(playerEventObj->currentMetatileBehavior)) { // we let go of B and arent on a bumpy slope, set state to normal because now we need to handle this gPlayerAvatar.acroBikeState = ACRO_STATE_NORMAL; @@ -524,10 +525,10 @@ static u8 AcroBikeHandleInputWheelieMoving(u8 *newDirection, u16 newKeys, u16 he static u8 AcroBikeHandleInputSidewaysJump(u8 *ptr, u16 newKeys, u16 heldKeys) { - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - playerMapObj->mapobj_bit_9 = 0; - FieldObjectSetDirection(playerMapObj, playerMapObj->mapobj_unk_18); + playerEventObj->facingDirectionLocked = 0; + SetEventObjectDirection(playerEventObj, playerEventObj->facingDirection); gPlayerAvatar.acroBikeState = ACRO_STATE_NORMAL; return CheckMovementInputAcroBike(ptr, newKeys, heldKeys); } @@ -545,21 +546,21 @@ static void AcroBikeTransition_FaceDirection(u8 direction) static void AcroBikeTransition_TurnDirection(u8 direction) { - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == 0) - direction = playerMapObj->placeholder18; + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) + direction = playerEventObj->movementDirection; PlayerFaceDirection(direction); } static void AcroBikeTransition_Moving(u8 direction) { u8 collision; - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == 0) + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) { - AcroBikeTransition_FaceDirection(playerMapObj->placeholder18); + AcroBikeTransition_FaceDirection(playerEventObj->movementDirection); return; } collision = get_some_collision(direction); @@ -580,48 +581,48 @@ static void AcroBikeTransition_Moving(u8 direction) static void AcroBikeTransition_NormalToWheelie(u8 direction) { - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == 0) - direction = playerMapObj->placeholder18; + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) + direction = playerEventObj->movementDirection; PlayerStartWheelie(direction); } static void AcroBikeTransition_WheelieToNormal(u8 direction) { - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == 0) - direction = playerMapObj->placeholder18; + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) + direction = playerEventObj->movementDirection; PlayerEndWheelie(direction); } static void AcroBikeTransition_WheelieIdle(u8 direction) { - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == 0) - direction = playerMapObj->placeholder18; + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) + direction = playerEventObj->movementDirection; PlayerIdleWheelie(direction); } static void AcroBikeTransition_WheelieHoppingStanding(u8 direction) { - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == 0) - direction = playerMapObj->placeholder18; + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) + direction = playerEventObj->movementDirection; PlayerStandingHoppingWheelie(direction); } static void AcroBikeTransition_WheelieHoppingMoving(u8 direction) { u8 collision; - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == 0) + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) { - AcroBikeTransition_WheelieHoppingStanding(playerMapObj->placeholder18); + AcroBikeTransition_WheelieHoppingStanding(playerEventObj->movementDirection); return; } collision = get_some_collision(direction); @@ -651,7 +652,7 @@ static void AcroBikeTransition_WheelieHoppingMoving(u8 direction) static void AcroBikeTransition_SideJump(u8 direction) { u8 collision; - struct MapObject *playerMapObj; + struct EventObject *playerEventObj; collision = get_some_collision(direction); if (collision != 0) @@ -669,10 +670,10 @@ static void AcroBikeTransition_SideJump(u8 direction) return; } } - playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; PlaySE(SE_JITE_PYOKO); - playerMapObj->mapobj_bit_9 = 1; - PlayerSetAnimId(sub_8093514(direction), 2); + playerEventObj->facingDirectionLocked = 1; + PlayerSetAnimId(GetJumpMovementAction(direction), 2); } static void AcroBikeTransition_TurnJump(u8 direction) @@ -683,11 +684,11 @@ static void AcroBikeTransition_TurnJump(u8 direction) static void AcroBikeTransition_WheelieMoving(u8 direction) { u8 collision; - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == 0) + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) { - PlayerIdleWheelie(playerMapObj->placeholder18); + PlayerIdleWheelie(playerEventObj->movementDirection); return; } collision = get_some_collision(direction); @@ -703,7 +704,7 @@ static void AcroBikeTransition_WheelieMoving(u8 direction) } else if (collision <= 4) { - if (MetatileBehavior_IsBumpySlope(playerMapObj->mapobj_unk_1E)) + if (MetatileBehavior_IsBumpySlope(playerEventObj->currentMetatileBehavior)) PlayerIdleWheelie(direction); else sub_808B980(direction); //hit wall? @@ -717,11 +718,11 @@ static void AcroBikeTransition_WheelieMoving(u8 direction) static void AcroBikeTransition_WheelieRisingMoving(u8 direction) { u8 collision; - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == 0) + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) { - PlayerStartWheelie(playerMapObj->placeholder18); + PlayerStartWheelie(playerEventObj->movementDirection); return; } collision = get_some_collision(direction); @@ -737,7 +738,7 @@ static void AcroBikeTransition_WheelieRisingMoving(u8 direction) } else if (collision <= 4) { - if (MetatileBehavior_IsBumpySlope(playerMapObj->mapobj_unk_1E)) + if (MetatileBehavior_IsBumpySlope(playerEventObj->currentMetatileBehavior)) PlayerIdleWheelie(direction); else sub_808B980(direction); //hit wall? @@ -751,11 +752,11 @@ static void AcroBikeTransition_WheelieRisingMoving(u8 direction) static void AcroBikeTransition_WheelieLoweringMoving(u8 direction) { u8 collision; - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - if (CanBikeFaceDirOnMetatile(direction, playerMapObj->mapobj_unk_1E) == 0) + if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) { - PlayerEndWheelie(playerMapObj->placeholder18); + PlayerEndWheelie(playerEventObj->movementDirection); return; } collision = get_some_collision(direction); @@ -880,18 +881,18 @@ static u8 get_some_collision(u8 direction) s16 x; s16 y; u8 metatitleBehavior; - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; - x = playerMapObj->coords2.x; - y = playerMapObj->coords2.y; + x = playerEventObj->currentCoords.x; + y = playerEventObj->currentCoords.y; MoveCoords(direction, &x, &y); metatitleBehavior = MapGridGetMetatileBehaviorAt(x, y); - return Bike_CheckCollisionTryAdvanceCollisionCount(playerMapObj, x, y, direction, metatitleBehavior); + return Bike_CheckCollisionTryAdvanceCollisionCount(playerEventObj, x, y, direction, metatitleBehavior); } -static u8 Bike_CheckCollisionTryAdvanceCollisionCount(struct MapObject *mapObject, s16 x, s16 y, u8 direction, u8 metatitleBehavior) +static u8 Bike_CheckCollisionTryAdvanceCollisionCount(struct EventObject *eventObject, s16 x, s16 y, u8 direction, u8 metatitleBehavior) { - u8 collision = CheckForFieldObjectCollision(mapObject, x, y, direction, metatitleBehavior); + u8 collision = CheckForEventObjectCollision(eventObject, x, y, direction, metatitleBehavior); if (collision > 4) return collision; @@ -979,7 +980,7 @@ bool8 IsBikingDisallowedByPlayer(void) bool8 player_should_look_direction_be_enforced_upon_movement(void) { - if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE) != FALSE && MetatileBehavior_IsBumpySlope(gMapObjects[gPlayerAvatar.mapObjectId].mapobj_unk_1E) != FALSE) + if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE) != FALSE && MetatileBehavior_IsBumpySlope(gEventObjects[gPlayerAvatar.eventObjectId].currentMetatileBehavior) != FALSE) return FALSE; else return TRUE; @@ -1062,7 +1063,7 @@ void Bike_HandleBumpySlopeJump(void) if (MetatileBehavior_IsBumpySlope(tileBehavior)) { gPlayerAvatar.acroBikeState = ACRO_STATE_WHEELIE_STANDING; - sub_808C1B4(player_get_direction_upper_nybble()); + sub_808C1B4(GetPlayerMovementDirection()); } } } |