示例#1
0
        public override PipelineReturnData pushThrough(List <EntityOnMap <SickEntity> > currentSick, List <EntityOnMap <HealthyEntity> > currentHealthy, ulong timeDeltaMs)
        {
            // Make entities sick if they need to

            /*
             * NOTE: Because the timeScale parameter removes "frames"
             * and possible intersections (no interpolation is being
             * done as it's quite intensive to do at real time),
             * the code tries to compensate by increasing the radius.
             * Because we don't want everyone to become sick immediately,
             * then linear scaling is not possible. Using this
             * (https://www.desmos.com/calculator/7agyg8rqqz) for
             * trying out some things.
             */
            var toBeSick = currentHealthy
                           .Where(h =>
            {
                // Only keep entries that are intersecting with sick people
                return(currentSick
                       .Any(s => EntityOnMap <SickEntity> .IsIntersecting(
                                s.location, radius,
                                h.location, radius)
                            ));
            })
                           .Select((x, idx) =>
            {
                // Covert to sick entities
                var sickEntity  = SickEntity.ConvertToSick(x.entity);
                var sickMapItem = EntityConverterUtility <HealthyEntity, SickEntity> .ConvertInnerEntities(x, sickEntity);
                return(sickMapItem);
            })
                           .Aggregate((new List <ulong>(), new List <EntityOnMap <SickEntity> >()), (aggregate, item) =>
            {
                aggregate.Item1.Add(item.ID);
                aggregate.Item2.Add(item);
                return(aggregate);
            })
                           .ToTuple();

            return(new PipelineReturnData
            {
                newHealthy = currentHealthy.Where(x => !toBeSick.Item1.Contains(x.ID)).ToList(),
                newSick = currentSick.Concat(toBeSick.Item2).ToList(),
            });
        }
示例#2
0
 internal static void iterateOver(
     List <EntityOnMap <T> > entities,
     Random random,
     Dictionary <ulong, int> nextAttractor,
     List <Point> attractors,
     int attractorRadius
     )
 {
     // Perform attractor assignment
     entities.ForEach(x =>
     {
         // Check if is registered
         if (nextAttractor.ContainsKey(x.ID))
         {
             var attractorIndex = nextAttractor[x.ID];
             // Check if located at desired attractor
             if (EntityOnMap <SickEntity> .IsIntersecting(x.location, 1, attractors[attractorIndex], (ushort)attractorRadius))
             {
                 // Generte a new attractor to head towards
                 nextAttractor[x.ID] = random.Next(0, attractors.Count() - 1);
             }
             // Add some randomness
             if (random.Next(100) == 0)
             {
                 var attractorDirectionX = Math.Sign(attractors[attractorIndex].X - x.location.X);
                 var attractorDirectionY = Math.Sign(attractors[attractorIndex].Y - x.location.Y);
                 x.entity.direction      = new Vector3(attractorDirectionX, attractorDirectionY, 0);
             }
         }
         else
         {
             // Generte a new attractor to head towards
             nextAttractor[x.ID] = random.Next(0, attractors.Count() - 1);
         }
     });
 }