/// <summary> /// De-spawns the vehicle. /// </summary> private static void DeSpawnVehicle(ushort vehicleId) { if (Global.Buildings != null) { foreach (BuildingKeeper.StandardServiceBuildings buildings in Global.Buildings.StandardServices) { foreach (ServiceBuildingInfo serviceBuilding in buildings.ServiceBuildings.Values) { ServiceVehicleInfo serviceVehicle; if (serviceBuilding.Vehicles.TryGetValue(vehicleId, out serviceVehicle) && serviceVehicle.Target != 0) { TargetBuildingInfo targetBuilding; if (buildings.TargetBuildings.TryGetValue(serviceVehicle.Target, out targetBuilding)) { targetBuilding.Handled = false; } } serviceBuilding.Vehicles.Remove(vehicleId); } } } VehicleHelper.DeSpawn(vehicleId); }
private void DeSpawnTrailer() { ushort count; ushort prevId; ushort nextId; Vehicle[] vehicles = Singleton <VehicleManager> .instance.m_vehicles.m_buffer; LinkedList <ushort> ids = new LinkedList <ushort>(new ushort[] { this.VehicleId }); count = 0; prevId = this.VehicleId; nextId = vehicles[prevId].m_leadingVehicle; while (nextId != 0) { if (vehicles[nextId].m_trailingVehicle != prevId) { break; } ids.AddFirst(nextId); if (count >= ushort.MaxValue) { throw new Exception("Loop counter too high"); } count++; prevId = nextId; nextId = vehicles[prevId].m_leadingVehicle; } count = 0; prevId = this.VehicleId; nextId = vehicles[prevId].m_trailingVehicle; while (nextId != 0) { if (vehicles[nextId].m_leadingVehicle != prevId) { break; } ids.AddLast(nextId); if (count >= ushort.MaxValue) { throw new Exception("Loop counter too high"); } count++; prevId = nextId; nextId = vehicles[prevId].m_trailingVehicle; } count = 0; foreach (ushort id in ids) { if (count == 0 && vehicles[id].m_leadingVehicle == 0) { DeSpawnVehicle(id); } else { VehicleHelper.DeSpawn(id); } count++; } }