示例#1
0
        /// <summary>
        /// Creates command executions for undefined command type.
        /// </summary>
        /// <param name="scvsToHandle">The SCVs to order.</param>
        /// <param name="fullEntitySet">The set of selected entities.</param>
        /// <param name="targetPosition">The target position.</param>
        /// <param name="targetEntityID">The ID of the target entity or -1 if undefined.</param>
        private IEnumerable <CmdExecutionBase> CreateUndefinedExecutions(RCSet <SCV> scvsToHandle, RCSet <Entity> fullEntitySet, RCNumVector targetPosition, int targetEntityID)
        {
            Entity         targetEntity   = scvsToHandle.First().Scenario.GetElementOnMap <Entity>(targetEntityID, MapObjectLayerEnum.GroundObjects);
            TerranBuilding targetBuilding = targetEntity as TerranBuilding;

            MagicBox magicBox = new MagicBox(fullEntitySet, targetPosition);

            foreach (SCV scv in scvsToHandle.Where(scv => !scv.IsConstructing))
            {
                if (targetBuilding != null && targetBuilding.Owner == scv.Owner &&
                    targetBuilding.ConstructionJob != null && !targetBuilding.ConstructionJob.IsFinished &&
                    targetBuilding.ConstructionJob.AttachedSCV == null)
                {
                    /// The target entity is a friendly Terran building that is under construction but its construction is
                    /// not currently in progress -> start a continue build command.
                    yield return(new SCVContinueBuildExecution(scv, targetPosition, targetBuilding.ID.Read()));
                }
                else if (targetEntity != null && targetEntity.Owner == scv.Owner && this.IsValidTargetForRepair(targetEntity))
                {
                    /// The target entity is a friendly entity and is valid for a repair command -> start a repair command.
                    yield return(new SCVRepairExecution(scv, targetPosition, targetEntityID));
                }
                else if (targetEntity != null && targetEntity.Owner != null && targetEntity.Owner != scv.Owner)
                {
                    /// The target entity is an enemy entity -> start an attack execution.
                    yield return(new AttackExecution(scv, magicBox.GetTargetPosition(scv), targetEntityID));
                }
                else
                {
                    /// In any other cases -> start a move execution.
                    yield return(new MoveExecution(scv, magicBox.GetTargetPosition(scv), targetEntityID));
                }
                /// TODO: Handle the cases for Repair, Gather and Return commands!
            }
        }
示例#2
0
 /// <summary>
 /// Creates hold executions for the given SCVs.
 /// </summary>
 /// <param name="scvsToHandle">The SCVs to hold.</param>
 private IEnumerable <CmdExecutionBase> CreateHoldExecutions(RCSet <SCV> scvsToHandle)
 {
     foreach (SCV scv in scvsToHandle.Where(scv => !scv.IsConstructing))
     {
         yield return(new HoldExecution(scv));
     }
 }
示例#3
0
 /// <summary>
 /// Creates build executions for the given SCVs.
 /// </summary>
 /// <param name="scvsToHandle">The SCVs to build.</param>
 /// <param name="topLeftQuadTile">The coordinates of the top-left quadratic tile of the building.</param>
 /// <param name="buildingType">The type of the building.</param>
 private IEnumerable <CmdExecutionBase> CreateBuildExecutions(RCSet <SCV> scvsToHandle, RCIntVector topLeftQuadTile, string buildingType)
 {
     foreach (SCV scv in scvsToHandle.Where(scv => !scv.IsConstructing))
     {
         yield return(new SCVStartBuildExecution(scv, buildingType, topLeftQuadTile));
     }
 }
示例#4
0
        /// <summary>
        /// Creates patrol executions for the given SCVs.
        /// </summary>
        /// <param name="scvsToHandle">The SCVs to patrol.</param>
        /// <param name="fullEntitySet">The set of selected entities.</param>
        /// <param name="targetPosition">The target position.</param>
        private IEnumerable <CmdExecutionBase> CreatePatrolExecutions(RCSet <SCV> scvsToHandle, RCSet <Entity> fullEntitySet, RCNumVector targetPosition)
        {
            MagicBox magicBox = new MagicBox(fullEntitySet, targetPosition);

            foreach (SCV scv in scvsToHandle.Where(scv => !scv.IsConstructing))
            {
                yield return(new PatrolExecution(scv, magicBox.GetTargetPosition(scv)));
            }
        }
示例#5
0
 /// <summary>
 /// Adds the given static agent to this sector for moving agents of the given size or bigger.
 /// </summary>
 /// <param name="movingSize">The given moving agent size.</param>
 /// <param name="agent">The agent to be added.</param>
 public void AddStaticAgent(int movingSize, Agent agent)
 {
     for (int size = movingSize; size <= this.grid.MaxMovingSize; size++)
     {
         if (this.staticAgents[size - 1].Add(agent))
         {
             RCSet <SectorSubdivision> subdivisionsCopy = new RCSet <SectorSubdivision>(this.subdivisions);
             foreach (SectorSubdivision subdivisionToInvalidate in subdivisionsCopy.Where(subdivision => subdivision.MovingSize == size))
             {
                 subdivisionToInvalidate.Invalidate();
                 this.subdivisions.Remove(subdivisionToInvalidate);
             }
         }
     }
 }
示例#6
0
        /// <summary>
        /// Creates repair executions for the given SCVs.
        /// </summary>
        /// <param name="scvsToHandle">The reapiring SCVs.</param>
        /// <param name="targetPosition">The target position.</param>
        /// <param name="targetEntityID">The ID of the target entity or -1 if undefined.</param>
        private IEnumerable <CmdExecutionBase> CreateRepairExecutions(RCSet <SCV> scvsToHandle, RCNumVector targetPosition, int targetEntityID)
        {
            MagicBox magicBox = new MagicBox(new RCSet <Entity>(scvsToHandle), targetPosition);

            Entity targetEntity = scvsToHandle.First().Scenario.GetElementOnMap <Entity>(targetEntityID, MapObjectLayerEnum.GroundObjects, MapObjectLayerEnum.AirObjects);

            if (targetEntity == null)
            {
                /// If there is no target entity -> create simple move executions.
                foreach (SCV scv in scvsToHandle.Where(scv => !scv.IsConstructing))
                {
                    yield return(new MoveExecution(scv, magicBox.GetTargetPosition(scv), targetEntityID));
                }
            }

            /// Create the repair command executions if the target is valid for a repair command.
            if (this.IsValidTargetForRepair(targetEntity))
            {
                foreach (SCV scv in scvsToHandle.Where(scv => !scv.IsConstructing))
                {
                    yield return(new SCVRepairExecution(scv, targetPosition, targetEntityID));
                }
            }
        }
示例#7
0
        /// <summary>
        /// Checks whether the given cell is walkable from the point of view of this subdivision.
        /// </summary>
        /// <param name="cell">The checked cell.</param>
        /// <returns>True if the given cell is walkable from the point of view of this subdivision; otherwise false.</returns>
        public bool IsCellWalkable(Cell cell)
        {
            if (cell.WallCellDistance < this.movingSize)
            {
                return(false);
            }

            RCSet <Agent> agentsAtCell = cell.GetAgents(this.movingSize);

            foreach (Agent staticAgent in agentsAtCell.Where(agent => agent.MovingStatus == AgentMovingStatusEnum.Static))
            {
                if (!this.overlapEnabledAgents.Contains(staticAgent))
                {
                    return(false);
                }
            }
            return(true);
        }