示例#1
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);
        }
示例#2
0
        /// <see cref="IFogOfWarBC.CheckPlacementConstraints"/>
        public RCSet <RCIntVector> CheckPlacementConstraints(IScenarioElementType elementType, RCIntVector position, RCSet <Entity> entitiesToIgnore)
        {
            if (this.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }

            RCIntVector         objectQuadraticSize = this.ActiveScenario.Map.CellToQuadSize(elementType.Area.Read().Size);
            RCSet <RCIntVector> violatingQuadCoords = elementType.CheckPlacementConstraints(this.ActiveScenario, position, entitiesToIgnore);

            for (int x = 0; x < objectQuadraticSize.X; x++)
            {
                for (int y = 0; y < objectQuadraticSize.Y; y++)
                {
                    RCIntVector relativeQuadCoords = new RCIntVector(x, y);
                    RCIntVector absQuadCoords      = position + relativeQuadCoords;
                    if (absQuadCoords.X < 0 || absQuadCoords.X >= this.ActiveScenario.Map.Size.X ||
                        absQuadCoords.Y < 0 || absQuadCoords.Y >= this.ActiveScenario.Map.Size.Y ||
                        this.GetFullFowTileFlags(absQuadCoords).HasFlag(FOWTileFlagsEnum.Current))
                    {
                        violatingQuadCoords.Add(relativeQuadCoords);
                    }
                }
            }
            return(violatingQuadCoords);
        }
示例#3
0
        /// <see cref="IMapEditorService.PlaceStartLocation"/>
        public bool PlaceStartLocation(RCIntVector position, int playerIndex)
        {
            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(StartLocation.STARTLOCATION_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);
            }

            /// Check if a start location with the given player index already exists.
            RCSet <StartLocation> startLocations = this.scenarioManager.ActiveScenario.GetAllElements <StartLocation>();
            StartLocation         startLocation  = null;

            foreach (StartLocation sl in startLocations)
            {
                if (sl.PlayerIndex == playerIndex)
                {
                    startLocation = sl;
                    break;
                }
            }

            /// If a start location with the given player index already exists, change its quadratic coordinates,
            /// otherwise create a new start location.
            if (startLocation != null)
            {
                startLocation.DetachFromMap();
            }
            else
            {
                startLocation = new StartLocation(playerIndex);
                this.scenarioManager.ActiveScenario.AddElementToScenario(startLocation);
            }
            startLocation.AttachToMap(this.scenarioManager.ActiveScenario.Map.GetQuadTile(topLeftQuadCoords));
            return(true);
        }