コード例 #1
0
        private void RemoveBot()
        {
            // Viewer
            if (_viewer != null)
            {
                _viewer.Close();
                _viewer = null;
            }

            // Brain Viewer
            panelCustom.Content = null;
            _brainViewer = null;

            //Progress Bars
            _progressBars = null;
            pnlProgressBars.Visibility = Visibility.Collapsed;

            // Bot
            if (_bot != null)
            {
                _map.RemoveItem(_bot);

                _bot.Dispose();
                _bot = null;
            }
        }
コード例 #2
0
        private void SetBot(DefenseBot bot)
        {
            // Remove
            RemoveBot();

            // Set bot
            _map.AddItem(bot);
            _bot = bot;

            // Brain Viewer
            BrainRGBRecognizer brainRecog = _bot.Parts.FirstOrDefault(o => o is BrainRGBRecognizer) as BrainRGBRecognizer;
            if (brainRecog != null)
            {
                _brainViewer = new BrainRGBRecognizerViewer()
                {
                    Recognizer = brainRecog,
                };
                panelCustom.Content = _brainViewer;
            }

            // Progress bars
            _progressBars = new ShipProgressBarManager(pnlProgressBars);
            _progressBars.Bot = _bot;
            _progressBars.Foreground = this.Foreground;
            pnlProgressBars.Visibility = Visibility.Visible;
        }
コード例 #3
0
        private void SetBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                #region DNA

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

                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.44329742616787, -2.22044604925031E-16, -0.750606111984116), Scale = new Vector3D(.65, .65, .65) });

                parts.Add(new ShipPartDNA() { PartType = AmmoBox.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.44329742616787, -2.22044604925031E-16, -0.839035218662306), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = ProjectileGun.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.139350859269598, -2.22044604925031E-16, 0.0736057604093046), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = CameraColorRGB.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.443930484830668, -2.22044604925031E-16, -0.0296267373083678), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(1.17108888679796, 2.22044604925031E-16, -0.787190712968899), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new BrainRGBRecognizerDNA() { PartType = BrainRGBRecognizer.PARTTYPE, Orientation = new Quaternion(3.91881768803066E-16, -0.264772715428398, 1.07599743798686E-16, 0.964310846752577), Position = new Point3D(0.977003177386146, 0, -0.204027736848604), Scale = new Vector3D(1, 1, 1), Extra = GetBrainRGBRecognizerExtra() });

                parts.Add(new ShipPartDNA() { PartType = CargoBay.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.812435730367477, 0, -1.83945537515666), Scale = new Vector3D(1, 1, 1) });

                //parts.Add(new ShipPartDNA() { PartType = ConverterMatterToAmmo.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.724059461163413, 0, -1.57962039018549), Scale = new Vector3D(1, 1, 1) });
                parts.Add(new ShipPartDNA() { PartType = ConverterMatterToEnergy.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.127736487867665, 0, -1.58633876430099), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = PlasmaTank.PARTTYPE, Orientation = new Quaternion(0, -0.706641960456376, 0, 0.707571296564784), Position = new Point3D(-0.406755692018177, 0, -2.20579025132833), Scale = new Vector3D(1, 1, 1) });

                ShipDNA dna = ShipDNA.Create(parts);
                dna.ShipLineage = Guid.NewGuid().ToString();

                #endregion

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Projectile,
                    CameraPool = _cameraPool,
                    IsPhysicsStatic = true,
                };

                BotConstruction_Result seed = BotConstructor.ConstructBot(dna, core, extra);
                DefenseBot bot = new DefenseBot(seed);
                bot.PhysicsBody.Position = new Point3D(0, 0, -12);

                bot.ShouldLearnFromLifeEvents = false;

                if (bot.Energy != null)
                {
                    bot.Energy.QuantityCurrent = bot.Energy.QuantityMax;
                }
                if (bot.Ammo != null)
                {
                    bot.Ammo.QuantityCurrent = bot.Ammo.QuantityMax;
                }
                if (bot.Plasma != null)
                {
                    bot.Plasma.QuantityCurrent = bot.Plasma.QuantityMax;
                }

                bot.ShouldLearnFromLifeEvents = true;

                SetBot(bot);

                #region save to file

                //dna = bot.GetNewDNA();

                ////C:\Users\<username>\AppData\Roaming\Asteroid Miner\MissileCommand0D\
                //string foldername = UtilityCore.GetOptionsFolder();
                //foldername = System.IO.Path.Combine(foldername, FOLDER);
                //System.IO.Directory.CreateDirectory(foldername);

                //string filename = DateTime.Now.ToString("yyyyMMdd HHmmssfff") + " - bot";
                //filename = System.IO.Path.Combine(foldername, filename);

                //UtilityCore.SerializeToFile(filename, dna);

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }