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
 
@@ -2081,12 +2081,16 @@
 
			</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"
 
				>
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -2078,12 +2078,16 @@
 
			</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"
 
				>
source.list
Show inline comments
 
@@ -447,12 +447,13 @@ 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
src/airport.h
Show inline comments
 
@@ -36,12 +36,13 @@ enum {
 
	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,
src/newgrf.cpp
Show inline comments
 
@@ -6255,12 +6255,21 @@ static void FinaliseIndustriesArray()
 
 * 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]);
 
				}
src/newgrf.h
Show inline comments
 
@@ -101,12 +101,13 @@ struct GRFFile {
 
	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.
src/newgrf_airport.cpp
Show inline comments
 
@@ -13,30 +13,40 @@
 
#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
 
@@ -61,12 +71,14 @@ bool AirportSpec::IsAvailable() const
 
 */
 
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
 
@@ -200,6 +212,30 @@ void ResetAirportClasses()
 
	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
 
@@ -12,12 +12,13 @@
 
#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;
 
@@ -62,12 +63,13 @@ struct AirportSpec {
 
	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;
 

	
src/newgrf_commons.h
Show inline comments
 
@@ -94,12 +94,21 @@ 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) :
 
@@ -108,12 +117,13 @@ public:
 
	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);
 

	
src/openttd.cpp
Show inline comments
 
@@ -310,12 +310,13 @@ 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
src/saveload/saveload.cpp
Show inline comments
 
@@ -125,12 +125,13 @@ extern const ChunkHandler _ai_chunk_hand
 
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,
 
@@ -152,12 +153,13 @@ static const ChunkHandler * const _chunk
 
	_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
src/table/airport_defaults.h
Show inline comments
 
@@ -375,13 +375,13 @@ static AirportTileTable *_tile_table_hel
 

	
 
#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)
 

	
0 comments (0 inline, 0 general)