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 switch (rt) {
00202 default: NOT_REACHED();
00203 case ROADTYPE_ROAD: return (Owner)GB(IsNormalRoadTile(t) ? _m[t].m1 : _me[t].m7, 0, 5);
00204 case ROADTYPE_TRAM: {
00205
00206
00207 Owner o = (Owner)GB(_m[t].m3, 4, 4);
00208 return o == OWNER_TOWN ? OWNER_NONE : o;
00209 }
00210 }
00211 }
00212
00219 static inline void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
00220 {
00221 switch (rt) {
00222 default: NOT_REACHED();
00223 case ROADTYPE_ROAD: SB(IsNormalRoadTile(t) ? _m[t].m1 : _me[t].m7, 0, 5, o); break;
00224 case ROADTYPE_TRAM: SB(_m[t].m3, 4, 4, o == OWNER_NONE ? OWNER_TOWN : o); break;
00225 }
00226 }
00227
00236 static inline bool IsRoadOwner(TileIndex t, RoadType rt, Owner o)
00237 {
00238 assert(HasTileRoadType(t, rt));
00239 return (GetRoadOwner(t, rt) == o);
00240 }
00241
00248 static inline bool HasTownOwnedRoad(TileIndex t)
00249 {
00250 return HasTileRoadType(t, ROADTYPE_ROAD) && IsRoadOwner(t, ROADTYPE_ROAD, OWNER_TOWN);
00251 }
00252
00254 enum DisallowedRoadDirections {
00255 DRD_NONE,
00256 DRD_SOUTHBOUND,
00257 DRD_NORTHBOUND,
00258 DRD_BOTH,
00259 DRD_END
00260 };
00261 DECLARE_ENUM_AS_BIT_SET(DisallowedRoadDirections)
00262 template <> struct EnumPropsT<DisallowedRoadDirections> : MakeEnumPropsT<DisallowedRoadDirections, byte, DRD_NONE, DRD_END, DRD_END, 2> {};
00263
00269 static inline DisallowedRoadDirections GetDisallowedRoadDirections(TileIndex t)
00270 {
00271 assert(IsNormalRoad(t));
00272 return (DisallowedRoadDirections)GB(_m[t].m5, 4, 2);
00273 }
00274
00280 static inline void SetDisallowedRoadDirections(TileIndex t, DisallowedRoadDirections drd)
00281 {
00282 assert(IsNormalRoad(t));
00283 assert(drd < DRD_END);
00284 SB(_m[t].m5, 4, 2, drd);
00285 }
00286
00293 static inline Axis GetCrossingRoadAxis(TileIndex t)
00294 {
00295 assert(IsLevelCrossing(t));
00296 return (Axis)GB(_m[t].m5, 0, 1);
00297 }
00298
00305 static inline Axis GetCrossingRailAxis(TileIndex t)
00306 {
00307 assert(IsLevelCrossing(t));
00308 return OtherAxis((Axis)GetCrossingRoadAxis(t));
00309 }
00310
00316 static inline RoadBits GetCrossingRoadBits(TileIndex tile)
00317 {
00318 return GetCrossingRoadAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y;
00319 }
00320
00326 static inline Track GetCrossingRailTrack(TileIndex tile)
00327 {
00328 return AxisToTrack(GetCrossingRailAxis(tile));
00329 }
00330
00336 static inline TrackBits GetCrossingRailBits(TileIndex tile)
00337 {
00338 return AxisToTrackBits(GetCrossingRailAxis(tile));
00339 }
00340
00341
00348 static inline bool HasCrossingReservation(TileIndex t)
00349 {
00350 assert(IsLevelCrossingTile(t));
00351 return HasBit(_m[t].m5, 4);
00352 }
00353
00361 static inline void SetCrossingReservation(TileIndex t, bool b)
00362 {
00363 assert(IsLevelCrossingTile(t));
00364 SB(_m[t].m5, 4, 1, b ? 1 : 0);
00365 }
00366
00373 static inline TrackBits GetCrossingReservationTrackBits(TileIndex t)
00374 {
00375 return HasCrossingReservation(t) ? GetCrossingRailBits(t) : TRACK_BIT_NONE;
00376 }
00377
00384 static inline bool IsCrossingBarred(TileIndex t)
00385 {
00386 assert(IsLevelCrossing(t));
00387 return HasBit(_m[t].m5, 5);
00388 }
00389
00396 static inline void SetCrossingBarred(TileIndex t, bool barred)
00397 {
00398 assert(IsLevelCrossing(t));
00399 SB(_m[t].m5, 5, 1, barred ? 1 : 0);
00400 }
00401
00406 static inline void UnbarCrossing(TileIndex t)
00407 {
00408 SetCrossingBarred(t, false);
00409 }
00410
00415 static inline void BarCrossing(TileIndex t)
00416 {
00417 SetCrossingBarred(t, true);
00418 }
00419
00421 #define IsOnDesert IsOnSnow
00422
00427 static inline bool IsOnSnow(TileIndex t)
00428 {
00429 return HasBit(_me[t].m7, 5);
00430 }
00431
00433 #define ToggleDesert ToggleSnow
00434
00438 static inline void ToggleSnow(TileIndex t)
00439 {
00440 ToggleBit(_me[t].m7, 5);
00441 }
00442
00443
00445 enum Roadside {
00446 ROADSIDE_BARREN = 0,
00447 ROADSIDE_GRASS = 1,
00448 ROADSIDE_PAVED = 2,
00449 ROADSIDE_STREET_LIGHTS = 3,
00450 ROADSIDE_TREES = 5,
00451 ROADSIDE_GRASS_ROAD_WORKS = 6,
00452 ROADSIDE_PAVED_ROAD_WORKS = 7
00453 };
00454
00460 static inline Roadside GetRoadside(TileIndex tile)
00461 {
00462 return (Roadside)GB(_m[tile].m6, 3, 3);
00463 }
00464
00470 static inline void SetRoadside(TileIndex tile, Roadside s)
00471 {
00472 SB(_m[tile].m6, 3, 3, s);
00473 }
00474
00480 static inline bool HasRoadWorks(TileIndex t)
00481 {
00482 return GetRoadside(t) >= ROADSIDE_GRASS_ROAD_WORKS;
00483 }
00484
00490 static inline bool IncreaseRoadWorksCounter(TileIndex t)
00491 {
00492 AB(_me[t].m7, 0, 4, 1);
00493
00494 return GB(_me[t].m7, 0, 4) == 15;
00495 }
00496
00502 static inline void StartRoadWorks(TileIndex t)
00503 {
00504 assert(!HasRoadWorks(t));
00505
00506 switch (GetRoadside(t)) {
00507 case ROADSIDE_BARREN:
00508 case ROADSIDE_GRASS: SetRoadside(t, ROADSIDE_GRASS_ROAD_WORKS); break;
00509 default: SetRoadside(t, ROADSIDE_PAVED_ROAD_WORKS); break;
00510 }
00511 }
00512
00518 static inline void TerminateRoadWorks(TileIndex t)
00519 {
00520 assert(HasRoadWorks(t));
00521 SetRoadside(t, (Roadside)(GetRoadside(t) - ROADSIDE_GRASS_ROAD_WORKS + ROADSIDE_GRASS));
00522
00523 SB(_me[t].m7, 0, 4, 0);
00524 }
00525
00526
00532 static inline DiagDirection GetRoadDepotDirection(TileIndex t)
00533 {
00534 assert(IsRoadDepot(t));
00535 return (DiagDirection)GB(_m[t].m5, 0, 2);
00536 }
00537
00538
00555 RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt, bool straight_tunnel_bridge_entrance = false);
00556
00557
00567 static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram)
00568 {
00569 SetTileType(t, MP_ROAD);
00570 SetTileOwner(t, road);
00571 _m[t].m2 = town;
00572 _m[t].m3 = (HasBit(rot, ROADTYPE_TRAM) ? bits : 0);
00573 _m[t].m4 = 0;
00574 _m[t].m5 = (HasBit(rot, ROADTYPE_ROAD) ? bits : 0) | ROAD_TILE_NORMAL << 6;
00575 SB(_m[t].m6, 2, 4, 0);
00576 _me[t].m7 = rot << 6;
00577 SetRoadOwner(t, ROADTYPE_TRAM, tram);
00578 }
00579
00591 static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner rail, Axis roaddir, RailType rat, RoadTypes rot, uint town)
00592 {
00593 SetTileType(t, MP_ROAD);
00594 SetTileOwner(t, rail);
00595 _m[t].m2 = town;
00596 _m[t].m3 = rat;
00597 _m[t].m4 = 0;
00598 _m[t].m5 = ROAD_TILE_CROSSING << 6 | roaddir;
00599 SB(_m[t].m6, 2, 4, 0);
00600 _me[t].m7 = rot << 6 | road;
00601 SetRoadOwner(t, ROADTYPE_TRAM, tram);
00602 }
00603
00612 static inline void MakeRoadDepot(TileIndex t, Owner owner, DepotID did, DiagDirection dir, RoadType rt)
00613 {
00614 SetTileType(t, MP_ROAD);
00615 SetTileOwner(t, owner);
00616 _m[t].m2 = did;
00617 _m[t].m3 = 0;
00618 _m[t].m4 = 0;
00619 _m[t].m5 = ROAD_TILE_DEPOT << 6 | dir;
00620 SB(_m[t].m6, 2, 4, 0);
00621 _me[t].m7 = RoadTypeToRoadTypes(rt) << 6 | owner;
00622 SetRoadOwner(t, ROADTYPE_TRAM, owner);
00623 }
00624
00625 #endif