Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AUnitElementItemData" /> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="owner">The owner.</param>
 /// <param name="passiveCMs">The passive countermeasures.</param>
 /// <param name="hullEquipment">The hull equipment.</param>
 /// <param name="activeCMs">The active countermeasures.</param>
 /// <param name="sensors">The sensors.</param>
 /// <param name="shieldGenerators">The shield generators.</param>
 /// <param name="hqPriority">The HQ priority.</param>
 public AUnitElementData(IUnitElement element, Player owner, IEnumerable<PassiveCountermeasure> passiveCMs, AHullEquipment hullEquipment,
     IEnumerable<ActiveCountermeasure> activeCMs, IEnumerable<Sensor> sensors, IEnumerable<ShieldGenerator> shieldGenerators, Priority hqPriority)
     : base(element, owner, hullEquipment.MaxHitPoints, passiveCMs) {
     HullEquipment = hullEquipment;
     Mass = hullEquipment.Mass + hullEquipment.Weapons.Sum(w => w.Mass) + activeCMs.Sum(cm => cm.Mass) + sensors.Sum(s => s.Mass) + passiveCMs.Sum(cm => cm.Mass) + shieldGenerators.Sum(gen => gen.Mass);
     Expense = hullEquipment.Expense + hullEquipment.Weapons.Sum(w => w.Expense) + activeCMs.Sum(cm => cm.Expense) + sensors.Sum(s => s.Expense) + passiveCMs.Sum(cm => cm.Expense) + shieldGenerators.Sum(gen => gen.Expense);
     InitializeWeapons();
     Initialize(sensors);
     Initialize(activeCMs);
     Initialize(shieldGenerators);
     HQPriority = hqPriority;
 }
Пример #2
0
 public void HandleSubordinateElementDeath(IUnitElement deadSubordinateElement) {
     // No ShowDebugLog as I always want this to report except when it doesn't compile
     D.LogBold("{0} acknowledging {1} has been lost.", DebugName, deadSubordinateElement.DebugName);
     RemoveElement(deadSubordinateElement as AUnitElementItem);
     // state machine notification is after removal so attempts to acquire a replacement don't come up with same element
     if (IsOperational) {    // no point in notifying Cmd's Dead state of the subordinate element's death that killed it
         UponSubordinateElementDeath(deadSubordinateElement as AUnitElementItem);
     }
 }
Пример #3
0
 /// <summary>
 /// Positions the element in formation. This base class version simply places the 
 /// element at the designated offset location from the HQElement.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="stationSlotInfo">The slot information.</param>
 public virtual void PositionElementInFormation(IUnitElement element, FormationStationSlotInfo stationSlotInfo) {
     (element as AUnitElementItem).transform.localPosition = stationSlotInfo.LocalOffset;
     //D.Log(ShowDebugLog, "{0} positioned at {1}, offset by {2} from {3} at {4}.",
     //element.DebugName, element.Position, stationSlotInfo.LocalOffset, HQElement.DebugName, HQElement.Position);
 }
Пример #4
0
 /// <summary>
 /// Selects a FormationStation slot for the provided (non-HQ) element based on default selection constraints, 
 /// and then calls Command.PositionElementInFormation() using the slot selected.
 /// </summary>
 /// <param name="element">The element.</param>
 public void AddAndPositionNonHQElement(IUnitElement element) {
     D.Assert(!element.IsHQ);
     AddAndPositionElement(element);
 }
Пример #5
0
    /// <summary>
    /// Positions the element in formation. This FleetCmd version assigns a FleetFormationStation to the element (ship) after
    /// removing the existing station, if any. The ship will then assume its station by moving to its location when ordered.
    /// If this Cmd client is not yet operational meaning the fleet is being deployed for the first time, the ship will
    /// be placed at the station's location.
    /// </summary>
    /// <param name="element">The element.</param>
    /// <param name="stationSlotInfo">The station slot information.</param>
    public override void PositionElementInFormation(IUnitElement element, FormationStationSlotInfo stationSlotInfo) {
        ShipItem ship = element as ShipItem;

        if (!IsOperational) {
            // If not operational, this positioning is occurring during construction so place the ship now where it belongs
            base.PositionElementInFormation(element, stationSlotInfo);
        }

        FleetFormationStation station = ship.FormationStation;
        if (station != null) {
            // the ship already has a formation station so get rid of it
            D.Log(ShowDebugLog, "{0} is removing and despawning old {1}.", ship.DebugName, typeof(FleetFormationStation).Name);
            ship.FormationStation = null;
            station.AssignedShip = null;
            // FormationMgr will have already removed stationInfo from occupied list if present //FormationMgr.ReturnSlotAsAvailable(ship, station.StationInfo);
            MyPoolManager.Instance.DespawnFormationStation(station.transform);
        }
        //D.Log(ShowDebugLog, "{0} is adding a new {1} with SlotID {2}.", DebugName, typeof(FleetFormationStation).Name, stationSlotInfo.SlotID.GetValueName());
        station = MyPoolManager.Instance.SpawnFormationStation(Position, Quaternion.identity, transform);
        station.StationInfo = stationSlotInfo;
        station.AssignedShip = ship;
        ship.FormationStation = station;
    }
Пример #6
0
 /// <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);
 }
Пример #7
0
 /// <summary>
 /// Handles changes the FormationManager needs to make when an element is removed from the Unit.
 /// WARNING: This does not include removing the FormationStation from the ship and the ship
 /// from the FormationStation, nor does it deal with return the Station to the pool.
 /// </summary>
 /// <param name="element">The element.</param>
 public void HandleElementRemoval(IUnitElement element) {
     FormationStationSlotInfo elementStationInfo;
     bool isStationSlotFound = _occupiedStationSlotLookup.TryGetValue(element, out elementStationInfo);
     D.Assert(isStationSlotFound, element.DebugName);
     _occupiedStationSlotLookup.Remove(element);
     _availableStationSlots.Add(elementStationInfo);
 }
Пример #8
0
        /// <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;
        }
Пример #9
0
 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;
 }
Пример #10
0
 /// <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);
 }