mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r16814) -Codechange: make IsNormalAircraft() member of Aircraft
This commit is contained in:
parent
868c21cbcc
commit
b6960e4e17
|
@ -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)
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue