|
6 | 6 | using TrafficManager.State; |
7 | 7 | using TrafficManager.Geometry; |
8 | 8 | using CSUtil.Commons; |
| 9 | +using TrafficManager.Custom.AI; |
9 | 10 |
|
10 | 11 | namespace TrafficManager.Manager { |
11 | 12 | public class UtilityManager : AbstractCustomManager { |
@@ -94,43 +95,77 @@ private void PrintAllDebugInfo() { |
94 | 95 | } |
95 | 96 |
|
96 | 97 | private void ResetStuckEntities() { |
97 | | - Log._Debug($"UtilityManager.RemoveStuckEntities() called."); |
| 98 | + Log.Info($"UtilityManager.RemoveStuckEntities() called."); |
98 | 99 |
|
99 | | - Log._Debug($"UtilityManager.RemoveStuckEntities(): Pausing simulation."); |
| 100 | + Log.Info($"UtilityManager.RemoveStuckEntities(): Pausing simulation."); |
100 | 101 | Singleton<SimulationManager>.instance.ForcedSimulationPaused = true; |
101 | 102 |
|
102 | | - Log._Debug($"UtilityManager.RemoveStuckEntities(): Waiting for all paths."); |
| 103 | + Log.Info($"UtilityManager.RemoveStuckEntities(): Waiting for all paths."); |
103 | 104 | Singleton<PathManager>.instance.WaitForAllPaths(); |
104 | 105 |
|
105 | | - Log._Debug($"UtilityManager.RemoveStuckEntities(): Resetting citizen instances that are waiting for a path."); |
| 106 | + Log.Info($"UtilityManager.RemoveStuckEntities(): Resetting citizen instances that are waiting for a path."); |
106 | 107 | for (uint citizenInstanceId = 1; citizenInstanceId < CitizenManager.MAX_INSTANCE_COUNT; ++citizenInstanceId) { |
107 | 108 | //Log._Debug($"UtilityManager.RemoveStuckEntities(): Processing instance {citizenInstanceId}."); |
108 | | - CitizenInstance citizenData = Singleton<CitizenManager>.instance.m_instances.m_buffer[citizenInstanceId]; |
109 | | - if ((citizenData.m_flags & CitizenInstance.Flags.WaitingPath) != CitizenInstance.Flags.None) { |
| 109 | + if ((Singleton<CitizenManager>.instance.m_instances.m_buffer[citizenInstanceId].m_flags & CitizenInstance.Flags.WaitingPath) != CitizenInstance.Flags.None) { |
110 | 110 | CitizenAI ai = Singleton<CitizenManager>.instance.m_instances.m_buffer[citizenInstanceId].Info.m_citizenAI; |
111 | 111 |
|
112 | | - if (citizenData.m_path != 0u) { |
113 | | - Singleton<PathManager>.instance.ReleasePath(citizenData.m_path); |
114 | | - Singleton<CitizenManager>.instance.m_instances.m_buffer[citizenInstanceId].m_path = 0u; |
| 112 | + if (Singleton<CitizenManager>.instance.m_instances.m_buffer[citizenInstanceId].m_path != 0u) { |
| 113 | +#if DEBUG |
| 114 | + if (GlobalConfig.Instance.DebugSwitches[3]) { |
| 115 | + Log._Debug($"Would reset citizen instance {citizenInstanceId} (waiting for path)"); |
| 116 | + } else { |
| 117 | +#endif |
| 118 | + Singleton<PathManager>.instance.ReleasePath(Singleton<CitizenManager>.instance.m_instances.m_buffer[citizenInstanceId].m_path); |
| 119 | + Singleton<CitizenManager>.instance.m_instances.m_buffer[citizenInstanceId].m_path = 0u; |
| 120 | +#if DEBUG |
| 121 | + } |
| 122 | +#endif |
115 | 123 | } |
116 | 124 | Singleton<CitizenManager>.instance.m_instances.m_buffer[citizenInstanceId].m_flags &= ~(CitizenInstance.Flags.WaitingTransport | CitizenInstance.Flags.EnteringVehicle | CitizenInstance.Flags.BoredOfWaiting | CitizenInstance.Flags.WaitingTaxi | CitizenInstance.Flags.WaitingPath); |
117 | 125 | } |
118 | 126 | } |
119 | 127 |
|
120 | | - Log._Debug($"UtilityManager.RemoveStuckEntities(): Resetting vehicles that are waiting for a path."); |
| 128 | + Log.Info($"UtilityManager.RemoveStuckEntities(): Resetting vehicles that are waiting for a path."); |
121 | 129 | for (uint vehicleId = 1; vehicleId < VehicleManager.MAX_VEHICLE_COUNT; ++vehicleId) { |
122 | 130 | //Log._Debug($"UtilityManager.RemoveStuckEntities(): Processing vehicle {vehicleId}."); |
123 | | - Vehicle vehicleData = Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId]; |
124 | | - if ((vehicleData.m_flags & Vehicle.Flags.WaitingPath) != 0) { |
125 | | - if (vehicleData.m_path != 0u) { |
126 | | - Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path); |
127 | | - Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId].m_path = 0u; |
| 131 | + if ((Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.WaitingPath) != 0) { |
| 132 | + if (Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId].m_path != 0u) { |
| 133 | +#if DEBUG |
| 134 | + if (GlobalConfig.Instance.DebugSwitches[3]) { |
| 135 | + Log._Debug($"Would reset vehicle {vehicleId} (waiting for path)"); |
| 136 | + } else { |
| 137 | +#endif |
| 138 | + Singleton<PathManager>.instance.ReleasePath(Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId].m_path); |
| 139 | + Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId].m_path = 0u; |
| 140 | +#if DEBUG |
| 141 | + } |
| 142 | +#endif |
128 | 143 | } |
129 | 144 | Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId].m_flags &= ~Vehicle.Flags.WaitingPath; |
130 | 145 | } |
131 | 146 | } |
132 | 147 |
|
133 | | - Log._Debug($"UtilityManager.RemoveStuckEntities(): Unpausing simulation."); |
| 148 | + Log.Info($"UtilityManager.RemoveStuckEntities(): Resetting vehicles that are parking and where no parked vehicle is assigned to the driver."); |
| 149 | + for (uint vehicleId = 1; vehicleId < VehicleManager.MAX_VEHICLE_COUNT; ++vehicleId) { |
| 150 | + //Log._Debug($"UtilityManager.RemoveStuckEntities(): Processing vehicle {vehicleId}."); |
| 151 | + if ((Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Parking) != 0) { |
| 152 | + ushort driverInstanceId = CustomPassengerCarAI.GetDriverInstance((ushort)vehicleId, ref Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId]); |
| 153 | + uint citizen = Singleton<CitizenManager>.instance.m_instances.m_buffer[(int)driverInstanceId].m_citizen; |
| 154 | + if (citizen != 0u && Singleton<CitizenManager>.instance.m_citizens.m_buffer[(int)((UIntPtr)citizen)].m_parkedVehicle == 0) { |
| 155 | +#if DEBUG |
| 156 | + if (GlobalConfig.Instance.DebugSwitches[3]) { |
| 157 | + Log._Debug($"Would reset vehicle {vehicleId} (parking without parked vehicle)"); |
| 158 | + } else { |
| 159 | +#endif |
| 160 | + Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId].m_flags &= ~Vehicle.Flags.Parking; |
| 161 | +#if DEBUG |
| 162 | + } |
| 163 | +#endif |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + Log.Info($"UtilityManager.RemoveStuckEntities(): Unpausing simulation."); |
134 | 169 | Singleton<SimulationManager>.instance.ForcedSimulationPaused = false; |
135 | 170 | } |
136 | 171 | } |
|
0 commit comments