Exemplo n.º 1
0
        public void Do_SlowUpdate()
        {
            if (activeExperiment != null)
            {
                double curTime = Planetarium.GetUniversalTime();
                double delta   = curTime - lastUpdateTime;

                // Tasks
                // 1. Make sure experiment situation hasn't changed, if it has, then return
                // 2. calcualte resource usage
                // 3. Check to see if exeriment is completed, if so, set a flag

                string biome, displayBiome;
                if (vessel.landedAt != string.Empty)
                {
                    biome        = Vessel.GetLandedAtString(vessel.landedAt);
                    displayBiome = Localizer.Format(vessel.displaylandedAt);
                }
                else
                {
                    biome        = ScienceUtil.GetExperimentBiome(vessel.mainBody, vessel.latitude, vessel.longitude);
                    displayBiome = ScienceUtil.GetBiomedisplayName(vessel.mainBody, biome);
                }

                var curExp = new ActiveExperiment(activeExperiment.activeExpid, vessel.mainBody.bodyName, ScienceUtil.GetExperimentSituation(vessel), biome);

                if ((object)curExp != null && curExp.Key == activeExperiment.Key)
                {
                    if (!expStatuses.ContainsKey(activeExperiment.Key))
                    {
                        Log.Error("Key missing from expStatuses, key: " + activeExperiment.Key);
                        foreach (var e in expStatuses.Keys)
                        {
                            Log.Error("key: " + e);
                        }
                    }
                    double resourceRequest = delta / Planetarium.fetch.fixedDeltaTime;

                    double amtNeeded = Math.Min(
                        experiments[activeExperiment.activeExpid].resourceUsageRate * resourceRequest,
                        experiments[activeExperiment.activeExpid].resourceAmtRequired - expStatuses[activeExperiment.Key].processedResource);
                    amtNeeded = amtNeeded * KCT_Interface.ResearchTimeAdjustment();

                    //Log.Info("SkylabExperiment, amtNeeded: " + amtNeeded.ToString("F3") + ",  activeExperiment.Key: " + activeExperiment.Key +
                    //    ", processedResource: " + expStatuses[activeExperiment.Key].processedResource +
                    //    ", resourceAmtRequired: " + Addon.experiments[activeExperiment.activeExpid].resourceAmtRequired);

                    double resource = part.RequestResource(experiments[activeExperiment.activeExpid].neededResourceName, amtNeeded);
                    expStatuses[activeExperiment.Key].processedResource += resource;

                    int resourceID = GetResourceID(expStatuses[activeExperiment.Key].reqResource);
                    //                    part.GetConnectedResourceTotals(resourceID, out double amount, out double maxAmount);

                    expStatuses[activeExperiment.Key].lastTimeUpdated = Planetarium.GetUniversalTime();

                    if (HighLogic.CurrentGame.Parameters.CustomParams <LTech_1>().exitWarpWhenDone)
                    {
                        var percent = 0.001 + expStatuses[activeExperiment.Key].processedResource / Addon.experiments[activeExperiment.activeExpid].resourceAmtRequired * 100;
                        if (percent >= 100f)
                        {
                            if (TimeWarp.CurrentRateIndex > 0)
                            {
                                StartCoroutine(CancelWarp());
                                //TimeWarp.fetch.CancelAutoWarp();
                                //TimeWarp.SetRate(0, true);
                            }
                        }
                    }
                    // var experiment = experiments[activeExperiment.activeExpid];
                }
                else
                {
                    Log.Info("Situation changed");
                    Utils.DisplayScreenMsg("Vessel Situation Changed, Experiment Paused");
                } // need to decide what to do if something changed
                lastUpdateTime = curTime;
            }
            else
            if (experimentStarted)
            {
                Log.Info("FixedUpdate, activeExperiment is null");
            }
        }
Exemplo n.º 2
0
        public void Do_SlowUpdate()
        {
            if ((object)activeExperiment != null)
            {
                var curTime = Planetarium.GetUniversalTime();
                var delta   = curTime - lastUpdateTime;

                // Tasks
                // 1. Make sure experiment situation hasn't changed, if it has, then return
                // 2. calcualte resource usage
                // 3. Check to see if exeriment is completed, if so, set a flag

                string biome, displayBiome;
                if (vessel.landedAt != string.Empty)
                {
                    biome        = Vessel.GetLandedAtString(vessel.landedAt);
                    displayBiome = Localizer.Format(vessel.displaylandedAt);
                }
                else
                {
                    biome        = ScienceUtil.GetExperimentBiome(vessel.mainBody, vessel.latitude, vessel.longitude);
                    displayBiome = ScienceUtil.GetBiomedisplayName(vessel.mainBody, biome);
                }
                var curExp = new ActiveExperiment(activeExperiment.activeExpid, vessel.mainBody.bodyName, ScienceUtil.GetExperimentSituation(vessel), biome);

                if ((object)curExp != null && curExp.Key == activeExperiment.Key)
                {
                    if (!expStatuses.ContainsKey(activeExperiment.Key))
                    {
                        Log.Info("Key missing from expStatuses, key: " + activeExperiment.Key);
                        foreach (var e in expStatuses.Keys)
                        {
                            Log.Info("key: " + e);
                        }
                    }
                    double resourceRequest = delta / Planetarium.fetch.fixedDeltaTime;

                    double amtNeeded = Math.Min(
                        experiments[activeExperiment.activeExpid].resourceUsageRate * resourceRequest,
                        experiments[activeExperiment.activeExpid].resourceAmtRequired - expStatuses[activeExperiment.Key].processedResource);
                    amtNeeded = amtNeeded * KCT_Interface.ResearchTimeAdjustment();

                    double resource = part.RequestResource(experiments[activeExperiment.activeExpid].neededResourceName, amtNeeded);
                    expStatuses[activeExperiment.Key].processedResource += resource;


                    int resourceID = GetResourceID(expStatuses[activeExperiment.Key].reqResource);
                    part.GetConnectedResourceTotals(resourceID, out double amount, out double maxAmount);

                    expStatuses[activeExperiment.Key].lastTimeUpdated = Planetarium.GetUniversalTime();
                    // var experiment = experiments[activeExperiment.activeExpid];
                }
                else
                {
                    Log.Info("Situation changed");
                    Utils.DisplayScreenMsg("Vessel Situation Changed, Experiment Paused");
                } // need to decide what to do if something changed
                lastUpdateTime = curTime;
            }
            else
            if (experimentStarted)
            {
                Log.Info("FixedUpdate, activeExperiment is null");
            }
        }