summaryrefslogtreecommitdiff
path: root/src/road_func.h
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2019-04-06 07:46:15 +0100
committerMichael Lutz <michi@icosahedron.de>2019-05-01 21:36:27 +0200
commitc02ef3e4564b7b54d49f0827d2d7625cbc38f335 (patch)
tree1c0ee62b6ce55124b247daaafa42300bfaa932e7 /src/road_func.h
parent21edf67f89c60351d5a0d84625455aa296b6b950 (diff)
downloadopenttd-c02ef3e4564b7b54d49f0827d2d7625cbc38f335.tar.xz
Feature: Add NotRoadTypes (NRT)
Diffstat (limited to 'src/road_func.h')
-rw-r--r--src/road_func.h88
1 files changed, 34 insertions, 54 deletions
diff --git a/src/road_func.h b/src/road_func.h
index 06be7c4aa..ebb68de69 100644
--- a/src/road_func.h
+++ b/src/road_func.h
@@ -13,29 +13,9 @@
#define ROAD_FUNC_H
#include "core/bitmath_func.hpp"
-#include "road_type.h"
+#include "road.h"
#include "economy_func.h"
-
-/**
- * Iterate through each set RoadType in a RoadTypes value.
- * For more informations see FOR_EACH_SET_BIT_EX.
- *
- * @param var Loop index variable that stores fallowing set road type. Must be of type RoadType.
- * @param road_types The value to iterate through (any expression).
- *
- * @see FOR_EACH_SET_BIT_EX
- */
-#define FOR_EACH_SET_ROADTYPE(var, road_types) FOR_EACH_SET_BIT_EX(RoadType, var, RoadTypes, road_types)
-
-/**
- * Whether the given roadtype is valid.
- * @param rt the roadtype to check for validness
- * @return true if and only if valid
- */
-static inline bool IsValidRoadType(RoadType rt)
-{
- return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM;
-}
+#include "transparency.h"
/**
* Whether the given roadtype is valid.
@@ -48,32 +28,6 @@ static inline bool IsValidRoadBits(RoadBits r)
}
/**
- * Maps a RoadType to the corresponding RoadTypes value
- *
- * @param rt the roadtype to get the roadtypes from
- * @return the roadtypes with the given roadtype
- */
-static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
-{
- assert(IsValidRoadType(rt));
- return (RoadTypes)(1 << rt);
-}
-
-/**
- * Returns the RoadTypes which are not present in the given RoadTypes
- *
- * This function returns the complement of a given RoadTypes.
- *
- * @param r The given RoadTypes
- * @return The complement of the given RoadTypes
- */
-static inline RoadTypes ComplementRoadTypes(RoadTypes r)
-{
- return (RoadTypes)(ROADTYPES_ALL ^ r);
-}
-
-
-/**
* Calculate the complement of a RoadBits value
*
* Simply flips all bits in the RoadBits value to get the complement
@@ -167,18 +121,44 @@ static inline RoadBits AxisToRoadBits(Axis a)
* Calculates the maintenance cost of a number of road bits.
* @param roadtype Road type to get the cost for.
* @param num Number of road bits.
+ * @param total_num Total number of road bits of all road/tram-types.
* @return Total cost.
*/
-static inline Money RoadMaintenanceCost(RoadType roadtype, uint32 num)
+static inline Money RoadMaintenanceCost(RoadType roadtype, uint32 num, uint32 total_num)
+{
+ assert(roadtype < ROADTYPE_END);
+ return (_price[PR_INFRASTRUCTURE_ROAD] * GetRoadTypeInfo(roadtype)->maintenance_multiplier * num * (1 + IntSqrt(total_num))) >> 12;
+}
+
+/**
+ * Test if a road type has catenary
+ * @param roadtype Road type to test
+ */
+static inline bool HasRoadCatenary(RoadType roadtype)
{
- assert(IsValidRoadType(roadtype));
- return (_price[PR_INFRASTRUCTURE_ROAD] * (roadtype == ROADTYPE_TRAM ? 3 : 2) * num * (1 + IntSqrt(num))) >> 9; // 2 bits fraction for the multiplier and 7 bits scaling.
+ assert(roadtype < ROADTYPE_END);
+ return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_CATENARY);
}
-bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts);
-bool ValParamRoadType(const RoadType rt);
-RoadTypes GetCompanyRoadtypes(const CompanyID company);
+/**
+ * Test if we should draw road catenary
+ * @param roadtype Road type to test
+ */
+static inline bool HasRoadCatenaryDrawn(RoadType roadtype)
+{
+ return HasRoadCatenary(roadtype) && !IsInvisibilitySet(TO_CATENARY);
+}
+
+bool HasRoadTypeAvail(CompanyID company, RoadType roadtype);
+bool ValParamRoadType(RoadType roadtype);
+RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces = true);
+RoadTypes GetRoadTypes(bool introduces);
+RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date);
void UpdateLevelCrossing(TileIndex tile, bool sound = true);
+void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count);
+
+struct TileInfo;
+void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset);
#endif /* ROAD_FUNC_H */