/// <summary> /// Selects a FormationStation slot for the provided (non-HQ) element based on the selection constraints /// provided, and then calls Command.PositionElementInFormation() using the slot selected. /// </summary> /// <param name="element">The element.</param> /// <param name="selectionConstraint">The selection constraint.</param> public void AddAndPositionNonHQElement(IUnitElement element, FormationStationSelectionCriteria selectionConstraint) { D.Assert(!element.IsHQ); AddAndPositionElement(element, selectionConstraint); }
/// <summary> /// Returns <c>true</c> if a FormationStation (slot) that matches the <c>selectionConstraint</c> is available for assignment. /// </summary> /// <param name="selectionConstraint">The selection constraint.</param> /// <returns></returns> public bool IsSlotAvailable(FormationStationSelectionCriteria selectionConstraint) { D.Assert(_availableStationSlots.Where(sInfo => sInfo.IsHQSlot).IsNullOrEmpty()); // HQ slot should never be available here return _availableStationSlots.Where(sInfo => sInfo.IsReserve == selectionConstraint.IsReserveReqd).Any(); }
private FormationStationSlotInfo SelectAndRecordSlotAsOccupied(IUnitElement element, FormationStationSelectionCriteria selectionConstraints) { bool isRemoved; FormationStationSlotInfo slotInfo; if (_occupiedStationSlotLookup.TryGetValue(element, out slotInfo)) { // return element's existing slotInfo BEFORE selecting another isRemoved = _occupiedStationSlotLookup.Remove(element); D.Assert(isRemoved, element.DebugName); _availableStationSlots.Add(slotInfo); } slotInfo = SelectSlotInfoFor(element, selectionConstraints); isRemoved = _availableStationSlots.Remove(slotInfo); D.Assert(isRemoved, slotInfo.ToString()); _occupiedStationSlotLookup.Add(element, slotInfo); return slotInfo; }
/// <summary> /// TEMP method that selects the stationSlot for the provided element based off of /// the provided selectionConstraints. /// </summary> /// <param name="element">The element.</param> /// <param name="selectionConstraints">The selection constraints.</param> /// <returns></returns> private FormationStationSlotInfo SelectSlotInfoFor(IUnitElement element, FormationStationSelectionCriteria selectionConstraints) { if (element.IsHQ) { //D.Log(ShowDebugLog, "{0} is about to validate {1} is only HQ.", DebugName, element.DebugName); __ValidateSingleHqSlotAvailable(); return _availableStationSlots.Single(sInfo => sInfo.IsHQSlot); // 7.15.16 Single violation recorded } FormationStationSlotInfo result = _availableStationSlots.Where(sInfo => !sInfo.IsHQSlot && sInfo.IsReserve == selectionConstraints.IsReserveReqd).FirstOrDefault(); if (result == default(FormationStationSlotInfo)) { result = _availableStationSlots.Where(sInfo => !sInfo.IsHQSlot).FirstOrDefault(); } if (result == default(FormationStationSlotInfo)) { D.Error("{0}: Cannot find {1} meeting Constraint {2} for {3}.", DebugName, typeof(FormationStationSlotInfo).Name, selectionConstraints, element.DebugName); } return result; }
/// <summary> /// Selects a FormationStation slot for the provided element based on the selection constraints /// provided, if any, and then calls Command.PositionElementInFormation() using the slot selected. /// </summary> /// <param name="element">The element.</param> /// <param name="selectionConstraint">The selection constraint.</param> private void AddAndPositionElement(IUnitElement element, FormationStationSelectionCriteria selectionConstraint = default(FormationStationSelectionCriteria)) { var slotInfo = SelectAndRecordSlotAsOccupied(element, selectionConstraint); _unitCmd.PositionElementInFormation(element, slotInfo); }