summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2007-11-12 20:40:58 +0000
committerglx <glx@openttd.org>2007-11-12 20:40:58 +0000
commit60ccc5bbce380f8b6203902b9206e0e86ba8462b (patch)
treec2837b3eb9dae895812edefca8ada66006ce06ed /src
parent49b4aa32bb2bc0085ad5c1f1e197c9c45c6ba132 (diff)
downloadopenttd-60ccc5bbce380f8b6203902b9206e0e86ba8462b.tar.xz
(svn r11423) -Codechange: store grfid when adding an override
Diffstat (limited to 'src')
-rw-r--r--src/newgrf.cpp6
-rw-r--r--src/newgrf_commons.cpp15
-rw-r--r--src/newgrf_commons.h3
3 files changed, 16 insertions, 8 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index f02feadaa..6d96424b3 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -1336,7 +1336,7 @@ static bool TownHouseChangeInfo(uint hid, int numinfo, int prop, byte **bufp, in
continue;
}
- _house_mngr.Add(hid + i, override);
+ _house_mngr.Add(hid + i, _cur_grffile->grfid, override);
} break;
case 0x16: // Periodic refresh multiplier
@@ -1764,7 +1764,7 @@ static bool IndustrytilesChangeInfo(uint indtid, int numinfo, int prop, byte **b
return false;
}
- _industile_mngr.Add(indtid + i, ovrid);
+ _industile_mngr.Add(indtid + i, _cur_grffile->grfid, ovrid);
} break;
case 0x0A: // Tile acceptance
@@ -1877,7 +1877,7 @@ static bool IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp,
return false;
}
indsp->grf_prop.override = ovrid;
- _industry_mngr.Add(indid + i, ovrid);
+ _industry_mngr.Add(indid + i, _cur_grffile->grfid, ovrid);
} break;
case 0x0A: { // Set industry layout(s)
diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp
index 2ba38fe6e..823c0f918 100644
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -27,6 +27,7 @@ OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 i
mapping_ID = CallocT<EntityIDMapping>(max_new_entities);
entity_overrides = MallocT<uint16>(max_offset);
memset(entity_overrides, invalid, sizeof(entity_overrides));
+ grfid_overrides = CallocT<uint32>(max_offset);
}
/** Destructor of the generic class.
@@ -36,18 +37,21 @@ OverrideManagerBase::~OverrideManagerBase()
{
free(mapping_ID);
free(entity_overrides);
+ free(grfid_overrides);
}
/** Since the entity IDs defined by the GRF file does not necessarily correlate
* to those used by the game, the IDs used for overriding old entities must be
* translated when the entity spec is set.
- * @param local_id id in grf file
+ * @param local_id ID in grf file
+ * @param grfid ID of the grf file
* @param entity_type original entity type
*/
-void OverrideManagerBase::Add(uint8 local_id, uint entity_type)
+void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type)
{
assert(entity_type < max_offset);
entity_overrides[entity_type] = local_id;
+ grfid_overrides[entity_type] = grfid;
}
/** Resets the mapping, which is used while initializing game */
@@ -61,6 +65,7 @@ void OverrideManagerBase::ResetOverride()
{
for (uint16 i = 0; i < max_offset; i++) {
entity_overrides[i] = invalid_ID;
+ grfid_overrides[i] = 0;
}
}
@@ -144,10 +149,11 @@ void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
for (int i = 0; i != max_offset; i++) {
HouseSpec *overridden_hs = GetHouseSpecs(i);
- if (entity_overrides[i] != hs->local_id) continue;
+ if (entity_overrides[i] != hs->local_id || grfid_overrides[i] != hs->grffile->grfid) continue;
overridden_hs->override = house_id;
entity_overrides[i] = invalid_ID;
+ grfid_overrides[i] = 0;
}
}
@@ -236,11 +242,12 @@ void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
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;
+ if (entity_overrides[i] != its->grf_prop.local_id || grfid_overrides[i] != its->grf_prop.grffile->grfid) continue;
overridden_its->grf_prop.override = indt_id;
overridden_its->enabled = false;
entity_overrides[i] = invalid_ID;
+ grfid_overrides[i] = 0;
}
}
diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h
index a8e3eabf9..c4526a89c 100644
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -28,6 +28,7 @@ struct EntityIDMapping {
class OverrideManagerBase {
protected:
uint16 *entity_overrides;
+ uint32 *grfid_overrides;
uint16 max_offset; ///< what is the length of the original entity's array of specs
uint16 max_new_entities; ///< what is the amount of entities, old and new summed
@@ -44,7 +45,7 @@ public:
void ResetOverride();
void ResetMapping();
- void Add(uint8 local_id, uint entity_type);
+ void Add(uint8 local_id, uint32 grfid, uint entity_type);
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
uint16 GetSubstituteID(byte entity_id);