Beispiel #1
0
        public static Vector3 GetSize(Vessel v)
        {
            Bounds  bounds = default(Bounds);
            Vector3 orgPos = v.parts[0].orgPos;

            bounds.center = orgPos;
            List <Bounds> list = new List <Bounds>();

            foreach (Part current in v.parts)
            {
                MPLog.Writelog("[Maritime Pack] part: " + current.name + " WCoM" + current.WCoM);
                MPLog.Writelog("[Maritime Pack] part: " + current.name + " CoB" + current.CenterOfBuoyancy);
                MPLog.Writelog("[Maritime Pack] part: " + current.name + " CoD" + current.CenterOfDisplacement);

                Bounds[] partRendererBounds = PartGeometryUtil.GetPartRendererBounds(current);
                Bounds[] array = partRendererBounds;
                for (int i = 0; i < array.Length; i++)
                {
                    Bounds bounds2 = array[i];
                    Bounds bounds3 = bounds2;
                    bounds3.size *= current.boundsMultiplier;
                    Vector3 size = bounds3.size;
                    bounds3.Expand(current.GetModuleSize(size));
                    list.Add(bounds2);
                }
            }
            return(PartGeometryUtil.MergeBounds(list.ToArray(), v.parts[0].transform.root).size);
        }
Beispiel #2
0
        public override void OnStart(StartState state)
        {
            MPLog.Writelog("[Maritime Pack] MPSub Found");

            if (HighLogic.LoadedSceneIsFlight)
            {
                // set the default pressure to all parts
                if (currentPressure <= 0.0f)
                {
                    currentPressure = 4000f;
                }
                for (int i = this.vessel.parts.Count - 1; i >= 0; --i)
                {
                    this.vessel.parts[i].maxPressure = currentPressure;
                }

                /*  This code just double checks that part maxPressure is set
                 * double mPress = double.Parse(maxPressure);
                 * for (int i = this.vessel.parts.Count - 1; i >= 0; --i)
                 * {
                 *  double thisp = this.vessel.parts[i].maxPressure;
                 *  if (thisp < mPress)
                 *  {
                 *      mPress = thisp;
                 *  }
                 * }
                 */
                maxPressure = currentPressure + " kPa";
            }
        }
Beispiel #3
0
 public void Start()
 {
     if (HighLogic.LoadedSceneIsFlight)
     {
         foreach (Part mypart in this.vessel.parts)
         {
             if (mypart.Resources.Contains("CompressedWater"))
             {
                 if (rescount == 0)
                 {
                     Part1 = mypart;
                 }
                 if (rescount == 1)
                 {
                     Part2 = mypart;
                 }
                 rescount++;
             }
         }
         MPLog.Writelog("[Maritime Pack] Compressed Water Found: " + rescount);
         id           = MPFunctions.GetResourceID(Part1, "CompressedWater");
         batid        = MPFunctions.GetResourceID(Part1, "ElectricCharge");
         vesselvolume = MPFunctions.GetVolume(this.vessel);
     }
 }
Beispiel #4
0
 private void Start()
 {
     try
     {
         this.subWaterModel = GameDatabase.Instance.GetModel("Maritime Pack/Dome/Sub/model");
     }
     catch
     {
         MPLog.Writelog("[Maritime Pack] Problem locating SubWaterLayer!");
     }
     if (this.subWaterModel != null)
     {
         this.subWaterModel.SetActive(false);
     }
     else
     {
         MPLog.Writelog("[Maritime Pack ] One of the underwater environment models are not loading!");
     }
     if (UnderwaterCamera.ManualControl)
     {
         try
         {
             UnderwaterCamera.RestoreCameraParent();
         }
         catch (Exception)
         {
             MPLog.Writelog("[Maritime Pack ] Startup no active camera parent");
         }
         UnderwaterCamera.ManualControl = false;
     }
 }
Beispiel #5
0
        public bool shutdownUnder;  // in or out.  shuts down the engine based on if in or out of water.

        public override void OnStart(StartState state)
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            MPLog.Writelog("[Maritime Pack] (MPEngine) MPEngine Found" + this.vessel.name);
        }
Beispiel #6
0
        public static void RestoreCameraParent()
        {
            // Restore camera control to vessel.
            FlightCamera.fetch.transform.parent = _originalParentTransform;
            _originalParentTransform            = null;


            ManualControl = false;

            MPLog.Writelog("[Maritime Pack] FlightCamera restored to vessel.");
        }
Beispiel #7
0
 public void FindClone()
 {
     foreach (Part potentialMaster in this.part.symmetryCounterparts) //search for parts that might be my symmetry counterpart
     {
         if (potentialMaster != null)                                 //or we'll get a null-ref
         {
             clone = potentialMaster.Modules.OfType <ModuleMirror>().FirstOrDefault();
             MPLog.Writelog("[Maritime Pack] (found my clone");
         }
     }
 }
Beispiel #8
0
 public void Play_Anim(string aname, float aspeed, float atime = 0.0f)
 {
     logdelay -= Time.deltaTime;
     if (useRotorDiscSwap == true)
     {
         if (propeller != null && rotorDisc != null)
         {
             if (Math.Abs(aspeed) >= rotorDiscFadeInStart)
             {
                 rotorDisc.gameObject.GetComponent <Renderer>().enabled = true;
                 propeller.gameObject.GetComponent <Renderer>().enabled = false;
             }
             else
             {
                 rotorDisc.gameObject.GetComponent <Renderer>().enabled = false;
                 propeller.gameObject.GetComponent <Renderer>().enabled = true;
             }
         }
     }
     try
     {
         Animation   anim;
         Animation[] animators = part.FindModelAnimators(aname);
         if (animators.Length > 0)
         {
             anim      = animators[0];
             anim.clip = anim.GetClip(animationName);
             if (loopAnim == true)
             {
                 anim[aname].speed    = aspeed * animSpeed;
                 anim[aname].wrapMode = WrapMode.Loop;
             }
             else
             {
                 anim[aname].speed          = aspeed;
                 anim[aname].normalizedTime = atime;
             }
             if (logdelay <= 0)
             {
                 //MPLog.Writelog("[Maritime Pack] (aniEngine) Playing: "+aname+" speed:"+aspeed+" time:"+atime);
                 logdelay = 3;
             }
             anim.Play(aname);
         }
     }
     catch (Exception ex)
     {
         MPLog.Writelog("[Maritime Pack] (aniEngine) Exception in Play_Anim");
         MPLog.Writelog("[Maritime Pack] (aniEngine) Err: " + ex);
     }
 }
Beispiel #9
0
 public void Awake()
 {
     MPConfig.Getconfig();
     MPLog.NewLog();
     Application.runInBackground = true;
     if (MPUtilsrunning || !ElectionAndCheck())
     {
         MPLog.Writelog("[Maritime Pack] Multiple copies. Using the first copy. Version: " + MPFunctions.GetVersion());
         Destroy(gameObject);
         return;
     }
     DontDestroyOnLoad(gameObject);
     MPUtilsrunning = true;
     MPLog.Writelog("[Maritime Pack] MPUtils v" + MPFunctions.GetVersion() + " Anchors Aweigh!");
 }
Beispiel #10
0
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart(state);

            foreach (Transform tr in this.part.GetComponentsInChildren <Transform>())
            {
                if (tr.name.Equals("Left", StringComparison.Ordinal))
                {
                    MPLog.Writelog("[Maritime Pack] (Found left");
                    leftObject = tr;
                }

                if (tr.name.Equals("Right", StringComparison.Ordinal))
                {
                    MPLog.Writelog("[Maritime Pack] (Found right");
                    rightObject = tr;
                }
            }

            if (HighLogic.LoadedSceneIsFlight)
            {
                SetSide(flightSide);
                print("Loaded scene is flight");
            }

            print("Loaded scene is editor");
            print(flightSide);

            FindClone();
            if (clone != null)
            {
                MPLog.Writelog("[Maritime Pack] (Part is clone");
                //FindClone(); //make sure we have the clone. No harm in checking again
                SetSide(clone.cloneSide);
            }

            if (flightSide == "") //check to see if we have a value in persistence
            {
                MPLog.Writelog("[Maritime Pack] (No flightSide value in persistence. Sertting default");
                //print(this.part.isClone);
                LeftSide();
            }
            else //flightSide has a value, so set it.
            {
                MPLog.Writelog("[Maritime Pack] (Setting value from persistence");
                SetSide(flightSide);
            }
        }//end OnStart
Beispiel #11
0
        public bool ElectionAndCheck()
        {
            #region Type election

            // TODO : Move the old version check in a process that call Update.

            Assembly currentAssembly = Assembly.GetExecutingAssembly();
            IEnumerable <AssemblyLoader.LoadedAssembly> eligible = from a in AssemblyLoader.loadedAssemblies
                                                                   let ass = a.assembly
                                                                             where ass.GetName().Name == currentAssembly.GetName().Name
                                                                             orderby ass.GetName().Version descending, a.path ascending
            select a;

            if (eligible.Count() > 1)
            {
                multipleCopies = true;
            }
            if (eligible.First().assembly != currentAssembly)
            {
                //loaded = true;
                MPLog.Writelog("version " + currentAssembly.GetName().Version + " at " + currentAssembly.Location +
                               " lost the election");
                Destroy(gameObject);
                return(false);
            }
            string candidates = "";
            foreach (AssemblyLoader.LoadedAssembly a in eligible)
            {
                if (currentAssembly.Location != a.path)
                {
                    candidates += "Version " + a.assembly.GetName().Version + " " + a.path + " " + "\n";
                }
            }
            if (candidates.Length > 0)
            {
                MPLog.Writelog("version " + currentAssembly.GetName().Version + " at " + currentAssembly.Location +
                               " won the election against\n" + candidates);
            }

            #endregion Type election

            return(true);
        }
Beispiel #12
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");
             }
         }
     }
 }
Beispiel #13
0
        public static void SetCameraParent()
        {
            // Assign FlightCamera instance to public var.
            ActiveFlightCamera = FlightCamera.fetch;

            // For replacing the camera when done editing.
            if (_originalParentTransform == null)
            {
                _originalParentTransform = ActiveFlightCamera.transform.parent;
            }

            // For translating the camera
            if (ActiveCameraPivot != null)
            {
                GameObject.Destroy(ActiveCameraPivot);
            }
            ActiveCameraPivot = new GameObject("FSCamPivot");
            ActiveCameraPivot.transform.position = FlightGlobals.ActiveVessel.transform.position;

            ActiveFlightCamera.transform.position = FlightCamera.fetch.transform.position;
            ActiveCameraPivot.transform.LookAt(ActiveFlightCamera.transform.position, -1 * FlightGlobals.getGeeForceAtPosition(UnderwaterCamera.ActiveFlightCamera.transform.position).normalized);
            ActiveFlightCamera.transform.LookAt(ActiveCameraPivot.transform.position, -1 * FlightGlobals.getGeeForceAtPosition(UnderwaterCamera.ActiveFlightCamera.transform.position).normalized);

            // Switch to active object.
            ActiveFlightCamera.transform.parent = ActiveCameraPivot.transform;

            ActiveFlightCamera.maxDistance = 4900.00f; // dome is 5km

            // Use the FlightCamera sensitivity for the speed.
            CameraSpeed = ActiveFlightCamera.orbitSensitivity * CameraSpeedMulti;

            // Instruct LateUpdate that we're controlling the camera manually now.
            ManualControl = true;

            // Say something.
            MPLog.Writelog("[Maritime Pack] FlightCamera switched to: " + FlightGlobals.ActiveVessel.name);
        }
Beispiel #14
0
 public void Update()
 {
     if (!SubFound || FlightGlobals.ActiveVessel == null)
     {
         return;
     }
     //Camera Switch
     if (FlightGlobals.ActiveVessel.altitude <= -2.0 && MPUnderwaterCamera.active)
     {
         try
         {
             if (UnderwaterCamera.ManualControl && (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA || CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Internal)) // Exit when IVA too
             {
                 UnderwaterCamera.RestoreCameraParent();
                 return;
             }
         }
         catch (Exception)
         {
             MPLog.Writelog("[Maritime Pack] RestoreCameraParent Exception!");
             return;
         }
         if (!UnderwaterCamera.ManualControl)
         {
             try
             {
                 UnderwaterCamera.SetCameraParent();
                 MPLog.Writelog("[Maritime Pack] Setting Camera Parent");
             }
             catch (Exception ex)
             {
                 print("[Maritime Pack] Set Camera Exception!"); print(ex.Message);
             }
             try
             {
                 UnderwaterCamera.ManualControl = true;
                 cameraManualControl();
                 MPLog.Writelog("[Maritime Pack] Camera Manual Control Activated");
             }
             catch (Exception ex)
             {
                 MPLog.Writelog("[Maritime Pack] Camera Manual Control Exception!"); print(ex.Message);
             }
         }
         else
         {
             if (FlightCamera.fetch.enabled)
             {
                 new WaitForEndOfFrame();
                 cameraManualControl();
             }
         }
     }
     else
     {
         if (UnderwaterCamera.ManualControl)
         {
             try
             {
                 UnderwaterCamera.RestoreCameraParent();
             }
             catch (Exception ex)
             {
                 MPLog.Writelog("[Maritime Pack] Restore Camera Parent Exception!"); print(ex.Message);
             }
         }
     }
     //End Camera Switch
 }
Beispiel #15
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;
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #16
0
 public override void OnStart(StartState state)
 {
     MPLog.Writelog("[Maritime Pack] (SolarSteam) FCWSolarSteam Found on " + this.vessel.name);
 }
Beispiel #17
0
 public override void OnStart(StartState state)
 {
     MPLog.Writelog("[Maritime Pack] Sub Camera Found on " + vessel.name);
     // Add stuff to the log
     MPSubRoutines.SubFound = true;
 }
Beispiel #18
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            //man the pumps
            pumpDelay    -= Time.deltaTime;
            messageDelay -= Time.deltaTime;
            bool letsgo = true;

            if (pumpDelay <= 0)
            {
                pumpDelay = 1;
                if (pressurizerActive == true)
                {
                    depressurizerActive = false;
                    if (currentPressure >= MaxDepth * 10)
                    {
                        pressurizerActive = false;
                    }
                    else
                    {
                        if (pressureResource1 != "")
                        {
                            letsgo = ConsumeResource(pressureResource1, pressureResource1Amount);
                        }
                        if (pressureResource2 != "" && letsgo == true)
                        {
                            letsgo = ConsumeResource(pressureResource2, pressureResource2Amount);
                        }
                        if (letsgo)
                        {
                            currentPressure += 10;
                            for (int i = this.vessel.parts.Count - 1; i >= 0; --i)
                            {
                                this.vessel.parts[i].maxPressure = currentPressure;
                            }
                        }
                    }
                    maxPressure = currentPressure + " kPa";
                }
                if (depressurizerActive == true)
                {
                    if (currentPressure <= 4000)
                    {
                        depressurizerActive = false;
                    }
                    else
                    {
                        if (depressureResource1 != "")
                        {
                            letsgo = ConsumeResource(depressureResource1, depressureResource1Amount);
                        }
                        if (depressureResource2 != "" && letsgo == true)
                        {
                            letsgo = ConsumeResource(depressureResource2, depressureResource2Amount);
                        }
                        if (letsgo)
                        {
                            currentPressure -= 10;
                            for (int i = this.vessel.parts.Count - 1; i >= 0; --i)
                            {
                                this.vessel.parts[i].maxPressure = currentPressure;
                            }
                        }
                    }
                    maxPressure = currentPressure + " kPa";
                }
            }


            //get the current pressure on the parts
            double maxSPressure = 0.0f;

            for (int i = this.vessel.parts.Count - 1; i >= 0; --i)
            {
                double thisp = this.vessel.parts[i].staticPressureAtm;
                if (thisp > maxSPressure)
                {
                    maxSPressure = thisp;
                }
                sPressure = string.Format("{0:0.00}", (maxSPressure * 100)) + " kPa";
            }

            //check for overpressure
            if (currentPressure - maxSPressure < 4000)
            {
                if (messageDelay <= 0)
                {
                    messageDelay = 5;
                    //ScreenMessages.PostScreenMessage("Warning: Vessel is Over-Pressurized!!", 3);
                }
            }



            //MaxDepth - Prevent diving below max depth
            //if (this.vessel.altitude < -MPConfig.MPMaxDepth && MPConfig.MPMaxDepth != 0)
            //{
            //    vessel.ChangeWorldVelocity(vessel.upAxis + new Vector3d(0, 0, 0.1));
            //}

            //Close Intakes if we're diving
            if (manageIntakes && vessel.isActiveVessel && this.vessel.mainBody.ocean)
            {
                if (this.vessel.altitude <= -1.0)
                {
                    if (intakesOpen)
                    {
                        for (int p = this.vessel.Parts.Count - 1; p >= 0; --p)
                        {
                            for (int i = this.vessel.Parts[p].Modules.Count - 1; i >= 0; --i)
                            {
                                PartModule m = this.vessel.Parts[p].Modules[i];
                                if (m is ModuleResourceIntake)
                                {
                                    (m as ModuleResourceIntake).enabled = false;
                                    (m as ModuleResourceIntake).Deactivate();
                                    intakesOpen = false;
                                    MPLog.Writelog("[Maritime Pack] Closing Intakes");
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (!intakesOpen)
                    {
                        for (int p = this.vessel.Parts.Count - 1; p >= 0; --p)
                        {
                            for (int i = this.vessel.Parts[p].Modules.Count - 1; i >= 0; --i)
                            {
                                PartModule m = this.vessel.Parts[p].Modules[i];
                                if (m is ModuleResourceIntake)
                                {
                                    (m as ModuleResourceIntake).enabled = true;
                                    (m as ModuleResourceIntake).Activate();
                                    intakesOpen = true;
                                    MPLog.Writelog("[Maritime Pack] Opening Intakes");
                                }
                            }
                        }
                    }
                }
            }
            //end Close Intakes
            //Engine Shutdown if we're trying to fly
            //if (manageThrottle && vessel.isActiveVessel && this.vessel.mainBody.ocean)
            //{
            //    if (this.vessel.altitude > 2.0)
            //    {
            //        FlightInputHandler.state.mainThrottle = 0.0f;
            //    }
            //}
            //end Engine Shutdown
        }
Beispiel #19
0
 public override void OnStart(StartState state)
 {
     if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight)
     {
         if (partType == "Engine")
         {
             myEngine      = part.Modules.OfType <ModuleEngines>().FirstOrDefault();
             mytransform   = part.FindModelTransform(myEngine.thrustVectorTransformName);
             startRotation = mytransform.localRotation;
             if (useRotorDiscSwap == true)
             {
                 MPLog.Writelog("[Maritime Pack] (aniEngine) Disc swapping active.");
                 propeller = part.FindModelTransform(propellerName);
                 rotorDisc = part.FindModelTransform(rotorDiscName);
                 if (propeller == null)
                 {
                     useRotorDiscSwap = false;
                     MPLog.Writelog("[Maritime Pack] (aniEngine) Rotor Disc Swap enalbled but propeller gameObject not found");
                 }
                 if (rotorDisc == null)
                 {
                     useRotorDiscSwap = false;
                     MPLog.Writelog("[Maritime Pack] (aniEngine) Rotor Disc Swap enalbled but rotorDisc gameObject not found");
                 }
                 if (rotorDisc != null)
                 {
                     try
                     {
                         rotorDisc.gameObject.GetComponent <Renderer>().enabled = false;
                     }
                     catch (Exception)
                     {
                         MPLog.Writelog("[Maritime Pack] (aniEngine) Mesh Renederer not found on rotorDisc!!!");
                     }
                 }
                 if (propeller != null)
                 {
                     try
                     {
                         propeller.gameObject.GetComponent <Renderer>().enabled = true;
                     }
                     catch (Exception)
                     {
                         MPLog.Writelog("[Maritime Pack] (aniEngine) Mesh Renederer not found on propeller!!!");
                     }
                 }
             }
         }
         if (HighLogic.LoadedSceneIsFlight)
         {
             foreach (var anim in part.FindModelAnimators(animationName))
             {
                 aniEngine = anim;
                 if (aniEngine.GetClipCount() > 1)
                 {
                     aniEngine.Stop(); //stopping any animations loaded by ModuleAnimateGeneric
                 }
                 MPLog.Writelog("[Maritime Pack] (aniEngine) Found animation: " + animationName + " on " + part.name);
             }
             //MPLog.Writelog("[Maritime Pack] (aniEngine) Found Engine: " + myEngine.name);
             //MPLog.Writelog("[Maritime Pack] (aniEngine) Found aniEngine Name: " + aniEngine.name);
             //MPLog.Writelog("[Maritime Pack] (aniEngine) Sync Throttle: " + syncThrottle);
             //MPLog.Writelog("[Maritime Pack] (aniEngine) Smooth Throttle: " + smoothThrottle);
             //MPLog.Writelog("[Maritime Pack] (aniEngine) Loop Anim : " + loopAnim);
             //MPLog.Writelog("[Maritime Pack] (aniEngine) Anim Speed : " + animSpeed);
         }
         if (partType == "Intake")
         {
             myIntake = part.Modules.OfType <ModuleResourceIntake>().FirstOrDefault();
         }
     }
 }