src/road_map.h
branchcpp_gui
changeset 6285 187e3ef04cc9
parent 5726 8f399788f6c9
child 6298 c30fe89622df
equal deleted inserted replaced
6284:45d0233e7d79 6285:187e3ef04cc9
    63 
    63 
    64 // TODO swap owner of road and rail
    64 // TODO swap owner of road and rail
    65 static inline Owner GetCrossingRoadOwner(TileIndex t)
    65 static inline Owner GetCrossingRoadOwner(TileIndex t)
    66 {
    66 {
    67 	assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
    67 	assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
    68 	return (Owner)_m[t].m3;
    68 	return (Owner)_m[t].m4;
    69 }
    69 }
    70 
    70 
    71 static inline void SetCrossingRoadOwner(TileIndex t, Owner o)
    71 static inline void SetCrossingRoadOwner(TileIndex t, Owner o)
    72 {
    72 {
    73 	assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
    73 	assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
    74 	_m[t].m3 = o;
    74 	_m[t].m4 = o;
    75 }
    75 }
    76 
    76 
    77 static inline void UnbarCrossing(TileIndex t)
    77 static inline void UnbarCrossing(TileIndex t)
    78 {
    78 {
    79 	assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
    79 	assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
    93 }
    93 }
    94 
    94 
    95 #define IsOnDesert IsOnSnow
    95 #define IsOnDesert IsOnSnow
    96 static inline bool IsOnSnow(TileIndex t)
    96 static inline bool IsOnSnow(TileIndex t)
    97 {
    97 {
    98 	return HASBIT(_m[t].m4, 7);
    98 	return HASBIT(_m[t].m3, 7);
    99 }
    99 }
   100 
   100 
   101 #define ToggleDesert ToggleSnow
   101 #define ToggleDesert ToggleSnow
   102 static inline void ToggleSnow(TileIndex t)
   102 static inline void ToggleSnow(TileIndex t)
   103 {
   103 {
   104 	TOGGLEBIT(_m[t].m4, 7);
   104 	TOGGLEBIT(_m[t].m3, 7);
   105 }
   105 }
   106 
   106 
   107 
   107 
   108 typedef enum Roadside {
   108 typedef enum Roadside {
   109 	ROADSIDE_BARREN           = 0,
   109 	ROADSIDE_BARREN           = 0,
   115 	ROADSIDE_PAVED_ROAD_WORKS = 7
   115 	ROADSIDE_PAVED_ROAD_WORKS = 7
   116 } Roadside;
   116 } Roadside;
   117 
   117 
   118 static inline Roadside GetRoadside(TileIndex tile)
   118 static inline Roadside GetRoadside(TileIndex tile)
   119 {
   119 {
   120 	return (Roadside)GB(_m[tile].m4, 4, 3);
   120 	return (Roadside)GB(_m[tile].m3, 4, 3);
   121 }
   121 }
   122 
   122 
   123 static inline void SetRoadside(TileIndex tile, Roadside s)
   123 static inline void SetRoadside(TileIndex tile, Roadside s)
   124 {
   124 {
   125 	SB(_m[tile].m4, 4, 3, s);
   125 	SB(_m[tile].m3, 4, 3, s);
   126 }
   126 }
   127 
   127 
   128 static inline bool HasRoadWorks(TileIndex t)
   128 static inline bool HasRoadWorks(TileIndex t)
   129 {
   129 {
   130 	return GetRoadside(t) >= ROADSIDE_GRASS_ROAD_WORKS;
   130 	return GetRoadside(t) >= ROADSIDE_GRASS_ROAD_WORKS;
   131 }
   131 }
   132 
   132 
   133 static inline bool IncreaseRoadWorksCounter(TileIndex t)
   133 static inline bool IncreaseRoadWorksCounter(TileIndex t)
   134 {
   134 {
   135 	AB(_m[t].m4, 0, 4, 1);
   135 	AB(_m[t].m3, 0, 4, 1);
   136 
   136 
   137 	return GB(_m[t].m4, 0, 4) == 15;
   137 	return GB(_m[t].m3, 0, 4) == 15;
   138 }
   138 }
   139 
   139 
   140 static inline void StartRoadWorks(TileIndex t)
   140 static inline void StartRoadWorks(TileIndex t)
   141 {
   141 {
   142 	assert(!HasRoadWorks(t));
   142 	assert(!HasRoadWorks(t));
   151 static inline void TerminateRoadWorks(TileIndex t)
   151 static inline void TerminateRoadWorks(TileIndex t)
   152 {
   152 {
   153 	assert(HasRoadWorks(t));
   153 	assert(HasRoadWorks(t));
   154 	SetRoadside(t, (Roadside)(GetRoadside(t) - ROADSIDE_GRASS_ROAD_WORKS + ROADSIDE_GRASS));
   154 	SetRoadside(t, (Roadside)(GetRoadside(t) - ROADSIDE_GRASS_ROAD_WORKS + ROADSIDE_GRASS));
   155 	/* Stop the counter */
   155 	/* Stop the counter */
   156 	SB(_m[t].m4, 0, 4, 0);
   156 	SB(_m[t].m3, 0, 4, 0);
   157 }
   157 }
   158 
   158 
   159 
   159 
   160 static inline DiagDirection GetRoadDepotDirection(TileIndex t)
   160 static inline DiagDirection GetRoadDepotDirection(TileIndex t)
   161 {
   161 {
   181 static inline void MakeRoadNormal(TileIndex t, Owner owner, RoadBits bits, TownID town)
   181 static inline void MakeRoadNormal(TileIndex t, Owner owner, RoadBits bits, TownID town)
   182 {
   182 {
   183 	SetTileType(t, MP_STREET);
   183 	SetTileType(t, MP_STREET);
   184 	SetTileOwner(t, owner);
   184 	SetTileOwner(t, owner);
   185 	_m[t].m2 = town;
   185 	_m[t].m2 = town;
   186 	_m[t].m3 = 0;
   186 	_m[t].m3 = 0 << 7 | 0 << 4 | 0;
   187 	_m[t].m4 = 0 << 7 | 0 << 4 | 0;
   187 	_m[t].m4 = 0;
   188 	_m[t].m5 = ROAD_TILE_NORMAL << 4 | bits;
   188 	_m[t].m5 = ROAD_TILE_NORMAL << 4 | bits;
   189 }
   189 }
   190 
   190 
   191 
   191 
   192 static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner rail, Axis roaddir, RailType rt, uint town)
   192 static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner rail, Axis roaddir, RailType rt, uint town)
   193 {
   193 {
   194 	SetTileType(t, MP_STREET);
   194 	SetTileType(t, MP_STREET);
   195 	SetTileOwner(t, rail);
   195 	SetTileOwner(t, rail);
   196 	_m[t].m2 = town;
   196 	_m[t].m2 = town;
   197 	_m[t].m3 = road;
   197 	_m[t].m3 = 0 << 7 | 0 << 4 | rt;
   198 	_m[t].m4 = 0 << 7 | 0 << 4 | rt;
   198 	_m[t].m4 = road;
   199 	_m[t].m5 = ROAD_TILE_CROSSING << 4 | roaddir << 3 | 0 << 2;
   199 	_m[t].m5 = ROAD_TILE_CROSSING << 4 | roaddir << 3 | 0 << 2;
   200 }
   200 }
   201 
   201 
   202 
   202 
   203 static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir)
   203 static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir)