#include "core/random_func.hpp"
#include "core/bitmath_func.hpp"
Go to the source code of this file.
Data Structures | |
struct | PlayerFaceBitsInfo |
Information about the valid values of PlayerFace 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... | |
enum | PlayerFaceVariable { PFV_GENDER, PFV_ETHNICITY, PFV_GEN_ETHN, PFV_HAS_MOUSTACHE, PFV_HAS_TIE_EARRING, PFV_HAS_GLASSES, PFV_EYE_COLOUR, PFV_CHEEKS, PFV_CHIN, PFV_EYEBROWS, PFV_MOUSTACHE, PFV_LIPS, PFV_NOSE, PFV_HAIR, PFV_JACKET, PFV_COLLAR, PFV_TIE_EARRING, PFV_GLASSES, PFV_END } |
Bitgroups of the PlayerFace variable. | |
Functions | |
DECLARE_ENUM_AS_BIT_SET (GenderEthnicity) | |
See GenderRace as a bitset. | |
DECLARE_POSTFIX_INCREMENT (PlayerFaceVariable) | |
assert_compile (lengthof(_pf_info)==PFV_END) | |
static uint | GetPlayerFaceBits (PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge) |
Gets the player's face bits for the given player face variable. | |
static void | SetPlayerFaceBits (PlayerFace &pf, PlayerFaceVariable pfv, GenderEthnicity ge, uint val) |
Sets the player's face bits for the given player face variable. | |
static void | IncreasePlayerFaceBits (PlayerFace &pf, PlayerFaceVariable pfv, GenderEthnicity ge, int8 amount) |
Increase/Decrease the player face variable by the given amount. | |
static bool | ArePlayerFaceBitsValid (PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge) |
Checks whether the player bits have a valid range. | |
static uint | ScalePlayerFaceValue (PlayerFaceVariable pfv, GenderEthnicity ge, uint val) |
Scales a player face bits variable to the correct scope. | |
static void | ScaleAllPlayerFaceBits (PlayerFace &pf) |
Scales all player face bits to the correct scope. | |
static void | RandomPlayerFaceBits (PlayerFace &pf, GenderEthnicity ge, bool adv) |
Make a random new face. | |
static SpriteID | GetPlayerFaceSprite (PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge) |
Gets the sprite to draw for the given player face variable. | |
void | DrawPlayerFace (PlayerFace face, int color, int x, int y) |
Draws the face of a player. | |
PlayerFace | ConvertFromOldPlayerFace (uint32 face) |
Converts an old player face format to the new player face format. | |
bool | IsValidPlayerFace (PlayerFace pf) |
Checks whether a player's face is a valid encoding. | |
void | DrawFaceStringLabel (const Window *w, byte widget_index, StringID str, uint8 val, bool is_bool_widget) |
Draw dynamic a label to the left of the button and a value in the button. | |
Variables | |
static const PlayerFaceBitsInfo | _pf_info [] |
Lookup table for indices into the PlayerFace, valid ranges and sprites. |
Definition in file player_face.h.
enum GenderEthnicity |
The gender/race combinations that we have faces for.
Definition at line 12 of file player_face.h.
static bool ArePlayerFaceBitsValid | ( | PlayerFace | pf, | |
PlayerFaceVariable | pfv, | |||
GenderEthnicity | ge | |||
) | [inline, static] |
Checks whether the player bits have a valid range.
pf | the face to extract the bits from | |
pfv | the face variable to get the data of | |
ge | the gender and ethnicity of the face |
Definition at line 143 of file player_face.h.
References GB(), and PlayerFaceBitsInfo::valid_values.
Referenced by IsValidPlayerFace().
PlayerFace ConvertFromOldPlayerFace | ( | uint32 | face | ) |
Converts an old player face format to the new player face format.
Meaning of the bits in the old face (some bits are used in several times):
face | the face in the old format |
Definition at line 109 of file players.cpp.
References ClampU(), ETHNICITY_BLACK, GB(), GE_WF, GE_WM, GENDER_FEMALE, HasBit(), max(), ScalePlayerFaceValue(), SetBit(), and SetPlayerFaceBits().
void DrawFaceStringLabel | ( | const Window * | w, | |
byte | widget_index, | |||
StringID | str, | |||
uint8 | val, | |||
bool | is_bool_widget | |||
) |
Draw dynamic a label to the left of the button and a value in the button.
w | Window on which the widget is located | |
widget_index | index of this widget in the window | |
str | the label which will be draw | |
val | the value which will be draw | |
is_bool_widget | is it a bool button |
Definition at line 681 of file player_gui.cpp.
Referenced by SelectPlayerFaceWndProc().
void DrawPlayerFace | ( | PlayerFace | pf, | |
int | color, | |||
int | x, | |||
int | y | |||
) |
Draws the face of a player.
pf | the player's face | |
color | the (background) color of the gradient | |
x | x-position to draw the face | |
y | y-position to draw the face |
Definition at line 512 of file player_gui.cpp.
References _pf_info, GE_WM, GENDER_FEMALE, GetPlayerFaceBits(), GetPlayerFaceSprite(), and HasBit().
Referenced by PlayerCompanyWndProc(), and SelectPlayerFaceWndProc().
static uint GetPlayerFaceBits | ( | PlayerFace | pf, | |
PlayerFaceVariable | pfv, | |||
GenderEthnicity | ge | |||
) | [inline, static] |
Gets the player's face bits for the given player face variable.
pf | the face to extract the bits from | |
pfv | the face variable to get the data of | |
ge | the gender and ethnicity of the face |
Definition at line 88 of file player_face.h.
References GB().
Referenced by DrawPlayerFace(), IncreasePlayerFaceBits(), IsValidPlayerFace(), ScaleAllPlayerFaceBits(), and SelectPlayerFaceWndProc().
static SpriteID GetPlayerFaceSprite | ( | PlayerFace | pf, | |
PlayerFaceVariable | pfv, | |||
GenderEthnicity | ge | |||
) | [inline, static] |
Gets the sprite to draw for the given player face variable.
pf | the face to extract the data from | |
pfv | the face variable to get the sprite of | |
ge | the gender and ethnicity of the face |
Definition at line 223 of file player_face.h.
References PlayerFaceBitsInfo::first_sprite, and GB().
Referenced by DrawPlayerFace().
static void IncreasePlayerFaceBits | ( | PlayerFace & | pf, | |
PlayerFaceVariable | pfv, | |||
GenderEthnicity | ge, | |||
int8 | amount | |||
) | [inline, static] |
Increase/Decrease the player 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 negativ (< 0) it will be set to max value.
pf | the player face to write the bits to | |
pfv | the player face variable to write the data of | |
ge | the gender and ethnicity of the player face | |
amount | the amount which change the value |
Definition at line 122 of file player_face.h.
References GetPlayerFaceBits(), SetPlayerFaceBits(), and PlayerFaceBitsInfo::valid_values.
Referenced by ScaleAllPlayerFaceBits(), and SelectPlayerFaceWndProc().
bool IsValidPlayerFace | ( | PlayerFace | pf | ) |
Checks whether a player's face is a valid encoding.
Unused bits are not enforced to be 0.
pf | the fact to check |
Definition at line 165 of file players.cpp.
References ArePlayerFaceBitsValid(), GE_WM, GENDER_FEMALE, GetPlayerFaceBits(), and HasBit().
Referenced by CmdSetPlayerFace().
static void RandomPlayerFaceBits | ( | PlayerFace & | pf, | |
GenderEthnicity | ge, | |||
bool | adv | |||
) | [inline, static] |
Make a random new face.
If it is for the advanced player 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.
pf | the player face to write the bits to | |
ge | the gender and ethnicity of the old player face | |
adv | if it for the advanced player face window |
Definition at line 197 of file player_face.h.
References GENDER_FEMALE, HasBit(), ScaleAllPlayerFaceBits(), and SetPlayerFaceBits().
Referenced by DoStartupNewPlayer(), and SelectPlayerFaceWndProc().
static void ScaleAllPlayerFaceBits | ( | PlayerFace & | pf | ) | [inline, static] |
Scales all player face bits to the correct scope.
pf | the player face to write the bits to |
Definition at line 168 of file player_face.h.
References GB(), GE_WM, GENDER_FEMALE, GetPlayerFaceBits(), HasBit(), and IncreasePlayerFaceBits().
Referenced by RandomPlayerFaceBits(), and SelectPlayerFaceWndProc().
static uint ScalePlayerFaceValue | ( | PlayerFaceVariable | pfv, | |
GenderEthnicity | ge, | |||
uint | val | |||
) | [inline, static] |
Scales a player face bits variable to the correct scope.
pfv | the face variable to write the data of | |
ge | the gender and ethnicity of the face | |
val | the to value to scale |
Definition at line 156 of file player_face.h.
References PlayerFaceBitsInfo::length.
Referenced by ConvertFromOldPlayerFace().
static void SetPlayerFaceBits | ( | PlayerFace & | pf, | |
PlayerFaceVariable | pfv, | |||
GenderEthnicity | ge, | |||
uint | val | |||
) | [inline, static] |
Sets the player's face bits for the given player face variable.
pf | the face to write the bits to | |
pfv | the face variable to write the data of | |
ge | the gender and ethnicity of the face | |
val | the new value |
Definition at line 103 of file player_face.h.
References SB().
Referenced by ConvertFromOldPlayerFace(), IncreasePlayerFaceBits(), RandomPlayerFaceBits(), and SelectPlayerFaceWndProc().
const PlayerFaceBitsInfo _pf_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, 4 }, { 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 } } }
Definition at line 57 of file player_face.h.
Referenced by DrawPlayerFace(), and SelectPlayerFaceWndProc().