예제 #1
0
파일: TrainManager.cs 프로젝트: ttv86/CsNut
        public static void BuildTrain(TileIndex depot, StationID[] stations, Action <TileIndex, string> sign = null)
        {
            var list = new AIEngineList(AIVehicle.VT_RAIL);

            list.Valuate(AIEngine.GetMaxSpeed);
            EngineID passangerWagon = null;
            EngineID mailWagon      = null;

            foreach (var(a, b) in list)
            {
                if (AIEngine.IsBuildable(a) && !AIEngine.IsWagon(a))
                {
                    //AILog.Info(a + ": " + AIEngine.GetName(a) + " | " + AIEngine.GetMaxSpeed(a) + " | " + AIEngine.GetReliability(a) + " | " + AIEngine.GetMaxTractiveEffort(a));
                }
                else if (AIEngine.IsBuildable(a) && AIEngine.IsWagon(a))
                {
                    //AILog.Info(a + ": " + AIEngine.GetName(a) + " | " + AIEngine.GetCargoType(a));
                    if (AICargo.HasCargoClass(AIEngine.GetCargoType(a), AICargo.CC_PASSENGERS))
                    {
                        passangerWagon = a;
                        //AILog.Info("passanger");
                    }
                    else if (AICargo.HasCargoClass(AIEngine.GetCargoType(a), AICargo.CC_MAIL))
                    {
                        mailWagon = a;
                        //AILog.Info("mail");
                    }
                }
            }

            var engineType = list.Begin();
            //AILog.Info("Engine id: " + engineType);
            //AILog.Info("Building: " + AIEngine.GetName(engineType));
            var train          = AIVehicle.BuildVehicle(depot, engineType);
            var firstPassanger = AIVehicle.BuildVehicle(depot, passangerWagon);

            AIVehicle.BuildVehicle(depot, passangerWagon);
            AIVehicle.BuildVehicle(depot, passangerWagon);
            var firstMail = AIVehicle.BuildVehicle(depot, mailWagon);

            AIVehicle.MoveWagonChain(firstMail, 0, train, 0);
            AIVehicle.MoveWagonChain(firstPassanger, 0, train, 0);

            for (var i = 0; i < stations.Length; i++)
            {
                AIOrder.AppendOrder(train, AIStation.GetLocation(stations[i]), AIOrder.OF_NONE);
            }

            AIVehicle.StartStopVehicle(train);
        }
예제 #2
0
        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);
        }