예제 #1
0
 public void Start()
 {
     CVConfig.Getconfig();
     MPLog.NewLog();
     MPLog.Writelog("[CVFlightDeck] DLL Active!");
     FSArrestingGear.KLOLSActive = false;
 }
예제 #2
0
 public override void OnStart(StartState state)
 {
     MPLog.Writelog("[CVFlightDeck] Arresting Gear ready. Clear the flight deck.");
     if (KLOLSActive == true)
     {
         ActivateKLOLS();
     }
 }
예제 #3
0
 public void FixedUpdate()
 {
     //if the scene isn't a flight or the carrier is the active vessel... don't bother with the code. added to get rid of errors in sph.
     if (!HighLogic.LoadedSceneIsFlight || vessel.isActiveVessel)
     {
         return;
     }
     {
         bool lgfound = false;
         if (catapultActive == true)// is a launch requested?
         {
             foreach (Part aPart in FlightGlobals.ActiveVessel.Parts)
             {
                 if (model == "C1" && aPart.Modules.Contains("ModuleWheelBase"))  //see if there's landing gear attached so we know what to launch
                 {
                     landingGear = aPart;
                     lgfound     = true;
                     break;
                 }
                 if (model == "C2" && aPart.Modules.Contains("FSCatapultShuttle")) //rotating catapult, look for the shuttle
                 {
                     landingGear = aPart;
                     lgfound     = true;
                     break;
                 }
             }
             if (lgfound == true)
             {
                 MPLog.Writelog("[CVFlightDeck] Landing gear or shuttle found. Proceeding to launch.");
                 doEMCtakeoff();
             }
             else
             {
                 if (model == "C1")
                 {
                     ScreenMessages.PostScreenMessage("Unable to launch. No valid landing gear found!", 5);
                 }
                 else if (model == "C2")
                 {
                     ScreenMessages.PostScreenMessage("Catapult shuttle not found on aircraft.", 5);
                 }
                 catapultActive  = false;
                 EMCtakeoffTimer = 0f;
             }
         }
     }
 }
예제 #4
0
        private void doLandAssist()
        {
            // Stop the plane!
            if (playOnce == false)
            {
                SoundGroup.audio      = gameObject.AddComponent <AudioSource>();
                SoundGroup.audio.clip = GameDatabase.Instance.GetAudioClip(ArrestingSound);
                SoundGroup.audio.Play();
                SoundGroup.audio.loop = false;
                playOnce = true;
            }
            MPLog.Writelog("[CVFlightDeck] ----------- Landing Assist! -----------");
            float distanceFromCarrier = (FlightGlobals.ActiveVessel.transform.position - this.part.transform.position).magnitude;

            MPLog.Writelog("[CVFlightDeck] Distance from carrier: " + distanceFromCarrier);
            FlightInputHandler.state.mainThrottle = 0f;
            FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true); //temporary to see the effect.
            MPLog.Writelog("[CVFlightDeck] Setting aircraft brakes.");
            double aircraftSpeed = FlightGlobals.ActiveVessel.srf_velocity.magnitude;

            MPLog.Writelog("[CVFlightDeck] Aircraft Speed:" + aircraftSpeed);
            Vector3 headingDirection = FlightGlobals.ActiveVessel.GetComponent <Rigidbody>().transform.position - this.transform.position;
            Vector3 forward;

            forward = FlightGlobals.ActiveVessel.transform.up;
            if (Vector3.Dot(forward, headingDirection.normalized) > 0f)
            {
                //if (FSTailHook != null)
                //{
                //    FSTailHook.GetComponent<Rigidbody>().AddForce(-forward * ((float)aircraftSpeed * 25));
                //    MPLog.Writelog("[CVFlightDeck] Braking force added to tailhook: " + (float)aircraftSpeed * 25);
                //}
                //else
                //{
                FSTailHook.vessel.GetComponent <Rigidbody>().AddForce(-forward * ((float)aircraftSpeed * 25));
                MPLog.Writelog("[CVFlightDeck] Braking force added to vessel: " + (float)aircraftSpeed * 25);
                //}
            }
        }
예제 #5
0
        private void doEMCtakeoff()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            float distanceFromCarrier = (FlightGlobals.ActiveVessel.transform.position - this.part.transform.position).magnitude;

            if (FlightGlobals.ActiveVessel.srf_velocity.magnitude <= 100f && EMCtakeoffTimer < MaxEMCTimer && distanceFromCarrier <= 15f)
            {
                if (playOnce == false)
                {
                    SoundGroup.audio      = gameObject.AddComponent <AudioSource>();
                    SoundGroup.audio.clip = GameDatabase.Instance.GetAudioClip(ArrestingSound);
                    SoundGroup.audio.Play();
                    SoundGroup.audio.loop = false;
                    playOnce = true;
                }
                MPLog.Writelog("[CVFlightDeck] Catapult launching.");
                ScreenMessages.PostScreenMessage("Launch!", 5);
                EMCtakeoffTimer += 1f;
                // Aircraft needs to be stopped and throttle at zero.
                FlightInputHandler.state.mainThrottle = 100f;

                FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false); //remove brakes
                                                                                                // apply 100% throttle and remove brakes...

                Vector3 forward = FlightGlobals.ActiveVessel.transform.up;

                if (FlightGlobals.ActiveVessel.GetComponent <Rigidbody>() != null)
                {
                    FlightGlobals.ActiveVessel.GetComponent <Rigidbody>().AddForce(forward * (power_modifier * 50), ForceMode.Acceleration);
                    MPLog.Writelog("[CVFlightDeck] LAUNCH! T+" + EMCtakeoffTimer);
                }
                else
                {
                    MPLog.Writelog("[CVFlightDeck] No rigidbody found on aircraft!  Unable to launch.");
                    ScreenMessages.PostScreenMessage("Unable to launch. No valid rigidbody found!!!", 5);
                }
            }
            else
            {
                string abortreason = "[CVFlightDeck] Catapult deactivated. Reason:";
                if (distanceFromCarrier > 15f)
                {
                    abortreason += " Distance > 15 meters: " + distanceFromCarrier + " meters";
                }
                else if (FlightGlobals.ActiveVessel.srf_velocity.magnitude > 100)
                {
                    abortreason += " Velocity > 100: " + FlightGlobals.ActiveVessel.srf_velocity.magnitude + " m/s";
                }
                else if (EMCtakeoffTimer >= MaxEMCTimer)
                {
                    abortreason += " Launch count > " + MaxEMCTimer;
                }
                MPLog.Writelog(abortreason);
                catapultActive  = false;
                playOnce        = false;
                EMCtakeoffTimer = 0f;
                MPLog.Writelog("[CVFlightDeck] Aircraft away: V=" + FlightGlobals.ActiveVessel.srf_velocity.magnitude + " D=" + distanceFromCarrier + " T=" + EMCtakeoffTimer);
            }
        }
예제 #6
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            distancecheck -= Time.deltaTime;
            messagedelay  -= Time.deltaTime;
            double distanceFromCarrier = AGactivationRange;
            bool   tailHookFound       = false;
            bool   inthebox            = false;

            foreach (Part aPart in FlightGlobals.ActiveVessel.Parts)
            {
                foreach (PartModule aModule in aPart.Modules)
                {
                    if (aModule is FSTailHook)
                    {
                        tailHookFound = true;
                        FSTailHook    = aPart;
                        break;
                    }
                }
                if (tailHookFound == true)
                {
                    distanceFromCarrier = (aPart.transform.position - this.part.transform.position).magnitude;
                    break;
                }
            }
            if (tailHookFound == true && distanceFromCarrier > 500 && distanceFromCarrier <= AGactivationRange && arrestingGearActive == false)
            {
                arrestingGearActive = true;
                MPLog.Writelog("[CVFlightDeck] Arresting gear standing by.");
            }
            if (arrestingGearActive == true && distanceFromCarrier < 5f && FlightGlobals.ActiveVessel.srf_velocity.magnitude > 10)
            {
                // turn assist system on.
                if (hookdeployed)
                {
                    doLandAssist();
                }
                else
                {
                    MPLog.Writelog("[CVFlightDeck] Hook not deployed. Landlubber incoming!");
                }
            }
            if (FlightGlobals.ActiveVessel.srf_velocity.magnitude < 1 && arrestingGearActive == true) //when the plane is completely stopped the system is disabled.
            {
                arrestingGearActive = false;
                playOnce            = false;
                if (line != null)
                {
                    line.SetColors(Color.red, Color.red);
                }
                inthebox = false;
                if (FlightGlobals.ActiveVessel.Splashed)
                {
                    MPLog.Writelog("[CVFlightDeck] Man Overboard! Pilot in the drink!");
                }
                else if (FlightGlobals.ActiveVessel.Landed)
                {
                    MPLog.Writelog("[CVFlightDeck] Aircraft landed. Welcome aboard!");
                }
            }
            if (arrestingGearActive == true)
            {
                // do some math
                double CVHeading    = MPFunctions.GetHeading(this.vessel);
                double RevCVHeading = 0.0f;
                if (CVHeading >= 180)
                {
                    RevCVHeading = CVHeading - 180;
                }
                else
                {
                    RevCVHeading = CVHeading + 180;
                }
                //double portdeg = MPFunctions.NormalizeAngle(RevCVHeading, -boxdeflection);
                //double stbddeg = MPFunctions.NormalizeAngle(RevCVHeading, boxdeflection);
                double  aircraftheading = MPFunctions.GetHeading(FlightGlobals.ActiveVessel);
                Vector3 UpVect          = (this.vessel.transform.position - this.vessel.mainBody.position).normalized;
                //                Vector3 EastVect = this.vessel.mainBody.getRFrmVel(this.vessel.findWorldCenterOfMass()).normalized;
                Vector3 EastVect = this.vessel.mainBody.getRFrmVel(this.vessel.CurrentCoM.normalized);

                Vector3 NorthVect      = Vector3.Cross(EastVect, UpVect).normalized;
                Vector3 TargetVect     = FlightGlobals.ActiveVessel.transform.position - this.vessel.transform.position;
                Vector3 SurfTargetVect = TargetVect - Vector3.Dot(UpVect, TargetVect) * UpVect; // removing the vertical component
                float   bearing        = Vector3.Angle(SurfTargetVect, NorthVect);
                if (Math.Sign(Vector3.Dot(SurfTargetVect, EastVect)) < 0)
                {
                    bearing = 360 - bearing;                                                                                        // westward headings become angles greater than 180
                }
                Vector3 ToFlyingVect = (FlightGlobals.ActiveVessel.transform.position - this.vessel.transform.position).normalized; // A vector pointing toward the flying vessel with length 1
                UpVect = (this.vessel.transform.position - this.vessel.mainBody.transform.position).normalized;                     // A vector from the center of the current planet through the root part of your vessel with length 1
                float  elevation       = 90 - Vector3.Angle(UpVect, ToFlyingVect);                                                  // 90 (vertical) less angle from vertical
                double revBearing      = MPFunctions.NormalizeAngle(bearing, 180);
                double aircraftPortdeg = MPFunctions.NormalizeAngle(revBearing, -45);
                double aircraftStbddeg = MPFunctions.NormalizeAngle(revBearing, 45);

                if (distancecheck < 0.0f && showstats)
                {
                    distancecheck = 1f;
                    MPLog.Writelog("[CVFlightDeck] ----------- ");
                    MPLog.Writelog("[CVFlightDeck] CV Heading " + CVHeading);
                    MPLog.Writelog("[CVFlightDeck] CV Rev Heading " + RevCVHeading);
                    //MPLog.Writelog("[CVFlightDeck] Port Deg: " + portdeg);
                    //MPLog.Writelog("[CVFlightDeck] Starboard Deg: " + stbddeg);
                    MPLog.Writelog("[CVFlightDeck] Aircraft Heading: " + aircraftheading);
                    MPLog.Writelog("[CVFlightDeck] Bearing: " + bearing);
                    MPLog.Writelog("[CVFlightDeck] Rev Bearing: " + revBearing);
                    MPLog.Writelog("[CVFlightDeck] Aircraft Stbd Deg: " + aircraftStbddeg);
                    MPLog.Writelog("[CVFlightDeck] Aircraft Port Deg: " + aircraftPortdeg);
                    MPLog.Writelog("[CVFlightDeck] Aircraft Stbd Angle Diff: " + MPFunctions.AngleDiff(aircraftheading, aircraftStbddeg));
                    MPLog.Writelog("[CVFlightDeck] Aircraft Port Angle Diff: " + MPFunctions.AngleDiff(aircraftheading, aircraftPortdeg));
                    MPLog.Writelog("[CVFlightDeck] Aircraft Deg off CV Rev Heading: " + MPFunctions.AngleDiff(RevCVHeading, bearing));

                    MPLog.Writelog("[CVFlightDeck] Incoming aircraft distance: " + distanceFromCarrier);
                    MPLog.Writelog("[CVFlightDeck] Aircraft Alt: " + FlightGlobals.ActiveVessel.altitude);
                    MPLog.Writelog("[CVFlightDeck] Elevation: " + elevation);
                }

                if (MPFunctions.AngleDiff(RevCVHeading, bearing) < boxdeflection)
                {
                    if (elevation < 10 && elevation > 0)
                    {
                        if (MPFunctions.AngleDiff(aircraftheading, aircraftPortdeg) < 45 || MPFunctions.AngleDiff(aircraftheading, aircraftStbddeg) < 45)
                        {
                            inthebox = true;
                        }
                    }
                }
                if (inthebox == true)
                {
                    //is aircraft in the box?

                    if (messagedelay <= 0)
                    {
                        if (inthebox)
                        {
                            ScreenMessages.PostScreenMessage("In the box", 2);
                            if (line != null)
                            {
                                line.SetColors(Color.green, Color.green);
                            }
                        }
                        else
                        {
                            ScreenMessages.PostScreenMessage("Out of the box", 2);
                            if (line != null)
                            {
                                line.SetColors(Color.red, Color.red);
                            }
                        }
                        messagedelay = 2f;
                    }
                }
            }
        }
예제 #7
0
        public void Update()
        {
            if (!HighLogic.LoadedSceneIsFlight || vessel.isActiveVessel)
            {
                return;                                                          //if the scene isn't a flight or the carrier is the active vessel... don't bother with the code. added to get rid of errors in sph.
            }
            if (waitforpilot)
            {
                preflighttimer -= Time.fixedDeltaTime;
                if (preflighttimer <= 0f)
                {
                    waitforpilot   = false;
                    preflighttimer = 3.0f;
                }
            }
            if (Input.GetKey(KeyCode.Tab) && (FlightGlobals.ActiveVessel.transform.position - this.part.transform.position).magnitude < 50)
            {
                if (catapultActive == false)
                {
                    if ((FlightGlobals.ActiveVessel.transform.position - this.part.transform.position).magnitude >= (5 + catapultLength))
                    {
                        if (waitforpilot == false)
                        {
                            float distancetocat = (FlightGlobals.ActiveVessel.transform.position - this.part.transform.position).magnitude;

                            MPLog.Writelog("[CVFlightDeck] Launch requested. Waiting for pilot.");
                            ScreenMessages.PostScreenMessage("You are " + distancetocat.ToString("n2") + " meters away from the catapult.");
                            ScreenMessages.PostScreenMessage("Move within 5 meters of the catapult.", 5);
                            MPLog.Writelog("[CVFlightDeck] Catapult distance > 5m.");
                            waitforpilot   = true;
                            preflighttimer = 3.0f;
                        }
                    }
                    else if (FlightGlobals.ActiveVessel.ctrlState.mainThrottle > 0f)
                    {
                        if (waitforpilot == false)
                        {
                            MPLog.Writelog("[CVFlightDeck] Launch requested. Waiting for pilot.");
                            ScreenMessages.PostScreenMessage("Pilot, set your throttle to 0.", 5);
                            MPLog.Writelog("[CVFlightDeck] Launch Throttle > 0.");
                            waitforpilot   = true;
                            preflighttimer = 3.0f;
                        }
                    }
                    else if (FlightGlobals.ActiveVessel.srf_velocity.magnitude > 0.1)
                    {
                        if (waitforpilot == false)
                        {
                            MPLog.Writelog("[CVFlightDeck] Launch requested. Waiting for pilot.");
                            ScreenMessages.PostScreenMessage("Pilot, set your brakes and bring your aircraft to a complete stop.", 5);
                            MPLog.Writelog("[CVFlightDeck] Launch Speed > 1.");
                            waitforpilot   = true;
                            preflighttimer = 3.0f;
                        }
                    }
                    else
                    {
                        MPLog.Writelog("[CVFlightDeck] Launch request accepted.");
                        ScreenMessages.PostScreenMessage("Launch requested.  Stand by...", 5);
                        waitforpilot   = false;
                        preflighttimer = 3.0f;
                        catapultActive = true;
                    }
                }
            }
        }
예제 #8
0
 public override void OnStart(StartState state)
 {
     MPLog.Writelog("[CVFlightDeck] Catapult ready. Clear the flight deck.");
 }