private OrbitBodyWithTerraformInfo GetOrCreateTargetsFor(int orbitBodyId, int populationId)
        {
            var target = this.GetTargetsFor(orbitBodyId, populationId);

            if (target == null)
            {
                target = new OrbitBodyWithTerraformInfo(orbitBodyId, populationId);
                _allTerraforming.Add(target);
            }

            return(target);
        }
        public ProcessedTerraformingResult ProcessOrbitBody(OrbitBodyWithTerraformInfo target, OrbitBodyWithCurrentElementInfo currentElements, long deltaTimeInSeconds)
        {
            var maxPossibleDelta = _terraformCapacityGetter.GetTotalTerraformingDeltaForPopulation(target.PopulationId, secondsSinceLastCalc: deltaTimeInSeconds);

            var adjustResults = AdjustMultipleElements(currentElements: currentElements.CurrentElements, targets: target.DesiredTargets, maxChangePossible: maxPossibleDelta);

            currentElements.CurrentElements = adjustResults.currentElementValues;
            target.DesiredTargets           = adjustResults.adjustedTargets;

            return(new ProcessedTerraformingResult()
            {
                newTargets = target,
                newValues = currentElements
            });
        }
        public void Manager_WhenProcessingAll_Should_ProcessAllCorrectly()
        {
            var allMockInfo = new List <OrbitBodyWithTerraformInfo>();

            var entry = new OrbitBodyWithTerraformInfo(2100, 1100);

            entry.DesiredTargets.Set(1, 0.8);
            entry.DesiredTargets.Set(2, 0.2);
            allMockInfo.Add(entry);

            entry = new OrbitBodyWithTerraformInfo(2071, 1099);
            entry.DesiredTargets.Set(1, 0.1);
            entry.DesiredTargets.Set(2, 0.9);
            allMockInfo.Add(entry);

            var allBodyInfo = new List <OrbitBodyWithCurrentElementInfo>();

            var entryEle = new OrbitBodyWithCurrentElementInfo(2100);

            entryEle.CurrentElements.Set(1, 0.7);
            allBodyInfo.Add(entryEle);

            entryEle = new OrbitBodyWithCurrentElementInfo(2071);
            entryEle.CurrentElements.Set(5, 85.76);
            allBodyInfo.Add(entryEle);

            var results = _terraformManager.ProcessAll(allMockInfo, allBodyInfo, 3600 * 24 * 5);

            var body2071Results = results.newValues.First(body => body.OrbitBodyId == 2071);
            var body2071Targets = results.newTargets.First(body => body.OrbitBodyId == 2071);

            Assert.IsFalse(body2071Targets.DesiredTargets.IsPresent(1));

            TwoDoublesAreCloseEnough(0.1, body2071Results.CurrentElements.GetAmount(1));
            TwoDoublesAreCloseEnough(0.2, body2071Results.CurrentElements.GetAmount(2));
            TwoDoublesAreCloseEnough(85.76, body2071Results.CurrentElements.GetAmount(5));


            var body2100Results = results.newValues.First(body => body.OrbitBodyId == 2100);
            var body2100Targets = results.newTargets.First(body => body.OrbitBodyId == 2100);

            Assert.IsFalse(body2100Targets.DesiredTargets.IsPresent(1));
            Assert.IsFalse(body2100Targets.DesiredTargets.IsPresent(2));
            TwoDoublesAreCloseEnough(0.8, body2100Results.CurrentElements.GetAmount(1));
            TwoDoublesAreCloseEnough(0.2, body2100Results.CurrentElements.GetAmount(2));
        }
        public void Manager_WhenProcessingOrbitBody_Should_ProcessCorrectly()
        {
            var mockPopulation = new OrbitBodyWithTerraformInfo(2071, 1099);

            mockPopulation.DesiredTargets.Set(1, 0.2);
            mockPopulation.DesiredTargets.Set(2, 0.8);

            var mockOrbitBody = new OrbitBodyWithCurrentElementInfo(2071);

            mockOrbitBody.CurrentElements.Set(5, 85.76);

            var results = _terraformManager.ProcessOrbitBody(mockPopulation, mockOrbitBody, 3600 * 24 * 5);

            Assert.IsFalse(results.newTargets.DesiredTargets.IsPresent(1));
            TwoDoublesAreCloseEnough(0.2, results.newValues.CurrentElements.GetAmount(1));
            TwoDoublesAreCloseEnough(0.1, results.newValues.CurrentElements.GetAmount(2));
            TwoDoublesAreCloseEnough(85.76, results.newValues.CurrentElements.GetAmount(5));
        }
Example #5
0
        public static List <ListViewItem> GenerateTargetsList(OrbitBodyWithTerraformInfo dataToShow)
        {
            var result = new List <ListViewItem>();

            result.Add(new ListViewItem(new[] { "Gas", "Atm" }));
            result.Add(new ListViewItem(new[] { "", "" }));

            if (dataToShow != null && dataToShow.DesiredTargets != null)
            {
                foreach (var element in dataToShow.DesiredTargets.theElements)
                {
                    var textToDisplay = $"{GetGasName(element.elementId)} with a target of {element.amount} Atm";

                    result.Add(new ListViewItem(new[] { GetGasName(element.elementId), element.amount.ToString() })
                    {
                        Tag = element
                    });
                }
            }

            return(result);
        }