|
@@ -52,14 +52,12 @@
|
|
|
|
|
|
#include "safeguards.h"
|
|
|
|
|
|
/** Delay counter for considering the next disaster. */
|
|
|
uint16 _disaster_delay;
|
|
|
|
|
|
static const uint INITIAL_DISASTER_VEHICLE_ZPOS = 135; ///< Initial Z position of flying disaster vehicles.
|
|
|
|
|
|
static void DisasterClearSquare(TileIndex tile)
|
|
|
{
|
|
|
if (EnsureNoVehicleOnGround(tile).Failed()) return;
|
|
|
|
|
|
switch (GetTileType(tile)) {
|
|
|
case MP_RAILWAY:
|
|
@@ -134,17 +132,18 @@ DisasterVehicle::DisasterVehicle(int x,
|
|
|
case ST_ZEPPELINER:
|
|
|
case ST_SMALL_UFO:
|
|
|
case ST_AIRPLANE:
|
|
|
case ST_HELICOPTER:
|
|
|
case ST_BIG_UFO:
|
|
|
case ST_BIG_UFO_DESTROYER:
|
|
|
this->z_pos = INITIAL_DISASTER_VEHICLE_ZPOS;
|
|
|
GetAircraftFlightLevelBounds(this, &this->z_pos, NULL);
|
|
|
break;
|
|
|
|
|
|
case ST_HELICOPTER_ROTORS:
|
|
|
this->z_pos = INITIAL_DISASTER_VEHICLE_ZPOS + ROTOR_Z_OFFSET;
|
|
|
GetAircraftFlightLevelBounds(this, &this->z_pos, NULL);
|
|
|
this->z_pos += ROTOR_Z_OFFSET;
|
|
|
break;
|
|
|
|
|
|
case ST_SMALL_SUBMARINE:
|
|
|
case ST_BIG_SUBMARINE:
|
|
|
this->z_pos = 0;
|
|
|
break;
|
|
@@ -226,13 +225,13 @@ static bool DisasterTick_Zeppeliner(Disa
|
|
|
|
|
|
if (v->current_order.GetDestination() < 2) {
|
|
|
if (HasBit(v->tick_counter, 0)) return true;
|
|
|
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
|
|
|
|
|
v->UpdatePosition(gp.x, gp.y, v->z_pos);
|
|
|
v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
|
|
|
|
|
|
if (v->current_order.GetDestination() == 1) {
|
|
|
if (++v->age == 38) {
|
|
|
v->current_order.SetDestination(2);
|
|
|
v->age = 0;
|
|
|
}
|
|
@@ -264,13 +263,13 @@ static bool DisasterTick_Zeppeliner(Disa
|
|
|
if (IsValidTile(v->tile) && IsAirportTile(v->tile)) {
|
|
|
Station *st = Station::GetByTile(v->tile);
|
|
|
CLRBITS(st->airport.flags, RUNWAY_IN_block);
|
|
|
AI::NewEvent(GetTileOwner(v->tile), new ScriptEventDisasterZeppelinerCleared(st->index));
|
|
|
}
|
|
|
|
|
|
v->UpdatePosition(v->x_pos, v->y_pos, v->z_pos);
|
|
|
v->UpdatePosition(v->x_pos, v->y_pos, GetAircraftFlightLevel(v));
|
|
|
delete v;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int x = v->x_pos;
|
|
|
int y = v->y_pos;
|
|
@@ -320,13 +319,13 @@ static bool DisasterTick_Ufo(DisasterVeh
|
|
|
/* Fly around randomly */
|
|
|
int x = TileX(v->dest_tile) * TILE_SIZE;
|
|
|
int y = TileY(v->dest_tile) * TILE_SIZE;
|
|
|
if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= (int)TILE_SIZE) {
|
|
|
v->direction = GetDirectionTowards(v, x, y);
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
|
|
v->UpdatePosition(gp.x, gp.y, v->z_pos);
|
|
|
v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
|
|
|
return true;
|
|
|
}
|
|
|
if (++v->age < 6) {
|
|
|
v->dest_tile = RandomTile();
|
|
|
return true;
|
|
|
}
|
|
@@ -423,13 +422,13 @@ static void DestructIndustry(Industry *i
|
|
|
static bool DisasterTick_Aircraft(DisasterVehicle *v, uint16 image_override, bool leave_at_top, StringID news_message, IndustryBehaviour industry_flag)
|
|
|
{
|
|
|
v->tick_counter++;
|
|
|
v->image_override = (v->current_order.GetDestination() == 1 && HasBit(v->tick_counter, 2)) ? image_override : 0;
|
|
|
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
|
|
v->UpdatePosition(gp.x, gp.y, v->z_pos);
|
|
|
v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
|
|
|
|
|
|
if ((leave_at_top && gp.x < (-10 * (int)TILE_SIZE)) || (!leave_at_top && gp.x > (int)(MapSizeX() * TILE_SIZE + 9 * TILE_SIZE) - 1)) {
|
|
|
delete v;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -520,13 +519,13 @@ static bool DisasterTick_Big_Ufo(Disaste
|
|
|
int x = TileX(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2;
|
|
|
int y = TileY(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2;
|
|
|
if (Delta(v->x_pos, x) + Delta(v->y_pos, y) >= 8) {
|
|
|
v->direction = GetDirectionTowards(v, x, y);
|
|
|
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
|
|
v->UpdatePosition(gp.x, gp.y, v->z_pos);
|
|
|
v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
if (!IsValidTile(v->dest_tile)) {
|
|
|
/* Make sure we don't land outside the map. */
|
|
|
delete v;
|
|
@@ -565,13 +564,13 @@ static bool DisasterTick_Big_Ufo(Disaste
|
|
|
} else if (v->current_order.GetDestination() == 0) {
|
|
|
int x = TileX(v->dest_tile) * TILE_SIZE;
|
|
|
int y = TileY(v->dest_tile) * TILE_SIZE;
|
|
|
if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= (int)TILE_SIZE) {
|
|
|
v->direction = GetDirectionTowards(v, x, y);
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
|
|
v->UpdatePosition(gp.x, gp.y, v->z_pos);
|
|
|
v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
if (++v->age < 6) {
|
|
|
v->dest_tile = RandomTile();
|
|
|
return true;
|
|
@@ -600,13 +599,13 @@ static bool DisasterTick_Big_Ufo(Disaste
|
|
|
*/
|
|
|
static bool DisasterTick_Big_Ufo_Destroyer(DisasterVehicle *v)
|
|
|
{
|
|
|
v->tick_counter++;
|
|
|
|
|
|
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
|
|
|
v->UpdatePosition(gp.x, gp.y, v->z_pos);
|
|
|
v->UpdatePosition(gp.x, gp.y, GetAircraftFlightLevel(v));
|
|
|
|
|
|
if (gp.x > (int)(MapSizeX() * TILE_SIZE + 9 * TILE_SIZE) - 1) {
|
|
|
delete v;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -962,13 +961,13 @@ void ReleaseDisastersTargetingVehicle(Ve
|
|
|
/* 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();
|
|
|
v->z_pos = INITIAL_DISASTER_VEHICLE_ZPOS;
|
|
|
GetAircraftFlightLevelBounds(v, &v->z_pos, NULL);
|
|
|
v->age = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|