/// <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); }
/// <summary> /// Updates the specified trailer vehicle. /// </summary> /// <param name="vehicle">The vehicle.</param> private void UpdateTrailer(ref Vehicle vehicle) { Vehicle[] vehicles = Singleton <VehicleManager> .instance.m_vehicles.m_buffer; LostReasons lost = LostReasons.None; ushort count = 0; ushort leadId = this.VehicleId; ushort nextId = vehicle.m_leadingVehicle; while (nextId != 0) { if (vehicles[nextId].m_trailingVehicle != leadId) { lost = LostReasons.IgnorantLead; break; } if (count >= ushort.MaxValue) { throw new Exception("Loop counter too high"); } count++; leadId = nextId; nextId = vehicles[leadId].m_leadingVehicle; } if (lost == LostReasons.None && (vehicles[leadId].Info == null || (vehicles[leadId].m_flags & Vehicle.Flags.Spawned) == ~VehicleHelper.VehicleAll)) { lost = LostReasons.NoLead; } if (lost != LostReasons.None) { if (this.lostSinceFrame == 0 || this.lostSinceTime == 0 || this.lostReason == LostReasons.None || lost != this.lostReason) { if (Log.LogALot) { Log.DevDebug(this, "UpdateTrailer", "NewLost", lost, this.VehicleId, this.LostForSeconds, this.LostForFrames, Global.Settings.RecoveryCrews.DelaySeconds, Global.CheckFlagStuckDelay, vehicle.m_leadingVehicle, vehicle.m_flags, VehicleHelper.GetVehicleName(this.VehicleId)); } this.isLost = false; this.lostReason = lost; this.lostSinceTime = Global.SimulationTime; this.lostSinceFrame = Global.CurrentFrame; } else if (!this.isLost) { double delta; if (this.lostReason != LostReasons.None && this.LostForFrames > Global.CheckFlagStuckDelay) { delta = this.LostForSeconds; if (delta > Global.Settings.RecoveryCrews.DelaySeconds) { Log.Info(this, "IsLost", lost, this.VehicleId, delta, VehicleHelper.GetVehicleName(this.VehicleId)); this.isLost = true; } } } } else { this.isLost = false; this.lostReason = LostReasons.None; this.lostSinceTime = 0; this.lostSinceFrame = 0; } this.isStuck = this.isLost || this.isConfused || this.isFlagged || this.isBroken; }