00001
00002
00005 #ifndef COMPANY_MANAGER_FACE_H
00006 #define COMPANY_MANAGER_FACE_H
00007
00008 #include "core/random_func.hpp"
00009 #include "core/bitmath_func.hpp"
00010 #include "table/sprites.h"
00011 #include "company_type.h"
00012
00014 enum GenderEthnicity {
00015 GENDER_FEMALE = 0,
00016 ETHNICITY_BLACK = 1,
00017
00018 GE_WM = 0,
00019 GE_WF = 1 << GENDER_FEMALE,
00020 GE_BM = 1 << ETHNICITY_BLACK,
00021 GE_BF = 1 << ETHNICITY_BLACK | 1 << GENDER_FEMALE,
00022 GE_END,
00023 };
00024 DECLARE_ENUM_AS_BIT_SET(GenderEthnicity);
00025
00027 enum CompanyManagerFaceVariable {
00028 CMFV_GENDER,
00029 CMFV_ETHNICITY,
00030 CMFV_GEN_ETHN,
00031 CMFV_HAS_MOUSTACHE,
00032 CMFV_HAS_TIE_EARRING,
00033 CMFV_HAS_GLASSES,
00034 CMFV_EYE_COLOUR,
00035 CMFV_CHEEKS,
00036 CMFV_CHIN,
00037 CMFV_EYEBROWS,
00038 CMFV_MOUSTACHE,
00039 CMFV_LIPS,
00040 CMFV_NOSE,
00041 CMFV_HAIR,
00042 CMFV_JACKET,
00043 CMFV_COLLAR,
00044 CMFV_TIE_EARRING,
00045 CMFV_GLASSES,
00046 CMFV_END
00047 };
00048 DECLARE_POSTFIX_INCREMENT(CompanyManagerFaceVariable);
00049
00051 struct CompanyManagerFaceBitsInfo {
00052 byte offset;
00053 byte length;
00054 byte valid_values[GE_END];
00055 SpriteID first_sprite[GE_END];
00056 };
00057
00059 static const CompanyManagerFaceBitsInfo _cmf_info[] = {
00060
00061 { 0, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } },
00062 { 1, 2, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } },
00063 { 0, 3, { 4, 4, 4, 4 }, { 0, 0, 0, 0 } },
00064 { 3, 1, { 2, 0, 2, 0 }, { 0, 0, 0, 0 } },
00065 { 3, 1, { 0, 2, 0, 2 }, { 0, 0, 0, 0 } },
00066 { 4, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } },
00067 { 5, 2, { 3, 3, 1, 1 }, { 0, 0, 0, 0 } },
00068 { 0, 0, { 1, 1, 1, 1 }, { 0x325, 0x326, 0x390, 0x3B0 } },
00069 { 7, 2, { 4, 1, 2, 2 }, { 0x327, 0x327, 0x391, 0x3B1 } },
00070 { 9, 4, { 12, 16, 11, 16 }, { 0x32B, 0x337, 0x39A, 0x3B8 } },
00071 { 13, 2, { 3, 0, 3, 0 }, { 0x367, 0, 0x397, 0 } },
00072 { 13, 4, { 12, 10, 9, 9 }, { 0x35B, 0x351, 0x3A5, 0x3C8 } },
00073 { 17, 3, { 8, 4, 4, 5 }, { 0x349, 0x34C, 0x393, 0x3B3 } },
00074 { 20, 4, { 9, 5, 5, 4 }, { 0x382, 0x38B, 0x3D4, 0x3D9 } },
00075 { 24, 2, { 3, 3, 3, 3 }, { 0x36B, 0x378, 0x36B, 0x378 } },
00076 { 26, 2, { 4, 4, 4, 4 }, { 0x36E, 0x37B, 0x36E, 0x37B } },
00077 { 28, 3, { 6, 3, 6, 3 }, { 0x372, 0x37F, 0x372, 0x3D1 } },
00078 { 31, 1, { 2, 2, 2, 2 }, { 0x347, 0x347, 0x3AE, 0x3AE } }
00079 };
00080 assert_compile(lengthof(_cmf_info) == CMFV_END);
00081
00090 static inline uint GetCompanyManagerFaceBits(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
00091 {
00092 assert(_cmf_info[cmfv].valid_values[ge] != 0);
00093
00094 return GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length);
00095 }
00096
00105 static inline void SetCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
00106 {
00107 assert(val < _cmf_info[cmfv].valid_values[ge]);
00108
00109 SB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length, val);
00110 }
00111
00124 static inline void IncreaseCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, int8 amount)
00125 {
00126 int8 val = GetCompanyManagerFaceBits(cmf, cmfv, ge) + amount;
00127
00128
00129 if (val >= _cmf_info[cmfv].valid_values[ge]) {
00130 val = 0;
00131 } else if (val < 0) {
00132 val = _cmf_info[cmfv].valid_values[ge] - 1;
00133 }
00134
00135 SetCompanyManagerFaceBits(cmf, cmfv, ge, val);
00136 }
00137
00145 static inline bool AreCompanyManagerFaceBitsValid(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
00146 {
00147 return GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length) < _cmf_info[cmfv].valid_values[ge];
00148 }
00149
00158 static inline uint ScaleCompanyManagerFaceValue(CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
00159 {
00160 assert(val < (1U << _cmf_info[cmfv].length));
00161
00162 return (val * _cmf_info[cmfv].valid_values[ge]) >> _cmf_info[cmfv].length;
00163 }
00164
00170 static inline void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf)
00171 {
00172 IncreaseCompanyManagerFaceBits(cmf, CMFV_ETHNICITY, GE_WM, 0);
00173
00174 GenderEthnicity ge = (GenderEthnicity)GB(cmf, _cmf_info[CMFV_GEN_ETHN].offset, _cmf_info[CMFV_GEN_ETHN].length);
00175
00176
00177 bool is_moust_male = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge) != 0;
00178
00179 for (CompanyManagerFaceVariable cmfv = CMFV_EYE_COLOUR; cmfv < CMFV_END; cmfv++) {
00180
00181
00182 if (cmfv != CMFV_MOUSTACHE || is_moust_male) {
00183 IncreaseCompanyManagerFaceBits(cmf, cmfv, ge, 0);
00184 }
00185 }
00186 }
00187
00199 static inline void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv)
00200 {
00201 cmf = InteractiveRandom();
00202
00203
00204 ge = (GenderEthnicity)((uint)ge % GE_END);
00205
00206
00207 if (adv) {
00208 SetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, ge, ge);
00209 } else {
00210 SetCompanyManagerFaceBits(cmf, CMFV_GENDER, ge, HasBit(ge, GENDER_FEMALE));
00211 }
00212
00213
00214 ScaleAllCompanyManagerFaceBits(cmf);
00215 }
00216
00225 static inline SpriteID GetCompanyManagerFaceSprite(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
00226 {
00227 assert(_cmf_info[cmfv].valid_values[ge] != 0);
00228
00229 return _cmf_info[cmfv].first_sprite[ge] + GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length);
00230 }
00231
00232 void DrawCompanyManagerFace(CompanyManagerFace face, int colour, int x, int y);
00233 bool IsValidCompanyManagerFace(CompanyManagerFace cmf);
00234
00235 #endif