/// <summary>
        /// Repositions all the Unit elements in the formation designated by the Cmd.
        /// Called when 1) a fleet is first formed, 2) the desired formation has changed, 3) the HQ Element has changed,
        /// or 4) when another large fleet joins this one.
        /// <remarks>Repositioning is accomplished by calling Cmd.PositionElementInFormation().</remarks>
        /// </summary>
        /// <param name="allElements">All elements.</param>
        public void RepositionAllElementsInFormation(IList<IUnitElement> allElements) {
            Formation formation = _unitCmd.UnitFormation;
            if (formation != _currentFormation) {
                _occupiedStationSlotLookup.Clear();
                float formationRadius;
                _availableStationSlots = GenerateFormationSlotInfo(formation, _unitCmd.transform, out formationRadius);
                //D.Log(ShowDebugLog, "{0} generated {1} {2}s for Formation {3} => {4}.", DebugName, _availableStationSlots.Count, typeof(FormationStationSlotInfo).Name, formation.GetValueName(), _availableStationSlots.Concatenate());
                _unitCmd.UnitMaxFormationRadius = formationRadius;
                _currentFormation = formation;
            }
            else {
                ReturnAllOccupiedStationSlotsToAvailable();
            }

            int hqCount = Constants.Zero;
            allElements.ForAll(e => {
                if (e.IsHQ) {
                    hqCount++;
                }
                AddAndPositionElement(e);
            });
            D.AssertEqual(Constants.One, hqCount);
        }
Example #2
0
    /// <summary>
    /// Detaches one or more sensors from this command's SensorRangeMonitors.
    /// Note: Sensors are part of a Unit's elements but the monitors they attach to
    /// are children of the Command. Thus sensor range is always measured from
    /// the Command, not from the element.
    /// </summary>
    /// <param name="sensors">The sensors.</param>
    private void DetachSensorsFromMonitors(IList<Sensor> sensors) {
        sensors.ForAll(sensor => {
            var monitor = sensor.RangeMonitor;
            bool isRangeMonitorStillInUse = monitor.Remove(sensor);

            if (!isRangeMonitorStillInUse) {
                monitor.enemyTargetsInRange -= EnemyTargetsInSensorRangeChangedEventHandler;
                monitor.Reset();    // OPTIMIZE either reset or destroy, not both
                SensorRangeMonitors.Remove(monitor);
                //D.Log(ShowDebugLog, "{0} is destroying unused {1} as a result of removing {2}.", DebugName, typeof(SensorRangeMonitor).Name, sensor.Name);
                GameUtility.DestroyIfNotNullOrAlreadyDestroyed(monitor);
            }
        });
    }
Example #3
0
 /// <summary>
 /// Attaches one or more sensors to this command's SensorRangeMonitors.
 /// Note: Sensors are part of a Unit's elements but the monitors they attach to
 /// are children of the Command. Thus sensor range is always measured from
 /// the Command, not from the element.
 /// </summary>
 /// <param name="sensors">The sensors.</param>
 private void AttachSensorsToMonitors(IList<Sensor> sensors) {
     sensors.ForAll(sensor => {
         var monitor = UnitFactory.Instance.AttachSensorToCmdsMonitor(sensor, this);
         if (!SensorRangeMonitors.Contains(monitor)) {
             // only need to record and setup range monitors once. The same monitor can have more than 1 sensor
             SensorRangeMonitors.Add(monitor);
             monitor.enemyTargetsInRange += EnemyTargetsInSensorRangeChangedEventHandler;
         }
     });
 }
 protected void SetRootNodes(IEnumerable<TreeViewItemViewModel> source, string defaultText = "")
 {
     _currentRootNodesViewModel = source.ToList();
       if (_currentRootNodesViewModel.Count == 0 && !string.IsNullOrEmpty(defaultText)) {
     _currentRootNodesViewModel.Add(new TextItemViewModel(_imageSourceFactory, null, defaultText));
       }
       _rootNodes.Clear();
       _currentRootNodesViewModel.ForAll(x => _rootNodes.Add(x));
 }