Changeset - r19266:a55aa4bf5bd3
[Not reviewed]
master
0 5 0
frosch - 12 years ago 2012-04-22 16:28:27
frosch@openttd.org
(svn r24169) -Add: Make NewGRFClass distinguish between defined specs and specs visible for the user.
5 files changed with 42 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/newgrf_airport.cpp
Show inline comments
 
@@ -28,12 +28,18 @@ template <typename Tspec, typename Tid, 
 
	AirportClass::Get(AirportClass::Allocate('SMAL'))->name = STR_AIRPORT_CLASS_SMALL;
 
	AirportClass::Get(AirportClass::Allocate('LARG'))->name = STR_AIRPORT_CLASS_LARGE;
 
	AirportClass::Get(AirportClass::Allocate('HUB_'))->name = STR_AIRPORT_CLASS_HUB;
 
	AirportClass::Get(AirportClass::Allocate('HELI'))->name = STR_AIRPORT_CLASS_HELIPORTS;
 
}
 

	
 
template <typename Tspec, typename Tid, Tid Tmax>
 
bool NewGRFClass<Tspec, Tid, Tmax>::IsUIAvailable(uint index) const
 
{
 
	return true;
 
}
 

	
 
INSTANTIATE_NEWGRF_CLASS_METHODS(AirportClass, AirportSpec, AirportClassID, APC_MAX)
 

	
 

	
 
AirportOverrideManager _airport_mngr(NEW_AIRPORT_OFFSET, NUM_AIRPORTS, AT_INVALID);
 

	
 
AirportSpec AirportSpec::specs[NUM_AIRPORTS]; ///< Airport specifications.
src/newgrf_class.h
Show inline comments
 
@@ -18,12 +18,13 @@
 
 * Struct containing information relating to NewGRF classes for stations and airports.
 
 */
 
template <typename Tspec, typename Tid, Tid Tmax>
 
struct NewGRFClass {
 
private:
 
	uint count;       ///< Number of specs in this class.
 
	uint ui_count;    ///< Number of specs in this class potentially available to the user.
 
	Tspec **spec;     ///< Array of specifications.
 

	
 
	/**
 
	 * The actual classes.
 
	 * @note We store pointers to membes of this array in various places outside this class (e.g. to 'name' for GRF string resolving).
 
	 *       Thus this must be a static array, and cannot be a self-resizing SmallVector or similar.
 
@@ -40,19 +41,25 @@ public:
 
	StringID name;    ///< Name of this class.
 

	
 
	void Insert(Tspec *spec);
 

	
 
	/** Get the number of allocated specs within the class. */
 
	uint GetSpecCount() const { return this->count; }
 
	/** Get the number of potentially user-available specs within the class. */
 
	uint GetUISpecCount() const { return this->ui_count; }
 

	
 
	const Tspec *GetSpec(uint index) const;
 

	
 
	/** Check whether the spec will be available to the user at some point in time. */
 
	bool IsUIAvailable(uint index) const;
 

	
 
	static void Reset();
 
	static Tid Allocate(uint32 global_id);
 
	static void Assign(Tspec *spec);
 
	static uint GetClassCount();
 
	static uint GetUIClassCount();
 
	static NewGRFClass *Get(Tid cls_id);
 

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

	
 
#endif /* NEWGRF_CLASS_H */
src/newgrf_class_func.h
Show inline comments
 
@@ -28,12 +28,13 @@ NewGRFClass<Tspec, Tid, Tmax> NewGRFClas
 
/** Reset the class, i.e. clear everything. */
 
DEFINE_NEWGRF_CLASS_METHOD(void)::ResetClass()
 
{
 
	this->global_id = 0;
 
	this->name      = STR_EMPTY;
 
	this->count     = 0;
 
	this->ui_count  = 0;
 

	
 
	free(this->spec);
 
	this->spec = NULL;
 
}
 

	
 
/** Reset the classes, i.e. clear everything. */
 
@@ -77,12 +78,14 @@ DEFINE_NEWGRF_CLASS_METHOD(Tid)::Allocat
 
DEFINE_NEWGRF_CLASS_METHOD(void)::Insert(Tspec *spec)
 
{
 
	uint i = this->count++;
 
	this->spec = ReallocT(this->spec, this->count);
 

	
 
	this->spec[i] = spec;
 

	
 
	if (this->IsUIAvailable(i)) this->ui_count++;
 
}
 

	
 
/**
 
 * Assign a spec to one of the classes.
 
 * @param spec The spec to assign.
 
 * @note The spec must have a valid class id set.
 
@@ -114,12 +117,25 @@ DEFINE_NEWGRF_CLASS_METHOD(uint)::GetCla
 
	uint i;
 
	for (i = 0; i < Tmax && classes[i].global_id != 0; i++) {}
 
	return i;
 
}
 

	
 
/**
 
 * Get the number of classes available to the user.
 
 * @return The number of classes.
 
 */
 
DEFINE_NEWGRF_CLASS_METHOD(uint)::GetUIClassCount()
 
{
 
	uint cnt = 0;
 
	for (uint i = 0; i < Tmax && classes[i].global_id != 0; i++) {
 
		if (classes[i].GetUISpecCount() > 0) cnt++;
 
	}
 
	return cnt;
 
}
 

	
 
/**
 
 * Get a spec from the class at a given index.
 
 * @param index  The index where to find the spec.
 
 * @return The spec at given location.
 
 */
 
DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetSpec(uint index) const
 
{
 
@@ -160,8 +176,9 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *
 
	template void name::Reset(); \
 
	template Tid name::Allocate(uint32 global_id); \
 
	template void name::Insert(Tspec *spec); \
 
	template void name::Assign(Tspec *spec); \
 
	template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \
 
	template uint name::GetClassCount(); \
 
	template uint name::GetUIClassCount(); \
 
	template const Tspec *name::GetSpec(uint index) const; \
 
	template const Tspec *name::GetByGrf(uint32 grfid, byte localidx, int *index);
src/newgrf_object.cpp
Show inline comments
 
@@ -110,12 +110,18 @@ template <typename Tspec, typename Tid, 
 
	cls = ObjectClass::Allocate('TRNS');
 
	ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_TRNS;
 
	_object_specs[OBJECT_TRANSMITTER].cls_id = cls;
 
	ObjectClass::Assign(&_object_specs[OBJECT_TRANSMITTER]);
 
}
 

	
 
template <typename Tspec, typename Tid, Tid Tmax>
 
bool NewGRFClass<Tspec, Tid, Tmax>::IsUIAvailable(uint index) const
 
{
 
	return this->GetSpec(index)->IsEverAvailable();
 
}
 

	
 
INSTANTIATE_NEWGRF_CLASS_METHODS(ObjectClass, ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX)
 

	
 

	
 
static uint32 ObjectGetRandomBits(const ResolverObject *object)
 
{
 
	TileIndex t = object->u.object.tile;
src/newgrf_station.cpp
Show inline comments
 
@@ -37,12 +37,18 @@ template <typename Tspec, typename Tid, 
 

	
 
	classes[1].global_id = 'WAYP';
 
	classes[1].name = STR_STATION_CLASS_WAYP;
 
	classes[1].Insert(NULL);
 
}
 

	
 
template <typename Tspec, typename Tid, Tid Tmax>
 
bool NewGRFClass<Tspec, Tid, Tmax>::IsUIAvailable(uint index) const
 
{
 
	return true;
 
}
 

	
 
INSTANTIATE_NEWGRF_CLASS_METHODS(StationClass, StationSpec, StationClassID, STAT_CLASS_MAX)
 

	
 
static const uint MAX_SPECLIST = 255;
 

	
 
enum TriggerArea {
 
	TA_TILE,
0 comments (0 inline, 0 general)