OpenTTD
Data Structures | Typedefs | Functions | Variables
disaster_vehicle.cpp File Reference

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 "date_func.h"
#include "viewport_func.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "effectvehicle_func.h"
#include "roadveh.h"
#include "ai/ai.hpp"
#include "game/game.hpp"
#include "company_base.h"
#include "core/random_func.hpp"
#include "core/backup_type.hpp"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  Disaster
 

Typedefs

typedef bool DisasterVehicleTickProc(DisasterVehicle *v)
 
typedef void DisasterInitProc()
 

Functions

static void DisasterClearSquare (TileIndex tile)
 
static bool DisasterTick_Zeppeliner (DisasterVehicle *v)
 Zeppeliner handling, v->current_order.dest states: 0: Zeppeliner initialization has found a small 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 *v)
 (Small) Ufo handling, v->current_order.dest 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 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 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. More...
 
static bool DisasterTick_Airplane (DisasterVehicle *v)
 Airplane handling. More...
 
static bool DisasterTick_Helicopter (DisasterVehicle *v)
 Helicopter handling. More...
 
static bool DisasterTick_Helicopter_Rotors (DisasterVehicle *v)
 Helicopter rotor blades; keep these spinning.
 
static bool DisasterTick_Big_Ufo (DisasterVehicle *v)
 (Big) Ufo handling, v->current_order.dest 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... More...
 
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 shoot it down.
 
static bool DisasterTick_Submarine (DisasterVehicle *v)
 Submarine, v->current_order.dest states: Unused, just float around aimlessly and pop up at different places, turning around.
 
static bool DisasterTick_NULL (DisasterVehicle *v)
 
static void Disaster_Zeppeliner_Init ()
 Zeppeliner which crashes on a small 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)
 
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 ()
 
static void ResetDisasterDelay ()
 
void DisasterDailyLoop ()
 
void StartupDisasters ()
 
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. More...
 
void ReleaseDisastersTargetingVehicle (VehicleID vehicle)
 Notify disasters that we are about to delete a vehicle. More...
 

Variables

uint16 _disaster_delay
 Delay counter for considering the next disaster. More...
 
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 Disaster _disasters []
 

Detailed Description

All disaster/easter egg vehicles are handled here.

The general flow of control for the disaster vehicles is as follows:

  1. Initialize the disaster in a disaster specific way (eg start position, possible target, etc.) Disaster_XXX_Init() function
  2. Add a subtype to a disaster, which is an index into the function array that handles the vehicle's ticks.
  3. Run the disaster vehicles each tick until their target has been reached, this happens in the DisasterTick_XXX() functions. In here, a vehicle's state is kept by v->current_order.dest variable. Each achieved sub-target will increase this value, and the last one will remove the disaster itself

Definition in file disaster_vehicle.cpp.

Function Documentation

◆ DisasterTick_Aircraft()

static bool DisasterTick_Aircraft ( DisasterVehicle v,
uint16  image_override,
bool  leave_at_top,
StringID  news_message,
IndustryBehaviour  industry_flag 
)
static

Aircraft handling, v->current_order.dest 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.

Parameters
vThe disaster vehicle.
image_overrideThe image at the time the aircraft is firing.
leave_at_topTrue iff the vehicle leaves the map at the north side.
news_messageThe string that's used as news message.
industry_flagOnly attack industries that have this flag set.

Definition at line 423 of file disaster_vehicle.cpp.

References Vehicle::current_order, Order::GetDestination(), GetNewVehiclePos(), HasBit(), DisasterVehicle::image_override, Vehicle::tick_counter, DisasterVehicle::UpdatePosition(), and GetNewVehiclePosResult::y.

Referenced by DisasterTick_Airplane(), and DisasterTick_Helicopter().

◆ DisasterTick_Airplane()

static bool DisasterTick_Airplane ( DisasterVehicle v)
static

Airplane handling.

Definition at line 485 of file disaster_vehicle.cpp.

References DisasterTick_Aircraft().

◆ DisasterTick_Big_Ufo()

static bool DisasterTick_Big_Ufo ( DisasterVehicle v)
static

(Big) Ufo handling, v->current_order.dest 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

Definition at line 516 of file disaster_vehicle.cpp.

References Vehicle::current_order, Order::GetDestination(), and Vehicle::tick_counter.

◆ DisasterTick_Helicopter()

static bool DisasterTick_Helicopter ( DisasterVehicle v)
static

Helicopter handling.

Definition at line 491 of file disaster_vehicle.cpp.

References DisasterTick_Aircraft().

◆ ReleaseDisastersTargetingIndustry()

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.

Parameters
ideleted industry

Definition at line 943 of file disaster_vehicle.cpp.

References Vehicle::current_order, Vehicle::dest_tile, FOR_ALL_DISASTERVEHICLES, Order::GetDestination(), Order::SetDestination(), ST_AIRPLANE, ST_HELICOPTER, and Vehicle::subtype.

◆ ReleaseDisastersTargetingVehicle()

void ReleaseDisastersTargetingVehicle ( VehicleID  vehicle)

Notify disasters that we are about to delete a vehicle.

So make them head elsewhere.

Parameters
vehicledeleted vehicle

Definition at line 959 of file disaster_vehicle.cpp.

References Vehicle::age, Vehicle::current_order, Vehicle::dest_tile, FOR_ALL_DISASTERVEHICLES, GetAircraftFlightLevelBounds(), Order::GetDestination(), RandomTile, Order::SetDestination(), ST_SMALL_UFO, Vehicle::subtype, and Vehicle::z_pos.

Variable Documentation

◆ _disaster_delay

uint16 _disaster_delay

Delay counter for considering the next disaster.

Definition at line 56 of file disaster_vehicle.cpp.

◆ _disaster_images

const SpriteID* const _disaster_images[]
static
Initial value:
= {
_disaster_images_1, _disaster_images_1,
_disaster_images_2, _disaster_images_2,
_disaster_images_3, _disaster_images_3,
_disaster_images_8, _disaster_images_8, _disaster_images_9,
_disaster_images_6, _disaster_images_6,
_disaster_images_7, _disaster_images_7,
_disaster_images_4, _disaster_images_5,
}

Definition at line 101 of file disaster_vehicle.cpp.

◆ _disasters

const Disaster _disasters[]
static
Initial value:
= {
{Disaster_Zeppeliner_Init, 1930, 1955},
{Disaster_Small_Ufo_Init, 1940, 1970},
{Disaster_Airplane_Init, 1960, 1990},
{Disaster_Helicopter_Init, 1970, 2000},
{Disaster_Big_Ufo_Init, 2000, 2100},
{Disaster_Small_Submarine_Init, 1940, 1965},
{Disaster_Big_Submarine_Init, 1975, 2010},
{Disaster_CoalMine_Init, 1950, 1985},
}
static void Disaster_CoalMine_Init()
Coal mine catastrophe, destroys a stretch of 30 tiles of land in a certain direction.
static void Disaster_Zeppeliner_Init()
Zeppeliner which crashes on a small airport if one found, otherwise crashes on a random tile...
static void Disaster_Helicopter_Init()
Combat helicopter that destroys a factory.
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...

Definition at line 893 of file disaster_vehicle.cpp.

◆ _disastervehicle_tick_procs

DisasterVehicleTickProc* const _disastervehicle_tick_procs[]
static
Initial value:
= {
DisasterTick_Zeppeliner, DisasterTick_NULL,
DisasterTick_Ufo, DisasterTick_NULL,
DisasterTick_Airplane, DisasterTick_NULL,
DisasterTick_NULL,
}
static bool DisasterTick_Submarine(DisasterVehicle *v)
Submarine, v->current_order.dest states: Unused, just float around aimlessly and pop up at different ...
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...
static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
(Big) Ufo handling, v->current_order.dest states: 0: Fly around to the middle of the map...
static bool DisasterTick_Helicopter_Rotors(DisasterVehicle *v)
Helicopter rotor blades; keep these spinning.
static bool DisasterTick_Ufo(DisasterVehicle *v)
(Small) Ufo handling, v->current_order.dest states: 0: Fly around to the middle of the map...
static bool DisasterTick_Airplane(DisasterVehicle *v)
Airplane handling.
static bool DisasterTick_Helicopter(DisasterVehicle *v)
Helicopter handling.
static bool DisasterTick_Zeppeliner(DisasterVehicle *v)
Zeppeliner handling, v->current_order.dest states: 0: Zeppeliner initialization has found a small air...

Definition at line 682 of file disaster_vehicle.cpp.