Mercurial > hg > openttd
comparison src/player_face.h @ 7734:0352f37d7696 draft
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 15 Oct 2007 19:59:27 +0000 |
parents | bc64c4b38dc3 |
children | ebb1669ac65d |
comparison
equal
deleted
inserted
replaced
7733:d498b80af241 | 7734:0352f37d7696 |
---|---|
57 /* PFV_ETHNICITY */ { 1, 2, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< 0 = (Western-)Caucasian, 1 = African(-American)/Black | 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 | 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 | 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. | 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 | 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 | 62 /* PFV_EYE_COLOUR */ { 5, 2, { 3, 3, 1, 1 }, { 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 | 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 } }, | 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 } }, | 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 | 66 /* PFV_MOUSTACHE */ { 13, 2, { 3, 0, 3, 0 }, { 0x367, 0, 0x397, 0 } }, ///< Depends on PFV_HAS_MOUSTACHE |
67 /* PFV_LIPS */ { 13, 4, { 12, 10, 9, 9 }, { 0x35B, 0x351, 0x3A5, 0x3C8 } }, ///< Depends on !PFV_HAS_MOUSTACHE | 67 /* PFV_LIPS */ { 13, 4, { 12, 10, 9, 9 }, { 0x35B, 0x351, 0x3A5, 0x3C8 } }, ///< Depends on !PFV_HAS_MOUSTACHE |
103 | 103 |
104 SB(pf, _pf_info[pfv].offset, _pf_info[pfv].length, val); | 104 SB(pf, _pf_info[pfv].offset, _pf_info[pfv].length, val); |
105 } | 105 } |
106 | 106 |
107 /** | 107 /** |
108 * Increase/Decrease the player face variable by the given amount. | |
109 * If the new value greater than the max value for this variable it will be set to 0. | |
110 * Or is it negativ (< 0) it will be set to max value. | |
111 * | |
112 * @param pf the player face to write the bits to | |
113 * @param pfv the player face variable to write the data of | |
114 * @param ge the gender and ethnicity of the player face | |
115 * @param amount the amount which change the value | |
116 * | |
117 * @pre 0 <= val < _pf_info[pfv].valid_values[ge] | |
118 */ | |
119 static inline void IncreasePlayerFaceBits(PlayerFace &pf, PlayerFaceVariable pfv, GenderEthnicity ge, int8 amount) | |
120 { | |
121 int8 val = GetPlayerFaceBits(pf, pfv, ge) + amount; // the new value for the pfv | |
122 | |
123 /* scales the new value to the correct scope */ | |
124 if (val >= _pf_info[pfv].valid_values[ge]) { | |
125 val = 0; | |
126 } else if (val < 0) { | |
127 val = _pf_info[pfv].valid_values[ge] - 1; | |
128 } | |
129 | |
130 SetPlayerFaceBits(pf, pfv, ge, val); // save the new value | |
131 } | |
132 | |
133 /** | |
108 * Checks whether the player bits have a valid range | 134 * Checks whether the player bits have a valid range |
109 * @param pf the face to extract the bits from | 135 * @param pf the face to extract the bits from |
110 * @param pfv the face variable to get the data of | 136 * @param pfv the face variable to get the data of |
111 * @param ge the gender and ethnicity of the face | 137 * @param ge the gender and ethnicity of the face |
112 * @return true if and only if the bits are valid | 138 * @return true if and only if the bits are valid |
130 | 156 |
131 return (val * _pf_info[pfv].valid_values[ge]) >> _pf_info[pfv].length; | 157 return (val * _pf_info[pfv].valid_values[ge]) >> _pf_info[pfv].length; |
132 } | 158 } |
133 | 159 |
134 /** | 160 /** |
161 * Scales all player face bits to the correct scope | |
162 * | |
163 * @param pf the player face to write the bits to | |
164 */ | |
165 static inline void ScaleAllPlayerFaceBits(PlayerFace &pf) | |
166 { | |
167 IncreasePlayerFaceBits(pf, PFV_ETHNICITY, GE_WM, 0); // scales the ethnicity | |
168 | |
169 GenderEthnicity ge = (GenderEthnicity)GB(pf, _pf_info[PFV_GEN_ETHN].offset, _pf_info[PFV_GEN_ETHN].length); // gender & ethnicity of the face | |
170 | |
171 /* Is a male face with moustache. Need to reduce CPU load in the loop. */ | |
172 bool is_moust_male = !HASBIT(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge) != 0; | |
173 | |
174 for (PlayerFaceVariable pfv = PFV_EYE_COLOUR; pfv < PFV_END; pfv++) { // scales all other variables | |
175 | |
176 /* The moustache variable will be scaled only if it is a male face with has a moustache */ | |
177 if (pfv != PFV_MOUSTACHE || is_moust_male) { | |
178 IncreasePlayerFaceBits(pf, pfv, ge, 0); | |
179 } | |
180 } | |
181 } | |
182 | |
183 /** | |
184 * Make a random new face. | |
185 * If it is for the advanced player face window then the new face have the same gender | |
186 * and ethnicity as the old one, else the gender is equal and the ethnicity is random. | |
187 * | |
188 * @param pf the player face to write the bits to | |
189 * @param ge the gender and ethnicity of the old player face | |
190 * @param adv if it for the advanced player face window | |
191 * | |
192 * @pre scale 'ge' to a valid gender/ethnicity combination | |
193 */ | |
194 static inline void RandomPlayerFaceBits(PlayerFace &pf, GenderEthnicity ge, bool adv) | |
195 { | |
196 pf = Random(); // random all player face bits | |
197 | |
198 /* scale ge: 0 == GE_WM, 1 == GE_WF, 2 == GE_BM, 3 == GE_BF (and maybe in future: ...) */ | |
199 ge = (GenderEthnicity)(ge % GE_END); | |
200 | |
201 /* set the gender (and ethnicity) for the new player face */ | |
202 if (adv) { | |
203 SetPlayerFaceBits(pf, PFV_GEN_ETHN, ge, ge); | |
204 } else { | |
205 SetPlayerFaceBits(pf, PFV_GENDER, ge, HASBIT(ge, GENDER_FEMALE)); | |
206 } | |
207 | |
208 /* scales all player face bits to the correct scope */ | |
209 ScaleAllPlayerFaceBits(pf); | |
210 } | |
211 | |
212 /** | |
135 * Gets the sprite to draw for the given player face variable | 213 * Gets the sprite to draw for the given player face variable |
136 * @param pf the face to extract the data from | 214 * @param pf the face to extract the data from |
137 * @param pfv the face variable to get the sprite of | 215 * @param pfv the face variable to get the sprite of |
138 * @param ge the gender and ethnicity of the face | 216 * @param ge the gender and ethnicity of the face |
139 * @pre _pf_info[pfv].valid_values[ge] != 0 | 217 * @pre _pf_info[pfv].valid_values[ge] != 0 |
147 } | 225 } |
148 | 226 |
149 void DrawPlayerFace(PlayerFace face, int color, int x, int y); | 227 void DrawPlayerFace(PlayerFace face, int color, int x, int y); |
150 PlayerFace ConvertFromOldPlayerFace(uint32 face); | 228 PlayerFace ConvertFromOldPlayerFace(uint32 face); |
151 bool IsValidPlayerFace(PlayerFace pf); | 229 bool IsValidPlayerFace(PlayerFace pf); |
230 void DrawFaceStringLabel(const Window *w, byte widget_index, StringID str, uint8 val, bool is_bool_widget); | |
152 | 231 |
153 #endif /* PLAYER_FACE_H */ | 232 #endif /* PLAYER_FACE_H */ |