Changeset - r12374:50d157b51c2c
[Not reviewed]
master
0 11 0
smatz - 15 years ago 2009-07-13 16:37:27
smatz@openttd.org
(svn r16814) -Codechange: make IsNormalAircraft() member of Aircraft
11 files changed with 33 insertions and 32 deletions:
0 comments (0 inline, 0 general)
src/aircraft.h
Show inline comments
 
@@ -21,20 +21,6 @@ enum AircraftSubType {
 
};
 

	
 

	
 
/** Check if the aircraft type is a normal flying device; eg
 
 * not a rotor or a shadow
 
 * @param v vehicle to check
 
 * @return Returns true if the aircraft is a helicopter/airplane and
 
 * false if it is a shadow or a rotor) */
 
static inline bool IsNormalAircraft(const Vehicle *v)
 
{
 
	assert(v->type == VEH_AIRCRAFT);
 
	/* To be fully correct the commented out functionality is the proper one,
 
	 * but since value can only be 0 or 2, it is sufficient to only check <= 2
 
	 * return (v->subtype == AIR_HELICOPTER) || (v->subtype == AIR_AIRCRAFT); */
 
	return v->subtype <= AIR_AIRCRAFT;
 
}
 

	
 
/**
 
 * Calculates cargo capacity based on an aircraft's passenger
 
 * and mail capacities.
 
@@ -108,7 +94,7 @@ struct Aircraft : public SpecializedVehi
 
	void MarkDirty();
 
	void UpdateDeltaXY(Direction direction);
 
	ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; }
 
	bool IsPrimaryVehicle() const { return IsNormalAircraft(this); }
 
	bool IsPrimaryVehicle() const { return this->IsNormalAircraft(); }
 
	SpriteID GetImage(Direction direction) const;
 
	int GetDisplaySpeed() const { return this->cur_speed; }
 
	int GetDisplayMaxSpeed() const { return this->max_speed; }
 
@@ -118,6 +104,20 @@ struct Aircraft : public SpecializedVehi
 
	void OnNewDay();
 
	TileIndex GetOrderStationLocation(StationID station);
 
	bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
 

	
 
	/**
 
	 * Check if the aircraft type is a normal flying device; eg
 
	 * not a rotor or a shadow
 
	 * @return Returns true if the aircraft is a helicopter/airplane and
 
	 * false if it is a shadow or a rotor
 
	 */
 
	FORCEINLINE bool IsNormalAircraft() const
 
	{
 
		/* To be fully correct the commented out functionality is the proper one,
 
		 * but since value can only be 0 or 2, it is sufficient to only check <= 2
 
		 * return (this->subtype == AIR_HELICOPTER) || (this->subtype == AIR_AIRCRAFT); */
 
		return this->subtype <= AIR_AIRCRAFT;
 
	}
 
};
 

	
 
#define FOR_ALL_AIRCRAFT(var) FOR_ALL_VEHICLES_OF_TYPE(Aircraft, var)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -613,7 +613,7 @@ Money Aircraft::GetRunningCost() const
 

	
 
void Aircraft::OnNewDay()
 
{
 
	if (!IsNormalAircraft(this)) return;
 
	if (!this->IsNormalAircraft()) return;
 

	
 
	if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
 

	
 
@@ -2029,7 +2029,7 @@ static bool AircraftEventHandler(Aircraf
 

	
 
bool Aircraft::Tick()
 
{
 
	if (!IsNormalAircraft(this)) return true;
 
	if (!this->IsNormalAircraft()) return true;
 

	
 
	if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
 

	
 
@@ -2074,7 +2074,7 @@ void UpdateAirplanesOnNewStation(const S
 

	
 
	Aircraft *v;
 
	FOR_ALL_AIRCRAFT(v) {
 
		if (IsNormalAircraft(v)) {
 
		if (v->IsNormalAircraft()) {
 
			if (v->targetairport == st->index) { // if heading to this airport
 
				/* update position of airplane. If plane is not flying, landing, or taking off
 
				 * you cannot delete airport, so it doesn't matter */
src/aircraft_gui.cpp
Show inline comments
 
@@ -22,13 +22,13 @@
 
 * @param right The right most coordinate to draw
 
 * @param y     The y coordinate
 
 */
 
void DrawAircraftDetails(const Vehicle *v, int left, int right, int y)
 
void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
 
{
 
	int y_offset = (v->Next()->cargo_cap != 0) ? -11 : 0;
 
	Money feeder_share = 0;
 

	
 
	for (const Vehicle *u = v ; u != NULL ; u = u->Next()) {
 
		if (IsNormalAircraft(u)) {
 
	for (const Aircraft *u = v ; u != NULL ; u = u->Next()) {
 
		if (u->IsNormalAircraft()) {
 
			SetDParam(0, u->engine_type);
 
			SetDParam(1, u->build_year);
 
			SetDParam(2, u->value);
src/economy.cpp
Show inline comments
 
@@ -123,7 +123,7 @@ Money CalculateCompanyValue(const Compan
 

	
 
		if (v->type == VEH_TRAIN ||
 
				v->type == VEH_ROAD ||
 
				(v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) ||
 
				(v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft()) ||
 
				v->type == VEH_SHIP) {
 
			value += v->value * 3 >> 1;
 
		}
 
@@ -1300,7 +1300,7 @@ static void LoadUnloadVehicle(Vehicle *v
 
		byte load_amount = EngInfo(v->engine_type)->load_amount;
 

	
 
		/* The default loadamount for mail is 1/4 of the load amount for passengers */
 
		if (v->type == VEH_AIRCRAFT && !IsNormalAircraft(v)) load_amount = (load_amount + 3) / 4;
 
		if (v->type == VEH_AIRCRAFT && !Aircraft::From(v)->IsNormalAircraft()) load_amount = (load_amount + 3) / 4;
 

	
 
		if (_settings_game.order.gradual_loading && HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_LOAD_AMOUNT)) {
 
			uint16 cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v);
src/engine.cpp
Show inline comments
 
@@ -658,7 +658,7 @@ static void NewVehicleAvailable(Engine *
 

	
 
			FOR_ALL_VEHICLES(v) {
 
				if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
 
						(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) {
 
						(v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft())) {
 
					if (v->owner == c->index && v->engine_type == index) {
 
						/* The user did prove me wrong, so restore old value */
 
						c->block_preview = block_preview;
src/saveload/afterload.cpp
Show inline comments
 
@@ -1760,7 +1760,7 @@ bool AfterLoadGame()
 
		Aircraft *a;
 
		FOR_ALL_AIRCRAFT(a) {
 
			/* Set engine_type of shadow and rotor */
 
			if (!IsNormalAircraft(a)) {
 
			if (!a->IsNormalAircraft()) {
 
				a->engine_type = a->First()->engine_type;
 
			}
 
		}
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -164,7 +164,7 @@ void UpdateOldAircraft()
 
	FOR_ALL_AIRCRAFT(a) {
 
		/* airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor)
 
		 * skip those */
 
		if (IsNormalAircraft(a)) {
 
		if (a->IsNormalAircraft()) {
 
			/* airplane in terminal stopped doesn't hurt anyone, so goto next */
 
			if ((a->vehstatus & VS_STOPPED) && a->state == 0) {
 
				a->state = HANGAR;
 
@@ -356,7 +356,7 @@ void AfterLoadVehicles(bool part_of_load
 
				break;
 

	
 
			case VEH_AIRCRAFT:
 
				if (IsNormalAircraft(v)) {
 
				if (Aircraft::From(v)->IsNormalAircraft()) {
 
					v->cur_image = v->GetImage(v->direction);
 

	
 
					/* The plane's shadow will have the same image as the plane */
src/station.cpp
Show inline comments
 
@@ -63,7 +63,7 @@ Station::~Station()
 

	
 
	Aircraft *a;
 
	FOR_ALL_AIRCRAFT(a) {
 
		if (!IsNormalAircraft(a)) continue;
 
		if (!a->IsNormalAircraft()) continue;
 
		if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
 
	}
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -1878,7 +1878,7 @@ static CommandCost RemoveAirport(TileInd
 

	
 
	const Aircraft *a;
 
	FOR_ALL_AIRCRAFT(a) {
 
		if (!IsNormalAircraft(a)) continue;
 
		if (!a->IsNormalAircraft()) continue;
 
		if (a->targetairport == st->index && a->state != FLYING) return CMD_ERROR;
 
	}
 

	
src/vehicle.cpp
Show inline comments
 
@@ -478,7 +478,7 @@ uint CountVehiclesInChain(const Vehicle 
 
bool Vehicle::IsEngineCountable() const
 
{
 
	switch (this->type) {
 
		case VEH_AIRCRAFT: return IsNormalAircraft(this); // don't count plane shadows and helicopter rotors
 
		case VEH_AIRCRAFT: return Aircraft::From(this)->IsNormalAircraft(); // don't count plane shadows and helicopter rotors
 
		case VEH_TRAIN:
 
			return !Train::From(this)->IsArticulatedPart() && // tenders and other articulated parts
 
					!Train::From(this)->IsRearDualheaded(); // rear parts of multiheaded engines
src/vehicle_gui.cpp
Show inline comments
 
@@ -19,6 +19,7 @@
 
#include "station_base.h"
 
#include "roadveh.h"
 
#include "train.h"
 
#include "aircraft.h"
 
#include "depot_base.h"
 
#include "group_gui.h"
 
#include "strings_func.h"
 
@@ -1343,7 +1344,7 @@ extern int GetTrainDetailsWndVScroll(Veh
 
extern void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab);
 
extern void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y);
 
extern void DrawShipDetails(const Vehicle *v, int left, int right, int y);
 
extern void DrawAircraftDetails(const Vehicle *v, int left, int right, int y);
 
extern void DrawAircraftDetails(const Aircraft *v, int left, int right, int y);
 

	
 
struct VehicleDetailsWindow : Window {
 
	TrainDetailsWindowTabs tab;
 
@@ -1436,7 +1437,7 @@ struct VehicleDetailsWindow : Window {
 
			case VEH_TRAIN:    DrawTrainDetails(Train::From(v), left, right, y, vscroll_pos, vscroll_cap, det_tab);  break;
 
			case VEH_ROAD:     DrawRoadVehDetails(v, left, right, y);  break;
 
			case VEH_SHIP:     DrawShipDetails(v, left, right, y);     break;
 
			case VEH_AIRCRAFT: DrawAircraftDetails(v, left, right, y); break;
 
			case VEH_AIRCRAFT: DrawAircraftDetails(Aircraft::From(v), left, right, y); break;
 
			default: NOT_REACHED();
 
		}
 
	}
0 comments (0 inline, 0 general)