OpenTTD Source: src/newgrf_badge.h File Reference

OpenTTD Source 15.0-RC2

Data Structures | Functions
newgrf_badge.h File Reference

Functions related to NewGRF badges. More...

`#include "core/flatset_type.hpp"`
`#include "newgrf.h"`
`#include "newgrf_badge_type.h"`
`#include "newgrf_commons.h"`
`#include "strings_type.h"`
`#include "timer/timer_game_calendar.h"`

Go to the source code of this file.

## Data Structures
class | Badge
class | UsedBadgeClasses
| Utility class to create a list of badge classes used by a feature. More...
class | BadgeTextFilter
class | BadgeDropdownFilter

## Functions
void | ResetBadges ()
| Reset badges to the default state.
Badge & | GetOrCreateBadge (std::string_view label)
| Register a badge label and return its global index.
void | MarkBadgeSeen (BadgeID index, GrfSpecFeature feature)
| Mark a badge a seen (used) by a feature.
void | AppendCopyableBadgeList (std::vector< BadgeID > &dst, std::span< const BadgeID > src, GrfSpecFeature feature)
| Append copyable badges from a list onto another.
void | ApplyBadgeFeaturesToClassBadges ()
| Apply features from all badges to their badge classes.
std::span< const Badge > | GetBadges ()
| Get a read-only view of badges.
Badge * | GetBadge (BadgeID index)
| Get a badge if it exists.
Badge * | GetBadgeByLabel (std::string_view label)
| Get a badge by label if it exists.
Badge * | GetClassBadge (BadgeClassID class_index)
| Get the badge for a badge class index.
std::span< const BadgeID > | GetClassBadges ()
| Get a read-only view of class badge index.
uint32_t | GetBadgeVariableResult (const struct GRFFile &grffile, std::span< const BadgeID > badges, uint32_t parameter)
PalSpriteID | GetBadgeSprite (const Badge &badge, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap)
| Get sprite for the given badge.

## Detailed Description

Functions related to NewGRF badges.

Definition in file newgrf_badge.h.

## Function Documentation

## ◆ AppendCopyableBadgeList()

void AppendCopyableBadgeList | ( | std::vector< BadgeID > & | dst,
|  | std::span< const BadgeID > | src,
|  | GrfSpecFeature | feature
| ) |  |

Append copyable badges from a list onto another.

Badges must exist and be marked with the Copy flag.

Parameters

  dst | Destination badge list.
  src | Source badge list.
  feature | Feature of list.

Definition at line 250 of file newgrf_badge.cpp.

References Copy, Badge::features, Badge::flags, GetBadge(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by FinaliseEngineArray().

## ◆ ApplyBadgeFeaturesToClassBadges()

void ApplyBadgeFeaturesToClassBadges | ( |  | ) |

Apply features from all badges to their badge classes.

Definition at line 267 of file newgrf_badge.cpp.

References Badge::features, Badge::flags, GetBadges(), GetClassBadge(), HasText, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().

Referenced by FinaliseBadges().

## ◆ GetBadge()

Badge * GetBadge | ( | BadgeID | index | ) |

Get a badge if it exists.

Parameters

  index | Index of badge.

Returns
  Badge with specified index, or nullptr if it does not exist.

Definition at line 113 of file newgrf_badge.cpp.

References _badges, and Badges::specs.

Referenced by AddBadgeClassesToConfiguration(), AppendCopyableBadgeList(), DrawBadgeColumn(), DrawBadgeNameList(), NewGRFInspectWindow::DrawMainPanelWidget(), GetClassBadge(), MarkBadgeSeen(), ResetBadgeClassConfiguration(), SetBadgeFilter(), and UsedBadgeClasses::UsedBadgeClasses().

## ◆ GetBadgeByLabel()

Badge * GetBadgeByLabel | ( | std::string_view | label | ) |

Get a badge by label if it exists.

Parameters

  label | Label of badge.

Returns
  Badge with specified label, or nullptr if it does not exist.

Definition at line 124 of file newgrf_badge.cpp.

References _badges, Badge::label, and Badges::specs.

Referenced by FinaliseBadges().

## ◆ GetBadges()

std::span< const Badge > GetBadges | ( |  | ) |

Get a read-only view of badges.

Returns
  Span of badges.

Definition at line 40 of file newgrf_badge.cpp.

References _badges, and Badges::specs.

Referenced by ApplyBadgeFeaturesToClassBadges(), BadgeTextFilter::BadgeTextFilter(), and NWidgetBadgeFilter::GetDropDownList().

## ◆ GetBadgeSprite()

PalSpriteID GetBadgeSprite | ( | const Badge & | badge,
|  | GrfSpecFeature | feature,
|  | std::optional< TimerGameCalendar::Date > | introduction_date,
|  | PaletteID | remap
| ) |  |

Get sprite for the given badge.

Parameters

  badge | Badge being queried.
  feature | GRF feature being used.
  introduction_date | Introduction date of the item, if it has one.
  remap | Palette remap to use if the flag is company-coloured.

Returns
  Custom sprite to draw, or `0` if not available.

Definition at line 285 of file newgrf_badge.cpp.

References Badge::flags, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and UseCompanyColour.

Referenced by DrawBadgeColumn(), and NWidgetBadgeFilter::GetDropDownList().

## ◆ GetClassBadge()

Badge * GetClassBadge | ( | BadgeClassID | class_index | ) |

Get the badge for a badge class index.

Parameters

  class_index | Index of the badge class.

Returns
  Class badge for the class index, or nullptr if not present.

Definition at line 137 of file newgrf_badge.cpp.

References _badges, Badges::classes, and GetBadge().

Referenced by AddBadgeDropdownFilters(), ApplyBadgeFeaturesToClassBadges(), DrawBadgeNameList(), NWidgetBadgeFilter::GetDropDownList(), GUIBadgeClasses::GUIBadgeClasses(), HandleBadgeConfigurationDropDownClick(), and UsedBadgeClasses::UsedBadgeClasses().

## ◆ GetClassBadges()

std::span< const BadgeID > GetClassBadges | ( |  | ) |

Get a read-only view of class badge index.

Returns
  Span of badges.

Definition at line 49 of file newgrf_badge.cpp.

References _badges, and Badges::classes.

Referenced by AddBadgeClassesToConfiguration(), and ResetBadgeClassConfiguration().

## ◆ GetOrCreateBadge()

Badge & GetOrCreateBadge | ( | std::string_view | label | ) |

Register a badge label and return its global index.

Parameters

  label | Badge label to register.

Returns
  Global index of the badge.

Definition at line 82 of file newgrf_badge.cpp.

References _badges, BADGE_CLASS_SEPARATOR, Badge::class_index, GetOrCreateBadge(), GetOrCreateBadgeClass(), Badge::label, and Badges::specs.

Referenced by GetOrCreateBadge().

## ◆ MarkBadgeSeen()

void MarkBadgeSeen | ( | BadgeID | index,
|  | GrfSpecFeature | feature
| ) |  |

Mark a badge a seen (used) by a feature.

Definition at line 236 of file newgrf_badge.cpp.

References Badge::features, GetBadge(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().

Referenced by ReadBadgeList().

## ◆ ResetBadges()

void ResetBadges | ( |  | ) |

Reset badges to the default state.

Definition at line 72 of file newgrf_badge.cpp.

References _badges.

Referenced by ResetNewGRFData().