diff options
Diffstat (limited to 'src/bike.c')
-rw-r--r-- | src/bike.c | 143 |
1 files changed, 73 insertions, 70 deletions
diff --git a/src/bike.c b/src/bike.c index b1176997b..c03926168 100644 --- a/src/bike.c +++ b/src/bike.c @@ -20,6 +20,7 @@ extern u8 gUnknown_020297ED; u8 debug_sub_805F2B0(u8); #endif +// this file's functions static void MovePlayerOnMachBike(u8, u16, u16); static u8 GetMachBikeTransition(u8 *); static void MachBikeTransition_FaceDirection(u8); @@ -54,13 +55,15 @@ 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 EventObject *, s16, s16, u8, u8); +static u8 Bike_CheckCollisionTryAdvanceCollisionCount(struct ObjectEvent *, s16, s16, u8, u8); static bool8 IsRunningDisallowedByMetatile(u8); static void Bike_TryAdvanceCyclingRoadCollisions(); static u8 CanBikeFaceDirOnMetatile(u8, u8); static bool8 WillPlayerCollideWithCollision(u8, u8); static void Bike_SetBikeStill(void); +// const rom data + /* A bike transition is a type of callback for the bike that actually modifies the bicycle's direction or momentum or otherwise movement. @@ -123,7 +126,7 @@ static const u8 sAcroBikeJumpTimerList[] = {4, 0}; // this is a list of history inputs to do in order to do the check to retrieve a jump direction for acro bike. it seems to be an extensible list, so its possible that Game Freak may have intended for the Acro Bike to have more complex tricks at some point. The final list only has the acro jump. static const struct BikeHistoryInputInfo sAcroBikeTricksList[] = { - // the 0xF is a mask performed with each byte of the array in order to perform the check on only the last entry of the history list, otherwise the check wouldnt work as there can be 0xF0 as opposed to 0x0F. + // the 0xF is a mask performed with each byte of the array in order to perform the check on only the last entry of the history list, otherwise the check wouldn't work as there can be 0xF0 as opposed to 0x0F. {DIR_SOUTH, B_BUTTON, 0xF, 0xF, sAcroBikeJumpTimerList, sAcroBikeJumpTimerList, DIR_SOUTH}, {DIR_NORTH, B_BUTTON, 0xF, 0xF, sAcroBikeJumpTimerList, sAcroBikeJumpTimerList, DIR_NORTH}, {DIR_WEST, B_BUTTON, 0xF, 0xF, sAcroBikeJumpTimerList, sAcroBikeJumpTimerList, DIR_WEST}, @@ -199,31 +202,31 @@ static void MachBikeTransition_FaceDirection(u8 direction) static void MachBikeTransition_TurnDirection(u8 direction) { - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior)) + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior)) { PlayerTurnInPlace(direction); Bike_SetBikeStill(); } else { - MachBikeTransition_FaceDirection(playerEventObj->facingDirection); + MachBikeTransition_FaceDirection(playerObjEvent->facingDirection); } } static void MachBikeTransition_TrySpeedUp(u8 direction) { - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; u8 collision; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == FALSE) + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == FALSE) { // we cannot go forward, so either slow down or, if we are stopped, idle face direction. if (gPlayerAvatar.bikeSpeed) - MachBikeTransition_TrySlowDown(playerEventObj->movementDirection); + MachBikeTransition_TrySlowDown(playerObjEvent->movementDirection); else - MachBikeTransition_FaceDirection(playerEventObj->movementDirection); + MachBikeTransition_FaceDirection(playerObjEvent->movementDirection); } else { @@ -383,10 +386,10 @@ static u8 AcroBikeHandleInputTurning(u8 *newDirection, u16 newKeys, u16 heldKeys static u8 AcroBikeHandleInputWheelieStanding(u8 *newDirection, u16 newKeys, u16 heldKeys) { u8 direction; - struct EventObject *playerEventObj; + struct ObjectEvent *playerObjEvent; direction = GetPlayerMovementDirection(); - playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; gPlayerAvatar.runningState = NOT_MOVING; if (heldKeys & B_BUTTON) @@ -395,7 +398,7 @@ static u8 AcroBikeHandleInputWheelieStanding(u8 *newDirection, u16 newKeys, u16 { // B button was released. gPlayerAvatar.bikeFrameCounter = 0; - if (!MetatileBehavior_IsBumpySlope(playerEventObj->currentMetatileBehavior)) + if (!MetatileBehavior_IsBumpySlope(playerObjEvent->currentMetatileBehavior)) { // Go back to normal on flat ground *newDirection = direction; @@ -430,15 +433,15 @@ static u8 AcroBikeHandleInputWheelieStanding(u8 *newDirection, u16 newKeys, u16 static u8 AcroBikeHandleInputBunnyHop(u8 *newDirection, u16 newKeys, u16 heldKeys) { u8 direction; - struct EventObject *playerEventObj; + struct ObjectEvent *playerObjEvent; direction = GetPlayerMovementDirection(); - playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; if (!(heldKeys & B_BUTTON)) { // B button was released Bike_SetBikeStill(); - if (MetatileBehavior_IsBumpySlope(playerEventObj->currentMetatileBehavior)) + if (MetatileBehavior_IsBumpySlope(playerObjEvent->currentMetatileBehavior)) { // even though B was released, dont undo the wheelie on the bumpy slope. gPlayerAvatar.acroBikeState = ACRO_STATE_WHEELIE_STANDING; @@ -477,15 +480,15 @@ static u8 AcroBikeHandleInputBunnyHop(u8 *newDirection, u16 newKeys, u16 heldKey static u8 AcroBikeHandleInputWheelieMoving(u8 *newDirection, u16 newKeys, u16 heldKeys) { u8 direction; - struct EventObject *playerEventObj; + struct ObjectEvent *playerObjEvent; direction = GetPlayerFacingDirection(); - playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; 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(playerEventObj->currentMetatileBehavior)) + if (!MetatileBehavior_IsBumpySlope(playerObjEvent->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; @@ -531,10 +534,10 @@ static u8 AcroBikeHandleInputWheelieMoving(u8 *newDirection, u16 newKeys, u16 he static u8 AcroBikeHandleInputSidewaysJump(u8 *ptr, u16 newKeys, u16 heldKeys) { - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - playerEventObj->facingDirectionLocked = 0; - SetEventObjectDirection(playerEventObj, playerEventObj->facingDirection); + playerObjEvent->facingDirectionLocked = 0; + SetObjectEventDirection(playerObjEvent, playerObjEvent->facingDirection); gPlayerAvatar.acroBikeState = ACRO_STATE_NORMAL; return CheckMovementInputAcroBike(ptr, newKeys, heldKeys); } @@ -552,21 +555,21 @@ static void AcroBikeTransition_FaceDirection(u8 direction) static void AcroBikeTransition_TurnDirection(u8 direction) { - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) - direction = playerEventObj->movementDirection; + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == 0) + direction = playerObjEvent->movementDirection; PlayerFaceDirection(direction); } static void AcroBikeTransition_Moving(u8 direction) { u8 collision; - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == 0) { - AcroBikeTransition_FaceDirection(playerEventObj->movementDirection); + AcroBikeTransition_FaceDirection(playerObjEvent->movementDirection); return; } collision = get_some_collision(direction); @@ -585,52 +588,52 @@ static void AcroBikeTransition_Moving(u8 direction) static void AcroBikeTransition_NormalToWheelie(u8 direction) { - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) - direction = playerEventObj->movementDirection; + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == 0) + direction = playerObjEvent->movementDirection; PlayerStartWheelie(direction); } static void AcroBikeTransition_WheelieToNormal(u8 direction) { - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) - direction = playerEventObj->movementDirection; + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == 0) + direction = playerObjEvent->movementDirection; PlayerEndWheelie(direction); } static void AcroBikeTransition_WheelieIdle(u8 direction) { - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) - direction = playerEventObj->movementDirection; + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == 0) + direction = playerObjEvent->movementDirection; PlayerIdleWheelie(direction); } static void AcroBikeTransition_WheelieHoppingStanding(u8 direction) { - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) - direction = playerEventObj->movementDirection; + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == 0) + direction = playerObjEvent->movementDirection; PlayerStandingHoppingWheelie(direction); } static void AcroBikeTransition_WheelieHoppingMoving(u8 direction) { u8 collision; - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == 0) { - AcroBikeTransition_WheelieHoppingStanding(playerEventObj->movementDirection); + AcroBikeTransition_WheelieHoppingStanding(playerObjEvent->movementDirection); return; } collision = get_some_collision(direction); - //TODO: Try to get rid of this goto + // TODO: Try to get rid of this goto if (collision == 0 || collision == 9) { goto derp; @@ -647,7 +650,7 @@ static void AcroBikeTransition_WheelieHoppingMoving(u8 direction) } else { - derp: + derp: PlayerMovingHoppingWheelie(direction); } } @@ -656,7 +659,7 @@ static void AcroBikeTransition_WheelieHoppingMoving(u8 direction) static void AcroBikeTransition_SideJump(u8 direction) { u8 collision; - struct EventObject *playerEventObj; + struct ObjectEvent *playerObjEvent; collision = get_some_collision(direction); if (collision != 0) @@ -674,9 +677,9 @@ static void AcroBikeTransition_SideJump(u8 direction) return; } } - playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; PlaySE(SE_JITE_PYOKO); - playerEventObj->facingDirectionLocked = 1; + playerObjEvent->facingDirectionLocked = 1; PlayerSetAnimId(GetJumpMovementAction(direction), 2); } @@ -688,11 +691,11 @@ static void AcroBikeTransition_TurnJump(u8 direction) static void AcroBikeTransition_WheelieMoving(u8 direction) { u8 collision; - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == 0) { - PlayerIdleWheelie(playerEventObj->movementDirection); + PlayerIdleWheelie(playerObjEvent->movementDirection); return; } collision = get_some_collision(direction); @@ -708,7 +711,7 @@ static void AcroBikeTransition_WheelieMoving(u8 direction) } else if (collision <= 4) { - if (MetatileBehavior_IsBumpySlope(playerEventObj->currentMetatileBehavior)) + if (MetatileBehavior_IsBumpySlope(playerObjEvent->currentMetatileBehavior)) PlayerIdleWheelie(direction); else sub_80595DC(direction); //hit wall? @@ -722,11 +725,11 @@ static void AcroBikeTransition_WheelieMoving(u8 direction) static void AcroBikeTransition_WheelieRisingMoving(u8 direction) { u8 collision; - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == 0) { - PlayerStartWheelie(playerEventObj->movementDirection); + PlayerStartWheelie(playerObjEvent->movementDirection); return; } collision = get_some_collision(direction); @@ -742,7 +745,7 @@ static void AcroBikeTransition_WheelieRisingMoving(u8 direction) } else if (collision <= 4) { - if (MetatileBehavior_IsBumpySlope(playerEventObj->currentMetatileBehavior)) + if (MetatileBehavior_IsBumpySlope(playerObjEvent->currentMetatileBehavior)) PlayerIdleWheelie(direction); else sub_80595DC(direction); //hit wall? @@ -755,20 +758,20 @@ static void AcroBikeTransition_WheelieRisingMoving(u8 direction) static void AcroBikeTransition_WheelieLoweringMoving(u8 direction) { - u8 var; - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + u8 collision; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (CanBikeFaceDirOnMetatile(direction, playerEventObj->currentMetatileBehavior) == 0) + if (CanBikeFaceDirOnMetatile(direction, playerObjEvent->currentMetatileBehavior) == 0) { - PlayerEndWheelie(playerEventObj->movementDirection); + PlayerEndWheelie(playerObjEvent->movementDirection); return; } - var = get_some_collision(direction); - if (var > 0 && var < 12) + collision = get_some_collision(direction); + if (collision > 0 && collision < 12) { - if (var == 6) + if (collision == 6) PlayerJumpLedge(direction); - else if (var < 5 || var > 8) + else if (collision < 5 || collision > 8) PlayerEndWheelie(direction); return; } @@ -885,18 +888,18 @@ static u8 get_some_collision(u8 direction) s16 x; s16 y; u8 metatitleBehavior; - struct EventObject *playerEventObj = &gEventObjects[gPlayerAvatar.eventObjectId]; + struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - x = playerEventObj->currentCoords.x; - y = playerEventObj->currentCoords.y; + x = playerObjEvent->currentCoords.x; + y = playerObjEvent->currentCoords.y; MoveCoords(direction, &x, &y); metatitleBehavior = MapGridGetMetatileBehaviorAt(x, y); - return Bike_CheckCollisionTryAdvanceCollisionCount(playerEventObj, x, y, direction, metatitleBehavior); + return Bike_CheckCollisionTryAdvanceCollisionCount(playerObjEvent, x, y, direction, metatitleBehavior); } -static u8 Bike_CheckCollisionTryAdvanceCollisionCount(struct EventObject *eventObject, s16 x, s16 y, u8 direction, u8 metatitleBehavior) +static u8 Bike_CheckCollisionTryAdvanceCollisionCount(struct ObjectEvent *objectEvent, s16 x, s16 y, u8 direction, u8 metatitleBehavior) { - u8 collision = CheckForEventObjectCollision(eventObject, x, y, direction, metatitleBehavior); + u8 collision = CheckForObjectEventCollision(objectEvent, x, y, direction, metatitleBehavior); if (collision > 4) return collision; @@ -984,7 +987,7 @@ bool8 IsBikingDisallowedByPlayer(void) bool8 player_should_look_direction_be_enforced_upon_movement(void) { - if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE) != FALSE && MetatileBehavior_IsBumpySlope(gEventObjects[gPlayerAvatar.eventObjectId].currentMetatileBehavior) != FALSE) + if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE) != FALSE && MetatileBehavior_IsBumpySlope(gObjectEvents[gPlayerAvatar.objectEventId].currentMetatileBehavior) != FALSE) return FALSE; else return TRUE; |