Loading

Paste #ptvy7ysmq

  1. Index: lang/english.txt
  2. ===================================================================
  3. --- lang/english.txt    (revision 27764)
  4. +++ lang/english.txt    (working copy)
  5. @@ -3689,7 +3689,9 @@
  6.  
  7.  # Extra buttons for train details windows
  8.  STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE                :{LTBLUE}{ENGINE}{BLACK}   Built: {LTBLUE}{NUM}{BLACK} Value: {LTBLUE}{CURRENCY_LONG}
  9. +STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_VALUE_RUNCOST            :{LTBLUE}{ENGINE}{BLACK}   Built: {LTBLUE}{NUM}{BLACK} Value: {LTBLUE}{CURRENCY_LONG}{BLACK} Running Cost: {LTBLUE}{CURRENCY_LONG}/yr
  10.  STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE                           :{LTBLUE}{ENGINE}{BLACK}   Value: {LTBLUE}{CURRENCY_LONG}
  11. +STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE_RUNCOST                   :{LTBLUE}{ENGINE}{BLACK}   Value: {LTBLUE}{CURRENCY_LONG}{BLACK} Running Cost: {LTBLUE}{CURRENCY_LONG}/yr
  12.  
  13.  STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT                   :{BLACK}Total cargo capacity of this train:
  14.  STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY                        :{LTBLUE}- {CARGO_LONG} ({CARGO_SHORT})
  15. Index: train.h
  16. ===================================================================
  17. --- train.h (revision 27764)
  18. +++ train.h (working copy)
  19. @@ -117,7 +117,7 @@
  20.     void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const;
  21.     int GetDisplaySpeed() const { return this->gcache.last_speed; }
  22.     int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed; }
  23. -   Money GetRunningCost() const;
  24. +   Money GetRunningCost(bool single_part = false) const;
  25.     int GetDisplayImageWidth(Point *offset = NULL) const;
  26.     bool IsInDepot() const { return this->track == TRACK_BIT_DEPOT; }
  27.     bool Tick();
  28. Index: train_cmd.cpp
  29. ===================================================================
  30. --- train_cmd.cpp   (revision 27764)
  31. +++ train_cmd.cpp   (working copy)
  32. @@ -3897,25 +3897,84 @@
  33.   * Get running cost for the train consist.
  34.   * @return Yearly running costs.
  35.   */
  36. -Money Train::GetRunningCost() const
  37. +Money Train::GetRunningCost(bool single_part) const
  38.  {
  39.     Money cost = 0;
  40.     const Train *v = this;
  41. +   const Train *v1 = single_part ? v->First() : v;
  42. +   const Train *v2 = v1;
  43. +   bool unc_len = false;
  44. +   uint cal_cost = 0;
  45. +   uint unc_cost = 0;
  46.  
  47.     do {
  48. -       const Engine *e = v->GetEngine();
  49. -       if (e->u.rail.running_cost_class == INVALID_PRICE) continue;
  50. +       const Engine *e = v1->GetEngine();
  51. +       if (e->u.rail.running_cost_class == INVALID_PRICE) {
  52. +           unc_len = true;
  53. +           continue;
  54. +       }
  55.  
  56. -       uint cost_factor = GetVehicleProperty(v, PROP_TRAIN_RUNNING_COST_FACTOR, e->u.rail.running_cost);
  57. +       uint cost_factor = GetVehicleProperty(v1, PROP_TRAIN_RUNNING_COST_FACTOR, e->u.rail.running_cost);
  58.         if (cost_factor == 0) continue;
  59.  
  60.         /* Halve running cost for multiheaded parts */
  61. +       if (v1->IsMultiheaded()) cost_factor /= 2;
  62. +
  63. +       cal_cost += GetPrice(e->u.rail.running_cost_class, cost_factor, e->GetGRF());
  64. +   } while ((v1 = v1->GetNextVehicle()) != NULL);
  65. +
  66. +   if (unc_len && cal_cost > 0) {
  67. +       do {
  68. +           const Engine *e = v2->GetEngine();
  69. +           if (e->u.rail.running_cost_class != INVALID_PRICE) continue;
  70. +
  71. +           const Train *a = v2;
  72. +           uint ind_len = 0;
  73. +           do {
  74. +               ind_len += a->gcache.cached_veh_length;
  75. +               a = a->HasArticulatedPart() ? a->GetNextArticulatedPart() : NULL;
  76. +           } while (a != NULL);
  77. +           if (ind_len == 0) continue;
  78. +
  79. +           uint ind_cost = cal_cost * ind_len / (VEHICLE_LENGTH * 2 * _settings_game.vehicle.max_train_length);
  80. +           uint cost_factor = GetEngineProperty(e->index, PROP_TRAIN_RUNNING_COST_FACTOR, ind_cost);
  81. +
  82. +           /* Halve running cost for multiheaded parts */
  83. +           if (v2->IsMultiheaded()) cost_factor /= 2;
  84. +
  85. +           unc_cost += GetPrice(PR_RUNNING_TRAIN_STEAM, cost_factor, e->GetGRF()) / _price[PR_RUNNING_TRAIN_STEAM];
  86. +       } while ((v2 = v2->GetNextVehicle()) != NULL);
  87. +   }
  88. +
  89. +   cost = unc_cost + cal_cost;
  90. +   if (!single_part) return cost;
  91. +
  92. +   const Engine *e = v->GetEngine();
  93. +   if (e->u.rail.running_cost_class == INVALID_PRICE) {
  94. +       const Train *a = v;
  95. +       uint ind_len = 0;
  96. +       do {
  97. +           ind_len += a->gcache.cached_veh_length;
  98. +           a = a->HasArticulatedPart() ? a->GetNextArticulatedPart() : NULL;
  99. +       } while (a != NULL);
  100. +
  101. +       uint ind_cost = cal_cost * ind_len / (VEHICLE_LENGTH * 2 * _settings_game.vehicle.max_train_length);
  102. +       uint cost_factor = GetEngineProperty(e->index, PROP_TRAIN_RUNNING_COST_FACTOR, ind_cost);
  103. +
  104. +       /* Halve running cost for multiheaded parts */
  105.         if (v->IsMultiheaded()) cost_factor /= 2;
  106.  
  107. -       cost += GetPrice(e->u.rail.running_cost_class, cost_factor, e->GetGRF());
  108. -   } while ((v = v->GetNextVehicle()) != NULL);
  109. +       unc_cost = GetPrice(PR_RUNNING_TRAIN_STEAM, cost_factor, e->GetGRF()) / _price[PR_RUNNING_TRAIN_STEAM];
  110. +       return unc_cost;
  111. +   } else {
  112. +       uint cost_factor = GetVehicleProperty(v, PROP_TRAIN_RUNNING_COST_FACTOR, e->u.rail.running_cost);
  113.  
  114. -   return cost;
  115. +       /* Halve running cost for multiheaded parts */
  116. +       if (v->IsMultiheaded()) cost_factor /= 2;
  117. +
  118. +       cal_cost = GetPrice(e->u.rail.running_cost_class, cost_factor, e->GetGRF());
  119. +       return cal_cost;
  120. +   }
  121.  }
  122.  
  123.  /**
  124. Index: train_gui.cpp
  125. ===================================================================
  126. --- train_gui.cpp   (revision 27764)
  127. +++ train_gui.cpp   (working copy)
  128. @@ -222,12 +222,14 @@
  129.     if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) {
  130.         SetDParam(0, v->engine_type);
  131.         SetDParam(1, v->value);
  132. -       DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE);
  133. +       SetDParam(2, v->GetRunningCost(true) >> 8);
  134. +       DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE_RUNCOST);
  135.     } else {
  136.         SetDParam(0, v->engine_type);
  137.         SetDParam(1, v->build_year);
  138.         SetDParam(2, v->value);
  139. -       DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE);
  140. +       SetDParam(3, v->GetRunningCost(true) >> 8);
  141. +       DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_VALUE_RUNCOST);
  142.     }
  143.  }
  144.  
  145. Index: vehicle_base.h
  146. ===================================================================
  147. --- vehicle_base.h  (revision 27764)
  148. +++ vehicle_base.h  (working copy)
  149. @@ -495,7 +495,7 @@
  150.      * Gets the running cost of a vehicle
  151.      * @return the vehicle's running cost
  152.      */
  153. -   virtual Money GetRunningCost() const { return 0; }
  154. +   virtual Money GetRunningCost(bool single_part = false) const { return 0; }
  155.  
  156.     /**
  157.      * Check whether the vehicle is in the depot.

Comments