summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-03-18 23:12:38 +0000
committeryexo <yexo@openttd.org>2010-03-18 23:12:38 +0000
commit38f4cb64699af17b3456b93157eb528d6532b46d (patch)
treed2a6a9f247738a42f24309155a0e40af43362cb9 /src
parenta99a7e7a3784ce6678f8ce2402473133efe511e5 (diff)
downloadopenttd-38f4cb64699af17b3456b93157eb528d6532b46d.tar.xz
(svn r19457) -Codechange: introduce AirportOverrideManager to keep track of airports if a newgrf can't be found
Diffstat (limited to 'src')
-rw-r--r--src/airport.h1
-rw-r--r--src/newgrf.cpp9
-rw-r--r--src/newgrf.h1
-rw-r--r--src/newgrf_airport.cpp40
-rw-r--r--src/newgrf_airport.h2
-rw-r--r--src/newgrf_commons.h10
-rw-r--r--src/openttd.cpp1
-rw-r--r--src/saveload/saveload.cpp2
-rw-r--r--src/table/airport_defaults.h2
9 files changed, 65 insertions, 3 deletions
diff --git a/src/airport.h b/src/airport.h
index d1cddba15..2aaddfbc1 100644
--- a/src/airport.h
+++ b/src/airport.h
@@ -39,6 +39,7 @@ enum {
AT_OILRIG = 9,
NEW_AIRPORT_OFFSET = 10,
NUM_AIRPORTS = 128,
+ AT_INVALID = 254,
AT_DUMMY = 255
};
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index d0b6ab8f5..7e0fa228b 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -6258,6 +6258,15 @@ 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++) {
diff --git a/src/newgrf.h b/src/newgrf.h
index 9220c5014..4f6b73acb 100644
--- a/src/newgrf.h
+++ b/src/newgrf.h
@@ -104,6 +104,7 @@ struct GRFFile {
HouseSpec **housespec;
IndustrySpec **industryspec;
IndustryTileSpec **indtspec;
+ struct AirportSpec **airportspec;
struct AirportTileSpec **airtspec;
uint32 param[0x80];
diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp
index aaac23c52..adf1801b6 100644
--- a/src/newgrf_airport.cpp
+++ b/src/newgrf_airport.cpp
@@ -16,11 +16,14 @@
#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];
@@ -33,7 +36,14 @@ AirportSpec AirportSpec::specs[NUM_AIRPORTS];
/* 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;
}
/**
@@ -64,6 +74,8 @@ 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();
}
/**
@@ -203,3 +215,27 @@ void ResetAirportClasses()
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;
+ }
+}
+
diff --git a/src/newgrf_airport.h b/src/newgrf_airport.h
index 61f7b66e1..49a2cc754 100644
--- a/src/newgrf_airport.h
+++ b/src/newgrf_airport.h
@@ -15,6 +15,7 @@
#include "date_type.h"
#include "map_type.h"
#include "strings_type.h"
+#include "newgrf_commons.h"
/* Copy from station_map.h */
typedef byte StationGfx;
@@ -65,6 +66,7 @@ struct AirportSpec {
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);
diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h
index a6b94e2e2..d5b9d9901 100644
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -97,6 +97,15 @@ public:
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:
@@ -111,6 +120,7 @@ public:
extern HouseOverrideManager _house_mngr;
extern IndustryOverrideManager _industry_mngr;
extern IndustryTileOverrideManager _industile_mngr;
+extern AirportOverrideManager _airport_mngr;
extern AirportTileOverrideManager _airporttile_mngr;
uint32 GetTerrainType(TileIndex tile);
diff --git a/src/openttd.cpp b/src/openttd.cpp
index eb7798955..4c25fd1c6 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -313,6 +313,7 @@ static void InitializeDynamicVariables()
_house_mngr.ResetMapping();
_industry_mngr.ResetMapping();
_industile_mngr.ResetMapping();
+ _airport_mngr.ResetMapping();
_airporttile_mngr.ResetMapping();
}
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 0e8fea766..8dc12eea2 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -128,6 +128,7 @@ 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,
@@ -155,6 +156,7 @@ static const ChunkHandler * const _chunk_handlers[] = {
_cargopacket_chunk_handlers,
_autoreplace_chunk_handlers,
_labelmaps_chunk_handlers,
+ _airport_chunk_handlers,
NULL,
};
diff --git a/src/table/airport_defaults.h b/src/table/airport_defaults.h
index 0ff8ea2c2..0ff1bb3a3 100644
--- a/src/table/airport_defaults.h
+++ b/src/table/airport_defaults.h
@@ -378,7 +378,7 @@ static AirportTileTable *_tile_table_helistation[] = {
/** 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) \