internal bool IsViewObstructed(Transform Origin, Transform Target) { float distance = Vector3.Distance(Target.position, Origin.position); RaycastHit[] hitInfo; Vector3 direction = (Target.position - Origin.position).normalized; if (RSTLogWriter.debuggingOn) { Debug.DrawRay(Origin.position, direction * distance, Color.red, 5f); } hitInfo = Physics.RaycastAll(new Ray(Origin.position, direction), distance, 3245585, QueryTriggerInteraction.Ignore); for (int i = 0; i < hitInfo.Length; i++) { if (hitInfo[i].transform.name != Target.transform.name) { RSTLogWriter.Log_Debug("View Obstructed by {0} , Origin: {1} , Target {2} , Direction {3} , Hit: {4}, Layer: {5}", hitInfo[i].collider.name, Origin.position, Target.position, direction, hitInfo[i].transform.position, hitInfo[i].collider.gameObject.layer); return(true); } } RSTLogWriter.Log_Debug("No View obstruction"); return(false); }
public override void OnLoad(ConfigNode gameNode) { base.OnLoad(gameNode); RBgameSettings.Load(gameNode); // Load the global settings //if (File.Exists(globalConfigFilename)) //{ // globalNode = ConfigNode.Load(globalConfigFilename); // foreach (Savable s in children.Where(c => c is Savable)) // { // s.Load(globalNode); // } //} RSTLogWriter.debuggingOn = RBgameSettings.DebugLogging; if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX && !Database.instance.enableInSandbox) { RBgameSettings.Enabled = false; } enabled = RBgameSettings.Enabled; 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."); } }
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_Debug("Added locale \"{0}\"", l.LocaleId); } } if (File.Exists(PathcacheLocalePath)) { StreamReader sr = new StreamReader(PathcacheLocalePath); string line = sr.ReadLine(); foreach (Locale l in locales) { if (l.LocaleId == line) { currentLocale = l; RSTLogWriter.Log_Debug("Loaded {0} from cache", l.LocaleFull); } } sr.Close(); } else { foreach (Locale l in locales) { if (l.LocaleId == "en") { currentLocale = l; } } TextWriter tw = new StreamWriter(PathcacheLocalePath); tw.Write(currentLocale.LocaleId); tw.Close(); } if (locales.Count == 0) { RSTLogWriter.Log_Debug("No locale added !"); } else { RSTLogWriter.Log_Debug("Added {0} locales", locales.Count); } }
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."); } }
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(); }
private void LoadModDatabaseNodes() { string[] sep = new string[] { " " }; //Load all Mod supplied database config files. RSTLogWriter.Log_Debug("Loading mods databases"); ConfigNode[] modNodes = GameDatabase.Instance.GetConfigNodes("RESEARCHBODIES"); foreach (ConfigNode node in modNodes) { if (node.GetValue("loadAs") == "mod") { if (node.HasValue("name")) { RSTLogWriter.Log_Debug("Loading {0} configuration", node.GetValue("name")); } if (node.HasNode("ONDISCOVERY")) { foreach (CelestialBody body in BodyList) { foreach (ConfigNode.Value value in node.GetNode("ONDISCOVERY").values) { if (value.name.Contains(body.bodyName)) { CelestialBodies[body].discoveryMessage = value.value; } } } } if (node.HasNode("IGNORE")) { foreach (ConfigNode.Value value in node.GetNode("IGNORE").values) { if (value.name == "body") { foreach (CelestialBody cb in BodyList) { if (value.value == cb.GetName()) { CelestialBodies[cb].IgnoreData.setBodyIgnoreData(false, false, false, false); RSTLogWriter.Log_Debug("Added {0} to the ignore list (pre-1.5 method !)", cb.GetName()); } } } else if (value.name == "!body") { foreach (CelestialBody cb in BodyList) { if (value.value == cb.GetName() && CelestialBodies.ContainsKey(cb)) { CelestialBodies[cb].IgnoreData.setBodyIgnoreData(true, true, true, true); RSTLogWriter.Log_Debug("Removed {0} from the ignore list (pre-1.5 method!)", cb.GetName()); } } } } } if (node.HasNode("IGNORELEVELS")) { foreach (ConfigNode.Value value in node.GetNode("IGNORELEVELS").values) { foreach (CelestialBody body in BodyList) { if (body.bodyName == value.name) { string[] args; args = value.value.Split(sep, StringSplitOptions.RemoveEmptyEntries); CelestialBodies[body].IgnoreData.setBodyIgnoreData(bool.Parse(args[0]), bool.Parse(args[1]), bool.Parse(args[2]), bool.Parse(args[3])); RSTLogWriter.Log_Debug("Body Ignore Data for {0} : {1}", body.bodyName, CelestialBodies[body].IgnoreData.ToString()); } } } } } } }
void Start() { 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 BodyList = FlightGlobals.Bodies.ToList(); if (isTSTInstalled && TSTWrapper.APITSTReady) //If TST is installed add the TST Galaxies to the list. { BodyList = BodyList.Concat(TSTWrapper.actualTSTAPI.CBGalaxies).ToList(); } //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. foreach (var CB in CelestialBodies.Where(a => a.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 CB.Key.orbitingBodies) { CelestialBody findOrbitBody = FlightGlobals.Bodies.FirstOrDefault(a => a.name.Contains(CB.Key.name) && a.name.Contains(orbitingBody.name) && a.name.Contains("Orbit")); //so if we found the related Orbit body we store it into the CelestialBodies dictionary. if (findOrbitBody != null) { CelestialBodies[orbitingBody].KOPrelbarycenterBody = findOrbitBody; } } } //Load the database.cfg file. //=========================== ConfigNode cfg = ConfigNode.Load(Locales.PathDatabasePath); string[] sep = new string[] { " " }; //Get Costs string[] _startResearchCosts; _startResearchCosts = cfg.GetNode("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 = cfg.GetNode("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 = cfg.GetNode("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_Debug("Loading Priority database"); foreach (CelestialBody body in BodyList) { //Load the priorities - DEPRECATED string name = body.GetName(); foreach (ConfigNode.Value value in cfg.GetNode("RESEARCHBODIES").GetNode("PRIORITIES").values) { if (name == value.name) { Priority[body] = int.Parse(value.value); RSTLogWriter.Log_Debug("Priority for body {0} set to {1}.", name, value.value); } } //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 == name) { CelestialBodies[body].discoveryMessage = value.value; } //DiscoveryMessage[value.name] = value.value; } } //Load the IgnoreData dictionary. RSTLogWriter.Log_Debug("Loading ignore body list from database"); foreach (ConfigNode.Value value in cfg.GetNode("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_Debug("Body Ignore Data for {0} : {1}", body.GetName(), CelestialBodies[body].IgnoreData); } } } LoadModDatabaseNodes(); //Load the NothingHere dictionary from the database config file. foreach (ConfigNode.Value value in cfg.GetNode("RESEARCHBODIES").GetNode("NOTHING").values) { if (value.name == "text") { NothingHere.Add(value.value); } } //So this is deprecated? Checks all CBs are in the Priority dictionary. Any that aren't are added with priority set to 3. foreach (CelestialBody cb in BodyList) { if (!Priority.Keys.Contains(cb) && !CelestialBodies[cb].ignore) { Priority[cb] = 3; RSTLogWriter.Log("Config not found for {0}, priority set to 3.", cb.GetName()); } } chances = int.Parse(cfg.GetNode("RESEARCHBODIES").GetValue("chances")); RSTLogWriter.Log_Debug("Chances to get a body is set to {0}", chances); enableInSandbox = bool.Parse(cfg.GetNode("RESEARCHBODIES").GetValue("enableInSandbox")); allowTSlevel1 = bool.Parse(cfg.GetNode("RESEARCHBODIES").GetValue("allowTrackingStationLvl1")); if (cfg.GetNode("RESEARCHBODIES").HasValue("useAppLauncher")) { UseAppLauncher = bool.Parse(cfg.GetNode("RESEARCHBODIES").GetValue("useAppLauncher")); } RSTLogWriter.Log_Debug("Loaded gamemode-related information : enable mod in sandbox = {0}, allow tracking with Tracking station lvl 1 = {1}", enableInSandbox, allowTSlevel1); // Load locales for OnDiscovery - Locales are loaded Immediately gamescene. Before this is loaded in MainMenu. if (Locales.currentLocale.LocaleId != "en") { foreach (CelestialBody body in BodyList) { if (Locales.currentLocale.Values.ContainsKey("discovery_" + body.GetName()) && CelestialBodies.ContainsKey(body)) { CelestialBodies[body].discoveryMessage = Locales.currentLocale.Values["discovery_" + body.GetName()]; } } } }