Esempio n. 1
0
        public static Entity ImportEntity([NotNull] Game game, [NotNull] Stream inputStream, [NotNull] EntityManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }


            var protoEntity = new ProtoEntity();

            protoEntity = Import(game, inputStream, protoEntity);

            //the block of code below is a somewhat hacky way of fixing a problem where an entity has a datablob that refers back to the entity.
            //eg a faction entitiy with a NameDB. in such cases the Import above creates an empty entity because of the NameDB's reference.
            //then Entity.Create below checks for an exsisting entity guid, finds it, then returns an entity with a new GUID.
            //this then gives us two entities, one with the correct guid but with no datablobs, and a second one with a new different guid and all the datablobs.
            //checking if the datablob count is 0 is a poor and not guarenteed way of seeing if the entity hasn't been created some other way previously.
            //I'm wondering if we shouldn't throw an exception if we try to add an entity with the same guid, instead of just changing the guid.
            Entity entity;

            if (manager.FindEntityByGuid(protoEntity.Guid, out entity) && entity.DataBlobs.Count == 0)
            {
                manager.RemoveEntity(entity);
            }



            entity = Entity.Create(manager, protoEntity);
            game.PostGameLoad();
            return(entity);
        }
Esempio n. 2
0
        /// <summary>
        /// This asteroid was destroyed, see if it is big enough for child asteroids to spawn, and if so spawn them.
        /// </summary>
        /// <param name="Asteroid"></param>
        internal static void SpawnSubAsteroids(Entity Asteroid, DateTime atDateTime)
        {
            Game         game = Asteroid.Manager.Game;
            MassVolumeDB ADB  = Asteroid.GetDataBlob <MassVolumeDB>();

            //const double massDefault = 1.5e+12; //150 B tonnes?
            const double massThreshold = 1.5e+9; //150 M tonnes?

            if (ADB.Mass > massThreshold)
            {
                //spawn new asteroids. call the asteroid factory?

                double newMass = ADB.Mass * 0.4; //add a random factor into this? do we care? will mass be printed to the player?

                OrbitDB    origOrbit = Asteroid.GetDataBlob <OrbitDB>();
                PositionDB pDB       = Asteroid.GetDataBlob <PositionDB>();

                EntityManager mySystem = Asteroid.Manager;


                var origVel = OrbitProcessor.AbsoluteOrbitalVector_AU(origOrbit, atDateTime);

                //public static Entity CreateAsteroid(StarSystem starSys, Entity target, DateTime collisionDate, double asteroidMass = -1.0)
                //I need the target entity, the collisionDate, and the starSystem. I may have starsystem from guid.
                //Ok so this should create the asteroid without having to add the new asteroids to a list. as that is done in the factory.
                Entity newAsteroid1 = AsteroidFactory.CreateAsteroid4(pDB.AbsolutePosition_AU, origOrbit, atDateTime, newMass);
                //var newOrbit = OrbitDB.FromVector(origOrbit.Parent, )
                Entity newAsteroid2 = AsteroidFactory.CreateAsteroid4(pDB.AbsolutePosition_AU, origOrbit, atDateTime, newMass);

                mySystem.RemoveEntity(Asteroid);

                //Randomize the number of created asteroids?
            }
            else
            {
                //delete the existing asteroid.
                PositionDB pDB = Asteroid.GetDataBlob <PositionDB>();

                StarSystem mySystem;
                if (!game.Systems.TryGetValue(pDB.SystemGuid, out mySystem))
                {
                    throw new GuidNotFoundException(pDB.SystemGuid);
                }

                mySystem.RemoveEntity(Asteroid);
            }
        }