(svn r10256) -Add: Addition of IndustryTileOverrideManager
authorbelugas
Thu, 21 Jun 2007 17:09:10 +0000
changeset 7496 628e1191ee45
parent 7495 3bed6c98b8f3
child 7497 f7ee60306e04
(svn r10256) -Add: Addition of IndustryTileOverrideManager
src/newgrf_commons.cpp
src/newgrf_commons.h
src/newgrf_industries.cpp
--- a/src/newgrf_commons.cpp	Thu Jun 21 16:53:57 2007 +0000
+++ b/src/newgrf_commons.cpp	Thu Jun 21 17:09:10 2007 +0000
@@ -220,6 +220,29 @@
 	_industry_specs[ind_id].enabled = true;
 }
 
+void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
+{
+	IndustryGfx indt_id = this->AddEntityID(its->grf_prop.local_id, its->grf_prop.grffile->grfid, its->grf_prop.subst_id);
+
+	if (indt_id == invalid_ID) {
+		grfmsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
+		return;
+	}
+
+	memcpy(&_industry_tile_specs[indt_id], its, sizeof(*its));
+
+	/* Now add the overrides. */
+	for (int i = 0; i < max_offset; i++) {
+		IndustryTileSpec *overridden_its = &_industry_tile_specs[i];
+
+		if (entity_overrides[i] != its->grf_prop.local_id) continue;
+
+		overridden_its->grf_prop.override = indt_id;
+		overridden_its->enabled = false;
+		entity_overrides[i] = invalid_ID;
+	}
+}
+
 /** Function used by houses (and soon industries) to get information
  * on type of "terrain" the tile it is queries sits on.
  * @param tile TileIndex of the tile been queried
--- a/src/newgrf_commons.h	Thu Jun 21 16:53:57 2007 +0000
+++ b/src/newgrf_commons.h	Thu Jun 21 17:09:10 2007 +0000
@@ -76,8 +76,19 @@
 		void SetEntitySpec(const IndustrySpec *inds);
 };
 
+
+struct IndustryTileSpec;
+class IndustryTileOverrideManager : public OverrideManagerBase
+{
+	public:
+		IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
+				OverrideManagerBase(offset, maximum, invalid) {};
+		void SetEntitySpec(const IndustryTileSpec *indts);
+};
+
 extern HouseOverrideManager _house_mngr;
 extern IndustryOverrideManager _industry_mngr;
+extern IndustryTileOverrideManager _industile_mngr;
 
 uint32 GetTerrainType(TileIndex tile);
 TileIndex GetNearbyTile(byte parameter, TileIndex tile);
--- a/src/newgrf_industries.cpp	Thu Jun 21 16:53:57 2007 +0000
+++ b/src/newgrf_industries.cpp	Thu Jun 21 17:09:10 2007 +0000
@@ -19,6 +19,7 @@
  * to those used by the game, the IDs used for overriding old industries must be
  * translated when the idustry spec is set. */
 IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
+IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE);
 
 /**
  * Finds the distance for the closest tile with water/land given a tile