OpenTTD Source: src/newgrf_class_func.h File Reference

OpenTTD Source 12.2

Macros | Functions
newgrf_class_func.h File Reference
`#include "newgrf_class.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Macros
#define | DEFINE_NEWGRF_CLASS_METHOD(type)
| Helper for defining the class method's signatures. More...
#define | INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax)
| Force instantiation of the methods so we don't get linker errors. More...

## Functions
| DEFINE_NEWGRF_CLASS_METHOD (void)
| Reset the class, i.e. More...
| DEFINE_NEWGRF_CLASS_METHOD (Tid)
| Allocate a class with a given global class ID. More...
| DEFINE_NEWGRF_CLASS_METHOD (uint)
| Get the number of allocated classes. More...
| DEFINE_NEWGRF_CLASS_METHOD (const Tspec *)
| Get a spec from the class at a given index. More...

## Detailed Description

Implementation of the NewGRF class' functions.

Definition in file newgrf_class_func.h.

## Macro Definition Documentation

## ◆ DEFINE_NEWGRF_CLASS_METHOD

#define DEFINE_NEWGRF_CLASS_METHOD | ( |  | type | ) |

Value:
template <typename Tspec, typename Tid, Tid Tmax> \
type NewGRFClass<Tspec, Tid, Tmax>

Helper for defining the class method's signatures.

Parameters

  type | The type of the class.

Definition at line 18 of file newgrf_class_func.h.

## ◆ INSTANTIATE_NEWGRF_CLASS_METHODS

#define INSTANTIATE_NEWGRF_CLASS_METHODS | ( |  | name,
|  |  | Tspec,
|  |  | Tid,
|  |  | Tmax
| ) |  |

Value:
template void name::ResetClass(); \
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 Tid name::GetUIClass(uint index); \
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);

Force instantiation of the methods so we don't get linker errors.

Definition at line 216 of file newgrf_class_func.h.

## Function Documentation

## ◆ DEFINE_NEWGRF_CLASS_METHOD() [1/4]

DEFINE_NEWGRF_CLASS_METHOD | ( | const Tspec * |  | ) |

Get a spec from the class at a given index.

Parameters

  index | The index where to find the spec.

Returns
  The spec at given location. Translate a UI spec index into a spec index.

Parameters

  ui_index | UI index of the spec.

Returns
  index of the spec, or -1 if out of range. Translate a spec index into a UI spec index.

Parameters

  index | index of the spec.

Returns
  UI index of the spec, or -1 if out of range. Retrieve a spec by GRF location.

Parameters

  grfid | GRF ID of spec.
  local_id | Index within GRF file of spec.
  index | Pointer to return the index of the spec in its class. If nullptr then not used.

Returns
  The spec.

Definition at line 152 of file newgrf_class_func.h.

## ◆ DEFINE_NEWGRF_CLASS_METHOD() [2/4]

DEFINE_NEWGRF_CLASS_METHOD | ( | Tid |  | ) |

Allocate a class with a given global class ID.

Get the nth-class with user available specs.

Parameters

  cls_id | The global class id, such as 'DFLT'.

Returns
  The (non global!) class ID for the class.

Note
  Upon allocating the same global class ID for a second time, this first allocation will be given.

Parameters

  index | UI index of a class.

Returns
  The class ID of the class.

Definition at line 55 of file newgrf_class_func.h.

References grfmsg().

## ◆ DEFINE_NEWGRF_CLASS_METHOD() [3/4]

DEFINE_NEWGRF_CLASS_METHOD | ( | uint |  | ) |

Get the number of allocated classes.

Get the number of classes available to the user.

Returns
  The number of classes.

Definition at line 113 of file newgrf_class_func.h.

## ◆ DEFINE_NEWGRF_CLASS_METHOD() [4/4]

DEFINE_NEWGRF_CLASS_METHOD | ( | void |  | ) |

Reset the class, i.e.

Assign a spec to one of the classes.

Insert a spec into the class.

Reset the classes, i.e.

clear everything.

Parameters

  spec | The spec to insert.
  spec | The spec to assign.

Note
  The spec must have a valid class id set.

Definition at line 27 of file newgrf_class_func.h.

References free().

NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:19