예제 #1
0
        /// <summary>
        /// Adds the effect with name effectName to info
        /// </summary>
        public static bool AddEffect(VehicleInfo info, string effectName, Vehicle.Flags flagsRequired = Vehicle.Flags.Created, Vehicle.Flags flagsForbidden = 0)
        {
            EffectInfo effect = EffectCollection.FindEffect(effectName);

            if (effect == null)
            {
                return(false);
            }

            int size = info.m_effects != null ? info.m_effects.Length + 1 : 1;

            VehicleInfo.Effect[] tmp = new VehicleInfo.Effect[size];
            if (size > 1)
            {
                Array.Copy(info.m_effects, tmp, size - 1);
            }
            var newEffect = new VehicleInfo.Effect
            {
                m_effect = effect,
                m_parkedFlagsForbidden  = VehicleParked.Flags.Created,
                m_parkedFlagsRequired   = VehicleParked.Flags.None,
                m_vehicleFlagsForbidden = flagsForbidden,
                m_vehicleFlagsRequired  = flagsRequired,
            };

            tmp[size - 1]  = newEffect;
            info.m_effects = tmp;

            return(true);
        }
예제 #2
0
        public void Show(string title, Vehicle.Flags checkedFlags, OnFlagsSet callback)
        {
            m_callback1  = callback;
            m_callback2  = null;
            m_label.text = title;

            m_flagsPanel.isVisible       = true;
            m_parkedFlagsPanel.isVisible = false;

            var flags = (Vehicle.Flags[])Enum.GetValues(typeof(Vehicle.Flags));

            for (int i = 0; i < flags.Length; i++)
            {
                if ((checkedFlags & flags[i]) > 0)
                {
                    Debug.Log("True");
                    m_flagBoxDict[flags[i]].isChecked = true;
                }
                else
                {
                    Debug.Log("False");
                    m_flagBoxDict[flags[i]].isChecked = false;
                }
            }

            isVisible = true;
        }
예제 #3
0
        /// <summary>
        /// Deserializes the specified serialized data to this instance.
        /// </summary>
        /// <param name="serializedData">The serialized data.</param>
        /// <returns>
        /// The deserialization result.
        /// </returns>
        private SerializableSettings.DeserializationResult Deserialize(SerializableSettings.BinaryData serializedData)
        {
            if (serializedData == null || serializedData.Left == 0)
            {
                return(SerializableSettings.DeserializationResult.EndOfData);
            }

            serializedData.ResetLocalCheckSum();

            ulong version = serializedData.GetVersion();

            if (version > 0)
            {
                Log.Warning(this, "Deserialize", "Serialized data version too high!", version, 0);
                return(SerializableSettings.DeserializationResult.Error);
            }

            this.VehicleId                    = serializedData.GetUshort();
            this.targetBuildingId             = serializedData.GetUshort();
            this.dispatcherType               = serializedData.GetDispatcherType();
            this.checkFlags                   = serializedData.GetVehicleFlags();
            this.checkFlagPosition            = serializedData.GetVector3();
            this.checkFlagSinceFrame          = serializedData.GetUint();
            this.checkFlagSinceTime           = serializedData.GetDouble();
            this.confusedDeAssignedSinceFrame = serializedData.GetUint();
            this.confusedSinceFrame           = serializedData.GetUint();
            this.confusedSinceTime            = serializedData.GetDouble();
            this.lostSinceFrame               = serializedData.GetUint();
            this.lostSinceTime                = serializedData.GetDouble();
            this.lostReason                   = serializedData.GetLostReason();

            serializedData.CheckLocalCheckSum();

            return(SerializableSettings.DeserializationResult.Success);
        }
예제 #4
0
 public override void OnBeforeSimulationFrame()
 {
     base.OnBeforeSimulationFrame();
     if (Loader.CurrentLoadMode == LoadMode.LoadGame || Loader.CurrentLoadMode == LoadMode.NewGame)
     {
         if (RealCity.IsEnabled)
         {
             CheckDetour();
             int vehicleStep           = (int)(Singleton <VehicleManager> .instance.m_vehicles.m_size >> 4);
             int frameIndex            = (int)(Singleton <SimulationManager> .instance.m_currentFrameIndex & 15u);
             int currentStartVehicleID = frameIndex * vehicleStep;
             int currentEndVehicleID   = (frameIndex + 1) * vehicleStep - 1;
             for (int k = currentStartVehicleID; k <= currentEndVehicleID; k++)
             {
                 VehicleManager instance = Singleton <VehicleManager> .instance;
                 Vehicle        vehicle  = instance.m_vehicles.m_buffer[k];
                 Vehicle.Flags  flags    = vehicle.m_flags;
                 if ((flags & Vehicle.Flags.Created) != 0 && vehicle.m_leadingVehicle == 0)
                 {
                     VehicleStatus((ushort)k);
                 }
             }
         }
     }
 }
예제 #5
0
 private void Done()
 {
     if (m_callback1 != null)
     {
         Vehicle.Flags flags = 0;
         foreach (var v in m_boxFlagDict)
         {
             if (v.Key.isChecked)
             {
                 flags |= v.Value;
             }
         }
         Debug.LogWarning(flags.ToString());
         m_callback1.Invoke(flags);
     }
     else if (m_callback2 != null)
     {
         VehicleParked.Flags flags = 0;
         foreach (var v in m_boxFlagDictAlt)
         {
             if (v.Key.isChecked)
             {
                 flags |= v.Value;
             }
         }
         Debug.LogWarning(flags.ToString());
         m_callback2.Invoke(flags);
     }
     isVisible = false;
 }
예제 #6
0
        public void Show(string title, Vehicle.Flags checkedFlags, OnFlagsSet callback, bool allowEdit = true)
        {
            m_callback1  = callback;
            m_callback2  = null;
            m_label.text = title;

            m_flagsPanel.isVisible       = true;
            m_parkedFlagsPanel.isVisible = false;

            var flags = (Vehicle.Flags[])Enum.GetValues(typeof(Vehicle.Flags));

            for (int i = 0; i < flags.Length; i++)
            {
                if ((checkedFlags & flags[i]) > 0)
                {
                    m_flagBoxDict[flags[i]].isChecked = true;
                }
                else
                {
                    m_flagBoxDict[flags[i]].isChecked = false;
                }
            }

            Show(true);
            m_confirmButton.isEnabled = allowEdit;
            m_label.relativePosition  = new Vector3(WIDTH / 2 - m_label.width / 2, 10);
        }
예제 #7
0
        public override void RenderExtraStuff(ushort vehicleID, ref Vehicle vehicleData, RenderManager.CameraInfo cameraInfo, InstanceID id, Vector3 position, Quaternion rotation, Vector4 tyrePosition, Vector4 lightState, Vector3 scale, Vector3 swayPosition, bool underground, bool overground)
        {
            VehicleManager instance = Singleton <VehicleManager> .instance;

            Vehicle.Flags flags = instance.m_vehicles.m_buffer[vehicleID].m_flags;
            if (m_info != null && m_info.m_vehicleAI != null && m_info.m_subMeshes != null)
            {
                Matrix4x4 bodyMatrix = m_info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref rotation, ref scale, ref swayPosition);
                Matrix4x4 value      = m_info.m_vehicleAI.CalculateTyreMatrix(flags, ref position, ref rotation, ref scale, ref bodyMatrix);
                if ((flags & Vehicle.Flags.Inverted) != 0)
                {
                    tyrePosition.x = 0f - tyrePosition.x;
                    tyrePosition.y = 0f - tyrePosition.y;
                }
                MaterialPropertyBlock materialBlock = instance.m_materialBlock;
                materialBlock.Clear();
                materialBlock.SetMatrix(instance.ID_TyreMatrix, value);
                materialBlock.SetVector(instance.ID_TyrePosition, tyrePosition);
                materialBlock.SetVector(instance.ID_LightState, lightState);
                for (int i = 0; i < m_info.m_subMeshes.Length; i++)
                {
                    VehicleInfo.MeshInfo meshInfo = m_info.m_subMeshes[i];
                    RenderPoleMesh(vehicleID, ref vehicleData, position, rotation, swayPosition, underground, overground, instance, meshInfo, materialBlock);
                }
            }
            base.RenderExtraStuff(vehicleID, ref vehicleData, cameraInfo, id, position, rotation, tyrePosition, lightState, scale, swayPosition, underground, overground);
        }
예제 #8
0
        public bool CheckVehicleFlags(ushort vehicleId, Vehicle.Flags flagMask, Vehicle.Flags?expectedResult = default(Vehicle.Flags?))
        {
            bool ret = false;

            ProcessVehicle(vehicleId, delegate(ushort vId, ref Vehicle vehicle) {
                ret = LogicUtil.CheckFlags((uint)vehicle.m_flags, (uint)flagMask, (uint?)expectedResult);
                return(true);
            });
            return(ret);
        }
        /// <summary>
        /// Check vehicle flags contain at least one of the flags in <paramref name="flagMask"/>.
        /// </summary>
        ///
        /// <param name="vehicleId">The id of the vehicle to inspect.</param>
        /// <param name="flagMask">The flags to test.</param>
        /// <param name="expectedResult">If specified, ensure only the expected flags are found.</param>
        ///
        /// <returns>Returns <c>true</c> if the test passes, otherwise <c>false</c>.</returns>
        public bool CheckVehicleFlags(ushort vehicleId,
                                      Vehicle.Flags flagMask,
                                      Vehicle.Flags?expectedResult = null)
        {
            Vehicle.Flags result =
                Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags
                & flagMask;

            return(expectedResult == null ? result != 0 : result == expectedResult);
        }
예제 #10
0
 private void OnSetStateFlag(Vehicle.Flags f, int y) => SafeObtain((ref BoardTextDescriptorGeneralXml desc) =>
 {
     desc.IlluminationConfig.m_forbiddenFlags &= ~(int)f;
     desc.IlluminationConfig.m_requiredFlags  &= ~(int)f;
     if (y == 1)
     {
         desc.IlluminationConfig.m_requiredFlags |= (int)f;
     }
     else if (y == 2)
     {
         desc.IlluminationConfig.m_forbiddenFlags |= (int)f;
     }
 });
예제 #11
0
        public void AfterRenderExtraStuff(VehicleAI thiz, ushort vehicleID, ref Vehicle vehicleData, RenderManager.CameraInfo cameraInfo, InstanceID id, Vector3 position, Quaternion rotation, Vector4 tyrePosition, Vector4 lightState, Vector3 scale, Vector3 swayPosition, bool underground, bool overground)
        {
            if (thiz.m_info == null || thiz.m_info.m_vehicleAI == null || thiz.m_info.m_subMeshes == null)
            {
                return;
            }

            GetTargetDescriptor(thiz.m_info.name, out _, out LayoutDescriptorVehicleXml targetDescriptor);

            if (targetDescriptor != null)
            {
                Vehicle.Flags         flags         = VehicleManager.instance.m_vehicles.m_buffer[vehicleID].m_flags;
                Matrix4x4             vehicleMatrix = thiz.m_info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref rotation, ref scale, ref swayPosition);
                MaterialPropertyBlock materialBlock = VehicleManager.instance.m_materialBlock;
                materialBlock.Clear();

                RenderDescriptor(ref vehicleData, cameraInfo, vehicleID, position, vehicleMatrix, ref targetDescriptor);
            }
        }
예제 #12
0
        private void RenderInfo(RenderManager.CameraInfo cameraInfo, VehicleInfo info, Vector3 position, bool inverted)
        {
            // Full implementation of VehicleInfo.RenderMesh so we can change its facing direction
            if (info.m_lodMeshData == null && info.m_lodMesh != null && info.m_lodMesh.vertexCount > 0)
            {
                info.m_lodMeshData = new RenderGroup.MeshData(info.m_lodMesh);
                info.m_lodMeshData.UpdateBounds();
            }
            // Change for inverted vehicles
            // Quaternion rotation = isInverted ? Quaternion.Euler(0, 180, 0) : Quaternion.identity;
            Quaternion rotation = Quaternion.identity;

            Vehicle.Flags flags = Vehicle.Flags.Created | Vehicle.Flags.Spawned;
            if (inverted)
            {
                flags |= Vehicle.Flags.Inverted;
            }
            // Effect display options
            if (DisplayOptions.activeOptions.Reversed)
            {
                flags |= Vehicle.Flags.Reversed;
            }
            if (DisplayOptions.activeOptions.ShowLanding)
            {
                flags |= Vehicle.Flags.Landing;
            }
            if (DisplayOptions.activeOptions.ShowTakeOff)
            {
                flags |= Vehicle.Flags.TakingOff;
            }
            if (DisplayOptions.activeOptions.ShowEmergency)
            {
                flags |= Vehicle.Flags.Emergency1;
            }
            if (DisplayOptions.activeOptions.ShowEmergency2)
            {
                flags |= Vehicle.Flags.Emergency2;
            }

            Vehicle.RenderInstance(cameraInfo, info, position, rotation, Vector3.zero, Vector4.zero, Vector4.zero, Vector3.zero, 0f, info.m_color0, flags, -1, InstanceID.Empty, false, true);
            // End of VehicleInfo.RenderMesh
        }
예제 #13
0
        /// <summary>
        /// Removes all effects that have the given name and at least the given requiredflags set
        /// </summary>
        public static void RemoveEffect(VehicleInfo info, string effectName, Vehicle.Flags requiredFlags)
        {
            int index;

            do
            {
                index = GetEffectIndex(info, effectName);

                if (info.m_effects == null || index < 0 || index >= info.m_effects.Length)
                {
                    continue;
                }

                if ((info.m_effects[index].m_vehicleFlagsRequired & requiredFlags) > 0)
                {
                    List <VehicleInfo.Effect> tmp = new List <VehicleInfo.Effect>();
                    tmp.AddRange(info.m_effects);
                    tmp.RemoveAt(index);
                    info.m_effects = tmp.ToArray();
                }
            }while(index >= 0);
        }
        public void Unspawn(ushort vehicleID)
        {
            VehicleManager instance = Singleton <VehicleManager> .instance;

            if (this.m_leadingVehicle == 0 && this.m_trailingVehicle != 0)
            {
                ushort num = this.m_trailingVehicle;
                this.m_trailingVehicle = 0;
                int num2 = 0;
                while (num != 0)
                {
                    ushort trailingVehicle = instance.m_vehicles.m_buffer [(int)num].m_trailingVehicle;
                    instance.m_vehicles.m_buffer [(int)num].m_leadingVehicle  = 0;
                    instance.m_vehicles.m_buffer [(int)num].m_trailingVehicle = 0;
                    instance.ReleaseVehicle(num);
                    num = trailingVehicle;
                    if (++num2 > 65536)
                    {
                        CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                        break;
                    }
                }
            }
            if ((this.m_flags & Vehicle.Flags.Spawned) != Vehicle.Flags.None)
            {
                VehicleInfo info = PrefabCollection <VehicleInfo> .GetPrefab((uint)this.m_infoIndex);

                if (info != null)
                {
                    object  thisVeh      = this;
                    Vehicle thisVehAsVeh = ((Vehicle)thisVeh);
                    instance.RemoveFromGrid(vehicleID, ref thisVehAsVeh, info.m_isLargeVehicle);
                }
                this.m_flags &= ~Vehicle.Flags.Spawned;
            }
        }
예제 #15
0
        private Matrix4x4 CalculatePoleMatrix(ushort vehicleID, ref Vehicle vehicleData, Vector3 position, Quaternion rotation, Vector3 swayPosition, VehicleInfo.MeshInfo meshInfo, VehicleInfoBase subInfo, bool assetEditor)
        {
            Vehicle.Flags           flags    = meshInfo.m_vehicleFlagsRequired & (Vehicle.Flags.TakingOff | Vehicle.Flags.Landing);
            VehicleInfo.VehicleType wireType = GetWireType(vehicleData.m_flags, flags);
            float      poleLength            = m_poleLength;
            Quaternion rhs     = Quaternion.Euler(swayPosition.z * 57.29578f, 0f, swayPosition.x * -57.29578f);
            Vector3    a       = (flags != Vehicle.Flags.TakingOff) ? Vector3.left : Vector3.right;
            Vector3    vector  = position + rotation * rhs * (a * m_offsetX + Vector3.back * m_offsetZ + Vector3.up * m_offsetY);
            Vector3    poleEnd = position + rotation * rhs * (a * m_offsetX + Vector3.back * (m_offsetZ + poleLength) + Vector3.up * m_offsetY);
            Vector3    wireAttachmentPosition;

            if (!assetEditor)
            {
                TrolleybusReversePatch.FindWireConnection(vehicleID, ref vehicleData, wireType, poleLength, vector, poleEnd, out wireAttachmentPosition);
            }
            else
            {
                wireAttachmentPosition = position + rotation * rhs * (a * m_offsetX + Vector3.back * (m_offsetZ + poleLength) + Vector3.up * 4.55f);
            }
            Matrix4x4 result = default(Matrix4x4);

            result.SetTRS(vector, Quaternion.LookRotation(vector - wireAttachmentPosition, Vector3.up), Vector3.one);
            return(result);
        }
예제 #16
0
        public CargoParcel(ushort buildingID, bool incoming, byte transferType, ushort transferSize, Vehicle.Flags flags)
        {
            this.transferSize = transferSize;
            this.building     = buildingID;
            this.flags        = incoming ? CarFlags.None: CarFlags.Sent;

            if ((flags & Vehicle.Flags.Exporting) != 0)
            {
                this.flags |= CarFlags.Exported;
            }
            else if ((flags & Vehicle.Flags.Importing) != 0)
            {
                this.flags |= CarFlags.Imported;
            }

            switch ((TransferType)transferType)
            {
            case TransferType.Oil:
                this.flags |= CarFlags.Oil;
                break;

            case TransferType.Ore:
                this.flags |= CarFlags.Ore;
                break;

            case TransferType.Logs:
                this.flags |= CarFlags.Logs;
                break;

            case TransferType.Grain:
                this.flags |= CarFlags.Grain;
                break;

            case TransferType.Petrol:
                this.flags |= CarFlags.Petrol;
                break;

            case TransferType.Coal:
                this.flags |= CarFlags.Coal;
                break;

            case TransferType.Lumber:
                this.flags |= CarFlags.Lumber;
                break;

            case TransferType.Food:
                this.flags |= CarFlags.Food;
                break;

            case TransferType.Goods:
                this.flags |= CarFlags.Goods;
                break;

            default:
                Debug.LogErrorFormat("Unexpected transfer type: {0}", Enum.GetName(typeof(TransferType), transferType));
                break;
            }
        }
예제 #17
0
 /// <summary>
 /// Adds the specified data.
 /// </summary>
 /// <param name="data">The data.</param>
 public void Add(Vehicle.Flags data)
 {
     this.Add((ulong)data);
 }
        /// <summary>
        /// Starts the transfer.
        /// </summary>
        /// <param name="serviceBuildingId">The building identifier.</param>
        /// <param name="building">The building.</param>
        /// <param name="material">The material.</param>
        /// <param name="targetBuildingId">The target building identifier.</param>
        /// <param name="targetCitizenId">The target citizen identifier.</param>
        /// <param name="vehicleId">The vehicle identifier.</param>
        /// <returns>Vehicle info for the created vehicle.</returns>
        public static VehicleInfo StartTransfer(ushort serviceBuildingId, ref Building building, TransferManager.TransferReason material, ushort targetBuildingId, uint targetCitizenId, out ushort vehicleId)
        {
            if (building.Info.m_buildingAI is HospitalAI && targetCitizenId == 0)
            {
                return(VehicleHelper.CreateServiceVehicle(serviceBuildingId, material, targetBuildingId, targetCitizenId, out vehicleId));
            }

            Vehicle[] vehicles = Singleton <VehicleManager> .instance.m_vehicles.m_buffer;
            Citizen[] citizens = Singleton <CitizenManager> .instance.m_citizens.m_buffer;

            TransferManager.TransferOffer offer = TransferManagerHelper.MakeOffer(targetBuildingId, targetCitizenId);

            int count;
            HashSet <ushort> ownVehicles = new HashSet <ushort>();

            count     = 0;
            vehicleId = building.m_ownVehicles;
            while (vehicleId != 0)
            {
                ownVehicles.Add(vehicleId);

                if (count >= ushort.MaxValue)
                {
                    throw new Exception("Loop counter too high");
                }
                count++;

                vehicleId = vehicles[vehicleId].m_nextOwnVehicle;
            }

            // Cast AI as games original AI so detoured methods are called, but not methods from not replaced classes.
            if (Global.Settings.CreationCompatibilityMode == ServiceDispatcherSettings.ModCompatibilityMode.UseInstanciatedClassMethods || !Global.Settings.AllowReflection())
            {
                building.Info.m_buildingAI.StartTransfer(serviceBuildingId, ref building, material, offer);
            }
            else if (building.Info.m_buildingAI is CemeteryAI)
            {
                ((CemeteryAI)building.Info.m_buildingAI.CastTo <CemeteryAI>()).StartTransfer(serviceBuildingId, ref building, material, offer);
            }
            else if (building.Info.m_buildingAI is LandfillSiteAI)
            {
                ((LandfillSiteAI)building.Info.m_buildingAI.CastTo <LandfillSiteAI>()).StartTransfer(serviceBuildingId, ref building, material, offer);
            }
            else if (building.Info.m_buildingAI is HospitalAI)
            {
                ((HospitalAI)building.Info.m_buildingAI.CastTo <HospitalAI>()).StartTransfer(serviceBuildingId, ref building, material, offer);
            }
            else
            {
                building.Info.m_buildingAI.StartTransfer(serviceBuildingId, ref building, material, offer);
            }

            ushort newVehicleId     = 0;
            ushort waitingVehicleId = 0;

            Vehicle.Flags findFlags = Vehicle.Flags.Created;
            switch (material)
            {
            case TransferManager.TransferReason.Dead:
            case TransferManager.TransferReason.Garbage:
            case TransferManager.TransferReason.Sick:
                findFlags |= Vehicle.Flags.TransferToSource;
                break;

            case TransferManager.TransferReason.DeadMove:
            case TransferManager.TransferReason.GarbageMove:
            case TransferManager.TransferReason.SickMove:
                findFlags |= Vehicle.Flags.TransferToSource;
                break;
            }

            count     = 0;
            vehicleId = building.m_ownVehicles;
            while (vehicleId != 0)
            {
                if (!ownVehicles.Contains(vehicleId) && (vehicles[vehicleId].m_flags & findFlags) == findFlags && vehicles[vehicleId].Info != null)
                {
                    if (vehicles[vehicleId].m_targetBuilding == targetBuildingId && (targetCitizenId == 0 || citizens[targetCitizenId].m_vehicle == vehicleId))
                    {
                        return(vehicles[vehicleId].Info);
                    }

                    newVehicleId = vehicleId;
                    if ((vehicles[vehicleId].m_flags & Vehicle.Flags.WaitingTarget) == Vehicle.Flags.WaitingTarget)
                    {
                        waitingVehicleId = vehicleId;
                    }
                }

                if (count >= ushort.MaxValue)
                {
                    throw new Exception("Loop counter too high");
                }

                count++;
                vehicleId = vehicles[vehicleId].m_nextOwnVehicle;
            }

            if (waitingVehicleId != 0)
            {
                vehicleId = waitingVehicleId;
                //Log.DevDebug(typeof(BuildingHelper), "StartTransfer", "Waiting Vehicle", serviceBuildingId, targetBuildingId, targetCitizenId, material, vehicleId, vehicles[vehicleId].m_flags);
            }
            else if (newVehicleId != 0)
            {
                vehicleId = newVehicleId;
                //Log.DevDebug(typeof(BuildingHelper), "StartTransfer", "Guess Vehicle", serviceBuildingId, targetBuildingId, targetCitizenId, material, vehicleId, vehicles[vehicleId].m_flags);
            }
            else
            {
                vehicleId = 0;
                Log.Info(typeof(BuildingHelper), "StartTransfer", "Lost Vehicle", serviceBuildingId, targetBuildingId, targetCitizenId, material);

                return(null);
            }

            if (!VehicleHelper.AssignTarget(vehicleId, ref vehicles[vehicleId], material, targetBuildingId, targetCitizenId))
            {
                return(null);
            }

            return(vehicles[vehicleId].Info);
        }
예제 #19
0
        public CargoParcel(ushort buildingID, bool incoming, byte transferType, ushort transferSize, Vehicle.Flags flags)
        {
            this.transferSize = transferSize;
            this.building     = buildingID;
            this.flags        = incoming ? CarFlags.None : CarFlags.Sent;

            if ((flags & Vehicle.Flags.Exporting) != 0)
            {
                this.flags |= CarFlags.Exported;
            }
            else if ((flags & Vehicle.Flags.Importing) != 0)
            {
                this.flags |= CarFlags.Imported;
            }

            switch ((TransferType)transferType)
            {
            case TransferType.Oil:
                this.flags |= CarFlags.Oil;
                break;

            case TransferType.Ore:
                this.flags |= CarFlags.Ore;
                break;

            case TransferType.Logs:
                this.flags |= CarFlags.Logs;
                break;

            case TransferType.Grain:
                this.flags |= CarFlags.Grain;
                break;

            case TransferType.Petrol:
                this.flags |= CarFlags.Petrol;
                break;

            case TransferType.Coal:
                this.flags |= CarFlags.Coal;
                break;

            case TransferType.Lumber:
                this.flags |= CarFlags.Lumber;
                break;

            case TransferType.Food:
                this.flags |= CarFlags.Food;
                break;

            case TransferType.Goods:
                this.flags |= CarFlags.Goods;
                break;

            case TransferType.Mail:
                this.flags |= CarFlags.Mail;
                break;

            case TransferType.UnsortedMail:
                this.flags |= CarFlags.UnsortedMail;
                break;

            case TransferType.SortedMail:
                this.flags |= CarFlags.SortedMail;
                break;

            case TransferType.OutgoingMail:
                this.flags |= CarFlags.OutgoingMail;
                break;

            case TransferType.IncomingMail:
                this.flags |= CarFlags.IncomingMail;
                break;

            case TransferType.AnimalProducts:
                this.flags |= CarFlags.AnimalProducts;
                break;

            case TransferType.Flours:
                this.flags |= CarFlags.Flours;
                break;

            case TransferType.Paper:
                this.flags |= CarFlags.Paper;
                break;

            case TransferType.PlanedTimber:
                this.flags |= CarFlags.PlanedTimber;
                break;

            case TransferType.Petroleum:
                this.flags |= CarFlags.Petroleum;
                break;

            case TransferType.Plastics:
                this.flags |= CarFlags.Plastics;
                break;

            case TransferType.Glass:
                this.flags |= CarFlags.Glass;
                break;

            case TransferType.Metals:
                this.flags |= CarFlags.Metals;
                break;

            case TransferType.LuxuryProducts:
                this.flags |= CarFlags.LuxuryProducts;
                break;

            default:
                Debug.LogErrorFormat("Unexpected transfer type: {0}", Enum.GetName(typeof(TransferType), transferType));
                break;
            }
        }
예제 #20
0
        internal CargoBatch(ushort buildingID, bool incoming, byte transferReason, ushort transferSize, Vehicle.Flags flags)
        {
            this.transferSize      = transferSize;
            this.buildingID        = buildingID;
            transferConnectionType = incoming ? TransferConnectionType.Receive : TransferConnectionType.Sent;
            if ((flags & Vehicle.Flags.Exporting) != 0)
            {
                transferConnectionType |= TransferConnectionType.Exported;
            }
            else if ((flags & Vehicle.Flags.Importing) != 0)
            {
                transferConnectionType |= TransferConnectionType.Imported;
            }

            if (DataShared.TrackedCargoTypes.Contains(transferReason))
            {
                this.transferReason = (TransferReason)transferReason;
            }
            else
            {
                if (Options.debugEnabled)
                {
                    Debug.LogErrorFormat("TransferInfo: CargoBatch.CargoBatch - Unexpected transfer type: {0}", Enum.GetName(typeof(TransferReason), transferReason));
                }
                this.transferReason = TransferReason.None;
            }
        }
        public void NotifyReservation(ushort vehicle_id, ushort segment_id, bool train_on_segment, Vehicle.Flags arrive_or_leave_station = 0)
        {
            int s_index = -1;

            for (int i = 0; i < m_data.reservedSegments.Count; i++)
            {
                if (m_data.reservedSegments[i].segment_id == segment_id)
                {
                    s_index = i;
                    break;
                }
            }



            if (s_index == -1)
            {
                //CODebug.Log(LogChannel.Modding, Mod.modName + " - no reservation was made for vehicle " + vehicle_id + " on segment " + segment_id);
                return;
            }

            ushort reservation_id = m_data.reservedSegments[s_index].reservation_id;



            for (int r_index = 0; r_index < m_data.reservations.Count; r_index++)
            {
                if (m_data.reservations[r_index].ID == reservation_id && m_data.reservations[r_index].train_ids.Contains(vehicle_id))
                {
                    ReservationInfo ri = m_data.reservations[r_index];

                    //CODebug.Log(LogChannel.Modding, Mod.modName + " - NotifyReservation train_on_segment="+ train_on_segment+ " IsSingleTrackStation="+ IsSingleTrackStation(segment_id)+" arriving at station "+arrive_or_leave_station+" previous status "+ri.status+" for train "+vehicle_id);

                    if (IsStation(segment_id))
                    {
                        if (ri.status != ReservationStatus.TrainAtStation && ri.status != ReservationStatus.TrainExitStation)
                        {
                            ri.status = ReservationStatus.TrainEnterOrSkipStation;
                        }
                    }
                    else if (train_on_segment) //and not in a station
                    {
                        m_data.ClearCacheForTrain(vehicle_id);
                        ri.status = ReservationStatus.TrainOnSection;
                    }

                    /*else //if next segment and not a station
                     * {
                     *  if (ri.status == ReservationStatus.TrainExitStation)
                     *      ri.status = ReservationStatus.BeforeTrainEnter;
                     * }*/

                    //CODebug.Log(LogChannel.Modding, Mod.modName + " - new status " + ri.status + " for train " + vehicle_id);


                    ri.clearing_timer            = 0;
                    m_data.reservations[r_index] = ri;

                    break;
                }
            }
        }
        /// <summary>
        /// Updates the specified vehicle.
        /// </summary>
        /// <param name="vehicle">The vehicle.</param>
        public void Update(ref Vehicle vehicle)
        {
            this.targetBuildingId = vehicle.m_targetBuilding;

            // Check if vehicle has flag that should be checked.
            Vehicle.Flags flags = vehicle.m_flags & FlagsToCheck;
            if ((flags & Vehicle.Flags.All) != ~Vehicle.Flags.All)
            {
                Vector3 position = vehicle.GetLastFramePosition();

                // Remember first time stamp the vehicle was seen with this flag at this position.
                if (this.checkFlagSinceFrame == 0 || this.checkFlagSinceTime == 0 || flags != this.checkFlags || Math.Truncate((position - this.checkFlagPosition).sqrMagnitude) > 0)
                {
                    ////if (Log.LogALot)
                    ////{
                    ////    if (this.checkFlags == Vehicle.Flags.None)
                    ////    {
                    ////        Log.DevDebug(this, "Update", "NewCheckFlag", flags, this.vehicleId, this.CheckFlaggedForSeconds, this.CheckFlaggedForFrames, Global.Settings.RemoveStuckVehiclesDelaySeconds, Global.CheckFlagStuckDelay, this.checkFlags, flags, this.checkFlagPosition, position, '-', vehicle.m_targetBuilding, vehicle.m_flags, VehicleHelper.GetVehicleName(this.vehicleId), this.GetHashCode().ToString());
                    ////    }
                    ////    else
                    ////    {
                    ////        Log.DevDebug(this, "Update", "NewCheckFlag", flags, this.vehicleId, this.CheckFlaggedForSeconds, this.CheckFlaggedForFrames, Global.Settings.RemoveStuckVehiclesDelaySeconds, Global.CheckFlagStuckDelay, this.checkFlags, flags, this.checkFlagPosition, position, (position - this.checkFlagPosition).sqrMagnitude, vehicle.m_targetBuilding, vehicle.m_flags, VehicleHelper.GetVehicleName(this.vehicleId), this.GetHashCode().ToString());
                    ////    }
                    ////}

                    this.checkFlags = flags;
                    this.checkFlagPosition = position;
                    this.checkFlagSinceTime = Global.SimulationTime;
                    this.checkFlagSinceFrame = Global.CurrentFrame;
                }
                ////else if (Log.LogALot)
                ////{
                ////    Log.DevDebug(this, "Update", "CheckFlag", flags, this.vehicleId, this.CheckFlaggedForSeconds, this.CheckFlaggedForFrames, Global.Settings.RemoveStuckVehiclesDelaySeconds, Global.CheckFlagStuckDelay, this.checkFlags, flags, this.checkFlagPosition, position, (position - this.checkFlagPosition).sqrMagnitude, vehicle.m_targetBuilding, vehicle.m_flags, VehicleHelper.GetVehicleName(this.vehicleId), this.GetHashCode().ToString());
                ////}
            }
            else if ((this.checkFlags & Vehicle.Flags.All) != ~Vehicle.Flags.All || this.checkFlagSinceTime != 0 || this.checkFlagSinceFrame != 0)
            {
                ////if (Log.LogALot)
                ////{
                ////    Log.DevDebug(this, "Update", "ResetCheckFlag", flags, this.vehicleId, this.CheckFlaggedForSeconds, this.CheckFlaggedForFrames, Global.Settings.RemoveStuckVehiclesDelaySeconds, Global.CheckFlagStuckDelay, this.checkFlags, flags, vehicle.m_targetBuilding, vehicle.m_flags, VehicleHelper.GetVehicleName(this.vehicleId), this.GetHashCode().ToString());
                ////}

                this.checkFlags = ~Vehicle.Flags.All;
                this.checkFlagSinceTime = 0;
                this.checkFlagSinceFrame = 0;
            }

            // Check if vehicle is confused.
            if (ConfusionHelper.VehicleIsConfused(ref vehicle))
            {
                if (this.confusedDeAssignedSinceFrame == 0)
                {
                    this.confusedDeAssignedSinceFrame = Global.CurrentFrame;
                }

                if (this.confusedSinceFrame == 0 || this.confusedSinceTime == 0)
                {
                    if (Log.LogALot)
                    {
                        Log.DevDebug(this, "Update", "NewConfused", this.vehicleId, this.ConfusedForSeconds, this.ConfusedForFrames, Global.Settings.RecoveryCrews.DelaySeconds, Global.DeAssignConfusedDelay, vehicle.m_targetBuilding, vehicle.m_flags, VehicleHelper.GetVehicleName(this.vehicleId));
                    }

                    this.confusedSinceTime = Global.SimulationTime;
                    this.confusedSinceFrame = Global.CurrentFrame;
                    this.confusedDeAssignedSinceFrame = Global.CurrentFrame;
                }
                ////else if (Log.LogALot)
                ////{
                ////    Log.DevDebug(this, "Update", "Confused", this.vehicleId, this.ConfusedForSeconds, this.ConfusedForFrames, Global.Settings.RemoveStuckVehiclesDelaySeconds, Global.DeAssignConfusedDelay, vehicle.m_targetBuilding, vehicle.m_flags, VehicleHelper.GetVehicleName(this.vehicleId));
                ////}
            }
            else if (this.confusedSinceTime != 0 || this.confusedSinceFrame != 0 || this.confusedDeAssignedSinceFrame != 0)
            {
                ////if (Log.LogALot)
                ////{
                ////    Log.DevDebug(this, "Update", "ResetConfused", this.vehicleId, this.ConfusedForSeconds, this.ConfusedForFrames, Global.Settings.RemoveStuckVehiclesDelaySeconds, Global.DeAssignConfusedDelay, vehicle.m_targetBuilding, vehicle.m_flags, VehicleHelper.GetVehicleName(this.vehicleId));
                ////}

                this.confusedSinceTime = 0;
                this.confusedSinceFrame = 0;
                this.confusedDeAssignedSinceFrame = 0;
            }

            // Check if vehicle is stuck.
            if (!this.isStuck)
            {
                double delta;

                // Check if stuck with flag.
                if ((this.checkFlags & Vehicle.Flags.All) != ~Vehicle.Flags.All && this.CheckFlaggedForFrames > Global.CheckFlagStuckDelay)
                {
                    delta = this.CheckFlaggedForSeconds;

                    if (delta > Global.Settings.RecoveryCrews.DelaySeconds)
                    {
                        Log.Info(this, "IsStuck", this.checkFlags, this.vehicleId, delta, VehicleHelper.GetVehicleName(this.vehicleId));

                        this.isStuck = true;
                    }
                }

                // Check if stuck confused.
                if (this.ConfusedForFrames > Global.CheckFlagStuckDelay)
                {
                    delta = this.ConfusedForSeconds;

                    if (delta > Global.Settings.RecoveryCrews.DelaySeconds)
                    {
                        Log.Info(this, "IsStuck", "Confused", this.vehicleId, delta, VehicleHelper.GetVehicleName(this.vehicleId));

                        this.isStuck = true;
                    }
                }
            }
        }
예제 #23
0
        /// <summary>
        /// Updates the specified vehicle.
        /// </summary>
        /// <param name="vehicle">The vehicle.</param>
        public void Update(ref Vehicle vehicle)
        {
            this.targetBuildingId = vehicle.m_targetBuilding;
            this.isTrailer        = vehicle.m_leadingVehicle != 0;
            this.hasCargoParent   = vehicle.m_cargoParent != 0;

            if (this.hasCargoParent && !Global.Settings.Experimental.AllowTrackingOfCargoChildren)
            {
                return;
            }

            if (this.isTrailer)
            {
                if (Global.Settings.Experimental.TrackLostTrailers)
                {
                    this.UpdateTrailer(ref vehicle);
                }

                return;
            }

            // Check if vehicle has flag that should be checked.
            Vehicle.Flags flags = vehicle.m_flags & FlagsToCheck;
            if ((flags & VehicleHelper.VehicleAll) != ~VehicleHelper.VehicleAll)
            {
                Vector3 position = vehicle.GetLastFramePosition();

                // Remember first time stamp the vehicle was seen with this flag at this position.
                if (this.checkFlagSinceFrame == 0 || this.checkFlagSinceTime == 0 || flags != this.checkFlags || Math.Truncate((position - this.checkFlagPosition).sqrMagnitude) > 0)
                {
                    this.isFlagged           = false;
                    this.checkFlags          = flags;
                    this.checkFlagPosition   = position;
                    this.checkFlagSinceTime  = Global.SimulationTime;
                    this.checkFlagSinceFrame = Global.CurrentFrame;
                }
                else if (!this.isFlagged && this.CheckFlaggedForFrames > Global.CheckFlagStuckDelay)
                {
                    // Check if stuck with flag.
                    double delta = this.CheckFlaggedForSeconds;

                    if (delta > Global.Settings.RecoveryCrews.DelaySeconds)
                    {
                        Log.Info(this, "IsFlagged", this.checkFlags, this.VehicleId, delta, VehicleHelper.GetVehicleName(this.VehicleId));
                        this.isFlagged = true;
                    }
                }
            }
            else if ((this.checkFlags & VehicleHelper.VehicleAll) != ~VehicleHelper.VehicleAll || this.checkFlagSinceTime != 0 || this.checkFlagSinceFrame != 0)
            {
                this.isFlagged           = false;
                this.checkFlags          = ~VehicleHelper.VehicleAll;
                this.checkFlagSinceTime  = 0;
                this.checkFlagSinceFrame = 0;
            }

            // Check if vehicle is confused.
            if (ConfusionHelper.VehicleIsConfused(ref vehicle))
            {
                if (this.confusedDeAssignedSinceFrame == 0)
                {
                    this.confusedDeAssignedSinceFrame = Global.CurrentFrame;
                }

                if (this.confusedSinceFrame == 0 || this.confusedSinceTime == 0)
                {
                    if (Log.LogALot)
                    {
                        Log.DevDebug(this, "Update", "NewConfused", this.VehicleId, this.ConfusedForSeconds, this.ConfusedForFrames, Global.Settings.RecoveryCrews.DelaySeconds, Global.DeAssignConfusedDelay, vehicle.m_targetBuilding, vehicle.m_flags, VehicleHelper.GetVehicleName(this.VehicleId));
                    }

                    this.isConfused                   = false;
                    this.confusedSinceTime            = Global.SimulationTime;
                    this.confusedSinceFrame           = Global.CurrentFrame;
                    this.confusedDeAssignedSinceFrame = Global.CurrentFrame;
                }
                else if (!this.isConfused && this.ConfusedForFrames > Global.CheckFlagStuckDelay)
                {
                    // Check if stuck confused.
                    double delta = this.ConfusedForSeconds;

                    if (delta > Global.Settings.RecoveryCrews.DelaySeconds)
                    {
                        Log.Info(this, "IsConfused", this.VehicleId, delta, VehicleHelper.GetVehicleName(this.VehicleId));
                        this.isConfused = true;
                    }
                }
            }
            else if (this.confusedSinceTime != 0 || this.confusedSinceFrame != 0 || this.confusedDeAssignedSinceFrame != 0)
            {
                this.isConfused                   = false;
                this.confusedSinceTime            = 0;
                this.confusedSinceFrame           = 0;
                this.confusedDeAssignedSinceFrame = 0;
            }

            this.isStuck = this.isLost || this.isConfused || this.isFlagged || this.isBroken;
        }
        // Run before the original method. Skip the original one if the vehicle is a cable car
        public static bool Prefix(RenderManager.CameraInfo cameraInfo, VehicleInfo info, Vector3 position, ref Quaternion rotation, Vector3 swayPosition, Vector4 lightState, Vector4 tyrePosition, Vector3 velocity, float acceleration, Color color, Vehicle.Flags flags, int variationMask, InstanceID id, bool underground, bool overground)
        {
            // if the vehicle is not a cable car, skip and use the original method
            if ((int)info.m_vehicleType != 0x1000)
            {
                return(true);
            }

            // limit rotation along the x and z axes for all meshes except submesh1
            // submesh1 would rotate in the original way(along with the cable)
            Quaternion originalRotation = rotation;

            rotation.x = 0.0f;
            rotation.z = 0.0f;

            // change how cable cars sway
            // so they don't move up and down on the cables as if they're ships moving in sea waves
            swayPosition.y = 0.0f;

            if ((cameraInfo.m_layerMask & (1 << info.m_prefabDataLayer)) == 0)
            {
                // return false to skip the original method
                return(false);
            }
            Vector3 scale = Vector3.one;

            if ((flags & Vehicle.Flags.Inverted) != 0)
            {
                scale = new Vector3(-1f, 1f, -1f);
                Vector4 vector = lightState;
                lightState.x = vector.y;
                lightState.y = vector.x;
                lightState.z = vector.w;
                lightState.w = vector.z;
            }

            info.m_vehicleAI.RenderExtraStuff(id.Vehicle, ref Singleton <VehicleManager> .instance.m_vehicles.m_buffer[id.Vehicle], cameraInfo, id, position, rotation, tyrePosition, lightState, scale, swayPosition, underground, overground);

            if (cameraInfo.CheckRenderDistance(position, info.m_lodRenderDistance))
            {
                VehicleManager instance           = Singleton <VehicleManager> .instance;
                Matrix4x4      bodyMatrix         = info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref rotation, ref scale, ref swayPosition);
                Matrix4x4      originalBodyMatrix = info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref originalRotation, ref scale, ref swayPosition);
                Matrix4x4      value = info.m_vehicleAI.CalculateTyreMatrix(flags, ref position, ref rotation, ref scale, ref bodyMatrix);
                if (Singleton <InfoManager> .instance.CurrentMode == InfoManager.InfoMode.None)
                {
                    RenderGroup.MeshData effectMeshData = info.m_vehicleAI.GetEffectMeshData();
                    EffectInfo.SpawnArea area           = new EffectInfo.SpawnArea(bodyMatrix, effectMeshData, info.m_generatedInfo.m_tyres, info.m_lightPositions);
                    if (info.m_effects != null)
                    {
                        for (int i = 0; i < info.m_effects.Length; i++)
                        {
                            VehicleInfo.Effect effect = info.m_effects[i];
                            if (((effect.m_vehicleFlagsRequired | effect.m_vehicleFlagsForbidden) & flags) == effect.m_vehicleFlagsRequired && effect.m_parkedFlagsRequired == VehicleParked.Flags.None)
                            {
                                effect.m_effect.RenderEffect(id, area, velocity, acceleration, 1f, -1f, Singleton <SimulationManager> .instance.m_simulationTimeDelta, cameraInfo);
                            }
                        }
                    }
                }
                if ((flags & Vehicle.Flags.Inverted) != 0)
                {
                    tyrePosition.x = 0f - tyrePosition.x;
                    tyrePosition.y = 0f - tyrePosition.y;
                }
                MaterialPropertyBlock materialBlock = instance.m_materialBlock;
                materialBlock.Clear();
                materialBlock.SetMatrix(instance.ID_TyreMatrix, value);
                materialBlock.SetVector(instance.ID_TyrePosition, tyrePosition);
                materialBlock.SetVector(instance.ID_LightState, lightState);
                bool flag = Singleton <ToolManager> .instance.m_properties.m_mode == ItemClass.Availability.AssetEditor;
                if (!flag)
                {
                    materialBlock.SetColor(instance.ID_Color, color);
                }
                bool flag2 = true;
                if (flag)
                {
                    flag2 = BuildingDecoration.IsMainMeshRendered();
                }
                if (info.m_subMeshes != null)
                {
                    for (int j = 0; j < info.m_subMeshes.Length; j++)
                    {
                        VehicleInfo.MeshInfo meshInfo = info.m_subMeshes[j];
                        VehicleInfoBase      subInfo  = meshInfo.m_subInfo;
                        if ((!flag && ((meshInfo.m_vehicleFlagsRequired | meshInfo.m_vehicleFlagsForbidden) & flags) == meshInfo.m_vehicleFlagsRequired && (meshInfo.m_variationMask & variationMask) == 0 && meshInfo.m_parkedFlagsRequired == VehicleParked.Flags.None) || (flag && BuildingDecoration.IsSubMeshRendered(subInfo)))
                        {
                            if (!(subInfo != null))
                            {
                                continue;
                            }
                            instance.m_drawCallData.m_defaultCalls++;
                            if (underground)
                            {
                                if (subInfo.m_undergroundMaterial == null && subInfo.m_material != null)
                                {
                                    VehicleProperties properties = instance.m_properties;
                                    if (properties != null)
                                    {
                                        subInfo.m_undergroundMaterial = new Material(properties.m_undergroundShader);
                                        subInfo.m_undergroundMaterial.CopyPropertiesFromMaterial(subInfo.m_material);
                                    }
                                }
                                subInfo.m_undergroundMaterial.SetVectorArray(instance.ID_TyreLocation, subInfo.m_generatedInfo.m_tyres);
                                if (j == 1)
                                {
                                    Graphics.DrawMesh(subInfo.m_mesh, originalBodyMatrix, subInfo.m_undergroundMaterial, instance.m_undergroundLayer, null, 0, materialBlock);
                                }
                                else
                                {
                                    Graphics.DrawMesh(subInfo.m_mesh, bodyMatrix, subInfo.m_undergroundMaterial, instance.m_undergroundLayer, null, 0, materialBlock);
                                }
                            }
                            if (overground)
                            {
                                subInfo.m_material.SetVectorArray(instance.ID_TyreLocation, subInfo.m_generatedInfo.m_tyres);
                                if (j == 1)
                                {
                                    Graphics.DrawMesh(subInfo.m_mesh, originalBodyMatrix, subInfo.m_material, info.m_prefabDataLayer, null, 0, materialBlock);
                                }
                                else
                                {
                                    Graphics.DrawMesh(subInfo.m_mesh, bodyMatrix, subInfo.m_material, info.m_prefabDataLayer, null, 0, materialBlock);
                                }
                            }
                        }
                        else if (subInfo == null)
                        {
                            flag2 = false;
                        }
                    }
                }
                if (!flag2)
                {
                    // return false to skip the original method
                    return(false);
                }
                instance.m_drawCallData.m_defaultCalls++;
                if (underground)
                {
                    if (info.m_undergroundMaterial == null && info.m_material != null)
                    {
                        VehicleProperties properties2 = instance.m_properties;
                        if (properties2 != null)
                        {
                            info.m_undergroundMaterial = new Material(properties2.m_undergroundShader);
                            info.m_undergroundMaterial.CopyPropertiesFromMaterial(info.m_material);
                        }
                    }
                    info.m_undergroundMaterial.SetVectorArray(instance.ID_TyreLocation, info.m_generatedInfo.m_tyres);
                    Graphics.DrawMesh(info.m_mesh, bodyMatrix, info.m_undergroundMaterial, instance.m_undergroundLayer, null, 0, materialBlock);
                }
                if (overground)
                {
                    info.m_material.SetVectorArray(instance.ID_TyreLocation, info.m_generatedInfo.m_tyres);
                    Graphics.DrawMesh(info.m_mesh, bodyMatrix, info.m_material, info.m_prefabDataLayer, null, 0, materialBlock);
                }
                // return false to skip the original method
                return(false);
            }
            Matrix4x4 bodyMatrix2         = info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref rotation, ref scale, ref swayPosition);
            Matrix4x4 originalBodyMatrix2 = info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref originalRotation, ref scale, ref swayPosition);

            if (Singleton <ToolManager> .instance.m_properties.m_mode == ItemClass.Availability.AssetEditor)
            {
                Matrix4x4             value2         = info.m_vehicleAI.CalculateTyreMatrix(flags, ref position, ref rotation, ref scale, ref bodyMatrix2);
                VehicleManager        instance2      = Singleton <VehicleManager> .instance;
                MaterialPropertyBlock materialBlock2 = instance2.m_materialBlock;
                materialBlock2.Clear();
                materialBlock2.SetMatrix(instance2.ID_TyreMatrix, value2);
                materialBlock2.SetVector(instance2.ID_TyrePosition, tyrePosition);
                materialBlock2.SetVector(instance2.ID_LightState, lightState);
                Mesh     mesh     = null;
                Material material = null;
                if (info.m_lodObject != null)
                {
                    MeshFilter component = info.m_lodObject.GetComponent <MeshFilter>();
                    if (component != null)
                    {
                        mesh = component.sharedMesh;
                    }
                    Renderer component2 = info.m_lodObject.GetComponent <Renderer>();
                    if (component2 != null)
                    {
                        material = component2.sharedMaterial;
                    }
                }
                if (mesh != null && material != null)
                {
                    materialBlock2.SetVectorArray(instance2.ID_TyreLocation, info.m_generatedInfo.m_tyres);
                    Graphics.DrawMesh(mesh, bodyMatrix2, material, info.m_prefabDataLayer, null, 0, materialBlock2);
                }
            }
            else if (Singleton <InfoManager> .instance.CurrentMode == InfoManager.InfoMode.None)
            {
                RenderGroup.MeshData effectMeshData2 = info.m_vehicleAI.GetEffectMeshData();
                EffectInfo.SpawnArea area2           = new EffectInfo.SpawnArea(bodyMatrix2, effectMeshData2, info.m_generatedInfo.m_tyres, info.m_lightPositions);
                if (info.m_effects != null)
                {
                    for (int k = 0; k < info.m_effects.Length; k++)
                    {
                        VehicleInfo.Effect effect2 = info.m_effects[k];
                        if (((effect2.m_vehicleFlagsRequired | effect2.m_vehicleFlagsForbidden) & flags) == effect2.m_vehicleFlagsRequired && effect2.m_parkedFlagsRequired == VehicleParked.Flags.None)
                        {
                            effect2.m_effect.RenderEffect(id, area2, velocity, acceleration, 1f, -1f, Singleton <SimulationManager> .instance.m_simulationTimeDelta, cameraInfo);
                        }
                    }
                }
            }
            bool flag3 = true;

            if (info.m_subMeshes != null)
            {
                for (int l = 0; l < info.m_subMeshes.Length; l++)
                {
                    VehicleInfo.MeshInfo meshInfo2 = info.m_subMeshes[l];
                    VehicleInfoBase      subInfo2  = meshInfo2.m_subInfo;
                    if (((meshInfo2.m_vehicleFlagsRequired | meshInfo2.m_vehicleFlagsForbidden) & flags) == meshInfo2.m_vehicleFlagsRequired && (meshInfo2.m_variationMask & variationMask) == 0 && meshInfo2.m_parkedFlagsRequired == VehicleParked.Flags.None)
                    {
                        if (!(subInfo2 != null))
                        {
                            continue;
                        }
                        if (underground)
                        {
                            if (l == 1)
                            {
                                subInfo2.m_undergroundLodTransforms[subInfo2.m_undergroundLodCount] = originalBodyMatrix2;
                            }
                            else
                            {
                                subInfo2.m_undergroundLodTransforms[subInfo2.m_undergroundLodCount] = bodyMatrix2;
                            }

                            subInfo2.m_undergroundLodLightStates[subInfo2.m_undergroundLodCount] = lightState;
                            subInfo2.m_undergroundLodColors[subInfo2.m_undergroundLodCount]      = color.linear;
                            subInfo2.m_undergroundLodMin = Vector3.Min(subInfo2.m_undergroundLodMin, position);
                            subInfo2.m_undergroundLodMax = Vector3.Max(subInfo2.m_undergroundLodMax, position);
                            if (++subInfo2.m_undergroundLodCount == subInfo2.m_undergroundLodTransforms.Length)
                            {
                                Vehicle.RenderUndergroundLod(cameraInfo, subInfo2);
                            }
                        }
                        if (overground)
                        {
                            if (l == 1)
                            {
                                subInfo2.m_lodTransforms[subInfo2.m_lodCount] = originalBodyMatrix2;
                            }
                            else
                            {
                                subInfo2.m_lodTransforms[subInfo2.m_lodCount] = bodyMatrix2;
                            }
                            subInfo2.m_lodLightStates[subInfo2.m_lodCount] = lightState;
                            subInfo2.m_lodColors[subInfo2.m_lodCount]      = color.linear;
                            subInfo2.m_lodMin = Vector3.Min(subInfo2.m_lodMin, position);
                            subInfo2.m_lodMax = Vector3.Max(subInfo2.m_lodMax, position);
                            if (++subInfo2.m_lodCount == subInfo2.m_lodTransforms.Length)
                            {
                                Vehicle.RenderLod(cameraInfo, subInfo2);
                            }
                        }
                    }
                    else if (subInfo2 == null)
                    {
                        flag3 = false;
                    }
                }
            }
            if (!flag3)
            {
                return(false);
            }
            if (underground)
            {
                info.m_undergroundLodTransforms[info.m_undergroundLodCount]  = bodyMatrix2;
                info.m_undergroundLodLightStates[info.m_undergroundLodCount] = lightState;
                info.m_undergroundLodColors[info.m_undergroundLodCount]      = color.linear;
                info.m_undergroundLodMin = Vector3.Min(info.m_undergroundLodMin, position);
                info.m_undergroundLodMax = Vector3.Max(info.m_undergroundLodMax, position);
                if (++info.m_undergroundLodCount == info.m_undergroundLodTransforms.Length)
                {
                    Vehicle.RenderUndergroundLod(cameraInfo, info);
                }
            }
            if (overground)
            {
                info.m_lodTransforms[info.m_lodCount]  = bodyMatrix2;
                info.m_lodLightStates[info.m_lodCount] = lightState;
                info.m_lodColors[info.m_lodCount]      = color.linear;
                info.m_lodMin = Vector3.Min(info.m_lodMin, position);
                info.m_lodMax = Vector3.Max(info.m_lodMax, position);
                if (++info.m_lodCount == info.m_lodTransforms.Length)
                {
                    Vehicle.RenderLod(cameraInfo, info);
                }
            }
            // return false to skip the original method
            return(false);
        }
 internal static bool CheckFlags(this Vehicle.Flags value, Vehicle.Flags required, Vehicle.Flags forbidden = 0) =>
 (value & (required | forbidden)) == required;
 internal static bool IsFlagSet(this Vehicle.Flags value, Vehicle.Flags flag) => (value & flag) != 0;
예제 #27
0
 private static VehicleInfo.VehicleType GetWireType(Vehicle.Flags vehicleFlags, Vehicle.Flags subMeshFlags)
 {
     return((subMeshFlags == Vehicle.Flags.TakingOff) ? (((vehicleFlags & Vehicle.Flags.LeftHandDrive) != 0) ? VehicleInfo.VehicleType.TrolleybusLeftPole : VehicleInfo.VehicleType.TrolleybusRightPole) : (((vehicleFlags & Vehicle.Flags.LeftHandDrive) != 0) ? VehicleInfo.VehicleType.TrolleybusRightPole : VehicleInfo.VehicleType.TrolleybusLeftPole));
 }