// Parser Post Apply Event void IParserEventSubscriber.PostApply(ConfigNode node) { // Create a barycenter if (Barycenter.Value) { CreateBarycenter(); } // Add an OnDemand CBMap trigger CelestialBody.gameObject.AddComponent <CBMapTrigger>(); // Loads external parser targets Parser.LoadParserTargetsExternal(node, "Kopernicus", "Kopernicus"); // Post gen celestial body Utility.DumpObjectFields(GeneratedBody.celestialBody, " Celestial Body "); // Events Events.OnBodyPostApply.Fire(this, node); // We need to generate new scaled space meshes if // a) we are using a template and we've change the radius of body // b) we aren't using a template // c) debug mode is active if (ScaledVersion.DeferMesh || (Template == null || !(Math.Abs(Template.Radius - GeneratedBody.celestialBody.Radius) > 1.0)) && Template != null && !Debug.Update) { return; } ScaledVersion.RebuildScaledSpace(); Events.OnBodyGenerateScaledSpace.Fire(this, node); }
// Sun // Parser Apply Event public void Apply(ConfigNode node) { // If we have a template, generatedBody *is* the template body if (template != null) { generatedBody = template.body; // Patch the game object names in the template generatedBody.name = name; generatedBody.celestialBody.bodyName = name; generatedBody.scaledVersion.name = name; if (generatedBody.pqsVersion != null) { foreach (PQS p in generatedBody.pqsVersion.GetComponentsInChildren(typeof(PQS), true)) { p.name = p.name.Replace(template.body.celestialBody.bodyName, name); } } // If this body has an orbit, create editor/loader if (generatedBody.orbitDriver != null) { orbit = new OrbitLoader(generatedBody); } // If this body has a PQS, create editor/loader if (generatedBody.pqsVersion != null) { pqs = new PQSLoader(generatedBody.pqsVersion); } // Create the scaled version editor/loader scaledVersion = new ScaledVersion(generatedBody.scaledVersion, generatedBody.celestialBody, template.type); } // Otherwise we have to generate all the things for this body else { // Create the PSystemBody object GameObject generatedBodyGameObject = new GameObject(name); generatedBodyGameObject.transform.parent = Utility.Deactivator; generatedBody = generatedBodyGameObject.AddComponent <PSystemBody> (); generatedBody.flightGlobalsIndex = 0; // Create the celestial body GameObject generatedBodyProperties = new GameObject(name); generatedBodyProperties.transform.parent = generatedBodyGameObject.transform; generatedBody.celestialBody = generatedBodyProperties.AddComponent <CelestialBody> (); generatedBody.resources = generatedBodyProperties.AddComponent <PResource> (); // Sensible defaults generatedBody.celestialBody.bodyName = name; generatedBody.celestialBody.atmosphere = false; generatedBody.celestialBody.ocean = false; // Create the scaled version generatedBody.scaledVersion = new GameObject(name); generatedBody.scaledVersion.layer = Constants.GameLayers.ScaledSpace; generatedBody.scaledVersion.transform.parent = Utility.Deactivator; // Create the scaled version editor/loader scaledVersion = new ScaledVersion(generatedBody.scaledVersion, generatedBody.celestialBody, BodyType.Atmospheric); } // Create property editor/loader objects properties = new Properties(generatedBody.celestialBody); // Atmospheric settings atmosphere = new Atmosphere(generatedBody.celestialBody, generatedBody.scaledVersion); }
// Parser Apply Event public void Apply (ConfigNode node) { // If we have a template, generatedBody *is* the template body if (template != null) { generatedBody = template.body; // Patch the game object names in the template generatedBody.name = name; generatedBody.celestialBody.bodyName = name; generatedBody.celestialBody.transform.name = name; generatedBody.celestialBody.bodyTransform.name = name; generatedBody.scaledVersion.name = name; if (generatedBody.pqsVersion != null) { generatedBody.pqsVersion.name = name; generatedBody.pqsVersion.gameObject.name = name; generatedBody.pqsVersion.transform.name = name; foreach (PQS p in generatedBody.pqsVersion.GetComponentsInChildren(typeof (PQS), true)) p.name = p.name.Replace (template.body.celestialBody.bodyName, name); } // If we've changed the name, reset use_The_InName if (generatedBody.name != template.body.name) { generatedBody.celestialBody.use_The_InName = false; } // If this body has an orbit, create editor/loader if (generatedBody.orbitDriver != null) { orbit = new OrbitLoader(generatedBody); } // If this body has a PQS, create editor/loader if (generatedBody.pqsVersion != null) { pqs = new PQSLoader(generatedBody.pqsVersion); // If this body has an ocean PQS, create editor/loader if (generatedBody.celestialBody.ocean == true) { foreach (PQS PQSocean in generatedBody.pqsVersion.GetComponentsInChildren<PQS>(true)) { if (PQSocean.name == name + "Ocean") { ocean = new OceanPQS(PQSocean); break; } } } } // Create the scaled version editor/loader scaledVersion = new ScaledVersion(generatedBody.scaledVersion, generatedBody.celestialBody, template.type); } // Otherwise we have to generate all the things for this body else { // Create the PSystemBody object GameObject generatedBodyGameObject = new GameObject (name); generatedBodyGameObject.transform.parent = Utility.Deactivator; generatedBody = generatedBodyGameObject.AddComponent<PSystemBody> (); generatedBody.flightGlobalsIndex = 0; // Create the celestial body GameObject generatedBodyProperties = new GameObject (name); generatedBodyProperties.transform.parent = generatedBodyGameObject.transform; generatedBody.celestialBody = generatedBodyProperties.AddComponent<CelestialBody> (); generatedBody.resources = generatedBodyProperties.AddComponent<PResource> (); generatedBody.celestialBody.progressTree = null; // Sensible defaults generatedBody.celestialBody.bodyName = name; generatedBody.celestialBody.atmosphere = false; generatedBody.celestialBody.ocean = false; // Create the scaled version generatedBody.scaledVersion = new GameObject(name); generatedBody.scaledVersion.layer = Constants.GameLayers.ScaledSpace; generatedBody.scaledVersion.transform.parent = Utility.Deactivator; // Create the scaled version editor/loader scaledVersion = new ScaledVersion(generatedBody.scaledVersion, generatedBody.celestialBody, BodyType.Atmospheric); } // Create property editor/loader objects properties = new Properties (generatedBody.celestialBody); // Atmospheric settings atmosphere = new Atmosphere(generatedBody.celestialBody, generatedBody.scaledVersion); // Particles particle = new ParticleLoader(generatedBody.scaledVersion.gameObject); }
/// <summary> /// Generates a planet /// </summary> public static void Planet(int starCount, int planetID, string gameDataPath, Random random) { Dictionary <string, Dictionary <string, string> > configFile = new Dictionary <string, Dictionary <string, string> >(); Dictionary <string, string> processorSettings = new Dictionary <string, string>(); Dictionary <string, Dictionary <string, string> > pqsMods = new Dictionary <string, Dictionary <string, string> >(); //====PQS things===========================// double mainColorR = random.NextDouble(); double mainColorG = random.NextDouble(); double mainColorB = random.NextDouble(); double secondaryColorR = random.NextDouble(); double secondaryColorG = random.NextDouble(); double secondaryColorB = random.NextDouble(); //=========================================// //====Keys and values for the body node====// Body body = new Body(); Dictionary <string, string> bodyNode = new Dictionary <string, string>(); body.Name = "Star " + starCount + " Planet N." + planetID; body.CacheFile = @"Infinity/StarSystems/Cache/" + "Star " + starCount + " Planet N." + planetID + ".bin"; bodyNode.Add("name", body.Name); bodyNode.Add("cacheFile", body.CacheFile); configFile.Add("Body", bodyNode); //=========================================// //====Keys and values for properties node==// Dictionary <string, string> propertiesNode = new Dictionary <string, string>(); double minRadius = 25000; double maxRadius = 1500000; double radius = random.NextDouble() * (minRadius - maxRadius) + maxRadius; bool isHomeWorld = false; propertiesNode.Add("radius", radius.ToString()); propertiesNode.Add("density", 5.515e+3.ToString()); //Yes, fact is the real name of this is volumic mass and not density.. ikr | I take Earth's one for testing issues. propertiesNode.Add("isHomeWorld", isHomeWorld.ToString()); configFile.Add("Properties", propertiesNode); //=========================================// //==Keys and values for the template node==// Template template = new Template(); Dictionary <string, string> templateNode = new Dictionary <string, string>(); template.Name = Datas.Enums.Template.Tylo; template.removeAllPQSMods = true; template.removeOcean = true; templateNode.Add("name", template.Name.ToString()); templateNode.Add("removeAllPQSMods", template.removeAllPQSMods.ToString()); templateNode.Add("removeOcean", template.removeOcean.ToString()); configFile.Add("Template", templateNode); //=========================================// //====Keys and values for the orbit node===// Dictionary <string, double> orbitD = Orbit.Planet(random); string referenceBody = "Star " + starCount.ToString(); string orbitColor = mainColorR + ", " + mainColorG + ", " + mainColorB + ", 1"; Dictionary <string, string> orbitNode = new Dictionary <string, string>(); foreach (KeyValuePair <string, double> param in orbitD) { orbitNode.Add(param.Key, param.Value.ToString()); } orbitNode.Add("referenceBody", referenceBody); orbitNode.Add("color", orbitColor); configFile.Add("Orbit", orbitNode); //=========================================// //==Keys and value for ScaledVersion nodes=// ScaledVersion scaledVersion = new ScaledVersion(); Dictionary <string, string> scaledVersionNode = new Dictionary <string, string>(); Dictionary <string, string> scaledVersionMaterialNode = new Dictionary <string, string>(); scaledVersion.Type = Datas.Enums.Body.ScaledVersionTypes.Vacuum; scaledVersion.Texture = @"Infinity\StarSystems\Planets\Star " + starCount + " Planet N." + planetID + "_Color.png"; scaledVersion.Normals = @"Infinity\StarSystems\Planets\Star " + starCount + " Planet N." + planetID + "_Normal.png"; scaledVersionNode.Add("type", scaledVersion.Type.ToString()); scaledVersionMaterialNode.Add("texture", scaledVersion.Texture.ToString()); scaledVersionMaterialNode.Add("normals", scaledVersion.Normals.ToString()); configFile.Add("ScaledVersion", scaledVersionNode); configFile.Add("SVMaterial", scaledVersionMaterialNode); //=========================================// //====PQS Nodes keys and values============// string modName = ""; Dictionary <string, string> VertexSimplexHeightAbsolute = new Dictionary <string, string>(); modName = "VertexSimplexHeightAbsolute"; VertexSimplexHeightAbsolute.Add("deformity", "8000"); VertexSimplexHeightAbsolute.Add("frequency", "10"); VertexSimplexHeightAbsolute.Add("octaves", "3"); VertexSimplexHeightAbsolute.Add("persistence", "0.5"); VertexSimplexHeightAbsolute.Add("seed", "645546"); VertexSimplexHeightAbsolute.Add("order", "10"); VertexSimplexHeightAbsolute.Add("enabled", "True"); pqsMods.Add(modName, VertexSimplexHeightAbsolute); Dictionary <string, string> VertexSimplexNoiseColor = new Dictionary <string, string>(); modName = "VertexSimplexNoiseColor"; string colorStart = orbitColor; string colorEnd = secondaryColorR + ", " + secondaryColorG + ", " + secondaryColorB + ", 1"; VertexSimplexNoiseColor.Add("blend", "1"); VertexSimplexNoiseColor.Add("colorStart", colorStart); VertexSimplexNoiseColor.Add("colorEnd", colorEnd); VertexSimplexNoiseColor.Add("frequency", "1"); VertexSimplexNoiseColor.Add("octaves", "8"); VertexSimplexNoiseColor.Add("persistence", "0.5"); VertexSimplexNoiseColor.Add("seed", random.Next(int.MinValue, int.MaxValue).ToString()); VertexSimplexNoiseColor.Add("order", "100"); VertexSimplexNoiseColor.Add("enabled", "True"); pqsMods.Add(modName, VertexSimplexNoiseColor); //=========================================// //====Processor settings===================// double res = 1024; double lowRes = 512; double lowResRad = 135000; double midRes = 1024; double midResRad = 300000; double highRes = 2048; double highResRad = 750000; double ultraRes = 4096; double ultraResRad = maxRadius; if (radius <= lowResRad) { res = lowRes; } if (radius > lowResRad && radius <= midResRad) { res = midRes; } if (radius > midResRad && radius <= highResRad) { res = highRes; } if (radius > highResRad && radius <= ultraRes) { res = ultraRes; } processorSettings.Add("__resolution", res.ToString()); processorSettings.Add("__radius", radius.ToString()); processorSettings.Add("__hasOcean", "false"); processorSettings.Add("__oceanHeight", "0"); processorSettings.Add("__oceanColor", "0,0,0,0"); processorSettings.Add("__normalStrength", "7"); processorSettings.Add("mapMaxHeight", "9000"); //=========================================// //Makes and saves config file ConfigNode conf = PlanetConfig(configFile, pqsMods); conf.Save(gameDataPath + @"StarSystems/Planets/Star " + starCount + " Planet N." + planetID + ".cfg"); //Makes and saves maps string[] args = { "" }; PlanetMaps.Save(args, gameDataPath, body.Name, processorSettings, pqsMods); }