diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -36,6 +36,7 @@ #include "core/random_func.hpp" #include "core/backup_type.hpp" #include "zoom_func.h" +#include "disaster_vehicle.h" #include "table/strings.h" @@ -763,6 +764,8 @@ int GetAircraftFlightLevel(T *v, bool ta return z; } +template int GetAircraftFlightLevel(DisasterVehicle *v, bool takeoff = false); + /** * Find the entry point to an airport depending on direction which * the airport is being approached from. Each airport can have up to diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -55,8 +55,6 @@ /** 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; @@ -137,11 +135,12 @@ DisasterVehicle::DisasterVehicle(int x, 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: @@ -229,7 +228,7 @@ static bool DisasterTick_Zeppeliner(Disa 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) { @@ -267,7 +266,7 @@ static bool DisasterTick_Zeppeliner(Disa 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; } @@ -323,7 +322,7 @@ static bool DisasterTick_Ufo(DisasterVeh 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) { @@ -426,7 +425,7 @@ static bool DisasterTick_Aircraft(Disast 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; @@ -523,7 +522,7 @@ static bool DisasterTick_Big_Ufo(Disaste 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; } @@ -568,7 +567,7 @@ static bool DisasterTick_Big_Ufo(Disaste 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; } @@ -603,7 +602,7 @@ static bool DisasterTick_Big_Ufo_Destroy 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; @@ -965,7 +964,7 @@ void ReleaseDisastersTargetingVehicle(Ve /* 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; } } diff --git a/src/disaster_vehicle.h b/src/disaster_vehicle.h --- a/src/disaster_vehicle.h +++ b/src/disaster_vehicle.h @@ -39,6 +39,7 @@ enum DisasterSubType { struct DisasterVehicle FINAL : public SpecializedVehicle { SpriteID image_override; ///< Override for the default disaster vehicle sprite. VehicleID big_ufo_destroyer_target; ///< The big UFO that this destroyer is supposed to bomb. + byte flags; ///< Flags about the state of the vehicle, @see AirVehicleFlags /** For use by saveload. */ DisasterVehicle() : SpecializedVehicleBase() {} diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -845,6 +845,7 @@ const SaveLoad *GetVehicleDescription(Ve SLE_CONDVAR(DisasterVehicle, image_override, SLE_UINT32, 191, SL_MAX_VERSION), SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_FILE_U16 | SLE_VAR_U32, 0, 190), SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_UINT32, 191, SL_MAX_VERSION), + SLE_CONDVAR(DisasterVehicle, flags, SLE_UINT8, 194, SL_MAX_VERSION), SLE_CONDNULL(16, 2, 143), // old reserved space