mirror of https://github.com/OpenTTD/OpenTTD
(svn r19465) -Codechange: support for multi-tile hangars
parent
f2743cd5ed
commit
1579e9ded2
|
@ -96,7 +96,7 @@
|
||||||
if (st->owner != _current_company) return -1;
|
if (st->owner != _current_company) return -1;
|
||||||
if ((st->facilities & FACIL_AIRPORT) == 0) return -1;
|
if ((st->facilities & FACIL_AIRPORT) == 0) return -1;
|
||||||
|
|
||||||
return st->airport.GetSpec()->nof_depots;
|
return st->airport.GetNumHangars();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ TileIndex AIAirport::GetHangarOfAirport(TileIndex tile)
|
/* static */ TileIndex AIAirport::GetHangarOfAirport(TileIndex tile)
|
||||||
|
|
|
@ -29,8 +29,7 @@ AIDepotList::AIDepotList(AITile::TransportType transport_type)
|
||||||
const Station *st;
|
const Station *st;
|
||||||
FOR_ALL_STATIONS(st) {
|
FOR_ALL_STATIONS(st) {
|
||||||
if (st->owner == ::_current_company) {
|
if (st->owner == ::_current_company) {
|
||||||
const AirportSpec *as = st->airport.GetSpec();
|
for (uint i = 0; i < st->airport.GetNumHangars(); i++) {
|
||||||
for (uint i = 0; i < as->nof_depots; i++) {
|
|
||||||
this->AddItem(st->airport.GetHangarTile(i));
|
this->AddItem(st->airport.GetHangarTile(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,13 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "airport.h"
|
#include "airport.h"
|
||||||
#include "map_type.h"
|
#include "map_type.h"
|
||||||
#include "table/airport_movement.h"
|
|
||||||
#include "core/alloc_func.hpp"
|
#include "core/alloc_func.hpp"
|
||||||
#include "date_func.h"
|
#include "date_func.h"
|
||||||
#include "settings_type.h"
|
#include "settings_type.h"
|
||||||
#include "newgrf_airport.h"
|
#include "newgrf_airport.h"
|
||||||
#include "station_base.h"
|
#include "station_base.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
#include "table/airport_movement.h"
|
||||||
#include "table/airporttile_ids.h"
|
#include "table/airporttile_ids.h"
|
||||||
|
|
||||||
/* Uncomment this to print out a full report of the airport-structure
|
/* Uncomment this to print out a full report of the airport-structure
|
||||||
|
|
|
@ -2509,7 +2509,7 @@ static void DuplicateTileTable(AirportSpec *as)
|
||||||
MemCpyT(table_list[i], as->table[i], num_tiles);
|
MemCpyT(table_list[i], as->table[i], num_tiles);
|
||||||
}
|
}
|
||||||
as->table = table_list;
|
as->table = table_list;
|
||||||
TileIndexDiffC *depot_table = MallocT<TileIndexDiffC>(as->nof_depots);
|
HangarTileTable *depot_table = MallocT<HangarTileTable>(as->nof_depots);
|
||||||
MemCpyT(depot_table, as->depot_table, as->nof_depots);
|
MemCpyT(depot_table, as->depot_table, as->nof_depots);
|
||||||
as->depot_table = depot_table;
|
as->depot_table = depot_table;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,12 @@ enum TTDPAirportType {
|
||||||
ATP_TTDP_OILRIG, ///< Same as AT_OILRIG
|
ATP_TTDP_OILRIG, ///< Same as AT_OILRIG
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** A list of all hangar tiles in an airport */
|
||||||
|
struct HangarTileTable {
|
||||||
|
TileIndexDiffC ti;
|
||||||
|
byte hangar_num;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the data structure for an airport.
|
* Defines the data structure for an airport.
|
||||||
*/
|
*/
|
||||||
|
@ -53,8 +59,8 @@ struct AirportSpec {
|
||||||
const struct AirportFTAClass *fsm; ///< the finite statemachine for the default airports
|
const struct AirportFTAClass *fsm; ///< the finite statemachine for the default airports
|
||||||
const AirportTileTable * const *table; ///< list of the tiles composing the airport
|
const AirportTileTable * const *table; ///< list of the tiles composing the airport
|
||||||
byte num_table; ///< number of elements in the table
|
byte num_table; ///< number of elements in the table
|
||||||
const TileIndexDiffC *depot_table; ///< gives the position of the depots on the airports
|
const HangarTileTable *depot_table; ///< gives the position of the depots on the airports
|
||||||
byte nof_depots; ///< the number of depots in this airport
|
byte nof_depots; ///< the number of hangar tiles in this airport
|
||||||
byte size_x; ///< size of airport in x direction
|
byte size_x; ///< size of airport in x direction
|
||||||
byte size_y; ///< size of airport in y direction
|
byte size_y; ///< size of airport in y direction
|
||||||
byte noise_level; ///< noise that this airport generates
|
byte noise_level; ///< noise that this airport generates
|
||||||
|
|
|
@ -70,9 +70,38 @@ struct Airport : public TileArea {
|
||||||
|
|
||||||
FORCEINLINE TileIndex GetHangarTile(uint hangar_num) const
|
FORCEINLINE TileIndex GetHangarTile(uint hangar_num) const
|
||||||
{
|
{
|
||||||
assert(this->tile != INVALID_TILE);
|
const AirportSpec *as = this->GetSpec();
|
||||||
assert(hangar_num < this->GetSpec()->nof_depots);
|
for (uint i = 0; i < as->nof_depots; i++) {
|
||||||
return this->tile + ToTileIndexDiff(this->GetSpec()->depot_table[hangar_num]);
|
if (as->depot_table[i].hangar_num == hangar_num) {
|
||||||
|
return this->tile + ToTileIndexDiff(as->depot_table[i].ti);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
FORCEINLINE uint GetHangarNum(TileIndex tile) const
|
||||||
|
{
|
||||||
|
const AirportSpec *as = this->GetSpec();
|
||||||
|
for (uint i = 0; i < as->nof_depots; i++) {
|
||||||
|
if (this->tile + ToTileIndexDiff(as->depot_table[i].ti) == tile) {
|
||||||
|
return as->depot_table[i].hangar_num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
FORCEINLINE uint GetNumHangars() const
|
||||||
|
{
|
||||||
|
uint num = 0;
|
||||||
|
uint counted = 0;
|
||||||
|
const AirportSpec *as = this->GetSpec();
|
||||||
|
for (uint i = 0; i < as->nof_depots; i++) {
|
||||||
|
if (!HasBit(counted, as->depot_table[i].hangar_num)) {
|
||||||
|
num++;
|
||||||
|
SetBit(counted, as->depot_table[i].hangar_num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return num;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2294,7 +2294,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
const AirportSpec *as = st->airport.GetSpec();
|
const AirportSpec *as = st->airport.GetSpec();
|
||||||
for (uint i = 0; i < as->nof_depots; ++i) {
|
for (uint i = 0; i < st->airport.GetNumHangars(); ++i) {
|
||||||
DeleteWindowById(
|
DeleteWindowById(
|
||||||
WC_VEHICLE_DEPOT, st->airport.GetHangarTile(i)
|
WC_VEHICLE_DEPOT, st->airport.GetHangarTile(i)
|
||||||
);
|
);
|
||||||
|
@ -2916,14 +2916,15 @@ static void AnimateTile_Station(TileIndex tile)
|
||||||
|
|
||||||
static bool ClickTile_Station(TileIndex tile)
|
static bool ClickTile_Station(TileIndex tile)
|
||||||
{
|
{
|
||||||
const BaseStation *st = BaseStation::GetByTile(tile);
|
const BaseStation *bst = BaseStation::GetByTile(tile);
|
||||||
|
|
||||||
if (st->facilities & FACIL_WAYPOINT) {
|
if (bst->facilities & FACIL_WAYPOINT) {
|
||||||
ShowWaypointWindow(Waypoint::From(st));
|
ShowWaypointWindow(Waypoint::From(bst));
|
||||||
} else if (IsHangar(tile)) {
|
} else if (IsHangar(tile)) {
|
||||||
ShowDepotWindow(tile, VEH_AIRCRAFT);
|
const Station *st = Station::From(bst);
|
||||||
|
ShowDepotWindow(st->airport.GetHangarTile(st->airport.GetHangarNum(tile)), VEH_AIRCRAFT);
|
||||||
} else {
|
} else {
|
||||||
ShowStationViewWindow(st->index);
|
ShowStationViewWindow(bst->index);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,7 +407,7 @@ static const AirportFTAbuildup _airport_fta_dummy[] = {
|
||||||
|
|
||||||
/* First element of terminals array tells us how many depots there are (to know size of array)
|
/* First element of terminals array tells us how many depots there are (to know size of array)
|
||||||
* this may be changed later when airports are moved to external file */
|
* this may be changed later when airports are moved to external file */
|
||||||
static const TileIndexDiffC _airport_depots_country[] = {{3, 0}};
|
static const HangarTileTable _airport_depots_country[] = { {{3, 0}, 0} };
|
||||||
static const byte _airport_terminal_country[] = {1, 2};
|
static const byte _airport_terminal_country[] = {1, 2};
|
||||||
static const byte _airport_entries_country[] = {16, 15, 18, 17};
|
static const byte _airport_entries_country[] = {16, 15, 18, 17};
|
||||||
static const AirportFTAbuildup _airport_fta_country[] = {
|
static const AirportFTAbuildup _airport_fta_country[] = {
|
||||||
|
@ -439,7 +439,7 @@ static const AirportFTAbuildup _airport_fta_country[] = {
|
||||||
{ MAX_ELEMENTS, 0, 0, 0 } // end marker. DO NOT REMOVE
|
{ MAX_ELEMENTS, 0, 0, 0 } // end marker. DO NOT REMOVE
|
||||||
};
|
};
|
||||||
|
|
||||||
static const TileIndexDiffC _airport_depots_commuter[] = { { 4, 0 } };
|
static const HangarTileTable _airport_depots_commuter[] = { {{4, 0}, 0} };
|
||||||
static const byte _airport_terminal_commuter[] = { 1, 3 };
|
static const byte _airport_terminal_commuter[] = { 1, 3 };
|
||||||
static const byte _airport_helipad_commuter[] = { 1, 2 };
|
static const byte _airport_helipad_commuter[] = { 1, 2 };
|
||||||
static const byte _airport_entries_commuter[] = {22, 21, 24, 23};
|
static const byte _airport_entries_commuter[] = {22, 21, 24, 23};
|
||||||
|
@ -490,7 +490,7 @@ static const AirportFTAbuildup _airport_fta_commuter[] = {
|
||||||
{ MAX_ELEMENTS, 0, 0, 0 } // end marker. DO NOT REMOVE
|
{ MAX_ELEMENTS, 0, 0, 0 } // end marker. DO NOT REMOVE
|
||||||
};
|
};
|
||||||
|
|
||||||
static const TileIndexDiffC _airport_depots_city[] = { { 5, 0 } };
|
static const HangarTileTable _airport_depots_city[] = { {{5, 0}, 0} };
|
||||||
static const byte _airport_terminal_city[] = { 1, 3 };
|
static const byte _airport_terminal_city[] = { 1, 3 };
|
||||||
static const byte _airport_entries_city[] = {26, 29, 27, 28};
|
static const byte _airport_entries_city[] = {26, 29, 27, 28};
|
||||||
static const AirportFTAbuildup _airport_fta_city[] = {
|
static const AirportFTAbuildup _airport_fta_city[] = {
|
||||||
|
@ -531,7 +531,7 @@ static const AirportFTAbuildup _airport_fta_city[] = {
|
||||||
{ MAX_ELEMENTS, 0, 0, 0 } // end marker. DO NOT REMOVE
|
{ MAX_ELEMENTS, 0, 0, 0 } // end marker. DO NOT REMOVE
|
||||||
};
|
};
|
||||||
|
|
||||||
static const TileIndexDiffC _airport_depots_metropolitan[] = { { 5, 0 } };
|
static const HangarTileTable _airport_depots_metropolitan[] = { {{5, 0}, 0} };
|
||||||
static const byte _airport_terminal_metropolitan[] = { 1, 3 };
|
static const byte _airport_terminal_metropolitan[] = { 1, 3 };
|
||||||
static const byte _airport_entries_metropolitan[] = {20, 19, 22, 21};
|
static const byte _airport_entries_metropolitan[] = {20, 19, 22, 21};
|
||||||
static const AirportFTAbuildup _airport_fta_metropolitan[] = {
|
static const AirportFTAbuildup _airport_fta_metropolitan[] = {
|
||||||
|
@ -570,7 +570,7 @@ static const AirportFTAbuildup _airport_fta_metropolitan[] = {
|
||||||
{ MAX_ELEMENTS, 0, 0, 0 } // end marker. DO NOT REMOVE
|
{ MAX_ELEMENTS, 0, 0, 0 } // end marker. DO NOT REMOVE
|
||||||
};
|
};
|
||||||
|
|
||||||
static const TileIndexDiffC _airport_depots_international[] = { { 0, 3 }, { 6, 1 } };
|
static const HangarTileTable _airport_depots_international[] = { {{0, 3}, 0}, {{6, 1}, 1} };
|
||||||
static const byte _airport_terminal_international[] = { 2, 3, 3 };
|
static const byte _airport_terminal_international[] = { 2, 3, 3 };
|
||||||
static const byte _airport_helipad_international[] = { 1, 2 };
|
static const byte _airport_helipad_international[] = { 1, 2 };
|
||||||
static const byte _airport_entries_international[] = { 38, 37, 40, 39 };
|
static const byte _airport_entries_international[] = { 38, 37, 40, 39 };
|
||||||
|
@ -636,7 +636,7 @@ static const AirportFTAbuildup _airport_fta_international[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* intercontinental */
|
/* intercontinental */
|
||||||
static const TileIndexDiffC _airport_depots_intercontinental[] = { { 0, 5 }, { 8, 4 } };
|
static const HangarTileTable _airport_depots_intercontinental[] = { {{0, 5}, 0}, {{8, 4}, 1} };
|
||||||
static const byte _airport_terminal_intercontinental[] = { 2, 4, 4 };
|
static const byte _airport_terminal_intercontinental[] = { 2, 4, 4 };
|
||||||
static const byte _airport_helipad_intercontinental[] = { 1, 2 };
|
static const byte _airport_helipad_intercontinental[] = { 1, 2 };
|
||||||
static const byte _airport_entries_intercontinental[] = { 44, 43, 46, 45 };
|
static const byte _airport_entries_intercontinental[] = { 44, 43, 46, 45 };
|
||||||
|
@ -748,7 +748,7 @@ static const AirportFTAbuildup _airport_fta_heliport_oilrig[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* helidepots */
|
/* helidepots */
|
||||||
static const TileIndexDiffC _airport_depots_helidepot[] = { { 1, 0 } };
|
static const HangarTileTable _airport_depots_helidepot[] = { {{1, 0}, 0} };
|
||||||
static const byte _airport_helipad_helidepot[] = { 1, 1 };
|
static const byte _airport_helipad_helidepot[] = { 1, 1 };
|
||||||
static const byte _airport_entries_helidepot[] = { 4, 4, 4, 4 };
|
static const byte _airport_entries_helidepot[] = { 4, 4, 4, 4 };
|
||||||
static const AirportFTAbuildup _airport_fta_helidepot[] = {
|
static const AirportFTAbuildup _airport_fta_helidepot[] = {
|
||||||
|
@ -778,7 +778,7 @@ static const AirportFTAbuildup _airport_fta_helidepot[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* helistation */
|
/* helistation */
|
||||||
static const TileIndexDiffC _airport_depots_helistation[] = { { 0, 0 } };
|
static const HangarTileTable _airport_depots_helistation[] = { {{0, 0}, 0} };
|
||||||
static const byte _airport_helipad_helistation[] = { 1, 3 };
|
static const byte _airport_helipad_helistation[] = { 1, 3 };
|
||||||
static const byte _airport_entries_helistation[] = { 25, 25, 25, 25 };
|
static const byte _airport_entries_helistation[] = { 25, 25, 25, 25 };
|
||||||
static const AirportFTAbuildup _airport_fta_helistation[] = {
|
static const AirportFTAbuildup _airport_fta_helistation[] = {
|
||||||
|
|
Loading…
Reference in New Issue