Beispiel #1
0
        public PlasmaTank(EditorOptions options, ItemOptions itemOptions, ShipPartDNA dna)
            : base(options, dna, itemOptions.PlasmaTank_Damage.HitpointMin, itemOptions.PlasmaTank_Damage.HitpointSlope, itemOptions.PlasmaTank_Damage.Damage)
        {
            _itemOptions = itemOptions;

            this.Design = new PlasmaTankDesign(options, true);
            this.Design.SetDNA(dna);

            double surfaceArea, radius;

            _container = FuelTank.GetContainer(out surfaceArea, out _scaleActual, out radius, itemOptions, dna);

            _mass       = _container.QuantityMax * itemOptions.PlasmaTank_Density; // max quantity is the volume
            this.Radius = radius;

            _neuron = new Neuron_SensorPosition(new Point3D(0, 0, 0), false);

            this.Destroyed += PlasmaTank_Destroyed;
        }
        private PartBase GetRandomPart()
        {
            Point3D position = Math3D.GetRandomVector(2d).ToPoint();
            Quaternion orientation = Math3D.GetRandomRotation();
            double radius = 1d + StaticRandom.NextDouble() * 4d;
            double height = 1d + StaticRandom.NextDouble() * 4d;

            switch (StaticRandom.Next(8))
            {
                case 0:
                    #region Spin

                    double spinSize = 5d + (StaticRandom.NextDouble() * 8d);
                    ShipPartDNA dnaSpin = new ShipPartDNA() { PartType = SensorSpin.PARTTYPE, Position = position, Orientation = orientation, Scale = new Vector3D(spinSize, spinSize, spinSize) };
                    return new SensorSpin(_editorOptions, _itemOptions, dnaSpin, null);

                    #endregion

                case 1:
                    #region Fuel

                    ShipPartDNA dnaFuel = new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = position, Orientation = orientation, Scale = new Vector3D(radius, radius, height) };
                    FuelTank fuel = new FuelTank(_editorOptions, _itemOptions, dnaFuel);
                    fuel.QuantityCurrent = fuel.QuantityMax;		// without this, the fuel tank gets tossed around because it's so light
                    return fuel;

                    #endregion

                case 2:
                    #region Energy

                    ShipPartDNA dnaEnergy = new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Position = position, Orientation = orientation, Scale = new Vector3D(radius, radius, height) };
                    return new EnergyTank(_editorOptions, _itemOptions, dnaEnergy);

                    #endregion

                case 3:
                    #region Brain

                    ShipPartDNA dnaBrain = new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = position, Orientation = orientation, Scale = new Vector3D(radius, radius, radius) };
                    return new Brain(_editorOptions, _itemOptions, dnaBrain, null);

                    #endregion

                case 4:
                    #region Thruster

                    ThrusterDNA dnaThruster1 = new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = position, Orientation = orientation, Scale = new Vector3D(height, height, height), ThrusterType = UtilityCore.GetRandomEnum(ThrusterType.Custom) };
                    return new Thruster(_editorOptions, _itemOptions, dnaThruster1, null);

                    #endregion

                case 5:
                    #region Solar

                    ConverterRadiationToEnergyDNA dnaSolar = new ConverterRadiationToEnergyDNA() { PartType = ConverterRadiationToEnergy.PARTTYPE, Position = position, Orientation = orientation, Scale = new Vector3D(height, 1d + StaticRandom.NextDouble() * 4d, 1d), Shape = UtilityCore.GetRandomEnum<SolarPanelShape>() };
                    return new ConverterRadiationToEnergy(_editorOptions, _itemOptions, dnaSolar, null, _radiation);

                    #endregion

                case 6:
                    #region Fuel->Energy

                    ShipPartDNA dnaBurner = new ShipPartDNA() { PartType = ConverterFuelToEnergy.PARTTYPE, Position = position, Orientation = orientation, Scale = new Vector3D(radius, radius, height) };
                    return new ConverterFuelToEnergy(_editorOptions, _itemOptions, dnaBurner, null, null);

                    #endregion

                case 7:
                    #region Energy->Ammo

                    ShipPartDNA dnaReplicator = new ShipPartDNA() { PartType = ConverterEnergyToAmmo.PARTTYPE, Position = position, Orientation = orientation, Scale = new Vector3D(radius, radius, height) };
                    return new ConverterEnergyToAmmo(_editorOptions, _itemOptions, dnaReplicator, null, null);

                    #endregion

                default:
                    throw new ApplicationException("Unexpected integer");
            }
        }
        private void btnTwoCylinderCylinder_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool isEnergy1 = StaticRandom.Next(2) == 0;
                bool isEnergy2 = StaticRandom.Next(2) == 0;

                ShipPartDNA dna1 = new ShipPartDNA() { PartType = isEnergy1 ? EnergyTank.PARTTYPE : FuelTank.PARTTYPE, Position = new Point3D(-.5, -.1, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(4, 4, 3) };
                ShipPartDNA dna2 = new ShipPartDNA() { PartType = isEnergy2 ? EnergyTank.PARTTYPE : FuelTank.PARTTYPE, Position = new Point3D(.5, .1, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(4, 4, 3) };

                PartBase cylinder1 = null;
                if (isEnergy1)
                {
                    cylinder1 = new EnergyTank(_editorOptions, _itemOptions, dna1);
                }
                else
                {
                    cylinder1 = new FuelTank(_editorOptions, _itemOptions, dna1);
                }

                PartBase cylinder2 = null;
                if (isEnergy2)
                {
                    cylinder2 = new EnergyTank(_editorOptions, _itemOptions, dna2);
                }
                else
                {
                    cylinder2 = new FuelTank(_editorOptions, _itemOptions, dna2);
                }

                StartScene(new PartBase[] { cylinder1, cylinder2 }, 7);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnTwoCubeCylinder_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool isEnergy = StaticRandom.Next(2) == 0;

                ShipPartDNA dna1 = new ShipPartDNA() { PartType = isEnergy ? EnergyTank.PARTTYPE : FuelTank.PARTTYPE, Position = new Point3D(-.5, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(4, 4, 3) };
                ShipPartDNA dnaSpin = new ShipPartDNA() { PartType = SensorSpin.PARTTYPE, Position = new Point3D(.5, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(10, 10, 10) };

                PartBase cylinder = null;
                if (isEnergy)
                {
                    cylinder = new EnergyTank(_editorOptions, _itemOptions, dna1);
                }
                else
                {
                    cylinder = new FuelTank(_editorOptions, _itemOptions, dna1);
                }
                SensorSpin spin = new SensorSpin(_editorOptions, _itemOptions, dnaSpin, null);

                StartScene(new PartBase[] { cylinder, spin }, 7);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnStandaloneFuelFull_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ShipPartDNA dna = GetDefaultDNA(FuelTank.PARTTYPE);
                ModifyDNA(dna, chkStandaloneRandSize.IsChecked.Value, chkStandaloneRandOrientation.IsChecked.Value);
                double radius = (dna.Scale.X + dna.Scale.Y) * .5d;
                dna.Scale = new Vector3D(radius, radius, dna.Scale.Z);

                //dna.Scale = new Vector3D(2, 2, .9);
                //dna.Scale = new Vector3D(1.15, 1.15, 4);

                FuelTank fuelTank = new FuelTank(_editorOptions, _itemOptions, dna);
                fuelTank.QuantityCurrent = fuelTank.QuantityMax;

                BuildStandalonePart(fuelTank);

                if (chkStandaloneShowMassBreakdown.IsChecked.Value)
                {
                    double cellSize = Math1D.Max(dna.Scale.X, dna.Scale.Y, dna.Scale.Z) * UtilityCore.GetScaledValue_Capped(.1d, .3d, 0d, 1d, _rand.NextDouble());
                    DrawMassBreakdown(fuelTank.GetMassBreakdown(cellSize), cellSize);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnThruster_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ShipPartDNA dna = GetDefaultDNA(FuelTank.PARTTYPE);
                FuelTank fuelTank = new FuelTank(_editorOptions, _itemOptions, dna);

                ThrusterDNA dna2 = new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE,
                    ThrusterType = UtilityCore.GetRandomEnum<ThrusterType>(),
                    Position = new Point3D(0, 0, 0),
                    Orientation = Quaternion.Identity,
                    Scale = new Vector3D(1, 1, 1)
                };
                Thruster thruster = new Thruster(_editorOptions, _itemOptions, dna2, fuelTank);

                fuelTank.QuantityCurrent = fuelTank.QuantityMax;

                double percent;
                Vector3D? thrust;

                do
                {
                    percent = 1d;
                    thrust = thruster.Fire(ref percent, 0, 1d);
                } while (fuelTank.QuantityCurrent > 0d);

                percent = 1d;
                thrust = thruster.Fire(ref percent, 0, 1d);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnFuelToEnergy_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ShipPartDNA dna = GetDefaultDNA(FuelTank.PARTTYPE);
                FuelTank fuelTank = new FuelTank(_editorOptions, _itemOptions, dna);

                dna = GetDefaultDNA(EnergyTank.PARTTYPE);
                EnergyTank energyTank = new EnergyTank(_editorOptions, _itemOptions, dna);

                dna = GetDefaultDNA(ConverterFuelToEnergy.PARTTYPE);
                ConverterFuelToEnergy converter = new ConverterFuelToEnergy(_editorOptions, _itemOptions, dna, fuelTank, energyTank);

                fuelTank.QuantityCurrent = fuelTank.QuantityMax;

                double mass = converter.DryMass;
                mass = converter.TotalMass;

                converter.Transfer(1d, .5d);
                converter.Transfer(1d, 1d);
                converter.Transfer(1d, .1d);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnSingleFuel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ShipPartDNA dna = GetDefaultDNA(FuelTank.PARTTYPE);
                FuelTank fuelTank = new FuelTank(_editorOptions, _itemOptions, dna);

                double mass1 = fuelTank.TotalMass;

                double remainder = fuelTank.AddQuantity(.05d, false);
                double mass2 = fuelTank.TotalMass;

                remainder = fuelTank.AddQuantity(500d, false);
                double mass3 = fuelTank.TotalMass;

                double output = fuelTank.RemoveQuantity(.1d, false);
                double mass4 = fuelTank.TotalMass;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }