airport.c
author bjarni
Sun, 06 Nov 2005 01:15:10 +0000
changeset 2607 08f42ae6fbfc
parent 2549 f1d3b383d557
child 2639 8a7342eb3a78
permissions -rw-r--r--
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1299
diff changeset
     4
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1093
diff changeset
     5
#include "debug.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 222
diff changeset
     6
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "airport.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
     8
#include "macros.h"
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
     9
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
AirportFTAClass *CountryAirport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
AirportFTAClass *CityAirport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
AirportFTAClass *Heliport, *Oilrig;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
AirportFTAClass *MetropolitanAirport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
AirportFTAClass *InternationalAirport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    18
																				const byte *terminals, const byte *helipads,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
																				const byte entry_point,  const byte acc_planes,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
																				const AirportFTAbuildup *FA,
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 699
diff changeset
    21
																				const TileIndexDiffC *depots, const byte nof_depots);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
static void AirportFTAClass_Destructor(AirportFTAClass *Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
static uint16 AirportGetNofElements(const AirportFTAbuildup *FA);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuildup *FA);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
static byte AirportTestFTA(const AirportFTAClass *Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
/*static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
static byte AirportBlockToString(uint32 block);*/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1019
diff changeset
    30
void InitializeAirports(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	// country airport
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    33
	CountryAirport = malloc(sizeof(AirportFTAClass));
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    34
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    35
	AirportFTAClass_Constructor(
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    36
		CountryAirport,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    37
		_airport_terminal_country,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    38
		NULL,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    39
		16,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    40
		ALL,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    41
		_airport_fta_country,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    42
		_airport_depots_country,
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    43
		lengthof(_airport_depots_country)
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    44
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
	// city airport
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    47
	CityAirport = malloc(sizeof(AirportFTAClass));
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    48
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    49
	AirportFTAClass_Constructor(
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    50
		CityAirport,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    51
		_airport_terminal_city,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    52
		NULL,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    53
		19,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    54
		ALL,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    55
		_airport_fta_city,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    56
		_airport_depots_city,
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    57
		lengthof(_airport_depots_city)
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    58
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
	// metropolitan airport
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    61
	MetropolitanAirport = malloc(sizeof(AirportFTAClass));
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    62
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    63
	AirportFTAClass_Constructor(
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    64
		MetropolitanAirport,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    65
		_airport_terminal_metropolitan,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    66
		NULL,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    67
		20,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    68
		ALL,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    69
		_airport_fta_metropolitan,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    70
		_airport_depots_metropolitan,
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    71
		lengthof(_airport_depots_metropolitan)
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    72
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	// international airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	InternationalAirport = (AirportFTAClass *)malloc(sizeof(AirportFTAClass));
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    76
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    77
	AirportFTAClass_Constructor(
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    78
		InternationalAirport,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    79
		_airport_terminal_international,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    80
		_airport_helipad_international,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    81
		37,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    82
		ALL,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    83
		_airport_fta_international,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    84
		_airport_depots_international,
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    85
		lengthof(_airport_depots_international)
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    86
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	// heliport, oilrig
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	Heliport = (AirportFTAClass *)malloc(sizeof(AirportFTAClass));
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    90
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    91
	AirportFTAClass_Constructor(
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    92
		Heliport,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    93
		NULL,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    94
		_airport_helipad_heliport_oilrig,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    95
		7,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    96
		HELICOPTERS_ONLY,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    97
		_airport_fta_heliport_oilrig,
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    98
		NULL,
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    99
		0
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   100
	);
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   101
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	Oilrig = Heliport;  // exactly the same structure for heliport/oilrig, so share state machine
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1019
diff changeset
   105
void UnInitializeAirports(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	AirportFTAClass_Destructor(CountryAirport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	AirportFTAClass_Destructor(CityAirport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	AirportFTAClass_Destructor(Heliport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
	AirportFTAClass_Destructor(MetropolitanAirport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	AirportFTAClass_Destructor(InternationalAirport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   115
																				const byte *terminals, const byte *helipads,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
																				const byte entry_point, const byte acc_planes,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
																				const AirportFTAbuildup *FA,
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 699
diff changeset
   118
																				const TileIndexDiffC *depots, const byte nof_depots)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
{
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   120
	byte nofterminals, nofhelipads;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   121
	byte nofterminalgroups = 0;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   122
	byte nofhelipadgroups = 0;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   123
	const byte * curr;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   124
	int i;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   125
	nofterminals = nofhelipads = 0;
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   126
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   127
	//now we read the number of terminals we have
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   128
	if (terminals != NULL) {
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   129
		i = terminals[0];
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   130
		nofterminalgroups = i;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   131
		curr = terminals;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   132
		while (i-- > 0) {
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   133
			curr++;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   134
			assert(*curr != 0);	//we don't want to have an empty group
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   135
			nofterminals += *curr;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   136
		}
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   137
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   138
	}
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   139
	Airport->terminals = terminals;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   140
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   141
	//read helipads
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   142
	if (helipads != NULL) {
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   143
		i = helipads[0];
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   144
		nofhelipadgroups = i;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   145
		curr = helipads;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   146
		while (i-- > 0) {
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   147
			curr++;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   148
			assert(*curr != 0); //no empty groups please
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   149
			nofhelipads += *curr;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   150
		}
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   151
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   152
	}
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   153
	Airport->helipads = helipads;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   154
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	// if there are more terminals than 6, internal variables have to be changed, so don't allow that
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	// same goes for helipads
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	if (nofterminals > MAX_TERMINALS) { printf("Currently only maximum of %2d terminals are supported (you wanted %2d)\n", MAX_TERMINALS, nofterminals);}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	if (nofhelipads > MAX_HELIPADS) { printf("Currently only maximum of %2d helipads are supported (you wanted %2d)\n", MAX_HELIPADS, nofhelipads);}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	// terminals/helipads are divided into groups. Groups are computed by dividing the number
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	// of terminals by the number of groups. Half in half. If #terminals is uneven, first group
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	// will get the less # of terminals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	assert(nofterminals <= MAX_TERMINALS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	assert(nofhelipads <= MAX_HELIPADS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	Airport->nofelements = AirportGetNofElements(FA);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
	// check
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	if (entry_point >= Airport->nofelements) {printf("Entry point (%2d) must be within the airport positions (which is max %2d)\n", entry_point, Airport->nofelements);}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	assert(entry_point < Airport->nofelements);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	Airport->acc_planes = acc_planes;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
	Airport->entry_point = entry_point;
699
02b8b9c9194f (svn r1149) Fix hack which abuses first TileIndex of airport depot array as number of depots (similar change as in map branch)
tron
parents: 679
diff changeset
   173
	Airport->airport_depots = depots;
02b8b9c9194f (svn r1149) Fix hack which abuses first TileIndex of airport depot array as number of depots (similar change as in map branch)
tron
parents: 679
diff changeset
   174
	Airport->nof_depots = nof_depots;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	// build the state machine
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	AirportBuildAutomata(Airport, FA);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   179
	DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s); Entry Point %d",
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   180
		Airport->nofelements, nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, Airport->entry_point
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   181
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	{
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   185
		byte ret = AirportTestFTA(Airport);
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   186
		if (ret != MAX_ELEMENTS) printf("ERROR with element: %d\n", ret - 1);
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   187
		assert(ret == MAX_ELEMENTS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	// print out full information
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
	// true  -- full info including heading, block, etc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	// false -- short info, only position and next position
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	//AirportPrintOut(Airport, false);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
static void AirportFTAClass_Destructor(AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	AirportFTA *current, *next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
	for (i = 0; i < Airport->nofelements; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
		current = Airport->layout[i].next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
		while (current != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
			next = current->next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
			free(current);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
			current = next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
	free(Airport->layout);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
	free(Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
static uint16 AirportGetNofElements(const AirportFTAbuildup *FA)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	uint16 nofelements = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
	int temp = FA[0].position;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   217
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	for (i = 0; i < MAX_ELEMENTS; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
		if (temp != FA[i].position) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
			nofelements++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
			temp = FA[i].position;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
		}
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   223
		if (FA[i].position == MAX_ELEMENTS) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	return nofelements;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuildup *FA)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	AirportFTA *FAutomata;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	AirportFTA *current;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	uint16 internalcounter, i;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   233
	FAutomata = malloc(sizeof(AirportFTA) * Airport->nofelements);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	Airport->layout = FAutomata;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	internalcounter = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
	for (i = 0; i < Airport->nofelements; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
		current = &Airport->layout[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
		current->position = FA[internalcounter].position;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
		current->heading  = FA[internalcounter].heading;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
		current->block    = FA[internalcounter].block;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
		current->next_position = FA[internalcounter].next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
		// outgoing nodes from the same position, create linked list
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   245
		while (current->position == FA[internalcounter + 1].position) {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   246
			AirportFTA* newNode = malloc(sizeof(AirportFTA));
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   247
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   248
			newNode->position = FA[internalcounter + 1].position;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   249
			newNode->heading  = FA[internalcounter + 1].heading;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   250
			newNode->block    = FA[internalcounter + 1].block;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   251
			newNode->next_position = FA[internalcounter + 1].next_in_chain;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
			// create link
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
			current->next_in_chain = newNode;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
			current = current->next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
			internalcounter++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
		} // while
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
		current->next_in_chain = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
		internalcounter++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
static byte AirportTestFTA(const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	byte position, i, next_element;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	AirportFTA *temp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
	next_element = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	for (i = 0; i < Airport->nofelements; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
		position = Airport->layout[i].position;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   270
		if (position != next_element) return i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
		temp = &Airport->layout[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
		do {
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   274
			if (temp->heading > MAX_HEADINGS && temp->heading != 255) return i;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   275
			if (temp->heading == 0 && temp->next_in_chain != 0) return i;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   276
			if (position != temp->position) return i;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   277
			if (temp->next_position >= Airport->nofelements) return i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
			temp = temp->next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
		} while (temp != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
		next_element++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	return MAX_ELEMENTS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   285
#if 0
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   286
static const char* const _airport_heading_strings[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	"TO_ALL",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	"HANGAR",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	"TERM1",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
	"TERM2",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
	"TERM3",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
	"TERM4",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
	"TERM5",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
	"TERM6",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
	"HELIPAD1",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	"HELIPAD2",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	"TAKEOFF",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	"STARTTAKEOFF",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	"ENDTAKEOFF",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	"HELITAKEOFF",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	"FLYING",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
	"LANDING",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	"ENDLANDING",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	"HELILANDING",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	"HELIENDLANDING",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	"DUMMY"	// extra heading for 255
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	AirportFTA *temp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
	uint16 i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	byte heading;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	printf("(P = Current Position; NP = Next Position)\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
	for (i = 0; i < Airport->nofelements; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
		temp = &Airport->layout[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
		if (full_report) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
			heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
			printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
						 _airport_heading_strings[heading], AirportBlockToString(temp->block));
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   322
		} else {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   323
			printf("P:%2d NP:%2d", temp->position, temp->next_position);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
		while (temp->next_in_chain != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
			temp = temp->next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
			if (full_report) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
				heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
				printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
							_airport_heading_strings[heading], AirportBlockToString(temp->block));
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   331
			} else {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   332
				printf("P:%2d NP:%2d", temp->position, temp->next_position);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
		printf("\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
static byte AirportBlockToString(uint32 block)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
	byte i = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
	if (block & 0xffff0000) { block >>= 16; i += 16; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
	if (block & 0x0000ff00) { block >>= 8;  i += 8; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
	if (block & 0x000000f0) { block >>= 4;  i += 4; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
	if (block & 0x0000000c) { block >>= 2;  i += 2; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
	if (block & 0x00000002) { i += 1; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
	return i;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   349
}
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   350
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
const AirportFTAClass* GetAirport(const byte airport_type)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
	AirportFTAClass *Airport = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	//FIXME -- AircraftNextAirportPos_and_Order -> Needs something nicer, don't like this code
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
	// needs constant change if more airports are added
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
	switch (airport_type) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
		case AT_SMALL: Airport = CountryAirport; break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
		case AT_LARGE: Airport = CityAirport; break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
		case AT_METROPOLITAN: Airport = MetropolitanAirport; break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
		case AT_HELIPORT: Airport = Heliport; break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
		case AT_OILRIG: Airport = Oilrig; break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
		case AT_INTERNATIONAL: Airport = InternationalAirport; break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
		default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
			#ifdef DEBUG__
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
				printf("Airport AircraftNextAirportPos_and_Order not yet implemented\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
			#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
			assert(airport_type <= AT_INTERNATIONAL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
	return Airport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
}
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   372
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   373
uint32 GetValidAirports(void)
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   374
{
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   375
	uint32 bytemask = _avail_aircraft; /// sets the first 3 bytes, 0 - 2, @see AdjustAvailAircraft()
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   376
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   377
	// 1980-1-1 is --> 21915
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   378
	// 1990-1-1 is --> 25568
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   379
	if (_date >= 21915) {SETBIT(bytemask, 3);}	// metropilitan airport 1980
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   380
	if (_date >= 25568) {SETBIT(bytemask, 4);}	// international airport 1990
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   381
	return bytemask;
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   382
}