summaryrefslogtreecommitdiff
path: root/src/rail.h
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2011-12-03 23:40:46 +0000
committermichi_cc <michi_cc@openttd.org>2011-12-03 23:40:46 +0000
commitd3b7b89493e025654d218fb77da095649b4f6ba2 (patch)
tree6667e4164c5c8bda4c1b7092376872b315c65610 /src/rail.h
parentf98312eb77e12cfa45de40a1b4e8359160b0d9ff (diff)
downloadopenttd-d3b7b89493e025654d218fb77da095649b4f6ba2.tar.xz
(svn r23415) -Feature: Infrastructure maintenance costs.
Diffstat (limited to 'src/rail.h')
-rw-r--r--src/rail.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/rail.h b/src/rail.h
index 54b5c27b6..43672d058 100644
--- a/src/rail.h
+++ b/src/rail.h
@@ -20,6 +20,7 @@
#include "slope_type.h"
#include "strings_type.h"
#include "date_type.h"
+#include "core/math_func.hpp"
/** Railtype flags. */
enum RailTypeFlags {
@@ -189,6 +190,11 @@ struct RailtypeInfo {
uint16 cost_multiplier;
/**
+ * Cost multiplier for maintenance of this rail type
+ */
+ uint16 maintenance_multiplier;
+
+ /**
* Acceleration type of this rail type
*/
uint8 acceleration_type;
@@ -363,6 +369,28 @@ static inline Money RailConvertCost(RailType from, RailType to)
return rebuildcost;
}
+/**
+ * Calculates the maintenance cost of a number of track bits.
+ * @param railtype The railtype to get the cost of.
+ * @param num Number of track bits.
+ * @return Total cost.
+ */
+static inline Money RailMaintenanceCost(RailType railtype, uint32 num)
+{
+ assert(railtype < RAILTYPE_END);
+ return (_price[PR_INFRASTRUCTURE_RAIL] * GetRailTypeInfo(railtype)->maintenance_multiplier * num * (1 + IntSqrt(num))) >> 11; // 4 bits fraction for the multiplier and 7 bits scaling.
+}
+
+/**
+ * Calculates the maintenance cost of a number of signals.
+ * @param num Number of signals.
+ * @return Total cost.
+ */
+static inline Money SignalMaintenanceCost(uint32 num)
+{
+ return (_price[PR_INFRASTRUCTURE_RAIL] * 15 * num * (1 + IntSqrt(num))) >> 8; // 1 bit fraction for the multiplier and 7 bits scaling.
+}
+
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
int TicksToLeaveDepot(const Train *v);