summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-07-13 16:37:27 +0000
committersmatz <smatz@openttd.org>2009-07-13 16:37:27 +0000
commitb6960e4e17c9d9464041d8c04907a5e1caf5c609 (patch)
tree9a5101e644b98bd50bdb6d5f7adc7bbe17aee09a /src
parent868c21cbcc3b04e4e6649417ff94763a82c7d8b5 (diff)
downloadopenttd-b6960e4e17c9d9464041d8c04907a5e1caf5c609.tar.xz
(svn r16814) -Codechange: make IsNormalAircraft() member of Aircraft
Diffstat (limited to 'src')
-rw-r--r--src/aircraft.h30
-rw-r--r--src/aircraft_cmd.cpp6
-rw-r--r--src/aircraft_gui.cpp6
-rw-r--r--src/economy.cpp4
-rw-r--r--src/engine.cpp2
-rw-r--r--src/saveload/afterload.cpp2
-rw-r--r--src/saveload/vehicle_sl.cpp4
-rw-r--r--src/station.cpp2
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle_gui.cpp5
11 files changed, 33 insertions, 32 deletions
diff --git a/src/aircraft.h b/src/aircraft.h
index 278b42a43..b61b413b5 100644
--- a/src/aircraft.h
+++ b/src/aircraft.h
@@ -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 SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
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 SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
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)
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 4c2fd57a1..e3cd7f608 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -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(Aircraft *v, int loop)
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 Station *st)
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 */
diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp
index ccc04490b..038950f7a 100644
--- a/src/aircraft_gui.cpp
+++ b/src/aircraft_gui.cpp
@@ -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);
diff --git a/src/economy.cpp b/src/economy.cpp
index 0006c564f..2c2077c0c 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -123,7 +123,7 @@ Money CalculateCompanyValue(const Company *c)
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, int *cargo_left)
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);
diff --git a/src/engine.cpp b/src/engine.cpp
index 814f14e40..f1f0036c8 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -658,7 +658,7 @@ static void NewVehicleAvailable(Engine *e)
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;
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index a31dc4a44..bfba2cdd5 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -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;
}
}
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index bd1202fb6..5eb71cc45 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -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 */
diff --git a/src/station.cpp b/src/station.cpp
index b4b26e2df..8cb1a8cc4 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -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;
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index bd4c0d1c0..890191682 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1878,7 +1878,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
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;
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index df1059391..95c6c8fff 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -478,7 +478,7 @@ uint CountVehiclesInChain(const Vehicle *v)
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
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 7f55f3b24..407b563cf 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -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(VehicleID veh_id, TrainDetailsWindowTabs de
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();
}
}