(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
pull/155/head
smatz 17 years ago
parent 2657090b1f
commit 9bdb194b2a

@ -112,8 +112,8 @@ static void AiStateVehLoop(Player *p)
/* not profitable? */ /* not profitable? */
if (v->age >= 730 && if (v->age >= 730 &&
v->profit_last_year >> 8 < _price.station_value * 5 && v->profit_last_year < _price.station_value * 5 * 256 &&
v->profit_this_year >> 8 < _price.station_value * 5) { v->profit_this_year < _price.station_value * 5 * 256) {
_players_ai[p->index].state_counter = 0; _players_ai[p->index].state_counter = 0;
_players_ai[p->index].state = AIS_SELL_VEHICLE; _players_ai[p->index].state = AIS_SELL_VEHICLE;
_players_ai[p->index].cur_veh = v; _players_ai[p->index].cur_veh = v;

@ -1251,7 +1251,7 @@ static void AiNew_CheckVehicle(Player *p, Vehicle *v)
if (v->age > 360) { if (v->age > 360) {
// If both years together are not more than AI_MINIMUM_ROUTE_PROFIT, // If both years together are not more than AI_MINIMUM_ROUTE_PROFIT,
// it is not worth the line I guess... // 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) { (v->reliability * 100 >> 16) < 40) {
// There is a possibility that the route is fucked up... // There is a possibility that the route is fucked up...
if (v->cargo.DaysInTransit() > AI_VEHICLE_LOST_DAYS) { if (v->cargo.DaysInTransit() > AI_VEHICLE_LOST_DAYS) {

@ -163,14 +163,16 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
num++; num++;
if (v->age > 730) { if (v->age > 730) {
/* Find the vehicle with the lowest amount of profit */ /* Find the vehicle with the lowest amount of profit */
if (min_profit_first || min_profit > v->profit_last_year >> 8) { if (min_profit_first || min_profit > v->profit_last_year) {
min_profit = v->profit_last_year >> 8; min_profit = v->profit_last_year;
min_profit_first = false; min_profit_first = false;
} }
} }
} }
} }
min_profit >>= 8; // remove the fract part
_score_part[owner][SCORE_VEHICLES] = num; _score_part[owner][SCORE_VEHICLES] = num;
/* Don't allow negative min_profit to show */ /* Don't allow negative min_profit to show */
if (min_profit > 0) if (min_profit > 0)

@ -483,8 +483,8 @@ static void GroupWndProc(Window *w, WindowEvent *e)
if (w->resize.step_height == PLY_WND_PRC__SIZE_OF_ROW_BIG2) DrawSmallOrderList(v, x + 138, y2); 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(0, v->GetDisplayProfitThisYear());
SetDParam(1, v->profit_last_year >> 8); SetDParam(1, v->GetDisplayProfitLastYear());
DrawString(x + 19, y2 + w->resize.step_height - 8, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, TC_FROMSTRING); DrawString(x + 19, y2 + w->resize.step_height - 8, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, TC_FROMSTRING);
if (IsValidGroupID(v->group_id)) { if (IsValidGroupID(v->group_id)) {

@ -694,14 +694,14 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
case 0x4F: return GB(v->reliability, 8, 8); case 0x4F: return GB(v->reliability, 8, 8);
case 0x50: return v->reliability_spd_dec; case 0x50: return v->reliability_spd_dec;
case 0x51: return GB(v->reliability_spd_dec, 8, 8); case 0x51: return GB(v->reliability_spd_dec, 8, 8);
case 0x52: return ClampToI32(v->profit_this_year >> 8); case 0x52: return ClampToI32(v->GetDisplayProfitThisYear());
case 0x53: return GB(ClampToI32(v->profit_this_year >> 8), 8, 24); case 0x53: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 8, 24);
case 0x54: return GB(ClampToI32(v->profit_this_year >> 8), 16, 16); case 0x54: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 16, 16);
case 0x55: return GB(ClampToI32(v->profit_this_year >> 8), 24, 8); case 0x55: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 24, 8);
case 0x56: return ClampToI32(v->profit_last_year >> 8); case 0x56: return ClampToI32(v->GetDisplayProfitLastYear());
case 0x57: return GB(ClampToI32(v->profit_last_year >> 8), 8, 24); case 0x57: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 8, 24);
case 0x58: return GB(ClampToI32(v->profit_last_year >> 8), 16, 16); case 0x58: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 16, 16);
case 0x59: return GB(ClampToI32(v->profit_last_year >> 8), 24, 8); case 0x59: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 24, 8);
case 0x5A: return v->Next() == NULL ? INVALID_VEHICLE : v->Next()->index; case 0x5A: return v->Next() == NULL ? INVALID_VEHICLE : v->Next()->index;
case 0x5C: return ClampToI32(v->value); case 0x5C: return ClampToI32(v->value);
case 0x5D: return GB(ClampToI32(v->value), 8, 24); case 0x5D: return GB(ClampToI32(v->value), 8, 24);

@ -3689,8 +3689,8 @@ void TrainsYearlyLoop()
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (v->type == VEH_TRAIN && IsFrontEngine(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) */ /* 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) { if (_patches.train_income_warn && v->owner == _local_player && v->age >= 730 && v->GetDisplayProfitThisYear() < 0) {
SetDParam(1, v->profit_this_year); SetDParam(1, v->GetDisplayProfitThisYear());
SetDParam(0, v->unitnumber); SetDParam(0, v->unitnumber);
AddNewsItem( AddNewsItem(
STR_TRAIN_IS_UNPROFITABLE, STR_TRAIN_IS_UNPROFITABLE,

@ -437,6 +437,18 @@ public:
*/ */
Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); } 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. * Set the next vehicle of this vehicle.
* @param next the next vehicle. NULL removes the next vehicle. * @param next the next vehicle. NULL removes the next vehicle.

@ -171,9 +171,9 @@ void DrawVehicleProfitButton(const Vehicle *v, int x, int y)
/* draw profit-based colored icons */ /* draw profit-based colored icons */
if (v->age <= 365 * 2) { if (v->age <= 365 * 2) {
pal = PALETTE_TO_GREY; pal = PALETTE_TO_GREY;
} else if (v->profit_last_year < 0) { } else if (v->GetDisplayProfitLastYear() < 0) {
pal = PALETTE_TO_RED; pal = PALETTE_TO_RED;
} else if (v->profit_last_year >> 8 < 10000) { } else if (v->GetDisplayProfitLastYear() < 10000) {
pal = PALETTE_TO_YELLOW; pal = PALETTE_TO_YELLOW;
} else { } else {
pal = PALETTE_TO_GREEN; pal = PALETTE_TO_GREEN;
@ -587,7 +587,7 @@ static int CDECL VehicleProfitThisYearSorter(const void *a, const void *b)
{ {
const Vehicle* va = *(const Vehicle**)a; const Vehicle* va = *(const Vehicle**)a;
const Vehicle* vb = *(const Vehicle**)b; 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); VEHICLEUNITNUMBERSORTER(r, va, vb);
@ -598,7 +598,7 @@ static int CDECL VehicleProfitLastYearSorter(const void *a, const void *b)
{ {
const Vehicle* va = *(const Vehicle**)a; const Vehicle* va = *(const Vehicle**)a;
const Vehicle* vb = *(const Vehicle**)b; 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); VEHICLEUNITNUMBERSORTER(r, va, vb);
@ -983,8 +983,8 @@ static void DrawVehicleListWindow(Window *w)
const Vehicle *v = vl->sort_list[i]; const Vehicle *v = vl->sort_list[i];
StringID str; StringID str;
SetDParam(0, v->profit_this_year >> 8); SetDParam(0, v->GetDisplayProfitThisYear());
SetDParam(1, v->profit_last_year >> 8); 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); 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); 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(Window *w)
} }
/* Draw profit */ /* Draw profit */
SetDParam(0, v->profit_this_year >> 8); SetDParam(0, v->GetDisplayProfitThisYear());
SetDParam(1, v->profit_last_year >> 8); SetDParam(1, v->GetDisplayProfitLastYear());
DrawString(2, 35, _vehicle_translation_table[VST_VEHICLE_PROFIT_THIS_YEAR_LAST_YEAR][v->type], TC_FROMSTRING); DrawString(2, 35, _vehicle_translation_table[VST_VEHICLE_PROFIT_THIS_YEAR_LAST_YEAR][v->type], TC_FROMSTRING);
/* Draw breakdown & reliability */ /* Draw breakdown & reliability */

Loading…
Cancel
Save