* Generate the RoadBits of a grid tile. * * @param t The current town. * @param tile The tile in reference to the town. * @param dir The direction to which we are growing. * @return The RoadBit of the current tile regarding the selected town layout. */
| 1152 | * @return The RoadBit of the current tile regarding the selected town layout. |
| 1153 | */ |
| 1154 | static RoadBits GetTownRoadGridElement(Town *t, TileIndex tile, DiagDirection dir) |
| 1155 | { |
| 1156 | /* align the grid to the downtown */ |
| 1157 | TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile); // Vector from downtown to the tile |
| 1158 | RoadBits rcmd = ROAD_NONE; |
| 1159 | |
| 1160 | switch (t->layout) { |
| 1161 | default: NOT_REACHED(); |
| 1162 | |
| 1163 | case TL_2X2_GRID: |
| 1164 | if ((grid_pos.x % 3) == 0) rcmd |= ROAD_Y; |
| 1165 | if ((grid_pos.y % 3) == 0) rcmd |= ROAD_X; |
| 1166 | break; |
| 1167 | |
| 1168 | case TL_3X3_GRID: |
| 1169 | if ((grid_pos.x % 4) == 0) rcmd |= ROAD_Y; |
| 1170 | if ((grid_pos.y % 4) == 0) rcmd |= ROAD_X; |
| 1171 | break; |
| 1172 | } |
| 1173 | |
| 1174 | /* Optimise only X-junctions */ |
| 1175 | if (rcmd != ROAD_ALL) return rcmd; |
| 1176 | |
| 1177 | RoadBits rb_template; |
| 1178 | |
| 1179 | switch (GetTileSlope(tile)) { |
| 1180 | default: rb_template = ROAD_ALL; break; |
| 1181 | case SLOPE_W: rb_template = ROAD_NW | ROAD_SW; break; |
| 1182 | case SLOPE_SW: rb_template = ROAD_Y | ROAD_SW; break; |
| 1183 | case SLOPE_S: rb_template = ROAD_SW | ROAD_SE; break; |
| 1184 | case SLOPE_SE: rb_template = ROAD_X | ROAD_SE; break; |
| 1185 | case SLOPE_E: rb_template = ROAD_SE | ROAD_NE; break; |
| 1186 | case SLOPE_NE: rb_template = ROAD_Y | ROAD_NE; break; |
| 1187 | case SLOPE_N: rb_template = ROAD_NE | ROAD_NW; break; |
| 1188 | case SLOPE_NW: rb_template = ROAD_X | ROAD_NW; break; |
| 1189 | case SLOPE_STEEP_W: |
| 1190 | case SLOPE_STEEP_S: |
| 1191 | case SLOPE_STEEP_E: |
| 1192 | case SLOPE_STEEP_N: |
| 1193 | rb_template = ROAD_NONE; |
| 1194 | break; |
| 1195 | } |
| 1196 | |
| 1197 | /* Stop if the template is compatible to the growth dir */ |
| 1198 | if (DiagDirToRoadBits(ReverseDiagDir(dir)) & rb_template) return rb_template; |
| 1199 | /* If not generate a straight road in the direction of the growth */ |
| 1200 | return DiagDirToRoadBits(dir) | DiagDirToRoadBits(ReverseDiagDir(dir)); |
| 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * Grows the town with an extra house. |
no test coverage detected