OpenTTD Source 20250529-master-g10c159a79f
newgrf_badge.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10#ifndef NEWGRF_BADGE_H
11#define NEWGRF_BADGE_H
12
13#include "core/flatset_type.hpp"
14#include "newgrf.h"
15#include "newgrf_badge_type.h"
16#include "newgrf_commons.h"
17#include "strings_type.h"
19
32
35public:
36 explicit UsedBadgeClasses(GrfSpecFeature feature);
37
38 inline std::span<const BadgeClassID> Classes() const
39 {
40 return this->classes;
41 }
42
43private:
44 std::vector<BadgeClassID> classes;
45};
46
47void ResetBadges();
48
49Badge &GetOrCreateBadge(std::string_view label);
50void MarkBadgeSeen(BadgeID index, GrfSpecFeature feature);
51void AppendCopyableBadgeList(std::vector<BadgeID> &dst, std::span<const BadgeID> src, GrfSpecFeature feature);
53
54std::span<const Badge> GetBadges();
55Badge *GetBadge(BadgeID index);
56Badge *GetBadgeByLabel(std::string_view label);
57Badge *GetClassBadge(BadgeClassID class_index);
58std::span<const BadgeID> GetClassBadges();
59
60uint32_t GetBadgeVariableResult(const struct GRFFile &grffile, std::span<const BadgeID> badges, uint32_t parameter);
61
62PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, PaletteID remap);
63
65public:
66 BadgeTextFilter(struct StringFilter &filter, GrfSpecFeature feature);
67 bool Filter(std::span<const BadgeID> badges) const;
68
69private:
70 FlatSet<BadgeID> badges{};
71};
72
73#endif /* NEWGRF_BADGE_H */
BadgeClassID class_index
Index of class this badge belongs to.
VariableGRFFileProps< GrfSpecFeature > grf_prop
Sprite information.
std::string label
Label of badge.
BadgeID index
Index assigned to badge.
BadgeFlags flags
Display flags.
GrfSpecFeatures features
Bitmask of which features use this badge.
StringID name
Short name.
Flat set implementation that uses a sorted vector for storage.
Utility class to create a list of badge classes used by a feature.
std::vector< BadgeClassID > classes
List of badge classes.
Flat set container implementation.
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
Base for the NewGRF implementation.
GrfSpecFeature
Definition newgrf.h:69
uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span< const BadgeID > badges, uint32_t parameter)
Test for a matching badge in a list of badges, returning the number of matching bits.
Badge * GetBadge(BadgeID index)
Get a badge if it exists.
std::span< const Badge > GetBadges()
Get a read-only view of badges.
void ApplyBadgeFeaturesToClassBadges()
Apply features from all badges to their badge classes.
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.
PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap)
Get sprite for the given badge.
std::span< const BadgeID > GetClassBadges()
Get a read-only view of class badge index.
Badge * GetClassBadge(BadgeClassID class_index)
Get the badge class of a badge label.
Badge & GetOrCreateBadge(std::string_view label)
Register a badge label and return its global index.
Badge * GetBadgeByLabel(std::string_view label)
Get a badge by label if it exists.
void ResetBadges()
Reset badges to the default state.
Types related to NewGRF badges.
This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities.
@ Filter
filter disabled/enabled
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Dynamic data of a loaded NewGRF.
Definition newgrf.h:115
Combination of a palette sprite and a 'real' sprite.
Definition gfx_type.h:22
String filter and state.
Variable-length list of sprite groups for an entity.
Definition of the game-calendar-timer.