//NOTE: There is only an add method.  Any cargo added to this converter is burned off over time
        public bool Add(Cargo cargo)
        {
            lock (_lock)
            {
                //double sumVolume = this.UsedVolume + cargo.Volume;
                double sumVolume = _cargo.Sum(o => o.Volume) + cargo.Volume;        // inlined this.UsedVolume because of the lock

                if (sumVolume <= this.MaxVolume || Math1D.IsNearValue(sumVolume, this.MaxVolume))
                {
                    ConverterMatterToFuel.Add(_cargo, cargo);
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        /// <summary>
        /// This keeps the cargo hold sorted by density
        /// NOTE: If volumes change outside of this thread, then this could place cargo in an imperfect order.  No real damage, just be aware
        /// </summary>
        internal static void Add(List<Cargo> cargoHold, Cargo cargo)
        {
            if (cargoHold.Count == 0)
            {
                cargoHold.Add(cargo);
                return;
            }

            for (int cntr = 0; cntr < cargoHold.Count; cntr++)
            {
                if (cargo.Density < cargoHold[cntr].Density)
                {
                    // This is less dense, put it here
                    cargoHold.Insert(cntr, cargo);
                    return;
                }
                else if (Math1D.IsNearValue(cargo.Density, cargoHold[cntr].Density) && cargo.Volume < cargoHold[cntr].Volume)
                {
                    // This is the same density, but has less volume, so put it here
                    cargoHold.Insert(cntr, cargo);
                    return;
                }
            }

            // This is more desnse than everything else, put it at the end
            cargoHold.Add(cargo);
        }
 private void Transfer_One(Cargo[] cargo)
 {
     for (int cntr = 0; cntr < cargo.Length; cntr++)
     {
         if (!_converters[0].Add(cargo[cntr]))
         {
             // Give it back to the cargo bays (this should never happen)
             _cargoBays.Add(cargo[cntr]);
         }
     }
 }
Beispiel #4
0
        public bool Add(Cargo cargo)
        {
            lock (_lock)
            {
                // Add it to a random cargo bay
                foreach (int index in UtilityCore.RandomRange(0, _cargoBays.Length))
                {
                    if (_cargoBays[index].Add(cargo))
                    {
                        return true;
                    }
                }

                return false;
            }
        }
Beispiel #5
0
        private Tuple<double, Cargo[]> RemoveMineral_Continue(Cargo[] candidates, double volume)
        {
            List<Cargo> retVal = new List<Cargo>();
            double current = 0d;

            for (int cntr = 0; cntr < candidates.Length; cntr++)
            {
                if (current + candidates[cntr].Volume < volume)
                {
                    _cargo.Remove(candidates[cntr]);

                    retVal.Add(candidates[cntr]);
                    current += candidates[cntr].Volume;
                }
                else
                {
                    // This one is the next smallest, but is too big
                    Cargo_Mineral remainder = new Cargo_Mineral(((Cargo_Mineral)candidates[cntr]).MineralType, candidates[cntr].Density, volume - current);
                    candidates[cntr].Volume -= remainder.Volume;

                    retVal.Add(remainder);
                    current += remainder.Volume;
                    break;
                }
            }

            this.UsedVolume = GetUsedVolume();

            // Exit Function
            return Tuple.Create(current, retVal.ToArray());
        }
Beispiel #6
0
        //TODO: Add an overload that takes part of the cargo (only if mineral), and returns the remainder
        public bool Add(Cargo cargo)
        {
            lock (_lock)
            {
                if (this.IsDestroyed || this.UsedVolume + cargo.Volume > this.MaxVolume)
                {
                    return false;
                }

                _cargo.Add(cargo);
                this.UsedVolume = GetUsedVolume();

                return true;
            }
        }
        private void StoreInStation(Cargo cargo)
        {
            Inventory inventory;
            if (cargo is Cargo_Mineral)
            {
                Cargo_Mineral cargoMineral = (Cargo_Mineral)cargo;
                MineralDNA mineralDNA = ItemOptionsAstMin2D.GetMineral(cargoMineral.MineralType, cargoMineral.Volume);
                inventory = new Inventory(mineralDNA);
            }
            else if (cargo is Cargo_ShipPart)
            {
                Cargo_ShipPart cargoPart = (Cargo_ShipPart)cargo;
                inventory = new Inventory(cargoPart.PartDNA);
            }
            else
            {
                throw new ApplicationException("Unknown type of cargo: " + cargo.GetType().ToString());
            }

            _spaceDock.AddInventory(inventory, true);
        }
        private void RedistributeParts(Cargo[] remainder, List<ShipPartDNA> unaccountedParts)
        {
            // Look for parts that are currently in the station, but are now also part of the ship
            foreach (var inventory in _fromNearby.Concat(_fromHangar))
            {
                if (IsInList(unaccountedParts, inventory.Item1.Inventory.Part, true))
                {
                    // This is now part of the ship.  Remove from the station
                    RemoveFromStation(inventory.Item1);
                }
            }

            // These two are external to the station's current inventory, so they need be processed after looking at the
            // current inventory

            foreach (Cargo cargo in remainder)
            {
                StoreInStation(cargo);
            }

            // Remove unnaccounted that came from the old ship
            foreach (ShipPartDNA dna in _fromShip)
            {
                if (!IsInList(unaccountedParts, dna, true))
                {
                    StoreInStation(dna);
                }
            }

            if (unaccountedParts.Count > 0)
            {
                // These are parts that are in the new ship.  They should have come from the old ship, or cargo bays, or nearby, or hangar
                throw new ApplicationException("There are still unnaccounted parts");
            }
        }