OpenTTD Source: src/newgrf_badge.h Source File

OpenTTD Source 15.3

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
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"
18#include "timer/timer_game_calendar.h"
19
20 class Badge {
21public:
22 std::string label;
23 BadgeID index;
24 BadgeClassID class_index;
25 BadgeFlags flags = {};
26 StringID name = 0;
27 GrfSpecFeatures features{};
28 VariableGRFFileProps<GrfSpecFeature> grf_prop;
29
30 Badge(std::string_view label, BadgeID index, BadgeClassID class_index) : label(label), index(index), class_index(class_index) {}
31};
32
34 class 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
56 Badge &GetOrCreateBadge(std::string_view label);
57void MarkBadgeSeen(BadgeID index, GrfSpecFeature feature);
58void AppendCopyableBadgeList(std::vector<BadgeID> &dst, std::span<const BadgeID> src, GrfSpecFeature feature);
59void ApplyBadgeFeaturesToClassBadges();
60
61std::span<const Badge> GetBadges();
62 Badge *GetBadge(BadgeID index);
63 Badge *GetBadgeByLabel(std::string_view label);
64 Badge *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
69 PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, PaletteID remap);
70
71 class BadgeTextFilter {
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
80 class 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 */
BadgeDropdownFilter
Definition newgrf_badge.h:80
BadgeTextFilter
Definition newgrf_badge.h:71
Badge
Definition newgrf_badge.h:20
Badge::class_index
BadgeClassID class_index
Index of class this badge belongs to.
Definition newgrf_badge.h:24
Badge::grf_prop
VariableGRFFileProps< GrfSpecFeature > grf_prop
Sprite information.
Definition newgrf_badge.h:28
Badge::label
std::string label
Label of badge.
Definition newgrf_badge.h:22
Badge::index
BadgeID index
Index assigned to badge.
Definition newgrf_badge.h:23
Badge::flags
BadgeFlags flags
Display flags.
Definition newgrf_badge.h:25
Badge::features
GrfSpecFeatures features
Bitmask of which features use this badge.
Definition newgrf_badge.h:27
Badge::name
StringID name
Short name.
Definition newgrf_badge.h:26
EnumBitSet< BadgeFlag, uint8_t >
FlatSet
Flat set implementation that uses a sorted vector for storage.
Definition flatset_type.hpp:20
UsedBadgeClasses
Utility class to create a list of badge classes used by a feature.
Definition newgrf_badge.h:34
UsedBadgeClasses::classes
std::vector< BadgeClassID > classes
List of badge classes.
Definition newgrf_badge.h:51
flatset_type.hpp
Flat set container implementation.
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
newgrf.h
Base for the NewGRF implementation.
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
GetBadgeVariableResult
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.
Definition newgrf_badge.cpp:225
GetBadge
Badge * GetBadge(BadgeID index)
Get a badge if it exists.
Definition newgrf_badge.cpp:113
GetBadges
std::span< const Badge > GetBadges()
Get a read-only view of badges.
Definition newgrf_badge.cpp:40
ApplyBadgeFeaturesToClassBadges
void ApplyBadgeFeaturesToClassBadges()
Apply features from all badges to their badge classes.
Definition newgrf_badge.cpp:267
MarkBadgeSeen
void MarkBadgeSeen(BadgeID index, GrfSpecFeature feature)
Mark a badge a seen (used) by a feature.
Definition newgrf_badge.cpp:236
AppendCopyableBadgeList
void AppendCopyableBadgeList(std::vector< BadgeID > &dst, std::span< const BadgeID > src, GrfSpecFeature feature)
Append copyable badges from a list onto another.
Definition newgrf_badge.cpp:250
GetBadgeSprite
PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap)
Get sprite for the given badge.
Definition newgrf_badge.cpp:285
GetClassBadges
std::span< const BadgeID > GetClassBadges()
Get a read-only view of class badge index.
Definition newgrf_badge.cpp:49
GetClassBadge
Badge * GetClassBadge(BadgeClassID class_index)
Get the badge for a badge class index.
Definition newgrf_badge.cpp:137
GetOrCreateBadge
Badge & GetOrCreateBadge(std::string_view label)
Register a badge label and return its global index.
Definition newgrf_badge.cpp:82
GetBadgeByLabel
Badge * GetBadgeByLabel(std::string_view label)
Get a badge by label if it exists.
Definition newgrf_badge.cpp:124
ResetBadges
void ResetBadges()
Reset badges to the default state.
Definition newgrf_badge.cpp:72
newgrf_badge_type.h
Types related to NewGRF badges.
newgrf_commons.h
This file simplifies and embeds a common mechanism of loading/saving and mapping of grf entities.
SortListFlag::Filter
@ Filter
filter disabled/enabled
strings_type.h
Types related to strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
PalSpriteID
Combination of a palette sprite and a 'real' sprite.
Definition gfx_type.h:22
StringFilter
String filter and state.
Definition stringfilter_type.h:30
StrongType::Typedef< uint32_t, struct BadgeIDTag, StrongType::Compare >
VariableGRFFileProps
Variable-length list of sprite groups for an entity.
Definition newgrf_commons.h:406
timer_game_calendar.h
Definition of the game-calendar-timer.