Loading

Paste #paxapdugj

  1. /**
  2.  * Get running cost for the train consist.
  3.  * @return Yearly running costs.
  4.  */
  5. Money Train::GetRunningCost() const
  6. {
  7.     Money cost = 0;
  8.     const Train *v = this;
  9.     const Train *v2 = v;
  10.     bool unc_len = false;
  11.     uint cal_cost = 0;
  12.     uint unc_cost = 0;
  13.  
  14.     do {
  15.         const Engine *e = v->GetEngine();
  16.         if (e->u.rail.running_cost_class == INVALID_PRICE) {
  17.             unc_len = true;
  18.             continue;
  19.         }
  20.  
  21.         uint cost_factor = GetVehicleProperty(v, PROP_TRAIN_RUNNING_COST_FACTOR, e->u.rail.running_cost);
  22.         if (cost_factor == 0) continue;
  23.  
  24.         /* Halve running cost for multiheaded parts */
  25.         if (v->IsMultiheaded()) cost_factor /= 2;
  26.  
  27.         cal_cost += GetPrice(e->u.rail.running_cost_class, cost_factor, e->GetGRF());
  28.     } while ((v = v->GetNextVehicle()) != NULL);
  29.  
  30.     if (unc_len) {
  31.         do {
  32.             if (cal_cost == 0) continue;
  33.  
  34.             const Engine *e = v2->GetEngine();
  35.             if (e->u.rail.running_cost_class != INVALID_PRICE) continue;
  36.  
  37.             const Train *a = v2;
  38.             uint ind_len = 0;
  39.             do {
  40.                 ind_len += a->gcache.cached_veh_length;
  41.                 a = a->HasArticulatedPart() ? a->GetNextArticulatedPart() : NULL;
  42.             } while (a != NULL);
  43.             if (ind_len == 0) continue;
  44.  
  45.             uint ind_cost = cal_cost * ind_len / (VEHICLE_LENGTH * 2 * _settings_game.vehicle.max_train_length);
  46.             uint cost_factor = GetEngineProperty(e->index, PROP_TRAIN_RUNNING_COST_FACTOR, ind_cost);
  47.  
  48.             /* Halve running cost for multiheaded parts */
  49.             if (v2->IsMultiheaded()) cost_factor /= 2;
  50.  
  51.             unc_cost += GetPrice(PR_RUNNING_TRAIN_STEAM, cost_factor, e->GetGRF()) / _price[PR_RUNNING_TRAIN_STEAM];
  52.         } while ((v2 = v2->GetNextVehicle()) != NULL);
  53.     }
  54.  
  55.     cost = unc_cost + cal_cost;
  56.     return cost;
  57. }

Comments