Example #1
0
        protected IEnumerator <YieldInstruction> runConverter(WBIBackgroundConverter converter, double elapsedTime, ProtoVessel protoVessel)
        {
            //Get ready to process
            converter.PrepareToProcess(protoVessel);
            yield return(new WaitForFixedUpdate());

            //Check required
            converter.CheckRequiredResources(protoVessel, elapsedTime);
            yield return(new WaitForFixedUpdate());

            //Consume inputs
            converter.ConsumeInputResources(protoVessel, elapsedTime);
            yield return(new WaitForFixedUpdate());

            //Produce outputs
            converter.ProduceOutputResources(protoVessel, elapsedTime);
            yield return(new WaitForFixedUpdate());

            //Produce yields
            converter.ProduceYieldResources(protoVessel);
            yield return(new WaitForFixedUpdate());

            //Post process
            converter.PostProcess(protoVessel);
            yield return(new WaitForFixedUpdate());
        }
Example #2
0
        protected IEnumerator <YieldInstruction> runConverter(WBIBackgroundConverter converter, double elapsedTime)
        {
            //If the vessel is currently loaded, then we're done
            bool vesselIsLoaded = false;

            Vessel[] loadedVessels = FlightGlobals.VesselsLoaded.ToArray();
            for (int vesselIndex = 0; vesselIndex < loadedVessels.Length; vesselIndex++)
            {
                if (loadedVessels[vesselIndex].id.ToString() == converter.vesselID)
                {
                    vesselIsLoaded = true;
                    break;
                }
            }
            yield return(new WaitForFixedUpdate());

            if (!vesselIsLoaded)
            {
                //Find the unloaded vessel
                int         count           = FlightGlobals.VesselsUnloaded.Count;
                Vessel[]    unloadedVessels = FlightGlobals.VesselsUnloaded.ToArray();
                Vessel      unloadedVessel  = null;
                ProtoVessel protoVessel;
                string      unloadedVesselID;
                for (int index = 0; index < count; index++)
                {
                    unloadedVessel   = unloadedVessels[index];
                    unloadedVesselID = unloadedVessel.id.ToString();
                    if (unloadedVesselID == converter.vesselID)
                    {
                        break;
                    }
                    else
                    {
                        unloadedVessel = null;
                    }
                }
                yield return(new WaitForFixedUpdate());

                //Process our resources if we found the vessel.
                if (unloadedVessel != null)
                {
                    //Get the proto vessel
                    protoVessel = unloadedVessel.protoVessel;

                    //Get ready to process
                    converter.PrepareToProcess(protoVessel);
                    yield return(new WaitForFixedUpdate());

                    //Check required
                    converter.CheckRequiredResources(protoVessel, elapsedTime);
                    yield return(new WaitForFixedUpdate());

                    //Consume inputs
                    converter.ConsumeInputResources(protoVessel, elapsedTime);
                    yield return(new WaitForFixedUpdate());

                    //Produce outputs
                    converter.ProduceOutputResources(protoVessel, elapsedTime);
                    yield return(new WaitForFixedUpdate());

                    //Produce yields
                    converter.ProduceYieldResources(protoVessel);
                    yield return(new WaitForFixedUpdate());

                    //Post process
                    converter.PostProcess(protoVessel);
                }

                //We didn't find the vessel. Remove the converter from our list.
                else
                {
                    backgroundConverters.Remove(converter.converterID);
                }
            }

            yield return(new WaitForFixedUpdate());
        }