Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public static Entity CreateAsteroid4(Vector3 position, OrbitDB origOrbit, DateTime atDateTime, 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;
            }

            var     speed    = Distance.KmToAU(40);
            Vector3 velocity = new Vector3(speed, 0, 0);


            var massVolume  = MassVolumeDB.NewFromMassAndRadius_AU(mass, radius);
            var planetInfo  = new SystemBodyInfoDB();
            var name        = new NameDB("Ellie");
            var AsteroidDmg = new AsteroidDamageDB();

            AsteroidDmg.FractureChance = new PercentValue(0.75f);
            var dmgPfl     = EntityDamageProfileDB.AsteroidDamageProfile(massVolume.Volume_km3, massVolume.Density, massVolume.RadiusInM, 50);
            var sensorPfil = new SensorProfileDB();

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


            var parent     = origOrbit.Parent;
            var parentMass = parent.GetDataBlob <MassVolumeDB>().Mass;
            var myMass     = massVolume.Mass;

            double sgp = GameConstants.Science.GravitationalConstant * (parentMass + myMass) / 3.347928976e33;
            //OrbitDB orbit = OrbitDB.FromVector(parent, myMass, parentMass, sgp, position, velocity, atDateTime);
            //OrbitDB orbit = (OrbitDB)origOrbit.Clone();
            OrbitDB orbit = new OrbitDB(origOrbit.Parent, parentMass, myMass, origOrbit.SemiMajorAxis_AU,
                                        origOrbit.Eccentricity, origOrbit.Inclination_Degrees, origOrbit.LongitudeOfAscendingNode_Degrees,
                                        origOrbit.ArgumentOfPeriapsis_Degrees, origOrbit.MeanMotion_DegreesSec, origOrbit.Epoch);

            var posDB = new PositionDB(position.X, position.Y, position.Z, parent.Manager.ManagerGuid, parent);


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

            Entity newELE = new Entity(origOrbit.OwningEntity.Manager, planetDBs);

            return(newELE);
        }
Ejemplo n.º 3
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 < 0)
            {
                mass = 1.5e+12; //about 1.5 billion tonne
            }
            else
            {
                mass = asteroidMass;
            }

            var     speed    = 40000;
            Vector3 velocity = new Vector3(speed, 0, 0);


            var massVolume  = MassVolumeDB.NewFromMassAndRadius_AU(mass, radius);
            var planetInfo  = new SystemBodyInfoDB();
            var name        = new NameDB("Ellie");
            var AsteroidDmg = new AsteroidDamageDB();

            AsteroidDmg.FractureChance = new PercentValue(0.75f);
            var dmgPfl     = EntityDamageProfileDB.AsteroidDamageProfile(massVolume.Volume_km3, massVolume.Density, massVolume.RadiusInM, 50);
            var sensorPfil = new SensorProfileDB();

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

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


            var parent     = target.GetDataBlob <OrbitDB>().Parent;
            var parentMass = parent.GetDataBlob <MassVolumeDB>().Mass;
            var myMass     = massVolume.Mass;

            double  sgp   = OrbitMath.CalculateStandardGravityParameterInM3S2(myMass, parentMass);
            OrbitDB orbit = OrbitDB.FromVector(parent, myMass, parentMass, sgp, targetPos, velocity, collisionDate);

            var currentpos = OrbitProcessor.GetAbsolutePosition_AU(orbit, StaticRefLib.CurrentDateTime);
            var posDB      = new PositionDB(currentpos.X, currentpos.Y, currentpos.Z, parent.Manager.ManagerGuid, parent);


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

            Entity newELE = new Entity(starSys, planetDBs);

            return(newELE);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Deep copy constructor
 /// </summary>
 /// <param name="clone"></param>
 public AsteroidDamageDB(AsteroidDamageDB clone)
 {
     _health = clone._health;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// This will work for missiles, ships, asteroids, and populations at some point.
        /// Damage type may eventually be required.
        /// </summary>
        /// <param name="damageableEntity"></param>
        /// <param name="damageAmount"></param>
        public static void OnTakingDamage(Entity damageableEntity, int damageAmount, DateTime atDateTime)
        {
            if (damageableEntity.HasDataBlob <AsteroidDamageDB>())
            {
                AsteroidDamageDB AstDmgDB = damageableEntity.GetDataBlob <AsteroidDamageDB>();
                AstDmgDB.Health = AstDmgDB.Health - damageAmount;

                if (AstDmgDB.Health <= 0)
                {
                    SpawnSubAsteroids(damageableEntity, atDateTime);
                }
            }
            else if (damageableEntity.HasDataBlob <ShipInfoDB>())
            {
                //do shield damage
                //do armor damage
                //for components:
                Game       game         = damageableEntity.Manager.Game;
                PositionDB ShipPosition = damageableEntity.GetDataBlob <PositionDB>();

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

                ComponentInstancesDB ShipInst = damageableEntity.GetDataBlob <ComponentInstancesDB>(); //These are ship components in this context

                int damageAttempt = 0;
                while (damageAmount > 0)
                {
                    int randValue = mySystem.RNG.Next((int)(damageableEntity.GetDataBlob <MassVolumeDB>().VolumeM3)); //volume in m^3

                    foreach (KeyValuePair <Entity, double> pair in ShipInst.ComponentDictionary)
                    {
                        if (pair.Value > randValue)
                        {
                            //check if this component is destroyed
                            //if it isn't get density
                            MassVolumeDB mvDB = pair.Key.GetDataBlob <MassVolumeDB>();

                            double DensityThreshold = 1.0; //what should this be?
                            double dmgPercent       = DensityThreshold * mvDB.Density * 1000;

                            int dmgDone = (int)(damageAmount * dmgPercent);

                            ComponentInfoDB         ciDB  = pair.Key.GetDataBlob <ComponentInfoDB>();
                            ComponentInstanceInfoDB ciiDB = pair.Key.GetDataBlob <ComponentInstanceInfoDB>();

                            if (ciiDB.HTKRemaining > 0)            //component is not destroyed yet
                            {
                                if (dmgDone >= ciiDB.HTKRemaining) //component is definitely wrecked
                                {
                                    damageAmount       = damageAmount - ciiDB.HTKRemaining;
                                    ciiDB.HTKRemaining = 0;
                                }
                                else
                                {
                                    ciiDB.HTKRemaining = ciiDB.HTKRemaining - damageAmount;
                                    damageAmount       = 0;
                                }
                            }
                            else
                            {
                                damageAttempt++;
                                if (damageAttempt == 20) // Aurora default, seems like an ok number to use for now.
                                {
                                    break;
                                }
                                /// <summary>
                                /// Need to pick a new component to try and destroy.
                                /// Should any damage get absorbed by the wreck?
                                /// How many of these failures should I run into before declaring the ship destroyed?
                                /// Should ship distruction happen differently?
                                /// </summary>
                                continue;
                            }


                            //compare this density to some density value to calculate how much to modify damage by
                            //if damage is greater than the HTK then the component is destroyed. modify damageAmount and move onto the next component.
                            //leave this loop if damage is zero.

                            break;
                        }
                    }
                    if (damageAttempt == 20) // need to copy this to fully break out of the loop;
                    {
                        break;
                    }
                }

                if (damageAttempt == 20) // the ship is destroyed. how to mark it as such?
                {
                    SpawnWreck(damageableEntity);
                }
                else
                {
                    ReCalcProcessor.ReCalcAbilities(damageableEntity);
                }
            }
            else if (damageableEntity.HasDataBlob <ColonyInfoDB>())
            {
                //Think about how to unify this one and shipInfoDB if possible.
                //do Terraforming/Infra/Pop damage
                Game game = damageableEntity.Manager.Game;

                ColonyInfoDB     ColIDB    = damageableEntity.GetDataBlob <ColonyInfoDB>();
                SystemBodyInfoDB SysInfoDB = ColIDB.PlanetEntity.GetDataBlob <SystemBodyInfoDB>();

                PositionDB ColonyPosition = ColIDB.PlanetEntity.GetDataBlob <PositionDB>();

                StarSystem mySystem; //I need all of this to get to the rng.
                if (!game.Systems.TryGetValue(ColonyPosition.SystemGuid, out mySystem))
                {
                    throw new GuidNotFoundException(ColonyPosition.SystemGuid);
                }

                //How should damage work here?
                //quarter million dead per strength of nuclear attack? 1 radiation/1 dust per strength?
                //Same chance to destroy components as ship destruction?

                //I need damage type for these. Missiles/bombs(missile damage but no engine basically) will be the only thing that causes this damage.
                //ColIDB.Population
                //SysInfoDB.AtmosphericDust
                //SysInfoDB.RadiationLevel


                //Installation Damage section:
                ComponentInstancesDB ColInst = damageableEntity.GetDataBlob <ComponentInstancesDB>(); //These are installations in this context
                int damageAttempt            = 0;
                while (damageAmount > 0)
                {
                    int randValue = mySystem.RNG.Next((int)damageableEntity.GetDataBlob <MassVolumeDB>().Volume);

                    foreach (KeyValuePair <Entity, double> pair in ColInst.ComponentDictionary)
                    {
                        if (pair.Value > randValue) //This installation was targeted
                        {
                            //check if this Installation is destroyed
                            //if it isn't get density
                            MassVolumeDB mvDB = pair.Key.GetDataBlob <MassVolumeDB>();

                            double DensityThreshold = 1.0; //what should this be?
                            double dmgPercent       = DensityThreshold * mvDB.Density;

                            int dmgDone = (int)(damageAmount * dmgPercent);

                            ComponentInfoDB         ciDB  = pair.Key.GetDataBlob <ComponentInfoDB>();
                            ComponentInstanceInfoDB ciiDB = pair.Key.GetDataBlob <ComponentInstanceInfoDB>();

                            if (ciiDB.HTKRemaining > 0)            //Installation is not destroyed yet
                            {
                                if (dmgDone >= ciiDB.HTKRemaining) //Installation is definitely wrecked
                                {
                                    damageAmount       = damageAmount - ciiDB.HTKRemaining;
                                    ciiDB.HTKRemaining = 0;
                                }
                                else
                                {
                                    ciiDB.HTKRemaining = ciiDB.HTKRemaining - damageAmount;
                                    damageAmount       = 0;
                                }
                            }
                            else
                            {
                                damageAttempt++;
                                if (damageAttempt == 20) // The planet won't blow up because of this, but no more attempts to damage installations should be made here.
                                {
                                    break;
                                }

                                continue;
                            }
                        }
                    }
                    if (damageAttempt == 20) // need to copy this to fully break out of the loop;
                    {
                        break;
                    }
                }

                //This will need to be updated to deal with colonies.
                ReCalcProcessor.ReCalcAbilities(damageableEntity);
            }
        }
Ejemplo n.º 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);
        }