Changeset - r16765:532d8dc160e6
[Not reviewed]
master
0 3 0
rubidium - 14 years ago 2010-12-13 21:55:06
rubidium@openttd.org
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
3 files changed with 35 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/train_cmd.cpp
Show inline comments
 
@@ -2405,38 +2405,13 @@ static Track ChooseTrainTrack(Train *v, 
 
		/* Pathfinders are able to tell that route was only 'guessed'. */
 
		bool      path_not_found = false;
 
		TileIndex new_tile = res_dest.tile;
 

	
 
		Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, &path_not_found, do_track_reservation, &res_dest);
 
		if (new_tile == tile) best_track = next_track;
 

	
 
		/* handle "path not found" state */
 
		if (path_not_found) {
 
			/* PF didn't find the route */
 
			if (!HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) {
 
				/* It is first time the problem occurred, set the "lost" flag. */
 
				SetBit(v->vehicle_flags, VF_PATHFINDER_LOST);
 
				/* and notify user about the event */
 
				AI::NewEvent(v->owner, new AIEventVehicleLost(v->index));
 
				if (_settings_client.gui.lost_vehicle_warn && v->owner == _local_company) {
 
					SetDParam(0, v->index);
 
					AddVehicleNewsItem(
 
						STR_NEWS_VEHICLE_IS_LOST,
 
						NS_ADVICE,
 
						v->index
 
					);
 
				}
 
			}
 
		} else {
 
			/* route found, is the train marked with "path not found" flag? */
 
			if (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) {
 
				/* clear the flag as the PF's problem was solved */
 
				ClrBit(v->vehicle_flags, VF_PATHFINDER_LOST);
 
				/* can we also delete the "News" item somehow? */
 
			}
 
		}
 
		v->HandlePathfindingResult(!path_not_found);
 
	}
 

	
 
	/* No track reservation requested -> finished. */
 
	if (!do_track_reservation) return best_track;
 

	
 
	/* A path was found, but could not be reserved. */
src/vehicle.cpp
Show inline comments
 
@@ -621,12 +621,45 @@ bool Vehicle::IsEngineCountable() const
 
		case VEH_ROAD: return RoadVehicle::From(this)->IsRoadVehFront();
 
		case VEH_SHIP: return true;
 
		default: return false; // Only count company buildable vehicles
 
	}
 
}
 

	
 
/**
 
 * Handle the pathfinding result, especially the lost status.
 
 * If the vehicle is now lost and wasn't previously fire an
 
 * event to the AIs and a news message to the user. If the
 
 * vehicle is not lost anymore remove the news message.
 
 * @param path_found Whether the vehicle has a path to its destination.
 
 */
 
void Vehicle::HandlePathfindingResult(bool path_found)
 
{
 
	if (path_found) {
 
		/* Route found, is the vehicle marked with "lost" flag? */
 
		if (!HasBit(this->vehicle_flags, VF_PATHFINDER_LOST)) return;
 

	
 
		/* Clear the flag as the PF's problem was solved. */
 
		ClrBit(this->vehicle_flags, VF_PATHFINDER_LOST);
 
		/* Delete the news item. */
 
		DeleteVehicleNews(this->index, STR_NEWS_VEHICLE_IS_LOST);
 
		return;
 
	}
 

	
 
	/* Were we already lost? */
 
	if (HasBit(this->vehicle_flags, VF_PATHFINDER_LOST)) return;
 

	
 
	/* It is first time the problem occurred, set the "lost" flag. */
 
	SetBit(this->vehicle_flags, VF_PATHFINDER_LOST);
 
	/* Notify user about the event. */
 
	AI::NewEvent(this->owner, new AIEventVehicleLost(this->index));
 
	if (_settings_client.gui.lost_vehicle_warn && this->owner == _local_company) {
 
		SetDParam(0, this->index);
 
		AddVehicleNewsItem(STR_NEWS_VEHICLE_IS_LOST, NS_ADVICE, this->index);
 
	}
 
}
 

	
 
void Vehicle::PreDestructor()
 
{
 
	if (CleaningPool()) return;
 

	
 
	if (Station::IsValidID(this->last_station_visited)) {
 
		Station::Get(this->last_station_visited)->loading_vehicles.remove(this);
src/vehicle_base.h
Show inline comments
 
@@ -657,12 +657,13 @@ public:
 
	{
 
		return (this->orders.list == NULL) ? NULL : this->orders.list->GetLastOrder();
 
	}
 

	
 
	bool IsEngineCountable() const;
 
	bool HasDepotOrder() const;
 
	void HandlePathfindingResult(bool path_found);
 
};
 

	
 
#define FOR_ALL_VEHICLES_FROM(var, start) FOR_ALL_ITEMS_FROM(Vehicle, vehicle_index, var, start)
 
#define FOR_ALL_VEHICLES(var) FOR_ALL_VEHICLES_FROM(var, 0)
 

	
 
/**
0 comments (0 inline, 0 general)