(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
This commit is contained in:
		@@ -78,10 +78,7 @@ static inline uint GetBridgeType(TileIndex t)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static inline DiagDirection GetBridgeRampDirection(TileIndex t)
 | 
					static inline DiagDirection GetBridgeRampDirection(TileIndex t)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* Heavy wizardry to convert the X/Y (bit 0) + N/S (bit 5) encoding of
 | 
						return ReverseDiagDir(XYNSToDiagDir((Axis)GB(_m[t].m5, 0, 1), GB(_m[t].m5, 5, 1)));
 | 
				
			||||||
	 * bridges to a DiagDirection
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	return (DiagDirection)((6 - (_m[t].m5 >> 4 & 2) - (_m[t].m5 & 1)) % 4);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										16
									
								
								depot.h
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								depot.h
									
									
									
									
									
								
							@@ -12,6 +12,7 @@
 | 
				
			|||||||
#include "road_map.h"
 | 
					#include "road_map.h"
 | 
				
			||||||
#include "tile.h"
 | 
					#include "tile.h"
 | 
				
			||||||
#include "variables.h"
 | 
					#include "variables.h"
 | 
				
			||||||
 | 
					#include "water_map.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Depot {
 | 
					struct Depot {
 | 
				
			||||||
	TileIndex xy;
 | 
						TileIndex xy;
 | 
				
			||||||
@@ -98,20 +99,11 @@ static inline DiagDirection GetDepotDirection(TileIndex tile, TransportType type
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	assert(IsTileDepotType(tile, type));
 | 
						assert(IsTileDepotType(tile, type));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (type)
 | 
						switch (type) {
 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		case TRANSPORT_RAIL:  return GetRailDepotDirection(tile);
 | 
							case TRANSPORT_RAIL:  return GetRailDepotDirection(tile);
 | 
				
			||||||
		case TRANSPORT_ROAD:  return GetRoadDepotDirection(tile);
 | 
							case TRANSPORT_ROAD:  return GetRoadDepotDirection(tile);
 | 
				
			||||||
		case TRANSPORT_WATER:
 | 
							case TRANSPORT_WATER: return GetShipDepotDirection(tile);
 | 
				
			||||||
			/* Water is stubborn, it stores the directions in a different order. */
 | 
							default: return INVALID_DIAGDIR; /* Not reached */
 | 
				
			||||||
			switch (GB(_m[tile].m5, 0, 2)) {
 | 
					 | 
				
			||||||
				case 0: return DIAGDIR_NE;
 | 
					 | 
				
			||||||
				case 1: return DIAGDIR_SW;
 | 
					 | 
				
			||||||
				case 2: return DIAGDIR_NW;
 | 
					 | 
				
			||||||
				case 3: return DIAGDIR_SE;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			return INVALID_DIAGDIR; /* Not reached */
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								direction.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								direction.h
									
									
									
									
									
								
							@@ -113,6 +113,16 @@ static inline DiagDirection AxisToDiagDir(Axis a)
 | 
				
			|||||||
	return (DiagDirection)(2 - a);
 | 
						return (DiagDirection)(2 - a);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Convert an axis and a flag for north/south into a DiagDirection
 | 
				
			||||||
 | 
					 * @param ns north -> 0, south -> 1
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static inline DiagDirection XYNSToDiagDir(Axis xy, uint ns)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return (DiagDirection)(xy * 3 ^ ns * 2);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline bool IsValidDiagDirection(DiagDirection d)
 | 
					static inline bool IsValidDiagDirection(DiagDirection d)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return d < DIAGDIR_END;
 | 
						return d < DIAGDIR_END;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1989,7 +1989,7 @@ Trackdir GetVehicleTrackdir(const Vehicle* v)
 | 
				
			|||||||
		case VEH_Ship:
 | 
							case VEH_Ship:
 | 
				
			||||||
			if (v->u.ship.state == 0x80)  /* Inside a depot? */
 | 
								if (v->u.ship.state == 0x80)  /* Inside a depot? */
 | 
				
			||||||
				/* We'll assume the ship is facing outwards */
 | 
									/* We'll assume the ship is facing outwards */
 | 
				
			||||||
				return DiagdirToDiagTrackdir(GetDepotDirection(v->tile, TRANSPORT_WATER)); /* Ship in depot */
 | 
									return DiagdirToDiagTrackdir(GetShipDepotDirection(v->tile));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.ship.state),v->direction);
 | 
								return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.ship.state),v->direction);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,6 +63,11 @@ static inline Axis GetShipDepotAxis(TileIndex t)
 | 
				
			|||||||
	return (Axis)GB(_m[t].m5, 1, 1);
 | 
						return (Axis)GB(_m[t].m5, 1, 1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline DiagDirection GetShipDepotDirection(TileIndex t)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return XYNSToDiagDir(GetShipDepotAxis(t), GB(_m[t].m5, 0, 1));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline DiagDirection GetLockDirection(TileIndex t)
 | 
					static inline DiagDirection GetLockDirection(TileIndex t)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return (DiagDirection)GB(_m[t].m5, 0, 2);
 | 
						return (DiagDirection)GB(_m[t].m5, 0, 2);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user