OpenTTD Source 20260206-master-g4d4e37dbf1
company_manager_face.h File Reference

Functionality related to the company manager's face. More...

#include "core/random_func.hpp"
#include "core/bitmath_func.hpp"
#include "strings_type.h"
#include "company_type.h"
#include "gfx_type.h"
#include "table/strings.h"

Go to the source code of this file.

Data Structures

struct  FaceVar
 Information about the valid values of CompanyManagerFace bitgroups as well as the sprites to draw. More...
struct  FaceSpec

Typedefs

using FaceVars = std::span<const FaceVar>

Enumerations

enum class  FaceVarType : uint8_t { Sprite , Palette , Toggle }
 Ways a FaceVar should be interpreted. More...

Functions

void ResetFaces ()
 Reset company manager face styles to default.
uint GetNumCompanyManagerFaceStyles ()
 Get the number of company manager face styles.
std::optional< uint > FindCompanyManagerFaceLabel (std::string_view label)
 Find a company manager face style by label.
const FaceSpecGetCompanyManagerFaceSpec (uint style_index)
 Get the definition of a company manager face style.
FaceVars GetCompanyManagerFaceVars (uint style_index)
 Get the face variables for a face style.
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.
void RandomiseCompanyManagerFaceBits (CompanyManagerFace &cmf, FaceVars vars, Randomizer &randomizer)
 Make a random new face without changing the face style.
void SetCompanyManagerFaceStyle (CompanyManagerFace &cmf, uint style)
 Set a company face style.
void RandomiseCompanyManagerFace (CompanyManagerFace &cmf, Randomizer &randomizer)
 Completely randomise a company manager face, including style.
uint32_t MaskCompanyManagerFaceBits (const CompanyManagerFace &cmf, FaceVars vars)
 Mask company manager face bits to ensure they are all within range.
std::string FormatCompanyManagerFaceCode (const CompanyManagerFace &cmf)
 Get a face code representation of a company manager face.
std::optional< CompanyManagerFaceParseCompanyManagerFaceCode (std::string_view str)
 Parse a face code into a company manager face.
void DrawCompanyManagerFace (const CompanyManagerFace &cmf, Colours colour, const Rect &r)
 Draws the face of a company manager's face.

Detailed Description

Functionality related to the company manager's face.

Definition in file company_manager_face.h.

Typedef Documentation

◆ FaceVars

using FaceVars = std::span<const FaceVar>

Definition at line 112 of file company_manager_face.h.

Enumeration Type Documentation

◆ FaceVarType

enum class FaceVarType : uint8_t
strong

Ways a FaceVar should be interpreted.

Enumerator
Sprite 

FaceVar describes an offset to the given SpriteID.

Palette 

FaceVar describes a palette to apply to the given parts bitmask.

Toggle 

FaceVar describes which other FaceVars should be turned off.

Definition at line 22 of file company_manager_face.h.

Function Documentation

◆ DrawCompanyManagerFace()

void DrawCompanyManagerFace ( const CompanyManagerFace & cmf,
Colours colour,
const Rect & r )

Draws the face of a company manager's face.

Parameters
cmfthe company manager's face
colourthe (background) colour of the gradient
rposition to draw the face

Definition at line 1120 of file company_gui.cpp.

References CentreBounds(), DrawSprite(), GetActiveFaceVars(), GetColourPalette(), GetCompanyManagerFaceVars(), GetSpriteSize(), Palette, Rect, Sprite, and CompanyManagerFace::style.

Referenced by BuyCompanyWindow::DrawWidget(), CompanyWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), NewsWindow::DrawWidget(), and SelectCompanyManagerFaceWindow::DrawWidget().

◆ FindCompanyManagerFaceLabel()

std::optional< uint > FindCompanyManagerFaceLabel ( std::string_view label)

Find a company manager face style by label.

Parameters
labelLabel to find.
Returns
Index of face style if label is found, otherwise std::nullopt.

Definition at line 1414 of file company_cmd.cpp.

References _faces.

Referenced by AfterLoadGame(), and ParseCompanyManagerFaceCode().

◆ FormatCompanyManagerFaceCode()

std::string FormatCompanyManagerFaceCode ( const CompanyManagerFace & cmf)

Get a face code representation of a company manager face.

Parameters
cmfThe company manager face.
Returns
String containing face code.

Definition at line 1484 of file company_cmd.cpp.

References GetCompanyManagerFaceVars(), MaskCompanyManagerFaceBits(), CompanyManagerFace::style, and CompanyManagerFace::style_label.

Referenced by SelectCompanyManagerFaceWindow::OnClick().

◆ GetActiveFaceVars()

uint64_t GetActiveFaceVars ( const CompanyManagerFace & cmf,
FaceVars vars )
inline

Get a bitmask of currently active face variables.

Face variables can be inactive due to toggles in the face variables.

Parameters
cmfThe company manager face.
varsThe face variables of the face.
Returns
Currently active face variables for the face.

Definition at line 141 of file company_manager_face.h.

References CompanyManagerFace::bits, HasBit(), and Toggle.

Referenced by DrawCompanyManagerFace(), IsValidCompanyManagerFace(), MaskCompanyManagerFaceBits(), ScaleAllCompanyManagerFaceBits(), and SelectCompanyManagerFaceWindow::UpdateData().

◆ GetCompanyManagerFaceSpec()

const FaceSpec * GetCompanyManagerFaceSpec ( uint style_index)

Get the definition of a company manager face style.

Parameters
style_indexFace style to get.
Returns
Definition of face style.

Definition at line 1403 of file company_cmd.cpp.

References _faces, and GetNumCompanyManagerFaceStyles().

Referenced by ConvertFromOldCompanyManagerFace(), GetCompanyManagerFaceVars(), and SetCompanyManagerFaceStyle().

◆ GetCompanyManagerFaceVars()

FaceVars GetCompanyManagerFaceVars ( uint style)

◆ GetNumCompanyManagerFaceStyles()

uint GetNumCompanyManagerFaceStyles ( )

Get the number of company manager face styles.

Returns
Number of face styles.

Definition at line 1393 of file company_cmd.cpp.

References _faces.

Referenced by SelectCompanyManagerFaceWindow::DrawWidget(), GetCompanyManagerFaceSpec(), IsValidCompanyManagerFace(), SelectCompanyManagerFaceWindow::OnClick(), and RandomiseCompanyManagerFace().

◆ MaskCompanyManagerFaceBits()

uint32_t MaskCompanyManagerFaceBits ( const CompanyManagerFace & cmf,
FaceVars vars )

Mask company manager face bits to ensure they are all within range.

Note
Does not update the CompanyManagerFace itself. Unused bits are cleared.
Parameters
cmfThe CompanyManagerFace.
varsThe face variables.
Returns
The masked face bits.

Definition at line 1468 of file company_cmd.cpp.

References CompanyManagerFace::bits, and GetActiveFaceVars().

Referenced by FormatCompanyManagerFaceCode(), and ParseCompanyManagerFaceCode().

◆ ParseCompanyManagerFaceCode()

◆ RandomiseCompanyManagerFace()

void RandomiseCompanyManagerFace ( CompanyManagerFace & cmf,
Randomizer & randomizer )

Completely randomise a company manager face, including style.

Note
randomizer should passed be appropriate for server-side or client-side usage.
Parameters
cmfThe CompanyManagerFace to randomise.
randomizerThe randomizer to use.

Definition at line 1455 of file company_cmd.cpp.

References GetCompanyManagerFaceVars(), GetNumCompanyManagerFaceStyles(), Randomizer::Next(), RandomiseCompanyManagerFaceBits(), SetCompanyManagerFaceStyle(), and CompanyManagerFace::style.

Referenced by AfterLoadGame(), DoStartupNewCompany(), and SelectCompanyManagerFaceWindow::OnClick().

◆ RandomiseCompanyManagerFaceBits()

void RandomiseCompanyManagerFaceBits ( CompanyManagerFace & cmf,
FaceVars vars,
Randomizer & randomizer )
inline

Make a random new face without changing the face style.

Parameters
cmfThe company manager's face to write the bits to
varsThe face variables.
randomizerThe source of random to use for creating the manager face

Definition at line 173 of file company_manager_face.h.

References CompanyManagerFace::bits, Randomizer::Next(), and ScaleAllCompanyManagerFaceBits().

Referenced by RandomiseCompanyManagerFace().

◆ ResetFaces()

void ResetFaces ( )

Reset company manager face styles to default.

Definition at line 1383 of file company_cmd.cpp.

References _faces, and _original_faces.

Referenced by ResetNewGRFData().

◆ ScaleAllCompanyManagerFaceBits()

void ScaleAllCompanyManagerFaceBits ( CompanyManagerFace & cmf,
FaceVars vars )
inline

Scales all company manager's face bits to the correct scope.

Parameters
cmfthe company manager's face to write the bits to
varsThe face variables to scale.

Definition at line 160 of file company_manager_face.h.

References GetActiveFaceVars().

Referenced by ParseCompanyManagerFaceCode(), RandomiseCompanyManagerFaceBits(), and SelectCompanyManagerFaceWindow::UpdateData().

◆ SetCompanyManagerFaceStyle()

void SetCompanyManagerFaceStyle ( CompanyManagerFace & cmf,
uint style )

Set a company face style.

Changes both the style index and the label.

Parameters
cmfThe CompanyManagerFace to change.
styleThe style to set.

Definition at line 1440 of file company_cmd.cpp.

References GetCompanyManagerFaceSpec(), CompanyManagerFace::style, and CompanyManagerFace::style_label.

Referenced by AfterLoadGame(), CmdSetCompanyManagerFace(), SelectCompanyManagerFaceWindow::OnClick(), ParseCompanyManagerFaceCode(), and RandomiseCompanyManagerFace().