예제 #1
0
        /// <summary>
        /// creates an asteroid that will collide with the given entity on the given date.
        /// </summary>
        /// <param name="starSys"></param>
        /// <param name="target"></param>
        /// <param name="collisionDate"></param>
        /// <returns></returns>
        public static Entity CreateAsteroid(StarSystem starSys, Entity target, DateTime collisionDate, double asteroidMass = -1.0)
        {
            //todo rand these a bit.
            double radius = Distance.KmToAU(0.5);

            double mass;

            if (asteroidMass == -1.0)
            {
                mass = 1.5e+12; //about 1.5 billion tonne
            }
            else
            {
                mass = asteroidMass;
            }
            Vector3 velocity = new Vector3(8, 7, 0);

            var position     = new PositionDB(0, 0, 0, Guid.Empty);
            var massVolume   = MassVolumeDB.NewFromMassAndRadius(mass, radius);
            var planetInfo   = new SystemBodyInfoDB();
            var balisticTraj = new NewtonBalisticDB(target.Guid, collisionDate);
            var name         = new NameDB("Ellie");
            var AsteroidDmg  = new AsteroidDamageDB();
            var sensorPfil   = new SensorProfileDB();

            planetInfo.SupportsPopulations = false;
            planetInfo.BodyType            = BodyType.Asteroid;

            Vector3  targetPos       = OrbitProcessor.GetAbsolutePosition_AU(target.GetDataBlob <OrbitDB>(), collisionDate);
            TimeSpan timeToCollision = collisionDate - StaticRefLib.CurrentDateTime;


            Vector3 offset = velocity * timeToCollision.TotalSeconds;

            targetPos -= Distance.KmToAU(offset);
            position.AbsolutePosition_AU = targetPos;
            position.SystemGuid          = starSys.Guid;
            balisticTraj.CurrentSpeed    = velocity;



            var planetDBs = new List <BaseDataBlob>
            {
                position,
                massVolume,
                planetInfo,
                name,
                balisticTraj,
                AsteroidDmg,
                sensorPfil
            };

            Entity newELE = new Entity(starSys, planetDBs);

            return(newELE);
        }
예제 #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)
        {
            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?

                NewtonBalisticDB nDB = Asteroid.GetDataBlob <NewtonBalisticDB>();
                PositionDB       pDB = Asteroid.GetDataBlob <PositionDB>();

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

                Entity myTarget;
                if (!mySystem.FindEntityByGuid(nDB.TargetGuid, out myTarget))
                {
                    throw new GuidNotFoundException(nDB.TargetGuid);
                }

                //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.CreateAsteroid(mySystem, myTarget, nDB.CollisionDate, newMass);
                Entity newAsteroid2 = AsteroidFactory.CreateAsteroid(mySystem, myTarget, nDB.CollisionDate, 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);
            }
        }
예제 #3
0
        /// <summary>
        /// process balistic movement for a single system
        /// currently is not affected by gravity.
        /// </summary>
        /// <param name="manager">the system to process</param>
        internal static void Process(EntityManager manager)
        {
            TimeSpan orbitCycle = manager.Game.Settings.OrbitCycleTime;
            DateTime toDate     = manager.ManagerSubpulses.SystemLocalDateTime + orbitCycle;

            manager.ManagerSubpulses.AddSystemInterupt(toDate + orbitCycle, PulseActionEnum.BalisticMoveProcessor);

            List <Entity>     RemoveList   = new List <Entity>();
            List <StarSystem> RemoveSystem = new List <StarSystem>();

            foreach (Entity objectEntity in manager.GetAllEntitiesWithDataBlob <NewtonBalisticDB>())
            {
                NewtonBalisticDB balisticDB = objectEntity.GetDataBlob <NewtonBalisticDB>();
                PositionDB       position   = objectEntity.GetDataBlob <PositionDB>();
                position.RelativePosition += Distance.KmToAU(balisticDB.CurrentSpeed * orbitCycle.TotalSeconds);

                Entity     myTarget  = manager.GetLocalEntityByGuid(balisticDB.TargetGuid);
                PositionDB targetPos = myTarget.GetDataBlob <PositionDB>();

                if (targetPos.AbsolutePosition == position.AbsolutePosition)
                {
                    //do something in damage processor for asteroid hitting a planet?
                    DamageProcessor.OnTakingDamage(myTarget, 1000000); ///one. million. damage points.

                    StarSystem mySystem;
                    if (!manager.Game.Systems.TryGetValue(position.SystemGuid, out mySystem))
                    {
                        throw new GuidNotFoundException(position.SystemGuid);
                    }

                    RemoveList.Add(objectEntity);
                    RemoveSystem.Add(mySystem);

                    mySystem.SystemManager.RemoveEntity(objectEntity); //get rid of the asteroid
                }
            }

            /// <summary>
            /// Clean up the asteroids that have hit something and been put in the remove list.
            /// </summary>
            for (int removeIterator = 0; removeIterator < RemoveList.Count; removeIterator++)
            {
                RemoveSystem[removeIterator].SystemManager.RemoveEntity(RemoveList[removeIterator]);
            }

            /// <summary>
            /// This may not be necessary but clear these two lists.
            /// </summary>
            RemoveList.Clear();
            RemoveSystem.Clear();
        }
        /// <summary>
        /// process balistic movement for a single system
        /// currently is not affected by gravity.
        /// </summary>
        /// <param name="manager">the system to process</param>
        internal static void Process(EntityManager manager, int deltaSeconds)
        {
            List <Entity>     RemoveList   = new List <Entity>();
            List <StarSystem> RemoveSystem = new List <StarSystem>();

            foreach (Entity objectEntity in manager.GetAllEntitiesWithDataBlob <NewtonBalisticDB>())
            {
                NewtonBalisticDB balisticDB = objectEntity.GetDataBlob <NewtonBalisticDB>();
                PositionDB       position   = objectEntity.GetDataBlob <PositionDB>();
                position.RelativePosition += Distance.KmToAU(balisticDB.CurrentSpeed * deltaSeconds);

                /*TODO: rethink how this is done, unless this is the only place we're going to do collision, then it shouldnt be done here.
                 * ALso, this currently breaks down in a network situation because we're not sending the target entity (the client probilby shouldnt know that)
                 * Entity myTarget = manager.GetLocalEntityByGuid(balisticDB.TargetGuid);
                 * PositionDB targetPos = myTarget.GetDataBlob<PositionDB>();
                 *
                 * if(targetPos.AbsolutePosition == position.AbsolutePosition)
                 * {
                 *  //do something in damage processor for asteroid hitting a planet?
                 *  DamageProcessor.OnTakingDamage(myTarget, 1000000); ///one. million. damage points.
                 *
                 *  StarSystem mySystem;
                 *  if (!manager.Game.Systems.TryGetValue(position.SystemGuid, out mySystem))
                 *      throw new GuidNotFoundException(position.SystemGuid);
                 *
                 *  RemoveList.Add(objectEntity);
                 *  RemoveSystem.Add(mySystem);
                 *
                 *  mySystem.SystemManager.RemoveEntity(objectEntity); //get rid of the asteroid
                 * }*/
            }

            /// <summary>
            /// Clean up the asteroids that have hit something and been put in the remove list.
            /// </summary>
            for (int removeIterator = 0; removeIterator < RemoveList.Count; removeIterator++)
            {
                RemoveSystem[removeIterator].RemoveEntity(RemoveList[removeIterator]);
            }

            /// <summary>
            /// This may not be necessary but clear these two lists.
            /// </summary>
            RemoveList.Clear();
            RemoveSystem.Clear();
        }
예제 #5
0
 public NewtonBalisticDB(NewtonBalisticDB db)
 {
     CurrentSpeed  = db.CurrentSpeed;
     TargetGuid    = db.TargetGuid;
     CollisionDate = db.CollisionDate;
 }
예제 #6
0
        public static Entity CreateAsteroid2(StarSystem starSys, Entity target, DateTime collisionDate, double asteroidMass = -1.0)
        {
            //todo rand these a bit.
            double radius = Distance.KmToAU(0.5);

            double mass;

            if (asteroidMass == -1.0)
            {
                mass = 1.5e+12; //about 1.5 billion tonne
            }
            else
            {
                mass = asteroidMass;
            }
            Vector3 velocity = new Vector3(8, 7, 0);

            var position     = new PositionDB(0, 0, 0, Guid.Empty);
            var massVolume   = MassVolumeDB.NewFromMassAndRadius(mass, radius);
            var planetInfo   = new SystemBodyInfoDB();
            var balisticTraj = new NewtonBalisticDB(target.Guid, collisionDate);
            var name         = new NameDB("Ellie");
            var AsteroidDmg  = new AsteroidDamageDB();
            var sensorPfil   = new SensorProfileDB();

            planetInfo.SupportsPopulations = false;
            planetInfo.BodyType            = BodyType.Asteroid;

            Vector3  targetPos       = OrbitProcessor.GetAbsolutePosition_AU(target.GetDataBlob <OrbitDB>(), collisionDate);
            TimeSpan timeToCollision = collisionDate - StaticRefLib.CurrentDateTime;


            Vector3 offset = velocity * timeToCollision.TotalSeconds;

            targetPos -= Distance.KmToAU(offset);
            position.AbsolutePosition_AU = targetPos;
            position.SystemGuid          = starSys.Guid;
            balisticTraj.CurrentSpeed    = velocity;


            var parent          = target.GetDataBlob <OrbitDB>().Parent;
            var parentMass      = parent.GetDataBlob <MassVolumeDB>().Mass;
            var myMass          = massVolume.Mass;
            var mySemiMajorAxis = 5.055;
            var myEccentricity  = 0.8;
            var myInclination   = 0;
            var myLoAN          = 0;
            var myAoP           = -10;
            //var EccentricAnomaly = Math.Atan2()
            //var meanAnomaly =;
            double myLoP       = 0;
            double myMeanLongd = 355.5;
            //OrbitDB orbit = OrbitDB.FromAsteroidFormat(parent, parentMass, myMass, mySemiMajorAxis, myEccentricity, myInclination, myLoAN, myAoP, meanAnomaly, starSys.Game.CurrentDateTime);
            OrbitDB orbit = OrbitDB.FromMajorPlanetFormat(parent, parentMass, myMass, mySemiMajorAxis, myEccentricity, myInclination, myLoAN, myLoP, myMeanLongd, StaticRefLib.CurrentDateTime);

            var planetDBs = new List <BaseDataBlob>
            {
                position,
                massVolume,
                planetInfo,
                name,
                orbit,
                AsteroidDmg,
                sensorPfil
            };

            Entity newELE = new Entity(starSys, planetDBs);

            return(newELE);
        }