summaryrefslogtreecommitdiff
path: root/src/rail.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-01-09 21:05:03 +0000
committerrubidium <rubidium@openttd.org>2008-01-09 21:05:03 +0000
commit998d7644f6a1b58de0b06d539c0436808b1f1e95 (patch)
tree6b9fc11a0135e1ccdb74151dd8962e4fd5264843 /src/rail.cpp
parent82fe2885abb359c813908b0c844533bfec2c2b22 (diff)
downloadopenttd-998d7644f6a1b58de0b06d539c0436808b1f1e95.tar.xz
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
Diffstat (limited to 'src/rail.cpp')
-rw-r--r--src/rail.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/rail.cpp b/src/rail.cpp
index ea8a78de3..b722fd5d8 100644
--- a/src/rail.cpp
+++ b/src/rail.cpp
@@ -9,6 +9,8 @@
#include "station_map.h"
#include "tunnel_map.h"
#include "tunnelbridge_map.h"
+#include "settings_type.h"
+#include "date_func.h"
/* XXX: Below 3 tables store duplicate data. Maybe remove some? */
@@ -140,3 +142,43 @@ RailType GetTileRailType(TileIndex tile)
}
return INVALID_RAILTYPE;
}
+
+bool HasRailtypeAvail(const PlayerID p, const RailType railtype)
+{
+ return HasBit(GetPlayer(p)->avail_railtypes, railtype);
+}
+
+bool ValParamRailtype(const RailType rail)
+{
+ return HasRailtypeAvail(_current_player, rail);
+}
+
+RailType GetBestRailtype(const PlayerID p)
+{
+ if (HasRailtypeAvail(p, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
+ if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO;
+ if (HasRailtypeAvail(p, RAILTYPE_ELECTRIC)) return RAILTYPE_ELECTRIC;
+ return RAILTYPE_RAIL;
+}
+
+RailTypes GetPlayerRailtypes(PlayerID p)
+{
+ RailTypes rt = RAILTYPES_NONE;
+
+ for (EngineID i = 0; i != TOTAL_NUM_ENGINES; i++) {
+ const Engine* e = GetEngine(i);
+ const EngineInfo *ei = EngInfo(i);
+
+ if (e->type == VEH_TRAIN && HasBit(ei->climates, _opt.landscape) &&
+ (HasBit(e->player_avail, p) || _date >= e->intro_date + 365)) {
+ const RailVehicleInfo *rvi = RailVehInfo(i);
+
+ if (rvi->railveh_type != RAILVEH_WAGON) {
+ assert(rvi->railtype < RAILTYPE_END);
+ SetBit(rt, rvi->railtype);
+ }
+ }
+ }
+
+ return rt;
+}