예제 #1
0
        /// <summary>
        /// This returns a random ball, with some optional fixed values
        /// </summary>
        public static WeaponSpikeBallDNA GetRandomDNA(WeaponSpikeBallMaterial?material = null, double?radius = null)
        {
            WeaponSpikeBallDNA retVal = new WeaponSpikeBallDNA();

            Random rand = StaticRandom.GetRandomForThread();

            // Radius
            if (radius != null)
            {
                retVal.Radius = radius.Value;
            }
            else
            {
                retVal.Radius = rand.NextDouble(.2, .5);
            }

            // Material
            if (material == null)
            {
                retVal.Material = UtilityCore.GetRandomEnum <WeaponSpikeBallMaterial>();
            }
            else
            {
                retVal.Material = material.Value;
            }

            return(retVal);
        }
예제 #2
0
        /// <summary>
        /// This should get called on an infrequent basis, and randomize the available inventory
        /// </summary>
        public void RandomizeInventory(bool completelyNew)
        {
            RandomizePrices();

            if (completelyNew)
            {
                this.StationInventory.Clear();
            }

            List <Inventory> inventory = new List <Inventory>();

            // Ships
            inventory.AddRange(AdjustInventory(
                                   this.StationInventory.Where(o => o.Ship != null),
                                   3,
                                   () =>
            {
                DefaultShipType shipType = GetRandomItemChance(_shipChances).ShipType;
                ShipDNA shipDNA          = DefaultShips.GetDNA(shipType);
                return(new Inventory(shipDNA, StaticRandom.NextDouble(.5, 2)));
            }));


            // Parts
            inventory.AddRange(AdjustInventory(
                                   this.StationInventory.Where(o => o.Part != null),
                                   4,
                                   () =>
            {
                PartCreateChance partType = GetRandomItemChance(_partChances);
                ShipPartDNA partDNA       = GetRandomPart(partType);    //TODO: Have a chance to make 2 if it's something that could come in pairs (thruster, gun, etc)
                return(new Inventory(partDNA));
            }));

            // Minerals
            inventory.AddRange(AdjustInventory(
                                   this.StationInventory.Where(o => o.Mineral != null),
                                   4,
                                   () =>
            {
                MineralType type = UtilityCore.GetRandomEnum <MineralType>();
                double volume    = StaticRandom.NextPercent(ItemOptionsAstMin2D.MINERAL_AVGVOLUME, 2);
                return(new Inventory(ItemOptionsAstMin2D.GetMineral(type, volume)));
            }));

            this.StationInventory.Clear();
            this.StationInventory.AddRange(inventory);

            _inventoryRandomizeCountdown = StaticRandom.NextDouble(3 * 60, 8 * 60);
        }
예제 #3
0
        /// <summary>
        /// This returns a random axe, with some optional fixed values
        /// </summary>
        public static WeaponAxeDNA GetRandomDNA(double?sizeSingleSide = null, WeaponAxeType?axeType = null, WeaponAxeSides?sides = null, WeaponAxeStye?style = null)
        {
            WeaponAxeDNA retVal = new WeaponAxeDNA();

            Random rand = StaticRandom.GetRandomForThread();

            // Size
            if (sizeSingleSide != null)
            {
                retVal.SizeSingle = sizeSingleSide.Value;
            }
            else
            {
                retVal.SizeSingle = rand.NextDouble(.4, 1);
            }

            // AxeType
            if (axeType != null)
            {
                retVal.AxeType = axeType.Value;
            }
            else
            {
                retVal.AxeType = UtilityCore.GetRandomEnum <WeaponAxeType>();
            }

            // Sides
            if (sides != null)
            {
                retVal.Sides = sides.Value;
            }
            else
            {
                retVal.Sides = UtilityCore.GetRandomEnum <WeaponAxeSides>();
            }

            // Style
            if (style != null)
            {
                retVal.Style = style.Value;
            }
            else
            {
                retVal.Style = UtilityCore.GetRandomEnum <WeaponAxeStye>();
            }

            return(retVal);
        }
예제 #4
0
        public static Tuple <FlagBackType, FlagOverlayType?, FlagOverlayType?> GetRandomEnums()
        {
            Random rand = StaticRandom.GetRandomForThread();

            double overlayProb = rand.NextDouble();

            // Choose a background
            FlagBackType backType = UtilityCore.GetRandomEnum <FlagBackType>();

            FlagOverlayType[] backTypeFilter = _similarOptions.Value.
                                               Where(o => o.Item2.Any(p => p == backType)).
                                               SelectMany(o => o.Item1).
                                               ToArray();

            // Choose overlay one
            FlagOverlayType?overlayType1 = null;

            if (overlayProb > .33)
            {
                overlayType1 = UtilityCore.GetRandomEnum <FlagOverlayType>(backTypeFilter);
            }

            // Choose overlay two
            FlagOverlayType?overlayType2 = null;

            if (overlayProb > .66)
            {
                var test = _notAbove.Value.
                           Where(o => o.Item2.Any(p => p == overlayType1.Value)).
                           SelectMany(o => o.Item1).
                           ToArray();


                IEnumerable <FlagOverlayType> filter2 = UtilityCore.Iterate(
                    new[] { overlayType1.Value },
                    backTypeFilter,
                    _similarOptions.Value.Where(o => o.Item1.Any(p => p == overlayType1.Value)).SelectMany(o => o.Item1),
                    _notAbove.Value.Where(o => o.Item2.Any(p => p == overlayType1.Value)).SelectMany(o => o.Item1)
                    );

                overlayType2 = UtilityCore.GetRandomEnum <FlagOverlayType>(filter2);
            }

            return(Tuple.Create(backType, overlayType1, overlayType2));
        }
예제 #5
0
        private static ShipPartDNA[] GetRandomThrusters(int count, bool randomOrientations, ThrusterTypeValues thrustType, bool someDestroyed)
        {
            const double MINRADIUS = 1.5;
            const double MAXRADIUS = 3;
            const double MINSIZE   = .5;
            const double MAXSIZE   = 1.5;

            if (count < 2)
            {
                throw new ApplicationException("Must have at least two thrusters");
            }

            List <ShipPartDNA> retVal = new List <ShipPartDNA>();

            Random rand = StaticRandom.GetRandomForThread();

            double stepAngle  = 360d / count;
            double rangeAngle = 120d / count;       // the sum of these pie slices should cover 2/3 of the area

            Vector3D axis       = new Vector3D(0, 0, 1);
            double   startAngle = rand.NextDouble(360);

            for (int cntr = 0; cntr < count; cntr++)
            {
                double angle = startAngle + (cntr * stepAngle);
                angle += rand.NextDouble(-rangeAngle, rangeAngle);

                Vector3D position = new Vector3D(rand.NextDouble(MINRADIUS, MAXRADIUS), 0, 0);
                position = position.GetRotatedVector(axis, angle);

                double size = rand.NextDouble(MINSIZE, MAXSIZE);

                //Random direction
                Quaternion orientation = Quaternion.Identity;
                if (randomOrientations)
                {
                    Vector3D standardVect = new Vector3D(0, 0, 1);
                    Vector3D rotatedVect  = Math3D.GetRandomVector_Cone(axis, 0, 90, 1, 1);
                    orientation = Math3D.GetRotation(standardVect, rotatedVect);
                }

                ThrusterType type;
                switch (thrustType)
                {
                case ThrusterTypeValues.Single:
                    type = ThrusterType.One;
                    break;

                case ThrusterTypeValues.Dual:
                    type = ThrusterType.Two;
                    break;

                case ThrusterTypeValues.Six:
                    type = ThrusterType.Two_Two_Two;
                    break;

                case ThrusterTypeValues.Random:
                    type = UtilityCore.GetRandomEnum <ThrusterType>(ThrusterType.Custom);
                    break;

                default:
                    throw new ApplicationException("Unknown ThrusterTypeValues: " + thrustType.ToString());
                }

                double percentDamaged = 0d;
                if (someDestroyed && rand.NextDouble() < .15)
                {
                    percentDamaged = 1d;
                }

                retVal.Add(new ThrusterDNA()
                {
                    PartType       = Thruster.PARTTYPE,
                    Orientation    = orientation,
                    Position       = position.ToPoint(),
                    Scale          = new Vector3D(size, size, size),
                    ThrusterType   = type,
                    PercentDamaged = percentDamaged,
                });
            }

            return(retVal.ToArray());
        }
예제 #6
0
        public static WeaponHandleDNA GetRandomDNA(WeaponHandleMaterial?material = null, WeaponHandleType?type = null, bool?isDouble = null, double?length = null, double?radius = null)
        {
            const double DOUBLE_END    = .2d;
            const double DOUBLE_CENTER = .05d;       // this is only half of the center

            WeaponHandleDNA retVal = new WeaponHandleDNA();

            Random rand = StaticRandom.GetRandomForThread();

            bool isDoubleActual = isDouble ?? (rand.Next(2) == 0);

            #region Material

            if (material == null)
            {
                retVal.HandleMaterial = UtilityCore.GetRandomEnum <WeaponHandleMaterial>();
            }
            else
            {
                retVal.HandleMaterial = material.Value;
            }

            #endregion

            //TODO: Support rope
            retVal.HandleType = WeaponHandleType.Rod;

            #region Length

            if (length == null)
            {
                //double lengthActual = rand.NextDouble(1.5d, 3.5d);
                double lengthActual = rand.NextDouble(1.5d, 2.8d);
                if (isDoubleActual)
                {
                    lengthActual *= 2d;
                }

                retVal.Length = lengthActual;
            }
            else
            {
                retVal.Length = length.Value;
            }

            #endregion
            #region Radius

            if (radius == null)
            {
                //double radiusActual = rand.NextDouble(.03d, .17d);
                double radiusActual = rand.NextDouble(.03d, .12d);
                if (isDoubleActual)
                {
                    radiusActual *= 2d;
                }

                retVal.Radius = radiusActual;
            }
            else
            {
                retVal.Radius = radius.Value;
            }

            #endregion
            #region AttachPoint

            if (isDoubleActual)
            {
                // Since the center of mass is in the middle, the attach point can't be in the middle.
                // Both ends are out as well.
                // So, choose one of the areas that are stars
                //  |----|********|--------|********|----|

                double randMaxValue = .5d - DOUBLE_END - DOUBLE_CENTER;
                double randValue    = rand.NextDouble(randMaxValue);
                double half         = DOUBLE_CENTER + randValue;

                if (rand.NextBool())
                {
                    // left side
                    retVal.AttachPointPercent = .5d - half;
                }
                else
                {
                    // right side
                    retVal.AttachPointPercent = .5d + half;
                }
            }
            else
            {
                // Choose one of the ends
                retVal.AttachPointPercent = rand.NextBool() ? 0d : 1d;
            }

            #endregion

            #region Color

            switch (retVal.HandleMaterial)
            {
            case WeaponHandleMaterial.Composite:
                retVal.MaterialsForCustomizable = GetRandomMaterials_Composite();
                break;

            case WeaponHandleMaterial.Klinth:
                retVal.MaterialsForCustomizable = GetRandomMaterials_Klinth();
                break;
            }

            #endregion

            return(retVal);
        }
예제 #7
0
        private static ShipPartDNA GetRandomPart(PartCreateChance part)
        {
            ShipPartDNA retVal = null;

            switch (part.PartType)
            {
            case Thruster.PARTTYPE:
                #region Thruster

                ThrusterDNA dnaThrust = new ThrusterDNA()
                {
                    PartType    = part.PartType,
                    Orientation = Math3D.GetRandomRotation(),
                    Position    = new Point3D(),
                    Scale       = GetRandomScale(part.ScaleBase),
                };

                dnaThrust.ThrusterType = UtilityCore.GetRandomEnum <ThrusterType>(new[] { ThrusterType.Two_Two_One, ThrusterType.Two_Two_Two });        // only want 2D thrusters
                if (dnaThrust.ThrusterType == ThrusterType.Custom)
                {
                    dnaThrust.ThrusterDirections = Enumerable.Range(0, StaticRandom.Next(2, 5)).
                                                   Select(o => Math3D.GetRandomVector_Circular_Shell(1)). // only want 2D thrusters
                                                   ToArray();
                }

                retVal = dnaThrust;

                #endregion
                break;

            case ConverterRadiationToEnergy.PARTTYPE:
                #region ConverterRadiationToEnergy

                ConverterRadiationToEnergyDNA dnaCon = new ConverterRadiationToEnergyDNA()
                {
                    PartType    = part.PartType,
                    Orientation = Math3D.GetRandomRotation(),
                    Position    = new Point3D(),
                    Scale       = GetRandomScale(part.ScaleBase),

                    Shape = UtilityCore.GetRandomEnum <SolarPanelShape>(),
                };

                retVal = dnaCon;

                #endregion
                break;

            default:
                #region default

                retVal = new ShipPartDNA()
                {
                    PartType    = part.PartType,
                    Orientation = Math3D.GetRandomRotation(),
                    Position    = new Point3D(),
                    Scale       = GetRandomScale(part.ScaleBase),
                };

                #endregion
                break;
            }

            return(retVal);
        }