src/players.cpp
changeset 7928 63e18de69e50
parent 7922 a7e266f966d9
child 7931 b0a46cd92225
equal deleted inserted replaced
7927:3a3289a049f9 7928:63e18de69e50
    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)) {
   595 
   595 
   596 	for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
   596 	for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
   597 		const Engine* e = GetEngine(i);
   597 		const Engine* e = GetEngine(i);
   598 		const EngineInfo *ei = EngInfo(i);
   598 		const EngineInfo *ei = EngInfo(i);
   599 
   599 
   600 		if (e->type == VEH_TRAIN && HASBIT(ei->climates, _opt.landscape) &&
   600 		if (e->type == VEH_TRAIN && HasBit(ei->climates, _opt.landscape) &&
   601 				(HASBIT(e->player_avail, p) || _date >= e->intro_date + 365)) {
   601 				(HasBit(e->player_avail, p) || _date >= e->intro_date + 365)) {
   602 			const RailVehicleInfo *rvi = RailVehInfo(i);
   602 			const RailVehicleInfo *rvi = RailVehInfo(i);
   603 
   603 
   604 			if (rvi->railveh_type != RAILVEH_WAGON) {
   604 			if (rvi->railveh_type != RAILVEH_WAGON) {
   605 				assert(rvi->railtype < RAILTYPE_END);
   605 				assert(rvi->railtype < RAILTYPE_END);
   606 				SETBIT(rt, rvi->railtype);
   606 				SETBIT(rt, rvi->railtype);
   618 
   618 
   619 	for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
   619 	for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
   620 		const Engine* e = GetEngine(i);
   620 		const Engine* e = GetEngine(i);
   621 		const EngineInfo *ei = EngInfo(i);
   621 		const EngineInfo *ei = EngInfo(i);
   622 
   622 
   623 		if (e->type == VEH_ROAD && HASBIT(ei->climates, _opt.landscape) &&
   623 		if (e->type == VEH_ROAD && HasBit(ei->climates, _opt.landscape) &&
   624 				(HASBIT(e->player_avail, p) || _date >= e->intro_date + 365)) {
   624 				(HasBit(e->player_avail, p) || _date >= e->intro_date + 365)) {
   625 			SETBIT(rt, HASBIT(ei->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
   625 			SETBIT(rt, HasBit(ei->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
   626 		}
   626 		}
   627 	}
   627 	}
   628 
   628 
   629 	return rt;
   629 	return rt;
   630 }
   630 }
   675 	if (!IsValidPlayer(_current_player)) return CMD_ERROR;
   675 	if (!IsValidPlayer(_current_player)) return CMD_ERROR;
   676 
   676 
   677 	p = GetPlayer(_current_player);
   677 	p = GetPlayer(_current_player);
   678 	switch (GB(p1, 0, 3)) {
   678 	switch (GB(p1, 0, 3)) {
   679 		case 0:
   679 		case 0:
   680 			if (p->engine_renew == HASBIT(p2, 0))
   680 			if (p->engine_renew == HasBit(p2, 0))
   681 				return CMD_ERROR;
   681 				return CMD_ERROR;
   682 
   682 
   683 			if (flags & DC_EXEC) {
   683 			if (flags & DC_EXEC) {
   684 				p->engine_renew = HASBIT(p2, 0);
   684 				p->engine_renew = HasBit(p2, 0);
   685 				if (IsLocalPlayer()) {
   685 				if (IsLocalPlayer()) {
   686 					_patches.autorenew = p->engine_renew;
   686 					_patches.autorenew = p->engine_renew;
   687 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   687 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   688 				}
   688 				}
   689 			}
   689 			}
   733 				if (GetEngine(new_engine_type)->type == VEH_AIRCRAFT &&
   733 				if (GetEngine(new_engine_type)->type == VEH_AIRCRAFT &&
   734 						(AircraftVehInfo(old_engine_type)->subtype & AIR_CTOL) != (AircraftVehInfo(new_engine_type)->subtype & AIR_CTOL))
   734 						(AircraftVehInfo(old_engine_type)->subtype & AIR_CTOL) != (AircraftVehInfo(new_engine_type)->subtype & AIR_CTOL))
   735 					return CMD_ERROR;
   735 					return CMD_ERROR;
   736 
   736 
   737 				/* make sure that the player can actually buy the new engine */
   737 				/* make sure that the player can actually buy the new engine */
   738 				if (!HASBIT(GetEngine(new_engine_type)->player_avail, _current_player))
   738 				if (!HasBit(GetEngine(new_engine_type)->player_avail, _current_player))
   739 					return CMD_ERROR;
   739 					return CMD_ERROR;
   740 
   740 
   741 				cost = AddEngineReplacementForPlayer(p, old_engine_type, new_engine_type, id_g, flags);
   741 				cost = AddEngineReplacementForPlayer(p, old_engine_type, new_engine_type, id_g, flags);
   742 			} else {
   742 			} else {
   743 				cost = RemoveEngineReplacementForPlayer(p, old_engine_type,id_g, flags);
   743 				cost = RemoveEngineReplacementForPlayer(p, old_engine_type,id_g, flags);
   748 			return cost;
   748 			return cost;
   749 		}
   749 		}
   750 
   750 
   751 		case 4:
   751 		case 4:
   752 			if (flags & DC_EXEC) {
   752 			if (flags & DC_EXEC) {
   753 				p->engine_renew = HASBIT(p1, 15);
   753 				p->engine_renew = HasBit(p1, 15);
   754 				p->engine_renew_months = (int16)GB(p1, 16, 16);
   754 				p->engine_renew_months = (int16)GB(p1, 16, 16);
   755 				p->engine_renew_money = (uint32)p2;
   755 				p->engine_renew_money = (uint32)p2;
   756 
   756 
   757 				if (IsLocalPlayer()) {
   757 				if (IsLocalPlayer()) {
   758 					_patches.autorenew = p->engine_renew;
   758 					_patches.autorenew = p->engine_renew;
   761 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   761 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   762 				}
   762 				}
   763 			}
   763 			}
   764 			break;
   764 			break;
   765 		case 5:
   765 		case 5:
   766 			if (p->renew_keep_length == HASBIT(p2, 0))
   766 			if (p->renew_keep_length == HasBit(p2, 0))
   767 				return CMD_ERROR;
   767 				return CMD_ERROR;
   768 
   768 
   769 			if (flags & DC_EXEC) {
   769 			if (flags & DC_EXEC) {
   770 				p->renew_keep_length = HASBIT(p2, 0);
   770 				p->renew_keep_length = HasBit(p2, 0);
   771 				if (IsLocalPlayer()) {
   771 				if (IsLocalPlayer()) {
   772 					InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN);
   772 					InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN);
   773 				}
   773 				}
   774 			}
   774 			}
   775 		break;
   775 		break;