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