Пример #1
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            double kw    = Math.Abs(this.part.thermalRadiationFlux);
            Part   rPart = MPFunctions.GetResourcePart(FlightGlobals.ActiveVessel, resourceName);

            if (rPart != null)
            {
                int    id     = MPFunctions.GetResourceID(rPart, resourceName);
                double rTotal = MPFunctions.GetResourceTotal(FlightGlobals.ActiveVessel, resourceName);
                double rMax   = MPFunctions.GetResourceMax(FlightGlobals.ActiveVessel, resourceName);
                transAmt = resourceAmt * kw;
                if (actRad == true)     // look for active radiator
                {
                    for (int i = this.part.Modules.Count - 1; i >= 0; --i)
                    {
                        PartModule M = this.part.Modules[i];
                        if (M is ModuleActiveRadiator)
                        {
                            if ((M as ModuleActiveRadiator).IsCooling)
                            {
                                rPart.TransferResource(id, transAmt);
                            }
                        }
                    }
                }
                else
                {
                    rPart.TransferResource(id, transAmt);
                }
            }
        }
Пример #2
0
 public void FixedUpdate()
 {
     if (!HighLogic.LoadedSceneIsFlight)
     {
         return;
     }
     for (int i = this.part.Modules.Count - 1; i >= 0; --i)
     {
         PartModule M = this.part.Modules[i];
         if (M is ModuleDeployableSolarPanel)
         {
             if ((M as ModuleDeployableSolarPanel).deployState == ModuleDeployableSolarPanel.DeployState.EXTENDED)
             {
                 Double CWTotal   = MPFunctions.GetResourceTotal(this.vessel, "CompressedWater");
                 Double elecTotal = MPFunctions.GetResourceTotal(this.vessel, "ElectricCharge");
                 if (CWTotal <= 0 || elecTotal <= 0)
                 {
                     if (CWTotal <= 0)
                     {
                         (M as ModuleDeployableSolarPanel).status = "No Compressed Water";
                     }
                     else
                     {
                         (M as ModuleDeployableSolarPanel).status = "No Electric Charge";
                     }
                     (M as ModuleDeployableSolarPanel).enabled = false;
                 }
                 else
                 {
                     (M as ModuleDeployableSolarPanel).enabled = true;
                     float thisflow = (M as ModuleDeployableSolarPanel).flowRate;
                     if (thisflow > 0)
                     {
                         Part   sPart  = MPFunctions.GetResourcePart(FlightGlobals.ActiveVessel, "CompressedWater");
                         int    CWID   = MPFunctions.GetResourceID(sPart, "CompressedWater");
                         double CWFlow = sPart.RequestResource(CWID, thisflow * CWRate, ResourceFlowMode.ALL_VESSEL);
                         sPart = MPFunctions.GetResourcePart(FlightGlobals.ActiveVessel, "ElectricCharge");
                         int EcID = MPFunctions.GetResourceID(sPart, "ElectricCharge");
                         sPart.RequestResource(EcID, CWFlow * elRate, ResourceFlowMode.ALL_VESSEL);
                     }
                 }
             }
             else
             {
                 (M as ModuleDeployableSolarPanel).enabled = true;
             }
         }
     }
 }
Пример #3
0
        public bool ConsumeResource(string thisresource, double amount)
        {
            Part   rPart  = MPFunctions.GetResourcePart(FlightGlobals.ActiveVessel, thisresource);
            double rTotal = MPFunctions.GetResourceTotal(FlightGlobals.ActiveVessel, pressureResource1);

            if (rPart != null && rTotal >= amount)
            {
                int    id    = MPFunctions.GetResourceID(rPart, thisresource);
                double rFlow = rPart.RequestResource(id, amount, ResourceFlowMode.ALL_VESSEL);
                if (rFlow > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #4
0
 public void FixedUpdate()
 {
     varPeriod -= Time.deltaTime;
     if (varPeriod < 0)
     {
         varPeriod = decayPeriod;
         resPart   = MPFunctions.GetResourcePart(FlightGlobals.ActiveVessel, resourceName);
         resID     = MPFunctions.GetResourceID(resPart, resourceName);
         resAmt    = MPFunctions.GetResourceTotal(FlightGlobals.ActiveVessel, resourceName);
         if (resPart != null && resAmt > 0)
         {
             try
             {
                 resPart.RequestResource(resID, decayAmount, ResourceFlowMode.ALL_VESSEL);
             }
             catch
             {
                 MPLog.Writelog("[Maritime Pack] ResDecay: Error removing resource");
             }
         }
     }
 }
Пример #5
0
        public override void OnUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight && rescount != 2)
            {
                return;
            }
            {
                //Computer Power Drain
                if (Events["BuoyDeactivate"].active || Events["KeelDeactivate"].active || Events["InfoDeactivate"].active)
                {
                    float rConsume = 0;
                    if (Events["BuoyDeactivate"].active)
                    {
                        rConsume++;
                    }
                    if (Events["KeelDeactivate"].active)
                    {
                        rConsume++;
                    }
                    if (Events["InfoDeactivate"].active)
                    {
                        rConsume += 0.5f;
                    }


                    batterycheck -= Time.deltaTime;
                    bool goodcheck = false;
                    if (batterycheck < 0)
                    {
                        double rFlow  = 0.0f;
                        Part   rPart  = MPFunctions.GetResourcePart(FlightGlobals.ActiveVessel, "ElectricCharge");
                        double rTotal = MPFunctions.GetResourceTotal(FlightGlobals.ActiveVessel, "ElectricCharge");
                        if (rPart != null && rTotal >= rConsume)
                        {
                            rFlow     = rPart.RequestResource(batid, rConsume, ResourceFlowMode.ALL_VESSEL);
                            goodcheck = true;
                        }
                        if (!goodcheck || rFlow != rConsume || rTotal < rConsume)
                        {
                            Events["BuoyDeactivate"].active = false;
                            Events["BuoyActivate"].active   = true;
                            Events["KeelActivate"].active   = true;
                            Events["KeelDeactivate"].active = false;
                            Events["InfoActivate"].active   = true;
                            Events["InfoDeactivate"].active = false;
                            MPLog.Writelog("[Maritime Pack] Sub Computer: Battery depleted.");
                        }
                        batterycheck = 10.0f;
                    }
                }
                //AutoBuoyancy
                if (Events["BuoyDeactivate"].active == true)
                {
                    buoycheck -= Time.deltaTime;
                    if (buoycheck < 0)
                    {
                        buoycheck = 2.0f;
                        double vesselspeed = (double)Decimal.Round((decimal)this.vessel.verticalSpeed, 3);
                        MPLog.Writelog("[Maritime Pack] Vessel Vertical Speed: " + vesselspeed);
                        transferamount = (double)decimal.Round((decimal)vesselspeed, 2) / 2;
                        if (vesselspeed < 0)
                        {
                            MPLog.Writelog("[Maritime Pack] Removing buoy: " + transferamount);
                            double p1amount = MPFunctions.GetResourceAmount(Part1, "CompressedWater");
                            double p2amount = MPFunctions.GetResourceAmount(Part2, "CompressedWater");
                            if (p1amount > transferamount)
                            {
                                Part1.TransferResource(id, transferamount);
                            }
                            else if (p1amount > 0)
                            {
                                Part1.TransferResource(id, -p1amount);
                            }
                            if (p2amount > transferamount)
                            {
                                Part2.TransferResource(id, transferamount);
                            }
                            else if (p1amount > 0)
                            {
                                Part2.TransferResource(id, -p2amount);
                            }
                        }
                        else if (vesselspeed > 0)
                        {
                            MPLog.Writelog("[Maritime Pack] Adding buoy: " + transferamount);
                            double p1amount = MPFunctions.GetResourceSpace(Part1, "CompressedWater");
                            double p2amount = MPFunctions.GetResourceSpace(Part2, "CompressedWater");
                            if (p1amount > transferamount)
                            {
                                Part1.TransferResource(id, transferamount);
                            }
                            else if (p1amount > 0)
                            {
                                Part1.TransferResource(id, p1amount);
                            }
                            if (p2amount > transferamount)
                            {
                                Part2.TransferResource(id, transferamount);
                            }
                            else if (p1amount > 0)
                            {
                                Part2.TransferResource(id, p2amount);
                            }
                        }
                        else
                        {
                            Events["BuoyDeactivate"].active = false;
                            Events["BuoyActivate"].active   = true;
                        }
                    }
                }

                //AutoKeel
                if (Events["KeelDeactivate"].active == true)
                {
                    keelcheck -= Time.deltaTime;
                    if (keelcheck < 0)
                    {
                        bool   skip      = false;
                        double pitch     = Math.Abs(MPFunctions.GetPitch(this.vessel) - 90);
                        double realpitch = MPFunctions.GetPitch(this.vessel);
                        if (lastpitch != -1)
                        {
                            double deltapitch = Math.Abs(lastpitch - pitch);
                            MPLog.Writelog("[Maritime Pack] AutoKeel: DeltaPitch: " + deltapitch);
                            if (deltapitch > 10)
                            {
                                skip      = true;
                                keelcheck = 10.0f;
                            }
                            else if (deltapitch < 3)
                            {
                                keelcheck = 7.0f;
                            }
                            else
                            {
                                keelcheck = (10 - (float)deltapitch);
                            }
                        }
                        else
                        {
                            keelcheck = 3.0f;
                            this.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, false);
                        }
                        lastpitch = pitch;
                        if (!skip)
                        {
                            transferamount = ((.20 - .01) / (90 - 30)) * pitch;
                            if (transferamount < 0.01f)
                            {
                                transferamount = 0.01f;
                            }
                            MPLog.Writelog("[Maritime Pack] Pitch: " + pitch);
                            alt1 = MPFunctions.findAltitude(Part1.transform);
                            alt2 = MPFunctions.findAltitude(Part2.transform);
                            MPLog.Writelog("[Maritime Pack] Autokeel Running: Alt1:" + alt1 + " Alt2:" + alt2 + " Amt: " + transferamount);
                            if (Math.Abs(alt1 - alt2) < 1.0f)
                            {
                                MPLog.Writelog("[Maritime Pack] AutoKeel: Shut Down: " + alt1 + " " + alt2);
                                Events["KeelActivate"].active   = true;
                                Events["KeelDeactivate"].active = false;
                                this.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true);
                            }
                            else if (alt1 > alt2)
                            {
                                if (MPFunctions.GetResourceAmount(Part2, "CompressedWater") > transferamount && MPFunctions.GetResourceSpace(Part1, "CompressedWater") > transferamount)
                                {
                                    Part2.TransferResource(id, -transferamount);
                                    Part1.TransferResource(id, transferamount);
                                    MPLog.Writelog("[Maritime Pack] Moving " + transferamount + " to " + Part1.name);
                                }
                                else
                                {
                                    MPLog.Writelog("[Maritime Pack] AutoKeel: Unable to transfer resources.");
                                    Events["KeelActivate"].active   = true;
                                    Events["KeelDeactivate"].active = false;
                                }
                            }
                            else if (alt1 < alt2)
                            {
                                if (MPFunctions.GetResourceAmount(Part1, "CompressedWater") > transferamount && MPFunctions.GetResourceSpace(Part2, "CompressedWater") > transferamount)
                                {
                                    Part1.TransferResource(id, -transferamount);
                                    Part2.TransferResource(id, transferamount);
                                    MPLog.Writelog("[Maritime Pack] Moving " + transferamount + " to " + Part2.name);
                                }
                                else
                                {
                                    MPLog.Writelog("[Maritime Pack] AutoKeel: Unable to transfer resources.");
                                    Events["KeelActivate"].active   = true;
                                    Events["KeelDeactivate"].active = false;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (myEngine == null && myIntake == null && partType != "Throttle" && partType != "Stirling" && partType != "Battery" || animationName == "null" || !vessel.isActiveVessel)
            {
                return;
            }
            else if (vessel.isActiveVessel)
            {
                double thisenergy = 0;
                if (partType == "Stirling")
                {
                    thisenergy = Math.Abs(this.part.thermalRadiationFlux) / 100;
                    if (thisenergy > 1)
                    {
                        thisenergy = 1;
                    }
                    if (thisenergy < 0)
                    {
                        thisenergy = 0;
                    }
                    Play_Anim(animationName, (float)thisenergy, 0.0f);
                    return;
                }
                if (partType == "Battery")
                {
                    double rTotal = MPFunctions.GetResourceTotal(FlightGlobals.ActiveVessel, "ElectricCharge");
                    double rMax   = MPFunctions.GetResourceMax(FlightGlobals.ActiveVessel, "ElectricCharge");
                    thisenergy = rTotal / rMax;
                }
                else
                {
                    thisenergy = FlightInputHandler.state.mainThrottle;
                }

                if ((partType == "Engine" && !myEngine.EngineIgnited) || (partType == "Engine" && myEngine.getFlameoutState == true) || (partType == "Intake" && !myIntake.intakeEnabled)) //Intake or Engine shut down, reverse animation
                {
                    if (syncThrust)
                    {
                        if (syncThrust)
                        {
                            float direction = CheckDirection();
                            thisenergy = myEngine.normalizedThrustOutput;
                            Play_Anim(animationName, (float)thisenergy * direction, 0.0f);
                            return;
                        }
                    }
                    if (lastThrottle != 0.0f)
                    {
                        if (syncThrottle)
                        {
                            if (smoothThrottle)
                            {
                                lastThrottle = lastThrottle - 0.02f;
                                if (lastThrottle < 0.0f)
                                {
                                    lastThrottle = 0.0f;
                                }
                            }
                            else
                            {
                                lastThrottle = 0.0f;
                            }
                            if (loopAnim == true)
                            {
                                Play_Anim(animationName, lastThrottle);
                            }
                            else
                            {
                                Play_Anim(animationName, 0.0f, lastThrottle);
                            }
                        }
                        else //not synced to play at full speed from the end to the beginning
                        {
                            if (!aniEngine.isPlaying)
                            {
                                if (loopAnim == true)
                                {
                                    Play_Anim(animationName, 0.0f);
                                }
                                else
                                {
                                    Play_Anim(animationName, -1.0f, 1.0f);
                                }
                                lastThrottle = 0.0f;
                            }
                        }
                    }
                }
                else //engine ignited or it's another type, run animation
                {
                    if (syncThrust)
                    {
                        float direction = CheckDirection();
                        thisenergy = myEngine.normalizedThrustOutput;
                        if (loopAnim == true)
                        {
                            Play_Anim(animationName, (float)thisenergy, 0.0f);
                        }
                        else
                        {
                            Play_Anim(animationName, 0.0f, (float)thisenergy);
                        }
                        return;
                    }
                    if (syncThrottle)
                    {
                        if (smoothThrottle)
                        {
                            if (thisenergy > lastThrottle)
                            {
                                if (thisenergy + lastThrottle > 0.02f)
                                {
                                    lastThrottle = lastThrottle + 0.02f;
                                    if (lastThrottle > 1.0f)
                                    {
                                        lastThrottle = 1.0f;
                                    }
                                }
                                else
                                {
                                    lastThrottle = (float)thisenergy;
                                }
                            }
                            if (thisenergy < lastThrottle)
                            {
                                if (lastThrottle - thisenergy > 0.02f || thisenergy == 0 && lastThrottle != 0)
                                {
                                    lastThrottle = lastThrottle - 0.02f;
                                    if (lastThrottle < 0.0f)
                                    {
                                        lastThrottle = 0.0f;
                                    }
                                }
                                else
                                {
                                    lastThrottle = (float)thisenergy;
                                }
                            }
                            if (loopAnim == true)
                            {
                                Play_Anim(animationName, lastThrottle, 0.0f);
                            }
                            else
                            {
                                Play_Anim(animationName, 0.0f, lastThrottle);
                            }
                        }
                        else
                        {
                            if (loopAnim == true)
                            {
                                Play_Anim(animationName, (float)thisenergy);
                            }
                            else
                            {
                                Play_Anim(animationName, 0.0f, (float)thisenergy);
                            }
                        }
                    }
                    else //not synced so play at full speed from the beginning
                    {
                        if (!aniEngine.isPlaying && lastThrottle != 1.0f)
                        {
                            Play_Anim(animationName, 1.0f, 0.0f);
                            lastThrottle = 1.0f;
                        }
                    }
                }
            }
        }