Go to the documentation of this file.
49 #include "table/strings.h"
56 static void DisasterClearSquare(
TileIndex tile)
89 static const SpriteID _disaster_images_1[] = {SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP};
90 static const SpriteID _disaster_images_2[] = {SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT};
91 static const SpriteID _disaster_images_3[] = {SPR_F_15, SPR_F_15, SPR_F_15, SPR_F_15, SPR_F_15, SPR_F_15, SPR_F_15, SPR_F_15};
92 static const SpriteID _disaster_images_4[] = {SPR_SUB_SMALL_NE, SPR_SUB_SMALL_NE, SPR_SUB_SMALL_SE, SPR_SUB_SMALL_SE, SPR_SUB_SMALL_SW, SPR_SUB_SMALL_SW, SPR_SUB_SMALL_NW, SPR_SUB_SMALL_NW};
93 static const SpriteID _disaster_images_5[] = {SPR_SUB_LARGE_NE, SPR_SUB_LARGE_NE, SPR_SUB_LARGE_SE, SPR_SUB_LARGE_SE, SPR_SUB_LARGE_SW, SPR_SUB_LARGE_SW, SPR_SUB_LARGE_NW, SPR_SUB_LARGE_NW};
94 static const SpriteID _disaster_images_6[] = {SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER};
95 static const SpriteID _disaster_images_7[] = {SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER};
96 static const SpriteID _disaster_images_8[] = {SPR_AH_64A, SPR_AH_64A, SPR_AH_64A, SPR_AH_64A, SPR_AH_64A, SPR_AH_64A, SPR_AH_64A, SPR_AH_64A};
97 static const SpriteID _disaster_images_9[] = {SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1};
99 static const SpriteID *
const _disaster_images[] = {
100 _disaster_images_1, _disaster_images_1,
101 _disaster_images_2, _disaster_images_2,
102 _disaster_images_3, _disaster_images_3,
103 _disaster_images_8, _disaster_images_8, _disaster_images_9,
104 _disaster_images_6, _disaster_images_6,
105 _disaster_images_7, _disaster_images_7,
106 _disaster_images_4, _disaster_images_5,
109 void DisasterVehicle::UpdateImage()
196 u->
y_pos = y - 1 - (std::max(z - GetSlopePixelZ(safe_x, safe_y), 0) >> 3);
198 u->
z_pos = GetSlopePixelZ(safe_x, safe_y);
204 if ((u = u->
Next()) !=
nullptr) {
233 if (++v->
age == 38) {
260 if (++v->
age <= 13320)
return true;
275 int z = GetSlopePixelZ(x, y);
276 if (z < v->z_pos) z = v->
z_pos - 1;
283 }
else if (v->
age == 70) {
285 }
else if (v->
age <= 300) {
295 }
else if (v->
age == 350) {
322 v->
direction = GetDirectionTowards(v, x, y);
335 if (u->IsFrontEngine()) n++;
347 if (u->IsFrontEngine() && (n-- == 0)) {
372 if (dist <= TILE_SIZE && z > u->
z_pos) z--;
399 static void DestructIndustry(
Industry *i)
451 if (++v->
age == 112) {
502 if (++cur_image > SPR_ROTOR_MOVING_3) cur_image = SPR_ROTOR_MOVING_1;
523 v->
direction = GetDirectionTowards(v, x, y);
545 if (target->IsGroundVehicle()) {
547 target->breakdown_ctr = 5;
548 target->breakdown_delay = 0xF0;
568 v->
direction = GetDirectionTowards(v, x, y);
588 }
while (tile != tile_org);
622 for (
int i = 0; i != 80; i++) {
631 for (
int dy = -3; dy < 3; dy++) {
632 for (
int dx = -3; dx < 3; dx++) {
650 if (++v->
age > 8880) {
680 static DisasterVehicleTickProc *
const _disastervehicle_tick_procs[] = {
694 return _disastervehicle_tick_procs[this->
subtype](
this);
697 typedef void DisasterInitProc();
744 static void Disaster_Airplane_Init()
752 (found ==
nullptr ||
Chance16(1, 2))) {
757 if (found ==
nullptr)
return;
778 (found ==
nullptr ||
Chance16(1, 2))) {
783 if (found ==
nullptr)
return;
799 static void Disaster_Big_Ufo_Init()
838 static void Disaster_Small_Submarine_Init()
845 static void Disaster_Big_Submarine_Init()
857 int index =
GB(Random(), 0, 4);
860 for (m = 0; m < 15; m++) {
870 for (uint n = 0; n < 30; n++) {
871 DisasterClearSquare(tile);
888 static const Disaster _disasters[] = {
891 {Disaster_Airplane_Init, 1960, 1990},
893 {Disaster_Big_Ufo_Init, 2000, 2100},
894 {Disaster_Small_Submarine_Init, 1940, 1965},
895 {Disaster_Big_Submarine_Init, 1975, 2010},
899 static void DoDisaster()
904 for (
size_t i = 0; i !=
lengthof(_disasters); i++) {
905 if (
_cur_year >= _disasters[i].min_year &&
_cur_year < _disasters[i].max_year) buf[j++] = (byte)i;
914 static void ResetDisasterDelay()
919 void DisasterDailyLoop()
923 ResetDisasterDelay();
928 void StartupDisasters()
930 ResetDisasterDelay();
SpriteID image_override
Override for the default disaster vehicle sprite.
Buses, trucks and trams belong to this class.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
@ MP_HOUSE
A house by a town.
uint32 TileIndex
The index/ID of a Tile.
static bool DisasterTick_Airplane(DisasterVehicle *v)
Airplane handling.
static bool DisasterTick_Zeppeliner(DisasterVehicle *v)
Zeppeliner handling, v->current_order.dest states: 0: Zeppeliner initialization has found a small air...
static bool DisasterTick_Submarine(DisasterVehicle *v)
Submarine, v->current_order.dest states: Unused, just float around aimlessly and pop up at different ...
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
static Titem * Get(size_t index)
Returns Titem with given index.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Direction
Defines the 8 directions on the map.
VehicleSpriteSeq sprite_seq
Vehicle appearance.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Class to backup a specific variable and restore it later.
Year _cur_year
Current year, starting at 0.
DisasterVehicle * Next() const
Get next vehicle in the chain.
VehicleID big_ufo_destroyer_target
The big UFO that this destroyer is supposed to bomb.
byte y_extent
y-extent of vehicle bounding box
DestinationID GetDestination() const
Gets the destination of this order.
static bool IsAirportTile(TileIndex t)
Is this tile a station tile and an airport tile?
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
@ INDUSTRYBEH_CAN_SUBSIDENCE
can cause a subsidence (coal mine, shaft that collapses)
Tindex index
Index of this pool item.
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
SpriteID sprite
The 'real' sprite.
void Free()
'Free' the order
@ ST_SMALL_UFO_SHADOW
Shadow of small UFO.
DifficultySettings difficulty
settings related to the difficulty
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
static const uint TILE_SIZE
Tile size in world coordinates.
void UpdatePosition(int x, int y, int z)
Update the position of the vehicle.
ClientSettings _settings_client
The current settings for this game.
@ MP_INDUSTRY
Part of an industry.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
static bool DisasterTick_Big_Ufo_Destroyer(DisasterVehicle *v)
Skyranger destroying (Big) Ufo handling, v->current_order.dest states: 0: Home in on landed Ufo and s...
@ EV_EXPLOSION_SMALL
Various explosions.
DisasterSubType
Different sub types of disaster vehicles.
@ VEH_ROAD
Road vehicle type.
Defines the internal data of a functional industry.
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
Owner owner
Which company owns the vehicle?
@ EV_EXPLOSION_LARGE
Various explosions.
@ DC_EXEC
execute the given command
@ ST_BIG_SUBMARINE
Big submarine, pops up in the oceans but doesn't do anything.
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static void Disaster_Zeppeliner_Init()
Zeppeliner which crashes on a small airport if one found, otherwise crashes on a random tile.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
#define SETBITS(x, y)
Sets several bits in a variable.
static void ResetIndustryConstructionStage(TileIndex tile)
Reset the construction stage counter of the industry, as well as the completion bit.
static uint TileX(TileIndex tile)
Get the X component of a tile.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
static uint MapSizeX()
Get the size of the map along the X.
static void Disaster_CoalMine_Init()
Coal mine catastrophe, destroys a stretch of 30 tiles of land in a certain direction.
bool disasters
are disasters enabled
@ INDUSTRYBEH_AIRPLANE_ATTACKS
can be exploded by a military airplane (oil refinery)
byte breakdown_ctr
Counter for managing breakdown events.
@ VS_HIDDEN
Vehicle is not visible.
@ ST_AIRPLANE
Airplane destroying an oil refinery.
TileIndex dest_tile
Heading for this tile.
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
static uint MapSize()
Get the size of the map.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges.
TileArea location
Location of the industry.
@ ST_ZEPPELINER
Zeppelin, crashes at airports.
SoundSettings sound
sound effect settings
@ DIRDIFF_90LEFT
Angle of 90 degrees left.
IndustryType type
type of industry.
int32 TileIndexDiff
An offset value between to tiles.
TileIndex tile
Current tile index.
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
void SetDestination(DestinationID destination)
Sets the destination of this order.
@ ST_BIG_UFO_SHADOW
Shadow of the big UFO.
static void Disaster_Helicopter_Init()
Combat helicopter that destroys a factory.
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
bool Tick()
Calls the tick handler of the vehicle.
Order current_order
The current order (+ status, like: loading)
Airport airport
Tile area the airport covers.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
static bool DisasterTick_Aircraft(DisasterVehicle *v, uint16 image_override, bool leave_at_top, StringID news_message, IndustryBehaviour industry_flag)
Aircraft handling, v->current_order.dest states: 0: Fly towards the targeted industry 1: If within 15...
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void Disaster_Small_Ufo_Init()
Ufo which flies around aimlessly from the middle of the map a bit until it locates a road vehicle whi...
void GetAircraftFlightLevelBounds(const Vehicle *v, int *min, int *max)
Get the 'flight level' bounds, in pixels from 'z_pos' 0 for a particular vehicle for normal flight si...
static RoadVehicle * Get(size_t index)
Gets vehicle with given index.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
@ EV_CRASH_SMOKE
Smoke of disasters.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
bool freeform_edges
allow terraforming the tiles at the map edges
#define RandomTile()
Get a valid random tile.
void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
bool disaster
Play disaster and accident sounds.
DiagDirection
Enumeration for diagonal directions.
static uint MapSizeY()
Get the size of the map along the Y.
@ TRACK_BIT_ALL
All possible tracks.
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
static bool IsHumanID(size_t index)
Is this company a company not controlled by a NoAI program?
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
void ReleaseDisastersTargetingIndustry(IndustryID i)
Marks all disasters targeting this industry in such a way they won't call Industry::Get(v->dest_tile)...
uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
int8 y_offs
y offset for vehicle sprite
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Disasters, like submarines, skyrangers and their shadows, belong to this class.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Direction direction
facing
@ MP_TREES
Tile got trees.
@ ST_HELICOPTER_SHADOW
Shadow of helicopter.
@ ST_SMALL_SUBMARINE
Small submarine, pops up in the oceans but doesn't do anything.
static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
(Big) Ufo handling, v->current_order.dest states: 0: Fly around to the middle of the map,...
byte x_extent
x-extent of vehicle bounding box
uint32 StringID
Numeric value that represents a string, independent of the selected language.
@ ST_BIG_UFO_DESTROYER_SHADOW
Shadow of the aircraft.
CompanyID _current_company
Company currently doing an action.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static bool DisasterTick_Helicopter_Rotors(DisasterVehicle *v)
Helicopter rotor blades; keep these spinning.
@ ST_AIRPLANE_SHADOW
Shadow of airplane.
static bool DisasterTick_Ufo(DisasterVehicle *v)
(Small) Ufo handling, v->current_order.dest states: 0: Fly around to the middle of the map,...
byte tick_counter
Increased by one for each tick.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
int8 x_offs
x offset for vehicle sprite
void Restore()
Restore the variable.
byte z_extent
z-extent of vehicle bounding box
@ ST_HELICOPTER
Helicopter destroying a factory.
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
TileIndex tile
The base tile of the area.
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
@ TRANSPORT_WATER
Transport over water.
void ReleaseDisastersTargetingVehicle(VehicleID vehicle)
Notify disasters that we are about to delete a vehicle.
@ OWNER_NONE
The tile has no ownership.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Position information of a vehicle after it moved.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
@ NT_ACCIDENT
An accident or disaster has occurred.
uint16 crashed_ctr
Animation counter when the vehicle has crashed.
@ DIRDIFF_90RIGHT
Angle of 90 degrees right.
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
static Pool::IterateWrapper< RoadVehicle > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
byte breakdown_delay
Counter for managing breakdown length.
Year min_year
The first year this disaster will occur.
uint32 VehicleID
The type all our vehicle IDs have.
TrackBits
Bitfield corresponding to Track.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
@ VS_UNCLICKABLE
Vehicle is not clickable by the user (shadow vehicles).
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
#define lengthof(x)
Return the length of an fixed size array.
@ ST_HELICOPTER_ROTORS
Rotors of helicopter.
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
uint16 _disaster_delay
Delay counter for considering the next disaster.
@ INDUSTRYBEH_CHOPPER_ATTACKS
can be exploded by a military helicopter (factory)
ConstructionSettings construction
construction of things in-game
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
@ ST_BIG_UFO_DESTROYER
Aircraft the will bomb the big UFO.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
IndustryBehaviour
Various industry behaviours mostly to represent original TTD specialities.
VehicleType type
Type of vehicle.
@ ST_BIG_UFO
Big UFO, finds a piece of railroad to "park" on.
void UpdatePositionAndViewport()
Update the position of the vehicle, and update the viewport.
void UpdatePosition()
Update the position of the vehicle.
int y
x and y position of the vehicle after moving
@ ST_ZEPPELINER_SHADOW
Shadow of the zeppelin.
DisasterVehicle()
For use by saveload.
static bool DisasterTick_Helicopter(DisasterVehicle *v)
Helicopter handling.
@ OWNER_WATER
The tile/execution is done by "water".
#define CLRBITS(x, y)
Clears several bits in a variable.
DisasterInitProc * init_proc
The init function for this disaster.
@ VS_SHADOW
Vehicle is a shadow vehicle.
Year max_year
The last year this disaster will occur.
@ ST_SMALL_UFO
Small UFO, tries to find a road vehicle to destroy.
@ CMD_LANDSCAPE_CLEAR
demolish a tile
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
static const int ROTOR_Z_OFFSET
Z Offset between helicopter- and rotorsprite.
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.