bridge_cmd.c
branchcustombridgeheads
changeset 5611 11da6bafbfb9
parent 5608 a0768f524071
child 5612 5e103bb5236d
equal deleted inserted replaced
5610:f67ca2533978 5611:11da6bafbfb9
   980 		return 0;
   980 		return 0;
   981 	}
   981 	}
   982 	return 0;
   982 	return 0;
   983 }
   983 }
   984 
   984 
   985 static uint32 VehicleEnter_Railway_Bridge(Vehicle *v, TileIndex tile, int x, int y)
   985 uint32 VehicleEnter_Railway_Bridge(Vehicle *v, TileIndex tile, int x, int y)
       
   986 {
       
   987 	DiagDirection dir;
       
   988 	assert(IsBridgeTile(v->tile));
       
   989 	dir = GetBridgeRampDirection(v->tile);
       
   990 	v->u.rail.track = 0x40;
       
   991 	v->direction = DiagDirToDir(dir);
       
   992 	CLRBIT(v->u.rail.flags, VRF_GOINGUP);
       
   993 	CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
       
   994 	return 0;
       
   995 }
       
   996 
       
   997 static uint32 VehicleEnter_Railway_BridgeRamp(Vehicle *v, TileIndex tile, int x, int y)
   986 {
   998 {
   987 	int z = GetSlopeZ(x, y) - v->z_pos;
   999 	int z = GetSlopeZ(x, y) - v->z_pos;
   988 
  1000 
   989 	DiagDirection dir;
  1001 	DiagDirection dir;
   990 
  1002 
  1002 		uint16 spd = _bridge[GetBridgeType(tile)].speed;
  1014 		uint16 spd = _bridge[GetBridgeType(tile)].speed;
  1003 		if (v->cur_speed > spd) v->cur_speed = spd;
  1015 		if (v->cur_speed > spd) v->cur_speed = spd;
  1004 	}
  1016 	}
  1005 
  1017 
  1006 	dir = GetBridgeRampDirection(tile);
  1018 	dir = GetBridgeRampDirection(tile);
  1007 	if (DirToDiagDir(v->direction) == dir ||
  1019 	if (v->direction == DiagDirToDir(ReverseDiagDir(dir))) {
  1008 			(IsTileType(tile, MP_RAILWAY_BRIDGE) && DirToDiagDir(v->direction) != ReverseDiagDir(dir))) {
  1020 		/* leaving the bridge */
  1009 		switch (dir) {
       
  1010 			default: NOT_REACHED();
       
  1011 			case DIAGDIR_NE: if ((x & 0xF) != 0)             return 0; break;
       
  1012 			case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break;
       
  1013 			case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break;
       
  1014 			case DIAGDIR_NW: if ((y & 0xF) != 0)             return 0; break;
       
  1015 		}
       
  1016 		v->u.rail.track = 0x40;
       
  1017 		CLRBIT(v->u.rail.flags, VRF_GOINGUP);
       
  1018 		CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
       
  1019 		return 4;
       
  1020 	} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
       
  1021 		v->tile = tile;
  1021 		v->tile = tile;
  1022 		if (v->u.rail.track == 0x40) {
  1022 		if (v->u.rail.track == 0x40) {
  1023 			v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2);
  1023 			v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2);
  1024 			return 4;
  1024 			return 4;
  1025 		}
  1025 		}
  1028 	return 0;
  1028 	return 0;
  1029 }
  1029 }
  1030 
  1030 
  1031 static uint32 VehicleEnter_Bridge(Vehicle *v, TileIndex tile, int x, int y)
  1031 static uint32 VehicleEnter_Bridge(Vehicle *v, TileIndex tile, int x, int y)
  1032 {
  1032 {
  1033 	if (v->type == VEH_Train) return VehicleEnter_Railway_Bridge(v, tile, x, y);
  1033 	if (v->type == VEH_Train) return VehicleEnter_Railway_BridgeRamp(v, tile, x, y);
  1034 
  1034 
  1035 	if (v->type == VEH_Road) return VehicleEnter_Street_Bridge(v, tile, x, y);
  1035 	if (v->type == VEH_Road) return VehicleEnter_Street_Bridge(v, tile, x, y);
  1036 
  1036 
  1037 	NOT_REACHED();
  1037 	NOT_REACHED();
  1038 }
  1038 }