Beispiel #1
0
        /// <summary>
        /// Collect the shadow sprites of the given map object into the given list.
        /// </summary>
        /// <param name="mapObject">The given map object.</param>
        /// <param name="targetList">The given target list.</param>
        private void CollectMapObjectShadowSprites(MapObject mapObject, ref List <Tuple <SpriteRenderInfo, PlayerEnum> > targetList)
        {
            if (mapObject.ShadowCenter != RCNumVector.Undefined)
            {
                /// This map object has a shadow to be rendered -> calculate the display coordinates of the shadow
                RCIntVector    shadowCenterOnDisplay = this.MapWindowBC.AttachedWindow.MapToWindowCoords(mapObject.ShadowCenter);
                RCIntRectangle shadowSection         = this.scenarioManagerBC.Metadata.ShadowPalette.GetSection(mapObject.Owner.ElementType.ShadowSpriteIndex);
                RCIntVector    shadowDisplayCoords   = shadowCenterOnDisplay - (shadowSection.Size / 2);

                /// Ensure that overlapping shadows won't overlie the terrain.
                if ((shadowDisplayCoords.X + shadowDisplayCoords.Y) % 2 != 0)
                {
                    shadowDisplayCoords += new RCIntVector(1, 0);
                }

                /// Create the sprite render info from the calculated display coordinates.
                targetList.Add(Tuple.Create(new SpriteRenderInfo()
                {
                    SpriteGroup   = SpriteGroupEnum.MapObjectShadowSpriteGroup,
                    Index         = this.scenarioManagerBC.Metadata.ShadowPalette.Index,
                    DisplayCoords = shadowDisplayCoords,
                    Section       = shadowSection
                }, BizLogicHelpers.GetMapObjectLastOwner(mapObject)));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a snapshot of the given source Entity at the current simulation frame of the Scenario it belongs to.
        /// </summary>
        /// <param name="sourceEntity">The source Entity of this snapshot.</param>
        /// <exception cref="ArgumentException">If the source Entity doesn't belong to a Scenario.</exception>
        public EntitySnapshot(Entity sourceEntity)
        {
            if (sourceEntity == null)
            {
                throw new ArgumentNullException("sourceEntity");
            }
            if (sourceEntity.Scenario == null)
            {
                throw new ArgumentException("The source Entity doesn't belong to a scenario!");
            }
            if (!sourceEntity.HasMapObject(MapObjectLayerEnum.GroundObjects, MapObjectLayerEnum.AirObjects))
            {
                throw new ArgumentException("The source Entity is not attached to the map!");
            }

            /// Copy some properties of the source entity.
            this.id                = sourceEntity.ID.Read();
            this.timeStamp         = sourceEntity.Scenario.CurrentFrameIndex;
            this.position          = sourceEntity.Area;
            this.entityType        = sourceEntity.ElementType;
            this.quadraticPosition = sourceEntity.MapObject.QuadraticPosition;

            /// Save the current animation frame of the source entity.
            List <int> spriteIndices = new List <int>();

            foreach (AnimationPlayer animation in sourceEntity.MapObject.CurrentAnimations)
            {
                spriteIndices.AddRange(animation.CurrentFrame);
            }
            this.animationFrame = spriteIndices.ToArray();

            /// Save the last known owner player of the source entity.
            this.owner = BizLogicHelpers.GetMapObjectLastOwner(sourceEntity.MapObject);
        }
Beispiel #3
0
        /// <see cref="IMinimapView.RefreshPixelInfos"/>
        public void RefreshPixelInfos(int firstRowIndex, int rowsCount, MinimapPixelInfo[,] pixelInfos)
        {
            if (firstRowIndex < 0)
            {
                throw new ArgumentOutOfRangeException("firstRowIndex", "The index of the first row must be non-negative!");
            }
            if (firstRowIndex >= this.MapWindowBC.Minimap.MinimapPosition.Height)
            {
                throw new ArgumentOutOfRangeException("firstRowIndex", "The index of the first row must be less than the height of the minimap image!");
            }
            if (rowsCount < 1)
            {
                throw new ArgumentOutOfRangeException("rowsCount", "The number of scanned rows must be positive!");
            }

            /// Collect the FOW-status of the scanned pixels.
            for (int row = firstRowIndex; row < firstRowIndex + rowsCount && row < this.MapWindowBC.Minimap.MinimapPosition.Height; row++)
            {
                for (int col = 0; col < this.MapWindowBC.Minimap.MinimapPosition.Width; col++)
                {
                    RCIntVector pixelCoords = new RCIntVector(col, row);
                    pixelInfos[col, row].PixelCoords         = pixelCoords;
                    pixelInfos[col, row].FOWStatus           = this.GetFowStateAtPixel(pixelCoords);
                    pixelInfos[col, row].EntityIndicatorType = MinimapPixelInfo.EntityIndicatorTypeEnum.None;
                }
            }

            /// Collect the entity informations.
            RCIntRectangle topLeftQuadRect =
                this.MapWindowBC.Minimap.GetMinimapPixel(new RCIntVector(0, firstRowIndex)).CoveredQuadTiles;
            RCIntRectangle bottomRightQuadRect =
                this.MapWindowBC.Minimap.GetMinimapPixel(new RCIntVector(this.MapWindowBC.Minimap.MinimapPosition.Width - 1, firstRowIndex + rowsCount - 1)).CoveredQuadTiles;
            RCIntVector    topLeftQuadTile     = topLeftQuadRect.Location;
            RCIntVector    bottomRightQuadTile = bottomRightQuadRect.Location + bottomRightQuadRect.Size;
            RCIntRectangle scannedQuadWindow   = new RCIntRectangle(topLeftQuadTile, bottomRightQuadTile - topLeftQuadTile);

            foreach (MapObject mapObject in this.fogOfWarBC.GetAllMapObjectsInWindow(scannedQuadWindow))
            {
                Entity entity = mapObject.Owner as Entity;
                if (entity != null)
                {
                    bool attackSignal = entity.Biometrics.FrameIndexOfLastEnemyDamage != -1 &&
                                        entity.Scenario.CurrentFrameIndex - entity.Biometrics.FrameIndexOfLastEnemyDamage <= ATTACK_INDICATION_DURATION;
                    this.AddEntityInfo(mapObject.QuadraticPosition, BizLogicHelpers.GetMapObjectCurrentOwner(mapObject), attackSignal, pixelInfos);
                }
            }
            foreach (EntitySnapshot entitySnapshot in this.fogOfWarBC.GetEntitySnapshotsInWindow(scannedQuadWindow))
            {
                this.AddEntityInfo(entitySnapshot.QuadraticPosition, entitySnapshot.Owner, false, pixelInfos);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Collect the sprites of the given map object into the given list.
        /// </summary>
        /// <param name="mapObject">The given map object.</param>
        /// <param name="targetList">The given target list.</param>
        private void CollectMapObjectSprites(MapObject mapObject, ref List <Tuple <SpriteRenderInfo, PlayerEnum> > targetList)
        {
            RCIntRectangle displayRect = this.MapWindowBC.AttachedWindow.MapToWindowRect(mapObject.BoundingBox);

            foreach (AnimationPlayer animation in mapObject.CurrentAnimations)
            {
                foreach (int spriteIdx in animation.CurrentFrame)
                {
                    targetList.Add(Tuple.Create(new SpriteRenderInfo()
                    {
                        SpriteGroup   = SpriteGroupEnum.MapObjectSpriteGroup,
                        Index         = mapObject.Owner.ElementType.SpritePalette.Index,
                        DisplayCoords = displayRect.Location + mapObject.Owner.ElementType.SpritePalette.GetOffset(spriteIdx),
                        Section       = mapObject.Owner.ElementType.SpritePalette.GetSection(spriteIdx)
                    }, BizLogicHelpers.GetMapObjectLastOwner(mapObject)));
                }
            }
        }