openttd.c
changeset 3933 231ae3c419f4
parent 3900 2c84ed52709d
child 3977 513433ebd092
equal deleted inserted replaced
3932:dfe10fa5ce4f 3933:231ae3c419f4
    46 #include "waypoint.h"
    46 #include "waypoint.h"
    47 #include "ai/ai.h"
    47 #include "ai/ai.h"
    48 #include "train.h"
    48 #include "train.h"
    49 #include "yapf/yapf.h"
    49 #include "yapf/yapf.h"
    50 #include "settings.h"
    50 #include "settings.h"
       
    51 
       
    52 #include "bridge_map.h"
       
    53 #include "clear_map.h"
       
    54 #include "rail_map.h"
       
    55 #include "road_map.h"
       
    56 #include "water_map.h"
    51 
    57 
    52 #include <stdarg.h>
    58 #include <stdarg.h>
    53 
    59 
    54 void GenerateWorld(int mode, uint size_x, uint size_y);
    60 void GenerateWorld(int mode, uint size_x, uint size_y);
    55 void CallLandscapeTick(void);
    61 void CallLandscapeTick(void);
  1254 			p->engine_renew_months = _patches.autorenew_months;
  1260 			p->engine_renew_months = _patches.autorenew_months;
  1255 			p->engine_renew_money = _patches.autorenew_money;
  1261 			p->engine_renew_money = _patches.autorenew_money;
  1256 		}
  1262 		}
  1257 	}
  1263 	}
  1258 
  1264 
       
  1265 	if (CheckSavegameVersion(29)) {
       
  1266 		TileIndex map_end = MapSize();
       
  1267 		TileIndex tile;
       
  1268 		Vehicle* v;
       
  1269 
       
  1270 		for (tile = 0; tile != map_end; tile++) {
       
  1271 			if (MayHaveBridgeAbove(tile)) ClearBridgeMiddle(tile);
       
  1272 			if (IsTileType(tile, MP_TUNNELBRIDGE) &&
       
  1273 					_m[tile].m5 & 0x80 && // bridge
       
  1274 					_m[tile].m5 & 0x40) { // middle part
       
  1275 				Axis axis = (Axis)GB(_m[tile].m5, 0, 1);
       
  1276 
       
  1277 				if (_m[tile].m5 & 0x20) { // transport route under bridge?
       
  1278 					if (GB(_m[tile].m5, 3, 2) == TRANSPORT_RAIL) {
       
  1279 						MakeRailNormal(
       
  1280 							tile,
       
  1281 							GetTileOwner(tile),
       
  1282 							axis == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X,
       
  1283 							GetRailType(tile)
       
  1284 						);
       
  1285 					} else {
       
  1286 						uint town = IsTileOwner(tile, OWNER_TOWN) ? ClosestTownFromTile(tile, (uint)-1)->index : 0;
       
  1287 
       
  1288 						MakeRoadNormal(
       
  1289 							tile,
       
  1290 							GetTileOwner(tile),
       
  1291 							axis == AXIS_X ? ROAD_Y : ROAD_X,
       
  1292 							town
       
  1293 						);
       
  1294 					}
       
  1295 				} else {
       
  1296 					if (GB(_m[tile].m5, 3, 2) == 0) {
       
  1297 						MakeClear(tile, CLEAR_GRASS, 3);
       
  1298 					} else {
       
  1299 						MakeWater(tile);
       
  1300 					}
       
  1301 				}
       
  1302 				SetBridgeMiddle(tile, axis);
       
  1303 			}
       
  1304 		}
       
  1305 
       
  1306 		FOR_ALL_VEHICLES(v) {
       
  1307 			if (v->type != VEH_Train && v->type != VEH_Road) continue;
       
  1308 			if (IsBridgeTile(v->tile)) {
       
  1309 				DiagDirection dir = GetBridgeRampDirection(v->tile);
       
  1310 
       
  1311 				if (dir != DirToDiagDir(v->direction)) continue;
       
  1312 				switch (dir) {
       
  1313 					default:
       
  1314 					case DIAGDIR_NE: if ((v->x_pos & 0xF) !=  0) continue;
       
  1315 					case DIAGDIR_SE: if ((v->y_pos & 0xF) != 15) continue;
       
  1316 					case DIAGDIR_SW: if ((v->x_pos & 0xF) != 15) continue;
       
  1317 					case DIAGDIR_NW: if ((v->y_pos & 0xF) !=  0) continue;
       
  1318 				}
       
  1319 			} else if (v->z_pos <= GetSlopeZ(v->x_pos, v->y_pos)) {
       
  1320 				continue;
       
  1321 			}
       
  1322 			if (!IsBridgeTile(v->tile)) v->tile = GetNorthernBridgeEnd(v->tile);
       
  1323 			if (v->type == VEH_Train) {
       
  1324 				v->u.rail.track = 0x40;
       
  1325 			} else {
       
  1326 				v->u.road.state = 0xFF;
       
  1327 			}
       
  1328 		}
       
  1329 	}
       
  1330 
  1259 	/* Elrails got added in rev 24 */
  1331 	/* Elrails got added in rev 24 */
  1260 	if (CheckSavegameVersion(24)) {
  1332 	if (CheckSavegameVersion(24)) {
  1261 		Vehicle* v;
  1333 		Vehicle* v;
  1262 		uint i;
  1334 		uint i;
  1263 		TileIndex t;
  1335 		TileIndex t;
  1304 						if (GetTunnelTransportType(t) == TRANSPORT_RAIL) {
  1376 						if (GetTunnelTransportType(t) == TRANSPORT_RAIL) {
  1305 							SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
  1377 							SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
  1306 						}
  1378 						}
  1307 					} else {
  1379 					} else {
  1308 						if (GetBridgeTransportType(t) == TRANSPORT_RAIL) {
  1380 						if (GetBridgeTransportType(t) == TRANSPORT_RAIL) {
  1309 							if (IsBridgeRamp(t)) {
       
  1310 								SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
       
  1311 							} else {
       
  1312 								SetRailTypeOnBridge(t, UpdateRailType(GetRailTypeOnBridge(t), min_rail));
       
  1313 							}
       
  1314 						}
       
  1315 						if (IsBridgeMiddle(t) &&
       
  1316 								IsTransportUnderBridge(t) &&
       
  1317 								GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL) {
       
  1318 							SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
  1381 							SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
  1319 						}
  1382 						}
  1320 					}
  1383 					}
  1321 					break;
  1384 					break;
  1322 
  1385