2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* @file disaster_cmd.cpp
|
2007-01-16 16:54:06 +00:00
|
|
|
* All disaster/easter egg vehicles are handled here.
|
|
|
|
* The general flow of control for the disaster vehicles is as follows:
|
|
|
|
* <ol>
|
|
|
|
* <li>Initialize the disaster in a disaster specific way (eg start position,
|
|
|
|
* possible target, etc.) Disaster_XXX_Init() function
|
|
|
|
* <li>Add a subtype to a disaster, which is an index into the function array
|
|
|
|
* that handles the vehicle's ticks.
|
|
|
|
* <li>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
|
|
|
|
* </ol>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2007-12-21 22:50:51 +00:00
|
|
|
|
2009-08-30 11:47:41 +00:00
|
|
|
#include "industry.h"
|
2009-06-24 17:39:54 +00:00
|
|
|
#include "station_base.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2008-03-28 08:53:36 +00:00
|
|
|
#include "news_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "town.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2011-02-07 22:29:47 +00:00
|
|
|
#include "viewport_func.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_func.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2008-04-20 11:12:07 +00:00
|
|
|
#include "effectvehicle_func.h"
|
2008-09-07 22:23:25 +00:00
|
|
|
#include "roadveh.h"
|
2009-02-05 17:38:47 +00:00
|
|
|
#include "ai/ai.hpp"
|
2011-12-19 20:59:36 +00:00
|
|
|
#include "game/game.hpp"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "company_base.h"
|
|
|
|
#include "core/random_func.hpp"
|
2010-05-31 20:22:57 +00:00
|
|
|
#include "core/backup_type.hpp"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2010-07-19 15:51:06 +00:00
|
|
|
/** Delay counter for considering the next disaster. */
|
|
|
|
uint16 _disaster_delay;
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
enum DisasterSubType {
|
2009-03-15 21:34:18 +00:00
|
|
|
ST_ZEPPELINER,
|
|
|
|
ST_ZEPPELINER_SHADOW,
|
|
|
|
ST_SMALL_UFO,
|
|
|
|
ST_SMALL_UFO_SHADOW,
|
|
|
|
ST_AIRPLANE,
|
|
|
|
ST_AIRPLANE_SHADOW,
|
|
|
|
ST_HELICOPTER,
|
|
|
|
ST_HELICOPTER_SHADOW,
|
|
|
|
ST_HELICOPTER_ROTORS,
|
|
|
|
ST_BIG_UFO,
|
|
|
|
ST_BIG_UFO_SHADOW,
|
|
|
|
ST_BIG_UFO_DESTROYER,
|
|
|
|
ST_BIG_UFO_DESTROYER_SHADOW,
|
|
|
|
ST_SMALL_SUBMARINE,
|
|
|
|
ST_BIG_SUBMARINE,
|
2007-01-16 16:54:06 +00:00
|
|
|
};
|
|
|
|
|
2011-02-02 22:01:01 +00:00
|
|
|
static const uint INITIAL_DISASTER_VEHICLE_ZPOS = 135; ///< Initial Z position of flying disaster vehicles.
|
|
|
|
|
2005-01-17 09:41:46 +00:00
|
|
|
static void DisasterClearSquare(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-03-05 21:20:22 +00:00
|
|
|
if (EnsureNoVehicleOnGround(tile).Failed()) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-29 15:12:40 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2005-01-17 09:41:46 +00:00
|
|
|
case MP_RAILWAY:
|
2009-07-27 11:59:36 +00:00
|
|
|
if (Company::IsHumanID(GetTileOwner(tile))) {
|
2010-06-05 12:16:12 +00:00
|
|
|
Backup<CompanyByte> cur_company(_current_company, OWNER_WATER, FILE_LINE);
|
2006-05-27 16:12:16 +00:00
|
|
|
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
2010-05-31 20:22:57 +00:00
|
|
|
cur_company.Restore();
|
2008-01-18 02:16:39 +00:00
|
|
|
|
|
|
|
/* update signals in buffer */
|
|
|
|
UpdateSignalsInBuffer();
|
2006-05-27 16:12:16 +00:00
|
|
|
}
|
2005-01-17 09:41:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_HOUSE: {
|
2010-06-05 12:16:12 +00:00
|
|
|
Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
|
2006-04-10 07:15:58 +00:00
|
|
|
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
2010-05-31 20:22:57 +00:00
|
|
|
cur_company.Restore();
|
2005-01-17 09:41:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-17 09:41:46 +00:00
|
|
|
case MP_TREES:
|
|
|
|
case MP_CLEAR:
|
2004-08-09 17:04:08 +00:00
|
|
|
DoClearSquare(tile);
|
2005-01-17 09:41:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
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};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static const SpriteID * const _disaster_images[] = {
|
2007-02-23 18:55:07 +00:00
|
|
|
_disaster_images_1, _disaster_images_1, ///< zeppeliner and zeppeliner shadow
|
|
|
|
_disaster_images_2, _disaster_images_2, ///< small ufo and small ufo shadow
|
|
|
|
_disaster_images_3, _disaster_images_3, ///< combat aircraft and shadow
|
|
|
|
_disaster_images_8, _disaster_images_8, _disaster_images_9, ///< combat helicopter, shadow and rotor
|
|
|
|
_disaster_images_6, _disaster_images_6, ///< big ufo and shadow
|
|
|
|
_disaster_images_7, _disaster_images_7, ///< skyranger and shadow
|
|
|
|
_disaster_images_4, _disaster_images_5, ///< small and big submarine sprites
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
static void DisasterVehicleUpdateImage(DisasterVehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-05-22 18:57:11 +00:00
|
|
|
SpriteID img = v->image_override;
|
2007-01-16 16:54:06 +00:00
|
|
|
if (img == 0) img = _disaster_images[v->subtype][v->direction];
|
2004-08-09 17:04:08 +00:00
|
|
|
v->cur_image = img;
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Initialize a disaster vehicle. These vehicles are of type VEH_DISASTER, are unclickable
|
2010-08-01 19:44:49 +00:00
|
|
|
* and owned by nobody
|
|
|
|
*/
|
2011-11-04 11:52:19 +00:00
|
|
|
static void InitializeDisasterVehicle(DisasterVehicle *v, int x, int y, int z, Direction direction, byte subtype)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
v->x_pos = x;
|
|
|
|
v->y_pos = y;
|
|
|
|
v->z_pos = z;
|
2005-06-25 06:15:43 +00:00
|
|
|
v->tile = TileVirtXY(x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->direction = direction;
|
|
|
|
v->subtype = subtype;
|
2007-05-01 16:35:14 +00:00
|
|
|
v->UpdateDeltaXY(INVALID_DIR);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->owner = OWNER_NONE;
|
|
|
|
v->vehstatus = VS_UNCLICKABLE;
|
2009-05-22 18:57:11 +00:00
|
|
|
v->image_override = 0;
|
2007-03-08 21:39:34 +00:00
|
|
|
v->current_order.Free();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DisasterVehicleUpdateImage(v);
|
2012-01-02 13:44:30 +00:00
|
|
|
VehicleUpdatePositionAndViewport(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 11:52:19 +00:00
|
|
|
static void SetDisasterVehiclePos(DisasterVehicle *v, int x, int y, int z)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
v->x_pos = x;
|
|
|
|
v->y_pos = y;
|
|
|
|
v->z_pos = z;
|
2005-06-25 06:15:43 +00:00
|
|
|
v->tile = TileVirtXY(x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DisasterVehicleUpdateImage(v);
|
2012-01-02 13:44:30 +00:00
|
|
|
VehicleUpdatePositionAndViewport(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *u = v->Next();
|
2009-03-17 00:47:01 +00:00
|
|
|
if (u != NULL) {
|
2007-11-19 18:38:10 +00:00
|
|
|
int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
|
|
|
|
int safe_y = Clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
u->x_pos = x;
|
2011-11-04 11:09:06 +00:00
|
|
|
u->y_pos = y - 1 - (max(z - GetSlopePixelZ(safe_x, safe_y), 0) >> 3);
|
2007-11-19 18:38:10 +00:00
|
|
|
safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
|
2011-11-04 10:18:13 +00:00
|
|
|
u->z_pos = GetSlopePixelZ(safe_x, safe_y);
|
2004-08-09 17:04:08 +00:00
|
|
|
u->direction = v->direction;
|
|
|
|
|
|
|
|
DisasterVehicleUpdateImage(u);
|
2012-01-02 13:44:30 +00:00
|
|
|
VehicleUpdatePositionAndViewport(u);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-08-30 13:03:56 +00:00
|
|
|
if ((u = u->Next()) != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
u->x_pos = x;
|
|
|
|
u->y_pos = y;
|
|
|
|
u->z_pos = z + 5;
|
2012-01-02 13:44:30 +00:00
|
|
|
VehicleUpdatePositionAndViewport(u);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2009-05-22 18:57:11 +00:00
|
|
|
static bool DisasterTick_Zeppeliner(DisasterVehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-16 16:54:06 +00:00
|
|
|
v->tick_counter++;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
if (v->current_order.GetDestination() < 2) {
|
2009-05-22 13:53:14 +00:00
|
|
|
if (HasBit(v->tick_counter, 0)) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-25 10:49:13 +00:00
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
if (v->current_order.GetDestination() == 1) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (++v->age == 38) {
|
2008-04-06 07:48:51 +00:00
|
|
|
v->current_order.SetDestination(2);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
|
2011-05-28 09:45:12 +00:00
|
|
|
if (GB(v->tick_counter, 0, 3) == 0) CreateEffectVehicleRel(v, 0, -17, 2, EV_CRASH_SMOKE);
|
2007-01-16 16:54:06 +00:00
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
} else if (v->current_order.GetDestination() == 0) {
|
2010-01-18 12:36:08 +00:00
|
|
|
if (IsValidTile(v->tile) && IsAirportTile(v->tile)) {
|
2008-04-06 07:48:51 +00:00
|
|
|
v->current_order.SetDestination(1);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
SetDParam(0, GetStationIndex(v->tile));
|
2009-05-24 16:52:42 +00:00
|
|
|
AddVehicleNewsItem(STR_NEWS_DISASTER_ZEPPELIN,
|
|
|
|
NS_ACCIDENT,
|
|
|
|
v->index); // Delete the news, when the zeppelin is gone
|
2011-11-29 23:15:35 +00:00
|
|
|
AI::NewEvent(GetTileOwner(v->tile), new ScriptEventDisasterZeppelinerCrashed(GetStationIndex(v->tile)));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-16 16:54:06 +00:00
|
|
|
|
2010-05-13 11:19:30 +00:00
|
|
|
if (v->y_pos >= (int)((MapSizeY() + 9) * TILE_SIZE - 1)) {
|
2009-05-22 13:53:14 +00:00
|
|
|
delete v;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
if (v->current_order.GetDestination() > 2) {
|
2009-05-22 13:53:14 +00:00
|
|
|
if (++v->age <= 13320) return true;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2010-01-18 12:36:08 +00:00
|
|
|
if (IsValidTile(v->tile) && IsAirportTile(v->tile)) {
|
2009-06-24 17:39:54 +00:00
|
|
|
Station *st = Station::GetByTile(v->tile);
|
2010-03-18 21:02:20 +00:00
|
|
|
CLRBITS(st->airport.flags, RUNWAY_IN_block);
|
2011-11-29 23:15:35 +00:00
|
|
|
AI::NewEvent(GetTileOwner(v->tile), new ScriptEventDisasterZeppelinerCleared(st->index));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos);
|
2008-12-26 21:16:15 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
int x = v->x_pos;
|
|
|
|
int y = v->y_pos;
|
2011-11-04 11:52:19 +00:00
|
|
|
int z = GetSlopePixelZ(x, y);
|
2007-01-16 16:54:06 +00:00
|
|
|
if (z < v->z_pos) z = v->z_pos - 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
SetDisasterVehiclePos(v, x, y, z);
|
|
|
|
|
|
|
|
if (++v->age == 1) {
|
2005-02-12 15:53:32 +00:00
|
|
|
CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE);
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayVehicleFx(SND_12_EXPLOSION, v);
|
2009-05-22 18:57:11 +00:00
|
|
|
v->image_override = SPR_BLIMP_CRASHING;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (v->age == 70) {
|
2009-05-22 18:57:11 +00:00
|
|
|
v->image_override = SPR_BLIMP_CRASHED;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (v->age <= 300) {
|
2007-01-16 16:54:06 +00:00
|
|
|
if (GB(v->tick_counter, 0, 3) == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 r = Random();
|
|
|
|
|
|
|
|
CreateEffectVehicleRel(v,
|
2005-07-20 15:29:28 +00:00
|
|
|
GB(r, 0, 4) - 7,
|
|
|
|
GB(r, 4, 4) - 7,
|
|
|
|
GB(r, 8, 3) + 5,
|
2005-02-12 15:53:32 +00:00
|
|
|
EV_EXPLOSION_SMALL);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} else if (v->age == 350) {
|
2008-04-06 07:48:51 +00:00
|
|
|
v->current_order.SetDestination(3);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
|
2010-01-18 12:36:08 +00:00
|
|
|
if (IsValidTile(v->tile) && IsAirportTile(v->tile)) {
|
2010-03-18 21:02:20 +00:00
|
|
|
SETBITS(Station::GetByTile(v->tile)->airport.flags, RUNWAY_IN_block);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
/**
|
|
|
|
* (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
|
|
|
|
*/
|
2009-05-22 18:57:11 +00:00
|
|
|
static bool DisasterTick_Ufo(DisasterVehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-05-22 18:57:11 +00:00
|
|
|
v->image_override = (HasBit(++v->tick_counter, 3)) ? SPR_UFO_SMALL_SCOUT_DARKER : SPR_UFO_SMALL_SCOUT;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
if (v->current_order.GetDestination() == 0) {
|
2007-01-16 16:54:06 +00:00
|
|
|
/* Fly around randomly */
|
2006-04-03 05:32:11 +00:00
|
|
|
int x = TileX(v->dest_tile) * TILE_SIZE;
|
|
|
|
int y = TileY(v->dest_tile) * TILE_SIZE;
|
2010-05-13 11:19:30 +00:00
|
|
|
if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= (int)TILE_SIZE) {
|
2004-08-09 17:04:08 +00:00
|
|
|
v->direction = GetDirectionTowards(v, x, y);
|
2007-02-25 10:49:13 +00:00
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
2009-05-22 13:53:14 +00:00
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
if (++v->age < 6) {
|
2005-07-13 19:51:31 +00:00
|
|
|
v->dest_tile = RandomTile();
|
2009-05-22 13:53:14 +00:00
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-04-06 07:48:51 +00:00
|
|
|
v->current_order.SetDestination(1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-02-02 23:06:38 +00:00
|
|
|
uint n = 0; // Total number of targetable road vehicles.
|
2009-05-26 22:45:48 +00:00
|
|
|
RoadVehicle *u;
|
|
|
|
FOR_ALL_ROADVEHICLES(u) {
|
2011-02-02 23:06:38 +00:00
|
|
|
if (u->IsFrontEngine()) n++;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-02 23:06:38 +00:00
|
|
|
if (n == 0) {
|
|
|
|
/* If there are no targetable road vehicles, destroy the UFO. */
|
|
|
|
delete v;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = RandomRange(n); // Choose one of them.
|
|
|
|
FOR_ALL_ROADVEHICLES(u) {
|
|
|
|
/* Find (n+1)-th road vehicle. */
|
|
|
|
if (u->IsFrontEngine() && (n-- == 0)) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Target it. */
|
|
|
|
v->dest_tile = u->index;
|
|
|
|
v->age = 0;
|
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2007-01-16 16:54:06 +00:00
|
|
|
/* Target a vehicle */
|
2009-06-06 16:54:22 +00:00
|
|
|
RoadVehicle *u = RoadVehicle::Get(v->dest_tile);
|
2011-01-19 18:44:13 +00:00
|
|
|
assert(u != NULL && u->type == VEH_ROAD && u->IsFrontEngine());
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
uint dist = Delta(v->x_pos, u->x_pos) + Delta(v->y_pos, u->y_pos);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
if (dist < TILE_SIZE && !(u->vehstatus & VS_HIDDEN) && u->breakdown_ctr == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
u->breakdown_ctr = 3;
|
|
|
|
u->breakdown_delay = 140;
|
|
|
|
}
|
|
|
|
|
|
|
|
v->direction = GetDirectionTowards(v, u->x_pos, u->y_pos);
|
2007-02-25 10:49:13 +00:00
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2011-11-04 11:52:19 +00:00
|
|
|
int z = v->z_pos;
|
2006-04-03 05:32:11 +00:00
|
|
|
if (dist <= TILE_SIZE && z > u->z_pos) z--;
|
2004-08-09 17:04:08 +00:00
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, z);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-04-18 22:10:36 +00:00
|
|
|
if (z <= u->z_pos && (u->vehstatus & VS_HIDDEN) == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age++;
|
2009-05-22 20:22:20 +00:00
|
|
|
if (u->crashed_ctr == 0) {
|
2009-12-04 20:29:46 +00:00
|
|
|
u->Crash();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-24 16:52:42 +00:00
|
|
|
AddVehicleNewsItem(STR_NEWS_DISASTER_SMALL_UFO,
|
|
|
|
NS_ACCIDENT,
|
|
|
|
u->index); // delete the news, when the roadvehicle is gone
|
2008-09-07 22:23:25 +00:00
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
AI::NewEvent(u->owner, new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO));
|
2011-12-19 20:59:36 +00:00
|
|
|
Game::NewEvent(new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
/* Destroy? */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (v->age > 50) {
|
2005-02-12 15:53:32 +00:00
|
|
|
CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE);
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayVehicleFx(SND_12_EXPLOSION, v);
|
2008-12-26 21:16:15 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DestructIndustry(Industry *i)
|
|
|
|
{
|
2009-03-17 00:47:01 +00:00
|
|
|
for (TileIndex tile = 0; tile != MapSize(); tile++) {
|
2011-12-09 16:11:42 +00:00
|
|
|
if (i->TileBelongsToIndustry(tile)) {
|
2006-04-10 15:09:56 +00:00
|
|
|
ResetIndustryConstructionStage(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
/**
|
2009-03-17 00:47:01 +00:00
|
|
|
* Aircraft handling, v->current_order.dest states:
|
|
|
|
* 0: Fly towards the targetted industry
|
2007-01-16 16:54:06 +00:00
|
|
|
* 1: If within 15 tiles, fire away rockets and destroy industry
|
2009-03-17 00:47:01 +00:00
|
|
|
* 2: Industry explosions
|
2007-01-16 16:54:06 +00:00
|
|
|
* 3: Fly out of the map
|
2009-03-17 00:47:01 +00:00
|
|
|
* If the industry was removed in the meantime just fly to the end of the map.
|
|
|
|
* @param v The disaster vehicle.
|
|
|
|
* @param image_override The image at the time the aircraft is firing.
|
|
|
|
* @param leave_at_top True iff the vehicle leaves the map at the north side.
|
|
|
|
* @param news_message The string that's used as news message.
|
|
|
|
* @param industry_flag Only attack industries that have this flag set.
|
2007-01-16 16:54:06 +00:00
|
|
|
*/
|
2009-05-22 18:57:11 +00:00
|
|
|
static bool DisasterTick_Aircraft(DisasterVehicle *v, uint16 image_override, bool leave_at_top, StringID news_message, IndustryBehaviour industry_flag)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
v->tick_counter++;
|
2009-05-22 18:57:11 +00:00
|
|
|
v->image_override = (v->current_order.GetDestination() == 1 && HasBit(v->tick_counter, 2)) ? image_override : 0;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-02-25 10:49:13 +00:00
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
|
|
|
|
2010-05-13 11:19:30 +00:00
|
|
|
if ((leave_at_top && gp.x < (-10 * (int)TILE_SIZE)) || (!leave_at_top && gp.x > (int)(MapSizeX() * TILE_SIZE + 9 * TILE_SIZE) - 1)) {
|
2008-12-26 21:16:15 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
if (v->current_order.GetDestination() == 2) {
|
2007-01-16 16:54:06 +00:00
|
|
|
if (GB(v->tick_counter, 0, 2) == 0) {
|
2009-06-06 10:40:16 +00:00
|
|
|
Industry *i = Industry::Get(v->dest_tile); // Industry destructor calls ReleaseDisastersTargetingIndustry, so this is valid
|
2010-01-04 18:21:07 +00:00
|
|
|
int x = TileX(i->location.tile) * TILE_SIZE;
|
|
|
|
int y = TileY(i->location.tile) * TILE_SIZE;
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 r = Random();
|
|
|
|
|
|
|
|
CreateEffectVehicleAbove(
|
2005-07-20 15:29:28 +00:00
|
|
|
GB(r, 0, 6) + x,
|
|
|
|
GB(r, 6, 6) + y,
|
|
|
|
GB(r, 12, 4),
|
2005-02-12 15:53:32 +00:00
|
|
|
EV_EXPLOSION_SMALL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
if (++v->age >= 55) v->current_order.SetDestination(3);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-04-06 07:48:51 +00:00
|
|
|
} else if (v->current_order.GetDestination() == 1) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (++v->age == 112) {
|
2008-04-06 07:48:51 +00:00
|
|
|
v->current_order.SetDestination(2);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
|
2009-06-06 10:40:16 +00:00
|
|
|
Industry *i = Industry::Get(v->dest_tile); // Industry destructor calls ReleaseDisastersTargetingIndustry, so this is valid
|
2004-08-09 17:04:08 +00:00
|
|
|
DestructIndustry(i);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, i->town->index);
|
2009-05-24 16:52:42 +00:00
|
|
|
AddIndustryNewsItem(news_message, NS_ACCIDENT, i->index); // delete the news, when the industry closes
|
2010-01-04 18:21:07 +00:00
|
|
|
SndPlayTileFx(SND_12_EXPLOSION, i->location.tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-04-06 07:48:51 +00:00
|
|
|
} else if (v->current_order.GetDestination() == 0) {
|
2010-10-08 21:23:41 +00:00
|
|
|
int x = v->x_pos + ((leave_at_top ? -15 : 15) * TILE_SIZE);
|
2009-03-17 00:47:01 +00:00
|
|
|
int y = v->y_pos;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 13:53:14 +00:00
|
|
|
if ((uint)x > MapMaxX() * TILE_SIZE - 1) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
TileIndex tile = TileVirtXY(x, y);
|
2009-05-22 13:53:14 +00:00
|
|
|
if (!IsTileType(tile, MP_INDUSTRY)) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
IndustryID ind = GetIndustryIndex(tile);
|
2006-03-24 08:00:45 +00:00
|
|
|
v->dest_tile = ind;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
if (GetIndustrySpec(Industry::Get(ind)->type)->behaviour & industry_flag) {
|
2008-04-06 07:48:51 +00:00
|
|
|
v->current_order.SetDestination(1);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
/** Airplane handling. */
|
2009-05-22 18:57:11 +00:00
|
|
|
static bool DisasterTick_Airplane(DisasterVehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-05-22 13:53:14 +00:00
|
|
|
return DisasterTick_Aircraft(v, SPR_F_15_FIRING, true, STR_NEWS_DISASTER_AIRPLANE_OIL_REFINERY, INDUSTRYBEH_AIRPLANE_ATTACKS);
|
2009-03-17 00:47:01 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
/** Helicopter handling. */
|
2009-05-22 18:57:11 +00:00
|
|
|
static bool DisasterTick_Helicopter(DisasterVehicle *v)
|
2009-03-17 00:47:01 +00:00
|
|
|
{
|
2009-05-22 13:53:14 +00:00
|
|
|
return DisasterTick_Aircraft(v, SPR_AH_64A_FIRING, false, STR_NEWS_DISASTER_HELICOPTER_FACTORY, INDUSTRYBEH_CHOPPER_ATTACKS);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
/** Helicopter rotor blades; keep these spinning */
|
2009-05-22 18:57:11 +00:00
|
|
|
static bool DisasterTick_Helicopter_Rotors(DisasterVehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-16 16:54:06 +00:00
|
|
|
v->tick_counter++;
|
2009-05-22 13:53:14 +00:00
|
|
|
if (HasBit(v->tick_counter, 0)) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-19 06:46:41 +00:00
|
|
|
if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2012-01-02 13:44:30 +00:00
|
|
|
VehicleUpdatePositionAndViewport(v);
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
/**
|
|
|
|
* (Big) Ufo handling, v->current_order.dest states:
|
2007-01-16 20:16:30 +00:00
|
|
|
* 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...
|
2007-01-16 16:54:06 +00:00
|
|
|
* because as soon as the Ufo lands, a fighter jet, a Skyranger, is called to clear up the mess
|
|
|
|
*/
|
2009-05-22 18:57:11 +00:00
|
|
|
static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
v->tick_counter++;
|
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
if (v->current_order.GetDestination() == 1) {
|
2006-04-23 19:35:36 +00:00
|
|
|
int x = TileX(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2;
|
|
|
|
int y = TileY(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2;
|
2007-11-26 16:01:29 +00:00
|
|
|
if (Delta(v->x_pos, x) + Delta(v->y_pos, y) >= 8) {
|
2004-08-09 17:04:08 +00:00
|
|
|
v->direction = GetDirectionTowards(v, x, y);
|
|
|
|
|
2007-02-25 10:49:13 +00:00
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
2009-05-22 13:53:14 +00:00
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-03-17 01:30:39 +00:00
|
|
|
if (!IsValidTile(v->dest_tile)) {
|
|
|
|
/* Make sure we don't land outside the map. */
|
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2009-03-17 01:30:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 11:52:19 +00:00
|
|
|
int z = GetSlopePixelZ(v->x_pos, v->y_pos);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (z < v->z_pos) {
|
|
|
|
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos - 1);
|
2009-05-22 13:53:14 +00:00
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
v->current_order.SetDestination(2);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
Vehicle *target;
|
|
|
|
FOR_ALL_VEHICLES(target) {
|
2010-12-14 21:26:03 +00:00
|
|
|
if (target->IsGroundVehicle()) {
|
2010-05-13 11:19:30 +00:00
|
|
|
if (Delta(target->x_pos, v->x_pos) + Delta(target->y_pos, v->y_pos) <= 12 * (int)TILE_SIZE) {
|
2009-05-22 18:57:11 +00:00
|
|
|
target->breakdown_ctr = 5;
|
|
|
|
target->breakdown_delay = 0xF0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
Town *t = ClosestTownFromTile(v->dest_tile, UINT_MAX);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, t->index);
|
2012-05-26 14:15:57 +00:00
|
|
|
AddTileNewsItem(STR_NEWS_DISASTER_BIG_UFO, NS_ACCIDENT, v->tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-01-09 14:59:02 +00:00
|
|
|
if (!Vehicle::CanAllocateItem(2)) {
|
2008-12-26 21:16:15 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *u = new DisasterVehicle();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-02-02 22:01:01 +00:00
|
|
|
InitializeDisasterVehicle(u, -6 * (int)TILE_SIZE, v->y_pos, INITIAL_DISASTER_VEHICLE_ZPOS, DIR_SW, ST_BIG_UFO_DESTROYER);
|
2009-05-22 18:57:11 +00:00
|
|
|
u->big_ufo_destroyer_target = v->index;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *w = new DisasterVehicle();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-08-30 13:09:44 +00:00
|
|
|
u->SetNext(w);
|
2010-05-13 12:42:56 +00:00
|
|
|
InitializeDisasterVehicle(w, -6 * (int)TILE_SIZE, v->y_pos, 0, DIR_SW, ST_BIG_UFO_DESTROYER_SHADOW);
|
2006-07-26 08:32:20 +00:00
|
|
|
w->vehstatus |= VS_SHADOW;
|
2008-04-06 07:48:51 +00:00
|
|
|
} else if (v->current_order.GetDestination() == 0) {
|
2006-04-03 05:32:11 +00:00
|
|
|
int x = TileX(v->dest_tile) * TILE_SIZE;
|
|
|
|
int y = TileY(v->dest_tile) * TILE_SIZE;
|
2010-05-13 11:19:30 +00:00
|
|
|
if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= (int)TILE_SIZE) {
|
2004-08-09 17:04:08 +00:00
|
|
|
v->direction = GetDirectionTowards(v, x, y);
|
2007-02-25 10:49:13 +00:00
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
2009-05-22 13:53:14 +00:00
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (++v->age < 6) {
|
2005-07-13 19:51:31 +00:00
|
|
|
v->dest_tile = RandomTile();
|
2009-05-22 13:53:14 +00:00
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-04-06 07:48:51 +00:00
|
|
|
v->current_order.SetDestination(1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
TileIndex tile_org = RandomTile();
|
|
|
|
TileIndex tile = tile_org;
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2009-05-18 01:26:23 +00:00
|
|
|
if (IsPlainRailTile(tile) &&
|
2009-06-23 12:11:35 +00:00
|
|
|
Company::IsHumanID(GetTileOwner(tile))) {
|
2005-06-04 11:56:32 +00:00
|
|
|
break;
|
2006-03-19 13:48:08 +00:00
|
|
|
}
|
2007-01-16 16:54:06 +00:00
|
|
|
tile = TILE_MASK(tile + 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
} while (tile != tile_org);
|
|
|
|
v->dest_tile = tile;
|
|
|
|
v->age = 0;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
/**
|
|
|
|
* Skyranger destroying (Big) Ufo handling, v->current_order.dest states:
|
|
|
|
* 0: Home in on landed Ufo and shoot it down
|
|
|
|
*/
|
2009-05-22 18:57:11 +00:00
|
|
|
static bool DisasterTick_Big_Ufo_Destroyer(DisasterVehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
v->tick_counter++;
|
|
|
|
|
2007-02-25 10:49:13 +00:00
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
|
|
|
|
2010-05-13 11:19:30 +00:00
|
|
|
if (gp.x > (int)(MapSizeX() * TILE_SIZE + 9 * TILE_SIZE) - 1) {
|
2008-12-26 21:16:15 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
if (v->current_order.GetDestination() == 0) {
|
2009-05-22 18:57:11 +00:00
|
|
|
Vehicle *u = Vehicle::Get(v->big_ufo_destroyer_target);
|
2010-05-13 11:19:30 +00:00
|
|
|
if (Delta(v->x_pos, u->x_pos) > (int)TILE_SIZE) return true;
|
2008-04-06 07:48:51 +00:00
|
|
|
v->current_order.SetDestination(1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-12 15:53:32 +00:00
|
|
|
CreateEffectVehicleRel(u, 0, 7, 8, EV_EXPLOSION_LARGE);
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayVehicleFx(SND_12_EXPLOSION, u);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-12-26 21:16:15 +00:00
|
|
|
delete u;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
for (int i = 0; i != 80; i++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 r = Random();
|
|
|
|
CreateEffectVehicleAbove(
|
2005-07-20 15:29:28 +00:00
|
|
|
GB(r, 0, 6) + v->x_pos - 32,
|
|
|
|
GB(r, 5, 6) + v->y_pos - 32,
|
2004-08-09 17:04:08 +00:00
|
|
|
0,
|
2005-02-12 15:53:32 +00:00
|
|
|
EV_EXPLOSION_SMALL);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-02-25 21:29:50 +00:00
|
|
|
for (int dy = -3; dy < 3; dy++) {
|
|
|
|
for (int dx = -3; dx < 3; dx++) {
|
|
|
|
TileIndex tile = TileAddWrap(v->tile, dx, dy);
|
|
|
|
if (tile != INVALID_TILE) DisasterClearSquare(tile);
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
/**
|
|
|
|
* Submarine, v->current_order.dest states:
|
|
|
|
* Unused, just float around aimlessly and pop up at different places, turning around
|
|
|
|
*/
|
2009-05-22 18:57:11 +00:00
|
|
|
static bool DisasterTick_Submarine(DisasterVehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
v->tick_counter++;
|
|
|
|
|
|
|
|
if (++v->age > 8880) {
|
2007-08-03 19:36:00 +00:00
|
|
|
delete v;
|
2009-05-22 13:53:14 +00:00
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 13:53:14 +00:00
|
|
|
if (!HasBit(v->tick_counter, 0)) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
TileIndex tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction));
|
2007-01-16 16:54:06 +00:00
|
|
|
if (IsValidTile(tile)) {
|
2008-02-20 17:49:50 +00:00
|
|
|
TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));
|
|
|
|
if (trackbits == TRACK_BIT_ALL && !Chance16(1, 90)) {
|
2007-02-25 10:49:13 +00:00
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
2007-01-16 16:54:06 +00:00
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
2009-05-22 13:53:14 +00:00
|
|
|
return true;
|
2007-01-16 16:54:06 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 08:16:31 +00:00
|
|
|
v->direction = ChangeDir(v->direction, GB(Random(), 0, 1) ? DIRDIFF_90RIGHT : DIRDIFF_90LEFT);
|
2009-05-22 13:53:14 +00:00
|
|
|
|
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
static bool DisasterTick_NULL(DisasterVehicle *v)
|
2009-05-22 13:53:14 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
typedef bool DisasterVehicleTickProc(DisasterVehicle *v);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = {
|
2007-01-16 16:54:06 +00:00
|
|
|
DisasterTick_Zeppeliner, DisasterTick_NULL,
|
|
|
|
DisasterTick_Ufo, DisasterTick_NULL,
|
|
|
|
DisasterTick_Airplane, DisasterTick_NULL,
|
|
|
|
DisasterTick_Helicopter, DisasterTick_NULL, DisasterTick_Helicopter_Rotors,
|
|
|
|
DisasterTick_Big_Ufo, DisasterTick_NULL, DisasterTick_Big_Ufo_Destroyer,
|
|
|
|
DisasterTick_NULL,
|
|
|
|
DisasterTick_Submarine,
|
|
|
|
DisasterTick_Submarine,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-22 13:53:14 +00:00
|
|
|
bool DisasterVehicle::Tick()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-05-22 13:53:14 +00:00
|
|
|
return _disastervehicle_tick_procs[this->subtype](this);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
typedef void DisasterInitProc();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Zeppeliner which crashes on a small airport if one found,
|
2010-08-01 19:44:49 +00:00
|
|
|
* otherwise crashes on a random tile
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Disaster_Zeppeliner_Init()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-01-09 14:59:02 +00:00
|
|
|
if (!Vehicle::CanAllocateItem(2)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
/* Pick a random place, unless we find a small airport */
|
2009-01-09 14:59:02 +00:00
|
|
|
int x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2;
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
Station *st;
|
2005-01-06 22:31:58 +00:00
|
|
|
FOR_ALL_STATIONS(st) {
|
2010-03-18 21:02:20 +00:00
|
|
|
if (st->airport.tile != INVALID_TILE && (st->airport.type == AT_SMALL || st->airport.type == AT_LARGE)) {
|
2010-02-22 14:17:07 +00:00
|
|
|
x = (TileX(st->airport.tile) + 2) * TILE_SIZE;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *v = new DisasterVehicle();
|
2011-02-02 22:01:01 +00:00
|
|
|
InitializeDisasterVehicle(v, x, 0, INITIAL_DISASTER_VEHICLE_ZPOS, DIR_SE, ST_ZEPPELINER);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-01-09 14:59:02 +00:00
|
|
|
/* Allocate shadow */
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *u = new DisasterVehicle();
|
2009-01-09 14:59:02 +00:00
|
|
|
v->SetNext(u);
|
2009-03-15 21:34:18 +00:00
|
|
|
InitializeDisasterVehicle(u, x, 0, 0, DIR_SE, ST_ZEPPELINER_SHADOW);
|
2009-01-09 14:59:02 +00:00
|
|
|
u->vehstatus |= VS_SHADOW;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Ufo which flies around aimlessly from the middle of the map a bit
|
2010-08-01 19:44:49 +00:00
|
|
|
* until it locates a road vehicle which it targets and then destroys
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Disaster_Small_Ufo_Init()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-01-09 14:59:02 +00:00
|
|
|
if (!Vehicle::CanAllocateItem(2)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *v = new DisasterVehicle();
|
2009-01-09 14:59:02 +00:00
|
|
|
int x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-02-02 22:01:01 +00:00
|
|
|
InitializeDisasterVehicle(v, x, 0, INITIAL_DISASTER_VEHICLE_ZPOS, DIR_SE, ST_SMALL_UFO);
|
2005-06-25 16:44:57 +00:00
|
|
|
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
|
2009-01-09 14:59:02 +00:00
|
|
|
/* Allocate shadow */
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *u = new DisasterVehicle();
|
2009-01-09 14:59:02 +00:00
|
|
|
v->SetNext(u);
|
2009-03-15 21:34:18 +00:00
|
|
|
InitializeDisasterVehicle(u, x, 0, 0, DIR_SE, ST_SMALL_UFO_SHADOW);
|
2009-01-09 14:59:02 +00:00
|
|
|
u->vehstatus |= VS_SHADOW;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
|
|
|
|
/* Combat airplane which destroys an oil refinery */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Disaster_Airplane_Init()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-01-09 14:59:02 +00:00
|
|
|
if (!Vehicle::CanAllocateItem(2)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-01-09 14:59:02 +00:00
|
|
|
Industry *i, *found = NULL;
|
2004-12-30 10:03:35 +00:00
|
|
|
|
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
2007-03-28 20:06:28 +00:00
|
|
|
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) &&
|
2007-11-25 15:35:25 +00:00
|
|
|
(found == NULL || Chance16(1, 2))) {
|
2004-08-09 17:04:08 +00:00
|
|
|
found = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (found == NULL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *v = new DisasterVehicle();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
/* Start from the bottom (south side) of the map */
|
2009-01-09 14:59:02 +00:00
|
|
|
int x = (MapSizeX() + 9) * TILE_SIZE - 1;
|
2010-01-04 18:21:07 +00:00
|
|
|
int y = TileY(found->location.tile) * TILE_SIZE + 37;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-02-02 22:01:01 +00:00
|
|
|
InitializeDisasterVehicle(v, x, y, INITIAL_DISASTER_VEHICLE_ZPOS, DIR_NE, ST_AIRPLANE);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *u = new DisasterVehicle();
|
2009-01-09 14:59:02 +00:00
|
|
|
v->SetNext(u);
|
2009-03-15 21:34:18 +00:00
|
|
|
InitializeDisasterVehicle(u, x, y, 0, DIR_SE, ST_AIRPLANE_SHADOW);
|
2009-01-09 14:59:02 +00:00
|
|
|
u->vehstatus |= VS_SHADOW;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
|
|
|
|
/** Combat helicopter that destroys a factory */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Disaster_Helicopter_Init()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-01-09 14:59:02 +00:00
|
|
|
if (!Vehicle::CanAllocateItem(3)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-01-09 14:59:02 +00:00
|
|
|
Industry *i, *found = NULL;
|
2004-12-30 10:03:35 +00:00
|
|
|
|
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
2007-03-28 20:06:28 +00:00
|
|
|
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) &&
|
2007-11-25 15:35:25 +00:00
|
|
|
(found == NULL || Chance16(1, 2))) {
|
2004-08-09 17:04:08 +00:00
|
|
|
found = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (found == NULL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *v = new DisasterVehicle();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-05-13 12:42:56 +00:00
|
|
|
int x = -16 * (int)TILE_SIZE;
|
2010-01-04 18:21:07 +00:00
|
|
|
int y = TileY(found->location.tile) * TILE_SIZE + 37;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-02-02 22:01:01 +00:00
|
|
|
InitializeDisasterVehicle(v, x, y, INITIAL_DISASTER_VEHICLE_ZPOS, DIR_SW, ST_HELICOPTER);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *u = new DisasterVehicle();
|
2009-01-09 14:59:02 +00:00
|
|
|
v->SetNext(u);
|
2009-03-15 21:34:18 +00:00
|
|
|
InitializeDisasterVehicle(u, x, y, 0, DIR_SW, ST_HELICOPTER_SHADOW);
|
2009-01-09 14:59:02 +00:00
|
|
|
u->vehstatus |= VS_SHADOW;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *w = new DisasterVehicle();
|
2009-01-09 14:59:02 +00:00
|
|
|
u->SetNext(w);
|
2009-03-15 21:34:18 +00:00
|
|
|
InitializeDisasterVehicle(w, x, y, 140, DIR_SW, ST_HELICOPTER_ROTORS);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
|
|
|
|
/* Big Ufo which lands on a piece of rail and will consequently be shot
|
|
|
|
* down by a combat airplane, destroying the surroundings */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Disaster_Big_Ufo_Init()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-01-09 14:59:02 +00:00
|
|
|
if (!Vehicle::CanAllocateItem(2)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *v = new DisasterVehicle();
|
2009-01-09 14:59:02 +00:00
|
|
|
int x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2;
|
|
|
|
int y = MapMaxX() * TILE_SIZE - 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-02-02 22:01:01 +00:00
|
|
|
InitializeDisasterVehicle(v, x, y, INITIAL_DISASTER_VEHICLE_ZPOS, DIR_NW, ST_BIG_UFO);
|
2005-06-25 16:44:57 +00:00
|
|
|
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
|
2009-01-09 14:59:02 +00:00
|
|
|
/* Allocate shadow */
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *u = new DisasterVehicle();
|
2009-01-09 14:59:02 +00:00
|
|
|
v->SetNext(u);
|
2009-03-15 21:34:18 +00:00
|
|
|
InitializeDisasterVehicle(u, x, y, 0, DIR_NW, ST_BIG_UFO_SHADOW);
|
2009-01-09 14:59:02 +00:00
|
|
|
u->vehstatus |= VS_SHADOW;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
|
2009-03-15 21:29:07 +00:00
|
|
|
static void Disaster_Submarine_Init(DisasterSubType subtype)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-01-09 14:59:02 +00:00
|
|
|
if (!Vehicle::CanAllocateItem()) return;
|
|
|
|
|
|
|
|
int y;
|
2006-03-08 06:55:33 +00:00
|
|
|
Direction dir;
|
2009-01-09 14:59:02 +00:00
|
|
|
uint32 r = Random();
|
|
|
|
int x = TileX(r) * TILE_SIZE + TILE_SIZE / 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(r, 31)) {
|
2009-03-16 23:23:33 +00:00
|
|
|
y = MapMaxY() * TILE_SIZE - TILE_SIZE / 2 - 1;
|
2006-03-08 06:55:33 +00:00
|
|
|
dir = DIR_NW;
|
|
|
|
} else {
|
2006-04-23 19:35:36 +00:00
|
|
|
y = TILE_SIZE / 2;
|
2009-03-15 21:49:37 +00:00
|
|
|
if (_settings_game.construction.freeform_edges) y += TILE_SIZE;
|
2006-03-08 06:55:33 +00:00
|
|
|
dir = DIR_SE;
|
|
|
|
}
|
2009-03-15 21:49:37 +00:00
|
|
|
if (!IsWaterTile(TileVirtXY(x, y))) return;
|
2009-03-15 21:29:07 +00:00
|
|
|
|
2009-05-22 18:57:11 +00:00
|
|
|
DisasterVehicle *v = new DisasterVehicle();
|
2009-03-15 21:29:07 +00:00
|
|
|
InitializeDisasterVehicle(v, x, y, 0, dir, subtype);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
|
2009-03-15 21:29:07 +00:00
|
|
|
/* Curious submarine #1, just floats around */
|
|
|
|
static void Disaster_Small_Submarine_Init()
|
|
|
|
{
|
2009-03-15 21:34:18 +00:00
|
|
|
Disaster_Submarine_Init(ST_SMALL_SUBMARINE);
|
2009-03-15 21:29:07 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
|
|
|
|
/* Curious submarine #2, just floats around */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Disaster_Big_Submarine_Init()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-03-15 21:34:18 +00:00
|
|
|
Disaster_Submarine_Init(ST_BIG_SUBMARINE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:54:06 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Coal mine catastrophe, destroys a stretch of 30 tiles of
|
2010-08-01 19:44:49 +00:00
|
|
|
* land in a certain direction
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Disaster_CoalMine_Init()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-11-15 08:49:46 +00:00
|
|
|
int index = GB(Random(), 0, 4);
|
2005-11-15 11:46:49 +00:00
|
|
|
uint m;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-11-15 11:46:49 +00:00
|
|
|
for (m = 0; m < 15; m++) {
|
2007-01-16 16:54:06 +00:00
|
|
|
const Industry *i;
|
2006-02-06 09:18:04 +00:00
|
|
|
|
2004-12-30 10:03:35 +00:00
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
2007-03-28 20:06:28 +00:00
|
|
|
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CAN_SUBSIDENCE) && --index < 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, i->town->index);
|
2012-05-26 14:15:57 +00:00
|
|
|
AddTileNewsItem(STR_NEWS_DISASTER_COAL_MINE_SUBSIDENCE, NS_ACCIDENT, i->location.tile + TileDiffXY(1, 1)); // keep the news, even when the mine closes
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-01-04 18:21:07 +00:00
|
|
|
TileIndex tile = i->location.tile;
|
2007-07-24 13:03:24 +00:00
|
|
|
TileIndexDiff step = TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2));
|
2005-06-24 12:38:35 +00:00
|
|
|
|
2009-01-03 16:27:52 +00:00
|
|
|
for (uint n = 0; n < 30; n++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DisasterClearSquare(tile);
|
2009-01-03 16:27:52 +00:00
|
|
|
tile += step;
|
|
|
|
if (!IsValidTile(tile)) break;
|
2005-11-15 11:46:49 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2005-11-15 11:46:49 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
struct Disaster {
|
|
|
|
DisasterInitProc *init_proc; ///< The init function for this disaster.
|
|
|
|
Year min_year; ///< The first year this disaster will occur.
|
|
|
|
Year max_year; ///< The last year this disaster will occur.
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
static const Disaster _disasters[] = {
|
|
|
|
{Disaster_Zeppeliner_Init, 1930, 1955}, // zeppeliner
|
|
|
|
{Disaster_Small_Ufo_Init, 1940, 1970}, // ufo (small)
|
|
|
|
{Disaster_Airplane_Init, 1960, 1990}, // airplane
|
|
|
|
{Disaster_Helicopter_Init, 1970, 2000}, // helicopter
|
|
|
|
{Disaster_Big_Ufo_Init, 2000, 2100}, // ufo (big)
|
|
|
|
{Disaster_Small_Submarine_Init, 1940, 1965}, // submarine (small)
|
|
|
|
{Disaster_Big_Submarine_Init, 1975, 2010}, // submarine (big)
|
|
|
|
{Disaster_CoalMine_Init, 1950, 1985}, // coalmine
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void DoDisaster()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-03-17 00:47:01 +00:00
|
|
|
byte buf[lengthof(_disasters)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-24 22:00:11 +00:00
|
|
|
byte j = 0;
|
2009-03-17 00:47:01 +00:00
|
|
|
for (size_t i = 0; i != lengthof(_disasters); i++) {
|
2009-03-24 22:00:11 +00:00
|
|
|
if (_cur_year >= _disasters[i].min_year && _cur_year < _disasters[i].max_year) buf[j++] = (byte)i;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (j == 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-17 00:47:01 +00:00
|
|
|
_disasters[buf[RandomRange(j)]].init_proc();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void ResetDisasterDelay()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-03 21:20:01 +00:00
|
|
|
_disaster_delay = GB(Random(), 0, 9) + 730;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void DisasterDailyLoop()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
if (--_disaster_delay != 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
ResetDisasterDelay();
|
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.difficulty.disasters != 0) DoDisaster();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void StartupDisasters()
|
2005-01-22 20:23:18 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
ResetDisasterDelay();
|
|
|
|
}
|
2007-05-01 16:35:14 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Marks all disasters targeting this industry in such a way
|
2009-05-16 23:34:14 +00:00
|
|
|
* they won't call Industry::Get(v->dest_tile) on invalid industry anymore.
|
2008-12-26 19:37:50 +00:00
|
|
|
* @param i deleted industry
|
|
|
|
*/
|
|
|
|
void ReleaseDisastersTargetingIndustry(IndustryID i)
|
|
|
|
{
|
2009-05-26 22:45:48 +00:00
|
|
|
DisasterVehicle *v;
|
|
|
|
FOR_ALL_DISASTERVEHICLES(v) {
|
2008-12-26 19:37:50 +00:00
|
|
|
/* primary disaster vehicles that have chosen target */
|
2009-05-26 22:45:48 +00:00
|
|
|
if (v->subtype == ST_AIRPLANE || v->subtype == ST_HELICOPTER) {
|
2008-12-26 19:37:50 +00:00
|
|
|
/* if it has chosen target, and it is this industry (yes, dest_tile is IndustryID here), set order to "leaving map peacefully" */
|
|
|
|
if (v->current_order.GetDestination() > 0 && v->dest_tile == i) v->current_order.SetDestination(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Notify disasters that we are about to delete a vehicle. So make them head elsewhere.
|
2009-06-06 14:46:50 +00:00
|
|
|
* @param vehicle deleted vehicle
|
|
|
|
*/
|
|
|
|
void ReleaseDisastersTargetingVehicle(VehicleID vehicle)
|
|
|
|
{
|
|
|
|
DisasterVehicle *v;
|
|
|
|
FOR_ALL_DISASTERVEHICLES(v) {
|
|
|
|
/* primary disaster vehicles that have chosen target */
|
|
|
|
if (v->subtype == ST_SMALL_UFO) {
|
|
|
|
if (v->current_order.GetDestination() != 0 && v->dest_tile == vehicle) {
|
|
|
|
/* Revert to target-searching */
|
|
|
|
v->current_order.SetDestination(0);
|
|
|
|
v->dest_tile = RandomTile();
|
2011-02-02 22:01:01 +00:00
|
|
|
v->z_pos = INITIAL_DISASTER_VEHICLE_ZPOS;
|
2009-06-06 14:46:50 +00:00
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-01 16:35:14 +00:00
|
|
|
void DisasterVehicle::UpdateDeltaXY(Direction direction)
|
|
|
|
{
|
|
|
|
this->x_offs = -1;
|
|
|
|
this->y_offs = -1;
|
2008-04-01 14:03:20 +00:00
|
|
|
this->x_extent = 2;
|
|
|
|
this->y_extent = 2;
|
|
|
|
this->z_extent = 5;
|
2007-05-01 16:35:14 +00:00
|
|
|
}
|