From d3b7b89493e025654d218fb77da095649b4f6ba2 Mon Sep 17 00:00:00 2001 From: michi_cc Date: Sat, 3 Dec 2011 23:40:46 +0000 Subject: (svn r23415) -Feature: Infrastructure maintenance costs. --- src/rail.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/rail.h') 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 { @@ -188,6 +189,11 @@ struct RailtypeInfo { */ uint16 cost_multiplier; + /** + * Cost multiplier for maintenance of this rail type + */ + uint16 maintenance_multiplier; + /** * Acceleration type of this rail 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); -- cgit v1.2.3-54-g00ecf