tunnelbridge_cmd.c
changeset 1977 37bbebf94434
parent 1930 29c3aae05716
child 1981 3c9c682f1212
equal deleted inserted replaced
1976:2eb82bb3cb2d 1977:37bbebf94434
     9 #include "command.h"
     9 #include "command.h"
    10 #include "player.h"
    10 #include "player.h"
    11 #include "town.h"
    11 #include "town.h"
    12 #include "sound.h"
    12 #include "sound.h"
    13 
    13 
    14 extern void DrawCanalWater(uint tile);
    14 extern void DrawCanalWater(TileIndex tile);
    15 
    15 
    16 static const byte _bridge_available_year[MAX_BRIDGES] = {
    16 static const byte _bridge_available_year[MAX_BRIDGES] = {
    17 	0, 0, 10, 0, 10, 10, 10, 10, 10, 10, 75, 85, 90
    17 	0, 0, 10, 0, 10, 10, 10, 10, 10, 10, 75, 85, 90
    18 };
    18 };
    19 
    19 
   398 	}
   398 	}
   399 
   399 
   400 	return cost;
   400 	return cost;
   401 }
   401 }
   402 
   402 
   403 static bool DoCheckTunnelInWay(uint tile, uint z, uint dir)
   403 static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir)
   404 {
   404 {
       
   405 	TileIndexDiff delta = TileOffsByDir(dir);
   405 	TileInfo ti;
   406 	TileInfo ti;
   406 	int delta;
       
   407 
       
   408 	delta = TileOffsByDir(dir);
       
   409 
   407 
   410 	do {
   408 	do {
   411 		tile -= delta;
   409 		tile -= delta;
   412 		FindLandscapeHeightByTile(&ti, tile);
   410 		FindLandscapeHeightByTile(&ti, tile);
   413 	} while (z < ti.z);
   411 	} while (z < ti.z);
   418 	}
   416 	}
   419 
   417 
   420 	return true;
   418 	return true;
   421 }
   419 }
   422 
   420 
   423 bool CheckTunnelInWay(uint tile, int z)
   421 bool CheckTunnelInWay(TileIndex tile, int z)
   424 {
   422 {
   425 	return DoCheckTunnelInWay(tile,z,0) &&
   423 	return DoCheckTunnelInWay(tile,z,0) &&
   426 		DoCheckTunnelInWay(tile,z,1) &&
   424 		DoCheckTunnelInWay(tile,z,1) &&
   427 		DoCheckTunnelInWay(tile,z,2) &&
   425 		DoCheckTunnelInWay(tile,z,2) &&
   428 		DoCheckTunnelInWay(tile,z,3);
   426 		DoCheckTunnelInWay(tile,z,3);
   591 {
   589 {
   592 	uint z = GetTileZ(tile);
   590 	uint z = GetTileZ(tile);
   593 	byte m5 = _map5[tile];
   591 	byte m5 = _map5[tile];
   594 	int delta = TileOffsByDir(m5 & 3);
   592 	int delta = TileOffsByDir(m5 & 3);
   595 	uint len = 0;
   593 	uint len = 0;
   596 	uint starttile = tile;
   594 	TileIndex starttile = tile;
   597 	Vehicle *v;
   595 	Vehicle *v;
   598 
   596 
   599 	do {
   597 	do {
   600 		tile += delta;
   598 		tile += delta;
   601 		len++;
   599 		len++;
   615 
   613 
   616 	if (length != NULL) *length = len;
   614 	if (length != NULL) *length = len;
   617 	return tile;
   615 	return tile;
   618 }
   616 }
   619 
   617 
   620 static int32 DoClearTunnel(uint tile, uint32 flags)
   618 static int32 DoClearTunnel(TileIndex tile, uint32 flags)
   621 {
   619 {
   622 	Town *t;
   620 	Town *t;
   623 	TileIndex endtile;
   621 	TileIndex endtile;
   624 	uint length;
   622 	uint length;
   625 	static const byte _updsignals_tunnel_dir[4] = { 5, 7, 1, 3};
   623 	static const byte _updsignals_tunnel_dir[4] = { 5, 7, 1, 3};
   660 			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
   658 			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
   661 	}
   659 	}
   662 	return  _price.clear_tunnel * (length + 1);
   660 	return  _price.clear_tunnel * (length + 1);
   663 }
   661 }
   664 
   662 
   665 static uint FindEdgesOfBridge(uint tile, uint *endtile)
   663 static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile)
   666 {
   664 {
   667 	int direction = _map5[tile] & 1;
   665 	int direction = _map5[tile] & 1;
   668 	uint start;
   666 	TileIndex start;
   669 
   667 
   670 	// find start of bridge
   668 	// find start of bridge
   671 	for(;;) {
   669 	for(;;) {
   672 		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0x80)
   670 		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0x80)
   673 			break;
   671 			break;
   686 	*endtile = tile;
   684 	*endtile = tile;
   687 
   685 
   688 	return start;
   686 	return start;
   689 }
   687 }
   690 
   688 
   691 static int32 DoClearBridge(uint tile, uint32 flags)
   689 static int32 DoClearBridge(TileIndex tile, uint32 flags)
   692 {
   690 {
   693 	uint endtile;
   691 	TileIndex endtile;
   694 	Vehicle *v;
   692 	Vehicle *v;
   695 	Town *t;
   693 	Town *t;
   696 	int direction;
   694 	int direction;
   697 
   695 
   698 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   696 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   809 	}
   807 	}
   810 
   808 
   811 	return ((((endtile - tile) >> (direction?8:0))&0xFF)+1) * _price.clear_bridge;
   809 	return ((((endtile - tile) >> (direction?8:0))&0xFF)+1) * _price.clear_bridge;
   812 }
   810 }
   813 
   811 
   814 static int32 ClearTile_TunnelBridge(uint tile, byte flags) {
   812 static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)
       
   813 {
   815 	byte m5 = _map5[tile];
   814 	byte m5 = _map5[tile];
   816 
   815 
   817 	if ((m5 & 0xF0) == 0) {
   816 	if ((m5 & 0xF0) == 0) {
   818 		if (flags & DC_AUTO)
   817 		if (flags & DC_AUTO)
   819 			return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
   818 			return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
   827 	}
   826 	}
   828 
   827 
   829 	return CMD_ERROR;
   828 	return CMD_ERROR;
   830 }
   829 }
   831 
   830 
   832 int32 DoConvertTunnelBridgeRail(uint tile, uint totype, bool exec)
   831 int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
   833 {
   832 {
   834 	TileIndex endtile;
   833 	TileIndex endtile;
   835 	uint length;
   834 	uint length;
   836 	Vehicle *v;
   835 	Vehicle *v;
   837 
   836 
  1227 	// not accurate, but good enough for slope graphics drawing
  1226 	// not accurate, but good enough for slope graphics drawing
  1228 	return 0;
  1227 	return 0;
  1229 }
  1228 }
  1230 
  1229 
  1231 
  1230 
  1232 static void GetAcceptedCargo_TunnelBridge(uint tile, AcceptedCargo ac)
  1231 static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac)
  1233 {
  1232 {
  1234 	/* not used */
  1233 	/* not used */
  1235 }
  1234 }
  1236 
  1235 
  1237 static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = {
  1236 static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = {
  1264 	STR_5028_TUBULAR_ROAD_BRIDGE,
  1263 	STR_5028_TUBULAR_ROAD_BRIDGE,
  1265 	STR_5028_TUBULAR_ROAD_BRIDGE,
  1264 	STR_5028_TUBULAR_ROAD_BRIDGE,
  1266 	0,0,0,
  1265 	0,0,0,
  1267 };
  1266 };
  1268 
  1267 
  1269 static void GetTileDesc_TunnelBridge(uint tile, TileDesc *td)
  1268 static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
  1270 {
  1269 {
  1271 	int delta;
  1270 	int delta;
  1272 
  1271 
  1273 	if ((_map5[tile] & 0x80) == 0) {
  1272 	if ((_map5[tile] & 0x80) == 0) {
  1274 		td->str = STR_5017_RAILROAD_TUNNEL + ((_map5[tile] >> 2) & 3);
  1273 		td->str = STR_5017_RAILROAD_TUNNEL + ((_map5[tile] >> 2) & 3);
  1283 	}
  1282 	}
  1284 	td->owner = GetTileOwner(tile);
  1283 	td->owner = GetTileOwner(tile);
  1285 }
  1284 }
  1286 
  1285 
  1287 
  1286 
  1288 static void AnimateTile_TunnelBridge(uint tile)
  1287 static void AnimateTile_TunnelBridge(TileIndex tile)
  1289 {
  1288 {
  1290 	/* not used */
  1289 	/* not used */
  1291 }
  1290 }
  1292 
  1291 
  1293 static void TileLoop_TunnelBridge(uint tile)
  1292 static void TileLoop_TunnelBridge(TileIndex tile)
  1294 {
  1293 {
  1295 	if (_opt.landscape == LT_HILLY) {
  1294 	if (_opt.landscape == LT_HILLY) {
  1296 		if ( GetTileZ(tile) > _opt.snow_line) {
  1295 		if ( GetTileZ(tile) > _opt.snow_line) {
  1297 			if (!(_map3_hi[tile] & 0x80)) {
  1296 			if (!(_map3_hi[tile] & 0x80)) {
  1298 				_map3_hi[tile] |= 0x80;
  1297 				_map3_hi[tile] |= 0x80;
  1313 
  1312 
  1314 	// if it's a bridge with water below, call tileloop_water on it.
  1313 	// if it's a bridge with water below, call tileloop_water on it.
  1315 	if ((_map5[tile] & 0xF8) == 0xC8) TileLoop_Water(tile);
  1314 	if ((_map5[tile] & 0xF8) == 0xC8) TileLoop_Water(tile);
  1316 }
  1315 }
  1317 
  1316 
  1318 static void ClickTile_TunnelBridge(uint tile)
  1317 static void ClickTile_TunnelBridge(TileIndex tile)
  1319 {
  1318 {
  1320 	/* not used */
  1319 	/* not used */
  1321 }
  1320 }
  1322 
  1321 
  1323 
  1322 
  1324 static uint32 GetTileTrackStatus_TunnelBridge(uint tile, TransportType mode)
  1323 static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode)
  1325 {
  1324 {
  1326 	uint32 result;
  1325 	uint32 result;
  1327 	byte m5 = _map5[tile];
  1326 	byte m5 = _map5[tile];
  1328 
  1327 
  1329 	if ((m5 & 0xF0) == 0) {
  1328 	if ((m5 & 0xF0) == 0) {
  1366 		assert(0); /* This should never occur */
  1365 		assert(0); /* This should never occur */
  1367 	}
  1366 	}
  1368 	return 0;
  1367 	return 0;
  1369 }
  1368 }
  1370 
  1369 
  1371 static void ChangeTileOwner_TunnelBridge(uint tile, byte old_player, byte new_player)
  1370 static void ChangeTileOwner_TunnelBridge(TileIndex tile, byte old_player, byte new_player)
  1372 {
  1371 {
  1373 	if (!IsTileOwner(tile, old_player)) return;
  1372 	if (!IsTileOwner(tile, old_player)) return;
  1374 
  1373 
  1375 	if (new_player != 255) {
  1374 	if (new_player != 255) {
  1376 		SetTileOwner(tile, new_player);
  1375 		SetTileOwner(tile, new_player);
  1402 static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29};
  1401 static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29};
  1403 static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25};
  1402 static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25};
  1404 static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45};
  1403 static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45};
  1405 static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49};
  1404 static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49};
  1406 
  1405 
  1407 static uint32 VehicleEnter_TunnelBridge(Vehicle *v, uint tile, int x, int y)
  1406 static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
  1408 {
  1407 {
  1409 	int z;
  1408 	int z;
  1410 	int dir, vdir;
  1409 	int dir, vdir;
  1411 	byte fc;
  1410 	byte fc;
  1412 
  1411