88 PlayerFace ConvertFromOldPlayerFace(uint32 face) |
88 PlayerFace ConvertFromOldPlayerFace(uint32 face) |
89 { |
89 { |
90 PlayerFace pf = 0; |
90 PlayerFace pf = 0; |
91 GenderEthnicity ge = GE_WM; |
91 GenderEthnicity ge = GE_WM; |
92 |
92 |
93 if (HASBIT(face, 31)) SetBitT(ge, GENDER_FEMALE); |
93 if (HasBit(face, 31)) SetBitT(ge, GENDER_FEMALE); |
94 if (HASBIT(face, 27) && (HASBIT(face, 26) == HASBIT(face, 19))) SetBitT(ge, ETHNICITY_BLACK); |
94 if (HasBit(face, 27) && (HasBit(face, 26) == HasBit(face, 19))) SetBitT(ge, ETHNICITY_BLACK); |
95 |
95 |
96 SetPlayerFaceBits(pf, PFV_GEN_ETHN, ge, ge); |
96 SetPlayerFaceBits(pf, PFV_GEN_ETHN, ge, ge); |
97 SetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge, GB(face, 28, 3) <= 1); |
97 SetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge, GB(face, 28, 3) <= 1); |
98 SetPlayerFaceBits(pf, PFV_EYE_COLOUR, ge, HASBIT(ge, ETHNICITY_BLACK) ? 0 : ClampU(GB(face, 20, 3), 5, 7) - 5); |
98 SetPlayerFaceBits(pf, PFV_EYE_COLOUR, ge, HasBit(ge, ETHNICITY_BLACK) ? 0 : ClampU(GB(face, 20, 3), 5, 7) - 5); |
99 SetPlayerFaceBits(pf, PFV_CHIN, ge, ScalePlayerFaceValue(PFV_CHIN, ge, GB(face, 4, 2))); |
99 SetPlayerFaceBits(pf, PFV_CHIN, ge, ScalePlayerFaceValue(PFV_CHIN, ge, GB(face, 4, 2))); |
100 SetPlayerFaceBits(pf, PFV_EYEBROWS, ge, ScalePlayerFaceValue(PFV_EYEBROWS, ge, GB(face, 6, 4))); |
100 SetPlayerFaceBits(pf, PFV_EYEBROWS, ge, ScalePlayerFaceValue(PFV_EYEBROWS, ge, GB(face, 6, 4))); |
101 SetPlayerFaceBits(pf, PFV_HAIR, ge, ScalePlayerFaceValue(PFV_HAIR, ge, GB(face, 16, 4))); |
101 SetPlayerFaceBits(pf, PFV_HAIR, ge, ScalePlayerFaceValue(PFV_HAIR, ge, GB(face, 16, 4))); |
102 SetPlayerFaceBits(pf, PFV_JACKET, ge, ScalePlayerFaceValue(PFV_JACKET, ge, GB(face, 20, 2))); |
102 SetPlayerFaceBits(pf, PFV_JACKET, ge, ScalePlayerFaceValue(PFV_JACKET, ge, GB(face, 20, 2))); |
103 SetPlayerFaceBits(pf, PFV_COLLAR, ge, ScalePlayerFaceValue(PFV_COLLAR, ge, GB(face, 22, 2))); |
103 SetPlayerFaceBits(pf, PFV_COLLAR, ge, ScalePlayerFaceValue(PFV_COLLAR, ge, GB(face, 22, 2))); |
104 SetPlayerFaceBits(pf, PFV_GLASSES, ge, GB(face, 28, 1)); |
104 SetPlayerFaceBits(pf, PFV_GLASSES, ge, GB(face, 28, 1)); |
105 |
105 |
106 uint lips = GB(face, 10, 4); |
106 uint lips = GB(face, 10, 4); |
107 if (!HASBIT(ge, GENDER_FEMALE) && lips < 4) { |
107 if (!HasBit(ge, GENDER_FEMALE) && lips < 4) { |
108 SetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge, true); |
108 SetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge, true); |
109 SetPlayerFaceBits(pf, PFV_MOUSTACHE, ge, max(lips, 1U) - 1); |
109 SetPlayerFaceBits(pf, PFV_MOUSTACHE, ge, max(lips, 1U) - 1); |
110 } else { |
110 } else { |
111 if (!HASBIT(ge, GENDER_FEMALE)) { |
111 if (!HasBit(ge, GENDER_FEMALE)) { |
112 lips = lips * 15 / 16; |
112 lips = lips * 15 / 16; |
113 lips -= 3; |
113 lips -= 3; |
114 if (HASBIT(ge, ETHNICITY_BLACK) && lips > 8) lips = 0; |
114 if (HasBit(ge, ETHNICITY_BLACK) && lips > 8) lips = 0; |
115 } else { |
115 } else { |
116 lips = ScalePlayerFaceValue(PFV_LIPS, ge, lips); |
116 lips = ScalePlayerFaceValue(PFV_LIPS, ge, lips); |
117 } |
117 } |
118 SetPlayerFaceBits(pf, PFV_LIPS, ge, lips); |
118 SetPlayerFaceBits(pf, PFV_LIPS, ge, lips); |
119 |
119 |
125 } |
125 } |
126 SetPlayerFaceBits(pf, PFV_NOSE, ge, nose); |
126 SetPlayerFaceBits(pf, PFV_NOSE, ge, nose); |
127 } |
127 } |
128 |
128 |
129 uint tie_earring = GB(face, 24, 4); |
129 uint tie_earring = GB(face, 24, 4); |
130 if (!HASBIT(ge, GENDER_FEMALE) || tie_earring < 3) { // Not all females have an earring |
130 if (!HasBit(ge, GENDER_FEMALE) || tie_earring < 3) { // Not all females have an earring |
131 if (HASBIT(ge, GENDER_FEMALE)) SetPlayerFaceBits(pf, PFV_HAS_TIE_EARRING, ge, true); |
131 if (HasBit(ge, GENDER_FEMALE)) SetPlayerFaceBits(pf, PFV_HAS_TIE_EARRING, ge, true); |
132 SetPlayerFaceBits(pf, PFV_TIE_EARRING, ge, HASBIT(ge, GENDER_FEMALE) ? tie_earring : ScalePlayerFaceValue(PFV_TIE_EARRING, ge, tie_earring / 2)); |
132 SetPlayerFaceBits(pf, PFV_TIE_EARRING, ge, HasBit(ge, GENDER_FEMALE) ? tie_earring : ScalePlayerFaceValue(PFV_TIE_EARRING, ge, tie_earring / 2)); |
133 } |
133 } |
134 |
134 |
135 return pf; |
135 return pf; |
136 } |
136 } |
137 |
137 |
144 bool IsValidPlayerFace(PlayerFace pf) |
144 bool IsValidPlayerFace(PlayerFace pf) |
145 { |
145 { |
146 if (!ArePlayerFaceBitsValid(pf, PFV_GEN_ETHN, GE_WM)) return false; |
146 if (!ArePlayerFaceBitsValid(pf, PFV_GEN_ETHN, GE_WM)) return false; |
147 |
147 |
148 GenderEthnicity ge = (GenderEthnicity)GetPlayerFaceBits(pf, PFV_GEN_ETHN, GE_WM); |
148 GenderEthnicity ge = (GenderEthnicity)GetPlayerFaceBits(pf, PFV_GEN_ETHN, GE_WM); |
149 bool has_moustache = !HASBIT(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge) != 0; |
149 bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge) != 0; |
150 bool has_tie_earring = !HASBIT(ge, GENDER_FEMALE) || GetPlayerFaceBits(pf, PFV_HAS_TIE_EARRING, ge) != 0; |
150 bool has_tie_earring = !HasBit(ge, GENDER_FEMALE) || GetPlayerFaceBits(pf, PFV_HAS_TIE_EARRING, ge) != 0; |
151 bool has_glasses = GetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge) != 0; |
151 bool has_glasses = GetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge) != 0; |
152 |
152 |
153 if (!ArePlayerFaceBitsValid(pf, PFV_EYE_COLOUR, ge)) return false; |
153 if (!ArePlayerFaceBitsValid(pf, PFV_EYE_COLOUR, ge)) return false; |
154 for (PlayerFaceVariable pfv = PFV_CHEEKS; pfv < PFV_END; pfv++) { |
154 for (PlayerFaceVariable pfv = PFV_CHEEKS; pfv < PFV_END; pfv++) { |
155 switch (pfv) { |
155 switch (pfv) { |
195 |
195 |
196 tmp = CommandCost(p->yearly_expenses[0][_yearly_expenses_type]); |
196 tmp = CommandCost(p->yearly_expenses[0][_yearly_expenses_type]); |
197 tmp.AddCost(cost); |
197 tmp.AddCost(cost); |
198 p->yearly_expenses[0][_yearly_expenses_type] = tmp.GetCost(); |
198 p->yearly_expenses[0][_yearly_expenses_type] = tmp.GetCost(); |
199 |
199 |
200 if (HASBIT(1 << EXPENSES_TRAIN_INC | |
200 if (HasBit(1 << EXPENSES_TRAIN_INC | |
201 1 << EXPENSES_ROADVEH_INC | |
201 1 << EXPENSES_ROADVEH_INC | |
202 1 << EXPENSES_AIRCRAFT_INC | |
202 1 << EXPENSES_AIRCRAFT_INC | |
203 1 << EXPENSES_SHIP_INC, _yearly_expenses_type)) { |
203 1 << EXPENSES_SHIP_INC, _yearly_expenses_type)) { |
204 tmp = CommandCost(p->cur_economy.income); |
204 tmp = CommandCost(p->cur_economy.income); |
205 tmp.AddCost(-cost.GetCost()); |
205 tmp.AddCost(-cost.GetCost()); |
206 p->cur_economy.income = tmp.GetCost(); |
206 p->cur_economy.income = tmp.GetCost(); |
207 } else if (HASBIT(1 << EXPENSES_TRAIN_RUN | |
207 } else if (HasBit(1 << EXPENSES_TRAIN_RUN | |
208 1 << EXPENSES_ROADVEH_RUN | |
208 1 << EXPENSES_ROADVEH_RUN | |
209 1 << EXPENSES_AIRCRAFT_RUN | |
209 1 << EXPENSES_AIRCRAFT_RUN | |
210 1 << EXPENSES_SHIP_RUN | |
210 1 << EXPENSES_SHIP_RUN | |
211 1 << EXPENSES_PROPERTY | |
211 1 << EXPENSES_PROPERTY | |
212 1 << EXPENSES_LOAN_INT, _yearly_expenses_type)) { |
212 1 << EXPENSES_LOAN_INT, _yearly_expenses_type)) { |