summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/airport.h12
-rw-r--r--src/industrytype.h10
-rw-r--r--src/newgrf.cpp4
-rw-r--r--src/newgrf_airporttiles.cpp46
-rw-r--r--src/newgrf_airporttiles.h12
-rw-r--r--src/newgrf_commons.h21
-rw-r--r--src/table/airporttiles.h4
7 files changed, 90 insertions, 19 deletions
diff --git a/src/airport.h b/src/airport.h
index 49d86b62a..ffd453d0d 100644
--- a/src/airport.h
+++ b/src/airport.h
@@ -16,12 +16,14 @@
#include "map_type.h"
#include "date_type.h"
-/** Current limits for airports */
+/** Some airport-related constants */
enum {
- MAX_TERMINALS = 10, ///< maximum number of terminals per airport
- MAX_HELIPADS = 4, ///< maximum number of helipads per airport
- MAX_ELEMENTS = 255, ///< maximum number of aircraft positions at airport
- NUM_AIRPORTTILES = 74, ///< total number of airport tiles
+ MAX_TERMINALS = 10, ///< maximum number of terminals per airport
+ MAX_HELIPADS = 4, ///< maximum number of helipads per airport
+ MAX_ELEMENTS = 255, ///< maximum number of aircraft positions at airport
+ NUM_AIRPORTTILES = 256, ///< total number of airport tiles
+ NEW_AIRPORTTILE_OFFSET = 74, ///< offset of first newgrf airport tile
+ INVALID_AIRPORTTILE = NUM_AIRPORTTILES, ///< id for an invalid airport tile
};
/** Airport types */
diff --git a/src/industrytype.h b/src/industrytype.h
index 6ee5101e6..c3570d785 100644
--- a/src/industrytype.h
+++ b/src/industrytype.h
@@ -19,6 +19,7 @@
#include "landscape_type.h"
#include "strings_type.h"
#include "cargo_type.h"
+#include "newgrf_commons.h"
enum {
CLEAN_RANDOMSOUNDS, ///< Free the dynamically allocated sounds table
@@ -94,15 +95,6 @@ struct IndustryTileTable {
IndustryGfx gfx;
};
-/** Data related to the handling of grf files. Common to both industry and industry tile */
-struct GRFFileProps {
- uint16 subst_id;
- uint16 local_id; ///< id defined by the grf file for this industry
- struct SpriteGroup *spritegroup; ///< pointer to the different sprites of the industry
- const struct GRFFile *grffile; ///< grf file that introduced this industry
- uint16 override; ///< id of the entity been replaced by
-};
-
/**
* Defines the data structure for constructing industry.
*/
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 5f356d369..54372575f 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -35,6 +35,7 @@
#include "newgrf_commons.h"
#include "newgrf_townname.h"
#include "newgrf_industries.h"
+#include "newgrf_airporttiles.h"
#include "rev.h"
#include "fios.h"
#include "rail.h"
@@ -5768,6 +5769,9 @@ static void ResetNewGRFData()
ResetStationClasses();
ResetCustomStations();
+ /* Reset airport-related structures */
+ AirportTileSpec::ResetAirportTiles();
+
/* Reset canal sprite groups and flags */
memset(_water_feature, 0, sizeof(_water_feature));
diff --git a/src/newgrf_airporttiles.cpp b/src/newgrf_airporttiles.cpp
index 0735016a6..0eda02e1a 100644
--- a/src/newgrf_airporttiles.cpp
+++ b/src/newgrf_airporttiles.cpp
@@ -11,10 +11,15 @@
#include "stdafx.h"
#include "airport.h"
+#include "newgrf.h"
#include "newgrf_airporttiles.h"
#include "table/airporttiles.h"
+AirportTileSpec AirportTileSpec::tiles[NUM_AIRPORTTILES];
+
+AirportTileOverrideManager _airporttile_mngr(NEW_AIRPORTTILE_OFFSET, NUM_AIRPORTTILES, INVALID_AIRPORTTILE);
+
/**
* Retrieve airport tile spec for the given airport tile
* @param gfx index of airport tile
@@ -22,8 +27,43 @@
*/
/* static */ const AirportTileSpec *AirportTileSpec::Get(StationGfx gfx)
{
- assert(gfx < NUM_AIRPORTTILES);
- extern const AirportTileSpec _origin_airporttile_specs[];
- return &_origin_airporttile_specs[gfx];
+ assert(gfx < lengthof(AirportTileSpec::tiles));
+ return &AirportTileSpec::tiles[gfx];
+}
+
+/**
+ * This function initializes the tile array of AirportTileSpec
+ */
+void AirportTileSpec::ResetAirportTiles()
+{
+ memset(&AirportTileSpec::tiles, 0, sizeof(AirportTileSpec::tiles));
+ memcpy(&AirportTileSpec::tiles, &_origin_airporttile_specs, sizeof(_origin_airporttile_specs));
+
+ /* Reset any overrides that have been set. */
+ _airporttile_mngr.ResetOverride();
+}
+
+void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts)
+{
+ StationGfx airpt_id = this->AddEntityID(airpts->grf_prop.local_id, airpts->grf_prop.grffile->grfid, airpts->grf_prop.subst_id);
+
+ if (airpt_id == invalid_ID) {
+ grfmsg(1, "AirportTile.SetEntitySpec: Too many airport tiles allocated. Ignoring.");
+ return;
+ }
+
+ memcpy(&AirportTileSpec::tiles[airpt_id], airpts, sizeof(*airpts));
+
+ /* Now add the overrides. */
+ for (int i = 0; i < max_offset; i++) {
+ AirportTileSpec *overridden_airpts = &AirportTileSpec::tiles[i];
+
+ if (entity_overrides[i] != airpts->grf_prop.local_id || grfid_overrides[i] != airpts->grf_prop.grffile->grfid) continue;
+
+ overridden_airpts->grf_prop.override = airpt_id;
+ overridden_airpts->enabled = false;
+ entity_overrides[i] = invalid_ID;
+ grfid_overrides[i] = 0;
+ }
}
diff --git a/src/newgrf_airporttiles.h b/src/newgrf_airporttiles.h
index 8c38da661..0cf148357 100644
--- a/src/newgrf_airporttiles.h
+++ b/src/newgrf_airporttiles.h
@@ -13,6 +13,8 @@
#define NEWGRF_AIRPORTTILES_H
#include "station_map.h"
+#include "newgrf_commons.h"
+#include "airport.h"
/**
* Defines the data structure of each indivudual tile of an airport.
@@ -21,7 +23,17 @@ struct AirportTileSpec {
uint16 animation_info; ///< Information about the animation (is it looping, how many loops etc)
uint8 animation_speed; ///< The speed of the animation
+ bool enabled; ///< entity still available (by default true). newgrf can disable it, though
+ GRFFileProps grf_prop; ///< properties related the the grf file
+
static const AirportTileSpec *Get(StationGfx gfx);
+
+ static void ResetAirportTiles();
+
+private:
+ static AirportTileSpec tiles[NUM_AIRPORTTILES];
+
+ friend void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts);
};
#endif /* NEWGRF_AIRPORTTILES_H */
diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h
index 56a16aaeb..e531c824e 100644
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -97,12 +97,33 @@ public:
void SetEntitySpec(const IndustryTileSpec *indts);
};
+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 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
+ uint16 override; ///< id of the entity been replaced by
+};
+
#endif /* NEWGRF_COMMONS_H */
diff --git a/src/table/airporttiles.h b/src/table/airporttiles.h
index d01b5df66..5d7c61c18 100644
--- a/src/table/airporttiles.h
+++ b/src/table/airporttiles.h
@@ -13,7 +13,7 @@
#define AIRPORTTILES_H
/** Writes all airport tile properties in the AirportTile struct */
-#define AT(num_frames, anim_speed) {(1 << 8) | num_frames, anim_speed}
+#define AT(num_frames, anim_speed) {(1 << 8) | num_frames, anim_speed, true, {INVALID_AIRPORTTILE, 0, NULL, NULL, INVALID_AIRPORTTILE}}
/** Writes an airport tile without animation in the AirportTile struct */
#define AT_NOANIM {0xFFFF, 2}
@@ -104,7 +104,7 @@ static const AirportTileSpec _origin_airporttile_specs[] = {
AT(4, 1), // APT_GRASS_FENCE_NE_FLAG_2
};
-assert_compile(NUM_AIRPORTTILES == lengthof(_origin_airporttile_specs));
+assert_compile(NEW_AIRPORTTILE_OFFSET == lengthof(_origin_airporttile_specs));
#undef AT_NOANIM
#undef AT