OpenTTD Source: src/disaster_vehicle.cpp Source File

OpenTTD Source 12.2

disaster_vehicle.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
26 #include "stdafx.h"
27
28 #include "aircraft.h"
29 #include "disaster_vehicle.h"
30 #include "industry.h"
31 #include "station_base.h"
32 #include "command_func.h"
33 #include "news_func.h"
34 #include "town.h"
35 #include "company_func.h"
36 #include "strings_func.h"
37 #include "date_func.h"
38 #include "viewport_func.h"
39 #include "vehicle_func.h"
40 #include "sound_func.h"
41 #include "effectvehicle_func.h"
42 #include "roadveh.h"
43 #include "ai/ai.hpp"
44 #include "game/game.hpp"
45 #include "company_base.h"
46 #include "core/random_func.hpp"
47 #include "core/backup_type.hpp"
48
49 #include "table/strings.h"
50
51 #include "safeguards.h"
52
54 uint16 _disaster_delay;
55
56 static void DisasterClearSquare(TileIndex tile)
57 {
58 if (EnsureNoVehicleOnGround(tile).Failed()) return;
59
60 switch (GetTileType(tile)) {
61 case MP_RAILWAY:
62 if (Company::IsHumanID(GetTileOwner(tile)) && !IsRailDepot(tile)) {
63 Backup<CompanyID> cur_company(_current_company, OWNER_WATER, FILE_LINE);
64 DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
65 cur_company.Restore();
66
67 /* update signals in buffer */
68 UpdateSignalsInBuffer();
69 }
70 break;
71
72 case MP_HOUSE: {
73 Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
74 DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
75 cur_company.Restore();
76 break;
77 }
78
79 case MP_TREES:
80 case MP_CLEAR:
81 DoClearSquare(tile);
82 break;
83
84 default:
85 break;
86 }
87 }
88
89 static const SpriteID _disaster_images_1[] = {SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP};
90 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};
91 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};
92 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};
93 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};
94 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};
95 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};
96 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};
97 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};
98
99 static const SpriteID * const _disaster_images[] = {
100 _disaster_images_1, _disaster_images_1,
101 _disaster_images_2, _disaster_images_2,
102 _disaster_images_3, _disaster_images_3,
103 _disaster_images_8, _disaster_images_8, _disaster_images_9,
104 _disaster_images_6, _disaster_images_6,
105 _disaster_images_7, _disaster_images_7,
106 _disaster_images_4, _disaster_images_5,
107 };
108
109 void DisasterVehicle::UpdateImage()
110 {
111 SpriteID img = this->image_override;
112 if (img == 0) img = _disaster_images[this->subtype][this->direction];
113 this->sprite_cache.sprite_seq.Set(img);
114 }
115
124 DisasterVehicle::DisasterVehicle(int x, int y, Direction direction, DisasterSubType subtype, VehicleID big_ufo_destroyer_target) :
125 SpecializedVehicleBase(), big_ufo_destroyer_target(big_ufo_destroyer_target)
126 {
127 this->vehstatus = VS_UNCLICKABLE;
128
129 this->x_pos = x;
130 this->y_pos = y;
131 switch (subtype) {
132 case ST_ZEPPELINER:
133 case ST_SMALL_UFO:
134 case ST_AIRPLANE:
135 case ST_HELICOPTER:
136 case ST_BIG_UFO:
137 case ST_BIG_UFO_DESTROYER:
138 GetAircraftFlightLevelBounds(this, &this->z_pos, nullptr);
139 break;
140
141 case ST_HELICOPTER_ROTORS:
142 GetAircraftFlightLevelBounds(this, &this->z_pos, nullptr);
143 this->z_pos += ROTOR_Z_OFFSET;
144 break;
145
146 case ST_SMALL_SUBMARINE:
147 case ST_BIG_SUBMARINE:
148 this->z_pos = 0;
149 break;
150
151 case ST_ZEPPELINER_SHADOW:
152 case ST_SMALL_UFO_SHADOW:
153 case ST_AIRPLANE_SHADOW:
154 case ST_HELICOPTER_SHADOW:
155 case ST_BIG_UFO_SHADOW:
156 case ST_BIG_UFO_DESTROYER_SHADOW:
157 this->z_pos = 0;
158 this->vehstatus |= VS_SHADOW;
159 break;
160 }
161
162 this->direction = direction;
163 this->tile = TileVirtXY(x, y);
164 this->subtype = subtype;
165 this->UpdateDeltaXY();
166 this->owner = OWNER_NONE;
167 this->image_override = 0;
168 this->current_order.Free();
169
170 this->UpdateImage();
171 this->UpdatePositionAndViewport();
172 }
173
180 void DisasterVehicle::UpdatePosition(int x, int y, int z)
181 {
182 this->x_pos = x;
183 this->y_pos = y;
184 this->z_pos = z;
185 this->tile = TileVirtXY(x, y);
186
187 this->UpdateImage();
188 this->UpdatePositionAndViewport();
189
190 DisasterVehicle *u = this->Next();
191 if (u != nullptr) {
192 int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
193 int safe_y = Clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
194
195 u->x_pos = x;
196 u->y_pos = y - 1 - (std::max(z - GetSlopePixelZ(safe_x, safe_y), 0) >> 3);
197 safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
198 u->z_pos = GetSlopePixelZ(safe_x, safe_y);
199 u->direction = this->direction;
200
201 u->UpdateImage();
202 u->UpdatePositionAndViewport();
203
204 if ((u = u->Next()) != nullptr) {
205 u->x_pos = x;
206 u->y_pos = y;
207 u->z_pos = z + ROTOR_Z_OFFSET;
208 u->UpdatePositionAndViewport();
209 }
210 }
211 }
212
221 static bool DisasterTick_Zeppeliner(DisasterVehicle *v)
222 {
223 v->tick_counter++;
224
225 if (v->current_order.GetDestination() < 2) {
226 if (HasBit(v->tick_counter, 0)) return true;
227
228 GetNewVehiclePosResult gp = GetNewVehiclePos(v);
229
230 v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
231
232 if (v->current_order.GetDestination() == 1) {
233 if (++v->age == 38) {
234 v->current_order.SetDestination(2);
235 v->age = 0;
236 }
237
238 if (GB(v->tick_counter, 0, 3) == 0) CreateEffectVehicleRel(v, 0, -17, 2, EV_CRASH_SMOKE);
239
240 } else if (v->current_order.GetDestination() == 0) {
241 if (IsValidTile(v->tile) && IsAirportTile(v->tile)) {
242 v->current_order.SetDestination(1);
243 v->age = 0;
244
245 SetDParam(0, GetStationIndex(v->tile));
246 AddTileNewsItem(STR_NEWS_DISASTER_ZEPPELIN, NT_ACCIDENT, v->tile);
247 AI::NewEvent(GetTileOwner(v->tile), new ScriptEventDisasterZeppelinerCrashed(GetStationIndex(v->tile)));
248 }
249 }
250
251 if (v->y_pos >= (int)((MapSizeY() + 9) * TILE_SIZE - 1)) {
252 delete v;
253 return false;
254 }
255
256 return true;
257 }
258
259 if (v->current_order.GetDestination() > 2) {
260 if (++v->age <= 13320) return true;
261
262 if (IsValidTile(v->tile) && IsAirportTile(v->tile)) {
263 Station *st = Station::GetByTile(v->tile);
264 CLRBITS(st->airport.flags, RUNWAY_IN_block);
265 AI::NewEvent(GetTileOwner(v->tile), new ScriptEventDisasterZeppelinerCleared(st->index));
266 }
267
268 v->UpdatePosition(v->x_pos, v->y_pos, GetAircraftFlightLevel(v));
269 delete v;
270 return false;
271 }
272
273 int x = v->x_pos;
274 int y = v->y_pos;
275 int z = GetSlopePixelZ(x, y);
276 if (z < v->z_pos) z = v->z_pos - 1;
277 v->UpdatePosition(x, y, z);
278
279 if (++v->age == 1) {
280 CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE);
281 if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
282 v->image_override = SPR_BLIMP_CRASHING;
283 } else if (v->age == 70) {
284 v->image_override = SPR_BLIMP_CRASHED;
285 } else if (v->age <= 300) {
286 if (GB(v->tick_counter, 0, 3) == 0) {
287 uint32 r = Random();
288
289 CreateEffectVehicleRel(v,
290 GB(r, 0, 4) - 7,
291 GB(r, 4, 4) - 7,
292 GB(r, 8, 3) + 5,
293 EV_EXPLOSION_SMALL);
294 }
295 } else if (v->age == 350) {
296 v->current_order.SetDestination(3);
297 v->age = 0;
298 }
299
300 if (IsValidTile(v->tile) && IsAirportTile(v->tile)) {
301 SETBITS(Station::GetByTile(v->tile)->airport.flags, RUNWAY_IN_block);
302 }
303
304 return true;
305 }
306
313 static bool DisasterTick_Ufo(DisasterVehicle *v)
314 {
315 v->image_override = (HasBit(++v->tick_counter, 3)) ? SPR_UFO_SMALL_SCOUT_DARKER : SPR_UFO_SMALL_SCOUT;
316
317 if (v->current_order.GetDestination() == 0) {
318 /* Fly around randomly */
319 int x = TileX(v->dest_tile) * TILE_SIZE;
320 int y = TileY(v->dest_tile) * TILE_SIZE;
321 if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= (int)TILE_SIZE) {
322 v->direction = GetDirectionTowards(v, x, y);
323 GetNewVehiclePosResult gp = GetNewVehiclePos(v);
324 v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
325 return true;
326 }
327 if (++v->age < 6) {
328 v->dest_tile = RandomTile();
329 return true;
330 }
331 v->current_order.SetDestination(1);
332
333 uint n = 0; // Total number of targetable road vehicles.
334 for (const RoadVehicle *u : RoadVehicle::Iterate()) {
335 if (u->IsFrontEngine()) n++;
336 }
337
338 if (n == 0) {
339 /* If there are no targetable road vehicles, destroy the UFO. */
340 delete v;
341 return false;
342 }
343
344 n = RandomRange(n); // Choose one of them.
345 for (const RoadVehicle *u : RoadVehicle::Iterate()) {
346 /* Find (n+1)-th road vehicle. */
347 if (u->IsFrontEngine() && (n-- == 0)) {
348 /* Target it. */
349 v->dest_tile = u->index;
350 v->age = 0;
351 break;
352 }
353 }
354
355 return true;
356 } else {
357 /* Target a vehicle */
358 RoadVehicle *u = RoadVehicle::Get(v->dest_tile);
359 assert(u != nullptr && u->type == VEH_ROAD && u->IsFrontEngine());
360
361 uint dist = Delta(v->x_pos, u->x_pos) + Delta(v->y_pos, u->y_pos);
362
363 if (dist < TILE_SIZE && !(u->vehstatus & VS_HIDDEN) && u->breakdown_ctr == 0) {
364 u->breakdown_ctr = 3;
365 u->breakdown_delay = 140;
366 }
367
368 v->direction = GetDirectionTowards(v, u->x_pos, u->y_pos);
369 GetNewVehiclePosResult gp = GetNewVehiclePos(v);
370
371 int z = v->z_pos;
372 if (dist <= TILE_SIZE && z > u->z_pos) z--;
373 v->UpdatePosition(gp.x, gp.y, z);
374
375 if (z <= u->z_pos && (u->vehstatus & VS_HIDDEN) == 0) {
376 v->age++;
377 if (u->crashed_ctr == 0) {
378 u->Crash();
379
380 AddTileNewsItem(STR_NEWS_DISASTER_SMALL_UFO, NT_ACCIDENT, u->tile);
381
382 AI::NewEvent(u->owner, new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO));
383 Game::NewEvent(new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO));
384 }
385 }
386
387 /* Destroy? */
388 if (v->age > 50) {
389 CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE);
390 if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
391 delete v;
392 return false;
393 }
394 }
395
396 return true;
397 }
398
399 static void DestructIndustry(Industry *i)
400 {
401 for (TileIndex tile = 0; tile != MapSize(); tile++) {
402 if (i->TileBelongsToIndustry(tile)) {
403 ResetIndustryConstructionStage(tile);
404 MarkTileDirtyByTile(tile);
405 }
406 }
407 }
408
422 static bool DisasterTick_Aircraft(DisasterVehicle *v, uint16 image_override, bool leave_at_top, StringID news_message, IndustryBehaviour industry_flag)
423 {
424 v->tick_counter++;
425 v->image_override = (v->current_order.GetDestination() == 1 && HasBit(v->tick_counter, 2)) ? image_override : 0;
426
427 GetNewVehiclePosResult gp = GetNewVehiclePos(v);
428 v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
429
430 if ((leave_at_top && gp.x < (-10 * (int)TILE_SIZE)) || (!leave_at_top && gp.x > (int)(MapSizeX() * TILE_SIZE + 9 * TILE_SIZE) - 1)) {
431 delete v;
432 return false;
433 }
434
435 if (v->current_order.GetDestination() == 2) {
436 if (GB(v->tick_counter, 0, 2) == 0) {
437 Industry *i = Industry::Get(v->dest_tile); // Industry destructor calls ReleaseDisastersTargetingIndustry, so this is valid
438 int x = TileX(i->location.tile) * TILE_SIZE;
439 int y = TileY(i->location.tile) * TILE_SIZE;
440 uint32 r = Random();
441
442 CreateEffectVehicleAbove(
443 GB(r, 0, 6) + x,
444 GB(r, 6, 6) + y,
445 GB(r, 12, 4),
446 EV_EXPLOSION_SMALL);
447
448 if (++v->age >= 55) v->current_order.SetDestination(3);
449 }
450 } else if (v->current_order.GetDestination() == 1) {
451 if (++v->age == 112) {
452 v->current_order.SetDestination(2);
453 v->age = 0;
454
455 Industry *i = Industry::Get(v->dest_tile); // Industry destructor calls ReleaseDisastersTargetingIndustry, so this is valid
456 DestructIndustry(i);
457
458 SetDParam(0, i->town->index);
459 AddIndustryNewsItem(news_message, NT_ACCIDENT, i->index);
460 if (_settings_client.sound.disaster) SndPlayTileFx(SND_12_EXPLOSION, i->location.tile);
461 }
462 } else if (v->current_order.GetDestination() == 0) {
463 int x = v->x_pos + ((leave_at_top ? -15 : 15) * TILE_SIZE);
464 int y = v->y_pos;
465
466 if ((uint)x > MapMaxX() * TILE_SIZE - 1) return true;
467
468 TileIndex tile = TileVirtXY(x, y);
469 if (!IsTileType(tile, MP_INDUSTRY)) return true;
470
471 IndustryID ind = GetIndustryIndex(tile);
472 v->dest_tile = ind;
473
474 if (GetIndustrySpec(Industry::Get(ind)->type)->behaviour & industry_flag) {
475 v->current_order.SetDestination(1);
476 v->age = 0;
477 }
478 }
479
480 return true;
481 }
482
484 static bool DisasterTick_Airplane(DisasterVehicle *v)
485 {
486 return DisasterTick_Aircraft(v, SPR_F_15_FIRING, true, STR_NEWS_DISASTER_AIRPLANE_OIL_REFINERY, INDUSTRYBEH_AIRPLANE_ATTACKS);
487 }
488
490 static bool DisasterTick_Helicopter(DisasterVehicle *v)
491 {
492 return DisasterTick_Aircraft(v, SPR_AH_64A_FIRING, false, STR_NEWS_DISASTER_HELICOPTER_FACTORY, INDUSTRYBEH_CHOPPER_ATTACKS);
493 }
494
496 static bool DisasterTick_Helicopter_Rotors(DisasterVehicle *v)
497 {
498 v->tick_counter++;
499 if (HasBit(v->tick_counter, 0)) return true;
500
501 SpriteID &cur_image = v->sprite_cache.sprite_seq.seq[0].sprite;
502 if (++cur_image > SPR_ROTOR_MOVING_3) cur_image = SPR_ROTOR_MOVING_1;
503
504 v->UpdatePositionAndViewport();
505
506 return true;
507 }
508
515 static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
516 {
517 v->tick_counter++;
518
519 if (v->current_order.GetDestination() == 1) {
520 int x = TileX(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2;
521 int y = TileY(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2;
522 if (Delta(v->x_pos, x) + Delta(v->y_pos, y) >= 8) {
523 v->direction = GetDirectionTowards(v, x, y);
524
525 GetNewVehiclePosResult gp = GetNewVehiclePos(v);
526 v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
527 return true;
528 }
529
530 if (!IsValidTile(v->dest_tile)) {
531 /* Make sure we don't land outside the map. */
532 delete v;
533 return false;
534 }
535
536 int z = GetSlopePixelZ(v->x_pos, v->y_pos);
537 if (z < v->z_pos) {
538 v->UpdatePosition(v->x_pos, v->y_pos, v->z_pos - 1);
539 return true;
540 }
541
542 v->current_order.SetDestination(2);
543
544 for (Vehicle *target : Vehicle::Iterate()) {
545 if (target->IsGroundVehicle()) {
546 if (Delta(target->x_pos, v->x_pos) + Delta(target->y_pos, v->y_pos) <= 12 * (int)TILE_SIZE) {
547 target->breakdown_ctr = 5;
548 target->breakdown_delay = 0xF0;
549 }
550 }
551 }
552
553 Town *t = ClosestTownFromTile(v->dest_tile, UINT_MAX);
554 SetDParam(0, t->index);
555 AddTileNewsItem(STR_NEWS_DISASTER_BIG_UFO, NT_ACCIDENT, v->tile);
556
557 if (!Vehicle::CanAllocateItem(2)) {
558 delete v;
559 return false;
560 }
561 DisasterVehicle *u = new DisasterVehicle(-6 * (int)TILE_SIZE, v->y_pos, DIR_SW, ST_BIG_UFO_DESTROYER, v->index);
562 DisasterVehicle *w = new DisasterVehicle(-6 * (int)TILE_SIZE, v->y_pos, DIR_SW, ST_BIG_UFO_DESTROYER_SHADOW);
563 u->SetNext(w);
564 } else if (v->current_order.GetDestination() == 0) {
565 int x = TileX(v->dest_tile) * TILE_SIZE;
566 int y = TileY(v->dest_tile) * TILE_SIZE;
567 if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= (int)TILE_SIZE) {
568 v->direction = GetDirectionTowards(v, x, y);
569 GetNewVehiclePosResult gp = GetNewVehiclePos(v);
570 v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
571 return true;
572 }
573
574 if (++v->age < 6) {
575 v->dest_tile = RandomTile();
576 return true;
577 }
578 v->current_order.SetDestination(1);
579
580 TileIndex tile_org = RandomTile();
581 TileIndex tile = tile_org;
582 do {
583 if (IsPlainRailTile(tile) &&
584 Company::IsHumanID(GetTileOwner(tile))) {
585 break;
586 }
587 tile = TILE_MASK(tile + 1);
588 } while (tile != tile_org);
589 v->dest_tile = tile;
590 v->age = 0;
591 }
592
593 return true;
594 }
595
600 static bool DisasterTick_Big_Ufo_Destroyer(DisasterVehicle *v)
601 {
602 v->tick_counter++;
603
604 GetNewVehiclePosResult gp = GetNewVehiclePos(v);
605 v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
606
607 if (gp.x > (int)(MapSizeX() * TILE_SIZE + 9 * TILE_SIZE) - 1) {
608 delete v;
609 return false;
610 }
611
612 if (v->current_order.GetDestination() == 0) {
613 Vehicle *u = Vehicle::Get(v->big_ufo_destroyer_target);
614 if (Delta(v->x_pos, u->x_pos) > (int)TILE_SIZE) return true;
615 v->current_order.SetDestination(1);
616
617 CreateEffectVehicleRel(u, 0, 7, 8, EV_EXPLOSION_LARGE);
618 if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, u);
619
620 delete u;
621
622 for (int i = 0; i != 80; i++) {
623 uint32 r = Random();
624 CreateEffectVehicleAbove(
625 GB(r, 0, 6) + v->x_pos - 32,
626 GB(r, 5, 6) + v->y_pos - 32,
627 0,
628 EV_EXPLOSION_SMALL);
629 }
630
631 for (int dy = -3; dy < 3; dy++) {
632 for (int dx = -3; dx < 3; dx++) {
633 TileIndex tile = TileAddWrap(v->tile, dx, dy);
634 if (tile != INVALID_TILE) DisasterClearSquare(tile);
635 }
636 }
637 }
638
639 return true;
640 }
641
646 static bool DisasterTick_Submarine(DisasterVehicle *v)
647 {
648 v->tick_counter++;
649
650 if (++v->age > 8880) {
651 delete v;
652 return false;
653 }
654
655 if (!HasBit(v->tick_counter, 0)) return true;
656
657 TileIndex tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction));
658 if (IsValidTile(tile)) {
659 TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));
660 if (trackbits == TRACK_BIT_ALL && !Chance16(1, 90)) {
661 GetNewVehiclePosResult gp = GetNewVehiclePos(v);
662 v->UpdatePosition(gp.x, gp.y, v->z_pos);
663 return true;
664 }
665 }
666
667 v->direction = ChangeDir(v->direction, GB(Random(), 0, 1) ? DIRDIFF_90RIGHT : DIRDIFF_90LEFT);
668
669 return true;
670 }
671
672
673 static bool DisasterTick_NULL(DisasterVehicle *v)
674 {
675 return true;
676 }
677
678 typedef bool DisasterVehicleTickProc(DisasterVehicle *v);
679
680 static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = {
681 DisasterTick_Zeppeliner, DisasterTick_NULL,
682 DisasterTick_Ufo, DisasterTick_NULL,
683 DisasterTick_Airplane, DisasterTick_NULL,
684 DisasterTick_Helicopter, DisasterTick_NULL, DisasterTick_Helicopter_Rotors,
685 DisasterTick_Big_Ufo, DisasterTick_NULL, DisasterTick_Big_Ufo_Destroyer,
686 DisasterTick_NULL,
687 DisasterTick_Submarine,
688 DisasterTick_Submarine,
689 };
690
691
692 bool DisasterVehicle::Tick()
693 {
694 return _disastervehicle_tick_procs[this->subtype](this);
695 }
696
697 typedef void DisasterInitProc();
698
699
704 static void Disaster_Zeppeliner_Init()
705 {
706 if (!Vehicle::CanAllocateItem(2)) return;
707
708 /* Pick a random place, unless we find a small airport */
709 int x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2;
710
711 for (const Station *st : Station::Iterate()) {
712 if (st->airport.tile != INVALID_TILE && (st->airport.type == AT_SMALL || st->airport.type == AT_LARGE)) {
713 x = (TileX(st->airport.tile) + 2) * TILE_SIZE;
714 break;
715 }
716 }
717
718 DisasterVehicle *v = new DisasterVehicle(x, 0, DIR_SE, ST_ZEPPELINER);
719 /* Allocate shadow */
720 DisasterVehicle *u = new DisasterVehicle(x, 0, DIR_SE, ST_ZEPPELINER_SHADOW);
721 v->SetNext(u);
722 }
723
724
729 static void Disaster_Small_Ufo_Init()
730 {
731 if (!Vehicle::CanAllocateItem(2)) return;
732
733 int x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2;
734 DisasterVehicle *v = new DisasterVehicle(x, 0, DIR_SE, ST_SMALL_UFO);
735 v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2);
736
737 /* Allocate shadow */
738 DisasterVehicle *u = new DisasterVehicle(x, 0, DIR_SE, ST_SMALL_UFO_SHADOW);
739 v->SetNext(u);
740 }
741
742
743 /* Combat airplane which destroys an oil refinery */
744 static void Disaster_Airplane_Init()
745 {
746 if (!Vehicle::CanAllocateItem(2)) return;
747
748 Industry *found = nullptr;
749
750 for (Industry *i : Industry::Iterate()) {
751 if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) &&
752 (found == nullptr || Chance16(1, 2))) {
753 found = i;
754 }
755 }
756
757 if (found == nullptr) return;
758
759 /* Start from the bottom (south side) of the map */
760 int x = (MapSizeX() + 9) * TILE_SIZE - 1;
761 int y = TileY(found->location.tile) * TILE_SIZE + 37;
762
763 DisasterVehicle *v = new DisasterVehicle(x, y, DIR_NE, ST_AIRPLANE);
764 DisasterVehicle *u = new DisasterVehicle(x, y, DIR_NE, ST_AIRPLANE_SHADOW);
765 v->SetNext(u);
766 }
767
768
770 static void Disaster_Helicopter_Init()
771 {
772 if (!Vehicle::CanAllocateItem(3)) return;
773
774 Industry *found = nullptr;
775
776 for (Industry *i : Industry::Iterate()) {
777 if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) &&
778 (found == nullptr || Chance16(1, 2))) {
779 found = i;
780 }
781 }
782
783 if (found == nullptr) return;
784
785 int x = -16 * (int)TILE_SIZE;
786 int y = TileY(found->location.tile) * TILE_SIZE + 37;
787
788 DisasterVehicle *v = new DisasterVehicle(x, y, DIR_SW, ST_HELICOPTER);
789 DisasterVehicle *u = new DisasterVehicle(x, y, DIR_SW, ST_HELICOPTER_SHADOW);
790 v->SetNext(u);
791
792 DisasterVehicle *w = new DisasterVehicle(x, y, DIR_SW, ST_HELICOPTER_ROTORS);
793 u->SetNext(w);
794 }
795
796
797 /* Big Ufo which lands on a piece of rail and will consequently be shot
798 * down by a combat airplane, destroying the surroundings */
799 static void Disaster_Big_Ufo_Init()
800 {
801 if (!Vehicle::CanAllocateItem(2)) return;
802
803 int x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2;
804 int y = MapMaxX() * TILE_SIZE - 1;
805
806 DisasterVehicle *v = new DisasterVehicle(x, y, DIR_NW, ST_BIG_UFO);
807 v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2);
808
809 /* Allocate shadow */
810 DisasterVehicle *u = new DisasterVehicle(x, y, DIR_NW, ST_BIG_UFO_SHADOW);
811 v->SetNext(u);
812 }
813
814
815 static void Disaster_Submarine_Init(DisasterSubType subtype)
816 {
817 if (!Vehicle::CanAllocateItem()) return;
818
819 int y;
820 Direction dir;
821 uint32 r = Random();
822 int x = TileX(r) * TILE_SIZE + TILE_SIZE / 2;
823
824 if (HasBit(r, 31)) {
825 y = MapMaxY() * TILE_SIZE - TILE_SIZE / 2 - 1;
826 dir = DIR_NW;
827 } else {
828 y = TILE_SIZE / 2;
829 if (_settings_game.construction.freeform_edges) y += TILE_SIZE;
830 dir = DIR_SE;
831 }
832 if (!IsWaterTile(TileVirtXY(x, y))) return;
833
834 new DisasterVehicle(x, y, dir, subtype);
835 }
836
837 /* Curious submarine #1, just floats around */
838 static void Disaster_Small_Submarine_Init()
839 {
840 Disaster_Submarine_Init(ST_SMALL_SUBMARINE);
841 }
842
843
844 /* Curious submarine #2, just floats around */
845 static void Disaster_Big_Submarine_Init()
846 {
847 Disaster_Submarine_Init(ST_BIG_SUBMARINE);
848 }
849
850
855 static void Disaster_CoalMine_Init()
856 {
857 int index = GB(Random(), 0, 4);
858 uint m;
859
860 for (m = 0; m < 15; m++) {
861 for (const Industry *i : Industry::Iterate()) {
862 if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CAN_SUBSIDENCE) && --index < 0) {
863 SetDParam(0, i->town->index);
864 AddTileNewsItem(STR_NEWS_DISASTER_COAL_MINE_SUBSIDENCE, NT_ACCIDENT, i->location.tile + TileDiffXY(1, 1)); // keep the news, even when the mine closes
865
866 {
867 TileIndex tile = i->location.tile;
868 TileIndexDiff step = TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2));
869
870 for (uint n = 0; n < 30; n++) {
871 DisasterClearSquare(tile);
872 tile += step;
873 if (!IsValidTile(tile)) break;
874 }
875 }
876 return;
877 }
878 }
879 }
880 }
881
882 struct Disaster {
883 DisasterInitProc *init_proc;
884 Year min_year;
885 Year max_year;
886 };
887
888 static const Disaster _disasters[] = {
889 {Disaster_Zeppeliner_Init, 1930, 1955}, // zeppeliner
890 {Disaster_Small_Ufo_Init, 1940, 1970}, // ufo (small)
891 {Disaster_Airplane_Init, 1960, 1990}, // airplane
892 {Disaster_Helicopter_Init, 1970, 2000}, // helicopter
893 {Disaster_Big_Ufo_Init, 2000, 2100}, // ufo (big)
894 {Disaster_Small_Submarine_Init, 1940, 1965}, // submarine (small)
895 {Disaster_Big_Submarine_Init, 1975, 2010}, // submarine (big)
896 {Disaster_CoalMine_Init, 1950, 1985}, // coalmine
897 };
898
899 static void DoDisaster()
900 {
901 byte buf[lengthof(_disasters)];
902
903 byte j = 0;
904 for (size_t i = 0; i != lengthof(_disasters); i++) {
905 if (_cur_year >= _disasters[i].min_year && _cur_year < _disasters[i].max_year) buf[j++] = (byte)i;
906 }
907
908 if (j == 0) return;
909
910 _disasters[buf[RandomRange(j)]].init_proc();
911 }
912
913
914 static void ResetDisasterDelay()
915 {
916 _disaster_delay = GB(Random(), 0, 9) + 730;
917 }
918
919 void DisasterDailyLoop()
920 {
921 if (--_disaster_delay != 0) return;
922
923 ResetDisasterDelay();
924
925 if (_settings_game.difficulty.disasters != 0) DoDisaster();
926 }
927
928 void StartupDisasters()
929 {
930 ResetDisasterDelay();
931 }
932
938 void ReleaseDisastersTargetingIndustry(IndustryID i)
939 {
940 for (DisasterVehicle *v : DisasterVehicle::Iterate()) {
941 /* primary disaster vehicles that have chosen target */
942 if (v->subtype == ST_AIRPLANE || v->subtype == ST_HELICOPTER) {
943 /* if it has chosen target, and it is this industry (yes, dest_tile is IndustryID here), set order to "leaving map peacefully" */
944 if (v->current_order.GetDestination() > 0 && v->dest_tile == i) v->current_order.SetDestination(3);
945 }
946 }
947 }
948
953 void ReleaseDisastersTargetingVehicle(VehicleID vehicle)
954 {
955 for (DisasterVehicle *v : DisasterVehicle::Iterate()) {
956 /* primary disaster vehicles that have chosen target */
957 if (v->subtype == ST_SMALL_UFO) {
958 if (v->current_order.GetDestination() != 0 && v->dest_tile == vehicle) {
959 /* Revert to target-searching */
960 v->current_order.SetDestination(0);
961 v->dest_tile = RandomTile();
962 GetAircraftFlightLevelBounds(v, &v->z_pos, nullptr);
963 v->age = 0;
964 }
965 }
966 }
967 }
968
969 void DisasterVehicle::UpdateDeltaXY()
970 {
971 this->x_offs = -1;
972 this->y_offs = -1;
973 this->x_extent = 2;
974 this->y_extent = 2;
975 this->z_extent = 5;
976 }
DisasterVehicle::image_override
SpriteID image_override
Override for the default disaster vehicle sprite.
Definition: disaster_vehicle.h:38
game.hpp
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:46
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition: tile_type.h:49
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
DIR_SW
@ DIR_SW
Southwest.
Definition: direction_type.h:31
DisasterTick_Airplane
static bool DisasterTick_Airplane(DisasterVehicle *v)
Airplane handling.
Definition: disaster_vehicle.cpp:484
sound_func.h
DisasterTick_Zeppeliner
static bool DisasterTick_Zeppeliner(DisasterVehicle *v)
Zeppeliner handling, v->current_order.dest states: 0: Zeppeliner initialization has found a small air...
Definition: disaster_vehicle.cpp:221
DisasterTick_Submarine
static bool DisasterTick_Submarine(DisasterVehicle *v)
Submarine, v->current_order.dest states: Unused, just float around aimlessly and pop up at different ...
Definition: disaster_vehicle.cpp:646
Chance16
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
Definition: random_func.hpp:131
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:450
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
Vehicle::y_pos
int32 y_pos
y coordinate.
Definition: vehicle_base.h:281
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:194
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
Vehicle::x_pos
int32 x_pos
x coordinate.
Definition: vehicle_base.h:280
ChangeDir
static Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
Definition: direction_func.h:104
UpdateSignalsInBuffer
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
Definition: signal.cpp:468
command_func.h
DIR_SE
@ DIR_SE
Southeast.
Definition: direction_type.h:29
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Definition: town_cmd.cpp:3592
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
company_base.h
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
SpecializedVehicle< DisasterVehicle, VEH_DISASTER >::Next
DisasterVehicle * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1081
DisasterVehicle::big_ufo_destroyer_target
VehicleID big_ufo_destroyer_target
The big UFO that this destroyer is supposed to bomb.
Definition: disaster_vehicle.h:39
Vehicle::y_extent
byte y_extent
y-extent of vehicle bounding box
Definition: vehicle_base.h:293
Station
Station data structure.
Definition: station_base.h:447
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:97
Vehicle::z_pos
int32 z_pos
z coordinate.
Definition: vehicle_base.h:282
IsAirportTile
static bool IsAirportTile(TileIndex t)
Is this tile a station tile and an airport tile?
Definition: station_map.h:167
VehicleSpriteSeq::Set
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:162
DIR_NW
@ DIR_NW
Northwest.
Definition: direction_type.h:33
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:328
INDUSTRYBEH_CAN_SUBSIDENCE
@ INDUSTRYBEH_CAN_SUBSIDENCE
can cause a subsidence (coal mine, shaft that collapses)
Definition: industrytype.h:76
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
Vehicle::SetNext
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
Definition: vehicle.cpp:2740
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
Order::Free
void Free()
'Free' the order
Definition: order_cmd.cpp:62
ST_SMALL_UFO_SHADOW
@ ST_SMALL_UFO_SHADOW
Shadow of small UFO.
Definition: disaster_vehicle.h:20
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:576
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
SND_12_EXPLOSION
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Definition: sound_type.h:55
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:47
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
aircraft.h
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:13
DisasterVehicle::UpdatePosition
void UpdatePosition(int x, int y, int z)
Update the position of the vehicle.
Definition: disaster_vehicle.cpp:180
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:52
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:54
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
RandomRange
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
Definition: random_func.hpp:81
DisasterTick_Big_Ufo_Destroyer
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...
Definition: disaster_vehicle.cpp:600
EV_EXPLOSION_SMALL
@ EV_EXPLOSION_SMALL
Various explosions.
Definition: effectvehicle_func.h:24
DisasterSubType
DisasterSubType
Different sub types of disaster vehicles.
Definition: disaster_vehicle.h:16
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:221
Industry
Defines the internal data of a functional industry.
Definition: industry.h:66
TILE_MASK
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
Definition: map_func.h:26
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:285
EV_EXPLOSION_LARGE
@ EV_EXPLOSION_LARGE
Various explosions.
Definition: effectvehicle_func.h:22
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:348
ST_BIG_SUBMARINE
@ ST_BIG_SUBMARINE
Big submarine, pops up in the oceans but doesn't do anything.
Definition: disaster_vehicle.h:31
IsRailDepot
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
Definition: rail_map.h:95
AT_LARGE
@ AT_LARGE
Large airport.
Definition: airport.h:30
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
Disaster_Zeppeliner_Init
static void Disaster_Zeppeliner_Init()
Zeppeliner which crashes on a small airport if one found, otherwise crashes on a random tile.
Definition: disaster_vehicle.cpp:704
EnsureNoVehicleOnGround
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition: vehicle.cpp:539
SETBITS
#define SETBITS(x, y)
Sets several bits in a variable.
Definition: bitmath_func.hpp:136
ResetIndustryConstructionStage
static void ResetIndustryConstructionStage(TileIndex tile)
Reset the construction stage counter of the industry, as well as the completion bit.
Definition: industry_map.h:187
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:590
effectvehicle_func.h
SpecializedStation< Station, false >::Iterate
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition: base_station_base.h:270
ai.hpp
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
MapSizeX
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:72
Disaster_CoalMine_Init
static void Disaster_CoalMine_Init()
Coal mine catastrophe, destroys a stretch of 30 tiles of land in a certain direction.
Definition: disaster_vehicle.cpp:855
Disaster
Definition: disaster_vehicle.cpp:882
DifficultySettings::disasters
bool disasters
are disasters enabled
Definition: settings_type.h:91
INDUSTRYBEH_AIRPLANE_ATTACKS
@ INDUSTRYBEH_AIRPLANE_ATTACKS
can be exploded by a military airplane (oil refinery)
Definition: industrytype.h:74
Vehicle::breakdown_ctr
byte breakdown_ctr
Counter for managing breakdown events.
Definition: vehicle_base.h:275
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:31
ST_AIRPLANE
@ ST_AIRPLANE
Airplane destroying an oil refinery.
Definition: disaster_vehicle.h:21
Vehicle::dest_tile
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:249
DirToDiagDir
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Definition: direction_func.h:166
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:234
TileAddWrap
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges.
Definition: map.cpp:114
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:67
ST_ZEPPELINER
@ ST_ZEPPELINER
Zeppelin, crashes at airports.
Definition: disaster_vehicle.h:17
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:597
DIRDIFF_90LEFT
@ DIRDIFF_90LEFT
Angle of 90 degrees left.
Definition: direction_type.h:67
Industry::type
IndustryType type
type of industry.
Definition: industry.h:83
TileIndexDiff
int32 TileIndexDiff
An offset value between to tiles.
Definition: map_func.h:154
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:242
TrackStatusToTrackBits
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:362
Order::SetDestination
void SetDestination(DestinationID destination)
Sets the destination of this order.
Definition: order_base.h:104
ST_BIG_UFO_SHADOW
@ ST_BIG_UFO_SHADOW
Shadow of the big UFO.
Definition: disaster_vehicle.h:27
Disaster_Helicopter_Init
static void Disaster_Helicopter_Init()
Combat helicopter that destroys a factory.
Definition: disaster_vehicle.cpp:770
SpecializedVehicle
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
Definition: vehicle_base.h:1046
DisasterVehicle::Tick
bool Tick()
Calls the tick handler of the vehicle.
Definition: disaster_vehicle.cpp:692
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:329
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:461
DIR_NE
@ DIR_NE
Northeast.
Definition: direction_type.h:27
Vehicle::IsFrontEngine
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:899
DisasterTick_Aircraft
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...
Definition: disaster_vehicle.cpp:422
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:53
Disaster_Small_Ufo_Init
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: disaster_vehicle.cpp:729
GetAircraftFlightLevelBounds
void GetAircraftFlightLevelBounds(const Vehicle *v, int *min, int *max)
Get the 'flight level' bounds, in pixels from 'z_pos' 0 for a particular vehicle for normal flight si...
Definition: aircraft_cmd.cpp:718
SpecializedVehicle< RoadVehicle, Type >::Get
static RoadVehicle * Get(size_t index)
Gets vehicle with given index.
Definition: vehicle_base.h:1147
Game::NewEvent
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:141
industry.h
safeguards.h
EV_CRASH_SMOKE
@ EV_CRASH_SMOKE
Smoke of disasters.
Definition: effectvehicle_func.h:21
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
Airport::flags
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Definition: station_base.h:305
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:346
RandomTile
#define RandomTile()
Get a valid random tile.
Definition: map_func.h:435
DisasterVehicle::UpdateDeltaXY
void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: disaster_vehicle.cpp:969
SoundSettings::disaster
bool disaster
Play disaster and accident sounds.
Definition: settings_type.h:212
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
MapSizeY
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:82
TRACK_BIT_ALL
@ TRACK_BIT_ALL
All possible tracks.
Definition: track_type.h:53
CreateEffectVehicleRel
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
Definition: effectvehicle.cpp:638
date_func.h
stdafx.h
Company::IsHumanID
static bool IsHumanID(size_t index)
Is this company a company not controlled by a NoAI program?
Definition: company_base.h:160
Vehicle::sprite_cache
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition: vehicle_base.h:343
ReleaseDisastersTargetingIndustry
void ReleaseDisastersTargetingIndustry(IndustryID i)
Marks all disasters targeting this industry in such a way they won't call Industry::Get(v->dest_tile)...
Definition: disaster_vehicle.cpp:938
RoadVehicle::Crash
uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
Definition: roadveh_cmd.cpp:532
Vehicle::y_offs
int8 y_offs
y offset for vehicle sprite
Definition: vehicle_base.h:298
viewport_func.h
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
DisasterVehicle
Disasters, like submarines, skyrangers and their shadows, belong to this class.
Definition: disaster_vehicle.h:37
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:283
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:50
Industry::town
Town * town
Nearest town.
Definition: industry.h:68
ST_HELICOPTER_SHADOW
@ ST_HELICOPTER_SHADOW
Shadow of helicopter.
Definition: disaster_vehicle.h:24
ST_SMALL_SUBMARINE
@ ST_SMALL_SUBMARINE
Small submarine, pops up in the oceans but doesn't do anything.
Definition: disaster_vehicle.h:30
DisasterTick_Big_Ufo
static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
(Big) Ufo handling, v->current_order.dest states: 0: Fly around to the middle of the map,...
Definition: disaster_vehicle.cpp:515
Vehicle::x_extent
byte x_extent
x-extent of vehicle bounding box
Definition: vehicle_base.h:292
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
ST_BIG_UFO_DESTROYER_SHADOW
@ ST_BIG_UFO_DESTROYER_SHADOW
Shadow of the aircraft.
Definition: disaster_vehicle.h:29
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
station_base.h
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
Pool::PoolItem<&_vehicle_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
strings_func.h
DisasterTick_Helicopter_Rotors
static bool DisasterTick_Helicopter_Rotors(DisasterVehicle *v)
Helicopter rotor blades; keep these spinning.
Definition: disaster_vehicle.cpp:496
ST_AIRPLANE_SHADOW
@ ST_AIRPLANE_SHADOW
Shadow of airplane.
Definition: disaster_vehicle.h:22
DisasterTick_Ufo
static bool DisasterTick_Ufo(DisasterVehicle *v)
(Small) Ufo handling, v->current_order.dest states: 0: Fly around to the middle of the map,...
Definition: disaster_vehicle.cpp:313
Vehicle::tick_counter
byte tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:325
MapMaxY
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
Vehicle::x_offs
int8 x_offs
x offset for vehicle sprite
Definition: vehicle_base.h:297
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
Vehicle::z_extent
byte z_extent
z-extent of vehicle bounding box
Definition: vehicle_base.h:294
ST_HELICOPTER
@ ST_HELICOPTER
Helicopter destroying a factory.
Definition: disaster_vehicle.h:23
IsWaterTile
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
Definition: water_map.h:184
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
GetIndustryIndex
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
Definition: industry_map.h:63
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1987
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
ReleaseDisastersTargetingVehicle
void ReleaseDisastersTargetingVehicle(VehicleID vehicle)
Notify disasters that we are about to delete a vehicle.
Definition: disaster_vehicle.cpp:953
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
TileDiffXY
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:179
GetNewVehiclePosResult
Position information of a vehicle after it moved.
Definition: vehicle_func.h:75
Vehicle::age
Date age
Age in days.
Definition: vehicle_base.h:270
SpecializedStation< Station, false >::GetByTile
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:238
GetStationIndex
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:28
Pool::PoolItem<&_vehicle_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:307
NT_ACCIDENT
@ NT_ACCIDENT
An accident or disaster has occurred.
Definition: news_type.h:24
RoadVehicle::crashed_ctr
uint16 crashed_ctr
Animation counter when the vehicle has crashed.
Definition: roadveh.h:114
DIRDIFF_90RIGHT
@ DIRDIFF_90RIGHT
Angle of 90 degrees right.
Definition: direction_type.h:65
CreateEffectVehicleAbove
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
Definition: effectvehicle.cpp:622
company_func.h
SpecializedVehicle< RoadVehicle, Type >::Iterate
static Pool::IterateWrapper< RoadVehicle > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition: vehicle_base.h:1235
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
Vehicle::breakdown_delay
byte breakdown_delay
Counter for managing breakdown length.
Definition: vehicle_base.h:276
Disaster::min_year
Year min_year
The first year this disaster will occur.
Definition: disaster_vehicle.cpp:884
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
Vehicle::subtype
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:338
VS_UNCLICKABLE
@ VS_UNCLICKABLE
Vehicle is not clickable by the user (shadow vehicles).
Definition: vehicle_base.h:33
IndustrySpec::behaviour
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
Definition: industrytype.h:125
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
Town
Town data structure.
Definition: town.h:50
ST_HELICOPTER_ROTORS
@ ST_HELICOPTER_ROTORS
Rotors of helicopter.
Definition: disaster_vehicle.h:25
random_func.hpp
IsPlainRailTile
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
Definition: rail_map.h:60
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:88
_disaster_delay
uint16 _disaster_delay
Delay counter for considering the next disaster.
Definition: disaster_vehicle.cpp:54
INDUSTRYBEH_CHOPPER_ATTACKS
@ INDUSTRYBEH_CHOPPER_ATTACKS
can be exploded by a military helicopter (factory)
Definition: industrytype.h:75
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:578
GetIndustrySpec
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition: industry_cmd.cpp:121
ST_BIG_UFO_DESTROYER
@ ST_BIG_UFO_DESTROYER
Aircraft the will bomb the big UFO.
Definition: disaster_vehicle.h:28
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
IndustryBehaviour
IndustryBehaviour
Various industry behaviours mostly to represent original TTD specialities.
Definition: industrytype.h:61
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
ST_BIG_UFO
@ ST_BIG_UFO
Big UFO, finds a piece of railroad to "park" on.
Definition: disaster_vehicle.h:26
Vehicle::UpdatePositionAndViewport
void UpdatePositionAndViewport()
Update the position of the vehicle, and update the viewport.
Definition: vehicle.cpp:1681
Vehicle::UpdatePosition
void UpdatePosition()
Update the position of the vehicle.
Definition: vehicle.cpp:1610
GetNewVehiclePosResult::y
int y
x and y position of the vehicle after moving
Definition: vehicle_func.h:76
ST_ZEPPELINER_SHADOW
@ ST_ZEPPELINER_SHADOW
Shadow of the zeppelin.
Definition: disaster_vehicle.h:18
disaster_vehicle.h
AT_SMALL
@ AT_SMALL
Small airport.
Definition: airport.h:29
DisasterVehicle::DisasterVehicle
DisasterVehicle()
For use by saveload.
Definition: disaster_vehicle.h:43
DisasterTick_Helicopter
static bool DisasterTick_Helicopter(DisasterVehicle *v)
Helicopter handling.
Definition: disaster_vehicle.cpp:490
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:166
Disaster::init_proc
DisasterInitProc * init_proc
The init function for this disaster.
Definition: disaster_vehicle.cpp:883
VS_SHADOW
@ VS_SHADOW
Vehicle is a shadow vehicle.
Definition: vehicle_base.h:36
Disaster::max_year
Year max_year
The last year this disaster will occur.
Definition: disaster_vehicle.cpp:885
ST_SMALL_UFO
@ ST_SMALL_UFO
Small UFO, tries to find a road vehicle to destroy.
Definition: disaster_vehicle.h:19
CMD_LANDSCAPE_CLEAR
@ CMD_LANDSCAPE_CLEAR
demolish a tile
Definition: command_type.h:180
Delta
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
Definition: math_func.hpp:170
GetNewVehiclePos
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing.
Definition: vehicle.cpp:1701
TileVirtXY
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:194
news_func.h
roadveh.h
ROTOR_Z_OFFSET
static const int ROTOR_Z_OFFSET
Z Offset between helicopter- and rotorsprite.
Definition: aircraft.h:50
Industry::TileBelongsToIndustry
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
Definition: industry.h:117
backup_type.hpp