/** * Get running cost for the train consist. * @return Yearly running costs. */ Money Train::GetRunningCost() const { Money cost = 0; const Train *v = this; const Train *v2 = v; bool unc_len = false; uint cal_cost = 0; uint unc_cost = 0; do { const Engine *e = v->GetEngine(); if (e->u.rail.running_cost_class == INVALID_PRICE) { unc_len = true; continue; } uint cost_factor = GetVehicleProperty(v, PROP_TRAIN_RUNNING_COST_FACTOR, e->u.rail.running_cost); if (cost_factor == 0) continue; /* Halve running cost for multiheaded parts */ if (v->IsMultiheaded()) cost_factor /= 2; cal_cost += GetPrice(e->u.rail.running_cost_class, cost_factor, e->GetGRF()); } while ((v = v->GetNextVehicle()) != NULL); if (unc_len) { do { if (cal_cost == 0) continue; const Engine *e = v2->GetEngine(); if (e->u.rail.running_cost_class != INVALID_PRICE) continue; const Train *a = v2; uint ind_len = 0; do { ind_len += a->gcache.cached_veh_length; a = a->HasArticulatedPart() ? a->GetNextArticulatedPart() : NULL; } while (a != NULL); if (ind_len == 0) continue; uint ind_cost = cal_cost * ind_len / (VEHICLE_LENGTH * 2 * _settings_game.vehicle.max_train_length); uint cost_factor = GetEngineProperty(e->index, PROP_TRAIN_RUNNING_COST_FACTOR, ind_cost); /* Halve running cost for multiheaded parts */ if (v2->IsMultiheaded()) cost_factor /= 2; unc_cost += GetPrice(PR_RUNNING_TRAIN_STEAM, cost_factor, e->GetGRF()) / _price[PR_RUNNING_TRAIN_STEAM]; } while ((v2 = v2->GetNextVehicle()) != NULL); } cost = unc_cost + cal_cost; return cost; }