author | glx |
Sun, 15 Jun 2008 22:18:10 +0000 | |
branch | noai |
changeset 10971 | aaf89f8c59b9 |
parent 10455 | 22c441f5adf9 |
permissions | -rw-r--r-- |
3963
d7d284c2f1f7
(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff
changeset
|
1 |
/* $Id$ */ |
d7d284c2f1f7
(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff
changeset
|
2 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
3 |
/** @file aircraft.h Base for aircraft. */ |
6443
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6413
diff
changeset
|
4 |
|
3987
96b119a9fb94
(svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents:
3963
diff
changeset
|
5 |
#ifndef AIRCRAFT_H |
96b119a9fb94
(svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents:
3963
diff
changeset
|
6 |
#define AIRCRAFT_H |
96b119a9fb94
(svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents:
3963
diff
changeset
|
7 |
|
3963
d7d284c2f1f7
(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff
changeset
|
8 |
#include "station_map.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9724
diff
changeset
|
9 |
#include "station_base.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9704
diff
changeset
|
10 |
#include "vehicle_base.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9724
diff
changeset
|
11 |
#include "engine_func.h" |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
12 |
#include "engine_base.h" |
3963
d7d284c2f1f7
(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff
changeset
|
13 |
|
9574 | 14 |
/** An aircraft can be one ot those types */ |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6571
diff
changeset
|
15 |
enum AircraftSubType { |
9574 | 16 |
AIR_HELICOPTER = 0, ///< an helicopter |
17 |
AIR_AIRCRAFT = 2, ///< an airplane |
|
18 |
AIR_SHADOW = 4, ///< shadow of the aircraft |
|
19 |
AIR_ROTOR = 6 ///< rotor of an helicopter |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6571
diff
changeset
|
20 |
}; |
6105
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
21 |
|
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
22 |
|
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
23 |
/** Check if the aircraft type is a normal flying device; eg |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
24 |
* not a rotor or a shadow |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
25 |
* @param v vehicle to check |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
26 |
* @return Returns true if the aircraft is a helicopter/airplane and |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
27 |
* false if it is a shadow or a rotor) */ |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
28 |
static inline bool IsNormalAircraft(const Vehicle *v) |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
29 |
{ |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
30 |
assert(v->type == VEH_AIRCRAFT); |
6105
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
31 |
/* To be fully correct the commented out functionality is the proper one, |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
32 |
* but since value can only be 0 or 2, it is sufficient to only check <= 2 |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
33 |
* return (v->subtype == AIR_HELICOPTER) || (v->subtype == AIR_AIRCRAFT); */ |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
34 |
return v->subtype <= AIR_AIRCRAFT; |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
35 |
} |
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6031
diff
changeset
|
36 |
|
9704 | 37 |
/** Checks if an aircraft can use the station in question |
6563
d08d813ecd42
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6447
diff
changeset
|
38 |
* @param engine The engine to test |
9704 | 39 |
* @param st The station |
40 |
* @return true if the aircraft can use the station |
|
6563
d08d813ecd42
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6447
diff
changeset
|
41 |
*/ |
9704 | 42 |
static inline bool CanAircraftUseStation(EngineID engine, const Station *st) |
6563
d08d813ecd42
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6447
diff
changeset
|
43 |
{ |
d08d813ecd42
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6447
diff
changeset
|
44 |
const AirportFTAClass *apc = st->Airport(); |
d08d813ecd42
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6447
diff
changeset
|
45 |
const AircraftVehicleInfo *avi = AircraftVehInfo(engine); |
d08d813ecd42
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6447
diff
changeset
|
46 |
|
6571 | 47 |
return (apc->flags & (avi->subtype & AIR_CTOL ? AirportFTAClass::AIRPLANES : AirportFTAClass::HELICOPTERS)) != 0; |
6563
d08d813ecd42
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6447
diff
changeset
|
48 |
} |
d08d813ecd42
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6447
diff
changeset
|
49 |
|
9704 | 50 |
/** Checks if an aircraft can use the station at the tile in question |
51 |
* @param engine The engine to test |
|
52 |
* @param tile The tile where the station is |
|
53 |
* @return true if the aircraft can use the station |
|
54 |
*/ |
|
55 |
static inline bool CanAircraftUseStation(EngineID engine, TileIndex tile) |
|
56 |
{ |
|
57 |
return CanAircraftUseStation(engine, GetStationByTile(tile)); |
|
58 |
} |
|
59 |
||
9574 | 60 |
/** |
61 |
* Calculates cargo capacity based on an aircraft's passenger |
|
62 |
* and mail capacities. |
|
63 |
* @param cid Which cargo type to calculate a capacity for. |
|
64 |
* @param avi Which engine to find a cargo capacity for. |
|
65 |
* @return New cargo capacity value. |
|
66 |
*/ |
|
67 |
uint16 AircraftDefaultCargoCapacity(CargoID cid, const AircraftVehicleInfo *avi); |
|
3987
96b119a9fb94
(svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents:
3963
diff
changeset
|
68 |
|
9574 | 69 |
/** |
70 |
* This is the Callback method after the construction attempt of an aircraft |
|
71 |
* @param success indicates completion (or not) of the operation |
|
72 |
* @param tile of depot where aircraft is built |
|
73 |
* @param p1 unused |
|
74 |
* @param p2 unused |
|
75 |
*/ |
|
6031
f6d1eef3fa24
(svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents:
5726
diff
changeset
|
76 |
void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2); |
9574 | 77 |
|
78 |
/** Handle Aircraft specific tasks when a an Aircraft enters a hangar |
|
79 |
* @param *v Vehicle that enters the hangar |
|
80 |
*/ |
|
4732
da9d305d1c94
(svn r6644) -Fix(r6637): remove inline to allow MSVC compilation
belugas
parents:
4725
diff
changeset
|
81 |
void HandleAircraftEnterHangar(Vehicle *v); |
9574 | 82 |
|
83 |
/** Get the size of the sprite of an aircraft sprite heading west (used for lists) |
|
84 |
* @param engine The engine to get the sprite from |
|
85 |
* @param width The width of the sprite |
|
86 |
* @param height The height of the sprite |
|
87 |
*/ |
|
6223
92d2073c3d7e
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
6105
diff
changeset
|
88 |
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height); |
4653
091f530bae28
(svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents:
3987
diff
changeset
|
89 |
|
9574 | 90 |
/** |
91 |
* Updates the status of the Aircraft heading or in the station |
|
92 |
* @param st Station been updated |
|
93 |
*/ |
|
6413 | 94 |
void UpdateAirplanesOnNewStation(const Station *st); |
95 |
||
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
96 |
/** Update cached values of an aircraft. |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
97 |
* Currently caches callback 36 max speed. |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
98 |
* @param v Vehicle |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
99 |
*/ |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
100 |
void UpdateAircraftCache(Vehicle *v); |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
101 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
102 |
/** |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
103 |
* This class 'wraps' Vehicle; you do not actually instantiate this class. |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
104 |
* You create a Vehicle using AllocateVehicle, so it is added to the pool |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
105 |
* and you reinitialize that to a Train using: |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
106 |
* v = new (v) Aircraft(); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
107 |
* |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
108 |
* As side-effect the vehicle type is set correctly. |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
109 |
*/ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
110 |
struct Aircraft : public Vehicle { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
111 |
/** Initializes the Vehicle to an aircraft */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
112 |
Aircraft() { this->type = VEH_AIRCRAFT; } |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
113 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
114 |
/** We want to 'destruct' the right class. */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
115 |
virtual ~Aircraft() { this->PreDestructor(); } |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
116 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
117 |
const char *GetTypeString() const { return "aircraft"; } |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
118 |
void MarkDirty(); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
119 |
void UpdateDeltaXY(Direction direction); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
120 |
ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; } |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9620
diff
changeset
|
121 |
bool IsPrimaryVehicle() const { return IsNormalAircraft(this); } |
10294 | 122 |
SpriteID GetImage(Direction direction) const; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
123 |
int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; } |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
124 |
int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 16; } |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
125 |
Money GetRunningCost() const { return AircraftVehInfo(this->engine_type)->running_cost * _price.aircraft_running; } |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
126 |
bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); } |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9625
diff
changeset
|
127 |
void Tick(); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
128 |
void OnNewDay(); |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
129 |
TileIndex GetOrderStationLocation(StationID station); |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
130 |
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
131 |
}; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
132 |
|
3987
96b119a9fb94
(svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents:
3963
diff
changeset
|
133 |
#endif /* AIRCRAFT_H */ |