Beispiel #1
0
        /// <summary>
        /// This fires in an arbitrary thread.  It looks at what's in the map, and builds instructions that will be run in the main thread
        /// (adds/removes)
        /// </summary>
        public void Update_AnyThread(double elapsedTime)
        {
            MapOctree snapshot = _map.LatestSnapshot;

            if (snapshot == null)
            {
                return;
            }

            IEnumerable <MapObjectInfo> allItems = snapshot.GetItems();

            //_map.GetAllItems(true)        //TODO: May want to use this to get disposed items

            // Look for too few/many
            ChangeInstruction[] asteroids = ExamineAsteroids(allItems, _boundry);
            ChangeInstruction[] minerals  = ExamineMinerals(allItems, _boundry, _mineralTypesByValue);

            // Store these instructions for the main thread to do
            if (asteroids != null || minerals != null)
            {
                ChangeInstruction[] instructions = UtilityCore.ArrayAdd(asteroids, minerals);

                if (instructions.Length > MAXCHANGES)
                {
                    instructions = UtilityCore.RandomOrder(instructions, MAXCHANGES).ToArray();
                }

                _instructions = instructions;
            }
        }
Beispiel #2
0
        private Point3D[] GetNearbyObjects(Point3D center, double radius)
        {
            //TODO: filter what they can drag toward
            //TODO: frequent requests should reuse results of a prev call

            MapOctree snapshot = _map.LatestSnapshot;

            if (snapshot != null)
            {
                // The snapshot is designed for this kind of request, so use it
                return(snapshot.GetItems(center, radius).
                       Where(o => o.MapObject != _selectedItem.Item).   // don't return the item behing dragged
                       Select(o => o.Position).ToArray());
            }

            double radSquared = radius * radius;

            // Do a brute force scan of all objects
            return(_map.GetAllItems().
                   Where(o => o != _selectedItem.Item).     // don't return the item behing dragged
                   Select(o => o.PhysicsBody.Position).
                   Where(o => (center - o).LengthSquared <= radSquared).
                   ToArray());
        }
Beispiel #3
0
        private Tuple<MapObjectInfo, double, ForceSettings_Initial>[] GetNeighbors(MapOctree snapshot, Point3D position)
        {
            // Get nearby items, sort by distance
            double searchRadius = this.SearchRadius;

            var initial = snapshot.GetItems(position, searchRadius).
                Where(o => o.Token != this.Token).
                Select(o => Tuple.Create(o, (o.Position - position).LengthSquared)).
                OrderBy(o => o.Item2).
                ToArray();

            // Get chase settings for each item
            //NOTE: This needs to be done after sorting on distance, because bots will have different settings if too many are actively chased
            var retVal = new List<Tuple<MapObjectInfo, double, ForceSettings_Initial>>();

            int chaseNeighborCount = this.ChaseNeighborCount;
            int currentNeighborCount = 0;

            foreach (var item in initial)
            {
                ForceSettings_Initial chaseProps = GetForceSetting_Initial(ref currentNeighborCount, item.Item1, chaseNeighborCount);

                if (chaseProps != null)
                {
                    retVal.Add(Tuple.Create(item.Item1, item.Item2, chaseProps));
                }
            }

            return retVal.ToArray();
        }