OpenTTD Source: FaceVar Struct Reference

OpenTTD Source 15.3

Public Member Functions | Data Fields
FaceVar Struct Reference

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

`#include <company_manager_face.h>`

## Public Member Functions
uint | GetBits (const CompanyManagerFace &cmf) const
| Gets the company manager's face bits.
void | SetBits (CompanyManagerFace &cmf, uint val) const
| Sets 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.
bool | IsValid (const CompanyManagerFace &cmf) const
| Checks whether the company manager's face bits have a valid range.
uint | ScaleBits (uint val) const
| Scales a company manager's face bits variable to the correct scope.
SpriteID | GetSprite (const CompanyManagerFace &cmf) const
| Gets the sprite to draw.

## Data Fields
FaceVarType | type
uint8_t | position
| Position in UI.
uint8_t | offset
| Offset in bits into the CompanyManagerFace.
uint8_t | length
| Number of bits used in the CompanyManagerFace.
uint8_t | valid_values
| The number of valid values.
std::variant< SpriteID, uint64_t, std::pair< uint64_t, uint64_t > > | data
| The first sprite.
StringID | name = STR_NULL

## Detailed Description

Information about the valid values of CompanyManagerFace bitgroups as well as the sprites to draw.

Definition at line 28 of file company_manager_face.h.

## Member Function Documentation

## ◆ ChangeBits()

void FaceVar::ChangeBits | ( | CompanyManagerFace & | cmf,
|  | int8_t | amount
| ) |  | const
| inline

Increase/Decrease the company manager's face variable by the given amount.

The value wraps around to stay in the valid range.

Parameters

  cmf | The face to write the bits to.
  amount | the amount to change the value

Definition at line 63 of file company_manager_face.h.

References GetBits(), SetBits(), and valid_values.

## ◆ GetBits()

uint FaceVar::GetBits | ( | const CompanyManagerFace & | cmf | ) | const
| inline

Gets the company manager's face bits.

Parameters

  cmf | The face to extract the bits from.

Returns
  the requested bits

Definition at line 42 of file company_manager_face.h.

References CompanyManagerFace::bits, and GB().

Referenced by ChangeBits(), and GetSprite().

## ◆ GetSprite()

SpriteID FaceVar::GetSprite | ( | const CompanyManagerFace & | cmf | ) | const
| inline

Gets the sprite to draw.

Parameters

  cmf | The face to extract the data from

Precondition
  vars[var].type == FaceVarType::Sprite.

Returns
  sprite to draw

Definition at line 104 of file company_manager_face.h.

References GetBits().

## ◆ IsValid()

bool FaceVar::IsValid | ( | const CompanyManagerFace & | cmf | ) | const
| inline

Checks whether the company manager's face bits have a valid range.

Parameters

  cmf | The face to check.

Returns
  true if and only if the bits are valid

Definition at line 81 of file company_manager_face.h.

References CompanyManagerFace::bits, GB(), and valid_values.

## ◆ ScaleBits()

uint FaceVar::ScaleBits | ( | uint | val | ) | const
| inline

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

Parameters

  vars | The face variables of the face style.

Precondition
  val < (1U << length), i.e. val has a value of 0..2^(bits used for this variable)-1

Returns
  the scaled value

Definition at line 92 of file company_manager_face.h.

References length.

## ◆ SetBits()

void FaceVar::SetBits | ( | CompanyManagerFace & | cmf,
|  | uint | val
| ) |  | const
| inline

Sets the company manager's face bits.

Parameters

  cmf | The face to write the bits to.
  val | The new value.

Definition at line 52 of file company_manager_face.h.

References CompanyManagerFace::bits, and SB().

Referenced by ChangeBits().

## Field Documentation

## ◆ data

std::variant<SpriteID, uint64_t, std::pair<uint64_t, uint64_t> > FaceVar::data

The first sprite.

Definition at line 34 of file company_manager_face.h.

## ◆ length

uint8_t FaceVar::length

Number of bits used in the CompanyManagerFace.

Definition at line 32 of file company_manager_face.h.

Referenced by ScaleBits().

## ◆ name

StringID FaceVar::name = STR_NULL

Definition at line 35 of file company_manager_face.h.

## ◆ offset

uint8_t FaceVar::offset

Offset in bits into the CompanyManagerFace.

Definition at line 31 of file company_manager_face.h.

## ◆ position

uint8_t FaceVar::position

Position in UI.

Definition at line 30 of file company_manager_face.h.

Referenced by SelectCompanyManagerFaceWindow::UpdateData().

## ◆ type

FaceVarType FaceVar::type

Definition at line 29 of file company_manager_face.h.

## ◆ valid_values

uint8_t FaceVar::valid_values

The number of valid values.

Definition at line 33 of file company_manager_face.h.

Referenced by ChangeBits(), SelectCompanyManagerFaceWindow::DrawWidget(), and IsValid().

The documentation for this struct was generated from the following file:

- src/company_manager_face.h