Esempio n. 1
0
        /// <see cref="ITerrainObjectType.CheckTerrainObjectIntersections"/>
        public RCSet <RCIntVector> CheckTerrainObjectIntersections(IMapAccess map, RCIntVector position)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }
            if (position == RCIntVector.Undefined)
            {
                throw new ArgumentNullException("position");
            }

            RCSet <RCIntVector> retList = new RCSet <RCIntVector>();

            for (int quadX = 0; quadX < this.quadraticSize.X; quadX++)
            {
                for (int quadY = 0; quadY < this.quadraticSize.Y; quadY++)
                {
                    RCIntVector relQuadCoords = new RCIntVector(quadX, quadY);
                    RCIntVector absQuadCoords = position + relQuadCoords;
                    if (absQuadCoords.X >= 0 && absQuadCoords.X < map.Size.X &&
                        absQuadCoords.Y >= 0 && absQuadCoords.Y < map.Size.Y)
                    {
                        /// Check intersection with other terrain object at the current quadratic tile.
                        ITerrainObject objToCheck = map.GetQuadTile(absQuadCoords).TerrainObject;
                        if (objToCheck != null && !this.IsExcluded(relQuadCoords) && objToCheck.GetQuadTile(absQuadCoords - objToCheck.MapCoords) != null)
                        {
                            retList.Add(relQuadCoords);
                        }
                    }
                }
            }
            return(retList);
        }
Esempio n. 2
0
        /// <see cref="IMapEditor.RemoveTerrainObject"/>
        public void RemoveTerrainObject(IMapAccess targetMap, ITerrainObject terrainObject)
        {
            if (targetMap == null)
            {
                throw new ArgumentNullException("targetMap");
            }
            if (terrainObject == null)
            {
                throw new ArgumentNullException("terrainObject");
            }
            if (targetMap != terrainObject.ParentMap)
            {
                throw new InvalidOperationException("The map of the terrain object must equal with the target map!");
            }

            /// TODO: Avoid this downcast!
            MapAccess targetMapObj = targetMap as MapAccess;

            if (targetMapObj == null)
            {
                throw new ArgumentException("The given map cannot be handled by the MapEditor!", "targetMap");
            }

            /// Undo the cell data changesets of the removed terrain object.
            foreach (ICellDataChangeSet changeset in terrainObject.Type.CellDataChangesets)
            {
                changeset.Undo(terrainObject);
            }
            targetMapObj.DetachTerrainObject(terrainObject);
        }
Esempio n. 3
0
 /// <summary>
 /// Converts the given terrain object into a SpriteInst structure.
 /// </summary>
 /// <param name="terrainObject">The terrain object to convert.</param>
 /// <returns>The converted SpriteInst structure.</returns>
 private SpriteRenderInfo ConvertTerrainObjectToSpriteInst(ITerrainObject terrainObject)
 {
     return(new SpriteRenderInfo()
     {
         SpriteGroup = SpriteGroupEnum.TerrainObjectSpriteGroup,
         Index = terrainObject.Type.Index,
         DisplayCoords = this.MapWindowBC.FullWindow.QuadToWindowRect(new RCIntRectangle(terrainObject.MapCoords, new RCIntVector(1, 1))).Location,
         Section = RCIntRectangle.Undefined
     });
 }
Esempio n. 4
0
        /// <see cref="IMapTerrainView.GetTerrainObjectDisplayCoords"/>
        public RCIntVector GetTerrainObjectDisplayCoords(RCIntVector position)
        {
            RCIntVector    navCellCoords = this.MapWindowBC.AttachedWindow.WindowToMapCoords(position).Round();
            ITerrainObject objToCheck    = this.Map.GetCell(navCellCoords).ParentQuadTile.TerrainObject;

            if (objToCheck != null)
            {
                return(this.MapWindowBC.AttachedWindow.QuadToWindowRect(new RCIntRectangle(objToCheck.MapCoords, new RCIntVector(1, 1))).Location);
            }

            return(RCIntVector.Undefined);
        }
Esempio n. 5
0
 /// <summary>
 /// Attaches the given terrain object to this quadratic tile.
 /// </summary>
 /// <param name="terrainObj">The terrain object to attach.</param>
 /// <exception cref="InvalidOperationException">If a terrain object has already been attached to this quadratic tile.</exception>
 public void AttachTerrainObject(ITerrainObject terrainObj)
 {
     if (terrainObj == null)
     {
         throw new ArgumentNullException("terrainObj");
     }
     if (this.terrainObject != null)
     {
         throw new InvalidOperationException("A terrain object has already been attached to this quadratic tile!");
     }
     this.terrainObject = terrainObj;
 }
Esempio n. 6
0
        /// <see cref="IMapEditorService.PlaceTerrainObject"/>
        public bool PlaceTerrainObject(RCIntVector position, string terrainObject)
        {
            if (this.scenarioManager.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (position == RCIntVector.Undefined)
            {
                throw new ArgumentNullException("position");
            }
            if (terrainObject == null)
            {
                throw new ArgumentNullException("terrainObject");
            }

            ITerrainObjectType terrainObjType    = this.scenarioManager.ActiveScenario.Map.Tileset.GetTerrainObjectType(terrainObject);
            RCIntVector        navCellCoords     = this.mapWindowBC.AttachedWindow.WindowToMapCoords(position).Round();
            IQuadTile          quadTileAtPos     = this.scenarioManager.ActiveScenario.Map.GetCell(navCellCoords).ParentQuadTile;
            RCIntVector        topLeftQuadCoords = quadTileAtPos.MapCoords - terrainObjType.QuadraticSize / 2;

            ITerrainObject placedTerrainObject = null;

            if (topLeftQuadCoords.X >= 0 && topLeftQuadCoords.Y >= 0 &&
                topLeftQuadCoords.X < this.scenarioManager.ActiveScenario.Map.Size.X && topLeftQuadCoords.Y < this.scenarioManager.ActiveScenario.Map.Size.Y)
            {
                IQuadTile targetQuadTile = this.scenarioManager.ActiveScenario.Map.GetQuadTile(topLeftQuadCoords);
                placedTerrainObject = this.mapEditor.PlaceTerrainObject(this.scenarioManager.ActiveScenario.Map, targetQuadTile, terrainObjType);
            }

            if (placedTerrainObject != null)
            {
                RCNumRectangle terrObjRect = new RCNumRectangle(this.scenarioManager.ActiveScenario.Map.GetQuadTile(placedTerrainObject.MapCoords).GetCell(new RCIntVector(0, 0)).MapCoords, placedTerrainObject.CellSize)
                                             - new RCNumVector(1, 1) / 2;
                foreach (Entity affectedEntity in this.scenarioManager.ActiveScenario.GetElementsOnMap <Entity>(terrObjRect, MapObjectLayerEnum.AirObjects, MapObjectLayerEnum.GroundObjects))
                {
                    if (affectedEntity.CheckPlacementConstraints(affectedEntity.MapObject.QuadraticPosition.Location, new RCSet <Entity>()).Count != 0)
                    {
                        affectedEntity.DetachFromMap();
                        this.scenarioManager.ActiveScenario.RemoveElementFromScenario(affectedEntity);
                        affectedEntity.Dispose();
                    }
                }
            }
            return(placedTerrainObject != null);
        }
Esempio n. 7
0
 /// <summary>
 /// Detaches the given terrain object from the map structure.
 /// </summary>
 /// <param name="terrainObj">The terrain object to be detached.</param>
 /// <exception cref="InvalidOperationException">If the given terrain object was not attached to this map.</exception>
 public void DetachTerrainObject(ITerrainObject terrainObj)
 {
     if (!this.terrainObjects.Remove(terrainObj))
     {
         throw new InvalidOperationException("The given terrain object was not attached to this map!");
     }
     for (int x = 0; x < terrainObj.Type.QuadraticSize.X; x++)
     {
         for (int y = 0; y < terrainObj.Type.QuadraticSize.Y; y++)
         {
             IQuadTile quadTile = terrainObj.GetQuadTile(new RCIntVector(x, y));
             if (quadTile != null)
             {
                 QuadTile quadTileObj = this.mapStructure.GetQuadTile(quadTile.MapCoords);
                 quadTileObj.DetachTerrainObject();
             }
         }
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Adds the given terrain object and all of its cutting quadratic tiles into the update lists.
 /// </summary>
 /// <param name="terrainObj">The terrain object to add.</param>
 /// <param name="terrainObjUpdateList">The terrain object update list.</param>
 /// <param name="quadTileUpdateList">The quadratic update list.</param>
 private void AddTerrainObjectToUpdate(ITerrainObject terrainObj, RCSet <ITerrainObject> terrainObjUpdateList, RCSet <IQuadTile> quadTileUpdateList)
 {
     if (terrainObj != null && terrainObjUpdateList.Add(terrainObj))
     {
         for (int col = 0; col < terrainObj.Type.QuadraticSize.X; col++)
         {
             for (int row = 0; row < terrainObj.Type.QuadraticSize.Y; row++)
             {
                 IQuadTile quadTileToUpdate = terrainObj.GetQuadTile(new RCIntVector(col, row));
                 if (quadTileToUpdate != null &&
                     (this.fowCacheMatrix.GetFullFowFlagsAtQuadTile(quadTileToUpdate.MapCoords) != FOWTileFlagsEnum.None ||
                      this.fowCacheMatrix.GetPartialFowFlagsAtQuadTile(quadTileToUpdate.MapCoords) != FOWTileFlagsEnum.None))
                 {
                     quadTileUpdateList.Add(quadTileToUpdate);
                 }
             }
         }
     }
 }
Esempio n. 9
0
        /// <see cref="IMapEditorService.RemoveTerrainObject"/>
        public bool RemoveTerrainObject(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();
            ITerrainObject objToCheck    = this.scenarioManager.ActiveScenario.Map.GetCell(navCellCoords).ParentQuadTile.TerrainObject;

            if (objToCheck != null)
            {
                this.mapEditor.RemoveTerrainObject(this.scenarioManager.ActiveScenario.Map, objToCheck);
                return(true);
            }
            return(false);
        }
Esempio n. 10
0
        /// <see cref="IMapEditor.DrawTerrain"/>
        public IEnumerable <IIsoTile> DrawTerrain(IMapAccess targetMap, IIsoTile targetTile, ITerrainType terrainType)
        {
            if (targetMap == null)
            {
                throw new ArgumentNullException("targetMap");
            }
            if (targetTile == null)
            {
                throw new ArgumentNullException("targetTile");
            }
            if (terrainType == null)
            {
                throw new ArgumentNullException("terrainType");
            }
            if (targetMap.Tileset != terrainType.Tileset)
            {
                throw new InvalidOperationException("The tileset of the new terrain type must be the same as the tileset of the map!");
            }

            /// Notify the map that the tile exchanging procedure is started.
            targetMap.BeginExchangingTiles();

            /// First we have to search the basis layer of the draw operation.
            ITerrainType baseLayer = terrainType;
            FloodArea    floodArea = new FloodArea();

            while (!this.CheckLayer(targetMap, targetTile, baseLayer, floodArea))
            {
                floodArea.Enlarge(baseLayer.TransitionLength + 1);
                baseLayer = baseLayer.Parent;
                if (baseLayer == null)
                {
                    throw new MapException("Basis-layer not found for draw terrain operation!");
                }
            }

            /// Clear the appropriate areas of the map around the target tile of the draw operation.
            foreach (ITerrainType topmostLayer in targetMap.Tileset.TerrainTypes)
            {
                if (topmostLayer.IsDescendantOf(baseLayer) && topmostLayer != terrainType && !topmostLayer.HasChildren)
                {
                    ITerrainType[] layersToClear = terrainType.FindRoute(topmostLayer);
                    this.ClearLayers(targetMap, targetTile, terrainType, baseLayer, layersToClear);
                }
            }

            /// Fill the appropriate areas of the map around the target tile of the draw operation.
            this.FillLayers(targetMap, targetTile, terrainType, baseLayer);

            /// Force regenerating the variant of the draw operation center and its neighbours.
            targetTile.ExchangeType(targetTile.Type);

            /// Remove the terrain objects that are violating the new map terrain.
            IEnumerable <IIsoTile> affectedIsoTiles = targetMap.EndExchangingTiles();

            foreach (IIsoTile affectedIsoTile in affectedIsoTiles)
            {
                foreach (IQuadTile cuttingQuadTile in affectedIsoTile.CuttingQuadTiles)
                {
                    ITerrainObject affectedTerrainObj = cuttingQuadTile.TerrainObject;
                    if (affectedTerrainObj != null && affectedTerrainObj.Type.CheckConstraints(targetMap, affectedTerrainObj.MapCoords).Count != 0)
                    {
                        this.RemoveTerrainObject(targetMap, affectedTerrainObj);
                    }
                }
            }
            return(affectedIsoTiles);
        }
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            ITerrainObject obj = context.Instance as ITerrainObject;

            if (obj == null)
            {
                return(null);
            }
            TerrainShape terrain = obj.OwnerTerrain;

            if (terrain == null)
            {
                return(null);
            }

            frmsvr = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (frmsvr == null)
            {
                return(null);
            }

            GUI.DynamicImageList il = new GUI.DynamicImageList(32);
            _comboBox.BeginUpdate();
            _comboBox.Items.Clear();
            _comboBox.SmallImageList = il.ImageList;
            int iSelIndex = -1;

            if (_bSupportsNoneTexture)
            {
                ListViewItem item = new ListViewItem("None");
                item.Tag        = null;
                item.ImageIndex = -1;
                _comboBox.Items.Add(item);
            }

            foreach (DetailTextureResource tex in terrain.DetailTextures)
            {
                if (tex._bIsBaseTexture && !_bSupportsBaseTexture)
                {
                    continue;
                }

                ListViewItem item = new ListViewItem(tex.ToString());
                item.Tag        = tex;
                item.ImageIndex = il.AddBitmap(EditorManager.Project.MakeAbsolute(tex.DiffuseFilename), System.Drawing.Color.Magenta);
                _comboBox.Items.Add(item);

                if (tex == value)
                {
                    item.Selected = true;
                    iSelIndex     = item.Index;
                }
            }
            _comboBox.EndUpdate();

            if (iSelIndex >= 0)
            {
                _comboBox.EnsureVisible(iSelIndex);
            }

            using (EditorManager.ActiveView.AcquireModal())
            {
                frmsvr.DropDownControl(_comboBox);
            }

            if (_comboBox.SelectedItems.Count == 1)
            {
                return(_comboBox.SelectedItems[0].Tag as DetailTextureResource);
            }
            return(null);
        }