private bool ArriveAtTarget(ushort vehicleID, ref Vehicle data)
        {
            if ((int)data.m_targetBuilding == 0 || (data.m_flags & Vehicle.Flags.DummyTraffic) != ~(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))
            {
                Singleton <VehicleManager> .instance.ReleaseVehicle(vehicleID);

                return(true);
            }
            ushort targetBuilding = data.m_targetBuilding;
            ushort nextStop       = 0;

            if ((int)data.m_transportLine != 0)
            {
                nextStop = TransportLine.GetNextStop(data.m_targetBuilding);
            }
            else if ((data.m_flags & (Vehicle.Flags.Importing | Vehicle.Flags.Exporting)) != ~(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))
            {
                nextStop = TransportLine.GetNextStop(data.m_targetBuilding);
                Vector3 lastFramePosition = data.GetLastFramePosition();
                byte    max;
                if ((double)Mathf.Max(Mathf.Abs(lastFramePosition.x), Mathf.Abs(lastFramePosition.z)) > 4800.0 && PanelExtenderLine.CountWaitingPassengers(targetBuilding, nextStop, out max) == 0)
                {
                    nextStop = (ushort)0;
                }
            }
            ushort transferSize1 = data.m_transferSize;

            PassengerShipAIMod.UnloadPassengers(data.Info.m_vehicleAI as PassengerShipAI, vehicleID, ref data, targetBuilding, nextStop);
            ushort num1 = (ushort)((uint)transferSize1 - (uint)data.m_transferSize);

            VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].LastStopGonePassengers = (int)num1;
            VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].CurrentStop            = targetBuilding;
            NetManagerMod.m_cachedNodeData[(int)targetBuilding].PassengersOut           += (int)num1;
            if ((int)nextStop == 0)
            {
                data.m_waitCounter = (byte)0;
                data.m_flags      |= Vehicle.Flags.WaitingLoading;
            }
            else
            {
                data.m_targetBuilding = nextStop;
                if (!this.StartPathFind(vehicleID, ref data))
                {
                    return(true);
                }
                ushort transferSize2 = data.m_transferSize;
                PassengerShipAIMod.LoadPassengers(data.Info.m_vehicleAI as PassengerShipAI, vehicleID, ref data, targetBuilding, nextStop);
                ushort num2        = (ushort)((uint)data.m_transferSize - (uint)transferSize2);
                int    ticketPrice = data.Info.m_vehicleAI.GetTicketPrice(vehicleID, ref data);
                VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].Add((int)num2, ticketPrice);
                NetManagerMod.m_cachedNodeData[(int)targetBuilding].PassengersIn += (int)num2;
                data.m_flags      &= 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.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;
                data.m_flags      |= Vehicle.Flags.Stopped;
                data.m_waitCounter = (byte)0;
            }
            return(false);
        }
 public void OnLevelLoaded(LoadMode mode)
 {
     this._loadMode = mode;
     if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame)
     {
         return;
     }
     try
     {
         Utils.Log((object)"Begin init version: 3.8.10");
         ImprovedPublicTransportMod.Settings.LogSettings();
         this.ReleaseUnusedCitizenUnits();
         UIView objectOfType = UnityEngine.Object.FindObjectOfType <UIView>();
         if ((UnityEngine.Object)objectOfType != (UnityEngine.Object)null)
         {
             this._iptGameObject = new GameObject("IptGameObject");
             this._iptGameObject.transform.parent = objectOfType.transform;
             this._iptGameObject.AddComponent <VehicleEditor>();
             this._iptGameObject.AddComponent <PanelExtenderLine>();
             this._iptGameObject.AddComponent <PanelExtenderVehicle>();
             this._iptGameObject.AddComponent <PanelExtenderCityService>();
             this._iptGameObject.AddComponent <SimHelper>();
             this._iptGameObject.AddComponent <LineWatcher>();
             this._worldInfoPanel = new GameObject("PublicTransportStopWorldInfoPanel");
             this._worldInfoPanel.transform.parent = objectOfType.transform;
             this._worldInfoPanel.AddComponent <PublicTransportStopWorldInfoPanel>().Show();
             NetManagerMod.Init();
             VehicleManagerMod.Init();
             BusAIMod.Init();
             PassengerTrainAIMod.Init();
             PassengerShipAIMod.Init();
             PassengerPlaneAIMod.Init();
             TramAIMod.Init();
             BuildingWatcher.instance.Init();
             LineWatcher.instance.Init();
             TransportLineMod.Init();
             VehiclePrefabs.Init();
             SerializableDataExtension.instance.Loaded = true;
             LocaleModifier.Init();
             Utils.Log((object)"Loading done!");
         }
         else
         {
             Utils.LogError((object)"UIView not found, aborting!");
         }
     }
     catch (Exception ex)
     {
         Utils.LogError((object)("Error during initialization, IPT disables itself." + System.Environment.NewLine + "Please try again without any other mod." + System.Environment.NewLine + "Please upload your log file and post the link here if that didn't help:" + System.Environment.NewLine + "http://steamcommunity.com/workshop/filedetails/discussion/424106600/615086038663282271/" + System.Environment.NewLine + ex.Message + System.Environment.NewLine + (object)ex.InnerException + System.Environment.NewLine + ex.StackTrace));
         this.Deinit();
     }
 }
 private void Deinit()
 {
     TramAIMod.Deinit();
     PassengerTrainAIMod.Deinit();
     PassengerShipAIMod.Deinit();
     PassengerPlaneAIMod.Deinit();
     BusAIMod.Deinit();
     TransportLineMod.Deinit();
     BuildingWatcher.instance.Deinit();
     NetManagerMod.Deinit();
     VehicleManagerMod.Deinit();
     VehiclePrefabs.Deinit();
     SerializableDataExtension.instance.Loaded = false;
     LocaleModifier.Deinit();
     if ((UnityEngine.Object) this._iptGameObject != (UnityEngine.Object)null)
     {
         UnityEngine.Object.Destroy((UnityEngine.Object) this._iptGameObject);
     }
     if (!((UnityEngine.Object) this._worldInfoPanel != (UnityEngine.Object)null))
     {
         return;
     }
     UnityEngine.Object.Destroy((UnityEngine.Object) this._worldInfoPanel);
 }