Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private bool CreateNewBot()
        {
            // Pull plasma
            if (_plasma == null || _plasma.RemoveQuantity(_birthCost, true) > 0)
            {
                return(false);
            }

            #region get position

            // this was copied from ProjectileGun

            // Model coords
            Point3D modelPosition = this.Design.Position;

            double length = this.Design.Scale.Z / 2d;
            length *= 3;     // make it a bit longer so it doesn't collide with the bay
            Vector3D modelDirection = new Vector3D(0, 0, length);

            // World coords
            var worldLoc   = GetWorldLocation();
            var worldSpeed = GetWorldSpeed(null);

            Vector3D worldDirection     = worldLoc.Item2.GetRotatedVector(modelDirection);
            Vector3D worldDirectionUnit = worldDirection.ToUnit();

            Point3D worldPosition = worldLoc.Item1 + worldDirection;

            #endregion

            double radius = StaticRandom.NextPercent(_birthRadius, .07);

            //NOTE: Could come back null if this part is in some kind of tester
            IMapObject parent = GetParent();

            // Create the bot
            SwarmBot1b bot = new SwarmBot1b(radius, worldPosition, parent, _world, _map, _strokes, _material_SwarmBot, _itemOptions.SwarmBot_HealRate, _itemOptions.SwarmBot_DamageAtMaxSpeed, _itemOptions.SwarmBot_MaxHealth);

            SetBotConstraints(bot);

            bot.PhysicsBody.Velocity        = worldSpeed.Item1;
            bot.PhysicsBody.AngularVelocity = Math3D.GetRandomVector_Spherical(3d);

            _map.AddItem(bot);
            _bots.Add(bot);

            return(true);
        }
Ejemplo n.º 3
0
        public static RamWeaponDNA Fix(RamWeaponDNA dna)
        {
            if (dna != null)
            {
                return(dna);
            }

            RamWeaponDNA retVal = new RamWeaponDNA()
            {
                MaxAngle         = StaticRandom.NextPercent(20, .33),
                DamageMult       = StaticRandom.NextPercent(1.5, .33),
                AccelerationMult = StaticRandom.NextPercent(1, .25)
            };

            return(retVal);
        }
Ejemplo n.º 4
0
        private void AddAsteroid_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Point3D position = Math3D.GetRandomVector_Spherical(BOUNDRYSIZEHALF * .75d).ToPoint();

                Asteroid asteroid = new Asteroid(StaticRandom.NextPercent(ASTEROIDRADIUS, .5), GetAsteroidMass, position, _world, _map, _material_Asteroid);

                asteroid.PhysicsBody.AngularVelocity = Math3D.GetRandomVector_Spherical(1d);
                asteroid.PhysicsBody.Velocity        = Math3D.GetRandomVector_Spherical(4d);

                _map.AddItem(asteroid);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 5
0
        private static int GetRandomInventoryCount(int current, int averageIfNone)
        {
            double retVal;

            if (current == 0)
            {
                retVal = StaticRandom.NextPercent(averageIfNone, 2.5);
            }
            else
            {
                retVal = current * StaticRandom.NextPercent(1, .5);
            }

            if (retVal == 0)
            {
                retVal = 1;
            }

            return(Convert.ToInt32(Math.Round(retVal)));
        }
Ejemplo n.º 6
0
        public SwarmBay(EditorOptions options, ItemOptions itemOptions, ShipPartDNA dna, Map map, World world, int material_SwarmBot, IContainer plasma, SwarmObjectiveStrokes strokes)
            : base(options, dna, itemOptions.SwarmBay_Damage.HitpointMin, itemOptions.SwarmBay_Damage.HitpointSlope, itemOptions.SwarmBay_Damage.Damage)
        {
            _itemOptions       = itemOptions;
            _map               = map;
            _world             = world;
            _material_SwarmBot = material_SwarmBot;
            _plasma            = plasma;
            _strokes           = strokes;

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

            double volume, radius;

            GetMass(out _mass, out volume, out radius, out _scaleActual, dna, itemOptions);
            //this.Radius = radius;

            _timeBetweenBots = StaticRandom.NextPercent(itemOptions.SwarmBay_BirthRate, .1);

            int maxCount = (itemOptions.SwarmBay_MaxCount * Math1D.Avg(dna.Scale.X, dna.Scale.Y, dna.Scale.Z)).ToInt_Round();

            if (maxCount < 0)
            {
                maxCount = 1;
            }
            _maxBots = maxCount;

            _plasmaTankThreshold = itemOptions.SwarmBay_Birth_TankThresholdPercent;

            _birthCost   = itemOptions.SwarmBay_BirthCost;
            _birthRadius = itemOptions.SwarmBay_BirthSize / 2d;

            if (_map != null)
            {
                _map.ItemRemoved += Map_ItemRemoved;
            }

            this.Destroyed += SwarmBay_Destroyed;
        }
Ejemplo n.º 7
0
        private static Model3DGroup GetModel_Klinth(WeaponSpikeBallDNA dna, WeaponSpikeBallDNA finalDNA, WeaponMaterialCache materials)
        {
            Model3DGroup retVal = new Model3DGroup();

            var from = dna.KeyValues;
            var to   = finalDNA.KeyValues;

            double spikeLength = WeaponDNA.GetKeyValue("spikeLength", from, to, StaticRandom.NextPercent(dna.Radius * 1.1d, .05));
            double ballRadius  = dna.Radius;

            double spikeRadius = WeaponDNA.GetKeyValue("spikeRadius", from, to, StaticRandom.NextPercent(dna.Radius * .2, .1));

            var color = WeaponMaterialCache.GetKlinth(dna.MaterialsForCustomizable);

            finalDNA.MaterialsForCustomizable = color.Item3;

            GeometryModel3D geometry;

            #region Ball

            geometry = new GeometryModel3D();

            geometry.Material     = color.Item1;
            geometry.BackMaterial = color.Item1;

            Icosidodecahedron ball = UtilityWPF.GetIcosidodecahedron(ballRadius);

            geometry.Geometry = UtilityWPF.GetMeshFromTriangles_IndependentFaces(ball.AllTriangles);

            retVal.Children.Add(geometry);

            #endregion

            #region Spikes

            // Put a spike through the center of each pentagon
            foreach (Vector3D spikeLocation in ball.PentagonPolys.Select(o => Math3D.GetCenter(o.Select(p => ball.AllPoints[p]))))
            {
                geometry = new GeometryModel3D();

                geometry.Material     = color.Item2;
                geometry.BackMaterial = color.Item2;

                RotateTransform3D transform = new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRotation(new Vector3D(0, 0, 1), spikeLocation)));       // the tube builds along z

                List <TubeRingBase> rings = new List <TubeRingBase>();

                double spikeLengthMid = spikeLength * .8d;

                rings.Add(new TubeRingRegularPolygon(0, false, spikeRadius, spikeRadius, false));
                rings.Add(new TubeRingRegularPolygon(spikeLengthMid, false, spikeRadius, spikeRadius, false));
                rings.Add(new TubeRingDome(spikeLength - spikeLengthMid, false, 3));

                geometry.Geometry = UtilityWPF.GetMultiRingedTube(9, rings, false, false, transform);

                retVal.Children.Add(geometry);
            }

            #endregion

            return(retVal);
        }
Ejemplo n.º 8
0
        private static GeometryModel3D GetModel_WoodIron_Ring_Band(double ballRadius, double z, System.Windows.Media.Media3D.Material material, TriangleIndexed[] ball, SortedList <string, double> from, SortedList <string, double> to, string prefix)
        {
            const double ENLARGE = 1.04d;

            GeometryModel3D retVal = new GeometryModel3D();

            retVal.Material     = material;
            retVal.BackMaterial = material;

            double bandHeight     = WeaponDNA.GetKeyValue(prefix + "Height", from, to, StaticRandom.NextPercent(ballRadius * .15, .5));
            double bandHeightHalf = bandHeight / 2d;

            // Slice the hull at the top and bottom band z's
            Point3D[] slice1 = Math3D.GetIntersection_Hull_Plane(ball, new Triangle(new Point3D(0, 0, z - bandHeightHalf), new Point3D(1, 0, z - bandHeightHalf), new Point3D(0, 1, z - bandHeightHalf)));
            Point3D[] slice2 = Math3D.GetIntersection_Hull_Plane(ball, new Triangle(new Point3D(0, 0, z + bandHeightHalf), new Point3D(1, 0, z + bandHeightHalf), new Point3D(0, 1, z + bandHeightHalf)));

            // Enlarge those polygons xy, leave z alone
            slice1 = slice1.Select(o => new Point3D(o.X * ENLARGE, o.Y * ENLARGE, o.Z)).ToArray();
            slice2 = slice2.Select(o => new Point3D(o.X * ENLARGE, o.Y * ENLARGE, o.Z)).ToArray();

            // Now turn those two polygons into a 3d hull
            TriangleIndexed[] band = Math3D.GetConvexHull(UtilityCore.Iterate(slice1, slice2).ToArray());

            retVal.Geometry = UtilityWPF.GetMeshFromTriangles(band);

            return(retVal);
        }
Ejemplo n.º 9
0
        private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            const double LIFESPAN = 45;     // seconds
            const double MINSCORE = .5;
            const int    LEVEL    = 1;

            lock (_lock)
            {
                if (_isDisposed)
                {
                    return;
                }

                foreach (TrackedBot tracked in _trackedBots)
                {
                    switch (tracked.State)
                    {
                    case BotState.Adding:
                    case BotState.Removing:
                        break;

                    case BotState.None:
                        #region None

                        // Create a bot

                        BotDNA dna        = null;
                        BotDNA winningBot = _winningBot;
                        if (winningBot == null)
                        {
                            dna = GetRandomDNA(_itemOptions, _shellColors).Item1;
                        }
                        else
                        {
                            // Create a mutated copy of the winning design
                            dna          = UtilityCore.Clone(winningBot);
                            dna.UniqueID = Guid.NewGuid();
                            dna.Generation++;

                            if (dna.Parts != null)
                            {
                                MutateUtility.Mutate(dna.Parts, _mutateArgs);
                            }
                        }

                        tracked.State = BotState.Adding;

                        tracked.Lifespan = StaticRandom.NextPercent(LIFESPAN, .1);          // randomizing the lifespan a bit to stagger when bots get killed/created

                        Point3D position = Math3D.GetRandomVector_Circular(HOMINGRADIUS / 4d).ToPoint();
                        _dreamWorld.Add(new OfflineWorld.AddBotArgs(position, null, tracked.BotAdded, dna, LEVEL, new Point3D(0, 0, 0), HOMINGRADIUS, this.WeaponDNA));

                        #endregion
                        break;

                    case BotState.Added:
                        #region Added

                        // See if this should die
                        double age = (DateTime.UtcNow - tracked.Bot.CreationTime).TotalSeconds;
                        if (age > tracked.Lifespan)
                        {
                            FitnessTracker rules = tracked.Rules;
                            tracked.Rules = null;          // set it to null as soon as possible so that the rules tick doesn't do unnecessary work

                            double score = rules.Score / age;

                            if (score > MINSCORE && score > _winningScore)
                            {
                                BotDNA winningDNA = tracked.Bot.DNAFinal;

                                if (winningDNA != null)         // it should be non null long before this point, but just make sure
                                {
                                    _winningScore = score;
                                    _winningBot   = winningDNA;
                                }
                            }

                            // Kill it
                            tracked.State = BotState.Removing;
                            _dreamWorld.Remove(new OfflineWorld.RemoveArgs(tracked.Bot.Token, tracked.BotRemoved));
                        }

                        #endregion
                        break;
                    }

                    _timer.Start();
                }
            }
        }