Changeset - r14851:b3915c863ff3
[Not reviewed]
master
0 12 0
yexo - 14 years ago 2010-03-18 23:12:38
yexo@openttd.org
(svn r19457) -Codechange: introduce AirportOverrideManager to keep track of airports if a newgrf can't be found
12 files changed with 74 insertions and 3 deletions:
0 comments (0 inline, 0 general)
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -2075,24 +2075,28 @@
 
		<Filter
 
			Name="Save/Load handlers"
 
			>
 
			<File
 
				RelativePath=".\..\src\saveload\afterload.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\ai_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\airport_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\animated_tile_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\autoreplace_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\cargopacket_sl.cpp"
 
				>
 
			</File>
 
			<File
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -2072,24 +2072,28 @@
 
		<Filter
 
			Name="Save/Load handlers"
 
			>
 
			<File
 
				RelativePath=".\..\src\saveload\afterload.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\ai_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\airport_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\animated_tile_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\autoreplace_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\cargopacket_sl.cpp"
 
				>
 
			</File>
 
			<File
source.list
Show inline comments
 
@@ -441,24 +441,25 @@ timetable_cmd.cpp
 
town_cmd.cpp
 
train_cmd.cpp
 
tree_cmd.cpp
 
tunnelbridge_cmd.cpp
 
unmovable_cmd.cpp
 
vehicle_cmd.cpp
 
water_cmd.cpp
 
waypoint_cmd.cpp
 

	
 
# Save/Load handlers
 
saveload/afterload.cpp
 
saveload/ai_sl.cpp
 
saveload/airport_sl.cpp
 
saveload/animated_tile_sl.cpp
 
saveload/autoreplace_sl.cpp
 
saveload/cargopacket_sl.cpp
 
saveload/cheat_sl.cpp
 
saveload/company_sl.cpp
 
saveload/depot_sl.cpp
 
saveload/economy_sl.cpp
 
saveload/engine_sl.cpp
 
saveload/gamelog_sl.cpp
 
saveload/group_sl.cpp
 
saveload/industry_sl.cpp
 
saveload/labelmaps_sl.cpp
src/airport.h
Show inline comments
 
@@ -30,24 +30,25 @@ enum {
 
	AT_SMALL         =   0,
 
	AT_LARGE         =   1,
 
	AT_HELIPORT      =   2,
 
	AT_METROPOLITAN  =   3,
 
	AT_INTERNATIONAL =   4,
 
	AT_COMMUTER      =   5,
 
	AT_HELIDEPOT     =   6,
 
	AT_INTERCON      =   7,
 
	AT_HELISTATION   =   8,
 
	AT_OILRIG        =   9,
 
	NEW_AIRPORT_OFFSET = 10,
 
	NUM_AIRPORTS     =  128,
 
	AT_INVALID       = 254,
 
	AT_DUMMY         = 255
 
};
 

	
 
enum {
 
	AMED_NOSPDCLAMP = 1 << 0,
 
	AMED_TAKEOFF    = 1 << 1,
 
	AMED_SLOWTURN   = 1 << 2,
 
	AMED_LAND       = 1 << 3,
 
	AMED_EXACTPOS   = 1 << 4,
 
	AMED_BRAKE      = 1 << 5,
 
	AMED_HELI_RAISE = 1 << 6,
 
	AMED_HELI_LOWER = 1 << 7,
src/newgrf.cpp
Show inline comments
 
@@ -6249,24 +6249,33 @@ static void FinaliseIndustriesArray()
 
	}
 
}
 

	
 
/**
 
 * Add all new airports to the airport array. Airport properties can be set at any
 
 * time in the GRF file, so we can only add a airport spec to the airport array
 
 * after the file has finished loading.
 
 */
 
static void FinaliseAirportsArray()
 
{
 
	const GRFFile * const *end = _grf_files.End();
 
	for (GRFFile **file = _grf_files.Begin(); file != end; file++) {
 
		AirportSpec **&airportspec = (*file)->airportspec;
 
		if (airportspec != NULL) {
 
			for (int i = 0; i < NUM_AIRPORTS; i++) {
 
				if (airportspec[i] != NULL && airportspec[i]->enabled) {
 
					_airport_mngr.SetEntitySpec(airportspec[i]);
 
				}
 
			}
 
		}
 

	
 
		AirportTileSpec **&airporttilespec = (*file)->airtspec;
 
		if (airporttilespec != NULL) {
 
			for (int i = 0; i < NUM_AIRPORTTILES; i++) {
 
				if (airporttilespec[i] != NULL && airporttilespec[i]->enabled) {
 
					_airporttile_mngr.SetEntitySpec(airporttilespec[i]);
 
				}
 
			}
 
		}
 
	}
 
}
 

	
 
/* Here we perform initial decoding of some special sprites (as are they
src/newgrf.h
Show inline comments
 
@@ -95,24 +95,25 @@ struct GRFFile {
 
	int spriteset_numents;
 
	int spriteset_feature;
 

	
 
	int spritegroups_count;
 
	struct SpriteGroup **spritegroups;
 

	
 
	uint sound_offset;
 

	
 
	StationSpec **stations;
 
	HouseSpec **housespec;
 
	IndustrySpec **industryspec;
 
	IndustryTileSpec **indtspec;
 
	struct AirportSpec **airportspec;
 
	struct AirportTileSpec **airtspec;
 

	
 
	uint32 param[0x80];
 
	uint param_end;  ///< one more than the highest set parameter
 

	
 
	GRFLabel *label; ///< Pointer to the first label. This is a linked list, not an array.
 

	
 
	uint8 cargo_max;
 
	CargoLabel *cargo_list;
 
	uint8 cargo_map[NUM_CARGO];
 

	
 
	uint8 railtype_max;
src/newgrf_airport.cpp
Show inline comments
 
@@ -7,42 +7,52 @@
 
 * 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 "newgrf_commons.h"
 
#include "table/strings.h"
 

	
 
static AirportClass _airport_classes[APC_MAX];
 

	
 
AirportSpec AirportSpec::dummy = {NULL, NULL, 0, NULL, 0, 0, 0, 0, 0, MIN_YEAR, MIN_YEAR, STR_NULL, ATP_TTDP_LARGE, APC_BEGIN, false};
 
AirportOverrideManager _airport_mngr(NEW_AIRPORT_OFFSET, NUM_AIRPORTS, AT_INVALID);
 

	
 
AirportSpec AirportSpec::dummy = {NULL, NULL, 0, NULL, 0, 0, 0, 0, 0, MIN_YEAR, MIN_YEAR, STR_NULL, ATP_TTDP_LARGE, APC_BEGIN, false, {AT_INVALID, 0, NULL, NULL, AT_INVALID}};
 

	
 
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)
 
{
 
	assert(type < lengthof(AirportSpec::specs));
 
	return &AirportSpec::specs[type];
 
	const AirportSpec *as = &AirportSpec::specs[type];
 
	if (type >= NEW_AIRPORT_OFFSET && !as->enabled) {
 
		byte subst_id = _airport_mngr.GetSubstituteID(type);
 
		if (subst_id == AT_INVALID) return as;
 
		as = &AirportSpec::specs[subst_id];
 
	}
 
	if (as->grf_prop.override != AT_INVALID) return &AirportSpec::specs[as->grf_prop.override];
 
	return as;
 
}
 

	
 
/**
 
 * Retrieve airport spec for the given airport. Even if an override is
 
 *  available the base spec is returned.
 
 * @param type index of airport
 
 * @return A pointer to the corresponding AirportSpec
 
 */
 
/* static */ AirportSpec *AirportSpec::GetWithoutOverride(byte type)
 
{
 
	assert(type < lengthof(AirportSpec::specs));
 
	return &AirportSpec::specs[type];
 
@@ -55,24 +65,26 @@ bool AirportSpec::IsAvailable() const
 
	if (_settings_game.station.never_expire_airports) return true;
 
	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) * NEW_AIRPORT_OFFSET);
 

	
 
	_airport_mngr.ResetOverride();
 
}
 

	
 
/**
 
 * 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. */
 
@@ -194,12 +206,36 @@ void ResetAirportClasses()
 
	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);
 
}
 

	
 
void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
 
{
 
	byte airport_id = this->AddEntityID(as->grf_prop.local_id, as->grf_prop.grffile->grfid, as->grf_prop.subst_id);
 

	
 
	if (airport_id == invalid_ID) {
 
		grfmsg(1, "Airport.SetEntitySpec: Too many airports allocated. Ignoring.");
 
		return;
 
	}
 

	
 
	memcpy(AirportSpec::GetWithoutOverride(airport_id), as, sizeof(*as));
 

	
 
	/* Now add the overrides. */
 
	for (int i = 0; i < max_offset; i++) {
 
		AirportSpec *overridden_as = AirportSpec::GetWithoutOverride(i);
 

	
 
		if (entity_overrides[i] != as->grf_prop.local_id || grfid_overrides[i] != as->grf_prop.grffile->grfid) continue;
 

	
 
		overridden_as->grf_prop.override = airport_id;
 
		overridden_as->enabled = false;
 
		entity_overrides[i] = invalid_ID;
 
		grfid_overrides[i] = 0;
 
	}
 
}
 

	
src/newgrf_airport.h
Show inline comments
 
@@ -6,24 +6,25 @@
 
 * 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"
 
#include "newgrf_commons.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
 
@@ -56,24 +57,25 @@ struct AirportSpec {
 
	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
 
	StringID name;                         ///< name of this airport
 
	TTDPAirportType ttd_airport_type;      ///< ttdpatch airport type (Small/Large/Helipad/Oilrig)
 
	AirportClassID aclass;                 ///< the class to which this airport type belongs
 
	/* Newgrf data */
 
	bool enabled;                          ///< entity still avaible (by default true).newgrf can disable it, though
 
	GRFFileProps grf_prop;                 ///< properties related the the grf file
 

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

	
 
	bool IsAvailable() const;
 

	
 
	static void ResetAirports();
 

	
 
	/** Get the index of this spec. */
 
	byte GetIndex() const
 
	{
 
		assert(this >= specs && this < endof(specs));
src/newgrf_commons.h
Show inline comments
 
@@ -88,38 +88,48 @@ public:
 

	
 
struct IndustryTileSpec;
 
class IndustryTileOverrideManager : public OverrideManagerBase {
 
protected:
 
	virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
 
public:
 
	IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
 
			OverrideManagerBase(offset, maximum, invalid) {}
 

	
 
	void SetEntitySpec(const IndustryTileSpec *indts);
 
};
 

	
 
struct AirportSpec;
 
class AirportOverrideManager : public OverrideManagerBase {
 
public:
 
	AirportOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
 
			OverrideManagerBase(offset, maximum, invalid) {}
 

	
 
	void SetEntitySpec(AirportSpec *inds);
 
};
 

	
 
struct AirportTileSpec;
 
class AirportTileOverrideManager : public OverrideManagerBase {
 
protected:
 
	virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
 
public:
 
	AirportTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
 
			OverrideManagerBase(offset, maximum, invalid) {}
 

	
 
	void SetEntitySpec(const AirportTileSpec *ats);
 
};
 

	
 
extern HouseOverrideManager _house_mngr;
 
extern IndustryOverrideManager _industry_mngr;
 
extern IndustryTileOverrideManager _industile_mngr;
 
extern AirportOverrideManager _airport_mngr;
 
extern AirportTileOverrideManager _airporttile_mngr;
 

	
 
uint32 GetTerrainType(TileIndex tile);
 
TileIndex GetNearbyTile(byte parameter, TileIndex tile);
 
uint32 GetNearbyTileInformation(TileIndex tile);
 

	
 
/** Data related to the handling of grf files. */
 
struct GRFFileProps {
 
	uint16 subst_id;
 
	uint16 local_id;                      ///< id defined by the grf file for this entity
 
	struct SpriteGroup *spritegroup;      ///< pointer to the different sprites of the entity
 
	const struct GRFFile *grffile;        ///< grf file that introduced this entity
src/openttd.cpp
Show inline comments
 
@@ -304,24 +304,25 @@ static void ParseResolution(Dimension *r
 

	
 
	res->width  = max(strtoul(s, NULL, 0), 64UL);
 
	res->height = max(strtoul(t + 1, NULL, 0), 64UL);
 
}
 

	
 
static void InitializeDynamicVariables()
 
{
 
	/* Dynamic stuff needs to be initialized somewhere... */
 
	_engine_mngr.ResetToDefaultMapping();
 
	_house_mngr.ResetMapping();
 
	_industry_mngr.ResetMapping();
 
	_industile_mngr.ResetMapping();
 
	_airport_mngr.ResetMapping();
 
	_airporttile_mngr.ResetMapping();
 
}
 

	
 

	
 
/** Unitializes drivers, frees allocated memory, cleans pools, ...
 
 * Generally, prepares the game for shutting down
 
 */
 
static void ShutdownGame()
 
{
 
	IConsoleFree();
 

	
 
	if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
src/saveload/saveload.cpp
Show inline comments
 
@@ -119,24 +119,25 @@ extern const ChunkHandler _town_chunk_ha
 
extern const ChunkHandler _sign_chunk_handlers[];
 
extern const ChunkHandler _station_chunk_handlers[];
 
extern const ChunkHandler _industry_chunk_handlers[];
 
extern const ChunkHandler _economy_chunk_handlers[];
 
extern const ChunkHandler _subsidy_chunk_handlers[];
 
extern const ChunkHandler _ai_chunk_handlers[];
 
extern const ChunkHandler _animated_tile_chunk_handlers[];
 
extern const ChunkHandler _newgrf_chunk_handlers[];
 
extern const ChunkHandler _group_chunk_handlers[];
 
extern const ChunkHandler _cargopacket_chunk_handlers[];
 
extern const ChunkHandler _autoreplace_chunk_handlers[];
 
extern const ChunkHandler _labelmaps_chunk_handlers[];
 
extern const ChunkHandler _airport_chunk_handlers[];
 

	
 
static const ChunkHandler * const _chunk_handlers[] = {
 
	_gamelog_chunk_handlers,
 
	_map_chunk_handlers,
 
	_misc_chunk_handlers,
 
	_name_chunk_handlers,
 
	_cheat_chunk_handlers,
 
	_setting_chunk_handlers,
 
	_veh_chunk_handlers,
 
	_waypoint_chunk_handlers,
 
	_depot_chunk_handlers,
 
	_order_chunk_handlers,
 
@@ -146,24 +147,25 @@ static const ChunkHandler * const _chunk
 
	_engine_chunk_handlers,
 
	_town_chunk_handlers,
 
	_sign_chunk_handlers,
 
	_station_chunk_handlers,
 
	_company_chunk_handlers,
 
	_ai_chunk_handlers,
 
	_animated_tile_chunk_handlers,
 
	_newgrf_chunk_handlers,
 
	_group_chunk_handlers,
 
	_cargopacket_chunk_handlers,
 
	_autoreplace_chunk_handlers,
 
	_labelmaps_chunk_handlers,
 
	_airport_chunk_handlers,
 
	NULL,
 
};
 

	
 
/**
 
 * Iterate over all chunk handlers.
 
 * @param ch the chunk handler iterator
 
 */
 
#define FOR_ALL_CHUNK_HANDLERS(ch) \
 
	for (const ChunkHandler * const *chsc = _chunk_handlers; *chsc != NULL; chsc++) \
 
		for (const ChunkHandler *ch = *chsc; ch != NULL; ch = (ch->flags & CH_LAST) ? NULL : ch + 1)
 

	
 
static SaveLoadParams _sl;
src/table/airport_defaults.h
Show inline comments
 
@@ -369,25 +369,25 @@ static AirportTileTable _tile_table_heli
 
	MKEND
 
};
 

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

	
 
#undef MK
 
#undef MKEND
 

	
 
/** General AirportSpec definition. */
 
#define AS_GENERIC(fsm, att, att_len, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id, name, enabled) \
 
	{fsm, att, att_len, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, name, ttdpatch_type, class_id, enabled}
 
	{fsm, att, att_len, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, name, ttdpatch_type, class_id, enabled, {AT_INVALID, 0, NULL, NULL, AT_INVALID}}
 

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

	
 
/** 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, class_id, name) \
 
	AS_GENERIC(&_airportfta_##ap_name, _tile_table_##ap_name, lengthof(_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, name, true)
 

	
 
/* The helidepot and helistation have ATP_TTDP_SMALL because they are at ground level */
0 comments (0 inline, 0 general)