From 568b19e7b35785de34c6e40a1e3c05bcea191dbe Mon Sep 17 00:00:00 2001 From: jeysbach Date: Mon, 16 Mar 2020 09:48:26 +0100 Subject: [PATCH] Feature #10637: Console command for removing floating objects --- src/openrct2/interface/InteractiveConsole.cpp | 8 +++++ src/openrct2/world/Duck.cpp | 5 +++ src/openrct2/world/Sprite.cpp | 35 +++++++++++++++++++ src/openrct2/world/Sprite.h | 2 ++ 4 files changed, 50 insertions(+) diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 833c6d4263..f7f5e0ad19 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -1192,6 +1192,13 @@ static int32_t cc_remove_unused_objects(InteractiveConsole& console, [[maybe_unu return 0; } +static int32_t cc_remove_floating_objects(InteractiveConsole& console, const arguments_t& argv) +{ + uint16_t result = remove_floating_sprites(); + console.WriteFormatLine("Removed %d flying objects", result); + return 0; +} + static int32_t cc_remove_park_fences(InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv) { tile_element_iterator it; @@ -1675,6 +1682,7 @@ static constexpr const console_command console_command_table[] = { { "quit", cc_close, "Closes the console.", "quit" }, { "remove_park_fences", cc_remove_park_fences, "Removes all park fences from the surface", "remove_park_fences" }, { "remove_unused_objects", cc_remove_unused_objects, "Removes all the unused objects from the object selection.", "remove_unused_objects" }, + { "remove_floating_objects", cc_remove_floating_objects, "Removes floating objects", "remove_floating_objects"}, { "rides", cc_rides, "Ride management.", "rides " }, { "save_park", cc_save_park, "Save current state of park. If no name specified default path will be used.", "save_park [name]" }, { "say", cc_say, "Say to other players.", "say " }, diff --git a/src/openrct2/world/Duck.cpp b/src/openrct2/world/Duck.cpp index c965ab4a3c..9cf0fbcbe1 100644 --- a/src/openrct2/world/Duck.cpp +++ b/src/openrct2/world/Duck.cpp @@ -94,6 +94,11 @@ void Duck::Invalidate() invalidate_sprite_1(this); } +bool Duck::IsFlying() +{ + return this->state == DUCK_STATE::FLY_AWAY || this->state == DUCK_STATE::FLY_TO_WATER; +} + void Duck::Remove() { Invalidate(); diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index 8e85c9cc53..bef7ef98b7 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -814,6 +814,41 @@ void litter_remove_at(int32_t x, int32_t y, int32_t z) } } +/** + * Loops through all sprites, finds floating objects and removes them. + * Returns the amount of removed objects as feedback. + */ +uint16_t remove_floating_sprites() +{ + uint16_t removed = 0; + for (uint16_t i = 0; i < MAX_SPRITES; i++) + { + rct_sprite* rctSprite = get_sprite(i); + if (rctSprite->IsBalloon()) + { + sprite_remove(rctSprite->AsBalloon()); + sprite_misc_update(rctSprite); + removed++; + } + else if (rctSprite->IsDuck()) + { + if (rctSprite->AsDuck()->IsFlying()) + { + rctSprite->duck.Remove(); + sprite_misc_update(rctSprite); + removed++; + } + } + else if (rctSprite->IsMoneyEffect()) + { + sprite_remove(rctSprite->AsMoneyEffect()); + sprite_misc_update(rctSprite); + removed++; + } + } + return removed; +} + /** * Determines whether it's worth tweening a sprite or not when frame smoothing is on. */ diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index b803eff9c0..d106d1a82f 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -68,6 +68,7 @@ struct Duck : SpriteGeneric void UpdateFlyAway(); uint32_t GetFrameImage(int32_t direction) const; void Invalidate(); + bool IsFlying(); void Remove(); void MoveTo(const CoordsXYZ& destination); }; @@ -214,6 +215,7 @@ void invalidate_sprite_2(SpriteBase* sprite); void sprite_remove(SpriteBase* sprite); void litter_create(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t type); void litter_remove_at(int32_t x, int32_t y, int32_t z); +uint16_t remove_floating_sprites(); void sprite_misc_explosion_cloud_create(int32_t x, int32_t y, int32_t z); void sprite_misc_explosion_flare_create(int32_t x, int32_t y, int32_t z); uint16_t sprite_get_first_in_quadrant(int32_t x, int32_t y);