internal static Entity TryGetFirstEntityWithName(List <Entity> entitysWithNameDB, string name) { foreach (var item in entitysWithNameDB) { NameDB namedb = item.GetDataBlob <NameDB>(); if (namedb.DefaultName == name) { return(item); } } throw new Exception(name + " not found"); }
/// <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; } Vector4 velocity = new Vector4(8, 7, 0, 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; Vector4 targetPos = OrbitProcessor.GetAbsolutePosition(target.GetDataBlob <OrbitDB>(), collisionDate); TimeSpan timeToCollision = collisionDate - starSys.Game.CurrentDateTime; Vector4 offset = velocity * timeToCollision.TotalSeconds; targetPos -= Distance.KmToAU(offset); position.AbsolutePosition = 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); }
internal static bool TryGetFirstEntityWithName(List <Entity> entitiesWithNameDB, string name, out Entity entity) { foreach (var item in entitiesWithNameDB) { NameDB namedb = item.GetDataBlob <NameDB>(); if (namedb.DefaultName == name) { entity = item; return(true); } } entity = null; return(false); }
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>(), 10000000); var posDB = new PositionDB(x, y, 0, Guid.Empty); var nameDB = new NameDB($"Survey Point #{nameNumber}"); //for testing purposes var sensorProfileDB = new SensorProfileDB(); return(ProtoEntity.Create(Guid.Empty, new BaseDataBlob[] { surveyDB, posDB, nameDB, sensorProfileDB })); }
/// <summary> /// Creates a new colony with zero population. /// </summary> /// <param name="systemEntityManager"></param> /// <param name="factionEntity"></param> /// <returns></returns> public static Entity CreateColony(Entity factionEntity, Entity speciesEntity, Entity planetEntity) { List <BaseDataBlob> blobs = new List <BaseDataBlob>(); string planetName = planetEntity.GetDataBlob <NameDB>().GetName(factionEntity.Guid); NameDB name = new NameDB(planetName + " Colony"); // TODO: Review default name. name.SetName(factionEntity.Guid, name.DefaultName); blobs.Add(name); ColonyInfoDB colonyInfoDB = new ColonyInfoDB(speciesEntity, 0, planetEntity); blobs.Add(colonyInfoDB); ColonyBonusesDB colonyBonuses = new ColonyBonusesDB(); blobs.Add(colonyBonuses); MiningDB colonyMinesDB = new MiningDB(); blobs.Add(colonyMinesDB); RefiningDB colonyRefining = new RefiningDB(); blobs.Add(colonyRefining); ConstructionDB colonyConstruction = new ConstructionDB(); blobs.Add(colonyConstruction); OrderableDB orderableDB = new OrderableDB(); blobs.Add(orderableDB); MassVolumeDB mvDB = new MassVolumeDB(); blobs.Add(mvDB); TeamsHousedDB th = new TeamsHousedDB(); blobs.Add(th); //installations get added to the componentInstancesDB ComponentInstancesDB installations = new ComponentInstancesDB(); blobs.Add(installations); Entity colonyEntity = new Entity(planetEntity.Manager, factionEntity.Guid, blobs); var factionInfo = factionEntity.GetDataBlob <FactionInfoDB>(); factionInfo.Colonies.Add(colonyEntity); factionEntity.GetDataBlob <FactionOwnerDB>().SetOwned(colonyEntity); planetEntity.GetDataBlob <SystemBodyInfoDB>().Colonies.Add(colonyEntity); return(colonyEntity); }
public static Entity CreateFaction(Game game, string factionName) { var name = new NameDB(factionName); var factionDB = new FactionInfoDB(); var factionAbilitiesDB = new FactionAbilitiesDB(); var techDB = new FactionTechDB(game.StaticData.Techs.Values.ToList()); var blobs = new List <BaseDataBlob> { name, factionDB, factionAbilitiesDB, techDB }; var factionEntity = new Entity(game.GlobalManager, blobs); // Add this faction to the SM's access list. game.SpaceMaster.SetAccess(factionEntity, AccessRole.SM); return(factionEntity); }
/// <summary> /// Creates a new colony with zero population. /// </summary> /// <param name="systemEntityManager"></param> /// <param name="factionEntity"></param> /// <returns></returns> public static Entity CreateColony(Entity factionEntity, Entity speciesEntity, Entity planetEntity) { List <BaseDataBlob> blobs = new List <BaseDataBlob>(); string planetName = planetEntity.GetDataBlob <NameDB>().GetName(factionEntity); var OwnedDB = new OwnedDB(factionEntity); blobs.Add(OwnedDB); NameDB name = new NameDB(planetName + " Colony"); // TODO: Review default name. blobs.Add(name); ColonyInfoDB colonyInfoDB = new ColonyInfoDB(speciesEntity, 0, planetEntity); blobs.Add(colonyInfoDB); ColonyBonusesDB colonyBonuses = new ColonyBonusesDB(); blobs.Add(colonyBonuses); ColonyMinesDB colonyMinesDB = new ColonyMinesDB(); blobs.Add(colonyMinesDB); ColonyRefiningDB colonyRefining = new ColonyRefiningDB(); blobs.Add(colonyRefining); ColonyConstructionDB colonyConstruction = new ColonyConstructionDB(); blobs.Add(colonyConstruction); MassVolumeDB mvDB = new MassVolumeDB(); blobs.Add(mvDB); //installations get added to the componentInstancesDB ComponentInstancesDB installations = new ComponentInstancesDB(); blobs.Add(installations); Entity colonyEntity = new Entity(planetEntity.Manager, blobs); factionEntity.GetDataBlob <FactionInfoDB>().Colonies.Add(colonyEntity); return(colonyEntity); }
internal static Entity NewInstanceFromDesignEntity(Entity design, Guid factionID, EntityManager manager) { List <BaseDataBlob> blobs = new List <BaseDataBlob>(); ComponentInstanceInfoDB info = new ComponentInstanceInfoDB(design); NameDB name = new NameDB(design.GetDataBlob <NameDB>().DefaultName); name.SetName(factionID, design.GetDataBlob <NameDB>().GetName(factionID)); blobs.Add(info); blobs.Add(name); blobs.Add(new DesignInfoDB(design)); // Added because each component instance needs its own copy of this datablob //Components have a mass and volume. MassVolumeDB mvDB = (MassVolumeDB)design.GetDataBlob <MassVolumeDB>().Clone(); blobs.Add(mvDB); Entity newInstance = new Entity(manager, factionID, blobs); return(newInstance); }
public static Entity CreateJumpPoint(StarSystemFactory ssf, StarSystem system) { var primaryStarInfoDB = system.GetFirstEntityWithDataBlob <StarInfoDB>().GetDataBlob <OrbitDB>().Root.GetDataBlob <StarInfoDB>(); NameDB jpNameDB = new NameDB("Jump Point"); PositionDB jpPositionDB = new PositionDB(0, 0, 0, system.Guid); TransitableDB jpTransitableDB = new TransitableDB(); jpTransitableDB.IsStabilized = system.Game.Settings.AllJumpPointsStabilized ?? false; if (!jpTransitableDB.IsStabilized) { // TODO: Introduce a random chance to stablize jumppoints. } var jpPositionLimits = new MinMaxStruct(ssf.GalaxyGen.Settings.OrbitalDistanceByStarSpectralType[primaryStarInfoDB.SpectralType].Min, ssf.GalaxyGen.Settings.OrbitalDistanceByStarSpectralType[primaryStarInfoDB.SpectralType].Max); jpPositionDB.X_AU = GMath.SelectFromRange(jpPositionLimits, system.RNG.NextDouble()); jpPositionDB.Y_AU = GMath.SelectFromRange(jpPositionLimits, system.RNG.NextDouble()); // Randomly flip the position sign to allow negative values. if (system.RNG.Next(0, 100) < 50) { jpPositionDB.X_AU = 0 - jpPositionDB.X_AU; } if (system.RNG.Next(0, 100) < 50) { jpPositionDB.Y_AU = 0 - jpPositionDB.Y_AU; } var dataBlobs = new List <BaseDataBlob> { jpNameDB, jpTransitableDB, jpPositionDB }; Entity jumpPoint = Entity.Create(system, Guid.Empty, dataBlobs); return(jumpPoint); }
/// <summary> /// Creates an test system with planets of varying eccentricity. /// Adds to game.StarSystems /// </summary> public StarSystem CreateEccTest(Game game) { StarSystem system = new StarSystem(game, "Eccentricity test", -1); Entity sun = _starFactory.CreateStar(system, GameConstants.Units.SolarMassInKG, GameConstants.Units.SolarRadiusInAu, 4.6E9, "G", 5778, 1, SpectralType.G, "_ecc"); MassVolumeDB sunMVDB = sun.GetDataBlob <MassVolumeDB>(); double planetSemiMajAxis = 0.387098; double planetEccentricity = 0.205630; double planetInclination = 0; double planetLoAN = 48.33167; double planetLoP = 77.45645; double planetMeanLongd = 252.25084; for (int i = 0; i < 16; 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); planetEccentricity = i / 16.0; 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); }
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); }
/// <summary> /// Creates our own solar system. /// This probibly needs to be Json! (since we're getting atmo stuff) /// Adds sol to game.StarSystems. /// </summary> public StarSystem CreateSol(Game game) { // WIP Function. Not complete. StarSystem sol = new StarSystem(game, "Sol", -1); Entity sun = _starFactory.CreateStar(sol, GameConstants.Units.SolarMassInKG, GameConstants.Units.SolarRadiusInAu, 4.6E9, "G", 5778, 1, SpectralType.G, "Sol"); MassVolumeDB sunMVDB = sun.GetDataBlob <MassVolumeDB>(); SystemBodyInfoDB mercuryBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.068f }; //Albedo = 0.068f MassVolumeDB mercuryMVDB = MassVolumeDB.NewFromMassAndRadius_AU(3.3022E23, Distance.KmToAU(2439.7)); NameDB mercuryNameDB = new NameDB("Mercury"); double mercurySemiMajAxis = 0.387098; double mercuryEccentricity = 0.205630; double mercuryInclination = 0; double mercuryLoAN = 48.33167; double mercuryLoP = 77.45645; double mercuryMeanLongd = 252.25084; OrbitDB mercuryOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, mercuryMVDB.MassDry, mercurySemiMajAxis, mercuryEccentricity, mercuryInclination, mercuryLoAN, mercuryLoP, mercuryMeanLongd, GalaxyGen.Settings.J2000); mercuryBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, mercuryOrbitDB); PositionDB mercuryPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(mercuryOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); //AtmosphereDB mercuryAtmo = new AtmosphereDB(); SensorProfileDB sensorProfile = new SensorProfileDB(); Entity mercury = new Entity(sol, new List <BaseDataBlob> { sensorProfile, mercuryPositionDB, mercuryBodyDB, mercuryMVDB, mercuryNameDB, mercuryOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, mercury); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, mercuryBodyDB, mercuryMVDB); SystemBodyInfoDB venusBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.77f }; MassVolumeDB venusMVDB = MassVolumeDB.NewFromMassAndRadius_AU(4.8676E24, Distance.KmToAU(6051.8)); NameDB venusNameDB = new NameDB("Venus"); double venusSemiMajAxis = 0.72333199; double venusEccentricity = 0.00677323; double venusInclination = 0; double venusLoAN = 76.68069; double venusLoP = 131.53298; double venusMeanLongd = 181.97973; OrbitDB venusOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, venusMVDB.MassDry, venusSemiMajAxis, venusEccentricity, venusInclination, venusLoAN, venusLoP, venusMeanLongd, GalaxyGen.Settings.J2000); venusBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, venusOrbitDB); PositionDB venusPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(venusOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); sensorProfile = new SensorProfileDB(); Entity venus = new Entity(sol, new List <BaseDataBlob> { sensorProfile, venusPositionDB, venusBodyDB, venusMVDB, venusNameDB, venusOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, venus); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, venusBodyDB, venusMVDB); SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.306f }; MassVolumeDB earthMVDB = MassVolumeDB.NewFromMassAndRadius_AU(5.9726E24, Distance.KmToAU(6378.1)); NameDB earthNameDB = new NameDB("Earth"); double earthSemiMajAxis = 1.00000011; double earthEccentricity = 0.01671022; double earthInclination = 0; double earthLoAN = -11.26064; double earthLoP = 102.94719; double earthMeanLongd = 100.46435; OrbitDB earthOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, earthMVDB.MassDry, earthSemiMajAxis, earthEccentricity, earthInclination, earthLoAN, earthLoP, earthMeanLongd, GalaxyGen.Settings.J2000); earthBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, earthOrbitDB); earthBodyDB.Tectonics = TectonicActivity.EarthLike; PositionDB earthPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(earthOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>(); atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.78f); atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.12f); atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.01f); AtmosphereDB earthAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? sensorProfile = new SensorProfileDB(); Entity earth = new Entity(sol, new List <BaseDataBlob> { sensorProfile, earthPositionDB, earthBodyDB, earthMVDB, earthNameDB, earthOrbitDB, earthAtmosphereDB }); _systemBodyFactory.HomeworldMineralGeneration(game.StaticData, sol, earth); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, earthBodyDB, earthMVDB); SystemBodyInfoDB lunaBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Moon, SupportsPopulations = true }; MassVolumeDB lunaMVDB = MassVolumeDB.NewFromMassAndRadius_AU(0.073E24, Distance.KmToAU(1738.14)); NameDB lunaNameDB = new NameDB("Luna"); double lunaSemiMajAxis = Distance.KmToAU(0.3844E6); double lunaEccentricity = 0.0549; double lunaInclination = 0;//5.1; // Next three values are unimportant. Luna's LoAN and AoP regress/progress by one revolution every 18.6/8.85 years respectively. // Our orbit code it not advanced enough to deal with LoAN/AoP regression/progression. double lunaLoAN = 125.08; double lunaAoP = 318.0634; double lunaMeanAnomaly = 115.3654; OrbitDB lunaOrbitDB = OrbitDB.FromAsteroidFormat(earth, earthMVDB.MassDry, lunaMVDB.MassDry, lunaSemiMajAxis, lunaEccentricity, lunaInclination, lunaLoAN, lunaAoP, lunaMeanAnomaly, GalaxyGen.Settings.J2000); lunaBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, earthOrbitDB); //yes, using earth orbit here, since this is the DB it calculates the average distance from. PositionDB lunaPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(lunaOrbitDB, StaticRefLib.CurrentDateTime) + earthPositionDB.AbsolutePosition_AU, sol.Guid, earth); sensorProfile = new SensorProfileDB(); Entity luna = new Entity(sol, new List <BaseDataBlob> { sensorProfile, lunaPositionDB, lunaBodyDB, lunaMVDB, lunaNameDB, lunaOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, luna); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, lunaBodyDB, lunaMVDB); SystemBodyInfoDB marsBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.25f }; MassVolumeDB marsMVDB = MassVolumeDB.NewFromMassAndRadius_AU(0.64174E24, Distance.KmToAU(3396.2)); NameDB marsNameDB = new NameDB("Mars"); double marsSemiMajAxis = Distance.KmToAU(227.92E6); double marsEccentricity = 0.0934; //wiki says .0934 double marsInclination = 0; //1.85; double marsLoAN = 49.57854; double marsAoP = 336.04084; double marsMeanLong = 355.45332; OrbitDB marsOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, marsMVDB.MassDry, marsSemiMajAxis, marsEccentricity, marsInclination, marsLoAN, marsAoP, marsMeanLong, GalaxyGen.Settings.J2000); marsBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, marsOrbitDB); Dictionary <AtmosphericGasSD, float> marsAtmoGasses = new Dictionary <AtmosphericGasSD, float>(); marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(12), 0.95f * 0.01f); // C02% * Mars Atms marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.027f * 0.01f); // N% * Mars Atms marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.007f * 0.01f); // O% * Mars Atms marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.016f * 0.01f); // Ar% * Mars Atms AtmosphereDB marsAtmo = new AtmosphereDB(0.087f, false, 0, 0, 0, -55, marsAtmoGasses); PositionDB marsPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(marsOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); sensorProfile = new SensorProfileDB(); Entity mars = new Entity(sol, new List <BaseDataBlob> { sensorProfile, marsPositionDB, marsBodyDB, marsMVDB, marsNameDB, marsOrbitDB, marsAtmo }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, mars); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, marsBodyDB, marsMVDB); SystemBodyInfoDB halleysBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Comet, SupportsPopulations = false, Albedo = 0.04f }; //Albedo = 0.04f MassVolumeDB halleysMVDB = MassVolumeDB.NewFromMassAndRadius_AU(2.2e14, Distance.KmToAU(11)); NameDB halleysNameDB = new NameDB("Halleys Comet"); double halleysSemiMajAxis = 17.834; //AU double halleysEccentricity = 0.96714; double halleysInclination = 180; //162.26° note retrograde orbit. double halleysLoAN = 58.42; //° double halleysAoP = 111.33; //° double halleysMeanAnomaly = 38.38; //° OrbitDB halleysOrbitDB = OrbitDB.FromAsteroidFormat(sun, sunMVDB.MassDry, halleysMVDB.MassDry, halleysSemiMajAxis, halleysEccentricity, halleysInclination, halleysLoAN, halleysAoP, halleysMeanAnomaly, new System.DateTime(1994, 2, 17)); halleysBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, halleysOrbitDB); PositionDB halleysPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(halleysOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); // + earthPositionDB.AbsolutePosition_AU, sol.ID); sensorProfile = new SensorProfileDB(); Entity halleysComet = new Entity(sol, new List <BaseDataBlob> { sensorProfile, halleysPositionDB, halleysBodyDB, halleysMVDB, halleysNameDB, halleysOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, halleysComet); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, halleysBodyDB, halleysMVDB); /* * * SystemBody Jupiter = new SystemBody(sun, SystemBody.PlanetType.GasGiant); * Jupiter.Name = "Jupiter"; * Jupiter.Orbit = Orbit.FromMajorPlanetFormat(1898.3E24, sun.Orbit.Mass, 5.20336301, 0.04839266, 1.30530, 100.55615, 14.75385, 34.40438, GalaxyGen.J2000); * Jupiter.Radius = Distance.ToAU(71492); * Jupiter.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Jupiter.Position.System = Sol; * Jupiter.Position.X = x; * Jupiter.Position.Y = y; * sun.Planets.Add(Jupiter); * * SystemBody Saturn = new SystemBody(sun, SystemBody.PlanetType.GasGiant); * Saturn.Name = "Saturn"; * Saturn.Orbit = Orbit.FromMajorPlanetFormat(568.36E24, sun.Orbit.Mass, 9.53707032, 0.05415060, 2.48446, 113.71504, 92.43194, 49.94432, GalaxyGen.J2000); * Saturn.Radius = Distance.ToAU(60268); * Saturn.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Saturn.Position.System = Sol; * Saturn.Position.X = x; * Saturn.Position.Y = y; * sun.Planets.Add(Saturn); * * SystemBody Uranus = new SystemBody(sun, SystemBody.PlanetType.IceGiant); * Uranus.Name = "Uranus"; * Uranus.Orbit = Orbit.FromMajorPlanetFormat(86.816E24, sun.Orbit.Mass, 19.19126393, 0.04716771, 0.76986, 74.22988, 170.96424, 313.23218, GalaxyGen.J2000); * Uranus.Radius = Distance.ToAU(25559); * Uranus.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Uranus.Position.System = Sol; * Uranus.Position.X = x; * Uranus.Position.Y = y; * sun.Planets.Add(Uranus); * * SystemBody Neptune = new SystemBody(sun, SystemBody.PlanetType.IceGiant); * Neptune.Name = "Neptune"; * Neptune.Orbit = Orbit.FromMajorPlanetFormat(102E24, sun.Orbit.Mass, Distance.ToAU(4495.1E6), 0.011, 1.8, 131.72169, 44.97135, 304.88003, GalaxyGen.J2000); * Neptune.Radius = Distance.ToAU(24764); * Neptune.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Neptune.Position.System = Sol; * Neptune.Position.X = x; * Neptune.Position.Y = y; * sun.Planets.Add(Neptune); * * SystemBody Pluto = new SystemBody(sun, SystemBody.PlanetType.DwarfPlanet); * Pluto.Name = "Pluto"; * Pluto.Orbit = Orbit.FromMajorPlanetFormat(0.0131E24, sun.Orbit.Mass, Distance.ToAU(5906.38E6), 0.24880766, 17.14175, 110.30347, 224.06676, 238.92881, GalaxyGen.J2000); * Pluto.Radius = Distance.ToAU(1195); * Pluto.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Pluto.Position.System = Sol; * Pluto.Position.X = x; * Pluto.Position.Y = y; * sun.Planets.Add(Pluto); * * GenerateJumpPoints(Sol); * * // Clean up cached RNG: * m_RNG = null; * GameState.Instance.StarSystems.Add(Sol); * GameState.Instance.StarSystemCurrentIndex++; */ /* * double planetSemiMajAxis = 0.387098; * double planetEccentricity = 0.205630; * double planetInclination = 0; * double planetLoAN = 0;//48.33167; * double planetLoP = 0;//77.45645; * double planetMeanLongd = 252.25084; * * EMWaveForm waveform; * * for (int i = 0; i < 8; i++) * { * NameDB planetNameDB = new NameDB("planetE" + 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(sol.ID); * planetEccentricity = i * 2 / 16.0; * OrbitDB planetOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, planetMVDB.Mass, planetSemiMajAxis, planetEccentricity, planetInclination, planetLoAN, planetLoP, planetMeanLongd, GalaxyGen.Settings.J2000); * planetPositionDB.AbsolutePosition = OrbitProcessor.GetPosition(planetOrbitDB, game.CurrentDateTime); * * waveform = new EMWaveForm() * { * WavelengthAverage_nm = 600, * WavelengthMin_nm = 600 - 400, //4k angstrom, semi arbitrary number pulled outa my ass from 0min of internet research. * WavelengthMax_nm = 600 + 600 * }; * * sensorProfile = new SensorProfileDB(); * sensorProfile.EmittedEMSpectra.Add(waveform, 3.827e23); * Entity planet = new Entity(sol, new List<BaseDataBlob> { sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetNameDB, planetOrbitDB }); * } * * planetEccentricity = 0.9; * for (int i = 0; i < 8; i++) * { * NameDB planetNameDB = new NameDB("planetL" + 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(sol.ID); * planetLoP = i * 15; * OrbitDB planetOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, planetMVDB.Mass, planetSemiMajAxis, planetEccentricity, planetInclination, planetLoAN, planetLoP, planetMeanLongd, GalaxyGen.Settings.J2000); * planetPositionDB.AbsolutePosition = OrbitProcessor.GetPosition(planetOrbitDB, game.CurrentDateTime); * * waveform = new EMWaveForm() * { * WavelengthAverage_nm = 600, * WavelengthMin_nm = 600 - 400, //4k angstrom, semi arbitrary number pulled outa my ass from 0min of internet research. * WavelengthMax_nm = 600 + 600 * }; * * sensorProfile = new SensorProfileDB(); * sensorProfile.EmittedEMSpectra.Add(waveform, 3.827e23); * Entity planet = new Entity(sol, new List<BaseDataBlob> {sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetNameDB, planetOrbitDB }); * } */ JPSurveyFactory.GenerateJPSurveyPoints(sol); game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid); return(sol); }
/// <summary> /// Generates an entire group of stars for a starSystem. /// </summary> /// <remarks> /// Stars created with this method are sorted by mass. /// Stars created with this method are added to the newSystem's EntityManager. /// </remarks> /// <param name="system">The Star System the new stars belongs to.</param> /// <param name="numStars">The number of stars to create.</param> /// <returns>A mass-sorted list of entity ID's for the generated stars.</returns> public List <Entity> CreateStarsForSystem(StarSystem system, int numStars, DateTime currentDateTime) { // Argument Validation. if (system == null) { throw new ArgumentNullException("system"); } if (numStars <= 0) { throw new ArgumentOutOfRangeException("numStars", "numStars must be greater than 0."); } // List of stars we'll be creating. var stars = new List <Entity>(); while (stars.Count < numStars) { // Generate a SpectralType for the star. SpectralType starType; if (_galaxyGen.Settings.RealStarSystems) { starType = _galaxyGen.Settings.StarTypeDistributionForRealStars.Select(system.RNG.NextDouble()); } else { starType = _galaxyGen.Settings.StarTypeDistributionForFakeStars.Select(system.RNG.NextDouble()); } // We will use the one random number to select from all the spectral type ranges. Should give us saner numbers for stars. double randomSelection = system.RNG.NextDouble(); // Generate the star's datablobs. MassVolumeDB starMVDB = MassVolumeDB.NewFromMassAndRadius( GMath.SelectFromRange(_galaxyGen.Settings.StarMassBySpectralType[starType], randomSelection), GMath.SelectFromRange(_galaxyGen.Settings.StarRadiusBySpectralType[starType], randomSelection)); StarInfoDB starData = GenerateStarInfo(starMVDB, starType, randomSelection); // Initialize Position as 0,0,0. It will be updated when the star's orbit is calculated. PositionDB positionData = new PositionDB(0, 0, 0, system.Guid); var baseDataBlobs = new List <BaseDataBlob> { starMVDB, starData, positionData }; stars.Add(Entity.Create(system, Guid.Empty, baseDataBlobs)); } // The root star must be the most massive. Find it. Entity rootStar = stars[0]; double rootStarMass = rootStar.GetDataBlob <MassVolumeDB>().Mass; foreach (Entity currentStar in stars) { double currentStarMass = currentStar.GetDataBlob <MassVolumeDB>().Mass; if (rootStarMass < currentStarMass) { rootStar = currentStar; rootStarMass = rootStar.GetDataBlob <MassVolumeDB>().Mass; } } // Swap the root star to index 0. int rootIndex = stars.IndexOf(rootStar); Entity displacedStar = stars[0]; stars[rootIndex] = displacedStar; stars[0] = rootStar; // Generate orbits. Entity anchorStar = stars[0]; MassVolumeDB anchorMVDB = anchorStar.GetDataBlob <MassVolumeDB>(); Entity previousStar = stars[0]; previousStar.SetDataBlob(new OrbitDB()); int starIndex = 0; foreach (Entity currentStar in stars) { StarInfoDB currentStarInfo = currentStar.GetDataBlob <StarInfoDB>(); NameDB currentStarNameDB = new NameDB(system.NameDB.DefaultName + " " + (char)('A' + starIndex) + " " + currentStarInfo.SpectralType + currentStarInfo.SpectralSubDivision + currentStarInfo.LuminosityClass); currentStar.SetDataBlob(currentStarNameDB); if (previousStar == currentStar) { // This is the "Anchor Star" continue; } OrbitDB previousOrbit = previousStar.GetDataBlob <OrbitDB>(); StarInfoDB previousStarInfo = previousStar.GetDataBlob <StarInfoDB>(); double minDistance = _galaxyGen.Settings.OrbitalDistanceByStarSpectralType[previousStarInfo.SpectralType].Max + _galaxyGen.Settings.OrbitalDistanceByStarSpectralType[currentStarInfo.SpectralType].Max + previousOrbit.SemiMajorAxis; double sma = minDistance * Math.Pow(system.RNG.NextDouble(), 3); double eccentricity = Math.Pow(system.RNG.NextDouble() * 0.8, 3); OrbitDB currentOrbit = OrbitDB.FromAsteroidFormat(anchorStar, anchorMVDB.Mass, currentStar.GetDataBlob <MassVolumeDB>().Mass, sma, eccentricity, _galaxyGen.Settings.MaxBodyInclination * system.RNG.NextDouble(), system.RNG.NextDouble() * 360, system.RNG.NextDouble() * 360, system.RNG.NextDouble() * 360, currentDateTime); currentStar.SetDataBlob(currentOrbit); currentStar.GetDataBlob <PositionDB>().SetParent(currentOrbit.Parent); previousStar = currentStar; starIndex++; } return(stars); }
/// <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); }
/// <summary> /// Creates Entity and blobs. /// </summary> /// <param name="globalEntityManager"></param> /// <param name="componentDesign"></param> /// <param name="factionTech"></param> /// <returns></returns> public static Entity DesignToDesignEntity(Game game, Entity factionEntity, ComponentDesign componentDesign) { EntityManager globalEntityManager = game.GlobalManager; StaticDataStore staticData = game.StaticData; FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>(); FactionInfoDB faction = factionEntity.GetDataBlob <FactionInfoDB>(); //TODO probilby do checking to see if valid here? Entity component = new Entity(globalEntityManager, factionEntity); TechSD tech = new TechSD(); tech.ID = Guid.NewGuid(); tech.Name = componentDesign.Name + " Design Research"; tech.Description = "Research into building " + componentDesign.Name; tech.MaxLevel = 1; tech.CostFormula = componentDesign.ResearchCostValue.ToString(); factionTech.ResearchableTechs.Add(tech, 0); NameDB nameDB = new NameDB(componentDesign.RawName); nameDB.SetName(factionEntity.Guid, componentDesign.Name); Dictionary <Guid, int> mineralCosts = new Dictionary <Guid, int>(); Dictionary <Guid, int> materalCosts = new Dictionary <Guid, int>(); Dictionary <Guid, int> componentCosts = new Dictionary <Guid, int>(); foreach (var kvp in componentDesign.MineralCostValues) { if (staticData.CargoGoods.IsMaterial(kvp.Key)) { materalCosts.Add(kvp.Key, kvp.Value); } else if (staticData.ComponentTemplates.ContainsKey(kvp.Key)) { componentCosts.Add(kvp.Key, kvp.Value); } else if (staticData.CargoGoods.IsMineral(kvp.Key)) { mineralCosts.Add(kvp.Key, kvp.Value); } else { throw new Exception("GUID object {" + kvp.Key + "} not found in materialCosting for " + componentDesign.Name + " This object needs to be either a mineral, material or component defined in the Data folder"); } } ComponentInfoDB componentInfo = new ComponentInfoDB(component.Guid, componentDesign.MassValue, componentDesign.HTKValue, componentDesign.BuildCostValue, mineralCosts, materalCosts, componentCosts, tech.ID, componentDesign.CrewReqValue); componentInfo.ComponentMountType = componentDesign.ComponentMountType; componentInfo.ConstructionType = componentDesign.ConstructionType; CargoAbleTypeDB cargoType = new CargoAbleTypeDB(componentDesign.CargoTypeID); component.SetDataBlob(componentInfo); component.SetDataBlob(nameDB); component.SetDataBlob(cargoType); //note: MassVolumeDB stores mass in kg and volume in km^3, however we use kg and m^3 in the json data. component.SetDataBlob(MassVolumeDB.NewFromMassAndVolume(componentDesign.MassValue, componentDesign.VolumeValue * 1e-9)); foreach (var designAttribute in componentDesign.ComponentDesignAttributes) { if (designAttribute.DataBlobType != null) { if (designAttribute.DataBlobArgs == null) { designAttribute.SetValue(); //force recalc. } object[] constructorArgs = designAttribute.DataBlobArgs; dynamic datablob = (BaseDataBlob)Activator.CreateInstance(designAttribute.DataBlobType, constructorArgs); component.SetDataBlob(datablob); if (datablob is IComponentDesignAttribute) { componentInfo.DesignAttributes.Add(datablob); } } } faction.InternalComponentDesigns.Add(component.Guid, component); return(component); }
public NameDB(NameDB nameDB) { _names = new Dictionary <Entity, string>(nameDB._names); }
NameDB(NameDB db, SensorInfoDB sensorInfo) { _names.Add(Guid.Empty, db.DefaultName); _names[sensorInfo.Faction.Guid] = db.GetName(sensorInfo.Faction.Guid); }
public static Entity CreateShip(Entity classEntity, EntityManager systemEntityManager, Entity ownerFaction, Vector3 pos, StarSystem starsys, string shipName = null) { // @todo replace ownerFaction with formationDB later. Now ownerFaction used just to add name // @todo: make sure each component design and component instance is unique, not duplicated ProtoEntity protoShip = classEntity.Clone(); ShipInfoDB shipInfoDB = protoShip.GetDataBlob <ShipInfoDB>(); shipInfoDB.ShipClassDefinition = classEntity.Guid; if (shipName == null) { shipName = "Ship Name"; } NameDB nameDB = new NameDB(shipName); nameDB.SetName(ownerFaction.Guid, shipName); protoShip.SetDataBlob(nameDB); OrderableDB orderableDB = new OrderableDB(); protoShip.SetDataBlob(orderableDB); PositionDB position = new PositionDB(pos, starsys.Guid); protoShip.SetDataBlob(position); protoShip.SetDataBlob(new DesignInfoDB(classEntity)); //replace the ships references to the design's specific instances with shiny new specific instances ComponentInstancesDB classInstances = classEntity.GetDataBlob <ComponentInstancesDB>(); Entity shipEntity = new Entity(systemEntityManager, ownerFaction.Guid, protoShip); shipEntity.RemoveDataBlob <ComponentInstancesDB>(); shipEntity.SetDataBlob(new ComponentInstancesDB()); if (shipEntity.HasDataBlob <FireControlAbilityDB>()) { shipEntity.RemoveDataBlob <FireControlAbilityDB>(); } foreach (var designKVP in classInstances.DesignsAndComponentCount) { for (int i = 0; i < designKVP.Value; i++) { Entity newInstance = ComponentInstanceFactory.NewInstanceFromDesignEntity(designKVP.Key, ownerFaction.Guid, systemEntityManager); EntityManipulation.AddComponentToEntity(shipEntity, newInstance); } } FactionOwnerDB factionOwner = ownerFaction.GetDataBlob <FactionOwnerDB>(); factionOwner.SetOwned(shipEntity); ComponentInstancesDB shipComponentInstanceDB = shipEntity.GetDataBlob <ComponentInstancesDB>(); //TODO: do this somewhere else, recalcprocessor maybe? foreach (var design in shipComponentInstanceDB.GetDesignsByType(typeof(SensorReceverAtbDB))) { foreach (var instance in shipComponentInstanceDB.GetComponentsBySpecificDesign(design.Guid)) { var sensor = design.GetDataBlob <SensorReceverAtbDB>(); DateTime nextDatetime = shipEntity.Manager.ManagerSubpulses.StarSysDateTime + TimeSpan.FromSeconds(sensor.ScanTime); shipEntity.Manager.ManagerSubpulses.AddEntityInterupt(nextDatetime, new SensorScan().TypeName, instance.OwningEntity); } } ReCalcProcessor.ReCalcAbilities(shipEntity); return(shipEntity); }
NameDB(NameDB db, SensorInfoDB sensorInfo) { _names.Add(Entity.InvalidEntity, db.DefaultName); _names[sensorInfo.Faction] = db.GetName(sensorInfo.Faction); }
public static Entity CreateShip(Entity classEntity, EntityManager systemEntityManager, Entity ownerFaction, Vector4 pos, StarSystem starsys, string shipName = null) { // @todo replace ownerFaction with formationDB later. Now ownerFaction used just to add name // @todo: make sure each component design and component instance is unique, not duplicated ProtoEntity protoShip = classEntity.Clone(); ShipInfoDB shipInfoDB = protoShip.GetDataBlob <ShipInfoDB>(); shipInfoDB.ShipClassDefinition = classEntity.Guid; if (shipName == null) { shipName = "Ship Name"; } NameDB nameDB = new NameDB(shipName); nameDB.SetName(ownerFaction, shipName); protoShip.SetDataBlob(nameDB); OrderableDB orderableDB = new OrderableDB(); protoShip.SetDataBlob(orderableDB); PositionDB position = new PositionDB(pos, starsys.Guid); protoShip.SetDataBlob(position); protoShip.SetDataBlob(new DesignInfoDB(classEntity)); Entity shipEntity = new Entity(systemEntityManager, protoShip); new OwnedDB(ownerFaction, shipEntity); //replace the ships references to the design's specific instances with shiny new specific instances ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>(); var newSpecificInstances = new PrIwObsDict <Entity, PrIwObsList <Entity> >(); foreach (var kvp in componentInstances.SpecificInstances) { newSpecificInstances.Add(kvp.Key, new PrIwObsList <Entity>()); for (int i = 0; i < kvp.Value.Count; i++) { var ownerdb = ownerFaction.GetDataBlob <FactionOwnerDB>(); newSpecificInstances[kvp.Key].Add(ComponentInstanceFactory.NewInstanceFromDesignEntity(kvp.Key, ownerFaction, ownerdb, systemEntityManager)); } } componentInstances.SpecificInstances = newSpecificInstances; foreach (var componentType in shipEntity.GetDataBlob <ComponentInstancesDB>().SpecificInstances) { int numComponents = componentType.Value.Count; componentType.Value.Clear(); for (int i = 0; i < numComponents; i++) { EntityManipulation.AddComponentToEntity(shipEntity, componentType.Key); } foreach (var componentInstance in componentType.Value) { // Set the parent/owning Entity to the shipEntity AttributeToAbilityMap.AddAbility(shipEntity, componentType.Key, componentInstance); //TODO: do this somewhere else, recalcprocessor maybe? if (componentInstance.HasDataBlob <SensorReceverAtbDB>()) { var sensor = componentInstance.GetDataBlob <SensorReceverAtbDB>(); DateTime nextDatetime = shipEntity.Manager.ManagerSubpulses.SystemLocalDateTime + TimeSpan.FromSeconds(sensor.ScanTime); shipEntity.Manager.ManagerSubpulses.AddEntityInterupt(nextDatetime, new SensorScan().TypeName, componentInstance); } } } ReCalcProcessor.ReCalcAbilities(shipEntity); return(shipEntity); }
public static Entity CreateSpeciesFromBlobs(Entity faction, EntityManager globalManager, NameDB nameDB, SpeciesDB speciesDB) { var blobs = new List <BaseDataBlob> { nameDB, speciesDB }; Entity species = new Entity(globalManager, blobs); faction.GetDataBlob <FactionInfoDB>().Species.Add(species); return(species); }
public static Entity CreateShip(Entity classEntity, EntityManager systemEntityManager, Entity ownerFaction, Vector4 pos, StarSystem starsys, string shipName = null) { // @todo replace ownerFaction with formationDB later. Now ownerFaction used just to add name // @todo: make sure each component design and component instance is unique, not duplicated ProtoEntity protoShip = classEntity.Clone(); ShipInfoDB shipInfoDB = protoShip.GetDataBlob <ShipInfoDB>(); shipInfoDB.ShipClassDefinition = classEntity.Guid; if (shipName == null) { shipName = "Ship Name"; } NameDB nameDB = new NameDB(shipName); protoShip.SetDataBlob(nameDB); var OwnedDB = new OwnedDB(ownerFaction); protoShip.SetDataBlob(OwnedDB); PositionDB position = new PositionDB(pos, starsys.Guid); protoShip.SetDataBlob(position); protoShip.SetDataBlob(new DesignInfoDB(classEntity)); Entity shipEntity = new Entity(systemEntityManager, protoShip); //replace the ships references to the design's specific instances with shiny new specific instances ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>(); var newSpecificInstances = new PrIwObsDict <Entity, PrIwObsList <Entity> >(); foreach (var kvp in componentInstances.SpecificInstances) { newSpecificInstances.Add(kvp.Key, new PrIwObsList <Entity>()); for (int i = 0; i < kvp.Value.Count; i++) { newSpecificInstances[kvp.Key].Add(ComponentInstanceFactory.NewInstanceFromDesignEntity(kvp.Key, ownerFaction)); } } componentInstances.SpecificInstances = newSpecificInstances; foreach (var componentType in shipEntity.GetDataBlob <ComponentInstancesDB>().SpecificInstances) { int numComponents = componentType.Value.Count; componentType.Value.Clear(); for (int i = 0; i < numComponents; i++) { EntityManipulation.AddComponentToEntity(shipEntity, componentType.Key); } foreach (var componentInstance in componentType.Value) { // Set the parent/owning Entity to the shipEntity AttributeToAbilityMap.AddAbility(shipEntity, componentType.Key, componentInstance); } } ReCalcProcessor.ReCalcAbilities(shipEntity); return(shipEntity); }
public static Entity CreateNewShipClass(Game game, Entity faction, string className = null) { //check className before any to use it in NameDB constructor if (string.IsNullOrEmpty(className)) { ///< @todo source the class name from faction theme. className = "New Class"; // <- Hack for now. } // lets start by creating all the Datablobs that make up a ship class: TODO only need to add datablobs for compoents it has abilites for. var shipInfo = new ShipInfoDB(); var armor = new ArmorDB(); var buildCost = new BuildCostDB(); var cargotype = new CargoAbleTypeDB(); var crew = new CrewDB(); var damage = new DamageDB(); var maintenance = new MaintenanceDB(); var sensorProfile = new SensorProfileDB(); var name = new NameDB(className); name.SetName(faction.Guid, className); var componentInstancesDB = new ComponentInstancesDB(); var massVolumeDB = new MassVolumeDB(); // now lets create a list of all these datablobs so we can create our new entity: List <BaseDataBlob> shipDBList = new List <BaseDataBlob>() { shipInfo, armor, buildCost, cargotype, crew, damage, maintenance, sensorProfile, name, componentInstancesDB, massVolumeDB, }; // now lets create the ship class: Entity shipClassEntity = new Entity(game.GlobalManager, faction.Guid, shipDBList); FactionOwnerDB factionOwner = faction.GetDataBlob <FactionOwnerDB>(); factionOwner.SetOwned(shipClassEntity); // also gets factionDB: FactionInfoDB factionDB = faction.GetDataBlob <FactionInfoDB>(); // and add it to the faction: factionDB.ShipClasses.Add(shipClassEntity); // now lets set some ship info: shipInfo.ShipClassDefinition = Guid.Empty; // just make sure it is marked as a class and not a ship. // now lets add some components: ///< @todo Add ship components // -- basic armour of current faction tech level // -- minimum crew quaters defaulting to 3 months deployment time. // -- a bridge // -- an engineering space // -- a fuel tank // now update the ship system DBs to reflect the components: ///< @todo update ship to reflect added components return(shipClassEntity); }
public StarSystem CreateTestSystem(Game game, int x = 0, int y = 0) { StarSystem sol = new StarSystem(game, "something", -1); Entity sun = _starFactory.CreateStar(sol, GameConstants.Units.SolarMassInKG, GameConstants.Units.SolarRadiusInAu, 4.6E9, "G", 5778, 1, SpectralType.G, "something"); sun.GetDataBlob <PositionDB>().X_AU += x; sun.GetDataBlob <PositionDB>().Y_AU += x; MassVolumeDB sunMVDB = sun.GetDataBlob <MassVolumeDB>(); SystemBodyInfoDB mercuryBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.068f }; //Albedo = 0.068f MassVolumeDB mercuryMVDB = MassVolumeDB.NewFromMassAndRadius_AU(3.3022E23, Distance.KmToAU(2439.7)); NameDB mercuryNameDB = new NameDB("LOLXDWTF"); double mercurySemiMajAxis = 0.387098; double mercuryEccentricity = 0.205630; double mercuryInclination = 0; double mercuryLoAN = 48.33167; double mercuryLoP = 77.45645; double mercuryMeanLongd = 252.25084; OrbitDB mercuryOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, mercuryMVDB.MassDry, mercurySemiMajAxis, mercuryEccentricity, mercuryInclination, mercuryLoAN, mercuryLoP, mercuryMeanLongd, GalaxyGen.Settings.J2000); PositionDB mercuryPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(mercuryOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); //AtmosphereDB mercuryAtmo = new AtmosphereDB(); SensorProfileDB sensorProfile = new SensorProfileDB(); mercuryPositionDB.X_AU += x; mercuryPositionDB.Y_AU += x; Entity mercury = new Entity(sol, new List <BaseDataBlob> { sensorProfile, mercuryPositionDB, mercuryBodyDB, mercuryMVDB, mercuryNameDB, mercuryOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, mercury); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, mercuryBodyDB, mercuryMVDB); SystemBodyInfoDB venusBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.77f }; MassVolumeDB venusMVDB = MassVolumeDB.NewFromMassAndRadius_AU(4.8676E24, Distance.KmToAU(6051.8)); NameDB venusNameDB = new NameDB("AYLMAOROFL"); double venusSemiMajAxis = 0.72333199; double venusEccentricity = 0.00677323; double venusInclination = 0; double venusLoAN = 76.68069; double venusLoP = 131.53298; double venusMeanLongd = 181.97973; OrbitDB venusOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, venusMVDB.MassDry, venusSemiMajAxis, venusEccentricity, venusInclination, venusLoAN, venusLoP, venusMeanLongd, GalaxyGen.Settings.J2000); PositionDB venusPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(venusOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); sensorProfile = new SensorProfileDB(); Entity venus = new Entity(sol, new List <BaseDataBlob> { sensorProfile, venusPositionDB, venusBodyDB, venusMVDB, venusNameDB, venusOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, venus); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, venusBodyDB, venusMVDB); SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.306f }; MassVolumeDB earthMVDB = MassVolumeDB.NewFromMassAndRadius_AU(5.9726E24, Distance.KmToAU(6378.1)); NameDB earthNameDB = new NameDB("OMG"); double earthSemiMajAxis = 1.00000011; double earthEccentricity = 0.01671022; double earthInclination = 0; double earthLoAN = -11.26064; double earthLoP = 102.94719; double earthMeanLongd = 100.46435; OrbitDB earthOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, earthMVDB.MassDry, earthSemiMajAxis, earthEccentricity, earthInclination, earthLoAN, earthLoP, earthMeanLongd, GalaxyGen.Settings.J2000); earthBodyDB.Tectonics = TectonicActivity.EarthLike; PositionDB earthPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(earthOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>(); atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.78f); atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.12f); atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.01f); AtmosphereDB earthAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? sensorProfile = new SensorProfileDB(); Entity earth = new Entity(sol, new List <BaseDataBlob> { sensorProfile, earthPositionDB, earthBodyDB, earthMVDB, earthNameDB, earthOrbitDB, earthAtmosphereDB }); _systemBodyFactory.HomeworldMineralGeneration(game.StaticData, sol, earth); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, earthBodyDB, earthMVDB); SystemBodyInfoDB lunaBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Moon, SupportsPopulations = true }; MassVolumeDB lunaMVDB = MassVolumeDB.NewFromMassAndRadius_AU(0.073E24, Distance.KmToAU(1738.14)); NameDB lunaNameDB = new NameDB("NOWAY"); double lunaSemiMajAxis = Distance.KmToAU(0.3844E6); double lunaEccentricity = 0.0549; double lunaInclination = 0;//5.1; // Next three values are unimportant. Luna's LoAN and AoP regress/progress by one revolution every 18.6/8.85 years respectively. // Our orbit code it not advanced enough to deal with LoAN/AoP regression/progression. double lunaLoAN = 125.08; double lunaAoP = 318.0634; double lunaMeanAnomaly = 115.3654; OrbitDB lunaOrbitDB = OrbitDB.FromAsteroidFormat(earth, earthMVDB.MassDry, lunaMVDB.MassDry, lunaSemiMajAxis, lunaEccentricity, lunaInclination, lunaLoAN, lunaAoP, lunaMeanAnomaly, GalaxyGen.Settings.J2000); PositionDB lunaPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(lunaOrbitDB, StaticRefLib.CurrentDateTime) + earthPositionDB.AbsolutePosition_AU, sol.Guid, earth); sensorProfile = new SensorProfileDB(); Entity luna = new Entity(sol, new List <BaseDataBlob> { sensorProfile, lunaPositionDB, lunaBodyDB, lunaMVDB, lunaNameDB, lunaOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, luna); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, lunaBodyDB, lunaMVDB); SystemBodyInfoDB halleysBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Comet, SupportsPopulations = false, Albedo = 0.04f }; //Albedo = 0.04f MassVolumeDB halleysMVDB = MassVolumeDB.NewFromMassAndRadius_AU(2.2e14, Distance.KmToAU(11)); NameDB halleysNameDB = new NameDB("ASSHOLE"); double halleysSemiMajAxis = 17.834; //AU double halleysEccentricity = 0.96714; double halleysInclination = 180; //162.26° note retrograde orbit. double halleysLoAN = 58.42; //° double halleysAoP = 111.33; //° double halleysMeanAnomaly = 38.38; //° OrbitDB halleysOrbitDB = OrbitDB.FromAsteroidFormat(sun, sunMVDB.MassDry, halleysMVDB.MassDry, halleysSemiMajAxis, halleysEccentricity, halleysInclination, halleysLoAN, halleysAoP, halleysMeanAnomaly, new System.DateTime(1994, 2, 17)); PositionDB halleysPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(halleysOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); // + earthPositionDB.AbsolutePosition_AU, sol.ID); sensorProfile = new SensorProfileDB(); Entity halleysComet = new Entity(sol, new List <BaseDataBlob> { sensorProfile, halleysPositionDB, halleysBodyDB, halleysMVDB, halleysNameDB, halleysOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, halleysComet); SensorProcessorTools.PlanetEmmisionSig(sensorProfile, halleysBodyDB, halleysMVDB); JPSurveyFactory.GenerateJPSurveyPoints(sol); game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid); return(sol); }
public NameDB(NameDB nameDB) { _names = new Dictionary <Guid, string>(nameDB._names); }
/// <summary> /// Creates our own solar system. /// This probibly needs to be Json! (since we're getting atmo stuff) /// Adds sol to game.StarSystems. /// </summary> public StarSystem CreateSol(Game game) { // WIP Function. Not complete. StarSystem sol = new StarSystem(game, "Sol", -1); Entity sun = _starFactory.CreateStar(sol, GameConstants.Units.SolarMassInKG, GameConstants.Units.SolarRadiusInAu, 4.6E9, "G", 5778, 1, SpectralType.G, "Sol"); MassVolumeDB sunMVDB = sun.GetDataBlob <MassVolumeDB>(); SystemBodyInfoDB mercuryBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true }; MassVolumeDB mercuryMVDB = MassVolumeDB.NewFromMassAndRadius(3.3022E23, Distance.KmToAU(2439.7)); NameDB mercuryNameDB = new NameDB("Mercury"); double mercurySemiMajAxis = 0.387098; double mercuryEccentricity = 0.205630; double mercuryInclination = 0; double mercuryLoAN = 48.33167; double mercuryLoP = 77.45645; double mercuryMeanLongd = 252.25084; OrbitDB mercuryOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, mercuryMVDB.Mass, mercurySemiMajAxis, mercuryEccentricity, mercuryInclination, mercuryLoAN, mercuryLoP, mercuryMeanLongd, GalaxyGen.Settings.J2000); PositionDB mercuryPositionDB = new PositionDB(OrbitProcessor.GetPosition(mercuryOrbitDB, game.CurrentDateTime), sol.Guid); Entity mercury = new Entity(sol.SystemManager, new List <BaseDataBlob> { mercuryPositionDB, mercuryBodyDB, mercuryMVDB, mercuryNameDB, mercuryOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, mercury); SystemBodyInfoDB venusBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true }; MassVolumeDB venusMVDB = MassVolumeDB.NewFromMassAndRadius(4.8676E24, Distance.KmToAU(6051.8)); NameDB venusNameDB = new NameDB("Venus"); double venusSemiMajAxis = 0.72333199; double venusEccentricity = 0.00677323; double venusInclination = 0; double venusLoAN = 76.68069; double venusLoP = 131.53298; double venusMeanLongd = 181.97973; OrbitDB venusOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, venusMVDB.Mass, venusSemiMajAxis, venusEccentricity, venusInclination, venusLoAN, venusLoP, venusMeanLongd, GalaxyGen.Settings.J2000); PositionDB venusPositionDB = new PositionDB(OrbitProcessor.GetPosition(venusOrbitDB, game.CurrentDateTime), sol.Guid); Entity venus = new Entity(sol.SystemManager, new List <BaseDataBlob> { venusPositionDB, venusBodyDB, venusMVDB, venusNameDB, venusOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, venus); SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true }; MassVolumeDB earthMVDB = MassVolumeDB.NewFromMassAndRadius(5.9726E24, Distance.KmToAU(6378.1)); NameDB earthNameDB = new NameDB("Earth"); double earthSemiMajAxis = 1.00000011; double earthEccentricity = 0.01671022; double earthInclination = 0; double earthLoAN = -11.26064; double earthLoP = 102.94719; double earthMeanLongd = 100.46435; OrbitDB earthOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, earthMVDB.Mass, earthSemiMajAxis, earthEccentricity, earthInclination, earthLoAN, earthLoP, earthMeanLongd, GalaxyGen.Settings.J2000); earthBodyDB.Tectonics = TectonicActivity.EarthLike; PositionDB earthPositionDB = new PositionDB(OrbitProcessor.GetPosition(earthOrbitDB, game.CurrentDateTime), sol.Guid); Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>(); atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.78f); atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.12f); atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.01f); AtmosphereDB earthAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? Entity earth = new Entity(sol.SystemManager, new List <BaseDataBlob> { earthPositionDB, earthBodyDB, earthMVDB, earthNameDB, earthOrbitDB, earthAtmosphereDB }); _systemBodyFactory.HomeworldMineralGeneration(game.StaticData, sol, earth); SystemBodyInfoDB lunaBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Moon, SupportsPopulations = true }; MassVolumeDB lunaMVDB = MassVolumeDB.NewFromMassAndRadius(0.073E24, Distance.KmToAU(1738.14)); NameDB lunaNameDB = new NameDB("Luna"); double lunaSemiMajAxis = Distance.KmToAU(0.3844E6); double lunaEccentricity = 0.0549; double lunaInclination = 5.1; // Next three values are unimportant. Luna's LoAN and AoP regress/progress by one revolution every 18.6/8.85 years respectively. // Our orbit code it not advanced enough to deal with LoAN/AoP regression/progression. double lunaLoAN = 125.08; double lunaAoP = 318.0634; double lunaMeanAnomaly = 115.3654; OrbitDB lunaOrbitDB = OrbitDB.FromAsteroidFormat(earth, earthMVDB.Mass, lunaMVDB.Mass, lunaSemiMajAxis, lunaEccentricity, lunaInclination, lunaLoAN, lunaAoP, lunaMeanAnomaly, GalaxyGen.Settings.J2000); PositionDB lunaPositionDB = new PositionDB(OrbitProcessor.GetPosition(lunaOrbitDB, game.CurrentDateTime), sol.Guid); Entity luna = new Entity(sol.SystemManager, new List <BaseDataBlob> { lunaPositionDB, lunaBodyDB, lunaMVDB, lunaNameDB, lunaOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, luna); SystemBodyInfoDB marsBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true }; MassVolumeDB marsMVDB = MassVolumeDB.NewFromMassAndRadius(0.64174E24, Distance.KmToAU(3396.2)); NameDB marsNameDB = new NameDB("Mars"); double marsSemiMajAxis = Distance.KmToAU(227.92E6); double marsEccentricity = 0.0934; //wiki says .0934 double marsInclination = 1.85; double marsLoAN = 49.57854; double marsAoP = 336.04084; double marsMeanLong = 355.45332; OrbitDB marsOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, marsMVDB.Mass, marsSemiMajAxis, marsEccentricity, marsInclination, marsLoAN, marsAoP, marsMeanLong, GalaxyGen.Settings.J2000); PositionDB marsPositionDB = new PositionDB(OrbitProcessor.GetPosition(marsOrbitDB, game.CurrentDateTime), sol.Guid); Entity mars = new Entity(sol.SystemManager, new List <BaseDataBlob> { marsPositionDB, marsBodyDB, marsMVDB, marsNameDB, marsOrbitDB }); _systemBodyFactory.MineralGeneration(game.StaticData, sol, mars); /* * * SystemBody Mars = new SystemBody(sun, SystemBody.PlanetType.Terrestrial); * Mars.Name = "Mars"; * Mars.Orbit = Orbit.FromMajorPlanetFormat(0.64174E24, sun.Orbit.Mass, 1.52366231, 0.09341233, 1.85061, 49.57854, 336.04084, 355.45332, GalaxyGen.J2000); * Mars.Radius = Distance.ToAU(3396.2); * Mars.BaseTemperature = (float)CalculateBaseTemperatureOfBody(sun, Mars.Orbit.SemiMajorAxis);// 210.1f + (float)Constants.Units.KELVIN_TO_DEGREES_C; * Mars.Tectonics = SystemBody.TectonicActivity.Dead; * Mars.SurfaceGravity = 3.71f; * Mars.Atmosphere = new Atmosphere(Mars); * Mars.Atmosphere.Albedo = 0.250f; * Mars.Atmosphere.SurfaceTemperature = Mars.BaseTemperature; * AddGasToAtmoSafely(Mars.Atmosphere, AtmosphericGas.AtmosphericGases.SelectAt(12), 0.95f * 0.01f); // C02% * Mars Atms * AddGasToAtmoSafely(Mars.Atmosphere, AtmosphericGas.AtmosphericGases.SelectAt(6), 0.027f * 0.01f); // N% * Mars Atms * AddGasToAtmoSafely(Mars.Atmosphere, AtmosphericGas.AtmosphericGases.SelectAt(9), 0.007f * 0.01f); // O% * Mars Atms * AddGasToAtmoSafely(Mars.Atmosphere, AtmosphericGas.AtmosphericGases.SelectAt(11), 0.016f * 0.01f); // Ar% * Mars Atms * Mars.Atmosphere.UpdateState(); * Mars.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Mars.Position.System = Sol; * Mars.Position.X = x; * Mars.Position.Y = y; * sun.Planets.Add(Mars); * * SystemBody Jupiter = new SystemBody(sun, SystemBody.PlanetType.GasGiant); * Jupiter.Name = "Jupiter"; * Jupiter.Orbit = Orbit.FromMajorPlanetFormat(1898.3E24, sun.Orbit.Mass, 5.20336301, 0.04839266, 1.30530, 100.55615, 14.75385, 34.40438, GalaxyGen.J2000); * Jupiter.Radius = Distance.ToAU(71492); * Jupiter.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Jupiter.Position.System = Sol; * Jupiter.Position.X = x; * Jupiter.Position.Y = y; * sun.Planets.Add(Jupiter); * * SystemBody Saturn = new SystemBody(sun, SystemBody.PlanetType.GasGiant); * Saturn.Name = "Saturn"; * Saturn.Orbit = Orbit.FromMajorPlanetFormat(568.36E24, sun.Orbit.Mass, 9.53707032, 0.05415060, 2.48446, 113.71504, 92.43194, 49.94432, GalaxyGen.J2000); * Saturn.Radius = Distance.ToAU(60268); * Saturn.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Saturn.Position.System = Sol; * Saturn.Position.X = x; * Saturn.Position.Y = y; * sun.Planets.Add(Saturn); * * SystemBody Uranus = new SystemBody(sun, SystemBody.PlanetType.IceGiant); * Uranus.Name = "Uranus"; * Uranus.Orbit = Orbit.FromMajorPlanetFormat(86.816E24, sun.Orbit.Mass, 19.19126393, 0.04716771, 0.76986, 74.22988, 170.96424, 313.23218, GalaxyGen.J2000); * Uranus.Radius = Distance.ToAU(25559); * Uranus.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Uranus.Position.System = Sol; * Uranus.Position.X = x; * Uranus.Position.Y = y; * sun.Planets.Add(Uranus); * * SystemBody Neptune = new SystemBody(sun, SystemBody.PlanetType.IceGiant); * Neptune.Name = "Neptune"; * Neptune.Orbit = Orbit.FromMajorPlanetFormat(102E24, sun.Orbit.Mass, Distance.ToAU(4495.1E6), 0.011, 1.8, 131.72169, 44.97135, 304.88003, GalaxyGen.J2000); * Neptune.Radius = Distance.ToAU(24764); * Neptune.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Neptune.Position.System = Sol; * Neptune.Position.X = x; * Neptune.Position.Y = y; * sun.Planets.Add(Neptune); * * SystemBody Pluto = new SystemBody(sun, SystemBody.PlanetType.DwarfPlanet); * Pluto.Name = "Pluto"; * Pluto.Orbit = Orbit.FromMajorPlanetFormat(0.0131E24, sun.Orbit.Mass, Distance.ToAU(5906.38E6), 0.24880766, 17.14175, 110.30347, 224.06676, 238.92881, GalaxyGen.J2000); * Pluto.Radius = Distance.ToAU(1195); * Pluto.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); * Pluto.Position.System = Sol; * Pluto.Position.X = x; * Pluto.Position.Y = y; * sun.Planets.Add(Pluto); * * GenerateJumpPoints(Sol); * * // Clean up cached RNG: * m_RNG = null; * GameState.Instance.StarSystems.Add(Sol); * GameState.Instance.StarSystemCurrentIndex++; */ JPSurveyFactory.GenerateJPSurveyPoints(sol); game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid); return(sol); }
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); }