src/openttd.cpp
changeset 7157 270bc5b64e08
parent 7150 2cfe4a46fa1c
child 7181 f966d75af3a6
equal deleted inserted replaced
7156:68de47bdcb80 7157:270bc5b64e08
  1106 	TileIndex tile;
  1106 	TileIndex tile;
  1107 
  1107 
  1108 	for (tile = 0; tile != MapSize(); tile++) {
  1108 	for (tile = 0; tile != MapSize(); tile++) {
  1109 		switch (GetTileType(tile)) {
  1109 		switch (GetTileType(tile)) {
  1110 			case MP_STREET:
  1110 			case MP_STREET:
  1111 				if (IsLevelCrossing(tile) && GetCrossingRoadOwner(tile) & 0x80) {
  1111 				if (GB(_m[tile].m5, 4, 2) == ROAD_TILE_CROSSING && HASBIT(_m[tile].m4, 7)) {
  1112 					SetCrossingRoadOwner(tile, OWNER_TOWN);
  1112 					_m[tile].m4 = OWNER_TOWN;
  1113 				}
  1113 				}
  1114 				/* FALLTHROUGH */
  1114 				/* FALLTHROUGH */
  1115 
  1115 
  1116 			case MP_TUNNELBRIDGE:
  1116 			case MP_TUNNELBRIDGE:
  1117 				if (GetTileOwner(tile) & 0x80) SetTileOwner(tile, OWNER_TOWN);
  1117 				if (GetTileOwner(tile) & 0x80) SetTileOwner(tile, OWNER_TOWN);
  1412 			p->engine_renew_months = _patches.autorenew_months;
  1412 			p->engine_renew_months = _patches.autorenew_months;
  1413 			p->engine_renew_money  = _patches.autorenew_money;
  1413 			p->engine_renew_money  = _patches.autorenew_money;
  1414 		}
  1414 		}
  1415 	}
  1415 	}
  1416 
  1416 
  1417 	if (CheckSavegameVersion(42)) {
       
  1418 		Vehicle* v;
       
  1419 
       
  1420 		for (TileIndex t = 0; t < map_size; t++) {
       
  1421 			if (MayHaveBridgeAbove(t)) ClearBridgeMiddle(t);
       
  1422 			if (IsBridgeTile(t)) {
       
  1423 				if (HASBIT(_m[t].m5, 6)) { // middle part
       
  1424 					Axis axis = (Axis)GB(_m[t].m5, 0, 1);
       
  1425 
       
  1426 					if (HASBIT(_m[t].m5, 5)) { // transport route under bridge?
       
  1427 						if (GB(_m[t].m5, 3, 2) == TRANSPORT_RAIL) {
       
  1428 							MakeRailNormal(
       
  1429 								t,
       
  1430 								GetTileOwner(t),
       
  1431 								axis == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X,
       
  1432 								GetRailType(t)
       
  1433 							);
       
  1434 						} else {
       
  1435 							TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, (uint)-1)->index : 0;
       
  1436 
       
  1437 							MakeRoadNormal(
       
  1438 								t,
       
  1439 								GetTileOwner(t),
       
  1440 								axis == AXIS_X ? ROAD_Y : ROAD_X,
       
  1441 								town
       
  1442 							);
       
  1443 						}
       
  1444 					} else {
       
  1445 						if (GB(_m[t].m5, 3, 2) == 0) {
       
  1446 							MakeClear(t, CLEAR_GRASS, 3);
       
  1447 						} else {
       
  1448 							MakeCanal(t, GetTileOwner(t));
       
  1449 						}
       
  1450 					}
       
  1451 					SetBridgeMiddle(t, axis);
       
  1452 				} else { // ramp
       
  1453 					Axis axis = (Axis)GB(_m[t].m5, 0, 1);
       
  1454 					uint north_south = GB(_m[t].m5, 5, 1);
       
  1455 					DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
       
  1456 					TransportType type = (TransportType)GB(_m[t].m5, 1, 2);
       
  1457 
       
  1458 					_m[t].m5 = 1 << 7 | type << 2 | dir;
       
  1459 				}
       
  1460 			}
       
  1461 		}
       
  1462 
       
  1463 		FOR_ALL_VEHICLES(v) {
       
  1464 			if (v->type != VEH_TRAIN && v->type != VEH_ROAD) continue;
       
  1465 			if (IsBridgeTile(v->tile)) {
       
  1466 				DiagDirection dir = GetBridgeRampDirection(v->tile);
       
  1467 
       
  1468 				if (dir != DirToDiagDir(v->direction)) continue;
       
  1469 				switch (dir) {
       
  1470 					default: NOT_REACHED();
       
  1471 					case DIAGDIR_NE: if ((v->x_pos & 0xF) !=  0)            continue; break;
       
  1472 					case DIAGDIR_SE: if ((v->y_pos & 0xF) != TILE_SIZE - 1) continue; break;
       
  1473 					case DIAGDIR_SW: if ((v->x_pos & 0xF) != TILE_SIZE - 1) continue; break;
       
  1474 					case DIAGDIR_NW: if ((v->y_pos & 0xF) !=  0)            continue; break;
       
  1475 				}
       
  1476 			} else if (v->z_pos > GetSlopeZ(v->x_pos, v->y_pos)) {
       
  1477 				v->tile = GetNorthernBridgeEnd(v->tile);
       
  1478 			} else {
       
  1479 				continue;
       
  1480 			}
       
  1481 			if (v->type == VEH_TRAIN) {
       
  1482 				v->u.rail.track = TRACK_BIT_WORMHOLE;
       
  1483 			} else {
       
  1484 				v->u.road.state = RVSB_WORMHOLE;
       
  1485 			}
       
  1486 		}
       
  1487 	}
       
  1488 
       
  1489 	if (CheckSavegameVersion(48)) {
  1417 	if (CheckSavegameVersion(48)) {
  1490 		for (TileIndex t = 0; t < map_size; t++) {
  1418 		for (TileIndex t = 0; t < map_size; t++) {
  1491 			switch (GetTileType(t)) {
  1419 			switch (GetTileType(t)) {
  1492 				case MP_RAILWAY:
  1420 				case MP_RAILWAY:
  1493 					if (IsPlainRailTile(t)) {
  1421 					if (IsPlainRailTile(t)) {
  1512 				default: break;
  1440 				default: break;
  1513 			}
  1441 			}
  1514 		}
  1442 		}
  1515 	}
  1443 	}
  1516 
  1444 
       
  1445 	if (CheckSavegameVersion(61)) {
       
  1446 		/* Added the RoadType */
       
  1447 		for (TileIndex t = 0; t < map_size; t++) {
       
  1448 			switch(GetTileType(t)) {
       
  1449 				case MP_STREET:
       
  1450 					SB(_m[t].m5, 6, 2, GB(_m[t].m5, 4, 2));
       
  1451 					switch (GetRoadTileType(t)) {
       
  1452 						default: NOT_REACHED();
       
  1453 						case ROAD_TILE_NORMAL:
       
  1454 							SB(_m[t].m4, 0, 4, GB(_m[t].m5, 0, 4));
       
  1455 							SB(_m[t].m4, 4, 4, 0);
       
  1456 							SB(_m[t].m6, 2, 4, 0);
       
  1457 							break;
       
  1458 						case ROAD_TILE_CROSSING:
       
  1459 							SB(_m[t].m4, 5, 2, GB(_m[t].m5, 2, 2));
       
  1460 							break;
       
  1461 						case ROAD_TILE_DEPOT:    break;
       
  1462 					}
       
  1463 					SetRoadTypes(t, ROADTYPES_ROAD);
       
  1464 					break;
       
  1465 
       
  1466 				case MP_STATION:
       
  1467 					if (IsRoadStop(t)) SetRoadTypes(t, ROADTYPES_ROAD);
       
  1468 					break;
       
  1469 
       
  1470 				case MP_TUNNELBRIDGE:
       
  1471 					if ((IsTunnel(t) ? GetTunnelTransportType(t) : GetBridgeTransportType(t)) == TRANSPORT_ROAD) {
       
  1472 						SetRoadTypes(t, ROADTYPES_ROAD);
       
  1473 					}
       
  1474 					break;
       
  1475 
       
  1476 				default: break;
       
  1477 			}
       
  1478 		}
       
  1479 	}
       
  1480 
       
  1481 	if (CheckSavegameVersion(42)) {
       
  1482 		Vehicle* v;
       
  1483 
       
  1484 		for (TileIndex t = 0; t < map_size; t++) {
       
  1485 			if (MayHaveBridgeAbove(t)) ClearBridgeMiddle(t);
       
  1486 			if (IsBridgeTile(t)) {
       
  1487 				if (HASBIT(_m[t].m5, 6)) { // middle part
       
  1488 					Axis axis = (Axis)GB(_m[t].m5, 0, 1);
       
  1489 
       
  1490 					if (HASBIT(_m[t].m5, 5)) { // transport route under bridge?
       
  1491 						if (GB(_m[t].m5, 3, 2) == TRANSPORT_RAIL) {
       
  1492 							MakeRailNormal(
       
  1493 								t,
       
  1494 								GetTileOwner(t),
       
  1495 								axis == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X,
       
  1496 								GetRailType(t)
       
  1497 							);
       
  1498 						} else {
       
  1499 							TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, (uint)-1)->index : 0;
       
  1500 
       
  1501 							MakeRoadNormal(
       
  1502 								t,
       
  1503 								axis == AXIS_X ? ROAD_Y : ROAD_X,
       
  1504 								ROADTYPES_ROAD,
       
  1505 								town,
       
  1506 								GetTileOwner(t), OWNER_NONE, OWNER_NONE
       
  1507 							);
       
  1508 						}
       
  1509 					} else {
       
  1510 						if (GB(_m[t].m5, 3, 2) == 0) {
       
  1511 							MakeClear(t, CLEAR_GRASS, 3);
       
  1512 						} else {
       
  1513 							MakeCanal(t, GetTileOwner(t));
       
  1514 						}
       
  1515 					}
       
  1516 					SetBridgeMiddle(t, axis);
       
  1517 				} else { // ramp
       
  1518 					Axis axis = (Axis)GB(_m[t].m5, 0, 1);
       
  1519 					uint north_south = GB(_m[t].m5, 5, 1);
       
  1520 					DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
       
  1521 					TransportType type = (TransportType)GB(_m[t].m5, 1, 2);
       
  1522 
       
  1523 					_m[t].m5 = 1 << 7 | type << 2 | dir;
       
  1524 				}
       
  1525 			}
       
  1526 		}
       
  1527 
       
  1528 		FOR_ALL_VEHICLES(v) {
       
  1529 			if (v->type != VEH_TRAIN && v->type != VEH_ROAD) continue;
       
  1530 			if (IsBridgeTile(v->tile)) {
       
  1531 				DiagDirection dir = GetBridgeRampDirection(v->tile);
       
  1532 
       
  1533 				if (dir != DirToDiagDir(v->direction)) continue;
       
  1534 				switch (dir) {
       
  1535 					default: NOT_REACHED();
       
  1536 					case DIAGDIR_NE: if ((v->x_pos & 0xF) !=  0)            continue; break;
       
  1537 					case DIAGDIR_SE: if ((v->y_pos & 0xF) != TILE_SIZE - 1) continue; break;
       
  1538 					case DIAGDIR_SW: if ((v->x_pos & 0xF) != TILE_SIZE - 1) continue; break;
       
  1539 					case DIAGDIR_NW: if ((v->y_pos & 0xF) !=  0)            continue; break;
       
  1540 				}
       
  1541 			} else if (v->z_pos > GetSlopeZ(v->x_pos, v->y_pos)) {
       
  1542 				v->tile = GetNorthernBridgeEnd(v->tile);
       
  1543 			} else {
       
  1544 				continue;
       
  1545 			}
       
  1546 			if (v->type == VEH_TRAIN) {
       
  1547 				v->u.rail.track = TRACK_BIT_WORMHOLE;
       
  1548 			} else {
       
  1549 				v->u.road.state = RVSB_WORMHOLE;
       
  1550 			}
       
  1551 		}
       
  1552 	}
       
  1553 
  1517 	/* Elrails got added in rev 24 */
  1554 	/* Elrails got added in rev 24 */
  1518 	if (CheckSavegameVersion(24)) {
  1555 	if (CheckSavegameVersion(24)) {
  1519 		Vehicle *v;
  1556 		Vehicle *v;
  1520 		RailType min_rail = RAILTYPE_ELECTRIC;
  1557 		RailType min_rail = RAILTYPE_ELECTRIC;
  1521 
  1558 
  1770 
  1807 
  1771 	/* From version 53, the map array was changed for house tiles to allow
  1808 	/* From version 53, the map array was changed for house tiles to allow
  1772 	 * space for newhouses grf features. A new byte, m7, was also added. */
  1809 	 * space for newhouses grf features. A new byte, m7, was also added. */
  1773 	if (CheckSavegameVersion(53)) {
  1810 	if (CheckSavegameVersion(53)) {
  1774 		for (TileIndex t = 0; t < map_size; t++) {
  1811 		for (TileIndex t = 0; t < map_size; t++) {
  1775 			_me[t].m7 = 0;
       
  1776 
       
  1777 			if (IsTileType(t, MP_HOUSE)) {
  1812 			if (IsTileType(t, MP_HOUSE)) {
  1778 				if (GB(_m[t].m3, 6, 2) != TOWN_HOUSE_COMPLETED) {
  1813 				if (GB(_m[t].m3, 6, 2) != TOWN_HOUSE_COMPLETED) {
  1779 					/* Move the construction stage from m3[7..6] to m5[5..4].
  1814 					/* Move the construction stage from m3[7..6] to m5[5..4].
  1780 					 * The construction counter does not have to move. */
  1815 					 * The construction counter does not have to move. */
  1781 					SB(_m[t].m5, 3, 2, GB(_m[t].m3, 6, 2));
  1816 					SB(_m[t].m5, 3, 2, GB(_m[t].m3, 6, 2));