Beispiel #1
0
        /// <summary>
        /// Adds the building information to the string information.
        /// </summary>
        /// <param name="vehicle">The vehicle.</param>
        /// <param name="vehicles">The vehicles.</param>
        /// <param name="buildings">The buildings.</param>
        /// <param name="getHead">if set to <c>true</c> get for header instead of data.</param>
        /// <param name="buildingId">The building identifier.</param>
        /// <param name="buildingType">Type of the building.</param>
        /// <param name="info">The information.</param>
        private static void InfoStringInfoForBuilding(StuckVehicleInfo vehicle, Vehicle[] vehicles, Building[] buildings, bool getHead, ushort buildingId, string buildingType, Log.InfoList info)
        {
            if (getHead)
            {
                info.Add("[" + buildingType + "]", "<buildingId>", "[BuildingName]", "[districtId]", "[DistrictName]");
                return;
            }

            if (buildingId == 0)
            {
                return;
            }

            byte districtId = BuildingHelper.GetDistrict(buildingId);

            if (districtId == 0)
            {
                info.Add(
                    buildingType,
                    buildingId,
                    BuildingHelper.GetBuildingName(vehicles[vehicle.VehicleId].m_sourceBuilding));
            }
            else
            {
                info.Add(
                    buildingType,
                    buildingId,
                    BuildingHelper.GetBuildingName(vehicles[vehicle.VehicleId].m_sourceBuilding),
                    districtId,
                    DistrictHelper.GetDistrictName(districtId));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Tries to deserialize the specified serialized data to this instance.
        /// </summary>
        /// <param name="serializedData">The serialized data.</param>
        /// <param name="stuckVehicleInfo">The stuck vehicle information.</param>
        /// <returns>
        /// The deserialization result.
        /// </returns>
        public static SerializableSettings.DeserializationResult Deserialize(SerializableSettings.BinaryData serializedData, out StuckVehicleInfo stuckVehicleInfo)
        {
            stuckVehicleInfo = new StuckVehicleInfo();
            SerializableSettings.DeserializationResult result = stuckVehicleInfo.Deserialize(serializedData);

            if (result != SerializableSettings.DeserializationResult.Success)
            {
                stuckVehicleInfo = null;
            }

            return(result);
        }
        /// <summary>
        /// Deserializes the automatic emptying building list.
        /// </summary>
        /// <param name="serializedData">The serialized data.</param>
        public void DeserializeStuckVehicles(SerializableSettings.BinaryData serializedData)
        {
            if (serializedData.Left == 0)
            {
                return;
            }

            try
            {
                ulong version = serializedData.GetVersion();
                if (version > 0)
                {
                    Log.Warning(this, "DeserializeStuckVehicles", "Serialized data version too high!", version, 0);
                    return;
                }

                if (serializedData.Left == 0 || this.StuckVehicles == null)
                {
                    return;
                }

                StuckVehicleInfo vehicle;
                SerializableSettings.DeserializationResult result;
                while ((result = StuckVehicleInfo.Deserialize(serializedData, out vehicle)) == SerializableSettings.DeserializationResult.Success)
                {
                    this.StuckVehicles[vehicle.VehicleId] = vehicle;
                }

                if (result == SerializableSettings.DeserializationResult.Error)
                {
                    this.StuckVehicles.Clear();
                }
                else if (Log.LogALot)
                {
                    Log.DevDebug(this, "DeserializeStuckVehicles", this.StuckVehicles.Count, String.Join(" | ", this.StuckVehicles.Values.OrderBy(v => v.VehicleId).SelectToArray(v => "[" + v.ToString() + "]")));
                }
            }
            catch (Exception ex)
            {
                Log.Error(this, "DeserializeStuckVehicles", ex);

                if (this.StuckVehicles != null)
                {
                    this.StuckVehicles.Clear();
                }
            }
        }
        /// <summary>
        /// Categorizes the vehicles.
        /// </summary>
        /// <param name="firstVehicleId">The first vehicle identifier.</param>
        /// <param name="lastVehicleId">The last vehicle identifier.</param>
        private void HandleVehicles(ushort firstVehicleId, int lastVehicleId)
        {
            Vehicle[] vehicles = Singleton<VehicleManager>.instance.m_vehicles.m_buffer;
            Building[] buildings = Singleton<BuildingManager>.instance.m_buildings.m_buffer;

            for (ushort id = firstVehicleId; id < lastVehicleId; id++)
            {
                // Is the vehicle?
                if (vehicles[id].m_leadingVehicle != 0 || vehicles[id].m_cargoParent != 0 || vehicles[id].Info == null || (vehicles[id].m_flags & VehicleHelper.VehicleExists) == ~Vehicle.Flags.All)
                {
                    if (this.removedFromGrid != null && this.removedFromGrid.Contains(id))
                    {
                        this.removedFromGrid.Remove(id);
                    }

                    if (this.StuckVehicles != null && this.StuckVehicles.ContainsKey(id))
                    {
                        if (Log.LogALot && Log.LogToFile)
                        {
                            Log.DevDebug(this, "HandleVehicles", "StuckVehicles", "Gone", id);
                        }

                        this.StuckVehicles.Remove(id);
                    }
                }
                else
                {
                    // Check target assignments for service vehicles.
                    if ((vehicles[id].m_flags & Vehicle.Flags.TransferToSource) != ~Vehicle.Flags.All &&
                        (vehicles[id].m_flags & (Vehicle.Flags.TransferToTarget | Vehicle.Flags.Arriving | Vehicle.Flags.Stopped)) == ~Vehicle.Flags.All &&
                        (vehicles[id].m_flags & VehicleHelper.VehicleUnavailable) == ~Vehicle.Flags.All &&
                        vehicles[id].m_targetBuilding != vehicles[id].m_sourceBuilding && (buildings[vehicles[id].m_sourceBuilding].m_flags & Building.Flags.Downgrading) == Building.Flags.None)
                    {
                        if (Global.Settings.DeathCare.DispatchVehicles && Global.HearseDispatcher != null && vehicles[id].m_transferType == Global.HearseDispatcher.TransferType)
                        {
                            Global.HearseDispatcher.CheckVehicleTarget(id, ref vehicles[id]);
                        }

                        if (Global.Settings.Garbage.DispatchVehicles && Global.GarbageTruckDispatcher != null && vehicles[id].m_transferType == Global.GarbageTruckDispatcher.TransferType)
                        {
                            Global.GarbageTruckDispatcher.CheckVehicleTarget(id, ref vehicles[id]);
                        }

                        if (Global.Settings.HealthCare.DispatchVehicles && Global.AmbulanceDispatcher != null && vehicles[id].m_transferType == Global.AmbulanceDispatcher.TransferType)
                        {
                            Global.AmbulanceDispatcher.CheckVehicleTarget(id, ref vehicles[id]);
                        }
                    }

                    // Handle grid removals.
                    if (this.removedFromGrid != null)
                    {
                        if ((vehicles[id].m_flags & Vehicle.Flags.Stopped) == ~Vehicle.Flags.All &&
                            (vehicles[id].Info.m_vehicleAI is HearseAI || vehicles[id].Info.m_vehicleAI is AmbulanceAI))
                        {
                            if (this.removedFromGrid.Contains(id))
                            {
                                if (Log.LogToFile)
                                {
                                    Log.Debug(this, "HandleVehicles", "Moving", id, vehicles[id].m_targetBuilding, vehicles[id].Info.name, VehicleHelper.GetVehicleName(id), vehicles[id].m_flags);
                                }

                                this.removedFromGrid.Remove(id);
                            }
                        }
                        else if ((Global.Settings.DeathCare.RemoveFromGrid && vehicles[id].Info.m_vehicleAI is HearseAI) ||
                                  (Global.Settings.HealthCare.RemoveFromGrid && vehicles[id].Info.m_vehicleAI is AmbulanceAI))
                        {
                            if (!this.removedFromGrid.Contains(id))
                            {
                                if (Log.LogToFile)
                                {
                                    Log.Debug(this, "HandleVehicles", "RemoveFromGrid", id, vehicles[id].m_targetBuilding, vehicles[id].Info.name, VehicleHelper.GetVehicleName(id), vehicles[id].m_flags);
                                }

                                Singleton<VehicleManager>.instance.RemoveFromGrid(id, ref vehicles[id], false);
                                this.removedFromGrid.Add(id);
                            }
                        }
                    }

                    // Try to fix stuck vehicles.
                    if (this.StuckVehicles != null)
                    {
                        if (StuckVehicleInfo.HasProblem(id, ref vehicles[id]))
                        {
                            StuckVehicleInfo stuckVehicle;
                            if (this.StuckVehicles.TryGetValue(id, out stuckVehicle))
                            {
                                stuckVehicle.Update(ref vehicles[id]);
                            }
                            else
                            {
                                if (Log.LogALot && Log.LogToFile)
                                {
                                    Log.DevDebug(this, "HandleVehicles", "StuckVehicles", "New", id, vehicles[id].m_flags, vehicles[id].m_flags & StuckVehicleInfo.FlagsToCheck, ConfusionHelper.VehicleIsConfused(ref vehicles[id]));
                                }
                                else
                                {
                                    Log.Debug(this, "HandleVehicles", "StuckVehicles", "New", id);
                                }
                                stuckVehicle = new StuckVehicleInfo(id, ref vehicles[id]);
                                this.StuckVehicles[id] = stuckVehicle;
                            }

                            if (stuckVehicle.HandleProblem())
                            {
                                if (Log.LogALot && Log.LogToFile)
                                {
                                    Log.DevDebug(this, "HandleVehicles", "StuckVehicles", "Handled", id);
                                }

                                this.StuckVehicles.Remove(id);
                            }
                        }
                        else if (this.StuckVehicles.ContainsKey(id))
                        {
                            if (Log.LogALot && Log.LogToFile)
                            {
                                Log.DevDebug(this, "HandleVehicles", "StuckVehicles", "NoProblem", id, vehicles[id].m_flags, vehicles[id].m_flags & StuckVehicleInfo.FlagsToCheck, ConfusionHelper.VehicleIsConfused(ref vehicles[id]));
                            }

                            this.StuckVehicles.Remove(id);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <param name="vehicle">The vehicle.</param>
        /// <param name="vehicles">The vehicles.</param>
        /// <param name="buildings">The buildings.</param>
        /// <param name="getHead">if set to <c>true</c> get header instead of data.</param>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        private static string InfoString(StuckVehicleInfo vehicle, Vehicle[] vehicles, Building[] buildings, bool getHead)
        {
            Log.InfoList info = new Log.InfoList();

            List <string> status   = null;
            List <string> dispatch = null;
            string        ai       = null;

            if (!getHead)
            {
                if (vehicles == null)
                {
                    vehicles = Singleton <VehicleManager> .instance.m_vehicles.m_buffer;
                }

                if (buildings == null)
                {
                    buildings = Singleton <BuildingManager> .instance.m_buildings.m_buffer;
                }

                status = new List <string>(1);
                if (vehicle.isStuck)
                {
                    status.Add("Stuck");
                }
                if (vehicle.isBroken)
                {
                    status.Add("Broken");
                }
                if (vehicle.isLost)
                {
                    status.Add("Lost");
                }
                if (vehicle.isConfused)
                {
                    status.Add("Confused");
                }
                if (vehicle.isFlagged)
                {
                    status.Add("Flagged");
                }
                if (status.Count == 0)
                {
                    status.Add("Checking");
                }

                dispatch = new List <string>(2);
                if (IsDispatchersResponsibility(vehicle.dispatcherType))
                {
                    dispatch.Add("IsResponsible");
                }
                if (vehicle.dispatcherType != Dispatcher.DispatcherTypes.None)
                {
                    dispatch.Add(vehicle.dispatcherType.ToString());
                }

                try
                {
                    if (vehicles[vehicle.VehicleId].Info != null)
                    {
                        if (vehicles[vehicle.VehicleId].Info.m_vehicleAI != null)
                        {
                            ai = vehicles[vehicle.VehicleId].Info.m_vehicleAI.GetType().ToString();
                        }
                    }
                }
                catch { }
            }

            if (getHead)
            {
                info.Add("<Status>", "<Status>");
                info.Add("<Vehicle>", "<VehicleId>", "[VehicleName]", "[VehicleAI]", "[ExtraInfo]");
            }
            else
            {
                info.Add("Status", status);
                info.Add("Vehicle", vehicle.VehicleId, vehicle.VehicleName, ai, vehicle.ExtraInfo);
            }

            if (getHead)
            {
                info.Add("[Dispatch]", "[Responsibility]", "[DispatcherType]");
            }
            else if (dispatch.Count > 0)
            {
                info.Add("Dispatch", dispatch);
            }

            if (getHead)
            {
                info.Add("[Confused]", "<ConfusedForSeconds>", "<ConfusedForFrames>");
            }
            else if (vehicle.confusedSinceFrame > 0 || vehicle.confusedSinceTime > 0.0)
            {
                info.Add("Confused", vehicle.ConfusedForSeconds, vehicle.ConfusedForFrames);
            }

            if (getHead)
            {
                info.Add("[Flagged]", "<FlaggedForSeconds>", "<FlaggedForFrames>", "[Flags]", "[Position]");
            }
            else if (vehicle.checkFlagSinceFrame > 0 || vehicle.checkFlagSinceTime > 0.0)
            {
                info.Add("Flagged", vehicle.CheckFlaggedForSeconds, vehicle.CheckFlaggedForFrames, vehicle.checkFlags, vehicle.checkFlagPosition);
            }

            if (getHead)
            {
                info.Add("[Lost]", "<LostForSeconds>", "<LostForFrames>", "[LostReason]");
            }
            else if (vehicle.lostSinceFrame > 0 || vehicle.lostSinceTime > 0.0)
            {
                info.Add("Lost", vehicle.LostForSeconds, vehicle.LostForFrames, vehicle.lostReason);
            }

            if (getHead)
            {
                info.Add("[District]", "<districtId>", "[DistrictName]");
            }
            else if (vehicle.checkFlagSinceFrame > 0 || vehicle.checkFlagSinceTime > 0.0)
            {
                try
                {
                    byte districtId = DistrictHelper.GetDistrict(vehicle.checkFlagPosition);
                    if (districtId != 0)
                    {
                        info.Add("District", districtId, DistrictHelper.GetDistrictName(districtId));
                    }
                }
                catch { }
            }

            if (getHead)
            {
                InfoStringInfoForBuilding(null, null, null, true, 0, "SourceBuilding", info);
                InfoStringInfoForBuilding(null, null, null, true, 0, "TargetBuilding", info);
            }
            else
            {
                try
                {
                    InfoStringInfoForBuilding(vehicle, vehicles, buildings, false, vehicles[vehicle.VehicleId].m_sourceBuilding, "SourceBuilding", info);
                    InfoStringInfoForBuilding(vehicle, vehicles, buildings, false, vehicles[vehicle.VehicleId].m_targetBuilding, "TargetBuilding", info);
                }
                catch { }
            }

            if (getHead)
            {
                info.Add("[Handling]", "<HandledForFrames>", "<HandlingErrors>");
            }
            else if (vehicle.handlingErrors > 0 || vehicle.lastHandledStamp > 0)
            {
                info.Add("Handling", (vehicle.lastHandledStamp > 0 && vehicle.lastHandledStamp < Global.CurrentFrame) ? Global.CurrentFrame - vehicle.lastHandledStamp : 0, vehicle.handlingErrors);
            }

            return(info.ToString());
        }
        /// <summary>
        /// Categorizes the vehicles.
        /// </summary>
        /// <param name="firstVehicleId">The first vehicle identifier.</param>
        /// <param name="lastVehicleId">The last vehicle identifier.</param>
        private void HandleVehicles(ushort firstVehicleId, int lastVehicleId)
        {
            Vehicle[]  vehicles  = Singleton <VehicleManager> .instance.m_vehicles.m_buffer;
            Building[] buildings = Singleton <BuildingManager> .instance.m_buildings.m_buffer;

            for (ushort id = firstVehicleId; id < lastVehicleId; id++)
            {
                // Is the vehicle?
                if (vehicles[id].m_leadingVehicle != 0 || vehicles[id].m_cargoParent != 0 || vehicles[id].Info == null || (vehicles[id].m_flags & VehicleHelper.VehicleExists) == ~VehicleHelper.VehicleAll)
                {
                    if (this.removedFromGrid != null && this.removedFromGrid.Contains(id))
                    {
                        this.removedFromGrid.Remove(id);
                    }

                    if (this.StuckVehicles != null && this.StuckVehicles.ContainsKey(id))
                    {
                        //if (Log.LogALot)
                        //{
                        //    Log.DevDebug(this, "HandleVehicles", "StuckVehicles", "Gone", id);
                        //}

                        this.StuckVehicles.Remove(id);
                    }
                }
                else
                {
                    // Check target assignments for service vehicles.
                    if ((vehicles[id].m_flags & Vehicle.Flags.TransferToSource) != ~VehicleHelper.VehicleAll &&
                        (vehicles[id].m_flags & (Vehicle.Flags.TransferToTarget | Vehicle.Flags.Arriving | Vehicle.Flags.Stopped)) == ~VehicleHelper.VehicleAll &&
                        (vehicles[id].m_flags & VehicleHelper.VehicleUnavailable) == ~VehicleHelper.VehicleAll &&
                        vehicles[id].m_targetBuilding != vehicles[id].m_sourceBuilding && (buildings[vehicles[id].m_sourceBuilding].m_flags & Building.Flags.Downgrading) == Building.Flags.None)
                    {
                        if (Global.Settings.DeathCare.DispatchVehicles && Global.HearseDispatcher != null && vehicles[id].m_transferType == Global.HearseDispatcher.TransferType)
                        {
                            Global.HearseDispatcher.CheckVehicleTarget(id, ref vehicles[id]);
                        }

                        if (Global.Settings.Garbage.DispatchVehicles && Global.GarbageTruckDispatcher != null && vehicles[id].m_transferType == Global.GarbageTruckDispatcher.TransferType)
                        {
                            Global.GarbageTruckDispatcher.CheckVehicleTarget(id, ref vehicles[id]);
                        }

                        if (Global.Settings.HealthCare.DispatchVehicles && Global.AmbulanceDispatcher != null && vehicles[id].m_transferType == Global.AmbulanceDispatcher.TransferType)
                        {
                            Global.AmbulanceDispatcher.CheckVehicleTarget(id, ref vehicles[id]);
                        }
                    }

                    // Handle grid removals.
                    if (this.removedFromGrid != null)
                    {
                        if ((vehicles[id].m_flags & Vehicle.Flags.Stopped) == ~VehicleHelper.VehicleAll &&
                            (vehicles[id].Info.m_vehicleAI is HearseAI || vehicles[id].Info.m_vehicleAI is AmbulanceAI))
                        {
                            if (this.removedFromGrid.Contains(id))
                            {
                                if (Log.LogALot)
                                {
                                    Log.Debug(this, "HandleVehicles", "Moving", id, vehicles[id].m_targetBuilding, vehicles[id].Info.name, VehicleHelper.GetVehicleName(id), vehicles[id].m_flags);
                                }

                                this.removedFromGrid.Remove(id);
                            }
                        }
                        else if ((Global.Settings.DeathCare.RemoveFromGrid && vehicles[id].Info.m_vehicleAI is HearseAI) ||
                                 (Global.Settings.HealthCare.RemoveFromGrid && vehicles[id].Info.m_vehicleAI is AmbulanceAI))
                        {
                            if (!this.removedFromGrid.Contains(id))
                            {
                                if (Log.LogALot)
                                {
                                    Log.Debug(this, "HandleVehicles", "RemoveFromGrid", id, vehicles[id].m_targetBuilding, vehicles[id].Info.name, VehicleHelper.GetVehicleName(id), vehicles[id].m_flags);
                                }

                                Singleton <VehicleManager> .instance.RemoveFromGrid(id, ref vehicles[id], false);

                                this.removedFromGrid.Add(id);
                            }
                        }
                    }

                    // Try to fix stuck vehicles.
                    if (this.StuckVehicles != null)
                    {
                        if (StuckVehicleInfo.HasProblem(id, ref vehicles[id]))
                        {
                            StuckVehicleInfo stuckVehicle;
                            if (this.StuckVehicles.TryGetValue(id, out stuckVehicle))
                            {
                                stuckVehicle.Update(ref vehicles[id]);
                            }
                            else
                            {
                                stuckVehicle           = new StuckVehicleInfo(id, ref vehicles[id]);
                                this.StuckVehicles[id] = stuckVehicle;

                                if (Log.LogALot)
                                {
                                    Log.DevDebug(this, "HandleVehicles", "StuckVehicles", "New", id, vehicles[id].m_flags, stuckVehicle.Flagged, stuckVehicle.Lost, stuckVehicle.Confused, stuckVehicle.ExtraInfo);
                                }
                            }

                            if (stuckVehicle.HandleProblem())
                            {
                                if (Log.LogALot)
                                {
                                    Log.DevDebug(this, "HandleVehicles", "StuckVehicles", "Handled", id);
                                }

                                this.StuckVehicles.Remove(id);
                            }
                        }
                        else if (this.StuckVehicles.ContainsKey(id))
                        {
                            if (Log.LogALot)
                            {
                                Log.DevDebug(this, "HandleVehicles", "StuckVehicles", "NoProblem", id, vehicles[id].m_flags, vehicles[id].m_flags & StuckVehicleInfo.FlagsToCheck, ConfusionHelper.VehicleIsConfused(ref vehicles[id]));
                            }

                            this.StuckVehicles.Remove(id);
                        }
                    }
                }
            }
        }