228 static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b) |
228 static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b) |
229 { |
229 { |
230 const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a); |
230 const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a); |
231 const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b); |
231 const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b); |
232 |
232 |
233 Money va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); |
233 Money va = rvi_a->running_cost * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); |
234 Money vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); |
234 Money vb = rvi_b->running_cost * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); |
235 int r = ClampToI32(va - vb); |
235 int r = ClampToI32(va - vb); |
236 |
236 |
237 return _internal_sort_order ? -r : r; |
237 return _internal_sort_order ? -r : r; |
238 } |
238 } |
239 |
239 |
246 * We want power/running cost, but since we usually got higher running cost than power and we store the result in an int, |
246 * We want power/running cost, but since we usually got higher running cost than power and we store the result in an int, |
247 * we will actually calculate cunning cost/power (to make it more than 1). |
247 * we will actually calculate cunning cost/power (to make it more than 1). |
248 * Because of this, the return value have to be reversed as well and we return b - a instead of a - b. |
248 * Because of this, the return value have to be reversed as well and we return b - a instead of a - b. |
249 * Another thing is that both power and running costs should be doubled for multiheaded engines. |
249 * Another thing is that both power and running costs should be doubled for multiheaded engines. |
250 * Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */ |
250 * Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */ |
251 Money va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max(1U, (uint)rvi_a->power); |
251 Money va = (rvi_a->running_cost * _price.running_rail[rvi_a->running_cost_class]) / max(1U, (uint)rvi_a->power); |
252 Money vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max(1U, (uint)rvi_b->power); |
252 Money vb = (rvi_b->running_cost * _price.running_rail[rvi_b->running_cost_class]) / max(1U, (uint)rvi_b->power); |
253 int r = ClampToI32(vb - va); |
253 int r = ClampToI32(vb - va); |
254 |
254 |
255 return _internal_sort_order ? -r : r; |
255 return _internal_sort_order ? -r : r; |
256 } |
256 } |
257 |
257 |
601 DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, TC_FROMSTRING); |
601 DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, TC_FROMSTRING); |
602 y += 10; |
602 y += 10; |
603 } |
603 } |
604 |
604 |
605 /* Running cost */ |
605 /* Running cost */ |
606 SetDParam(0, (GetEngineProperty(engine_number, 0x0D, rvi->running_cost_base) * _price.running_rail[rvi->running_cost_class] >> 8) << multihead); |
606 SetDParam(0, (GetEngineProperty(engine_number, 0x0D, rvi->running_cost) * _price.running_rail[rvi->running_cost_class] >> 8) << multihead); |
607 DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING); |
607 DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING); |
608 y += 10; |
608 y += 10; |
609 |
609 |
610 /* Powered wagons power - Powered wagons extra weight */ |
610 /* Powered wagons power - Powered wagons extra weight */ |
611 if (rvi->pow_wag_power != 0) { |
611 if (rvi->pow_wag_power != 0) { |