示例#1
0
        //displays selected entity info
        internal override void Display()
        {
            if (IsActive && ImGui.Begin("Spawn Entity", _flags))
            {
                if (ImGui.Combo("##entityselector", ref _entityindex, _entitytypes, _entitytypes.Length))
                {
                }


                if (_entitytypes[_entityindex] == "Ship")
                {
                    //ImGui.BeginChild("exsistingdesigns");

                    if (_exsistingClasses == null || _exsistingClasses.Count != _uiState.Faction.GetDataBlob <FactionInfoDB>().ShipDesigns.Values.ToList().Count)
                    {
                        _exsistingClasses = _uiState.Faction.GetDataBlob <FactionInfoDB>().ShipDesigns.Values.ToList();
                    }

                    for (int i = 0; i < _exsistingClasses.Count; i++)
                    {
                        string name = _exsistingClasses[i].Name;
                        if (ImGui.Selectable(name))
                        {
                            Entity _spawnedship = ShipFactory.CreateShip(_exsistingClasses[i], _uiState.Faction, _uiState.LastClickedEntity.Entity, _uiState.SelectedSystem, Guid.NewGuid().ToString());
                            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(_spawnedship);
                            //_uiState.SelectedSystem.SetDataBlob(_spawnedship.ID, new TransitableDB());
                            //var rp1 = NameLookup.GetMaterialSD(game, "LOX/Hydrocarbon");
                            //StorageSpaceProcessor.AddCargo(_spawnedship.GetDataBlob<CargoStorageDB>(), rp1, 15000);
                        }
                    }

                    //ImGui.EndChild();
                }
            }
        }
示例#2
0
        public void TestNewtonTrajectory()
        {
            Game          game         = new Game();
            EntityManager mgr          = new EntityManager(game, false);
            Entity        parentEntity = TestingUtilities.BasicEarth(mgr);

            PositionDB pos1 = new PositionDB(mgr.ManagerGuid)
            {
                X = 0, Y = 8.52699302490434E-05, Z = 0
            };

            BaseDataBlob[] objBlobs1 = new BaseDataBlob[3];
            objBlobs1[0] = pos1;
            objBlobs1[1] = new MassVolumeDB()
            {
                Mass = 10000
            };
            objBlobs1[2] = new NewtonMoveDB(parentEntity)
            {
                CurrentVector_kms = new Vector3(-10.0, 0, 0)
            };
            Entity     objEntity1 = new Entity(mgr, objBlobs1);
            PositionDB pos2       = new PositionDB(mgr.ManagerGuid)
            {
                X = 0, Y = 8.52699302490434E-05, Z = 0
            };

            BaseDataBlob[] objBlobs2 = new BaseDataBlob[3];
            objBlobs2[0] = pos2;
            objBlobs2[1] = new MassVolumeDB()
            {
                Mass = 10000
            };
            objBlobs2[2] = new NewtonMoveDB(parentEntity)
            {
                CurrentVector_kms = new Vector3(-10.0, 0, 0)
            };
            Entity objEntity2 = new Entity(mgr, objBlobs2);

            var seconds = 100;

            for (int i = 0; i < seconds; i++)
            {
                NewtonionMovementProcessor.NewtonMove(objEntity1, 1);
            }
            NewtonionMovementProcessor.NewtonMove(objEntity2, seconds);
            var distance1 = Distance.AuToKm(pos1.AbsolutePosition_AU.Length());
            var distance2 = Distance.AuToKm(pos2.AbsolutePosition_AU.Length());

            //this test is currently failing and I'm unsure why. right now the code is using a 1s timestep so it should come out exact...
            //it looks ok graphicaly though so I'm not *too* conserned about this one right now.
            Assert.AreEqual(distance1, distance2); //if we put the variable timstep which is related to the speed of the object in we'll have to give this a delta
        }
示例#3
0
        public static Entity CreateShip(ShipDesign shipDesign, Entity ownerFaction, Vector3 position, Entity parent, StarSystem starsys, string shipName = null)
        {
            List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>();

            var shipinfo = new ShipInfoDB();

            dataBlobs.Add(shipinfo);
            var mvdb = MassVolumeDB.NewFromMassAndVolume(shipDesign.Mass, shipDesign.Volume);

            dataBlobs.Add(mvdb);
            PositionDB posdb = new PositionDB(Distance.MToAU(position), starsys.Guid, parent);

            dataBlobs.Add(posdb);
            EntityDamageProfileDB damagedb = (EntityDamageProfileDB)shipDesign.DamageProfileDB.Clone();

            dataBlobs.Add(damagedb);
            ComponentInstancesDB compInstances = new ComponentInstancesDB();

            dataBlobs.Add(compInstances);
            OrderableDB ordable = new OrderableDB();

            dataBlobs.Add(ordable);
            var ship = Entity.Create(starsys, ownerFaction.Guid, dataBlobs);

            //some DB's need tobe created after the entity.
            var namedb = new NameDB(ship.Guid.ToString());

            namedb.SetName(ownerFaction.Guid, shipName);
            OrbitDB orbit = OrbitDB.FromPosition(parent, ship, starsys.ManagerSubpulses.StarSysDateTime);

            ship.SetDataBlob(namedb);
            ship.SetDataBlob(orbit);

            foreach (var item in shipDesign.Components)
            {
                EntityManipulation.AddComponentToEntity(ship, item.design, item.count);
            }

            if (ship.HasDataBlob <NewtonThrustAbilityDB>() && ship.HasDataBlob <CargoStorageDB>())
            {
                NewtonionMovementProcessor.CalcDeltaV(ship);
            }

            return(ship);
        }
示例#4
0
        public static Entity CreateShip(ShipDesign shipDesign, Entity ownerFaction, Vector3 position, Entity parent, StarSystem starsys, string shipName = null)
        {
            List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>();

            var shipinfo = new ShipInfoDB();

            dataBlobs.Add(shipinfo);
            var mvdb = MassVolumeDB.NewFromMassAndVolume(shipDesign.MassPerUnit, shipDesign.VolumePerUnit);

            dataBlobs.Add(mvdb);
            PositionDB posdb = new PositionDB(Distance.MToAU(position), starsys.Guid, parent);

            dataBlobs.Add(posdb);
            EntityDamageProfileDB damagedb = (EntityDamageProfileDB)shipDesign.DamageProfileDB.Clone();

            dataBlobs.Add(damagedb);
            ComponentInstancesDB compInstances = new ComponentInstancesDB();

            dataBlobs.Add(compInstances);
            OrderableDB ordable = new OrderableDB();

            dataBlobs.Add(ordable);
            var ship = Entity.Create(starsys, ownerFaction.Guid, dataBlobs);

            StaticDataStore   staticdata = StaticRefLib.StaticData;
            ComponentDesigner fireControlDesigner;
            ComponentDesign   integratedfireControl;


            ComponentTemplateSD bfcSD = staticdata.ComponentTemplates[new Guid("33fcd1f5-80ab-4bac-97be-dbcae19ab1a0")];

            fireControlDesigner      = new ComponentDesigner(bfcSD, ownerFaction.GetDataBlob <FactionTechDB>());
            fireControlDesigner.Name = "Bridge Computer Systems";
            fireControlDesigner.ComponentDesignAttributes["Range"].SetValueFromInput(0);
            fireControlDesigner.ComponentDesignAttributes["Tracking Speed"].SetValueFromInput(0);
            fireControlDesigner.ComponentDesignAttributes["Size vs Range"].SetValueFromInput(0);

            //return fireControlDesigner.CreateDesign(faction);
            integratedfireControl = fireControlDesigner.CreateDesign(ownerFaction);
            ownerFaction.GetDataBlob <FactionTechDB>().IncrementLevel(integratedfireControl.TechID);

            //some DB's need tobe created after the entity.
            var namedb = new NameDB(ship.Guid.ToString());

            namedb.SetName(ownerFaction.Guid, shipName);
            OrbitDB orbit = OrbitDB.FromPosition(parent, ship, starsys.ManagerSubpulses.StarSysDateTime);

            ship.SetDataBlob(namedb);
            ship.SetDataBlob(orbit);

            EntityManipulation.AddComponentToEntity(ship, integratedfireControl, 1);

            foreach (var item in shipDesign.Components)
            {
                EntityManipulation.AddComponentToEntity(ship, item.design, item.count);
            }

            if (ship.HasDataBlob <NewtonThrustAbilityDB>())
            {
                NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(ship);
            }



            return(ship);
        }
示例#5
0
        public void TestNewtonTrajectory()
        {
            Game          game         = new Game();
            EntityManager mgr          = new EntityManager(game, false);
            Entity        parentEntity = TestingUtilities.BasicEarth(mgr);

            PositionDB pos1 = new PositionDB(mgr.ManagerGuid, parentEntity)
            {
                X_AU = 0, Y_AU = 8.52699302490434E-05, Z_AU = 0
            };
            var newt1 = new NewtonMoveDB(parentEntity, new Vector3(-10.0, 0, 0))
            {
                DeltaVForManuver_FoRO_m = new Vector3(0, 1, 0)
            };

            BaseDataBlob[] objBlobs1 = new BaseDataBlob[4];
            objBlobs1[0] = pos1;
            objBlobs1[1] = new MassVolumeDB()
            {
                MassDry = 10000
            };
            objBlobs1[2] = new NewtonThrustAbilityDB(mgr.ManagerGuid);
            objBlobs1[3] = newt1;
            Entity objEntity1 = new Entity(mgr, objBlobs1);


            PositionDB pos2 = new PositionDB(mgr.ManagerGuid, parentEntity)
            {
                X_AU = 0, Y_AU = 8.52699302490434E-05, Z_AU = 0
            };
            var newt2 = new NewtonMoveDB(parentEntity, new Vector3(-10.0, 0, 0))
            {
                DeltaVForManuver_FoRO_m = new Vector3(0, 1, 0)
            };

            BaseDataBlob[] objBlobs2 = new BaseDataBlob[4];
            objBlobs2[0] = pos2;
            objBlobs2[1] = new MassVolumeDB()
            {
                MassDry = 10000
            };
            objBlobs2[2] = new NewtonThrustAbilityDB(mgr.ManagerGuid);
            objBlobs2[3] = newt2;
            Entity objEntity2 = new Entity(mgr, objBlobs2);

            var seconds = 100;

            for (int i = 0; i < seconds; i++)
            {
                NewtonionMovementProcessor.NewtonMove(objEntity1, 1);

                //this is a hacky way to allow us to increment each second,
                //since the above method looks at the manager datetime and we're not updating that.
                newt1.LastProcessDateTime -= TimeSpan.FromSeconds(1);
            }
            NewtonionMovementProcessor.NewtonMove(objEntity2, seconds);
            var distance1 = (pos1.RelativePosition_m.Length());
            var distance2 = (pos2.RelativePosition_m.Length());

            Assert.AreEqual(distance1, distance2); //if we put the variable timstep which is related to the speed of the object in we'll have to give this a delta
        }