KUDr@6285: /* $Id$ */ KUDr@6285: KUDr@6285: /** @file player_face.h Functionality related to the player's face */ KUDr@6285: KUDr@6285: #ifndef PLAYER_FACE_H KUDr@6285: #define PLAYER_FACE_H KUDr@6285: KUDr@6285: /** The gender/race combinations that we have faces for */ KUDr@6285: enum GenderEthnicity { KUDr@6285: GENDER_FEMALE = 0, ///< This bit set means a female, otherwise male KUDr@6285: ETHNICITY_BLACK = 1, ///< This bit set means black, otherwise white KUDr@6285: KUDr@6285: GE_WM = 0, ///< A male of Caucasian origin (white) KUDr@6285: GE_WF = 1 << GENDER_FEMALE, ///< A female of Caucasian origin (white) KUDr@6285: GE_BM = 1 << ETHNICITY_BLACK, ///< A male of African origin (black) KUDr@6285: GE_BF = 1 << ETHNICITY_BLACK | 1 << GENDER_FEMALE, ///< A female of African origin (black) KUDr@6285: GE_END, KUDr@6285: }; KUDr@6285: DECLARE_ENUM_AS_BIT_SET(GenderEthnicity); ///< See GenderRace as a bitset KUDr@6285: KUDr@6285: /** Bitgroups of the PlayerFace variable */ KUDr@6285: enum PlayerFaceVariable { KUDr@6285: PFV_GENDER, KUDr@6285: PFV_ETHNICITY, KUDr@6285: PFV_GEN_ETHN, KUDr@6285: PFV_HAS_MOUSTACHE, KUDr@6285: PFV_HAS_TIE_EARRING, KUDr@6285: PFV_HAS_GLASSES, KUDr@6285: PFV_EYE_COLOUR, KUDr@6285: PFV_CHEEKS, KUDr@6285: PFV_CHIN, KUDr@6285: PFV_EYEBROWS, KUDr@6285: PFV_MOUSTACHE, KUDr@6285: PFV_LIPS, KUDr@6285: PFV_NOSE, KUDr@6285: PFV_HAIR, KUDr@6285: PFV_JACKET, KUDr@6285: PFV_COLLAR, KUDr@6285: PFV_TIE_EARRING, KUDr@6285: PFV_GLASSES, KUDr@6285: PFV_END KUDr@6285: }; KUDr@6285: DECLARE_POSTFIX_INCREMENT(PlayerFaceVariable); KUDr@6285: KUDr@6285: /** Information about the valid values of PlayerFace bitgroups as well as the sprites to draw */ KUDr@6285: struct PlayerFaceBitsInfo { KUDr@6285: byte offset; ///< Offset in bits into the PlayerFace KUDr@6285: byte length; ///< Number of bits used in the PlayerFace KUDr@6285: byte valid_values[GE_END]; ///< The number of valid values per gender/ethnicity KUDr@6285: SpriteID first_sprite[GE_END]; ///< The first sprite per gender/ethnicity KUDr@6285: }; KUDr@6285: KUDr@6285: /** Lookup table for indices into the PlayerFace, valid ranges and sprites */ KUDr@6285: static const PlayerFaceBitsInfo _pf_info[] = { KUDr@6285: /* Index off len WM WF BM BF WM WF BM BF */ KUDr@6285: /* PFV_GENDER */ { 0, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< 0 = male, 1 = female KUDr@6285: /* PFV_ETHNICITY */ { 1, 2, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< 0 = (Western-)Caucasian, 1 = African(-American)/Black KUDr@6285: /* PFV_GEN_ETHN */ { 0, 3, { 4, 4, 4, 4 }, { 0, 0, 0, 0 } }, ///< Shortcut to get/set gender _and_ ethnicity KUDr@6285: /* PFV_HAS_MOUSTACHE */ { 3, 1, { 2, 0, 2, 0 }, { 0, 0, 0, 0 } }, ///< Females do not have a moustache KUDr@6285: /* 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. KUDr@6285: /* PFV_HAS_GLASSES */ { 4, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< Whether to draw glasses or not KUDr@6285: /* PFV_EYE_COLOUR */ { 5, 2, { 3, 3, 3, 3 }, { 0, 0, 0, 0 } }, ///< Palette modification KUDr@6285: /* PFV_CHEEKS */ { 0, 0, { 1, 1, 1, 1 }, { 0x325, 0x326, 0x390, 0x3B0 } }, ///< Cheeks are only indexed by their gender/ethnicity KUDr@6285: /* PFV_CHIN */ { 7, 2, { 4, 1, 2, 2 }, { 0x327, 0x327, 0x391, 0x3B1 } }, KUDr@6285: /* PFV_EYEBROWS */ { 9, 4, { 12, 16, 11, 16 }, { 0x32B, 0x337, 0x39A, 0x3B8 } }, KUDr@6285: /* PFV_MOUSTACHE */ { 13, 2, { 3, 0, 3, 0 }, { 0x367, 0, 0x397, 0 } }, ///< Depends on PFV_HAS_MOUSTACHE KUDr@6303: /* PFV_LIPS */ { 13, 4, { 12, 10, 9, 9 }, { 0x35B, 0x351, 0x3A5, 0x3C8 } }, ///< Depends on !PFV_HAS_MOUSTACHE KUDr@6285: /* PFV_NOSE */ { 17, 3, { 8, 4, 4, 5 }, { 0x349, 0x34C, 0x393, 0x3B3 } }, ///< Depends on !PFV_HAS_MOUSTACHE KUDr@6285: /* PFV_HAIR */ { 20, 4, { 9, 5, 5, 4 }, { 0x382, 0x38B, 0x3D4, 0x3D9 } }, KUDr@6285: /* PFV_JACKET */ { 24, 2, { 3, 3, 3, 3 }, { 0x36B, 0x378, 0x36B, 0x378 } }, KUDr@6285: /* PFV_COLLAR */ { 26, 2, { 4, 4, 4, 4 }, { 0x36E, 0x37B, 0x36E, 0x37B } }, KUDr@6285: /* PFV_TIE_EARRING */ { 28, 3, { 6, 3, 6, 3 }, { 0x372, 0x37F, 0x372, 0x3D1 } }, ///< Depends on PFV_HAS_TIE_EARRING KUDr@6285: /* PFV_GLASSES */ { 31, 1, { 2, 2, 2, 2 }, { 0x347, 0x347, 0x3AE, 0x3AE } } ///< Depends on PFV_HAS_GLASSES KUDr@6285: }; KUDr@6285: assert_compile(lengthof(_pf_info) == PFV_END); KUDr@6285: KUDr@6285: /** KUDr@6285: * Gets the player's face bits for the given player face variable KUDr@6285: * @param pf the face to extract the bits from KUDr@6285: * @param pfv the face variable to get the data of KUDr@6285: * @param ge the gender and ethnicity of the face KUDr@6285: * @pre _pf_info[pfv].valid_values[ge] != 0 KUDr@6285: * @return the requested bits KUDr@6285: */ KUDr@6285: static inline uint GetPlayerFaceBits(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge) KUDr@6285: { KUDr@6285: assert(_pf_info[pfv].valid_values[ge] != 0); KUDr@6285: KUDr@6285: return GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length); KUDr@6285: } KUDr@6285: KUDr@6285: /** KUDr@6285: * Sets the player's face bits for the given player face variable KUDr@6285: * @param pf the face to write the bits to KUDr@6285: * @param pfv the face variable to write the data of KUDr@6285: * @param ge the gender and ethnicity of the face KUDr@6285: * @param val the new value KUDr@6285: * @pre val < _pf_info[pfv].valid_values[ge] KUDr@6285: */ KUDr@6285: static inline void SetPlayerFaceBits(PlayerFace &pf, PlayerFaceVariable pfv, GenderEthnicity ge, uint val) KUDr@6285: { KUDr@6285: assert(val < _pf_info[pfv].valid_values[ge]); KUDr@6285: KUDr@6285: SB(pf, _pf_info[pfv].offset, _pf_info[pfv].length, val); KUDr@6285: } KUDr@6285: KUDr@6285: /** KUDr@6285: * Checks whether the player bits have a valid range KUDr@6285: * @param pf the face to extract the bits from KUDr@6285: * @param pfv the face variable to get the data of KUDr@6285: * @param ge the gender and ethnicity of the face KUDr@6285: * @return true if and only if the bits are valid KUDr@6285: */ KUDr@6285: static inline bool ArePlayerFaceBitsValid(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge) KUDr@6285: { KUDr@6285: return GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length) < _pf_info[pfv].valid_values[ge]; KUDr@6285: } KUDr@6285: KUDr@6285: /** KUDr@6285: * Scales a player face bits variable to the correct scope KUDr@6285: * @param pfv the face variable to write the data of KUDr@6285: * @param ge the gender and ethnicity of the face KUDr@6285: * @param val the to value to scale KUDr@6285: * @pre val < (1U << _pf_info[pfv].length), i.e. val has a value of 0..2^(bits used for this variable)-1 KUDr@6285: * @return the scaled value KUDr@6285: */ KUDr@6285: static inline uint ScalePlayerFaceValue(PlayerFaceVariable pfv, GenderEthnicity ge, uint val) KUDr@6285: { KUDr@6285: assert(val < (1U << _pf_info[pfv].length)); KUDr@6285: KUDr@6285: return (val * _pf_info[pfv].valid_values[ge]) >> _pf_info[pfv].length; KUDr@6285: } KUDr@6285: KUDr@6285: /** KUDr@6285: * Gets the sprite to draw for the given player face variable KUDr@6285: * @param pf the face to extract the data from KUDr@6285: * @param pfv the face variable to get the sprite of KUDr@6285: * @param ge the gender and ethnicity of the face KUDr@6285: * @pre _pf_info[pfv].valid_values[ge] != 0 KUDr@6285: * @return sprite to draw KUDr@6285: */ KUDr@6285: static inline SpriteID GetPlayerFaceSprite(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge) KUDr@6285: { KUDr@6285: assert(_pf_info[pfv].valid_values[ge] != 0); KUDr@6285: KUDr@6285: return _pf_info[pfv].first_sprite[ge] + GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length); KUDr@6285: } KUDr@6285: KUDr@6285: void DrawPlayerFace(PlayerFace face, int color, int x, int y); KUDr@6285: PlayerFace ConvertFromOldPlayerFace(uint32 face); KUDr@6285: bool IsValidPlayerFace(PlayerFace pf); KUDr@6285: KUDr@6285: #endif /* PLAYER_FACE_H */