示例#1
0
        public void TestSelfReferencingEntity()
        {
            NameDB name       = new NameDB();
            Entity testEntity = Entity.Create(_game.GlobalManager, Guid.Empty);

            name.SetName(testEntity.Guid, "TestName");
            testEntity.SetDataBlob(name);

            //serialise the test entity into a mem stream
            var mStream = new MemoryStream();

            SerializationManager.Export(_game, mStream, testEntity);


            //create a second game, we're going to import this entity to here (this would be the case in a network game)
            var settings = new NewGameSettings {
                GameName = "Test Game2", StartDateTime = DateTime.Now, MaxSystems = 1
            };
            Game game2 = new Game(settings);


            //import the entity into the second game.
            Entity clonedEntity = SerializationManager.ImportEntity(game2, mStream, game2.GlobalManager);

            mStream.Close();

            Assert.IsTrue(testEntity.GetValueCompareHash() == clonedEntity.GetValueCompareHash(), "ValueCompareHash should match");//currently valueCompareHash does not check guid of the entity. I'm undecided wheather it should or not.
            Entity clonedTest;

            Assert.IsTrue(game2.GlobalManager.FindEntityByGuid(testEntity.Guid, out clonedTest), "Game2 should have the test entity");
            Assert.IsTrue(testEntity.Guid == clonedEntity.Guid, "Guid's need to match, if we get to this assert, then we've got two entities in game2, one of them has the correct guid but no datablobs, the other has a new guid but is complete.");
            Assert.IsTrue(ReferenceEquals(clonedTest, clonedEntity), "These should be the same object");
            Assert.IsTrue(testEntity.DataBlobs.Count == clonedTest.DataBlobs.Count);
            Assert.IsTrue(testEntity.DataBlobs.Count == clonedEntity.DataBlobs.Count);
        }
示例#2
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);
        }
示例#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.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);
        }