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
00057
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 };
00088 assert_compile(lengthof(_cmf_info) == CMFV_END);
00089
00098 static inline uint GetCompanyManagerFaceBits(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
00099 {
00100 assert(_cmf_info[cmfv].valid_values[ge] != 0);
00101
00102 return GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length);
00103 }
00104
00113 static inline void SetCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
00114 {
00115 assert(val < _cmf_info[cmfv].valid_values[ge]);
00116
00117 SB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length, val);
00118 }
00119
00132 static inline void IncreaseCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, int8 amount)
00133 {
00134 int8 val = GetCompanyManagerFaceBits(cmf, cmfv, ge) + amount;
00135
00136
00137 if (val >= _cmf_info[cmfv].valid_values[ge]) {
00138 val = 0;
00139 } else if (val < 0) {
00140 val = _cmf_info[cmfv].valid_values[ge] - 1;
00141 }
00142
00143 SetCompanyManagerFaceBits(cmf, cmfv, ge, val);
00144 }
00145
00153 static inline bool AreCompanyManagerFaceBitsValid(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
00154 {
00155 return GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length) < _cmf_info[cmfv].valid_values[ge];
00156 }
00157
00166 static inline uint ScaleCompanyManagerFaceValue(CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
00167 {
00168 assert(val < (1U << _cmf_info[cmfv].length));
00169
00170 return (val * _cmf_info[cmfv].valid_values[ge]) >> _cmf_info[cmfv].length;
00171 }
00172
00178 static inline void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf)
00179 {
00180 IncreaseCompanyManagerFaceBits(cmf, CMFV_ETHNICITY, GE_WM, 0);
00181
00182 GenderEthnicity ge = (GenderEthnicity)GB(cmf, _cmf_info[CMFV_GEN_ETHN].offset, _cmf_info[CMFV_GEN_ETHN].length);
00183
00184
00185 bool is_moust_male = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge) != 0;
00186
00187 for (CompanyManagerFaceVariable cmfv = CMFV_EYE_COLOUR; cmfv < CMFV_END; cmfv++) {
00188
00189
00190 if (cmfv != CMFV_MOUSTACHE || is_moust_male) {
00191 IncreaseCompanyManagerFaceBits(cmf, cmfv, ge, 0);
00192 }
00193 }
00194 }
00195
00207 static inline void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv)
00208 {
00209 cmf = InteractiveRandom();
00210
00211
00212 ge = (GenderEthnicity)((uint)ge % GE_END);
00213
00214
00215 if (adv) {
00216 SetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, ge, ge);
00217 } else {
00218 SetCompanyManagerFaceBits(cmf, CMFV_GENDER, ge, HasBit(ge, GENDER_FEMALE));
00219 }
00220
00221
00222 ScaleAllCompanyManagerFaceBits(cmf);
00223 }
00224
00233 static inline SpriteID GetCompanyManagerFaceSprite(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
00234 {
00235 assert(_cmf_info[cmfv].valid_values[ge] != 0);
00236
00237 return _cmf_info[cmfv].first_sprite[ge] + GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length);
00238 }
00239
00240 bool IsValidCompanyManagerFace(CompanyManagerFace cmf);
00241 void DrawCompanyManagerFace(CompanyManagerFace face, int colour, int x, int y);
00242
00243 #endif