示例#1
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()));
        }
示例#2
0
        private void AddFood(Mineral mineral)
        {
            var quantity = base.CargoBays.CargoVolume;

            if (quantity.Item2 - quantity.Item1 < mineral.VolumeInCubicMeters)
            {
                // The cargo bays are too full
                return;
            }

            // Try to pop this out of the map
            if (!_map.RemoveItem(mineral, true))
            {
                // It's already gone
                return;
            }

            // Convert it to cargo
            Cargo_Mineral cargo = new Cargo_Mineral(mineral.MineralType, mineral.Density, mineral.VolumeInCubicMeters);

            // Try to add this to the cargo bays - the total volume may be enough, but the mineral may be too large for any
            // one cargo bay
            if (base.CargoBays.Add(cargo))
            {
                // Finish removing it from the real world
                mineral.PhysicsBody.Dispose();

                this.ShouldRecalcMass_Large = true;
            }
            else
            {
                // It didn't fit, give it back to the map
                _map.AddItem(mineral);
            }
        }
        private void ApplyItem_Click(object sender, RoutedEventArgs e)
        {
            const double PERCENT = .2;

            try
            {
                if (_bot != null)
                {
                    // Asteroids cause damage (currently using plasma tank as a hitpoint meter)
                    foreach (Asteroid asteroid in _map.GetItems<Asteroid>(false))
                    {
                        if (_bot.Plasma != null)
                        {
                            _bot.Plasma.RemoveQuantity(_bot.Plasma.QuantityMax * PERCENT, false);
                        }
                    }

                    // Minerals get added to the cargobay.  The bot has converters that turn minerals into energy and ammo
                    foreach (Mineral mineral in _map.GetItems<Mineral>(false))
                    {
                        if (_bot.CargoBays != null)
                        {
                            var volume = _bot.CargoBays.CargoVolume;
                            double addVol = Math.Min(volume.Item2 * PERCENT, volume.Item2 - volume.Item1);

                            if (addVol > 0 && !addVol.IsNearZero())
                            {
                                Cargo cargo = new Cargo_Mineral(mineral.MineralType, mineral.Density, addVol);
                                _bot.CargoBays.Add(cargo);
                            }
                        }
                    }
                }

                RemoveItem_Click(this, new RoutedEventArgs());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#4
0
        public void CollidedMineral(Mineral mineral, World world, int materialID, SharedVisuals sharedVisuals)
        {
            //TODO: Let the user specify thresholds for which minerals to take ($, density, mass, type).  Also give an option to be less picky if near empty
            //TODO: Let the user specify thresholds for swapping lesser minerals for better ones
            //TODO: Add a portion

            if (base.CargoBays == null)
            {
                return;
            }
            else if (mineral.IsDisposed)
            {
                return;
            }

            var quantity = base.CargoBays.CargoVolume;

            if (quantity.Item2 - quantity.Item1 < mineral.VolumeInCubicMeters)
            {
                // The cargo bays are too full
                return;
            }

            // Save location in case it needs to be brought back
            Point3D position = mineral.PositionWorld;

            // Convert it to cargo
            Cargo_Mineral cargo = new Cargo_Mineral(mineral.MineralType, mineral.Density, mineral.VolumeInCubicMeters);

            // Try to add this to the cargo bays - the total volume may be enough, but the mineral may be too large for any
            // one cargo bay (or some of the cargo bays could be destroyed)
            if (base.CargoBays.Add(cargo))
            {
                // Finish removing it from the real world
                _map.RemoveItem(mineral, true);
                mineral.PhysicsBody.Dispose();

                this.ShouldRecalcMass_Large = true;
            }
        }
示例#5
0
        /// <summary>
        /// This will take the mineral if it fits
        /// NOTE: This method removes the mineral from the map
        /// </summary>
        private void CollidedMineral_ORIG(Mineral mineral, World world, int materialID, SharedVisuals sharedVisuals)
        {
            //TODO: Let the user specify thresholds for which minerals to take ($, density, mass, type).  Also give an option to be less picky if near empty
            //TODO: Let the user specify thresholds for swapping lesser minerals for better ones

            if (base.CargoBays == null)
            {
                return;
            }
            else if (mineral.IsDisposed)
            {
                return;
            }

            var quantity = base.CargoBays.CargoVolume;

            if (quantity.Item2 - quantity.Item1 < mineral.VolumeInCubicMeters)
            {
                // The cargo bays are too full
                return;
            }

            // Save location in case it needs to be brought back
            Point3D position = mineral.PositionWorld;

            // Try to pop this out of the map
            if (!_map.RemoveItem(mineral, true))
            {
                // It's already gone
                return;
            }

            // Convert it to cargo
            Cargo_Mineral cargo = new Cargo_Mineral(mineral.MineralType, mineral.Density, mineral.VolumeInCubicMeters);

            // Try to add this to the cargo bays - the total volume may be enough, but the mineral may be too large for any
            // one cargo bay
            if (base.CargoBays.Add(cargo))
            {
                // Finish removing it from the real world
                mineral.PhysicsBody.Dispose();

                this.ShouldRecalcMass_Large = true;
            }
            else
            {
                // It didn't fit, give it back to the map
                Mineral clone = new Mineral(mineral.MineralType, position, mineral.VolumeInCubicMeters, world, materialID, sharedVisuals, ItemOptionsAstMin2D.MINERAL_DENSITYMULT, mineral.Scale, mineral.Credits);
                _map.AddItem(clone);
            }
        }
示例#6
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());
        }
        private void StoreIn_Cargo_Hangar_Nearby(Inventory inventory, string name)
        {
            Cargo cargo = null;
            if (inventory.Mineral != null)
            {
                cargo = new Cargo_Mineral(inventory.Mineral.MineralType, inventory.Mineral.Density, inventory.Mineral.Volume);
            }
            else if (inventory.Part != null)
            {
                cargo = new Cargo_ShipPart(inventory.Part, _itemOptions, _editorOptions);
            }
            else
            {
                throw new ApplicationException("finish this");
            }

            if (_player.Ship.CargoBays != null && _player.Ship.CargoBays.Add(cargo))
            {
                AddShipCargoGraphic(inventory);
            }
            else
            {
                StoreIn_Hangar_Nearby(inventory, name);
            }
        }
        /// <summary>
        /// This will take the mineral if it fits
        /// NOTE: This method removes the mineral from the map
        /// </summary>
        public void CollidedMineral(Mineral mineral)
        {
            //TODO: Let the user specify thresholds for which minerals to take ($, density, mass, type).  Also give an option to be less picky if near empty
            //TODO: Let the user specify thresholds for swapping lesser minerals for better ones

            var quantity = base.CargoBays.CargoVolume;

            if (quantity.Item2 - quantity.Item1 < mineral.VolumeInCubicMeters)
            {
                // The cargo bays are too full
                return;
            }

            // Try to pop this out of the map
            if (!_map.RemoveItem(mineral, true))
            {
                // It's already gone
                return;
            }

            // Convert it to cargo
            Cargo_Mineral cargo = new Cargo_Mineral(mineral.MineralType, mineral.Density, mineral.VolumeInCubicMeters);

            // Try to add this to the cargo bays - the total volume may be enough, but the mineral may be too large for any
            // one cargo bay
            if (base.CargoBays.Add(cargo))
            {
                // Finish removing it from the real world
                mineral.PhysicsBody.Dispose();

                this.ShouldRecalcMass_Large = true;
            }
            else
            {
                // It didn't fit, give it back to the map
                _map.AddItem(mineral);
            }
        }