public void CallElevator(Elevator.Elevator mainPart, int entryLevel) { if (!mainPart.floorsToVisit.Contains(entryLevel)) { mainPart.floorsToVisit.Add(entryLevel); } }
public void NotifyDropOff(Elevator.Elevator elevator, Request request) { if (elevator.IsIdle) { this.Relocator?.RelocateIdleElevator(elevator); } }
public void RelocateIdleElevator(Elevator.Elevator elevator) { if (!IsReady) { // If not ready, return return; } var otherElevators = this.Elevaotrs.Elevators.FindAll(e => e != elevator); List <int> otherElevatorPositions = new List <int>(); foreach (Elevator.Elevator e in otherElevators) { if (e.IsIdle) { otherElevatorPositions.Add((int)e.CurrentFloor); } else { otherElevatorPositions.Add((int)e.Waypoints.Last().DestinationFloor); } } var bestPos = BestPosition(otherElevatorPositions); if (bestPos != elevator.CurrentFloor) { elevator.AddWaypoint(new ElevatorWaypoint(bestPos, WaypointType.RELOCATION)); } }
public bool IsElevatorComingToFloor(Elevator.Elevator mainPart, int level) { if (mainPart.floorsToVisit.Contains(level)) { return(true); } return(false); }
public int GetLevel(Elevator.Elevator mainPart, Vector3 pos) { if (mainPart != null) { for (int i = 0; i < mainPart.linkPoints.Length; i++) { if (mainPart.linkPoints[i].transform.position == pos) { return(i); } } } return(-1); }
public void GetElevatorInformation(Squad.Core core, OffMeshLink link, Vector3 startPos) { Elevator.Elevator mainPart = link.GetComponent <Elevator.MeshLinkDetector>().main; core.mainPart = mainPart; if (link.startTransform.position == startPos) { core.entry = GetLevel(mainPart, link.startTransform.position); core.exit = GetLevel(mainPart, link.endTransform.position); } else { core.entry = GetLevel(mainPart, link.endTransform.position); core.exit = GetLevel(mainPart, link.startTransform.position); } if (core.entry != core.exit || mainPart != null) { core.toUseElevator = true; } }
private int[] TimePenalty(Request request, Elevator.Elevator elevator) { int[] penalty = { int.MaxValue, -1 }; if (elevator.Direction == request.Direction && elevator.Direction == Direction.DOWN && request.Source < elevator.CurrentFloor && !elevator.OnTheWayRequests.Exists(r => r.Direction == Direction.UP && r.Source > request.Destination)) { // The elevator is going down in the same direction as our request // If it is picking up a request to go up, it is below our destination penalty[1] = 0; // Time for elevator to get to the request penalty[0] = (int)Math.Ceiling(Math.Abs((double)((int)elevator.CurrentFloor - (int)request.Source)) / this.SpeedPerTick); // Time wasted for other people already travelling in the elevator penalty[0] += (int)elevator.LoadingTimeRemaining + (elevator.OnTheWayRequests.FindAll(r => r.Source != request.Source && r.Destination != request.Source).Count() + elevator.OnTheWayRequests.FindAll(r => r.Source != request.Destination && r.Destination != request.Destination).Count() + elevator.PickedUpRequests.FindAll(r => r.Source != request.Source && r.Destination != request.Source).Count() + elevator.PickedUpRequests.FindAll(r => r.Source != request.Destination && r.Destination != request.Destination).Count() ) * (int)this.LoadingTime; } else if (elevator.Direction == request.Direction && elevator.Direction == Direction.UP && request.Source > elevator.CurrentFloor && !elevator.OnTheWayRequests.Exists(r => r.Direction == Direction.DOWN && r.Source < request.Destination)) { // The elevator is travelling up in the same direction as the request // If it is going to pick up someone that wants to go down, it is above the request destination penalty[1] = 0; // Time for elevator to get to the request penalty[0] = (int)Math.Ceiling(Math.Abs((double)((int)elevator.CurrentFloor - (int)request.Source)) / this.SpeedPerTick); // Time wasted for other people already travelling in the elevator penalty[0] += (int)elevator.LoadingTimeRemaining + (elevator.OnTheWayRequests.FindAll(r => r.Source != request.Source && r.Destination != request.Source).Count() + elevator.OnTheWayRequests.FindAll(r => r.Source != request.Destination && r.Destination != request.Destination).Count() + elevator.PickedUpRequests.FindAll(r => r.Source != request.Source && r.Destination != request.Source).Count() + elevator.PickedUpRequests.FindAll(r => r.Source != request.Destination && r.Destination != request.Destination).Count() ) * (int)this.LoadingTime; } // Now concider the penalty if we pick up this request later after fufilling all requests var distinctFloors = new HashSet <int>(); distinctFloors.Add((int)elevator.CurrentFloor); foreach (var r in elevator.OnTheWayRequests) { distinctFloors.Add((int)r.Source); distinctFloors.Add((int)r.Destination); } foreach (var r in elevator.PickedUpRequests) { distinctFloors.Add((int)r.Destination); } int penaltyNoPickup = (int)elevator.LoadingTimeRemaining + (int)Math.Ceiling((double)(distinctFloors.Max() - distinctFloors.Min()) / this.SpeedPerTick) + distinctFloors.Count() * (int)this.LoadingTime; var direction = (elevator.OnTheWayRequests.Count() == 0) ? elevator.Direction : elevator.OnTheWayRequests.First().Direction; var endPoint = (direction == Direction.DOWN) ? distinctFloors.Min() : distinctFloors.Max(); penaltyNoPickup += (int)Math.Ceiling(Math.Abs((double)(endPoint - (int)request.Source) / this.SpeedPerTick)); if (penaltyNoPickup < penalty[0]) { penalty[0] = penaltyNoPickup; // Update the best penalty penalty[1] = -1; // Indicate that it is batter not to use the elevator } return(penalty); }
public void EnterOnElevator(Squad.Core core, Elevator.Elevator mainPart) { core.curWaypoint = mainPart.platform.position; }
public void AddToWaitList(Elevator.Elevator mainPart, int level, Squad.Core core) { mainPart.linkPoints[level].GetComponent <Elevator.MeshLinkDetector>().inWait.Add(core); }