2021-01-07 21:06:49 +02:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2014-05-25 19:47:11 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2014-05-25 19:47:11 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-05-25 19:47:11 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 23:17:03 +02:00
|
|
|
#include "Sprite.h"
|
|
|
|
|
|
2017-12-13 13:02:24 +01:00
|
|
|
#include "../Cheats.h"
|
2018-06-22 23:17:03 +02:00
|
|
|
#include "../Game.h"
|
|
|
|
|
#include "../OpenRCT2.h"
|
|
|
|
|
#include "../audio/audio.h"
|
2021-05-09 19:12:44 +01:00
|
|
|
#include "../core/ChecksumStream.h"
|
2018-05-23 20:27:00 +01:00
|
|
|
#include "../core/Crypt.h"
|
2021-05-09 19:12:44 +01:00
|
|
|
#include "../core/DataSerialiser.h"
|
2018-03-13 13:14:02 +01:00
|
|
|
#include "../core/Guard.hpp"
|
2021-05-09 19:12:44 +01:00
|
|
|
#include "../core/MemoryStream.h"
|
2018-01-05 23:45:53 +00:00
|
|
|
#include "../interface/Viewport.h"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "../localisation/Date.h"
|
|
|
|
|
#include "../localisation/Localisation.h"
|
2018-01-02 17:58:43 +00:00
|
|
|
#include "../scenario/Scenario.h"
|
2017-03-23 17:56:39 +00:00
|
|
|
#include "Fountain.h"
|
2018-06-22 23:17:03 +02:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cmath>
|
2018-11-21 23:16:04 +01:00
|
|
|
#include <iterator>
|
2021-03-26 05:48:38 +00:00
|
|
|
#include <numeric>
|
2021-01-23 07:36:46 +00:00
|
|
|
#include <vector>
|
2014-05-25 19:47:11 +01:00
|
|
|
|
2021-02-24 23:34:34 +01:00
|
|
|
static rct_sprite _spriteList[MAX_ENTITIES];
|
2021-03-16 11:18:06 +00:00
|
|
|
static std::array<std::list<uint16_t>, EnumValue(EntityType::Count)> gEntityLists;
|
2021-01-26 07:42:56 +00:00
|
|
|
static std::vector<uint16_t> _freeIdList;
|
2016-09-12 18:56:52 +01:00
|
|
|
|
2021-02-24 23:34:34 +01:00
|
|
|
static bool _spriteFlashingList[MAX_ENTITIES];
|
2017-06-17 12:55:41 +02:00
|
|
|
|
2021-01-23 07:36:46 +00:00
|
|
|
static std::array<std::vector<uint16_t>, SPATIAL_INDEX_SIZE> gSpriteSpatialIndex;
|
2016-05-09 00:08:03 +01:00
|
|
|
|
2021-01-23 07:36:46 +00:00
|
|
|
constexpr size_t GetSpatialIndexOffset(int32_t x, int32_t y)
|
|
|
|
|
{
|
|
|
|
|
size_t index = SPATIAL_INDEX_LOCATION_NULL;
|
|
|
|
|
if (x != LOCATION_NULL)
|
|
|
|
|
{
|
|
|
|
|
x = std::clamp(x, 0, 0xFFFF);
|
|
|
|
|
y = std::clamp(y, 0, 0xFFFF);
|
|
|
|
|
|
|
|
|
|
int16_t flooredX = floor2(x, 32);
|
|
|
|
|
uint8_t tileY = y >> 5;
|
|
|
|
|
index = (flooredX << 3) | tileY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index >= sizeof(gSpriteSpatialIndex))
|
|
|
|
|
{
|
|
|
|
|
return SPATIAL_INDEX_LOCATION_NULL;
|
|
|
|
|
}
|
|
|
|
|
return index;
|
|
|
|
|
}
|
2017-01-28 22:12:07 +01:00
|
|
|
|
2020-06-06 11:32:37 +01:00
|
|
|
// Required for GetEntity to return a default
|
|
|
|
|
template<> bool SpriteBase::Is<SpriteBase>() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-23 21:59:45 +00:00
|
|
|
template<> bool SpriteBase::Is<Litter>() const
|
|
|
|
|
{
|
2021-03-17 08:04:41 +00:00
|
|
|
return Type == EntityType::Litter;
|
2020-01-23 21:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 21:24:50 +00:00
|
|
|
constexpr bool EntityTypeIsMiscEntity(const EntityType type)
|
2021-01-10 15:14:34 +00:00
|
|
|
{
|
2021-03-22 21:24:50 +00:00
|
|
|
switch (type)
|
2021-03-17 08:04:41 +00:00
|
|
|
{
|
|
|
|
|
case EntityType::SteamParticle:
|
|
|
|
|
case EntityType::MoneyEffect:
|
|
|
|
|
case EntityType::CrashedVehicleParticle:
|
|
|
|
|
case EntityType::ExplosionCloud:
|
|
|
|
|
case EntityType::CrashSplash:
|
|
|
|
|
case EntityType::ExplosionFlare:
|
|
|
|
|
case EntityType::JumpingFountain:
|
|
|
|
|
case EntityType::Balloon:
|
|
|
|
|
case EntityType::Duck:
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-01-10 15:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 21:24:50 +00:00
|
|
|
template<> bool SpriteBase::Is<MiscEntity>() const
|
|
|
|
|
{
|
|
|
|
|
return EntityTypeIsMiscEntity(Type);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-23 21:59:45 +00:00
|
|
|
template<> bool SpriteBase::Is<SteamParticle>() const
|
|
|
|
|
{
|
2021-03-17 08:04:41 +00:00
|
|
|
return Type == EntityType::SteamParticle;
|
2020-01-23 21:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<> bool SpriteBase::Is<ExplosionFlare>() const
|
|
|
|
|
{
|
2021-03-17 08:04:41 +00:00
|
|
|
return Type == EntityType::ExplosionFlare;
|
2020-01-23 21:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<> bool SpriteBase::Is<ExplosionCloud>() const
|
|
|
|
|
{
|
2021-03-17 08:04:41 +00:00
|
|
|
return Type == EntityType::ExplosionCloud;
|
2020-01-23 21:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-16 11:18:06 +00:00
|
|
|
uint16_t GetEntityListCount(EntityType type)
|
2020-07-04 07:53:10 +01:00
|
|
|
{
|
2021-03-16 11:18:06 +00:00
|
|
|
return static_cast<uint16_t>(gEntityLists[EnumValue(type)].size());
|
2020-07-04 07:53:10 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-26 07:42:56 +00:00
|
|
|
uint16_t GetNumFreeEntities()
|
|
|
|
|
{
|
|
|
|
|
return static_cast<uint16_t>(_freeIdList.size());
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-11 03:05:57 +01:00
|
|
|
std::string rct_sprite_checksum::ToString() const
|
|
|
|
|
{
|
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
|
|
result.reserve(raw.size() * 2);
|
|
|
|
|
for (auto b : raw)
|
|
|
|
|
{
|
|
|
|
|
char buf[3];
|
2021-05-09 19:12:44 +01:00
|
|
|
snprintf(buf, 3, "%02x", static_cast<int32_t>(b));
|
2018-12-11 03:05:57 +01:00
|
|
|
result.append(buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-01 11:29:54 +01:00
|
|
|
SpriteBase* try_get_sprite(size_t spriteIndex)
|
2017-03-10 17:26:08 +00:00
|
|
|
{
|
2021-02-24 23:34:34 +01:00
|
|
|
return spriteIndex >= MAX_ENTITIES ? nullptr : &_spriteList[spriteIndex].misc;
|
2017-03-10 17:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-01 11:29:54 +01:00
|
|
|
SpriteBase* get_sprite(size_t spriteIndex)
|
2016-07-17 22:14:44 +02:00
|
|
|
{
|
2020-08-01 11:29:54 +01:00
|
|
|
if (spriteIndex == SPRITE_INDEX_NULL)
|
2019-03-09 12:29:33 +00:00
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2021-02-24 23:34:34 +01:00
|
|
|
openrct2_assert(spriteIndex < MAX_ENTITIES, "Tried getting sprite %u", spriteIndex);
|
2020-08-01 11:29:54 +01:00
|
|
|
return try_get_sprite(spriteIndex);
|
2016-07-17 22:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-23 07:36:46 +00:00
|
|
|
const std::vector<uint16_t>& GetEntityTileList(const CoordsXY& spritePos)
|
2015-09-05 13:59:12 +01:00
|
|
|
{
|
2020-06-21 14:03:35 -03:00
|
|
|
return gSpriteSpatialIndex[GetSpatialIndexOffset(spritePos.x, spritePos.y)];
|
2015-09-05 13:59:12 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-31 18:43:48 +02:00
|
|
|
void SpriteBase::Invalidate()
|
2015-03-25 23:57:09 +00:00
|
|
|
{
|
2021-01-07 21:06:49 +02:00
|
|
|
if (sprite_left == LOCATION_NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-12-31 18:43:48 +02:00
|
|
|
int32_t maxZoom = 0;
|
2021-03-17 08:04:41 +00:00
|
|
|
switch (Type)
|
2020-12-31 18:43:48 +02:00
|
|
|
{
|
2021-03-17 08:04:41 +00:00
|
|
|
case EntityType::Vehicle:
|
|
|
|
|
case EntityType::Guest:
|
|
|
|
|
case EntityType::Staff:
|
2021-01-05 19:24:52 +02:00
|
|
|
maxZoom = 2;
|
2020-12-31 18:43:48 +02:00
|
|
|
break;
|
2021-03-17 08:04:41 +00:00
|
|
|
case EntityType::CrashedVehicleParticle:
|
|
|
|
|
case EntityType::JumpingFountain:
|
|
|
|
|
maxZoom = 0;
|
|
|
|
|
break;
|
|
|
|
|
case EntityType::Duck:
|
|
|
|
|
maxZoom = 1;
|
|
|
|
|
break;
|
|
|
|
|
case EntityType::SteamParticle:
|
|
|
|
|
case EntityType::MoneyEffect:
|
|
|
|
|
case EntityType::ExplosionCloud:
|
|
|
|
|
case EntityType::CrashSplash:
|
|
|
|
|
case EntityType::ExplosionFlare:
|
|
|
|
|
case EntityType::Balloon:
|
|
|
|
|
maxZoom = 2;
|
|
|
|
|
break;
|
|
|
|
|
case EntityType::Litter:
|
2020-12-31 18:43:48 +02:00
|
|
|
maxZoom = 0;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-01-07 21:06:49 +02:00
|
|
|
|
|
|
|
|
viewports_invalidate(sprite_left, sprite_top, sprite_right, sprite_bottom, maxZoom);
|
2015-03-25 23:57:09 +00:00
|
|
|
}
|
2021-03-16 11:18:06 +00:00
|
|
|
|
2021-03-26 05:48:38 +00:00
|
|
|
static void ResetEntityLists()
|
2021-01-21 18:36:34 +00:00
|
|
|
{
|
|
|
|
|
for (auto& list : gEntityLists)
|
|
|
|
|
{
|
|
|
|
|
list.clear();
|
|
|
|
|
}
|
2021-03-26 05:48:38 +00:00
|
|
|
}
|
2021-01-21 18:36:34 +00:00
|
|
|
|
2021-03-26 05:48:38 +00:00
|
|
|
static void ResetFreeIds()
|
|
|
|
|
{
|
2021-01-26 07:42:56 +00:00
|
|
|
_freeIdList.clear();
|
|
|
|
|
|
2021-03-26 05:48:38 +00:00
|
|
|
_freeIdList.resize(MAX_ENTITIES);
|
2021-01-26 07:42:56 +00:00
|
|
|
// List needs to be back to front to simplify removing
|
2021-03-26 05:48:38 +00:00
|
|
|
std::iota(std::rbegin(_freeIdList), std::rend(_freeIdList), 0);
|
2021-01-21 18:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-16 11:18:06 +00:00
|
|
|
const std::list<uint16_t>& GetEntityList(const EntityType id)
|
2021-01-21 18:36:34 +00:00
|
|
|
{
|
|
|
|
|
return gEntityLists[EnumValue(id)];
|
|
|
|
|
}
|
2015-03-25 23:57:09 +00:00
|
|
|
|
2015-12-11 09:38:37 -06:00
|
|
|
/**
|
2014-06-20 15:31:28 +01:00
|
|
|
*
|
2015-12-11 09:38:37 -06:00
|
|
|
* rct2: 0x0069EB13
|
2014-06-20 15:31:28 +01:00
|
|
|
*/
|
2016-05-09 00:08:03 +01:00
|
|
|
void reset_sprite_list()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gSavedAge = 0;
|
2020-02-18 00:00:19 +01:00
|
|
|
std::memset(static_cast<void*>(_spriteList), 0, sizeof(_spriteList));
|
2021-02-24 23:34:34 +01:00
|
|
|
for (int32_t i = 0; i < MAX_ENTITIES; ++i)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-06-06 11:32:37 +01:00
|
|
|
auto* spr = GetEntity(i);
|
2020-07-06 22:02:25 +01:00
|
|
|
if (spr == nullptr)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 08:04:41 +00:00
|
|
|
spr->Type = EntityType::Null;
|
2020-06-06 11:32:37 +01:00
|
|
|
spr->sprite_index = i;
|
2014-06-20 15:31:28 +01:00
|
|
|
|
2017-06-17 12:55:41 +02:00
|
|
|
_spriteFlashingList[i] = false;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2021-03-26 05:48:38 +00:00
|
|
|
ResetEntityLists();
|
|
|
|
|
ResetFreeIds();
|
2017-06-06 23:24:18 +02:00
|
|
|
reset_sprite_spatial_index();
|
2014-06-21 13:31:28 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-23 07:36:46 +00:00
|
|
|
static void SpriteSpatialInsert(SpriteBase* sprite, const CoordsXY& newLoc);
|
|
|
|
|
|
2015-06-08 21:35:09 +01:00
|
|
|
/**
|
2015-12-11 09:38:37 -06:00
|
|
|
*
|
|
|
|
|
* rct2: 0x0069EBE4
|
2014-06-21 13:31:28 +01:00
|
|
|
* This function looks as though it sets some sort of order for sprites.
|
2017-04-29 23:39:24 -05:00
|
|
|
* Sprites can share their position if this is the case.
|
2014-06-21 13:31:28 +01:00
|
|
|
*/
|
2016-06-03 18:13:00 +01:00
|
|
|
void reset_sprite_spatial_index()
|
2016-05-09 00:08:03 +01:00
|
|
|
{
|
2021-01-23 07:36:46 +00:00
|
|
|
for (auto& vec : gSpriteSpatialIndex)
|
|
|
|
|
{
|
|
|
|
|
vec.clear();
|
|
|
|
|
}
|
2021-02-24 23:34:34 +01:00
|
|
|
for (size_t i = 0; i < MAX_ENTITIES; i++)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-06-06 11:32:37 +01:00
|
|
|
auto* spr = GetEntity(i);
|
2021-03-17 08:04:41 +00:00
|
|
|
if (spr != nullptr && spr->Type != EntityType::Null)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2021-01-23 07:36:46 +00:00
|
|
|
SpriteSpatialInsert(spr, { spr->x, spr->y });
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-09-04 23:21:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-24 21:32:57 +02:00
|
|
|
#ifndef DISABLE_NETWORK
|
|
|
|
|
|
2021-05-09 19:12:44 +01:00
|
|
|
template<typename T> void NetworkSerialseEntityType(DataSerialiser& ds)
|
2021-03-27 09:36:41 +00:00
|
|
|
{
|
|
|
|
|
for (auto* ent : EntityList<T>())
|
|
|
|
|
{
|
2021-05-09 19:12:44 +01:00
|
|
|
ent->Serialise(ds);
|
2021-03-27 09:36:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-09 19:12:44 +01:00
|
|
|
template<typename... T> void NetworkSerialiseEntityTypes(DataSerialiser& ds)
|
2021-03-27 09:36:41 +00:00
|
|
|
{
|
2021-05-09 19:12:44 +01:00
|
|
|
(NetworkSerialseEntityType<T>(ds), ...);
|
2021-03-27 09:36:41 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-11 03:05:57 +01:00
|
|
|
rct_sprite_checksum sprite_checksum()
|
2016-07-24 21:32:57 +02:00
|
|
|
{
|
2021-05-09 19:12:44 +01:00
|
|
|
rct_sprite_checksum checksum{};
|
2018-06-01 19:17:13 +01:00
|
|
|
|
2021-05-09 19:12:44 +01:00
|
|
|
OpenRCT2::ChecksumStream ms(checksum.raw);
|
|
|
|
|
DataSerialiser ds(true, ms);
|
|
|
|
|
NetworkSerialiseEntityTypes<Guest, Staff, Vehicle, Litter>(ds);
|
2018-12-11 03:05:57 +01:00
|
|
|
|
|
|
|
|
return checksum;
|
2016-07-24 21:32:57 +02:00
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
|
2018-12-11 09:57:04 +01:00
|
|
|
rct_sprite_checksum sprite_checksum()
|
2016-07-24 21:32:57 +02:00
|
|
|
{
|
2018-12-11 09:57:04 +01:00
|
|
|
return rct_sprite_checksum{};
|
2016-07-24 21:32:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // DISABLE_NETWORK
|
|
|
|
|
|
2020-01-19 17:02:43 +00:00
|
|
|
static void sprite_reset(SpriteBase* sprite)
|
2016-07-23 13:32:58 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Need to retain how the sprite is linked in lists
|
2018-06-20 17:28:51 +02:00
|
|
|
uint16_t sprite_index = sprite->sprite_index;
|
2017-06-17 12:55:41 +02:00
|
|
|
_spriteFlashingList[sprite_index] = false;
|
2016-07-23 13:32:58 +02:00
|
|
|
|
2018-12-15 22:23:31 +01:00
|
|
|
std::memset(sprite, 0, sizeof(rct_sprite));
|
2016-07-23 13:32:58 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
sprite->sprite_index = sprite_index;
|
2021-03-17 08:04:41 +00:00
|
|
|
sprite->Type = EntityType::Null;
|
2016-07-23 13:32:58 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-05 22:55:46 +01:00
|
|
|
/**
|
2018-06-22 23:17:03 +02:00
|
|
|
* Clears all the unused sprite memory to zero. Probably so that it can be compressed better when saving.
|
|
|
|
|
* rct2: 0x0069EBA4
|
|
|
|
|
*/
|
2017-07-05 22:55:46 +01:00
|
|
|
void sprite_clear_all_unused()
|
2017-06-20 16:34:04 +02:00
|
|
|
{
|
2021-01-26 07:42:56 +00:00
|
|
|
for (auto index : _freeIdList)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2021-01-26 07:42:56 +00:00
|
|
|
auto* entity = GetEntity(index);
|
|
|
|
|
if (entity == nullptr)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
sprite_reset(entity);
|
2017-07-05 22:55:46 +01:00
|
|
|
|
2021-01-26 07:42:56 +00:00
|
|
|
_spriteFlashingList[entity->sprite_index] = false;
|
2017-06-20 16:34:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 17:10:57 +02:00
|
|
|
static constexpr uint16_t MAX_MISC_SPRITES = 300;
|
2021-03-15 08:13:00 +00:00
|
|
|
static void AddToEntityList(SpriteBase* entity)
|
2021-01-21 18:36:34 +00:00
|
|
|
{
|
2021-03-17 08:04:41 +00:00
|
|
|
auto& list = gEntityLists[EnumValue(entity->Type)];
|
2021-01-21 18:36:34 +00:00
|
|
|
// Entity list must be in sprite_index order to prevent desync issues
|
|
|
|
|
list.insert(std::lower_bound(std::begin(list), std::end(list), entity->sprite_index), entity->sprite_index);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-26 07:42:56 +00:00
|
|
|
static void AddToFreeList(uint16_t index)
|
|
|
|
|
{
|
|
|
|
|
// Free list must be in reverse sprite_index order to prevent desync issues
|
|
|
|
|
_freeIdList.insert(std::upper_bound(std::rbegin(_freeIdList), std::rend(_freeIdList), index).base(), index);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 18:36:34 +00:00
|
|
|
static void RemoveFromEntityList(SpriteBase* entity)
|
|
|
|
|
{
|
2021-03-17 08:04:41 +00:00
|
|
|
auto& list = gEntityLists[EnumValue(entity->Type)];
|
2021-01-21 18:36:34 +00:00
|
|
|
auto ptr = std::lower_bound(std::begin(list), std::end(list), entity->sprite_index);
|
|
|
|
|
if (ptr != std::end(list) && *ptr == entity->sprite_index)
|
|
|
|
|
{
|
|
|
|
|
list.erase(ptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-19 17:10:57 +02:00
|
|
|
|
2021-03-16 11:18:06 +00:00
|
|
|
uint16_t GetMiscEntityCount()
|
|
|
|
|
{
|
|
|
|
|
uint16_t count = 0;
|
|
|
|
|
for (auto id : { EntityType::SteamParticle, EntityType::MoneyEffect, EntityType::CrashedVehicleParticle,
|
|
|
|
|
EntityType::ExplosionCloud, EntityType::CrashSplash, EntityType::ExplosionFlare,
|
|
|
|
|
EntityType::JumpingFountain, EntityType::Balloon, EntityType::Duck })
|
|
|
|
|
{
|
|
|
|
|
count += GetEntityListCount(id);
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-26 05:48:38 +00:00
|
|
|
static void PrepareNewEntity(SpriteBase* base, const EntityType type)
|
|
|
|
|
{
|
|
|
|
|
// Need to reset all sprite data, as the uninitialised values
|
|
|
|
|
// may contain garbage and cause a desync later on.
|
|
|
|
|
sprite_reset(base);
|
|
|
|
|
|
|
|
|
|
base->Type = type;
|
|
|
|
|
AddToEntityList(base);
|
|
|
|
|
|
|
|
|
|
base->x = LOCATION_NULL;
|
|
|
|
|
base->y = LOCATION_NULL;
|
|
|
|
|
base->z = 0;
|
|
|
|
|
base->sprite_width = 0x10;
|
|
|
|
|
base->sprite_height_negative = 0x14;
|
|
|
|
|
base->sprite_height_positive = 0x8;
|
|
|
|
|
base->sprite_left = LOCATION_NULL;
|
|
|
|
|
|
|
|
|
|
SpriteSpatialInsert(base, { LOCATION_NULL, 0 });
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-16 11:18:06 +00:00
|
|
|
rct_sprite* create_sprite(EntityType type)
|
2014-09-04 23:21:17 +02:00
|
|
|
{
|
2021-01-26 07:42:56 +00:00
|
|
|
if (_freeIdList.size() == 0)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2019-06-19 17:10:57 +02:00
|
|
|
// No free sprites.
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 21:24:50 +00:00
|
|
|
if (EntityTypeIsMiscEntity(type))
|
2019-06-19 17:10:57 +02:00
|
|
|
{
|
|
|
|
|
// Misc sprites are commonly used for effects, if there are less than MAX_MISC_SPRITES
|
|
|
|
|
// free it will fail to keep slots for more relevant sprites.
|
|
|
|
|
// Also there can't be more than MAX_MISC_SPRITES sprites in this list.
|
2021-03-16 11:18:06 +00:00
|
|
|
uint16_t miscSlotsRemaining = MAX_MISC_SPRITES - GetMiscEntityCount();
|
2021-01-26 07:42:56 +00:00
|
|
|
if (miscSlotsRemaining >= _freeIdList.size())
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2018-01-29 17:06:01 +01:00
|
|
|
return nullptr;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-09-04 23:21:17 +02:00
|
|
|
|
2021-01-26 07:42:56 +00:00
|
|
|
auto* sprite = GetEntity(_freeIdList.back());
|
2020-07-06 22:02:25 +01:00
|
|
|
if (sprite == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2021-01-26 07:42:56 +00:00
|
|
|
_freeIdList.pop_back();
|
|
|
|
|
|
2021-03-26 05:48:38 +00:00
|
|
|
PrepareNewEntity(sprite, type);
|
2014-09-04 23:21:17 +02:00
|
|
|
|
2020-04-17 16:08:22 -03:00
|
|
|
return reinterpret_cast<rct_sprite*>(sprite);
|
2014-09-05 19:31:25 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-26 05:48:38 +00:00
|
|
|
SpriteBase* CreateEntityAt(const uint16_t index, const EntityType type)
|
|
|
|
|
{
|
|
|
|
|
auto id = std::lower_bound(std::rbegin(_freeIdList), std::rend(_freeIdList), index);
|
|
|
|
|
if (id == std::rend(_freeIdList) || *id != index)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto* entity = GetEntity(index);
|
|
|
|
|
if (entity == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_freeIdList.erase(std::next(id).base());
|
|
|
|
|
|
|
|
|
|
PrepareNewEntity(entity, type);
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
2015-06-29 17:22:01 +01:00
|
|
|
/**
|
|
|
|
|
*
|
2015-12-11 09:38:37 -06:00
|
|
|
* rct2: 0x00673200
|
2015-06-29 17:22:01 +01:00
|
|
|
*/
|
2020-07-10 14:16:03 +01:00
|
|
|
void SteamParticle::Update()
|
2015-06-29 17:22:01 +01:00
|
|
|
{
|
2017-11-22 19:08:14 +00:00
|
|
|
// Move up 1 z every 3 ticks (Starts after 4 ticks)
|
2020-12-31 18:43:48 +02:00
|
|
|
Invalidate();
|
2020-07-10 14:16:03 +01:00
|
|
|
time_to_move++;
|
|
|
|
|
if (time_to_move >= 4)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-07-10 14:16:03 +01:00
|
|
|
time_to_move = 1;
|
|
|
|
|
MoveTo({ x, y, z + 1 });
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2020-07-10 14:16:03 +01:00
|
|
|
frame += 64;
|
|
|
|
|
if (frame >= (56 * 64))
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-07-10 14:16:03 +01:00
|
|
|
sprite_remove(this);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-06-29 17:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2015-08-22 16:39:24 +01:00
|
|
|
* rct2: 0x0067363D
|
2015-06-29 17:22:01 +01:00
|
|
|
*/
|
2020-06-21 13:58:13 -03:00
|
|
|
void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos)
|
2015-06-29 17:22:01 +01:00
|
|
|
{
|
2021-03-16 11:18:06 +00:00
|
|
|
auto* sprite = CreateEntity<ExplosionCloud>();
|
2018-06-22 23:17:03 +02:00
|
|
|
if (sprite != nullptr)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
sprite->sprite_width = 44;
|
|
|
|
|
sprite->sprite_height_negative = 32;
|
|
|
|
|
sprite->sprite_height_positive = 34;
|
2020-06-21 13:58:13 -03:00
|
|
|
sprite->MoveTo(cloudPos + CoordsXYZ{ 0, 0, 4 });
|
2017-06-06 23:24:18 +02:00
|
|
|
sprite->frame = 0;
|
|
|
|
|
}
|
2015-06-29 17:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2015-12-11 09:38:37 -06:00
|
|
|
* rct2: 0x00673385
|
2015-06-29 17:22:01 +01:00
|
|
|
*/
|
2020-07-10 14:16:03 +01:00
|
|
|
void ExplosionCloud::Update()
|
2015-06-29 17:22:01 +01:00
|
|
|
{
|
2020-12-31 18:43:48 +02:00
|
|
|
Invalidate();
|
2020-07-10 14:16:03 +01:00
|
|
|
frame += 128;
|
|
|
|
|
if (frame >= (36 * 128))
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-07-10 14:16:03 +01:00
|
|
|
sprite_remove(this);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-06-29 17:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2015-08-22 16:39:24 +01:00
|
|
|
* rct2: 0x0067366B
|
2015-06-29 17:22:01 +01:00
|
|
|
*/
|
2020-06-21 14:00:37 -03:00
|
|
|
void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos)
|
2015-06-29 17:22:01 +01:00
|
|
|
{
|
2021-03-16 11:18:06 +00:00
|
|
|
MiscEntity* sprite = CreateEntity<ExplosionFlare>();
|
2018-06-22 23:17:03 +02:00
|
|
|
if (sprite != nullptr)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
sprite->sprite_width = 25;
|
|
|
|
|
sprite->sprite_height_negative = 85;
|
|
|
|
|
sprite->sprite_height_positive = 8;
|
2020-06-21 14:00:37 -03:00
|
|
|
sprite->MoveTo(flarePos + CoordsXYZ{ 0, 0, 4 });
|
2017-06-06 23:24:18 +02:00
|
|
|
sprite->frame = 0;
|
|
|
|
|
}
|
2015-06-29 17:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2015-12-11 09:38:37 -06:00
|
|
|
* rct2: 0x006733B4
|
2015-06-29 17:22:01 +01:00
|
|
|
*/
|
2020-07-10 14:16:03 +01:00
|
|
|
void ExplosionFlare::Update()
|
2015-06-29 17:22:01 +01:00
|
|
|
{
|
2020-12-31 18:43:48 +02:00
|
|
|
Invalidate();
|
2020-07-10 14:16:03 +01:00
|
|
|
frame += 64;
|
|
|
|
|
if (frame >= (124 * 64))
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-07-10 14:16:03 +01:00
|
|
|
sprite_remove(this);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-06-29 17:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-21 08:29:02 +00:00
|
|
|
template<typename T> void MiscUpdateAllType()
|
2015-03-23 10:39:47 +00:00
|
|
|
{
|
2021-03-16 11:18:06 +00:00
|
|
|
for (auto misc : EntityList<T>())
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2021-01-21 08:29:02 +00:00
|
|
|
misc->Update();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-03-23 10:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-21 08:29:02 +00:00
|
|
|
template<typename... T> void MiscUpdateAllTypes()
|
|
|
|
|
{
|
|
|
|
|
(MiscUpdateAllType<T>(), ...);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 20:31:58 +01:00
|
|
|
/**
|
|
|
|
|
*
|
2015-12-11 09:38:37 -06:00
|
|
|
* rct2: 0x00672AA4
|
2014-10-09 20:31:58 +01:00
|
|
|
*/
|
2015-03-23 10:39:47 +00:00
|
|
|
void sprite_misc_update_all()
|
2014-10-09 20:31:58 +01:00
|
|
|
{
|
2021-01-21 08:29:02 +00:00
|
|
|
MiscUpdateAllTypes<
|
|
|
|
|
SteamParticle, MoneyEffect, VehicleCrashParticle, ExplosionCloud, CrashSplashParticle, ExplosionFlare, JumpingFountain,
|
|
|
|
|
Balloon, Duck>();
|
2014-09-20 16:18:02 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-09 10:46:26 +01:00
|
|
|
// Performs a search to ensure that insert keeps next_in_quadrant in sprite_index order
|
|
|
|
|
static void SpriteSpatialInsert(SpriteBase* sprite, const CoordsXY& newLoc)
|
|
|
|
|
{
|
|
|
|
|
size_t newIndex = GetSpatialIndexOffset(newLoc.x, newLoc.y);
|
2021-01-23 07:36:46 +00:00
|
|
|
auto& spatialVector = gSpriteSpatialIndex[newIndex];
|
|
|
|
|
auto index = std::lower_bound(std::begin(spatialVector), std::end(spatialVector), sprite->sprite_index);
|
|
|
|
|
spatialVector.insert(index, sprite->sprite_index);
|
2020-04-09 10:46:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SpriteSpatialRemove(SpriteBase* sprite)
|
|
|
|
|
{
|
|
|
|
|
size_t currentIndex = GetSpatialIndexOffset(sprite->x, sprite->y);
|
2021-01-23 07:36:46 +00:00
|
|
|
auto& spatialVector = gSpriteSpatialIndex[currentIndex];
|
|
|
|
|
auto index = std::lower_bound(std::begin(spatialVector), std::end(spatialVector), sprite->sprite_index);
|
|
|
|
|
if (index != std::end(spatialVector) && *index == sprite->sprite_index)
|
|
|
|
|
{
|
|
|
|
|
spatialVector.erase(index, index + 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-04-09 10:46:26 +01:00
|
|
|
{
|
|
|
|
|
log_warning("Bad sprite spatial index. Rebuilding the spatial index...");
|
|
|
|
|
reset_sprite_spatial_index();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SpriteSpatialMove(SpriteBase* sprite, const CoordsXY& newLoc)
|
|
|
|
|
{
|
|
|
|
|
size_t newIndex = GetSpatialIndexOffset(newLoc.x, newLoc.y);
|
|
|
|
|
size_t currentIndex = GetSpatialIndexOffset(sprite->x, sprite->y);
|
|
|
|
|
if (newIndex == currentIndex)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
SpriteSpatialRemove(sprite);
|
|
|
|
|
SpriteSpatialInsert(sprite, newLoc);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 12:36:45 +02:00
|
|
|
void SpriteBase::MoveTo(const CoordsXYZ& newLocation)
|
2017-01-28 22:12:07 +01:00
|
|
|
{
|
2020-12-31 18:43:48 +02:00
|
|
|
if (x != LOCATION_NULL)
|
|
|
|
|
{
|
|
|
|
|
// Invalidate old position.
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 12:36:45 +02:00
|
|
|
auto loc = newLocation;
|
|
|
|
|
if (!map_is_location_valid(loc))
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-05-11 12:36:45 +02:00
|
|
|
loc.x = LOCATION_NULL;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-09-20 16:18:02 +01:00
|
|
|
|
2020-05-11 12:36:45 +02:00
|
|
|
SpriteSpatialMove(this, loc);
|
2014-09-20 16:18:02 +01:00
|
|
|
|
2020-05-11 12:36:45 +02:00
|
|
|
if (loc.x == LOCATION_NULL)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-05-11 12:36:45 +02:00
|
|
|
sprite_left = LOCATION_NULL;
|
|
|
|
|
x = loc.x;
|
|
|
|
|
y = loc.y;
|
|
|
|
|
z = loc.z;
|
2018-06-22 23:17:03 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-06-21 13:50:54 -03:00
|
|
|
sprite_set_coordinates(loc, this);
|
2020-12-31 18:43:48 +02:00
|
|
|
Invalidate(); // Invalidate new position.
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-08-06 10:21:08 -06:00
|
|
|
}
|
|
|
|
|
|
2021-02-10 19:23:45 +02:00
|
|
|
CoordsXYZ SpriteBase::GetLocation() const
|
|
|
|
|
{
|
|
|
|
|
return { x, y, z };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpriteBase::SetLocation(const CoordsXYZ& newLocation)
|
|
|
|
|
{
|
|
|
|
|
x = static_cast<int16_t>(newLocation.x);
|
|
|
|
|
y = static_cast<int16_t>(newLocation.y);
|
|
|
|
|
z = static_cast<int16_t>(newLocation.z);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 13:50:54 -03:00
|
|
|
void sprite_set_coordinates(const CoordsXYZ& spritePos, SpriteBase* sprite)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-06-21 13:50:54 -03:00
|
|
|
auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), spritePos);
|
2014-09-20 16:18:02 +01:00
|
|
|
|
2020-01-19 16:22:17 +00:00
|
|
|
sprite->sprite_left = screenCoords.x - sprite->sprite_width;
|
|
|
|
|
sprite->sprite_right = screenCoords.x + sprite->sprite_width;
|
|
|
|
|
sprite->sprite_top = screenCoords.y - sprite->sprite_height_negative;
|
|
|
|
|
sprite->sprite_bottom = screenCoords.y + sprite->sprite_height_positive;
|
2020-06-21 13:50:54 -03:00
|
|
|
sprite->x = spritePos.x;
|
|
|
|
|
sprite->y = spritePos.y;
|
|
|
|
|
sprite->z = spritePos.z;
|
2014-11-10 00:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-10 01:44:30 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x0069EDB6
|
|
|
|
|
*/
|
2020-01-19 16:12:29 +00:00
|
|
|
void sprite_remove(SpriteBase* sprite)
|
2014-12-10 01:44:30 +00:00
|
|
|
{
|
2020-06-06 10:55:01 +01:00
|
|
|
auto peep = sprite->As<Peep>();
|
2019-02-20 20:03:48 +00:00
|
|
|
if (peep != nullptr)
|
|
|
|
|
{
|
2019-07-21 20:44:19 +01:00
|
|
|
peep->SetName({});
|
2019-02-20 20:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-05 01:35:18 +02:00
|
|
|
EntityTweener::Get().RemoveEntity(sprite);
|
2021-01-21 18:36:34 +00:00
|
|
|
RemoveFromEntityList(sprite); // remove from existing list
|
2021-01-26 07:42:56 +00:00
|
|
|
AddToFreeList(sprite->sprite_index);
|
2021-01-05 01:35:18 +02:00
|
|
|
|
2020-08-01 11:29:54 +01:00
|
|
|
SpriteSpatialRemove(sprite);
|
2021-01-16 15:48:39 +00:00
|
|
|
sprite_reset(sprite);
|
2015-06-28 17:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-21 14:14:44 -03:00
|
|
|
static bool litter_can_be_at(const CoordsXYZ& mapPos)
|
2015-06-28 17:45:19 +01:00
|
|
|
{
|
2018-11-01 13:53:50 +01:00
|
|
|
TileElement* tileElement;
|
2015-06-28 17:45:19 +01:00
|
|
|
|
2020-06-21 14:14:44 -03:00
|
|
|
if (!map_is_location_owned(mapPos))
|
2017-06-06 23:24:18 +02:00
|
|
|
return false;
|
2015-06-28 17:45:19 +01:00
|
|
|
|
2020-06-21 14:14:44 -03:00
|
|
|
tileElement = map_get_first_element_at(mapPos);
|
2019-10-09 11:02:21 -03:00
|
|
|
if (tileElement == nullptr)
|
|
|
|
|
return false;
|
2018-06-22 23:17:03 +02:00
|
|
|
do
|
|
|
|
|
{
|
2018-05-02 19:27:04 +02:00
|
|
|
if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH)
|
2017-06-06 23:24:18 +02:00
|
|
|
continue;
|
2015-06-28 17:45:19 +01:00
|
|
|
|
2019-12-22 22:14:02 +01:00
|
|
|
int32_t pathZ = tileElement->GetBaseZ();
|
2020-06-21 14:14:44 -03:00
|
|
|
if (pathZ < mapPos.z || pathZ >= mapPos.z + 32)
|
2017-06-06 23:24:18 +02:00
|
|
|
continue;
|
2015-06-28 17:45:19 +01:00
|
|
|
|
2019-05-10 22:00:38 +02:00
|
|
|
return !tile_element_is_underground(tileElement);
|
2018-05-24 11:44:53 +02:00
|
|
|
} while (!(tileElement++)->IsLastForTile());
|
2017-06-06 23:24:18 +02:00
|
|
|
return false;
|
2015-06-28 17:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x0067375D
|
|
|
|
|
*/
|
2021-05-13 08:09:48 +01:00
|
|
|
void Litter::Create(const CoordsXYZD& litterPos, Type type)
|
2015-06-28 17:45:19 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
if (gCheatsDisableLittering)
|
|
|
|
|
return;
|
2015-06-28 17:45:19 +01:00
|
|
|
|
2020-06-21 14:13:22 -03:00
|
|
|
auto offsetLitterPos = litterPos
|
|
|
|
|
+ CoordsXY{ CoordsDirectionDelta[litterPos.direction >> 3].x / 8,
|
|
|
|
|
CoordsDirectionDelta[litterPos.direction >> 3].y / 8 };
|
2015-06-28 17:45:19 +01:00
|
|
|
|
2020-06-21 14:14:44 -03:00
|
|
|
if (!litter_can_be_at(offsetLitterPos))
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
2015-06-28 17:45:19 +01:00
|
|
|
|
2021-03-16 11:18:06 +00:00
|
|
|
if (GetEntityListCount(EntityType::Litter) >= 500)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-01-19 15:50:01 +00:00
|
|
|
Litter* newestLitter = nullptr;
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t newestLitterCreationTick = 0;
|
2021-03-16 11:18:06 +00:00
|
|
|
for (auto litter : EntityList<Litter>())
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
|
|
|
|
if (newestLitterCreationTick <= litter->creationTick)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
newestLitterCreationTick = litter->creationTick;
|
|
|
|
|
newestLitter = litter;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-28 17:45:19 +01:00
|
|
|
|
2018-06-22 23:17:03 +02:00
|
|
|
if (newestLitter != nullptr)
|
|
|
|
|
{
|
2020-12-31 18:43:48 +02:00
|
|
|
newestLitter->Invalidate();
|
2020-01-19 16:12:29 +00:00
|
|
|
sprite_remove(newestLitter);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-06-28 17:45:19 +01:00
|
|
|
|
2021-03-16 11:18:06 +00:00
|
|
|
Litter* litter = CreateEntity<Litter>();
|
2018-01-29 17:06:01 +01:00
|
|
|
if (litter == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
2015-06-28 17:45:19 +01:00
|
|
|
|
2020-06-21 14:13:22 -03:00
|
|
|
litter->sprite_direction = offsetLitterPos.direction;
|
2017-06-06 23:24:18 +02:00
|
|
|
litter->sprite_width = 6;
|
|
|
|
|
litter->sprite_height_negative = 6;
|
|
|
|
|
litter->sprite_height_positive = 3;
|
2021-01-10 15:14:34 +00:00
|
|
|
litter->SubType = type;
|
2020-06-21 14:13:22 -03:00
|
|
|
litter->MoveTo(offsetLitterPos);
|
2017-06-06 23:24:18 +02:00
|
|
|
litter->creationTick = gScenarioTicks;
|
2015-06-29 17:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-02 18:22:38 +01:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006738E1
|
|
|
|
|
*/
|
2021-05-13 08:09:48 +01:00
|
|
|
void Litter::RemoveAt(const CoordsXYZ& litterPos)
|
2015-07-02 18:22:38 +01:00
|
|
|
{
|
2021-01-23 07:36:46 +00:00
|
|
|
std::vector<Litter*> removals;
|
2020-06-21 14:06:56 -03:00
|
|
|
for (auto litter : EntityTileList<Litter>(litterPos))
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-06-21 14:06:56 -03:00
|
|
|
if (abs(litter->z - litterPos.z) <= 16)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2020-06-21 14:06:56 -03:00
|
|
|
if (abs(litter->x - litterPos.x) <= 8 && abs(litter->y - litterPos.y) <= 8)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2021-01-23 07:36:46 +00:00
|
|
|
removals.push_back(litter);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-23 07:36:46 +00:00
|
|
|
for (auto* litter : removals)
|
|
|
|
|
{
|
|
|
|
|
litter->Invalidate();
|
|
|
|
|
sprite_remove(litter);
|
|
|
|
|
}
|
2015-07-02 18:22:38 +01:00
|
|
|
}
|
2016-12-11 00:08:37 +00:00
|
|
|
|
2021-05-13 16:23:04 +02:00
|
|
|
static const rct_string_id litterNames[12] = {
|
|
|
|
|
STR_LITTER_VOMIT,
|
|
|
|
|
STR_LITTER_VOMIT,
|
|
|
|
|
STR_SHOP_ITEM_SINGULAR_EMPTY_CAN,
|
|
|
|
|
STR_SHOP_ITEM_SINGULAR_RUBBISH,
|
|
|
|
|
STR_SHOP_ITEM_SINGULAR_EMPTY_BURGER_BOX,
|
|
|
|
|
STR_SHOP_ITEM_SINGULAR_EMPTY_CUP,
|
|
|
|
|
STR_SHOP_ITEM_SINGULAR_EMPTY_BOX,
|
|
|
|
|
STR_SHOP_ITEM_SINGULAR_EMPTY_BOTTLE,
|
|
|
|
|
STR_SHOP_ITEM_SINGULAR_EMPTY_BOWL_RED,
|
|
|
|
|
STR_SHOP_ITEM_SINGULAR_EMPTY_DRINK_CARTON,
|
|
|
|
|
STR_SHOP_ITEM_SINGULAR_EMPTY_JUICE_CUP,
|
|
|
|
|
STR_SHOP_ITEM_SINGULAR_EMPTY_BOWL_BLUE,
|
|
|
|
|
};
|
2021-05-13 08:09:48 +01:00
|
|
|
|
|
|
|
|
rct_string_id Litter::GetName() const
|
|
|
|
|
{
|
|
|
|
|
if (EnumValue(SubType) >= sizeof(litterNames))
|
|
|
|
|
return STR_NONE;
|
|
|
|
|
return litterNames[EnumValue(SubType)];
|
|
|
|
|
}
|
2020-03-16 09:48:26 +01:00
|
|
|
/**
|
|
|
|
|
* 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;
|
2021-03-16 11:18:06 +00:00
|
|
|
for (auto* balloon : EntityList<Balloon>())
|
2020-03-16 09:48:26 +01:00
|
|
|
{
|
2021-01-22 14:36:55 +00:00
|
|
|
sprite_remove(balloon);
|
|
|
|
|
removed++;
|
|
|
|
|
}
|
2021-03-16 11:18:06 +00:00
|
|
|
for (auto* duck : EntityList<Duck>())
|
2021-01-22 14:36:55 +00:00
|
|
|
{
|
|
|
|
|
if (duck->IsFlying())
|
2020-03-16 09:48:26 +01:00
|
|
|
{
|
2021-01-22 14:36:55 +00:00
|
|
|
sprite_remove(duck);
|
2020-03-16 09:48:26 +01:00
|
|
|
removed++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-16 11:18:06 +00:00
|
|
|
for (auto* money : EntityList<MoneyEffect>())
|
2021-01-22 14:36:55 +00:00
|
|
|
{
|
|
|
|
|
sprite_remove(money);
|
|
|
|
|
removed++;
|
|
|
|
|
}
|
2020-03-16 09:48:26 +01:00
|
|
|
return removed;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-16 11:18:06 +00:00
|
|
|
void EntityTweener::PopulateEntities()
|
2016-12-11 00:08:37 +00:00
|
|
|
{
|
2021-03-16 11:18:06 +00:00
|
|
|
for (auto ent : EntityList<Guest>())
|
|
|
|
|
{
|
|
|
|
|
Entities.push_back(ent);
|
|
|
|
|
PrePos.emplace_back(ent->x, ent->y, ent->z);
|
|
|
|
|
}
|
|
|
|
|
for (auto ent : EntityList<Staff>())
|
|
|
|
|
{
|
|
|
|
|
Entities.push_back(ent);
|
|
|
|
|
PrePos.emplace_back(ent->x, ent->y, ent->z);
|
|
|
|
|
}
|
|
|
|
|
for (auto ent : EntityList<Vehicle>())
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2021-01-09 05:59:55 +09:00
|
|
|
Entities.push_back(ent);
|
2021-01-05 19:05:47 +02:00
|
|
|
PrePos.emplace_back(ent->x, ent->y, ent->z);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-12-11 00:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-04 23:31:41 +02:00
|
|
|
void EntityTweener::PreTick()
|
2016-12-11 00:08:37 +00:00
|
|
|
{
|
2021-01-04 23:31:41 +02:00
|
|
|
Restore();
|
|
|
|
|
Reset();
|
2021-03-16 11:18:06 +00:00
|
|
|
PopulateEntities();
|
2016-12-11 00:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-04 23:31:41 +02:00
|
|
|
void EntityTweener::PostTick()
|
2016-12-11 00:08:37 +00:00
|
|
|
{
|
2021-01-05 19:05:47 +02:00
|
|
|
for (auto* ent : Entities)
|
2021-01-04 23:31:41 +02:00
|
|
|
{
|
2021-01-05 01:35:18 +02:00
|
|
|
if (ent == nullptr)
|
2021-01-04 23:31:41 +02:00
|
|
|
{
|
|
|
|
|
// Sprite was removed, add a dummy position to keep the index aligned.
|
2021-01-05 19:05:47 +02:00
|
|
|
PostPos.emplace_back(0, 0, 0);
|
2021-01-04 23:31:41 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-01-05 19:05:47 +02:00
|
|
|
PostPos.emplace_back(ent->x, ent->y, ent->z);
|
2021-01-04 23:31:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-12-11 00:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-05 01:35:18 +02:00
|
|
|
void EntityTweener::RemoveEntity(SpriteBase* entity)
|
|
|
|
|
{
|
2021-03-17 08:04:41 +00:00
|
|
|
if (!entity->Is<Peep>() && !entity->Is<Vehicle>())
|
2021-01-05 01:35:18 +02:00
|
|
|
{
|
|
|
|
|
// Only peeps and vehicles are tweened, bail if type is incorrect.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 19:05:47 +02:00
|
|
|
auto it = std::find(Entities.begin(), Entities.end(), entity);
|
|
|
|
|
if (it != Entities.end())
|
2021-01-05 01:35:18 +02:00
|
|
|
*it = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-04 23:31:41 +02:00
|
|
|
void EntityTweener::Tween(float alpha)
|
2016-12-11 00:08:37 +00:00
|
|
|
{
|
2017-07-10 21:43:20 +02:00
|
|
|
const float inv = (1.0f - alpha);
|
2021-01-05 19:05:47 +02:00
|
|
|
for (size_t i = 0; i < Entities.size(); ++i)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2021-01-05 19:05:47 +02:00
|
|
|
auto* ent = Entities[i];
|
2021-01-05 01:35:18 +02:00
|
|
|
if (ent == nullptr)
|
2020-07-06 22:02:25 +01:00
|
|
|
continue;
|
|
|
|
|
|
2021-01-05 19:05:47 +02:00
|
|
|
auto& posA = PrePos[i];
|
|
|
|
|
auto& posB = PostPos[i];
|
2021-01-04 23:31:41 +02:00
|
|
|
|
|
|
|
|
if (posA == posB)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
sprite_set_coordinates(
|
|
|
|
|
{ static_cast<int32_t>(std::round(posB.x * alpha + posA.x * inv)),
|
|
|
|
|
static_cast<int32_t>(std::round(posB.y * alpha + posA.y * inv)),
|
|
|
|
|
static_cast<int32_t>(std::round(posB.z * alpha + posA.z * inv)) },
|
|
|
|
|
ent);
|
|
|
|
|
ent->Invalidate();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-12-11 00:08:37 +00:00
|
|
|
}
|
2017-06-17 12:55:41 +02:00
|
|
|
|
2021-01-04 23:31:41 +02:00
|
|
|
void EntityTweener::Restore()
|
|
|
|
|
{
|
2021-01-05 19:05:47 +02:00
|
|
|
for (size_t i = 0; i < Entities.size(); ++i)
|
2021-01-04 23:31:41 +02:00
|
|
|
{
|
2021-01-05 19:05:47 +02:00
|
|
|
auto* ent = Entities[i];
|
2021-01-05 01:35:18 +02:00
|
|
|
if (ent == nullptr)
|
2021-01-04 23:31:41 +02:00
|
|
|
continue;
|
|
|
|
|
|
2021-01-05 19:05:47 +02:00
|
|
|
sprite_set_coordinates(PostPos[i], ent);
|
2021-01-04 23:31:41 +02:00
|
|
|
ent->Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EntityTweener::Reset()
|
|
|
|
|
{
|
2021-01-05 19:05:47 +02:00
|
|
|
Entities.clear();
|
|
|
|
|
PrePos.clear();
|
|
|
|
|
PostPos.clear();
|
2021-01-04 23:31:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static EntityTweener tweener;
|
|
|
|
|
|
|
|
|
|
EntityTweener& EntityTweener::Get()
|
|
|
|
|
{
|
|
|
|
|
return tweener;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-19 17:02:43 +00:00
|
|
|
void sprite_set_flashing(SpriteBase* sprite, bool flashing)
|
2017-06-17 12:55:41 +02:00
|
|
|
{
|
2021-02-24 23:34:34 +01:00
|
|
|
assert(sprite->sprite_index < MAX_ENTITIES);
|
2020-01-19 17:02:43 +00:00
|
|
|
_spriteFlashingList[sprite->sprite_index] = flashing;
|
2017-06-17 12:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-19 17:02:43 +00:00
|
|
|
bool sprite_get_flashing(SpriteBase* sprite)
|
2017-06-17 12:55:41 +02:00
|
|
|
{
|
2021-02-24 23:34:34 +01:00
|
|
|
assert(sprite->sprite_index < MAX_ENTITIES);
|
2020-01-19 17:02:43 +00:00
|
|
|
return _spriteFlashingList[sprite->sprite_index];
|
2017-06-17 12:55:41 +02:00
|
|
|
}
|