10#ifndef COMPANY_MANAGER_FACE_H
11#define COMPANY_MANAGER_FACE_H
19#include "table/strings.h"
21enum class FaceVarType : uint8_t {
34 std::variant<SpriteID, uint64_t, std::pair<uint64_t, uint64_t>>
data;
44 return GB(cmf.
bits, this->offset, this->length);
54 SB(cmf.
bits, this->offset, this->length, val);
65 int8_t val = this->
GetBits(cmf) + amount;
94 assert(val < (1U << this->length));
95 return (val * this->valid_values) >> this->
length;
106 assert(this->type == FaceVarType::Sprite);
107 return std::get<SpriteID>(this->data) + this->
GetBits(cmf);
111using FaceVars = std::span<const FaceVar>;
115 std::variant<FaceVars, std::vector<FaceVar>> face_vars;
117 inline FaceVars GetFaceVars()
const
120 FaceVars operator()(FaceVars vars)
const {
return vars; }
121 FaceVars operator()(
const std::vector<FaceVar> &vars)
const {
return vars; }
123 return std::visit(visitor{}, this->face_vars);
142 uint64_t active_vars = (1ULL << std::size(vars)) - 1ULL;
144 for (
const auto &info : vars) {
145 if (info.type != FaceVarType::Toggle)
continue;
146 const auto &[off, on] = std::get<std::pair<uint64_t, uint64_t>>(info.data);
147 active_vars &= ~(
HasBit(cmf.
bits, info.offset) ? on : off);
161 vars[var].ChangeBits(cmf, 0);
Functions related to bit mathematics.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
std::optional< CompanyManagerFace > ParseCompanyManagerFaceCode(std::string_view str)
Parse a face code into a company manager face.
const FaceSpec * GetCompanyManagerFaceSpec(uint style_index)
Get the definition of a company manager face style.
void RandomiseCompanyManagerFace(CompanyManagerFace &cmf, Randomizer &randomizer)
Completely randomise a company manager face, including style.
void ResetFaces()
Reset company manager face styles to default.
uint32_t MaskCompanyManagerFaceBits(const CompanyManagerFace &cmf, FaceVars vars)
Mask company manager face bits to ensure they are all within range.
void RandomiseCompanyManagerFaceBits(CompanyManagerFace &cmf, FaceVars vars, Randomizer &randomizer)
Make a random new face without changing the face style.
FaceVars GetCompanyManagerFaceVars(uint style_index)
Get the face variables for a face style.
void SetCompanyManagerFaceStyle(CompanyManagerFace &cmf, uint style)
Set a company face style.
std::optional< uint > FindCompanyManagerFaceLabel(std::string_view label)
Find a company manager face style by label.
uint64_t GetActiveFaceVars(const CompanyManagerFace &cmf, FaceVars vars)
Get a bitmask of currently active face variables.
void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf, FaceVars vars)
Scales all company manager's face bits to the correct scope.
uint GetNumCompanyManagerFaceStyles()
Get the number of company manager face styles.
std::string FormatCompanyManagerFaceCode(const CompanyManagerFace &cmf)
Get a face code representation of a company manager face.
void DrawCompanyManagerFace(const CompanyManagerFace &cmf, Colours colour, const Rect &r)
Draws the face of a company manager's face.
Types related to companies.
Types related to the graphics and/or input devices.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Pseudo random number generator.
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
uint32_t bits
Company manager face bits, meaning is dependent on style.
Information about the valid values of CompanyManagerFace bitgroups as well as the sprites to draw.
uint8_t position
Position in UI.
uint GetBits(const CompanyManagerFace &cmf) const
Gets the company manager's face bits.
void ChangeBits(CompanyManagerFace &cmf, int8_t amount) const
Increase/Decrease the company manager's face variable by the given amount.
uint8_t offset
Offset in bits into the CompanyManagerFace.
std::variant< SpriteID, uint64_t, std::pair< uint64_t, uint64_t > > data
The first sprite.
uint8_t valid_values
The number of valid values.
uint ScaleBits(uint val) const
Scales a company manager's face bits variable to the correct scope.
bool IsValid(const CompanyManagerFace &cmf) const
Checks whether the company manager's face bits have a valid range.
SpriteID GetSprite(const CompanyManagerFace &cmf) const
Gets the sprite to draw.
void SetBits(CompanyManagerFace &cmf, uint val) const
Sets the company manager's face bits.
uint8_t length
Number of bits used in the CompanyManagerFace.
Information about the currently used palette.
Structure to encapsulate the pseudo random number generators.
uint32_t Next()
Generate the next pseudo random number.
Specification of a rectangle with absolute coordinates of all edges.
Iterable ensemble of each set bit in a value.
Data structure describing a sprite.