2005-07-24 15:12:37 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 21:21:05 +01:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 16:11:33 +01:00
|
|
|
/** @file airport.cpp Functions related to airports. */
|
2007-02-23 01:48:53 +00:00
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
#include "stdafx.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2004-08-09 18:04:08 +01:00
|
|
|
#include "airport.h"
|
2010-02-22 16:09:26 +00:00
|
|
|
#include "map_type.h"
|
2007-12-25 09:48:53 +00:00
|
|
|
#include "core/alloc_func.hpp"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2008-01-13 14:37:30 +00:00
|
|
|
#include "settings_type.h"
|
2010-02-22 16:09:26 +00:00
|
|
|
#include "newgrf_airport.h"
|
2010-03-18 18:38:32 +00:00
|
|
|
#include "station_base.h"
|
2010-03-05 23:21:41 +00:00
|
|
|
#include "table/strings.h"
|
2010-03-19 11:17:52 +00:00
|
|
|
#include "table/airport_movement.h"
|
2010-01-24 20:17:18 +00:00
|
|
|
#include "table/airporttile_ids.h"
|
2009-06-12 15:53:57 +01:00
|
|
|
|
2006-10-14 10:51:04 +01:00
|
|
|
|
2010-03-06 15:38:13 +00:00
|
|
|
static AirportFTAClass _airportfta_dummy(
|
2007-03-29 14:52:34 +01:00
|
|
|
_airport_moving_data_dummy,
|
|
|
|
NULL,
|
2010-08-13 01:36:12 +01:00
|
|
|
0,
|
2007-03-29 14:52:34 +01:00
|
|
|
_airport_entries_dummy,
|
|
|
|
AirportFTAClass::ALL,
|
|
|
|
_airport_fta_dummy,
|
2010-01-15 12:08:08 +00:00
|
|
|
0
|
2007-03-29 14:52:34 +01:00
|
|
|
);
|
|
|
|
|
2010-03-06 15:38:13 +00:00
|
|
|
static AirportFTAClass _airportfta_country(
|
2007-02-03 13:03:11 +00:00
|
|
|
_airport_moving_data_country,
|
2005-01-15 08:58:31 +00:00
|
|
|
_airport_terminal_country,
|
2010-08-13 01:36:12 +01:00
|
|
|
0,
|
2007-02-16 12:10:19 +00:00
|
|
|
_airport_entries_country,
|
2007-02-15 20:35:45 +00:00
|
|
|
AirportFTAClass::ALL | AirportFTAClass::SHORT_STRIP,
|
2005-01-15 08:58:31 +00:00
|
|
|
_airport_fta_country,
|
2010-01-15 12:08:08 +00:00
|
|
|
0
|
2005-01-09 08:49:40 +00:00
|
|
|
);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2010-03-06 15:38:13 +00:00
|
|
|
static AirportFTAClass _airportfta_city(
|
2007-02-03 13:03:11 +00:00
|
|
|
_airport_moving_data_town,
|
2005-01-15 08:58:31 +00:00
|
|
|
_airport_terminal_city,
|
2010-08-13 01:36:12 +01:00
|
|
|
0,
|
2007-02-16 12:10:19 +00:00
|
|
|
_airport_entries_city,
|
2007-02-15 20:16:33 +00:00
|
|
|
AirportFTAClass::ALL,
|
2005-01-15 08:58:31 +00:00
|
|
|
_airport_fta_city,
|
2010-01-15 12:08:08 +00:00
|
|
|
0
|
2005-01-09 08:49:40 +00:00
|
|
|
);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2010-03-06 15:38:13 +00:00
|
|
|
static AirportFTAClass _airportfta_oilrig(
|
|
|
|
_airport_moving_data_oilrig,
|
|
|
|
NULL,
|
2010-08-13 01:36:12 +01:00
|
|
|
1,
|
2010-03-06 15:38:13 +00:00
|
|
|
_airport_entries_heliport_oilrig,
|
|
|
|
AirportFTAClass::HELICOPTERS,
|
|
|
|
_airport_fta_heliport_oilrig,
|
|
|
|
54
|
|
|
|
);
|
|
|
|
|
|
|
|
static AirportFTAClass _airportfta_heliport(
|
|
|
|
_airport_moving_data_heliport,
|
|
|
|
NULL,
|
2010-08-13 01:36:12 +01:00
|
|
|
1,
|
2010-03-06 15:38:13 +00:00
|
|
|
_airport_entries_heliport_oilrig,
|
|
|
|
AirportFTAClass::HELICOPTERS,
|
|
|
|
_airport_fta_heliport_oilrig,
|
|
|
|
60
|
|
|
|
);
|
|
|
|
|
|
|
|
static AirportFTAClass _airportfta_metropolitan(
|
2007-02-03 13:03:11 +00:00
|
|
|
_airport_moving_data_metropolitan,
|
2005-01-15 08:58:31 +00:00
|
|
|
_airport_terminal_metropolitan,
|
2010-08-13 01:36:12 +01:00
|
|
|
0,
|
2007-02-16 12:10:19 +00:00
|
|
|
_airport_entries_metropolitan,
|
2007-02-15 20:16:33 +00:00
|
|
|
AirportFTAClass::ALL,
|
2005-01-15 08:58:31 +00:00
|
|
|
_airport_fta_metropolitan,
|
2010-01-15 12:08:08 +00:00
|
|
|
0
|
2005-01-09 08:49:40 +00:00
|
|
|
);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2010-03-06 15:38:13 +00:00
|
|
|
static AirportFTAClass _airportfta_international(
|
2007-02-03 13:03:11 +00:00
|
|
|
_airport_moving_data_international,
|
2005-01-15 08:58:31 +00:00
|
|
|
_airport_terminal_international,
|
2010-08-13 01:36:12 +01:00
|
|
|
2,
|
2007-02-16 12:10:19 +00:00
|
|
|
_airport_entries_international,
|
2007-02-15 20:16:33 +00:00
|
|
|
AirportFTAClass::ALL,
|
2005-01-15 08:58:31 +00:00
|
|
|
_airport_fta_international,
|
2010-01-15 12:08:08 +00:00
|
|
|
0
|
2005-01-09 08:49:40 +00:00
|
|
|
);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2010-03-06 15:38:13 +00:00
|
|
|
static AirportFTAClass _airportfta_commuter(
|
2007-02-03 13:03:11 +00:00
|
|
|
_airport_moving_data_commuter,
|
2006-06-23 23:05:40 +01:00
|
|
|
_airport_terminal_commuter,
|
2010-08-13 01:36:12 +01:00
|
|
|
2,
|
2007-02-16 12:10:19 +00:00
|
|
|
_airport_entries_commuter,
|
2007-02-15 20:35:45 +00:00
|
|
|
AirportFTAClass::ALL | AirportFTAClass::SHORT_STRIP,
|
2006-06-23 23:05:40 +01:00
|
|
|
_airport_fta_commuter,
|
2010-01-15 12:08:08 +00:00
|
|
|
0
|
2006-06-23 23:05:40 +01:00
|
|
|
);
|
|
|
|
|
2010-03-06 15:38:13 +00:00
|
|
|
static AirportFTAClass _airportfta_helidepot(
|
2007-02-03 13:03:11 +00:00
|
|
|
_airport_moving_data_helidepot,
|
2006-06-23 23:05:40 +01:00
|
|
|
NULL,
|
2010-08-13 01:36:12 +01:00
|
|
|
1,
|
2007-02-16 12:10:19 +00:00
|
|
|
_airport_entries_helidepot,
|
2007-02-15 20:16:33 +00:00
|
|
|
AirportFTAClass::HELICOPTERS,
|
2006-06-23 23:05:40 +01:00
|
|
|
_airport_fta_helidepot,
|
2010-01-15 12:08:08 +00:00
|
|
|
0
|
2006-06-23 23:05:40 +01:00
|
|
|
);
|
|
|
|
|
2010-03-06 15:38:13 +00:00
|
|
|
static AirportFTAClass _airportfta_intercontinental(
|
|
|
|
_airport_moving_data_intercontinental,
|
|
|
|
_airport_terminal_intercontinental,
|
2010-08-13 01:36:12 +01:00
|
|
|
2,
|
2010-03-06 15:38:13 +00:00
|
|
|
_airport_entries_intercontinental,
|
|
|
|
AirportFTAClass::ALL,
|
|
|
|
_airport_fta_intercontinental,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
static AirportFTAClass _airportfta_helistation(
|
2007-02-03 13:03:11 +00:00
|
|
|
_airport_moving_data_helistation,
|
2006-06-23 23:05:40 +01:00
|
|
|
NULL,
|
2010-08-13 01:36:12 +01:00
|
|
|
3,
|
2007-02-16 12:10:19 +00:00
|
|
|
_airport_entries_helistation,
|
2007-02-15 20:16:33 +00:00
|
|
|
AirportFTAClass::HELICOPTERS,
|
2006-06-23 23:05:40 +01:00
|
|
|
_airport_fta_helistation,
|
2010-01-15 12:08:08 +00:00
|
|
|
0
|
2006-06-23 23:05:40 +01:00
|
|
|
);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2010-03-06 15:38:13 +00:00
|
|
|
#include "table/airport_defaults.h"
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-02-04 10:25:57 +00:00
|
|
|
|
|
|
|
static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA);
|
2008-11-25 18:42:06 +00:00
|
|
|
static AirportFTA *AirportBuildAutomata(uint nofelements, const AirportFTAbuildup *apFA);
|
2007-02-04 10:25:57 +00:00
|
|
|
|
|
|
|
|
2010-08-05 13:03:06 +01:00
|
|
|
/**
|
|
|
|
* Rotate the airport moving data to another rotation.
|
|
|
|
* @param orig Pointer to the moving data to rotate.
|
|
|
|
* @param rotation How to rotate the moving data.
|
|
|
|
* @return The rotated moving data.
|
|
|
|
*/
|
|
|
|
AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y)
|
|
|
|
{
|
|
|
|
AirportMovingData amd;
|
|
|
|
amd.flag = orig->flag;
|
|
|
|
amd.direction = ChangeDir(orig->direction, (DirDiff)rotation);
|
|
|
|
switch (rotation) {
|
|
|
|
case DIR_N:
|
|
|
|
amd.x = orig->x;
|
|
|
|
amd.y = orig->y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIR_E:
|
|
|
|
amd.x = orig->y;
|
|
|
|
amd.y = num_tiles_y * TILE_SIZE - orig->x - 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIR_S:
|
|
|
|
amd.x = num_tiles_x * TILE_SIZE - orig->x - 1;
|
|
|
|
amd.y = num_tiles_y * TILE_SIZE - orig->y - 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIR_W:
|
|
|
|
amd.x = num_tiles_x * TILE_SIZE - orig->y - 1;
|
|
|
|
amd.y = orig->x;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
return amd;
|
|
|
|
}
|
2007-02-04 10:25:57 +00:00
|
|
|
|
|
|
|
AirportFTAClass::AirportFTAClass(
|
|
|
|
const AirportMovingData *moving_data_,
|
|
|
|
const byte *terminals_,
|
2010-08-13 01:36:12 +01:00
|
|
|
const byte num_helipads_,
|
2007-02-16 12:10:19 +00:00
|
|
|
const byte *entry_points_,
|
2007-02-15 20:16:33 +00:00
|
|
|
Flags flags_,
|
2006-10-14 00:08:55 +01:00
|
|
|
const AirportFTAbuildup *apFA,
|
2010-01-15 12:08:08 +00:00
|
|
|
byte delta_z_
|
2007-02-04 10:25:57 +00:00
|
|
|
) :
|
|
|
|
moving_data(moving_data_),
|
|
|
|
terminals(terminals_),
|
2010-08-13 01:36:12 +01:00
|
|
|
num_helipads(num_helipads_),
|
2007-02-15 20:16:33 +00:00
|
|
|
flags(flags_),
|
2007-02-04 13:46:21 +00:00
|
|
|
nofelements(AirportGetNofElements(apFA)),
|
2007-02-16 12:10:19 +00:00
|
|
|
entry_points(entry_points_),
|
2010-01-15 12:08:08 +00:00
|
|
|
delta_z(delta_z_)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2006-10-14 10:51:04 +01:00
|
|
|
/* Build the state machine itself */
|
2010-08-17 12:59:09 +01:00
|
|
|
this->layout = AirportBuildAutomata(this->nofelements, apFA);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-02-04 10:25:57 +00:00
|
|
|
AirportFTAClass::~AirportFTAClass()
|
|
|
|
{
|
|
|
|
for (uint i = 0; i < nofelements; i++) {
|
|
|
|
AirportFTA *current = layout[i].next;
|
2004-08-09 18:04:08 +01:00
|
|
|
while (current != NULL) {
|
2007-02-04 10:25:57 +00:00
|
|
|
AirportFTA *next = current->next;
|
2004-08-09 18:04:08 +01:00
|
|
|
free(current);
|
|
|
|
current = next;
|
|
|
|
};
|
|
|
|
}
|
2007-02-04 10:25:57 +00:00
|
|
|
free(layout);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2010-08-01 20:22:34 +01:00
|
|
|
/**
|
|
|
|
* Get the number of elements of a source Airport state automata
|
2006-10-14 10:51:04 +01:00
|
|
|
* Since it is actually just a big array of AirportFTA types, we only
|
2010-08-01 20:44:49 +01:00
|
|
|
* know one element from the other by differing 'position' identifiers
|
|
|
|
*/
|
2006-10-14 00:08:55 +01:00
|
|
|
static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
|
|
|
uint16 nofelements = 0;
|
2006-10-14 00:08:55 +01:00
|
|
|
int temp = apFA[0].position;
|
2005-10-23 14:04:44 +01:00
|
|
|
|
2007-02-20 06:39:09 +00:00
|
|
|
for (uint i = 0; i < MAX_ELEMENTS; i++) {
|
2006-10-14 00:08:55 +01:00
|
|
|
if (temp != apFA[i].position) {
|
2004-08-09 18:04:08 +01:00
|
|
|
nofelements++;
|
2006-10-14 00:08:55 +01:00
|
|
|
temp = apFA[i].position;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
2006-10-14 00:08:55 +01:00
|
|
|
if (apFA[i].position == MAX_ELEMENTS) break;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
return nofelements;
|
|
|
|
}
|
|
|
|
|
2007-02-04 10:25:57 +00:00
|
|
|
|
2008-11-25 18:42:06 +00:00
|
|
|
static AirportFTA *AirportBuildAutomata(uint nofelements, const AirportFTAbuildup *apFA)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2007-02-04 10:25:57 +00:00
|
|
|
AirportFTA *FAutomata = MallocT<AirportFTA>(nofelements);
|
2006-10-14 10:51:04 +01:00
|
|
|
uint16 internalcounter = 0;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-02-04 10:25:57 +00:00
|
|
|
for (uint i = 0; i < nofelements; i++) {
|
2007-02-20 06:39:09 +00:00
|
|
|
AirportFTA *current = &FAutomata[i];
|
2006-10-14 10:51:04 +01:00
|
|
|
current->position = apFA[internalcounter].position;
|
|
|
|
current->heading = apFA[internalcounter].heading;
|
|
|
|
current->block = apFA[internalcounter].block;
|
2006-10-14 00:08:55 +01:00
|
|
|
current->next_position = apFA[internalcounter].next;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-11-25 18:42:06 +00:00
|
|
|
/* outgoing nodes from the same position, create linked list */
|
2006-10-14 00:08:55 +01:00
|
|
|
while (current->position == apFA[internalcounter + 1].position) {
|
2007-01-11 17:29:39 +00:00
|
|
|
AirportFTA *newNode = MallocT<AirportFTA>(1);
|
2005-10-23 14:04:44 +01:00
|
|
|
|
2006-10-14 10:51:04 +01:00
|
|
|
newNode->position = apFA[internalcounter + 1].position;
|
|
|
|
newNode->heading = apFA[internalcounter + 1].heading;
|
|
|
|
newNode->block = apFA[internalcounter + 1].block;
|
2006-10-14 00:08:55 +01:00
|
|
|
newNode->next_position = apFA[internalcounter + 1].next;
|
2008-11-25 18:42:06 +00:00
|
|
|
/* create link */
|
2006-10-14 00:08:55 +01:00
|
|
|
current->next = newNode;
|
|
|
|
current = current->next;
|
2004-08-09 18:04:08 +01:00
|
|
|
internalcounter++;
|
2007-02-20 06:39:09 +00:00
|
|
|
}
|
2006-10-14 00:08:55 +01:00
|
|
|
current->next = NULL;
|
2004-08-09 18:04:08 +01:00
|
|
|
internalcounter++;
|
|
|
|
}
|
2007-02-04 10:25:57 +00:00
|
|
|
return FAutomata;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2006-07-26 04:33:12 +01:00
|
|
|
const AirportFTAClass *GetAirport(const byte airport_type)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2010-03-06 23:54:54 +00:00
|
|
|
if (airport_type == AT_DUMMY) return &_airportfta_dummy;
|
2010-03-06 15:38:13 +00:00
|
|
|
return AirportSpec::Get(airport_type)->fsm;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
2010-03-18 18:38:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the vehicle position when an aircraft is build at the given tile
|
|
|
|
* @param hangar_tile The tile on which the vehicle is build
|
|
|
|
* @return The position (index in airport node array) where the aircraft ends up
|
|
|
|
*/
|
|
|
|
byte GetVehiclePosOnBuild(TileIndex hangar_tile)
|
|
|
|
{
|
|
|
|
const Station *st = Station::GetByTile(hangar_tile);
|
2010-03-18 21:02:20 +00:00
|
|
|
const AirportFTAClass *apc = st->airport.GetFTA();
|
2010-03-18 18:38:32 +00:00
|
|
|
/* When we click on hangar we know the tile it is on. By that we know
|
|
|
|
* its position in the array of depots the airport has.....we can search
|
|
|
|
* layout for #th position of depot. Since layout must start with a listing
|
|
|
|
* of all depots, it is simple */
|
|
|
|
for (uint i = 0;; i++) {
|
2010-03-19 09:58:46 +00:00
|
|
|
if (st->airport.GetHangarTile(i) == hangar_tile) {
|
2010-03-18 18:38:32 +00:00
|
|
|
assert(apc->layout[i].heading == HANGAR);
|
|
|
|
return apc->layout[i].position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|