Changeset - r27254:8bf1b3d96bdc
[Not reviewed]
master
0 10 0
Peter Nelson - 17 months ago 2023-04-17 22:19:30
peter1138@openttd.org
Change: Extend entity override manager and station spec lists to support 16 bit IDs.
10 files changed with 30 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/base_station_base.h
Show inline comments
 
@@ -22,13 +22,13 @@ extern StationPool _station_pool;
 
struct StationSpecList {
 
	const StationSpec *spec;
 
	uint32 grfid;      ///< GRF ID of this custom station
 
	uint8  localidx;   ///< Station ID within GRF of station
 
	uint16_t localidx; ///< Station ID within GRF of station
 
};
 

	
 
struct RoadStopSpecList {
 
	const RoadStopSpec *spec;
 
	uint32 grfid;      ///< GRF ID of this custom road stop
 
	uint8  localidx;   ///< Station ID within GRF of road stop
 
	uint16_t localidx; ///< Station ID within GRF of road stop
 
};
 

	
 
struct RoadStopTileData {
src/newgrf_class.h
Show inline comments
 
@@ -61,7 +61,7 @@ public:
 
	static Tid GetUIClass(uint index);
 
	static NewGRFClass *Get(Tid cls_id);
 

	
 
	static const Tspec *GetByGrf(uint32 grfid, byte local_id, int *index);
 
	static const Tspec *GetByGrf(uint32 grfid, uint16_t local_id, int *index);
 
};
 

	
 
#endif /* NEWGRF_CLASS_H */
src/newgrf_class_func.h
Show inline comments
 
@@ -187,7 +187,7 @@ DEFINE_NEWGRF_CLASS_METHOD(int)::GetUIFr
 
 * @param index    Pointer to return the index of the spec in its class. If nullptr then not used.
 
 * @return The spec.
 
 */
 
DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetByGrf(uint32 grfid, byte local_id, int *index)
 
DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetByGrf(uint32 grfid, uint16_t local_id, int *index)
 
{
 
	uint j;
 

	
 
@@ -222,4 +222,4 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *
 
	template const Tspec *name::GetSpec(uint index) const; \
 
	template int name::GetUIFromIndex(int index) const; \
 
	template int name::GetIndexFromUI(int ui_index) const; \
 
	template const Tspec *name::GetByGrf(uint32 grfid, byte localidx, int *index);
 
	template const Tspec *name::GetByGrf(uint32 grfid, uint16_t local_id, int *index);
src/newgrf_commons.cpp
Show inline comments
 
@@ -58,7 +58,7 @@ OverrideManagerBase::OverrideManagerBase
 
 * @param grfid  ID of the grf file
 
 * @param entity_type original entity type
 
 */
 
void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type)
 
void OverrideManagerBase::Add(uint16_t local_id, uint32 grfid, uint entity_type)
 
{
 
	assert(entity_type < this->max_offset);
 
	/* An override can be set only once */
 
@@ -86,7 +86,7 @@ void OverrideManagerBase::ResetOverride(
 
 * @param grfid ID of the grf file
 
 * @return the ID of the candidate, of the Invalid flag item ID
 
 */
 
uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid) const
 
uint16 OverrideManagerBase::GetID(uint16_t grf_local_id, uint32 grfid) const
 
{
 
	for (uint16 id = 0; id < this->max_entities; id++) {
 
		const EntityIDMapping *map = &this->mappings[id];
 
@@ -105,7 +105,7 @@ uint16 OverrideManagerBase::GetID(uint8 
 
 * @param substitute_id is the original entity from which data is copied for the new one
 
 * @return the proper usable slot id, or invalid marker if none is found
 
 */
 
uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
 
uint16 OverrideManagerBase::AddEntityID(uint16_t grf_local_id, uint32 grfid, uint16_t substitute_id)
 
{
 
	uint16 id = this->GetID(grf_local_id, grfid);
 

	
 
@@ -184,7 +184,7 @@ void HouseOverrideManager::SetEntitySpec
 
 * @param grfid ID of the grf file
 
 * @return the ID of the candidate, of the Invalid flag item ID
 
 */
 
uint16 IndustryOverrideManager::GetID(uint8 grf_local_id, uint32 grfid) const
 
uint16 IndustryOverrideManager::GetID(uint16_t grf_local_id, uint32 grfid) const
 
{
 
	uint16 id = OverrideManagerBase::GetID(grf_local_id, grfid);
 
	if (id != this->invalid_id) return id;
 
@@ -204,7 +204,7 @@ uint16 IndustryOverrideManager::GetID(ui
 
 * @param substitute_id industry from which data has been copied
 
 * @return a free entity id (slotid) if ever one has been found, or Invalid_ID marker otherwise
 
 */
 
uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
 
uint16 IndustryOverrideManager::AddEntityID(uint16_t grf_local_id, uint32 grfid, uint16 substitute_id)
 
{
 
	/* This entity hasn't been defined before, so give it an ID now. */
 
	for (uint16 id = 0; id < this->max_entities; id++) {
src/newgrf_commons.h
Show inline comments
 
@@ -185,8 +185,8 @@ private:
 
 */
 
struct EntityIDMapping {
 
	uint32 grfid;          ///< The GRF ID of the file the entity belongs to
 
	uint8  entity_id;      ///< The entity ID within the GRF file
 
	uint8  substitute_id;  ///< The (original) entity ID to use if this GRF is not available
 
	uint16_t entity_id; ///< The entity ID within the GRF file
 
	uint16_t substitute_id; ///< The (original) entity ID to use if this GRF is not available
 
};
 

	
 
class OverrideManagerBase {
 
@@ -209,12 +209,12 @@ public:
 
	void ResetOverride();
 
	void ResetMapping();
 

	
 
	void Add(uint8 local_id, uint32 grfid, uint entity_type);
 
	virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
 
	void Add(uint16_t local_id, uint32 grfid, uint entity_type);
 
	virtual uint16 AddEntityID(uint16_t grf_local_id, uint32 grfid, uint16_t substitute_id);
 

	
 
	uint32 GetGRFID(uint16 entity_id) const;
 
	uint16 GetSubstituteID(uint16 entity_id) const;
 
	virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const;
 
	virtual uint16 GetID(uint16_t grf_local_id, uint32 grfid) const;
 

	
 
	inline uint16 GetMaxMapping() const { return this->max_entities; }
 
	inline uint16 GetMaxOffset() const { return this->max_offset; }
 
@@ -237,8 +237,8 @@ public:
 
	IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
 
			OverrideManagerBase(offset, maximum, invalid) {}
 

	
 
	uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id) override;
 
	uint16 GetID(uint8 grf_local_id, uint32 grfid) const override;
 
	uint16 AddEntityID(uint16_t grf_local_id, uint32 grfid, uint16_t substitute_id) override;
 
	uint16 GetID(uint16_t grf_local_id, uint32 grfid) const override;
 

	
 
	void SetEntitySpec(IndustrySpec *inds);
 
};
src/newgrf_roadstop.cpp
Show inline comments
 
@@ -157,7 +157,7 @@ uint32 RoadStopScopeResolver::GetVariabl
 

	
 
			if (IsCustomRoadStopSpecIndex(nearby_tile)) {
 
				const RoadStopSpecList ssl = BaseStation::GetByTile(nearby_tile)->roadstop_speclist[GetCustomRoadStopSpecIndex(nearby_tile)];
 
				res |= 1 << (ssl.grfid != grfid ? 9 : 8) | ssl.localidx;
 
				res |= 1 << (ssl.grfid != grfid ? 9 : 8) | std::max<uint16_t>(ssl.localidx, 0xFF);
 
			}
 
			return res;
 
		}
src/newgrf_station.cpp
Show inline comments
 
@@ -364,7 +364,7 @@ TownScopeResolver *StationResolverObject
 

	
 
			if (IsCustomStationSpecIndex(nearby_tile)) {
 
				const StationSpecList ssl = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)];
 
				res |= 1 << (ssl.grfid != grfid ? 9 : 8) | ssl.localidx;
 
				res |= 1 << (ssl.grfid != grfid ? 9 : 8) | std::max<uint16_t>(ssl.localidx, 0xFF);
 
			}
 
			return res;
 
		}
src/saveload/newgrf_sl.cpp
Show inline comments
 
@@ -20,8 +20,10 @@
 
/** Save and load the mapping between a spec and the NewGRF it came from. */
 
static const SaveLoad _newgrf_mapping_desc[] = {
 
	SLE_VAR(EntityIDMapping, grfid,         SLE_UINT32),
 
	SLE_VAR(EntityIDMapping, entity_id,     SLE_UINT8),
 
	SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
 
	SLE_CONDVAR(EntityIDMapping, entity_id,     SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION,            SLV_EXTEND_ENTITY_MAPPING),
 
	SLE_CONDVAR(EntityIDMapping, entity_id,     SLE_UINT16,                SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
 
	SLE_CONDVAR(EntityIDMapping, substitute_id, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION,            SLV_EXTEND_ENTITY_MAPPING),
 
	SLE_CONDVAR(EntityIDMapping, substitute_id, SLE_UINT16,                SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
 
};
 

	
 
/**
src/saveload/saveload.h
Show inline comments
 
@@ -354,6 +354,7 @@ enum SaveLoadVersion : uint16 {
 
	SLV_AI_START_DATE,                      ///< 309  PR#10653 Removal of individual AI start dates and added a generic one.
 

	
 
	SLV_EXTEND_VEHICLE_RANDOM,              ///< 310  PR#10701 Extend vehicle random bits.
 
	SLV_EXTEND_ENTITY_MAPPING,              ///< 311  PR#10672 Extend entity mapping range.
 

	
 
	SL_MAX_VERSION,                         ///< Highest possible saveload version
 
};
src/saveload/station_sl.cpp
Show inline comments
 
@@ -205,8 +205,9 @@ static void SwapPackets(GoodsEntry *ge)
 
class SlStationSpecList : public DefaultSaveLoadHandler<SlStationSpecList, BaseStation> {
 
public:
 
	inline static const SaveLoad description[] = {
 
		SLE_CONDVAR(StationSpecList, grfid,    SLE_UINT32, SLV_27, SL_MAX_VERSION),
 
		SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8,  SLV_27, SL_MAX_VERSION),
 
		SLE_CONDVAR(StationSpecList, grfid,    SLE_UINT32,                SLV_27,                    SL_MAX_VERSION),
 
		SLE_CONDVAR(StationSpecList, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27,                    SLV_EXTEND_ENTITY_MAPPING),
 
		SLE_CONDVAR(StationSpecList, localidx, SLE_UINT16,                SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
 
	};
 
	inline const static SaveLoadCompatTable compat_description = _station_spec_list_sl_compat;
 

	
 
@@ -236,8 +237,9 @@ uint8 SlStationSpecList::last_num_specs;
 
class SlRoadStopSpecList : public DefaultSaveLoadHandler<SlRoadStopSpecList, BaseStation> {
 
public:
 
	inline static const SaveLoad description[] = {
 
		SLE_VAR(RoadStopSpecList, grfid,    SLE_UINT32),
 
		SLE_VAR(RoadStopSpecList, localidx, SLE_UINT8),
 
		    SLE_VAR(RoadStopSpecList, grfid,    SLE_UINT32),
 
		SLE_CONDVAR(RoadStopSpecList, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27,                    SLV_EXTEND_ENTITY_MAPPING),
 
		SLE_CONDVAR(RoadStopSpecList, localidx, SLE_UINT16,                SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
 
	};
 
	inline const static SaveLoadCompatTable compat_description = _station_road_stop_spec_list_sl_compat;
 

	
0 comments (0 inline, 0 general)