Ejemplo n.º 1
0
 public override void ProcessHandler()
 {
     if (generatorIsActive)
     {
         base.ProcessHandler();
         efficiency = 1f;
         double amtReceived = 0f;
         UnloadedResourceProcessing.RequestResource(vessel.protovessel, "ElectricCharge", rate * TimeWarp.fixedDeltaTime, out amtReceived, true);
     }
 }
Ejemplo n.º 2
0
 public override void ProcessHandler()
 {
     if (converterIsActive)
     {
         base.ProcessHandler();
         double amtRequired    = 0f;
         double amtReceived    = 0f;
         bool   inputsReceived = true;
         for (int i = 0; i < inputResList.Count; i++)
         {
             if (inputResList[i].ResourceName == "IntakeAir")
             {
                 if (vessel.vessel.staticPressurekPa > 0d && vessel.vessel.mainBody.atmosphereContainsOxygen)
                 {
                     //Assume we have enough Air...
                     continue;
                 }
                 else
                 {
                     //RSTUtils.Utilities.Log("TACGenericConverter: Failed to Get Air Resource Vessel " + vessel.vessel.vesselName);
                     inputsReceived = false;
                     break;
                 }
             }
             amtRequired = inputResList[i].Ratio * TimeWarp.fixedDeltaTime;
             UnloadedResourceProcessing.RequestResource(vessel.protovessel, inputResList[i].ResourceName, amtRequired, out amtReceived);
             //RSTUtils.Utilities.Log("TACGenericConverter: Requested Input Resource " + inputResList[i].ResourceName + " Amount:" + amtReceived);
             if (amtReceived < amtRequired)
             {
                 //RSTUtils.Utilities.Log("TACGenericConverter: Failed to Get required Resource " + inputResList[i].ResourceName);
                 inputsReceived = false;
                 break;
             }
         }
         if (inputsReceived)
         {
             for (int i = 0; i < outputResList.Count; i++)
             {
                 amtRequired = outputResList[i].Ratio * TimeWarp.fixedDeltaTime;
                 UnloadedResourceProcessing.RequestResource(vessel.protovessel, outputResList[i].ResourceName, amtRequired, out amtReceived, true);
                 //RSTUtils.Utilities.Log("TACGenericConverter: Generated Output Resource " + outputResList[i].ResourceName + " Amount:" + amtReceived);
             }
         }
     }
 }
Ejemplo n.º 3
0
        public override void ProcessHandler()
        {
            base.ProcessHandler();
            //Calculate EC here.
            Vector3d sun_dir;
            double   sun_dist;
            bool     in_sunlight = RaytraceBody(vessel.vessel, FlightGlobals.Bodies[0], out sun_dir, out sun_dist);
            Vector3d partPos     = VesselPosition(vessel.vessel) + position;

            double orientationFactor = 1;

            if (sunTracking)
            {
                Vector3d localPivot = (vessel.vessel.transform.rotation * orientation * pivotAxis).normalized;
                orientationFactor = Math.Cos(Math.PI / 2.0 - Math.Acos(Vector3d.Dot(localPivot, sun_dir)));
            }
            else
            {
                Vector3d localSolarNormal = (vessel.vessel.transform.rotation * orientation * solarNormal).normalized;
                orientationFactor = Vector3d.Dot(localSolarNormal, sun_dir);
            }

            orientationFactor = Math.Max(orientationFactor, 0);

            if (in_sunlight)
            {
                double solarFlux = SolarLuminosity / (12.566370614359172 * sun_dist * sun_dist);

                double staticPressure = vessel.vessel.mainBody.GetPressure(vessel.vessel.altitude);

                if (staticPressure > 0.0)
                {
                    double  density  = vessel.vessel.mainBody.GetDensity(staticPressure, temperature);
                    Vector3 up       = FlightGlobals.getUpAxis(vessel.vessel.mainBody, vessel.vessel.vesselTransform.position).normalized;
                    double  sunPower = vessel.vessel.mainBody.radiusAtmoFactor * Vector3d.Dot(up, sun_dir);
                    double  sMult    = vessel.vessel.mainBody.GetSolarPowerFactor(density);
                    if (sunPower < 0)
                    {
                        sMult /= Math.Sqrt(2.0 * vessel.vessel.mainBody.radiusAtmoFactor + 1.0);
                    }
                    else
                    {
                        sMult /= Math.Sqrt(sunPower * sunPower + 2.0 * vessel.vessel.mainBody.radiusAtmoFactor + 1.0) - sunPower;
                    }
                    solarFlux *= sMult;
                }

                float multiplier = 1;
                if (usesCurve)
                {
                    multiplier = powerCurve.Evaluate((float)FlightGlobals.Bodies[0].GetAltitude(partPos));
                }
                else
                {
                    multiplier = (float)(solarFlux / PhysicsGlobals.SolarLuminosityAtHome);
                }

                float  tempFactor     = tempCurve.Evaluate(temperature);
                float  resourceAmount = chargeRate * (float)orientationFactor * tempFactor * multiplier;
                double amtReceived    = 0f;
                UnloadedResourceProcessing.RequestResource(vessel.protovessel, "ElectricCharge", resourceAmount * TimeWarp.fixedDeltaTime, out amtReceived, true);
            }
        }
Ejemplo n.º 4
0
        public override void ProcessHandler()
        {
            base.ProcessHandler();
            //Calculate EC here.
            if (Time.timeSinceLevelLoad < 2.0f || CheatOptions.InfiniteElectricity) // Check not loading level
            {
                return;
            }

            if (!DFWrapper.APIReady)
            {
                return;
            }

            // If the user does not have ECreqdForFreezer option ON, then we do nothing and return
            if (!DFWrapper.DeepFreezeAPI.ECReqd)
            {
                //if (debug) Debug.Log("FixedBackgroundUpdate ECreqdForFreezer is OFF, nothing to do");
                return;
            }
            // If the vessel this module is attached to is NOT stored in the DeepFreeze dictionary of known deepfreeze vessels we can't do anything, But this should NEVER happen.
            DFWrapper.VesselInfo vslinfo;
            Dictionary <Guid, DFWrapper.VesselInfo> knownVessels = DFWrapper.DeepFreezeAPI.KnownVessels;

            if (!knownVessels.TryGetValue(vessel.vessel.id, out vslinfo))
            {
                //Debug.Log("[UnloadedResources]: DeepFreezer unknown vessel, cannot process");
                return;
            }
            //Except if there are no frozen crew on board we don't need to consume any EC
            if (vslinfo.numFrozenCrew == 0)
            {
                //if (debug) Debug.Log("FixedBackgroundUpdate No Frozen Crew on-board, nothing to do");
                return;
            }
            DFWrapper.PartInfo partInfo;
            Dictionary <uint, DFWrapper.PartInfo> knownParts = DFWrapper.DeepFreezeAPI.KnownFreezerParts;

            if (!knownParts.TryGetValue(ProtoPart.flightID, out partInfo))
            {
                //Debug.Log("FixedBackgroundUpdate Can't get the Freezer Part Information, so cannot process");
                return;
            }
            // OK now we have something to do for real.
            // Calculate the time since last consumption of EC, then calculate the EC required and request it from BackgroundProcessing DLL.
            // If the vessel runs out of EC the DeepFreezeGUI class will handle notifying the user, not here.
            double currenttime = Planetarium.GetUniversalTime();

            double timeperiod = currenttime - partInfo.timeLastElectricity;

            if (timeperiod >= 1f && partInfo.numFrznCrew > 0) //We have frozen Kerbals, consume EC
            {
                double Ecreqd = partInfo.frznChargeRequired / 60.0f * timeperiod * vslinfo.numFrozenCrew * TimeWarp.fixedDeltaTime;
                //Debug.Log("FixedBackgroundUpdate timeperiod = " + timeperiod + " frozenkerbals onboard part = " + vslinfo.numFrozenCrew + " ECreqd = " + Ecreqd);
                double Ecrecvd = 0f;
                UnloadedResourceProcessing.RequestResource(vessel.protovessel, "ElectricCharge", (float)Ecreqd, out Ecrecvd, true);

                //Debug.Log("Consumed Freezer EC " + Ecreqd + " units");

                if ((float)Ecrecvd >= (float)Ecreqd * 0.99f)
                {
                    if (OnGoingECMsg != null)
                    {
                        ScreenMessages.RemoveMessage(OnGoingECMsg);
                    }
                    partInfo.timeLastElectricity = (float)currenttime;
                    partInfo.deathCounter        = currenttime;
                    partInfo.outofEC             = false;
                    partInfo.ECWarning           = false;
                    vslinfo.storedEC            -= Ecrecvd;
                }
                else
                {
                    //Debug.Log("FixedBackgroundUpdate DeepFreezer Ran out of EC to run the freezer");
                    if (!partInfo.ECWarning)
                    {
                        ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_DF_00072"), 10.0f, ScreenMessageStyle.UPPER_CENTER); //#autoLOC_DF_00072 = Insufficient electric charge to monitor frozen kerbals.
                        partInfo.ECWarning    = true;
                        partInfo.deathCounter = currenttime;
                    }
                    if (OnGoingECMsg != null)
                    {
                        ScreenMessages.RemoveMessage(OnGoingECMsg);
                    }
                    OnGoingECMsg     = ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_DF_00073", (deathRoll - (currenttime - partInfo.deathCounter)).ToString("######0"))); //#autoLOC_DF_00073 = \u0020Freezer Out of EC : Systems critical in <<1>> secs
                    partInfo.outofEC = true;
                    //Debug.Log("FixedBackgroundUpdate deathCounter = " + partInfo.deathCounter);
                    if (currenttime - partInfo.deathCounter > deathRoll)
                    {
                        if (DFWrapper.DeepFreezeAPI.DeathFatal)
                        {
                            //Debug.Log("FixedBackgroundUpdate deathRoll reached, Kerbals all die...");
                            partInfo.deathCounter = currenttime;
                            //all kerbals dies
                            var kerbalsToDelete = new List <string>();
                            foreach (KeyValuePair <string, DFWrapper.KerbalInfo> kerbal in DFWrapper.DeepFreezeAPI.FrozenKerbals)
                            {
                                if (kerbal.Value.partID == ProtoPart.flightID && kerbal.Value.vesselID == vessel.vessel.id && kerbal.Value.type != ProtoCrewMember.KerbalType.Tourist)
                                {
                                    kerbalsToDelete.Add(kerbal.Key);
                                }
                            }
                            foreach (string deathKerbal in kerbalsToDelete)
                            {
                                DFWrapper.DeepFreezeAPI.KillFrozenCrew(deathKerbal);
                                ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_DF_00074", deathKerbal), 10.0f, ScreenMessageStyle.UPPER_CENTER); //#autoLOC_DF_00074 = <<1>> died due to lack of Electrical Charge to run cryogenics
                                //Debug.Log("FixedBackgroundUpdate DeepFreezer - kerbal " + deathKerbal + " died due to lack of Electrical charge to run cryogenics");
                            }
                            //kerbalsToDelete.ForEach(id => DFWrapper.DeepFreezeAPI.FrozenKerbals.Remove(id));
                        }
                        else //NON Fatal option - emergency thaw all kerbals.
                        {
                            // Cannot emergency thaw in background processing. It is expected that DeepFreezeGUI will pick up that EC has run out and prompt the user to switch to the vessel.
                            // When the user switches to the vessel the DeepFreezer partmodule will detect no EC is available and perform an emergency thaw procedure.
                            //Debug.Log("FixedBackgroundUpdate DeepFreezer - EC has run out non-fatal option");
                        }
                    }
                }
            }
        }