public override void OnStart(PartModule.StartState state) 
        {
            antimatter = part.Resources[InterstellarResourcesConfiguration.Instance.Antimatter];

            if (state == StartState.Editor) return;
            this.part.force_activate();
		}
 public override void OnStart(PartModule.StartState state) {
     uranium_mononitride = part.Resources["UraniumNitride"];
     depleted_fuel = part.Resources["DepletedFuel"];
     base.OnStart(state);
     initial_thermal_power = ThermalPower;
     initial_resource_rate = resourceRate;
 }
        public override void OnStart(PartModule.StartState state) {
            deuterium = part.Resources["Deuterium"];
            he3 = part.Resources["Helium-3"];
            un = part.Resources["EnrichedUranium"];
            base.OnStart(state);
            /*
            lightGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            lightGameObject.collider.enabled = false;
            lightGameObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
            lightGameObject.AddComponent<Light>();
            lightGameObject.renderer.material.shader = Shader.Find("Unlit/Transparent");
            lightGameObject.renderer.material.mainTexture = GameDatabase.Instance.GetTexture("Interstellar/explode2", false);
            lightGameObject.renderer.material.color = new Color(Color.white.r, Color.white.g, Color.white.b, 0.9f);
            lightGameObject.renderer.enabled = false;
            light = lightGameObject.light;
            lightGameObject.transform.position = part.transform.position;
            light.type = LightType.Point;
            light.color = new Color(Color.white.r, Color.white.g, 0.87f, 1f);
            light.range = 1f;
            light.intensity = 50.0f;
            light.renderMode = LightRenderMode.ForcePixel;
             
            convert_charged_to_thermal = false;
            Destroy (lightGameObject.collider, 0.25f);
            Destroy(lightGameObject, 0.1f);
            */
            antimatter_rate = resourceRate * GameConstants.antimatter_initiated_antimatter_cons_constant*86400/1000000;
            d_he3_rate = resourceRate * GameConstants.antimatter_initiated_d_he3_cons_constant*86400;
            un_rate = resourceRate * GameConstants.antimatter_initiated_eu_cons_constant*86400;
            upgraded_d_he3_rate = upgradedResourceRate * GameConstants.antimatter_initiated_upgraded_eu_cons_constant;
            upgraded_amat_rate = upgradedResourceRate * GameConstants.antimatter_initiated_antimatter_cons_constant * 86400 / 1000000;


        }
        public override void OnStart(PartModule.StartState state)
        {
            double time_diff = lastActiveTime - Planetarium.GetUniversalTime();

            if (state == StartState.Editor)
                return;

            if (part.Resources.Contains(resourceName))
                decay_resource = part.Resources[resourceName];
            else
            {
                decay_resource = null;
                return;
            }

            resourceDefinitionsContainDecayProduct = PartResourceLibrary.Instance.resourceDefinitions.Contains(decayProduct);
            if (resourceDefinitionsContainDecayProduct)
                density_rat = decay_resource.info.density / PartResourceLibrary.Instance.GetDefinition(decayProduct).density;

            if (decay_resource != null && time_diff > 0)
            {
                double n_0 = decay_resource.amount;
                decay_resource.amount = n_0 * Math.Exp(-decayConstant * time_diff);
                double n_change = n_0 - decay_resource.amount;

                if (resourceDefinitionsContainDecayProduct)
                    ORSHelper.fixedRequestResource(part, decayProduct, -n_change * density_rat);
            }
        }
 private void SetState(PartResource.FlowMode state)
 {
     List<string> blacklist = this.resourceBlacklist.Split(',').ToList();
     List<PartResource> valid = null;
     for (int i = 0; i < base.part.Resources.list.Count; i++)
     {
         PartResource res = base.part.Resources.list[i];
         if (!blacklist.Contains(res.resourceName) && res.info.resourceFlowMode != ResourceFlowMode.NO_FLOW)
         {
             if (this.resourceName == "ALL" || res.resourceName == this.resourceName)
             {
                 res.flowMode = state;
                 return;
             }
             else if (this.resourceName == "ANY")
             {
                 if (valid == null)
                 {
                     valid = new List<PartResource>();
                 }
                 valid.Add(res);
             }
         }
     }
     if (this.resourceName == "ANY" && valid != null)
     {
         Random ran = new Random();
         int roll = ran.Next(0, valid.Count);
         valid[roll].flowMode = state;
     }
 }
 public override void OnStart(PartModule.StartState state)
 {
     if (state == StartState.Editor) {
         return;
     }
     decay_resource = part.Resources[resourceName];
     part.force_activate();
 }
        // ReSharper disable ParameterHidesMember
        public override void Setup(UIPartActionWindow window, Part part, UI_Scene scene, UI_Control control, PartResource resource)
        {
            double amount = resource.amount;
            base.Setup(window, part, scene, control, resource);
            this.resource.amount = amount;

            slider.SetValueChangedDelegate(OnSliderChanged);
        }
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     resource = part.Resources[resourceName];
     if (isDecoupled)
     {
         Events["jettisonEvent"].active = false;
         Actions["jettisonAction"].active = false;
     }            
 }
Exemplo n.º 9
0
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor) { return; }
            this.part.force_activate();

            PartResourceList prl = part.Resources;

            foreach (PartResource wanted_resource in prl) {
                if (wanted_resource.resourceName == "IntakeAtm") {
                    intake_atm = wanted_resource;
                }
            }
        }
Exemplo n.º 10
0
        //This is a simple module that automatically converts recyclables into machinery.
        //It's primary use is for MKS Lite.
        public override void OnStart(StartState state)
        {
            if (!part.Resources.Contains("Machinery"))
                return;
            if (!part.Resources.Contains("Recyclables"))
                return;
            if (part.FindModulesImplementing<BaseConverter>().Count == 0)
                return;

            _convertResources = true;
            _inRes = part.Resources["Recyclables"];
            _outRes = part.Resources["Machinery"];
        }
Exemplo n.º 11
0
        public static PartResource AddResource(this Part part, PartResourceDefinition info, float maxAmount, float amount)
        {
            PartResource resource = new PartResource(part);
            resource.SetInfo(info);
            resource.maxAmount = maxAmount;
            resource.amount = amount;
            resource.flowState = true;
            resource.isTweakable = info.isTweakable;
            resource.isVisible = info.isVisible;
            resource.hideFlow = false;
            resource.flowMode = PartResource.FlowMode.Both;
            part.Resources.dict.Add(info.name.GetHashCode(), resource);

            return resource;
        }
Exemplo n.º 12
0
 public override void OnStart(PartModule.StartState state)
 {
     deuterium = part.Resources["Deuterium"];
     tritium = part.Resources["Tritium"];
     he3 = part.Resources["Helium-3"];
     Fields["fuelmodeStr"].guiActive = true;
     Fields["fuelmodeStr"].guiActiveEditor = true;
     initial_laser_consumption = powerRequirements;
     initial_resource_rate = resourceRate;
     setupFuelMode();
     base.OnStart(state);
     if (isupgraded) {
         Events["SwapFuelMode"].active = true;
         Events["SwapFuelMode"].guiActiveEditor = true;
     }
 }
Exemplo n.º 13
0
        public override void OnStart(StartState state)
        {
            // parent OnStart
            base.OnStart(state);

            // get current amount
            resource = Utils.getResourceByNameFromList(base.part.Resources, "ElectricCharge");
            if (resource != null)
            {
                lastAmount = resource.amount;
            }

            // get original amount
            String info = base.part.partInfo.resourceInfos[0].info.Replace("Amount: ", "");
            String[] infos = info.Split('M');
            originalMaxAmount = float.Parse(infos[0]);
        }
Exemplo n.º 14
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            GameEvents.onVesselChange.Add(new EventData<Vessel>.OnEvent(this.OnVesselChange));

            if (state == StartState.Editor)
            {
                Events["paintEvent"].active = false;
                return;
            }

            _paintResource = PartResourceLibrary.Instance.GetDefinition("SpacePaint");
            _paint = this.part.Resources.Get(_paintResource.id);
            setPaintState();

            if (Global.Debug3) Utils.Log("paint resource id: {0}", _paintResource);
            if (Global.Debug3) Utils.Log("paint: {0}/{1}", _paint.amount, _paint.maxAmount);
        }
        void RecalculateFuelAndMass()
        {
            PartResource fuel = part.Resources[ModSegSRBs.Propellant];

            if (fuel != null)
            {
                fuel.amount        =
                    fuel.maxAmount = MaxSolidFuel();
                Log.Info("RecalculateFuelAndMass, Propellant found: " + ModSegSRBs.Propellant + " fuel.maxAmount: " + fuel.maxAmount);
            }
            PartResource burnableFuel = part.Resources[ModSegSRBs.BurnablePropellant];

            if (burnableFuel != null)
            {
                burnableFuel.amount    = 0;
                burnableFuel.maxAmount = 0;
                Log.Info("RecalculateFuelAndMass, BurnablePropellant found: " + ModSegSRBs.BurnablePropellant + " fuel.maxAmount: " + fuel.maxAmount);
            }
            part.mass = (float)fuel.maxAmount * part.Resources[ModSegSRBs.Propellant].info.density;
        }
Exemplo n.º 16
0
        public double GetResource(string resourceName, Part part, double demand)
        {
            PartResource resource = part.Resources[resourceName];
            double       supplied = 0;

            if (resource.amount >= demand)
            {
                resource.amount -= demand;
                supplied        += demand;
            }

            else
            {
                supplied       += resource.amount;
                demand         -= resource.amount;
                resource.amount = 0;
            }

            return(supplied);
        }
Exemplo n.º 17
0
        void UpdateRocketScales()
        {
            // This is a backup method only, rockets will be rescaled to zero on firing,
            // so this will be called only on start and if something weird happens.
            PartResource rocketResource = GetRocketResource();
            var          rocketsLeft    = Math.Floor(rocketResource.amount);

            rocketsMax = rocketResource.maxAmount;
            for (int i = 0; i < rocketsMax; i++)
            {
                if (i < rocketsLeft)
                {
                    rockets[i].localScale = Vector3.one;
                }
                else
                {
                    rockets[i].localScale = Vector3.zero;
                }
            }
        }
Exemplo n.º 18
0
        private void GetAmmo()
        {
            double totalAmount = 0;

            foreach (var p in vessel.parts)
            {
                PartResource r = p.Resources.Where(pr => pr.resourceName == "CannonBalls").FirstOrDefault();
                if (r != null)
                {
                    totalAmount += r.amount;
                }
            }

            if (totalAmount > 0)
            {
                ammoCount = Convert.ToInt32(totalAmount);
            }

            StartCoroutine(LoadDelay());
        }
Exemplo n.º 19
0
 private void CheckRA()
 {
     foreach (var p in vessel.parts)
     {
         PartResource r = p.Resources.Where(n => n.resourceName == "ShieldPlasma").FirstOrDefault();
         if (r != null)
         {
             totalAmount += r.amount;
             maxAmount   += r.maxAmount;
             if (totalAmount < maxAmount * 0.05)
             {
                 resourceAvailable = false;
             }
             else
             {
                 resourceAvailable = true;
             }
         }
     }
 }
Exemplo n.º 20
0
        public double GetSnackResource(Part part, double demand)
        {
            PartResource resource = part.Resources[SnacksProperties.SnacksResourceName];
            double       supplied = 0;

            if (resource.amount >= demand)
            {
                resource.amount -= demand;
                supplied        += demand;
            }

            else
            {
                supplied       += resource.amount;
                demand         -= resource.amount;
                resource.amount = 0;
            }

            return(supplied);
        }
 public override void DoFailure()
 {
     base.DoFailure();
     if (this.ablator != null)
     {
         double total   = this.baseConductivity - this.ablatorConductivity;
         double remains = total - (this.ablator.reentryConductivity - this.ablatorConductivity);
         if (remains > 0)
         {
             Random ran     = new Random();
             double degrade = (double)ran.Next(this.minDegradation, this.maxDegradation + 1) * 0.01;
             this.ablator.reentryConductivity += Math.Min(remains, total * degrade);
             if (this.ablator.ablativeResource != string.Empty && base.part.Resources.Contains(this.ablator.ablativeResource))
             {
                 PartResource res = base.part.Resources[this.ablator.ablativeResource];
                 res.amount -= res.amount * degrade;
             }
         }
     }
 }
Exemplo n.º 22
0
 // Failure will drain the battery and stop it from recharging.
 protected override void FailPart()
 {
     battery           = part.Resources["ElectricCharge"];
     battery.amount    = 0;
     battery.flowState = false;
     if (OhScrap.highlight)
     {
         OhScrap.SetFailedHighlight();
     }
     if (message)
     {
         return;
     }
     if (vessel.vesselType != VesselType.Debris)
     {
         ScreenMessages.PostScreenMessage("Battery short circuited!");
     }
     Debug.Log("[OhScrap]: " + SYP.ID + " has suffered a short circuit failure");
     message = true;
 }
Exemplo n.º 23
0
 public Resource(T res)
 {
     if (res == null)
     {
         throw new NullReferenceException("Resource<T>: res cannot be null");
     }
     if (!(is_resource || is_proto))
     {
         throw new NotSupportedException("Resource<T>: T should be either " +
                                         "PartResource or ProtoPartResourceSnapshot");
     }
     if (is_resource)
     {
         this.res = (PartResource)(object)res;
     }
     else
     {
         pres = (ProtoPartResourceSnapshot)(object)res;
     }
 }
Exemplo n.º 24
0
        // Gets connected resources to a part. Note fuel lines are NOT reversible! Add flow going TO the constructing part!
        // Safe to pass any string for name - if specified resource does not exist, a Partresource with amount 0 will be returned
        public static List <PartResource> GetConnectedResources(Part part, String resourceName)
        {
            var resources = new List <PartResource>();

            // Only check for connected resources if a Resource Definition for that resource exists
            if (PartResourceLibrary.Instance.resourceDefinitions.Contains(resourceName) == true)
            {
                PartResourceDefinition res = PartResourceLibrary.Instance.GetDefinition(resourceName);
                part.GetConnectedResources(res.id, resources);
            }
            // Do not return an empty list - if none of the resource found, create resource item and set amount to 0
            if (resources.Count < 1)
            {
                PartResource p = new PartResource();
                p.resourceName = resourceName;
                p.amount       = (double)0;
                resources.Add(p);
            }
            return(resources);
        }
Exemplo n.º 25
0
        protected double GetMaxFuelAmt()
        {
            double max = 0d;

            if (fuels == null || fuels[0] == null)
            {
                GetFuelTypes();
            }

            for (int i = 0; i < fuels.Length; i++)
            {
                int          id  = PartResourceLibrary.Instance.GetDefinition(fuels[i]).id;
                PartResource res = pm.part.Resources.Get(id);
                if (res != null)
                {
                    max += res.maxAmount;
                }
            }
            return(max);
        }
Exemplo n.º 26
0
        private void UpsertResource(bool fillTanks, bool zeroAmount)
        {
            float maxAmount = getVolumeDelegate() * tankResource.unitsPerVolume;
            float amount;

            if (zeroAmount && fillTanks)
            {
                amount = 0f;
            }
            else
            {
                amount = maxAmount * filledProportion;
            }
            PartResource partResource = part.AddOrCreateResource(tankResource.resourceDefinition, maxAmount, amount, fillTanks);

            if (tweakable.HasValue)
            {
                partResource.isTweakable = tweakable.Value;
            }
        }
Exemplo n.º 27
0
        private void updatePartResources()
        {
            if (heatSoak)
            {
                return;
            }                        //dont touch resources on heat-soak type setups
            float        scale  = standAlonePart? Mathf.Pow(mainModelData.currentDiameterScale, resourceScalePower) : 1;
            float        amount = baseResourceQuantity * scale * currentShieldTypeData.resourceMult;
            PartResource res    = part.Resources[resourceName];

            if (res == null)
            {
                MonoBehaviour.print("SEVERE ERROR: ModularHeatShield could not set resource, as no resource was found in part for name: " + resourceName);
            }
            else
            {
                res.amount = res.maxAmount = amount;
            }
            SSTUModInterop.updatePartResourceDisplay(part);
        }
Exemplo n.º 28
0
        protected virtual void checkPartAmount(Part p, bool a)
        {
            if (!p.Resources.Contains(name))
            {
                return;
            }

            PartResource pr = p.Resources[name];

            if (a)
            {
                vesselACurrent += pr.amount;
                vesselAMax     += pr.maxAmount;
            }
            else
            {
                vesselBCurrent += pr.amount;
                vesselBMax     += pr.maxAmount;
            }
        }
Exemplo n.º 29
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);
            }
        }
        public override void OnStart(PartModule.StartState state) {
            if (state == StartState.Editor) {
                return;
            }
            decay_resource = part.Resources[resourceName];
            part.force_activate();   
            
            if (PartResourceLibrary.Instance.resourceDefinitions.Contains(decayProduct)) {
                density_rat = decay_resource.info.density / PartResourceLibrary.Instance.GetDefinition(decayProduct).density;
            }

			double time_diff = Planetarium.GetUniversalTime() - lastActiveTime;
            if (time_diff > 0) {
				double decay_amount = decayWithProductionRate(time_diff);
				ORSHelper.fixedRequestResource(part, decayProduct, -decay_amount*density_rat);
				decay_resource.amount -= decay_amount;
            }

			lastActiveTime = (float) Planetarium.GetUniversalTime();
        }
Exemplo n.º 31
0
        public static void RefillVesselResources(Vessel vessel)
        {
            if (vessel.parts == null)
            {
                return;
            }
            foreach (var part in vessel.parts)
            {
                //foreach(PartResource resource in part.Resources)
                int resourceCount = part.Resources.Count;
                for (int i = 0; i < resourceCount; ++i)
                {
                    PartResource resource = part.Resources[i];

                    part.TransferResource(resource.info.id, resource.maxAmount - resource.amount);
                    Utils.Log(
                        $"Refilled part \"{part.partName}\"'s resource \"{resource.resourceName}\" by requesting {resource.maxAmount - resource.amount} from it");
                }
            }
        }
Exemplo n.º 32
0
		void ToEVA(GameEvents.FromToAction<Part, Part> data)
		{
			// get total crew in the origin vessel
			double tot_crew = (double)Lib.CrewCount(data.from.vessel) + 1.0;

			// get vessel resources handler
			Vessel_resources resources = ResourceCache.Get(data.from.vessel);

			// setup supply resources capacity in the eva kerbal
			Profile.SetupEva(data.to);

			// for each resource in the kerbal
			for (int i = 0; i < data.to.Resources.Count; ++i)
			{
				// get the resource
				PartResource res = data.to.Resources[i];

				// determine quantity to take
				double quantity = Math.Min(resources.Info(data.from.vessel, res.resourceName).amount / tot_crew, res.maxAmount);

				// remove resource from vessel
				quantity = data.from.RequestResource(res.resourceName, quantity);

				// add resource to eva kerbal
				data.to.RequestResource(res.resourceName, -quantity);
			}

			// show warning if there isn't monoprop in the eva suit
			string prop_name = Lib.EvaPropellantName();
			if (Lib.Amount(data.to, prop_name) <= double.Epsilon && !Lib.Landed(data.from.vessel))
			{
				Message.Post(Severity.danger, Lib.BuildString("There isn't any <b>", prop_name, "</b> in the EVA suit"), "Don't let the ladder go!");
			}

			// turn off headlamp light, to avoid stock bug that show them for a split second when going on eva
			KerbalEVA kerbal = data.to.FindModuleImplementing<KerbalEVA>();
			EVA.HeadLamps(kerbal, false);

			// execute script
			DB.Vessel(data.from.vessel).computer.Execute(data.from.vessel, ScriptType.eva_out);
		}
Exemplo n.º 33
0
        private void tranfer_resource_shipwide(Vessel SourceShip, Vessel TargetShip, string resourceName, float demand)
        {
            PartResource SourcepartResource = null;
            PartResource TargetpartResource = null;

            foreach (Part p in SourceShip.Parts)
            {
                if (SourcepartResource != null)
                {
                    continue;
                }
                PartResourceList pRL = p.Resources;
                foreach (PartResource pr in pRL)
                {
                    if (pr.resourceName == resourceName && pr.amount > 0)
                    {
                        SourcepartResource = pr;
                    }
                }
            }
            foreach (Part p2 in TargetShip.Parts)
            {
                if (TargetpartResource != null)
                {
                    continue;
                }
                PartResourceList pRL2 = p2.Resources;
                foreach (PartResource pr2 in pRL2)
                {
                    if (pr2.resourceName == resourceName && (pr2.maxAmount - pr2.amount) > 0)
                    {
                        TargetpartResource = pr2;
                    }
                }
            }
            tranfer_resource(SourcepartResource, TargetpartResource, demand);

            float power = demand * PT1.L2_usage;

            this.PowSys.draw(PT1.takerName, power);
        }
        public double ReprocessFuel(double rate)
        {
            if (part.Resources.Contains(InterstellarResourcesConfiguration.Instance.Actinides))
            {
                PartResource actinides            = part.Resources[InterstellarResourcesConfiguration.Instance.Actinides];
                double       new_actinides_amount = Math.Max(actinides.amount - rate, 0);
                double       actinides_change     = actinides.amount - new_actinides_amount;
                actinides.amount = new_actinides_amount;

                double depleted_fuels_request = actinides_change * 0.2;

                //depleted_fuels_change = -ORSHelper.fixedRequestResource(part, InterstellarResourcesConfiguration.Instance.DepletedFuel, -depleted_fuels_change);
                double depleted_fuels_produced = -Part.RequestResource(depletedFuelDefinition.id, -depleted_fuels_request, ResourceFlowMode.STAGE_PRIORITY_FLOW);

                // first try to replace depletedfuel with enriched uranium
                double enrichedUraniumRequest          = depleted_fuels_produced * enrichedUraniumVolumeMultiplier;
                double enrichedUraniumRetrieved        = Part.RequestResource(enrichedUraniumDefinition.id, enrichedUraniumRequest, ResourceFlowMode.STAGE_PRIORITY_FLOW);
                double receivedEnrichedUraniumFraction = enrichedUraniumRequest > 0 ? enrichedUraniumRetrieved / enrichedUraniumRequest : 0;

                // if missing fluorine is dumped
                double oxygenChange   = -Part.RequestResource(oxygenGasDefinition.id, -depleted_fuels_produced * oxygenDepletedUraniumVolumeMultipler * receivedEnrichedUraniumFraction, ResourceFlowMode.STAGE_PRIORITY_FLOW);
                double fluorineChange = -Part.RequestResource(fluorineGasDefinition.id, -depleted_fuels_produced * fluorineDepletedFuelVolumeMultiplier * (1 - receivedEnrichedUraniumFraction), ResourceFlowMode.STAGE_PRIORITY_FLOW);

                var reactorFuels = CurrentFuelMode.Variants.First().ReactorFuels;

                double sum_useage_per_mw = reactorFuels.Sum(fuel => fuel.AmountFuelUsePerMJ * fuelUsePerMJMult);

                foreach (ReactorFuel fuel in reactorFuels)
                {
                    PartResource fuel_resource = part.Resources[fuel.ResourceName];

                    double powerFraction = sum_useage_per_mw > 0.0 ? fuel.AmountFuelUsePerMJ * fuelUsePerMJMult / sum_useage_per_mw : 1;

                    double new_fuel_amount = Math.Min(fuel_resource.amount + ((depleted_fuels_produced * 4) + (depleted_fuels_produced * receivedEnrichedUraniumFraction)) * powerFraction * depletedToEnrichVolumeMultplier, fuel_resource.maxAmount);
                    fuel_resource.amount = new_fuel_amount;
                }

                return(actinides_change);
            }
            return(0);
        }
Exemplo n.º 35
0
        public override void upgradeValue(Part p, float value)
        {
            //Debug.log("[MUR] upgradeValue " + p.name + " rn=" + resourceName);
            if (resourceName == null || resourceName.Length == 0)
            {
                return;
            }
            foreach (PartResource pr in p.Resources)
            {
                //Debug.log("[MUR] has resource " + pr.resourceName + ", " + pr.maxAmount);
            }
            PartResource resource = p.Resources[resourceName];

            if (resource == null)
            {
                //create the resource
                resource = addResource(p, resourceName, value, value);
                //Debug.log("[MUR] addresource");
                if (resource == null)
                {
                    //Debug.logError("Error: cannot add resource " + resourceName + " to " + p.name + " because this resource don't exist.");
                    return;
                }
                AvailablePart.ResourceInfo newInfo = new AvailablePart.ResourceInfo();
                newInfo.resourceName = addSpaces(resource.resourceName);
                p.partInfo.resourceInfos.Add(newInfo);
                //Debug.log("[MUR] addresource info : " + newInfo.resourceName);
            }
            else
            {
                resource.maxAmount = (float)(/*resource.maxAmount + */ value);
                resource.amount    = (float)(/*resource.amount + */ value);
                //Debug.log("[MUR] better amount ");
            }
            foreach (PartResource pr in p.Resources)
            {
                //Debug.log("[MUR] has resource (before) " + pr.resourceName + ", " + pr.maxAmount);
            }
            //reload partinfo
            updateInfo(p, resource);
        }
        void FixedUpdate()
        {
            if (activeCount == 0 || FlightGlobals.ActiveVessel == null)
            {
                return;
            }

            if (FlightGlobals.ActiveVessel.id != currentVessel)
            {
                currentVessel = FlightGlobals.ActiveVessel.id;
                checks        = 0;
                partCount     = -1;
            }

            foreach (PartResourceDefinition resource in resources)
            {
                int    localCount = 0;
                double quantity   = 0.0;
                foreach (Part part in FlightGlobals.ActiveVessel.Parts)
                {
                    localCount++;
                    PartResource pr = part.Resources[resource.name];
                    if (pr != null)
                    {
                        quantity += pr.amount;
                    }
                }

                if (partCount == -1)
                {
                    partCount = localCount;
                }
                // Reset counter on vessel change
                if (partCount != localCount)
                {
                    checks = 0;
                }

                checkValues[resource][checks++ % CHECK_SIZE] = quantity;
            }
        }
Exemplo n.º 37
0
        // this is an unbelievable hack, but it's the only thing i've found that works
        /// <summary>
        /// Loads requirements from given config node
        /// </summary>
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            var pList = PartResourceLibrary.Instance.resourceDefinitions;

            foreach (ConfigNode resNode in node.GetNodes("REQUIREMENT"))
            {
                try
                {
                    string name = resNode.GetValue("name");
                    float  amt  = float.Parse(resNode.GetValue("maxAmount"));
                    requirements.Add(name, new Requirement(name, amt));

                    // check if this resource can be pumped
                    var def = pList[name];
                    if (def.resourceTransferMode != ResourceTransferMode.NONE)
                    {
                        // add the resource so it can be pre-filled in the VAB
                        PartResource resource = part.AddResource(resNode);

                        // but remove it so it doesn't show up in the info box in the VAB
                        part.Resources.Remove(resource);
                    }
                }
                catch { }
            }
            // Following needed to maintain compatibility with older parts
            if (eurekasRequired > 0 && !requirements.ContainsKey(EUREKAS))
            {
                requirements.Add(EUREKAS, new Requirement(EUREKAS, eurekasRequired));
            }
            if (kuarqsRequired > 0 && !requirements.ContainsKey(KUARQS))
            {
                requirements.Add(KUARQS, new Requirement(KUARQS, kuarqsRequired));
            }
            if (bioproductsRequired > 0 && !requirements.ContainsKey(BIOPRODUCTS))
            {
                requirements.Add(BIOPRODUCTS, new Requirement(BIOPRODUCTS, bioproductsRequired));
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            double time_diff = lastActiveTime - Planetarium.GetUniversalTime();

            if (state == StartState.Editor)
            {
                return;
            }

            if (part.Resources.Contains(resourceName))
            {
                decay_resource = part.Resources[resourceName];
            }
            else
            {
                decay_resource = null;
                return;
            }

            resourceDefinitionsContainDecayProduct = PartResourceLibrary.Instance.resourceDefinitions.Contains(decayProduct);
            if (resourceDefinitionsContainDecayProduct)
            {
                var decay_density = PartResourceLibrary.Instance.GetDefinition(decayProduct).density;
                if (decay_density > 0 && decay_resource.info.density > 0)
                {
                    density_rat = decay_resource.info.density / PartResourceLibrary.Instance.GetDefinition(decayProduct).density;
                }
            }

            if (!CheatOptions.UnbreakableJoints && decay_resource != null && time_diff > 0)
            {
                double n_0 = decay_resource.amount;
                decay_resource.amount = n_0 * Math.Exp(-decayConstant * time_diff);
                double n_change = n_0 - decay_resource.amount;

                if (resourceDefinitionsContainDecayProduct && n_change > 0)
                {
                    part.RequestResource(decayProduct, -n_change * density_rat);
                }
            }
        }
Exemplo n.º 39
0
        public override void OnStart(PartModule.StartState state)
        {
            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT, FNResourceManager.FNRESOURCE_MEGAJOULES };
            previousTimeWarp         = TimeWarp.fixedDeltaTime;
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);

            if (state == StartState.Editor)
            {
                return;
            }
            solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>();

            if (solarPanel != null)
            {
                if (solarPanel.resourceName == FNResourceManager.FNRESOURCE_MEGAJOULES)
                {
                    outputType = resourceType.megajoule;

                    megajoulePartResource = part.Resources[FNResourceManager.FNRESOURCE_MEGAJOULES];
                    if (megajoulePartResource != null)
                    {
                        fixedMegajouleBufferSize = megajoulePartResource.maxAmount * 50;
                    }
                }
                else if (solarPanel.resourceName == FNResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
                {
                    outputType = resourceType.electricCharge;

                    electricChargePartResource = part.Resources[FNResourceManager.STOCK_RESOURCE_ELECTRICCHARGE];
                    if (electricChargePartResource != null)
                    {
                        fixedElectricChargeBufferSize = electricChargePartResource.maxAmount * 50;
                    }
                }
                else
                {
                    outputType = resourceType.other;
                }
            }
        }
Exemplo n.º 40
0
        private float CalculateExplosionProbability(Part part)
        {
            ///////////////////////////////////////////////////////////////
            float probability = 0;
            float fuelPct     = 0;

            for (int i = 0; i < part.Resources.Count; i++)
            {
                PartResource current = part.Resources[i];
                switch (current.resourceName)
                {
                case "LiquidFuel":
                    fuelPct = (float)(current.amount / current.maxAmount);
                    break;
                    //case "Oxidizer":
                    //   probability += (float) (current.amount/current.maxAmount);
                    //    break;
                }
            }

            if (fuelPct > 0 && fuelPct <= 0.60f)
            {
                probability = Core.Utils.BDAMath.RangedProbability(new[] { 50f, 25f, 20f, 5f });
            }
            else
            {
                probability = Core.Utils.BDAMath.RangedProbability(new[] { 50f, 25f, 20f, 2f });
            }

            if (fuelPct == 1f || fuelPct == 0f)
            {
                probability = 0f;
            }

            if (BDArmorySettings.DRAW_DEBUG_LABELS)
            {
                Debug.Log("[BDArmory]: Explosive Probablitliy " + probability);
            }

            return(probability);
        }
Exemplo n.º 41
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            //Get the intake transforms
            if (!string.IsNullOrEmpty(intakeTransformName))
            {
                intakeTransforms = this.part.FindModelTransforms(intakeTransformName).ToArray();
            }

            //Grab the base buoyancy
            //Actual buoyancy will vary depending upon how much ballast is in the tank.
            baseBuoyancy = this.part.buoyancy;

            //Get the ballast resource & host part
            if (!string.IsNullOrEmpty(ballastResourceName))
            {
                //Check this part
                if (this.part.Resources.Contains(ballastResourceName))
                {
                    resourceBallast = this.part.Resources[ballastResourceName];
                    hostPart        = this.part;
                }

                //Check parent part
                else if (this.part.parent.Resources.Contains(ballastResourceName))
                {
                    resourceBallast = this.part.parent.Resources[ballastResourceName];
                    hostPart        = this.part.parent;
                }

                //Vent behavior applies to all ballast tanks as we can't find any that has the ballast resource.
                else
                {
                    hostPart        = this.part;
                    resourceBallast = null;
                }
            }

            updateGUI();
        }
Exemplo n.º 42
0
        protected void OnExperimentReceived(WBIModuleScienceExperiment transferRecipient)
        {
            ConfigNode   nodeResource = null;
            PartResource resource     = null;
            string       resourceName;

            string[] mapKeys;
            int      index;

            //If the experiment has resources then go through them and either add
            //the resources it needs or increase the max amount
            if (transferRecipient.resourceMap != null)
            {
                mapKeys = transferRecipient.resourceMap.Keys.ToArray <string>();
                for (index = 0; index < mapKeys.Length; index++)
                {
                    resourceName = mapKeys[index];

                    //Add the resource if needed
                    if (this.part.Resources.Contains(resourceName) == false)
                    {
                        nodeResource = new ConfigNode("RESOURCE");
                        nodeResource.AddValue("name", resourceName);
                        nodeResource.AddValue("amount", "0");
                        nodeResource.AddValue("maxAmount", transferRecipient.resourceMap[resourceName].targetAmount.ToString());
                        resource             = this.part.Resources.Add(nodeResource);
                        resource.isVisible   = false;
                        resource.isTweakable = false;
                    }

                    //Add to max amount to account for amount that the experiment needs
                    else
                    {
                        this.part.Resources[resourceName].maxAmount += transferRecipient.resourceMap[resourceName].targetAmount;
                    }
                }

                //Dirty the GUI
                MonoUtilities.RefreshContextWindows(this.part);
            }
        }
Exemplo n.º 43
0
        private bool AddRemoveSoil(Part p, double value)
        {
            Debug.Log("adding soil:" + value);
            List <PartResource> resources = new List <PartResource>();

            p.GetConnectedResources(soilResourceId, ResourceFlowMode.ALL_VESSEL, resources);
            PartResource pr = resources.First();

            pr.amount += value;
            if (pr.amount < 0)
            {
                pr.amount = 0;
            }
            if (pr.amount >= pr.maxAmount)
            {
                pr.amount = pr.maxAmount;
                return(true);
            }
            p.mass = Convert.ToSingle(kerbalMass + pr.amount * kerbalMass);
            return(false);
        }
Exemplo n.º 44
0
		void FromEVA(GameEvents.FromToAction<Part, Part> data)
		{
			// for each resource in the eva kerbal
			for (int i = 0; i < data.from.Resources.Count; ++i)
			{
				// get the resource
				PartResource res = data.from.Resources[i];

				// add leftovers to the vessel
				data.to.RequestResource(res.resourceName, -res.amount);
			}

			// merge drives data
			Drive.Transfer(data.from.vessel, data.to.vessel);

			// forget vessel data
			DB.vessels.Remove(Lib.RootID(data.from.vessel));

			// execute script
			DB.Vessel(data.to.vessel).computer.Execute(data.to.vessel, ScriptType.eva_in);
		}
Exemplo n.º 45
0
        void DropFlare()
        {
            PartResource cmResource = GetCMResource();

            if (cmResource && cmResource.amount >= 1)
            {
                cmResource.amount--;
                audioSource.pitch = UnityEngine.Random.Range(0.9f, 1.1f);
                audioSource.PlayOneShot(cmSound);

                GameObject cm = flarePool.GetPooledObject();
                cm.transform.position = transform.position;
                CMFlare cmf = cm.GetComponent <CMFlare>();
                cmf.startVelocity = part.rb.velocity + (ejectVelocity * transform.up) + (UnityEngine.Random.Range(-3f, 3f) * transform.forward) + (UnityEngine.Random.Range(-3f, 3f) * transform.right);
                cmf.sourceVessel  = vessel;

                cm.SetActive(true);

                FireParticleEffects();
            }
        }
        /// <summary>
        /// Called when this part is started.
        /// </summary>
        /// <param name="state">The start state.</param>
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart(state);

            foreach (PartResource r in part.Resources)
            {
                if (r.resourceName == "RocketParts")
                {
                    rocketParts = r;
                    break;
                }
            }

            if (!rocketParts)
            {
                Logger.DebugError("Cannot find RocketParts resource on \"" + part.name + "\"!");
            }

            rocketParts.flowMode = PartResource.FlowMode.Both;
            part.fuelCrossFeed = false;
        }
        public override void OnStart(PartModule.StartState state)
        {
            containerStates = SetUpAnimation(ContainerAnimationName, this.part);

            foreach(PartResource pr in part.Resources)  //finds which resource has been specified
            {
                if (pr.resourceName.Equals (ResourceType))
                {
                    animatedResource = pr;
                    break;
                }
            }

            resMax = animatedResource.maxAmount;
            resAmount = animatedResource.amount;
            normalizedRes = resAmount/resMax;
            foreach (var cs in containerStates)
            {
                cs.normalizedTime = (float)normalizedRes;
            }
        }
Exemplo n.º 48
0
 public override void OnStart(PartModule.StartState state) {
     pu238 = part.Resources["Plutonium-238"];
     resourceRate = (float)(GameConstants.plutonium_238_decay_constant * pu238.maxAmount);
     base.OnStart(state);
 }
Exemplo n.º 49
0
 protected void setUraniumFuel() {
     fuel_resource = uf4;
     fuelmodeStr = "Uranium";
     ThermalPower = (float)(initial_thermal_power);
     resourceRate = (float)(initial_resource_rate);
     uranium_fuel = true;
 }
Exemplo n.º 50
0
 protected void setThoriumFuel() {
     fuel_resource = thf4;
     fuelmodeStr = "Thorium";
     ThermalPower = (float)(initial_thermal_power * GameConstants.thorium_power_output_ratio);
     resourceRate = (float)(initial_resource_rate * GameConstants.thorium_resource_burnrate_ratio);
     uranium_fuel = false;
 }
Exemplo n.º 51
0
 public override void OnStart(PartModule.StartState state) {
     uf4 = part.Resources["UF4"];
     thf4 = part.Resources["ThF4"];
     actinides = part.Resources["Actinides"];
     Fields["fuelmodeStr"].guiActiveEditor = true;
     if (double.IsNaN(uf4.amount)) {
         uf4.amount = 0;
     }
     if (double.IsNaN(thf4.amount)) {
         thf4.amount = 0;
     }
     if (double.IsNaN(actinides.amount)) {
         actinides.amount = actinides.maxAmount;
     }
     if (!upgradedToV08) {
         upgradedToV08 = true;
         actinides.amount = actinides.maxAmount - uf4.amount;
     }
     if (!upgradedToV10 && state != PartModule.StartState.Editor) {
         upgradedToV10 = true;
         actinides.amount = actinides.amount * 1000;
         actinides.maxAmount = actinides.maxAmount * 1000;
         uf4.amount = uf4.amount * 1000;
         uf4.maxAmount = uf4.maxAmount * 1000;
         thf4.amount = thf4.amount * 1000;
         thf4.maxAmount = thf4.maxAmount * 1000;
     } else if (!upgradedToV10 && state == PartModule.StartState.Editor) {
         upgradedToV10 = true;
     }
     if (uranium_fuel) {
         fuel_resource = uf4;
     } else {
         fuel_resource = thf4;
     }
     base.OnStart(state);
     initial_thermal_power = ThermalPower;
     initial_resource_rate = resourceRate;
     if (uranium_fuel) {
         setUraniumFuel();
     } else {
         setThoriumFuel();
     }
 }
Exemplo n.º 52
0
 public override void OnStart(PartModule.StartState state) {
     _intake_atm = part.Resources.Contains(InterstellarResourcesConfiguration.Instance.IntakeAtmosphere) ? part.Resources[InterstellarResourcesConfiguration.Instance.IntakeAtmosphere] : null;
 }
Exemplo n.º 53
0
		public void Add(PartResource pr) {
			amount += pr.amount;
			maxAmount += pr.maxAmount;
		}
Exemplo n.º 54
0
 public ResourceValue(PartResource partResource)
     : this(partResource.resourceName)
 {
     amount = partResource.amount;
     capacity = partResource.maxAmount;
 }
Exemplo n.º 55
0
 public void AddResource(PartResource resource)
 {
     amount += resource.amount;
     capacity += resource.maxAmount;
 }
        private void SetResourceItems()
        {
            bool visibleResources = false;
            for (int i = 0; i < selectedPart.Resources.dict.Count; ++i)
            {
                if (selectedPart.Resources.dict.At(i).hideFlow == false)
                {
                    visibleResources = true;
                    break;
                }
            }
            if (visibleResources)
            {
                infoItems.Add(PartInfoItem.Create("Resources"));
                for (int i = 0; i < selectedPart.Resources.dict.Count; ++i)
                {
                    partResource = selectedPart.Resources.dict.At(i);

                    if (partResource.hideFlow == false)
                    {
                        infoItems.Add(partResource.GetDensity() > 0
                            ? PartInfoItem.Create("\t" + partResource.info.name, "(" + partResource.GetMass().ToMass() + ") " + partResource.amount.ToString("F1"))
                            : PartInfoItem.Create("\t" + partResource.info.name, partResource.amount.ToString("F1")));
                    }
                }
            }
        }
Exemplo n.º 57
0
 public CommonResource(PartResource targetResource, List<PartResource> localResList)
 {
     this.TargetPartResource = targetResource;
     this.LocalPartResources = localResList;
 }
Exemplo n.º 58
0
        public override void OnStart(PartModule.StartState state)
        {
            print("[KSP Interstellar]  Generator OnStart Begin " + startcount);

            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_MEGAJOULES, FNResourceManager.FNRESOURCE_WASTEHEAT };
            this.resources_to_supply = resources_to_supply;

            if (state == PartModule.StartState.Docked)
            {
                base.OnStart(state);
                return;
            }

            // calculate WasteHeat Capacity
            var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);
            if (wasteheatPowerResource != null)
            {
                var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount;
                wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                wasteheatPowerResource.amount = wasteheatPowerResource.maxAmount * ratio;
            }

            previousTimeWarp = TimeWarp.fixedDeltaTime - 1.0e-6f;
            megajouleResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_MEGAJOULES);

            base.OnStart(state);
            generatorType = originalName;

            Fields["maxChargedPower"].guiActive = chargedParticleMode;
            Fields["maxThermalPower"].guiActive = !chargedParticleMode;

            if (state == StartState.Editor)
            {
                if (this.HasTechsRequiredToUpgrade())
                {
                    isupgraded = true;
                    hasrequiredupgrade = true;
                    upgradePartModule();
                }
                part.OnEditorAttach += OnEditorAttach;
                return;
            }

            if (this.HasTechsRequiredToUpgrade())
                hasrequiredupgrade = true;

            this.part.force_activate();

            anim = part.FindModelAnimators(animName).FirstOrDefault();
            if (anim != null)
            {
                anim[animName].layer = 1;
                if (!IsEnabled)
                {
                    anim[animName].normalizedTime = 1f;
                    anim[animName].speed = -1f;
                }
                else
                {
                    anim[animName].normalizedTime = 0f;
                    anim[animName].speed = 1f;
                }
                anim.Play();
            }

            if (generatorInit == false)
            {
                generatorInit = true;
                IsEnabled = true;
            }

            if (isupgraded)
                upgradePartModule();

            FindAttachedThermalSource();

            UpdateHeatExchangedThrustDivisor();

            print("[KSP Interstellar]  Generator OnStart Finished");
        }
 public static void LockFuelTank()
 {
     SelectedResource = null;
     SelectedTank = null;
     bLqFIn = false;
     bLqFOut = false;
     bOxFIn = false;
     bOxFOut = false;
     bMoFIn = false;
     bMoFOut = false;
 }
        public static void FuelTanksInterface(StaticObject selectedObject)
        {
            string smessage = "";
            ScreenMessageStyle smsStyle = (ScreenMessageStyle)2;

            string sFacilityName = (string)selectedObject.model.getSetting("title");
            string sFacilityRole = (string)selectedObject.getSetting("FacilityType");

            fLqFMax = (float)selectedObject.model.getSetting("LqFMax");
            fLqFCurrent = (float)selectedObject.getSetting("LqFCurrent");
            fOxFMax = (float)selectedObject.model.getSetting("OxFMax");
            fOxFCurrent = (float)selectedObject.getSetting("OxFCurrent");
            fMoFMax = (float)selectedObject.model.getSetting("MoFMax");
            fMoFCurrent = (float)selectedObject.getSetting("MoFCurrent");

            float fPurchaseRate = fTransferRate * 100f;

            LabelInfo = new GUIStyle(GUI.skin.label);
            LabelInfo.normal.background = null;
            LabelInfo.normal.textColor = Color.white;
            LabelInfo.fontSize = 13;
            LabelInfo.fontStyle = FontStyle.Bold;
            LabelInfo.padding.left = 3;
            LabelInfo.padding.top = 0;
            LabelInfo.padding.bottom = 0;

            BoxInfo = new GUIStyle(GUI.skin.box);
            BoxInfo.normal.textColor = Color.cyan;
            BoxInfo.fontSize = 13;
            BoxInfo.padding.top = 2;
            BoxInfo.padding.bottom = 1;
            BoxInfo.padding.left = 5;
            BoxInfo.padding.right = 5;
            BoxInfo.normal.background = null;

            if (!FlightGlobals.ActiveVessel.Landed)
            {
                GUILayout.Box("A vessel must be landed to use this facility.", BoxInfo);
                LockFuelTank();
            }

            var vDist = Vector3.Distance(selectedObject.gameObject.transform.position, FlightGlobals.ActiveVessel.transform.position);

            if ((double)vDist < KerbalKonstructs.instance.facilityUseRange)
            { }
            else
            {
                GUILayout.Box("A vessel must be in range to use this facility.", BoxInfo);
                LockFuelTank();
            }

            GUILayout.Space(3);
            GUILayout.Label("Fuel Stores", LabelInfo);
            scrollPos4 = GUILayout.BeginScrollView(scrollPos4);
            if (fLqFMax > 0)
            {
                GUILayout.Label("LiquidFuel", LabelInfo);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(string.Format("{0}", fLqFMax), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.Label("Current ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(fLqFCurrent.ToString("#0.00"), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Order", GUILayout.Height(18)))
                {
                    LockFuelTank();
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedLqF = true;
                }
                GUI.enabled = !bLqFIn;
                if (GUILayout.Button("In", GUILayout.Height(18)))
                {
                    bLqFIn = true;
                    bLqFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = !bLqFOut;
                if (GUILayout.Button("Out", GUILayout.Height(18)))
                {
                    bLqFOut = true;
                    bLqFIn = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = bLqFIn || bLqFOut;
                if (GUILayout.Button("Stop", GUILayout.Height(18)))
                {
                    bLqFIn = false;
                    bLqFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer stopped";
                    ScreenMessages.PostScreenMessage(smessage, 10, smsStyle);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();
            }

            if (bOrderedLqF)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.RepeatButton("-", GUILayout.Height(18)))
                {
                    fLqFAmount = (float.Parse(fLqFAmount) - fPurchaseRate).ToString();
                    if ((float.Parse(fLqFAmount)) < 0f) fLqFAmount = "0.00";
                }
                GUI.enabled = false;
                GUILayout.TextField(fLqFAmount, GUILayout.Height(18));
                GUI.enabled = true;
                if (GUILayout.RepeatButton("+", GUILayout.Height(18)))
                {
                    fLqFAmount = (float.Parse(fLqFAmount) + fPurchaseRate).ToString();
                    if ((float.Parse(fLqFAmount)) > (fLqFMax - fLqFCurrent)) fLqFAmount = (fLqFMax - fLqFCurrent).ToString();
                }

                if (GUILayout.Button("Max", GUILayout.Height(18)))
                {
                    fLqFAmount = (fLqFMax - fLqFCurrent).ToString();
                    if ((float.Parse(fLqFAmount)) < 0f) fLqFAmount = "0.00";
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }

                float flqFPrice = 0.5f;

                float fLqFCost = (float.Parse(fLqFAmount)) * flqFPrice;
                GUILayout.Label("Cost: " + fLqFCost.ToString("#0") + " \\F", LabelInfo);
                if (GUILayout.Button("Buy", GUILayout.Height(18)))
                {
                    if ((float)selectedObject.getSetting("LqFCurrent") + (float.Parse(fLqFAmount)) > fLqFMax)
                    {
                        ScreenMessages.PostScreenMessage("Insufficient fuel capacity!", 10, 0);
                        fLqFAmount = "0.00";
                    }
                    else
                    {
                        if (MiscUtils.isCareerGame())
                        {
                            double currentfunds = Funding.Instance.Funds;

                            if (fLqFCost > currentfunds)
                            {
                                ScreenMessages.PostScreenMessage("Insufficient funds!", 10, 0);
                            }
                            else
                            {
                                Funding.Instance.AddFunds(-fLqFCost, TransactionReasons.Cheating);
                                selectedObject.setSetting("LqFCurrent", (float)selectedObject.getSetting("LqFCurrent") + (float.Parse(fLqFAmount)));
                            }
                        }
                        else
                        {
                            selectedObject.setSetting("LqFCurrent", (float)selectedObject.getSetting("LqFCurrent") + (float.Parse(fLqFAmount)));
                        }
                    }

                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                if (GUILayout.Button("Done", GUILayout.Height(18)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedLqF = false;
                }
                GUILayout.EndHorizontal();
            }

            if (fOxFMax > 0)
            {
                GUILayout.Label("Oxidizer", LabelInfo);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(string.Format("{0}", fOxFMax), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.Label("Current ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(fOxFCurrent.ToString("#0.00"), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Order", GUILayout.Height(18)))
                {
                    LockFuelTank();
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedOxF = true;
                }
                GUI.enabled = !bOxFIn;
                if (GUILayout.Button("In", GUILayout.Height(18)))
                {
                    bOxFIn = true;
                    bOxFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = !bOxFOut;
                if (GUILayout.Button("Out", GUILayout.Height(18)))
                {
                    bOxFOut = true;
                    bOxFIn = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = bOxFIn || bOxFOut;
                if (GUILayout.Button("Stop", GUILayout.Height(18)))
                {
                    bOxFIn = false;
                    bOxFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer stopped";
                    ScreenMessages.PostScreenMessage(smessage, 10, smsStyle);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();
            }

            if (bOrderedOxF)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.RepeatButton("-", GUILayout.Height(18)))
                {
                    fOxFAmount = (float.Parse(fOxFAmount) - fPurchaseRate).ToString();
                    if ((float.Parse(fOxFAmount)) < 0f) fOxFAmount = "0.00";
                }
                GUI.enabled = false;
                GUILayout.TextField(fOxFAmount, GUILayout.Height(18));
                GUI.enabled = true;
                if (GUILayout.RepeatButton("+", GUILayout.Height(18)))
                {
                    fOxFAmount = (float.Parse(fOxFAmount) + fPurchaseRate).ToString();
                    if ((float.Parse(fOxFAmount)) > (fOxFMax - fOxFCurrent)) fOxFAmount = (fOxFMax - fOxFCurrent).ToString();
                }

                if (GUILayout.Button("Max", GUILayout.Height(18)))
                {
                    fOxFAmount = (fOxFMax - fOxFCurrent).ToString();
                    if ((float.Parse(fOxFAmount)) < 0f) fOxFAmount = "0.00";
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }

                float fOxFPrice = 1.5f;

                float fOxFCost = (float.Parse(fOxFAmount)) * fOxFPrice;
                GUILayout.Label("Cost: " + fOxFCost.ToString("#0") + " \\F", LabelInfo);
                if (GUILayout.Button("Buy", GUILayout.Height(18)))
                {
                    if ((float)selectedObject.getSetting("OxFCurrent") + (float.Parse(fOxFAmount)) > fOxFMax)
                    {
                        ScreenMessages.PostScreenMessage("Insufficient fuel capacity!", 10, 0);
                        fOxFAmount = "0.00";
                    }
                    else
                    {
                        if (MiscUtils.isCareerGame())
                        {
                            double currentfunds = Funding.Instance.Funds;

                            if (fOxFCost > currentfunds)
                            {
                                ScreenMessages.PostScreenMessage("Insufficient funds!", 10, 0);
                            }
                            else
                            {
                                Funding.Instance.AddFunds(-fOxFCost, TransactionReasons.Cheating);
                                selectedObject.setSetting("OxFCurrent", (float)selectedObject.getSetting("OxFCurrent") + (float.Parse(fOxFAmount)));
                            }
                        }
                        else
                        {
                            selectedObject.setSetting("OxFCurrent", (float)selectedObject.getSetting("OxFCurrent") + (float.Parse(fOxFAmount)));
                        }
                    }

                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                if (GUILayout.Button("Done", GUILayout.Height(18)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedOxF = false;
                }
                GUILayout.EndHorizontal();
            }

            if (fMoFMax > 0)
            {
                GUILayout.Label("Monopropellant", LabelInfo);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(string.Format("{0}", fMoFMax), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.Label("Current ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(fMoFCurrent.ToString("#0.00"), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Order", GUILayout.Height(18)))
                {
                    LockFuelTank();
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedMoF = true;
                }
                GUI.enabled = !bMoFIn;
                if (GUILayout.Button("In", GUILayout.Height(18)))
                {
                    bMoFIn = true;
                    bMoFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = !bMoFOut;
                if (GUILayout.Button("Out", GUILayout.Height(18)))
                {
                    bMoFOut = true;
                    bMoFIn = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = bMoFIn || bMoFOut;
                if (GUILayout.Button("Stop", GUILayout.Height(18)))
                {
                    bMoFIn = false;
                    bMoFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer stopped";
                    ScreenMessages.PostScreenMessage(smessage, 10, smsStyle);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();
            }

            if (bOrderedMoF)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.RepeatButton("-", GUILayout.Height(18)))
                {
                    fMoFAmount = (float.Parse(fMoFAmount) - fPurchaseRate).ToString();
                    if ((float.Parse(fMoFAmount)) < 0f) fMoFAmount = "0.00";
                }
                GUI.enabled = false;
                GUILayout.TextField(fMoFAmount, GUILayout.Height(18));
                GUI.enabled = true;
                if (GUILayout.RepeatButton("+", GUILayout.Height(18)))
                {
                    fMoFAmount = (float.Parse(fMoFAmount) + fPurchaseRate).ToString();
                    if ((float.Parse(fMoFAmount)) > (fMoFMax - fMoFCurrent)) fMoFAmount = (fMoFMax - fMoFCurrent).ToString();
                }

                if (GUILayout.Button("Max", GUILayout.Height(18)))
                {
                    fMoFAmount = (fMoFMax - fMoFCurrent).ToString();
                    if ((float.Parse(fMoFAmount)) < 0f) fMoFAmount = "0.00";
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }

                float fMoFPrice = 1.2f;

                float fMoFCost = (float.Parse(fMoFAmount)) * fMoFPrice;
                GUILayout.Label("Cost: " + fMoFCost.ToString("#0") + " \\F", LabelInfo);
                if (GUILayout.Button("Buy", GUILayout.Height(18)))
                {
                    if ((float)selectedObject.getSetting("MoFCurrent") + (float.Parse(fMoFAmount)) > fMoFMax)
                    {
                        ScreenMessages.PostScreenMessage("Insufficient fuel capacity!", 10, 0);
                        fMoFAmount = "0.00";
                    }
                    else
                    {
                        if (MiscUtils.isCareerGame())
                        {
                            double currentfunds = Funding.Instance.Funds;

                            if (fMoFCost > currentfunds)
                            {
                                ScreenMessages.PostScreenMessage("Insufficient funds!", 10, 0);
                            }
                            else
                            {
                                Funding.Instance.AddFunds(-fMoFCost, TransactionReasons.Cheating);
                                selectedObject.setSetting("MoFCurrent", (float)selectedObject.getSetting("MoFCurrent") + (float.Parse(fMoFAmount)));
                            }
                        }
                        else
                        {
                            selectedObject.setSetting("MoFCurrent", (float)selectedObject.getSetting("MoFCurrent") + (float.Parse(fMoFAmount)));
                        }
                    }

                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                if (GUILayout.Button("Done", GUILayout.Height(18)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedMoF = false;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();

            if (fOxFMax > 0 || fLqFMax > 0 || fMoFMax > 0)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Transfer Rate", LabelInfo);

                GUI.enabled = (fTransferRate != 0.01f);
                if (GUILayout.Button(" x1", GUILayout.Height(18)))
                {
                    fTransferRate = 0.01f;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer rate set to x1";
                    ScreenMessages.PostScreenMessage(smessage, 10, smsStyle);
                }
                GUI.enabled = (fTransferRate != 0.04f);
                if (GUILayout.Button(" x4", GUILayout.Height(18)))
                {
                    fTransferRate = 0.04f;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer rate set to x4";
                    ScreenMessages.PostScreenMessage(smessage, 10, smsStyle);
                }
                GUI.enabled = (fTransferRate != 0.1f);
                if (GUILayout.Button("x10", GUILayout.Height(18)))
                {
                    fTransferRate = 0.1f;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer rate set to x10";
                    ScreenMessages.PostScreenMessage(smessage, 10, smsStyle);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                if (!FlightGlobals.ActiveVessel.isEVA && FlightGlobals.ActiveVessel.Landed)
                {
                    GUILayout.Label(FlightGlobals.ActiveVessel.vesselName + "'s Tanks", LabelInfo);

                    scrollPos3 = GUILayout.BeginScrollView(scrollPos3);
                    foreach (Part fTank in FlightGlobals.ActiveVessel.parts)
                    {
                        foreach (PartResource rResource in fTank.Resources)
                        {
                            if (rResource.resourceName == "LiquidFuel" || rResource.resourceName == "Oxidizer" || rResource.resourceName == "MonoPropellant")
                            {
                                if (SelectedTank == fTank && SelectedResource == rResource)
                                    PartSelected = true;
                                else
                                    PartSelected = false;

                                GUILayout.BeginHorizontal();
                                GUILayout.Box("" + fTank.gameObject.name, GUILayout.Height(18));
                                GUILayout.Box("" + rResource.resourceName, GUILayout.Height(18));
                                GUILayout.EndHorizontal();

                                GUILayout.BeginHorizontal();
                                GUILayout.Label("Fuel", LabelInfo);
                                GUI.enabled = false;
                                GUILayout.TextField("" + rResource.amount.ToString("#0.00"), GUILayout.Height(18));
                                GUI.enabled = true;

                                GUI.enabled = !PartSelected;
                                if (GUILayout.Button(" Select ", GUILayout.Height(18)))
                                {
                                    SelectedResource = rResource;
                                    SelectedTank = fTank;
                                    PersistenceUtils.saveStaticPersistence(selectedObject);
                                }

                                GUI.enabled = PartSelected;
                                if (GUILayout.Button("Deselect", GUILayout.Height(18)))
                                {
                                    SelectedResource = null;
                                    SelectedTank = null;
                                    PersistenceUtils.saveStaticPersistence(selectedObject);
                                }
                                GUI.enabled = true;
                                GUILayout.EndHorizontal();
                            }
                            else
                                continue;
                        }
                    }
                    GUILayout.EndScrollView();

                    GUI.enabled = true;

                    if (SelectedResource != null && SelectedTank != null)
                    {
                        if (bMoFOut || bOxFOut || bLqFOut)
                            doFuelOut(selectedObject);
                        if (bMoFIn || bOxFIn || bLqFIn)
                            doFuelIn(selectedObject);
                    }
                }
            }

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }