src/roadveh_cmd.cpp
branchnoai
changeset 9704 197cb8c6ae17
parent 9703 d2a6acdbd665
child 9718 f82a4facea8b
equal deleted inserted replaced
9703:d2a6acdbd665 9704:197cb8c6ae17
   999 
   999 
  1000 struct OvertakeData {
  1000 struct OvertakeData {
  1001 	const Vehicle* u;
  1001 	const Vehicle* u;
  1002 	const Vehicle* v;
  1002 	const Vehicle* v;
  1003 	TileIndex tile;
  1003 	TileIndex tile;
  1004 	byte tilebits;
  1004 	uint16 tilebits;
  1005 };
  1005 };
  1006 
  1006 
  1007 static void* EnumFindVehToOvertake(Vehicle* v, void* data)
  1007 static void* EnumFindVehToOvertake(Vehicle* v, void* data)
  1008 {
  1008 {
  1009 	const OvertakeData* od = (OvertakeData*)data;
  1009 	const OvertakeData* od = (OvertakeData*)data;
  1015 
  1015 
  1016 static bool FindRoadVehToOvertake(OvertakeData *od)
  1016 static bool FindRoadVehToOvertake(OvertakeData *od)
  1017 {
  1017 {
  1018 	uint32 bits;
  1018 	uint32 bits;
  1019 
  1019 
  1020 	bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD, od->v->u.road.compatible_roadtypes) & 0x3F;
  1020 	bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD, od->v->u.road.compatible_roadtypes);
  1021 
  1021 	bits |= bits >> 8;
  1022 	if (!(od->tilebits & bits) || (bits & 0x3C) || (bits & 0x3F3F0000))
  1022 
       
  1023 	if (!(od->tilebits & bits) || (bits & 0x3C3C) || (bits & 0x3F3F0000))
  1023 		return true;
  1024 		return true;
  1024 	return VehicleFromPos(od->tile, od, EnumFindVehToOvertake) != NULL;
  1025 	return VehicleFromPos(od->tile, od, EnumFindVehToOvertake) != NULL;
  1025 }
  1026 }
  1026 
  1027 
  1027 static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
  1028 static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
  1028 {
  1029 {
  1029 	OvertakeData od;
  1030 	OvertakeData od;
  1030 	byte tt;
  1031 	uint16 tt;
  1031 
  1032 
  1032 	od.v = v;
  1033 	od.v = v;
  1033 	od.u = u;
  1034 	od.u = u;
  1034 
  1035 
  1035 	if (u->max_speed >= v->max_speed &&
  1036 	if (u->max_speed >= v->max_speed &&
  1039 	}
  1040 	}
  1040 
  1041 
  1041 	/* Trams can't overtake other trams */
  1042 	/* Trams can't overtake other trams */
  1042 	if (v->u.road.roadtype == ROADTYPE_TRAM) return;
  1043 	if (v->u.road.roadtype == ROADTYPE_TRAM) return;
  1043 
  1044 
       
  1045 	/* Don't overtake in stations */
       
  1046 	if (IsTileType(v->tile, MP_STATION)) return;
       
  1047 
  1044 	/* For now, articulated road vehicles can't overtake anything. */
  1048 	/* For now, articulated road vehicles can't overtake anything. */
  1045 	if (RoadVehHasArticPart(v)) return;
  1049 	if (RoadVehHasArticPart(v)) return;
  1046 
  1050 
  1047 	if (v->direction != u->direction || !(v->direction & 1)) return;
  1051 	if (v->direction != u->direction || !(v->direction & 1)) return;
  1048 
  1052 
  1049 	/* Check if vehicle is in a road stop, depot, tunnel or bridge or not on a straight road */
  1053 	/* Check if vehicle is in a road stop, depot, tunnel or bridge or not on a straight road */
  1050 	if (v->u.road.state >= RVSB_IN_ROAD_STOP || !IsStraightRoadTrackdir((Trackdir)(v->u.road.state & RVSB_TRACKDIR_MASK))) return;
  1054 	if (v->u.road.state >= RVSB_IN_ROAD_STOP || !IsStraightRoadTrackdir((Trackdir)(v->u.road.state & RVSB_TRACKDIR_MASK))) return;
  1051 
  1055 
  1052 	tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes) & 0x3F;
  1056 	tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes);
       
  1057 	tt |= tt >> 8;
       
  1058 	tt &= 0x3F;
       
  1059 
  1053 	if ((tt & 3) == 0) return;
  1060 	if ((tt & 3) == 0) return;
  1054 	if ((tt & 0x3C) != 0) return;
  1061 	if ((tt & 0x3C) != 0) return;
  1055 
  1062 
  1056 	if (tt == 3) tt = (v->direction & 2) ? 2 : 1;
  1063 	if (tt == 3) tt = (v->direction & 2) ? 2 : 1;
  1057 	od.tilebits = tt;
  1064 	od.tilebits = tt;
  1648 		/* Vehicle is not in a road stop.
  1655 		/* Vehicle is not in a road stop.
  1649 		 * Check for another vehicle to overtake */
  1656 		 * Check for another vehicle to overtake */
  1650 		Vehicle* u = RoadVehFindCloseTo(v, x, y, new_dir);
  1657 		Vehicle* u = RoadVehFindCloseTo(v, x, y, new_dir);
  1651 
  1658 
  1652 		if (u != NULL) {
  1659 		if (u != NULL) {
  1653 			v->cur_speed = u->cur_speed;
       
  1654 			/* There is a vehicle in front overtake it if possible */
  1660 			/* There is a vehicle in front overtake it if possible */
  1655 			if (v->u.road.overtaking == 0) RoadVehCheckOvertake(v, u);
  1661 			if (v->u.road.overtaking == 0) RoadVehCheckOvertake(v, u);
       
  1662 			if (v->u.road.overtaking == 0) v->cur_speed = u->cur_speed;
  1656 			return false;
  1663 			return false;
  1657 		}
  1664 		}
  1658 	}
  1665 	}
  1659 
  1666 
  1660 	old_dir = v->direction;
  1667 	old_dir = v->direction;
  2024 		 * [Refit] button near each wagon. */
  2031 		 * [Refit] button near each wagon. */
  2025 		if (!CanRefitTo(v->engine_type, new_cid)) continue;
  2032 		if (!CanRefitTo(v->engine_type, new_cid)) continue;
  2026 
  2033 
  2027 		if (v->cargo_cap == 0) continue;
  2034 		if (v->cargo_cap == 0) continue;
  2028 
  2035 
  2029 		if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) {
  2036 		if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
  2030 			/* Back up the cargo type */
  2037 			/* Back up the cargo type */
  2031 			CargoID temp_cid = v->cargo_type;
  2038 			CargoID temp_cid = v->cargo_type;
  2032 			byte temp_subtype = v->cargo_subtype;
  2039 			byte temp_subtype = v->cargo_subtype;
  2033 			v->cargo_type = new_cid;
  2040 			v->cargo_type = new_cid;
  2034 			v->cargo_subtype = new_subtype;
  2041 			v->cargo_subtype = new_subtype;