diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index ff78782..6defdd5 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -2758,7 +2758,7 @@ MonoBehaviour: mainPlanContainer: {fileID: 557435656} emergencyPlanContainer: {fileID: 632826360} reconfigurationToggle: {fileID: 441283505} - defaultPath: Assets/Data/Tablica3.csv + defaultPath: Assets/Data/Tablica1.csv --- !u!1 &1347097428 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/ParkingManager.cs b/Assets/Scripts/ParkingManager.cs index 77342fd..8eb24d9 100644 --- a/Assets/Scripts/ParkingManager.cs +++ b/Assets/Scripts/ParkingManager.cs @@ -41,10 +41,10 @@ namespace Parking {new List(), new List(), new List(), new List()}; private bool _emergencyActivated; - private bool _reconfigurationActive = true; private int _initialConfigurationSpotCount; private int[,] _initialSolution; + private bool _reconfigurationActive = true; private int[] _rejectedDrivers = {0, 0, 0, 0}; private List _spotPrefabs; @@ -149,7 +149,7 @@ namespace Parking if (_emergencyActivated) return; - if(_reconfigurationActive) + if (_reconfigurationActive) ReconfigureSpots(); foreach (Driver driver in DataImporter.Drivers) { @@ -317,7 +317,7 @@ namespace Parking Debug.Log($"Needed spots = {neededSpots[0]} {neededSpots[1]} {neededSpots[2]} {neededSpots[3]}"); Debug.Log("Attempting reconfiguration..."); - List spotlessCars = new List(); + List spotlessCars = new(); // Filter drivers by assigning free space foreach (Driver nextCar in nextCars) @@ -363,7 +363,8 @@ namespace Parking newPosition.y, newPosition.z); } else { - float newX = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, true) - 2.25f / 2.0f; + float newX = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, true) - + 2.25f / 2.0f; if (spot.Lane == 0) { float xRelativeToRight = newX - Width / 2.0f - 2.25f / 2.0f; xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f; @@ -378,13 +379,14 @@ namespace Parking newPosition = new Vector3(newX, newPosition.y, newPosition.z); } - }else if (spot.Size < newSize) { + } + else if (spot.Size < newSize) { float spotBorder; float thisSizeOffset; if (spot.Perpendicular) - thisSizeOffset = _spotHeights[(int) spot.Size] / 2.0f; + thisSizeOffset = _spotHeights[size] / 2.0f; else - thisSizeOffset = 2.25f; + thisSizeOffset = 2.25f / 2.0f; if (!spot.AlignToTop) spotBorder = position.y + thisSizeOffset; else @@ -393,12 +395,13 @@ namespace Parking float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize, !spot.AlignToTop); if (Math.Abs(spotBorder - nextBorder) < 5.5f) - continue; // Try parallel + continue; // Try parallel (?) } else { float nextBorderLeft = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, !spot.AlignToTop); - float nextBorderRight = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, + float nextBorderRight = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, + newSize, !spot.AlignToTop); if (nextBorderRight - nextBorderLeft < _spotHeights[(int) newSize]) { // Try perpendicular @@ -410,9 +413,8 @@ namespace Parking float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize, !spot.AlignToTop); - if (Math.Abs(nextBorder - newBottomBorder) < 5.5f) { + if (Math.Abs(nextBorder - newBottomBorder) < 5.5f) continue; - } } else { float newBottomBorder = bottomBorder; @@ -420,32 +422,27 @@ namespace Parking float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize, !spot.AlignToTop); - if (Math.Abs(newTopBorder - nextBorder) < 5.5f) { + if (Math.Abs(newTopBorder - nextBorder) < 5.5f) continue; - } } newPosition.y = bottomBorder + _spotHeights[(int) newSize] / 2.0f; float newX = nextBorderRight; if (spot.Lane == 0) { - // float xRelativeToRight = newX - Width / 2.0f; - // xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f; - // newX = xRelativeToRight + Width / 2.0f; float xRelativeToRight = -(newX - Width / 2.0f); - // xRelativeToRight -= (xRelativeToRight - 2.25f / 2.0f) % 2.25f; xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f; xRelativeToRight += 2.25f; xRelativeToRight = Math.Max(xRelativeToRight, 2.25f / 2.0f); - newX = (-xRelativeToRight + Width / 2.0f); + newX = -xRelativeToRight + Width / 2.0f; } else { float xRelativeToLeft = newX + Width / 2.0f; xRelativeToLeft -= (xRelativeToLeft + 2.25f / 2.0f) % 2.25f; newX = xRelativeToLeft - Width / 2.0f; } - - - if(spot.Lane == 0 && Width / 2.0f - newX < 5.5f + 0.5f + 2.25f) + + + if (spot.Lane == 0 && Width / 2.0f - newX < 5.5f + 0.5f + 2.25f) continue; @@ -456,7 +453,7 @@ namespace Parking } } } - + Destroy(spot.GameObject); spot.Size = (Size) size; spot.Reserved = false; @@ -465,6 +462,7 @@ namespace Parking spot.LastReconfiguration = _currentTime; return true; } + return false; } @@ -500,7 +498,7 @@ namespace Parking private float GetNextBorderHorizontal(Vector3 position, int lane, bool perpendicular, Size size, bool right) { - List allBorders = new List(); + List allBorders = new(); List targetLane = _spotMap[lane]; foreach (Spot spot1 in targetLane) { if (spot1.GameObject.transform.position == position) @@ -511,7 +509,7 @@ namespace Parking sizeOffset = 2.25f / 2.0f; else sizeOffset = _spotHeights[(int) spot1.Size] / 2.0f; - if(right) + if (right) allBorders.Add(spotPosition.x - sizeOffset); else allBorders.Add(spotPosition.x + sizeOffset); @@ -550,7 +548,7 @@ namespace Parking private List GetNextCars(int steps) { - List nextCars = new List(); + List nextCars = new(); TimeSpan updatedTime = _currentTime + TimeSpan.FromMinutes(stepTime * steps); foreach (Driver driver in DataImporter.Drivers) if (updatedTime <= driver.Times[1].TimeOfDay && @@ -575,9 +573,7 @@ namespace Parking if (spot.Size != Size.D) maxP2 = Math.Max(maxP2, spot.Perpendicular ? _spotHeights[(int) spot.Size] : 2.25f); - // float maxP3 = spotMap[2].Count == 0 ? 0 : _spotHeights[(int) spotMap[2].Max().Size]; - // float maxP2 = spotMap[1].Count == 0 ? 0 : _spotHeights[(int) spotMap[1].Max().Size]; - List prefabs = new List {spotPrefabA, spotPrefabB, spotPrefabC, spotPrefabD}; + List prefabs = new() {spotPrefabA, spotPrefabB, spotPrefabC, spotPrefabD}; for (int i = 0; i < 4; i++) { float currentY; @@ -607,12 +603,10 @@ namespace Parking bool flipped = false; for (int j = 0; j < spotMap[i].Count; j++) { - // if (!spotMap[i][j].Perpendicular) - // currentX -= spotSizes[(int) spotMap[i][j].Size] / 2.0f; - // else if (spotMap[i][j].Perpendicular) - // currentX -= 2.25f / 2.0f; currentX += (i != 0 ? 1 : -1) * - (spotMap[i][j].Perpendicular ? 2.25f / 2.0f : spotSizes[(int) spotMap[i][j].Size] / 2.0f); + (spotMap[i][j].Perpendicular + ? 2.25f / 2.0f + : spotSizes[(int) spotMap[i][j].Size] / 2.0f); spotMap[i][j].Flipped = flipped; bool alignTop = i % 2 != 0; @@ -650,7 +644,9 @@ namespace Parking spotMap[i][j].Lane = i; currentX += (i != 0 ? 1 : -1) * - (spotMap[i][j].Perpendicular ? 2.25f / 2.0f : spotSizes[(int) spotMap[i][j].Size] / 2.0f); + (spotMap[i][j].Perpendicular + ? 2.25f / 2.0f + : spotSizes[(int) spotMap[i][j].Size] / 2.0f); flipped = !flipped; }