/// <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)); } }
/// <summary> /// Logs the transfer offers. /// </summary> /// <param name="direction">The direction.</param> /// <param name="offers">The offers.</param> /// <param name="count">The count.</param> /// <param name="amount">The amount.</param> /// <param name="buildings">The buildings.</param> /// <param name="material">The material.</param> private static void DebugListLog( string direction, TransferManager.TransferOffer[] offers, ushort[] count, int[] amount, Building[] buildings, TransferManager.TransferReason material) { for (int priority = 0; priority < 8; priority++) { int index = ((int)material * 8) + priority; for (int i = 0; i < count[index]; i++) { Log.InfoList info = new Log.InfoList(); TransferManager.TransferOffer offer = offers[(index * 256) + i]; info.Add("Active", offer.Active); info.Add("Amount", offer.Amount); info.Add("Priority", offer.Priority); info.Add("Vehicle", offer.Vehicle, VehicleHelper.GetVehicleName(offer.Vehicle)); info.Add("Citizen", offer.Citizen, CitizenHelper.GetCitizenName(offer.Citizen)); info.Add("TransportLine", offer.TransportLine, TransportLineHelper.GetLineName(offer.TransportLine)); info.Add("Building", offer.Building, BuildingHelper.GetBuildingName(offer.Building), BuildingHelper.GetDistrictName(offer.Building)); if (buildings != null && offer.Building > 0 && buildings[offer.Building].Info != null && (buildings[offer.Building].m_flags & Building.Flags.Created) == Building.Flags.Created) { info.Add("Garbage", buildings[offer.Building].m_garbageBuffer); info.Add("Dead", buildings[offer.Building].m_deathProblemTimer); } Log.DevDebug(typeof(TransferManagerHelper), "DebugListLog", direction, material, info); } } }
/// <summary> /// Creates a new instance of an information list with garbage vehicle info. /// </summary> /// <param name="vehicleId">The vehicle identifier.</param> /// <param name="vehicle">The vehicle.</param> /// <param name="dirtyBuildingId">The dirty building identifier.</param> /// <param name="dirtyBuilding">The dirty building.</param> /// <returns>The information list.</returns> private static Log.InfoList NewGarbageVehicleInfoList(ushort vehicleId, ref Vehicle vehicle, ushort dirtyBuildingId, ref Building dirtyBuilding) { Log.InfoList infoList = new Log.InfoList(); infoList.Add("SourceBuilding", vehicle.m_sourceBuilding, BuildingHelper.GetBuildingName(vehicle.m_sourceBuilding)); infoList.Add("Vehicle", vehicleId, VehicleHelper.GetVehicleName(vehicleId)); infoList.Add("DirtyBuilding", dirtyBuildingId, BuildingHelper.GetBuildingName(dirtyBuildingId)); infoList.Add("TargetBuilding", vehicle.m_targetBuilding, BuildingHelper.GetBuildingName(vehicle.m_targetBuilding)); return(infoList); }
public void DebugListLog() { Log.InfoList info = new Log.InfoList(); info.Add("ServiceBuildingId", this.ServiceBuilding); info.Add("TargetBuildingId", this.TargetBuilding); info.Add("Problem", this.ServiceProblem); info.Add("Weight", this.ProblemWeight); info.Add("ServiceBuildingName", BuildingHelper.GetBuildingName(this.ServiceBuilding)); info.Add("TargetBuildingName", BuildingHelper.GetBuildingName(this.TargetBuilding)); Log.DevDebug(this, "DebugListLog", info.ToString()); }
/// <summary> /// Gets the spawn position. /// </summary> /// <param name="vehicleId">The vehicle identifier.</param> /// <param name="vehicleInfo">The vehicle information.</param> /// <param name="buildingId">The building identifier.</param> /// <returns>The spawn position.</returns> public static Vector3 GetSpawnPosition(ushort vehicleId, VehicleInfo vehicleInfo, ushort buildingId) { try { Building building = BuildingHelper.GetBuilding(buildingId); Randomizer randomizer = new Randomizer((int)buildingId); Vector3 position; Vector3 target; building.Info.m_buildingAI.CalculateSpawnPosition(buildingId, ref building, ref randomizer, vehicleInfo, out position, out target); return(position); } catch (Exception) { return(Vector3.zero); } }
/// <summary> /// Logs a list of service problem info for debug use. /// </summary> public void DebugListLogServiceProblems() { try { foreach (KeyValuePair <uint, uint> size in this.ProblemSizes) { ushort serviceBuildingId = GetServiceBuildingFromBuildingKey(size.Key); ushort targetBuildingId = GetTargetBuildingFromBuildingKey(size.Key); Log.InfoList info = new Log.InfoList("ProblemSize"); info.Add("ServiceBuildingId", serviceBuildingId); info.Add("TargetBuildingId", targetBuildingId); info.Add("ProblemSize", size.Value); info.Add("ServiceBuildingName", BuildingHelper.GetBuildingName(serviceBuildingId)); info.Add("TargetBuildingName", BuildingHelper.GetBuildingName(targetBuildingId)); Log.DevDebug(this, "DebugListLog", info.ToString()); } foreach (KeyValuePair <ushort, BuildingProblem> problem in TargetBuildingProblems) { Log.InfoList info = new Log.InfoList("TargetBuildingProblem"); info.Add("TargetBuildingId", problem.Key); info.Add("ProblemCount", problem.Value.Count); info.Add("ProblemSize", problem.Value.Size); info.Add("TargetBuildingName", BuildingHelper.GetBuildingName(problem.Key)); Log.DevDebug(this, "DebugListLog", info.ToString()); } } catch (Exception ex) { Log.Error(this, "AddServiceProblemNote", ex); } }
/// <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.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> /// Collects vehicle debug information. /// </summary> /// <param name="vehicles">The vehicles.</param> /// <param name="buildings">The buildings.</param> /// <param name="vehicleId">The vehicle identifier.</param> /// <param name="verbose">If set to <c>true</c> include more information.</param> /// <returns> /// Vehicle information. /// </returns> private static Log.InfoList DebugInfoMsg(Vehicle[] vehicles, Building[] buildings, ushort vehicleId, bool verbose = false) { Log.InfoList info = new Log.InfoList(); InstanceID instanceId; float prgCur, prgMax; int bufCur, bufMax; string localeKey; float distance; string name; info.Add("VehicleId", vehicleId); if (verbose) { info.Add("LeadingVehicle", vehicles[vehicleId].m_leadingVehicle); info.Add("TrailingVehicle", vehicles[vehicleId].m_trailingVehicle); info.Add("CargoParent", vehicles[vehicleId].m_cargoParent); } try { info.Add("AI", vehicles[vehicleId].Info.m_vehicleAI.GetType()); info.Add("InfoName", vehicles[vehicleId].Info.name); name = GetVehicleName(vehicleId); if (!String.IsNullOrEmpty(name) && name != vehicles[vehicleId].Info.name) { info.Add("VehicleName", name); } } catch { info.Add("Error", "Info"); } try { TransferManager.TransferReason reason; if (Enums.TryConvertToTransferReason(vehicles[vehicleId].m_transferType, out reason)) { info.Add("Type", reason); } else { info.Add("Type", vehicles[vehicleId].m_transferType); } } catch { info.Add("Error", "Transfer"); } try { if (vehicles[vehicleId].m_sourceBuilding != 0 && buildings[vehicles[vehicleId].m_sourceBuilding].Info != null) { distance = (vehicles[vehicleId].GetLastFramePosition() - buildings[vehicles[vehicleId].m_sourceBuilding].m_position).sqrMagnitude; name = BuildingHelper.GetBuildingName(vehicles[vehicleId].m_sourceBuilding); if (String.IsNullOrEmpty(name)) { name = buildings[vehicles[vehicleId].m_sourceBuilding].Info.name; } info.Add("Source", vehicles[vehicleId].m_sourceBuilding, name, distance); } } catch { info.Add("Error", "SourceBuilding"); } try { if (vehicles[vehicleId].m_targetBuilding != 0 && buildings[vehicles[vehicleId].m_targetBuilding].Info != null) { distance = (vehicles[vehicleId].GetLastFramePosition() - buildings[vehicles[vehicleId].m_targetBuilding].m_position).sqrMagnitude; name = BuildingHelper.GetBuildingName(vehicles[vehicleId].m_targetBuilding); if (String.IsNullOrEmpty(name)) { name = buildings[vehicles[vehicleId].m_targetBuilding].Info.name; } info.Add("Target", vehicles[vehicleId].m_targetBuilding, name, distance); } } catch { info.Add("Error", "TargetBuilding"); } try { string flags = vehicles[vehicleId].m_flags.ToString(); if (flags.IndexOfAny(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }) >= 0) { foreach (Vehicle.Flags flag in Enum.GetValues(typeof(Vehicle.Flags))) { if ((vehicles[vehicleId].m_flags & flag) == flag) { flags += ", " + flag.ToString(); } } } info.Add("Flags", flags); } catch { info.Add("Error", "Flags"); } try { info.Add("Enabled", vehicles[vehicleId].Info.enabled); info.Add("Active", vehicles[vehicleId].Info.isActiveAndEnabled); info.Add("AIEnabled", vehicles[vehicleId].Info.m_vehicleAI.enabled); info.Add("AIActive", vehicles[vehicleId].Info.m_vehicleAI.isActiveAndEnabled); } catch { info.Add("Error", "Info"); } try { if (vehicles[vehicleId].Info.m_vehicleAI.GetProgressStatus(vehicleId, ref vehicles[vehicleId], out prgCur, out prgMax)) { info.Add("PrgCur", prgCur); info.Add("PrgMax", prgMax); } } catch { info.Add("Error", "Progress"); } try { vehicles[vehicleId].Info.m_vehicleAI.GetBufferStatus(vehicleId, ref vehicles[vehicleId], out localeKey, out bufCur, out bufMax); if (!String.IsNullOrEmpty(localeKey)) { info.Add("BufLocKey", localeKey); } info.Add("BufCur", bufCur); info.Add("BufMax", bufMax); } catch { info.Add("Error", "Buffer"); } info.Add("TransferSize", vehicles[vehicleId].m_transferSize); try { if (vehicles[vehicleId].Info.m_vehicleAI is HearseAI) { info.Add("Capacity", ((HearseAI)vehicles[vehicleId].Info.m_vehicleAI).m_corpseCapacity); } else if (vehicles[vehicleId].Info.m_vehicleAI is GarbageTruckAI) { info.Add("Capacity", ((GarbageTruckAI)vehicles[vehicleId].Info.m_vehicleAI).m_cargoCapacity); } else if (vehicles[vehicleId].Info.m_vehicleAI is AmbulanceAI) { info.Add("Capacity", ((AmbulanceAI)vehicles[vehicleId].Info.m_vehicleAI).m_patientCapacity); } } catch { info.Add("Error", "Capacity"); } try { string status = vehicles[vehicleId].Info.m_vehicleAI.GetLocalizedStatus(vehicleId, ref vehicles[vehicleId], out instanceId); if (!String.IsNullOrEmpty(status)) { info.Add("Status", status); } } catch { info.Add("Error", "Status"); } if (verbose) { try { if (vehicles[vehicleId].m_leadingVehicle == 0 && vehicles[vehicleId].m_trailingVehicle != 0) { ushort trailerCount = 0; ushort trailerId = vehicles[vehicleId].m_trailingVehicle; while (trailerId != 0 && trailerCount < ushort.MaxValue) { trailerId = vehicles[trailerId].m_trailingVehicle; trailerCount++; } info.Add("TrailerCount", trailerCount); } } catch { info.Add("Error", "Trailing"); } info.Add("WaitCounter", vehicles[vehicleId].m_waitCounter); try { info.Add("Position", vehicles[vehicleId].GetLastFramePosition()); } catch { info.Add("Error", "Position"); } if (Global.Vehicles != null) { try { if (Global.Vehicles.StuckVehicles != null) { StuckVehicleInfo stuckVehicle; if (Global.Vehicles.StuckVehicles.TryGetValue(vehicleId, out stuckVehicle)) { stuckVehicle.AddDebugInfoData(info); } } } catch { info.Add("Error", "Stuck"); } } } try { info.Add("AI", vehicles[vehicleId].Info.m_vehicleAI.GetType().AssemblyQualifiedName); } catch { info.Add("Error", "AI"); } return(info); }
/// <summary> /// Creates the service vehicle. /// </summary> /// <param name="serviceBuildingId">The service building identifier.</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> /// The vehicle information. /// </returns> /// <exception cref="System.NotImplementedException">Target citizen not implemented yet.</exception> /// <exception cref="System.InvalidOperationException">Hospital assigments reuires target citizen.</exception> /// <exception cref="System.ArgumentException">Unhandled material.</exception> /// <exception cref="ArgumentException">Unhandled material.</exception> public static VehicleInfo CreateServiceVehicle(ushort serviceBuildingId, TransferManager.TransferReason material, ushort targetBuildingId, uint targetCitizenId, out ushort vehicleId) { if (targetCitizenId != 0) { throw new NotImplementedException("Target citizen not implemented yet"); } vehicleId = 0; VehicleManager manager = Singleton <VehicleManager> .instance; ColossalFramework.Math.Randomizer randomizer = Singleton <SimulationManager> .instance.m_randomizer; Building building = BuildingHelper.GetBuilding(serviceBuildingId); if (building.Info.m_buildingAI is HospitalAI && targetCitizenId == 0) { throw new InvalidOperationException("Hospital assigments reuires target citizen"); } VehicleInfo info = manager.GetRandomVehicleInfo(ref randomizer, building.Info.m_class.m_service, building.Info.m_class.m_subService, building.Info.m_class.m_level); if (info == null) { Log.Debug(typeof(VehicleKeeper), "CreateVehicle", "GetRandomVehicleInfo", "no vehicle"); return(null); } bool transferToSource; bool transferToTarget; switch (material) { case TransferManager.TransferReason.Dead: transferToSource = true; transferToTarget = false; break; case TransferManager.TransferReason.DeadMove: transferToSource = false; transferToTarget = true; break; case TransferManager.TransferReason.Garbage: transferToSource = true; transferToTarget = false; break; case TransferManager.TransferReason.GarbageMove: transferToSource = false; transferToTarget = true; break; default: throw new ArgumentException("Unhandled material: " + material.ToString()); } if (!manager.CreateVehicle(out vehicleId, ref randomizer, info, building.m_position, material, transferToSource, transferToTarget)) { Log.Debug(typeof(VehicleKeeper), "CreateVehicle", "CreateVehicle", "not created"); return(null); } info.m_vehicleAI.SetSource(vehicleId, ref manager.m_vehicles.m_buffer[vehicleId], serviceBuildingId); if (targetBuildingId != 0 && !AssignTarget(vehicleId, ref manager.m_vehicles.m_buffer[vehicleId], material, targetBuildingId, 0)) { Log.Debug(typeof(VehicleKeeper), "CreateVehicle", "SetTarget", "target not set"); return(null); } return(info); }
/// <summary> /// Notes a problem. /// </summary> /// <param name="problem">The problem.</param> /// <param name="serviceBuildingId">The service building identifier.</param> /// <param name="targetBuildingId">The target building identifier.</param> public void Add(ServiceProblem problem, ushort serviceBuildingId, ushort targetBuildingId) { if (this.broken) { return; } try { if (Log.LogALot) { Log.Debug( this, "Add", problem, serviceBuildingId, targetBuildingId, BuildingHelper.GetBuildingName(serviceBuildingId), BuildingHelper.GetDistrictName(serviceBuildingId), BuildingHelper.GetBuildingName(targetBuildingId), BuildingHelper.GetDistrictName(targetBuildingId)); } uint key = MakeBuildingKey(serviceBuildingId, targetBuildingId); byte weight = this.GetServiceProblemWeight(problem); uint newValue; uint oldValue; BuildingProblem newProblem; BuildingProblem oldProblem; bool gotSize = this.ProblemSizes.TryGetValue(key, out oldValue); bool gotProblem = this.TargetBuildingProblems.TryGetValue(targetBuildingId, out oldProblem); if (gotSize) { newValue = oldValue + weight; } else { oldValue = 0; newValue = weight; } if (gotProblem) { newProblem = new BuildingProblem(oldProblem, weight, !gotSize); } else { newProblem = new BuildingProblem(weight); } this.ProblemSizes[key] = newValue; this.TargetBuildingProblems[targetBuildingId] = newProblem; //if (Log.LogALot) //{ // DevLog("Add", // Log.Data("ServiceBuilding", serviceBuildingId, BuildingHelper.GetBuildingName(serviceBuildingId)), // Log.Data("TargetBuilding", targetBuildingId, BuildingHelper.GetBuildingName(targetBuildingId)), // Log.Data("Actions", (gotSize ? "Set" : "Add"), (gotProblem ? "Set" : "Add"), weight), // "Problem", problem, // "Key", key, // "OldValue", oldValue, // "OldCount", oldProblem.Count, // "OldSize", oldProblem.Size, // "NewValue", newValue, // "NewCount", newProblem.Count, // "NewSize", newProblem.Size); //} } catch (Exception ex) { this.broken = true; Log.Error(this, "Add", ex); } }
/// <summary> /// Logs the debug lists. /// </summary> /// <param name="initializing">if set to <c>true</c> level is loading.</param> /// <param name="deInitializing">if set to <c>true</c> level is unloading.</param> private static void LogDebugLists(bool initializing, bool deInitializing) { try { bool flush = false; if (initializing) { if (Log.LogDebugLists) { Log.Debug(typeof(Global), "LogDebugLists", "Initializing"); } } else if (deInitializing) { if (Log.LogDebugLists) { Log.Debug(typeof(Global), "LogDebugLists", "DeInitializing"); } } else if (CurrentFrame == 0) { if (Log.LogDebugLists) { Log.Debug(typeof(Global), "LogDebugLists", "Started"); Detours.LogInfo(); TransferManagerHelper.LogInfo(); VehicleHelper.DebugListLog(); BuildingHelper.DebugListLog(); TransferManagerHelper.DebugListLog(); flush = true; } } else if (CurrentFrame > 0) { if (Log.LogDebugLists) { Log.Debug(typeof(Global), "LogDebugLists", "Running"); if (Global.Buildings != null) { Global.Buildings.DebugListLogBuildings(); } if (Global.Vehicles != null) { Global.Vehicles.DebugListLogVehicles(); } TransferManagerHelper.DebugListLog(); flush = true; } if (Global.ServiceProblems != null) { Global.ServiceProblems.DebugListLogServiceProblems(); flush = true; } } if (flush) { Log.FlushBuffer(); } } catch (Exception ex) { Log.Error(typeof(Global), "LogDebugLists", ex); } }