internal bool MakeRoute(TownNode fromTown, TownNode toTown) { AILog.Warning($"Building a route from {fromTown.Name} to {toTown.Name}."); RoadStationInfo fromStationTile = stations[fromTown.TownId]; RoadStationInfo toStationTile = stations[toTown.TownId]; Edge <TownNode> foundEdge = null; foreach (var edge in this.Graph.Edges) { if (((edge.Node1 == fromTown) && (edge.Node2 == toTown)) || ((edge.Node2 == fromTown) && (edge.Node1 == toTown))) { foundEdge = edge; } } if (foundEdge == null) { AILog.Warning($"No route found from {fromTown.Name} to {toTown.Name}."); return(false); } var list = new AIEngineList(AIVehicle.VT_ROAD); list.Valuate(AIEngine.GetMaxSpeed); VehicleID vehicleId = null; foreach (var(engineType, _) in list) { if (AICargo.HasCargoClass(AIEngine.GetCargoType(engineType), AICargo.CC_PASSENGERS)) { var price = AIEngine.GetPrice(engineType); CsTestAi.EnsureMoney(price + 1000); vehicleId = AIVehicle.BuildVehicle(depots[fromTown.TownId].tile, engineType); break; } } if (vehicleId == null) { AILog.Error("No passnger vehicle found."); } if (AIVehicle.IsValidVehicle(vehicleId)) { AIOrder.AppendOrder(vehicleId, fromStationTile.tile, AIOrder.OF_NONE); AIOrder.AppendOrder(vehicleId, toStationTile.tile, AIOrder.OF_NONE); AIVehicle.StartStopVehicle(vehicleId); if (!vehicles.ContainsKey(foundEdge)) { vehicles.Add(foundEdge, new List <VehicleID>()); } var vehicleList = vehicles[foundEdge]; vehicleList.Add(vehicleId); AILog.Info($"Route contains now {vehicleList.Count} vehicles."); return(true); } AILog.Error("Invalid vehicle."); return(false); }