public static void PrintFSM(KerbalEVA eva)
        {
            var fsm = eva.fsm;
            Debug.Log ("CurrentState: " + fsm.CurrentState.name);

            var type = fsm.GetType();
            Debug.Log ("Type: " + type.Name);
            var statesF = type.GetField ("States", BindingFlags.NonPublic | BindingFlags.Instance);
            List<KFSMState> states = (List<KFSMState>)statesF.GetValue (fsm);

            foreach (var state in states)
            {
                if (state == null)
                {
                    Debug.LogWarning ("null state found, skipping");
                    continue;
                }
                Debug.Log ("State: " + state.name + " : " + state.updateMode.ToString ());
                if (state.StateEvents == null)
                {
                    Debug.LogWarning ("No state events list found");
                    continue;
                }
                foreach (var evt in state.StateEvents)
                {
                    if (evt == null)
                    {
                        Debug.LogWarning ("null evt found, skipping");
                        continue;
                    }
                    Debug.Log ("----- Event: " + evt.name + ": => " + (evt.GoToStateOnEvent != null ? evt.GoToStateOnEvent.name : "N/A") + " : " + evt.updateMode.ToString ());
                }
            }
        }
 public static List<KFSMEvent> GetEVAEvents(KerbalEVA eva, List<KFSMState> states)
 {
     List<KFSMEvent> events = new List<KFSMEvent> ();
     foreach (var state in states)
     {
         events.AddRange ( state.StateEvents.Where(e => !events.Contains(e)) );
     }
     return events;
 }
    public static List<KFSMState> GetEVAStates(KerbalEVA eva)
    {
        var fsm = eva.fsm;

        var type = fsm.GetType();
        var statesF = type.GetField ("States", BindingFlags.NonPublic | BindingFlags.Instance);
        List<KFSMState> states = (List<KFSMState>)statesF.GetValue (fsm);
        return states;
    }
        //constructor
        public SelectedKerbalEVA(KerbalEVA eva)
        {
            Kerbal = eva;
            Joints01Transform = Part.transform.Find("globalMove01/joints01");
            States = KerbalEVAUtility.GetEVAStates (eva);

            AddAnimationState ();

            //set defaults
            IsAnimating = false;
        }
Exemplo n.º 5
0
        public static ExtendedSituation Extend(this Vessel.Situations?situation, TriState isEva, bool fallback)
        {
            if (!situation.HasValue)
            {
                return(ExtendedSituation.Default);
            }

            if (isEva == TriState.True)
            {
                KerbalEVA kerbal = FlightGlobals.ActiveVessel.evaController;

                bool ragDolled  = kerbal.isRagdoll;
                bool onLadder   = kerbal.OnALadder;
                bool clambering = NewMethod(kerbal);

                // Historian.Print(kerbal.fsm.currentStateName);
                if (!fallback)
                {
                    if (ragDolled)
                    {
                        return(ExtendedSituation.RagDolled);
                    }

                    if (clambering)
                    {
                        return(ExtendedSituation.Clambering);
                    }

                    if (onLadder)
                    {
                        return(ExtendedSituation.OnLadder);
                    }
                }
            }

            if (!fallback)
            {
                return((ExtendedSituation)situation.Value);
            }

            return(ExtendedSituation.Default);
        }
Exemplo n.º 6
0
        public static void Animate(this KerbalEVA eva, AnimationState state)
        {
            string anim = "Idle";

            switch (state)
            {
            case AnimationState.None: { } break;

            case AnimationState.Swim: { anim = "swim_forward"; } break;

            case AnimationState.Run: { anim = "wkC_run"; } break;

            case AnimationState.Walk: { anim = "wkC_forward"; } break;

            case AnimationState.BoundSpeed: { anim = "wkC_loG_forward"; } break;

            case AnimationState.Idle:
            {
                if (eva.part.WaterContact)
                {
                    anim = "swim_idle";
                }
                else if (eva.JetpackDeployed)
                {
                    anim = "jp_suspended";
                }
                else
                {
                    anim = "idle";
                }
            }
            break;
            }

            Animation _animation = null;

            eva.GetComponentCached <Animation>(ref _animation);
            if (_animation != null)
            {
                _animation.CrossFade(anim);
            }
        }
Exemplo n.º 7
0
            void OnChangeVessel(Vessel vessel)
            {
                Debug.Log("FlightTriggers.OnChangeVessel", "Vessel = " + vessel);

                if (vessel?.isEVA == true)
                {
                    KerbalEVA kerbal = FlightGlobals.ActiveVessel?.evaController;
                    Debug.Log("FlightTriggers.OnChangeVessel", "Kerbal = " + kerbal);

                    KerbalNavBall(kerbal);
                }
                else
                {
                    Part part = vessel?.GetReferenceTransformPart();

                    Debug.Log("FlightTriggers.OnChangeVessel", "Part = " + part);

                    PartNavBall(part);
                }
            }
Exemplo n.º 8
0
        /// <summary>
        /// Sets up left and right foot GameObjects. Called by the game.
        /// </summary>
        public void Start()
        {
            KerbalEVA evaModule = (KerbalEVA)this.part.Modules["KerbalEVA"];

            leftFoot      = new GameObject();
            leftFoot.name = "leftFoot";
            leftFoot.transform.position = transform.Search("footCollider_l").position;
            leftFoot.transform.rotation = transform.Search("footCollider_l").rotation;
            leftFoot.transform.parent   = evaModule.gameObject.transform;

            rightFoot      = new GameObject();
            rightFoot.name = "rightFoot";
            rightFoot.transform.position = transform.Search("footCollider_r").position;
            rightFoot.transform.rotation = transform.Search("footCollider_r").rotation;
            rightFoot.transform.parent   = evaModule.gameObject.transform;

            //KerbalEVA eva = (KerbalEVA) this.part.Modules["KerbalEVA"];
            //System.Collections.Generic.List<KFSMState> stateList = (System.Collections.Generic.List<KFSMState>) eva.fsm.GetType().GetField("States", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(eva.fsm);
            //stateList.ForEach(state => Debug.Log("[MagneticEVA] state: " + state.name));
        }
        bool checkForRagdoll(bool display = true)
        {
            KerbalEVA kEVA = this.vessel.gameObject.GetComponentInChildren <KerbalEVA>();

            if (kEVA)
            {
                Log.Info("KerbalEVA found");
                if (kEVA.isRagdoll)
                {
                    Log.Info("Kerbal is ragdoll: " + this.vessel.name);
                    if (display)
                    {
                        ScreenMessages.PostScreenMessage("Kerbal " + this.vessel.name + " is unconcious, unable to deploy parachute", 3, ScreenMessageStyle.UPPER_CENTER);
                    }
                    return(true);
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 10
0
        private void DisableSwimStopCondition(KerbalEVA eva)
        {
            if (this.swimStopCondition == null)
            {
                //Debug.Log("Disabling SwimStop");

                try
                {
                    foreach (var item in eva.fsm.CurrentState.StateEvents)
                    {
                        if (item.name == "Swim Stop")
                        {
                            this.swimStopCondition = item.OnCheckCondition;
                            item.OnCheckCondition  = this.eventConditionDisabled;
                        }
                    }
                }
                catch { }
            }
        }
Exemplo n.º 11
0
        public void evtHook_PostOnFixedUpdate(KerbalEVA eva)
        {
            ReflectedMembers.Initialize();

            //Recalculate fuel flow: proportional to power factor
            //Default power factors: rot 1, lin 0.3
            if (eva.JetpackDeployed)
            {
                float newflowrate = 0f;

                Vector3 cmdrot     = (Vector3)ReflectedMembers.eva_cmdRot.GetValue(eva);
                Vector3 packlinear = (Vector3)ReflectedMembers.eva_packLinear.GetValue(eva);

                newflowrate += cmdrot.magnitude * Time.fixedDeltaTime * eva.rotPower / 1f;
                newflowrate += packlinear.magnitude * Time.fixedDeltaTime * eva.linPower / 0.3f;

                //KSPLog.print ("Flow rates: " + ((float)ReflectedMembers.eva_fuelFlowRate.GetValue(eva)).ToString() + " -> " + newflowrate.ToString());
                ReflectedMembers.eva_fuelFlowRate.SetValue(eva, newflowrate);
            }
        }
Exemplo n.º 12
0
        //////////////////////////////////////////////////////////////////////////////

        public override void OnStart(StartState state)
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (part.vessel.isEVA)
                {
                    part.force_activate();

                    kerbalName = this.vessel.vesselName;
                    kerbal     = GetKerbal();

                    _maxJumpForce = kerbal.maxJumpForce;
                    _walkSpeed    = kerbal.walkSpeed;
                    _runSpeed     = kerbal.runSpeed;
                    _strafeSpeed  = kerbal.strafeSpeed;
                    _swimSpeed    = kerbal.swimSpeed;
                }
            }
            base.OnStart(state);
        }
Exemplo n.º 13
0
        public static void Update(Vessel v)
        {
            // do nothing if not an eva kerbal
            if (!v.isEVA)
            {
                return;
            }

            // get KerbalEVA module
            KerbalEVA kerbal = Lib.FindModules <KerbalEVA>(v)[0];

            // get resource handler
            Resource_Info ec = ResourceCache.Info(v, "ElectricCharge");

            // determine if headlamps need ec
            // - not required if there is no EC capacity in eva kerbal (no ec supply in profile)
            // - not required if no EC cost for headlamps is specified (set by the user)
            bool need_ec = ec.capacity > double.Epsilon && Settings.HeadLampsCost > double.Epsilon;

            // consume EC for the headlamps
            if (need_ec && kerbal.lampOn)
            {
                ec.Consume(Settings.HeadLampsCost * Kerbalism.elapsed_s);
            }

            // force the headlamps on/off
            HeadLamps(kerbal, kerbal.lampOn && (!need_ec || ec.amount > double.Epsilon));

            // if dead
            if (IsDead(v))
            {
                // enforce freezed state
                Freeze(kerbal);

                // disable modules
                DisableModules(kerbal);

                // remove plant flag action
                kerbal.flagItems = 0;
            }
        }
Exemplo n.º 14
0
        private MotionSettings GetNewMotionSettings(KerbalEVA kerbal, MotionSettings currentMotion)
        {
            var gforce    = FlightGlobals.currentMainBody.GeeASL;
            var newMotion = new MotionSettings
            {
                Animation = currentMotion.Animation,
                IsRunning = currentMotion.IsRunning,
                Speed     = currentMotion.Speed,
                State     = currentMotion.State,
            };

            if (currentMotion.State == MotionState.stopping)
            {
                newMotion.Animation = (kerbal.part.WaterContact) ? "swim_idle" : "idle";
                newMotion.Speed     = 0;
                newMotion.State     = MotionState.normal;
            }
            else if (kerbal.part.WaterContact)
            {
                newMotion.Animation = "swim_forward";
                newMotion.Speed     = kerbal.swimSpeed;
            }
            else if (currentMotion.IsRunning && (gforce >= kerbal.minRunningGee))
            {
                newMotion.Animation = "wkC_run";
                newMotion.Speed     = kerbal.runSpeed;
            }
            else if (gforce < kerbal.minWalkingGee)
            {
                newMotion.Animation = "wkC_loG_forward";
                newMotion.Speed     = kerbal.boundSpeed;
            }
            else
            {
                newMotion.Animation = "wkC_forward";
                newMotion.IsRunning = false;
                newMotion.Speed     = kerbal.walkSpeed;
            };

            return(newMotion);
        }
Exemplo n.º 15
0
        private void disableEvaEvents(KerbalEVA evaCtl, bool isEvaEnabled)
        {
            foreach (BaseEvent e in evaCtl.Events)
            {
                // Preserving the actions needed for EVA. These events should not be preserved if the Tourist can't EVA!
                if (isEvaEnabled && EVENT_WHITELIST.Contains(e.name))
                {
                    continue;
                }

                Log.dbg("disabling event {0} -- {1}", e.name, e.guiName);
                e.guiActive          = false;
                e.guiActiveUnfocused = false;
                e.guiActiveUncommand = false;
            }

            // ModuleScienceExperiment is only supported on KSP 1.7 **with** Breaking Ground installed, but it does not hurt
            // saving a DLL on the package by shoving the code here.
            foreach (PartModule m in evaCtl.part.Modules)
            {
                if (!m.ClassName.Equals("ModuleScienceExperiment"))
                {
                    continue;
                }
                Log.dbg("science module id: {0}", ((ModuleScienceExperiment)m).experimentID);
                // Disable all science
                foreach (BaseEvent e in m.Events)
                {
                    Log.dbg("disabling event {0}", e.guiName);
                    e.guiActive          = false;
                    e.guiActiveUnfocused = false;
                    e.guiActiveUncommand = false;
                }

                foreach (BaseAction a in m.Actions)
                {
                    Log.dbg("disabling action {0}", a.guiName);
                    a.active = false;
                }
            }
        }
Exemplo n.º 16
0
  [KSPField(isPersistant = true)] public bool is_dead = false;            // indicate if eva kerbal is dead


  public void FixedUpdate()
  {
    // get KerbalEVA module
    KerbalEVA kerbal = part.FindModuleImplementing<KerbalEVA>();

    // show/hide helmet, play nice with KIS
    if (!Kerbalism.detected_mods.KIS)
    {
      SetHelmet(kerbal, has_helmet);
    }
    // synchronize has_helmet state with KIS (for the headlights)
    else
    {
      has_helmet = HasHelmet(kerbal);
    }

    // consume EC for the headlamp
    if (has_helmet && kerbal.lampOn) part.RequestResource("ElectricCharge", Settings.HeadlightCost * TimeWarp.fixedDeltaTime);

    // determine if it has EC left
    bool ec_left = Lib.GetResourceAmount(part, "ElectricCharge") > double.Epsilon;

    // force the headlamp lights on/off depending on ec amount left and if it has an helmet
    SetHeadlamp(kerbal, has_helmet && kerbal.lampOn && ec_left);

    // synchronize helmet flares with headlamp state
    SetFlares(kerbal, has_helmet && kerbal.lampOn && ec_left);

    // if dead
    if (is_dead)
    {
      // enforce freezed state
      SetFreezed(kerbal);

      // remove plant flag action
      kerbal.flagItems = 0;

      // remove experiment actions (game engine keeps readding them)
      RemoveExperiments(kerbal);
    }
  }
Exemplo n.º 17
0
		void ToEVA(GameEvents.FromToAction<Part, Part> data)
		{
			// get total crew in the origin vessel
			double tot_crew = (double)Lib.CrewCount(data.from.vessel) + 1.0;

			// get vessel resources handler
			Vessel_resources resources = ResourceCache.Get(data.from.vessel);

			// setup supply resources capacity in the eva kerbal
			Profile.SetupEva(data.to);

			// for each resource in the kerbal
			for (int i = 0; i < data.to.Resources.Count; ++i)
			{
				// get the resource
				PartResource res = data.to.Resources[i];

				// determine quantity to take
				double quantity = Math.Min(resources.Info(data.from.vessel, res.resourceName).amount / tot_crew, res.maxAmount);

				// remove resource from vessel
				quantity = data.from.RequestResource(res.resourceName, quantity);

				// add resource to eva kerbal
				data.to.RequestResource(res.resourceName, -quantity);
			}

			// show warning if there isn't monoprop in the eva suit
			string prop_name = Lib.EvaPropellantName();
			if (Lib.Amount(data.to, prop_name) <= double.Epsilon && !Lib.Landed(data.from.vessel))
			{
				Message.Post(Severity.danger, Lib.BuildString("There isn't any <b>", prop_name, "</b> in the EVA suit"), "Don't let the ladder go!");
			}

			// turn off headlamp light, to avoid stock bug that show them for a split second when going on eva
			KerbalEVA kerbal = data.to.FindModuleImplementing<KerbalEVA>();
			EVA.HeadLamps(kerbal, false);

			// execute script
			DB.Vessel(data.from.vessel).computer.Execute(data.from.vessel, ScriptType.eva_out);
		}
Exemplo n.º 18
0
        public override void OnStart(StartState state)
        {
            bool useEvaSuit = false;

            ProtoCrewMember kerbal = part.protoModuleCrew.FirstOrDefault();

            if (kerbal != null)
            {
                KerbalEVA kerbalEva = GetComponent <KerbalEVA>();

                useEvaSuit = kerbal.hasHelmetOn || !kerbalEva.CanEVAWithoutHelmet();
                Personaliser.Instance.PersonaliseEva(part, kerbal, useEvaSuit);
            }

            if (Reflections.Instance.ReflectionType == Reflections.Type.Real &&
                Reflections.Instance.IsVisorReflectionEnabled)
            {
                reflectionScript = new Reflections.Script(part, 1);
                reflectionScript.SetActive(useEvaSuit);
            }
        }
Exemplo n.º 19
0
        public void ToggleJetpack()
        {
            if (!FlightGlobals.ActiveVessel.isEVA)
            {
                return;
            }

            KerbalEVA eva = GetKerbalEVA();

            try
            {
                foreach (var item in eva.fsm.CurrentState.StateEvents)
                {
                    if (item.name == "Pack Toggle")
                    {
                        eva.fsm.RunEvent(item);
                    }
                }
            }
            catch { }
        }
Exemplo n.º 20
0
  // set kerbal to the 'freezed' unescapable state
  public static void SetFreezed(KerbalEVA kerbal)
  {
    // do nothing if already freezed
    if (kerbal.fsm.currentStateName != "freezed")
    {
      // create freezed state
      KFSMState freezed = new KFSMState("freezed");

      // create freeze event
      KFSMEvent eva_freeze = new KFSMEvent("EVAfreeze");
      eva_freeze.GoToStateOnEvent = freezed;
      eva_freeze.updateMode = KFSMUpdateMode.MANUAL_TRIGGER;
      kerbal.fsm.AddEvent(eva_freeze, kerbal.fsm.CurrentState);

      // trigger eva death event
      kerbal.fsm.RunEvent(eva_freeze);
    }

    // stop animations
    kerbal.GetComponent<Animation>().Stop();
  }
Exemplo n.º 21
0
        /// <summary>
        /// Enable you to remove the helmet.
        /// </summary>
        /// <param name="eva"></param>
        /// <param name="showHelmet"></param>
        public static void ShowHelmet(this KerbalEVA eva, bool showHelmet)
        {
            foreach (Renderer renderer in eva.GetComponentsInChildren <Renderer>())
            {
                var smr = renderer as SkinnedMeshRenderer;

                if (smr != null)
                {
                    switch (smr.name)
                    {
                    case "helmet":
                    {
                        if (helmetMesh == null)
                        {
                            helmetMesh = smr.sharedMesh;
                        }

                        smr.sharedMesh = showHelmet ? helmetMesh : null;
                    }
                    break;

                    case "visor":
                    {
                        if (visorMesh == null)
                        {
                            visorMesh = smr.sharedMesh;
                        }

                        smr.sharedMesh = showHelmet ? visorMesh : null;
                    }
                    break;
                    }
                }
            }

            if (!showHelmet)
            {
                eva.TurnLamp(false);
            }
        }
Exemplo n.º 22
0
        private void UpdateWinchMouseGrab()
        {
            if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                if (clickedWinch)
                {
                    clickedWinch = null;
                    return;
                }
                if (FlightGlobals.ActiveVessel.isEVA)
                {
                    KerbalEVA kerbalEva = KAS_Shared.GetKerbalEvaUnderCursor();
                    if (kerbalEva)
                    {
                        KASModuleWinch winchModule = KAS_Shared.GetWinchModuleGrabbed(kerbalEva.vessel);
                        if (winchModule)
                        {
                            clickedWinch = winchModule;
                            return;
                        }
                    }

                    Transform headTransform = KAS_Shared.GetTransformUnderCursor();
                    if (headTransform)
                    {
                        KAS_LinkedPart linkedPart = headTransform.gameObject.GetComponent <KAS_LinkedPart>();
                        if (linkedPart)
                        {
                            float dist = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position,
                                                          headTransform.position);
                            if (dist <= radius)
                            {
                                clickedWinch = linkedPart.part.GetComponent <KASModuleWinch>();
                                return;
                            }
                        }
                    }
                }
            }
        }
        // Adding Selfie button
        private void addSelfie(KerbalEVA evaCtl)
        {
            Log.dbg("Adding Selfie to {0}", evaCtl.GUIName);
            BaseEventList     pEvents = evaCtl.Events;
            BaseEventDelegate slf     = new BaseEventDelegate(TakeSelfie);
            KSPEvent          evt     = new KSPEvent
            {
                active             = true,
                externalToEVAOnly  = true,
                guiActive          = true,
                guiActiveEditor    = false,
                guiActiveUnfocused = false,
                guiActiveUncommand = false,
                guiName            = "Take Selfie",
                name = "TakeSelfie"
            };
            BaseEvent selfie = new BaseEvent(pEvents, "Take Selfie", slf, evt);

            pEvents.Add(selfie);
            selfie.guiActive = true;
            selfie.active    = true;
        }
Exemplo n.º 24
0
        public void SetFirstPersonCameraSettings(KerbalEVA eva)
        {
            FlightCamera flightCam = FlightCamera.fetch;

            flightCam.transform.parent = eva.transform;
            //flightCam.transform.parent = FlightGlobals.ActiveVessel.transform;

            //enableRenderers(pVessel.transform, false);
            enableRenderers(eva.transform, false);

            flightCam.mainCamera.nearClipPlane = 0.01f;

            isFirstPerson = true;
            if (showSightAngle)
            {
                fpgui = flightCam.gameObject.AddOrGetComponent <FPGUI>();
            }
            flightCam.SetTargetNone();
            flightCam.DeactivateUpdate();
            viewToNeutral();
            reorient();
        }
Exemplo n.º 25
0
        public void DoJump()
        {
            if (!FlightGlobals.ActiveVessel.isEVA)
            {
                return;
            }
            //Debug.Log("DoJump");

            KerbalEVA eva = GetKerbalEVA();

            if (eva.OnALadder)
            {
                try
                {
                    foreach (var item in eva.fsm.CurrentState.StateEvents)
                    {
                        if (item.name == "Ladder Let Go")
                        {
                            eva.fsm.RunEvent(item);
                        }
                    }
                }
                catch { }
            }
            else
            {
                try
                {
                    foreach (var item in eva.fsm.CurrentState.StateEvents)
                    {
                        if (item.name == "Jump Start")
                        {
                            eva.fsm.RunEvent(item);
                        }
                    }
                }
                catch { }
            }
        }
Exemplo n.º 26
0
 private void Pickup()
 {
     icon = new KIS_IconViewer(draggedPart, draggedIconResolution);
     KISAddonCursor.StartPartDetection();
     grabActive = false;
     KISAddonCursor.CursorDisable();
     if (HighLogic.LoadedSceneIsFlight)
     {
         InputLockManager.SetControlLock(ControlTypes.VESSEL_SWITCHING, "KISpickup");
         // Disable jetpack mouse control (workaround as SetControlLock didn't have any effect on this)
         KerbalEVA Keva = FlightGlobals.ActiveVessel.rootPart.GetComponent <KerbalEVA>();
         if (Keva)
         {
             if (Keva.JetpackDeployed)
             {
                 Keva.JetpackDeployed = false;
                 jetpackLock          = true;
                 KIS_Shared.DebugLog("Jetpack mouse input disabled");
             }
         }
     }
 }
Exemplo n.º 27
0
        public void CheckAndSetFirstPerson(Vessel pVessel)
        {
            FlightCamera flightCam = FlightCamera.fetch;

            if (pVessel.isEVA)
            {
                if (!isFirstPerson &&
                    !pVessel.packed                    //this prevents altering camera until EVA is unpacked or else various weird effects are possible
                    )
                {
                    currentfpeva = pVessel.evaController;
                    SetFirstPersonCameraSettings(pVessel.evaController);

                    //Enter first person
                    FirstPersonEVA.instance.state.Reset(pVessel.evaController);

                    if (OnEnterFirstPerson != null)
                    {
                        OnEnterFirstPerson(pVessel.evaController);
                    }
                }

                KeyDisabler.instance.disableKey(KeyDisabler.eKeyCommand.CAMERA_NEXT, KeyDisabler.eDisableLockSource.FirstPersonEVA);
            }
            else
            {
                if (isFirstPerson)
                {
                    resetCamera(null);
                }
                else
                {
                    cameraState.saveState(flightCam);
                }

                KeyDisabler.instance.restoreKey(KeyDisabler.eKeyCommand.CAMERA_NEXT, KeyDisabler.eDisableLockSource.FirstPersonEVA);
            }
        }
        public void DoInteract()
        {
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                KerbalEVA eva = GetKerbalEVA();

                List <Collider> colliders = this.GetEVAColliders(eva);
                if (colliders.Count > 0)
                {
                    if (eva.OnALadder)
                    {
                        try
                        {
                            eva.fsm.RunEvent((KFSMEvent)this.eventFields[34].GetValue(eva));  // Board Vessel
                        }
                        catch (Exception)
                        {
                            return;
                        }
                    }
                    else
                    {
                        try
                        {
                            eva.fsm.RunEvent((KFSMEvent)this.eventFields[22].GetValue(eva));  // Grab Ladder
                        }
                        catch (Exception)
                        {
                            return;
                        }
                    }
                }
            }
            else
            {
                GoEVA();
            }
        }
        public override void InvokeAction()
        {
            // Store a transform for the destination position
            GameObject dummyObject = new GameObject("DummyLocation");
            dest = dummyObject.transform;

            // Get the actor and details
            actor = cutSceneDefinition.actor(actorName) as KerbalActor;
            Vessel eva = actor.eva;
            body = eva.mainBody;
            kerbalEVA = eva.gameObject.GetComponent<KerbalEVA>();

            // Set up the animation
            kerbalEVA.Animations.walkLowGee.State.speed = 2.7f;
            KerbalAnimationState animState = body.GeeASL > kerbalEVA.minWalkingGee ? kerbalEVA.Animations.walkFwd : kerbalEVA.Animations.walkLowGee;
            kerbalEVA.animation.CrossFade(animState.animationName);

            // Create the enumerator
            waypointEnumerator = waypoints.GetEnumerator();

            // Start the next waypoint
            NextWaypoint();
        }
 private void ReEnableStopConditions(KerbalEVA eva)
 {
     if (this.ladderStopCondition != null)
     {
         //Debug.Log("Re-enable LadderStop");
         KFSMEvent eLadderStop = (KFSMEvent)eventFields[26].GetValue(eva);
         eLadderStop.OnCheckCondition = this.ladderStopCondition;
         this.ladderStopCondition     = null;
     }
     if (this.swimStopCondition != null)
     {
         //Debug.Log("Re-enable SwimStop");
         KFSMEvent eSwimStop = (KFSMEvent)eventFields[21].GetValue(eva);
         eSwimStop.OnCheckCondition = this.swimStopCondition;
         this.swimStopCondition     = null;
     }
     if (this.runStopCondition != null)
     {
         //Debug.Log("Re-enable RunStop");
         KFSMEvent eRunStop = (KFSMEvent)eventFields[3].GetValue(eva);
         eRunStop.OnCheckCondition = this.runStopCondition;
         this.runStopCondition     = null;
     }
 }
Exemplo n.º 31
0
        public static void PrintFSM(KerbalEVA eva)
        {
            var fsm = eva.fsm;

            Debug.Log("CurrentState: " + fsm.CurrentState.name);

            var type = fsm.GetType();

            Debug.Log("Type: " + type.Name);
            var statesF             = type.GetField("States", BindingFlags.NonPublic | BindingFlags.Instance);
            List <KFSMState> states = (List <KFSMState>)statesF.GetValue(fsm);

            foreach (var state in states)
            {
                if (state == null)
                {
                    Debug.LogWarning("null state found, skipping");
                    continue;
                }
                Debug.Log("State: " + state.name + " : " + state.updateMode.ToString());
                if (state.StateEvents == null)
                {
                    Debug.LogWarning("No state events list found");
                    continue;
                }
                foreach (var evt in state.StateEvents)
                {
                    if (evt == null)
                    {
                        Debug.LogWarning("null evt found, skipping");
                        continue;
                    }
                    Debug.Log("----- Event: " + evt.name + ": => " + (evt.GoToStateOnEvent != null ? evt.GoToStateOnEvent.name : "N/A") + " : " + evt.updateMode.ToString());
                }
            }
        }
Exemplo n.º 32
0
        private void SunLightEVA(Vessel vessel, KerbalEVA kerbal)
        {
            if (CLSettings.onForEVASpace && (vessel.situation == Vessel.Situations.ESCAPING ||
                                             vessel.situation == Vessel.Situations.FLYING ||
                                             vessel.situation == Vessel.Situations.ORBITING ||
                                             vessel.situation == Vessel.Situations.SUB_ORBITAL))
            {
                kerbal.lampOn = true;
                return;
            }
            if (CLSettings.onForEVALanded && (vessel.situation == Vessel.Situations.LANDED ||
                                              vessel.situation == Vessel.Situations.PRELAUNCH ||
                                              vessel.situation == Vessel.Situations.SPLASHED))
            {
                kerbal.lampOn = true;
                return;
            }

            bool       isSunShine = false;
            RaycastHit hit;
            Vector3d   vesselPos = vessel.GetWorldPos3D();
            Vector3d   sunPos    = FlightGlobals.GetBodyByName("Sun").position;

            if (Physics.Raycast(vesselPos, sunPos, out hit, Mathf.Infinity, CLSettings.layerMask))
            {
                if (hit.transform.name == "Sun")
                {
                    isSunShine = true;
                }
            }

            if (!isSunShine)
            {
                kerbal.lampOn = true;
            }
        }
Exemplo n.º 33
0
        public void UpdateEVAFlightProperties(float pitch, float roll, float power)
        {
            KerbalEVA eva = FlightGlobals.ActiveVessel.GetComponent <KerbalEVA>();

            if (!FlightGlobals.ActiveVessel.Landed && eva.JetpackDeployed)
            {
                Quaternion rotation = Quaternion.identity;
                rotation *= Quaternion.AngleAxis(eva.turnRate * pitch * EVARotationStep * Time.deltaTime * power, -eva.transform.right);
                rotation *= Quaternion.AngleAxis(0, eva.transform.up);
                rotation *= Quaternion.AngleAxis(eva.turnRate * roll * EVARotationStep * Time.deltaTime * power, -eva.transform.forward);


                if (rotation != Quaternion.identity)
                {
                    var eva_tgtFwd = typeof(KerbalEVA).GetField("tgtFwd", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    var eva_tgtUp  = typeof(KerbalEVA).GetField("tgtUp", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

                    eva_tgtFwd.SetValue(eva, rotation * (Vector3)eva_tgtFwd.GetValue(eva));
                    eva_tgtUp.SetValue(eva, rotation * (Vector3)eva_tgtUp.GetValue(eva));
//                    this.vectorFields[9].SetValue(eva, rotation * (Vector3)this.vectorFields[9].GetValue(eva));
//                    this.vectorFields[13].SetValue(eva, rotation * (Vector3)this.vectorFields[13].GetValue(eva));
                }
            }
        }
Exemplo n.º 34
0
        public static void DisableModules(KerbalEVA kerbal)
        {
            for (int i = 0; i < kerbal.part.Modules.Count; ++i)
            {
                // get module
                PartModule m = kerbal.part.Modules[i];

                // ignore KerbalEVA itself
                if (m.moduleName == "KerbalEVA")
                {
                    continue;
                }

                // keep the flag decal
                if (m.moduleName == "FlagDecal")
                {
                    continue;
                }

                // disable all other modules
                m.isEnabled = false;
                m.enabled   = false;
            }
        }
Exemplo n.º 35
0
 private bool ProcessEjection(Part fromPart)
 {
     kerbalEVA = FlightEVA.fetch.spawnEVA(crew, fromPart, fromPart.airlock, true);
     if (kerbalEVA != null && kerbalEVA.vessel != null)
     {
         CameraManager.Instance.SetCameraFlight();
         if (crew != null && crew.KerbalRef != null)
         {
             crew.KerbalRef.state = Kerbal.States.BAILED_OUT;
             fromPart.vessel.RemoveCrew(crew);
         }
         Debug.Log("[BDArmory.KerbalSafety]: " + crew.displayName + " ejected from " + fromPart.vessel.vesselName + " at " + fromPart.vessel.radarAltitude.ToString("0.00") + "m with velocity " + fromPart.vessel.srf_velocity.magnitude.ToString("0.00") + "m/s (vertical: " + fromPart.vessel.verticalSpeed + ")");
         kerbalEVA.autoGrabLadderOnStart = false; // Don't grab the vessel.
         kerbalEVA.StartNonCollidePeriod(5f, 1f, fromPart, fromPart.airlock);
         KerbalSafetyManager.Instance.ManageNewlyEjectedKerbal(kerbalEVA, fromPart.vessel.GetSrfVelocity());
         recovered = true;
         OnDestroy();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 36
0
        /// <summary>
        /// Set the position of the selector. 
        /// </summary>
        /// <param name="eva"></param>
        /// <param name="lineRenderer"></param>
        private void SetSelectionLineProperties(KerbalEVA eva, LineRenderer lineRenderer)
        {
            double v = 1.5 + Math.Sin(angle) * 0.25;
            var p = eva.transform.position;
            var r = eva.transform.rotation;
            var f = eva.transform.forward;

            lineRenderer.transform.localScale = new Vector3((float)v, (float)v, (float)v);
            lineRenderer.transform.rotation = r * Quaternion.Euler(0,(float)(angle*60.0),0);;
            lineRenderer.transform.position = p;
        }
Exemplo n.º 37
0
 private void Start()
 {
     evaModule = this.part.GetComponent<KerbalEVA>();
 }
Exemplo n.º 38
0
		public void SetEva (KerbalEVA eva)
		{
			this.eva = eva;
			GenerateNewPosition ();
		}
Exemplo n.º 39
0
        public void Load(KerbalEVA eva)
        {
            //Load KerbalEVA.
            this.eva = eva;
            loaded = true;

            //Set Name
            this.Name = eva.name;

            //module on last.
            EvaModule module = (EvaModule)eva.GetComponent(typeof(EvaModule));
            module.Load(this);

            EvaDebug.DebugWarning("EvaContainer.Load("+eva.name+")");
        }
Exemplo n.º 40
0
 public void BoardWing()
 {
     seat.BoardSeat();
     wingCommander.MakeReference();
     evaKerbal = seat.Occupant.FindModuleImplementing<KerbalEVA>();
 }
        private bool CheckEVA()
        {
            if (currentVessel.isEVA && kerbalEVAPart == null)
              {
            kerbalEVAParts = currentVessel.FindPartModulesImplementing<KerbalEVA>();
            kerbalEVAPart = kerbalEVAParts.First();
              }

              if (currentVessel.isEVA && currentSettings.getBool("doEVAonlyIfOnGroundWhenLanded") && (parentVessel.Landed || parentVessel.Splashed) && (kerbalEVAPart.OnALadder || (!currentVessel.Landed && !currentVessel.Splashed)))
              {
            return false;
              }
              return true;
        }