Compare commits
No commits in common. "d4a4bcbebec3db606dfd6178e727efbab893aa94" and "932c7f9c17ff4cabe0b09db2bcf0697b1712dfd3" have entirely different histories.
d4a4bcbebe
...
932c7f9c17
@ -62,7 +62,6 @@ namespace Parking
|
||||
public bool Reserved = false;
|
||||
public int ReservedPriority = 0;
|
||||
public Size Size;
|
||||
public Driver OccupyingDriver;
|
||||
|
||||
public Spot(Size size, bool flipped)
|
||||
{
|
||||
|
@ -141,7 +141,7 @@ namespace Parking
|
||||
driver.Reserved = false;
|
||||
}
|
||||
|
||||
float rightTime = 12.0f;//(float)_currentTime.TotalHours;
|
||||
float rightTime = 10.0f;//(float)_currentTime.TotalHours;
|
||||
float leftTime = 16.0f;//(float)(_currentTime + TimeSpan.FromHours(hours)).TotalHours;
|
||||
|
||||
TimeSpan maxArrivalTime = _currentTime + TimeSpan.FromHours(hours);
|
||||
@ -152,31 +152,24 @@ namespace Parking
|
||||
}
|
||||
}
|
||||
// nextDrivers.Sort(((a, b) => Comparer<TimeSpan>.Default.Compare(a.PlannedDeparture, b.PlannedDeparture)));
|
||||
nextDrivers.Sort(((a, b) => Comparer<int>.Default.Compare(a.Priority, b.Priority)));
|
||||
//nextDrivers.Sort(((a, b) => Comparer<TimeSpan>.Default.Compare(a.RealDeparture, b.RealDeparture)));
|
||||
//nextDrivers.Sort(((a, b) => Comparer<TimeSpan>.Default.Compare(a.PlannedArrival, b.PlannedArrival)));
|
||||
nextDrivers.Sort(((a, b) => Comparer<TimeSpan>.Default.Compare(a.PlannedArrival, b.PlannedArrival)));
|
||||
|
||||
List<Spot> availableSpots = new List<Spot>();
|
||||
|
||||
foreach (List<Spot> list in _spotMap)
|
||||
foreach (Spot spot in list)
|
||||
// if (!spot.Reserved && spot.Free)
|
||||
if (!spot.Reserved && spot.Free)
|
||||
availableSpots.Add(spot);
|
||||
|
||||
// availableSpots.Reverse();
|
||||
|
||||
// leftTime = (float)nextDrivers.Max(d => d.PlannedDeparture).TotalHours;
|
||||
|
||||
Driver FindOccupyingDriver(Spot spot)
|
||||
{
|
||||
return spot.OccupyingDriver;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nextDrivers.Count; i++) {
|
||||
Driver driver = nextDrivers[i];
|
||||
|
||||
float driverTime = (float)driver.PlannedDeparture.TotalHours;
|
||||
//float driverTime = (float)driver.RealDeparture.TotalHours;
|
||||
// float driverTime = (float)driver.PlannedDeparture.TotalHours;
|
||||
float driverTime = (float)driver.RealDeparture.TotalHours;
|
||||
float timeProgress = (driverTime - rightTime) / (leftTime - rightTime);
|
||||
float xPosition = Width / 2.0f - (Width * timeProgress);
|
||||
availableSpots.Sort(((a, b) => Comparer<float>.Default.Compare(Mathf.Abs(xPosition - a.Position.x), Mathf.Abs(xPosition - b.Position.x))));
|
||||
@ -184,30 +177,7 @@ namespace Parking
|
||||
bool useBottomLane = true;
|
||||
for (int j = 0; j < availableSpots.Count; j++) {
|
||||
Spot spot = availableSpots[j];
|
||||
if (driver.Size == spot.Size && (spot.Lane != 0)) {
|
||||
TimeSpan leaveTime = spot.Free ? TimeSpan.Zero : FindOccupyingDriver(spot).PlannedDeparture;
|
||||
if (((!spot.Reserved && spot.Free)
|
||||
|| (!spot.Free &&
|
||||
leaveTime <
|
||||
driver.PlannedArrival))) {
|
||||
spot.Reserved = true;
|
||||
driver.Reserved = true;
|
||||
driver.ReservedSpot = spot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (Mathf.Abs(spot.Position.x - xPosition) > 20.0f) {
|
||||
// if (useBottomLane)
|
||||
// break;
|
||||
// // useBottomLane = true;
|
||||
// // j = -1;
|
||||
// }
|
||||
if(!driver.Reserved)
|
||||
for (int j = 0; j < availableSpots.Count; j++) {
|
||||
Spot spot = availableSpots[j];
|
||||
if (driver.Size == spot.Size && !spot.Reserved) {
|
||||
if (driver.Size == spot.Size && !spot.Reserved && (spot.Lane != 0 || useBottomLane)) {
|
||||
spot.Reserved = true;
|
||||
driver.Reserved = true;
|
||||
driver.ReservedSpot = spot;
|
||||
@ -367,20 +337,20 @@ namespace Parking
|
||||
private bool FindReservedSpot(Driver driver, out Spot spot)
|
||||
{
|
||||
if (driver.Reserved) {
|
||||
if(driver.ReservedSpot.GameObject == null || !driver.ReservedSpot.Free)
|
||||
Debug.Log("Spot not viable anymore");
|
||||
if(!driver.ReservedSpot.Free)
|
||||
Debug.Log("Spot should be free");
|
||||
else {
|
||||
spot = driver.ReservedSpot;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// foreach (List<Spot> list in _spotMap)
|
||||
// foreach (Spot spot1 in list)
|
||||
// if (spot1.Reserved && spot1.ReservedPriority == driver.Priority && driver.Size == spot1.Size) {
|
||||
// spot = spot1;
|
||||
// return true;
|
||||
// }
|
||||
foreach (List<Spot> list in _spotMap)
|
||||
foreach (Spot spot1 in list)
|
||||
if (spot1.Reserved && spot1.ReservedPriority == driver.Priority && driver.Size == spot1.Size) {
|
||||
spot = spot1;
|
||||
return true;
|
||||
}
|
||||
|
||||
spot = new Spot();
|
||||
|
||||
@ -429,7 +399,6 @@ namespace Parking
|
||||
}
|
||||
spot.Free = false;
|
||||
spot.Reserved = false;
|
||||
spot.OccupyingDriver = driver;
|
||||
driver.Spot = spot;
|
||||
driver.Parked = true;
|
||||
driver.GameObject = Instantiate(carPrefab);
|
||||
@ -584,14 +553,13 @@ namespace Parking
|
||||
}
|
||||
|
||||
// Try regeneration before returning false
|
||||
if (RegenerateSpots(newSize))
|
||||
return true;
|
||||
return RegenerateSpots(newSize);
|
||||
}
|
||||
|
||||
foreach (List<Spot> currentLaneSpots in _spotMap)
|
||||
for (int i = 0; i < currentLaneSpots.Count; i++) {
|
||||
Spot spot = currentLaneSpots[i];
|
||||
if (!spot.Free || spot.Size == Size.D || spot.Reserved)
|
||||
if (!(spot.Free && spot.Size != Size.D)) // && !spot.Reserved))
|
||||
continue;
|
||||
if (GetSpotCountOfSize(Size.A) <= 2 && spot.Size == Size.A)
|
||||
continue;
|
||||
@ -735,8 +703,7 @@ namespace Parking
|
||||
}
|
||||
|
||||
|
||||
float distToRightWall = Width / 2.0f - newX + SpotHeights[(int)newSize] / 2.0f;
|
||||
if (spot.Lane == 0 && distToRightWall < 5.5f && (distToRightWall != 0)) {
|
||||
if (spot.Lane == 0 && Width / 2.0f - newX < 5.5f + 0.5f + 2.25f) {
|
||||
// Try to remove one spot next
|
||||
continue;
|
||||
}
|
||||
@ -789,7 +756,7 @@ namespace Parking
|
||||
Vector3 newPosition = Vector3.zero;
|
||||
|
||||
float lastRightBorder = -Width / 2.0f + 5.5f;
|
||||
float spaceNeeded = SpotHeights[(int)size] + 1.0f;
|
||||
float spaceNeeded = SpotHeights[(int)size];
|
||||
|
||||
|
||||
|
||||
@ -825,8 +792,7 @@ namespace Parking
|
||||
|
||||
if (leftBorder - lastRightBorder >= spaceNeeded) {
|
||||
Spot newSpot = new Spot(size, false);
|
||||
//newPosition.x = (lastRightBorder + SpotHeights[(int)size] / 2.0f);
|
||||
newPosition.x = (lastRightBorder + 0.5f + SpotHeights[(int)size] / 2.0f);
|
||||
newPosition.x = (lastRightBorder + SpotHeights[(int)size] / 2.0f);
|
||||
newPosition.y = (-Height / 2.0f) + 2.25f / 2.0f;
|
||||
newSpot.Perpendicular = false;
|
||||
newSpot.GameObject = Instantiate(_spotPrefabs[(int)size],
|
||||
@ -839,35 +805,6 @@ namespace Parking
|
||||
lastRightBorder = _spotMap[0][i].RightBorder;
|
||||
}
|
||||
|
||||
// return false;
|
||||
float lastLeftBorder = Width / 2.0f;
|
||||
spaceNeeded = 2.25f;
|
||||
// Try for perpendicular
|
||||
for (int i = 0; i < _spotMap[0].Count; i++) {
|
||||
|
||||
float rightBorder = _spotMap[0][i].RightBorder;
|
||||
if (lastLeftBorder - rightBorder >= spaceNeeded) {
|
||||
newPosition.x = (lastLeftBorder - (2.25f / 2.0f));
|
||||
if(newPosition.x < Width / 2.0f - 2.25f && newPosition.x > Width / 2.0f - 5.5f - 2.25f)
|
||||
continue;
|
||||
newPosition.y = (-Height / 2.0f) + SpotHeights[(int)(size)] / 2.0f;
|
||||
float nextBorder = GetNextBorderVectical(newPosition, 0, true, size, true);
|
||||
float spotBorder = -Height / 2.0f + SpotHeights[(int) size];
|
||||
if(nextBorder - spotBorder < 5.5f)
|
||||
continue;
|
||||
Spot newSpot = new Spot(size, false);
|
||||
//newPosition.x = (lastRightBorder + SpotHeights[(int)size] / 2.0f);
|
||||
newSpot.Perpendicular = true;
|
||||
newSpot.GameObject = Instantiate(_spotPrefabs[(int)size],
|
||||
// TODO: Account for order
|
||||
newPosition, Quaternion.Euler(0, 0, 0), mainPlanContainer);
|
||||
_spotMap[0].Add(newSpot);
|
||||
_spotMap[0].Sort((a, b) => Comparer<float>.Default.Compare(b.Position.x, a.Position.x));
|
||||
return true;
|
||||
}
|
||||
lastLeftBorder = _spotMap[0][i].LeftBorder;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
// newPosition.y = bottomBorder + SpotHeights[(int) newSize] / 2.0f;
|
||||
@ -924,8 +861,8 @@ namespace Parking
|
||||
private float GetNextBorderVectical(Vector3 position, int lane, bool perpendicular, Size size, bool up)
|
||||
{
|
||||
|
||||
float minX = position.x - (perpendicular ? 2.25f : SpotHeights[(int) size]) - 2.25f/2.0f;
|
||||
float maxX = position.x + (perpendicular ? 2.25f : SpotHeights[(int) size]) + 2.25f/2.0f;
|
||||
float minX = position.x - (perpendicular ? 2.25f : SpotHeights[(int) size]);
|
||||
float maxX = position.x + (perpendicular ? 2.25f : SpotHeights[(int) size]);
|
||||
|
||||
List<float> allBorders = new();
|
||||
List<Spot> targetLane = up ? _spotMap[lane + 1] : _spotMap[lane - 1];
|
||||
|
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@
|
||||
"dependencies": {
|
||||
"com.unity.collab-proxy": "1.17.2",
|
||||
"com.unity.feature.2d": "1.0.0",
|
||||
"com.unity.ide.rider": "3.0.16",
|
||||
"com.unity.ide.rider": "3.0.15",
|
||||
"com.unity.ide.visualstudio": "2.0.16",
|
||||
"com.unity.ide.vscode": "1.2.5",
|
||||
"com.unity.test-framework": "1.1.31",
|
||||
|
@ -1,11 +1,11 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"com.unity.2d.animation": {
|
||||
"version": "7.0.8",
|
||||
"version": "7.0.6",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.2d.common": "6.0.5",
|
||||
"com.unity.2d.common": "6.0.3",
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
"com.unity.modules.uielements": "1.0.0"
|
||||
@ -13,7 +13,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.2d.common": {
|
||||
"version": "6.0.5",
|
||||
"version": "6.0.3",
|
||||
"depth": 2,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -39,12 +39,12 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.2d.psdimporter": {
|
||||
"version": "6.0.6",
|
||||
"version": "6.0.4",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.2d.animation": "7.0.8",
|
||||
"com.unity.2d.common": "6.0.5",
|
||||
"com.unity.2d.animation": "7.0.6",
|
||||
"com.unity.2d.common": "6.0.3",
|
||||
"com.unity.2d.sprite": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
@ -56,12 +56,12 @@
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.2d.spriteshape": {
|
||||
"version": "7.0.6",
|
||||
"version": "7.0.5",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.mathematics": "1.1.0",
|
||||
"com.unity.2d.common": "6.0.4",
|
||||
"com.unity.2d.common": "6.0.3",
|
||||
"com.unity.2d.path": "5.0.2",
|
||||
"com.unity.modules.physics2d": "1.0.0"
|
||||
},
|
||||
@ -115,17 +115,17 @@
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.2d.animation": "7.0.8",
|
||||
"com.unity.2d.animation": "7.0.6",
|
||||
"com.unity.2d.pixel-perfect": "5.0.1",
|
||||
"com.unity.2d.psdimporter": "6.0.6",
|
||||
"com.unity.2d.psdimporter": "6.0.4",
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.2d.spriteshape": "7.0.6",
|
||||
"com.unity.2d.spriteshape": "7.0.5",
|
||||
"com.unity.2d.tilemap": "1.0.0",
|
||||
"com.unity.2d.tilemap.extras": "2.2.3"
|
||||
}
|
||||
},
|
||||
"com.unity.ide.rider": {
|
||||
"version": "3.0.16",
|
||||
"version": "3.0.15",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -164,7 +164,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.services.core": {
|
||||
"version": "1.4.3",
|
||||
"version": "1.4.2",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
@ -1,2 +1,2 @@
|
||||
m_EditorVersion: 2021.3.12f1
|
||||
m_EditorVersionWithRevision: 2021.3.12f1 (8af3c3e441b1)
|
||||
m_EditorVersion: 2021.3.9f1
|
||||
m_EditorVersionWithRevision: 2021.3.9f1 (ad3870b89536)
|
||||
|
Loading…
Reference in New Issue
Block a user