Example #1
0
        void LoadScenarios(ConfigNode node)
        {
#if false
            Log.Info("LoadScenarios");
            if (node.HasNode(SCENARIO))
            {
                activeKeoCacheCollections = new Dictionary <string, KeoCacheCollection>();

                var gNode = node.GetNode(SCENARIO);
                if (gNode != null)
                {
                    var aNode = gNode.GetNodes();

                    for (int i = 0; i < aNode.Length; i++)
                    {
                        ConfigNode loadedCollectionNode = aNode[i].GetNode(FileIO.KEOCACHE_COLLECTION);
                        var        cache = KeoCacheCollection.LoadCollectionFromConfigNode(loadedCollectionNode);
                        if (cache != null)
                        {
                            Log.Info("LoadScenarios, adding collectionId: " + cache.keocacheCollectionData.collectionId);
                            KeoScenario.activeKeoCacheCollections.Add(cache.keocacheCollectionData.collectionId, cache);
                        }
                    }
                }
#endif
        }

#if false
        void LoadTravelBugs(ConfigNode node)
        {
            if (node.HasNode(SCENARIO))
            {
                travelBugs = new Dictionary <string, TravelBug>();
                var bNode = node.GetNode(TRAVELBUGS);
                if (bNode != null)
                {
                    var bNodes = bNode.GetNodes();
                    for (int i = 0; i < bNodes.Length; i++)
                    {
                        var travelBug = new TravelBug();

                        bNodes[i].TryGetValue("id", ref travelBug.travelbugId);
                        //bNodes[i].TryGetValue("name", ref travelBug.name);
                        bNodes[i].TryGetValue("collectionId", ref travelBug.activeCollectionId);

                        var entries = bNodes[i].GetNodes();
                        for (int e = 0; e < entries.Count() - 1; e++)
                        {
                            TravelBugEntry tbe = new TravelBugEntry();
                            entries[e].TryGetValue("keocachId", ref tbe.keocachId);
                            //entries[e].TryGetValue("hintId", ref tbe.hintId);
                            entries[e].TryGetValue("timeFound", ref tbe.timeFound);

                            travelBug.entries.Add(tbe);
                        }

                        travelBugs.Add(travelBug.travelbugId, travelBug);
                    }
                }
            }
        }
        void GetActiveTravelBugs()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }
            Log.Info("GetActiveTravelBugs");
            Log.Info("FlightGlobals.Vessels.Count: " + FlightGlobals.Vessels.Count +
                     ", VesselsUnloaded.Count: " + FlightGlobals.VesselsUnloaded.Count +
                     ", VesselsLoaded.Count: " + FlightGlobals.VesselsLoaded.Count);
            activeTravelBugs = new Dictionary <string, TravelBugEntry>();
            usedKeoCaches    = new List <string>();

            for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--)
            {
                Vessel vessel = FlightGlobals.Vessels[i];
                //Log.Info("TravelBug_Window, i: " + i + ", vessel: " + vessel.GetDisplayName() + ",  loaded: " + vessel.loaded);
                // May need to use moduleHandlers here instead of partModules, needed if vessel is unloaded
                //
                //
                // if (moduleHandlers.ContainsKey(p.modules[i].moduleName)) {
                //
                if (vessel != null)
                {
                    if (!vessel.loaded)
                    {
                        for (int imh = vessel.protoVessel.protoPartSnapshots.Count - 1; imh >= 0; imh--)
                        {
                            ProtoPartSnapshot mh = vessel.protoVessel.protoPartSnapshots[imh];
                            for (int mi = mh.modules.Count - 1; mi >= 0; mi--)
                            {
                                ProtoPartModuleSnapshot module = mh.modules[mi];
                                if (module.moduleName == "KeoTravelBugModule")
                                {
                                    ConfigNode cn = module.moduleValues.GetNode(FileIO.KEOCACHE_COLLECTION);
                                    if (cn != null)
                                    {
                                        KeoCacheCollection tbKcc = KeoCacheCollection.LoadCollectionFromConfigNode(cn);
                                        if (tbKcc != null)
                                        {
                                            TravelBugEntry tbe = new TravelBugEntry(tbKcc.keocacheCollectionData.collectionId, vessel.vesselName, vessel.protoVessel.vesselID);

                                            activeTravelBugs.Add(tbe.keocachId, tbe);
                                        }
                                        FindKeoCaches();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        List <KeoTravelBugModule> vesselTravelBugs = vessel.FindPartModulesImplementing <KeoTravelBugModule>();

                        if (vesselTravelBugs != null)
                        {
                            Log.Info("vesselTravelBugs.count: " + vesselTravelBugs.Count);
                            for (int i1 = vesselTravelBugs.Count - 1; i1 >= 0; i1--)
                            {
                                KeoTravelBugModule traveBug = vesselTravelBugs[i1];
                                Log.Info("creating TravelBugentry # " + i1);
                                if (traveBug == null)
                                {
                                    Log.Info("traveBug is null");
                                }
                                if (traveBug.tbKcc != null)
                                {
                                    if (traveBug.tbKcc == null)
                                    {
                                        Log.Info("traveBug.tbKcc is null");
                                    }
                                    if (traveBug.tbKcc.keocacheCollectionData == null)
                                    {
                                        Log.Info("traveBug.tbKcc.keocacheCollectionData is null");
                                    }
                                    if (traveBug.tbKcc.keocacheCollectionData.collectionId == null)
                                    {
                                        Log.Info("traveBug.tbKcc.keocacheCollectionData.collectionId is null");
                                    }

                                    if (vessel == null)
                                    {
                                        Log.Info("vessel is null");
                                    }
                                    if (vessel.vesselName == null)
                                    {
                                        Log.Info("vessel.vesselName is null");
                                    }
                                    if (vessel.protoVessel == null)
                                    {
                                        Log.Info("vessel.protoVessel is null");
                                    }

                                    TravelBugEntry tbe = new TravelBugEntry(traveBug.tbKcc.keocacheCollectionData.collectionId, vessel.vesselName, vessel.protoVessel.vesselID);

                                    activeTravelBugs.Add(tbe.keocachId, tbe);
                                    FindKeoCaches();
                                }
                            }
                        }
                    }
                }
            }
        }