Changeset - r14727:9ddd9a15dd3b
[Not reviewed]
master
0 5 0
yexo - 15 years ago 2010-03-05 23:21:35
yexo@openttd.org
(svn r19325) -Codechange: introduce airport classes and split the default airports in 4 classes
5 files changed with 200 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -2021,24 +2021,29 @@ STR_STATION_BUILD_AIRPORT_METRO_AIRPORT 
 
STR_STATION_BUILD_AIRPORT_INTERNATIONAL_AIRPORT                 :{BLACK}International
 
STR_STATION_BUILD_AIRPORT_COMMUTER_AIRPORT                      :{BLACK}Commuter
 
STR_STATION_BUILD_AIRPORT_INTERCONTINENTAL_AIRPORT              :{BLACK}Intercontinental
 
STR_STATION_BUILD_AIRPORT_HELIPORT                              :{BLACK}Heliport
 
STR_STATION_BUILD_AIRPORT_HELIDEPOT                             :{BLACK}Helidepot
 
STR_STATION_BUILD_AIRPORT_HELISTATION                           :{BLACK}Helistation
 

	
 
STR_STATION_BUILD_AIRPORT_SMALL_AIRPORTS                        :{BLACK}Small airports
 
STR_STATION_BUILD_AIRPORT_LARGE_AIRPORTS                        :{BLACK}Large airports
 
STR_STATION_BUILD_AIRPORT_HUB_AIRPORTS                          :{BLACK}Hub airports
 
STR_STATION_BUILD_AIRPORT_HELIPORTS                             :{BLACK}Helicopter airports
 

	
 
STR_AIRPORT_CLASS_SMALL                                         :Small airports
 
STR_AIRPORT_CLASS_LARGE                                         :Large airports
 
STR_AIRPORT_CLASS_HUB                                           :Hub airports
 
STR_AIRPORT_CLASS_HELIPORTS                                     :Helicopter airports
 

	
 
STR_STATION_BUILD_NOISE                                         :{BLACK}Noise generated: {GOLD}{COMMA}
 

	
 
# Landscaping toolbar
 
STR_LANDSCAPING_TOOLBAR                                         :{WHITE}Landscaping
 
STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND                  :{BLACK}Lower a corner of land
 
STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND                  :{BLACK}Raise a corner of land
 
STR_LANDSCAPING_LEVEL_LAND_TOOLTIP                              :{BLACK}Level land
 
STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND                           :{BLACK}Purchase land for future use
 

	
 
# Tree planting window (last two for SE only)
 
STR_PLANT_TREE_CAPTION                                          :{WHITE}Trees
 
STR_PLANT_TREE_TOOLTIP                                          :{BLACK}Select tree type to plant
src/newgrf.cpp
Show inline comments
 
@@ -5898,24 +5898,25 @@ static void ResetNewGRFData()
 
	ResetCustomHouses();
 
	ResetHouses();
 

	
 
	/* Reset the industries structures*/
 
	ResetCustomIndustries();
 
	ResetIndustries();
 

	
 
	/* Reset station classes */
 
	ResetStationClasses();
 
	ResetCustomStations();
 

	
 
	/* Reset airport-related structures */
 
	ResetAirportClasses();
 
	ResetCustomAirports();
 
	AirportSpec::ResetAirports();
 
	AirportTileSpec::ResetAirportTiles();
 

	
 
	/* Reset canal sprite groups and flags */
 
	memset(_water_feature, 0, sizeof(_water_feature));
 

	
 
	/* Reset the snowline table. */
 
	ClearSnowLine();
 

	
 
	/* Reset NewGRF files */
 
	ResetNewGRF();
 
@@ -6624,24 +6625,25 @@ static void AfterLoadGRFs()
 

	
 
	/* Add all new houses to the house array. */
 
	FinaliseHouseArray();
 

	
 
	/* Add all new industries to the industry array. */
 
	FinaliseIndustriesArray();
 

	
 
	/* Create dynamic list of industry legends for smallmap_gui.cpp */
 
	BuildIndustriesLegend();
 

	
 
	/* Add all new airports to the airports array. */
 
	FinaliseAirportsArray();
 
	BindAirportSpecs();
 

	
 
	/* Update the townname generators list */
 
	InitGRFTownGeneratorNames();
 

	
 
	/* Run all queued vehicle list order changes */
 
	CommitVehicleListOrderChanges();
 

	
 
	/* Load old shore sprites in new position, if they were replaced by ActionA */
 
	ActivateOldShore();
 

	
 
	/* Set up custom rail types */
 
	InitRailTypes();
src/newgrf_airport.cpp
Show inline comments
 
@@ -5,27 +5,32 @@
 
 * 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/>.
 
 */
 

	
 
/** @file newgrf_airport.h NewGRF handling of airports. */
 

	
 
#include "stdafx.h"
 
#include "airport.h"
 
#include "newgrf_airport.h"
 
#include "date_func.h"
 
#include "settings_type.h"
 
#include "core/alloc_type.hpp"
 
#include "newgrf.h"
 
#include "table/strings.h"
 

	
 
AirportSpec AirportSpec::dummy = {NULL, NULL, 0, 0, 0, 0, 0, MIN_YEAR, MIN_YEAR, ATP_TTDP_LARGE};
 
AirportSpec AirportSpec::oilrig = {NULL, NULL, 0, 1, 1, 0, 4, MIN_YEAR, MIN_YEAR, ATP_TTDP_OILRIG};
 
static AirportClass _airport_classes[APC_MAX];
 

	
 
AirportSpec AirportSpec::dummy = {NULL, NULL, 0, 0, 0, 0, 0, MIN_YEAR, MIN_YEAR, ATP_TTDP_LARGE, APC_BEGIN};
 
AirportSpec AirportSpec::oilrig = {NULL, NULL, 0, 1, 1, 0, 4, MIN_YEAR, MIN_YEAR, ATP_TTDP_OILRIG, APC_BEGIN};
 

	
 
AirportSpec AirportSpec::specs[NUM_AIRPORTS];
 

	
 
/**
 
 * Retrieve airport spec for the given airport. If an override is available
 
 *  it is returned.
 
 * @param type index of airport
 
 * @return A pointer to the corresponding AirportSpec
 
 */
 
/* static */ const AirportSpec *AirportSpec::Get(byte type)
 
{
 
	if (type == AT_OILRIG) return &oilrig;
 
@@ -53,12 +58,150 @@ bool AirportSpec::IsAvailable() const
 
	return _cur_year <= this->max_year;
 
}
 

	
 
/**
 
 * This function initialize the airportspec array.
 
 */
 
void AirportSpec::ResetAirports()
 
{
 
	extern const AirportSpec _origin_airport_specs[];
 
	memset(&AirportSpec::specs, 0, sizeof(AirportSpec::specs));
 
	memcpy(&AirportSpec::specs, &_origin_airport_specs, sizeof(AirportSpec) * NUM_AIRPORTS);
 
}
 

	
 
/**
 
 * Allocate an airport class for the given class id
 
 * @param cls A 32 bit value identifying the class
 
 * @return Index into _airport_classes of allocated class
 
 */
 
AirportClassID AllocateAirportClass(uint32 cls)
 
{
 
	for (AirportClassID i = APC_BEGIN; i < APC_MAX; i++) {
 
		if (_airport_classes[i].id == cls) {
 
			/* ClassID is already allocated, so reuse it. */
 
			return i;
 
		} else if (_airport_classes[i].id == 0) {
 
			/* This class is empty, so allocate it to the ClassID. */
 
			_airport_classes[i].id = cls;
 
			return i;
 
		}
 
	}
 

	
 
	grfmsg(2, "AllocateAirportClass: already allocated %d classes, using small airports class", APC_MAX);
 
	return APC_SMALL;
 
}
 

	
 
/**
 
 * Set the name of an airport class
 
 * @param id The id of the class to change the name from
 
 * @param name The new name for the class
 
 */
 
void SetAirportClassName(AirportClassID id, StringID name)
 
{
 
	assert(id < APC_MAX);
 
	_airport_classes[id].name = name;
 
}
 

	
 
/**
 
 * Retrieve the name of an airport class
 
 * @param id The id of the airport class to get the name from
 
 * @return The name of the given class
 
 */
 
StringID GetAirportClassName(AirportClassID id)
 
{
 
	assert(id < APC_MAX);
 
	return _airport_classes[id].name;
 
}
 

	
 
/**
 
 * Get the number of airport classes in use
 
 * @return The number of airport classes
 
 */
 
uint GetNumAirportClasses()
 
{
 
	uint i;
 
	for (i = APC_BEGIN; i < APC_MAX && _airport_classes[i].id != 0; i++) {}
 
	return i;
 
}
 

	
 
/**
 
 * Return the number of airports for the given airport class.
 
 * @param id Index of the airport class.
 
 * @return Number of airports in the class.
 
 */
 
uint GetNumAirportsInClass(AirportClassID id)
 
{
 
	assert(id < APC_MAX);
 
	return _airport_classes[id].airports;
 
}
 

	
 
/**
 
 * Tie an airport spec to its airport class.
 
 * @param statspec The airport spec.
 
 */
 
static void BindAirportSpecToClass(AirportSpec *as)
 
{
 
	assert(as->aclass < APC_MAX);
 
	AirportClass *airport_class = &_airport_classes[as->aclass];
 

	
 
	int i = airport_class->airports++;
 
	airport_class->spec = ReallocT(airport_class->spec, airport_class->airports);
 

	
 
	airport_class->spec[i] = as;
 
}
 

	
 
/**
 
 * Tie all airportspecs to their class.
 
 */
 
void BindAirportSpecs()
 
{
 
	for (int i = 0; i < NUM_AIRPORTS; i++) {
 
		AirportSpec *as = AirportSpec::GetWithoutOverride(i);
 
		BindAirportSpecToClass(as);
 
	}
 
}
 

	
 

	
 
/**
 
 * Retrieve an airport spec from a class.
 
 * @param aclass Index of the airport class.
 
 * @param airport The airport index with the class.
 
 * @return The station spec.
 
 */
 
const AirportSpec *GetAirportSpecFromClass(AirportClassID aclass, uint airport)
 
{
 
	assert(aclass < APC_MAX);
 
	assert(airport < _airport_classes[aclass].airports);
 

	
 
	return _airport_classes[aclass].spec[airport];
 
}
 

	
 
/**
 
 * Reset airport classes to their default state.
 
 * This includes initialising the defaults classes with an empty
 
 * entry, for standard airports.
 
 */
 
void ResetAirportClasses()
 
{
 
	for (AirportClassID i = APC_BEGIN; i < APC_MAX; i++) {
 
		_airport_classes[i].id = 0;
 
		_airport_classes[i].name = STR_EMPTY;
 
		_airport_classes[i].airports = 0;
 

	
 
		free(_airport_classes[i].spec);
 
		_airport_classes[i].spec = NULL;
 
	}
 

	
 
	/* Set up initial data */
 
	AirportClassID id = AllocateAirportClass('SMAL');
 
	SetAirportClassName(id, STR_AIRPORT_CLASS_SMALL);
 

	
 
	id = AllocateAirportClass('LARG');
 
	SetAirportClassName(id, STR_AIRPORT_CLASS_LARGE);
 

	
 
	id = AllocateAirportClass('HUB_');
 
	SetAirportClassName(id, STR_AIRPORT_CLASS_HUB);
 

	
 
	id = AllocateAirportClass('HELI');
 
	SetAirportClassName(id, STR_AIRPORT_CLASS_HELIPORTS);
 
}
 

	
src/newgrf_airport.h
Show inline comments
 
@@ -5,60 +5,93 @@
 
 * 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/>.
 
 */
 

	
 
/** @file newgrf_airport.h NewGRF handling of airports. */
 

	
 
#ifndef NEWGRF_AIRPORT_H
 
#define NEWGRF_AIRPORT_H
 

	
 
#include "date_type.h"
 
#include "map_type.h"
 
#include "strings_type.h"
 

	
 
/* Copy from station_map.h */
 
typedef byte StationGfx;
 

	
 
struct AirportTileTable {
 
	TileIndexDiffC ti;
 
	StationGfx gfx;
 
};
 

	
 
/** List of default airport classes. */
 
enum AirportClassID {
 
	APC_BEGIN     = 0,  ///< Lowest valid airport class id
 
	APC_SMALL     = 0,  ///< id for small airports class
 
	APC_LARGE,          ///< id for large airports class
 
	APC_HUB,            ///< id for hub airports class
 
	APC_HELIPORT,       ///< id for heliports
 
	APC_MAX       = 16, ///< maximum number of airport classes
 
};
 

	
 
/** Allow incrementing of AirportClassID variables */
 
DECLARE_POSTFIX_INCREMENT(AirportClassID);
 

	
 
/** TTDP airport types. Used to map our types to TTDPatch's */
 
enum TTDPAirportType {
 
	ATP_TTDP_SMALL,    ///< Same as AT_SMALL
 
	ATP_TTDP_LARGE,    ///< Same as AT_LARGE
 
	ATP_TTDP_HELIPORT, ///< Same as AT_HELIPORT
 
	ATP_TTDP_OILRIG,   ///< Same as AT_OILRIG
 
};
 

	
 
/**
 
 * Defines the data structure for an airport.
 
 */
 
struct AirportSpec {
 
	const AirportTileTable * const *table; ///< list of the tiles composing the airport
 
	const TileIndexDiffC *depot_table;     ///< gives the position of the depots on the airports
 
	byte nof_depots;                       ///< the number of depots in this airport
 
	byte size_x;                           ///< size of airport in x direction
 
	byte size_y;                           ///< size of airport in y direction
 
	byte noise_level;                      ///< noise that this airport generates
 
	byte catchment;                        ///< catchment area of this airport
 
	Year min_year;                         ///< first year the airport is available
 
	Year max_year;                         ///< last year the airport is available
 
	TTDPAirportType ttd_airport_type;      ///< ttdpatch airport type (Small/Large/Helipad/Oilrig)
 
	AirportClassID aclass;                 ///< the class to which this airport type belongs
 

	
 
	static const AirportSpec *Get(byte type);
 
	static AirportSpec *GetWithoutOverride(byte type);
 

	
 
	bool IsAvailable() const;
 

	
 
	static void ResetAirports();
 

	
 
	static AirportSpec dummy;
 
	static AirportSpec oilrig;
 

	
 
private:
 
	static AirportSpec specs[NUM_AIRPORTS];
 
};
 

	
 
/** Information related to airport classes. */
 
struct AirportClass {
 
	uint32 id;          ///< ID of this class, e.g. 'SMAL', 'LARG', 'HUB_', 'HELI', etc.
 
	StringID name;      ///< name of this class
 
	uint airports;      ///< number of airports in this class
 
	AirportSpec **spec; ///< array of airport specifications
 
};
 

	
 
void ResetAirportClasses();
 
AirportClassID AllocateAirportClass(uint32 cls);
 
void SetAirportClassName(AirportClassID id, StringID name);
 
StringID GetAirportClassName(AirportClassID id);
 

	
 
uint GetNumAirportClasses();
 
uint GetNumAirportsInClass(AirportClassID id);
 

	
 
void BindAirportSpecs();
 
const AirportSpec *GetAirportSpecFromClass(AirportClassID aclass, uint airport);
 

	
 
#endif /* NEWGRF_AIRPORT_H */
src/table/airport_defaults.h
Show inline comments
 
@@ -368,43 +368,43 @@ static AirportTileTable _tile_table_heli
 
	MK(3, 1, APT_HELIPAD_3_FENCE_SE_SW),
 
	MKEND
 
};
 

	
 
static AirportTileTable *_tile_table_helistation[] = {
 
	_tile_table_helistation_0,
 
};
 

	
 
#undef MK
 
#undef MKEND
 

	
 
/** General AirportSpec definition. */
 
#define AS_GENERIC(att, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type) \
 
	{att, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type}
 
#define AS_GENERIC(att, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id) \
 
	{att, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id}
 

	
 
/** AirportSpec definition for airports without any depot. */
 
#define AS_ND(ap_name, size_x, size_y, min_year, max_year, catchment, noise, ttdpatch_type) \
 
	AS_GENERIC(_tile_table_##ap_name, NULL, 0, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type)
 
#define AS_ND(ap_name, size_x, size_y, min_year, max_year, catchment, noise, ttdpatch_type, class_id) \
 
	AS_GENERIC(_tile_table_##ap_name, NULL, 0, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id)
 

	
 
/** AirportSpec definition for airports with at least one depot. */
 
#define AS(ap_name, size_x, size_y, min_year, max_year, catchment, noise, ttdpatch_type) \
 
	AS_GENERIC(_tile_table_##ap_name, _airport_depots_##ap_name, lengthof(_airport_depots_##ap_name), size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type)
 
#define AS(ap_name, size_x, size_y, min_year, max_year, catchment, noise, ttdpatch_type, class_id) \
 
	AS_GENERIC(_tile_table_##ap_name, _airport_depots_##ap_name, lengthof(_airport_depots_##ap_name), size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id)
 

	
 
/* The helidepot and helistation have ATP_TTDP_SMALL because they are at ground level */
 
extern const AirportSpec _origin_airport_specs[] = {
 
	AS(country, 4, 3, 0, 1959, 4, 3, ATP_TTDP_SMALL),
 
	AS(city, 6, 6, 1955, MAX_YEAR, 5, 5, ATP_TTDP_LARGE),
 
	AS_ND(heliport, 1, 1, 1963, MAX_YEAR, 4, 1, ATP_TTDP_HELIPORT),
 
	AS(metropolitan, 6, 6, 1980, MAX_YEAR, 6, 8, ATP_TTDP_LARGE),
 
	AS(international, 7, 7, 1990, MAX_YEAR, 8, 17, ATP_TTDP_LARGE),
 
	AS(commuter, 5, 4, 1983, MAX_YEAR, 4, 4, ATP_TTDP_SMALL),
 
	AS(helidepot, 2, 2, 1976, MAX_YEAR, 4, 2, ATP_TTDP_SMALL),
 
	AS(intercontinental, 9, 11, 2002, MAX_YEAR, 10, 25, ATP_TTDP_LARGE),
 
	AS(helistation, 4, 2, 1980, MAX_YEAR, 4, 3, ATP_TTDP_SMALL),
 
	AS(country, 4, 3, 0, 1959, 4, 3, ATP_TTDP_SMALL, APC_SMALL),
 
	AS(city, 6, 6, 1955, MAX_YEAR, 5, 5, ATP_TTDP_LARGE, APC_LARGE),
 
	AS_ND(heliport, 1, 1, 1963, MAX_YEAR, 4, 1, ATP_TTDP_HELIPORT, APC_HELIPORT),
 
	AS(metropolitan, 6, 6, 1980, MAX_YEAR, 6, 8, ATP_TTDP_LARGE, APC_LARGE),
 
	AS(international, 7, 7, 1990, MAX_YEAR, 8, 17, ATP_TTDP_LARGE, APC_HUB),
 
	AS(commuter, 5, 4, 1983, MAX_YEAR, 4, 4, ATP_TTDP_SMALL, APC_SMALL),
 
	AS(helidepot, 2, 2, 1976, MAX_YEAR, 4, 2, ATP_TTDP_SMALL, APC_HELIPORT),
 
	AS(intercontinental, 9, 11, 2002, MAX_YEAR, 10, 25, ATP_TTDP_LARGE, APC_HUB),
 
	AS(helistation, 4, 2, 1980, MAX_YEAR, 4, 3, ATP_TTDP_SMALL, APC_HELIPORT),
 
};
 

	
 
assert_compile(NUM_AIRPORTS == lengthof(_origin_airport_specs));
 

	
 
#undef AS
 
#undef AS_ND
 
#undef AS_GENERIC
 

	
 
#endif /* AIRPORT_DEFAULTS_H */
0 comments (0 inline, 0 general)