Beispiel #1
0
        public override void OnFixedUpdate()
        {
            try
            {
                //Check our time
                var deltaTime = GetDeltaTime();
                if (deltaTime < 0)
                {
                    return;
                }

                var recipe = PrepareRecipe(deltaTime);


                if (recipe != null)
                {
                    var result = _converter.ProcessRecipe(deltaTime, recipe, part, EfficiencBonus);
                    PostProcess(result, deltaTime);
                }
            }
            catch (Exception e)
            {
                print("[REGO] - Error in - BaseConverter_OnFixedUpdate - " + e.Message);
            }
        }
Beispiel #2
0
 public void Should_be_able_to_account_for_delta_time()
 {
     var recipe = GetComplexRecipe();
     var results = GetComplexOutputWithDelta();
     var conv = new ResourceConverter(new FakeResourceBroker());
     var actual = conv.ProcessRecipe(0.5, recipe, null,1);
     var result = comp.Compare(results, actual);
     Assert.IsTrue(result.AreEqual);
 }
Beispiel #3
0
        public void Should_be_able_to_account_for_delta_time()
        {
            var recipe  = GetComplexRecipe();
            var results = GetComplexOutputWithDelta();
            var conv    = new ResourceConverter(new FakeResourceBroker());
            var actual  = conv.ProcessRecipe(0.5, recipe, null, 1);
            var result  = comp.Compare(results, actual);

            Assert.IsTrue(result.AreEqual);
        }
Beispiel #4
0
 public void Should_be_able_to_perform_a_complex_multi_resource_conversion()
 {
     var recipe = GetComplexRecipe();
     var results = GetComplexOutput();
     var conv = new ResourceConverter(new FakeResourceBroker());
     //We'll start with a delta time of 1 second - the default.
     var actual = conv.ProcessRecipe(1, recipe, null,1);
     var result = comp.Compare(results, actual);
     Assert.IsTrue(result.AreEqual);
 }
Beispiel #5
0
        public void Should_be_able_to_perform_a_complex_multi_resource_conversion()
        {
            var recipe  = GetComplexRecipe();
            var results = GetComplexOutput();
            var conv    = new ResourceConverter(new FakeResourceBroker());
            //We'll start with a delta time of 1 second - the default.
            var actual = conv.ProcessRecipe(1, recipe, null, 1);
            var result = comp.Compare(results, actual);

            Assert.IsTrue(result.AreEqual);
        }
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight || this.vessel == null || !this.vessel.loaded)
            {
                return;
            }

            double now                = Planetarium.GetUniversalTime();
            var    upgradingParts     = this.GetUpgradingParts();
            int    numStaffedUpgrades = upgradingParts.Count(p => p.CrewRequirement.IsStaffed);

            if (numStaffedUpgrades == 0)
            {
                this.lastTimeCheck = now;
                return;
            }

            PartResourceDefinition rocketPartsResourceDefinition = PartResourceLibrary.Instance.GetDefinition("RocketParts");

            vessel.GetConnectedResourceTotals(rocketPartsResourceDefinition.id, out double availableRocketParts, out double _);

            double timeLeft        = now - lastTimeCheck;
            double rocketPartsUsed = 0;

            while (timeLeft > float.Epsilon && upgradingParts.Any() && rocketPartsUsed < availableRocketParts)
            {
                var workingOnParts = upgradingParts.Where(up => up.CrewRequirement.IsStaffed).ToList();
                if (workingOnParts.Count < numStaffedUpgrades)
                {
                    int others = numStaffedUpgrades - workingOnParts.Count;
                    workingOnParts.AddRange(
                        upgradingParts
                        .Where(up => !up.CrewRequirement.IsStaffed)
                        .Take(others));
                }

                // If we're working on all the parts that are staffed at once, what's the rate of consumption?
                double ratePerSecond = workingOnParts.Sum(wp => wp.PartsUseRateInRocketPartsPerSecond);
                // Time is limited by either running out of parts
                double timeToRunOutOfParts   = (availableRocketParts - rocketPartsUsed) / ratePerSecond;
                double timeToFinishSomething = workingOnParts.Select(wp => wp.remainingWork / wp.PartsUseRateInRocketPartsPerSecond).Min();
                double timeSpent             = Math.Min(timeLeft, Math.Min(timeToRunOutOfParts, timeToFinishSomething));

                foreach (var workingOnPart in workingOnParts)
                {
                    double numRocketPartsThatStillNeedToBeInstalled
                        = workingOnPart.remainingWork - timeSpent * workingOnPart.PartsUseRateInRocketPartsPerSecond;
                    if (numRocketPartsThatStillNeedToBeInstalled < float.Epsilon)
                    {
                        numRocketPartsThatStillNeedToBeInstalled = 0;
                        upgradingParts.Remove(workingOnPart);
                    }

                    workingOnPart.UpdateRemainingParts(numRocketPartsThatStillNeedToBeInstalled);
                }

                rocketPartsUsed += timeSpent * ratePerSecond;
                timeLeft        -= timeSpent;
            }

            ResourceConverter resourceConverter = new ResourceConverter();
            ConversionRecipe  recipe            = new ConversionRecipe();

            recipe.Inputs.Add(new ResourceRatio("RocketParts", rocketPartsUsed, dumpExcess: false));
            resourceConverter.ProcessRecipe(1, recipe, this.vessel.rootPart, resModule: null, efficiencyBonus: 1f);
            this.lastTimeCheck = now;
        }