예제 #1
0
        public void Start()
        {
            ConfigNode[] cfgs = GameDatabase.Instance.GetConfigNodes("RESEARCHBODIES");
            foreach (ConfigNode node in cfgs)
            {
                if (node.GetValue("loadAs") == "locale")
                {
                    Locale l = new Locale(node);
                    locales.Add(l);
                    RSTLogWriter.Log("Added locale \"{0}\"", l.LocaleId);
                }
            }

            if (locales.Count == 0)
            {
                RSTLogWriter.Log("No locale added !");
            }
            else
            {
                RSTLogWriter.Log("Added {0}  locales", locales.Count);
            }
            RSTLogWriter.Flush();
            Locales.setLocale("");
            Available = true;
        }
예제 #2
0
 /// <summary>
 /// Call this to signal that you have found a celestial body.
 /// It will set the celestial body to discovered.
 /// </summary>
 /// <param name="scienceReward">The scienceReward additional amount that is added to the base scienceReward for finding a body</param>
 /// <param name="bodyFound">The Celestial Body found</param>
 /// <param name="withParent">Will return true if the Parent Body has also been found</param>
 /// <param name="parentBody">The parent body that was discovered as well if withParent is true</param>
 /// <returns></returns>
 public static bool FoundBody(int scienceReward, CelestialBody bodyFound, out bool withParent, out CelestialBody parentBody)
 {
     withParent = false;
     parentBody = null;
     if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)  //If not sandbox add the Science Points reward!
     {
         //var sciencePtsReward = scienceReward + Database.Instance.RB_SettingsParms.ScienceReward;
         var sciencePtsReward = scienceReward + Database.instance.RB_SettingsParms.ScienceReward;
         ResearchAndDevelopment.Instance.AddScience(sciencePtsReward, TransactionReasons.None);
         ScreenMessages.PostScreenMessage("Added " + sciencePtsReward + " science points !", 5f);
     }
     //Check if the referencebody is also not known. If so, we discover both the body and it's referencebody (parent).
     if (bodyFound.referenceBody != null && bodyFound != bodyFound.referenceBody && bodyFound.referenceBody.DiscoveryInfo.Level == DiscoveryLevels.Presence)
     {
         CelestialBody cbKey = Database.instance.ContainsBodiesKey(bodyFound.referenceBody.bodyName);
         if (cbKey != null)
         {
             Database.instance.CelestialBodies[cbKey].isResearched = true;
         }
         cbKey = Database.instance.ContainsBodiesKey(bodyFound.bodyName);
         if (cbKey != null)
         {
             Database.instance.CelestialBodies[cbKey].isResearched = true;
             var tempEntry = new KeyValuePair <CelestialBody, CelestialBodyInfo>(bodyFound, Database.instance.CelestialBodies[bodyFound]);
             setCBContractWeight(tempEntry, false);
         }
         withParent = true;
         parentBody = bodyFound.referenceBody;
         //check for Barycenter as well.
         if (bodyFound.referenceBody.referenceBody != null)
         {
             if ((bodyFound.referenceBody.referenceBody.DiscoveryInfo.Level == DiscoveryLevels.Appearance ||
                  bodyFound.referenceBody.referenceBody.DiscoveryInfo.Level == DiscoveryLevels.Presence) &&
                 Database.instance.CelestialBodies.ContainsKey(bodyFound.referenceBody.referenceBody))
             {
                 Database.instance.CelestialBodies[bodyFound.referenceBody.referenceBody].isResearched = true;
                 var tempEntry = new KeyValuePair <CelestialBody, CelestialBodyInfo>(bodyFound.referenceBody.referenceBody, Database.instance.CelestialBodies[bodyFound.referenceBody.referenceBody]);
                 setCBContractWeight(tempEntry, false);
             }
         }
         RSTLogWriter.Log("Found body {0} orbiting around {1} !", bodyFound.GetName(), bodyFound.referenceBody.GetName());
     }
     else //No parent or parent is already discovered. So we just found this body.
     {
         CelestialBody cbKey = Database.instance.ContainsBodiesKey(bodyFound.bodyName);
         if (cbKey != null)
         {
             Database.instance.CelestialBodies[cbKey].isResearched = true;
             var tempEntry = new KeyValuePair <CelestialBody, CelestialBodyInfo>(cbKey, Database.instance.CelestialBodies[cbKey]);
             setCBContractWeight(tempEntry, false);
         }
         withParent = false;
         RSTLogWriter.Log("Found body {0} !", bodyFound.GetName());
     }
     RSTLogWriter.Flush();
     return(true);
 }
예제 #3
0
 private void TryWithDrawContract(Contract c)
 {
     try
     {
         //RSTLogWriter.Log("WithDrew contract \"{0}\"" , c.Title);
         c.Withdraw(); //Changed to Withdraw - this will not penalize reputation.
     }
     catch (Exception e)
     {
         RSTLogWriter.Log("Unable to Withraw contract ! {0}", e);
         RSTLogWriter.Flush();
     }
 }
예제 #4
0
 public override void OnLoad(ConfigNode gameNode)
 {
     Database.instance.ResetBodiesforLoad();
     base.OnLoad(gameNode);
     RBgameSettings.Load(gameNode);
     if (Database.instance.RB_SettingsParms != null)
     {
         RSTLogWriter.debuggingOn = Database.instance.RB_SettingsParms.DebugLogging;
     }
     APIReady = true;
     if (RSTLogWriter.debuggingOn)
     {
         RSTLogWriter.Log_Debug("Scenario: " + HighLogic.LoadedScene + " OnLoad: \n ");
     }
     //    RSTLogWriter.Log_Debug("Scenario: " + HighLogic.LoadedScene + " OnLoad: \n " + gameNode + "\n" + globalNode);
     else
     {
         RSTLogWriter.Log("ResearchBodies Scenario Onload Completed.");
     }
     RSTLogWriter.Flush();
 }
예제 #5
0
 public override void OnSave(ConfigNode gameNode)
 {
     //APIReady = false;
     base.OnSave(gameNode);
     RBgameSettings.Save(gameNode);
     //foreach (Savable s in children.Where(c => c is Savable))
     //{
     //    s.Save(globalNode);
     //}
     //globalNode.Save(globalConfigFilename);
     if (RSTLogWriter.debuggingOn)
     {
         RSTLogWriter.Log_Debug("Scenario: " + HighLogic.LoadedScene + " OnSave: \n");
     }
     //    RSTLogWriter.Log_Debug("Scenario: " + HighLogic.LoadedScene + " OnSave: \n" + gameNode + "\n" + globalNode);
     else
     {
         RSTLogWriter.Log("ResearchBodies Scenario OnSave completed.");
     }
     RSTLogWriter.Flush();
 }
예제 #6
0
        public void Save(ConfigNode node)
        {
            ConfigNode settingsNode;

            if (node.HasNode(configNodeName))
            {
                settingsNode = node.GetNode(configNodeName);
                settingsNode.ClearData();
            }
            else
            {
                settingsNode = node.AddNode(configNodeName);
            }

            foreach (var entry in Database.instance.CelestialBodies)
            {
                ConfigNode CBNode = entry.Value.Save(settingsNode);
                Utilities.Log_Debug("RBGameSettings Saving Entry = {0}", entry.Key.bodyName);
            }
            RSTLogWriter.Log("RBGameSettings Saving Complete");
            RSTLogWriter.Flush();
        }
        public void Save(ConfigNode node)
        {
            ConfigNode settingsNode;

            if (node.HasNode(configNodeName))
            {
                settingsNode = node.GetNode(configNodeName);
                settingsNode.ClearData();
            }
            else
            {
                settingsNode = node.AddNode(configNodeName);
            }

            node.AddValue("lastTimeCheckedSOIs", lastTimeCheckedSOIs);

            foreach (var entry in Database.instance.CelestialBodies)
            {
                ConfigNode CBNode = entry.Value.Save(settingsNode);
                Utilities.Log_Debug("RBGameSettings Saving Entry = {0}", entry.Key.bodyName);
            }

            if (Database.instance.VesselsInSOI.Count > 0)
            {
                ConfigNode cbSOINode = settingsNode.AddNode("VESSELSINSOI");
                var        dictEnum  = Database.instance.VesselsInSOI.GetEnumerator();
                while (dictEnum.MoveNext())
                {
                    var        entry         = dictEnum.Current;
                    ConfigNode vesselSOINode = entry.Value.Save(cbSOINode);
                    Utilities.Log_Debug("RBGameSettings Saving Vessel in SOI Entry = {0}", entry.Key);
                }

                dictEnum.Dispose();
            }

            RSTLogWriter.Log("RBGameSettings Saving Complete");
            RSTLogWriter.Flush();
        }
예제 #8
0
        public void LoadDatabase()
        {
            RSTLogWriter.Log("LoadDatabase");
            //RB_SettingsParms = HighLogic.CurrentGame.Parameters.CustomParams<ResearchBodies_SettingsParms>();

            isTSTInstalled = Utilities.IsTSTInstalled;
            if (isTSTInstalled)  //If TST assembly is present, initialise TST wrapper.
            {
                if (!TSTWrapper.InitTSTWrapper())
                {
                    isTSTInstalled = false; //If the initialise of wrapper failed set bool to false, we won't be interfacing to TST today.
                }
            }

            Textures.LoadIconAssets();

            //Get a list of CBs
            for (int i = 0; i < FlightGlobals.Bodies.Count; i++)
            {
                BodyList.Add(FlightGlobals.Bodies[i]);
            }
            if (isTSTInstalled && TSTWrapper.APITSTReady) //If TST is installed add the TST Galaxies to the list.
            {
                for (int i = 0; i < TSTWrapper.actualTSTAPI.CBGalaxies.Count; i++)
                {
                    BodyList.Add(TSTWrapper.actualTSTAPI.CBGalaxies[i]);
                }
            }

            //Process Kopernicus Barycenter's.
            foreach (CelestialBody body in BodyList)
            {
                CelestialBodyInfo bodyinfo = new CelestialBodyInfo(body.GetName());
                if (body.Radius < 100 && !body.name.Contains("TSTGalaxies"))  //This body is a barycenter
                {
                    bodyinfo.KOPbarycenter = true;
                }
                else
                {
                    if (body.referenceBody.Radius < 100)                    // This Bodies Reference Body has a Radius < 100m. IE: It's Part of a Barycenter.
                    {
                        bodyinfo.KOPrelbarycenterBody = body.referenceBody; //Yeah so what... well we need it for pass 2 below.
                    }
                }
                CelestialBodies.Add(body, bodyinfo);
            }
            //Now we look back through any CBs that were related to a barycenter body.
            var dictEnum = CelestialBodies.GetEnumerator();

            while (dictEnum.MoveNext())
            {
                var entry = dictEnum.Current;
                if (entry.Value.KOPrelbarycenterBody != null)
                {
                    //So does this body have any orbitingBodies?
                    //If it does we need to somehow find and link any related Orbit Body.
                    foreach (CelestialBody orbitingBody in entry.Key.orbitingBodies)
                    {
                        CelestialBody findOrbitBody = null;
                        for (int i = 0; i < FlightGlobals.Bodies.Count; i++)
                        {
                            if (FlightGlobals.Bodies[i].name.Contains(entry.Key.name) && FlightGlobals.Bodies[i].name.Contains(orbitingBody.name) && FlightGlobals.Bodies[i].name.Contains("Orbit"))
                            {
                                findOrbitBody = FlightGlobals.Bodies[i];
                                break;
                            }
                        }
                        //so if we found the related Orbit body we store it into the CelestialBodies dictionary.
                        if (findOrbitBody != null)
                        {
                            CelestialBodies[orbitingBody].KOPrelbarycenterBody = findOrbitBody;
                        }
                    }
                }
            }

            dictEnum.Dispose();

            //Load the database.cfg file.
            //===========================
            ConfigNode cfg = ConfigNode.Load(PathDatabasePath);

            string[]   sep            = new string[] { " " };
            ConfigNode researchBodies = cfg.GetNode("RESEARCHBODIES");

            if (researchBodies == null)
            {
                RSTLogWriter.Log("Failed to find Database.cfg RESEARCHBODIES node.");
                return;
            }

            Observatorylvl1Range     = float.Parse(researchBodies.GetValue("observatorylvl1range"));
            Observatorylvl2Range     = float.Parse(researchBodies.GetValue("observatorylvl2range"));
            AllowOldResearchinCareer = bool.Parse(researchBodies.GetValue("allowOldResearchinCareer"));
            DiscoveryByFlyby         = int.Parse(researchBodies.GetValue("discoveryByFlyby"));

            //Get Costs
            string[] _startResearchCosts;
            _startResearchCosts = researchBodies.GetValue("StartResearchCosts").Split(sep, StringSplitOptions.RemoveEmptyEntries);
            StartResearchCosts  = new int[] { int.Parse(_startResearchCosts[0]), int.Parse(_startResearchCosts[1]), int.Parse(_startResearchCosts[2]), int.Parse(_startResearchCosts[3]) };

            string[] _progressResearchCosts;
            _progressResearchCosts = researchBodies.GetValue("ProgressResearchCosts").Split(sep, StringSplitOptions.RemoveEmptyEntries);
            ProgressResearchCosts  = new int[] { int.Parse(_progressResearchCosts[0]), int.Parse(_progressResearchCosts[1]), int.Parse(_progressResearchCosts[2]), int.Parse(_progressResearchCosts[3]) };

            string[] _scienceRewards;
            _scienceRewards = researchBodies.GetValue("ScienceRewards").Split(sep, StringSplitOptions.RemoveEmptyEntries);
            ScienceRewards  = new int[] { int.Parse(_scienceRewards[0]), int.Parse(_scienceRewards[1]), int.Parse(_scienceRewards[2]), int.Parse(_scienceRewards[3]) };

            RSTLogWriter.Log("Loading Priority database");
            foreach (CelestialBody body in BodyList)
            {
                //Load the ondiscovery values - English only, which then get over-written in Locale.cs
                foreach (ConfigNode.Value value in cfg.GetNode("RESEARCHBODIES").GetNode("ONDISCOVERY").values)
                {
                    if (value.name.Contains(body.bodyName))
                    {
                        CelestialBodies[body].discoveryMessage = value.value;
                    }
                }
            }

            //Load the IgnoreData dictionary.
            RSTLogWriter.Log("Loading ignore body list from database");
            foreach (ConfigNode.Value value in researchBodies.GetNode("IGNORELEVELS").values)
            {
                foreach (CelestialBody body in BodyList)
                {
                    if (body.GetName() == value.name)
                    {
                        string[] args;
                        args = value.value.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                        BodyIgnoreData ignoredata = new BodyIgnoreData(bool.Parse(args[0]), bool.Parse(args[1]), bool.Parse(args[2]), bool.Parse(args[3]));
                        CelestialBodies[body].IgnoreData = ignoredata;
                        RSTLogWriter.Log("Body Ignore Data for {0} : {1}", body.GetName(), CelestialBodies[body].IgnoreData);
                    }
                }
            }
            RSTLogWriter.Flush();
            LoadModDatabaseNodes();

            NothingHere.Add("#autoLOC_RBodies_00052");
            NothingHere.Add("#autoLOC_RBodies_00053");
            NothingHere.Add("#autoLOC_RBodies_00054");
            NothingHere.Add("#autoLOC_RBodies_00055");

            RSTLogWriter.Log("Chances to get a body is set to {0}", chances);

            RSTLogWriter.Log("Loaded gamemode-related information : enable mod in sandbox = {0}, allow tracking with Tracking station lvl 1 = {1}", enableInSandbox, allowTSlevel1);

            RSTLogWriter.Flush();
        }
예제 #9
0
        public void Load(ConfigNode node)
        {
            //Does an old save file exist? If not then we load from persistent.SFS config nodes.
            if (!File.Exists("saves/" + HighLogic.SaveFolder + "/researchbodies.cfg"))
            {
                if (node.HasNode(configNodeName)) //Load SFS config nodes
                {
                    ConfigNode RBsettingsNode = node.GetNode(configNodeName);

                    foundOldSettings = RBsettingsNode.TryGetValue("Enabled", ref Enabled);
                    foundOldSettings = foundOldSettings || RBsettingsNode.TryGetValue("Difficulty", ref Difficulty);
                    foundOldSettings = foundOldSettings || RBsettingsNode.TryGetValue("ResearchCost", ref ResearchCost);
                    foundOldSettings = foundOldSettings || RBsettingsNode.TryGetValue("ProgressResearchCost", ref ProgressResearchCost);
                    foundOldSettings = foundOldSettings || RBsettingsNode.TryGetValue("ScienceReward", ref ScienceReward);
                    foundOldSettings = foundOldSettings || RBsettingsNode.TryGetValue("UseAppLauncher", ref UseAppLauncher);
                    foundOldSettings = foundOldSettings || RBsettingsNode.TryGetValue("DebugLogging", ref DebugLogging);
                    foundOldSettings = foundOldSettings || RBsettingsNode.TryGetValue("chances", ref chances);
                    foundOldSettings = foundOldSettings || RBsettingsNode.TryGetValue("enableInSandbox", ref enableInSandbox);
                    foundOldSettings = foundOldSettings || RBsettingsNode.TryGetValue("allowTSlevel1", ref allowTSlevel1);

                    var bodyNodes = RBsettingsNode.GetNodes(CelestialBodyInfo.ConfigNodeName);
                    foreach (ConfigNode bodyNode in bodyNodes)
                    {
                        if (bodyNode.HasValue("body"))
                        {
                            CelestialBodyInfo bodyInfo = CelestialBodyInfo.Load(bodyNode);
                            CelestialBody     CB       = FlightGlobals.Bodies.FirstOrDefault(a => a.bodyName == bodyInfo.body);
                            if (CB != null)
                            {
                                Database.instance.CelestialBodies[CB].isResearched  = bodyInfo.isResearched;
                                Database.instance.CelestialBodies[CB].researchState = bodyInfo.researchState;
                                Database.instance.CelestialBodies[CB].ignore        = bodyInfo.ignore;
                            }
                            else
                            {
                                if (Database.instance.isTSTInstalled)
                                {
                                    CelestialBody GalCB = TSTWrapper.actualTSTAPI.CBGalaxies.FirstOrDefault(a => a.bodyName == bodyInfo.body);
                                    if (GalCB != null)
                                    {
                                        CelestialBody cbKey = Database.instance.ContainsBodiesKey(GalCB.bodyName);
                                        if (cbKey != null)
                                        {
                                            Database.instance.CelestialBodies[cbKey].isResearched  = bodyInfo.isResearched;
                                            Database.instance.CelestialBodies[cbKey].researchState = bodyInfo.researchState;
                                            Database.instance.CelestialBodies[cbKey].ignore        = bodyInfo.ignore;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //if (Difficulty == 0) //If difficult == 0 user somehow hasn't selected new game difficulty. So show the startup UI.
                    //    ResearchBodiesController.instance.showStartUI = true;
                }
                else  //No config node, so Must be NEW Game!
                {
                    foreach (CelestialBody body in Database.instance.BodyList)
                    {
                        CelestialBodyInfo bodyInfo = new CelestialBodyInfo(body.GetName());
                        Database.instance.CelestialBodies[body].isResearched  = bodyInfo.isResearched;
                        Database.instance.CelestialBodies[body].researchState = bodyInfo.researchState;
                        Database.instance.CelestialBodies[body].ignore        = bodyInfo.ignore;
                    }
                    Database.instance.onGameStatePostLoad(node);
                }
            }
            else //OLD Save file found, convert to persistent.sfs confignode and delete file.
            {
                RSTLogWriter.Log("Converting Old Save file to new persistent.sfs config node - Loading old save file");
                foundOldSettings = true;
                ConfigNode mainnode = ConfigNode.Load("saves/" + HighLogic.SaveFolder + "/researchbodies.cfg");
                Difficulty           = int.Parse(mainnode.GetNode("RESEARCHBODIES").GetValue("difficulty") ?? "0");
                ResearchCost         = int.Parse(mainnode.GetNode("RESEARCHBODIES").GetValue("ResearchCost") ?? "10");
                ProgressResearchCost = int.Parse(mainnode.GetNode("RESEARCHBODIES").GetValue("ProgressResearchCost") ?? "5");
                ScienceReward        = int.Parse(mainnode.GetNode("RESEARCHBODIES").GetValue("ResearchCost") ?? "5");

                foreach (CelestialBody cb in Database.instance.BodyList)
                {
                    bool fileContainsCB = false;
                    foreach (ConfigNode oldnode in mainnode.GetNode("RESEARCHBODIES").nodes)
                    {
                        if (cb.GetName().Contains(oldnode.GetValue("body")))
                        {
                            if (bool.Parse(oldnode.GetValue("ignore")))
                            {
                                Database.instance.CelestialBodies[cb].isResearched  = true;
                                Database.instance.CelestialBodies[cb].researchState = 100;
                            }
                            else
                            {
                                Database.instance.CelestialBodies[cb].isResearched = bool.Parse(oldnode.GetValue("isResearched"));
                                if (oldnode.HasValue("researchState"))
                                {
                                    Database.instance.CelestialBodies[cb].researchState = int.Parse(oldnode.GetValue("researchState"));
                                }
                                else
                                {
                                    Database.instance.CelestialBodies[cb].researchState = 0;
                                }
                            }
                            fileContainsCB = true;
                        }
                    }
                    if (!fileContainsCB)
                    {
                        Database.instance.CelestialBodies[cb].isResearched  = false;
                        Database.instance.CelestialBodies[cb].researchState = 0;
                    }
                }

                File.Delete("saves/" + HighLogic.SaveFolder + "/researchbodies.cfg");
                RSTLogWriter.Log("unable to load OLD save file. Old save file deleted");
            }


            //So now we have CB data and we should have bunch of settings that from now on are handled by the stock settings integration.
            //If we did find those settings we overwrite the stock settings intregration values, but after this they won't exist any more for this save as we won't save them again here.
            if (foundOldSettings)
            {
                ResearchBodies.Enabled   = Enabled;
                RSTLogWriter.debuggingOn = DebugLogging;
                if (Database.instance != null)
                {
                    Database.instance.RB_SettingsParms.ResearchCost         = ResearchCost;
                    Database.instance.RB_SettingsParms.ProgressResearchCost = ProgressResearchCost;
                    Database.instance.RB_SettingsParms.ScienceReward        = ScienceReward;
                    Database.instance.RB_SettingsParms.DebugLogging         = DebugLogging;
                    Database.instance.RB_SettingsParms.DiscoverySeed        = chances;
                    Database.instance.RB_SettingsParms.Enabledtslvl1        = allowTSlevel1;
                    Database.instance.ApplySettings();
                }
                else
                {
                    RSTLogWriter.Log("Failed to apply old game settings to new Stock settings integration");
                }
            }
            else
            {
                Database.instance.onGameStatePostLoad(node);
            }
            RSTLogWriter.Log("RBGameSettings Loading Complete");
            RSTLogWriter.Flush();
        }