Changeset - r7873:778564304bdd
[Not reviewed]
master
0 3 0
glx - 17 years ago 2007-11-12 20:40:58
glx@openttd.org
(svn r11423) -Codechange: store grfid when adding an override
3 files changed with 16 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -1333,13 +1333,13 @@ static bool TownHouseChangeInfo(uint hid
 
				/* The house being overridden must be an original house. */
 
				if (override >= NEW_HOUSE_OFFSET) {
 
					grfmsg(2, "TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring.", override, hid + i);
 
					continue;
 
				}
 

	
 
				_house_mngr.Add(hid + i, override);
 
				_house_mngr.Add(hid + i, _cur_grffile->grfid, override);
 
			} break;
 

	
 
			case 0x16: // Periodic refresh multiplier
 
				housespec->processing_time = grf_load_byte(&buf);
 
				break;
 

	
 
@@ -1761,13 +1761,13 @@ static bool IndustrytilesChangeInfo(uint
 
				/* The industry being overridden must be an original industry. */
 
				if (ovrid >= NEW_INDUSTRYTILEOFFSET) {
 
					grfmsg(2, "IndustryTilesChangeInfo: Attempt to override new industry tile %u with industry tile id %u. Ignoring.", ovrid, indtid + i);
 
					return false;
 
				}
 

	
 
				_industile_mngr.Add(indtid + i, ovrid);
 
				_industile_mngr.Add(indtid + i, _cur_grffile->grfid, ovrid);
 
			} break;
 

	
 
			case 0x0A: // Tile acceptance
 
			case 0x0B:
 
			case 0x0C: {
 
				uint16 acctp = grf_load_word(&buf);
 
@@ -1874,13 +1874,13 @@ static bool IndustriesChangeInfo(uint in
 
				/* The industry being overridden must be an original industry. */
 
				if (ovrid >= NEW_INDUSTRYOFFSET) {
 
					grfmsg(2, "IndustriesChangeInfo: Attempt to override new industry %u with industry id %u. Ignoring.", ovrid, indid + i);
 
					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)
 
				indsp->num_table = grf_load_byte(&buf); // Number of layaouts
 
				uint32 defsize = grf_load_dword(&buf);  // Total size of the definition
 
				IndustryTileTable **tile_table = CallocT<IndustryTileTable*>(indsp->num_table); // Table with tiles to compose an industry
src/newgrf_commons.cpp
Show inline comments
 
@@ -24,33 +24,37 @@ OverrideManagerBase::OverrideManagerBase
 
	max_new_entities = maximum;
 
	invalid_ID = invalid;
 

	
 
	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.
 
 * Frees allocated memory of constructor
 
 */
 
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 */
 
void OverrideManagerBase::ResetMapping()
 
{
 
	memset(mapping_ID, 0, (max_new_entities - 1) * sizeof(EntityIDMapping));
 
@@ -58,12 +62,13 @@ void OverrideManagerBase::ResetMapping()
 

	
 
/** Resets the override, which is used while initializing game */
 
void OverrideManagerBase::ResetOverride()
 
{
 
	for (uint16 i = 0; i < max_offset; i++) {
 
		entity_overrides[i] = invalid_ID;
 
		grfid_overrides[i] = 0;
 
	}
 
}
 

	
 
/** Return the ID (if ever available) of a previously inserted entity.
 
 * @param grf_local_id ID of this enity withing the grfID
 
 * @param grfid ID of the grf file
 
@@ -141,16 +146,17 @@ void HouseOverrideManager::SetEntitySpec
 
	memcpy(&_house_specs[house_id], hs, sizeof(*hs));
 

	
 
	/* Now add the overrides. */
 
	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;
 
	}
 
}
 

	
 
/** Method to find an entity ID and to mark it as reserved for the Industry to be included.
 
 * @param grf_local_id ID used by the grf file for pre-installation work (equivalent of TTDPatch's setid
 
 * @param grfid ID of the current grf file
 
@@ -233,17 +239,18 @@ void IndustryTileOverrideManager::SetEnt
 
	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;
 
		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;
 
	}
 
}
 

	
 
/** 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
src/newgrf_commons.h
Show inline comments
 
@@ -25,12 +25,13 @@ struct EntityIDMapping {
 
	uint8  substitute_id;  ///< The (original) entity ID to use if this GRF is not available
 
};
 

	
 
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
 

	
 
	uint16 invalid_ID;       ///< ID used to dected invalid entities;
 
	virtual bool CheckValidNewID(uint16 testid) { return true; }
 
@@ -41,13 +42,13 @@ public:
 
	OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
 
	virtual ~OverrideManagerBase();
 

	
 
	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);
 
	uint16 GetID(uint8 grf_local_id, uint32 grfid);
 

	
 
	inline uint16 GetMaxMapping() { return max_new_entities; }
0 comments (0 inline, 0 general)