Exemplo n.º 1
0
        /// <summary>
        /// Constructs a MagicBox instance for the given recipient entities and target position.
        /// </summary>
        /// <param name="recipientEntities">The recipient entities.</param>
        /// <param name="targetPosition">The target position.</param>
        public MagicBox(RCSet <Entity> recipientEntities, RCNumVector targetPosition)
        {
            this.commonTargetPosition = RCNumVector.Undefined;
            this.targetPositions      = new Dictionary <Entity, RCNumVector>();

            /// Check if we shall keep formation of the recipient entities.
            RCNumRectangle boundingBox = this.CalculateBoundingBox(recipientEntities);

            if (!boundingBox.Contains(targetPosition))
            {
                RCNumVector boundingBoxCenter = (2 * boundingBox.Location + boundingBox.Size) / 2;
                foreach (Entity entity in recipientEntities)
                {
                    RCNumVector boxLocationToEntityVector = entity.MotionControl.PositionVector.Read() - boundingBox.Location;
                    RCNumVector magicBox = entity.MotionControl.IsFlying ? AIR_MAGIC_BOX : GROUND_MAGIC_BOX;
                    if (boxLocationToEntityVector.X > magicBox.X || boxLocationToEntityVector.Y > magicBox.Y)
                    {
                        /// Entity is outside of the magic box -> don't keep formation.
                        this.commonTargetPosition = targetPosition;
                        break;
                    }

                    /// Calculate the target position of the entity.
                    this.targetPositions[entity] = targetPosition + entity.MotionControl.PositionVector.Read() - boundingBoxCenter;
                }
            }
            else
            {
                /// Target position is inside the bounding box -> don't keep formation.
                this.commonTargetPosition = targetPosition;
            }
        }
Exemplo n.º 2
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>();

            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)
                    {
                        /// Collect all the entities that are on the ground, are too close and not to be ignored.
                        RCIntRectangle checkedQuadRect  = new RCIntRectangle(absQuadCoords - this.minimumDistance, this.checkedQuadRectSize);
                        RCNumRectangle checkedArea      = (RCNumRectangle)scenario.Map.QuadToCellRect(checkedQuadRect) - new RCNumVector(1, 1) / 2;
                        RCSet <T>      entitiesTooClose = scenario.GetElementsOnMap <T>(checkedArea, MapObjectLayerEnum.GroundObjects);
                        if (entitiesTooClose.Any(entityTooClose => !entitiesToIgnore.Contains(entityTooClose)))
                        {
                            retList.Add(absQuadCoords - position);
                        }
                    }
                }
            }
            return(retList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the scenario elements of the given type that are attached to at least one of the given layers of the map inside the given area.
        /// </summary>
        /// <typeparam name="T">The type of the scenario elements to get.</typeparam>
        /// <param name="area">
        /// <param name="firstLayer">The first layer to search in.</param>
        /// <param name="furtherLayers">List of the further layers to search in.</param>
        /// The area to search.
        /// </param>
        /// <returns>
        /// A list that contains the scenario elements of the given type that are attached to at least one of the given layers of the map inside
        /// the given area.
        /// </returns>
        public RCSet <T> GetElementsOnMap <T>(RCNumRectangle area, MapObjectLayerEnum firstLayer, params MapObjectLayerEnum[] furtherLayers) where T : ScenarioElement
        {
            if (area == RCNumRectangle.Undefined)
            {
                throw new ArgumentNullException("area");
            }
            if (furtherLayers == null)
            {
                throw new ArgumentNullException("furtherLayers");
            }

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

            foreach (MapObject mapObj in this.mapObjects[firstLayer].GetContents(area))
            {
                T elementAsT = mapObj.Owner as T;
                if (elementAsT != null)
                {
                    retList.Add(elementAsT);
                }
            }
            foreach (MapObjectLayerEnum furtherLayer in furtherLayers)
            {
                foreach (MapObject mapObj in this.mapObjects[furtherLayer].GetContents(area))
                {
                    T elementAsT = mapObj.Owner as T;
                    if (elementAsT != null)
                    {
                        retList.Add(elementAsT);
                    }
                }
            }
            return(retList);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Computes the distance between two rectangles on the map.
        /// </summary>
        /// <param name="fromRectangle">The first rectangle on the map.</param>
        /// <param name="toRectangle">The second rectangle on the map.</param>
        /// <returns>The computed distance between the given rectangles.</returns>
        public static RCNumber ComputeDistance(RCNumRectangle fromRectangle, RCNumRectangle toRectangle)
        {
            /// The distance is 0 in case of intersection.
            if (fromRectangle.IntersectsWith(toRectangle))
            {
                return(0);
            }

            /// Calculate the relative position.
            bool isOnLeftSide  = fromRectangle.Right <= toRectangle.Left;
            bool isOnRightSide = toRectangle.Right <= fromRectangle.Left;
            bool isAbove       = fromRectangle.Bottom <= toRectangle.Top;
            bool isBelow       = toRectangle.Bottom <= fromRectangle.Top;

            /// Handle the 8 possible cases.
            if (isOnLeftSide && isAbove && !isOnRightSide && !isBelow)
            {
                return(MapUtils.ComputeDistance(
                           new RCNumVector(fromRectangle.Right, fromRectangle.Bottom),
                           new RCNumVector(toRectangle.Left, toRectangle.Top)));
            }
            else if (isOnRightSide && isAbove && !isOnLeftSide && !isBelow)
            {
                return(MapUtils.ComputeDistance(
                           new RCNumVector(fromRectangle.Left, fromRectangle.Bottom),
                           new RCNumVector(toRectangle.Right, toRectangle.Top)));
            }
            else if (isOnLeftSide && isBelow && !isOnRightSide && !isAbove)
            {
                return(MapUtils.ComputeDistance(
                           new RCNumVector(fromRectangle.Right, fromRectangle.Top),
                           new RCNumVector(toRectangle.Left, toRectangle.Bottom)));
            }
            else if (isOnRightSide && isBelow && !isOnLeftSide && !isAbove)
            {
                return(MapUtils.ComputeDistance(
                           new RCNumVector(fromRectangle.Left, fromRectangle.Top),
                           new RCNumVector(toRectangle.Right, toRectangle.Bottom)));
            }
            else if (isAbove && !isOnLeftSide && !isOnRightSide && !isBelow)
            {
                return(toRectangle.Top - fromRectangle.Bottom);
            }
            else if (isOnRightSide && !isOnLeftSide && !isAbove && !isBelow)
            {
                return(fromRectangle.Left - toRectangle.Right);
            }
            else if (isBelow && !isOnLeftSide && !isOnRightSide && !isAbove)
            {
                return(fromRectangle.Top - toRectangle.Bottom);
            }
            else if (isOnLeftSide && !isOnRightSide && !isAbove && !isBelow)
            {
                return(toRectangle.Left - fromRectangle.Right);
            }
            else
            {
                throw new InvalidOperationException("Impossible case!");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets the location of this map object.
        /// </summary>
        /// <param name="newLocation">The new location of this map object.</param>
        public void SetLocation(RCNumRectangle newLocation)
        {
            if (this.owner == null)
            {
                throw new ObjectDisposedException("MapObject");
            }
            if (newLocation == RCNumRectangle.Undefined)
            {
                throw new ArgumentNullException("newLocation");
            }

            if (this.location != newLocation)
            {
                if (this.BoundingBoxChanging != null)
                {
                    this.BoundingBoxChanging(this);
                }
                this.location = newLocation;
                this.quadraticPositionCache.Invalidate();
                this.quadraticShadowPositionCache.Invalidate();
                if (this.BoundingBoxChanged != null)
                {
                    this.BoundingBoxChanged(this);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Calculates the map coordinates of the window.
        /// </summary>
        /// <returns>The calculated map coordinates of the window.</returns>
        private RCNumRectangle CalculateWindowMapCoords()
        {
            RCNumRectangle pixelWindowPixelCoords     = new RCNumRectangle(this.pixelWindowCache.Value.Location - MapWindowBase.HALF_VECTOR, this.pixelWindowCache.Value.Size);
            RCNumVector    topLeftCornerMapCoords     = this.mapToPixelGridTransformation.TransformBA(pixelWindowPixelCoords.Location);
            RCNumVector    bottomRightCornerMapCoords = this.mapToPixelGridTransformation.TransformBA(pixelWindowPixelCoords.Location + pixelWindowPixelCoords.Size);

            return(new RCNumRectangle(topLeftCornerMapCoords, bottomRightCornerMapCoords - topLeftCornerMapCoords));
        }
Exemplo n.º 7
0
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right && this.currentMode == Mode.Creating)
            {
                RCNumVector sizeVect = this.currentPos - this.beginPos;
                if (sizeVect.X > 0 && sizeVect.Y > 0)
                {
                    TestContent newContent = new TestContent(new RCNumRectangle(this.beginPos, sizeVect));

                    this.stopwatch.Reset(); this.stopwatch.Start();
                    this.contentManager.AttachContent(newContent);
                    this.stopwatch.Stop(); this.avgAttachContent.NewItem((int)this.stopwatch.ElapsedMilliseconds);

                    this.nonSelectedContents.Add(newContent);
                    this.Invalidate();
                }
                this.currentMode = Mode.None;
            }
            else if (e.Button == MouseButtons.Left && this.currentMode == Mode.Selecting)
            {
                RCNumVector sizeVect = this.currentPos - this.beginPos;
                if (sizeVect.X > 0 && sizeVect.Y > 0)
                {
                    foreach (TestContent content in this.selectedContents)
                    {
                        this.nonSelectedContents.Add(content);
                    }
                    this.selectedContents.Clear();

                    RCNumRectangle selBox = new RCNumRectangle(this.beginPos, sizeVect);

                    this.stopwatch.Reset(); this.stopwatch.Start();
                    RCSet <TestContent> contents = this.contentManager.GetContents(selBox);
                    this.stopwatch.Stop(); this.avgGetContentInBox.NewItem((int)this.stopwatch.ElapsedMilliseconds);

                    foreach (TestContent content in contents)
                    {
                        this.nonSelectedContents.Remove(content);
                        this.selectedContents.Add(content);
                    }
                    this.Invalidate();
                }
                this.currentMode = Mode.None;
            }
            else if (e.Button == MouseButtons.Left && this.currentMode == Mode.Dragging)
            {
                foreach (TestContent draggedContent in this.selectedContents)
                {
                    this.stopwatch.Reset(); this.stopwatch.Start();
                    draggedContent.BoundingBox += this.currentPos - this.beginPos;
                    this.stopwatch.Stop(); this.avgPositionChange.NewItem((int)this.stopwatch.ElapsedMilliseconds);
                }
                this.Invalidate();
                this.currentMode = Mode.None;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Checks whether the given target entity is in the attack range of this weapon.
        /// </summary>
        /// <param name="targetEntity">The target entity.</param>
        /// <returns>True if the given target entity is in the attack range of this weapon; otherwise false.</returns>
        public bool IsEntityInRange(Entity targetEntity)
        {
            if (!this.CanTargetEntity(targetEntity))
            {
                return(false);
            }

            RCNumRectangle ownerArea  = this.owner.Read().Area;
            RCNumRectangle targetArea = targetEntity.Area;

            return(this.IsInRange(MapUtils.ComputeDistance(ownerArea, targetArea)));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Sets the area of the corresponding element type in map coordinates.
 /// </summary>
 /// <param name="area">The rectangle that defines the area.</param>
 public void SetArea(RCNumRectangle area)
 {
     if (this.metadata.IsFinalized)
     {
         throw new InvalidOperationException("Already finalized!");
     }
     if (area == RCNumRectangle.Undefined)
     {
         throw new ArgumentNullException("area");
     }
     this.area = new ConstValue <RCNumRectangle>(area);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Constructs a MinimapPixel instance.
        /// </summary>
        /// <param name="targetScenario">Reference to the target scenario.</param>
        /// <param name="pixelCoords">The coordinates of this pixel on the minimap image.</param>
        /// <param name="mapToMinimapTransformation">Coordinate transformation between the map (A) and minimap (B) coordinate-systems.</param>
        public MinimapPixel(Scenario targetScenario, RCIntVector pixelCoords, RCCoordTransformation mapToMinimapTransformation)
        {
            this.isDisposed  = false;
            this.pixelCoords = pixelCoords;

            /// Calculate the area on the map covered by this pixel.
            RCNumVector minimapPixelTopLeft     = pixelCoords - (new RCNumVector(1, 1) / 2);
            RCNumVector minimapPixelBottomRight = pixelCoords + (new RCNumVector(1, 1) / 2);
            RCNumVector mapRectTopLeft          = mapToMinimapTransformation.TransformBA(minimapPixelTopLeft);
            RCNumVector mapRectBottomRight      = mapToMinimapTransformation.TransformBA(minimapPixelBottomRight);

            this.coveredArea = new RCNumRectangle(mapRectTopLeft, mapRectBottomRight - mapRectTopLeft);
            this.coveredArea.Intersect(new RCNumRectangle(new RCNumVector(0, 0), targetScenario.Map.CellSize) - (new RCNumVector(1, 1) / 2));

            /// Find the quadratic tiles whose centers are inside the covered area.
            RCIntVector    cellRectTopLeft     = this.coveredArea.Location.Round();
            RCIntVector    cellRectBottomRight = (this.coveredArea.Location + this.coveredArea.Size).Round();
            RCIntRectangle cellRect            = new RCIntRectangle(cellRectTopLeft, cellRectBottomRight - cellRectTopLeft + new RCIntVector(1, 1));
            RCIntRectangle quadRect            = targetScenario.Map.CellToQuadRect(cellRect);

            RCIntVector coveredQuadTilesTopLeft     = RCIntVector.Undefined;
            RCIntVector coveredQuadTilesBottomRight = RCIntVector.Undefined;

            for (int quadCoordX = quadRect.Left; quadCoordX < quadRect.Right; quadCoordX++)
            {
                for (int quadCoordY = quadRect.Top; quadCoordY < quadRect.Bottom; quadCoordY++)
                {
                    RCNumRectangle quadTileRect = (RCNumRectangle)targetScenario.Map.QuadToCellRect(new RCIntRectangle(quadCoordX, quadCoordY, 1, 1))
                                                  - (new RCNumVector(1, 1) / 2);
                    RCNumVector quadTileRectCenter = (quadTileRect.Location + quadTileRect.Location + quadTileRect.Size) / 2;
                    if (this.coveredArea.Contains(quadTileRectCenter))
                    {
                        RCIntVector quadCoords = new RCIntVector(quadCoordX, quadCoordY);
                        if (coveredQuadTilesTopLeft == RCIntVector.Undefined)
                        {
                            coveredQuadTilesTopLeft = quadCoords;
                        }
                        if (coveredQuadTilesBottomRight == RCIntVector.Undefined ||
                            quadCoords.Y > coveredQuadTilesBottomRight.Y ||
                            quadCoords.X > coveredQuadTilesBottomRight.X)
                        {
                            coveredQuadTilesBottomRight = quadCoords;
                        }
                    }
                }
            }
            this.coveredQuadTiles = new RCIntRectangle(coveredQuadTilesTopLeft, coveredQuadTilesBottomRight - coveredQuadTilesTopLeft + new RCIntVector(1, 1));
        }
Exemplo n.º 11
0
        /// <see cref="IMapWindow.MapToWindowRect"/>
        public RCIntRectangle MapToWindowRect(RCNumRectangle mapRect)
        {
            if (mapRect == RCNumRectangle.Undefined)
            {
                throw new ArgumentNullException("mapRect");
            }
            if (this.isDisposed)
            {
                throw new ObjectDisposedException("IMapWindow");
            }

            RCIntVector topLeftCornerWindowCoords     = this.mapToPixelGridTransformation.TransformAB(mapRect.Location).Round() - this.pixelWindowCache.Value.Location;
            RCIntVector bottomRightCornerWindowCoords = this.mapToPixelGridTransformation.TransformAB(mapRect.Location + mapRect.Size).Round() - this.pixelWindowCache.Value.Location;

            return(new RCIntRectangle(topLeftCornerWindowCoords, bottomRightCornerWindowCoords - topLeftCornerWindowCoords + new RCIntVector(1, 1)));
        }
Exemplo n.º 12
0
        /// <see cref="ISelectionManagerBC.AddEntitiesToSelection"/>
        public void AddEntitiesToSelection(RCNumRectangle selectionBox)
        {
            if (this.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (this.localPlayer == PlayerEnum.Neutral)
            {
                throw new InvalidOperationException("Selection manager not initialized!");
            }

            this.Update();
            foreach (Entity entityToAdd in this.ActiveScenario.GetElementsOnMap <Entity>(selectionBox, MapObjectLayerEnum.AirObjects, MapObjectLayerEnum.GroundObjects))
            {
                this.AddEntityToSelection(entityToAdd);
            }
        }
Exemplo n.º 13
0
        /// <see cref="IMapWindow.WindowToMapRect"/>
        public RCNumRectangle WindowToMapRect(RCIntRectangle windowRect)
        {
            if (windowRect == RCIntRectangle.Undefined)
            {
                throw new ArgumentNullException("windowRect");
            }
            if (this.isDisposed)
            {
                throw new ObjectDisposedException("IMapWindow");
            }

            RCNumRectangle windowRectPixelCoords      = new RCNumRectangle(this.pixelWindowCache.Value.Location + windowRect.Location - MapWindowBase.HALF_VECTOR, windowRect.Size);
            RCNumVector    topLeftCornerMapCoords     = this.mapToPixelGridTransformation.TransformBA(windowRectPixelCoords.Location);
            RCNumVector    bottomRightCornerMapCoords = this.mapToPixelGridTransformation.TransformBA(windowRectPixelCoords.Location + windowRectPixelCoords.Size);

            return(new RCNumRectangle(topLeftCornerMapCoords, bottomRightCornerMapCoords - topLeftCornerMapCoords));
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the map objects inside the given area of the given layers.
        /// </summary>
        /// <param name="area">The area to search.</param>
        /// <param name="firstLayer">The first layer to search in.</param>
        /// <param name="furtherLayers">List of the further layers to search in.</param>
        /// <returns>A list that contains the map objects inside the given area of the given layers.</returns>
        public RCSet <MapObject> GetMapObjects(RCNumRectangle area, MapObjectLayerEnum firstLayer, params MapObjectLayerEnum[] furtherLayers)
        {
            if (area == RCNumRectangle.Undefined)
            {
                throw new ArgumentNullException("area");
            }
            if (furtherLayers == null)
            {
                throw new ArgumentNullException("furtherLayers");
            }

            RCSet <MapObject> retList = this.mapObjects[firstLayer].GetContents(area);

            foreach (MapObjectLayerEnum furtherLayer in furtherLayers)
            {
                retList.UnionWith(this.mapObjects[furtherLayer].GetContents(area));
            }
            return(retList);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creates a map object for this scenario element to the given location in the given layer of the map.
        /// </summary>
        /// <param name="location">The location of the created map object on the map.</param>
        /// <param name="layer">The layer of the created map object.</param>
        /// <returns>The created map object.</returns>
        protected MapObject CreateMapObject(RCNumRectangle location, MapObjectLayerEnum layer)
        {
            if (this.scenario.Read() == null)
            {
                throw new InvalidOperationException("This scenario element doesn't not belong to a scenario!");
            }
            if (location == RCNumRectangle.Undefined)
            {
                throw new ArgumentNullException("location");
            }

            MapObject mapObject = new MapObject(this);

            mapObject.SetLocation(location);
            this.mapContext.GetMapObjectLayer(layer).AttachContent(mapObject);
            this.mapObjectsOfThisElementByLayer[layer].Add(mapObject);
            this.mapObjectsOfThisElement.Add(mapObject, layer);
            return(mapObject);
        }
Exemplo n.º 17
0
        /// <see cref="IFogOfWarBC.GetAllMapObjectsInWindow"/>
        public IEnumerable <MapObject> GetAllMapObjectsInWindow(RCIntRectangle quadWindow)
        {
            if (this.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }

            /// Collect the currently visible entities inside the given window.
            RCNumRectangle    cellWindow      = (RCNumRectangle)this.ActiveScenario.Map.QuadToCellRect(quadWindow) - new RCNumVector(1, 1) / 2;
            RCSet <MapObject> mapObjectsOnMap = this.ActiveScenario.GetMapObjects(
                cellWindow,
                MapObjectLayerEnum.GroundObjects,
                MapObjectLayerEnum.GroundMissiles,
                MapObjectLayerEnum.AirObjects,
                MapObjectLayerEnum.AirMissiles);

            foreach (MapObject mapObject in mapObjectsOnMap)
            {
                if (this.runningFowsCount == 0)
                {
                    yield return(mapObject);
                }
                else
                {
                    bool breakLoop = false;
                    for (int col = mapObject.QuadraticPosition.Left; !breakLoop && col < mapObject.QuadraticPosition.Right; col++)
                    {
                        for (int row = mapObject.QuadraticPosition.Top; !breakLoop && row < mapObject.QuadraticPosition.Bottom; row++)
                        {
                            if (this.fowCacheMatrix.GetFowStateAtQuadTile(new RCIntVector(col, row)) == FOWTypeEnum.None)
                            {
                                /// Found at least 1 quadratic tile where the entity is visible.
                                yield return(mapObject);

                                breakLoop = true;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Constructs a MapObject instance.
        /// </summary>
        /// <param name="owner">Reference to the scenario element that owns this map object.</param>
        public MapObject(ScenarioElement owner)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            if (owner.ElementType.AnimationPalette == null)
            {
                throw new ArgumentException("The type of the given scenario element has no animation palette defined!", "owner");
            }

            this.currentAnimations      = new AnimationPlayer[owner.ElementType.AnimationPalette.Count];
            this.quadraticPositionCache = new CachedValue <RCIntRectangle>(() =>
            {
                RCIntVector topLeft     = this.location.Location.Round();
                RCIntVector bottomRight = (this.location.Location + this.location.Size).Round();
                RCIntRectangle cellRect = new RCIntRectangle(topLeft.X, topLeft.Y, Math.Max(1, bottomRight.X - topLeft.X), Math.Max(1, bottomRight.Y - topLeft.Y));
                return(this.owner.Scenario.Map.CellToQuadRect(cellRect));
            });

            this.quadraticShadowPositionCache = new CachedValue <RCIntRectangle>(() =>
            {
                if (this.owner.ElementType.ShadowOffset == RCNumVector.Undefined || this.shadowTransition == new RCNumVector(0, 0))
                {
                    return(RCIntRectangle.Undefined);
                }
                RCNumRectangle shiftedLocation = this.location + (this.owner.ElementType.ShadowOffset + this.shadowTransition - this.location.Size / 2);
                RCIntVector topLeft            = shiftedLocation.Location.Round();
                RCIntVector bottomRight        = (shiftedLocation.Location + shiftedLocation.Size).Round();
                RCIntRectangle cellRect        = new RCIntRectangle(topLeft.X, topLeft.Y, Math.Max(1, bottomRight.X - topLeft.X), Math.Max(1, bottomRight.Y - topLeft.Y));
                return(this.owner.Scenario.Map.CellToQuadRect(cellRect));
            });

            this.owner            = owner;
            this.location         = RCNumRectangle.Undefined;
            this.shadowTransition = new RCNumVector(0, 0);
        }
Exemplo n.º 19
0
        /// <see cref="ISelectionManagerBC.SelectEntitiesOfTheSameType"/>
        public void SelectEntitiesOfTheSameType(RCNumVector position, RCNumRectangle selectionBox)
        {
            if (this.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (this.localPlayer == PlayerEnum.Neutral)
            {
                throw new InvalidOperationException("Selection manager not initialized!");
            }

            Entity entityAtPos = this.ActiveScenario.GetElementsOnMap <Entity>(position, MapObjectLayerEnum.AirObjects, MapObjectLayerEnum.GroundObjects).FirstOrDefault();

            if (entityAtPos == null)
            {
                return;
            }

            this.currentSelection.Clear();
            if (BizLogicHelpers.GetMapObjectCurrentOwner(entityAtPos.MapObject) == this.localPlayer &&
                entityAtPos is Unit)
            {
                foreach (Entity entityToAdd in this.ActiveScenario.GetElementsOnMap <Entity>(selectionBox, MapObjectLayerEnum.AirObjects, MapObjectLayerEnum.GroundObjects))
                {
                    if (BizLogicHelpers.GetMapObjectCurrentOwner(entityToAdd.MapObject) == this.localPlayer &&
                        entityToAdd.ElementType == entityAtPos.ElementType) // TODO: this might be problematic in case of Terran Siege Tanks!
                    {
                        this.AddEntityToSelection(entityToAdd);
                    }
                }
            }
            else
            {
                this.AddEntityToSelection(entityAtPos);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Updates the velocity and position of this entity.
        /// </summary>
        public void Update()
        {
            if (this.currentSpeed != 0 || !this.Position.Contains(this.goal))
            {
                this.CalculateAdmissibleVelocities();
                MotionController.UpdateVelocity(this, this, this);
            }

            if (this.selectedVelocity != null)
            {
                this.currentSpeed     = this.selectedVelocity.Item1;
                this.currentDirection = this.selectedVelocity.Item2;
                this.selectedVelocity = null;

                RCNumRectangle newPosition = new RCNumRectangle(this.currentPosition + this.Velocity - this.size / 2, this.size);
                foreach (TestEntity collideWith in this.entities.GetContents(newPosition))
                {
                    if (collideWith != this)
                    {
                        this.currentSpeed     = 0;
                        this.currentDirection = MapDirection.North;
                        return;
                    }
                }

                if (this.BoundingBoxChanging != null)
                {
                    this.BoundingBoxChanging(this);
                }
                this.currentPosition += this.Velocity;
                if (this.BoundingBoxChanged != null)
                {
                    this.BoundingBoxChanged(this);
                }
            }
        }
Exemplo n.º 21
0
        /// <see cref="IMapEditorService.DrawTerrain"/>
        public void DrawTerrain(RCIntVector position, string terrainType)
        {
            if (this.scenarioManager.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (position == RCIntVector.Undefined)
            {
                throw new ArgumentNullException("position");
            }
            if (terrainType == null)
            {
                throw new ArgumentNullException("terrainType");
            }

            RCIntVector navCellCoords = this.mapWindowBC.AttachedWindow.WindowToMapCoords(position).Round();
            IIsoTile    isotile       = this.scenarioManager.ActiveScenario.Map.GetCell(navCellCoords).ParentIsoTile;

            IEnumerable <IIsoTile> affectedIsoTiles = this.mapEditor.DrawTerrain(this.scenarioManager.ActiveScenario.Map, isotile,
                                                                                 this.scenarioManager.ActiveScenario.Map.Tileset.GetTerrainType(terrainType));

            foreach (IIsoTile affectedIsoTile in affectedIsoTiles)
            {
                RCNumRectangle isoTileRect = new RCNumRectangle(affectedIsoTile.GetCellMapCoords(new RCIntVector(0, 0)), affectedIsoTile.CellSize)
                                             - new RCNumVector(1, 1) / 2;
                foreach (Entity affectedEntity in this.scenarioManager.ActiveScenario.GetElementsOnMap <Entity>(isoTileRect, 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();
                    }
                }
            }
        }
Exemplo n.º 22
0
 public TestContent(RCNumRectangle initialPos)
 {
     this.currentPosition = initialPos;
 }
Exemplo n.º 23
0
        /// <see cref="ISelectionManagerBC.SelectEntities"/>
        public void SelectEntities(RCNumRectangle selectionBox)
        {
            if (this.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (this.localPlayer == PlayerEnum.Neutral)
            {
                throw new InvalidOperationException("Selection manager not initialized!");
            }

            bool           localPlayerUnitFound = false;
            Entity         localPlayerBuilding  = null;
            Entity         localPlayerAddon     = null;
            Entity         otherPlayerUnit      = null;
            Entity         otherPlayerBuilding  = null;
            Entity         otherPlayerAddon     = null;
            Entity         other         = null;
            RCSet <Entity> entitiesInBox = this.ActiveScenario.GetElementsOnMap <Entity>(selectionBox, MapObjectLayerEnum.AirObjects, MapObjectLayerEnum.GroundObjects);

            if (entitiesInBox.Count == 0)
            {
                return;
            }
            foreach (Entity entity in entitiesInBox)
            {
                if (entity is Unit)
                {
                    /// If the entity is a unit then check its owner.
                    if (entity.Owner != null && entity.Owner.PlayerIndex == (int)this.localPlayer)
                    {
                        /// If owned by the local player then add it to the current selection.
                        if (!localPlayerUnitFound)
                        {
                            this.currentSelection.Clear();
                            localPlayerUnitFound = true;
                        }

                        this.currentSelection.Add(entity.ID.Read());
                        if (this.currentSelection.Count == MAX_SELECTION_SIZE)
                        {
                            break;
                        }
                    }
                    else if (otherPlayerUnit == null && !localPlayerUnitFound)
                    {
                        /// If owned by another player then save its reference.
                        otherPlayerUnit = entity;
                    }
                }
                else if (entity is Building && !localPlayerUnitFound)
                {
                    /// If the entity is a building then check its owner.
                    if (entity.Owner != null && entity.Owner.PlayerIndex == (int)this.localPlayer)
                    {
                        if (localPlayerBuilding == null)
                        {
                            localPlayerBuilding = entity;
                        }
                    }
                    else if (otherPlayerBuilding == null)
                    {
                        otherPlayerBuilding = entity;
                    }
                }
                else if (entity is Addon && !localPlayerUnitFound)
                {
                    /// If the entity is an addon then check its owner.
                    if (entity.Owner != null && entity.Owner.PlayerIndex == (int)this.localPlayer)
                    {
                        if (localPlayerAddon == null)
                        {
                            localPlayerAddon = entity;
                        }
                    }
                    else if (otherPlayerAddon == null)
                    {
                        otherPlayerAddon = entity;
                    }
                }
                else if (other == null)
                {
                    other = entity;
                }
            }

            if (localPlayerUnitFound)
            {
                return;
            }

            this.currentSelection.Clear();
            if (localPlayerBuilding != null)
            {
                this.currentSelection.Add(localPlayerBuilding.ID.Read()); return;
            }
            if (localPlayerAddon != null)
            {
                this.currentSelection.Add(localPlayerAddon.ID.Read()); return;
            }
            if (otherPlayerUnit != null)
            {
                this.currentSelection.Add(otherPlayerUnit.ID.Read()); return;
            }
            if (otherPlayerBuilding != null)
            {
                this.currentSelection.Add(otherPlayerBuilding.ID.Read()); return;
            }
            if (otherPlayerAddon != null)
            {
                this.currentSelection.Add(otherPlayerAddon.ID.Read()); return;
            }
            if (other != null)
            {
                this.currentSelection.Add(other.ID.Read()); return;
            }
        }