コード例 #1
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));
        }
コード例 #2
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));
        }
コード例 #3
0
        public static PartBase InstantiateUnknownPart_Standard(ShipPartDNA dna, ShipCoreArgs core, ShipExtraArgs extra, BotConstruction_Containers containers, object[] botObjects)
        {
            ItemOptionsArco itemOptions = (ItemOptionsArco)extra.ItemOptions;

            var constructProps = botObjects?.FirstOrDefault(o => o is ArcBot2_ConstructionProps) as ArcBot2_ConstructionProps;

            if (constructProps == null)
            {
                throw new ApplicationException("ArcBot2_ConstructionProps needs to be given to the bot constructor in the botObjects param");
            }

            double botRadius = itemOptions.RadiusAtLevel[constructProps.Level];

            switch (dna.PartType)
            {
            case MotionController2.PARTTYPE:
                //if (MotionController.Count > 0)
                //{
                //    throw new ApplicationException("There can be only one plate writer in a bot");
                //}

                AIMousePlate mousePlate = new AIMousePlate(constructProps.DragPlane);
                mousePlate.MaxXY = botRadius * 20;
                mousePlate.Scale = 1;

                return(new MotionController2(extra.Options, itemOptions, dna, mousePlate));

            case SensorVision.PARTTYPE:
                if (dna is SensorVisionDNA sensorVisionDNA)
                {
                    return(new SensorVision(extra.Options, itemOptions, (SensorVisionDNA)dna, core.Map));
                }
                else
                {
                    throw new ApplicationException($"SensorVision requires SensorVisionDNA: {dna.GetType()}");
                }

            default:
                throw new ApplicationException($"Unknown PartType: {dna.PartType}");
            }
        }
コード例 #4
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;
        }
コード例 #5
0
        private void ConstructionTimings_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                #region Boston

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

                parts.Add(new ShipPartDNA() { PartType = SensorGravity.PARTTYPE, Position = new Point3D(0.06262624381726, 0.0452319990776786, 0.0107575852705214), Orientation = Quaternion.Identity, Scale = new Vector3D(1.98055565775194, 1.98055565775194, 1.98055565775194) });

                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Position = new Point3D(0.0640302221718942, 0.0452319990776786, -0.398262947326255), Orientation = Quaternion.Identity, Scale = new Vector3D(0.859573285557595, 0.859573285557595, 0.363133980141406) });
                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Position = new Point3D(0.0640302221718961, -0.359505731862839, 0.00974082197643137), Orientation = new Quaternion(-0.707994401651682, 0, 0, -0.706218045103548), Scale = new Vector3D(0.859573285557595, 0.859573285557595, 0.363133980141406) });
                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Position = new Point3D(0.0640302221718942, 0.0452319990776786, 0.415496593341741), Orientation = Quaternion.Identity, Scale = new Vector3D(0.859573285557595, 0.859573285557595, 0.363133980141406) });
                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Position = new Point3D(0.0640302221718945, 0.449970182263215, 0.00994044015096636), Orientation = new Quaternion(-0.707820225525904, 0, 0, 0.706392616281101), Scale = new Vector3D(0.859573285557595, 0.859573285557595, 0.363133980141406) });

                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(-0.633871040519167, 0.0452319990776786, 0.0105599048346808), Orientation = new Quaternion(-1.06613503606533E-14, 0.706983101400418, 1.04235729042214E-14, 0.707230439343675), Scale = new Vector3D(1.50569057774504, 1.50569057774504, 0.952322625051029) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(-0.40793184117455, -0.333915145708534, -0.399430190653673), Orientation = new Quaternion(0.0179820697650735, 0.410182924354628, 0.5149540512311, 0.752495142081016), Scale = new Vector3D(0.959781086082721, 0.959781086082721, 0.56790863228087) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(0.774629433149324, 0.0452319990776786, 0.0105599048346808), Orientation = new Quaternion(-1.06613503606533E-14, 0.706983101400418, 1.04235729042214E-14, 0.707230439343675), Scale = new Vector3D(1.50569057774504, 1.50569057774504, 0.952322625051029) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(0.315023390587194, 0.619221355357736, -0.505349024898043), Orientation = new Quaternion(0.290518532869616, 0.287747281934623, -0.74359105344961, 0.529030083292266), Scale = new Vector3D(0.829438489501124, 0.829438489501124, 0.737751084688027) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(0.309455393701602, -0.704869873678094, 0.553399487133765), Orientation = new Quaternion(0.54207375147106, 0.683170759778384, 0.237900525971097, -0.427594551757378), Scale = new Vector3D(0.959781086082721, 0.959781086082721, 0.56790863228087) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(-0.553193493827276, 0.478546505441548, 0.548071445321983), Orientation = new Quaternion(0.598130585181683, 0.578229996417228, 0.0768855317204965, 0.549525694872958), Scale = new Vector3D(0.959781086082721, 0.959781086082721, 0.56790863228087) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(-0.135795078147285, -0.112441024889166, 0.931542744345501), Orientation = new Quaternion(0.658120115364394, 0.744147750445601, 0.0233404096588955, 0.112148404074527), Scale = new Vector3D(0.959781086082721, 0.959781086082721, 0.56790863228087) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(0.318035997738273, 0.58888924058271, 0.53862326999682), Orientation = new Quaternion(0.727956183597861, 0.476918202992041, -0.358769433521041, 0.337510467967247), Scale = new Vector3D(0.959781086082721, 0.959781086082721, 0.56790863228087) });

                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-1.39207379925579, 0.31976381759203, -0.144977694320637), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-0.95108934283864, 0.082154705114342, -1.07864171487276), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-1.26237238850117, 0.137887583052503, 0.682744920802546), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-0.209724903293652, 0.759958101622015, -1.26625645655205), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-1.0437807852787, -0.703019537745404, -0.646324247998212), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-0.804024155014174, 1.04164516079897, -0.676156753899043), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(0.770385334720267, -0.614876859274918, -1.12021844293319), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(0.826083478713381, 1.19816066586892, 0.561812892638671), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(0.010054612300213, 1.35065612899851, 0.724114071596212), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(0.714123702527216, 0.972122864502635, -0.95474632300179), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-0.488119432659847, -1.33606569285772, -0.0560952239342334), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(1.27567102575173, -0.713124822170317, -0.400570386901382), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-0.122574480585318, -1.19141979478037, 0.818325814234051), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(1.49619785350449, 0.0968818300980203, 0.40822223383338), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(0.591501938051828, -0.897487268188259, 1.03415599018248), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(0.602146634482277, 0.495637281658607, 1.32294135345344), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-0.55718253942255, -0.516621575629162, 1.24198910079097), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-0.506679104500458, 0.585267411438967, 1.2756791582447), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-0.910122425235313, 1.08914531989134, 0.434760436071202), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = new Point3D(-0.125720513509375, -0.977047473173131, -1.0547205194421), Orientation = Quaternion.Identity, Scale = new Vector3D(0.312935800748763, 0.312935800748763, 0.312935800748763) });

                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-0.106944297856511, 0.516319596743188, -0.773690047891018), Orientation = new Quaternion(-0.580856706784479, -0.699755868826396, 0.0503555530721975, -0.412809312517655), Scale = new Vector3D(1.49381917197275, 1.49381917197275, 1.49381917197275), ThrusterType = ThrusterType.Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0.0632171036029679, -0.325806646160234, -0.86582557639219), Orientation = new Quaternion(0.737785723862743, -0.233171415729761, -0.625831434735991, 0.0981750062245953), Scale = new Vector3D(1.49381917197275, 1.49381917197275, 1.49381917197275), ThrusterType = ThrusterType.Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-0.263418167319983, 0.910216337620467, 0.35234290788821), Orientation = new Quaternion(-0.709121607920553, -0.661587817411694, 0.0915158899314037, 0.22599324530318), Scale = new Vector3D(1.49381917197275, 1.49381917197275, 1.49381917197275), ThrusterType = ThrusterType.Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0.715330638117321, 0.783214769802288, -0.289009839133333), Orientation = new Quaternion(-0.537212591502583, -0.0434864433563857, 0.354446845047803, 0.764119751616819), Scale = new Vector3D(1.49381917197275, 1.49381917197275, 1.49381917197275), ThrusterType = ThrusterType.Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-0.905756167892496, 0.0225358707746821, 0.86582557639219), Orientation = new Quaternion(0.0813043687631664, -0.919271965928561, 0.22938801712521, 0.309369988649878), Scale = new Vector3D(1.49381917197275, 1.49381917197275, 1.49381917197275), ThrusterType = ThrusterType.Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0.628431968023481, 0.045231999077678, 0.865721193462417), Orientation = new Quaternion(-0.253918376332788, -0.427868930729674, 0.0132499643648232, 0.867339653608145), Scale = new Vector3D(1.49381917197275, 1.49381917197275, 1.49381917197275), ThrusterType = ThrusterType.Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-0.680853218475483, -0.550318077194731, 0.0397893092320309), Orientation = new Quaternion(-0.211451384238473, 0.291481640750684, -0.61282901311167, 0.703397018686815), Scale = new Vector3D(1.49381917197275, 1.49381917197275, 1.49381917197275), ThrusterType = ThrusterType.Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0.206114029499385, -0.910216337620466, 0.0210624637402835), Orientation = new Quaternion(0.372907831130986, -0.397746694239423, -0.43263915221213, 0.718025543191859), Scale = new Vector3D(1.49381917197275, 1.49381917197275, 1.49381917197275), ThrusterType = ThrusterType.Two });

                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0.928614909100397, 0.820167522520978, 0.509485111341641), Orientation = new Quaternion(-0.0154277148958784, -0.45422481961171, 0.34155915471622, -0.822665875487335), Scale = new Vector3D(0.505726283020722, 0.505726283020722, 0.505726283020722), ThrusterType = ThrusterType.Two_Two_Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-0.043681216997261, -0.632488255381253, 1.07310619077886), Orientation = new Quaternion(0.311918646345471, 0.258046065296276, 0.179708948696996, 0.896562145088303), Scale = new Vector3D(0.505726283020722, 0.505726283020722, 0.505726283020722), ThrusterType = ThrusterType.Two_Two_Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-0.96687180750838, 0.511321117195848, -0.556767987230636), Orientation = new Quaternion(0.186682618578054, -0.817045952667937, -0.304044497706209, 0.452926544336234), Scale = new Vector3D(0.505726283020722, 0.505726283020722, 0.505726283020722), ThrusterType = ThrusterType.Two_Two_Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-0.422755203622775, -0.961633929728401, -0.580695228607911), Orientation = new Quaternion(-0.160516892633012, -0.663450532470308, 0.686825586338298, -0.249676454827765), Scale = new Vector3D(0.505726283020722, 0.505726283020722, 0.505726283020722), ThrusterType = ThrusterType.Two_Two_Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(1.17798984223157, -0.367610877704125, -0.419027688531442), Orientation = new Quaternion(0.188774232171627, -0.546763929161965, 0.629041024236897, -0.519346594156906), Scale = new Vector3D(0.505726283020722, 0.505726283020722, 0.505726283020722), ThrusterType = ThrusterType.Two_Two_Two });

                #endregion

                ShipDNA dna = ShipDNA.Create(parts);

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

                //var result = BotConstructor.ConstructBot_Profile(dna, core);
                //Bot botNew = new Bot(result.Item1);

                //botNew.Dispose();

                //MessageBox.Show(result.Item2, this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #6
0
        private async void ShipBot1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ClearBot_Click(this, e);

                #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(1, 1, 1) });

                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) });

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

                #endregion

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

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

                //DefenseBot bot = DefenseBot.GetNewDefenseBotAsync(dna, _world, _material_Bot, _map, extra).Result;        // can't directly call result.  it deadlocks this main thread
                //DefenseBot bot = await DefenseBot.GetNewDefenseBotAsync(dna, _world, _material_Bot, _map, extra);
                //bot.PhysicsBody.Position = new Point3D(0, 0, -12);

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




                BotConstruction_Result result = BotConstructor.ConstructBot(parts, core, extra);
                Bot botNew = new Bot(result);

                botNew.Dispose();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #7
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);
            }
        }
コード例 #8
0
        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;
        }
コード例 #9
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);
        }
コード例 #10
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);
            }
        }
コード例 #11
0
        private async void btnLoadShip_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string errMsg;
                ShipDNA shipDNA = ShipEditorWindow.LoadShip(out errMsg);
                if (shipDNA == null)
                {
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        MessageBox.Show(errMsg, this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                    return;
                }

                EnsureWorldStarted();

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

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = chkLoadRepairPositions.IsChecked.Value,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Bot, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Ship_ApplyForceAndTorque);

                _thrustController = new ThrustController(_bot, _viewport, _itemOptions);

                if (_bot.Fuel != null)
                {
                    _bot.Fuel.QuantityCurrent = _bot.Fuel.QuantityMax;
                }
                _bot.RecalculateMass();
                _thrustController.MassChanged(chkShipSimple.IsChecked.Value);

                if (chkShipDebugVisuals.IsChecked.Value)
                {
                    _thrustController.DrawDebugVisuals_Pre();
                }

                _map.AddItem(_bot);

                grdViewPort.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #12
0
        private async void btnShipChallenge2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EnsureWorldStarted();
                ClearCurrent();

                List<ShipPartDNA> parts = new List<ShipPartDNA>();
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(0.611527511599856, 0, 0.0153375982352619), Orientation = new Quaternion(0, -0.706493084706277, 0, 0.707719945502605), Scale = new Vector3D(4.70545346938791, 4.70545346938791, 1.04748080326409) });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-1.48216852903668, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(1.65021551755816, 1.65021551755816, 1.65021551755816), ThrusterDirections = ThrusterDesign.GetThrusterDirections(ThrusterType.Two), ThrusterType = ThrusterType.Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-2.60730396412872, 1.18811621237628, -0.0147591913688635), Orientation = new Quaternion(0, 0, -0.846976393198269, 0.531630500784946), Scale = new Vector3D(0.71390056433019, 0.71390056433019, 0.71390056433019), ThrusterDirections = ThrusterDesign.GetThrusterDirections(ThrusterType.Two_Two_One), ThrusterType = ThrusterType.Two_Two_One });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-2.60721450068017, -1.18828382189838, -0.0147591913688617), Orientation = new Quaternion(0, 0, -0.496864090131338, 0.867828367788216), Scale = new Vector3D(0.71390056433019, 0.71390056433019, 0.71390056433019), ThrusterDirections = ThrusterDesign.GetThrusterDirections(ThrusterType.Two_Two_One), ThrusterType = ThrusterType.Two_Two_One });

                ShipDNA shipDNA = ShipDNA.Create(parts);

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

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = false,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Bot, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Ship_ApplyForceAndTorque);

                _thrustController = new ThrustController(_bot, _viewport, _itemOptions);

                //double mass = _ship.PhysicsBody.Mass;

                _bot.Fuel.QuantityCurrent = _bot.Fuel.QuantityMax;
                _bot.RecalculateMass();
                _thrustController.MassChanged(chkShipSimple.IsChecked.Value);

                if (chkShipDebugVisuals.IsChecked.Value)
                {
                    _thrustController.DrawDebugVisuals_Pre();
                }

                //mass = _ship.PhysicsBody.Mass;

                _map.AddItem(_bot);

                grdViewPort.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #13
0
        private async void btnShipWackyFlyer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EnsureWorldStarted();
                ClearCurrent();

                List<ShipPartDNA> parts = new List<ShipPartDNA>();
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(0, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(3, 3, 1) });

                ThrusterType thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(1, 0, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-1, 0, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0, 1, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0, -1, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                ShipDNA shipDNA = ShipDNA.Create(parts);

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

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = false,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Bot, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Ship_ApplyForceAndTorque);

                _thrustController = new ThrustController(_bot, _viewport, _itemOptions);

                //double mass = _ship.PhysicsBody.Mass;

                _bot.Fuel.QuantityCurrent = _bot.Fuel.QuantityMax;
                _bot.RecalculateMass();
                _thrustController.MassChanged(chkShipSimple.IsChecked.Value);

                if (chkShipDebugVisuals.IsChecked.Value)
                {
                    _thrustController.DrawDebugVisuals_Pre();
                }

                //mass = _ship.PhysicsBody.Mass;

                _map.AddItem(_bot);

                grdViewPort.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #14
0
        private async void btnShipBasic_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EnsureWorldStarted();
                ClearCurrent();

                List<ShipPartDNA> parts = new List<ShipPartDNA>();
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(-.75, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(1, 1, 1) });
                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Position = new Point3D(.75, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(1, 1, 1) });

                ShipDNA shipDNA = ShipDNA.Create(parts);

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

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = false,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Ship, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _map.AddItem(_bot);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #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));

                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);
            }
        }