1
0
Fork 0

(svn r8747) -Fix

-Codechange: Make the encoding of accepted aircraft types of airports a bit more sensible and move the enum into struct AirportFTAClass
release/0.6
tron 2007-02-15 20:16:33 +00:00
parent 8675b8ec7d
commit 5231f5669d
6 changed files with 30 additions and 47 deletions

View File

@ -3244,7 +3244,6 @@ static void AiStateDeleteRoadBlocks(Player *p)
static void AiStateAirportStuff(Player *p) static void AiStateAirportStuff(Player *p)
{ {
const Station* st; const Station* st;
byte acc_planes;
int i; int i;
AiBuildRec *aib; AiBuildRec *aib;
byte rule; byte rule;
@ -3268,16 +3267,11 @@ static void AiStateAirportStuff(Player *p)
// Do we own the airport? (Oilrigs aren't owned, though.) // Do we own the airport? (Oilrigs aren't owned, though.)
if (st->owner != OWNER_NONE && st->owner != _current_player) continue; if (st->owner != OWNER_NONE && st->owner != _current_player) continue;
acc_planes = GetAirport(st->airport_type)->acc_planes; AirportFTAClass::Flags flags = GetAirport(st->airport_type)->flags;
// Dismiss heliports, unless we are checking an oilrig. if (!(flags & (p->ai.build_kind == 1 && i == 0 ? AirportFTAClass::HELICOPTERS : AirportFTAClass::PLANES))) {
if (acc_planes == HELICOPTERS_ONLY && (p->ai.build_kind != 1 || i != 1))
continue;
// Dismiss country airports if we are doing the other
// endpoint of an oilrig route.
if (acc_planes == AIRCRAFT_ONLY && (p->ai.build_kind == 1 && i == 0))
continue; continue;
}
// Dismiss airports too far away. // Dismiss airports too far away.
if (DistanceMax(st->airport_tile, aib->spec_tile) > aib->rand_rng) if (DistanceMax(st->airport_tile, aib->spec_tile) > aib->rand_rng)
@ -3298,7 +3292,7 @@ static void AiStateAirportStuff(Player *p)
* broken because they will probably need different * broken because they will probably need different
* tileoff values etc), no matter that * tileoff values etc), no matter that
* IsHangarTile() makes no sense. --pasky */ * IsHangarTile() makes no sense. --pasky */
if (acc_planes == HELICOPTERS_ONLY) { if (!(flags & AirportFTAClass::PLANES)) {
/* Heliports should have maybe own rulesets but /* Heliports should have maybe own rulesets but
* OTOH we don't want AI to pick them up when * OTOH we don't want AI to pick them up when
* looking for a suitable airport type to build. * looking for a suitable airport type to build.
@ -3372,7 +3366,7 @@ static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli,
for (i = 0; (p = _airport_default_block_data[i]) != NULL; i++) { for (i = 0; (p = _airport_default_block_data[i]) != NULL; i++) {
// If we are doing a helicopter service, avoid building // If we are doing a helicopter service, avoid building
// airports where they can't land. // airports where they can't land.
if (heli && GetAirport(p->attr)->acc_planes == AIRCRAFT_ONLY) continue; if (heli && !(GetAirport(p->attr)->flags & AirportFTAClass::HELICOPTERS)) continue;
*cost = AiDoBuildDefaultAirportBlock(tile, p, 0); *cost = AiDoBuildDefaultAirportBlock(tile, p, 0);
if (!CmdFailed(*cost) && AiCheckAirportResources(tile, p, cargo)) if (!CmdFailed(*cost) && AiCheckAirportResources(tile, p, cargo))

View File

@ -250,7 +250,7 @@ int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
// Prevent building aircraft types at places which can't handle them // Prevent building aircraft types at places which can't handle them
const Station* st = GetStationByTile(tile); const Station* st = GetStationByTile(tile);
const AirportFTAClass* apc = GetAirport(st->airport_type); const AirportFTAClass* apc = GetAirport(st->airport_type);
if ((avi->subtype & AIR_CTOL ? HELICOPTERS_ONLY : AIRCRAFT_ONLY) == apc->acc_planes) { if (!(apc->flags & (avi->subtype & AIR_CTOL ? AirportFTAClass::PLANES : AirportFTAClass::HELICOPTERS))) {
return CMD_ERROR; return CMD_ERROR;
} }
@ -1636,12 +1636,8 @@ static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *apc)
uint16 tcur_speed, tsubspeed; uint16 tcur_speed, tsubspeed;
st = GetStation(v->u.air.targetairport); st = GetStation(v->u.air.targetairport);
// flying device is accepted at this station
// small airport --> no helicopters (AIRCRAFT_ONLY)
// all other airports --> all types of flying devices (ALL)
// heliport/oilrig, etc --> no airplanes (HELICOPTERS_ONLY)
// runway busy or not allowed to use this airstation, circle // runway busy or not allowed to use this airstation, circle
if (v->subtype != apc->acc_planes && if (apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::PLANES) &&
st->airport_tile != 0 && st->airport_tile != 0 &&
(st->owner == OWNER_NONE || st->owner == v->owner)) { (st->owner == OWNER_NONE || st->owner == v->owner)) {
// {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41}, // {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41},

View File

@ -37,7 +37,7 @@ void InitializeAirports(void)
_airport_terminal_country, _airport_terminal_country,
NULL, NULL,
16, 16,
ALL, AirportFTAClass::ALL,
_airport_fta_country, _airport_fta_country,
_airport_depots_country, _airport_depots_country,
lengthof(_airport_depots_country), lengthof(_airport_depots_country),
@ -50,7 +50,7 @@ void InitializeAirports(void)
_airport_terminal_city, _airport_terminal_city,
NULL, NULL,
19, 19,
ALL, AirportFTAClass::ALL,
_airport_fta_city, _airport_fta_city,
_airport_depots_city, _airport_depots_city,
lengthof(_airport_depots_city), lengthof(_airport_depots_city),
@ -63,7 +63,7 @@ void InitializeAirports(void)
_airport_terminal_metropolitan, _airport_terminal_metropolitan,
NULL, NULL,
20, 20,
ALL, AirportFTAClass::ALL,
_airport_fta_metropolitan, _airport_fta_metropolitan,
_airport_depots_metropolitan, _airport_depots_metropolitan,
lengthof(_airport_depots_metropolitan), lengthof(_airport_depots_metropolitan),
@ -76,7 +76,7 @@ void InitializeAirports(void)
_airport_terminal_international, _airport_terminal_international,
_airport_helipad_international, _airport_helipad_international,
37, 37,
ALL, AirportFTAClass::ALL,
_airport_fta_international, _airport_fta_international,
_airport_depots_international, _airport_depots_international,
lengthof(_airport_depots_international), lengthof(_airport_depots_international),
@ -89,7 +89,7 @@ void InitializeAirports(void)
_airport_terminal_intercontinental, _airport_terminal_intercontinental,
_airport_helipad_intercontinental, _airport_helipad_intercontinental,
43, 43,
ALL, AirportFTAClass::ALL,
_airport_fta_intercontinental, _airport_fta_intercontinental,
_airport_depots_intercontinental, _airport_depots_intercontinental,
lengthof(_airport_depots_intercontinental), lengthof(_airport_depots_intercontinental),
@ -102,7 +102,7 @@ void InitializeAirports(void)
NULL, NULL,
_airport_helipad_heliport_oilrig, _airport_helipad_heliport_oilrig,
7, 7,
HELICOPTERS_ONLY, AirportFTAClass::HELICOPTERS,
_airport_fta_heliport_oilrig, _airport_fta_heliport_oilrig,
NULL, NULL,
0, 0,
@ -115,7 +115,7 @@ void InitializeAirports(void)
NULL, NULL,
_airport_helipad_heliport_oilrig, _airport_helipad_heliport_oilrig,
7, 7,
HELICOPTERS_ONLY, AirportFTAClass::HELICOPTERS,
_airport_fta_heliport_oilrig, _airport_fta_heliport_oilrig,
NULL, NULL,
0, 0,
@ -128,7 +128,7 @@ void InitializeAirports(void)
_airport_terminal_commuter, _airport_terminal_commuter,
_airport_helipad_commuter, _airport_helipad_commuter,
22, 22,
ALL, AirportFTAClass::ALL,
_airport_fta_commuter, _airport_fta_commuter,
_airport_depots_commuter, _airport_depots_commuter,
lengthof(_airport_depots_commuter), lengthof(_airport_depots_commuter),
@ -141,7 +141,7 @@ void InitializeAirports(void)
NULL, NULL,
_airport_helipad_helidepot, _airport_helipad_helidepot,
4, 4,
HELICOPTERS_ONLY, AirportFTAClass::HELICOPTERS,
_airport_fta_helidepot, _airport_fta_helidepot,
_airport_depots_helidepot, _airport_depots_helidepot,
lengthof(_airport_depots_helidepot), lengthof(_airport_depots_helidepot),
@ -154,7 +154,7 @@ void InitializeAirports(void)
NULL, NULL,
_airport_helipad_helistation, _airport_helipad_helistation,
25, 25,
HELICOPTERS_ONLY, AirportFTAClass::HELICOPTERS,
_airport_fta_helistation, _airport_fta_helistation,
_airport_depots_helistation, _airport_depots_helistation,
lengthof(_airport_depots_helistation), lengthof(_airport_depots_helistation),
@ -192,7 +192,7 @@ AirportFTAClass::AirportFTAClass(
const byte *terminals_, const byte *terminals_,
const byte *helipads_, const byte *helipads_,
const byte entry_point_, const byte entry_point_,
const AcceptPlanes acc_planes_, Flags flags_,
const AirportFTAbuildup *apFA, const AirportFTAbuildup *apFA,
const TileIndexDiffC *depots_, const TileIndexDiffC *depots_,
const byte nof_depots_, const byte nof_depots_,
@ -204,6 +204,7 @@ AirportFTAClass::AirportFTAClass(
terminals(terminals_), terminals(terminals_),
helipads(helipads_), helipads(helipads_),
airport_depots(depots_), airport_depots(depots_),
flags(flags_),
nof_depots(nof_depots_), nof_depots(nof_depots_),
nofelements(AirportGetNofElements(apFA)), nofelements(AirportGetNofElements(apFA)),
entry_point(entry_point_), entry_point(entry_point_),
@ -213,8 +214,6 @@ AirportFTAClass::AirportFTAClass(
{ {
byte nofterminalgroups, nofhelipadgroups; byte nofterminalgroups, nofhelipadgroups;
acc_planes = acc_planes_; // XXX TinyEnumT has no initialisation, only assignment
/* Set up the terminal and helipad count for an airport. /* Set up the terminal and helipad count for an airport.
* TODO: If there are more than 10 terminals or 4 helipads, internal variables * TODO: If there are more than 10 terminals or 4 helipads, internal variables
* need to be changed, so don't allow that for now */ * need to be changed, so don't allow that for now */

View File

@ -24,18 +24,6 @@ enum {
AT_OILRIG = 15 AT_OILRIG = 15
}; };
// do not change unless you change v->subtype too. This aligns perfectly with its current setting
enum AcceptPlanes {
ACC_BEGIN = 0,
AIRCRAFT_ONLY = 0,
ALL = 1,
HELICOPTERS_ONLY = 2,
ACC_END
};
/** Define basic enum properties */
template <> struct EnumPropsT<AcceptPlanes> : MakeEnumPropsT<AcceptPlanes, byte, ACC_BEGIN, ACC_END, ACC_END> {};
typedef TinyEnumT<AcceptPlanes> AcceptPlanesByte;
enum { enum {
AMED_NOSPDCLAMP = 1 << 0, AMED_NOSPDCLAMP = 1 << 0,
@ -133,12 +121,18 @@ struct AirportFTAbuildup;
// Finite sTate mAchine --> FTA // Finite sTate mAchine --> FTA
typedef struct AirportFTAClass { typedef struct AirportFTAClass {
public: public:
enum Flags {
PLANES = 0x1,
HELICOPTERS = 0x2,
ALL = PLANES | HELICOPTERS,
};
AirportFTAClass( AirportFTAClass(
const AirportMovingData *moving_data, const AirportMovingData *moving_data,
const byte *terminals, const byte *terminals,
const byte *helipads, const byte *helipads,
byte entry_point, byte entry_point,
AcceptPlanes acc_planes, Flags flags,
const AirportFTAbuildup *apFA, const AirportFTAbuildup *apFA,
const TileIndexDiffC *depots, const TileIndexDiffC *depots,
byte nof_depots, byte nof_depots,
@ -160,10 +154,10 @@ typedef struct AirportFTAClass {
const byte *terminals; const byte *terminals;
const byte *helipads; const byte *helipads;
const TileIndexDiffC *airport_depots; // gives the position of the depots on the airports const TileIndexDiffC *airport_depots; // gives the position of the depots on the airports
Flags flags;
byte nof_depots; // number of depots this airport has byte nof_depots; // number of depots this airport has
byte nofelements; // number of positions the airport consists of byte nofelements; // number of positions the airport consists of
byte entry_point; // when an airplane arrives at this airport, enter it at position entry_point byte entry_point; // when an airplane arrives at this airport, enter it at position entry_point
AcceptPlanesByte acc_planes; // accept airplanes or helicopters or both
byte size_x; byte size_x;
byte size_y; byte size_y;
byte delta_z; // Z adjustment for helicopter pads byte delta_z; // Z adjustment for helicopter pads

View File

@ -984,8 +984,8 @@ void ShowBuildVehicleWindow(TileIndex tile, byte type)
ResizeWindow(w, 27, 0); ResizeWindow(w, 27, 0);
break; break;
case VEH_Aircraft: case VEH_Aircraft:
AcceptPlanes acc_planes = (tile == 0) ? ALL : GetAirport(GetStationByTile(tile)->airport_type)->acc_planes; bv->filter.flags =
bv->filter.acc_planes = acc_planes; tile == 0 ? AirportFTAClass::ALL : GetAirport(GetStationByTile(tile)->airport_type)->flags;
ResizeWindow(w, 12, 0); ResizeWindow(w, 12, 0);
break; break;
} }

View File

@ -321,7 +321,7 @@ typedef struct {
byte vehicle_type; byte vehicle_type;
union { union {
RailTypeByte railtype; RailTypeByte railtype;
AcceptPlanesByte acc_planes; // AIRCRAFT_ONLY, ALL, HELICOPTERS_ONLY AirportFTAClass::Flags flags;
} filter; } filter;
byte sel_index; // deprecated value, used for 'unified' ship and road byte sel_index; // deprecated value, used for 'unified' ship and road
bool descending_sort_order; bool descending_sort_order;