MCPcopy Create free account
hub / github.com/SimHacker/micropolis / layRoad

Method layRoad

MicropolisCore/src/MicropolisEngine/src/connect.cpp:260–343  ·  view source on GitHub ↗

* Lay a road, and update road around it. * @param x X map coordinate. * @param y Y map coordinate. * @param effects Modification collecting object. * @return Tool result. */

Source from the content-addressed store, hash-verified

258 * @return Tool result.
259 */
260ToolResult Micropolis::layRoad(int x, int y, ToolEffects *effects)
261{
262 int cost = 10;
263
264 MapTile tile = effects->getMapTile(x, y);
265
266 switch (tile) {
267
268 case DIRT:
269 effects->setMapValue(x, y, ROADS | BULLBIT | BURNBIT);
270 break;
271
272 case RIVER: /* Road on Water */
273 case REDGE:
274 case CHANNEL: /* Check how to build bridges, if possible. */
275 cost = 50;
276
277 if (x < WORLD_W - 1) {
278 tile = effects->getMapTile(x + 1, y);
279 tile = neutralizeRoad(tile);
280 if (tile == VRAILROAD || tile == HBRIDGE
281 || (tile >= ROADS && tile <= HROADPOWER)) {
282 effects->setMapValue(x, y, HBRIDGE | BULLBIT);
283 break;
284 }
285 }
286
287 if (x > 0) {
288 tile = effects->getMapTile(x - 1, y);
289 tile = neutralizeRoad(tile);
290 if (tile == VRAILROAD || tile == HBRIDGE
291 || (tile >= ROADS && tile <= INTERSECTION)) {
292 effects->setMapValue(x, y, HBRIDGE | BULLBIT);
293 break;
294 }
295 }
296
297 if (y < WORLD_H - 1) {
298 tile = effects->getMapTile(x, y + 1);
299 tile = neutralizeRoad(tile);
300 if (tile == HRAILROAD || tile == VROADPOWER
301 || (tile >= VBRIDGE && tile <= INTERSECTION)) {
302 effects->setMapValue(x, y, VBRIDGE | BULLBIT);
303 break;
304 }
305 }
306
307 if (y > 0) {
308 tile = effects->getMapTile(x, y - 1);
309 tile = neutralizeRoad(tile);
310 if (tile == HRAILROAD || tile == VROADPOWER
311 || (tile >= VBRIDGE && tile <= INTERSECTION)) {
312 effects->setMapValue(x, y, VBRIDGE | BULLBIT);
313 break;
314 }
315 }
316
317 /* Can't do road... */

Callers

nothing calls this directly

Calls 4

neutralizeRoadFunction · 0.85
getMapTileMethod · 0.80
addCostMethod · 0.80
setMapValueMethod · 0.60

Tested by

no test coverage detected