tunnelbridge_cmd.c
changeset 3189 bf047128dee7
parent 3188 d1316a266fa8
child 3190 c80d3e9b7c03
equal deleted inserted replaced
3188:d1316a266fa8 3189:bf047128dee7
     5  * @todo seperate this file into two
     5  * @todo seperate this file into two
     6  */
     6  */
     7 
     7 
     8 #include "stdafx.h"
     8 #include "stdafx.h"
     9 #include "openttd.h"
     9 #include "openttd.h"
       
    10 #include "bridge_map.h"
    10 #include "rail_map.h"
    11 #include "rail_map.h"
    11 #include "road_map.h"
    12 #include "road_map.h"
    12 #include "table/sprites.h"
    13 #include "table/sprites.h"
    13 #include "table/strings.h"
    14 #include "table/strings.h"
    14 #include "functions.h"
    15 #include "functions.h"
   332 
   333 
   333 	tile = ti_start.tile;
   334 	tile = ti_start.tile;
   334 	delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
   335 	delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
   335 	for (i = 0; i != bridge_len; i++) {
   336 	for (i = 0; i != bridge_len; i++) {
   336 		TransportType transport_under;
   337 		TransportType transport_under;
       
   338 		Owner owner_under = OWNER_NONE;
       
   339 		RailType rail_under = INVALID_RAILTYPE;
   337 		uint z;
   340 		uint z;
   338 
   341 
   339 		tile += delta;
   342 		tile += delta;
   340 
   343 
   341 		if (GetTileSlope(tile, &z) != 0 && z >= ti_start.z) {
   344 		if (GetTileSlope(tile, &z) != 0 && z >= ti_start.z) {
   352 			case MP_RAILWAY:
   355 			case MP_RAILWAY:
   353 				if (_m[tile].m5 != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) {
   356 				if (_m[tile].m5 != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) {
   354 					goto not_valid_below;
   357 					goto not_valid_below;
   355 				}
   358 				}
   356 				transport_under = TRANSPORT_RAIL;
   359 				transport_under = TRANSPORT_RAIL;
       
   360 				owner_under = GetTileOwner(tile);
       
   361 				rail_under = GB(_m[tile].m3, 0, 4);
   357 				break;
   362 				break;
   358 
   363 
   359 			case MP_STREET:
   364 			case MP_STREET:
   360 				if (GetRoadType(tile) != ROAD_NORMAL ||
   365 				if (GetRoadType(tile) != ROAD_NORMAL ||
   361 						GetRoadBits(tile) != (direction == AXIS_X ? ROAD_Y : ROAD_X)) {
   366 						GetRoadBits(tile) != (direction == AXIS_X ? ROAD_Y : ROAD_X)) {
   362 					goto not_valid_below;
   367 					goto not_valid_below;
   363 				}
   368 				}
   364 				transport_under = TRANSPORT_ROAD;
   369 				transport_under = TRANSPORT_ROAD;
       
   370 				owner_under = GetTileOwner(tile);
   365 				break;
   371 				break;
   366 
   372 
   367 			default:
   373 			default:
   368 not_valid_below:;
   374 not_valid_below:;
   369 				/* try and clear the middle landscape */
   375 				/* try and clear the middle landscape */
   406 			}
   412 			}
   407 
   413 
   408 			_m[tile].m2 = (bridge_type << 4) | piece;
   414 			_m[tile].m2 = (bridge_type << 4) | piece;
   409 			SB(_m[tile].m3, 4, 4, railtype);
   415 			SB(_m[tile].m3, 4, 4, railtype);
   410 			switch (transport_under) {
   416 			switch (transport_under) {
   411 				case TRANSPORT_RAIL:  _m[tile].m5 = 0xE0 | TRANSPORT_RAIL << 3 | transport << 1 | direction; break; // rail
   417 				case TRANSPORT_RAIL:  SetRailUnderBridge(tile, owner_under, rail_under); break;
   412 				case TRANSPORT_ROAD:  _m[tile].m5 = 0xE0 | TRANSPORT_ROAD << 3 | transport << 1 | direction; break; // road
   418 				case TRANSPORT_ROAD:  SetRoadUnderBridge(tile, owner_under); break;
   413 				case TRANSPORT_WATER: _m[tile].m5 = 0xC0 |              1 << 3 | transport << 1 | direction; break; // water
   419 				case TRANSPORT_WATER: SetWaterUnderBridge(tile); break;
   414 				default:              _m[tile].m5 = 0xC0 |              0 << 3 | transport << 1 | direction; break; // grass
   420 				default:              SetClearUnderBridge(tile); break;
   415 			}
   421 			}
   416 
   422 
   417 			MarkTileDirtyByTile(tile);
   423 			MarkTileDirtyByTile(tile);
   418 		}
   424 		}
   419 	}
   425 	}
   642 			return CMD_ERROR;
   648 			return CMD_ERROR;
   643 
   649 
   644 		cost = (_m[tile].m5 & 8) ? _price.remove_road * 2 : _price.remove_rail;
   650 		cost = (_m[tile].m5 & 8) ? _price.remove_road * 2 : _price.remove_rail;
   645 
   651 
   646 		if (flags & DC_EXEC) {
   652 		if (flags & DC_EXEC) {
   647 			_m[tile].m5 = _m[tile].m5 & ~0x38;
   653 			SetClearUnderBridge(tile);
   648 			SetTileOwner(tile, OWNER_NONE);
       
   649 			MarkTileDirtyByTile(tile);
   654 			MarkTileDirtyByTile(tile);
   650 		}
   655 		}
   651 		return cost;
   656 		return cost;
   652 
   657 
   653 	/* delete canal under bridge */
   658 	/* delete canal under bridge */
   656 
   661 
   657 		// check for vehicles under bridge
   662 		// check for vehicles under bridge
   658 		if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR;
   663 		if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR;
   659 		cost = _price.clear_water;
   664 		cost = _price.clear_water;
   660 		if (flags & DC_EXEC) {
   665 		if (flags & DC_EXEC) {
   661 			_m[tile].m5 = _m[tile].m5 & ~0x38;
   666 			SetClearUnderBridge(tile);
   662 			SetTileOwner(tile, OWNER_NONE);
       
   663 			MarkTileDirtyByTile(tile);
   667 			MarkTileDirtyByTile(tile);
   664 		}
   668 		}
   665 		return cost;
   669 		return cost;
   666 	}
   670 	}
   667 
   671 
  1353 	}	else {
  1357 	}	else {
  1354 		if ((_m[tile].m5 & 0xC0) == 0xC0) {
  1358 		if ((_m[tile].m5 & 0xC0) == 0xC0) {
  1355 			// the stuff BELOW the middle part is owned by the deleted player.
  1359 			// the stuff BELOW the middle part is owned by the deleted player.
  1356 			if (!(_m[tile].m5 & (1 << 4 | 1 << 3))) {
  1360 			if (!(_m[tile].m5 & (1 << 4 | 1 << 3))) {
  1357 				// convert railway into grass.
  1361 				// convert railway into grass.
  1358 				_m[tile].m5 &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore..
  1362 				SetClearUnderBridge(tile);
  1359 			} else {
  1363 			} else {
  1360 				// for road, change the owner of the road to local authority
  1364 				// for road, change the owner of the road to local authority
  1361 				SetTileOwner(tile, OWNER_NONE);
  1365 				SetTileOwner(tile, OWNER_NONE);
  1362 			}
  1366 			}
  1363 		} else {
  1367 		} else {