public SelectedBean(Bean bean, ShipViewerWindow viewer, Vector3D cameraOffset)
            {
                this.Bean = bean;
                this.Viewer = viewer;
                this.CameraOffset = cameraOffset;

                this.Viewer.Closed += new EventHandler(Viewer_Closed);
            }
 public ExplodingBean(Bean bean, double waveSpeed, double forceAtCenter, double maxRadius, Viewport3D viewport, double visualStartRadius)
     : base(bean.PhysicsBody, waveSpeed, forceAtCenter, maxRadius, viewport, visualStartRadius)
 {
     this.Bean = bean;
 }
        private ExplodingBean ExplodeBean(Bean bean, bool isExplode, double sizeMultiplier, double forceMultiplier)
        {
            double explodeStartRadius = 1d;

            // Don't remove visuals.  Wait until the explosion is complete

            // Turn it into a ghost
            bean.PhysicsBody.ApplyForceAndTorque -= new EventHandler<BodyApplyForceAndTorqueArgs>(Bean_ApplyForceAndTorque);
            bean.PhysicsBody.MaterialGroupID = _material_ExplodingBean;		// the body now won't collide with anything

            double mass = bean.PhysicsBody.Mass;

            // Create the explosion
            ExplodingBean retVal = null;
            if (isExplode)
            {
                // Explode
                retVal = new ExplodingBean(bean, mass * sizeMultiplier * 60d, mass * forceMultiplier * 4000d, mass * sizeMultiplier * 16d, _viewport, explodeStartRadius);
            }
            else
            {
                // Implode
                retVal = new ExplodingBean(bean, mass * sizeMultiplier * 60d, mass * forceMultiplier * -3d, mass * sizeMultiplier * 16d, _viewport, explodeStartRadius);
            }

            _explosions.Add(retVal);

            // Exit Function
            return retVal;
        }
        private void DisposeBean(Bean bean)
        {
            //NOTE: This method should be called for an instant kill of a bean, not called by explosion

            if (_selectedBean != null && _selectedBean.Bean == bean)
            {
                if (_selectedBean.Viewer != null)
                {
                    //TODO: This will get very annoying
                    _selectedBean.Viewer.Close();
                }

                _selectedBean = null;
            }

            _map.RemoveItem(bean, true);
            _beans.Remove(bean);
            bean.Dispose();
        }
        private async Task<Bean> AddBeanAsync(ShipDNA dna)
        {
            ShipCoreArgs core = new ShipCoreArgs()
            {
                //Map = _map,       // this wasn't passed in when it was a ship
                Material_Ship = _material_Bean,
                World = _world,
            };

            ShipExtraArgs args = new ShipExtraArgs()
            {
                Options = _editorOptions,
                ItemOptions = _itemOptions,
                Material_Projectile = _material_Projectile,
                Radiation = _radiation,
                Gravity = _options.GravityField,
            };

            //Bean retVal = await Bean.GetNewBeanAsync(dna, _world, _material_Bean, args, _options);
            var seed = BotConstructor.ConstructBot(dna, core, args);
            Bean retVal = new Bean(seed, _options);

            //retVal.PhysicsBody.AngularDamping = new Vector3D(1, 1, 1);
            retVal.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Bean_ApplyForceAndTorque);
            retVal.Dead += new EventHandler<DeadBeanArgs>(Bean_Dead);

            if (_options.NewBeanRandomOrientation)
            {
                retVal.PhysicsBody.Rotation = Math3D.GetRandomRotation();
            }

            if (_options.NewBeanRandomSpin)
            {
                Vector3D angularVelocity = Math3D.GetRandomVector_Spherical_Shell(1d);
                angularVelocity *= _options.AngularVelocityDeath * .5d;

                retVal.PhysicsBody.AngularVelocity = angularVelocity;
            }

            if (retVal.Energy != null)
            {
                retVal.Energy.QuantityCurrent = retVal.Energy.QuantityMax;
            }
            if (retVal.Fuel != null)
            {
                retVal.Fuel.QuantityCurrent = retVal.Fuel.QuantityMax;
            }
            retVal.RecalculateMass();

            Vector3D position = Math3D.GetRandomVector_Circular(TERRAINRADIUS * .5d);
            retVal.PhysicsBody.Position = new Point3D(position.X, position.Y, STARTHEIGHT);

            _map.AddItem(retVal);
            _beans.Add(retVal);

            _options.TotalBeans++;
            this.TotalBeansText = _options.TotalBeans.ToString("N0");

            return retVal;
        }