Exemplo n.º 1
0
        public void OnPartResourceInitialAmountChanged(BaseEventData data)
        {
            if (!GameSceneFilter.AnyEditor.IsLoaded())
            {
                return;
            }

            if (selectedTankType == null)
            {
                return;
            }

            PartResource resource = data.Get <PartResource> ("resource");

            TankResource tankResource = selectedTankType.resources.Find(r => r.name == name);

            if (tankResource == null || !tankResource.forceEmpty)
            {
                return;
            }

            if (resource != null && resource.amount > 0)
            {
                resource.amount = 0;
                InitialAmountChanged(part, resource, resource.amount);
            }
        }
Exemplo n.º 2
0
        private double CalculateMaxResourceAmount(TankResource res)
        {
            double shapeMultiplier = (PPart is ProceduralPart && PPart.CurrentShape is ProceduralAbstractShape) ?
                                     PPart.CurrentShape.resourceMultiplier : 0;

            return(Math.Round((res.unitsConst + (tankVolume * res.unitsPerKL) + (mass * res.unitsPerT)) * shapeMultiplier, 2));
        }
Exemplo n.º 3
0
 public void Load(ConfigNode node)
 {
     ConfigNode.LoadObjectFromConfig(this, node);
     resources = new List <TankResource>();
     foreach (ConfigNode resNode in node.GetNodes("RESOURCE"))
     {
         TankResource resource = new TankResource();
         resource.Load(resNode);
         resources.Add(resource);
     }
     resources.Sort();
 }
Exemplo n.º 4
0
        public ResourceModifier(TankResource tankResource, GetVolumeDelegate getVolumeDelegate, Part part, float filledProportion, bool?tweakable)
        {
            tankResource.ThrowIfNullArgument(nameof(tankResource));
            getVolumeDelegate.ThrowIfNullArgument(nameof(getVolumeDelegate));
            part.ThrowIfNullArgument(nameof(part));

            this.tankResource      = tankResource;
            this.getVolumeDelegate = getVolumeDelegate;
            this.part             = part;
            this.filledProportion = filledProportion;
            this.tweakable        = tweakable;
        }
Exemplo n.º 5
0
        public ResourceModifier(TankResource tankResource, IVolumeProvider volumeProvider, Part part, float filledProportion, bool?tweakable)
        {
            tankResource.ThrowIfNullArgument(nameof(tankResource));
            volumeProvider.ThrowIfNullArgument(nameof(volumeProvider));
            part.ThrowIfNullArgument(nameof(part));

            this.tankResource     = tankResource;
            this.volumeProvider   = volumeProvider;
            this.part             = part;
            this.filledProportion = filledProportion;
            this.tweakable        = tweakable;
        }
Exemplo n.º 6
0
        private bool UpdateResources()
        {
            // Hopefully we can just fiddle with the existing part resources.
            // This saves having to make the window dirty, which breaks dragging on sliders.
            if (part.Resources.Count != selectedTankType.resources.Count)
            {
                Debug.LogWarning("*TCS* Selected and existing resource counts differ");
                return(false);
            }

            for (int i = 0; i < part.Resources.Count; ++i)
            {
                PartResource partRes = part.Resources[i];
                TankResource tankRes = selectedTankType.resources[i];

                if (partRes.resourceName != tankRes.name)
                {
                    Debug.LogWarning("*TCS* Selected and existing resource names differ");
                    return(false);
                }

                //double maxAmount = (float)Math.Round(tankRes.unitsConst + tankVolume * tankRes.unitsPerKL + mass * tankRes.unitsPerT, 2);
                double maxAmount = CalculateMaxResourceAmount(tankRes);

                // ReSharper disable CompareOfFloatsByEqualityOperator
                if (partRes.maxAmount == maxAmount)
                {
                    continue;
                }

                if (tankRes.forceEmpty)
                {
                    partRes.amount = 0;
                }
                else if (partRes.maxAmount == 0)
                {
                    partRes.amount = maxAmount;
                }
                else
                {
                    SIPrefix pfx = maxAmount.GetSIPrefix();
                    partRes.amount = pfx.Round(partRes.amount * maxAmount / partRes.maxAmount, 4);
                }
                partRes.maxAmount = maxAmount;
                // ReSharper restore CompareOfFloatsByEqualityOperator

                MaxAmountChanged(part, partRes, partRes.maxAmount);
                InitialAmountChanged(part, partRes, partRes.amount);
            }

            return(true);
        }
Exemplo n.º 7
0
        private double CalculateMaxResourceAmount(TankResource res)
        {
            double shapeMultiplier = 0;

            if (PPart != null)
            {
                if (PPart.CurrentShape != null)
                {
                    shapeMultiplier = PPart.CurrentShape.resourceMultiplier;
                }
            }

            return(Math.Round((res.unitsConst + tankVolume * res.unitsPerKL + mass * res.unitsPerT) * shapeMultiplier, 2));
        }
        public override void TestStartUp()
        {
            base.TestStartUp();

            part.partInfo = new AvailablePart(); // So that it thinks it's loading from a save

            module.baseVolume = 1;

            resourceDef1 = new PartResourceDefinition("resource1");
            resourceDef2 = new PartResourceDefinition("resource2");
            resourceDef3 = new PartResourceDefinition("resource3");

            TankResource tankResource1 = new TankResource();

            tankResource1.resourceDefinition = resourceDef1;
            TankResource tankResource2 = new TankResource();

            tankResource2.resourceDefinition = resourceDef1;
            TankResource tankResource3 = new TankResource();

            tankResource3.resourceDefinition = resourceDef2;

            TankType tankType1 = new TankType();

            tankType1.resources.Add(tankResource1);
            TankType tankType2 = new TankType();

            tankType2.resources.Add(tankResource2);
            tankType2.resources.Add(tankResource3);

            subtype1             = new PartSubtype();
            subtype1.subtypeName = "subtype1";
            subtype1.tankType    = tankType1;
            module.subtypes.Add(subtype1);

            subtype2             = new PartSubtype();
            subtype2.subtypeName = "subtype2";
            subtype2.tankType    = tankType2;
            module.subtypes.Add(subtype2);

            subtype3             = new PartSubtype();
            subtype3.subtypeName = "subtype3";
            subtype3.tankType    = B9TankSettings.StructuralTankType;
            module.subtypes.Add(subtype3);
        }
Exemplo n.º 9
0
        public void ResourceChanged(PartResource resource, double amount)
        {
            if (selectedTankType == null)
            {
                return;
            }

            TankResource tankResource = selectedTankType.resources.Find(r => r.name == name);

            if (tankResource == null || !tankResource.forceEmpty)
            {
                return;
            }

            if (resource != null && resource.amount > 0)
            {
                resource.amount = 0;
                InitialAmountChanged(resource, resource.amount);
            }
        }
Exemplo n.º 10
0
        private void ResourceChanged(string name, double amount)
        {
            if (selectedTankType == null)
            {
                return;
            }

            TankResource tankResource = selectedTankType.resources.Find(r => r.name == name);

            if (tankResource == null || !tankResource.forceEmpty)
            {
                return;
            }

            PartResource resource = part.Resources[name];

            if (resource != null && resource.amount > 0)
            {
                resource.amount = 0;
                InitialAmountChanged(resource.name, resource.amount);
            }
        }
        public void TestFindBestSubtype()
        {
            PartSubtype subtype1 = new PartSubtype();

            subtype1.subtypeName = "subtype1";
            subtype1.tankType    = B9TankSettings.StructuralTankType;
            module.subtypes.Add(subtype1);

            PartSubtype subtype2 = new PartSubtype();

            subtype2.subtypeName = "subtype2";
            subtype2.tankType    = B9TankSettings.StructuralTankType;
            module.subtypes.Add(subtype2);

            PartSubtype subtype3 = new PartSubtype();

            subtype3.subtypeName = "subtype3";
            subtype3.tankType    = B9TankSettings.StructuralTankType;
            module.subtypes.Add(subtype3);

            module.currentSubtypeName = "subtype2";

            module.OnStart(PartModule.StartState.Editor);

            assertEquals("Should identify the subtype by name", module.CurrentSubtype, subtype2);

            module.currentSubtypeName  = null;
            module.currentSubtypeIndex = 2;

            module.OnStart(PartModule.StartState.Editor);

            assertEquals("Should identify the subtype by index", module.CurrentSubtype, subtype3);

            PartResourceDefinition resourceDef1 = new PartResourceDefinition("resource1");
            PartResourceDefinition resourceDef2 = new PartResourceDefinition("resource2");
            PartResourceDefinition resourceDef3 = new PartResourceDefinition("resource3");

            TankResource tankResource1 = new TankResource();

            tankResource1.resourceDefinition = resourceDef1;
            TankResource tankResource2 = new TankResource();

            tankResource2.resourceDefinition = resourceDef1;
            TankResource tankResource3 = new TankResource();

            tankResource3.resourceDefinition = resourceDef2;

            TankType tankType1 = new TankType();

            tankType1.resources.Add(tankResource1);
            subtype1.tankType = tankType1;
            TankType tankType2 = new TankType();

            tankType2.resources.Add(tankResource2);
            tankType2.resources.Add(tankResource3);
            subtype2.tankType = tankType2;

            module.currentSubtypeName  = null;
            module.currentSubtypeIndex = -1;
            module.baseVolume          = 1f;
            module.OnStart(PartModule.StartState.Editor);

            assertEquals("It identifies a structural subtype when no resources present", module.CurrentSubtype, subtype3);

            PartResource partResource1 = part.AddResource(resourceDef3, 1f, 1f);

            module.currentSubtypeName  = null;
            module.currentSubtypeIndex = -1;
            module.OnStart(PartModule.StartState.Editor);

            assertEquals("It identifies a structural subtype when only an unmanaged resource present", module.CurrentSubtype, subtype3);

            PartResource partResource2 = part.AddResource(resourceDef1, 1f, 1f);
            PartResource partResource3 = part.AddResource(resourceDef2, 1f, 1f);

            module.currentSubtypeName  = null;
            module.currentSubtypeIndex = -1;
            module.OnStart(PartModule.StartState.Editor);

            assertEquals("It identifies the correct subtype by resources when present", module.CurrentSubtype, subtype2);

            part.RemoveResource(partResource2);

            module.currentSubtypeName  = null;
            module.currentSubtypeIndex = -1;
            module.OnStart(PartModule.StartState.Editor);

            assertEquals("It identifies the first subtype when subtype can't be determined from resources", module.CurrentSubtype, subtype1);
        }
Exemplo n.º 12
0
        public SwitcherSubtypeDescriptionGenerator(ModuleB9PartSwitch module)
        {
            module.ThrowIfNullArgument(nameof(module));
            this.module = module;

            Part partPrefab = module.part.GetPrefab();

            float prefabMass = partPrefab.mass;

            partDryMass = prefabMass + module.part.GetModuleMass(prefabMass);
            partWetMass = partDryMass + module.part.GetResourceMassMax();

            baseDryMass = partDryMass - module.GetDryMass(module.CurrentSubtype) - module.GetParentDryMass(module.CurrentSubtype);
            baseWetMass = partWetMass - module.GetWetMass(module.CurrentSubtype) - module.GetParentWetMass(module.CurrentSubtype);

            float prefabCost = module.part.partInfo.cost;

            partWetCost = prefabCost + module.part.GetModuleCosts(prefabCost);
            partDryCost = partWetCost - module.part.GetResourceCostMax();

            baseDryCost = partDryCost - module.GetDryCost(module.CurrentSubtype) - module.GetParentDryCost(module.CurrentSubtype);
            baseWetCost = partWetCost - module.GetWetCost(module.CurrentSubtype) - module.GetParentWetCost(module.CurrentSubtype);

            showWetMass  = module.ChangesResourceMass;
            showWetMass |= module.Parent?.CurrentTankType.ChangesResourceMass ?? false;

            showDryMass  = showWetMass;
            showDryMass |= module.ChangesDryMass;
            showDryMass |= (module.Parent?.CurrentTankType.tankMass ?? 0) != 0;

            showWetCost  = module.ChangesResourceCost;
            showWetCost |= module.Parent?.CurrentTankType.ChangesResourceCost ?? false;

            showDryCost  = showWetCost;
            showDryCost |= module.ChangesDryCost;
            showDryCost |= (module.Parent?.CurrentTankType.tankCost ?? 0) != 0;

            showMaxTemp        = module.HasPartAspectLock("maxTemp");
            showSkinMaxTemp    = module.HasPartAspectLock("skinMaxTemp");
            showCrashTolerance = module.HasPartAspectLock("crashTolerance");

            prefabMaxTemp        = (float)partPrefab.maxTemp;
            prefabSkinMaxTemp    = (float)partPrefab.skinMaxTemp;
            prefabCrashTolerance = partPrefab.crashTolerance;

            currentMaxTemp        = (float)module.part.maxTemp;
            currentSkinMaxTemp    = (float)module.part.skinMaxTemp;
            currentCrashTolerance = module.part.crashTolerance;

            float currentParentVolume = module.Parent?.GetTotalVolume(module.Parent.CurrentSubtype) ?? 0;

            baseParentVolume = currentParentVolume - (module.CurrentSubtype.volumeAddedToParent * module.VolumeScale);

            parentResources = new KeyValuePair <TankResource, float> [module.Parent?.CurrentTankType.resources.Count ?? 0];

            for (int i = 0; i < parentResources.Length; i++)
            {
                TankResource resource = module.Parent.CurrentTankType[i];
                parentResources[i] = new KeyValuePair <TankResource, float>(resource, resource.unitsPerVolume * currentParentVolume);
            }
        }