Changeset - r8614:5dc67f095106
[Not reviewed]
master
0 8 0
smatz - 16 years ago 2008-02-20 17:06:58
smatz@openttd.org
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
-Codechange: use GetDisplayProfitThisYear() to convert vehicle profit to readable form
8 files changed with 39 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/ai/default/default.cpp
Show inline comments
 
@@ -112,8 +112,8 @@ static void AiStateVehLoop(Player *p)
 

	
 
			/* not profitable? */
 
			if (v->age >= 730 &&
 
					v->profit_last_year >> 8 < _price.station_value * 5 &&
 
					v->profit_this_year >> 8 < _price.station_value * 5) {
 
					v->profit_last_year < _price.station_value * 5 * 256 &&
 
					v->profit_this_year < _price.station_value * 5 * 256) {
 
				_players_ai[p->index].state_counter = 0;
 
				_players_ai[p->index].state = AIS_SELL_VEHICLE;
 
				_players_ai[p->index].cur_veh = v;
src/ai/trolly/trolly.cpp
Show inline comments
 
@@ -1251,7 +1251,7 @@ static void AiNew_CheckVehicle(Player *p
 
	if (v->age > 360) {
 
		// If both years together are not more than AI_MINIMUM_ROUTE_PROFIT,
 
		//  it is not worth the line I guess...
 
		if ((v->profit_last_year + v->profit_this_year) >> 8 < AI_MINIMUM_ROUTE_PROFIT ||
 
		if (v->profit_last_year + v->profit_this_year < (Money)256 * AI_MINIMUM_ROUTE_PROFIT ||
 
				(v->reliability * 100 >> 16) < 40) {
 
			// There is a possibility that the route is fucked up...
 
			if (v->cargo.DaysInTransit() > AI_VEHICLE_LOST_DAYS) {
src/economy.cpp
Show inline comments
 
@@ -163,14 +163,16 @@ int UpdateCompanyRatingAndValue(Player *
 
				num++;
 
				if (v->age > 730) {
 
					/* Find the vehicle with the lowest amount of profit */
 
					if (min_profit_first || min_profit > v->profit_last_year >> 8) {
 
						min_profit = v->profit_last_year >> 8;
 
					if (min_profit_first || min_profit > v->profit_last_year) {
 
						min_profit = v->profit_last_year;
 
						min_profit_first = false;
 
					}
 
				}
 
			}
 
		}
 

	
 
		min_profit >>= 8; // remove the fract part
 

	
 
		_score_part[owner][SCORE_VEHICLES] = num;
 
		/* Don't allow negative min_profit to show */
 
		if (min_profit > 0)
src/group_gui.cpp
Show inline comments
 
@@ -483,8 +483,8 @@ static void GroupWndProc(Window *w, Wind
 

	
 
				if (w->resize.step_height == PLY_WND_PRC__SIZE_OF_ROW_BIG2) DrawSmallOrderList(v, x + 138, y2);
 

	
 
				SetDParam(0, v->profit_this_year >> 8);
 
				SetDParam(1, v->profit_last_year >> 8);
 
				SetDParam(0, v->GetDisplayProfitThisYear());
 
				SetDParam(1, v->GetDisplayProfitLastYear());
 
				DrawString(x + 19, y2 + w->resize.step_height - 8, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, TC_FROMSTRING);
 

	
 
				if (IsValidGroupID(v->group_id)) {
src/newgrf_engine.cpp
Show inline comments
 
@@ -694,14 +694,14 @@ static uint32 VehicleGetVariable(const R
 
		case 0x4F: return GB(v->reliability, 8, 8);
 
		case 0x50: return v->reliability_spd_dec;
 
		case 0x51: return GB(v->reliability_spd_dec, 8, 8);
 
		case 0x52: return ClampToI32(v->profit_this_year >> 8);
 
		case 0x53: return GB(ClampToI32(v->profit_this_year >> 8),  8, 24);
 
		case 0x54: return GB(ClampToI32(v->profit_this_year >> 8), 16, 16);
 
		case 0x55: return GB(ClampToI32(v->profit_this_year >> 8), 24,  8);
 
		case 0x56: return ClampToI32(v->profit_last_year >> 8);
 
		case 0x57: return GB(ClampToI32(v->profit_last_year >> 8),  8, 24);
 
		case 0x58: return GB(ClampToI32(v->profit_last_year >> 8), 16, 16);
 
		case 0x59: return GB(ClampToI32(v->profit_last_year >> 8), 24,  8);
 
		case 0x52: return ClampToI32(v->GetDisplayProfitThisYear());
 
		case 0x53: return GB(ClampToI32(v->GetDisplayProfitThisYear()),  8, 24);
 
		case 0x54: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 16, 16);
 
		case 0x55: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 24,  8);
 
		case 0x56: return ClampToI32(v->GetDisplayProfitLastYear());
 
		case 0x57: return GB(ClampToI32(v->GetDisplayProfitLastYear()),  8, 24);
 
		case 0x58: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 16, 16);
 
		case 0x59: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 24,  8);
 
		case 0x5A: return v->Next() == NULL ? INVALID_VEHICLE : v->Next()->index;
 
		case 0x5C: return ClampToI32(v->value);
 
		case 0x5D: return GB(ClampToI32(v->value),  8, 24);
src/train_cmd.cpp
Show inline comments
 
@@ -3689,8 +3689,8 @@ void TrainsYearlyLoop()
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_TRAIN && IsFrontEngine(v)) {
 
			/* show warning if train is not generating enough income last 2 years (corresponds to a red icon in the vehicle list) */
 
			if (_patches.train_income_warn && v->owner == _local_player && v->age >= 730 && v->profit_this_year < 0) {
 
				SetDParam(1, v->profit_this_year);
 
			if (_patches.train_income_warn && v->owner == _local_player && v->age >= 730 && v->GetDisplayProfitThisYear() < 0) {
 
				SetDParam(1, v->GetDisplayProfitThisYear());
 
				SetDParam(0, v->unitnumber);
 
				AddNewsItem(
 
					STR_TRAIN_IS_UNPROFITABLE,
src/vehicle_base.h
Show inline comments
 
@@ -438,6 +438,18 @@ public:
 
	Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
 

	
 
	/**
 
	 * Gets the profit vehicle had this year. It can be sent into SetDParam for string processing.
 
	 * @return the vehicle's profit this year
 
	 */
 
	Money GetDisplayProfitThisYear() const { return (this->profit_this_year >> 8); }
 

	
 
	/**
 
	 * Gets the profit vehicle had last year. It can be sent into SetDParam for string processing.
 
	 * @return the vehicle's profit last year
 
	 */
 
	Money GetDisplayProfitLastYear() const { return (this->profit_last_year >> 8); }
 

	
 
	/**
 
	 * Set the next vehicle of this vehicle.
 
	 * @param next the next vehicle. NULL removes the next vehicle.
 
	 */
src/vehicle_gui.cpp
Show inline comments
 
@@ -171,9 +171,9 @@ void DrawVehicleProfitButton(const Vehic
 
	/* draw profit-based colored icons */
 
	if (v->age <= 365 * 2) {
 
		pal = PALETTE_TO_GREY;
 
	} else if (v->profit_last_year < 0) {
 
	} else if (v->GetDisplayProfitLastYear() < 0) {
 
		pal = PALETTE_TO_RED;
 
	} else if (v->profit_last_year >> 8 < 10000) {
 
	} else if (v->GetDisplayProfitLastYear() < 10000) {
 
		pal = PALETTE_TO_YELLOW;
 
	} else {
 
		pal = PALETTE_TO_GREEN;
 
@@ -587,7 +587,7 @@ static int CDECL VehicleProfitThisYearSo
 
{
 
	const Vehicle* va = *(const Vehicle**)a;
 
	const Vehicle* vb = *(const Vehicle**)b;
 
	int r = ClampToI32(va->profit_this_year - vb->profit_this_year);
 
	int r = ClampToI32(va->GetDisplayProfitThisYear() - vb->GetDisplayProfitThisYear());
 

	
 
	VEHICLEUNITNUMBERSORTER(r, va, vb);
 

	
 
@@ -598,7 +598,7 @@ static int CDECL VehicleProfitLastYearSo
 
{
 
	const Vehicle* va = *(const Vehicle**)a;
 
	const Vehicle* vb = *(const Vehicle**)b;
 
	int r = ClampToI32((va->profit_last_year - vb->profit_last_year) >> 8);
 
	int r = ClampToI32(va->GetDisplayProfitLastYear() - vb->GetDisplayProfitLastYear());
 

	
 
	VEHICLEUNITNUMBERSORTER(r, va, vb);
 

	
 
@@ -983,8 +983,8 @@ static void DrawVehicleListWindow(Window
 
		const Vehicle *v = vl->sort_list[i];
 
		StringID str;
 

	
 
		SetDParam(0, v->profit_this_year >> 8);
 
		SetDParam(1, v->profit_last_year >> 8);
 
		SetDParam(0, v->GetDisplayProfitThisYear());
 
		SetDParam(1, v->GetDisplayProfitLastYear());
 

	
 
		DrawVehicleImage(v, x + 19, y + 6, INVALID_VEHICLE, w->widget[VLW_WIDGET_LIST].right - w->widget[VLW_WIDGET_LIST].left - 20, 0);
 
		DrawString(x + 19, y + w->resize.step_height - 8, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, TC_FROMSTRING);
 
@@ -1500,8 +1500,8 @@ static void DrawVehicleDetailsWindow(Win
 
	}
 

	
 
	/* Draw profit */
 
	SetDParam(0, v->profit_this_year >> 8);
 
	SetDParam(1, v->profit_last_year >> 8);
 
	SetDParam(0, v->GetDisplayProfitThisYear());
 
	SetDParam(1, v->GetDisplayProfitLastYear());
 
	DrawString(2, 35, _vehicle_translation_table[VST_VEHICLE_PROFIT_THIS_YEAR_LAST_YEAR][v->type], TC_FROMSTRING);
 

	
 
	/* Draw breakdown & reliability */
0 comments (0 inline, 0 general)