OpenTTD Source: src/company_manager_face.h File Reference

OpenTTD Source 15.0-RC2

Data Structures | Typedefs | Enumerations | Functions
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 FaceSpec * | GetCompanyManagerFaceSpec (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< CompanyManagerFace > | ParseCompanyManagerFaceCode (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

  cmf | the company manager's face
  colour | the (background) colour of the gradient
  r | position 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

  label | Label to find.

Returns
  Index of face style if label is found, otherwise std::nullopt.

Definition at line 1409 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

  cmf | The company manager face.

Returns
  String containing face code.

Definition at line 1479 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

  cmf | The company manager face.
  vars | The 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_index | Face style to get.

Returns
  Definition of face style.

Definition at line 1398 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_index | Face style to get variables for.

Returns
  Variables for the face style.

Definition at line 1422 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 1388 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

  cmf | The CompanyManagerFace.
  style | The face variables.

Returns
  The masked face bits.

Definition at line 1463 of file company_cmd.cpp.

References CompanyManagerFace::bits, and GetActiveFaceVars().

Referenced by FormatCompanyManagerFaceCode(), and ParseCompanyManagerFaceCode().

## ◆ ParseCompanyManagerFaceCode()

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

Parse a face code into a company manager face.

Parameters

  str | Face code to parse.

Returns
  Company manager face, or std::nullopt if it could not be parsed.

Definition at line 1490 of file company_cmd.cpp.

References CompanyManagerFace::bits, FindCompanyManagerFaceLabel(), GB(), GetCompanyManagerFaceVars(), MaskCompanyManagerFaceBits(), StringConsumer::npos, ParseInteger(), StringConsumer::ReadUntilChar(), ScaleAllCompanyManagerFaceBits(), SetCompanyManagerFaceStyle(), StringConsumer::SKIP_ONE_SEPARATOR, and CompanyManagerFace::style.

Referenced by CmdCompanyCtrl(), DoStartupNewCompany(), SelectCompanyManagerFaceWindow::OnClick(), and SelectCompanyManagerFaceWindow::OnQueryTextFinished().

## ◆ 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

  cmf | The CompanyManagerFace to randomise.
  randomizer | The randomizer to use.

Definition at line 1450 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

  cmf | The company manager's face to write the bits to
  vars | The face variables.
  randomizer | The 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 1378 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

  cmf | the 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

  cmf | The CompanyManagerFace to change.
  style | The style to set.

Definition at line 1435 of file company_cmd.cpp.

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

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