2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file effectvehicle.cpp Implementation of everything generic to vehicles. */
|
2008-04-20 11:12:07 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "landscape.h"
|
2009-10-04 17:16:41 +00:00
|
|
|
#include "core/random_func.hpp"
|
|
|
|
#include "industry_map.h"
|
2008-04-20 11:12:07 +00:00
|
|
|
#include "vehicle_func.h"
|
|
|
|
#include "sound_func.h"
|
|
|
|
#include "animated_tile_func.h"
|
|
|
|
#include "effectvehicle_func.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "effectvehicle_base.h"
|
2008-04-20 11:12:07 +00:00
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2008-04-20 11:12:07 +00:00
|
|
|
|
2016-10-16 14:56:52 +00:00
|
|
|
/**
|
|
|
|
* Increment the sprite unless it has reached the end of the animation.
|
|
|
|
* @param v Vehicle to increment sprite of.
|
|
|
|
* @param last Last sprite of animation.
|
|
|
|
* @return true if the sprite was incremented, false if the end was reached.
|
|
|
|
*/
|
|
|
|
static bool IncrementSprite(EffectVehicle *v, SpriteID last)
|
|
|
|
{
|
2021-01-03 13:32:58 +00:00
|
|
|
if (v->sprite_cache.sprite_seq.seq[0].sprite != last) {
|
|
|
|
v->sprite_cache.sprite_seq.seq[0].sprite++;
|
2016-10-16 14:56:52 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static void ChimneySmokeInit(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2023-05-08 17:01:06 +00:00
|
|
|
uint32_t r = Random();
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_CHIMNEY_SMOKE_0 + GB(r, 0, 3));
|
2008-04-20 11:12:07 +00:00
|
|
|
v->progress = GB(r, 16, 3);
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static bool ChimneySmokeTick(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
if (v->progress > 0) {
|
|
|
|
v->progress--;
|
|
|
|
} else {
|
|
|
|
TileIndex tile = TileVirtXY(v->x_pos, v->y_pos);
|
|
|
|
if (!IsTileType(tile, MP_INDUSTRY)) {
|
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-16 14:56:52 +00:00
|
|
|
if (!IncrementSprite(v, SPR_CHIMNEY_SMOKE_7)) {
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_CHIMNEY_SMOKE_0);
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
v->progress = 7;
|
2014-09-20 15:31:26 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static void SteamSmokeInit(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_STEAM_SMOKE_0);
|
2008-04-20 11:12:07 +00:00
|
|
|
v->progress = 12;
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static bool SteamSmokeTick(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
bool moved = false;
|
|
|
|
|
|
|
|
v->progress++;
|
|
|
|
|
|
|
|
if ((v->progress & 7) == 0) {
|
|
|
|
v->z_pos++;
|
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((v->progress & 0xF) == 4) {
|
2016-10-16 14:56:52 +00:00
|
|
|
if (!IncrementSprite(v, SPR_STEAM_SMOKE_4)) {
|
2008-04-20 11:12:07 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
|
2014-09-20 15:31:26 +00:00
|
|
|
if (moved) v->UpdatePositionAndViewport();
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static void DieselSmokeInit(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_DIESEL_SMOKE_0);
|
2008-04-20 11:12:07 +00:00
|
|
|
v->progress = 0;
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static bool DieselSmokeTick(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
v->progress++;
|
|
|
|
|
|
|
|
if ((v->progress & 3) == 0) {
|
|
|
|
v->z_pos++;
|
2014-09-20 15:31:26 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2008-04-20 11:12:07 +00:00
|
|
|
} else if ((v->progress & 7) == 1) {
|
2016-10-16 14:56:52 +00:00
|
|
|
if (!IncrementSprite(v, SPR_DIESEL_SMOKE_5)) {
|
2008-04-20 11:12:07 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2016-10-16 14:56:52 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static void ElectricSparkInit(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_ELECTRIC_SPARK_0);
|
2008-04-20 11:12:07 +00:00
|
|
|
v->progress = 1;
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static bool ElectricSparkTick(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
if (v->progress < 2) {
|
|
|
|
v->progress++;
|
|
|
|
} else {
|
|
|
|
v->progress = 0;
|
2016-10-16 14:56:52 +00:00
|
|
|
|
|
|
|
if (!IncrementSprite(v, SPR_ELECTRIC_SPARK_5)) {
|
2008-04-20 11:12:07 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2016-10-16 14:56:52 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static void SmokeInit(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_SMOKE_0);
|
2008-04-20 11:12:07 +00:00
|
|
|
v->progress = 12;
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static bool SmokeTick(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
bool moved = false;
|
|
|
|
|
|
|
|
v->progress++;
|
|
|
|
|
|
|
|
if ((v->progress & 3) == 0) {
|
|
|
|
v->z_pos++;
|
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((v->progress & 0xF) == 4) {
|
2016-10-16 14:56:52 +00:00
|
|
|
if (!IncrementSprite(v, SPR_SMOKE_4)) {
|
2008-04-20 11:12:07 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
|
2014-09-20 15:31:26 +00:00
|
|
|
if (moved) v->UpdatePositionAndViewport();
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static void ExplosionLargeInit(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_EXPLOSION_LARGE_0);
|
2008-04-20 11:12:07 +00:00
|
|
|
v->progress = 0;
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static bool ExplosionLargeTick(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
v->progress++;
|
|
|
|
if ((v->progress & 3) == 0) {
|
2016-10-16 14:56:52 +00:00
|
|
|
if (!IncrementSprite(v, SPR_EXPLOSION_LARGE_F)) {
|
2008-04-20 11:12:07 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2016-10-16 14:56:52 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static void BreakdownSmokeInit(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_BREAKDOWN_SMOKE_0);
|
2008-04-20 11:12:07 +00:00
|
|
|
v->progress = 0;
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static bool BreakdownSmokeTick(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
v->progress++;
|
|
|
|
if ((v->progress & 7) == 0) {
|
2016-10-16 14:56:52 +00:00
|
|
|
if (!IncrementSprite(v, SPR_BREAKDOWN_SMOKE_3)) {
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_BREAKDOWN_SMOKE_0);
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2014-09-20 15:31:26 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
v->animation_state--;
|
|
|
|
if (v->animation_state == 0) {
|
2008-04-20 11:12:07 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static void ExplosionSmallInit(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_EXPLOSION_SMALL_0);
|
2008-04-20 11:12:07 +00:00
|
|
|
v->progress = 0;
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static bool ExplosionSmallTick(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
v->progress++;
|
|
|
|
if ((v->progress & 3) == 0) {
|
2016-10-16 14:56:52 +00:00
|
|
|
if (!IncrementSprite(v, SPR_EXPLOSION_SMALL_B)) {
|
2008-04-20 11:12:07 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2016-10-16 14:56:52 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static void BulldozerInit(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_BULLDOZER_NE);
|
2008-04-20 11:12:07 +00:00
|
|
|
v->progress = 0;
|
2009-05-22 18:56:25 +00:00
|
|
|
v->animation_state = 0;
|
|
|
|
v->animation_substate = 0;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct BulldozerMovement {
|
|
|
|
byte direction:2;
|
|
|
|
byte image:2;
|
|
|
|
byte duration:3;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const BulldozerMovement _bulldozer_movement[] = {
|
|
|
|
{ 0, 0, 4 },
|
|
|
|
{ 3, 3, 4 },
|
|
|
|
{ 2, 2, 7 },
|
|
|
|
{ 0, 2, 7 },
|
|
|
|
{ 1, 1, 3 },
|
|
|
|
{ 2, 2, 7 },
|
|
|
|
{ 0, 2, 7 },
|
|
|
|
{ 1, 1, 3 },
|
|
|
|
{ 2, 2, 7 },
|
|
|
|
{ 0, 2, 7 },
|
|
|
|
{ 3, 3, 6 },
|
|
|
|
{ 2, 2, 6 },
|
|
|
|
{ 1, 1, 7 },
|
|
|
|
{ 3, 1, 7 },
|
|
|
|
{ 0, 0, 3 },
|
|
|
|
{ 1, 1, 7 },
|
|
|
|
{ 3, 1, 7 },
|
|
|
|
{ 0, 0, 3 },
|
|
|
|
{ 1, 1, 7 },
|
|
|
|
{ 3, 1, 7 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
2023-05-08 17:01:06 +00:00
|
|
|
int8_t x;
|
|
|
|
int8_t y;
|
2008-04-20 11:12:07 +00:00
|
|
|
} _inc_by_dir[] = {
|
|
|
|
{ -1, 0 },
|
|
|
|
{ 0, 1 },
|
|
|
|
{ 1, 0 },
|
|
|
|
{ 0, -1 }
|
|
|
|
};
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static bool BulldozerTick(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
v->progress++;
|
|
|
|
if ((v->progress & 7) == 0) {
|
2009-05-22 18:56:25 +00:00
|
|
|
const BulldozerMovement *b = &_bulldozer_movement[v->animation_state];
|
2008-04-20 11:12:07 +00:00
|
|
|
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_BULLDOZER_NE + b->image);
|
2008-04-20 11:12:07 +00:00
|
|
|
|
|
|
|
v->x_pos += _inc_by_dir[b->direction].x;
|
|
|
|
v->y_pos += _inc_by_dir[b->direction].y;
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
v->animation_substate++;
|
|
|
|
if (v->animation_substate >= b->duration) {
|
|
|
|
v->animation_substate = 0;
|
|
|
|
v->animation_state++;
|
|
|
|
if (v->animation_state == lengthof(_bulldozer_movement)) {
|
2008-04-20 11:12:07 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-20 15:31:26 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static void BubbleInit(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_BUBBLE_GENERATE_0);
|
2008-04-20 11:12:07 +00:00
|
|
|
v->spritenum = 0;
|
|
|
|
v->progress = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct BubbleMovement {
|
2023-05-08 17:01:06 +00:00
|
|
|
int8_t x:4;
|
|
|
|
int8_t y:4;
|
|
|
|
int8_t z:4;
|
2008-04-20 11:12:07 +00:00
|
|
|
byte image:4;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MK(x, y, z, i) { x, y, z, i }
|
|
|
|
#define ME(i) { i, 4, 0, 0 }
|
|
|
|
|
|
|
|
static const BubbleMovement _bubble_float_sw[] = {
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(1, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(1, 0, 1, 2),
|
|
|
|
ME(1)
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const BubbleMovement _bubble_float_ne[] = {
|
|
|
|
MK( 0, 0, 1, 0),
|
|
|
|
MK(-1, 0, 1, 1),
|
|
|
|
MK( 0, 0, 1, 0),
|
|
|
|
MK(-1, 0, 1, 2),
|
|
|
|
ME(1)
|
|
|
|
};
|
|
|
|
|
|
|
|
static const BubbleMovement _bubble_float_se[] = {
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 1, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 1, 1, 2),
|
|
|
|
ME(1)
|
|
|
|
};
|
|
|
|
|
|
|
|
static const BubbleMovement _bubble_float_nw[] = {
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, -1, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, -1, 1, 2),
|
|
|
|
ME(1)
|
|
|
|
};
|
|
|
|
|
|
|
|
static const BubbleMovement _bubble_burst[] = {
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 7),
|
|
|
|
MK(0, 0, 1, 8),
|
|
|
|
MK(0, 0, 1, 9),
|
|
|
|
ME(0)
|
|
|
|
};
|
|
|
|
|
|
|
|
static const BubbleMovement _bubble_absorb[] = {
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(0, 0, 1, 1),
|
|
|
|
MK(2, 1, 3, 0),
|
|
|
|
MK(1, 1, 3, 1),
|
|
|
|
MK(2, 1, 3, 0),
|
|
|
|
MK(1, 1, 3, 2),
|
|
|
|
MK(2, 1, 3, 0),
|
|
|
|
MK(1, 1, 3, 1),
|
|
|
|
MK(2, 1, 3, 0),
|
|
|
|
MK(1, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(1, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(1, 0, 1, 2),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(1, 0, 1, 1),
|
|
|
|
MK(0, 0, 1, 0),
|
|
|
|
MK(1, 0, 1, 2),
|
|
|
|
ME(2),
|
|
|
|
MK(0, 0, 0, 0xA),
|
|
|
|
MK(0, 0, 0, 0xB),
|
|
|
|
MK(0, 0, 0, 0xC),
|
|
|
|
MK(0, 0, 0, 0xD),
|
|
|
|
MK(0, 0, 0, 0xE),
|
|
|
|
ME(0)
|
|
|
|
};
|
|
|
|
#undef ME
|
|
|
|
#undef MK
|
|
|
|
|
|
|
|
static const BubbleMovement * const _bubble_movement[] = {
|
|
|
|
_bubble_float_sw,
|
|
|
|
_bubble_float_ne,
|
|
|
|
_bubble_float_se,
|
|
|
|
_bubble_float_nw,
|
|
|
|
_bubble_burst,
|
|
|
|
_bubble_absorb,
|
|
|
|
};
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
static bool BubbleTick(EffectVehicle *v)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2009-01-09 09:50:33 +00:00
|
|
|
uint anim_state;
|
2008-04-20 11:12:07 +00:00
|
|
|
|
|
|
|
v->progress++;
|
2009-05-22 13:53:14 +00:00
|
|
|
if ((v->progress & 3) != 0) return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
|
|
|
|
if (v->spritenum == 0) {
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.seq[0].sprite++;
|
|
|
|
if (v->sprite_cache.sprite_seq.seq[0].sprite < SPR_BUBBLE_GENERATE_3) {
|
2014-09-20 15:31:26 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2009-05-22 13:53:14 +00:00
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2009-05-22 18:56:25 +00:00
|
|
|
if (v->animation_substate != 0) {
|
2008-08-20 16:51:08 +00:00
|
|
|
v->spritenum = GB(Random(), 0, 2) + 1;
|
2008-04-20 11:12:07 +00:00
|
|
|
} else {
|
|
|
|
v->spritenum = 6;
|
|
|
|
}
|
2009-01-09 09:50:33 +00:00
|
|
|
anim_state = 0;
|
2008-04-20 11:12:07 +00:00
|
|
|
} else {
|
2009-05-22 18:56:25 +00:00
|
|
|
anim_state = v->animation_state + 1;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:50:33 +00:00
|
|
|
const BubbleMovement *b = &_bubble_movement[v->spritenum - 1][anim_state];
|
2008-04-20 11:12:07 +00:00
|
|
|
|
|
|
|
if (b->y == 4 && b->x == 0) {
|
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->y == 4 && b->x == 1) {
|
2008-08-20 16:51:08 +00:00
|
|
|
if (v->z_pos > 180 || Chance16I(1, 96, Random())) {
|
2008-04-20 11:12:07 +00:00
|
|
|
v->spritenum = 5;
|
2021-02-20 18:01:04 +00:00
|
|
|
if (_settings_client.sound.ambient) SndPlayVehicleFx(SND_2F_BUBBLE_GENERATOR_FAIL, v);
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
2009-01-09 09:50:33 +00:00
|
|
|
anim_state = 0;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->y == 4 && b->x == 2) {
|
|
|
|
TileIndex tile;
|
|
|
|
|
2009-01-09 09:50:33 +00:00
|
|
|
anim_state++;
|
2021-02-20 18:01:04 +00:00
|
|
|
if (_settings_client.sound.ambient) SndPlayVehicleFx(SND_31_BUBBLE_GENERATOR_SUCCESS, v);
|
2008-04-20 11:12:07 +00:00
|
|
|
|
|
|
|
tile = TileVirtXY(v->x_pos, v->y_pos);
|
|
|
|
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryGfx(tile) == GFX_BUBBLE_CATCHER) AddAnimatedTile(tile);
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
v->animation_state = anim_state;
|
2009-01-09 09:50:33 +00:00
|
|
|
b = &_bubble_movement[v->spritenum - 1][anim_state];
|
2008-04-20 11:12:07 +00:00
|
|
|
|
|
|
|
v->x_pos += b->x;
|
|
|
|
v->y_pos += b->y;
|
|
|
|
v->z_pos += b->z;
|
2021-01-03 13:32:58 +00:00
|
|
|
v->sprite_cache.sprite_seq.Set(SPR_BUBBLE_0 + b->image);
|
2008-04-20 11:12:07 +00:00
|
|
|
|
2014-09-20 15:31:26 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
typedef void EffectInitProc(EffectVehicle *v);
|
|
|
|
typedef bool EffectTickProc(EffectVehicle *v);
|
2008-04-20 11:12:07 +00:00
|
|
|
|
2011-05-28 09:43:22 +00:00
|
|
|
/** Functions to initialise an effect vehicle after construction. */
|
2008-04-20 11:12:07 +00:00
|
|
|
static EffectInitProc * const _effect_init_procs[] = {
|
2011-05-28 09:43:22 +00:00
|
|
|
ChimneySmokeInit, // EV_CHIMNEY_SMOKE
|
|
|
|
SteamSmokeInit, // EV_STEAM_SMOKE
|
|
|
|
DieselSmokeInit, // EV_DIESEL_SMOKE
|
|
|
|
ElectricSparkInit, // EV_ELECTRIC_SPARK
|
2011-05-28 09:45:12 +00:00
|
|
|
SmokeInit, // EV_CRASH_SMOKE
|
2011-05-28 09:43:22 +00:00
|
|
|
ExplosionLargeInit, // EV_EXPLOSION_LARGE
|
|
|
|
BreakdownSmokeInit, // EV_BREAKDOWN_SMOKE
|
|
|
|
ExplosionSmallInit, // EV_EXPLOSION_SMALL
|
|
|
|
BulldozerInit, // EV_BULLDOZER
|
|
|
|
BubbleInit, // EV_BUBBLE
|
2011-05-28 09:45:12 +00:00
|
|
|
SmokeInit, // EV_BREAKDOWN_SMOKE_AIRCRAFT
|
|
|
|
SmokeInit, // EV_COPPER_MINE_SMOKE
|
2008-04-20 11:12:07 +00:00
|
|
|
};
|
2020-12-27 10:44:22 +00:00
|
|
|
static_assert(lengthof(_effect_init_procs) == EV_END);
|
2008-04-20 11:12:07 +00:00
|
|
|
|
2013-01-08 22:46:42 +00:00
|
|
|
/** Functions for controlling effect vehicles at each tick. */
|
2008-04-20 11:12:07 +00:00
|
|
|
static EffectTickProc * const _effect_tick_procs[] = {
|
2011-05-28 09:43:22 +00:00
|
|
|
ChimneySmokeTick, // EV_CHIMNEY_SMOKE
|
|
|
|
SteamSmokeTick, // EV_STEAM_SMOKE
|
|
|
|
DieselSmokeTick, // EV_DIESEL_SMOKE
|
|
|
|
ElectricSparkTick, // EV_ELECTRIC_SPARK
|
2011-05-28 09:45:12 +00:00
|
|
|
SmokeTick, // EV_CRASH_SMOKE
|
2011-05-28 09:43:22 +00:00
|
|
|
ExplosionLargeTick, // EV_EXPLOSION_LARGE
|
|
|
|
BreakdownSmokeTick, // EV_BREAKDOWN_SMOKE
|
|
|
|
ExplosionSmallTick, // EV_EXPLOSION_SMALL
|
|
|
|
BulldozerTick, // EV_BULLDOZER
|
|
|
|
BubbleTick, // EV_BUBBLE
|
2011-05-28 09:45:12 +00:00
|
|
|
SmokeTick, // EV_BREAKDOWN_SMOKE_AIRCRAFT
|
|
|
|
SmokeTick, // EV_COPPER_MINE_SMOKE
|
2008-04-20 11:12:07 +00:00
|
|
|
};
|
2020-12-27 10:44:22 +00:00
|
|
|
static_assert(lengthof(_effect_tick_procs) == EV_END);
|
2008-04-20 11:12:07 +00:00
|
|
|
|
2011-05-28 09:46:37 +00:00
|
|
|
/** Transparency options affecting the effects. */
|
|
|
|
static const TransparencyOption _effect_transparency_options[] = {
|
|
|
|
TO_INDUSTRIES, // EV_CHIMNEY_SMOKE
|
|
|
|
TO_INVALID, // EV_STEAM_SMOKE
|
|
|
|
TO_INVALID, // EV_DIESEL_SMOKE
|
|
|
|
TO_INVALID, // EV_ELECTRIC_SPARK
|
|
|
|
TO_INVALID, // EV_CRASH_SMOKE
|
|
|
|
TO_INVALID, // EV_EXPLOSION_LARGE
|
|
|
|
TO_INVALID, // EV_BREAKDOWN_SMOKE
|
|
|
|
TO_INVALID, // EV_EXPLOSION_SMALL
|
|
|
|
TO_INVALID, // EV_BULLDOZER
|
|
|
|
TO_INDUSTRIES, // EV_BUBBLE
|
|
|
|
TO_INVALID, // EV_BREAKDOWN_SMOKE_AIRCRAFT
|
|
|
|
TO_INDUSTRIES, // EV_COPPER_MINE_SMOKE
|
|
|
|
};
|
2020-12-27 10:44:22 +00:00
|
|
|
static_assert(lengthof(_effect_transparency_options) == EV_END);
|
2011-05-28 09:46:37 +00:00
|
|
|
|
2008-04-20 11:12:07 +00:00
|
|
|
|
2011-05-02 17:42:12 +00:00
|
|
|
/**
|
|
|
|
* Create an effect vehicle at a particular location.
|
|
|
|
* @param x The x location on the map.
|
|
|
|
* @param y The y location on the map.
|
|
|
|
* @param z The z location on the map.
|
|
|
|
* @param type The type of effect vehicle.
|
|
|
|
* @return The effect vehicle.
|
|
|
|
*/
|
2009-05-22 18:56:25 +00:00
|
|
|
EffectVehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
if (!Vehicle::CanAllocateItem()) return nullptr;
|
2009-01-09 14:59:02 +00:00
|
|
|
|
2009-05-22 18:56:25 +00:00
|
|
|
EffectVehicle *v = new EffectVehicle();
|
2009-01-09 14:59:02 +00:00
|
|
|
v->subtype = type;
|
|
|
|
v->x_pos = x;
|
|
|
|
v->y_pos = y;
|
|
|
|
v->z_pos = z;
|
|
|
|
v->tile = 0;
|
2018-05-22 17:43:34 +00:00
|
|
|
v->UpdateDeltaXY();
|
2009-01-09 14:59:02 +00:00
|
|
|
v->vehstatus = VS_UNCLICKABLE;
|
2008-04-20 11:12:07 +00:00
|
|
|
|
2009-01-09 14:59:02 +00:00
|
|
|
_effect_init_procs[type](v);
|
|
|
|
|
2014-09-20 15:31:26 +00:00
|
|
|
v->UpdatePositionAndViewport();
|
2008-04-20 11:12:07 +00:00
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2011-05-02 17:42:12 +00:00
|
|
|
/**
|
|
|
|
* Create an effect vehicle above a particular location.
|
|
|
|
* @param x The x location on the map.
|
|
|
|
* @param y The y location on the map.
|
|
|
|
* @param z The offset from the ground.
|
|
|
|
* @param type The type of effect vehicle.
|
|
|
|
* @return The effect vehicle.
|
|
|
|
*/
|
2009-05-22 18:56:25 +00:00
|
|
|
EffectVehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2023-01-21 09:43:03 +00:00
|
|
|
int safe_x = Clamp(x, 0, Map::MaxX() * TILE_SIZE);
|
|
|
|
int safe_y = Clamp(y, 0, Map::MaxY() * TILE_SIZE);
|
2011-11-04 10:18:13 +00:00
|
|
|
return CreateEffectVehicle(x, y, GetSlopePixelZ(safe_x, safe_y) + z, type);
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2011-05-02 17:42:12 +00:00
|
|
|
/**
|
|
|
|
* Create an effect vehicle above a particular vehicle.
|
|
|
|
* @param v The vehicle to base the position on.
|
|
|
|
* @param x The x offset to the vehicle.
|
|
|
|
* @param y The y offset to the vehicle.
|
|
|
|
* @param z The z offset to the vehicle.
|
|
|
|
* @param type The type of effect vehicle.
|
|
|
|
* @return The effect vehicle.
|
|
|
|
*/
|
2009-05-22 18:56:25 +00:00
|
|
|
EffectVehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type);
|
|
|
|
}
|
|
|
|
|
2009-05-22 13:53:14 +00:00
|
|
|
bool EffectVehicle::Tick()
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
2009-05-22 13:53:14 +00:00
|
|
|
return _effect_tick_procs[this->subtype](this);
|
2008-04-20 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 17:43:34 +00:00
|
|
|
void EffectVehicle::UpdateDeltaXY()
|
2008-04-20 11:12:07 +00:00
|
|
|
{
|
|
|
|
this->x_offs = 0;
|
|
|
|
this->y_offs = 0;
|
|
|
|
this->x_extent = 1;
|
|
|
|
this->y_extent = 1;
|
|
|
|
this->z_extent = 1;
|
|
|
|
}
|
2011-05-28 09:46:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the transparency option affecting the effect.
|
|
|
|
* @return Transparency option, or TO_INVALID if none.
|
|
|
|
*/
|
|
|
|
TransparencyOption EffectVehicle::GetTransparencyOption() const
|
|
|
|
{
|
|
|
|
return _effect_transparency_options[this->subtype];
|
|
|
|
}
|