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 - (
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);
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)
430 if ((leave_at_top && gp.x < (-10 * (
int)
TILE_SIZE)) || (!leave_at_top && gp.x > (
int)(
MapSizeX() * TILE_SIZE + 9 * TILE_SIZE) - 1)) {
451 if (++v->
age == 112) {
463 int x = v->
x_pos + ((leave_at_top ? -15 : 15) * TILE_SIZE);
466 if ((uint)x >
MapMaxX() * TILE_SIZE - 1)
return true;
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);
883 DisasterInitProc *init_proc;
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();
static RoadVehicle * Get(size_t index)
Gets vehicle with given index.
Functions related to OTTD's strings.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
#define RandomTile()
Get a valid random tile.
can be exploded by a military airplane (oil refinery)
static uint MapSizeX()
Get the size of the map along the X.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Airplane destroying an oil refinery.
Definition of stuff that is very close to a company, like the company struct itself.
Year max_year
The last year this disaster will occur.
Year min_year
The first year this disaster will occur.
static uint MapSizeY()
Get the size of the map along the Y.
Direction direction
facing
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
static bool IsAirportTile(TileIndex t)
Is this tile a station tile and an airport tile?
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
static bool DisasterTick_Submarine(DisasterVehicle *v)
Submarine, v->current_order.dest states: Unused, just float around aimlessly and pop up at different ...
int32 TileIndexDiff
An offset value between to tiles.
static Titem * Get(size_t index)
Returns Titem with given index.
Functions related to dates.
byte breakdown_delay
Counter for managing breakdown length.
Angle of 90 degrees right.
Vehicle is a shadow vehicle.
static const int ROTOR_Z_OFFSET
Z Offset between helicopter- and rotorsprite.
#define SETBITS(x, y)
Sets several bits in a variable.
TileIndex dest_tile
Heading for this tile.
Functions related to vehicles.
static bool IsHumanID(size_t index)
Is this company a company not controlled by a NoAI program?
static uint TileX(TileIndex tile)
Get the X component of a tile.
bool disasters
are disasters enabled
Defines the internal data of a functional industry.
can cause a subsidence (coal mine, shaft that collapses)
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
DifficultySettings difficulty
settings related to the difficulty
Tindex index
Index of this pool item.
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Small submarine, pops up in the oceans but doesn't do anything.
#define CLRBITS(x, y)
Clears several bits in a variable.
static void ResetIndustryConstructionStage(TileIndex tile)
Reset the construction stage counter of the industry, as well as the completion bit.
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...
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
static T max(const T a, const T b)
Returns the maximum of two values.
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
Year _cur_year
Current year, starting at 0.
static void Disaster_CoalMine_Init()
Coal mine catastrophe, destroys a stretch of 30 tiles of land in a certain direction.
static const uint TILE_SIZE
Tile size in world coordinates.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Class to backup a specific variable and restore it later.
can be exploded by a military helicopter (factory)
Functions related to (drawing on) viewports.
Pseudo random number generator.
Small UFO, tries to find a road vehicle to destroy.
bool freeform_edges
allow terraforming the tiles at the map edges
byte breakdown_ctr
Counter for managing breakdown events.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Buses, trucks and trams belong to this class.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
Big UFO, finds a piece of railroad to "park" on.
Class defining several overloaded accessors so we don't have to cast vehicle types that often...
The tile has no ownership.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
int y
x and y position of the vehicle after moving
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
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...
SoundSettings sound
sound effect settings
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...
int8 y_offs
y offset for vehicle sprite
uint32 VehicleID
The type all our vehicle IDs have.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
static void Disaster_Zeppeliner_Init()
Zeppeliner which crashes on a small airport if one found, otherwise crashes on a random tile...
DisasterVehicle * Next() const
Get next vehicle in the chain.
ClientSettings _settings_client
The current settings for this game.
DisasterVehicle()
For use by saveload.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
byte x_extent
x-extent of vehicle bounding box
IndustryType type
type of industry.
Direction
Defines the 8 directions on the map.
byte z_extent
z-extent of vehicle bounding box
static void Disaster_Helicopter_Init()
Combat helicopter that destroys a factory.
TileArea location
Location of the industry.
TrackBits
Bitfield corresponding to Track.
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...
bool IsFrontEngine() const
Check if the vehicle is a front engine.
TileIndex tile
Current tile index.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
int8 x_offs
x offset for vehicle sprite
Owner owner
Which company owns the vehicle?
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
#define lengthof(x)
Return the length of an fixed size array.
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
SpriteID image_override
Override for the default disaster vehicle sprite.
uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
(Big) Ufo handling, v->current_order.dest states: 0: Fly around to the middle of the map...
Functions related to sound.
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
byte tick_counter
Increased by one for each tick.
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
uint16 crashed_ctr
Animation counter when the vehicle has crashed.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Aircraft the will bomb the big UFO.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
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. ...
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
TileIndex tile
The base tile of the area.
Helicopter destroying a factory.
Angle of 90 degrees left.
execute the given command
The tile/execution is done by "water".
Functions related to companies.
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing...
void UpdatePosition()
Update the position of the vehicle.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
static uint MapSize()
Get the size of the map.
void UpdatePosition(int x, int y, int z)
Update the position of the vehicle.
VehicleID big_ufo_destroyer_target
The big UFO that this destroyer is supposed to bomb.
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
DestinationID GetDestination() const
Gets the destination of this order.
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.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
uint32 TileIndex
The index/ID of a Tile.
void ReleaseDisastersTargetingIndustry(IndustryID i)
Marks all disasters targeting this industry in such a way they won't call Industry::Get(v->dest_tile)...
Position information of a vehicle after it moved.
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
void Free()
'Free' the order
Disasters, like submarines, skyrangers and their shadows, belong to this class.
DisasterInitProc * init_proc
The init function for this disaster.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
VehicleType type
Type of vehicle.
void ReleaseDisastersTargetingVehicle(VehicleID vehicle)
Notify disasters that we are about to delete a vehicle.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
bool disaster
Play disaster and accident sounds.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Base functions for all Games.
Functions related to commands.
IndustryBehaviour
Various industry behaviours mostly to represent original TTD specialities.
An accident or disaster has occurred.
CompanyID _current_company
Company currently doing an action.
static bool DisasterTick_Ufo(DisasterVehicle *v)
(Small) Ufo handling, v->current_order.dest states: 0: Fly around to the middle of the map...
Zeppelin, crashes at airports.
void SetDestination(DestinationID destination)
Sets the destination of this order.
ConstructionSettings construction
construction of things in-game
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static Pool::IterateWrapper< RoadVehicle > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Airport airport
Tile area the airport covers.
byte y_extent
y-extent of vehicle bounding box
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
DiagDirection
Enumeration for diagonal directions.
void Restore()
Restore the variable.
Base functions for all AIs.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
static bool DisasterTick_Airplane(DisasterVehicle *v)
Airplane handling.
A tile without any structures, i.e. grass, rocks, farm fields etc.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Big submarine, pops up in the oceans but doesn't do anything.
SpriteID sprite
The 'real' sprite.
Functions related to news.
Base classes/functions for stations.
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
Class for backupping variables and making sure they are restored later.
Functions related to effect vehicles.
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
DisasterSubType
Different sub types of disaster vehicles.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static bool DisasterTick_Helicopter(DisasterVehicle *v)
Helicopter handling.
Order current_order
The current order (+ status, like: loading)
void UpdatePositionAndViewport()
Update the position of the vehicle, and update the viewport.
void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
static bool DisasterTick_Zeppeliner(DisasterVehicle *v)
Zeppeliner handling, v->current_order.dest states: 0: Zeppeliner initialization has found a small air...
Vehicle is not clickable by the user (shadow vehicles).
uint16 _disaster_delay
Delay counter for considering the next disaster.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
bool Tick()
Calls the tick handler of the vehicle.