Ejemplo n.º 1
0
            public double Lifespan = 45d;       // seconds

            #region Public Methods

            public void BotAdded(IMapObject item)
            {
                lock (_parentLock)
                {
                    this.Bot = (ArcBotNPC)item;
                    this.Rules = GetRules(this.Bot);

                    this.State = BotState.Added;
                }
            }
Ejemplo n.º 2
0
            public void BotRemoved()
            {
                lock (_parentLock)
                {
                    this.Bot.Dispose();
                    this.Bot = null;
                    // _rules was set to null immediately

                    this.State = BotState.None;
                }
            }
Ejemplo n.º 3
0
        private void Update_AddBot(ArcBotNPC[] currentBots)
        {
            const double HOMINGRADIUS = 8d;
            //const int LEVEL = 1;

            if (currentBots.Length >= 2)       //TODO: Get this from DNA
            {
                // There are enough bots
                return;
            }

            if (_eggs.Count == 0)
            {
                return;
            }
            else if (_eggs[0].Item3 > _time - 4)        // item 0 will always be the oldest egg.  Time is in seconds
            {
                // The egg hasn't been sitting long enough to hatch
                return;
            }

            // Remove the egg
            _eggModels.Children.Remove(_eggs[0].Item1);
            _eggs.RemoveAt(0);

            // Create a bot
            Tuple<BotDNA, WeaponDNA> dna = _dreamer.GetBestBotDNA();

            Point3D? position = _dragPlane.CastRay(this.PositionWorld + Math3D.GetRandomVector_Circular(this.Radius * 3));
            if (position == null)
            {
                throw new ApplicationException("Drag plane couldn't find the nearest point");
            }

            int level = StaticRandom.Next(1, 20);
            ArcBotNPC bot = new ArcBotNPC(dna.Item1, level, position.Value, _world, _map, _keepItems2D, _materialIDs, _viewport, _editorOptions, _itemOptions, _gravity, _dragPlane, this.PositionWorld, HOMINGRADIUS, true, true);

            _map.AddItem(bot);
            _botTokens.Add(bot.Token);

            // Attached Weapon
            //NOTE: Doing this here, because bot.AttachWeapon plays with the viewport, so does map.  If this is done before map, it blows up.
            //if it's done after, then bot.AttachWeapon handles that properly
            if (dna.Item2 != null)
            {
                Weapon weapon = new Weapon(dna.Item2, new Point3D(0, 0, 0), _world, _materialIDs.Weapon);

                bot.AttachWeapon(weapon);
            }
        }
Ejemplo n.º 4
0
        private ArcBotNPC[] Update_DamageBots(ArcBotNPC[] bots)
        {
            if (bots.Length == 0)
            {
                return bots;
            }

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

            Point3D nestPosition = this.PositionWorld;

            double maxDistanceSq = Math.Pow(this.Radius * 14, 2);

            foreach (ArcBotNPC bot in bots)
            {
                //TODO: Add more rules
                if ((bot.PositionWorld - nestPosition).LengthSquared > maxDistanceSq)
                {
                    _map.RemoveItem(bot, true);
                    bot.Dispose();
                }
                else
                {
                    retVal.Add(bot);
                }
            }

            return retVal.ToArray();
        }
Ejemplo n.º 5
0
        //TODO: Move all but graphics to the any thread
        public void Update_MainThread(double elapsedTime)
        {
            _time += elapsedTime;

            _energy.AddQuantity(_itemOptions.Nest_Energy_Add * elapsedTime, false);

            // Get the currently live bots
            ArcBotNPC[] bots;
            if (_botTokens.Count == 0)
            {
                bots = new ArcBotNPC[0];
            }
            else
            {
                bots = _map.GetItems<ArcBotNPC>(false).Where(o => _botTokens.Contains(o.Token)).ToArray();
            }

            // Get rid of tokens that point to dead bots
            foreach (long token in _botTokens.Where(o => !bots.Any(p => p.Token == o)).ToArray())
            {
                _botTokens.Remove(token);
            }

            // Apply damage to existing bots
            bots = Update_DamageBots(bots);

            // Level up existing bots

            // Hatch a new bot
            Update_AddBot(bots);

            // Add egg
            Update_AddEgg(elapsedTime);
        }
Ejemplo n.º 6
0
        private static void AddBot(AddBotArgs dna, WorldVars arg)
        {
            // Bot
            ArcBotNPC bot = new ArcBotNPC(dna.Bot, dna.Level, dna.Position, arg.World, arg.Map, arg.Keep2D, arg.MaterialIDs, null, arg.EditorOptions, arg.ItemOptions, arg.Gravity, arg.DragPlane, dna.HomingPoint, dna.HomingRadius, true, true);

            if (dna.AngularVelocity != null)
            {
                bot.PhysicsBody.AngularVelocity = dna.AngularVelocity.Value;
            }

            arg.Map.AddItem(bot);

            // Attached Weapon
            if (dna.AttachedWeapon != null)
            {
                Weapon weapon = new Weapon(dna.AttachedWeapon, new Point3D(0, 0, 0), arg.World, arg.MaterialIDs.Weapon);

                bot.AttachWeapon(weapon);
            }

            // Inventory Weapons
            if (dna.InventoryWeapons != null)
            {
                foreach (var weapDNA in dna.InventoryWeapons)
                {
                    Weapon weapon = new Weapon(weapDNA, new Point3D(0, 0, 0), arg.World, arg.MaterialIDs.Weapon);

                    bot.AddToInventory(weapon);
                }
            }

            // Call delegate
            if (dna.ItemAdded != null)
            {
                dna.ItemAdded(bot);
            }
        }