20#include "table/strings.h"
93 if (sep != std::string_view::npos) {
100 if (sep == std::string_view::npos) {
105 it =
_badges.
specs.emplace(it, label, index, class_index);
116 if (index.base() >= std::size(
_badges.
specs))
return nullptr;
140 if (class_index.base() >= std::size(
_badges.
classes))
return nullptr;
147 const std::optional<TimerGameCalendar::Date> introduction_date;
156 :
ScopeResolver(
ro), badge(badge), introduction_date(introduction_date) { }
158 uint32_t
GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter,
bool &available)
const override;
165 if (this->introduction_date.has_value())
return this->introduction_date->base();
200 return this->self_scope.badge.
index.base();
213 :
ResolverObject(badge.grf_prop.grffile, callback, callback_param1, callback_param2), self_scope(*this, badge, introduction_date)
215 assert(feature <= GSF_END);
228 if (parameter >= std::size(grffile.
badge_list))
return UINT_MAX;
231 return std::ranges::find(badges, index) != std::end(badges);
240 assert(b !=
nullptr);
253 for (
const BadgeID &index : src) {
255 if (std::ranges::find(dst, index) != std::end(dst))
continue;
259 if (badge ==
nullptr)
continue;
262 dst.push_back(index);
272 assert(class_badge !=
nullptr);
289 if (group ==
nullptr || group->num_sprites == 0)
return {0, PAL_NONE};
293 return {group->sprite, pal};
324 if (badge.name == STR_NULL)
continue;
325 if (!badge.features.Test(feature))
continue;
331 this->badges.insert(badge.index);
342 return std::ranges::any_of(badges, [
this](
const BadgeID &badge) {
return std::ranges::binary_search(this->badges, badge); });
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.
Global state for badge definitions.
std::vector< BadgeID > classes
List of known badge classes.
std::vector< Badge > specs
List of known badges.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Set()
Set all bits.
static Date date
Current date in days (day counter).
std::vector< BadgeClassID > classes
List of badge classes.
UsedBadgeClasses(GrfSpecFeature feature)
Create a list of used badge classes for a feature.
uint32_t PaletteID
The number of the palette.
Base for the NewGRF implementation.
@ GSF_DEFAULT
Unspecified feature, default badge.
static Badges _badges
Static instance of badge state.
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.
static constexpr char BADGE_CLASS_SEPARATOR
Separator to identify badge classes from a label.
static BadgeClassID GetOrCreateBadgeClass(BadgeID index)
Assign a BadgeClassID to the given badge.
Badge & GetOrCreateBadge(std::string_view label)
Register a badge label and return its global index.
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 * GetBadgeByLabel(std::string_view label)
Get a badge by label if it exists.
void ResetBadges()
Reset badges to the default state.
Functions related to NewGRF badges.
Badge * GetBadge(BadgeID index)
Get a badge if it exists.
std::span< const Badge > GetBadges()
Get a read-only view of badges.
Badge * GetClassBadge(BadgeClassID class_index)
Get the badge class of a badge label.
Functions related to NewGRF badge configuration.
Types related to NewGRF badges.
@ UseCompanyColour
Apply company colour palette to this badge.
@ Copy
Copy badge to related things.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
@ VSG_SCOPE_SELF
Resolved object itself.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
Searching and filtering using a stringterm.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Functions related to OTTD's strings.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
BadgeResolverObject(const Badge &badge, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Constructor of the badge resolver.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0) override
Get a resolver for the scope.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Resolver for a badge scope.
BadgeScopeResolver(ResolverObject &ro, const Badge &badge, const std::optional< TimerGameCalendar::Date > introduction_date)
Scope resolver of a badge.
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
Dynamic data of a loaded NewGRF.
std::vector< BadgeID > badge_list
Badge translation table (local index -> global index)
Combination of a palette sprite and a 'real' sprite.
Interface for SpriteGroup-s to access the gamestate.
uint32_t callback_param2
Second parameter (var 18) of the callback.
CallbackID callback
Callback being resolved.
uint32_t callback_param1
First parameter (var 10) of the callback.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0)
Get a resolver for the scope.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
ResolverObject & ro
Surrounding resolver object.
bool IsEmpty() const
Check whether any filter words were entered.
void ResetState()
Reset the matching state to process a new item.
bool GetState() const
Get the matching state of the current item.
const struct SpriteGroup * GetFirstSpriteGroupOf(std::initializer_list< Tkey > indices) const
Get the first existing SpriteGroup from a list of options.
Definition of the game-calendar-timer.