Esempio n. 1
0
        private static bool FixedUpdatePrefix(KerbalismSentinel __instance)
        {
            if (__instance.isTrackingEnabled)
            {
                VesselData vd = __instance.vessel.KerbalismData();
                if (!vd.Connection.linked || vd.Connection.rate < __instance.comms_rate)
                {
                    __instance.isTracking = false;
                    __instance.status     = "Comms connection too weak";
                    return(false);
                }

                ResourceInfo ec = ResourceCache.GetResource(__instance.vessel, "ElectricCharge");
                ec.Consume(__instance.ec_rate * Kerbalism.elapsed_s, ResourceBroker.Scanner);

                if (ec.Amount <= double.Epsilon)
                {
                    __instance.isTracking = false;
                    __instance.status     = Local.Module_Experiment_issue4;                 // "no Electricity"
                    return(false);
                }

                __instance.isTracking = true;
            }

            return(true);
        }
Esempio n. 2
0
 private static void StartTrackingPostfix(KerbalismSentinel __instance)
 {
     if (__instance.isTracking)
     {
         __instance.isTrackingEnabled = true;
         __instance.isTracking        = false;
     }
     else
     {
         __instance.isTrackingEnabled = false;
     }
 }
Esempio n. 3
0
        private static bool TelescopeCanActivatePrefix(KerbalismSentinel __instance, ref bool __result)
        {
            if (__instance.vessel.orbit.referenceBody != Planetarium.fetch.Sun)
            {
                string msg = Localizer.Format("#autoLOC_6002295", SentinelUtilities.SentinelPartTitle);
                ScreenMessages.PostScreenMessage(msg, SentinelUtilities.CalculateReadDuration(msg), ScreenMessageStyle.UPPER_CENTER);
                __result = false;
            }
            __result = true;

            return(false);
        }
Esempio n. 4
0
        public static void BackgroundUpdate(Vessel v, ProtoPartModuleSnapshot m, KerbalismSentinel prefab, VesselData vd, ResourceInfo ec, double elapsed_s)
        {
            if (Lib.Proto.GetBool(m, "isTrackingEnabled"))
            {
                if (!vd.Connection.linked || vd.Connection.rate < prefab.comms_rate)
                {
                    Lib.Proto.Set(m, "isTracking", false);
                    return;
                }

                ec.Consume(prefab.ec_rate * elapsed_s, ResourceBroker.Scanner);

                if (ec.Amount <= double.Epsilon)
                {
                    Lib.Proto.Set(m, "isTracking", false);
                    return;
                }

                Lib.Proto.Set(m, "isTracking", true);
            }
        }
Esempio n. 5
0
        public static void Update(Vessel v, VesselData vd, VesselResources resources, double elapsed_s)
        {
            if (!Lib.IsVessel(v))
            {
                return;
            }

            // get most used resource handlers
            ResourceInfo ec = resources.GetResource(v, "ElectricCharge");

            List <ResourceInfo>         allResources       = resources.GetAllResources(v);
            Dictionary <string, double> availableResources = new Dictionary <string, double>();

            foreach (var ri in allResources)
            {
                availableResources[ri.ResourceName] = ri.Amount;
            }
            List <KeyValuePair <string, double> > resourceChangeRequests = new List <KeyValuePair <string, double> >();

            foreach (var e in Background_PMs(v))
            {
                switch (e.type)
                {
                case Module_type.Reliability: Reliability.BackgroundUpdate(v, e.p, e.m, e.module_prefab as Reliability, elapsed_s); break;

                case Module_type.Experiment: (e.module_prefab as Experiment).BackgroundUpdate(v, vd, e.m, ec, resources, elapsed_s); break;                         // experiments use the prefab as a singleton instead of a static method

                case Module_type.Greenhouse: Greenhouse.BackgroundUpdate(v, e.m, e.module_prefab as Greenhouse, vd, resources, elapsed_s); break;

                case Module_type.GravityRing: GravityRing.BackgroundUpdate(v, e.p, e.m, e.module_prefab as GravityRing, ec, elapsed_s); break;

                case Module_type.Harvester: Harvester.BackgroundUpdate(v, e.m, e.module_prefab as Harvester, elapsed_s); break;                         // Kerbalism ground and air harvester module

                case Module_type.Laboratory: Laboratory.BackgroundUpdate(v, e.p, e.m, e.module_prefab as Laboratory, ec, elapsed_s); break;

                case Module_type.Command: ProcessCommand(v, e.p, e.m, e.module_prefab as ModuleCommand, resources, elapsed_s); break;

                case Module_type.Generator: ProcessGenerator(v, e.p, e.m, e.module_prefab as ModuleGenerator, resources, elapsed_s); break;

                case Module_type.Converter: ProcessConverter(v, e.p, e.m, e.module_prefab as ModuleResourceConverter, resources, elapsed_s); break;

                case Module_type.Drill: ProcessDrill(v, e.p, e.m, e.module_prefab as ModuleResourceHarvester, resources, elapsed_s); break;                         // Stock ground harvester module

                // case Module_type.AsteroidDrill: ProcessAsteroidDrill(v, e.p, e.m, e.module_prefab as ModuleAsteroidDrill, resources, elapsed_s); break; // Stock asteroid harvester module
                case Module_type.StockLab: ProcessStockLab(v, e.p, e.m, e.module_prefab as ModuleScienceConverter, ec, elapsed_s); break;

                case Module_type.Light: ProcessLight(v, e.p, e.m, e.module_prefab as ModuleLight, ec, elapsed_s); break;

                case Module_type.Scanner: KerbalismScansat.BackgroundUpdate(v, e.p, e.m, e.module_prefab as KerbalismScansat, e.part_prefab, vd, ec, elapsed_s); break;

                case Module_type.FissionGenerator: ProcessFissionGenerator(v, e.p, e.m, e.module_prefab, ec, elapsed_s); break;

                case Module_type.RadioisotopeGenerator: ProcessRadioisotopeGenerator(v, e.p, e.m, e.module_prefab, ec, elapsed_s); break;

                case Module_type.CryoTank: ProcessCryoTank(v, e.p, e.m, e.module_prefab, resources, ec, elapsed_s); break;

                case Module_type.FNGenerator: ProcessFNGenerator(v, e.p, e.m, e.module_prefab, ec, elapsed_s); break;

                case Module_type.SolarPanelFixer: SolarPanelFixer.BackgroundUpdate(v, e.m, e.module_prefab as SolarPanelFixer, vd, ec, elapsed_s); break;

                case Module_type.KerbalismSentinel: KerbalismSentinel.BackgroundUpdate(v, e.m, e.module_prefab as KerbalismSentinel, vd, ec, elapsed_s); break;

                case Module_type.APIModule: ProcessApiModule(v, e.p, e.m, e.part_prefab, e.module_prefab, resources, availableResources, resourceChangeRequests, elapsed_s); break;
                }
            }
        }
Esempio n. 6
0
        public void Start()
        {
            // log version
            Lib.Log("Version : " + Lib.KerbalismVersion + " - Build : " + Lib.KerbalismDevBuild);

            if (LocalHelpers.GenerateEnglishLoc)
            {
                LocalHelpers.GenerateLoc();
            }

            if (LocalHelpers.UpdateNonEnglishLoc)
            {
                LocalHelpers.RegenerateNonEnglishLoc();
            }

            Lib.Log("Forcing KSP to load resources...");
            PartResourceLibrary.Instance.LoadDefinitions();

            // parse settings
            Settings.Parse();
            // parse profile
            Profile.Parse();
            // detect features
            Features.Detect();

            // get configs from DB
            UrlDir.UrlFile root = null;
            foreach (UrlDir.UrlConfig url in GameDatabase.Instance.root.AllConfigs)
            {
                root = url.parent; break;
            }

            // inject MM patches on-the-fly, so that profile/features can be queried with NEEDS[]
            Inject(root, "Profile", Lib.UppercaseFirst(Settings.Profile));
            if (Features.Reliability)
            {
                Inject(root, "Feature", "Reliability");
            }
            if (Features.Deploy)
            {
                Inject(root, "Feature", "Deploy");
            }
            if (Features.SpaceWeather)
            {
                Inject(root, "Feature", "SpaceWeather");
            }
            if (Features.Automation)
            {
                Inject(root, "Feature", "Automation");
            }
            if (Features.Science)
            {
                Inject(root, "Feature", "Science");
            }
            if (Features.Radiation)
            {
                Inject(root, "Feature", "Radiation");
            }
            if (Features.Shielding)
            {
                Inject(root, "Feature", "Shielding");
            }
            if (Features.LivingSpace)
            {
                Inject(root, "Feature", "LivingSpace");
            }
            if (Features.Comfort)
            {
                Inject(root, "Feature", "Comfort");
            }
            if (Features.Poisoning)
            {
                Inject(root, "Feature", "Poisoning");
            }
            if (Features.Pressure)
            {
                Inject(root, "Feature", "Pressure");
            }
            if (Features.Habitat)
            {
                Inject(root, "Feature", "Habitat");
            }
            if (Features.Supplies)
            {
                Inject(root, "Feature", "Supplies");
            }

            // inject harmony patches
            Harmony harmony = new Harmony("Kerbalism");

            harmony.PatchAll(Assembly.GetExecutingAssembly());
            KerbalismSentinel.ApplyHarmonyPatches(harmony);
            var methods = harmony.GetPatchedMethods();

            // register loading callbacks
            if (HighLogic.LoadedScene == GameScenes.LOADING)
            {
                GameEvents.OnPartLoaderLoaded.Add(SaveHabitatData);
            }
        }
Esempio n. 7
0
 private static void StopTrackingPostfix(KerbalismSentinel __instance)
 {
     __instance.isTrackingEnabled = false;
 }