OpenTTD Source 20260218-master-g2123fca5ea
effectvehicle.cpp File Reference

Implementation of everything generic to vehicles. More...

#include "stdafx.h"
#include "landscape.h"
#include "core/random_func.hpp"
#include "industry_map.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "animated_tile_func.h"
#include "effectvehicle_func.h"
#include "effectvehicle_base.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  BulldozerMovement
struct  BubbleMovement
struct  EffectProcs
 Container holding functions to call for a specific effect vehicle type. More...

Macros

#define MK(x, y, z, i)
#define ME(i)

Functions

static bool IncrementSprite (EffectVehicle *v, SpriteID last)
 Increment the sprite unless it has reached the end of the animation.
static void ChimneySmokeInit (EffectVehicle *v)
 Initialise the smoke of a chimney.
static bool ChimneySmokeTick (EffectVehicle *v)
 Run a single tick of the smoke of a chimney.
static void SteamSmokeInit (EffectVehicle *v)
 Initialise the smoke of a steam engine.
static bool SteamSmokeTick (EffectVehicle *v)
 Run a single tick of the smoke of a steam engine.
static void DieselSmokeInit (EffectVehicle *v)
 Initialise the smoke of a diesel engine.
static bool DieselSmokeTick (EffectVehicle *v)
 Run a single tick of the smoke of a diesel engine.
static void ElectricSparkInit (EffectVehicle *v)
 Initialise the sparks of a train.
static bool ElectricSparkTick (EffectVehicle *v)
 Run a single tick of the sparks of a train.
static void SmokeInit (EffectVehicle *v)
 Initialise some smoke.
static bool SmokeTick (EffectVehicle *v)
 Run a single tick of some smoke.
static void ExplosionLargeInit (EffectVehicle *v)
 Initialise a large explosion.
static bool ExplosionLargeTick (EffectVehicle *v)
 Run a single tick of a large explosion.
static void BreakdownSmokeInit (EffectVehicle *v)
 Initialise the smoke of a broken down vehicle.
static bool BreakdownSmokeTick (EffectVehicle *v)
 Run a single tick of the smoke of a broken down vehicle.
static void ExplosionSmallInit (EffectVehicle *v)
 Initialise a small explosion.
static bool ExplosionSmallTick (EffectVehicle *v)
 Run a single tick of a small explosion.
static void BulldozerInit (EffectVehicle *v)
 Initialise the bulldozer (road works).
static bool BulldozerTick (EffectVehicle *v)
 Run a single tick of a bulldozer (road works).
static void BubbleInit (EffectVehicle *v)
 Initialise the bubbles of the bubble generator industry.
static bool BubbleTick (EffectVehicle *v)
 Run a single tick of bubbles of the bubble generator industry.
EffectVehicleCreateEffectVehicle (int x, int y, int z, EffectVehicleType type)
 Create an effect vehicle at a particular location.
EffectVehicleCreateEffectVehicleAbove (int x, int y, int z, EffectVehicleType type)
 Create an effect vehicle above a particular location.
EffectVehicleCreateEffectVehicleRel (const Vehicle *v, int x, int y, int z, EffectVehicleType type)
 Create an effect vehicle above a particular vehicle.

Variables

static const BulldozerMovement _bulldozer_movement []
struct { 
   int8_t   x 
   int8_t   y 
_inc_by_dir []
static const BubbleMovement _bubble_float_sw []
static const BubbleMovement _bubble_float_ne []
static const BubbleMovement _bubble_float_se []
static const BubbleMovement _bubble_float_nw []
static const BubbleMovement _bubble_burst []
static const BubbleMovement _bubble_absorb []
static const BubbleMovement *const _bubble_movement []
static const std::array< EffectProcs, EV_END > _effect_procs
 Per-EffectVehicleType handling.

Detailed Description

Implementation of everything generic to vehicles.

Definition in file effectvehicle.cpp.

Macro Definition Documentation

◆ ME

#define ME ( i)
Value:
{ i, 4, 0, 0 }

Definition at line 346 of file effectvehicle.cpp.

◆ MK

#define MK ( x,
y,
z,
i )
Value:
{ x, y, z, i }

Definition at line 345 of file effectvehicle.cpp.

Function Documentation

◆ BreakdownSmokeInit()

void BreakdownSmokeInit ( EffectVehicle * v)
static

Initialise the smoke of a broken down vehicle.

Initialises effect vehicle for a specific type.

Parameters
vThe vehicle to initialise.

Definition at line 207 of file effectvehicle.cpp.

References Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, and MutableSpriteCache::sprite_seq.

◆ BreakdownSmokeTick()

bool BreakdownSmokeTick ( EffectVehicle * v)
static

Run a single tick of the smoke of a broken down vehicle.

Run the actions/perform the behaviour of an effect vehicle for a tick.

Parameters
vThe vehicle to work with.
Returns
true iff the vehicle is still valid, i.e. has not been removed yet.

Definition at line 214 of file effectvehicle.cpp.

References EffectVehicle::animation_state, IncrementSprite(), Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, and Vehicle::UpdatePositionAndViewport().

◆ BubbleInit()

void BubbleInit ( EffectVehicle * v)
static

Initialise the bubbles of the bubble generator industry.

Initialises effect vehicle for a specific type.

Parameters
vThe vehicle to initialise.

Definition at line 331 of file effectvehicle.cpp.

References Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, and Vehicle::spritenum.

◆ BubbleTick()

bool BubbleTick ( EffectVehicle * v)
static

Run a single tick of bubbles of the bubble generator industry.

Run the actions/perform the behaviour of an effect vehicle for a tick.

Parameters
vThe vehicle to work with.
Returns
true iff the vehicle is still valid, i.e. has not been removed yet.

Definition at line 489 of file effectvehicle.cpp.

References _settings_client, AddAnimatedTile(), EffectVehicle::animation_state, EffectVehicle::animation_substate, Chance16I(), GB(), GetIndustryGfx(), Industry, IsTileType(), Vehicle::progress, VehicleSpriteSeq::Set(), SND_2F_BUBBLE_GENERATOR_FAIL, SND_31_BUBBLE_GENERATOR_SUCCESS, Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, Vehicle::spritenum, TileVirtXY(), Vehicle::UpdatePositionAndViewport(), Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

◆ BulldozerInit()

void BulldozerInit ( EffectVehicle * v)
static

Initialise the bulldozer (road works).

Initialises effect vehicle for a specific type.

Parameters
vThe vehicle to initialise.

Definition at line 256 of file effectvehicle.cpp.

References EffectVehicle::animation_state, EffectVehicle::animation_substate, Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, and MutableSpriteCache::sprite_seq.

◆ BulldozerTick()

bool BulldozerTick ( EffectVehicle * v)
static

Run a single tick of a bulldozer (road works).

Run the actions/perform the behaviour of an effect vehicle for a tick.

Parameters
vThe vehicle to work with.
Returns
true iff the vehicle is still valid, i.e. has not been removed yet.

Definition at line 304 of file effectvehicle.cpp.

References EffectVehicle::animation_state, EffectVehicle::animation_substate, lengthof, Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, Vehicle::UpdatePositionAndViewport(), Vehicle::x_pos, and Vehicle::y_pos.

◆ ChimneySmokeInit()

void ChimneySmokeInit ( EffectVehicle * v)
static

Initialise the smoke of a chimney.

Initialises effect vehicle for a specific type.

Parameters
vThe vehicle to initialise.

Definition at line 40 of file effectvehicle.cpp.

References GB(), Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, and MutableSpriteCache::sprite_seq.

◆ ChimneySmokeTick()

bool ChimneySmokeTick ( EffectVehicle * v)
static

Run a single tick of the smoke of a chimney.

Run the actions/perform the behaviour of an effect vehicle for a tick.

Parameters
vThe vehicle to work with.
Returns
true iff the vehicle is still valid, i.e. has not been removed yet.

Definition at line 48 of file effectvehicle.cpp.

References IncrementSprite(), Industry, IsTileType(), Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, TileVirtXY(), Vehicle::UpdatePositionAndViewport(), Vehicle::x_pos, and Vehicle::y_pos.

◆ CreateEffectVehicle()

EffectVehicle * CreateEffectVehicle ( int x,
int y,
int z,
EffectVehicleType type )

Create an effect vehicle at a particular location.

Parameters
xThe x location on the map.
yThe y location on the map.
zThe z location on the map.
typeThe type of effect vehicle.
Returns
The effect vehicle.

Definition at line 597 of file effectvehicle.cpp.

References _effect_procs, Vehicle::subtype, Vehicle::tile, Unclickable, EffectVehicle::UpdateDeltaXY(), Vehicle::UpdatePositionAndViewport(), Vehicle::vehstatus, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by CreateEffectVehicleAbove(), and CreateEffectVehicleRel().

◆ CreateEffectVehicleAbove()

EffectVehicle * CreateEffectVehicleAbove ( int x,
int y,
int z,
EffectVehicleType type )

Create an effect vehicle above a particular location.

Parameters
xThe x location on the map.
yThe y location on the map.
zThe offset from the ground.
typeThe type of effect vehicle.
Returns
The effect vehicle.

Definition at line 625 of file effectvehicle.cpp.

References Clamp(), CreateEffectVehicle(), GetSlopePixelZ(), Map::MaxX(), Map::MaxY(), and TILE_SIZE.

Referenced by CmdClearArea(), DisasterTick_Aircraft(), and DisasterTick_Big_Ufo_Destroyer().

◆ CreateEffectVehicleRel()

EffectVehicle * CreateEffectVehicleRel ( const Vehicle * v,
int x,
int y,
int z,
EffectVehicleType type )

Create an effect vehicle above a particular vehicle.

Parameters
vThe vehicle to base the position on.
xThe x offset to the vehicle.
yThe y offset to the vehicle.
zThe z offset to the vehicle.
typeThe type of effect vehicle.
Returns
The effect vehicle.

Definition at line 641 of file effectvehicle.cpp.

References CreateEffectVehicle(), Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by CrashAirplane(), DisasterTick_Big_Ufo_Destroyer(), DisasterTick_Ufo(), DisasterTick_Zeppeliner(), FloodVehicle(), HandleAircraftSmoke(), Vehicle::HandleBreakdown(), HandleCrashedAircraft(), HandleCrashedTrain(), RoadVehIsCrashed(), Vehicle::ShowVisualEffect(), and SpawnAdvancedVisualEffect().

◆ DieselSmokeInit()

void DieselSmokeInit ( EffectVehicle * v)
static

Initialise the smoke of a diesel engine.

Initialises effect vehicle for a specific type.

Parameters
vThe vehicle to initialise.

Definition at line 102 of file effectvehicle.cpp.

References Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, and MutableSpriteCache::sprite_seq.

◆ DieselSmokeTick()

bool DieselSmokeTick ( EffectVehicle * v)
static

Run a single tick of the smoke of a diesel engine.

Run the actions/perform the behaviour of an effect vehicle for a tick.

Parameters
vThe vehicle to work with.
Returns
true iff the vehicle is still valid, i.e. has not been removed yet.

Definition at line 109 of file effectvehicle.cpp.

References IncrementSprite(), Vehicle::progress, Vehicle::UpdatePositionAndViewport(), and Vehicle::z_pos.

◆ ElectricSparkInit()

void ElectricSparkInit ( EffectVehicle * v)
static

Initialise the sparks of a train.

Initialises effect vehicle for a specific type.

Parameters
vThe vehicle to initialise.

Definition at line 128 of file effectvehicle.cpp.

References Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, and MutableSpriteCache::sprite_seq.

◆ ElectricSparkTick()

bool ElectricSparkTick ( EffectVehicle * v)
static

Run a single tick of the sparks of a train.

Run the actions/perform the behaviour of an effect vehicle for a tick.

Parameters
vThe vehicle to work with.
Returns
true iff the vehicle is still valid, i.e. has not been removed yet.

Definition at line 135 of file effectvehicle.cpp.

References IncrementSprite(), Vehicle::progress, and Vehicle::UpdatePositionAndViewport().

◆ ExplosionLargeInit()

void ExplosionLargeInit ( EffectVehicle * v)
static

Initialise a large explosion.

Initialises effect vehicle for a specific type.

Parameters
vThe vehicle to initialise.

Definition at line 185 of file effectvehicle.cpp.

References Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, and MutableSpriteCache::sprite_seq.

◆ ExplosionLargeTick()

bool ExplosionLargeTick ( EffectVehicle * v)
static

Run a single tick of a large explosion.

Run the actions/perform the behaviour of an effect vehicle for a tick.

Parameters
vThe vehicle to work with.
Returns
true iff the vehicle is still valid, i.e. has not been removed yet.

Definition at line 192 of file effectvehicle.cpp.

References IncrementSprite(), Vehicle::progress, and Vehicle::UpdatePositionAndViewport().

◆ ExplosionSmallInit()

void ExplosionSmallInit ( EffectVehicle * v)
static

Initialise a small explosion.

Initialises effect vehicle for a specific type.

Parameters
vThe vehicle to initialise.

Definition at line 234 of file effectvehicle.cpp.

References Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, and MutableSpriteCache::sprite_seq.

◆ ExplosionSmallTick()

bool ExplosionSmallTick ( EffectVehicle * v)
static

Run a single tick of a small explosion.

Run the actions/perform the behaviour of an effect vehicle for a tick.

Parameters
vThe vehicle to work with.
Returns
true iff the vehicle is still valid, i.e. has not been removed yet.

Definition at line 241 of file effectvehicle.cpp.

References IncrementSprite(), Vehicle::progress, and Vehicle::UpdatePositionAndViewport().

◆ IncrementSprite()

bool IncrementSprite ( EffectVehicle * v,
SpriteID last )
static

Increment the sprite unless it has reached the end of the animation.

Parameters
vVehicle to increment sprite of.
lastLast sprite of animation.
Returns
true if the sprite was incremented, false if the end was reached.

Definition at line 29 of file effectvehicle.cpp.

References Vehicle::sprite_cache, and MutableSpriteCache::sprite_seq.

Referenced by BreakdownSmokeTick(), ChimneySmokeTick(), DieselSmokeTick(), ElectricSparkTick(), ExplosionLargeTick(), ExplosionSmallTick(), SmokeTick(), and SteamSmokeTick().

◆ SmokeInit()

void SmokeInit ( EffectVehicle * v)
static

Initialise some smoke.

Initialises effect vehicle for a specific type.

Parameters
vThe vehicle to initialise.

Definition at line 153 of file effectvehicle.cpp.

References Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, and MutableSpriteCache::sprite_seq.

◆ SmokeTick()

bool SmokeTick ( EffectVehicle * v)
static

Run a single tick of some smoke.

Run the actions/perform the behaviour of an effect vehicle for a tick.

Parameters
vThe vehicle to work with.
Returns
true iff the vehicle is still valid, i.e. has not been removed yet.

Definition at line 160 of file effectvehicle.cpp.

References IncrementSprite(), Vehicle::progress, Vehicle::UpdatePositionAndViewport(), and Vehicle::z_pos.

◆ SteamSmokeInit()

void SteamSmokeInit ( EffectVehicle * v)
static

Initialise the smoke of a steam engine.

Initialises effect vehicle for a specific type.

Parameters
vThe vehicle to initialise.

Definition at line 70 of file effectvehicle.cpp.

References Vehicle::progress, VehicleSpriteSeq::Set(), Vehicle::sprite_cache, and MutableSpriteCache::sprite_seq.

◆ SteamSmokeTick()

bool SteamSmokeTick ( EffectVehicle * v)
static

Run a single tick of the smoke of a steam engine.

Run the actions/perform the behaviour of an effect vehicle for a tick.

Parameters
vThe vehicle to work with.
Returns
true iff the vehicle is still valid, i.e. has not been removed yet.

Definition at line 77 of file effectvehicle.cpp.

References IncrementSprite(), Vehicle::progress, Vehicle::UpdatePositionAndViewport(), and Vehicle::z_pos.

Variable Documentation

◆ _bubble_absorb

const BubbleMovement _bubble_absorb[]
static

Definition at line 389 of file effectvehicle.cpp.

◆ _bubble_burst

const BubbleMovement _bubble_burst[]
static
Initial value:
= {
MK(0, 0, 1, 2),
MK(0, 0, 1, 7),
MK(0, 0, 1, 8),
MK(0, 0, 1, 9),
}
#define MK(a, b)
Macro for ordinary entry of LegendAndColour.

Definition at line 381 of file effectvehicle.cpp.

◆ _bubble_float_ne

const BubbleMovement _bubble_float_ne[]
static
Initial value:
= {
MK( 0, 0, 1, 0),
MK(-1, 0, 1, 1),
MK( 0, 0, 1, 0),
MK(-1, 0, 1, 2),
}

Definition at line 357 of file effectvehicle.cpp.

◆ _bubble_float_nw

const BubbleMovement _bubble_float_nw[]
static
Initial value:
= {
MK(0, 0, 1, 0),
MK(0, -1, 1, 1),
MK(0, 0, 1, 0),
MK(0, -1, 1, 2),
}

Definition at line 373 of file effectvehicle.cpp.

◆ _bubble_float_se

const BubbleMovement _bubble_float_se[]
static
Initial value:
= {
MK(0, 0, 1, 0),
MK(0, 1, 1, 1),
MK(0, 0, 1, 0),
MK(0, 1, 1, 2),
}

Definition at line 365 of file effectvehicle.cpp.

◆ _bubble_float_sw

const BubbleMovement _bubble_float_sw[]
static
Initial value:
= {
MK(0, 0, 1, 0),
MK(1, 0, 1, 1),
MK(0, 0, 1, 0),
MK(1, 0, 1, 2),
}

Definition at line 348 of file effectvehicle.cpp.

◆ _bubble_movement

const BubbleMovement* const _bubble_movement[]
static
Initial value:
= {
_bubble_float_sw,
_bubble_float_ne,
_bubble_float_se,
_bubble_float_nw,
_bubble_burst,
_bubble_absorb,
}

Definition at line 479 of file effectvehicle.cpp.

◆ _bulldozer_movement

const BulldozerMovement _bulldozer_movement[]
static
Initial value:
= {
{ 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 }
}

Definition at line 270 of file effectvehicle.cpp.

◆ _effect_procs

const std::array<EffectProcs, EV_END> _effect_procs
static
Initial value:
= {{
}}
static void ElectricSparkInit(EffectVehicle *v)
Initialise the sparks of a train.
static void ExplosionLargeInit(EffectVehicle *v)
Initialise a large explosion.
static void BubbleInit(EffectVehicle *v)
Initialise the bubbles of the bubble generator industry.
static void DieselSmokeInit(EffectVehicle *v)
Initialise the smoke of a diesel engine.
static void ChimneySmokeInit(EffectVehicle *v)
Initialise the smoke of a chimney.
static bool BulldozerTick(EffectVehicle *v)
Run a single tick of a bulldozer (road works).
static bool DieselSmokeTick(EffectVehicle *v)
Run a single tick of the smoke of a diesel engine.
static bool BreakdownSmokeTick(EffectVehicle *v)
Run a single tick of the smoke of a broken down vehicle.
static void SteamSmokeInit(EffectVehicle *v)
Initialise the smoke of a steam engine.
static bool ElectricSparkTick(EffectVehicle *v)
Run a single tick of the sparks of a train.
static void BreakdownSmokeInit(EffectVehicle *v)
Initialise the smoke of a broken down vehicle.
static bool SteamSmokeTick(EffectVehicle *v)
Run a single tick of the smoke of a steam engine.
static void ExplosionSmallInit(EffectVehicle *v)
Initialise a small explosion.
static void BulldozerInit(EffectVehicle *v)
Initialise the bulldozer (road works).
static bool ChimneySmokeTick(EffectVehicle *v)
Run a single tick of the smoke of a chimney.
static bool SmokeTick(EffectVehicle *v)
Run a single tick of some smoke.
static bool BubbleTick(EffectVehicle *v)
Run a single tick of bubbles of the bubble generator industry.
static void SmokeInit(EffectVehicle *v)
Initialise some smoke.
static bool ExplosionSmallTick(EffectVehicle *v)
Run a single tick of a small explosion.
static bool ExplosionLargeTick(EffectVehicle *v)
Run a single tick of a large explosion.
@ TO_INVALID
Invalid transparency option.
@ TO_INDUSTRIES
industries

Per-EffectVehicleType handling.

Definition at line 574 of file effectvehicle.cpp.

Referenced by CreateEffectVehicle(), EffectVehicle::GetTransparencyOption(), and EffectVehicle::Tick().

◆ [struct]

const struct { ... } _inc_by_dir[]
Initial value:
= {
{ -1, 0 },
{ 0, 1 },
{ 1, 0 },
{ 0, -1 }
}

◆ x

int8_t x

Definition at line 294 of file effectvehicle.cpp.

◆ y

int8_t y

Definition at line 295 of file effectvehicle.cpp.