Exemplo n.º 1
0
        /// <summary>
        /// Adds the given entity to the current selection if possible.
        /// </summary>
        /// <param name="entityToAdd">The entity to be added to the current selection if possible.</param>
        private void AddEntityToSelection(Entity entityToAdd)
        {
            if (this.currentSelection.Count == MAX_SELECTION_SIZE)
            {
                return;
            }

            List <Entity> currentSelection = this.GetSelectedEntities();

            if (currentSelection.Count == 0)
            {
                /// Empty selection -> simply add the entity.
                this.currentSelection.Add(entityToAdd.ID.Read());
                return;
            }

            if (currentSelection.Count == 1 &&
                BizLogicHelpers.GetMapObjectCurrentOwner(currentSelection[0].MapObject) == this.localPlayer &&
                BizLogicHelpers.GetMapObjectCurrentOwner(entityToAdd.MapObject) == this.localPlayer &&
                currentSelection[0] is Unit &&
                entityToAdd is Unit)
            {
                /// Only 1 entity is selected -> add if both the new and the selected entities are units and owned by the local player.
                this.currentSelection.Add(entityToAdd.ID.Read());
                return;
            }

            if (currentSelection.TrueForAll(selectedEntity =>
                                            BizLogicHelpers.GetMapObjectCurrentOwner(selectedEntity.MapObject) == this.localPlayer &&
                                            BizLogicHelpers.GetMapObjectCurrentOwner(entityToAdd.MapObject) == this.localPlayer &&
                                            selectedEntity is Unit) &&
                entityToAdd is Unit)
            {
                /// Multiple entities are selected -> add if all selected entities and the new entity are units and owned by the local player.
                this.currentSelection.Add(entityToAdd.ID.Read());
                return;
            }
        }
Exemplo n.º 2
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);
            }
        }