src/roadveh_cmd.cpp
branchnoai
changeset 10776 07203fc29812
parent 10715 6bdf79ffb022
child 10867 5de2923d6e59
equal deleted inserted replaced
10774:2c882f0468f2 10776:07203fc29812
   204 
   204 
   205 	v = vl[0];
   205 	v = vl[0];
   206 
   206 
   207 	/* find the first free roadveh id */
   207 	/* find the first free roadveh id */
   208 	unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_ROAD);
   208 	unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_ROAD);
   209 	if (unit_num > _settings.vehicle.max_roadveh)
   209 	if (unit_num > _settings_game.vehicle.max_roadveh)
   210 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   210 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   211 
   211 
   212 	if (flags & DC_EXEC) {
   212 	if (flags & DC_EXEC) {
   213 		int x;
   213 		int x;
   214 		int y;
   214 		int y;
   256 		v->max_age = e->lifelength * 366;
   256 		v->max_age = e->lifelength * 366;
   257 		_new_vehicle_id = v->index;
   257 		_new_vehicle_id = v->index;
   258 
   258 
   259 		v->name = NULL;
   259 		v->name = NULL;
   260 
   260 
   261 		v->service_interval = _settings.vehicle.servint_roadveh;
   261 		v->service_interval = _settings_game.vehicle.servint_roadveh;
   262 
   262 
   263 		v->date_of_last_service = _date;
   263 		v->date_of_last_service = _date;
   264 		v->build_year = _cur_year;
   264 		v->build_year = _cur_year;
   265 
   265 
   266 		v->cur_image = 0xC15;
   266 		v->cur_image = 0xC15;
   418 	return false;
   418 	return false;
   419 }
   419 }
   420 
   420 
   421 static const Depot* FindClosestRoadDepot(const Vehicle* v)
   421 static const Depot* FindClosestRoadDepot(const Vehicle* v)
   422 {
   422 {
   423 	switch (_settings.pf.pathfinder_for_roadvehs) {
   423 	switch (_settings_game.pf.pathfinder_for_roadvehs) {
   424 		case VPF_YAPF: /* YAPF */
   424 		case VPF_YAPF: /* YAPF */
   425 			return YapfFindNearestRoadDepot(v);
   425 			return YapfFindNearestRoadDepot(v);
   426 
   426 
   427 		case VPF_NPF: { /* NPF */
   427 		case VPF_NPF: { /* NPF */
   428 			/* See where we are now */
   428 			/* See where we are now */
   703 
   703 
   704 		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
   704 		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
   705 		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
   705 		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
   706 
   706 
   707 		if (!PlayVehicleSound(v, VSE_BREAKDOWN)) {
   707 		if (!PlayVehicleSound(v, VSE_BREAKDOWN)) {
   708 			SndPlayVehicleFx((_settings.game_creation.landscape != LT_TOYLAND) ?
   708 			SndPlayVehicleFx((_settings_game.game_creation.landscape != LT_TOYLAND) ?
   709 				SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v);
   709 				SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v);
   710 		}
   710 		}
   711 
   711 
   712 		if (!(v->vehstatus & VS_HIDDEN)) {
   712 		if (!(v->vehstatus & VS_HIDDEN)) {
   713 			Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
   713 			Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
   864 	}
   864 	}
   865 
   865 
   866 	/* updates statusbar only if speed have changed to save CPU time */
   866 	/* updates statusbar only if speed have changed to save CPU time */
   867 	if (spd != v->cur_speed) {
   867 	if (spd != v->cur_speed) {
   868 		v->cur_speed = spd;
   868 		v->cur_speed = spd;
   869 		if (_settings.gui.vehicle_speed) {
   869 		if (_settings_client.gui.vehicle_speed) {
   870 			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
   870 			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
   871 		}
   871 		}
   872 	}
   872 	}
   873 
   873 
   874 	/* Decrease somewhat when turning */
   874 	/* Decrease somewhat when turning */
  1086 			if (GetRoadStopType(tile) != rstype) {
  1086 			if (GetRoadStopType(tile) != rstype) {
  1087 				/* Wrong station type */
  1087 				/* Wrong station type */
  1088 				trackdirs = TRACKDIR_BIT_NONE;
  1088 				trackdirs = TRACKDIR_BIT_NONE;
  1089 			} else {
  1089 			} else {
  1090 				/* Proper station type, check if there is free loading bay */
  1090 				/* Proper station type, check if there is free loading bay */
  1091 				if (!_settings.pf.roadveh_queue && IsStandardRoadStopTile(tile) &&
  1091 				if (!_settings_game.pf.roadveh_queue && IsStandardRoadStopTile(tile) &&
  1092 						!GetRoadStopByTile(tile, rstype)->HasFreeBay()) {
  1092 						!GetRoadStopByTile(tile, rstype)->HasFreeBay()) {
  1093 					/* Station is full and RV queuing is off */
  1093 					/* Station is full and RV queuing is off */
  1094 					trackdirs = TRACKDIR_BIT_NONE;
  1094 					trackdirs = TRACKDIR_BIT_NONE;
  1095 				}
  1095 				}
  1096 			}
  1096 			}
  1125 	/* Only one track to choose between? */
  1125 	/* Only one track to choose between? */
  1126 	if (KillFirstBit(trackdirs) == TRACKDIR_BIT_NONE) {
  1126 	if (KillFirstBit(trackdirs) == TRACKDIR_BIT_NONE) {
  1127 		return_track(FindFirstBit2x64(trackdirs));
  1127 		return_track(FindFirstBit2x64(trackdirs));
  1128 	}
  1128 	}
  1129 
  1129 
  1130 	switch (_settings.pf.pathfinder_for_roadvehs) {
  1130 	switch (_settings_game.pf.pathfinder_for_roadvehs) {
  1131 		case VPF_YAPF: { /* YAPF */
  1131 		case VPF_YAPF: { /* YAPF */
  1132 			Trackdir trackdir = YapfChooseRoadTrack(v, tile, enterdir);
  1132 			Trackdir trackdir = YapfChooseRoadTrack(v, tile, enterdir);
  1133 			if (trackdir != INVALID_TRACKDIR) return_track(trackdir);
  1133 			if (trackdir != INVALID_TRACKDIR) return_track(trackdir);
  1134 			return_track(PickRandomBit(trackdirs));
  1134 			return_track(PickRandomBit(trackdirs));
  1135 		} break;
  1135 		} break;
  1212 	return best_track;
  1212 	return best_track;
  1213 }
  1213 }
  1214 
  1214 
  1215 static uint RoadFindPathToStop(const Vehicle *v, TileIndex tile)
  1215 static uint RoadFindPathToStop(const Vehicle *v, TileIndex tile)
  1216 {
  1216 {
  1217 	if (_settings.pf.pathfinder_for_roadvehs == VPF_YAPF) {
  1217 	if (_settings_game.pf.pathfinder_for_roadvehs == VPF_YAPF) {
  1218 		/* use YAPF */
  1218 		/* use YAPF */
  1219 		return YapfRoadVehDistanceToTile(v, tile);
  1219 		return YapfRoadVehDistanceToTile(v, tile);
  1220 	}
  1220 	}
  1221 
  1221 
  1222 	/* use NPF */
  1222 	/* use NPF */
  1274 
  1274 
  1275 	DiagDirection dir = GetRoadDepotDirection(v->tile);
  1275 	DiagDirection dir = GetRoadDepotDirection(v->tile);
  1276 	v->direction = DiagDirToDir(dir);
  1276 	v->direction = DiagDirToDir(dir);
  1277 
  1277 
  1278 	Trackdir tdir = _roadveh_depot_exit_trackdir[dir];
  1278 	Trackdir tdir = _roadveh_depot_exit_trackdir[dir];
  1279 	const RoadDriveEntry *rdp = _road_drive_data[v->u.road.roadtype][(_settings.vehicle.road_side << RVS_DRIVE_SIDE) + tdir];
  1279 	const RoadDriveEntry *rdp = _road_drive_data[v->u.road.roadtype][(_settings_game.vehicle.road_side << RVS_DRIVE_SIDE) + tdir];
  1280 
  1280 
  1281 	int x = TileX(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].x & 0xF);
  1281 	int x = TileX(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].x & 0xF);
  1282 	int y = TileY(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].y & 0xF);
  1282 	int y = TileY(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].y & 0xF);
  1283 
  1283 
  1284 	if (first) {
  1284 	if (first) {
  1452 	/* Get move position data for next frame.
  1452 	/* Get move position data for next frame.
  1453 	 * For a drive-through road stop use 'straight road' move data.
  1453 	 * For a drive-through road stop use 'straight road' move data.
  1454 	 * In this case v->u.road.state is masked to give the road stop entry direction. */
  1454 	 * In this case v->u.road.state is masked to give the road stop entry direction. */
  1455 	rd = _road_drive_data[v->u.road.roadtype][(
  1455 	rd = _road_drive_data[v->u.road.roadtype][(
  1456 		(HasBit(v->u.road.state, RVS_IN_DT_ROAD_STOP) ? v->u.road.state & RVSB_ROAD_STOP_TRACKDIR_MASK : v->u.road.state) +
  1456 		(HasBit(v->u.road.state, RVS_IN_DT_ROAD_STOP) ? v->u.road.state & RVSB_ROAD_STOP_TRACKDIR_MASK : v->u.road.state) +
  1457 		(_settings.vehicle.road_side << RVS_DRIVE_SIDE)) ^ v->u.road.overtaking][v->u.road.frame + 1];
  1457 		(_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)) ^ v->u.road.overtaking][v->u.road.frame + 1];
  1458 
  1458 
  1459 	if (rd.x & RDE_NEXT_TILE) {
  1459 	if (rd.x & RDE_NEXT_TILE) {
  1460 		TileIndex tile = v->tile + TileOffsByDiagDir((DiagDirection)(rd.x & 3));
  1460 		TileIndex tile = v->tile + TileOffsByDiagDir((DiagDirection)(rd.x & 3));
  1461 		Trackdir dir;
  1461 		Trackdir dir;
  1462 		uint32 r;
  1462 		uint32 r;
  1530 				tile = v->tile;
  1530 				tile = v->tile;
  1531 			}
  1531 			}
  1532 		}
  1532 		}
  1533 
  1533 
  1534 		/* Get position data for first frame on the new tile */
  1534 		/* Get position data for first frame on the new tile */
  1535 		rdp = _road_drive_data[v->u.road.roadtype][(dir + (_settings.vehicle.road_side << RVS_DRIVE_SIDE)) ^ v->u.road.overtaking];
  1535 		rdp = _road_drive_data[v->u.road.roadtype][(dir + (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)) ^ v->u.road.overtaking];
  1536 
  1536 
  1537 		x = TileX(tile) * TILE_SIZE + rdp[start_frame].x;
  1537 		x = TileX(tile) * TILE_SIZE + rdp[start_frame].x;
  1538 		y = TileY(tile) * TILE_SIZE + rdp[start_frame].y;
  1538 		y = TileY(tile) * TILE_SIZE + rdp[start_frame].y;
  1539 
  1539 
  1540 		newdir = RoadVehGetSlidingDirection(v, x, y);
  1540 		newdir = RoadVehGetSlidingDirection(v, x, y);
  1633 		if (dir == INVALID_TRACKDIR) {
  1633 		if (dir == INVALID_TRACKDIR) {
  1634 			v->cur_speed = 0;
  1634 			v->cur_speed = 0;
  1635 			return false;
  1635 			return false;
  1636 		}
  1636 		}
  1637 
  1637 
  1638 		rdp = _road_drive_data[v->u.road.roadtype][(_settings.vehicle.road_side << RVS_DRIVE_SIDE) + dir];
  1638 		rdp = _road_drive_data[v->u.road.roadtype][(_settings_game.vehicle.road_side << RVS_DRIVE_SIDE) + dir];
  1639 
  1639 
  1640 		x = TileX(v->tile) * TILE_SIZE + rdp[turn_around_start_frame].x;
  1640 		x = TileX(v->tile) * TILE_SIZE + rdp[turn_around_start_frame].x;
  1641 		y = TileY(v->tile) * TILE_SIZE + rdp[turn_around_start_frame].y;
  1641 		y = TileY(v->tile) * TILE_SIZE + rdp[turn_around_start_frame].y;
  1642 
  1642 
  1643 		newdir = RoadVehGetSlidingDirection(v, x, y);
  1643 		newdir = RoadVehGetSlidingDirection(v, x, y);
  1712 	 * if the vehicle is in a drive-through road stop and this is the destination station
  1712 	 * if the vehicle is in a drive-through road stop and this is the destination station
  1713 	 * and it's the correct type of stop (bus or truck) and the frame equals the stop frame...
  1713 	 * and it's the correct type of stop (bus or truck) and the frame equals the stop frame...
  1714 	 * (the station test and stop type test ensure that other vehicles, using the road stop as
  1714 	 * (the station test and stop type test ensure that other vehicles, using the road stop as
  1715 	 * a through route, do not stop) */
  1715 	 * a through route, do not stop) */
  1716 	if (IsRoadVehFront(v) && ((IsInsideMM(v->u.road.state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END) &&
  1716 	if (IsRoadVehFront(v) && ((IsInsideMM(v->u.road.state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END) &&
  1717 			_road_veh_data_1[v->u.road.state - RVSB_IN_ROAD_STOP + (_settings.vehicle.road_side << RVS_DRIVE_SIDE)] == v->u.road.frame) ||
  1717 			_road_veh_data_1[v->u.road.state - RVSB_IN_ROAD_STOP + (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)] == v->u.road.frame) ||
  1718 			(IsInsideMM(v->u.road.state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) &&
  1718 			(IsInsideMM(v->u.road.state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) &&
  1719 			v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile)) &&
  1719 			v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile)) &&
  1720 			GetRoadStopType(v->tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
  1720 			GetRoadStopType(v->tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
  1721 			v->u.road.frame == RVC_DRIVE_THROUGH_STOP_FRAME))) {
  1721 			v->u.road.frame == RVC_DRIVE_THROUGH_STOP_FRAME))) {
  1722 
  1722 
  1888 }
  1888 }
  1889 
  1889 
  1890 static void CheckIfRoadVehNeedsService(Vehicle *v)
  1890 static void CheckIfRoadVehNeedsService(Vehicle *v)
  1891 {
  1891 {
  1892 	/* If we already got a slot at a stop, use that FIRST, and go to a depot later */
  1892 	/* If we already got a slot at a stop, use that FIRST, and go to a depot later */
  1893 	if (v->u.road.slot != NULL || _settings.vehicle.servint_roadveh == 0 || !v->NeedsAutomaticServicing()) return;
  1893 	if (v->u.road.slot != NULL || _settings_game.vehicle.servint_roadveh == 0 || !v->NeedsAutomaticServicing()) return;
  1894 	if (v->IsInDepot()) {
  1894 	if (v->IsInDepot()) {
  1895 		VehicleServiceInDepot(v);
  1895 		VehicleServiceInDepot(v);
  1896 		return;
  1896 		return;
  1897 	}
  1897 	}
  1898 
  1898