Files
OpenRCT2-Web/src/openrct2/world/Particle.cpp
T

150 lines
4.2 KiB
C++
Raw Normal View History

/*****************************************************************************
2020-07-21 15:04:34 +02:00
* Copyright (c) 2014-2020 OpenRCT2 developers
*
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
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2015-08-22 16:39:24 +01:00
#include "../audio/audio.h"
#include "../paint/sprite/Paint.Sprite.h"
2018-06-22 23:17:03 +02:00
#include "../scenario/Scenario.h"
2018-01-11 10:59:26 +01:00
#include "Sprite.h"
2015-08-22 16:39:24 +01:00
2018-11-21 23:16:04 +01:00
#include <iterator>
template<> bool SpriteBase::Is<VehicleCrashParticle>() const
{
2020-12-31 17:25:00 +02:00
return sprite_identifier == SpriteIdentifier::Misc
&& static_cast<MiscEntityType>(type) == MiscEntityType::CrashedVehicleParticle;
}
template<> bool SpriteBase::Is<CrashSplashParticle>() const
{
return sprite_identifier == SpriteIdentifier::Misc && static_cast<MiscEntityType>(type) == MiscEntityType::CrashSplash;
}
2015-08-22 16:39:24 +01:00
/**
*
* rct2: 0x006735A1
*/
void crashed_vehicle_particle_create(rct_vehicle_colour colours, const CoordsXYZ& vehiclePos)
2015-08-22 16:39:24 +01:00
{
VehicleCrashParticle* sprite = &create_sprite(SpriteIdentifier::Misc)->crashed_vehicle_particle;
2017-11-20 11:37:55 +01:00
if (sprite != nullptr)
{
2017-06-06 23:24:18 +02:00
sprite->colour[0] = colours.body_colour;
sprite->colour[1] = colours.trim_colour;
2018-06-22 23:17:03 +02:00
sprite->sprite_width = 8;
2017-06-06 23:24:18 +02:00
sprite->sprite_height_negative = 8;
sprite->sprite_height_positive = 8;
sprite->sprite_identifier = SpriteIdentifier::Misc;
sprite->MoveTo(vehiclePos);
sprite->type = EnumValue(MiscEntityType::CrashedVehicleParticle);
2015-08-22 16:39:24 +01:00
2018-06-22 23:17:03 +02:00
sprite->frame = (scenario_rand() & 0xFF) * 12;
sprite->time_to_live = (scenario_rand() & 0x7F) + 140;
2020-04-17 16:08:22 -03:00
sprite->crashed_sprite_base = scenario_rand_max(static_cast<uint32_t>(std::size(vehicle_particle_base_sprites)));
sprite->acceleration_x = (static_cast<int16_t>(scenario_rand() & 0xFFFF)) * 4;
sprite->acceleration_y = (static_cast<int16_t>(scenario_rand() & 0xFFFF)) * 4;
2017-06-06 23:24:18 +02:00
sprite->acceleration_z = (scenario_rand() & 0xFFFF) * 4 + 0x10000;
2018-06-22 23:17:03 +02:00
sprite->velocity_x = 0;
sprite->velocity_y = 0;
sprite->velocity_z = 0;
2017-06-06 23:24:18 +02:00
}
2015-08-22 16:39:24 +01:00
}
/**
*
2015-12-11 09:38:37 -06:00
* rct2: 0x00673298
2015-08-22 16:39:24 +01:00
*/
2020-07-10 14:16:03 +01:00
void VehicleCrashParticle::Update()
2015-08-22 16:39:24 +01:00
{
2020-07-10 14:16:03 +01:00
Invalidate0();
time_to_live--;
if (time_to_live == 0)
2017-11-20 11:37:55 +01:00
{
2020-07-10 14:16:03 +01:00
sprite_remove(this);
2017-06-06 23:24:18 +02:00
return;
}
2015-08-22 16:39:24 +01:00
2017-06-06 23:24:18 +02:00
// Apply gravity
2020-07-10 14:16:03 +01:00
acceleration_z -= 5041;
2015-08-22 16:39:24 +01:00
2017-06-06 23:24:18 +02:00
// Apply air resistance
2020-07-10 14:16:03 +01:00
acceleration_x -= (acceleration_x / 256);
acceleration_y -= (acceleration_y / 256);
acceleration_z -= (acceleration_z / 256);
2015-08-22 16:39:24 +01:00
2017-06-06 23:24:18 +02:00
// Update velocity and position
2020-07-10 14:16:03 +01:00
int32_t vx = velocity_x + acceleration_x;
int32_t vy = velocity_y + acceleration_y;
int32_t vz = velocity_z + acceleration_z;
2015-08-22 16:39:24 +01:00
2020-07-10 14:16:03 +01:00
CoordsXYZ newLoc = { x + (vx >> 16), y + (vy >> 16), z + (vz >> 16) };
2015-08-22 16:39:24 +01:00
2020-07-10 14:16:03 +01:00
velocity_x = vx & 0xFFFF;
velocity_y = vy & 0xFFFF;
velocity_z = vz & 0xFFFF;
2015-08-22 16:39:24 +01:00
2017-06-06 23:24:18 +02:00
// Check collision with land / water
2020-07-10 14:16:03 +01:00
int16_t landZ = tile_element_height(newLoc);
int16_t waterZ = tile_element_water_height(newLoc);
2015-08-22 16:39:24 +01:00
2020-07-10 14:16:03 +01:00
if (waterZ != 0 && z >= waterZ && newLoc.z <= waterZ)
2017-11-20 11:37:55 +01:00
{
2017-06-06 23:24:18 +02:00
// Splash
2020-10-07 00:34:42 +03:00
OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::Water2, { x, y, waterZ });
2020-07-10 14:16:03 +01:00
crash_splash_create({ x, y, waterZ });
sprite_remove(this);
2017-06-06 23:24:18 +02:00
return;
}
2015-08-22 16:39:24 +01:00
2020-07-10 14:16:03 +01:00
if (z >= landZ && newLoc.z <= landZ)
2017-11-20 11:37:55 +01:00
{
2017-06-06 23:24:18 +02:00
// Bounce
2020-07-10 14:16:03 +01:00
acceleration_z *= -1;
newLoc.z = landZ;
2017-06-06 23:24:18 +02:00
}
2020-07-10 14:16:03 +01:00
MoveTo(newLoc);
Invalidate0();
2015-08-22 16:39:24 +01:00
2020-07-10 14:16:03 +01:00
frame += 85;
if (frame >= 3072)
2017-11-20 11:37:55 +01:00
{
2020-07-10 14:16:03 +01:00
frame = 0;
2017-06-06 23:24:18 +02:00
}
2015-08-22 16:39:24 +01:00
}
/**
*
* rct2: 0x00673699
*/
2020-06-21 13:41:11 -03:00
void crash_splash_create(const CoordsXYZ& splashPos)
2015-08-22 16:39:24 +01:00
{
SpriteGeneric* sprite = &create_sprite(SpriteIdentifier::Misc)->generic;
2017-11-20 11:37:55 +01:00
if (sprite != nullptr)
{
2018-06-22 23:17:03 +02:00
sprite->sprite_width = 33;
2017-06-06 23:24:18 +02:00
sprite->sprite_height_negative = 51;
sprite->sprite_height_positive = 16;
sprite->sprite_identifier = SpriteIdentifier::Misc;
2020-06-21 13:41:11 -03:00
sprite->MoveTo(splashPos + CoordsXYZ{ 0, 0, 3 });
sprite->type = EnumValue(MiscEntityType::CrashSplash);
2018-06-22 23:17:03 +02:00
sprite->frame = 0;
2017-06-06 23:24:18 +02:00
}
2015-08-22 16:39:24 +01:00
}
/**
*
2015-12-11 09:38:37 -06:00
* rct2: 0x0067339D
2015-08-22 16:39:24 +01:00
*/
2020-07-10 14:16:03 +01:00
void CrashSplashParticle::Update()
2015-08-22 16:39:24 +01:00
{
2020-07-10 14:16:03 +01:00
Invalidate2();
frame += 85;
if (frame >= 7168)
2017-11-20 11:37:55 +01:00
{
2020-07-10 14:16:03 +01:00
sprite_remove(this);
2017-06-06 23:24:18 +02:00
}
2015-08-22 16:39:24 +01:00
}