Exemplo n.º 1
0
        private static void UpdateOrbit(ProtoEntity entity, PositionDB parentPositionDB, DateTime toDate)
        {
            var entityOrbitDB  = entity.GetDataBlob <OrbitDB>(OrbitTypeIndex);
            var entityPosition = entity.GetDataBlob <PositionDB>(PositionTypeIndex);


            // Get our Parent-Relative coordinates.
            try
            {
                Vector4 newPosition = GetPosition(entityOrbitDB, toDate);

                // Get our Absolute coordinates.
                entityPosition.AbsolutePosition = parentPositionDB.AbsolutePosition + newPosition;
            }
            catch (OrbitProcessorException e)
            {
                // TODO: Debug log this exception. Do NOT fail to the UI. There is NO data-corruption on this exception.
                // In this event, we did NOT update our position.
                throw new Exception("Position Exception thrown in OrbitProcessor");
            }

            // Update our children.
            foreach (Entity child in entityOrbitDB.Children)
            {
                // RECURSION!
                UpdateOrbit(child, entityPosition, toDate);
            }
        }
Exemplo n.º 2
0
        // sets the speed of the ship to the maximum speed allowed in the direction of the target.
        // Returns true if the destination has been reached.
        public override bool processOrder()
        {
            PositionDB currentPosition = Owner.GetDataBlob <PositionDB>();
            PositionDB targetPosition  = null;

            if (Target != Entity.InvalidEntity)
            {
                targetPosition = Target.GetDataBlob <PositionDB>();
            }
            else if (PositionTarget != null)
            {
                targetPosition = PositionTarget;
            }

            if (currentPosition == targetPosition) // We have reached the target
            {
                return(true);
            }

            // Set the speed of the ship
            // @todo - take into account Task Group speeds and limiting speed set by user
            Owner.GetDataBlob <PropulsionDB>().CurrentSpeed = getSpeed(currentPosition, targetPosition, Owner.GetDataBlob <PropulsionDB>().MaximumSpeed);

            return(false);
        }
Exemplo n.º 3
0
 internal override void ActionCommand(Game game)
 {
     OrderableProcessor.ProcessOrderList(game, NestedCommands);
     if (NestedCommands.Count == 0)
     {
         if (!IsRunning)
         {
             var    entPos     = _entityCommanding.GetDataBlob <PositionDB>().PositionInKm;
             var    tarPos     = _targetEntity.GetDataBlob <PositionDB>().PositionInKm;
             double distanceAU = PositionDB.GetDistanceBetween(_entityCommanding.GetDataBlob <PositionDB>(), _targetEntity.GetDataBlob <PositionDB>());
             var    rangeAU    = ApihelionInKM / GameConstants.Units.KmPerAu;
             if (Math.Abs(rangeAU - distanceAU) <= 500 / GameConstants.Units.MetersPerAu) //distance within 500m
             {
                 DateTime datenow  = _entityCommanding.Manager.ManagerSubpulses.SystemLocalDateTime;
                 var      newOrbit = ShipMovementProcessor.CreateOrbitHereWithPerihelion(_entityCommanding, _targetEntity, PerhelionInKM, datenow);
                 _entityCommanding.SetDataBlob(newOrbit);
                 IsRunning = true;
             }
             else //insert new translate move
             {
                 var cmd = new TranslateMoveCommand()
                 {
                     RequestingFactionGuid = this.RequestingFactionGuid, EntityCommandingGuid = this.EntityCommandingGuid, CreatedDate = this.CreatedDate, TargetEntityGuid = this.TargetEntityGuid, RangeInKM = this.ApihelionInKM
                 };
                 NestedCommands.Insert(0, cmd);
                 cmd.IsValidCommand(game);
                 cmd.ActionCommand(game);
             }
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Refreshes the properties of this ViewModel.
        ///
        /// If partialRefresh is set to true, the ViewModel will try to update only data changes during a pulse.
        /// </summary>
        public void Refresh(bool partialRefresh = false)
        {
            // Get up-to-date datablobs for this entity.
            PositionDB positionDB = _entity.GetDataBlob <PositionDB>();

            UpdateProperties(positionDB);

            SystemBodyInfoDB systemBodyDB = _entity.GetDataBlob <SystemBodyInfoDB>();

            UpdateProperties(systemBodyDB, partialRefresh);

            NameDB nameDB = _entity.GetDataBlob <NameDB>();

            UpdateProperties(nameDB);

            //AtmosphereDB atmosphereDB = _entity.GetDataBlob<AtmosphereDB>();
            //UpdateProperties(atmosphereDB);

            // Check if we're doing a full refresh.
            if (!partialRefresh)
            {
                OrbitDB orbitDB = _entity.GetDataBlob <OrbitDB>();
                UpdateProperties(orbitDB);

                MassVolumeDB massVolumeDB = _entity.GetDataBlob <MassVolumeDB>();
                UpdateProperties(massVolumeDB);
            }
        }
Exemplo n.º 5
0
        private static void UpdateOrbit(ProtoEntity entity, PositionDB parentPositionDB, DateTime toDate)
        {
            var entityOrbitDB  = entity.GetDataBlob <OrbitDB>(OrbitTypeIndex);
            var entityPosition = entity.GetDataBlob <PositionDB>(PositionTypeIndex);

            //if(toDate.Minute > entityOrbitDB.OrbitalPeriod.TotalMinutes)

            // Get our Parent-Relative coordinates.
            try
            {
                Vector3 newPosition = GetPosition_AU(entityOrbitDB, toDate);

                // Get our Absolute coordinates.
                entityPosition.AbsolutePosition_AU = parentPositionDB.AbsolutePosition_AU + newPosition;
            }
            catch (OrbitProcessorException e)
            {
                //Do NOT fail to the UI. There is NO data-corruption on this exception.
                // In this event, we did NOT update our position.
                Event evt = new Event(StaticRefLib.CurrentDateTime, "Non Critical Position Exception thrown in OrbitProcessor for EntityItem " + entity.Guid + " " + e.Message);
                evt.EventType = EventType.Opps;
                StaticRefLib.EventLog.AddEvent(evt);
            }

            // Update our children.
            foreach (Entity child in entityOrbitDB.Children)
            {
                // RECURSION!
                UpdateOrbit(child, entityPosition, toDate);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a star entity in the system.
        /// Does not initialize an orbit.
        /// </summary>
        public Entity CreateStar(StarSystem system, double mass, double radius, double age, string starClass, double temperature, float luminosity, SpectralType spectralType, string starName = null)
        {
            double          tempRange       = temperature / _galaxyGen.Settings.StarTemperatureBySpectralType[spectralType].Max; // temp range from 0 to 1.
            ushort          subDivision     = (ushort)Math.Round((1 - tempRange) * 10);
            LuminosityClass luminosityClass = LuminosityClass.V;

            if (starName == null)
            {
                starName = system.NameDB.DefaultName;
            }

            int starIndex = system.GetAllEntitiesWithDataBlob <StarInfoDB>().Count;

            starName += " " + (char)('A' + starIndex) + " " + spectralType + subDivision + luminosityClass;

            MassVolumeDB starMassVolumeDB = MassVolumeDB.NewFromMassAndRadius(mass, radius);
            StarInfoDB   starInfoDB       = new StarInfoDB {
                Age = age, Class = starClass, Luminosity = luminosity, SpectralType = spectralType, Temperature = temperature, LuminosityClass = luminosityClass, SpectralSubDivision = subDivision
            };
            PositionDB starPositionDB = new PositionDB(new Vector3(0, 0, 0), system.Guid);
            NameDB     starNameDB     = new NameDB(starName);
            OrbitDB    starOrbitDB    = new OrbitDB();

            SensorProfileDB emmisionSignature = SensorProcessorTools.SetStarEmmisionSig(starInfoDB, starMassVolumeDB);

            return(new Entity(system, new List <BaseDataBlob> {
                starOrbitDB, starMassVolumeDB, starInfoDB, starNameDB, starPositionDB, emmisionSignature
            }));
        }
Exemplo n.º 7
0
 public TranslateMoveDB(TranslateMoveDB db)
 {
     TargetPositionDB = db.TargetPositionDB;
     CurrentVector    = db.CurrentVector;
     MoveRangeInKM    = db.MoveRangeInKM;
     IsAtTarget       = db.IsAtTarget;
 }
Exemplo n.º 8
0
 public SensorPositionDB(PositionDB actualEntityPosition, DataFrom dataFrom = DataFrom.Parent)
 {
     ActualEntityPositionDB = actualEntityPosition;
     //if(actualEntityPosition.ParentDB != null)
     ParentPositionDB = (PositionDB)actualEntityPosition.ParentDB;
     GetDataFrom      = DataFrom.Parent;
 }
Exemplo n.º 9
0
        private Vector4 getSpeed(PositionDB currentPosition, PositionDB targetPosition, double speedMagnitude)
        {
            Vector4 speed = new Vector4(0, 0, 0, 0);
            double  length;


            Vector4 speedMagInKM;

            Vector4 direction = new Vector4(0, 0, 0, 0);

            direction.X = targetPosition.X - currentPosition.X;
            direction.Y = targetPosition.Y - currentPosition.Y;
            direction.Z = targetPosition.Z - currentPosition.Z;
            direction.W = 0;



            length = direction.Length(); // Distance between targets in AU

            direction.X = (direction.X / length);
            direction.Y = (direction.Y / length);
            direction.Z = (direction.Z / length);

            speedMagInKM.X = direction.X * speedMagnitude;
            speedMagInKM.Y = direction.Y * speedMagnitude;
            speedMagInKM.Z = direction.Z * speedMagnitude;



            speed.X = Distance.KmToAU(speedMagInKM.X);
            speed.Y = Distance.KmToAU(speedMagInKM.Y);
            speed.Z = Distance.KmToAU(speedMagInKM.Z);

            return(speed);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates an test system with planets of varying longitude of periapsis.
        /// Adds to game.StarSystem.
        /// </summary>
        public StarSystem CreateLongitudeTest(Game game)
        {
            StarSystem system = new StarSystem(game, "Longitude test", -1);

            Entity sun = _starFactory.CreateStar(system, GameConstants.Units.SolarMassInKG, GameConstants.Units.SolarRadiusInAu, 4.6E9, "G", 5778, 1, SpectralType.G, "_lop");

            MassVolumeDB sunMVDB = sun.GetDataBlob <MassVolumeDB>();

            double planetSemiMajAxis  = 0.387098;
            double planetEccentricity = 0.9;// 0.205630;
            double planetInclination  = 0;
            double planetLoAN         = 48.33167;
            double planetLoP          = 77.45645;
            double planetMeanLongd    = 252.25084;


            for (int i = 0; i < 13; i++)
            {
                NameDB           planetNameDB = new NameDB("planet" + i);
                SystemBodyInfoDB planetBodyDB = new SystemBodyInfoDB {
                    BodyType = BodyType.Terrestrial, SupportsPopulations = true
                };
                MassVolumeDB planetMVDB       = MassVolumeDB.NewFromMassAndRadius_AU(3.3022E23, Distance.KmToAU(2439.7));
                PositionDB   planetPositionDB = new PositionDB(system.Guid);
                planetLoP = i * 15;
                OrbitDB planetOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, planetMVDB.MassDry, planetSemiMajAxis, planetEccentricity, planetInclination, planetLoAN, planetLoP, planetMeanLongd, GalaxyGen.Settings.J2000);
                planetPositionDB.AbsolutePosition_AU = OrbitProcessor.GetPosition_AU(planetOrbitDB, StaticRefLib.CurrentDateTime);
                Entity planet = new Entity(system, new List <BaseDataBlob> {
                    planetPositionDB, planetBodyDB, planetMVDB, planetNameDB, planetOrbitDB
                });
            }
            game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(system.Guid);
            return(system);
        }
Exemplo n.º 11
0
        public PositionDB(PositionDB positionDB)
            : base(positionDB.Parent)
        {
            _positionInMeters = positionDB._positionInMeters;

            this.SystemGuid = positionDB.SystemGuid;
        }
Exemplo n.º 12
0
        /*
         * public TimeSpan RunFrequency => TimeSpan.FromMinutes(60);
         *
         * public void ProcessEntity(Entity entity, int deltaSeconds)
         * {
         *  SetEntityProfile(entity);
         * }
         *
         * public void ProcessManager(EntityManager manager, int deltaSeconds)
         * {
         *  Stopwatch timer = new Stopwatch();
         *  timer.Start();
         *  var entites = manager.GetAllEntitiesWithDataBlob<SensorProfileDB>();
         *  foreach (var entity in entites)
         *  {
         *      ProcessEntity(entity, deltaSeconds);
         *  }
         *  var ms = timer.ElapsedMilliseconds;
         *  var numEntites = entites.Count;
         * }
         */

        internal static void SetEntityProfile(Entity entity, DateTime atDate)
        {
            var position  = entity.GetDataBlob <PositionDB>();
            var sensorSig = entity.GetDataBlob <SensorProfileDB>();

            sensorSig.LastPositionOfReflectionSet = position.AbsolutePosition_AU;
            sensorSig.LastDatetimeOfReflectionSet = atDate;

            var emmiters          = entity.Manager.GetAllEntitiesWithDataBlob <SensorProfileDB>();
            int numberOfEmmitters = emmiters.Count;

            sensorSig.ReflectedEMSpectra.Clear();

            PercentValue reflectionPercent = 0.1f; //TODO: this should be calculated from crossSection(size), distance, and a reflectivity value(stealth armor?/ other design factors?).

            foreach (var emittingEntity in emmiters)
            {
                if (emittingEntity != entity) // don't reflect our own emmision.
                {
                    double distance    = PositionDB.GetDistanceBetween(position, emittingEntity.GetDataBlob <PositionDB>());
                    var    emmissionDB = emittingEntity.GetDataBlob <SensorProfileDB>();

                    foreach (var emitedItem in emmissionDB.EmittedEMSpectra)
                    {
                        var reflectedMagnatude = SensorProcessorTools.AttenuationCalc(emitedItem.Value, distance) * reflectionPercent;

                        sensorSig.ReflectedEMSpectra.Add(emitedItem.Key, emitedItem.Value);
                    }
                }
            }
        }
Exemplo n.º 13
0
 public PositionDB(PositionDB positionDB)
     : base(positionDB.Parent)
 {
     this.X          = positionDB.X;
     this.Y          = positionDB.Y;
     this.Z          = positionDB.Z;
     this.SystemGuid = positionDB.SystemGuid;
 }
Exemplo n.º 14
0
 public static Entity GetSOIParentEntity(Entity entity, PositionDB positionDB = null)
 {
     if (positionDB == null)
     {
         positionDB = entity.GetDataBlob <PositionDB>();
     }
     return(positionDB.Parent);
 }
Exemplo n.º 15
0
        private static PositionDB SetPositionClone(SensorInfoDB sensorInfo)
        {
            PositionDB position             = sensorInfo.DetectedEntity.GetDataBlob <PositionDB>();
            PositionDB sensorEntityPosition = GenericClone <PositionDB>(position, sensorInfo);

            //tweak add some random noise depending on quality;
            return(sensorEntityPosition);
        }
Exemplo n.º 16
0
 public TranslationMoveVM(Game game, CommandReferences cmdRef, Entity entity)
 {
     _tMoveDB = entity.GetDataBlob <TranslateMoveDB>();
     _posDB   = entity.GetDataBlob <PositionDB>();
     _propDB  = entity.GetDataBlob <PropulsionDB>();
     _cmdRef  = cmdRef;
     TargetList.SelectionChangedEvent += OnTargetSelectonChange;
     UpdateTargetList(entity.GetDataBlob <OwnedDB>().OwnedByFaction, entity.Manager);
 }
Exemplo n.º 17
0
 public MoveOrderDB(Entity ship, PositionDB target, long orbitRadius = 0)
 {
     DelayTime      = 0;
     Owner          = ship;
     Target         = Entity.InvalidEntity;
     PositionTarget = new PositionDB(target);
     OrbitRadius    = orbitRadius;
     MaximumSpeed   = ship.GetDataBlob <PropulsionDB>().MaximumSpeed;
 }
Exemplo n.º 18
0
        private void setPositionToTarget(Entity ship, PositionDB target)
        {
            Owner.GetDataBlob <PropulsionDB>().CurrentSpeed = new Vector4(0.0, 0.0, 0.0, 0.0);
            Owner.GetDataBlob <PositionDB>().X = target.X;
            Owner.GetDataBlob <PositionDB>().Y = target.Y;
            Owner.GetDataBlob <PositionDB>().Z = target.Z;

            return;
        }
Exemplo n.º 19
0
        // Creates a new order for a ship to move to the given coordinates in a star system
        public bool MoveOrder(Entity ship, StarSystem system, double x, double y)
        {
            PositionDB position  = new PositionDB(new Vector4(x, y, 0.0, 0.0), system.Guid);
            MoveOrder  moveOrder = new MoveOrder(ship, position);

            _orderList.Add(moveOrder);

            return(true);
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
0
        void SetOrbitHere(Entity entity, PositionDB positionDB, WarpMovingDB moveDB, DateTime atDateTime)
        {
            //propulsionDB.CurrentVectorMS = new Vector3(0, 0, 0);

            double targetSOI = OrbitProcessor.GetSOI_m(moveDB.TargetEntity);

            Entity targetEntity;

            if (moveDB.TargetEntity.GetDataBlob <PositionDB>().GetDistanceTo_m(positionDB) > targetSOI)
            {
                targetEntity = moveDB.TargetEntity.GetDataBlob <OrbitDB>().Parent; //TODO: it's concevable we could be in another SOI not the parent (ie we could be in a target's moon's SOI)
            }
            else
            {
                targetEntity = moveDB.TargetEntity;
            }
            OrbitDB targetOrbit = targetEntity.GetDataBlob <OrbitDB>();


            Vector3 insertionVector_m = OrbitProcessor.GetOrbitalInsertionVector_m(moveDB.SavedNewtonionVector, targetOrbit, atDateTime);

            positionDB.SetParent(targetEntity);

            if (moveDB.ExpendDeltaV.Length() != 0)
            {
                NewtonThrustCommand.CreateCommand(entity.FactionOwner, entity, entity.StarSysDateTime, moveDB.ExpendDeltaV);
                entity.RemoveDataBlob <WarpMovingDB>();
                moveDB.IsAtTarget = true;
            }
            else
            {
                OrbitDB newOrbit = OrbitDB.FromVelocity_m(targetEntity, entity, insertionVector_m, atDateTime);
                entity.RemoveDataBlob <WarpMovingDB>();


                if (newOrbit.Apoapsis < targetSOI) //furtherst point within soi, normal orbit
                {
                    entity.SetDataBlob(newOrbit);
                }
                else if (newOrbit.Periapsis > targetSOI) //closest point outside soi
                {
                    //find who's SOI we are in, and create an orbit around that.
                    targetEntity = OrbitProcessor.FindSOIForPosition((StarSystem)entity.Manager, positionDB.AbsolutePosition_m);
                    newOrbit     = OrbitDB.FromVelocity_m(targetEntity, entity, insertionVector_m, atDateTime);
                    entity.SetDataBlob(newOrbit);
                }
                else //closest point inside soi, but furtherest point outside. make a newtonion trajectory.
                {
                    var newtmove = new NewtonMoveDB(targetEntity, insertionVector_m);
                    entity.SetDataBlob(newtmove);
                }

                positionDB.SetParent(targetEntity);
                moveDB.IsAtTarget = true;
            }
        }
Exemplo n.º 22
0
        private double distanceBetweenPositions(PositionDB origin, PositionDB target)
        {
            Vector4 delta = new Vector4();

            delta.X = origin.X - target.X;
            delta.Y = origin.Y - target.Y;
            delta.Z = origin.Z - target.Z;

            return(delta.Length());
        }
Exemplo n.º 23
0
 private void Deserialized(StreamingContext context)
 {
     if (TargetEntity != null)
     {
         var game = (Game)context.Context;
         game.PostLoad += (sender, args) =>
         {
             TargetPositionDB = TargetEntity.GetDataBlob <PositionDB>();
         };
     }
 }
Exemplo n.º 24
0
        public TranslationMoveVM(Game game, CommandReferences cmdRef, Entity entity)
        {
            _tMoveDB = entity.GetDataBlob <TranslateMoveDB>();
            _posDB   = entity.GetDataBlob <PositionDB>();
            _propDB  = entity.GetDataBlob <PropulsionAbilityDB>();
            _cmdRef  = cmdRef;
            TargetList.SelectionChangedEvent += OnTargetSelectonChange;
            Entity faction;

            entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction);
            UpdateTargetList(faction, entity.Manager);
        }
Exemplo n.º 25
0
        private static ProtoEntity CreateSurveyPoint(double x, double y, int nameNumber)
        {
            // TODO: Rebalance "pointsRequired" here.
            // TODO: Load "pointsRequired" from GalaxyGen settings
            const int pointsRequired = 400;

            var surveyDB = new JPSurveyableDB(pointsRequired, new Dictionary <Entity, int>());
            var posDB    = new PositionDB(x, y, 0, Guid.Empty);
            var nameDB   = new NameDB($"Survey Point #{nameNumber}");

            return(ProtoEntity.Create(Guid.Empty, new BaseDataBlob[] { surveyDB, posDB, nameDB }));
        }
Exemplo n.º 26
0
        public MoveOrder(Entity ship, PositionDB target, long orbitRadius = 0) : this()
        {
            DelayTime = 0;
            Owner     = ship;

            // The owners positions is sometimes set to that of another entity for orbiting purposes.  This resets that issue
            Owner.SetDataBlob <PositionDB>(new PositionDB(Owner.GetDataBlob <PositionDB>()));
            Target         = Entity.InvalidEntity;
            PositionTarget = new PositionDB(target);
            OrbitRadius    = orbitRadius;
            MaximumSpeed   = ship.GetDataBlob <PropulsionDB>().MaximumSpeed;
        }
Exemplo n.º 27
0
        private void UpdateProperties([NotNull] PositionDB positionDB)
        {
            if (positionDB == null)
            {
                throw new ArgumentNullException("positionDB");
            }

            Position = positionDB.AbsolutePosition_AU;
            if (Name == "Earth")
            {
            }
        }
Exemplo n.º 28
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);
            }
        }
Exemplo n.º 29
0
        public TranslateMoveDB(TranslateMoveDB db)
        {
            LastProcessDateTime         = db.LastProcessDateTime;
            SavedNewtonionVector_AU     = db.SavedNewtonionVector_AU;
            TranslateEntryPoint_AU      = db.TranslateEntryPoint_AU;
            TranslateExitPoint_AU       = db.TranslateExitPoint_AU;
            CurrentNonNewtonionVectorMS = db.CurrentNonNewtonionVectorMS;
            ExpendDeltaV_AU             = db.ExpendDeltaV_AU;
            IsAtTarget   = db.IsAtTarget;
            TargetEntity = db.TargetEntity;

            TargetPositionDB = db.TargetPositionDB;
        }
Exemplo n.º 30
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();
        }