2010-08-08 00:05:58 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file newgrf_class.h Header file for classes to be used by e.g. NewGRF stations and airports */
|
|
|
|
|
|
|
|
#ifndef NEWGRF_CLASS_H
|
|
|
|
#define NEWGRF_CLASS_H
|
|
|
|
|
|
|
|
#include "strings_type.h"
|
|
|
|
|
2023-01-08 16:36:57 +01:00
|
|
|
|
2010-08-08 00:05:58 +02:00
|
|
|
/**
|
|
|
|
* Struct containing information relating to NewGRF classes for stations and airports.
|
|
|
|
*/
|
|
|
|
template <typename Tspec, typename Tid, Tid Tmax>
|
2024-03-23 22:55:50 +01:00
|
|
|
class NewGRFClass {
|
2012-04-22 18:28:00 +02:00
|
|
|
private:
|
2024-04-09 18:54:42 +02:00
|
|
|
uint ui_count = 0; ///< Number of specs in this class potentially available to the user.
|
2023-01-08 16:36:57 +01:00
|
|
|
std::vector<Tspec *> spec; ///< List of specifications.
|
2012-04-22 18:28:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The actual classes.
|
2024-04-09 18:54:42 +02:00
|
|
|
* @note This may be reallocated during initialization so pointers may be invalidated.
|
2012-04-22 18:28:00 +02:00
|
|
|
*/
|
2024-04-09 18:54:42 +02:00
|
|
|
static inline std::vector<NewGRFClass<Tspec, Tid, Tmax>> classes;
|
2012-04-22 18:28:04 +02:00
|
|
|
|
2010-08-08 00:05:58 +02:00
|
|
|
/** Initialise the defaults. */
|
|
|
|
static void InsertDefaults();
|
|
|
|
|
2012-04-22 18:28:00 +02:00
|
|
|
public:
|
2023-05-08 19:01:06 +02:00
|
|
|
uint32_t global_id; ///< Global ID for class, e.g. 'DFLT', 'WAYP', etc.
|
2012-04-22 18:28:00 +02:00
|
|
|
StringID name; ///< Name of this class.
|
|
|
|
|
2024-04-09 18:54:42 +02:00
|
|
|
/* Public constructor as emplace_back needs access. */
|
|
|
|
NewGRFClass(uint32_t global_id, StringID name) : global_id(global_id), name(name) { }
|
|
|
|
|
2024-04-09 18:54:43 +02:00
|
|
|
/**
|
|
|
|
* Get read-only span of specs of this class.
|
|
|
|
* @return Read-only span of specs.
|
|
|
|
*/
|
|
|
|
std::span<Tspec * const> Specs() const { return this->spec; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get read-only span of all classes of this type.
|
|
|
|
* @return Read-only span of classes.
|
|
|
|
*/
|
|
|
|
static std::span<NewGRFClass<Tspec, Tid, Tmax> const> Classes() { return NewGRFClass::classes; }
|
|
|
|
|
2012-04-22 18:28:09 +02:00
|
|
|
void Insert(Tspec *spec);
|
|
|
|
|
2024-04-09 18:54:42 +02:00
|
|
|
Tid Index() const { return static_cast<Tid>(std::distance(&*std::cbegin(NewGRFClass::classes), this)); }
|
2012-04-22 18:28:14 +02:00
|
|
|
/** Get the number of allocated specs within the class. */
|
2023-01-08 16:36:57 +01:00
|
|
|
uint GetSpecCount() const { return static_cast<uint>(this->spec.size()); }
|
2012-04-22 18:28:27 +02:00
|
|
|
/** Get the number of potentially user-available specs within the class. */
|
|
|
|
uint GetUISpecCount() const { return this->ui_count; }
|
2012-04-22 18:28:32 +02:00
|
|
|
int GetUIFromIndex(int index) const;
|
|
|
|
int GetIndexFromUI(int ui_index) const;
|
2012-04-22 18:28:14 +02:00
|
|
|
|
|
|
|
const Tspec *GetSpec(uint index) const;
|
|
|
|
|
2012-04-22 18:28:27 +02:00
|
|
|
/** Check whether the spec will be available to the user at some point in time. */
|
|
|
|
bool IsUIAvailable(uint index) const;
|
|
|
|
|
2012-04-22 18:28:00 +02:00
|
|
|
static void Reset();
|
2023-05-08 19:01:06 +02:00
|
|
|
static Tid Allocate(uint32_t global_id);
|
2010-08-08 00:05:58 +02:00
|
|
|
static void Assign(Tspec *spec);
|
2012-04-22 18:28:19 +02:00
|
|
|
static uint GetClassCount();
|
2012-04-22 18:28:27 +02:00
|
|
|
static uint GetUIClassCount();
|
2012-04-22 18:28:32 +02:00
|
|
|
static Tid GetUIClass(uint index);
|
2012-04-22 18:27:49 +02:00
|
|
|
static NewGRFClass *Get(Tid cls_id);
|
2010-08-08 00:05:58 +02:00
|
|
|
|
2023-05-08 19:01:06 +02:00
|
|
|
static const Tspec *GetByGrf(uint32_t grfid, uint16_t local_id, int *index);
|
2010-08-08 00:05:58 +02:00
|
|
|
};
|
|
|
|
|
2010-12-22 11:50:32 +01:00
|
|
|
#endif /* NEWGRF_CLASS_H */
|