summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/default/default.cpp4
-rw-r--r--src/ai/trolly/trolly.cpp2
-rw-r--r--src/economy.cpp6
-rw-r--r--src/group_gui.cpp4
-rw-r--r--src/newgrf_engine.cpp16
-rw-r--r--src/train_cmd.cpp4
-rw-r--r--src/vehicle_base.h12
-rw-r--r--src/vehicle_gui.cpp16
8 files changed, 39 insertions, 25 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index 438ec6621..1c83d4edf 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -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;
diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp
index 1a5a0fce4..e85fc36c4 100644
--- a/src/ai/trolly/trolly.cpp
+++ b/src/ai/trolly/trolly.cpp
@@ -1251,7 +1251,7 @@ static void AiNew_CheckVehicle(Player *p, Vehicle *v)
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) {
diff --git a/src/economy.cpp b/src/economy.cpp
index dc055dd5e..401948dba 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -163,14 +163,16 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
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)
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index 818b73479..7894a3b85 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -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);
- 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)) {
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index e35d25456..60c8a49b1 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -694,14 +694,14 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
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);
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 9e3c70e08..2bd318983 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -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,
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 8d9c015d4..428398d6c 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -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.
*/
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 38a864a22..28e9b5828 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -171,9 +171,9 @@ void DrawVehicleProfitButton(const Vehicle *v, int x, int y)
/* 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 VehicleProfitThisYearSorter(const void *a, const void *b)
{
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 VehicleProfitLastYearSorter(const void *a, const void *b)
{
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 *w)
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(Window *w)
}
/* 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 */