コード例 #1
0
 private void ProcessVesselToSOI(CelestialBody toBody, Vessel vsl)
 {
     if (Database.instance.CelestialBodies.ContainsKey(toBody))
     {
         //If it's not researched (found already) set it to found. and start tracking it's in SOI time.
         if (!Database.instance.CelestialBodies[toBody].isResearched)
         {
             bool          withparent;
             CelestialBody parentCB;
             FoundBody(0, toBody, out withparent, out parentCB);
         }
         //Start tracking this vessel in this CB SOI if it's researchstate is less than 100%
         if (Database.instance.CelestialBodies[toBody].researchState < 100)
         {
             if (!Database.instance.VesselsInSOI.ContainsKey(toBody.bodyName))
             {
                 CBVesselSOIInfo cbSOIInfo = new CBVesselSOIInfo(toBody.bodyName, vsl.persistentId, Planetarium.GetUniversalTime());
                 Database.instance.VesselsInSOI.Add(toBody.bodyName, cbSOIInfo);
             }
             else
             {
                 CBVesselSOIInfo cbSOIInfo = Database.instance.VesselsInSOI[toBody.bodyName];
                 cbSOIInfo.AddVessel(vsl.persistentId, Planetarium.GetUniversalTime());
             }
         }
         //If it's researchstate < minimum amount for a discovery by flyby we reward the player for the discovery and set the CB discovery level.
         if (Database.instance.CelestialBodies[toBody].researchState < Database.instance.DiscoveryByFlyby)
         {
             Database.instance.CelestialBodies[toBody].researchState = Database.instance.DiscoveryByFlyby;
             ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_RBodies_00051", toBody.displayName, Database.instance.RB_SettingsParms.ScienceReward.ToString()), 5f);
             ResearchAndDevelopment.Instance.AddScience(Database.instance.RB_SettingsParms.ScienceReward, TransactionReasons.None);
             KeyValuePair <CelestialBody, CelestialBodyInfo> keyValue = new KeyValuePair <CelestialBody, CelestialBodyInfo>();
             var dictEnum = Database.instance.CelestialBodies.GetEnumerator();
             while (dictEnum.MoveNext())
             {
                 var entry = dictEnum.Current;
                 if (entry.Key.bodyName == toBody.bodyName)
                 {
                     keyValue = entry;
                     break;
                 }
             }
             dictEnum.Dispose();
             if (keyValue.Key != null)
             {
                 SetIndividualBodyDiscoveryLevel(keyValue);
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// When a SOI change is triggered by GameEvents we check if the TO body Is Discovered or NOT.
        /// If it is not discovered we make it discovered.
        /// If it's researchState is less than 100 we set it to 100.
        /// Finally we set the discovery Level and ProgressiveCBMap.
        /// </summary>
        /// <param name="HostedfromtoAction"></param>
        private void onVesselSOIChanged(GameEvents.HostedFromToAction <Vessel, CelestialBody> HostedfromtoAction)
        {
            //Remove tracking of vessel in SOI FROM CB.
            if (Database.instance.VesselsInSOI.ContainsKey(HostedfromtoAction.from.bodyName))
            {
                CBVesselSOIInfo cbSOIInfo = Database.instance.VesselsInSOI[HostedfromtoAction.from.bodyName];
                cbSOIInfo.RemoveVessel(HostedfromtoAction.host.persistentId);
                //If the cb entry has no more vessels being tracked. remove the dictionary entry.
                if (cbSOIInfo.vesselSOIInfo.Count <= 0)
                {
                    Database.instance.VesselsInSOI.Remove(HostedfromtoAction.from.bodyName);
                }
            }

            ProcessVesselToSOI(HostedfromtoAction.to, HostedfromtoAction.host);
        }
コード例 #3
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);
                    RBsettingsNode.TryGetValue("lastTimeCheckedSOIs", ref lastTimeCheckedSOIs);

                    var bodyNodes = RBsettingsNode.GetNodes(CelestialBodyInfo.ConfigNodeName);
                    foreach (ConfigNode bodyNode in bodyNodes)
                    {
                        if (bodyNode.HasValue("body"))
                        {
                            CelestialBodyInfo bodyInfo = CelestialBodyInfo.Load(bodyNode);
                            CelestialBody     CB       = null;
                            for (int i = 0; i < FlightGlobals.Bodies.Count; i++)
                            {
                                if (FlightGlobals.Bodies[i].bodyName == bodyInfo.body)
                                {
                                    CB = FlightGlobals.Bodies[i];
                                    break;
                                }
                            }
                            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 = null;
                                    for (int i = 0; i < TSTWrapper.actualTSTAPI.CBGalaxies.Count; i++)
                                    {
                                        if (TSTWrapper.actualTSTAPI.CBGalaxies[i].bodyName == bodyInfo.body)
                                        {
                                            GalCB = TSTWrapper.actualTSTAPI.CBGalaxies[i];
                                            break;
                                        }
                                    }
                                    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;
                    ConfigNode vslsSOINode = new ConfigNode();
                    if (RBsettingsNode.TryGetNode("VESSELSINSOI", ref vslsSOINode))
                    {
                        ConfigNode[] cbSOINodes = vslsSOINode.GetNodes(CBVesselSOIInfo.ConfigNodeName);
                        foreach (ConfigNode cbNode in cbSOINodes)
                        {
                            CBVesselSOIInfo cbSoiInfo = CBVesselSOIInfo.Load(cbNode);
                            if (cbSoiInfo != null)
                            {
                                Database.instance.VesselsInSOI.Add(cbSoiInfo.body, cbSoiInfo);
                            }
                        }
                    }
                }
                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();
        }