mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
(svn r24169) -Add: Make NewGRFClass distinguish between defined specs and specs visible for the user.
This commit is contained in:
parent
6d9a0ff723
commit
34969178db
@ -31,6 +31,12 @@ template <typename Tspec, typename Tid, Tid Tmax>
|
|||||||
AirportClass::Get(AirportClass::Allocate('HELI'))->name = STR_AIRPORT_CLASS_HELIPORTS;
|
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)
|
INSTANTIATE_NEWGRF_CLASS_METHODS(AirportClass, AirportSpec, AirportClassID, APC_MAX)
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ template <typename Tspec, typename Tid, Tid Tmax>
|
|||||||
struct NewGRFClass {
|
struct NewGRFClass {
|
||||||
private:
|
private:
|
||||||
uint count; ///< Number of specs in this class.
|
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.
|
Tspec **spec; ///< Array of specifications.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,13 +44,19 @@ public:
|
|||||||
|
|
||||||
/** Get the number of allocated specs within the class. */
|
/** Get the number of allocated specs within the class. */
|
||||||
uint GetSpecCount() const { return this->count; }
|
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;
|
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 void Reset();
|
||||||
static Tid Allocate(uint32 global_id);
|
static Tid Allocate(uint32 global_id);
|
||||||
static void Assign(Tspec *spec);
|
static void Assign(Tspec *spec);
|
||||||
static uint GetClassCount();
|
static uint GetClassCount();
|
||||||
|
static uint GetUIClassCount();
|
||||||
static NewGRFClass *Get(Tid cls_id);
|
static NewGRFClass *Get(Tid cls_id);
|
||||||
|
|
||||||
static const Tspec *GetByGrf(uint32 grfid, byte local_id, int *index);
|
static const Tspec *GetByGrf(uint32 grfid, byte local_id, int *index);
|
||||||
|
@ -31,6 +31,7 @@ DEFINE_NEWGRF_CLASS_METHOD(void)::ResetClass()
|
|||||||
this->global_id = 0;
|
this->global_id = 0;
|
||||||
this->name = STR_EMPTY;
|
this->name = STR_EMPTY;
|
||||||
this->count = 0;
|
this->count = 0;
|
||||||
|
this->ui_count = 0;
|
||||||
|
|
||||||
free(this->spec);
|
free(this->spec);
|
||||||
this->spec = NULL;
|
this->spec = NULL;
|
||||||
@ -80,6 +81,8 @@ DEFINE_NEWGRF_CLASS_METHOD(void)::Insert(Tspec *spec)
|
|||||||
this->spec = ReallocT(this->spec, this->count);
|
this->spec = ReallocT(this->spec, this->count);
|
||||||
|
|
||||||
this->spec[i] = spec;
|
this->spec[i] = spec;
|
||||||
|
|
||||||
|
if (this->IsUIAvailable(i)) this->ui_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,6 +119,19 @@ DEFINE_NEWGRF_CLASS_METHOD(uint)::GetClassCount()
|
|||||||
return 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.
|
* Get a spec from the class at a given index.
|
||||||
* @param index The index where to find the spec.
|
* @param index The index where to find the spec.
|
||||||
@ -163,5 +179,6 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetByGrf(uint32 grfid, byte local_id,
|
|||||||
template void name::Assign(Tspec *spec); \
|
template void name::Assign(Tspec *spec); \
|
||||||
template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \
|
template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \
|
||||||
template uint name::GetClassCount(); \
|
template uint name::GetClassCount(); \
|
||||||
|
template uint name::GetUIClassCount(); \
|
||||||
template const Tspec *name::GetSpec(uint index) const; \
|
template const Tspec *name::GetSpec(uint index) const; \
|
||||||
template const Tspec *name::GetByGrf(uint32 grfid, byte localidx, int *index);
|
template const Tspec *name::GetByGrf(uint32 grfid, byte localidx, int *index);
|
||||||
|
@ -113,6 +113,12 @@ template <typename Tspec, typename Tid, Tid Tmax>
|
|||||||
ObjectClass::Assign(&_object_specs[OBJECT_TRANSMITTER]);
|
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)
|
INSTANTIATE_NEWGRF_CLASS_METHODS(ObjectClass, ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX)
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +40,12 @@ template <typename Tspec, typename Tid, Tid Tmax>
|
|||||||
classes[1].Insert(NULL);
|
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)
|
INSTANTIATE_NEWGRF_CLASS_METHODS(StationClass, StationSpec, StationClassID, STAT_CLASS_MAX)
|
||||||
|
|
||||||
static const uint MAX_SPECLIST = 255;
|
static const uint MAX_SPECLIST = 255;
|
||||||
|
Loading…
Reference in New Issue
Block a user