diff options
author | rubidium <rubidium@openttd.org> | 2008-01-09 21:05:03 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-01-09 21:05:03 +0000 |
commit | 998d7644f6a1b58de0b06d539c0436808b1f1e95 (patch) | |
tree | 6b9fc11a0135e1ccdb74151dd8962e4fd5264843 /src/road.cpp | |
parent | 82fe2885abb359c813908b0c844533bfec2c2b22 (diff) | |
download | openttd-998d7644f6a1b58de0b06d539c0436808b1f1e95.tar.xz |
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
Diffstat (limited to 'src/road.cpp')
-rw-r--r-- | src/road.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/road.cpp b/src/road.cpp index 2107ec0e3..698bb37fe 100644 --- a/src/road.cpp +++ b/src/road.cpp @@ -6,6 +6,11 @@ #include "road_map.h" #include "road_internal.h" #include "water_map.h" +#include "genworld.h" +#include "player.h" +#include "engine.h" +#include "settings_type.h" +#include "date_func.h" bool IsPossibleCrossing(const TileIndex tile, Axis ax) { @@ -67,3 +72,38 @@ RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb) return org_rb; } + +bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts) +{ + RoadTypes avail_roadtypes; + + if (p == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) { + avail_roadtypes = ROADTYPES_ROAD; + } else { + if (!IsValidPlayer(p)) return false; + avail_roadtypes = (RoadTypes)GetPlayer(p)->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody + } + return (rts & ~avail_roadtypes) == 0; +} + +bool ValParamRoadType(const RoadType rt) +{ + return HasRoadTypesAvail(_current_player, RoadTypeToRoadTypes(rt)); +} + +RoadTypes GetPlayerRoadtypes(PlayerID p) +{ + RoadTypes rt = ROADTYPES_NONE; + + for (EngineID i = 0; i != TOTAL_NUM_ENGINES; i++) { + const Engine* e = GetEngine(i); + const EngineInfo *ei = EngInfo(i); + + if (e->type == VEH_ROAD && HasBit(ei->climates, _opt.landscape) && + (HasBit(e->player_avail, p) || _date >= e->intro_date + 365)) { + SetBit(rt, HasBit(ei->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); + } + } + + return rt; +} |