From cba52b240e0f90907a85e17812fc09408ae092ba Mon Sep 17 00:00:00 2001 From: spacek531 Date: Sun, 29 Aug 2021 02:30:34 -0700 Subject: [PATCH] Bird animation (#15294) * initial implementation; progress 1 progress 2 refactor to chain start progress 3 begin walking finish bird remove walking remove unused functions refactor track element getting fix formatting refactor and add comments remove brackets from simple if-else statements invalidate vehicle refactor again fix format and refactor please satisfy clang format fix fallthrough invalidate default case remove redundant falltrhough network bump use std::max refactor animation again fix modulus * move array declaration * satisfy clang-format * add changelog entry --- contributors.md | 2 +- distribution/changelog.txt | 1 + src/openrct2/network/NetworkBase.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 46 ++++++++++++++++++++++++++++ src/openrct2/ride/Vehicle.h | 4 ++- 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/contributors.md b/contributors.md index 21c84806fa..b12d3c4d21 100644 --- a/contributors.md +++ b/contributors.md @@ -62,7 +62,7 @@ The following people are not part of the development team, but have been contrib * Robert Jordan (trigger-death) - UI theming, title sequence editor, misc. * Aaron van Geffen (AaronVanGeffen) - scenario select screen, font detection, misc. * Michał Janiszewski (janisozaur) - Linux port, crash handling, security, misc. -* Kelson Blakewood (spacek531) - title sequences for release versions 0.0.4 through 0.1.2, title sequences using milliseconds +* Kelson Blakewood (spacek531) - title sequences, title sequence features, vehicle features * Hugo Wallenburg (Goddesen) - Misc. * Edward Calver (X7123M3-256) - New Hybrid Coaster track, extended sprite toolchain, more vehicle cheats, misc. * Matte Andersson (Nubbie) - Misc, UX diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 0c91d3c290..5e5d7651a0 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -6,6 +6,7 @@ - Feature: [#15164] Highlight elements selected by the Tile Inspector, tracks are currently not supported. - Feature: [#15165] [Plugin] Add the ability to create entities using "map.createEntity". - Feature: [#15194] [Plugin] Add guest properties, ride downtime and park casualty penalty. +- Feature: [#15294] New vehicle animation type: flying animal - Fix: [#13465] Creating a scenario based on a won save game results in a scenario that’s instantly won. - Fix: [#14316] Closing the Track Designs Manager window causes broken state. - Fix: [#14667] “Extreme Hawaiian Island” has unpurchaseable land tiles (original bug). diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 4452f1f04f..bd09ca6b0b 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -37,7 +37,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "5" +#define NETWORK_STREAM_VERSION "6" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 8dcabb345e..bbbdef5358 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -1536,6 +1536,13 @@ bool Vehicle::OpenRestraints() restraintsOpen = false; continue; } + if (vehicleEntry->animation == VEHICLE_ENTRY_ANIMATION_ANIMAL_FLYING + && (vehicle->animation_frame != 0 || vehicle->animationState > 0)) + { + vehicle->UpdateAnimationAnimalFlying(); + restraintsOpen = false; + continue; + } if (vehicle->HasUpdateFlag(VEHICLE_UPDATE_FLAG_BROKEN_CAR) && vehicle->restraints_position != 0xFF && (curRide->breakdown_reason_pending == BREAKDOWN_RESTRAINTS_STUCK_CLOSED @@ -7269,6 +7276,39 @@ void Vehicle::UpdateSpinningCar() Invalidate(); } +void Vehicle::UpdateAnimationAnimalFlying() +{ + if (animationState > 0) + { + animationState--; + return; + } + else + { + if (animation_frame == 0) + { + auto trackType = GetTrackType(); + TileElement* trackElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0); + if (trackElement != nullptr && trackElement->AsTrack()->HasChain()) + { + // start flapping, bird + animation_frame = 1; + animationState = 5; + Invalidate(); + } + } + else + { + // continue flapping until reaching frame 0 + animation_frame = (animation_frame + 1) % 4; + Invalidate(); + } + // number of frames to skip before updating again + constexpr std::array frameWaitTimes = { 5, 3, 5, 3 }; + animationState = frameWaitTimes[animation_frame]; + } +} + /** * * rct2: 0x006D63D4 @@ -7421,6 +7461,12 @@ void Vehicle::UpdateAdditionalAnimation() } } break; + case VEHICLE_ENTRY_ANIMATION_ANIMAL_FLYING: + UpdateAnimationAnimalFlying(); + // makes animation play faster with vehicle speed + targetFrame = abs(_vehicleVelocityF64E08) >> 24; + animationState = std::max(animationState - targetFrame, 0); + break; } } diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index e8e84859f6..8963fb379d 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -324,6 +324,7 @@ private: void UpdateCrashSetup(); void UpdateCollisionSetup(); int32_t UpdateMotionDodgems(); + void UpdateAnimationAnimalFlying(); void UpdateAdditionalAnimation(); void CheckIfMissing(); bool CurrentTowerElementIsTop(); @@ -472,7 +473,8 @@ enum VEHICLE_ENTRY_ANIMATION_OBSERVATION_TOWER, VEHICLE_ENTRY_ANIMATION_HELICARS, VEHICLE_ENTRY_ANIMATION_MONORAIL_CYCLES, - VEHICLE_ENTRY_ANIMATION_MULTI_DIM_COASTER + VEHICLE_ENTRY_ANIMATION_MULTI_DIM_COASTER, + VEHICLE_ENTRY_ANIMATION_ANIMAL_FLYING // OpenRCT2-specific feature }; enum : uint32_t