MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / HandlePathfindingResult

Method HandlePathfindingResult

src/vehicle.cpp:762–793  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

760 * @param path_found Whether the vehicle has a path to its destination.
761 */
762void Vehicle::HandlePathfindingResult(bool path_found)
763{
764 if (path_found) {
765 /* Route found, is the vehicle marked with "lost" flag? */
766 if (!this->vehicle_flags.Test(VehicleFlag::PathfinderLost)) return;
767
768 /* Clear the flag as the PF's problem was solved. */
769 this->vehicle_flags.Reset(VehicleFlag::PathfinderLost);
770 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
771 InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type));
772 /* Delete the news item. */
773 DeleteVehicleNews(this->index, AdviceType::VehicleLost);
774 return;
775 }
776
777 /* Were we already lost? */
778 if (this->vehicle_flags.Test(VehicleFlag::PathfinderLost)) return;
779
780 /* It is first time the problem occurred, set the "lost" flag. */
781 this->vehicle_flags.Set(VehicleFlag::PathfinderLost);
782 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
783 InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type));
784
785 /* Unbunching data is no longer valid. */
786 this->ResetDepotUnbunching();
787
788 /* Notify user about the event. */
789 AI::NewEvent(this->owner, new ScriptEventVehicleLost(this->index));
790 if (_settings_client.gui.lost_vehicle_warn && this->owner == _local_company) {
791 AddVehicleAdviceNewsItem(AdviceType::VehicleLost, GetEncodedString(STR_NEWS_VEHICLE_IS_LOST, this->index), this->index);
792 }
793}
794
795/** Destroy all stuff that (still) needs the virtual functions to work properly */
796void Vehicle::PreDestructor()

Callers 3

ChooseShipTrackFunction · 0.80
ChooseTrainTrackFunction · 0.80
RoadFindPathToDestFunction · 0.80

Calls 10

SetWindowWidgetDirtyFunction · 0.85
DeleteVehicleNewsFunction · 0.85
AddVehicleAdviceNewsItemFunction · 0.85
TestMethod · 0.80
ResetDepotUnbunchingMethod · 0.80
GetEncodedStringFunction · 0.70
ResetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected