diff options
-rw-r--r-- | bridge_map.h | 26 | ||||
-rw-r--r-- | clear_map.h | 91 | ||||
-rw-r--r-- | industry_map.h | 8 | ||||
-rw-r--r-- | road_map.h | 49 | ||||
-rw-r--r-- | station_map.h | 12 | ||||
-rw-r--r-- | town_map.h | 1 | ||||
-rw-r--r-- | tree_map.h | 87 | ||||
-rw-r--r-- | tunnel_map.h | 3 | ||||
-rw-r--r-- | unmovable_map.h | 2 |
9 files changed, 228 insertions, 51 deletions
diff --git a/bridge_map.h b/bridge_map.h index 014a3671c..485935fbf 100644 --- a/bridge_map.h +++ b/bridge_map.h @@ -13,6 +13,7 @@ static inline bool IsBridge(TileIndex t) { + assert(IsTileType(t, MP_TUNNELBRIDGE)); return HASBIT(_m[t].m5, 7); } @@ -24,11 +25,13 @@ static inline bool IsBridgeTile(TileIndex t) static inline bool IsBridgeRamp(TileIndex t) { + assert(IsBridgeTile(t)); return !HASBIT(_m[t].m5, 6); } static inline bool IsBridgeMiddle(TileIndex t) { + assert(IsBridgeTile(t)); return HASBIT(_m[t].m5, 6); } @@ -38,9 +41,10 @@ static inline bool IsBridgeMiddle(TileIndex t) * @param tile The tile to analyze * @return the piece */ -static inline uint GetBridgePiece(TileIndex tile) +static inline uint GetBridgePiece(TileIndex t) { - return GB(_m[tile].m2, 0, 4); + assert(IsBridgeMiddle(t)); + return GB(_m[t].m2, 0, 4); } @@ -49,9 +53,10 @@ static inline uint GetBridgePiece(TileIndex tile) * @param tile The tile to analyze * @return The bridge type */ -static inline uint GetBridgeType(TileIndex tile) +static inline uint GetBridgeType(TileIndex t) { - return GB(_m[tile].m2, 4, 4); + assert(IsBridgeTile(t)); + return GB(_m[t].m2, 4, 4); } @@ -60,6 +65,7 @@ static inline uint GetBridgeType(TileIndex tile) */ static inline DiagDirection GetBridgeRampDirection(TileIndex t) { + assert(IsBridgeRamp(t)); /* Heavy wizardry to convert the X/Y (bit 0) + N/S (bit 5) encoding of * bridges to a DiagDirection */ @@ -69,44 +75,52 @@ static inline DiagDirection GetBridgeRampDirection(TileIndex t) static inline Axis GetBridgeAxis(TileIndex t) { + assert(IsBridgeMiddle(t)); return (Axis)GB(_m[t].m5, 0, 1); } static inline TransportType GetBridgeTransportType(TileIndex t) { + assert(IsBridgeTile(t)); return (TransportType)GB(_m[t].m5, 1, 2); } static inline bool IsClearUnderBridge(TileIndex t) { + assert(IsBridgeMiddle(t)); return GB(_m[t].m5, 3, 3) == 0; } static inline bool IsWaterUnderBridge(TileIndex t) { + assert(IsBridgeMiddle(t)); return GB(_m[t].m5, 3, 3) == 1; } static inline bool IsTransportUnderBridge(TileIndex t) { + assert(IsBridgeMiddle(t)); return HASBIT(_m[t].m5, 5); } static inline TransportType GetTransportTypeUnderBridge(TileIndex t) { + assert(IsTransportUnderBridge(t)); return (TransportType)GB(_m[t].m5, 3, 2); } static inline RoadBits GetRoadBitsUnderBridge(TileIndex t) { + assert(GetTransportTypeUnderBridge(t) == TRANSPORT_ROAD); return GetBridgeAxis(t) == AXIS_X ? ROAD_Y : ROAD_X; } static inline TrackBits GetRailBitsUnderBridge(TileIndex t) { + assert(GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL); return GetBridgeAxis(t) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X; } @@ -131,18 +145,21 @@ uint GetBridgeHeight(TileIndex t); static inline void SetClearUnderBridge(TileIndex t) { + assert(IsBridgeMiddle(t)); SetTileOwner(t, OWNER_NONE); SB(_m[t].m5, 3, 3, 0 << 2 | 0); } static inline void SetWaterUnderBridge(TileIndex t) { + assert(IsBridgeMiddle(t)); SetTileOwner(t, OWNER_WATER); SB(_m[t].m5, 3, 3, 0 << 2 | 1); } static inline void SetRailUnderBridge(TileIndex t, Owner o, RailType r) { + assert(IsBridgeMiddle(t)); SetTileOwner(t, o); SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_RAIL); SB(_m[t].m3, 0, 4, r); @@ -150,6 +167,7 @@ static inline void SetRailUnderBridge(TileIndex t, Owner o, RailType r) static inline void SetRoadUnderBridge(TileIndex t, Owner o) { + assert(IsBridgeMiddle(t)); SetTileOwner(t, o); SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD); } diff --git a/clear_map.h b/clear_map.h index b383e3639..655b0ef06 100644 --- a/clear_map.h +++ b/clear_map.h @@ -18,31 +18,96 @@ typedef enum ClearGround { CL_DESERT = 5 // 1,3 } ClearGround; -static inline ClearGround GetClearGround(TileIndex t) { return GB(_m[t].m5, 2, 3); } -static inline bool IsClearGround(TileIndex t, ClearGround ct) { return GetClearGround(t) == ct; } -static inline void AddClearDensity(TileIndex t, int d) { _m[t].m5 += d; } -static inline uint GetClearDensity(TileIndex t) { return GB(_m[t].m5, 0, 2); } +static inline ClearGround GetClearGround(TileIndex t) +{ + assert(IsTileType(t, MP_CLEAR)); + return GB(_m[t].m5, 2, 3); +} + +static inline bool IsClearGround(TileIndex t, ClearGround ct) +{ + return GetClearGround(t) == ct; +} + + +static inline uint GetClearDensity(TileIndex t) +{ + assert(IsTileType(t, MP_CLEAR)); + return GB(_m[t].m5, 0, 2); +} + +static inline void AddClearDensity(TileIndex t, int d) +{ + assert(IsTileType(t, MP_CLEAR)); // XXX incomplete + _m[t].m5 += d; +} + + +static inline uint GetClearCounter(TileIndex t) +{ + assert(IsTileType(t, MP_CLEAR)); + return GB(_m[t].m5, 5, 3); +} + +static inline void AddClearCounter(TileIndex t, int c) +{ + assert(IsTileType(t, MP_CLEAR)); // XXX incomplete + _m[t].m5 += c << 5; +} + +static inline void SetClearCounter(TileIndex t, uint c) +{ + assert(IsTileType(t, MP_CLEAR)); // XXX incomplete + SB(_m[t].m5, 5, 3, c); +} -static inline void AddClearCounter(TileIndex t, int c) { _m[t].m5 += c << 5; } -static inline uint GetClearCounter(TileIndex t) { return GB(_m[t].m5, 5, 3); } -static inline void SetClearCounter(TileIndex t, uint c) { SB(_m[t].m5, 5, 3, c); } /* Sets type and density in one go, also sets the counter to 0 */ static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density) { + assert(IsTileType(t, MP_CLEAR)); // XXX incomplete _m[t].m5 = 0 << 5 | type << 2 | density; } -static inline uint GetFieldType(TileIndex t) { return GB(_m[t].m3, 0, 4); } -static inline void SetFieldType(TileIndex t, uint f) { SB(_m[t].m3, 0, 4, f); } + +static inline uint GetFieldType(TileIndex t) +{ + assert(GetClearGround(t) == CL_FIELDS); + return GB(_m[t].m3, 0, 4); +} + +static inline void SetFieldType(TileIndex t, uint f) +{ + assert(GetClearGround(t) == CL_FIELDS); // XXX incomplete + SB(_m[t].m3, 0, 4, f); +} + /* Is used by tree tiles, too */ -static inline uint GetFenceSE(TileIndex t) { return GB(_m[t].m4, 2, 3); } -static inline void SetFenceSE(TileIndex t, uint h) { SB(_m[t].m4, 2, 3, h); } +static inline uint GetFenceSE(TileIndex t) +{ + assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); + return GB(_m[t].m4, 2, 3); +} -static inline uint GetFenceSW(TileIndex t) { return GB(_m[t].m4, 5, 3); } -static inline void SetFenceSW(TileIndex t, uint h) { SB(_m[t].m4, 5, 3, h); } +static inline void SetFenceSE(TileIndex t, uint h) +{ + assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete + SB(_m[t].m4, 2, 3, h); +} + +static inline uint GetFenceSW(TileIndex t) +{ + assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); + return GB(_m[t].m4, 5, 3); +} + +static inline void SetFenceSW(TileIndex t, uint h) +{ + assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete + SB(_m[t].m4, 5, 3, h); +} static inline void MakeClear(TileIndex t, ClearGround g, uint density) diff --git a/industry_map.h b/industry_map.h index f42d11833..3726b619c 100644 --- a/industry_map.h +++ b/industry_map.h @@ -7,6 +7,7 @@ static inline uint GetIndustryIndex(TileIndex t) { + assert(IsTileType(t, MP_INDUSTRY)); return _m[t].m2; } @@ -16,19 +17,22 @@ static inline Industry* GetIndustryByTile(TileIndex t) } -static inline bool IsIndustryCompleted(TileIndex tile) +static inline bool IsIndustryCompleted(TileIndex t) { - return HASBIT(_m[tile].m1, 7); + assert(IsTileType(t, MP_INDUSTRY)); + return HASBIT(_m[t].m1, 7); } static inline uint GetIndustryGfx(TileIndex t) { + assert(IsTileType(t, MP_INDUSTRY)); return _m[t].m5; } static inline void SetIndustryGfx(TileIndex t, uint gfx) { + assert(IsTileType(t, MP_INDUSTRY)); _m[t].m5 = gfx; } diff --git a/road_map.h b/road_map.h index 412616a65..e06afcd5c 100644 --- a/road_map.h +++ b/road_map.h @@ -28,20 +28,36 @@ static inline RoadBits DiagDirToRoadBits(DiagDirection d) } -static inline RoadBits GetRoadBits(TileIndex tile) +typedef enum RoadType { + ROAD_NORMAL, + ROAD_CROSSING, + ROAD_DEPOT +} RoadType; + +static inline RoadType GetRoadType(TileIndex t) +{ + assert(IsTileType(t, MP_STREET)); + return GB(_m[t].m5, 4, 4); +} + + +static inline RoadBits GetRoadBits(TileIndex t) { - return GB(_m[tile].m5, 0, 4); + assert(GetRoadType(t) == ROAD_NORMAL); + return GB(_m[t].m5, 0, 4); } -static inline void SetRoadBits(TileIndex tile, RoadBits r) +static inline void SetRoadBits(TileIndex t, RoadBits r) { - SB(_m[tile].m5, 0, 4, r); + assert(GetRoadType(t) == ROAD_NORMAL); // XXX incomplete + SB(_m[t].m5, 0, 4, r); } -static inline Axis GetCrossingRoadAxis(TileIndex tile) +static inline Axis GetCrossingRoadAxis(TileIndex t) { - return (Axis)GB(_m[tile].m5, 3, 1); + assert(GetRoadType(t) == ROAD_CROSSING); + return (Axis)GB(_m[t].m5, 3, 1); } static inline RoadBits GetCrossingRoadBits(TileIndex tile) @@ -58,44 +74,39 @@ static inline TrackBits GetCrossingRailBits(TileIndex tile) // TODO swap owner of road and rail static inline Owner GetCrossingRoadOwner(TileIndex t) { + assert(GetRoadType(t) == ROAD_CROSSING); return (Owner)_m[t].m3; } static inline void SetCrossingRoadOwner(TileIndex t, Owner o) { + assert(GetRoadType(t) == ROAD_CROSSING); _m[t].m3 = o; } static inline void UnbarCrossing(TileIndex t) { + assert(GetRoadType(t) == ROAD_CROSSING); CLRBIT(_m[t].m5, 2); } static inline void BarCrossing(TileIndex t) { + assert(GetRoadType(t) == ROAD_CROSSING); SETBIT(_m[t].m5, 2); } static inline bool IsCrossingBarred(TileIndex t) { + assert(GetRoadType(t) == ROAD_CROSSING); return HASBIT(_m[t].m5, 2); } -typedef enum RoadType { - ROAD_NORMAL, - ROAD_CROSSING, - ROAD_DEPOT -} RoadType; - -static inline RoadType GetRoadType(TileIndex tile) -{ - return GB(_m[tile].m5, 4, 4); -} - -static inline DiagDirection GetRoadDepotDirection(TileIndex tile) +static inline DiagDirection GetRoadDepotDirection(TileIndex t) { - return (DiagDirection)GB(_m[tile].m5, 0, 2); + assert(GetRoadType(t) == ROAD_DEPOT); + return (DiagDirection)GB(_m[t].m5, 0, 2); } diff --git a/station_map.h b/station_map.h index 77d1f435f..0fb8c50b0 100644 --- a/station_map.h +++ b/station_map.h @@ -9,6 +9,7 @@ static inline StationID GetStationIndex(TileIndex t) { + assert(IsTileType(t, MP_STATION)); return (StationID)_m[t].m2; } @@ -68,11 +69,13 @@ static inline RoadStopType GetRoadStopType(TileIndex t) static inline bool IsRailwayStation(TileIndex t) { + assert(IsTileType(t, MP_STATION)); return _m[t].m5 < RAILWAY_BASE + RAILWAY_SIZE; } static inline bool IsHangar(TileIndex t) { + assert(IsTileType(t, MP_STATION)); return _m[t].m5 == HANGAR_TILE_0 || _m[t].m5 == HANGAR_TILE_1 || @@ -81,6 +84,7 @@ static inline bool IsHangar(TileIndex t) static inline bool IsAirport(TileIndex t) { + assert(IsTileType(t, MP_STATION)); return IS_INT_INSIDE(_m[t].m5, AIRPORT_BASE, AIRPORT_BASE + AIRPORT_SIZE) || IS_INT_INSIDE(_m[t].m5, AIRPORT_BASE_EXTENDED, AIRPORT_BASE_EXTENDED + AIRPORT_SIZE_EXTENDED); @@ -88,11 +92,13 @@ static inline bool IsAirport(TileIndex t) static inline bool IsTruckStop(TileIndex t) { + assert(IsTileType(t, MP_STATION)); return IS_INT_INSIDE(_m[t].m5, TRUCK_BASE, TRUCK_BASE + TRUCK_SIZE); } static inline bool IsBusStop(TileIndex t) { + assert(IsTileType(t, MP_STATION)); return IS_INT_INSIDE(_m[t].m5, BUS_BASE, BUS_BASE + BUS_SIZE); } @@ -103,16 +109,19 @@ static inline bool IsRoadStop(TileIndex t) static inline bool IsOilRig(TileIndex t) { + assert(IsTileType(t, MP_STATION)); return _m[t].m5 == OILRIG_BASE; } static inline bool IsDock(TileIndex t) { + assert(IsTileType(t, MP_STATION)); return IS_INT_INSIDE(_m[t].m5, DOCK_BASE, DOCK_BASE + DOCK_SIZE_TOTAL); } static inline bool IsBuoy_(TileIndex t) // XXX _ due to naming conflict { + assert(IsTileType(t, MP_STATION)); return _m[t].m5 == BUOY_BASE; } @@ -147,17 +156,20 @@ static inline DiagDirection GetDockDirection(TileIndex t) static inline bool IsCustomStationSprite(TileIndex t) { + assert(IsTileType(t, MP_STATION)); return HASBIT(_m[t].m3, 4); } static inline void SetCustomStationSprite(TileIndex t, byte sprite) { + assert(IsTileType(t, MP_STATION)); SETBIT(_m[t].m3, 4); _m[t].m4 = sprite; } static inline uint GetCustomStationSprite(TileIndex t) { + assert(IsTileType(t, MP_STATION)); return _m[t].m4; } diff --git a/town_map.h b/town_map.h index 364d0047f..98b97007d 100644 --- a/town_map.h +++ b/town_map.h @@ -5,6 +5,7 @@ static inline uint GetTownIndex(TileIndex t) { + assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_STREET)); // XXX incomplete return _m[t].m2; } diff --git a/tree_map.h b/tree_map.h index c53ad05e8..bc35b98b7 100644 --- a/tree_map.h +++ b/tree_map.h @@ -31,30 +31,91 @@ typedef enum TreeGround { TR_SNOW_DESERT = 2 // 0-3 for snow, 3 for desert } TreeGround; -static inline TreeType GetTreeType(TileIndex t) { return _m[t].m3; } -static inline void SetTreeType(TileIndex t, TreeType r) { _m[t].m3 = r; } -static inline TreeGround GetTreeGround(TileIndex t) { return GB(_m[t].m2, 4, 2); } +static inline TreeType GetTreeType(TileIndex t) +{ + assert(IsTileType(t, MP_TREES)); + return _m[t].m3; +} + + +static inline TreeGround GetTreeGround(TileIndex t) +{ + assert(IsTileType(t, MP_TREES)); + return GB(_m[t].m2, 4, 2); +} + + +static inline uint GetTreeDensity(TileIndex t) +{ + assert(IsTileType(t, MP_TREES)); + return GB(_m[t].m2, 6, 2); +} -static inline uint GetTreeDensity(TileIndex t) { return GB(_m[t].m2, 6, 2); } static inline void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d) { + assert(IsTileType(t, MP_TREES)); // XXX incomplete SB(_m[t].m2, 4, 2, g); SB(_m[t].m2, 6, 2, d); } -static inline void AddTreeCount(TileIndex t, int c) { _m[t].m5 += c << 6; } -static inline uint GetTreeCount(TileIndex t) { return GB(_m[t].m5, 6, 2); } -static inline void SetTreeCount(TileIndex t, uint c) { SB(_m[t].m5, 6, 2, c); } -static inline void AddTreeGrowth(TileIndex t, int a) { _m[t].m5 += a; } -static inline uint GetTreeGrowth(TileIndex t) { return GB(_m[t].m5, 0, 3); } -static inline void SetTreeGrowth(TileIndex t, uint g) { SB(_m[t].m5, 0, 3, g); } +static inline uint GetTreeCount(TileIndex t) +{ + assert(IsTileType(t, MP_TREES)); + return GB(_m[t].m5, 6, 2); +} + +static inline void AddTreeCount(TileIndex t, int c) +{ + assert(IsTileType(t, MP_TREES)); // XXX incomplete + _m[t].m5 += c << 6; +} + +static inline void SetTreeCount(TileIndex t, uint c) +{ + assert(IsTileType(t, MP_TREES)); // XXX incomplete + SB(_m[t].m5, 6, 2, c); +} + -static inline void AddTreeCounter(TileIndex t, int a) { _m[t].m2 += a; } -static inline uint GetTreeCounter(TileIndex t) { return GB(_m[t].m2, 0, 4); } -static inline void SetTreeCounter(TileIndex t, uint c) { SB(_m[t].m2, 0, 4, c); } +static inline uint GetTreeGrowth(TileIndex t) +{ + assert(IsTileType(t, MP_TREES)); + return GB(_m[t].m5, 0, 3); +} + +static inline void AddTreeGrowth(TileIndex t, int a) +{ + assert(IsTileType(t, MP_TREES)); // XXX incomplete + _m[t].m5 += a; +} + +static inline void SetTreeGrowth(TileIndex t, uint g) +{ + assert(IsTileType(t, MP_TREES)); // XXX incomplete + SB(_m[t].m5, 0, 3, g); +} + + +static inline uint GetTreeCounter(TileIndex t) +{ + assert(IsTileType(t, MP_TREES)); + return GB(_m[t].m2, 0, 4); +} + +static inline void AddTreeCounter(TileIndex t, int a) +{ + assert(IsTileType(t, MP_TREES)); // XXX incomplete + _m[t].m2 += a; +} + +static inline void SetTreeCounter(TileIndex t, uint c) +{ + assert(IsTileType(t, MP_TREES)); // XXX incomplete + SB(_m[t].m2, 0, 4, c); +} static inline void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density) diff --git a/tunnel_map.h b/tunnel_map.h index 6ac6cb44b..67c1fa94f 100644 --- a/tunnel_map.h +++ b/tunnel_map.h @@ -11,6 +11,7 @@ static inline bool IsTunnel(TileIndex t) { + assert(IsTileType(t, MP_TUNNELBRIDGE)); return !HASBIT(_m[t].m5, 7); } @@ -23,12 +24,14 @@ static inline bool IsTunnelTile(TileIndex t) static inline DiagDirection GetTunnelDirection(TileIndex t) { + assert(IsTunnelTile(t)); return (DiagDirection)GB(_m[t].m5, 0, 2); } static inline TransportType GetTunnelTransportType(TileIndex t) { + assert(IsTunnelTile(t)); return (TransportType)GB(_m[t].m5, 2, 2); } diff --git a/unmovable_map.h b/unmovable_map.h index 32375c2cd..5f4b2b329 100644 --- a/unmovable_map.h +++ b/unmovable_map.h @@ -10,6 +10,7 @@ typedef enum UnmovableType { static inline UnmovableType GetUnmovableType(TileIndex t) { + assert(IsTileType(t, MP_UNMOVABLE)); return _m[t].m5; } @@ -24,6 +25,7 @@ static inline bool IsTransmitterTile(TileIndex t) static inline bool IsOwnedLand(TileIndex t) { + assert(IsTileType(t, MP_UNMOVABLE)); return GetUnmovableType(t) == UNMOVABLE_OWNED_LAND; } |