road.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "openttd.h"
00014 #include "rail_map.h"
00015 #include "road_map.h"
00016 #include "water_map.h"
00017 #include "genworld.h"
00018 #include "company_func.h"
00019 #include "company_base.h"
00020 #include "engine_base.h"
00021 #include "date_func.h"
00022 #include "landscape.h"
00023
00031 static bool IsPossibleCrossing(const TileIndex tile, Axis ax)
00032 {
00033 return (IsTileType(tile, MP_RAILWAY) &&
00034 GetRailTileType(tile) == RAIL_TILE_NORMAL &&
00035 GetTrackBits(tile) == (ax == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X) &&
00036 GetFoundationSlope(tile, NULL) == SLOPE_FLAT);
00037 }
00038
00039 RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb)
00040 {
00041 if (!IsValidTile(tile)) return ROAD_NONE;
00042 for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
00043 const TileIndex neighbor_tile = TileAddByDiagDir(tile, dir);
00044
00045
00046 const RoadBits target_rb = DiagDirToRoadBits(dir);
00047
00048
00049 if (org_rb & target_rb) {
00050 bool connective = false;
00051 const RoadBits mirrored_rb = MirrorRoadBits(target_rb);
00052
00053 switch (GetTileType(neighbor_tile)) {
00054
00055 case MP_CLEAR: case MP_TREES:
00056 connective = true;
00057 break;
00058
00059
00060 case MP_TUNNELBRIDGE:
00061 case MP_STATION:
00062 case MP_ROAD: {
00063 const RoadBits neighbor_rb = GetAnyRoadBits(neighbor_tile, ROADTYPE_ROAD) | GetAnyRoadBits(neighbor_tile, ROADTYPE_TRAM);
00064
00065
00066 connective = (neighbor_rb & mirrored_rb) ||
00067 CountBits(neighbor_rb) == 1;
00068
00069 } break;
00070
00071 case MP_RAILWAY:
00072 connective = IsPossibleCrossing(neighbor_tile, DiagDirToAxis(dir));
00073 break;
00074
00075 case MP_WATER:
00076
00077 connective = !IsWater(neighbor_tile);
00078 break;
00079
00080
00081 default: break;
00082 }
00083
00084
00085 if (!connective) org_rb ^= target_rb;
00086
00087 }
00088 }
00089
00090 return org_rb;
00091 }
00092
00093 bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts)
00094 {
00095 RoadTypes avail_roadtypes;
00096
00097 if (company == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) {
00098 avail_roadtypes = ROADTYPES_ROAD;
00099 } else {
00100 Company *c = Company::GetIfValid(company);
00101 if (c == NULL) return false;
00102 avail_roadtypes = (RoadTypes)c->avail_roadtypes | ROADTYPES_ROAD;
00103 }
00104 return (rts & ~avail_roadtypes) == 0;
00105 }
00106
00107 bool ValParamRoadType(const RoadType rt)
00108 {
00109 return HasRoadTypesAvail(_current_company, RoadTypeToRoadTypes(rt));
00110 }
00111
00112 RoadTypes GetCompanyRoadtypes(CompanyID company)
00113 {
00114 RoadTypes rt = ROADTYPES_NONE;
00115
00116 Engine *e;
00117 FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
00118 const EngineInfo *ei = &e->info;
00119
00120 if (HasBit(ei->climates, _settings_game.game_creation.landscape) &&
00121 (HasBit(e->company_avail, company) || _date >= e->intro_date + DAYS_IN_YEAR)) {
00122 SetBit(rt, HasBit(ei->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
00123 }
00124 }
00125
00126 return rt;
00127 }