Пример #1
0
        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 void UpdateRoutes()
        {
            AILog.Error(" -- UpdateRoutes --");
            CargoID passangerCargo = null;
            var     cargoList      = new AICargoList();

            foreach (var(cargo, _) in cargoList)
            {
                if (AICargo.HasCargoClass(cargo, AICargo.CC_PASSENGERS))
                {
                    passangerCargo = cargo;
                }
            }

            if (passangerCargo == null)
            {
                AILog.Error("No passanger cargo found.");
                return;
            }

            foreach (var edge in this.Graph.Edges)
            {
                if (!this.vehicles.ContainsKey(edge))
                {
                    continue;
                }

                var list     = this.vehicles[edge];
                var s1       = AIStation.GetStationID(stations[edge.Node1.TownId].tile);
                var s2       = AIStation.GetStationID(stations[edge.Node2.TownId].tile);
                var waiting1 = AIStation.GetCargoWaitingVia(s1, s2, passangerCargo);
                var waiting2 = AIStation.GetCargoWaitingVia(s2, s1, passangerCargo);
                var waiting  = waiting1 + waiting2;

                AILog.Info($"Route from {edge.Node1.Name} to {edge.Node2.Name} has {waiting} passangers waiting.");
                var target = (waiting / 31) - 1; // TODO: Capacity
                AILog.Info($"{list.Count} vehicles operating. Target: {target}");
                if (list.Count < target)
                {
                    if (waiting1 > waiting2)
                    {
                        MakeRoute(edge.Node1, edge.Node2);
                    }
                    else
                    {
                        MakeRoute(edge.Node2, edge.Node1);
                    }
                }
            }

            //var stations = new AIStationList(AIStation.STATION_BUS_STOP);
            //foreach (var (s1, _) in stations)
            //{
            //    AILog.Info(AIStation.GetName(s1) + ":");
            //    var stations2 = new AIStationList(AIStation.STATION_BUS_STOP);
            //    var totalWaiting = AIStation.GetCargoWaiting(s1, passangerCargo);
            //    foreach (var (s2, _) in stations2)
            //    {
            //        if (s1 != s2)
            //        {
            //            var waiting = AIStation.GetCargoWaitingVia(s1, s2, passangerCargo);
            //            AILog.Info($"- {AIStation.GetName(s2)}: {waiting}");
            //            totalWaiting -= waiting;
            //        }
            //    }

            //    AILog.Info($"- any: {totalWaiting}");
            //}
        }
Пример #3
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);
        }