Changeset - r21729:37178ad3391a
[Not reviewed]
master
0 4 0
rubidium - 10 years ago 2014-09-21 11:12:42
rubidium@openttd.org
(svn r26872) -Change: give the disaster vehicles the same treatment as aircraft in r26866; make the ascend and descend if needed to cross high mountains (based on patch by ic111)
4 files changed with 16 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -33,12 +33,13 @@
 
#include "effectvehicle_func.h"
 
#include "station_base.h"
 
#include "engine_base.h"
 
#include "core/random_func.hpp"
 
#include "core/backup_type.hpp"
 
#include "zoom_func.h"
 
#include "disaster_vehicle.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
void Aircraft::UpdateDeltaXY(Direction direction)
 
@@ -760,12 +761,14 @@ int GetAircraftFlightLevel(T *v, bool ta
 
		ClrBit(v->flags, VAF_IN_MAX_HEIGHT_CORRECTION);
 
	}
 

	
 
	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
 
 * four entry points for its approach system so that approaching
 
 * aircraft do not fly through each other or are forced to do 180
 
 * degree turns during the approach. The arrivals are grouped into
src/disaster_vehicle.cpp
Show inline comments
 
@@ -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;
 
			}
 
		}
 
	}
 
}
 

	
src/disaster_vehicle.h
Show inline comments
 
@@ -36,12 +36,13 @@ enum DisasterSubType {
 
/**
 
 * Disasters, like submarines, skyrangers and their shadows, belong to this class.
 
 */
 
struct DisasterVehicle FINAL : public SpecializedVehicle<DisasterVehicle, VEH_DISASTER> {
 
	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() {}
 
	DisasterVehicle(int x, int y, Direction direction, DisasterSubType subtype, VehicleID big_ufo_destroyer_target = VEH_INVALID);
 
	/** We want to 'destruct' the right class. */
 
	virtual ~DisasterVehicle() {}
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -842,12 +842,13 @@ const SaveLoad *GetVehicleDescription(Ve
 
		     SLE_VAR(Vehicle, tick_counter,          SLE_UINT8),
 

	
 
		 SLE_CONDVAR(DisasterVehicle, image_override,            SLE_FILE_U16 | SLE_VAR_U32,   0, 190),
 
		 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
 

	
 
		     SLE_END()
 
	};
 

	
0 comments (0 inline, 0 general)