public int WaitTime(DateTime currTime, int point) { UpdateState(currTime); int timeWait = TimeToNextStay; if (NextStay == point) { return(timeWait); } else { int indexNextPoint = Waybill.FindIndex(x => x.Item1 == NextStay) + 1; int lenWay = Waybill.Count; while (NextStay != point) { timeWait += Waybill[indexNextPoint % lenWay].Item2; NextStay = Waybill[indexNextPoint % lenWay].Item1; indexNextPoint++; } LastTimeState = LastTimeState.AddMinutes(timeWait); TimeToNextStay = 0; return(timeWait); } }
private void UpdateState(DateTime currTime) { if (currTime.CompareTo(StartWaybill) <= 0) { NextStay = Waybill[0].Item1; TimeToNextStay = (int)(StartWaybill - currTime).TotalMinutes; LastTimeState = currTime; return; } DateTime busTime; int indexNextPoint; if (LastTimeState.Year != 1) { busTime = LastTimeState; busTime = busTime.AddMinutes(TimeToNextStay); indexNextPoint = Waybill.FindIndex(x => x.Item1 == NextStay); } else { busTime = StartWaybill; indexNextPoint = 0; NextStay = Waybill[0].Item1; TimeToNextStay = 0; } int lenWay = Waybill.Count; while (busTime.CompareTo(currTime) < 0) { busTime = busTime.AddMinutes(Waybill[(indexNextPoint + 1) % lenWay].Item2); indexNextPoint++; } NextStay = Waybill[indexNextPoint % lenWay].Item1; TimeToNextStay = (int)(busTime - currTime).TotalMinutes; LastTimeState = currTime; }