|
1 /* $Id$ */ |
|
2 |
|
3 /** @file player_face.h Functionality related to the player's face */ |
|
4 |
|
5 #ifndef PLAYER_FACE_H |
|
6 #define PLAYER_FACE_H |
|
7 |
|
8 /** The gender/race combinations that we have faces for */ |
|
9 enum GenderEthnicity { |
|
10 GENDER_FEMALE = 0, ///< This bit set means a female, otherwise male |
|
11 ETHNICITY_BLACK = 1, ///< This bit set means black, otherwise white |
|
12 |
|
13 GE_WM = 0, ///< A male of Caucasian origin (white) |
|
14 GE_WF = 1 << GENDER_FEMALE, ///< A female of Caucasian origin (white) |
|
15 GE_BM = 1 << ETHNICITY_BLACK, ///< A male of African origin (black) |
|
16 GE_BF = 1 << ETHNICITY_BLACK | 1 << GENDER_FEMALE, ///< A female of African origin (black) |
|
17 GE_END, |
|
18 }; |
|
19 DECLARE_ENUM_AS_BIT_SET(GenderEthnicity); ///< See GenderRace as a bitset |
|
20 |
|
21 /** Bitgroups of the PlayerFace variable */ |
|
22 enum PlayerFaceVariable { |
|
23 PFV_GENDER, |
|
24 PFV_ETHNICITY, |
|
25 PFV_GEN_ETHN, |
|
26 PFV_HAS_MOUSTACHE, |
|
27 PFV_HAS_TIE_EARRING, |
|
28 PFV_HAS_GLASSES, |
|
29 PFV_EYE_COLOUR, |
|
30 PFV_CHEEKS, |
|
31 PFV_CHIN, |
|
32 PFV_EYEBROWS, |
|
33 PFV_MOUSTACHE, |
|
34 PFV_LIPS, |
|
35 PFV_NOSE, |
|
36 PFV_HAIR, |
|
37 PFV_JACKET, |
|
38 PFV_COLLAR, |
|
39 PFV_TIE_EARRING, |
|
40 PFV_GLASSES, |
|
41 PFV_END |
|
42 }; |
|
43 DECLARE_POSTFIX_INCREMENT(PlayerFaceVariable); |
|
44 |
|
45 /** Information about the valid values of PlayerFace bitgroups as well as the sprites to draw */ |
|
46 struct PlayerFaceBitsInfo { |
|
47 byte offset; ///< Offset in bits into the PlayerFace |
|
48 byte length; ///< Number of bits used in the PlayerFace |
|
49 byte valid_values[GE_END]; ///< The number of valid values per gender/ethnicity |
|
50 SpriteID first_sprite[GE_END]; ///< The first sprite per gender/ethnicity |
|
51 }; |
|
52 |
|
53 /** Lookup table for indices into the PlayerFace, valid ranges and sprites */ |
|
54 static const PlayerFaceBitsInfo _pf_info[] = { |
|
55 /* Index off len WM WF BM BF WM WF BM BF */ |
|
56 /* PFV_GENDER */ { 0, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< 0 = male, 1 = female |
|
57 /* PFV_ETHNICITY */ { 1, 2, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< 0 = (Western-)Caucasian, 1 = African(-American)/Black |
|
58 /* PFV_GEN_ETHN */ { 0, 3, { 4, 4, 4, 4 }, { 0, 0, 0, 0 } }, ///< Shortcut to get/set gender _and_ ethnicity |
|
59 /* PFV_HAS_MOUSTACHE */ { 3, 1, { 2, 0, 2, 0 }, { 0, 0, 0, 0 } }, ///< Females do not have a moustache |
|
60 /* 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. |
|
61 /* PFV_HAS_GLASSES */ { 4, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< Whether to draw glasses or not |
|
62 /* PFV_EYE_COLOUR */ { 5, 2, { 3, 3, 3, 3 }, { 0, 0, 0, 0 } }, ///< Palette modification |
|
63 /* PFV_CHEEKS */ { 0, 0, { 1, 1, 1, 1 }, { 0x325, 0x326, 0x390, 0x3B0 } }, ///< Cheeks are only indexed by their gender/ethnicity |
|
64 /* PFV_CHIN */ { 7, 2, { 4, 1, 2, 2 }, { 0x327, 0x327, 0x391, 0x3B1 } }, |
|
65 /* PFV_EYEBROWS */ { 9, 4, { 12, 16, 11, 16 }, { 0x32B, 0x337, 0x39A, 0x3B8 } }, |
|
66 /* PFV_MOUSTACHE */ { 13, 2, { 3, 0, 3, 0 }, { 0x367, 0, 0x397, 0 } }, ///< Depends on PFV_HAS_MOUSTACHE |
|
67 /* PFV_LIPS */ { 13, 4, { 13, 10, 9, 9 }, { 0x35B, 0x351, 0x3A5, 0x3C8 } }, ///< Depends on !PFV_HAS_MOUSTACHE |
|
68 /* PFV_NOSE */ { 17, 3, { 8, 4, 4, 5 }, { 0x349, 0x34C, 0x393, 0x3B3 } }, ///< Depends on !PFV_HAS_MOUSTACHE |
|
69 /* PFV_HAIR */ { 20, 4, { 9, 5, 5, 4 }, { 0x382, 0x38B, 0x3D4, 0x3D9 } }, |
|
70 /* PFV_JACKET */ { 24, 2, { 3, 3, 3, 3 }, { 0x36B, 0x378, 0x36B, 0x378 } }, |
|
71 /* PFV_COLLAR */ { 26, 2, { 4, 4, 4, 4 }, { 0x36E, 0x37B, 0x36E, 0x37B } }, |
|
72 /* PFV_TIE_EARRING */ { 28, 3, { 6, 3, 6, 3 }, { 0x372, 0x37F, 0x372, 0x3D1 } }, ///< Depends on PFV_HAS_TIE_EARRING |
|
73 /* PFV_GLASSES */ { 31, 1, { 2, 2, 2, 2 }, { 0x347, 0x347, 0x3AE, 0x3AE } } ///< Depends on PFV_HAS_GLASSES |
|
74 }; |
|
75 assert_compile(lengthof(_pf_info) == PFV_END); |
|
76 |
|
77 /** |
|
78 * Gets the player's face bits for the given player face variable |
|
79 * @param pf the face to extract the bits from |
|
80 * @param pfv the face variable to get the data of |
|
81 * @param ge the gender and ethnicity of the face |
|
82 * @pre _pf_info[pfv].valid_values[ge] != 0 |
|
83 * @return the requested bits |
|
84 */ |
|
85 static inline uint GetPlayerFaceBits(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge) |
|
86 { |
|
87 assert(_pf_info[pfv].valid_values[ge] != 0); |
|
88 |
|
89 return GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length); |
|
90 } |
|
91 |
|
92 /** |
|
93 * Sets the player's face bits for the given player face variable |
|
94 * @param pf the face to write the bits to |
|
95 * @param pfv the face variable to write the data of |
|
96 * @param ge the gender and ethnicity of the face |
|
97 * @param val the new value |
|
98 * @pre val < _pf_info[pfv].valid_values[ge] |
|
99 */ |
|
100 static inline void SetPlayerFaceBits(PlayerFace &pf, PlayerFaceVariable pfv, GenderEthnicity ge, uint val) |
|
101 { |
|
102 assert(val < _pf_info[pfv].valid_values[ge]); |
|
103 |
|
104 SB(pf, _pf_info[pfv].offset, _pf_info[pfv].length, val); |
|
105 } |
|
106 |
|
107 /** |
|
108 * Checks whether the player bits have a valid range |
|
109 * @param pf the face to extract the bits from |
|
110 * @param pfv the face variable to get the data of |
|
111 * @param ge the gender and ethnicity of the face |
|
112 * @return true if and only if the bits are valid |
|
113 */ |
|
114 static inline bool ArePlayerFaceBitsValid(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge) |
|
115 { |
|
116 return GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length) < _pf_info[pfv].valid_values[ge]; |
|
117 } |
|
118 |
|
119 /** |
|
120 * Scales a player face bits variable to the correct scope |
|
121 * @param pfv the face variable to write the data of |
|
122 * @param ge the gender and ethnicity of the face |
|
123 * @param val the to value to scale |
|
124 * @pre val < (1U << _pf_info[pfv].length), i.e. val has a value of 0..2^(bits used for this variable)-1 |
|
125 * @return the scaled value |
|
126 */ |
|
127 static inline uint ScalePlayerFaceValue(PlayerFaceVariable pfv, GenderEthnicity ge, uint val) |
|
128 { |
|
129 assert(val < (1U << _pf_info[pfv].length)); |
|
130 |
|
131 return (val * _pf_info[pfv].valid_values[ge]) >> _pf_info[pfv].length; |
|
132 } |
|
133 |
|
134 /** |
|
135 * Gets the sprite to draw for the given player face variable |
|
136 * @param pf the face to extract the data from |
|
137 * @param pfv the face variable to get the sprite of |
|
138 * @param ge the gender and ethnicity of the face |
|
139 * @pre _pf_info[pfv].valid_values[ge] != 0 |
|
140 * @return sprite to draw |
|
141 */ |
|
142 static inline SpriteID GetPlayerFaceSprite(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge) |
|
143 { |
|
144 assert(_pf_info[pfv].valid_values[ge] != 0); |
|
145 |
|
146 return _pf_info[pfv].first_sprite[ge] + GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length); |
|
147 } |
|
148 |
|
149 void DrawPlayerFace(PlayerFace face, int color, int x, int y); |
|
150 PlayerFace ConvertFromOldPlayerFace(uint32 face); |
|
151 bool IsValidPlayerFace(PlayerFace pf); |
|
152 |
|
153 #endif /* PLAYER_FACE_H */ |