/// <summary> /// Initializes a new instance of the <see cref="ServiceVehicleInfo" /> class. /// </summary> /// <param name="vehicleId">The vehicle identifier.</param> /// <param name="vehicle">The vehicle.</param> /// <param name="freeToCollect">If set to <c>true</c> the vehicle is free.</param> /// <param name="dispatcherType">Type of the dispatcher.</param> /// <param name="targetBuildingId">The target building identifier.</param> public ServiceVehicleInfo(ushort vehicleId, ref Vehicle vehicle, bool freeToCollect, Dispatcher.DispatcherTypes dispatcherType, ushort targetBuildingId = 0) { this.VehicleId = vehicleId; this.dispatcherType = dispatcherType; this.LastAssigned = 0; this.Target = targetBuildingId; this.Update(ref vehicle, freeToCollect, false, false); ////if (Log.LogALot) ////{ //// Log.DevDebug(this, "ServiceVehicleInfo", vehicleId, vehicle.m_targetBuilding, this.Target, targetBuildingId); ////} }
/// <summary> /// Creates the specified service building. /// </summary> /// <param name="serviceBuilding">The service building.</param> /// <param name="material">The material.</param> /// <param name="dispatcherType">Type of the dispatcher.</param> /// <param name="targetBuildingId">The target building identifier.</param> /// <param name="targetCitizenId">The target citizen identifier.</param> /// <returns> /// The service vehicle. /// </returns> public static ServiceVehicleInfo Create(ServiceBuildingInfo serviceBuilding, TransferManager.TransferReason material, Dispatcher.DispatcherTypes dispatcherType, ushort targetBuildingId, uint targetCitizenId) { ushort vehicleId = 0; VehicleInfo info = null; if (!Global.EnableExperiments) { info = VehicleHelper.CreateServiceVehicle(serviceBuilding.BuildingId, material, targetBuildingId, targetCitizenId, out vehicleId); } else if (Global.Settings.CreationCompatibilityMode == ServiceDispatcherSettings.ModCompatibilityMode.UseCustomCode) { info = VehicleHelper.CreateServiceVehicle(serviceBuilding.BuildingId, material, targetBuildingId, targetCitizenId, out vehicleId); } else { info = BuildingHelper.StartTransfer(serviceBuilding.BuildingId, material, targetBuildingId, targetCitizenId, out vehicleId); } if (info == null) { return null; } VehicleManager manager = Singleton<VehicleManager>.instance; return new ServiceVehicleInfo(vehicleId, ref manager.m_vehicles.m_buffer[vehicleId], targetBuildingId == 0, dispatcherType, targetBuildingId); }
/// <summary> /// Initializes the dispatchers. /// </summary> public static void ReInitializeHandlers() { // Initialize dispatch objects. try { if (Settings.DeathCare.DispatchVehicles || Settings.Garbage.DispatchVehicles || Settings.HealthCare.DispatchVehicles) { // Initialize buildings. if (Buildings == null) { Buildings = new BuildingKeeper(); } else { Buildings.ReInitialize(); } if (TargetBuildingInfoPriorityComparer == null) { TargetBuildingInfoPriorityComparer = new TargetBuildingInfo.PriorityComparer(); } else { TargetBuildingInfoPriorityComparer.ReInitialize(); } if (ServiceBuildingInfoPriorityComparer == null) { ServiceBuildingInfoPriorityComparer = new ServiceBuildingInfo.PriorityComparer(); } else { ServiceBuildingInfoPriorityComparer.ReInitialize(); } // Initialize hearse objects. if (Settings.DeathCare.DispatchVehicles) { if (HearseDispatcher == null) { HearseDispatcher = new Dispatcher(Dispatcher.DispatcherTypes.HearseDispatcher); } else { HearseDispatcher.ReInitialize(); } } // Initialize garbage truck objects. if (Settings.Garbage.DispatchVehicles) { if (GarbageTruckDispatcher == null) { GarbageTruckDispatcher = new Dispatcher(Dispatcher.DispatcherTypes.GarbageTruckDispatcher); } else { GarbageTruckDispatcher.ReInitialize(); } } // Initialize hearse objects. if (Settings.HealthCare.DispatchVehicles) { if (AmbulanceDispatcher == null) { AmbulanceDispatcher = new Dispatcher(Dispatcher.DispatcherTypes.AmbulanceDispatcher); } else { AmbulanceDispatcher.ReInitialize(); } } } // Initialize vehicle objects. if (Settings.DeathCare.DispatchVehicles || Settings.Garbage.DispatchVehicles || Settings.HealthCare.DispatchVehicles || Settings.DeathCare.RemoveFromGrid || Settings.HealthCare.RemoveFromGrid) { if (Vehicles == null) { Vehicles = new VehicleKeeper(); } else { Vehicles.ReInitialize(); } } BuildingUpdateNeeded = true; } catch (Exception ex) { Log.Error(typeof(Global), "ReInitializeHandlers", ex); } }
/// <summary> /// Creates the service group. /// </summary> /// <param name="helper">The helper.</param> /// <param name="settings">The settings.</param> /// <param name="dispatcher">The dispatcher.</param> /// <param name="canService">If set to <c>true</c> this service can be enabled.</param> /// <returns> /// The group. /// </returns> private UIHelperBase CreateServiceGroup(UIHelperBase helper, Settings.StandardServiceSettings settings, Dispatcher dispatcher, bool canService) { try { UIHelperBase group = helper.AddGroup(settings.VehicleNamePlural); if (canService) { group.AddCheckbox( "Dispatch " + settings.VehicleNamePlural.ToLower(), settings.DispatchVehicles, value => { try { if (settings.DispatchVehicles != value) { settings.DispatchVehicles = value; Global.Settings.Save(); Global.ReInitializeHandlers(); } } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "DispatchVehicles", value); } }); } else { UIComponent checkBox = group.AddCheckbox( "Dispatch " + settings.VehicleNamePlural.ToLower(), false, value => { }) as UIComponent; } group.AddCheckbox( "Dispatch by district", settings.DispatchByDistrict, value => { try { if (settings.DispatchByDistrict != value) { settings.DispatchByDistrict = value; Global.BuildingUpdateNeeded = true; Global.Settings.Save(); } } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "DispatchByDistrict", value); } }); group.AddCheckbox( "Dispatch by building range", settings.DispatchByRange, value => { try { if (settings.DispatchByRange != value) { settings.DispatchByRange = value; Global.BuildingUpdateNeeded = true; Global.Settings.Save(); } } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "DispatchByRange", value); } }); if (settings.CanRemoveFromGrid) { group.AddCheckbox( "Pass through " + settings.VehicleNamePlural.ToLower(), settings.RemoveFromGrid, value => { try { if (settings.RemoveFromGrid != value) { settings.RemoveFromGrid = value; Global.Settings.Save(); Global.ReInitializeHandlers(); } } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "RemoveFromGrid", value); } }); } if (settings.CanLimitOpportunisticCollection) { if (settings.OpportunisticCollectionLimitDetour == Detours.Methods.None || Detours.CanDetour(settings.OpportunisticCollectionLimitDetour)) { group.AddCheckbox( "Prioritize assigned buildings", settings.LimitOpportunisticCollection, value => { try { if (settings.LimitOpportunisticCollection != value) { settings.LimitOpportunisticCollection = value; Detours.InitNeeded = true; Global.Settings.Save(); } } catch (Exception ex) { Log.Error(this, "OnSettingsUI", ex, "GarbageGroup", "LimitOpportunisticGarbageCollection", value); Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "LimitOpportunisticCollection"); } }); } else { UIComponent limitOpportunisticGarbageCollectionCheckBox = group.AddCheckbox( "Prioritize assigned buildings", false, value => { }) as UIComponent; limitOpportunisticGarbageCollectionCheckBox.Disable(); } } group.AddDropdown( "Send out spare " + settings.VehicleNamePlural.ToLower() + " when", this.vehicleCreationOptions.OrderBy(vco => vco.Key).Select(vco => vco.Value).ToArray(), (int)settings.CreateSpares, value => { try { if (Log.LogALot || Library.IsDebugBuild) { Log.Debug(this, "CreateServiceGroup", "Set", settings.VehicleNamePlural, "CreateSpares", value); } foreach (ServiceDispatcherSettings.SpareVehiclesCreation option in Enum.GetValues(typeof(ServiceDispatcherSettings.SpareVehiclesCreation))) { if ((byte)option == value) { if (settings.CreateSpares != option) { if (Log.LogALot || Library.IsDebugBuild) { Log.Debug(this, "CreateServiceGroup", "Set", settings.VehicleNamePlural, "CreateSpares", value, option); } settings.CreateSpares = option; if (dispatcher != null) { try { dispatcher.ReInitialize(); } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "CreateSpares", "ReInitializeDispatcher"); } } Global.Settings.Save(); } break; } } } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "CreateSpares", value); } }); group.AddDropdown( settings.VehicleNameSingular + " dispatch strategy", this.targetBuildingChecks.OrderBy(bco => bco.Key).Select(bco => bco.Value).ToArray(), (int)settings.ChecksPreset, value => { try { if (Log.LogALot || Library.IsDebugBuild) { Log.Debug(this, "CreateServiceGroup", "Set", settings.VehicleNamePlural, "ChecksPreset", value); } foreach (ServiceDispatcherSettings.BuildingCheckOrder checks in Enum.GetValues(typeof(ServiceDispatcherSettings.BuildingCheckOrder))) { if ((byte)checks == value) { if (settings.ChecksPreset != checks) { if (Log.LogALot || Library.IsDebugBuild) { Log.Debug(this, "CreateServiceGroup", "Set", settings.VehicleNamePlural, "ChecksPreset", value, checks); } try { settings.ChecksPreset = checks; } catch (Exception ex) { Log.Error(this, "OnSettingsUI", ex, "Set", "DeathChecksPreset", checks); } if (dispatcher != null) { try { dispatcher.ReInitialize(); } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "ChecksPreset", "ReInitializeDispatcher"); } } Global.Settings.Save(); } break; } } } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "ChecksPreset", value); } }); if (settings.UseMinimumAmountForPatrol) { group.AddExtendedSlider( settings.MaterialName + " patrol limit", 1.0f, 5000.0f, 1.0f, settings.MinimumAmountForPatrol, false, value => { try { if (settings.MinimumAmountForPatrol != (ushort)value) { settings.MinimumAmountForPatrol = (ushort)value; Global.BuildingUpdateNeeded = true; Global.Settings.Save(); } } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "MinimumAmountForPatrol", value); } }); } if (settings.UseMinimumAmountForDispatch) { group.AddExtendedSlider( settings.MaterialName + " dispatch limit", 1.0f, 5000.0f, 1.0f, settings.MinimumAmountForDispatch, false, value => { try { if (settings.MinimumAmountForDispatch != (ushort)value) { settings.MinimumAmountForDispatch = (ushort)value; Global.BuildingUpdateNeeded = true; Global.Settings.Save(); } } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.VehicleNamePlural, "MinimumAmountForDispatch", value); } }); } return group; } catch (Exception ex) { Log.Error(this, "CreateServiceGroup", ex, settings.EmptiableServiceBuildingNamePlural); return null; } }
/// <summary> /// Disposes the dispatchers. /// </summary> public static void DisposeHandlers() { Global.GarbageTruckDispatcher = null; Global.HearseDispatcher = null; Global.AmbulanceDispatcher = null; Global.ServiceBuildingInfoPriorityComparer = null; Global.TargetBuildingInfoPriorityComparer = null; Global.Buildings = null; Global.Vehicles = null; }