OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Macros | Functions
newgrf_class_func.h File Reference

Implementation of the NewGRF class' functions. More...

`#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.
#define | INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax)
| Force instantiation of the methods so we don't get linker errors.

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

## Detailed Description

Implementation of the NewGRF class' functions.

Definition in file newgrf_class_func.h.

## Macro Definition Documentation

#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 20 of file newgrf_class_func.h.

#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 218 of file newgrf_class_func.h.

## Function Documentation

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 29 of file newgrf_class_func.h.

References free().

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 57 of file newgrf_class_func.h.

References grfmsg().

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 115 of file newgrf_class_func.h.

DEFINE_NEWGRF_CLASS_METHOD | ( | const Tspec * |  | ) |

Get a spec from the class at a given index.

Retrieve a spec by GRF location.

Parameters

  index | The index where to find the spec.

Returns
  The spec at given 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 NULL then not used.

Returns
  The spec.

Definition at line 154 of file newgrf_class_func.h.

DEFINE_NEWGRF_CLASS_METHOD | ( | int |  | ) |

Translate a UI spec index into a spec index.

Translate a spec index into a UI spec index.

Parameters

  ui_index | UI index of the spec.

Returns
  index of the spec, or -1 if out of range.

Parameters

  index | index of the spec.

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

Definition at line 165 of file newgrf_class_func.h.