pathfind.c
branch0.5
changeset 5403 4d10a17a22bc
parent 5383 98e463d11e18
child 5520 82988aae1562
equal deleted inserted replaced
5402:e49a2dead94a 5403:4d10a17a22bc
   251 48, 56, 56, 58, 56, 60, 60, 62,
   251 48, 56, 56, 58, 56, 60, 60, 62,
   252 };
   252 };
   253 
   253 
   254 static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
   254 static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
   255 {
   255 {
   256 	uint bits = 0;
   256 	uint bits;
   257 	int i;
   257 	int i;
   258 	RememberData rd;
   258 	RememberData rd;
   259 	TileIndex tile_org = tile;
   259 	TileIndex tile_org = tile;
   260 
   260 
   261 	// check if the old tile can be left at that direction
   261 	// check if the old tile can be left at that direction
   274 		}
   274 		}
   275 		tile = SkipToEndOfTunnel(tpf, tile, direction);
   275 		tile = SkipToEndOfTunnel(tpf, tile, direction);
   276 	}
   276 	}
   277 	tile += TileOffsByDiagDir(direction);
   277 	tile += TileOffsByDiagDir(direction);
   278 
   278 
   279 	/* check if the new tile can be entered from that direction */
   279 	/* Check in case of rail if the owner is the same */
   280 	/* Inside this block we should not use 'return' to indicate 'no way' condition (at least for rail transport type) */
   280 	if (tpf->tracktype == TRANSPORT_RAIL) {
   281 	if (tpf->tracktype == TRANSPORT_ROAD || tpf->tracktype == TRANSPORT_RAIL) {
   281 		// don't enter train depot from the back
   282 		if (tpf->tracktype == TRANSPORT_RAIL) {
   282 		if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) == direction) return;
   283 			/* don't enter train depot from the back */
   283 
   284 			if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) == direction) goto no_way;
   284 		if (IsTileType(tile_org, MP_RAILWAY) || IsTileType(tile_org, MP_STATION) || IsTileType(tile_org, MP_TUNNELBRIDGE))
   285 
   285 			if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE))
   286 			/* Check in case of rail if the owner is the same */
   286 				/* Check if we are on a bridge (middle parts don't have an owner */
   287 			if (IsTileType(tile_org, MP_RAILWAY) || IsTileType(tile_org, MP_STATION) || IsTileType(tile_org, MP_TUNNELBRIDGE))
   287 				if (!IsBridgeTile(tile) || !IsBridgeMiddle(tile))
   288 				if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE))
   288 					if (!IsBridgeTile(tile_org) || !IsBridgeMiddle(tile_org))
   289 					/* Check if we are on a bridge (middle parts don't have an owner */
   289 						if (GetTileOwner(tile_org) != GetTileOwner(tile))
   290 					if (!IsBridgeTile(tile) || !IsBridgeMiddle(tile))
   290 							return;
   291 						if (!IsBridgeTile(tile_org) || !IsBridgeMiddle(tile_org))
   291 	}
   292 							if (GetTileOwner(tile_org) != GetTileOwner(tile)) goto no_way;
   292 
   293 
   293 	// check if the new tile can be entered from that direction
   294 		} else if (tpf->tracktype == TRANSPORT_ROAD) {
   294 	if (tpf->tracktype == TRANSPORT_ROAD) {
   295 			/* road stops and depots now have a track (r4419) */
   295 		// road stops and depots now have a track (r4419)
   296 			/* don't enter road stop from the back */
   296 		// don't enter road stop from the back
   297 			if (IsRoadStopTile(tile) && ReverseDiagDir(GetRoadStopDir(tile)) != direction) goto no_way;
   297 		if (IsRoadStopTile(tile) && ReverseDiagDir(GetRoadStopDir(tile)) != direction) return;
   298 			/* don't enter road depot from the back */
   298 		// don't enter road depot from the back
   299 			if (IsTileDepotType(tile, TRANSPORT_ROAD) && ReverseDiagDir(GetRoadDepotDirection(tile)) != direction) goto no_way;
   299 		if (IsTileDepotType(tile, TRANSPORT_ROAD) && ReverseDiagDir(GetRoadDepotDirection(tile)) != direction) return;
   300 		}
   300 	}
   301 
   301 
   302 		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
   302 	/* Check if the new tile is a tunnel or bridge head and that the direction
   303 			if (IsTunnel(tile)) {
   303 	 * and transport type match */
   304 				/* tunnel hole can be entered only from one direction */
   304 	if (IsTileType(tile, MP_TUNNELBRIDGE) && IsTunnel(tile)) {
   305 				if (GetTunnelDirection(tile) != direction) goto no_way;
   305 		if (GetTunnelDirection(tile) != direction ||
   306 			}
   306 				GetTunnelTransportType(tile) != tpf->tracktype) {
   307 		}
   307 			return;
   308 		if (tpf->tracktype == TRANSPORT_RAIL) {
   308 		}
   309 			/* check for the rail type compatibility */
   309 	}
   310 			Trackdir td = DiagdirToDiagTrackdir(direction);
   310 
   311 			RailType type_org = GetTileRailType(tile_org, td);
   311 	tpf->rd.cur_length++;
   312 			RailType type = GetTileRailType(tile, td);
   312 
   313 			if (type != type_org) {
       
   314 				// they can be compatible only if one is normal and the other one is elrail
       
   315 				if (type_org == RAILTYPE_RAIL && type != RAILTYPE_ELECTRIC) goto no_way;
       
   316 				if (type == RAILTYPE_RAIL && type_org != RAILTYPE_ELECTRIC) goto no_way;
       
   317 			}
       
   318 		}
       
   319 	}
       
   320 
       
   321 	/* the next line is skipped when the new tile can't be entered from tile_org */
       
   322 	bits = GetTileTrackStatus(tile, tpf->tracktype);
   313 	bits = GetTileTrackStatus(tile, tpf->tracktype);
   323 no_way:
       
   324 
       
   325 	tpf->rd.cur_length++;
       
   326 
   314 
   327 	if ((byte)bits != tpf->var2) {
   315 	if ((byte)bits != tpf->var2) {
   328 		bits &= _tpfmode1_and[direction];
   316 		bits &= _tpfmode1_and[direction];
   329 		bits = bits | (bits>>8);
   317 		bits = bits | (bits>>8);
   330 	}
   318 	}
   358 	 * iterate all the tracks in a signal block, even when a normal train would
   346 	 * iterate all the tracks in a signal block, even when a normal train would
   359 	 * not reach it (for example, when two lines merge */
   347 	 * not reach it (for example, when two lines merge */
   360 	if (tpf->hasbit_13)
   348 	if (tpf->hasbit_13)
   361 		return;
   349 		return;
   362 
   350 
   363 	tile = tile_org;
       
   364 	direction = ReverseDiagDir(direction);
   351 	direction = ReverseDiagDir(direction);
       
   352 	tile += TileOffsByDiagDir(direction);
   365 
   353 
   366 	bits = GetTileTrackStatus(tile, tpf->tracktype);
   354 	bits = GetTileTrackStatus(tile, tpf->tracktype);
   367 	bits |= (bits >> 8);
   355 	bits |= (bits >> 8);
   368 
   356 
   369 	if ( (byte)bits != tpf->var2) {
   357 	if ( (byte)bits != tpf->var2) {