OpenTTD Source  20241120-master-g6d3adc6169
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 "table/sprites.h"
#include "company_type.h"

Go to the source code of this file.

Data Structures

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

Enumerations

enum  GenderEthnicity {
  GENDER_FEMALE = 0 , ETHNICITY_BLACK = 1 , GE_WM = 0 , GE_WF = 1 << GENDER_FEMALE ,
  GE_BM = 1 << ETHNICITY_BLACK , GE_BF = 1 << ETHNICITY_BLACK | 1 << GENDER_FEMALE , GE_END
}
 The gender/race combinations that we have faces for. More...
 

Functions

 DECLARE_ENUM_AS_BIT_SET (GenderEthnicity) enum CompanyManagerFaceVariable
 Bitgroups of the CompanyManagerFace variable.
 
uint GetCompanyManagerFaceBits (CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, [[maybe_unused]] GenderEthnicity ge)
 Make sure the table's size is right. More...
 
void SetCompanyManagerFaceBits (CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, [[maybe_unused]] GenderEthnicity ge, uint val)
 Sets the company manager's face bits for the given company manager's face variable. More...
 
void IncreaseCompanyManagerFaceBits (CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, int8_t amount)
 Increase/Decrease the company manager's face variable by the given amount. More...
 
bool AreCompanyManagerFaceBitsValid (CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
 Checks whether the company manager's face bits have a valid range. More...
 
uint ScaleCompanyManagerFaceValue (CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
 Scales a company manager's face bits variable to the correct scope. More...
 
void ScaleAllCompanyManagerFaceBits (CompanyManagerFace &cmf)
 Scales all company manager's face bits to the correct scope. More...
 
void RandomCompanyManagerFaceBits (CompanyManagerFace &cmf, GenderEthnicity ge, bool adv, Randomizer &randomizer)
 Make a random new face. More...
 
SpriteID GetCompanyManagerFaceSprite (CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
 Gets the sprite to draw for the given company manager's face variable. More...
 
void DrawCompanyManagerFace (CompanyManagerFace face, Colours colour, const Rect &r)
 Draws the face of a company manager's face. More...
 

Variables

static const CompanyManagerFaceBitsInfo _cmf_info []
 Lookup table for indices into the CompanyManagerFace, valid ranges and sprites. More...
 

Detailed Description

Functionality related to the company manager's face.

Definition in file company_manager_face.h.

Enumeration Type Documentation

◆ GenderEthnicity

The gender/race combinations that we have faces for.

Enumerator
GENDER_FEMALE 

This bit set means a female, otherwise male.

ETHNICITY_BLACK 

This bit set means black, otherwise white.

GE_WM 

A male of Caucasian origin (white)

GE_WF 

A female of Caucasian origin (white)

GE_BM 

A male of African origin (black)

GE_BF 

A female of African origin (black)

Definition at line 19 of file company_manager_face.h.

Function Documentation

◆ AreCompanyManagerFaceBitsValid()

bool AreCompanyManagerFaceBitsValid ( CompanyManagerFace  cmf,
CompanyManagerFaceVariable  cmfv,
GenderEthnicity  ge 
)
inline

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

Parameters
cmfthe face to extract the bits from
cmfvthe face variable to get the data of
gethe gender and ethnicity of the face
Returns
true if and only if the bits are valid

Definition at line 151 of file company_manager_face.h.

References _cmf_info, GB(), and CompanyManagerFaceBitsInfo::valid_values.

Referenced by IsValidCompanyManagerFace().

◆ DrawCompanyManagerFace()

void DrawCompanyManagerFace ( 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 1104 of file company_gui.cpp.

References GE_WM, GetCompanyManagerFaceBits(), and GetSpriteSize().

◆ GetCompanyManagerFaceBits()

uint GetCompanyManagerFaceBits ( CompanyManagerFace  cmf,
CompanyManagerFaceVariable  cmfv,
[[maybe_unused] ] GenderEthnicity  ge 
)
inline

Make sure the table's size is right.

Gets the company manager's face bits for the given company manager's face variable

Parameters
cmfthe face to extract the bits from
cmfvthe face variable to get the data of
gethe gender and ethnicity of the face
Precondition
_cmf_info[cmfv].valid_values[ge] != 0
Returns
the requested bits

Definition at line 96 of file company_manager_face.h.

References _cmf_info, and GB().

Referenced by DrawCompanyManagerFace(), IncreaseCompanyManagerFaceBits(), IsValidCompanyManagerFace(), SelectCompanyManagerFaceWindow::OnPaint(), and ScaleAllCompanyManagerFaceBits().

◆ GetCompanyManagerFaceSprite()

SpriteID GetCompanyManagerFaceSprite ( CompanyManagerFace  cmf,
CompanyManagerFaceVariable  cmfv,
GenderEthnicity  ge 
)
inline

Gets the sprite to draw for the given company manager's face variable.

Parameters
cmfthe face to extract the data from
cmfvthe face variable to get the sprite of
gethe gender and ethnicity of the face
Precondition
_cmf_info[cmfv].valid_values[ge] != 0
Returns
sprite to draw

Definition at line 232 of file company_manager_face.h.

References _cmf_info, CompanyManagerFaceBitsInfo::first_sprite, and GB().

◆ IncreaseCompanyManagerFaceBits()

void IncreaseCompanyManagerFaceBits ( CompanyManagerFace cmf,
CompanyManagerFaceVariable  cmfv,
GenderEthnicity  ge,
int8_t  amount 
)
inline

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

If the new value greater than the max value for this variable it will be set to 0. Or is it negative (< 0) it will be set to max value.

Parameters
cmfthe company manager face to write the bits to
cmfvthe company manager face variable to write the data of
gethe gender and ethnicity of the company manager's face
amountthe amount which change the value
Precondition
0 <= val < _cmf_info[cmfv].valid_values[ge]

Definition at line 130 of file company_manager_face.h.

References _cmf_info, GetCompanyManagerFaceBits(), SetCompanyManagerFaceBits(), and CompanyManagerFaceBitsInfo::valid_values.

Referenced by ScaleAllCompanyManagerFaceBits().

◆ RandomCompanyManagerFaceBits()

void RandomCompanyManagerFaceBits ( CompanyManagerFace cmf,
GenderEthnicity  ge,
bool  adv,
Randomizer randomizer 
)
inline

Make a random new face.

If it is for the advanced company manager's face window then the new face have the same gender and ethnicity as the old one, else the gender is equal and the ethnicity is random.

Parameters
cmfthe company manager's face to write the bits to
gethe gender and ethnicity of the old company manager's face
advif it for the advanced company manager's face window
randomizerthe source of random to use for creating the manager face
Precondition
scale 'ge' to a valid gender/ethnicity combination

Definition at line 206 of file company_manager_face.h.

References Randomizer::Next().

◆ ScaleAllCompanyManagerFaceBits()

void ScaleAllCompanyManagerFaceBits ( CompanyManagerFace cmf)
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 176 of file company_manager_face.h.

References _cmf_info, GB(), GE_WM, GENDER_FEMALE, GetCompanyManagerFaceBits(), HasBit(), and IncreaseCompanyManagerFaceBits().

◆ ScaleCompanyManagerFaceValue()

uint ScaleCompanyManagerFaceValue ( CompanyManagerFaceVariable  cmfv,
GenderEthnicity  ge,
uint  val 
)
inline

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

Parameters
cmfvthe face variable to write the data of
gethe gender and ethnicity of the face
valthe to value to scale
Precondition
val < (1U << _cmf_info[cmfv].length), i.e. val has a value of 0..2^(bits used for this variable)-1
Returns
the scaled value

Definition at line 164 of file company_manager_face.h.

References _cmf_info, and CompanyManagerFaceBitsInfo::length.

Referenced by ConvertFromOldCompanyManagerFace().

◆ SetCompanyManagerFaceBits()

void SetCompanyManagerFaceBits ( CompanyManagerFace cmf,
CompanyManagerFaceVariable  cmfv,
[[maybe_unused] ] GenderEthnicity  ge,
uint  val 
)
inline

Sets the company manager's face bits for the given company manager's face variable.

Parameters
cmfthe face to write the bits to
cmfvthe face variable to write the data of
gethe gender and ethnicity of the face
valthe new value
Precondition
val < _cmf_info[cmfv].valid_values[ge]

Definition at line 111 of file company_manager_face.h.

References _cmf_info, and SB().

Referenced by ConvertFromOldCompanyManagerFace(), and IncreaseCompanyManagerFaceBits().

Variable Documentation

◆ _cmf_info

const CompanyManagerFaceBitsInfo _cmf_info[]
static
Initial value:
= {
{ 0, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } },
{ 1, 2, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } },
{ 0, 3, { 4, 4, 4, 4 }, { 0, 0, 0, 0 } },
{ 3, 1, { 2, 0, 2, 0 }, { 0, 0, 0, 0 } },
{ 3, 1, { 0, 2, 0, 2 }, { 0, 0, 0, 0 } },
{ 4, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } },
{ 5, 2, { 3, 3, 1, 1 }, { 0, 0, 0, 0 } },
{ 0, 0, { 1, 1, 1, 1 }, { 0x325, 0x326, 0x390, 0x3B0 } },
{ 7, 2, { 4, 1, 2, 2 }, { 0x327, 0x327, 0x391, 0x3B1 } },
{ 9, 4, { 12, 16, 11, 16 }, { 0x32B, 0x337, 0x39A, 0x3B8 } },
{ 13, 2, { 3, 0, 3, 0 }, { 0x367, 0, 0x397, 0 } },
{ 13, 4, { 12, 10, 9, 9 }, { 0x35B, 0x351, 0x3A5, 0x3C8 } },
{ 17, 3, { 8, 4, 4, 5 }, { 0x349, 0x34C, 0x393, 0x3B3 } },
{ 20, 4, { 9, 5, 5, 5 }, { 0x382, 0x38B, 0x3D4, 0x3D9 } },
{ 24, 2, { 3, 3, 3, 3 }, { 0x36B, 0x378, 0x36B, 0x378 } },
{ 26, 2, { 4, 4, 4, 4 }, { 0x36E, 0x37B, 0x36E, 0x37B } },
{ 28, 3, { 6, 3, 6, 3 }, { 0x372, 0x37F, 0x372, 0x3D1 } },
{ 31, 1, { 2, 2, 2, 2 }, { 0x347, 0x347, 0x3AE, 0x3AE } }
}

Lookup table for indices into the CompanyManagerFace, valid ranges and sprites.

Definition at line 64 of file company_manager_face.h.

Referenced by AreCompanyManagerFaceBitsValid(), GetCompanyManagerFaceBits(), GetCompanyManagerFaceSprite(), IncreaseCompanyManagerFaceBits(), SelectCompanyManagerFaceWindow::OnPaint(), ScaleAllCompanyManagerFaceBits(), ScaleCompanyManagerFaceValue(), and SetCompanyManagerFaceBits().