Example #1
0
 public void FixedUpdate()
 {
     if (HighLogic.LoadedSceneIsFlight)
     {
         float num = (float)FlightGlobals.getStaticPressure(base.part.transform.position);
         if (hasInflated && !hasBurst)
         {
             if (isInflated)
             {
                 float lift = BalloonProperties.getLift(this);
                 base.part.AddForceAtPosition(base.vessel.upAxis * (double)lift, liftPointObject.transform.position);
                 Vector3 localScale = new Vector3(BalloonProperties.getScale(this), BalloonProperties.getScale(this), BalloonProperties.getScale(this));
                 balloonObject.transform.localScale = localScale;
                 ropeObject.transform.rotation      = Quaternion.Slerp(ropeObject.transform.rotation, Quaternion.LookRotation(base.vessel.upAxis, base.vessel.upAxis), BalloonProperties.getLift(this) / 10f);
                 balloonObject.transform.rotation   = Quaternion.Slerp(balloonObject.transform.rotation, Quaternion.LookRotation(base.vessel.upAxis, base.vessel.upAxis), BalloonProperties.getLift(this) / 8f);
                 balloonObject.transform.position   = balloonPointObject.transform.position;
                 if (!(num < minAtmoPressure) && !(num > maxAtmoPressure))
                 {
                     return;
                 }
                 hasBurst = true;
             }
             else if (isDeflating)
             {
                 if (scaleInc > 0f)
                 {
                     scaleInc -= BalloonProperties.getScale(this) / 100f;
                     balloonObject.transform.localScale = new Vector3(scaleInc, scaleInc, scaleInc);
                     float num2 = scaleInc / BalloonProperties.getScale(this);
                     float num3 = BalloonProperties.getLift(this) * num2;
                     base.part.AddForceAtPosition(base.vessel.upAxis * (double)num3, liftPointObject.transform.position);
                     ropeObject.transform.localScale  = new Vector3(1f, 1f, num2);
                     balloonObject.transform.position = balloonPointObject.transform.position;
                 }
                 else
                 {
                     balloonObject.SetActive(false);
                     ropeObject.SetActive(false);
                     isInflated  = false;
                     isDeflating = false;
                     isRepacked  = false;
                 }
             }
             else if (!isInflated && !isInflating && !isDeflating && !isRepacked)
             {
                 base.Events["repackBalloon"].active = true;
             }
         }
         else if (isInflating && !hasBurst)
         {
             if (scaleInc < BalloonProperties.getScale(this))
             {
                 scaleInc += BalloonProperties.getScale(this) / 200f;
                 balloonObject.transform.localScale = new Vector3(scaleInc, scaleInc, scaleInc);
                 float num4 = scaleInc / BalloonProperties.getScale(this);
                 float num5 = BalloonProperties.getLift(this) * num4;
                 base.part.AddForceAtPosition(base.vessel.upAxis * (double)num5, liftPointObject.transform.position);
                 ropeObject.transform.rotation    = Quaternion.Slerp(ropeObject.transform.rotation, Quaternion.LookRotation(base.vessel.upAxis, base.vessel.upAxis), BalloonProperties.getLift(this) / 10f);
                 balloonObject.transform.rotation = Quaternion.Slerp(balloonObject.transform.rotation, Quaternion.LookRotation(base.vessel.upAxis, base.vessel.upAxis), BalloonProperties.getLift(this) / 8f);
                 ropeObject.transform.localScale  = new Vector3(1f, 1f, num4);
                 balloonObject.transform.position = balloonPointObject.transform.position;
             }
             else
             {
                 hasInflated = true;
                 isInflated  = true;
                 isInflating = false;
             }
         }
         else if (hasBurst)
         {
             if (!isInflated && !isInflating && !isDeflating)
             {
                 return;
             }
             base.part.Effect("burst", -1);
             isInflated  = false;
             isInflating = false;
             isDeflating = false;
             balloonObject.SetActive(false);
             ropeObject.SetActive(false);
             base.Events["inflateBalloon"].active = false;
             base.Events["deflateBalloon"].active = false;
             base.Actions["inflateAction"].active = false;
             base.Actions["deflateAction"].active = false;
         }
     }
 }
        public void FixedUpdate()
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                //print("hasInflated: " + hasInflated + " | isInflated: " + isInflated + " | isInflating: " + isInflating + " | isDeflating: " + isDeflating + " | hasBurst: " + hasBurst + " | isRepacked: " + isRepacked);
                float currentPressure = (float)FlightGlobals.getStaticPressure(this.part.transform.position);
                if (hasInflated && !hasBurst)
                {
                    if (isInflated)
                    {
                        float     lift = BalloonProperties.getLift(this);
                        Rigidbody rb   = this.part.Rigidbody;

                        rb.AddForceAtPosition(vessel.upAxis * lift, liftPointObject.transform.position);
                        Vector3 scale = new Vector3(BalloonProperties.getScale(this), BalloonProperties.getScale(this), BalloonProperties.getScale(this));
                        balloonObject.transform.localScale = scale;

                        ropeObject.transform.rotation    = Quaternion.Slerp(ropeObject.transform.rotation, Quaternion.LookRotation(vessel.upAxis, vessel.upAxis), BalloonProperties.getLift(this) / 10);
                        balloonObject.transform.rotation = Quaternion.Slerp(balloonObject.transform.rotation, Quaternion.LookRotation(vessel.upAxis, vessel.upAxis), BalloonProperties.getLift(this) / 8);

                        balloonObject.transform.position = balloonPointObject.transform.position;

                        if (currentPressure < minAtmoPressure || currentPressure > maxAtmoPressure)
                        {
                            hasBurst = true;
                        }
                    }
                    else if (isDeflating)
                    {
                        if (scaleInc > 0)
                        {
                            scaleInc -= BalloonProperties.getScale(this) / 100;
                            balloonObject.transform.localScale = new Vector3(scaleInc, scaleInc, scaleInc);

                            float progress = scaleInc / BalloonProperties.getScale(this);

                            float lift = BalloonProperties.getLift(this) * progress;
                            this.part.Rigidbody.AddForceAtPosition(vessel.upAxis * lift, liftPointObject.transform.position);

                            ropeObject.transform.localScale  = new Vector3(1, 1, progress);
                            balloonObject.transform.position = balloonPointObject.transform.position;
                        }
                        else
                        {
                            balloonObject.SetActive(false);
                            ropeObject.SetActive(false);

                            isInflated  = false;
                            isDeflating = false;
                            isRepacked  = false;
                        }
                    }
                    else if (!isInflated && !isInflating && !isDeflating && !isRepacked)
                    {
                        Events["repackBalloon"].active = true;
                    }
                }
                else if (isInflating && !hasBurst)
                {
                    if (scaleInc < BalloonProperties.getScale(this))
                    {
                        scaleInc += BalloonProperties.getScale(this) / 200;
                        balloonObject.transform.localScale = new Vector3(scaleInc, scaleInc, scaleInc);

                        float progress = scaleInc / BalloonProperties.getScale(this);

                        float lift = BalloonProperties.getLift(this) * progress;
                        this.part.Rigidbody.AddForceAtPosition(vessel.upAxis * lift, liftPointObject.transform.position);


                        ropeObject.transform.rotation    = Quaternion.Slerp(ropeObject.transform.rotation, Quaternion.LookRotation(vessel.upAxis, vessel.upAxis), BalloonProperties.getLift(this) / 10);
                        balloonObject.transform.rotation = Quaternion.Slerp(balloonObject.transform.rotation, Quaternion.LookRotation(vessel.upAxis, vessel.upAxis), BalloonProperties.getLift(this) / 8);

                        ropeObject.transform.localScale  = new Vector3(1, 1, progress);
                        balloonObject.transform.position = balloonPointObject.transform.position;
                    }
                    else
                    {
                        hasInflated = true;
                        isInflated  = true;
                        isInflating = false;
                    }
                }
                else if (hasBurst && (isInflated || isInflating || isDeflating))
                {
                    this.part.Effect("burst");
                    isInflated  = false;
                    isInflating = false;
                    isDeflating = false;
                    balloonObject.SetActive(false);
                    ropeObject.SetActive(false);
                    Events["inflateBalloon"].active = false;
                    Events["deflateBalloon"].active = false;
                    Actions["inflateAction"].active = false;
                    Actions["deflateAction"].active = false;
                }
            }
        }
Example #3
0
        public override void OnStart(StartState state)
        {
            Debug.Log("ModuleKerBalloon Loaded");

            if (HighLogic.LoadedSceneIsEditor)
            {
                var switches = part.FindModulesImplementing <ModuleB9PartSwitch>();
                sizeSwitch   = switches.Find(s => s.moduleID == "balloonSizeSwitch");
                planetSwitch = switches.Find(s => s.moduleID == "planetSwitch");
                if (sizeSwitch == null)
                {
                    Log.Error("sizeSwitch is null");
                }
                if (planetSwitch == null)
                {
                    Log.Error("planetSwitch is null");
                }
                foreach (var s in planetSwitch.Fields)
                {
                    s.guiActiveEditor = false;
                }
                planetSwitch.Events["ShowSubtypesWindow"].guiActiveEditor = false;
                bodyName = recommendedBody;
                UpdatePersistentData();
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                balloonObject      = getChildGameObject(this.part.gameObject, CFGballoonObject, 0);      // balloonSize);
                ropeObject         = getChildGameObject(this.part.gameObject, CFGropeObject, 0);         //balloonSize);
                capObject          = getChildGameObject(this.part.gameObject, CFGcapObject, 0);          //balloonSize);
                liftPointObject    = getChildGameObject(this.part.gameObject, CFGliftPointObject, 0);    //balloonSize);
                balloonPointObject = getChildGameObject(this.part.gameObject, CFGballoonPointObject, 0); //balloonSize);

                balloonObject.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f);

                initialBalloonScale = balloonObject.transform.localScale;
                initialBalloonPos   = balloonObject.transform.transform.localPosition;
                initialRopeScale    = ropeObject.transform.localScale;

                if (hasInflated && !isInflated)
                {
                    balloonObject.SetActive(false);
                    ropeObject.SetActive(false);
                    capObject.SetActive(false);
                }
                else if (isInflating)
                {
                    repackBalloon();
                }
                else if (isDeflating)
                {
                    balloonObject.SetActive(false);
                    ropeObject.SetActive(false);

                    isInflated  = false;
                    isDeflating = false;
                    isRepacked  = false;
                }

                if (!isInflated && !isInflating && !isDeflating && !isRepacked)
                {
                    Events["repackBalloon"].active = true;
                }
                if (isInflated)
                {
                    Log.Info("isInflated");
                    Events["inflateBalloon"].active = false;
                    Events["deflateBalloon"].active = true;
                    balloonObject.SetActive(true);
                    ropeObject.SetActive(true);
                    capObject.SetActive(false);


                    ropeObject.transform.rotation   = Quaternion.Slerp(ropeObject.transform.rotation, Quaternion.LookRotation(vessel.upAxis, vessel.upAxis), BalloonProperties.getLift(this) / 10);
                    ropeObject.transform.localScale = new Vector3(1, 1, 1);
                }
            }
        }