Exemplo n.º 1
0
        private void RealModePumpXfer()
        {
            try
            {
                if (tXferOn || sXferOn)
                {
                    double deltaT = 0;
                    flow_rate = ShipManifestSettings.FlowRate;

                    switch (XferState)
                    {
                        case XFERState.Off:
                            // reset counters
                            timestamp = 0;

                            // Default sound license: CC-By-SA
                            // http://www.freesound.org/people/vibe_crc/sounds/59328/
                            string path1 = ShipManifestSettings.PumpSoundStart; // "ShipManifest/Sounds/59328-1";
                            string path2 = ShipManifestSettings.PumpSoundRun;   // "ShipManifest/Sounds/59328-2";
                            string path3 = ShipManifestSettings.PumpSoundStop;  // "ShipManifest/Sounds/59328-3";

                            // Load Sounds, and Play Sound 1
                            LoadSounds("Pump", path1, path2, path3, ShipManifestSettings.PumpSoundVol);
                            XferState = XFERState.Start;
                            break;

                        case XFERState.Start:

                            // calculate elapsed.
                            elapsed += Planetarium.GetUniversalTime();

                            // Play run sound when start sound is nearly done. (repeats)
                            if (elapsed >= source1.clip.length - 0.25)
                            {
                                source2.Play();
                                ManifestUtilities.LogMessage("Transfer State:  " + XferState.ToString() + "...", "Info", SettingsManager.VerboseLogging);
                                elapsed = 0;
                                XferState = XFERState.Run;
                            }
                            break;

                        case XFERState.Run:

                            deltaT = Planetarium.GetUniversalTime() - timestamp;
                            double deltaAmt = deltaT * flow_rate;

                            // This adjusts the delta when we get to the end of the xfer.
                            float XferAmount = 0f;
                            // which way we going?
                            if (tXferOn)
                                XferAmount = ManifestController.GetInstance(FlightGlobals.ActiveVessel).tXferAmount;
                            else
                                XferAmount = ManifestController.GetInstance(FlightGlobals.ActiveVessel).sXferAmount;

                            if (ManifestController.GetInstance(FlightGlobals.ActiveVessel).AmtXferred + (float)deltaAmt >= XferAmount)
                            {
                                deltaAmt = XferAmount - ManifestController.GetInstance(FlightGlobals.ActiveVessel).AmtXferred;
                                XferState = XFERState.Stop;
                                ManifestUtilities.LogMessage("10. Adjusted DeltaAmt = " + deltaAmt.ToString(), "Info", SettingsManager.VerboseLogging);
                            }
                            ManifestUtilities.LogMessage("11. DeltaAmt = " + deltaAmt.ToString(), "Info", SettingsManager.VerboseLogging);

                            // Lets increment the AmtXferred....
                            ManifestController.GetInstance(FlightGlobals.ActiveVessel).AmtXferred += (float)deltaAmt;
                            ManifestUtilities.LogMessage("11a. AmtXferred = " + ManifestController.GetInstance(FlightGlobals.ActiveVessel).AmtXferred.ToString(), "Info", SettingsManager.VerboseLogging);

                            // Drain source...
                            // and let's make sure we can move the amount requested or adjust it and stop the flow after the move.
                            if (tXferOn)
                            {
                                // Source is target on Interface...
                                // if the amount to move exceeds either the balance of the source or the capacity of the target, reduce it.
                                if (ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartTarget.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount - deltaAmt < 0)
                                {
                                    deltaAmt = ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartTarget.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount;
                                    XferState = XFERState.Stop;
                                }
                                else if (ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartSource.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount + deltaAmt > ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartSource.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].maxAmount)
                                {
                                    deltaAmt = ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartSource.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].maxAmount - ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartSource.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount;
                                    XferState = XFERState.Stop;
                                }

                                ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartTarget.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount -= deltaAmt;
                            }
                            else
                            {
                                // Source is source on Interface...
                                if (ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartSource.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount - deltaAmt < 0)
                                {
                                    deltaAmt = ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartSource.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount;
                                    XferState = XFERState.Stop;
                                }
                                else if (ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartTarget.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount + deltaAmt > ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartTarget.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].maxAmount)
                                {
                                    deltaAmt = ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartTarget.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].maxAmount - ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartTarget.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount;
                                    XferState = XFERState.Stop;
                                }

                                ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartSource.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount -= deltaAmt;
                            }

                            ManifestUtilities.LogMessage("12. Drain Source Part = " + deltaAmt.ToString(), "Info", SettingsManager.VerboseLogging);

                            // Fill target
                            if (tXferOn)
                                ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartSource.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount += deltaAmt;
                            else
                                ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartTarget.Resources[ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedResource].amount += deltaAmt;

                            ManifestUtilities.LogMessage("13. Fill Target Part = " + deltaAmt.ToString(), "Info", SettingsManager.VerboseLogging);

                            ManifestUtilities.LogMessage("Transfer State:  " + XferState.ToString() + "...", "Info", SettingsManager.VerboseLogging);
                            break;

                        case XFERState.Stop:

                            // play pump shutdown.
                            source2.Stop();
                            source3.Play();
                            timestamp = elapsed = 0;
                            XferState = XFERState.Off;
                            ManifestController.GetInstance(FlightGlobals.ActiveVessel).AmtXferred = 0f;
                            tXferOn = sXferOn = false;
                            break;
                    }
                    ManifestUtilities.LogMessage("Transfer State:  " + XferState.ToString() + "...", "Info", SettingsManager.VerboseLogging);
                    if (XferState != XFERState.Off)
                        timestamp = Planetarium.GetUniversalTime();
                }
            }
            catch (Exception ex)
            {
                ManifestUtilities.LogMessage(string.Format(" in RealModePumpXfer.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), "Error", true);
            }
        }
Exemplo n.º 2
0
        private void RealModeCrewXfer()
        {
            try
            {
                if (crewXfer)
                {
                    if (!ShipManifestSettings.RealismMode)
                    {
                        if (timestamp != 0)
                            elapsed += Planetarium.GetUniversalTime() - timestamp;

                        if (elapsed > 1)
                        {
                            // Fire Board event for Texture Replacer.
                            if (SettingsManager.EnableTextureReplacer)
                                GameEvents.onCrewBoardVessel.Fire(ManifestController.GetInstance(FlightGlobals.ActiveVessel).evaAction);

                            // Spawn crew in parts and in vessel.
                            ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartSource.vessel.SpawnCrew();
                            ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartTarget.vessel.SpawnCrew();
                            ManifestController.GetInstance(FlightGlobals.ActiveVessel).RespawnCrew();

                            FireEventTriggers();
                            elapsed = timestamp = 0;
                            crewXfer = false;
                            ManifestUtilities.LogMessage("crewXfer State:  " + crewXfer.ToString() + "...", "Info", SettingsManager.VerboseLogging);
                        }
                        if (crewXfer)
                            timestamp = Planetarium.GetUniversalTime();
                    }
                    else
                    {
                        switch (XferState)
                        {
                            case XFERState.Off:
                                // We're just starting loop, so set some evnironment stuff.
                                timestamp = 0;

                                // Default sound license: CC-By-SA
                                // http://www.freesound.org/people/adcbicycle/sounds/14214/
                                string path1 = ShipManifestSettings.CrewSoundStart; // "ShipManifest/Sounds/14214-1";
                                string path2 = ShipManifestSettings.CrewSoundRun;   // "ShipManifest/Sounds/14214-2";
                                string path3 = ShipManifestSettings.CrewSoundStop;  // "ShipManifest/Sounds/14214-3";

                                LoadSounds("Crew", path1, path2, path3, ShipManifestSettings.CrewSoundVol);
                                XferState = XFERState.Start;
                                break;

                            case XFERState.Start:

                                elapsed += Planetarium.GetUniversalTime() - timestamp;

                                // Play run sound when start sound is nearly done. (repeats)
                                if (elapsed >= source1.clip.length - 0.25)
                                {
                                    source2.Play();
                                    elapsed = 0;
                                    XferState = XFERState.Run;
                                }
                                break;

                            case XFERState.Run:

                                elapsed += Planetarium.GetUniversalTime() - timestamp;

                                // wait for movement to end...
                                if (elapsed >= crewXferDelaySec || (isSeat2Seat && elapsed > Seat2SeatXferDelaySec))
                                {
                                    // Reset State vars
                                    XferState = XFERState.Stop;
                                }
                                break;

                            case XFERState.Stop:

                                ManifestUtilities.LogMessage("Update:  Updating Portraits...", "info", SettingsManager.VerboseLogging);

                                // Spawn crew in parts and in vessel.
                                ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartSource.vessel.SpawnCrew();
                                ManifestController.GetInstance(FlightGlobals.ActiveVessel).SelectedPartTarget.vessel.SpawnCrew();
                                ManifestController.GetInstance(FlightGlobals.ActiveVessel).RespawnCrew();

                                // play crew sit.
                                source2.Stop();
                                source3.Play();
                                ShipManifestBehaviour.timestamp = elapsed = 0;
                                XferState = XFERState.Off;
                                crewXfer = false;
                                isSeat2Seat = false;

                                // Fire Board event for Texture Replacer.
                                if (SettingsManager.EnableTextureReplacer)
                                    GameEvents.onCrewBoardVessel.Fire(ManifestController.GetInstance(FlightGlobals.ActiveVessel).evaAction);

                                // Notify Mods requiring it to update (Texture Replacer Kerbal (IVA) textures, ConnectedLivingSpaces.
                                FireEventTriggers();
                                break;
                        }
                        ManifestUtilities.LogMessage("Transfer State:  " + XferState.ToString() + "...", "Info", SettingsManager.VerboseLogging);
                        if (XferState != XFERState.Off)
                            timestamp = Planetarium.GetUniversalTime();
                    }
                }
            }
            catch (Exception ex)
            {
                ManifestUtilities.LogMessage(string.Format(" in RealModeCrewXfer.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), "Error", true);
            }
        }