Ejemplo n.º 1
0
        /// <summary>
        /// This is to manually update the mass matrix
        /// </summary>
        /// <remarks>
        /// NOTE: There is some expense to calling this, so avoid calling it too often
        /// </remarks>
        public void RecalculateMass()
        {
            lock (_lockRecalculateMass)
            {
                Tuple <MassMatrix, Point3D> massBreakdown = BotConstructor.GetInertiaTensorAndCenterOfMass_Points(_parts.AllPartsArray, _dnaParts, _itemOptions.MomentOfInertiaMultiplier);

                if (_isPhysicsStatic)
                {
                    this.PhysicsBody.CenterOfMass = new Point3D(0, 0, 0);       // Part_RequestWorldLocation is wrong if this isn't zero as well
                    this.PhysicsBody.Mass         = 0;
                }
                else
                {
                    this.PhysicsBody.CenterOfMass = massBreakdown.Item2;
                    this.PhysicsBody.MassMatrix   = massBreakdown.Item1;
                }

                if (_parts.Containers.AmmoGroup != null)
                {
                    _ammoVolumeAtRecalc = _parts.Containers.AmmoGroup.QuantityCurrent;
                }

                _lastMassRecalculateTime     = this.Age;
                this.ShouldRecalcMass_Large  = false;
                this.ShouldRecalcMass_Medium = false;
                this.ShouldRecalcMass_Small  = false;
            }

            OnMassRecalculated();
        }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        bot = GameObject.Find("BotConstructor").GetComponent <BotConstructor>();
        rightBottomGunGUI = transform.Find("rightBottomGun");
        leftBottomGunGUI  = transform.Find("leftBottomGun");

        chassisText      = transform.Find("chassis/text").GetComponent <Text>();
        chassisText.text = chassis.ToString();

        bodyText      = transform.Find("body/text").GetComponent <Text>();
        bodyText.text = body.ToString();

        leftShoulderText      = transform.Find("leftShoulder/text").GetComponent <Text>();
        leftShoulderText.text = leftShoulder.ToString();

        rightShoulderText      = transform.Find("rightShoulder/text").GetComponent <Text>();
        rightShoulderText.text = rightShoulder.ToString();

        leftTopGunText      = transform.Find("leftTopGun/text").GetComponent <Text>();
        leftTopGunText.text = leftTopGun.ToString();

        rightTopGunText      = transform.Find("rightTopGun/text").GetComponent <Text>();
        rightTopGunText.text = rightTopGun.ToString();

        leftBottomGunText      = transform.Find("leftBottomGun/text").GetComponent <Text>();
        leftBottomGunText.text = leftBottomGun.ToString();

        rightBottomGunText      = transform.Find("rightBottomGun/text").GetComponent <Text>();
        rightBottomGunText.text = rightBottomGun.ToString();

        leftBottomGunGUI.gameObject.SetActive(bot.leftBottomGunAvailable);
        rightBottomGunGUI.gameObject.SetActive(bot.rightBottomGunAvailable);
    }
Ejemplo n.º 3
0
        //TODO: Make a static method off of Ship, and don't rely on world: public static Visual3D CreateVisual(ShipDNA dna, bool isDesign)
        private void RenderShipAsync(NewtonDynamics.World world)
        {
            ShipExtraArgs args = new ShipExtraArgs()
            {
                RunNeural           = false,
                RepairPartPositions = false,
            };

            //using (Ship ship = await Ship.GetNewShipAsync(this.ShipDNA, world, 0, null, args))
            using (Bot bot = new Bot(BotConstructor.ConstructBot(this.ShipDNA, new ShipCoreArgs()
            {
                World = world
            }, args)))
            {
                if (bot.PhysicsBody.Visuals != null)            // this will never be null
                {
                    // The model coords may not be centered, so move the ship so that it's centered on the origin
                    Point3D minPoint, maxPoint;
                    bot.PhysicsBody.GetAABB(out minPoint, out maxPoint);
                    Vector3D offset = (minPoint + ((maxPoint - minPoint) / 2d)).ToVector();

                    bot.PhysicsBody.Position = (-offset).ToPoint();

                    // Add the visuals
                    foreach (Visual3D visual in bot.PhysicsBody.Visuals)
                    {
                        _viewport.Children.Add(visual);
                    }

                    // Pull the camera back to a good distance
                    _camera.Position = (_camera.Position.ToVector().ToUnit() * (bot.Radius * 2.1d)).ToPoint();
                }
            }
        }
Ejemplo n.º 4
0
        public DesignPart Clone()
        {
            DesignPart retVal = new DesignPart(_options);

            retVal.Part2D = this.Part2D;                // this shouldn't be cloned, it's just a link to the source

            if (this.Part2D == null)
            {
                retVal.Part3D = BotConstructor.GetPartDesign(this.Part3D.GetDNA(), _options, this.Part3D.IsFinalModel);
            }
            else
            {
                retVal.Part3D = retVal.Part2D.GetNewDesignPart();
            }

            ModelVisual3D model = new ModelVisual3D();

            model.Content = retVal.Part3D.Model;
            retVal.Model  = model;

            retVal.Part3D.Position    = this.Part3D.Position;
            retVal.Part3D.Orientation = this.Part3D.Orientation;
            retVal.Part3D.Scale       = this.Part3D.Scale;

            if (this.GuideLines != null)                // this needs to be created after the position is set
            {
                retVal.CreateGuildLines();
            }

            return(retVal);
        }
Ejemplo n.º 5
0
        public static ShipPlayer GetNewShip(ShipDNA dna, World world, int material_Ship, Map map, ShipExtraArgs extra)
        {
            ShipDNA rotatedDNA = RotateDNA_FromExternal(dna);

            #region asserts

            //ShipDNA rockedDNA1 = RotateDNA_ToExternal(RotateDNA_FromExternal(dna));
            //ShipDNA rockedDNA2 = RotateDNA_FromExternal(rockedDNA1);

            //var compare1a = dna.PartsByLayer.SelectMany(o => o.Value).ToArray();
            //var compare1b = rockedDNA1.PartsByLayer.SelectMany(o => o.Value).ToArray();

            //var compare2a = rotatedDNA.PartsByLayer.SelectMany(o => o.Value).ToArray();
            //var compare2b = rockedDNA2.PartsByLayer.SelectMany(o => o.Value).ToArray();

            //for(int cntr = 0; cntr < compare1a.Length; cntr++)
            //{
            //    var com1a = compare1a[cntr];
            //    var com1b = compare1b[cntr];

            //    var com2a = compare2a[cntr];
            //    var com2b = compare2b[cntr];

            //    if(!Math3D.IsNearValue(com1a.Position, com1b.Position))
            //    {
            //        int three = 3;
            //    }
            //    if (!Math3D.IsNearValue(com1a.Orientation, com1b.Orientation))
            //    {
            //        int three = 3;
            //    }

            //    if (!Math3D.IsNearValue(com2a.Position, com2b.Position))
            //    {
            //        int four = 4;
            //    }
            //    if (!Math3D.IsNearValue(com2a.Orientation, com2b.Orientation))
            //    {
            //        int four = 4;
            //    }
            //}

            #endregion

            ShipCoreArgs core = new ShipCoreArgs()
            {
                Map           = map,
                Material_Ship = material_Ship,
                World         = world,
            };

            //var construction = await GetNewShipConstructionAsync(options, itemOptions, rotatedDNA, world, material_Ship, material_Projectile, radiation, gravity, cameraPool, map, true, true);
            //var construction = await GetNewShipConstructionAsync(rotatedDNA, world, material_Ship, map, extra);
            var construction = BotConstructor.ConstructBot(rotatedDNA, core, extra);

            return(new ShipPlayer(construction));
        }
Ejemplo n.º 6
0
        private static DesignPart CreateDesignPart(ShipPartDNA dna, EditorOptions options)
        {
            DesignPart retVal = new DesignPart(options)
            {
                Part2D = null,      // setting 2D to null will tell the editor that the part can't be resized or copied, only moved around
                Part3D = BotConstructor.GetPartDesign(dna, options, false),
            };

            ModelVisual3D visual = new ModelVisual3D();

            visual.Content = retVal.Part3D.Model;
            retVal.Model   = visual;

            return(retVal);
        }
Ejemplo n.º 7
0
        public Cargo_ShipPart(ShipPartDNA dna, ItemOptions options, EditorOptions editorOptions)
            : base(CargoType.ShipPart)
        {
            PartDesignBase part = BotConstructor.GetPartDesign(dna, editorOptions, true);

            //TODO: This is really ineficient, let design calculate it for real
            //TODO: Volume and Mass should be calculated by the design class (add to PartBase interface)
            var aabb = Math3D.GetAABB(UtilityWPF.GetPointsFromMesh(part.Model));

            this.Volume = (aabb.Item2.X - aabb.Item1.X) * (aabb.Item2.Y - aabb.Item1.Y) * (aabb.Item2.Y - aabb.Item1.Y);

            //TODO: Let the design class return this (expose a property called DryDensity)
            this.Density = Math1D.Avg(options.Thruster_Density, options.Sensor_Density);

            this.PartDNA = dna;
        }
Ejemplo n.º 8
0
        private static Tuple <InventoryEntry, PartDesignBase>[] GatherParts_FromPanel(UIElementCollection panel, EditorOptions editorOptions, bool isFinalModel)
        {
            var retVal = new List <Tuple <InventoryEntry, PartDesignBase> >();

            foreach (var item in panel)
            {
                InventoryEntry inventory = item as InventoryEntry;
                if (inventory == null || inventory.Inventory.Part == null)
                {
                    continue;
                }

                PartDesignBase part = BotConstructor.GetPartDesign(inventory.Inventory.Part, editorOptions, isFinalModel);

                retVal.Add(Tuple.Create(inventory, part));
            }

            return(retVal.ToArray());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// This will return a constructed arcbot (arcbots have hardcoded dna)
        /// </summary>
        public static BotConstruction_Result GetConstruction(int level, ShipCoreArgs core, ShipExtraArgs extra, DragHitShape dragPlane, bool addHomingSensor)
        {
            BotConstructor_Events events = new BotConstructor_Events
            {
                InstantiateUnknownPart_Standard = InstantiateUnknownPart_Standard,
            };

            object[] botObjects = new object[]
            {
                new ArcBot2_ConstructionProps()
                {
                    DragPlane = dragPlane,
                    Level     = level,
                },
            };

            ShipDNA dna = GetDefaultDNA(addHomingSensor);

            return(BotConstructor.ConstructBot(dna, core, extra, events, botObjects));
        }
Ejemplo n.º 10
0
        private PartDesignBase[] GatherParts(bool isFinalModel)
        {
            // CargoBay
            _fromCargo = _player.Ship.CargoBays == null ?
                         new Tuple <Cargo_ShipPart, PartDesignBase> [0] :
                         _player.Ship.CargoBays.GetCargoSnapshot().
                         Select(o => o as Cargo_ShipPart).
                         Where(o => o != null).
                         Select(o => Tuple.Create(o, BotConstructor.GetPartDesign(o.PartDNA, _editorOptions, isFinalModel))).
                         ToArray();

            // Nearby
            _fromNearby = GatherParts_FromPanel(_spaceDock.pnlNearbyItems.Children, _editorOptions, isFinalModel);

            // Hangar
            _fromHangar = GatherParts_FromPanel(_spaceDock.pnlHangar.Children, _editorOptions, isFinalModel);

            // Combine them
            return(_fromCargo.Select(o => o.Item2).
                   Concat(_fromNearby.Select(o => o.Item2)).
                   Concat(_fromHangar.Select(o => o.Item2)).
                   ToArray());
        }
Ejemplo n.º 11
0
        public Icon3D(ShipPartDNA dna, EditorOptions options)
        {
            InitializeComponent();

            // Need to set position to zero, or the image won't be centered (part's model considers position/orientation)
            dna             = UtilityCore.Clone(dna);
            dna.Position    = new Point3D();
            dna.Orientation = Quaternion.Identity;

            PartDesignBase part = BotConstructor.GetPartDesign(dna, options, false);

            this.ItemName = part.PartType;
            this.Part     = part;

            lblName.Text = this.ItemName;

            lblName.Visibility = _showName ? Visibility.Visible : Visibility.Collapsed;

            InitializeTrackball();

            RenderPart();
            InitializeLight();
        }
Ejemplo n.º 12
0
 public BotDriver(string host, int port, BotConstructor botSource)
 {
     client         = new GameClient(host, port);
     this.botSource = botSource;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Once the world is created on the worker thread, maps and bots need to be created for each room
        /// NOTE: This is called from the worker thread
        /// </summary>
        private void Arena_WorldCreated(object sender, EventArgs e)
        {
            World world = Arena.WorldAccessor.World;

            #region materials

            MaterialManager = new MaterialManager(world);
            MaterialIDs     = new MaterialIDs();

            // Wall
            Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material();
            material.Elasticity = ItemOptionsArco.ELASTICITY_WALL;
            MaterialIDs.Wall    = MaterialManager.AddMaterial(material);

            // Bot
            material        = new Game.Newt.v2.NewtonDynamics.Material();
            MaterialIDs.Bot = MaterialManager.AddMaterial(material);

            // Bot Ram
            material            = new Game.Newt.v2.NewtonDynamics.Material();
            material.Elasticity = ItemOptionsArco.ELASTICITY_BOTRAM;
            MaterialIDs.BotRam  = MaterialManager.AddMaterial(material);

            // Exploding Bot
            material = new Game.Newt.v2.NewtonDynamics.Material();
            material.IsCollidable    = false;
            MaterialIDs.ExplodingBot = MaterialManager.AddMaterial(material);

            // Weapon
            material           = new Game.Newt.v2.NewtonDynamics.Material();
            MaterialIDs.Weapon = MaterialManager.AddMaterial(material);

            // Treasure Box
            material = new Game.Newt.v2.NewtonDynamics.Material();
            MaterialIDs.TreasureBox = MaterialManager.AddMaterial(material);

            //TODO: Uncomment these
            // Collisions
            //_materialManager.RegisterCollisionEvent(_materialIDs.Bot, _materialIDs.Bot, Collision_BotBot);
            //_materialManager.RegisterCollisionEvent(_materialIDs.Bot, _materialIDs.Weapon, Collision_BotWeapon);
            //_materialManager.RegisterCollisionEvent(_materialIDs.Weapon, _materialIDs.Weapon, Collision_WeaponWeapon);
            ////_materialManager.RegisterCollisionEvent(_materialIDs.Bot, _materialIDs.Wall, Collision_BotWall);
            //_materialManager.RegisterCollisionEvent(_materialIDs.Weapon, _materialIDs.Wall, Collision_WeaponWall);
            //_materialManager.RegisterCollisionEvent(_materialIDs.Weapon, _materialIDs.TreasureBox, Collision_WeaponTreasureBox);
            //_materialManager.RegisterCollisionEvent(_materialIDs.Bot, _materialIDs.TreasureBox, Collision_BotTreasureBox);

            #endregion

            List <KeepItems2D> keep2Ds = new List <KeepItems2D>();

            foreach (var(room, _) in Arena.AllRooms)
            {
                #region keep 2D

                //TODO: drag plane should either be a plane or a large cylinder, based on the current (level|scene|stage|area|arena|map|place|region|zone)

                // This game is 3D emulating 2D, so always have the mouse go to the XY plane
                DragHitShape dragPlane = new DragHitShape();
                dragPlane.SetShape_Plane(new Triangle(new Point3D(-1, -1, room.Center.Z), new Point3D(1, -1, room.Center.Z), new Point3D(0, 1, room.Center.Z)));

                // This will keep objects onto that plane using forces (not velocities)
                KeepItems2D keep2D = new KeepItems2D
                {
                    SnapShape = dragPlane,
                };

                //keep2D.Add(room.Bot, false);
                keep2Ds.Add(keep2D);

                #endregion

                #region bot

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    World         = world,
                    Material_Ship = MaterialIDs.Bot,
                    Map           = room.Map,
                };

                //BotConstructor_Events events = new BotConstructor_Events();
                //events.

                // Create the bot
                Bot bot = null;
                if (RequestCustomBot != null)
                {
                    bot = RequestCustomBot(core, keep2D, dragPlane, MaterialIDs);
                }
                else
                {
                    BotConstruction_Result construction = BotConstructor.ConstructBot(DNA, core, ShipExtraArgs);
                    bot = new Bot(construction);
                }

                // Find some parts
                BrainNEAT brainPart = bot.Parts.FirstOrDefault(o => o is BrainNEAT) as BrainNEAT;
                if (brainPart == null)
                {
                    throw new ApplicationException("Didn't find BrainNEAT part");
                }

                SensorHoming[] homingParts = bot.Parts.
                                             Where(o => o is SensorHoming).
                                             Select(o => (SensorHoming)o).
                                             ToArray();

                if (homingParts.Length == 0)
                {
                    throw new ApplicationException("Didn't find SensorHoming part");
                }

                #endregion

                room.Bot         = bot;
                room.BrainPart   = brainPart;
                room.HomingParts = homingParts;

                foreach (SensorHoming homing in homingParts)
                {
                    homing.HomePoint  = room.Center;
                    homing.HomeRadius = (ROOMSIZE / 2d) * Evaluator3.MULT_HOMINGSIZE;
                }

                room.Map.AddItem(bot);

                keep2D.Add(room.Bot, false);
            }

            Keep2D = keep2Ds.ToArray();

            world.Updated += World_Updated;
        }
Ejemplo n.º 14
0
        private void AddBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //TODO: Implement:
                //  ConverterMatterToFuel
                //  ConverterMatterToEnergy

                //_itemOptions.CameraColorRGBNeuronDensity = 160 * 3;

                #region DNA

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

                parts.Add(new ShipPartDNA()
                {
                    PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 1.43121944558768), Scale = new Vector3D(2.7969681248785, 2.7969681248785, 0.754175785992705)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.617709955450103, 0, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-2.16134944924876E-05, -0.60985890545398, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.00387496389974934, 0.618396858731443, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.624666220599071, 0.00100528924605325, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });

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

                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.850947345148112, -0.0019217800299223, -0.1657062616585), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00589599969475301, 0.850929089078933, -0.1657062616585), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00522521361558187, -0.850933472485232, -0.165706261658499), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.850949515219971, 0, -0.165706261658499), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = ConverterMatterToFuel.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.232899395582397, -0.238935114546265, 0.773100284172734), Scale = new Vector3D(0.903613735551713, 0.903613735551713, 0.903613735551713)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = ConverterMatterToEnergy.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.22797553388197, 0.226717979419686, 0.775967026847012), Scale = new Vector3D(0.903613735551713, 0.903613735551713, 0.903613735551713)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = SensorSpin.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.262933776282848, 0.240405245709603, 0.755961022082205), Scale = new Vector3D(1, 1, 1)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.250217552102507, -0.280865739393283, 0.743561713316594), Scale = new Vector3D(0.399083346950047, 0.399083346950047, 0.236501125779081)
                });                                                                                                                                                                                                                                                                         // This is just a placeholder for a future sensor (need to put something here so mass is balanced)

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

                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00137913748707474, 0, -1.20661030017992), Scale = new Vector3D(1.29260597488229, 1.29260597488229, 1.29260597488229), ThrusterType = ThrusterType.One
                });

                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = new Quaternion(-0.623025498564933, -0.775855164007238, -0.0622612340741654, 0.0775340657568128), Position = new Point3D(0.189965645143804, -0.859019870524953, 0.883258802478369), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One
                });
                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = new Quaternion(0.948585651195026, -0.300495041099996, 0.0947956598959211, 0.0300295768554372), Position = new Point3D(-0.719304806310003, 0.506559650891123, 0.883258802478371), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One
                });
                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = new Quaternion(0.304146575685315, -0.947421167104513, 0.0303944881633535, 0.0946792887093452), Position = new Point3D(0.715381156965589, 0.512085817563994, 0.883258802478369), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One
                });

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

                #endregion

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

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

                //Swimbot bot = await Swimbot.GetNewSwimbotAsync(dna, _world, _material_Bot, _map, extra);
                Swimbot bot = new Swimbot(BotConstructor.ConstructBot(dna, core, extra));
                bot.PhysicsBody.ApplyForceAndTorque += new EventHandler <BodyApplyForceAndTorqueArgs>(Bot_ApplyForceAndTorque);

                bot.PhysicsBody.Rotation = Math3D.GetRandomRotation();
                bot.PhysicsBody.Position = Math3D.GetRandomVector_Spherical(BOUNDRYSIZEHALF * .5d).ToPoint();

                //bot.PhysicsBody.Position = new Point3D(0, 0, BOUNDRYSIZEHALF * -.75d);

                if (bot.Energy != null)
                {
                    bot.Energy.QuantityCurrent = bot.Energy.QuantityMax * .5d;
                }
                if (bot.Fuel != null)
                {
                    bot.Fuel.QuantityCurrent = bot.Fuel.QuantityMax * .5d;
                }
                bot.RecalculateMass();

                _map.AddItem(bot);
                _bots.Add(bot);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 15
0
        private void SetBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int numThrusters;
                if (!int.TryParse(txtNumThrusters.Text, out numThrusters))
                {
                    MessageBox.Show("Couldn't parse the number of thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                else if (numThrusters < 2)
                {
                    MessageBox.Show("Must have at least two thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                #region DNA

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

                parts.Add(new ShipPartDNA()
                {
                    PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0.283735185991315), Scale = new Vector3D(2.05963659008885, 2.05963659008885, 0.301082085094996)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, -0.490401090473184), Scale = new Vector3D(1.92697281805995, 1.92697281805995, 1.1591130722673)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = SensorSpin.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0.57985483357727), Scale = new Vector3D(1, 1, 1)
                });

                parts.AddRange(GetRandomThrusters(numThrusters, chkRandRotateThrusters.IsChecked.Value, (ThrusterTypeValues)cboThrusterTypes.SelectedItem, chkSomeDestroyed.IsChecked.Value));

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

                #endregion

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

                BotConstruction_Result seed = BotConstructor.ConstructBot(dna, core);
                ControlledThrustBot    bot  = new ControlledThrustBot(seed);

                SetBot(bot);

                // Start looking for a solution immediately
                if (chkBalanceThrusters.IsChecked.Value)
                {
                    BalanceBot_Forward(_bot);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 16
0
    // Use this for initialization
    void Start()
    {
        bot = GameObject.Find("BotConstructor").GetComponent<BotConstructor>();
        rightBottomGunGUI = transform.Find("rightBottomGun");
        leftBottomGunGUI = transform.Find("leftBottomGun");

        chassisText = transform.Find("chassis/text").GetComponent<Text>();
        chassisText.text = chassis.ToString();

        bodyText = transform.Find("body/text").GetComponent<Text>();
        bodyText.text = body.ToString();

        leftShoulderText = transform.Find("leftShoulder/text").GetComponent<Text>();
        leftShoulderText.text = leftShoulder.ToString();

        rightShoulderText = transform.Find("rightShoulder/text").GetComponent<Text>();
        rightShoulderText.text = rightShoulder.ToString();

        leftTopGunText = transform.Find("leftTopGun/text").GetComponent<Text>();
        leftTopGunText.text = leftTopGun.ToString();

        rightTopGunText = transform.Find("rightTopGun/text").GetComponent<Text>();
        rightTopGunText.text = rightTopGun.ToString();

        leftBottomGunText = transform.Find("leftBottomGun/text").GetComponent<Text>();
        leftBottomGunText.text = leftBottomGun.ToString();

        rightBottomGunText = transform.Find("rightBottomGun/text").GetComponent<Text>();
        rightBottomGunText.text = rightBottomGun.ToString();

        leftBottomGunGUI.gameObject.SetActive(bot.leftBottomGunAvailable);
        rightBottomGunGUI.gameObject.SetActive(bot.rightBottomGunAvailable);
    }