00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef ROAD_MAP_H
00013 #define ROAD_MAP_H
00014
00015 #include "track_func.h"
00016 #include "depot_type.h"
00017 #include "rail_type.h"
00018 #include "road_func.h"
00019 #include "tile_map.h"
00020
00021
00023 enum RoadTileType {
00024 ROAD_TILE_NORMAL,
00025 ROAD_TILE_CROSSING,
00026 ROAD_TILE_DEPOT
00027 };
00028
00035 static inline RoadTileType GetRoadTileType(TileIndex t)
00036 {
00037 assert(IsTileType(t, MP_ROAD));
00038 return (RoadTileType)GB(_m[t].m5, 6, 2);
00039 }
00040
00047 static inline bool IsNormalRoad(TileIndex t)
00048 {
00049 return GetRoadTileType(t) == ROAD_TILE_NORMAL;
00050 }
00051
00057 static inline bool IsNormalRoadTile(TileIndex t)
00058 {
00059 return IsTileType(t, MP_ROAD) && IsNormalRoad(t);
00060 }
00061
00068 static inline bool IsLevelCrossing(TileIndex t)
00069 {
00070 return GetRoadTileType(t) == ROAD_TILE_CROSSING;
00071 }
00072
00078 static inline bool IsLevelCrossingTile(TileIndex t)
00079 {
00080 return IsTileType(t, MP_ROAD) && IsLevelCrossing(t);
00081 }
00082
00089 static inline bool IsRoadDepot(TileIndex t)
00090 {
00091 return GetRoadTileType(t) == ROAD_TILE_DEPOT;
00092 }
00093
00099 static inline bool IsRoadDepotTile(TileIndex t)
00100 {
00101 return IsTileType(t, MP_ROAD) && IsRoadDepot(t);
00102 }
00103
00111 static inline RoadBits GetRoadBits(TileIndex t, RoadType rt)
00112 {
00113 assert(IsNormalRoad(t));
00114 switch (rt) {
00115 default: NOT_REACHED();
00116 case ROADTYPE_ROAD: return (RoadBits)GB(_m[t].m5, 0, 4);
00117 case ROADTYPE_TRAM: return (RoadBits)GB(_m[t].m3, 0, 4);
00118 }
00119 }
00120
00128 static inline RoadBits GetOtherRoadBits(TileIndex t, RoadType rt)
00129 {
00130 return GetRoadBits(t, rt == ROADTYPE_ROAD ? ROADTYPE_TRAM : ROADTYPE_ROAD);
00131 }
00132
00139 static inline RoadBits GetAllRoadBits(TileIndex tile)
00140 {
00141 return GetRoadBits(tile, ROADTYPE_ROAD) | GetRoadBits(tile, ROADTYPE_TRAM);
00142 }
00143
00151 static inline void SetRoadBits(TileIndex t, RoadBits r, RoadType rt)
00152 {
00153 assert(IsNormalRoad(t));
00154 switch (rt) {
00155 default: NOT_REACHED();
00156 case ROADTYPE_ROAD: SB(_m[t].m5, 0, 4, r); break;
00157 case ROADTYPE_TRAM: SB(_m[t].m3, 0, 4, r); break;
00158 }
00159 }
00160
00166 static inline RoadTypes GetRoadTypes(TileIndex t)
00167 {
00168 return (RoadTypes)GB(_me[t].m7, 6, 2);
00169 }
00170
00176 static inline void SetRoadTypes(TileIndex t, RoadTypes rt)
00177 {
00178 assert(IsTileType(t, MP_ROAD) || IsTileType(t, MP_STATION) || IsTileType(t, MP_TUNNELBRIDGE));
00179 SB(_me[t].m7, 6, 2, rt);
00180 }
00181
00188 static inline bool HasTileRoadType(TileIndex t, RoadType rt)
00189 {
00190 return HasBit(GetRoadTypes(t), rt);
00191 }
00192
00199 static inline Owner GetRoadOwner(TileIndex t, RoadType rt)
00200 {
00201 assert(IsTileType(t, MP_ROAD) || IsTileType(t, MP_STATION) || IsTileType(t, MP_TUNNELBRIDGE));
00202 switch (rt) {
00203 default: NOT_REACHED();
00204 case ROADTYPE_ROAD: return (Owner)GB(IsNormalRoadTile(t) ? _m[t].m1 : _me[t].m7, 0, 5);
00205 case ROADTYPE_TRAM: {
00206
00207
00208 Owner o = (Owner)GB(_m[t].m3, 4, 4);
00209 return o == OWNER_TOWN ? OWNER_NONE : o;
00210 }
00211 }
00212 }
00213
00220 static inline void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
00221 {
00222 switch (rt) {
00223 default: NOT_REACHED();
00224 case ROADTYPE_ROAD: SB(IsNormalRoadTile(t) ? _m[t].m1 : _me[t].m7, 0, 5, o); break;
00225 case ROADTYPE_TRAM: SB(_m[t].m3, 4, 4, o == OWNER_NONE ? OWNER_TOWN : o); break;
00226 }
00227 }
00228
00237 static inline bool IsRoadOwner(TileIndex t, RoadType rt, Owner o)
00238 {
00239 assert(HasTileRoadType(t, rt));
00240 return (GetRoadOwner(t, rt) == o);
00241 }
00242
00249 static inline bool HasTownOwnedRoad(TileIndex t)
00250 {
00251 return HasTileRoadType(t, ROADTYPE_ROAD) && IsRoadOwner(t, ROADTYPE_ROAD, OWNER_TOWN);
00252 }
00253
00255 enum DisallowedRoadDirections {
00256 DRD_NONE,
00257 DRD_SOUTHBOUND,
00258 DRD_NORTHBOUND,
00259 DRD_BOTH,
00260 DRD_END
00261 };
00262 DECLARE_ENUM_AS_BIT_SET(DisallowedRoadDirections)
00263 template <> struct EnumPropsT<DisallowedRoadDirections> : MakeEnumPropsT<DisallowedRoadDirections, byte, DRD_NONE, DRD_END, DRD_END, 2> {};
00264
00270 static inline DisallowedRoadDirections GetDisallowedRoadDirections(TileIndex t)
00271 {
00272 assert(IsNormalRoad(t));
00273 return (DisallowedRoadDirections)GB(_m[t].m5, 4, 2);
00274 }
00275
00281 static inline void SetDisallowedRoadDirections(TileIndex t, DisallowedRoadDirections drd)
00282 {
00283 assert(IsNormalRoad(t));
00284 assert(drd < DRD_END);
00285 SB(_m[t].m5, 4, 2, drd);
00286 }
00287
00294 static inline Axis GetCrossingRoadAxis(TileIndex t)
00295 {
00296 assert(IsLevelCrossing(t));
00297 return (Axis)GB(_m[t].m5, 0, 1);
00298 }
00299
00306 static inline Axis GetCrossingRailAxis(TileIndex t)
00307 {
00308 assert(IsLevelCrossing(t));
00309 return OtherAxis((Axis)GetCrossingRoadAxis(t));
00310 }
00311
00317 static inline RoadBits GetCrossingRoadBits(TileIndex tile)
00318 {
00319 return GetCrossingRoadAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y;
00320 }
00321
00327 static inline Track GetCrossingRailTrack(TileIndex tile)
00328 {
00329 return AxisToTrack(GetCrossingRailAxis(tile));
00330 }
00331
00337 static inline TrackBits GetCrossingRailBits(TileIndex tile)
00338 {
00339 return AxisToTrackBits(GetCrossingRailAxis(tile));
00340 }
00341
00342
00349 static inline bool HasCrossingReservation(TileIndex t)
00350 {
00351 assert(IsLevelCrossingTile(t));
00352 return HasBit(_m[t].m5, 4);
00353 }
00354
00362 static inline void SetCrossingReservation(TileIndex t, bool b)
00363 {
00364 assert(IsLevelCrossingTile(t));
00365 SB(_m[t].m5, 4, 1, b ? 1 : 0);
00366 }
00367
00374 static inline TrackBits GetCrossingReservationTrackBits(TileIndex t)
00375 {
00376 return HasCrossingReservation(t) ? GetCrossingRailBits(t) : TRACK_BIT_NONE;
00377 }
00378
00385 static inline bool IsCrossingBarred(TileIndex t)
00386 {
00387 assert(IsLevelCrossing(t));
00388 return HasBit(_m[t].m5, 5);
00389 }
00390
00397 static inline void SetCrossingBarred(TileIndex t, bool barred)
00398 {
00399 assert(IsLevelCrossing(t));
00400 SB(_m[t].m5, 5, 1, barred ? 1 : 0);
00401 }
00402
00407 static inline void UnbarCrossing(TileIndex t)
00408 {
00409 SetCrossingBarred(t, false);
00410 }
00411
00416 static inline void BarCrossing(TileIndex t)
00417 {
00418 SetCrossingBarred(t, true);
00419 }
00420
00422 #define IsOnDesert IsOnSnow
00423
00428 static inline bool IsOnSnow(TileIndex t)
00429 {
00430 return HasBit(_me[t].m7, 5);
00431 }
00432
00434 #define ToggleDesert ToggleSnow
00435
00439 static inline void ToggleSnow(TileIndex t)
00440 {
00441 ToggleBit(_me[t].m7, 5);
00442 }
00443
00444
00446 enum Roadside {
00447 ROADSIDE_BARREN = 0,
00448 ROADSIDE_GRASS = 1,
00449 ROADSIDE_PAVED = 2,
00450 ROADSIDE_STREET_LIGHTS = 3,
00451 ROADSIDE_TREES = 5,
00452 ROADSIDE_GRASS_ROAD_WORKS = 6,
00453 ROADSIDE_PAVED_ROAD_WORKS = 7
00454 };
00455
00461 static inline Roadside GetRoadside(TileIndex tile)
00462 {
00463 return (Roadside)GB(_m[tile].m6, 3, 3);
00464 }
00465
00471 static inline void SetRoadside(TileIndex tile, Roadside s)
00472 {
00473 SB(_m[tile].m6, 3, 3, s);
00474 }
00475
00481 static inline bool HasRoadWorks(TileIndex t)
00482 {
00483 return GetRoadside(t) >= ROADSIDE_GRASS_ROAD_WORKS;
00484 }
00485
00491 static inline bool IncreaseRoadWorksCounter(TileIndex t)
00492 {
00493 AB(_me[t].m7, 0, 4, 1);
00494
00495 return GB(_me[t].m7, 0, 4) == 15;
00496 }
00497
00503 static inline void StartRoadWorks(TileIndex t)
00504 {
00505 assert(!HasRoadWorks(t));
00506
00507 switch (GetRoadside(t)) {
00508 case ROADSIDE_BARREN:
00509 case ROADSIDE_GRASS: SetRoadside(t, ROADSIDE_GRASS_ROAD_WORKS); break;
00510 default: SetRoadside(t, ROADSIDE_PAVED_ROAD_WORKS); break;
00511 }
00512 }
00513
00519 static inline void TerminateRoadWorks(TileIndex t)
00520 {
00521 assert(HasRoadWorks(t));
00522 SetRoadside(t, (Roadside)(GetRoadside(t) - ROADSIDE_GRASS_ROAD_WORKS + ROADSIDE_GRASS));
00523
00524 SB(_me[t].m7, 0, 4, 0);
00525 }
00526
00527
00533 static inline DiagDirection GetRoadDepotDirection(TileIndex t)
00534 {
00535 assert(IsRoadDepot(t));
00536 return (DiagDirection)GB(_m[t].m5, 0, 2);
00537 }
00538
00539
00540 RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt, bool straight_tunnel_bridge_entrance = false);
00541
00542
00552 static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram)
00553 {
00554 SetTileType(t, MP_ROAD);
00555 SetTileOwner(t, road);
00556 _m[t].m2 = town;
00557 _m[t].m3 = (HasBit(rot, ROADTYPE_TRAM) ? bits : 0);
00558 _m[t].m4 = 0;
00559 _m[t].m5 = (HasBit(rot, ROADTYPE_ROAD) ? bits : 0) | ROAD_TILE_NORMAL << 6;
00560 SB(_m[t].m6, 2, 4, 0);
00561 _me[t].m7 = rot << 6;
00562 SetRoadOwner(t, ROADTYPE_TRAM, tram);
00563 }
00564
00576 static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner rail, Axis roaddir, RailType rat, RoadTypes rot, uint town)
00577 {
00578 SetTileType(t, MP_ROAD);
00579 SetTileOwner(t, rail);
00580 _m[t].m2 = town;
00581 _m[t].m3 = rat;
00582 _m[t].m4 = 0;
00583 _m[t].m5 = ROAD_TILE_CROSSING << 6 | roaddir;
00584 SB(_m[t].m6, 2, 4, 0);
00585 _me[t].m7 = rot << 6 | road;
00586 SetRoadOwner(t, ROADTYPE_TRAM, tram);
00587 }
00588
00597 static inline void MakeRoadDepot(TileIndex t, Owner owner, DepotID did, DiagDirection dir, RoadType rt)
00598 {
00599 SetTileType(t, MP_ROAD);
00600 SetTileOwner(t, owner);
00601 _m[t].m2 = did;
00602 _m[t].m3 = 0;
00603 _m[t].m4 = 0;
00604 _m[t].m5 = ROAD_TILE_DEPOT << 6 | dir;
00605 SB(_m[t].m6, 2, 4, 0);
00606 _me[t].m7 = RoadTypeToRoadTypes(rt) << 6 | owner;
00607 SetRoadOwner(t, ROADTYPE_TRAM, owner);
00608 }
00609
00610 #endif