00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef COMPANY_MANAGER_FACE_H
00013 #define COMPANY_MANAGER_FACE_H
00014
00015 #include "core/random_func.hpp"
00016 #include "core/bitmath_func.hpp"
00017 #include "table/sprites.h"
00018 #include "company_type.h"
00019
00021 enum GenderEthnicity {
00022 GENDER_FEMALE = 0,
00023 ETHNICITY_BLACK = 1,
00024
00025 GE_WM = 0,
00026 GE_WF = 1 << GENDER_FEMALE,
00027 GE_BM = 1 << ETHNICITY_BLACK,
00028 GE_BF = 1 << ETHNICITY_BLACK | 1 << GENDER_FEMALE,
00029 GE_END,
00030 };
00031 DECLARE_ENUM_AS_BIT_SET(GenderEthnicity);
00032
00034 enum CompanyManagerFaceVariable {
00035 CMFV_GENDER,
00036 CMFV_ETHNICITY,
00037 CMFV_GEN_ETHN,
00038 CMFV_HAS_MOUSTACHE,
00039 CMFV_HAS_TIE_EARRING,
00040 CMFV_HAS_GLASSES,
00041 CMFV_EYE_COLOUR,
00042 CMFV_CHEEKS,
00043 CMFV_CHIN,
00044 CMFV_EYEBROWS,
00045 CMFV_MOUSTACHE,
00046 CMFV_LIPS,
00047 CMFV_NOSE,
00048 CMFV_HAIR,
00049 CMFV_JACKET,
00050 CMFV_COLLAR,
00051 CMFV_TIE_EARRING,
00052 CMFV_GLASSES,
00053 CMFV_END
00054 };
00055 DECLARE_POSTFIX_INCREMENT(CompanyManagerFaceVariable);
00056
00058 struct CompanyManagerFaceBitsInfo {
00059 byte offset;
00060 byte length;
00061 byte valid_values[GE_END];
00062 SpriteID first_sprite[GE_END];
00063 };
00064
00066 static const CompanyManagerFaceBitsInfo _cmf_info[] = {
00067
00068 { 0, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } },
00069 { 1, 2, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } },
00070 { 0, 3, { 4, 4, 4, 4 }, { 0, 0, 0, 0 } },
00071 { 3, 1, { 2, 0, 2, 0 }, { 0, 0, 0, 0 } },
00072 { 3, 1, { 0, 2, 0, 2 }, { 0, 0, 0, 0 } },
00073 { 4, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } },
00074 { 5, 2, { 3, 3, 1, 1 }, { 0, 0, 0, 0 } },
00075 { 0, 0, { 1, 1, 1, 1 }, { 0x325, 0x326, 0x390, 0x3B0 } },
00076 { 7, 2, { 4, 1, 2, 2 }, { 0x327, 0x327, 0x391, 0x3B1 } },
00077 { 9, 4, { 12, 16, 11, 16 }, { 0x32B, 0x337, 0x39A, 0x3B8 } },
00078 { 13, 2, { 3, 0, 3, 0 }, { 0x367, 0, 0x397, 0 } },
00079 { 13, 4, { 12, 10, 9, 9 }, { 0x35B, 0x351, 0x3A5, 0x3C8 } },
00080 { 17, 3, { 8, 4, 4, 5 }, { 0x349, 0x34C, 0x393, 0x3B3 } },
00081 { 20, 4, { 9, 5, 5, 4 }, { 0x382, 0x38B, 0x3D4, 0x3D9 } },
00082 { 24, 2, { 3, 3, 3, 3 }, { 0x36B, 0x378, 0x36B, 0x378 } },
00083 { 26, 2, { 4, 4, 4, 4 }, { 0x36E, 0x37B, 0x36E, 0x37B } },
00084 { 28, 3, { 6, 3, 6, 3 }, { 0x372, 0x37F, 0x372, 0x3D1 } },
00085 { 31, 1, { 2, 2, 2, 2 }, { 0x347, 0x347, 0x3AE, 0x3AE } }
00086 };
00087 assert_compile(lengthof(_cmf_info) == CMFV_END);
00088
00097 static inline uint GetCompanyManagerFaceBits(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
00098 {
00099 assert(_cmf_info[cmfv].valid_values[ge] != 0);
00100
00101 return GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length);
00102 }
00103
00112 static inline void SetCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
00113 {
00114 assert(val < _cmf_info[cmfv].valid_values[ge]);
00115
00116 SB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length, val);
00117 }
00118
00131 static inline void IncreaseCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, int8 amount)
00132 {
00133 int8 val = GetCompanyManagerFaceBits(cmf, cmfv, ge) + amount;
00134
00135
00136 if (val >= _cmf_info[cmfv].valid_values[ge]) {
00137 val = 0;
00138 } else if (val < 0) {
00139 val = _cmf_info[cmfv].valid_values[ge] - 1;
00140 }
00141
00142 SetCompanyManagerFaceBits(cmf, cmfv, ge, val);
00143 }
00144
00152 static inline bool AreCompanyManagerFaceBitsValid(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
00153 {
00154 return GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length) < _cmf_info[cmfv].valid_values[ge];
00155 }
00156
00165 static inline uint ScaleCompanyManagerFaceValue(CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
00166 {
00167 assert(val < (1U << _cmf_info[cmfv].length));
00168
00169 return (val * _cmf_info[cmfv].valid_values[ge]) >> _cmf_info[cmfv].length;
00170 }
00171
00177 static inline void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf)
00178 {
00179 IncreaseCompanyManagerFaceBits(cmf, CMFV_ETHNICITY, GE_WM, 0);
00180
00181 GenderEthnicity ge = (GenderEthnicity)GB(cmf, _cmf_info[CMFV_GEN_ETHN].offset, _cmf_info[CMFV_GEN_ETHN].length);
00182
00183
00184 bool is_moust_male = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge) != 0;
00185
00186 for (CompanyManagerFaceVariable cmfv = CMFV_EYE_COLOUR; cmfv < CMFV_END; cmfv++) {
00187
00188
00189 if (cmfv != CMFV_MOUSTACHE || is_moust_male) {
00190 IncreaseCompanyManagerFaceBits(cmf, cmfv, ge, 0);
00191 }
00192 }
00193 }
00194
00206 static inline void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv)
00207 {
00208 cmf = InteractiveRandom();
00209
00210
00211 ge = (GenderEthnicity)((uint)ge % GE_END);
00212
00213
00214 if (adv) {
00215 SetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, ge, ge);
00216 } else {
00217 SetCompanyManagerFaceBits(cmf, CMFV_GENDER, ge, HasBit(ge, GENDER_FEMALE));
00218 }
00219
00220
00221 ScaleAllCompanyManagerFaceBits(cmf);
00222 }
00223
00232 static inline SpriteID GetCompanyManagerFaceSprite(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
00233 {
00234 assert(_cmf_info[cmfv].valid_values[ge] != 0);
00235
00236 return _cmf_info[cmfv].first_sprite[ge] + GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length);
00237 }
00238
00239 void DrawCompanyManagerFace(CompanyManagerFace face, int colour, int x, int y);
00240 bool IsValidCompanyManagerFace(CompanyManagerFace cmf);
00241
00242 #endif