(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
authorsmatz
Wed, 20 Feb 2008 17:06:58 +0000
changeset 8614 4c67a883c4c4
parent 8613 931d28d5c075
child 8615 d9525e4e85f5
(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
src/ai/default/default.cpp
src/ai/trolly/trolly.cpp
src/economy.cpp
src/group_gui.cpp
src/newgrf_engine.cpp
src/train_cmd.cpp
src/vehicle_base.h
src/vehicle_gui.cpp
--- a/src/ai/default/default.cpp	Wed Feb 20 16:24:56 2008 +0000
+++ b/src/ai/default/default.cpp	Wed Feb 20 17:06:58 2008 +0000
@@ -112,8 +112,8 @@
 
 			/* 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;
--- a/src/ai/trolly/trolly.cpp	Wed Feb 20 16:24:56 2008 +0000
+++ b/src/ai/trolly/trolly.cpp	Wed Feb 20 17:06:58 2008 +0000
@@ -1251,7 +1251,7 @@
 	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) {
--- a/src/economy.cpp	Wed Feb 20 16:24:56 2008 +0000
+++ b/src/economy.cpp	Wed Feb 20 17:06:58 2008 +0000
@@ -163,14 +163,16 @@
 				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)
--- a/src/group_gui.cpp	Wed Feb 20 16:24:56 2008 +0000
+++ b/src/group_gui.cpp	Wed Feb 20 17:06:58 2008 +0000
@@ -483,8 +483,8 @@
 
 				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)) {
--- a/src/newgrf_engine.cpp	Wed Feb 20 16:24:56 2008 +0000
+++ b/src/newgrf_engine.cpp	Wed Feb 20 17:06:58 2008 +0000
@@ -694,14 +694,14 @@
 		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);
--- a/src/train_cmd.cpp	Wed Feb 20 16:24:56 2008 +0000
+++ b/src/train_cmd.cpp	Wed Feb 20 17:06:58 2008 +0000
@@ -3689,8 +3689,8 @@
 	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,
--- a/src/vehicle_base.h	Wed Feb 20 16:24:56 2008 +0000
+++ b/src/vehicle_base.h	Wed Feb 20 17:06:58 2008 +0000
@@ -438,6 +438,18 @@
 	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.
 	 */
--- a/src/vehicle_gui.cpp	Wed Feb 20 16:24:56 2008 +0000
+++ b/src/vehicle_gui.cpp	Wed Feb 20 17:06:58 2008 +0000
@@ -171,9 +171,9 @@
 	/* 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 @@
 {
 	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 @@
 {
 	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 @@
 		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 @@
 	}
 
 	/* 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 */