(svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
This commit is contained in:
		
							
								
								
									
										1
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								Makefile
									
									
									
									
									
								
							@@ -612,6 +612,7 @@ SRCS += airport.c
 | 
				
			|||||||
SRCS += airport_gui.c
 | 
					SRCS += airport_gui.c
 | 
				
			||||||
SRCS += aystar.c
 | 
					SRCS += aystar.c
 | 
				
			||||||
SRCS += bridge_gui.c
 | 
					SRCS += bridge_gui.c
 | 
				
			||||||
 | 
					SRCS += bridge_map.c
 | 
				
			||||||
SRCS += callback_table.c
 | 
					SRCS += callback_table.c
 | 
				
			||||||
SRCS += clear_cmd.c
 | 
					SRCS += clear_cmd.c
 | 
				
			||||||
SRCS += command.c
 | 
					SRCS += command.c
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2146,7 +2146,6 @@ static bool AiRemoveTileAndGoForward(Player *p)
 | 
				
			|||||||
	int bit;
 | 
						int bit;
 | 
				
			||||||
	const byte *ptr;
 | 
						const byte *ptr;
 | 
				
			||||||
	TileIndex tile = p->ai.cur_tile_a;
 | 
						TileIndex tile = p->ai.cur_tile_a;
 | 
				
			||||||
	int offs;
 | 
					 | 
				
			||||||
	TileIndex tilenew;
 | 
						TileIndex tilenew;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 | 
						if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 | 
				
			||||||
@@ -2164,13 +2163,9 @@ static bool AiRemoveTileAndGoForward(Player *p)
 | 
				
			|||||||
			// This is not really needed the first place AiRemoveTileAndGoForward is called.
 | 
								// This is not really needed the first place AiRemoveTileAndGoForward is called.
 | 
				
			||||||
			if (DiagDirToAxis(GetBridgeRampDirection(tile)) != (p->ai.cur_dir_a & 1U)) return false;
 | 
								if (DiagDirToAxis(GetBridgeRampDirection(tile)) != (p->ai.cur_dir_a & 1U)) return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Find other side of bridge.
 | 
								tile = GetOtherBridgeEnd(tile);
 | 
				
			||||||
			offs = TileOffsByDir(p->ai.cur_dir_a);
 | 
					 | 
				
			||||||
			do {
 | 
					 | 
				
			||||||
				tile = TILE_MASK(tile - offs);
 | 
					 | 
				
			||||||
			} while (_m[tile].m5 & 0x40);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			tilenew = TILE_MASK(tile - offs);
 | 
								tilenew = TILE_MASK(tile - TileOffsByDir(p->ai.cur_dir_a));
 | 
				
			||||||
			// And clear the bridge.
 | 
								// And clear the bridge.
 | 
				
			||||||
			if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)))
 | 
								if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)))
 | 
				
			||||||
				return false;
 | 
									return false;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										17
									
								
								bridge_map.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								bridge_map.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					/* $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "stdafx.h"
 | 
				
			||||||
 | 
					#include "openttd.h"
 | 
				
			||||||
 | 
					#include "bridge_map.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TileIndex GetOtherBridgeEnd(TileIndex tile)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						TileIndexDiff delta = TileOffsByDir(GetBridgeRampDirection(tile));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						do {
 | 
				
			||||||
 | 
							tile += delta;
 | 
				
			||||||
 | 
						} while (!IsBridgeRamp(tile));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return tile;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										12
									
								
								bridge_map.h
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								bridge_map.h
									
									
									
									
									
								
							@@ -10,6 +10,12 @@
 | 
				
			|||||||
#include "tile.h"
 | 
					#include "tile.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline bool IsBridgeRamp(TileIndex t)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return !HASBIT(_m[t].m5, 6);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Get the direction pointing onto the bridge
 | 
					 * Get the direction pointing onto the bridge
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@@ -22,6 +28,12 @@ static inline DiagDirection GetBridgeRampDirection(TileIndex t)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Starting at one bridge end finds the other bridge end
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					TileIndex GetOtherBridgeEnd(TileIndex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline void SetClearUnderBridge(TileIndex t)
 | 
					static inline void SetClearUnderBridge(TileIndex t)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	SetTileOwner(t, OWNER_NONE);
 | 
						SetTileOwner(t, OWNER_NONE);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -809,7 +809,7 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
 | 
				
			|||||||
		if (!CheckTileOwnership(tile)) return CMD_ERROR;
 | 
							if (!CheckTileOwnership(tile)) return CMD_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// railway bridge
 | 
							// railway bridge
 | 
				
			||||||
		tile = FindEdgesOfBridge(tile, &endtile);
 | 
							tile = GetOtherBridgeEnd(tile);
 | 
				
			||||||
		// Make sure there's no vehicle on the bridge
 | 
							// Make sure there's no vehicle on the bridge
 | 
				
			||||||
		v = FindVehicleBetween(tile, endtile, z);
 | 
							v = FindVehicleBetween(tile, endtile, z);
 | 
				
			||||||
		if (v != NULL) {
 | 
							if (v != NULL) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user