public SatelliteStateForaging(Satellite satellite, MainInterface mainScript)
        {
            resourcePlacements = new Queue <Vector2>();

            untouchedResources        = new List <Vector2>();
            touchedResources          = new List <Vector2>();
            aboutToBeTouchedResources = new HashSet <Vector2>();
            resourcePlacements.Enqueue(new Vector2(29.5f, 29.5f));
            robotPositions   = new Dictionary <uint, Vector3>();
            robotResourceMap = new Dictionary <uint, Vector2>();

            this.satellite  = satellite;
            this.mainScript = mainScript;

            mainScript.getResourcePositions(out untouchedResources);
            scanForRobots(mainScript.getCurrentConfig());
            foraging = true;
            satellite.broadcastMessage("foraging\tstart");
        }
Beispiel #2
0
        ////////////////////////////////////////////////////////////////////////
        // Constructor and Functions
        ////////////////////////////////////////////////////////////////////////
        public SatelliteStateBuild(Satellite satellite, MainInterface mainScript, string args)
        {
            this.args       = args;
            this.mainScript = mainScript;
            this.satellite  = satellite;

            pendingRequests = new Queue <CommMessage>();

            // Initialize resource origins
            List <Vector2> resourceOriginList;

            mainScript.getResourcePositionsInCache(out resourceOriginList);
            resourceOriginList.Sort(delegate(Vector2 a, Vector2 b) {
                float difference;

                if (a.x == b.x)
                {
                    difference = a.y - b.y;
                }
                else
                {
                    difference = a.x - b.x;
                }

                return((difference == 0) ? 0 : ((difference > 0) ? 1 : -1));
            });

            resourceOrigins = new Queue <Vector2>(resourceOriginList);

            // Initialize wait queue
            waitQueue = new Queue <Vector2>();
            bool switchDirection = false;

            for (int i = 0; i < 6; ++i, switchDirection = !switchDirection)
            {
                for (int j = 0; j < 2; ++j)
                {
                    waitQueue.Enqueue(new Vector2(i * 2, 20 + (switchDirection ? 1 - j : j) * 10));
                }
            }

            if (args.StartsWith("\"") && args.EndsWith("\""))
            {
                resourcePlacements = new Queue <Vector2>(Words.getBuildOrder(args.Substring(1, args.Length - 2)));
            }
            else
            {
                resourcePlacements = new Queue <Vector2>();
            }

            Vector2 xMin = new Vector2(float.MaxValue, 15f);
            Vector2 xMax = new Vector2(float.MinValue, 15f);

            foreach (Vector2 v in resourcePlacements)
            {
                if (v.x < xMin.x)
                {
                    xMin.x = v.x;
                }

                if (v.x > xMax.x)
                {
                    xMax.x = v.x;
                }
            }

            xMax.x += 1.5f;
            xMin.x -= 1.5f;

            totalRequiredResources = resourcePlacements.Count;

            // start construction
            if (totalRequiredResources > 0)
            {
                satellite.broadcastMessage(new MessageBuildStart(waitQueue, xMin, xMax).ToString());
            }
        }
        ////////////////////////////////////////////////////////////////////////
        // Constructor and Functions
        ////////////////////////////////////////////////////////////////////////
        public SatelliteStateConstruction(Satellite satellite, MainInterface mainScript)
        {
            this.mainScript = mainScript;
            this.satellite  = satellite;

            structureLayers = new Queue <StructureLayer>();

            // Initialize resource origins
            List <Vector2> resourceOriginList;

            mainScript.getResourcePositions(out resourceOriginList);
            resourceOriginList.Sort(delegate(Vector2 a, Vector2 b) {
                float difference;

                if (a.x == b.x)
                {
                    difference = a.y - b.y;
                }
                else
                {
                    difference = a.x - b.x;
                }

                return((difference == 0) ? 0 : ((difference > 0) ? 1 : -1));
            });

            resourceOrigins = new Queue <Vector2>(resourceOriginList);

            // Initialize wait queue
            waitQueue = new Queue <Vector2>();
            bool switchDirection = false;

            for (int i = 0; i < 6; ++i, switchDirection = !switchDirection)
            {
                for (int j = 0; j < 2; ++j)
                {
                    waitQueue.Enqueue(new Vector2(i * 2, 20 + (switchDirection ? 1 - j : j) * 10));
                }
            }

            float           placementSpacing = 1.5f;
            List <Vector2>  constructionPerimeter;
            Queue <Vector2> resourcePlacements;

            // Initialize resource placements for first layer
            {
                placementSpacing   = 1.0f;
                resourcePlacements = new Queue <Vector2>();
                Stack <Vector2> reversePlacements = new Stack <Vector2>();

                for (int i = -1; i < 2; ++i)
                {
                    reversePlacements.Push(new Vector2(i * placementSpacing, placementSpacing));
                }

                reversePlacements.Push(new Vector2(placementSpacing, 0));

                for (int i = 1; i >= -1; --i)
                {
                    reversePlacements.Push(new Vector2(i * placementSpacing, -1 * placementSpacing));
                }

                reversePlacements.Push(new Vector2(-1 * placementSpacing, 0));

                while (reversePlacements.Count > 0)
                {
                    resourcePlacements.Enqueue(reversePlacements.Pop());
                }
            }

            // Initialize construction perimeter for first layer
            {
                placementSpacing      = 1.5f;
                constructionPerimeter = new List <Vector2>();
                constructionPerimeter.Add(new Vector2(-1 * placementSpacing, 3 * placementSpacing));
                constructionPerimeter.Add(new Vector2(-1 * placementSpacing, 2 * placementSpacing));
                constructionPerimeter.Add(new Vector2(2 * placementSpacing, 2 * placementSpacing));
                constructionPerimeter.Add(new Vector2(2 * placementSpacing, -2f * placementSpacing));
                constructionPerimeter.Add(new Vector2(-2 * placementSpacing, -2f * placementSpacing));
                constructionPerimeter.Add(new Vector2(-2 * placementSpacing, placementSpacing));
                constructionPerimeter.Add(new Vector2(-5 * placementSpacing, placementSpacing));
                constructionPerimeter.Add(new Vector2(-5 * placementSpacing, 5 * placementSpacing));
            }

            // Initialize first layer and add to layers list
            structureLayers.Enqueue(new StructureLayer(constructionPerimeter, resourcePlacements));
            totalRequiredResources += resourcePlacements.Count;

            // Initialize resource placements for the second layer
            {
                placementSpacing   = 1.5f;
                resourcePlacements = new Queue <Vector2>();
                Stack <Vector2> reversePlacements = new Stack <Vector2>();

                for (int i = -2; i <= 2; ++i)
                {
                    reversePlacements.Push(new Vector2(i * placementSpacing, 2 * placementSpacing));
                }

                for (int i = 1; i >= -1; --i)
                {
                    reversePlacements.Push(new Vector2(2 * placementSpacing, i * placementSpacing));
                }

                for (int i = 2; i >= -2; --i)
                {
                    reversePlacements.Push(new Vector2(i * placementSpacing, -2 * placementSpacing));
                }

                for (int i = -1; i <= 1; ++i)
                {
                    reversePlacements.Push(new Vector2(-2 * placementSpacing, i * placementSpacing));
                }

                while (reversePlacements.Count > 0)
                {
                    resourcePlacements.Enqueue(reversePlacements.Pop());
                }
            }

            // Initialize construction perimeter for second layer
            {
                placementSpacing     *= 2;
                constructionPerimeter = new List <Vector2>();
                constructionPerimeter.Add(new Vector2(-1 * placementSpacing, 3 * placementSpacing));
                constructionPerimeter.Add(new Vector2(-1 * placementSpacing, 2 * placementSpacing));
                constructionPerimeter.Add(new Vector2(2 * placementSpacing, 2 * placementSpacing));
                constructionPerimeter.Add(new Vector2(2 * placementSpacing, -2f * placementSpacing));
                constructionPerimeter.Add(new Vector2(-2 * placementSpacing, -2f * placementSpacing));
                constructionPerimeter.Add(new Vector2(-2 * placementSpacing, 2 * placementSpacing));
            }

            // Initialize second layer and add to layers list
            structureLayers.Enqueue(new StructureLayer(constructionPerimeter, resourcePlacements));
            totalRequiredResources += resourcePlacements.Count;

            // start construction
            satellite.broadcastMessage(new MessageConstructionStart(waitQueue).ToString());
        }