/// <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> /// 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> /// 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> /// 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); } }