Ejemplo n.º 1
0
        /// <see cref="ScenarioElement.AttachToMap"/>
        public override bool AttachToMap(RCNumVector position, params ScenarioElement[] elementsToIgnore)
        {
            /// Check if the position of this Refinery would align with a VespeneGeyser.
            RCSet <VespeneGeyser> vespeneGeysersAtPos = this.Scenario.GetElementsOnMap <VespeneGeyser>(position, MapObjectLayerEnum.GroundObjects);

            if (vespeneGeysersAtPos.Count != 1)
            {
                return(false);
            }
            VespeneGeyser vespeneGeyserAtPos = vespeneGeysersAtPos.First();

            if (this.CalculateArea(position) != vespeneGeyserAtPos.Area)
            {
                return(false);
            }

            /// Save the VespeneGeyser and detach it from the map.
            this.underlyingVespeneGeyser.Write(vespeneGeyserAtPos);
            this.underlyingVespeneGeyser.Read().DetachFromMap();

            /// Try to attach the Refinery.
            bool refineryAttached = base.AttachToMap(position, elementsToIgnore);

            if (!refineryAttached)
            {
                /// If the Refinery could not be attached -> reattach the underlying VespeneGeyser.
                this.underlyingVespeneGeyser.Read().AttachToMap(position);
                this.underlyingVespeneGeyser.Write(null);
            }

            return(refineryAttached);
        }
Ejemplo n.º 2
0
        /// <see cref="IMapEditorService.RemoveEntity"/>
        public bool ChangeResourceAmount(int objectID, int delta)
        {
            if (this.scenarioManager.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (objectID < 0)
            {
                throw new ArgumentOutOfRangeException("objectID");
            }

            MineralField  mineralField  = this.scenarioManager.ActiveScenario.GetElement <MineralField>(objectID);
            VespeneGeyser vespeneGeyser = this.scenarioManager.ActiveScenario.GetElement <VespeneGeyser>(objectID);

            if (mineralField != null)
            {
                int currentResourceAmount = mineralField.ResourceAmount.Read();
                mineralField.ResourceAmount.Write(Math.Max(MineralField.MINIMUM_RESOURCE_AMOUNT, currentResourceAmount + delta));
                return(true);
            }
            else if (vespeneGeyser != null)
            {
                int currentResourceAmount = vespeneGeyser.ResourceAmount.Read();
                vespeneGeyser.ResourceAmount.Write(Math.Max(VespeneGeyser.MINIMUM_RESOURCE_AMOUNT, currentResourceAmount + delta));
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <see cref="EntityPlacementConstraint.CheckImpl"/>
        protected override RCSet <RCIntVector> CheckImpl(Scenario scenario, RCIntVector position, RCSet <Entity> entitiesToIgnore)
        {
            RCIntRectangle      objArea            = new RCIntRectangle(position, scenario.Map.CellToQuadSize(this.EntityType.Area.Read().Size));
            RCSet <RCIntVector> retList            = new RCSet <RCIntVector>();
            VespeneGeyser       foundVespeneGeyser = null;
            bool isOK = true;

            for (int absY = objArea.Top; absY < objArea.Bottom; absY++)
            {
                for (int absX = objArea.Left; absX < objArea.Right; absX++)
                {
                    RCIntVector absQuadCoords = new RCIntVector(absX, absY);
                    if (absQuadCoords.X >= 0 && absQuadCoords.X < scenario.Map.Size.X &&
                        absQuadCoords.Y >= 0 && absQuadCoords.Y < scenario.Map.Size.Y)
                    {
                        retList.Add(absQuadCoords - position);
                        VespeneGeyser vespeneGeyserAtCoords = scenario.GetFixedEntity <VespeneGeyser>(absQuadCoords);
                        if (vespeneGeyserAtCoords == null || (foundVespeneGeyser != null && foundVespeneGeyser != vespeneGeyserAtCoords))
                        {
                            /// There is no VespeneGeyser at the given coordinates OR
                            /// the VespeneGeyser at the given coordinates is another VespeneGeyser.
                            isOK = false;
                            continue;
                        }
                        foundVespeneGeyser = vespeneGeyserAtCoords;
                    }
                }
            }
            if (isOK)
            {
                retList.Clear();
            }
            return(retList);
        }
Ejemplo n.º 4
0
        /// <see cref="IMapEditorService.PlaceVespeneGeyser"/>
        public bool PlaceVespeneGeyser(RCIntVector position)
        {
            if (this.scenarioManager.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (position == RCIntVector.Undefined)
            {
                throw new ArgumentNullException("position");
            }

            RCIntVector navCellCoords = this.mapWindowBC.AttachedWindow.WindowToMapCoords(position).Round();
            IQuadTile   quadTileAtPos = this.scenarioManager.ActiveScenario.Map.GetCell(navCellCoords).ParentQuadTile;

            IScenarioElementType objectType        = this.scenarioManager.Metadata.GetElementType(VespeneGeyser.VESPENEGEYSER_TYPE_NAME);
            RCIntVector          objQuadSize       = this.scenarioManager.ActiveScenario.Map.CellToQuadSize(objectType.Area.Read().Size);
            RCIntVector          topLeftQuadCoords = quadTileAtPos.MapCoords - objQuadSize / 2;

            if (objectType.CheckPlacementConstraints(this.scenarioManager.ActiveScenario, topLeftQuadCoords, new RCSet <Entity>()).Count != 0)
            {
                return(false);
            }

            VespeneGeyser placedVespeneGeyser = new VespeneGeyser();

            this.scenarioManager.ActiveScenario.AddElementToScenario(placedVespeneGeyser);
            placedVespeneGeyser.AttachToMap(this.scenarioManager.ActiveScenario.Map.GetQuadTile(topLeftQuadCoords));
            return(true);
        }
        /// <see cref="BuildingPlacementSuggestionProvider.GetSuggestionsImpl"/>
        protected override RCSet <Tuple <RCIntRectangle, RCIntVector> > GetSuggestionsImpl(Scenario scenario, RCIntRectangle area)
        {
            RCSet <Tuple <RCIntRectangle, RCIntVector> > retList = new RCSet <Tuple <RCIntRectangle, RCIntVector> >();
            RCSet <VespeneGeyser> processedVespeneGeysers        = new RCSet <VespeneGeyser>();

            for (int x = area.Left; x < area.Right; x++)
            {
                for (int y = area.Top; y < area.Bottom; y++)
                {
                    RCIntVector   quadCoords    = new RCIntVector(x, y);
                    VespeneGeyser vespeneGeyser = scenario.GetFixedEntity <VespeneGeyser>(quadCoords);
                    if (vespeneGeyser == null || processedVespeneGeysers.Contains(vespeneGeyser))
                    {
                        continue;
                    }

                    retList.Add(Tuple.Create(vespeneGeyser.MapObject.QuadraticPosition, new RCIntVector(0, 0)));
                    processedVespeneGeysers.Add(vespeneGeyser);
                }
            }
            return(retList);
        }