Пример #1
0
 public void Init(long millis)
 {
     Debug.WriteLine($"Initializing {Type}: {millis}, {TagCount}");
     Generator = GeneratorFactory.Create(this);
     if (TagCount == 0)
     {
         TagCount = 1;
     }
     _Tags = new List <TrackingTag>();
     for (int i = 0; i < TagCount; i++)
     {
         var tag = new TrackingTag
         {
             IsBall    = UseBalls,
             Timestamp = millis,
             Used      = false,
             InUse     = false,
             X         = QueuePoint.X0,
             Y         = QueuePoint.Y0
         };
         _Tags.Add(tag);
     }
     //  get to the queue point
     _MaxMillis = millis - 100;
     State      = ActivityState.Waiting;
     //GeneratePath(millis, false);
 }
Пример #2
0
        private void GeneratePath(long millis, bool waitScan)
        {
            Debug.WriteLine($"{Name} generating a new path: {waitScan}");
            var count = _Tags.Count(t => (t != _SelectedTag) && (!t.Used));

            if (count == 0)
            {
                //  all tags used - need to take back to the queue point
                var to   = new PointF(QueuePoint.X0, QueuePoint.Y0);
                var from = (_MaxMillis == 0) ? _Entrance : new PointF(CollectionPoint.X0, CollectionPoint.Y0);
                _ActivityData = ((GeneratorBase)Generator).Walk(millis, string.Empty, new List <PointF> {
                    from, to
                }).OrderBy(d => d.Timestamp).ToList();
                //  reset all tags
                foreach (var tag in _Tags)
                {
                    tag.InUse = false;
                    tag.Used  = false;
                }
                _MaxMillis = _ActivityData.Max(d => d.Timestamp);
                //  walk back to the queue point
                State = ActivityState.ToQueue;
            }
            else if (!waitScan)
            {
                //  generate a new action
                _ActivityData = Generator.Generate(millis).OrderBy(d => d.Timestamp).ToList();
                if (_SelectedTag != null)
                {
                    _SelectedTag.Used  = true;
                    _SelectedTag.InUse = false;
                }
                //  select a new tag
                _SelectedTag       = _Tags.FirstOrDefault(t => !t.Used && !t.InUse);
                _SelectedTag.InUse = true;
                _MaxMillis         = _ActivityData.Max(d => d.Timestamp);
                State = ActivityState.Ready;
            }
            else
            {
                Debug.WriteLine($"{Name} is waiting");
                if (CurrentPlayer != null)
                {
                    OnDoneAction?.Invoke(CurrentPlayer);
                }
                State = ActivityState.Waiting;
            }
        }