Jump to content

Help with modifying atmospheres


Recommended Posts

Hi, I'm learning C# and I created script that outputs .cfg to modify atmosphere on any body (I don't take any credit for the idea, 'cause it's not my idea), I believe that the app that creates  the .cfg files is working correctly, but I can't seem to modify or add atmospheres, all dependencies installed (Kopernicus, Modular Flight Integrator, Module Manager). Please, tell me if I made a mistake anywhere.

Spoiler

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KSP_Mod1_Real
{
    
    class Program
    {
        static void Line()
        {
            Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
        }
        static void writer(string body2, string height2) //This creates config file
        {
            if (!Directory.Exists(@"C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\GameData\MatusGoc\"))
            {
                Directory.CreateDirectory(@"C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\GameData\MatusGoc\");
            }
            string ksp = @"C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\GameData\MatusGoc\";
            var name = Path.Combine(ksp, body2 + ".cfg");
            FileStream config = File.Open(name, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            var writeConfig = new StreamWriter(config);
            //var readConfig = new StreamReader(config);
            writeConfig.AutoFlush = true;
            writeConfig.WriteLine("@Kopernicus:AFTER[KOPERNICUS] ");
            writeConfig.WriteLine("{");
            writeConfig.WriteLine("    @Body[{0}]", body2);
            writeConfig.WriteLine("    {");
            writeConfig.WriteLine("        %Atmosphere");
            writeConfig.WriteLine("        {");
            writeConfig.WriteLine("            %enabled = true");
            writeConfig.WriteLine("            %ambientColor = 0.306,0.187,0.235,1  ");
            writeConfig.WriteLine("            %lightColor = 0.509,0.588,0.643,");
            writeConfig.WriteLine("            %AtmosphereFromGround");
            writeConfig.WriteLine("            {");
            writeConfig.WriteLine("                %outerRadiusMult = {0}", height2);
            writeConfig.WriteLine("                %innerRadiusMult = {0}", height2);
            writeConfig.WriteLine("            }");
            writeConfig.WriteLine("            %altitude = {0}", (Convert.ToInt32(height2) * 70000));
            writeConfig.WriteLine("            %pressureCurve");
            writeConfig.WriteLine("            {");
            writeConfig.WriteLine("                %key = 0 {0} -1.01464047619048E-02 -1.01464047619048E-02", (Convert.ToInt32(height2) * 101));
            writeConfig.WriteLine("                %key = {0} {1} -8.25777380952381E-03 -8.25777380952381E-03", (Convert.ToInt32(height2) * 70000 * 0.05), (Convert.ToInt32(height2) * 50.5));
            writeConfig.WriteLine("                %key = {0} {1} -5.05395238095238E-03 -5.05395238095238E-03", (Convert.ToInt32(height2) * 70000 * 0.1), (Convert.ToInt32(height2) * 25.25));
            writeConfig.WriteLine("                %key = {0} {1} -2.83080952380952E-03 -2.83080952380952E-03", (Convert.ToInt32(height2) * 70000 * 0.15), (Convert.ToInt32(height2) * 12.625));
            writeConfig.WriteLine("                %key = {0} {1} -1.44432142857143E-03 -1.44432142857143E-03", (Convert.ToInt32(height2) * 70000 * 0.2), (Convert.ToInt32(height2) * 6.3125));
            writeConfig.WriteLine("                %key = {0} {1} -7.23142857142857E-04 -7.23142857142857E-04", (Convert.ToInt32(height2) * 70000 * 0.25), (Convert.ToInt32(height2) * 3.1562));
            writeConfig.WriteLine("                %key = {0} {1} -3.61869047619048E-04 -3.61869047619048E-04", (Convert.ToInt32(height2) * 70000 * 0.3), (Convert.ToInt32(height2) * 1.5781));
            writeConfig.WriteLine("                %key = {0} {1} -1.8247619047619E-04 -1.8247619047619E-04", (Convert.ToInt32(height2) * 70000 * 0.35), (Convert.ToInt32(height2) * 0.7890));
            writeConfig.WriteLine("                %key = {0} {1} -9.21904761904762E-05 -9.21904761904762E-05", (Convert.ToInt32(height2) * 70000 * 0.4), (Convert.ToInt32(height2) * 0.3945));
            writeConfig.WriteLine("                %key = {0} {1} -4.75238095238095E-05 -4.75238095238095E-05", (Convert.ToInt32(height2) * 70000 * 0.45), (Convert.ToInt32(height2) * 0.1972));
            writeConfig.WriteLine("                %key = {0} {1} -2.51547619047619E-05 -2.51547619047619E-05", (Convert.ToInt32(height2) * 70000 * 0.5), (Convert.ToInt32(height2) * 0.0986));
            writeConfig.WriteLine("                %key = {0} {1} -1.38214285714286E-05 -1.38214285714286E-05", (Convert.ToInt32(height2) * 70000 * 0.55), (Convert.ToInt32(height2) * 0.0493));
            writeConfig.WriteLine("                %key = {0} {1} -7.85714285714286E-06 -7.85714285714286E-06", (Convert.ToInt32(height2) * 70000 * 0.6), (Convert.ToInt32(height2) * 0.0246));
            writeConfig.WriteLine("                %key = {0} {1} -4.75E-06 -4.75E-06", (Convert.ToInt32(height2) * 70000 * 0.65), (Convert.ToInt32(height2) * 0.0123));
            writeConfig.WriteLine("                %key = {0} {1} -2.77380952380952E-06 -2.77380952380952E-06", (Convert.ToInt32(height2) * 70000 * 0.7), (Convert.ToInt32(height2) * 0.0061));
            writeConfig.WriteLine("                %key = {0} {1} -1.58333333333333E-06 -1.58333333333333E-06", (Convert.ToInt32(height2) * 70000 * 0.75), (Convert.ToInt32(height2) * 0.0030));
            writeConfig.WriteLine("                %key = {0} {1} -8.69047619047619E-07 -8.69047619047619E-07", (Convert.ToInt32(height2) * 70000 * 0.8), (Convert.ToInt32(height2) * 0.0015));
            writeConfig.WriteLine("                %key = {0} {1} -4.64285714285714E-07 -4.64285714285714E-07", (Convert.ToInt32(height2) * 70000 * 0.85), (Convert.ToInt32(height2) * 0.0008));
            writeConfig.WriteLine("                %key = {0} {1} -2.61904761904762E-07 -2.61904761904762E-07", (Convert.ToInt32(height2) * 70000 * 0.9), (Convert.ToInt32(height2) * 0.0004));
            writeConfig.WriteLine("                %key = {0} {1} -1.54761904761905E-07 -1.54761904761905E-07", (Convert.ToInt32(height2) * 70000 * 0.95), (Convert.ToInt32(height2) * 0.0002));
            writeConfig.WriteLine("                %key = {0} 0 -9.52380952380952E-08 -9.52380952380952E-08", (Convert.ToInt32(height2) * 70000));
            writeConfig.WriteLine("            }");
            writeConfig.WriteLine("            %temperatureCurve");
            writeConfig.WriteLine("            {");
            writeConfig.WriteLine("                %key = 0 {0} -0.007638889286 -0.007638889286", (Convert.ToInt32(height2) * 303));
            writeConfig.WriteLine("                %key = {0} {1} -0.001081974762 -0.001078639524", (Convert.ToInt32(height2) * 70000 * 0.12), (Convert.ToInt32(height2) * 303));
            writeConfig.WriteLine("                %key = {0} {1} 0.001078639524 0.001078639524", (Convert.ToInt32(height2) * 70000 * 0.21), (Convert.ToInt32(height2) * 250));
            writeConfig.WriteLine("                %key = {0} {1} 0.0005895409524 0.0005895409524", (Convert.ToInt32(height2) * 70000 * 0.31), (Convert.ToInt32(height2) * 200));
            writeConfig.WriteLine("                %key = {0} {1} -0.000813009881 -0.000813009881", (Convert.ToInt32(height2) * 70000 * 0.56), (Convert.ToInt32(height2) * 150));
            writeConfig.WriteLine("                %key = {0} {1} -0.001081974762 -0.001081974762", (Convert.ToInt32(height2) * 70000 * 0.8), (Convert.ToInt32(height2) * 100));
            writeConfig.WriteLine("                %key = {0} {1} 0.0005640172619 0.0005640172619", (Convert.ToInt32(height2) * 70000 * 0.9), (Convert.ToInt32(height2) * 50));
            writeConfig.WriteLine("                %key = {0} 0 0.0008269096429 0.0008269096429", (Convert.ToInt32(height2) * 70000));
            writeConfig.WriteLine("            }");
            //writeConfig.WriteLine("            %atmosphereMolarMass = {0}", (Convert.ToInt32(height2) * 0.02896440029));
            writeConfig.WriteLine("        }");
            writeConfig.WriteLine("    }");
            writeConfig.WriteLine("}");
            config.Close();
        }
        static void Main()
        {
            Directory.CreateDirectory(@"C:\Program Files\Steam(x86)\SteamApps\Common\Kerbal Space Program\GameData\MatusGoc\");
            string body1;
            string height1;
            Console.WriteLine("This only works if your KSP is in Steam folder (.../common/Kerbal Space Program)");
            while (true)
            {
                Console.WriteLine("Choose system to modify.");
                Console.WriteLine("1. Moho");
                Console.WriteLine("2. Eve");
                Console.WriteLine("3. Kerbin");
                Console.WriteLine("4. Duna");
                Console.WriteLine("5. Dress");
                Console.WriteLine("6. Jool");
                Console.WriteLine("7. Eeloo");
                Console.WriteLine("'Q' to quit");
                Console.Write("Enter option: ");
                string input = Console.ReadLine();
                Line();
                if (input == "Q")
                {
                    break;
                }
                else if (input == "1")
                {
                    Console.WriteLine("Choose body to modify.");
                    Console.WriteLine("1. Moho");
                    Console.WriteLine("'Q' to quit");
                    Console.Write("Enter option: ");
                    input = Console.ReadLine();
                    Line();
                    if (input == "1")
                    {
                        body1 = "Moho";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "Q")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Unknown command");
                        Line();
                    }
                }
                else if (input == "2")
                {
                    Console.WriteLine("Choose body to modify.");
                    Console.WriteLine("1. Eve");
                    Console.WriteLine("2. Gilly");
                    Console.WriteLine("'Q' to quit");
                    Console.Write("Enter option: ");
                    input = Console.ReadLine();
                    Line();
                    if (input == "1")
                    {
                        body1 = "Eve";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "2")
                    {
                        body1 = "Gilyl";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "Q")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Unknown command");
                        Line();
                    }
                }
                else if (input == "3")
                {
                    Console.WriteLine("Choose body to modify.");
                    Console.WriteLine("1. Kerbin");
                    Console.WriteLine("2. Mun");
                    Console.WriteLine("3. Minmus");
                    Console.WriteLine("'Q' to quit");
                    Console.Write("Enter option: ");
                    input = Console.ReadLine();
                    Line();
                    if (input == "1")
                    {
                        body1 = "Kerbin";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "2")
                    {
                        body1 = "Mun";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "3")
                    {
                        body1 = "Minmus";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "Q")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Unknown command");
                        Line();
                    }
                }
                else if (input == "4")
                {
                    Console.WriteLine("Choose body to modify.");
                    Console.WriteLine("1. Duna");
                    Console.WriteLine("2. Ike");
                    Console.WriteLine("'Q' to quit");
                    Console.Write("Enter option: ");
                    input = Console.ReadLine();
                    Line();
                    if (input == "1")
                    {
                        body1 = "Duna";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else  if (input == "2")
                    {
                        body1 = "Ike";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "Q")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Unknown command");
                        Line();
                    }
                }
                else if (input == "5")
                {
                    Console.WriteLine("Choose body to modify.");
                    Console.WriteLine("1. Dress");
                    Console.WriteLine("'Q' to quit");
                    Console.Write("Enter option: ");
                    input = Console.ReadLine();
                    Line();
                    if (input == "1")
                    {
                        body1 = "Dress";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "Q")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Unknown command");
                        Line();
                    }
                }
                else if (input == "6")
                {
                    Console.WriteLine("Choose body to modify.");
                    Console.WriteLine("1. Jool");
                    Console.WriteLine("2. Laythe");
                    Console.WriteLine("3. Vall");
                    Console.WriteLine("4. Tylo");
                    Console.WriteLine("5. Bop");
                    Console.WriteLine("6. Pol");
                    Console.WriteLine("'Q' to quit");
                    Console.Write("Enter option: ");
                    input = Console.ReadLine();
                    Line();
                    if (input == "1")
                    {
                        body1 = "Jool";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "2")
                    {
                        body1 = "Laythe";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "3")
                    {
                        body1 = "Vall";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "4")
                    {
                        body1 = "Tylo";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "5")
                    {
                        body1 = "Bop";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "6")
                    {
                        body1 = "Pol";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "Q")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Unknown command");
                        Line();
                    }
                }
                else if (input == "7")
                {
                    Console.WriteLine("Choose body to modify.");
                    Console.WriteLine("1. Eeloo");
                    Console.WriteLine("'Q' to quit");
                    Console.Write("Enter option: ");
                    input = Console.ReadLine();
                    Line();
                    if (input == "1")
                    {
                        body1 = "Eeloo";
                        Console.Write("Specify height of the atmosphere (this value is relative to stock Kerbin and all values are calculated from it)");
                        height1 = Console.ReadLine();
                        Line();
                        writer(body1, height1);
                    }
                    else if (input == "Q")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Unknown command");
                        Line();
                    }
                }
                else
                {
                    Console.WriteLine("Unknown command");
                    Line();
                }
            }
        }
    }
}

 

The app, but compiled

Edited by MatusGoc
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...