OpenTTD Source 20260206-master-g4d4e37dbf1
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
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
20class Badge {
21public:
22 std::string label;
23 BadgeID index;
24 BadgeClassID class_index;
25 BadgeFlags flags = {};
27 GrfSpecFeatures features{};
29
30 Badge(std::string_view label, BadgeID index, BadgeClassID class_index) : label(label), index(index), class_index(class_index) {}
31};
32
34class UsedBadgeClasses {
35public:
36 UsedBadgeClasses() = default;
37 explicit UsedBadgeClasses(GrfSpecFeature feature);
38
39 inline GrfSpecFeature GetFeature() const
40 {
41 return this->feature;
42 }
43
44 inline std::span<const BadgeClassID> Classes() const
45 {
46 return this->classes;
47 }
48
49private:
50 GrfSpecFeature feature{};
51 std::vector<BadgeClassID> classes;
52};
53
54void ResetBadges();
55
56Badge &GetOrCreateBadge(std::string_view label);
57void MarkBadgeSeen(BadgeID index, GrfSpecFeature feature);
58void AppendCopyableBadgeList(std::vector<BadgeID> &dst, std::span<const BadgeID> src, GrfSpecFeature feature);
60
61std::span<const Badge> GetBadges();
62Badge *GetBadge(BadgeID index);
63Badge *GetBadgeByLabel(std::string_view label);
64Badge *GetClassBadge(BadgeClassID class_index);
65std::span<const BadgeID> GetClassBadges();
66
67uint32_t GetBadgeVariableResult(const struct GRFFile &grffile, std::span<const BadgeID> badges, uint32_t parameter);
68
69PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, PaletteID remap);
70
72public:
73 BadgeTextFilter(struct StringFilter &filter, GrfSpecFeature feature);
74 bool Filter(std::span<const BadgeID> badges) const;
75
76private:
77 FlatSet<BadgeID> badges{};
78};
79
80class BadgeDropdownFilter {
81public:
82 BadgeDropdownFilter(const BadgeFilterChoices &conf) : badges(conf) {}
83 bool Filter(std::span<const BadgeID> badges) const;
84
85private:
86 const BadgeFilterChoices &badges;
87};
88
89#endif /* NEWGRF_BADGE_H */
bool Filter(std::span< const BadgeID > badges) const
Test if the given badges matches the filtered badge list.
bool Filter(std::span< const BadgeID > badges) const
Test if any of the given badges matches the filtered badge list.
BadgeTextFilter(struct StringFilter &filter, GrfSpecFeature feature)
Construct a badge text filter.
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.
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:71
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 for a badge class index.
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 simplifies and embeds a common mechanism of loading/saving and mapping of grf entities.
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:117
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.