51 #include "table/strings.h" 58 static void DisasterClearSquare(
TileIndex tile)
91 static const SpriteID _disaster_images_1[] = {SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP};
92 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};
93 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};
94 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};
95 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};
96 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};
97 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};
98 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};
99 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};
101 static const SpriteID *
const _disaster_images[] = {
102 _disaster_images_1, _disaster_images_1,
103 _disaster_images_2, _disaster_images_2,
104 _disaster_images_3, _disaster_images_3,
105 _disaster_images_8, _disaster_images_8, _disaster_images_9,
106 _disaster_images_6, _disaster_images_6,
107 _disaster_images_7, _disaster_images_7,
108 _disaster_images_4, _disaster_images_5,
111 void DisasterVehicle::UpdateImage()
198 u->
y_pos = y - 1 - (
max(z - GetSlopePixelZ(safe_x, safe_y), 0) >> 3);
200 u->
z_pos = GetSlopePixelZ(safe_x, safe_y);
206 if ((u = u->
Next()) != NULL) {
235 if (++v->
age == 38) {
262 if (++v->
age <= 13320)
return true;
277 int z = GetSlopePixelZ(x, y);
285 }
else if (v->
age == 70) {
287 }
else if (v->
age <= 300) {
297 }
else if (v->
age == 350) {
324 v->
direction = GetDirectionTowards(v, x, y);
337 FOR_ALL_ROADVEHICLES(u) {
348 FOR_ALL_ROADVEHICLES(u) {
373 if (dist <= TILE_SIZE && z > u->
z_pos) z--;
400 static void DestructIndustry(
Industry *i)
431 if ((leave_at_top && gp.x < (-10 * (
int)
TILE_SIZE)) || (!leave_at_top && gp.x > (
int)(
MapSizeX() * TILE_SIZE + 9 * TILE_SIZE) - 1)) {
452 if (++v->
age == 112) {
464 int x = v->
x_pos + ((leave_at_top ? -15 : 15) * TILE_SIZE);
467 if ((uint)x >
MapMaxX() * TILE_SIZE - 1)
return true;
503 if (++cur_image > SPR_ROTOR_MOVING_3) cur_image = SPR_ROTOR_MOVING_1;
524 v->
direction = GetDirectionTowards(v, x, y);
570 v->
direction = GetDirectionTowards(v, x, y);
590 }
while (tile != tile_org);
624 for (
int i = 0; i != 80; i++) {
633 for (
int dy = -3; dy < 3; dy++) {
634 for (
int dx = -3; dx < 3; dx++) {
652 if (++v->
age > 8880) {
682 static DisasterVehicleTickProc *
const _disastervehicle_tick_procs[] = {
696 return _disastervehicle_tick_procs[this->
subtype](
this);
699 typedef void DisasterInitProc();
714 FOR_ALL_STATIONS(st) {
747 static void Disaster_Airplane_Init()
753 FOR_ALL_INDUSTRIES(i) {
755 (found == NULL ||
Chance16(1, 2))) {
760 if (found == NULL)
return;
779 FOR_ALL_INDUSTRIES(i) {
781 (found == NULL ||
Chance16(1, 2))) {
786 if (found == NULL)
return;
802 static void Disaster_Big_Ufo_Init()
841 static void Disaster_Small_Submarine_Init()
848 static void Disaster_Big_Submarine_Init()
860 int index =
GB(Random(), 0, 4);
863 for (m = 0; m < 15; m++) {
866 FOR_ALL_INDUSTRIES(i) {
875 for (uint n = 0; n < 30; n++) {
876 DisasterClearSquare(tile);
888 DisasterInitProc *init_proc;
893 static const Disaster _disasters[] = {
896 {Disaster_Airplane_Init, 1960, 1990},
898 {Disaster_Big_Ufo_Init, 2000, 2100},
899 {Disaster_Small_Submarine_Init, 1940, 1965},
900 {Disaster_Big_Submarine_Init, 1975, 2010},
904 static void DoDisaster()
909 for (
size_t i = 0; i !=
lengthof(_disasters); i++) {
910 if (
_cur_year >= _disasters[i].min_year &&
_cur_year < _disasters[i].max_year) buf[j++] = (byte)i;
919 static void ResetDisasterDelay()
924 void DisasterDailyLoop()
928 ResetDisasterDelay();
933 void StartupDisasters()
935 ResetDisasterDelay();
Flag for an invalid direction.
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.
byte type
Type of this airport,.
#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.
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
DirectionByte direction
facing
static bool IsAirportTile(TileIndex t)
Is this tile a station tile and an airport tile?
void UpdateDeltaXY(Direction direction)
Updates the x and y offsets and the size of the sprite used for this vehicle.
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.
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.
Direction
Defines the 8 directions on the map.
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 #EffectVehicles/#TrainSubTypes/#AircraftSubTypes) ...
TrackBits
Bitfield corresponding to Track.
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...
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give 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.
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.
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.
The tile has no ownership.
static Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
int8 x_offs
x offset for vehicle sprite
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
DiagDirection
Enumeration for diagonal directions.
#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.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
Helicopter destroying a factory.
Angle of 90 degrees left.
execute the given command
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.
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
DestinationID GetDestination() const
Gets the destination of this order.
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.
CompanyByte _current_company
Company currently doing an action.
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.
OwnerByte owner
Which company owns the vehicle?
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.
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.
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).
#define FOR_ALL_DISASTERVEHICLES(var)
Iterate over disaster vehicles.
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.
void Restore()
Restore the variable.
Base functions for all AIs.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
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.
The tile/execution is done by "water".
VehicleTypeByte type
Type of vehicle.
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.
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.