示例#1
0
        public static void Initialize(VehicleCollection collection, Transform customPrefabs)
        {
            if (sm_initialized)
            {
                return;
            }
            VehicleInfo originalBus = collection.m_prefabs.Where(p => p.name.Contains("Bus")).FirstOrDefault();

            if (originalBus == null)
            {
                throw new KeyNotFoundException("Bus was not found on " + collection.name);
            }

            GameObject instance = GameObject.Instantiate <GameObject>(originalBus.gameObject);

            instance.name = "Bus";
            instance.transform.SetParent(customPrefabs);
            BusAI bai = instance.GetComponent <BusAI>();

            System.IO.File.AppendAllText("Bus.txt", bai.m_passengerCapacity + " | " + bai.m_ticketPrice + "\n");
            GameObject.Destroy(instance.GetComponent <BusAI>());
            instance.AddComponent <CustomBusAI>();

            VehicleInfo bus = instance.GetComponent <VehicleInfo>();

            bus.m_prefabInitialized = false;
            bus.m_vehicleAI         = null;

            MethodInfo initMethod = typeof(VehicleCollection).GetMethod("InitializePrefabs", BindingFlags.Static | BindingFlags.NonPublic);

            Singleton <LoadingManager> .instance.QueueLoadingAction((IEnumerator)initMethod.Invoke(null, new object[] { collection.name, new[] { bus }, new string[] { "Bus" } }));

            sm_initialized = true;
        }
示例#2
0
        public static bool GetProgressStatus(ushort vehicleID, ref Vehicle data, out float current, out float max)
        {
            ushort transportLine  = data.m_transportLine;
            ushort targetBuilding = data.m_targetBuilding;

            if ((int)transportLine != 0 && (int)targetBuilding != 0)
            {
                float min;
                float max1;
                float total;
                Singleton <TransportManager> .instance.m_lines.m_buffer[(int)transportLine].GetStopProgress(targetBuilding, out min, out max1, out total);
                uint path = data.m_path;
                bool valid;
                if ((int)path == 0 || (data.m_flags & Vehicle.Flags.WaitingPath) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive))
                {
                    current = min;
                    valid   = false;
                }
                else
                {
                    current = BusAI.GetPathProgress(path, (int)data.m_pathPositionIndex, min, max1, out valid);
                }
                max = total;
                return(valid);
            }
            current = 0.0f;
            max     = 0.0f;
            return(true);
        }
        private void UnloadPassengers(ushort vehicleID, ref Vehicle data, ushort currentStop, ushort nextStop)
        {
            if ((int)currentStop == 0)
            {
                return;
            }
            VehicleManager   instance1 = Singleton <VehicleManager> .instance;
            NetManager       instance2 = Singleton <NetManager> .instance;
            TransportManager instance3 = Singleton <TransportManager> .instance;
            Vector3          position  = instance2.m_nodes.m_buffer[(int)currentStop].m_position;
            Vector3          targetPos = Vector3.zero;

            if ((int)nextStop != 0)
            {
                targetPos = instance2.m_nodes.m_buffer[(int)nextStop].m_position;
            }
            int    serviceCounter = 0;
            int    num1           = 0;
            ushort vehicleID1     = vehicleID;
            ushort bufferStatus   = PassengerTrainAIMod.GetBufferStatus(vehicleID1, ref instance1.m_vehicles.m_buffer[(int)vehicleID1]);

            while ((int)vehicleID != 0)
            {
                if ((int)data.m_transportLine != 0)
                {
                    BusAI.TransportArriveAtTarget(vehicleID, ref instance1.m_vehicles.m_buffer[(int)vehicleID], position, targetPos, ref serviceCounter, ref instance3.m_lines.m_buffer[(int)data.m_transportLine].m_passengers, (int)nextStop == 0);
                }
                else
                {
                    BusAI.TransportArriveAtTarget(vehicleID, ref instance1.m_vehicles.m_buffer[(int)vehicleID], position, targetPos, ref serviceCounter, ref instance3.m_passengers[(int)this.m_transportInfo.m_transportType], (int)nextStop == 0);
                }
                vehicleID = instance1.m_vehicles.m_buffer[(int)vehicleID].m_trailingVehicle;
                if (++num1 > 16384)
                {
                    CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);

                    break;
                }
            }
            Singleton <StatisticsManager> .instance.Acquire <StatisticArray>(StatisticType.PassengerCount).Acquire <StatisticInt32>((int)this.m_transportInfo.m_transportType, 8).Add(serviceCounter);

            serviceCounter += (int)instance2.m_nodes.m_buffer[(int)currentStop].m_tempCounter;
            instance2.m_nodes.m_buffer[(int)currentStop].m_tempCounter = (ushort)Mathf.Min(serviceCounter, (int)ushort.MaxValue);
            ushort num2 = (ushort)((uint)bufferStatus - (uint)PassengerTrainAIMod.GetBufferStatus(vehicleID1, ref instance1.m_vehicles.m_buffer[(int)vehicleID1]));

            VehicleManagerMod.m_cachedVehicleData[(int)vehicleID1].LastStopGonePassengers = (int)num2;
            VehicleManagerMod.m_cachedVehicleData[(int)vehicleID1].CurrentStop            = currentStop;
            NetManagerMod.m_cachedNodeData[(int)currentStop].PassengersOut += (int)num2;
        }
示例#4
0
        private void UnloadPassengers(ushort vehicleID, ref Vehicle data, ushort currentStop, ushort nextStop)
        {
            if (currentStop == 0)
            {
                return;
            }
            VehicleManager   instance  = Singleton <VehicleManager> .instance;
            NetManager       instance2 = Singleton <NetManager> .instance;
            TransportManager instance3 = Singleton <TransportManager> .instance;
            Vector3          position  = instance2.m_nodes.m_buffer [(int)currentStop].m_position;
            Vector3          targetPos = Vector3.zero;

            if (nextStop != 0)
            {
                targetPos = instance2.m_nodes.m_buffer [(int)nextStop].m_position;
            }
            int num  = 0;
            int num2 = 0;

            while (vehicleID != 0)
            {
                if (data.m_transportLine != 0)
                {
                    BusAI.TransportArriveAtTarget(vehicleID, ref instance.m_vehicles.m_buffer [(int)vehicleID], position, targetPos, ref num, ref instance3.m_lines.m_buffer [(int)data.m_transportLine].m_passengers, nextStop == 0);
                }
                else
                {
                    BusAI.TransportArriveAtTarget(vehicleID, ref instance.m_vehicles.m_buffer [(int)vehicleID], position, targetPos, ref num, ref instance3.m_passengers [(int)this.m_transportInfo.m_transportType], nextStop == 0);
                }
                vehicleID = instance.m_vehicles.m_buffer [(int)vehicleID].m_trailingVehicle;
                if (++num2 > 65536)
                {
                    CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                    break;
                }
            }
            StatisticBase statisticBase = Singleton <StatisticsManager> .instance.Acquire <StatisticArray> (StatisticType.PassengerCount);

            statisticBase.Acquire <StatisticInt32> ((int)this.m_transportInfo.m_transportType, 8).Add(num);
            num += (int)instance2.m_nodes.m_buffer [(int)currentStop].m_tempCounter;
            instance2.m_nodes.m_buffer [(int)currentStop].m_tempCounter = (ushort)Mathf.Min(num, 65535);
        }
示例#5
0
        public static void Initialize(VehicleCollection collection, Transform customPrefabs)
        {
            if (sm_initialized)
            {
                return;
            }

            Debug.Log("Traffic++: Initializing Bus.\n");

            VehicleInfo originalBus = collection.m_prefabs.Where(p => p.name.Contains("Bus")).FirstOrDefault();

            if (originalBus == null)
            {
                throw new KeyNotFoundException("Bus was not found on " + collection.name);
            }

            GameObject instance = GameObject.Instantiate <GameObject>(originalBus.gameObject);

            instance.name = "Bus";
            instance.transform.SetParent(customPrefabs);

            BusAI         busAI         = instance.GetComponent <BusAI>();
            TransportInfo transportInfo = busAI.m_transportInfo;

            GameObject.Destroy(instance.GetComponent <BusAI>());
            CustomBusAI customBusAI = instance.AddComponent <CustomBusAI>();

            customBusAI.m_transportInfo = transportInfo;

            VehicleInfo bus = instance.GetComponent <VehicleInfo>();

            bus.m_prefabInitialized = false;
            bus.m_vehicleAI         = null;

            MethodInfo initMethod = typeof(VehicleCollection).GetMethod("InitializePrefabs", BindingFlags.Static | BindingFlags.NonPublic);

            Initializer.QueuePrioritizedLoadingAction((IEnumerator)initMethod.Invoke(null, new object[] { collection.name, new[] { bus }, new string[] { "Bus" } }));

            sm_initialized = true;
        }
示例#6
0
        private void UnloadPassengers(ushort vehicleID, ref Vehicle data, ushort currentStop, ushort nextStop)
        {
            if ((int)currentStop == 0)
            {
                return;
            }
            VehicleManager   instance1 = Singleton <VehicleManager> .instance;
            NetManager       instance2 = Singleton <NetManager> .instance;
            TransportManager instance3 = Singleton <TransportManager> .instance;
            Vector3          position  = instance2.m_nodes.m_buffer[(int)currentStop].m_position;
            Vector3          targetPos = Vector3.zero;

            if ((int)nextStop != 0)
            {
                targetPos = instance2.m_nodes.m_buffer[(int)nextStop].m_position;
            }
            int serviceCounter = 0;
            int num            = 0;

            //begin mod (+): calculate passenger count before unloading passengers
            ushort vehicleID1 = vehicleID;

            GetBufferStatus(vehicleID1, ref instance1.m_vehicles.m_buffer[(int)vehicleID1], out string localeKey,
                            out int bufferStatusBefore, out int max);
            //end mod

            while ((int)vehicleID != 0)
            {
                if ((int)data.m_transportLine != 0)
                {
                    BusAI.TransportArriveAtTarget(vehicleID, ref instance1.m_vehicles.m_buffer[(int)vehicleID],
                                                  position, targetPos, ref serviceCounter,
                                                  ref instance3.m_lines.m_buffer[(int)data.m_transportLine].m_passengers, (int)nextStop == 0);
                }
                else
                {
                    BusAI.TransportArriveAtTarget(vehicleID, ref instance1.m_vehicles.m_buffer[(int)vehicleID],
                                                  position, targetPos, ref serviceCounter,
                                                  ref instance3.m_passengers[(int)this.m_transportInfo.m_transportType], (int)nextStop == 0);
                }
                vehicleID = instance1.m_vehicles.m_buffer[(int)vehicleID].m_trailingVehicle;
                if (++num > VehicleManagerMod.MaxVehicleCount)
                {
                    CODebugBase <LogChannel> .Error(LogChannel.Core,
                                                    "Invalid list detected!\n" + System.Environment.StackTrace);

                    break;
                }
            }
            Singleton <StatisticsManager> .instance.Acquire <StatisticArray>(StatisticType.PassengerCount)
            .Acquire <StatisticInt32>((int)this.m_transportInfo.m_transportType, 10)
            .Add(serviceCounter);

            serviceCounter += (int)instance2.m_nodes.m_buffer[(int)currentStop].m_tempCounter;
            instance2.m_nodes.m_buffer[(int)currentStop].m_tempCounter =
                (ushort)Mathf.Min(serviceCounter, (int)ushort.MaxValue);

            //begin mod (+): calculate passenger count after unloading passengers
            GetBufferStatus(vehicleID1, ref instance1.m_vehicles.m_buffer[(int)vehicleID1], out localeKey,
                            out int bufferStatusAfter, out max);
            int diff = bufferStatusBefore - bufferStatusAfter;

            VehicleManagerMod.m_cachedVehicleData[(int)vehicleID1].LastStopGonePassengers = diff;
            VehicleManagerMod.m_cachedVehicleData[(int)vehicleID1].CurrentStop            = currentStop;
            NetManagerMod.m_cachedNodeData[(int)currentStop].PassengersOut += diff;
            //end mod
        }
 public static void GetTicketPricePost_BusAI(ushort vehicleID, ref Vehicle vehicleData, BusAI __instance, ref int __result)
 {
     if (__instance.m_ticketPrice == 0)
     {
         __result = 0;
     }
     else
     {
         __result = ticketPriceForPrefix(vehicleID, ref vehicleData, __instance.m_ticketPrice) * __result / __instance.m_ticketPrice;
     }
 }