src/player_face.h
author truebrain
Fri, 18 Jul 2008 10:15:16 +0000
branchnoai
changeset 11168 3842648184cd
parent 10645 8cbdb511a674
permissions -rw-r--r--
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
6516
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
     1
/* $Id$ */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
     2
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
     3
/** @file player_face.h Functionality related to the player's face */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
     4
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
     5
#ifndef PLAYER_FACE_H
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
     6
#define PLAYER_FACE_H
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
     7
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
     8
#include "core/random_func.hpp"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
     9
#include "core/bitmath_func.hpp"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    10
6516
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    11
/** The gender/race combinations that we have faces for */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    12
enum GenderEthnicity {
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    13
	GENDER_FEMALE    = 0, ///< This bit set means a female, otherwise male
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    14
	ETHNICITY_BLACK  = 1, ///< This bit set means black, otherwise white
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    15
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    16
	GE_WM = 0,                                         ///< A male of Caucasian origin (white)
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    17
	GE_WF = 1 << GENDER_FEMALE,                        ///< A female of Caucasian origin (white)
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    18
	GE_BM = 1 << ETHNICITY_BLACK,                      ///< A male of African origin (black)
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    19
	GE_BF = 1 << ETHNICITY_BLACK | 1 << GENDER_FEMALE, ///< A female of African origin (black)
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    20
	GE_END,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    21
};
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    22
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity); ///< See GenderRace as a bitset
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    23
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    24
/** Bitgroups of the PlayerFace variable */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    25
enum PlayerFaceVariable {
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    26
	PFV_GENDER,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    27
	PFV_ETHNICITY,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    28
	PFV_GEN_ETHN,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    29
	PFV_HAS_MOUSTACHE,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    30
	PFV_HAS_TIE_EARRING,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    31
	PFV_HAS_GLASSES,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    32
	PFV_EYE_COLOUR,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    33
	PFV_CHEEKS,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    34
	PFV_CHIN,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    35
	PFV_EYEBROWS,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    36
	PFV_MOUSTACHE,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    37
	PFV_LIPS,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    38
	PFV_NOSE,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    39
	PFV_HAIR,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    40
	PFV_JACKET,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    41
	PFV_COLLAR,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    42
	PFV_TIE_EARRING,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    43
	PFV_GLASSES,
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    44
	PFV_END
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    45
};
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    46
DECLARE_POSTFIX_INCREMENT(PlayerFaceVariable);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    47
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    48
/** Information about the valid values of PlayerFace bitgroups as well as the sprites to draw */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    49
struct PlayerFaceBitsInfo {
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    50
	byte     offset;               ///< Offset in bits into the PlayerFace
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    51
	byte     length;               ///< Number of bits used in the PlayerFace
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    52
	byte     valid_values[GE_END]; ///< The number of valid values per gender/ethnicity
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    53
	SpriteID first_sprite[GE_END]; ///< The first sprite per gender/ethnicity
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    54
};
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    55
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    56
/** Lookup table for indices into the PlayerFace, valid ranges and sprites */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    57
static const PlayerFaceBitsInfo _pf_info[] = {
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    58
	/* Index                   off len   WM  WF  BM  BF         WM     WF     BM     BF */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    59
	/* PFV_GENDER          */ {  0, 1, {  2,  2,  2,  2 }, {     0,     0,     0,     0 } }, ///< 0 = male, 1 = female
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    60
	/* PFV_ETHNICITY       */ {  1, 2, {  2,  2,  2,  2 }, {     0,     0,     0,     0 } }, ///< 0 = (Western-)Caucasian, 1 = African(-American)/Black
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    61
	/* PFV_GEN_ETHN        */ {  0, 3, {  4,  4,  4,  4 }, {     0,     0,     0,     0 } }, ///< Shortcut to get/set gender _and_ ethnicity
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    62
	/* PFV_HAS_MOUSTACHE   */ {  3, 1, {  2,  0,  2,  0 }, {     0,     0,     0,     0 } }, ///< Females do not have a moustache
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    63
	/* PFV_HAS_TIE_EARRING */ {  3, 1, {  0,  2,  0,  2 }, {     0,     0,     0,     0 } }, ///< Draw the earring for females or not. For males the tie is always drawn.
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    64
	/* PFV_HAS_GLASSES     */ {  4, 1, {  2,  2,  2,  2 }, {     0,     0,     0,     0 } }, ///< Whether to draw glasses or not
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
    65
	/* PFV_EYE_COLOUR      */ {  5, 2, {  3,  3,  1,  1 }, {     0,     0,     0,     0 } }, ///< Palette modification
6516
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    66
	/* PFV_CHEEKS          */ {  0, 0, {  1,  1,  1,  1 }, { 0x325, 0x326, 0x390, 0x3B0 } }, ///< Cheeks are only indexed by their gender/ethnicity
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    67
	/* PFV_CHIN            */ {  7, 2, {  4,  1,  2,  2 }, { 0x327, 0x327, 0x391, 0x3B1 } },
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    68
	/* PFV_EYEBROWS        */ {  9, 4, { 12, 16, 11, 16 }, { 0x32B, 0x337, 0x39A, 0x3B8 } },
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    69
	/* PFV_MOUSTACHE       */ { 13, 2, {  3,  0,  3,  0 }, { 0x367,     0, 0x397,     0 } }, ///< Depends on PFV_HAS_MOUSTACHE
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 6516
diff changeset
    70
	/* PFV_LIPS            */ { 13, 4, { 12, 10,  9,  9 }, { 0x35B, 0x351, 0x3A5, 0x3C8 } }, ///< Depends on !PFV_HAS_MOUSTACHE
6516
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    71
	/* PFV_NOSE            */ { 17, 3, {  8,  4,  4,  5 }, { 0x349, 0x34C, 0x393, 0x3B3 } }, ///< Depends on !PFV_HAS_MOUSTACHE
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    72
	/* PFV_HAIR            */ { 20, 4, {  9,  5,  5,  4 }, { 0x382, 0x38B, 0x3D4, 0x3D9 } },
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    73
	/* PFV_JACKET          */ { 24, 2, {  3,  3,  3,  3 }, { 0x36B, 0x378, 0x36B, 0x378 } },
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    74
	/* PFV_COLLAR          */ { 26, 2, {  4,  4,  4,  4 }, { 0x36E, 0x37B, 0x36E, 0x37B } },
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    75
	/* PFV_TIE_EARRING     */ { 28, 3, {  6,  3,  6,  3 }, { 0x372, 0x37F, 0x372, 0x3D1 } }, ///< Depends on PFV_HAS_TIE_EARRING
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    76
	/* PFV_GLASSES         */ { 31, 1, {  2,  2,  2,  2 }, { 0x347, 0x347, 0x3AE, 0x3AE } }  ///< Depends on PFV_HAS_GLASSES
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    77
};
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    78
assert_compile(lengthof(_pf_info) == PFV_END);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    79
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    80
/**
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    81
 * Gets the player's face bits for the given player face variable
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    82
 * @param pf  the face to extract the bits from
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    83
 * @param pfv the face variable to get the data of
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    84
 * @param ge  the gender and ethnicity of the face
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    85
 * @pre _pf_info[pfv].valid_values[ge] != 0
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    86
 * @return the requested bits
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    87
 */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    88
static inline uint GetPlayerFaceBits(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge)
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    89
{
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    90
	assert(_pf_info[pfv].valid_values[ge] != 0);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    91
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    92
	return GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    93
}
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    94
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    95
/**
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    96
 * Sets the player's face bits for the given player face variable
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    97
 * @param pf  the face to write the bits to
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    98
 * @param pfv the face variable to write the data of
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
    99
 * @param ge  the gender and ethnicity of the face
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   100
 * @param val the new value
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   101
 * @pre val < _pf_info[pfv].valid_values[ge]
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   102
 */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   103
static inline void SetPlayerFaceBits(PlayerFace &pf, PlayerFaceVariable pfv, GenderEthnicity ge, uint val)
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   104
{
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   105
	assert(val < _pf_info[pfv].valid_values[ge]);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   106
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   107
	SB(pf, _pf_info[pfv].offset, _pf_info[pfv].length, val);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   108
}
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   109
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   110
/**
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   111
 * Increase/Decrease the player face variable by the given amount.
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   112
 * If the new value greater than the max value for this variable it will be set to 0.
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   113
 * Or is it negativ (< 0) it will be set to max value.
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   114
 *
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   115
 * @param pf     the player face to write the bits to
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   116
 * @param pfv    the player face variable to write the data of
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   117
 * @param ge     the gender and ethnicity of the player face
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   118
 * @param amount the amount which change the value
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   119
 *
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   120
 * @pre 0 <= val < _pf_info[pfv].valid_values[ge]
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   121
 */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   122
static inline void IncreasePlayerFaceBits(PlayerFace &pf, PlayerFaceVariable pfv, GenderEthnicity ge, int8 amount)
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   123
{
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   124
	int8 val = GetPlayerFaceBits(pf, pfv, ge) + amount; // the new value for the pfv
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   125
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   126
	/* scales the new value to the correct scope */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   127
	if (val >= _pf_info[pfv].valid_values[ge]) {
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   128
		val = 0;
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   129
	} else if (val < 0) {
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   130
		val = _pf_info[pfv].valid_values[ge] - 1;
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   131
	}
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   132
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   133
	SetPlayerFaceBits(pf, pfv, ge, val); // save the new value
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   134
}
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   135
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   136
/**
6516
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   137
 * Checks whether the player bits have a valid range
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   138
 * @param pf  the face to extract the bits from
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   139
 * @param pfv the face variable to get the data of
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   140
 * @param ge  the gender and ethnicity of the face
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   141
 * @return true if and only if the bits are valid
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   142
 */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   143
static inline bool ArePlayerFaceBitsValid(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge)
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   144
{
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   145
	return GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length) < _pf_info[pfv].valid_values[ge];
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   146
}
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   147
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   148
/**
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   149
 * Scales a player face bits variable to the correct scope
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   150
 * @param pfv the face variable to write the data of
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   151
 * @param ge  the gender and ethnicity of the face
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   152
 * @param val the to value to scale
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   153
 * @pre val < (1U << _pf_info[pfv].length), i.e. val has a value of 0..2^(bits used for this variable)-1
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   154
 * @return the scaled value
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   155
 */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   156
static inline uint ScalePlayerFaceValue(PlayerFaceVariable pfv, GenderEthnicity ge, uint val)
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   157
{
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   158
	assert(val < (1U << _pf_info[pfv].length));
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   159
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   160
	return (val * _pf_info[pfv].valid_values[ge]) >> _pf_info[pfv].length;
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   161
}
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   162
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   163
/**
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   164
 * Scales all player face bits to the correct scope
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   165
 *
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   166
 * @param pf the player face to write the bits to
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   167
 */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   168
static inline void ScaleAllPlayerFaceBits(PlayerFace &pf)
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   169
{
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   170
	IncreasePlayerFaceBits(pf, PFV_ETHNICITY, GE_WM, 0); // scales the ethnicity
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   171
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   172
	GenderEthnicity ge = (GenderEthnicity)GB(pf, _pf_info[PFV_GEN_ETHN].offset, _pf_info[PFV_GEN_ETHN].length); // gender & ethnicity of the face
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   173
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   174
	/* Is a male face with moustache. Need to reduce CPU load in the loop. */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   175
	bool is_moust_male = !HasBit(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge) != 0;
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   176
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   177
	for (PlayerFaceVariable pfv = PFV_EYE_COLOUR; pfv < PFV_END; pfv++) { // scales all other variables
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   178
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   179
		/* The moustache variable will be scaled only if it is a male face with has a moustache */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   180
		if (pfv != PFV_MOUSTACHE || is_moust_male) {
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   181
			IncreasePlayerFaceBits(pf, pfv, ge, 0);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   182
		}
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   183
	}
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   184
}
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   185
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   186
/**
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   187
 * Make a random new face.
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   188
 * If it is for the advanced player face window then the new face have the same gender
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   189
 * and ethnicity as the old one, else the gender is equal and the ethnicity is random.
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   190
 *
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   191
 * @param pf  the player face to write the bits to
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   192
 * @param ge  the gender and ethnicity of the old player face
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   193
 * @param adv if it for the advanced player face window
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   194
 *
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   195
 * @pre scale 'ge' to a valid gender/ethnicity combination
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   196
 */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   197
static inline void RandomPlayerFaceBits(PlayerFace &pf, GenderEthnicity ge, bool adv)
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   198
{
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   199
	pf = InteractiveRandom(); // random all player face bits
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   200
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   201
	/* scale ge: 0 == GE_WM, 1 == GE_WF, 2 == GE_BM, 3 == GE_BF (and maybe in future: ...) */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   202
	ge = (GenderEthnicity)((uint)ge % GE_END);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   203
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   204
	/* set the gender (and ethnicity) for the new player face */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   205
	if (adv) {
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   206
		SetPlayerFaceBits(pf, PFV_GEN_ETHN, ge, ge);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   207
	} else {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   208
		SetPlayerFaceBits(pf, PFV_GENDER, ge, HasBit(ge, GENDER_FEMALE));
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   209
	}
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   210
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   211
	/* scales all player face bits to the correct scope */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   212
	ScaleAllPlayerFaceBits(pf);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   213
}
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   214
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9505
diff changeset
   215
/**
6516
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   216
 * Gets the sprite to draw for the given player face variable
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   217
 * @param pf  the face to extract the data from
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   218
 * @param pfv the face variable to get the sprite of
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   219
 * @param ge  the gender and ethnicity of the face
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   220
 * @pre _pf_info[pfv].valid_values[ge] != 0
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   221
 * @return sprite to draw
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   222
 */
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   223
static inline SpriteID GetPlayerFaceSprite(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge)
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   224
{
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   225
	assert(_pf_info[pfv].valid_values[ge] != 0);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   226
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   227
	return _pf_info[pfv].first_sprite[ge] + GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   228
}
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   229
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   230
void DrawPlayerFace(PlayerFace face, int color, int x, int y);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   231
PlayerFace ConvertFromOldPlayerFace(uint32 face);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   232
bool IsValidPlayerFace(PlayerFace pf);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   233
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
diff changeset
   234
#endif /* PLAYER_FACE_H */