|
OpenTTD Source 20260218-master-g2123fca5ea
|
All disaster/easter egg vehicles are handled here. More...
#include "stdafx.h"#include "aircraft.h"#include "disaster_vehicle.h"#include "industry.h"#include "station_base.h"#include "command_func.h"#include "news_func.h"#include "town.h"#include "company_func.h"#include "strings_func.h"#include "viewport_func.h"#include "vehicle_func.h"#include "sound_func.h"#include "effectvehicle_func.h"#include "roadveh.h"#include "train.h"#include "ai/ai.hpp"#include "game/game.hpp"#include "company_base.h"#include "core/random_func.hpp"#include "core/backup_type.hpp"#include "landscape_cmd.h"#include "timer/timer.h"#include "timer/timer_game_economy.h"#include "table/strings.h"#include "safeguards.h"Go to the source code of this file.
Data Structures | |
| struct | DisasterCreation |
| Initialisation function and time period to run the different disasters. More... | |
Typedefs | |
| using | DisasterVehicleTickProc = bool(DisasterVehicle *v) |
| Perform any actions for a given vehicle. | |
| typedef void | DisasterInitProc() |
Functions | |
| static void | DisasterClearSquare (TileIndex tile) |
| static bool | DisasterTick_Zeppeliner (DisasterVehicle *v) |
| Zeppeliner handling, v->state states: 0: Zeppeliner initialization has found an airport, go there and crash 1: Create crash and animate falling down for extra dramatic effect 2: Create more smoke and leave debris on ground 2: Clear the runway after some time and remove crashed zeppeliner If not airport was found, only state 0 is reached until zeppeliner leaves map. | |
| static bool | DisasterTick_Ufo (DisasterVehicle *ufo) |
| (Small) Ufo handling, v->state states: 0: Fly around to the middle of the map, then randomly, after a while target a road vehicle 1: Home in on a road vehicle and crash it >:) If not road vehicle was found, only state 0 is used and Ufo disappears after a while | |
| static void | DestructIndustry (Industry *i) |
| static bool | DisasterTick_Aircraft (DisasterVehicle *v, uint16_t image_override, bool leave_at_top, StringID news_message, IndustryBehaviour behaviour) |
| Aircraft handling, v->state states: 0: Fly towards the targeted industry 1: If within 15 tiles, fire away rockets and destroy industry 2: Industry explosions 3: Fly out of the map If the industry was removed in the meantime just fly to the end of the map. | |
| static bool | DisasterTick_Airplane (DisasterVehicle *v) |
| Airplane handling. | |
| static bool | DisasterTick_Helicopter (DisasterVehicle *v) |
| Helicopter handling. | |
| static bool | DisasterTick_Helicopter_Rotors (DisasterVehicle *v) |
| Helicopter rotor blades; keep these spinning. | |
| static bool | DisasterTick_Big_Ufo (DisasterVehicle *v) |
| (Big) Ufo handling, v->state states: 0: Fly around to the middle of the map, then randomly for a while and home in on a piece of rail 1: Land there and breakdown all trains in a radius of 12 tiles; and now we wait... because as soon as the Ufo lands, a fighter jet, a Skyranger, is called to clear up the mess. | |
| static bool | DisasterTick_Big_Ufo_Destroyer (DisasterVehicle *v) |
| Skyranger destroying (Big) Ufo handling, v->state states: 0: Home in on landed Ufo and shoot it down. | |
| static bool | DisasterTick_Submarine (DisasterVehicle *v) |
| Submarine, v->state states: Unused, just float around aimlessly and pop up at different places, turning around. | |
| static bool | DisasterTick_NULL (DisasterVehicle *v) |
| No-op vehicle tick. | |
| static void | Disaster_Zeppeliner_Init () |
| Zeppeliner which crashes on an airport if one found, otherwise crashes on a random tile. | |
| 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 which it targets and then destroys. | |
| static void | Disaster_Airplane_Init () |
| static void | Disaster_Helicopter_Init () |
| Combat helicopter that destroys a factory. | |
| static void | Disaster_Big_Ufo_Init () |
| static void | Disaster_Submarine_Init (DisasterSubType subtype) |
| Initialise a submarine. | |
| static void | Disaster_Small_Submarine_Init () |
| static void | Disaster_Big_Submarine_Init () |
| static void | Disaster_CoalMine_Init () |
| Coal mine catastrophe, destroys a stretch of 30 tiles of land in a certain direction. | |
| static void | DoDisaster () |
| Create a random disaster, if there is one available. | |
| static void | ResetDisasterDelay () |
| Resets the introduction of the next disaster. | |
| void | StartupDisasters () |
| Starts up disasters. | |
| void | ReleaseDisastersTargetingIndustry (IndustryID i) |
| Marks all disasters targeting this industry in such a way they won't call Industry::Get(v->dest_tile) on invalid industry anymore. | |
| void | ReleaseDisasterVehicle (VehicleID vehicle) |
| Notify disasters that we are about to delete a vehicle. | |
Variables | |
| uint16_t | _disaster_delay |
| Delay counter for considering the next disaster. | |
| static const SpriteID | _disaster_images_1 [] = {SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP} |
| 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} |
| 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} |
| 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} |
| 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} |
| 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} |
| 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} |
| 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} |
| 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} |
| static const SpriteID *const | _disaster_images [] |
| static DisasterVehicleTickProc *const | _disastervehicle_tick_procs [] |
| static const DisasterCreation | _disasters [] |
| Table per disaster subtype when to create disasters, and how to create them. | |
| static const IntervalTimer< TimerGameEconomy > | _economy_disaster_daily ({TimerGameEconomy::Trigger::Day, TimerGameEconomy::Priority::Disaster}, [](auto) { if(--_disaster_delay !=0) return;ResetDisasterDelay();if(_settings_game.difficulty.disasters !=0) DoDisaster();}) |
| Daily trigger to check whether to add a new disaster. | |
All disaster/easter egg vehicles are handled here.
The general flow of control for the disaster vehicles is as follows:
Definition in file disaster_vehicle.cpp.
| typedef void DisasterInitProc() |
Definition at line 737 of file disaster_vehicle.cpp.
| using DisasterVehicleTickProc = bool(DisasterVehicle *v) |
Perform any actions for a given vehicle.
| v | The vehicle to check. |
true iff the vehicle still exists, i.e. has not been destroyed. Definition at line 718 of file disaster_vehicle.cpp.
|
static |
Definition at line 414 of file disaster_vehicle.cpp.
|
static |
Definition at line 784 of file disaster_vehicle.cpp.
|
static |
Definition at line 889 of file disaster_vehicle.cpp.
|
static |
Definition at line 839 of file disaster_vehicle.cpp.
|
static |
Coal mine catastrophe, destroys a stretch of 30 tiles of land in a certain direction.
Definition at line 899 of file disaster_vehicle.cpp.
References Accident, IndustrySpec::behaviour, CanSubsidence, GB(), GetEncodedString(), GetIndustrySpec(), IsValidTile(), Industry::location, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, TileDiffXY(), TileOffsByDiagDir(), Industry::town, and Industry::type.
|
static |
Combat helicopter that destroys a factory.
Definition at line 810 of file disaster_vehicle.cpp.
References IndustrySpec::behaviour, Chance16(), ChopperAttacks, DIR_SW, GetIndustrySpec(), Industry::location, Vehicle::SetNext(), ST_HELICOPTER, ST_HELICOPTER_ROTORS, ST_HELICOPTER_SHADOW, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, TILE_SIZE, TileY(), and Industry::type.
|
static |
Definition at line 882 of file disaster_vehicle.cpp.
|
static |
Ufo which flies around aimlessly from the middle of the map a bit until it locates a road vehicle which it targets and then destroys.
Definition at line 769 of file disaster_vehicle.cpp.
References Vehicle::dest_tile, DIR_SE, RandomTile, Vehicle::SetNext(), Map::SizeX(), Map::SizeY(), ST_SMALL_UFO, ST_SMALL_UFO_SHADOW, TILE_SIZE, TileX(), and TileXY().
|
static |
Initialise a submarine.
| subtype | The sub type of submarine. |
Definition at line 859 of file disaster_vehicle.cpp.
References _settings_game, DIR_NW, DIR_SE, HasBit(), IsWaterTile(), Map::MaxY(), RandomTileSeed(), TILE_SIZE, TileVirtXY(), and TileX().
|
static |
Zeppeliner which crashes on an airport if one found, otherwise crashes on a random tile.
Definition at line 744 of file disaster_vehicle.cpp.
References AT_LARGE, AT_SMALL, DIR_SE, INVALID_TILE, SpecializedStation< Station, false >::Iterate(), RandomTile, Vehicle::SetNext(), ST_ZEPPELINER, ST_ZEPPELINER_SHADOW, TILE_SIZE, and TileX().
|
static |
Definition at line 59 of file disaster_vehicle.cpp.
|
static |
Aircraft handling, v->state states: 0: Fly towards the targeted industry 1: If within 15 tiles, fire away rockets and destroy industry 2: Industry explosions 3: Fly out of the map If the industry was removed in the meantime just fly to the end of the map.
| v | The disaster vehicle. |
| image_override | The image at the time the aircraft is firing. |
| leave_at_top | True iff the vehicle leaves the map at the north side. |
| news_message | The string that's used as news message. |
| behaviour | Only attack industries that have this behaviour set. |
true iff the vehicle still exists, i.e. has not been destroyed. Definition at line 438 of file disaster_vehicle.cpp.
References _settings_client, Accident, Vehicle::age, CreateEffectVehicleAbove(), Vehicle::dest_tile, EV_EXPLOSION_SMALL, GB(), GetEncodedString(), GetIndustryIndex(), GetIndustrySpec(), GetNewVehiclePos(), HasBit(), DisasterVehicle::image_override, Industry, IsTileType(), Industry::location, Map::MaxX(), TimerGameConst< struct Calendar >::MIN_DATE, Map::SizeX(), SND_12_EXPLOSION, DisasterVehicle::state, Vehicle::tick_counter, OrthogonalTileArea::tile, TILE_SIZE, TileVirtXY(), TileX(), TileY(), Industry::town, DisasterVehicle::UpdatePosition(), Vehicle::x_pos, GetNewVehiclePosResult::y, and Vehicle::y_pos.
Referenced by DisasterTick_Airplane(), and DisasterTick_Helicopter().
|
static |
Airplane handling.
Perform any actions for a given vehicle.
| v | The vehicle to check. |
true iff the vehicle still exists, i.e. has not been destroyed. Definition at line 499 of file disaster_vehicle.cpp.
References AirplaneAttacks, and DisasterTick_Aircraft().
|
static |
(Big) Ufo handling, v->state states: 0: Fly around to the middle of the map, then randomly for a while and home in on a piece of rail 1: Land there and breakdown all trains in a radius of 12 tiles; and now we wait... because as soon as the Ufo lands, a fighter jet, a Skyranger, is called to clear up the mess.
Perform any actions for a given vehicle.
| v | The vehicle to check. |
true iff the vehicle still exists, i.e. has not been destroyed. Definition at line 531 of file disaster_vehicle.cpp.
References Accident, Vehicle::age, ClosestTownFromTile(), Crashed, Delta(), Vehicle::dest_tile, DIR_SW, Vehicle::direction, GetEncodedString(), GetNewVehiclePos(), GetSlopePixelZ(), Company::IsHumanID(), IsPlainRailTile(), IsValidTile(), TimerGameConst< struct Calendar >::MIN_DATE, RandomRange(), RandomTile, Vehicle::SetNext(), ST_BIG_UFO_DESTROYER, ST_BIG_UFO_DESTROYER_SHADOW, DisasterVehicle::state, Vehicle::tick_counter, Vehicle::tile, TILE_SIZE, TileX(), TileY(), DisasterVehicle::UpdatePosition(), Vehicle::x_pos, GetNewVehiclePosResult::y, Vehicle::y_pos, and Vehicle::z_pos.
|
static |
Skyranger destroying (Big) Ufo handling, v->state states: 0: Home in on landed Ufo and shoot it down.
Perform any actions for a given vehicle.
| v | The vehicle to check. |
true iff the vehicle still exists, i.e. has not been destroyed. Definition at line 633 of file disaster_vehicle.cpp.
References _settings_client, DisasterVehicle::big_ufo_destroyer_target, CreateEffectVehicleAbove(), CreateEffectVehicleRel(), Delta(), EV_EXPLOSION_LARGE, EV_EXPLOSION_SMALL, GB(), GetNewVehiclePos(), INVALID_TILE, Map::SizeX(), SND_12_EXPLOSION, DisasterVehicle::state, Vehicle::tick_counter, Vehicle::tile, TILE_SIZE, TileAddWrap(), DisasterVehicle::UpdatePosition(), Vehicle::x_pos, GetNewVehiclePosResult::y, and Vehicle::y_pos.
|
static |
Helicopter handling.
Perform any actions for a given vehicle.
| v | The vehicle to check. |
true iff the vehicle still exists, i.e. has not been destroyed. Definition at line 505 of file disaster_vehicle.cpp.
References ChopperAttacks, and DisasterTick_Aircraft().
|
static |
Helicopter rotor blades; keep these spinning.
Perform any actions for a given vehicle.
| v | The vehicle to check. |
true iff the vehicle still exists, i.e. has not been destroyed. Definition at line 511 of file disaster_vehicle.cpp.
References HasBit(), Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, Vehicle::tick_counter, and Vehicle::UpdatePositionAndViewport().
|
static |
No-op vehicle tick.
Perform any actions for a given vehicle.
| v | The vehicle to check. |
true iff the vehicle still exists, i.e. has not been destroyed. Definition at line 708 of file disaster_vehicle.cpp.
|
static |
Submarine, v->state states: Unused, just float around aimlessly and pop up at different places, turning around.
Perform any actions for a given vehicle.
| v | The vehicle to check. |
true iff the vehicle still exists, i.e. has not been destroyed. Definition at line 680 of file disaster_vehicle.cpp.
References Vehicle::age, Chance16(), ChangeDir(), DIRDIFF_90LEFT, DIRDIFF_90RIGHT, Vehicle::direction, DirToDiagDir(), GB(), GetNewVehiclePos(), GetTileTrackStatus(), HasBit(), IsValidTile(), Vehicle::tick_counter, Vehicle::tile, TileOffsByDiagDir(), TRACK_BIT_ALL, TrackStatusToTrackBits(), TRANSPORT_WATER, DisasterVehicle::UpdatePosition(), GetNewVehiclePosResult::y, and Vehicle::z_pos.
|
static |
(Small) Ufo handling, v->state states: 0: Fly around to the middle of the map, then randomly, after a while target a road vehicle 1: Home in on a road vehicle and crash it >:) If not road vehicle was found, only state 0 is used and Ufo disappears after a while
| ufo | Ufo to handle. |
Definition at line 319 of file disaster_vehicle.cpp.
References _settings_client, Accident, Vehicle::age, Vehicle::breakdown_ctr, Vehicle::breakdown_delay, RoadVehicle::Crash(), RoadVehicle::crashed_ctr, CreateEffectVehicleRel(), Delta(), Vehicle::dest_tile, Vehicle::direction, RoadVehicle::disaster_vehicle, EV_EXPLOSION_LARGE, GetEncodedString(), GetNewVehiclePos(), HasBit(), Hidden, DisasterVehicle::image_override, Vehicle::IsFrontEngine(), TimerGameConst< struct Calendar >::MIN_DATE, AI::NewEvent(), Game::NewEvent(), Vehicle::owner, RandomRange(), RandomTile, SND_12_EXPLOSION, DisasterVehicle::state, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::tick_counter, Vehicle::tile, TILE_SIZE, TileX(), TileY(), BaseVehicle::type, DisasterVehicle::UpdatePosition(), VEH_ROAD, Vehicle::vehstatus, Vehicle::x_pos, GetNewVehiclePosResult::y, Vehicle::y_pos, and Vehicle::z_pos.
|
static |
Zeppeliner handling, v->state states: 0: Zeppeliner initialization has found an airport, go there and crash 1: Create crash and animate falling down for extra dramatic effect 2: Create more smoke and leave debris on ground 2: Clear the runway after some time and remove crashed zeppeliner If not airport was found, only state 0 is reached until zeppeliner leaves map.
Perform any actions for a given vehicle.
| v | The vehicle to check. |
true iff the vehicle still exists, i.e. has not been destroyed. Definition at line 226 of file disaster_vehicle.cpp.
References _settings_client, Accident, Vehicle::age, Station::airport, Airport::blocks, CreateEffectVehicleRel(), EV_CRASH_SMOKE, EV_EXPLOSION_LARGE, EV_EXPLOSION_SMALL, GB(), BaseStation::GetByTile(), GetEncodedString(), GetNewVehiclePos(), GetSlopePixelZ(), GetStationIndex(), GetTileOwner(), HasBit(), DisasterVehicle::image_override, IsAirportTile(), IsValidTile(), TimerGameConst< struct Calendar >::MIN_DATE, AI::NewEvent(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), RunwayIn, Map::SizeY(), SND_12_EXPLOSION, DisasterVehicle::state, Vehicle::tick_counter, Vehicle::tile, TILE_SIZE, DisasterVehicle::UpdatePosition(), Vehicle::x_pos, GetNewVehiclePosResult::y, Vehicle::y_pos, Vehicle::z_pos, and Zeppeliner.
|
static |
Create a random disaster, if there is one available.
Definition at line 944 of file disaster_vehicle.cpp.
References _disasters, RandomRange(), and TimerGameCalendar::year.
| void ReleaseDisastersTargetingIndustry | ( | IndustryID | i | ) |
Marks all disasters targeting this industry in such a way they won't call Industry::Get(v->dest_tile) on invalid industry anymore.
| i | deleted industry |
Definition at line 986 of file disaster_vehicle.cpp.
References Vehicle::dest_tile, ST_AIRPLANE, ST_HELICOPTER, DisasterVehicle::state, and Vehicle::subtype.
| void ReleaseDisasterVehicle | ( | VehicleID | vehicle | ) |
Notify disasters that we are about to delete a vehicle.
So make them head elsewhere.
| vehicle | deleted vehicle |
Definition at line 1001 of file disaster_vehicle.cpp.
References Vehicle::age, Vehicle::dest_tile, GetAircraftFlightLevelBounds(), TimerGameConst< struct Calendar >::MIN_DATE, RandomTile, ST_SMALL_UFO, DisasterVehicle::state, Vehicle::subtype, and Vehicle::z_pos.
Referenced by Vehicle::PreDestructor().
|
static |
Resets the introduction of the next disaster.
Definition at line 960 of file disaster_vehicle.cpp.
References _disaster_delay, and GB().
Referenced by StartupDisasters().
| void StartupDisasters | ( | ) |
Starts up disasters.
Definition at line 976 of file disaster_vehicle.cpp.
References ResetDisasterDelay().
Referenced by _GenerateWorld().
| uint16_t _disaster_delay |
Delay counter for considering the next disaster.
Definition at line 57 of file disaster_vehicle.cpp.
Referenced by ResetDisasterDelay().
|
static |
Definition at line 102 of file disaster_vehicle.cpp.
|
static |
Definition at line 92 of file disaster_vehicle.cpp.
|
static |
Definition at line 93 of file disaster_vehicle.cpp.
|
static |
Definition at line 94 of file disaster_vehicle.cpp.
|
static |
Definition at line 95 of file disaster_vehicle.cpp.
|
static |
Definition at line 96 of file disaster_vehicle.cpp.
|
static |
Definition at line 97 of file disaster_vehicle.cpp.
|
static |
Definition at line 98 of file disaster_vehicle.cpp.
|
static |
Definition at line 99 of file disaster_vehicle.cpp.
|
static |
Definition at line 100 of file disaster_vehicle.cpp.
|
static |
Table per disaster subtype when to create disasters, and how to create them.
Definition at line 932 of file disaster_vehicle.cpp.
Referenced by DoDisaster().
|
static |
Definition at line 720 of file disaster_vehicle.cpp.