tunnelbridge_cmd.c
changeset 1035 812f837ee03f
parent 1005 f48b2bdd84fc
child 1041 94db182c3614
equal deleted inserted replaced
1034:e761d474e204 1035:812f837ee03f
   591 	int delta = TileOffsByDir(m5 & 3);
   591 	int delta = TileOffsByDir(m5 & 3);
   592 	int len = 0;
   592 	int len = 0;
   593 	uint starttile = tile;
   593 	uint starttile = tile;
   594 	Vehicle *v;
   594 	Vehicle *v;
   595 
   595 
   596 	do { tile += delta; len++; } while (!IS_TILETYPE(tile, MP_TUNNELBRIDGE) || _map5[tile]&0xF0 || (byte)(_map5[tile] ^ 2) != m5 || GetTileZ(tile) != z);
   596 	do {
       
   597 		tile += delta;
       
   598 		len++;
       
   599 	} while (
       
   600 		!IsTileType(tile, MP_TUNNELBRIDGE) ||
       
   601 		(_map5[tile] & 0xF0) != 0 ||
       
   602 		(byte)(_map5[tile] ^ 2) != m5 ||
       
   603 		GetTileZ(tile) != z
       
   604 	);
   597 
   605 
   598 	if ((v=FindVehicleBetween(starttile, tile, z)) != NULL) {
   606 	if ((v=FindVehicleBetween(starttile, tile, z)) != NULL) {
   599 		_error_message = v->type == VEH_Train ? STR_5000_TRAIN_IN_TUNNEL : STR_5001_ROAD_VEHICLE_IN_TUNNEL;
   607 		_error_message = v->type == VEH_Train ? STR_5000_TRAIN_IN_TUNNEL : STR_5001_ROAD_VEHICLE_IN_TUNNEL;
   600 		return (uint)-1;
   608 		return (uint)-1;
   601 	}
   609 	}
   653 	int direction = _map5[tile] & 1;
   661 	int direction = _map5[tile] & 1;
   654 	uint start;
   662 	uint start;
   655 
   663 
   656 	// find start of bridge
   664 	// find start of bridge
   657 	for(;;) {
   665 	for(;;) {
   658 		if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0x80)
   666 		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0x80)
   659 			break;
   667 			break;
   660 		tile += direction ? TILE_XY(0,-1) : TILE_XY(-1,0);
   668 		tile += direction ? TILE_XY(0,-1) : TILE_XY(-1,0);
   661 	}
   669 	}
   662 
   670 
   663 	start = tile;
   671 	start = tile;
   664 
   672 
   665 	// find end of bridge
   673 	// find end of bridge
   666 	for(;;) {
   674 	for(;;) {
   667 		if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0xA0)
   675 		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0xA0)
   668 			break;
   676 			break;
   669 		tile += direction ? TILE_XY(0,1) : TILE_XY(1,0);
   677 		tile += direction ? TILE_XY(0,1) : TILE_XY(1,0);
   670 	}
   678 	}
   671 
   679 
   672 	*endtile = tile;
   680 	*endtile = tile;
   688 	/* delete stuff under the middle part if there's a transport route there..? */
   696 	/* delete stuff under the middle part if there's a transport route there..? */
   689 	if ((_map5[tile] & 0xE0) == 0xE0) {
   697 	if ((_map5[tile] & 0xE0) == 0xE0) {
   690 		int32 cost;
   698 		int32 cost;
   691 
   699 
   692 		// check if we own the tile below the bridge..
   700 		// check if we own the tile below the bridge..
   693 		if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, GET_TILEHEIGHT(tile)) ))
   701 		if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TileHeight(tile))))
   694 			return CMD_ERROR;
   702 			return CMD_ERROR;
   695 
   703 
   696 		cost = (_map5[tile] & 8) ? _price.remove_road * 2 : _price.remove_rail;
   704 		cost = (_map5[tile] & 8) ? _price.remove_road * 2 : _price.remove_rail;
   697 
   705 
   698 		if (flags & DC_EXEC) {
   706 		if (flags & DC_EXEC) {
   701 			MarkTileDirtyByTile(tile);
   709 			MarkTileDirtyByTile(tile);
   702 		}
   710 		}
   703 		return cost;
   711 		return cost;
   704 
   712 
   705 	/* delete canal under bridge */
   713 	/* delete canal under bridge */
   706 	} else if(_map5[tile]==0xC8 && GET_TILEHEIGHT(tile)!=0) {
   714 	} else if(_map5[tile] == 0xC8 && TileHeight(tile) != 0) {
   707 		int32 cost;
   715 		int32 cost;
   708 
   716 
   709 		// check for vehicles under bridge
   717 		// check for vehicles under bridge
   710 		if ( !EnsureNoVehicleZ(tile, GET_TILEHEIGHT(tile)) )
   718 		if (!EnsureNoVehicleZ(tile, TileHeight(tile)))
   711 			return CMD_ERROR;
   719 			return CMD_ERROR;
   712 		cost = _price.clear_water;
   720 		cost = _price.clear_water;
   713 		if (flags & DC_EXEC) {
   721 		if (flags & DC_EXEC) {
   714 			_map5[tile] = _map5[tile] & ~0x38;
   722 			_map5[tile] = _map5[tile] & ~0x38;
   715 			_map_owner[tile] = OWNER_NONE;
   723 			_map_owner[tile] = OWNER_NONE;
   733 			Omit tile and endtile, since these are already checked, thus solving the problem
   741 			Omit tile and endtile, since these are already checked, thus solving the problem
   734 			of bridges over water, or higher bridges, where z is not increased, eg level bridge
   742 			of bridges over water, or higher bridges, where z is not increased, eg level bridge
   735 	*/
   743 	*/
   736 	tile		+= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
   744 	tile		+= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
   737 	endtile	-= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
   745 	endtile	-= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
   738 	if ((v=FindVehicleBetween(tile, endtile, GET_TILEHEIGHT(tile) + 8)) != NULL) {
   746 	if ((v = FindVehicleBetween(tile, endtile, TileHeight(tile) + 8)) != NULL) {
   739 		VehicleInTheWayErrMsg(v);
   747 		VehicleInTheWayErrMsg(v);
   740 		return CMD_ERROR;
   748 		return CMD_ERROR;
   741 	}
   749 	}
   742 
   750 
   743 	/* Put the tiles back to start/end position */
   751 	/* Put the tiles back to start/end position */
   842 		}
   850 		}
   843 		return (length + 1) * (_price.build_rail >> 1);
   851 		return (length + 1) * (_price.build_rail >> 1);
   844 	} else if ((_map5[tile] & 0xF8) == 0xE0) {
   852 	} else if ((_map5[tile] & 0xF8) == 0xE0) {
   845 		// bridge middle part with rail below
   853 		// bridge middle part with rail below
   846 		// only check for train under bridge
   854 		// only check for train under bridge
   847 		if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, GET_TILEHEIGHT(tile)))
   855 		if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TileHeight(tile)))
   848 			return CMD_ERROR;
   856 			return CMD_ERROR;
   849 
   857 
   850 		// tile is already of requested type?
   858 		// tile is already of requested type?
   851 		if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR;
   859 		if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR;
   852 		// change type.
   860 		// change type.
   910 	FindLandscapeHeightByTile(&ti_end, tile);
   918 	FindLandscapeHeightByTile(&ti_end, tile);
   911 	if (HASBIT(1 << 7, ti_end.tileh))
   919 	if (HASBIT(1 << 7, ti_end.tileh))
   912 		z_correction += 8;
   920 		z_correction += 8;
   913 
   921 
   914 	// return the height there (the height of the NORTH CORNER)
   922 	// return the height there (the height of the NORTH CORNER)
   915 	return GET_TILEHEIGHT(tile) + z_correction;
   923 	return TileHeight(tile) + z_correction;
   916 }
   924 }
   917 
   925 
   918 static const byte _bridge_foundations[2][16] = {
   926 static const byte _bridge_foundations[2][16] = {
   919 // 0 1  2  3  4 5 6 7  8 9 10 11 12 13 14 15
   927 // 0 1  2  3  4 5 6 7  8 9 10 11 12 13 14 15
   920 	{1,16,18,3,20,5,0,7,22,0,10,11,12,13,14},
   928 	{1,16,18,3,20,5,0,7,22,0,10,11,12,13,14},