OpenTTD Source 20250719-master-gb8e56cd05d
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 }
 

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 111 of file company_manager_face.h.

Enumeration Type Documentation

◆ FaceVarType

enum class FaceVarType : uint8_t
strong

Definition at line 21 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(), and CompanyManagerFace::style.

Referenced by SelectCompanyManagerFaceWindow::DrawWidget(), CompanyWindow::DrawWidget(), BuyCompanyWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), and NewsWindow::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 1421 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 1491 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 140 of file company_manager_face.h.

References CompanyManagerFace::bits, and HasBit().

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 1410 of file company_cmd.cpp.

References _faces, and GetNumCompanyManagerFaceStyles().

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

◆ GetCompanyManagerFaceVars()

FaceVars GetCompanyManagerFaceVars ( uint  style)

Get the face variables for a face style.

Parameters
style_indexFace style to get variables for.
Returns
Variables for the face style.

Definition at line 1434 of file company_cmd.cpp.

References GetCompanyManagerFaceSpec().

Referenced by DrawCompanyManagerFace(), SelectCompanyManagerFaceWindow::DrawWidget(), FormatCompanyManagerFaceCode(), IsValidCompanyManagerFace(), SelectCompanyManagerFaceWindow::OnClick(), ParseCompanyManagerFaceCode(), RandomiseCompanyManagerFace(), and SelectCompanyManagerFaceWindow::UpdateData().

◆ GetNumCompanyManagerFaceStyles()

uint GetNumCompanyManagerFaceStyles ( )

Get the number of company manager face styles.

Returns
Number of face styles.

Definition at line 1400 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.
styleThe face variables.
Returns
The masked face bits.

Definition at line 1475 of file company_cmd.cpp.

References CompanyManagerFace::bits, and GetActiveFaceVars().

Referenced by FormatCompanyManagerFaceCode(), and ParseCompanyManagerFaceCode().

◆ ParseCompanyManagerFaceCode()

std::optional< CompanyManagerFace > ParseCompanyManagerFaceCode ( std::string_view  str)

◆ 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 1462 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 171 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 1390 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

Definition at line 158 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 1447 of file company_cmd.cpp.

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

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