/// <summary> /// Checks whether this placement constraint allows placing an entity of the corresponding type to the given scenario at the given /// quadratic position and collects all the violating quadratic coordinates relative to the given position. /// </summary> /// <param name="scenario">Reference to the given scenario.</param> /// <param name="position">The position to be checked.</param> /// <param name="entitiesToIgnore"> /// The list of entities to be ignored during the check. All entities in this list shall belong to the given scenario. /// </param> /// <returns> /// The list of the quadratic coordinates (relative to the given position) violating this placement constraint. /// </returns> public RCSet <RCIntVector> Check(Scenario scenario, RCIntVector position, RCSet <Entity> entitiesToIgnore) { if (this.entityType == null) { throw new SimulatorException("Entity type has not yet been set for this constraint!"); } if (scenario == null) { throw new ArgumentNullException("scenario"); } if (position == RCIntVector.Undefined) { throw new ArgumentNullException("position"); } if (entitiesToIgnore == null) { throw new ArgumentNullException("entitiesToIgnore"); } if (entitiesToIgnore.Any(entityToIgnore => entityToIgnore.Scenario != scenario)) { throw new ArgumentException("All entities to be ignored shall belong to the given scenario!", "entitiesToIgnore"); } return(this.CheckImpl(scenario, position, entitiesToIgnore)); }
/// <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); }
/// <summary> /// Checks the availability of the Repair command for the given SCVs. /// </summary> /// <param name="scvsToHandle">The SCVs to check.</param> /// <param name="fullEntitySet">The set of selected entities.</param> /// <returns>The availability of the Repair command for the given SCVs.</returns> private AvailabilityEnum CheckRepairAvailability(RCSet <SCV> scvsToHandle, RCSet <Entity> fullEntitySet) { if (scvsToHandle.Count != fullEntitySet.Count) { return(AvailabilityEnum.Unavailable); } return(scvsToHandle.Any(scv => !scv.IsConstructing) ? AvailabilityEnum.Enabled : AvailabilityEnum.Unavailable); }
/// <summary> /// Checks the availability of the Return command for the given SCVs. /// </summary> /// <param name="scvsToHandle">The SCVs to check.</param> /// <param name="fullEntitySet">The set of selected entities.</param> /// <returns>The availability of the Return command for the given SCVs.</returns> private AvailabilityEnum CheckReturnAvailability(RCSet <SCV> scvsToHandle, RCSet <Entity> fullEntitySet) { if (scvsToHandle.Count != fullEntitySet.Count) { return(AvailabilityEnum.Unavailable); } return(scvsToHandle.Any(scv => !scv.IsConstructing) ? AvailabilityEnum.Enabled : AvailabilityEnum.Unavailable); /// TODO: implement this method! }
/// <see cref="CommandExecutionFactoryBase.GetCommandAvailability"/> protected override AvailabilityEnum GetCommandAvailability(RCSet <T> entitiesToHandle, RCSet <Entity> fullEntitySet, string parameter) { /// Check if all the entities to handle are owned by the same player. Player owner = entitiesToHandle.First().Owner; if (entitiesToHandle.Any(entity => entity.Owner != owner)) { throw new InvalidOperationException("Entities with different player sent to SpecialAbilityExecutionFactory!"); } /// If the entities to handle are neutral -> the command is unavailable. if (owner == null) { return(AvailabilityEnum.Unavailable); } /// Enable the special ability execution if the owner player has the necessary research. return(owner.GetUpgradeStatus(this.CommandType) == UpgradeStatus.Researched ? AvailabilityEnum.Enabled : AvailabilityEnum.Disabled); }
/// <summary> /// Checks the availability of the basic commands for the given SCVs. /// </summary> /// <param name="scvsToHandle">The SCVs to check.</param> /// <returns>The availability of the basic commands for the given SCVs.</returns> private AvailabilityEnum CheckBasicCommandAvailability(RCSet <SCV> scvsToHandle) { return(scvsToHandle.Any(scv => !scv.IsConstructing) ? AvailabilityEnum.Enabled : AvailabilityEnum.Unavailable); }