2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "vehicle.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "news.h"
|
|
|
|
#include "station.h"
|
2005-09-17 13:57:01 +00:00
|
|
|
#include "waypoint.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "town.h"
|
|
|
|
#include "industry.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "airport_movement.h"
|
2004-11-05 23:12:33 +00:00
|
|
|
#include "sound.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2005-10-19 06:46:41 +00:00
|
|
|
#include "table/sprites.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-17 09:41:46 +00:00
|
|
|
static void DisasterClearSquare(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (!EnsureNoVehicle(tile))
|
|
|
|
return;
|
|
|
|
|
2005-01-29 15:12:40 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2005-01-17 09:41:46 +00:00
|
|
|
case MP_RAILWAY:
|
2005-09-17 13:57:01 +00:00
|
|
|
if (IS_HUMAN_PLAYER(GetTileOwner(tile)) && !IsRailWaypoint(_m[tile].m5)) DoClearSquare(tile);
|
2005-01-17 09:41:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_HOUSE: {
|
2005-09-17 13:57:01 +00:00
|
|
|
PlayerID p = _current_player;
|
2005-01-17 09:41:46 +00:00
|
|
|
_current_player = OWNER_NONE;
|
|
|
|
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
|
|
|
_current_player = p;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const SpriteID _disaster_images_1[] = {0xF41,0xF41,0xF41,0xF41,0xF41,0xF41,0xF41,0xF41};
|
|
|
|
static const SpriteID _disaster_images_2[] = {0xF44,0xF44,0xF44,0xF44,0xF44,0xF44,0xF44,0xF44};
|
|
|
|
static const SpriteID _disaster_images_3[] = {0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E};
|
|
|
|
static const SpriteID _disaster_images_4[] = {0xF46,0xF46,0xF47,0xF47,0xF48,0xF48,0xF49,0xF49};
|
|
|
|
static const SpriteID _disaster_images_5[] = {0xF4A,0xF4A,0xF4B,0xF4B,0xF4C,0xF4C,0xF4D,0xF4D};
|
|
|
|
static const SpriteID _disaster_images_6[] = {0xF50,0xF50,0xF50,0xF50,0xF50,0xF50,0xF50,0xF50};
|
|
|
|
static const SpriteID _disaster_images_7[] = {0xF51,0xF51,0xF51,0xF51,0xF51,0xF51,0xF51,0xF51};
|
|
|
|
static const SpriteID _disaster_images_8[] = {0xF52,0xF52,0xF52,0xF52,0xF52,0xF52,0xF52,0xF52};
|
|
|
|
static const SpriteID _disaster_images_9[] = {0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E};
|
|
|
|
|
|
|
|
static const SpriteID * const _disaster_images[] = {
|
|
|
|
_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,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void DisasterVehicleUpdateImage(Vehicle *v)
|
|
|
|
{
|
|
|
|
int img = v->u.disaster.image_override;
|
|
|
|
if (img == 0)
|
|
|
|
img = _disaster_images[v->subtype][v->direction];
|
|
|
|
v->cur_image = img;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, byte direction, byte subtype)
|
|
|
|
{
|
|
|
|
v->type = VEH_Disaster;
|
|
|
|
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;
|
|
|
|
v->x_offs = -1;
|
|
|
|
v->y_offs = -1;
|
|
|
|
v->sprite_width = 2;
|
|
|
|
v->sprite_height = 2;
|
|
|
|
v->z_height = 5;
|
|
|
|
v->owner = OWNER_NONE;
|
|
|
|
v->vehstatus = VS_UNCLICKABLE;
|
|
|
|
v->u.disaster.image_override = 0;
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.type = OT_NOTHING;
|
|
|
|
v->current_order.flags = 0;
|
|
|
|
v->current_order.station = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DisasterVehicleUpdateImage(v);
|
|
|
|
VehiclePositionChanged(v);
|
|
|
|
BeginVehicleMove(v);
|
|
|
|
EndVehicleMove(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DeleteDisasterVeh(Vehicle *v)
|
|
|
|
{
|
|
|
|
DeleteVehicleChain(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z)
|
|
|
|
{
|
|
|
|
Vehicle *u;
|
|
|
|
int yt;
|
|
|
|
|
|
|
|
BeginVehicleMove(v);
|
|
|
|
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);
|
|
|
|
VehiclePositionChanged(v);
|
|
|
|
EndVehicleMove(v);
|
|
|
|
|
|
|
|
if ( (u=v->next) != NULL) {
|
|
|
|
BeginVehicleMove(u);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
u->x_pos = x;
|
|
|
|
u->y_pos = yt = y - 1 - (max(z - GetSlopeZ(x, y-1), 0) >> 3);
|
|
|
|
u->z_pos = GetSlopeZ(x,yt);
|
|
|
|
u->direction = v->direction;
|
|
|
|
|
|
|
|
DisasterVehicleUpdateImage(u);
|
|
|
|
VehiclePositionChanged(u);
|
|
|
|
EndVehicleMove(u);
|
|
|
|
|
|
|
|
if ( (u=u->next) != NULL) {
|
|
|
|
BeginVehicleMove(u);
|
|
|
|
u->x_pos = x;
|
|
|
|
u->y_pos = y;
|
|
|
|
u->z_pos = z + 5;
|
|
|
|
VehiclePositionChanged(u);
|
|
|
|
EndVehicleMove(u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void DisasterTick_Zeppeliner(Vehicle *v)
|
|
|
|
{
|
|
|
|
GetNewVehiclePosResult gp;
|
|
|
|
Station *st;
|
|
|
|
int x,y;
|
|
|
|
byte z;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
++v->tick_counter;
|
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
if (v->current_order.station < 2) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (v->tick_counter&1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GetNewVehiclePos(v, &gp);
|
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);
|
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
if (v->current_order.station == 1) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (++v->age == 38) {
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((v->tick_counter&7)==0) {
|
2005-02-12 15:53:32 +00:00
|
|
|
CreateEffectVehicleRel(v, 0, -17, 2, EV_SMOKE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-05 12:43:04 +00:00
|
|
|
} else if (v->current_order.station == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
tile = v->tile; /**/
|
|
|
|
|
2005-01-29 14:53:05 +00:00
|
|
|
if (IsValidTile(tile) &&
|
|
|
|
IsTileType(tile, MP_STATION) &&
|
2005-07-13 18:04:01 +00:00
|
|
|
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
|
2005-06-04 11:56:32 +00:00
|
|
|
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
SetDParam(0, _m[tile].m2);
|
2004-08-09 17:04:08 +00:00
|
|
|
AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT,
|
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
|
|
|
|
v->index,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
2005-01-03 19:09:45 +00:00
|
|
|
if (v->y_pos >= ((int)MapSizeY() + 9) * 16 - 1)
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteDisasterVeh(v);
|
|
|
|
return;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
if (v->current_order.station > 2) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (++v->age <= 13320)
|
|
|
|
return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
tile = v->tile; /**/
|
|
|
|
|
2005-01-29 14:53:05 +00:00
|
|
|
if (IsValidTile(tile) &&
|
|
|
|
IsTileType(tile, MP_STATION) &&
|
2005-07-13 18:04:01 +00:00
|
|
|
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
|
2005-06-04 11:56:32 +00:00
|
|
|
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
|
2005-07-13 18:04:01 +00:00
|
|
|
st = GetStation(_m[tile].m2);
|
2004-08-09 17:04:08 +00:00
|
|
|
CLRBITS(st->airport_flags, RUNWAY_IN_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos);
|
|
|
|
DeleteDisasterVeh(v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = v->x_pos;
|
|
|
|
y = v->y_pos;
|
|
|
|
z = GetSlopeZ(x,y);
|
|
|
|
if (z < v->z_pos)
|
|
|
|
z = v->z_pos - 1;
|
|
|
|
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);
|
2005-10-19 06:46:41 +00:00
|
|
|
v->u.disaster.image_override = SPR_BLIMP_CRASHING;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (v->age == 70) {
|
2005-10-19 06:46:41 +00:00
|
|
|
v->u.disaster.image_override = SPR_BLIMP_CRASHED;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (v->age <= 300) {
|
|
|
|
if (!(v->tick_counter&7)) {
|
|
|
|
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) {
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 3;
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tile = v->tile;/**/
|
2005-01-29 14:53:05 +00:00
|
|
|
if (IsValidTile(tile) &&
|
|
|
|
IsTileType(tile, MP_STATION) &&
|
2005-07-13 18:04:01 +00:00
|
|
|
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
|
2005-06-04 11:56:32 +00:00
|
|
|
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
st = GetStation(_m[tile].m2);
|
2004-08-09 17:04:08 +00:00
|
|
|
SETBITS(st->airport_flags, RUNWAY_IN_block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// UFO starts in the middle, and flies around a bit until it locates
|
|
|
|
// a road vehicle which it targets.
|
|
|
|
static void DisasterTick_UFO(Vehicle *v)
|
|
|
|
{
|
|
|
|
GetNewVehiclePosResult gp;
|
|
|
|
Vehicle *u;
|
|
|
|
uint dist;
|
|
|
|
byte z;
|
|
|
|
|
2005-10-19 06:46:41 +00:00
|
|
|
v->u.disaster.image_override = (++v->tick_counter & 8) ? SPR_UFO_SMALL_SCOUT_DARKER : SPR_UFO_SMALL_SCOUT;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
if (v->current_order.station == 0) {
|
2004-09-10 19:02:27 +00:00
|
|
|
// fly around randomly
|
2005-01-07 17:02:43 +00:00
|
|
|
int x = TileX(v->dest_tile) * 16;
|
|
|
|
int y = TileY(v->dest_tile) * 16;
|
2005-07-08 22:25:24 +00:00
|
|
|
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) {
|
2004-08-09 17:04:08 +00:00
|
|
|
v->direction = GetDirectionTowards(v, x, y);
|
|
|
|
GetNewVehiclePos(v, &gp);
|
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (++v->age < 6) {
|
2005-07-13 19:51:31 +00:00
|
|
|
v->dest_tile = RandomTile();
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
FOR_ALL_VEHICLES(u) {
|
|
|
|
if (u->type == VEH_Road && IS_HUMAN_PLAYER(u->owner)) {
|
|
|
|
v->dest_tile = u->index;
|
|
|
|
v->age = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteDisasterVeh(v);
|
|
|
|
} else {
|
|
|
|
// target a vehicle
|
2005-01-06 22:31:58 +00:00
|
|
|
u = GetVehicle(v->dest_tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (u->type != VEH_Road) {
|
|
|
|
DeleteDisasterVeh(v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dist = abs(v->x_pos - u->x_pos) + abs(v->y_pos - u->y_pos);
|
|
|
|
|
|
|
|
if (dist < 16 && !(u->vehstatus&VS_HIDDEN) && u->breakdown_ctr==0) {
|
|
|
|
u->breakdown_ctr = 3;
|
|
|
|
u->breakdown_delay = 140;
|
|
|
|
}
|
|
|
|
|
|
|
|
v->direction = GetDirectionTowards(v, u->x_pos, u->y_pos);
|
|
|
|
GetNewVehiclePos(v, &gp);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
z = v->z_pos;
|
|
|
|
if (dist <= 16 && z > u->z_pos) z--;
|
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, z);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (z <= u->z_pos && (u->vehstatus&VS_HIDDEN)==0) {
|
|
|
|
v->age++;
|
|
|
|
if (u->u.road.crashed_ctr == 0) {
|
|
|
|
u->u.road.crashed_ctr++;
|
|
|
|
u->vehstatus |= VS_CRASHED;
|
|
|
|
|
|
|
|
AddNewsItem(STR_B001_ROAD_VEHICLE_DESTROYED,
|
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
|
|
|
|
u->index,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// destroy?
|
|
|
|
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);
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteDisasterVeh(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DestructIndustry(Industry *i)
|
|
|
|
{
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-08 22:25:24 +00:00
|
|
|
for (tile = 0; tile != MapSize(); tile++) {
|
2005-07-13 18:04:01 +00:00
|
|
|
if (IsTileType(tile, MP_INDUSTRY) && _m[tile].m2 == i->index) {
|
2005-08-23 18:47:04 +00:00
|
|
|
_m[tile].m1 = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Airplane which destroys an oil refinery
|
|
|
|
static void DisasterTick_2(Vehicle *v)
|
|
|
|
{
|
|
|
|
GetNewVehiclePosResult gp;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
v->tick_counter++;
|
2004-12-05 12:43:04 +00:00
|
|
|
v->u.disaster.image_override =
|
2005-10-19 06:46:41 +00:00
|
|
|
(v->current_order.station == 1 && v->tick_counter&4) ? SPR_F_15_FIRING : 0;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
GetNewVehiclePos(v, &gp);
|
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
|
|
|
|
|
|
|
if (gp.x < -160) {
|
|
|
|
DeleteDisasterVeh(v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
if (v->current_order.station == 2) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!(v->tick_counter&3)) {
|
2005-01-06 22:31:58 +00:00
|
|
|
Industry *i = GetIndustry(v->dest_tile);
|
2005-01-07 17:02:43 +00:00
|
|
|
int x = TileX(i->xy) * 16;
|
|
|
|
int y = TileY(i->xy) * 16;
|
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
|
|
|
|
|
|
|
if (++v->age >= 55)
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 3;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-05 12:43:04 +00:00
|
|
|
} else if (v->current_order.station == 1) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (++v->age == 112) {
|
|
|
|
Industry *i;
|
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
i = GetIndustry(v->dest_tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
DestructIndustry(i);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, i->town->index);
|
2004-08-09 17:04:08 +00:00
|
|
|
AddNewsItem(STR_B002_OIL_REFINERY_EXPLOSION, NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy, 0);
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_12_EXPLOSION, i->xy);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-05 12:43:04 +00:00
|
|
|
} else if (v->current_order.station == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
int x,y;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
int ind;
|
|
|
|
|
|
|
|
x = v->x_pos - 15*16;
|
|
|
|
y = v->y_pos;
|
|
|
|
|
2005-01-03 18:59:58 +00:00
|
|
|
if ( (uint)x > MapMaxX() * 16-1)
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
|
2005-06-25 06:15:43 +00:00
|
|
|
tile = TileVirtXY(x, y);
|
2005-01-16 11:24:58 +00:00
|
|
|
if (!IsTileType(tile, MP_INDUSTRY))
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
v->dest_tile = ind = _m[tile].m2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
if (GetIndustry(ind)->type == IT_OIL_REFINERY) {
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helicopter which destroys a factory
|
|
|
|
static void DisasterTick_3(Vehicle *v)
|
|
|
|
{
|
|
|
|
GetNewVehiclePosResult gp;
|
|
|
|
|
|
|
|
v->tick_counter++;
|
2004-12-05 12:43:04 +00:00
|
|
|
v->u.disaster.image_override =
|
2005-10-19 06:46:41 +00:00
|
|
|
(v->current_order.station == 1 && v->tick_counter&4) ? SPR_AH_64A_FIRING : 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
GetNewVehiclePos(v, &gp);
|
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
|
|
|
|
2005-01-03 19:09:45 +00:00
|
|
|
if (gp.x > (int)MapSizeX() * 16 + 9*16 - 1) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteDisasterVeh(v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
if (v->current_order.station == 2) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!(v->tick_counter&3)) {
|
2005-01-06 22:31:58 +00:00
|
|
|
Industry *i = GetIndustry(v->dest_tile);
|
2005-01-07 17:02:43 +00:00
|
|
|
int x = TileX(i->xy) * 16;
|
|
|
|
int y = TileY(i->xy) * 16;
|
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
|
|
|
|
|
|
|
if (++v->age >= 55)
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 3;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-05 12:43:04 +00:00
|
|
|
} else if (v->current_order.station == 1) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (++v->age == 112) {
|
|
|
|
Industry *i;
|
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
i = GetIndustry(v->dest_tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
DestructIndustry(i);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, i->town->index);
|
2004-08-09 17:04:08 +00:00
|
|
|
AddNewsItem(STR_B003_FACTORY_DESTROYED_IN_SUSPICIOUS, NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy, 0);
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_12_EXPLOSION, i->xy);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-05 12:43:04 +00:00
|
|
|
} else if (v->current_order.station == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
int x,y;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
int ind;
|
|
|
|
|
|
|
|
x = v->x_pos - 15*16;
|
|
|
|
y = v->y_pos;
|
|
|
|
|
2005-01-03 18:59:58 +00:00
|
|
|
if ( (uint)x > MapMaxX() * 16-1)
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
|
2005-06-25 06:15:43 +00:00
|
|
|
tile = TileVirtXY(x, y);
|
2005-01-16 11:24:58 +00:00
|
|
|
if (!IsTileType(tile, MP_INDUSTRY))
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
v->dest_tile = ind = _m[tile].m2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
if (GetIndustry(ind)->type == IT_FACTORY) {
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helicopter rotor blades
|
|
|
|
static void DisasterTick_3b(Vehicle *v)
|
|
|
|
{
|
|
|
|
if (++v->tick_counter & 1)
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
|
|
|
VehiclePositionChanged(v);
|
|
|
|
BeginVehicleMove(v);
|
|
|
|
EndVehicleMove(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Big UFO which lands on a piece of rail.
|
|
|
|
// Will be shot down by a plane
|
|
|
|
static void DisasterTick_4(Vehicle *v)
|
|
|
|
{
|
|
|
|
GetNewVehiclePosResult gp;
|
|
|
|
byte z;
|
|
|
|
Vehicle *u,*w;
|
|
|
|
Town *t;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
|
|
|
TileIndex tile_org;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
v->tick_counter++;
|
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
if (v->current_order.station == 1) {
|
2005-01-07 17:02:43 +00:00
|
|
|
int x = TileX(v->dest_tile) * 16 + 8;
|
|
|
|
int y = TileY(v->dest_tile) * 16 + 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (abs(v->x_pos - x) + abs(v->y_pos - y) >= 8) {
|
|
|
|
v->direction = GetDirectionTowards(v, x, y);
|
|
|
|
|
|
|
|
GetNewVehiclePos(v, &gp);
|
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
z = GetSlopeZ(v->x_pos, v->y_pos);
|
|
|
|
if (z < v->z_pos) {
|
|
|
|
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos - 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
FOR_ALL_VEHICLES(u) {
|
|
|
|
if (u->type == VEH_Train || u->type == VEH_Road) {
|
|
|
|
if (abs(u->x_pos - v->x_pos) + abs(u->y_pos - v->y_pos) <= 12*16) {
|
|
|
|
u->breakdown_ctr = 5;
|
|
|
|
u->breakdown_delay = 0xF0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t = ClosestTownFromTile(v->dest_tile, (uint)-1);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, t->index);
|
2004-08-09 17:04:08 +00:00
|
|
|
AddNewsItem(STR_B004_UFO_LANDS_NEAR,
|
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ACCIDENT, 0),
|
|
|
|
v->tile,
|
|
|
|
0);
|
|
|
|
|
|
|
|
u = ForceAllocateSpecialVehicle();
|
|
|
|
if (u == NULL) {
|
|
|
|
DeleteDisasterVeh(v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
InitializeDisasterVehicle(u, -6*16, v->y_pos, 135, 5, 11);
|
|
|
|
u->u.disaster.unk2 = v->index;
|
|
|
|
|
|
|
|
w = ForceAllocateSpecialVehicle();
|
|
|
|
if (w == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
u->next = w;
|
|
|
|
InitializeDisasterVehicle(w, -6*16, v->y_pos, 0, 5, 12);
|
|
|
|
w->vehstatus |= VS_DISASTER;
|
2004-12-05 12:43:04 +00:00
|
|
|
} else if (v->current_order.station < 1) {
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-07 17:02:43 +00:00
|
|
|
int x = TileX(v->dest_tile) * 16;
|
|
|
|
int y = TileY(v->dest_tile) * 16;
|
2005-07-08 22:25:24 +00:00
|
|
|
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) {
|
2004-08-09 17:04:08 +00:00
|
|
|
v->direction = GetDirectionTowards(v, x, y);
|
|
|
|
GetNewVehiclePos(v, &gp);
|
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++v->age < 6) {
|
2005-07-13 19:51:31 +00:00
|
|
|
v->dest_tile = RandomTile();
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 19:51:31 +00:00
|
|
|
tile_org = tile = RandomTile();
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-01-16 11:24:58 +00:00
|
|
|
if (IsTileType(tile, MP_RAILWAY) &&
|
2005-07-13 18:04:01 +00:00
|
|
|
(_m[tile].m5 & ~3) != 0xC0 && IS_HUMAN_PLAYER(GetTileOwner(tile)))
|
2005-06-04 11:56:32 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
tile = TILE_MASK(tile+1);
|
|
|
|
} while (tile != tile_org);
|
|
|
|
v->dest_tile = tile;
|
|
|
|
v->age = 0;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The plane which will shoot down the UFO
|
|
|
|
static void DisasterTick_4b(Vehicle *v)
|
|
|
|
{
|
|
|
|
GetNewVehiclePosResult gp;
|
|
|
|
Vehicle *u;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
v->tick_counter++;
|
|
|
|
|
|
|
|
GetNewVehiclePos(v, &gp);
|
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
|
|
|
|
2005-01-03 19:09:45 +00:00
|
|
|
if (gp.x > (int)MapSizeX() * 16 + 9*16 - 1) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteDisasterVeh(v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
if (v->current_order.station == 0) {
|
2005-01-06 22:31:58 +00:00
|
|
|
u = GetVehicle(v->u.disaster.unk2);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (abs(v->x_pos - u->x_pos) > 16)
|
|
|
|
return;
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.station = 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
|
|
|
|
|
|
|
DeleteDisasterVeh(u);
|
|
|
|
|
|
|
|
for(i=0; i!=80; i++) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-06-25 16:44:57 +00:00
|
|
|
BEGIN_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3))
|
2004-08-09 17:04:08 +00:00
|
|
|
tile = TILE_MASK(tile);
|
|
|
|
DisasterClearSquare(tile);
|
2005-06-25 16:44:57 +00:00
|
|
|
END_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3))
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Submarine handler
|
|
|
|
static void DisasterTick_5_and_6(Vehicle *v)
|
|
|
|
{
|
|
|
|
uint32 r;
|
|
|
|
GetNewVehiclePosResult gp;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
v->tick_counter++;
|
|
|
|
|
|
|
|
if (++v->age > 8880) {
|
|
|
|
VehiclePositionChanged(v);
|
|
|
|
BeginVehicleMove(v);
|
|
|
|
EndVehicleMove(v);
|
|
|
|
DeleteVehicle(v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(v->tick_counter&1))
|
|
|
|
return;
|
|
|
|
|
2005-01-05 13:32:03 +00:00
|
|
|
tile = v->tile + TileOffsByDir(v->direction >> 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (IsValidTile(tile) &&
|
2004-09-05 16:15:22 +00:00
|
|
|
(r=GetTileTrackStatus(tile,TRANSPORT_WATER),(byte)(r+(r >> 8)) == 0x3F) &&
|
2004-08-09 17:04:08 +00:00
|
|
|
!CHANCE16(1,90)) {
|
|
|
|
GetNewVehiclePos(v, &gp);
|
|
|
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
v->direction = (v->direction + ((Random()&1)?2:-2))&7;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void DisasterTick_NULL(Vehicle *v) {}
|
|
|
|
typedef void DisasterVehicleTickProc(Vehicle *v);
|
|
|
|
|
|
|
|
static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = {
|
|
|
|
DisasterTick_Zeppeliner,DisasterTick_NULL,
|
|
|
|
DisasterTick_UFO,DisasterTick_NULL,
|
|
|
|
DisasterTick_2,DisasterTick_NULL,
|
|
|
|
DisasterTick_3,DisasterTick_NULL,DisasterTick_3b,
|
|
|
|
DisasterTick_4,DisasterTick_NULL,
|
|
|
|
DisasterTick_4b,DisasterTick_NULL,
|
|
|
|
DisasterTick_5_and_6,
|
|
|
|
DisasterTick_5_and_6,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void DisasterVehicle_Tick(Vehicle *v)
|
|
|
|
{
|
|
|
|
_disastervehicle_tick_procs[v->subtype](v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HandleClickOnDisasterVeh(Vehicle *v)
|
|
|
|
{
|
|
|
|
// not used
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnNewDay_DisasterVehicle(Vehicle *v)
|
|
|
|
{
|
|
|
|
// not used
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
typedef void DisasterInitProc(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// Zeppeliner which crashes on a small airport
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Disaster0_Init(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Vehicle *v = ForceAllocateSpecialVehicle(), *u;
|
|
|
|
Station *st;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
if (v == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
/* Pick a random place, unless we find
|
|
|
|
a small airport */
|
2005-01-07 17:02:43 +00:00
|
|
|
x = TileX(Random()) * 16 + 8;
|
2005-01-06 22:31:58 +00:00
|
|
|
|
|
|
|
FOR_ALL_STATIONS(st) {
|
2004-09-10 19:02:27 +00:00
|
|
|
if (st->xy && st->airport_tile != 0 &&
|
2004-08-09 17:04:08 +00:00
|
|
|
st->airport_type <= 1 &&
|
|
|
|
IS_HUMAN_PLAYER(st->owner)) {
|
2005-01-07 17:02:43 +00:00
|
|
|
x = (TileX(st->xy) + 2) * 16;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InitializeDisasterVehicle(v, x, 0, 135, 3, 0);
|
|
|
|
|
|
|
|
// Allocate shadow too?
|
|
|
|
u = ForceAllocateSpecialVehicle();
|
|
|
|
if (u != NULL) {
|
|
|
|
v->next = u;
|
2005-01-06 22:31:58 +00:00
|
|
|
InitializeDisasterVehicle(u, x, 0, 0, 3, 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
u->vehstatus |= VS_DISASTER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Disaster1_Init(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Vehicle *v = ForceAllocateSpecialVehicle(), *u;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
if (v == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-01-07 17:02:43 +00:00
|
|
|
x = TileX(Random()) * 16 + 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
InitializeDisasterVehicle(v, x, 0, 135, 3, 2);
|
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;
|
|
|
|
|
|
|
|
// Allocate shadow too?
|
|
|
|
u = ForceAllocateSpecialVehicle();
|
|
|
|
if (u != NULL) {
|
|
|
|
v->next = u;
|
2004-09-10 19:02:27 +00:00
|
|
|
InitializeDisasterVehicle(u,x,0,0,3,3);
|
2004-08-09 17:04:08 +00:00
|
|
|
u->vehstatus |= VS_DISASTER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Disaster2_Init(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Industry *i, *found;
|
|
|
|
Vehicle *v,*u;
|
|
|
|
int x,y;
|
|
|
|
|
2004-12-30 10:03:35 +00:00
|
|
|
found = NULL;
|
|
|
|
|
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (i->xy != 0 &&
|
2004-09-10 19:02:27 +00:00
|
|
|
i->type == IT_OIL_REFINERY &&
|
2004-08-09 17:04:08 +00:00
|
|
|
(found==NULL || CHANCE16(1,2))) {
|
|
|
|
found = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
v = ForceAllocateSpecialVehicle();
|
|
|
|
if (v == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-01-03 18:59:58 +00:00
|
|
|
x = (MapSizeX() + 9) * 16 - 1;
|
2005-01-07 17:02:43 +00:00
|
|
|
y = TileY(found->xy) * 16 + 37;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
InitializeDisasterVehicle(v,x,y, 135,1,4);
|
|
|
|
|
|
|
|
u = ForceAllocateSpecialVehicle();
|
|
|
|
if (u != NULL) {
|
|
|
|
v->next = u;
|
2004-09-10 19:02:27 +00:00
|
|
|
InitializeDisasterVehicle(u,x,y,0,3,5);
|
2004-08-09 17:04:08 +00:00
|
|
|
u->vehstatus |= VS_DISASTER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Disaster3_Init(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Industry *i, *found;
|
|
|
|
Vehicle *v,*u,*w;
|
|
|
|
int x,y;
|
|
|
|
|
2004-12-30 10:03:35 +00:00
|
|
|
found = NULL;
|
|
|
|
|
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (i->xy != 0 &&
|
2004-09-10 19:02:27 +00:00
|
|
|
i->type == IT_FACTORY &&
|
2004-08-09 17:04:08 +00:00
|
|
|
(found==NULL || CHANCE16(1,2))) {
|
|
|
|
found = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
v = ForceAllocateSpecialVehicle();
|
|
|
|
if (v == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
x = -16 * 16;
|
2005-01-07 17:02:43 +00:00
|
|
|
y = TileY(found->xy) * 16 + 37;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
InitializeDisasterVehicle(v,x,y, 135,5,6);
|
|
|
|
|
|
|
|
u = ForceAllocateSpecialVehicle();
|
|
|
|
if (u != NULL) {
|
|
|
|
v->next = u;
|
2004-09-10 19:02:27 +00:00
|
|
|
InitializeDisasterVehicle(u,x,y,0,5,7);
|
2004-08-09 17:04:08 +00:00
|
|
|
u->vehstatus |= VS_DISASTER;
|
|
|
|
|
|
|
|
w = ForceAllocateSpecialVehicle();
|
|
|
|
if (w != NULL) {
|
|
|
|
u->next = w;
|
2004-09-10 19:02:27 +00:00
|
|
|
InitializeDisasterVehicle(w,x,y,140,5,8);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Disaster4_Init(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Vehicle *v = ForceAllocateSpecialVehicle(), *u;
|
|
|
|
int x,y;
|
|
|
|
|
|
|
|
if (v == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-01-07 17:02:43 +00:00
|
|
|
x = TileX(Random()) * 16 + 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-03 18:59:58 +00:00
|
|
|
y = MapMaxX() * 16 - 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeDisasterVehicle(v, x, y, 135, 7, 9);
|
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;
|
|
|
|
|
|
|
|
// Allocate shadow too?
|
|
|
|
u = ForceAllocateSpecialVehicle();
|
|
|
|
if (u != NULL) {
|
|
|
|
v->next = u;
|
2004-09-10 19:02:27 +00:00
|
|
|
InitializeDisasterVehicle(u,x,y,0,7,10);
|
2004-08-09 17:04:08 +00:00
|
|
|
u->vehstatus |= VS_DISASTER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Submarine type 1
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Disaster5_Init(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Vehicle *v = ForceAllocateSpecialVehicle();
|
|
|
|
int x,y;
|
|
|
|
byte dir;
|
|
|
|
uint32 r;
|
|
|
|
|
|
|
|
if (v == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
r = Random();
|
2005-01-07 17:02:43 +00:00
|
|
|
x = TileX(r) * 16 + 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
y = 8;
|
|
|
|
dir = 3;
|
2005-01-03 18:59:58 +00:00
|
|
|
if (r & 0x80000000) { y = MapMaxX() * 16 - 8 - 1; dir = 7; }
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeDisasterVehicle(v, x, y, 0, dir,13);
|
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Submarine type 2
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Disaster6_Init(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Vehicle *v = ForceAllocateSpecialVehicle();
|
|
|
|
int x,y;
|
|
|
|
byte dir;
|
|
|
|
uint32 r;
|
|
|
|
|
|
|
|
if (v == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
r = Random();
|
2005-01-07 17:02:43 +00:00
|
|
|
x = TileX(r) * 16 + 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
y = 8;
|
|
|
|
dir = 3;
|
2005-01-03 18:59:58 +00:00
|
|
|
if (r & 0x80000000) { y = MapMaxX() * 16 - 8 - 1; dir = 7; }
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeDisasterVehicle(v, x, y, 0, dir,14);
|
|
|
|
v->age = 0;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Disaster7_Init(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Industry *i;
|
|
|
|
int maxloop = 15;
|
|
|
|
int index = Random() & 0xF;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2004-12-30 10:03:35 +00:00
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
2005-07-08 22:25:24 +00:00
|
|
|
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) {
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, i->town->index);
|
2004-09-10 19:02:27 +00:00
|
|
|
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES,
|
2005-06-25 16:44:57 +00:00
|
|
|
NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TileDiffXY(1, 1), 0);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile = i->xy;
|
2005-01-06 11:39:00 +00:00
|
|
|
TileIndexDiff step = TileOffsByDir(Random() & 3);
|
2005-06-24 12:38:35 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
int count = 30;
|
|
|
|
do {
|
|
|
|
DisasterClearSquare(tile);
|
|
|
|
tile = TILE_MASK(tile + step);
|
|
|
|
} while (--count);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (--maxloop != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DisasterInitProc * const _disaster_initprocs[] = {
|
|
|
|
Disaster0_Init,
|
|
|
|
Disaster1_Init,
|
|
|
|
Disaster2_Init,
|
|
|
|
Disaster3_Init,
|
|
|
|
Disaster4_Init,
|
|
|
|
Disaster5_Init,
|
|
|
|
Disaster6_Init,
|
|
|
|
Disaster7_Init,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
byte min,max;
|
|
|
|
} DisasterYears;
|
|
|
|
|
|
|
|
#define MK(a,b) {a-20,b-20}
|
|
|
|
static const DisasterYears _dis_years[8] = {
|
|
|
|
MK(30,55),
|
|
|
|
MK(40,70),
|
|
|
|
MK(60,90),
|
|
|
|
MK(70,100),
|
|
|
|
MK(100,200),
|
|
|
|
MK(40,65),
|
|
|
|
MK(75,110),
|
|
|
|
MK(50,85),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void DoDisaster(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte buf[8];
|
|
|
|
byte year = _cur_year;
|
|
|
|
int i,j;
|
|
|
|
|
|
|
|
for(i=j=0; i!=lengthof(_dis_years); i++) {
|
|
|
|
if (year >= _dis_years[i].min &&
|
|
|
|
year < _dis_years[i].max)
|
|
|
|
buf[j++] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == 0)
|
|
|
|
return;
|
|
|
|
|
2005-10-03 21:20:01 +00:00
|
|
|
_disaster_initprocs[buf[GB(Random(), 0, 16) * j >> 16]]();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void ResetDisasterDelay(void)
|
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
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void DisasterDailyLoop(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (--_disaster_delay != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ResetDisasterDelay();
|
|
|
|
|
|
|
|
if (_opt.diff.disasters != 0)
|
|
|
|
DoDisaster();
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void StartupDisasters(void)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
ResetDisasterDelay();
|
|
|
|
}
|