src/aircraft.h
author glx
Sun, 08 Apr 2007 14:46:55 +0000
branchnoai
changeset 9574 698395509d12
parent 6585 7da94b26498a
child 9601 b499fdd106d5
permissions -rw-r--r--
(svn r9575) [NoAI] -Sync with trunk r9504:9574
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
6447
3b71e57fd22b (svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents: 6443
diff changeset
     3
/** @file aircraft.h */
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"
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
     9
#include "vehicle.h"
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
    10
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    11
/** 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
    12
enum AircraftSubType {
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    13
	AIR_HELICOPTER = 0, ///< an helicopter
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    14
	AIR_AIRCRAFT   = 2, ///< an airplane
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    15
	AIR_SHADOW     = 4, ///< shadow of the aircraft
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    16
	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
    17
};
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
    18
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
    19
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
    20
/** 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
    21
 * 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
    22
 * @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
    23
 * @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
    24
 * 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
    25
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
    26
{
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
    27
	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
    28
	/* 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
    29
	 * 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
    30
	 * 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
    31
	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
    32
}
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
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    34
/** Check if this aircraft is in a hangar
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    35
 * @param v vehicle to check
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    36
 * @return true if in hangar
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    37
 */
3963
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
    38
static inline bool IsAircraftInHangar(const Vehicle* v)
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
    39
{
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
    40
	assert(v->type == VEH_AIRCRAFT);
3963
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
    41
	return v->vehstatus & VS_HIDDEN && IsHangarTile(v->tile);
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
    42
}
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
    43
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    44
/** Check if this aircraft is in a hangar and stopped
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    45
 * @param v vehicle to check
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    46
 * @return true if in hangar and stopped
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    47
 */
3963
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
    48
static inline bool IsAircraftInHangarStopped(const Vehicle* v)
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
    49
{
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
    50
	return IsAircraftInHangar(v) && v->vehstatus & VS_STOPPED;
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
diff changeset
    51
}
3987
96b119a9fb94 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
    52
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
    53
/** Checks if an aircraft is buildable at the tile in question
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
    54
 * @param engine The engine to test
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
    55
 * @param tile The tile where the hangar is
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
    56
 * @return true if the aircraft can be build
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
    57
 */
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
    58
static inline bool IsAircraftBuildableAtStation(EngineID engine, TileIndex tile)
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
    59
{
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
    60
	const Station *st = GetStationByTile(tile);
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
    61
	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
    62
	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
    63
6571
a0f5bf2afa6c (svn r9048) -Fix r9040: non-bool used as bool
glx
parents: 6563
diff changeset
    64
	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
    65
}
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
    66
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    67
/**
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    68
 * Calculates cargo capacity based on an aircraft's passenger
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    69
 * and mail capacities.
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    70
 * @param cid Which cargo type to calculate a capacity for.
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    71
 * @param avi Which engine to find a cargo capacity for.
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    72
 * @return New cargo capacity value.
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    73
 */
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    74
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
    75
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    76
/**
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    77
 * This is the Callback method after the construction attempt of an aircraft
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    78
 * @param success indicates completion (or not) of the operation
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    79
 * @param tile of depot where aircraft is built
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    80
 * @param p1 unused
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    81
 * @param p2 unused
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    82
 */
6031
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5726
diff changeset
    83
void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2);
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    84
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    85
/**
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    86
 * This is the Callback method after the cloning attempt of an aircraft
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    87
 * @param success indicates completion (or not) of the operation
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    88
 * @param tile unused
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    89
 * @param p1 unused
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    90
 * @param p2 unused
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    91
 */
4653
091f530bae28 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 3987
diff changeset
    92
void CcCloneAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2);
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    93
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    94
/** Handle Aircraft specific tasks when a an Aircraft enters a hangar
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    95
 * @param *v Vehicle that enters the hangar
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    96
 */
4732
da9d305d1c94 (svn r6644) -Fix(r6637): remove inline to allow MSVC compilation
belugas
parents: 4725
diff changeset
    97
void HandleAircraftEnterHangar(Vehicle *v);
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    98
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
    99
/** Get the size of the sprite of an aircraft sprite heading west (used for lists)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
   100
 * @param engine The engine to get the sprite from
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
   101
 * @param width The width of the sprite
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
   102
 * @param height The height of the sprite
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
   103
 */
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
   104
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
   105
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
   106
/**
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
   107
 * Updates the status of the Aircraft heading or in the station
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
   108
 * @param st Station been updated
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6585
diff changeset
   109
 */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6223
diff changeset
   110
void UpdateAirplanesOnNewStation(const Station *st);
3d660a812fbd (svn r8822) -Fix
tron
parents: 6223
diff changeset
   111
3987
96b119a9fb94 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   112
#endif /* AIRCRAFT_H */