Ejemplo n.º 1
0
        protected override void OnEnterToState(KFSMState kfsmState)
        {
            Log.Info("OnEnterToState: LaunchState");
            base.OnEnterToState(kfsmState);

            _audioSource = _obj.AddComponent <AudioSource>();
            _audioSource.spatialBlend = 0;
            _audioSource.volume       = GameSettings.VOICE_VOLUME;

            if (ConfigInfo.Instance.EngineControl)
            {
                FlightGlobals.ActiveVessel.OnFlyByWire = (FlightInputCallback)Delegate.Combine(FlightGlobals.ActiveVessel.OnFlyByWire, (FlightInputCallback)OnFlyByWire);
            }

            GameEvents.onVesselSituationChange.Add(SituationChanged);

            if (!ConfigInfo.Instance.Sequences.ContainsKey(FlightGlobals.ActiveVessel.id))
            {
                ConfigInfo.Instance.Sequences.Add(FlightGlobals.ActiveVessel.id, Enumerable.Repeat(-1, 10).ToArray());
            }
            _stages = ConfigInfo.Instance.Sequences[FlightGlobals.ActiveVessel.id].Select(x => x < 0 ? new Action(() => { }) : new Action(() => StageManager.ActivateStage(x))).ToList();


            _dummy.StartCoroutine(this.TickLaunch());
        }
Ejemplo n.º 2
0
 void onleave_idle(KFSMState s)
 {
     if (RecycleField != null)
     {
         RecycleField.enabled = false;
     }
 }
Ejemplo n.º 3
0
        //bool initialPos = false;
        protected virtual void OnEnterToState(KFSMState kfsmState)
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return;
            }
            Log.Info("OnEnterToState: InitialState");
            if (FlightGlobals.ActiveVessel.situation != Vessel.Situations.PRELAUNCH)
            {
                Machine.RunEvent("Finish");
            }

            _obj               = new GameObject("Helper");
            _dummy             = _obj.AddComponent <DummyComponent>();
            StyleFactory.Scale = ConfigInfo.Instance.Scale;
            StyleFactory.Reload();

#if false
            if (!initialPos)
            {
                initialPos  = true;
                _windowRect = ScaleRect(GUIUtil.ScreenCenteredRect(459, 120));
            }
#else
            _windowRect = CountDownMain.saveLoadWinPos.initialWindow;
            //    CountDownMain.saveLoadWinPos.initialWindow;
            //if (!initialPos)
            //{
            //    initialPos = true;
            //    _windowRect = ScaleRect(_windowRect);
            //}
#endif
        }
Ejemplo n.º 4
0
 void onenter_idle(KFSMState s)
 {
     if (RecycleField != null)
     {
         RecycleField.enabled = true;
     }
 }
Ejemplo n.º 5
0
 public void Load(ConfigNode node)
 {
     recycle_parts = new HashSet <uint> ();
     if (node.HasValue("recycle_parts"))
     {
         var  ids = node.GetValue("recycle_parts").Split(new char[] { ' ' });
         uint id;
         for (int i = 0; i < ids.Length; i++)
         {
             if (uint.TryParse(ids[i], out id))
             {
                 recycle_parts.Add(id);
             }
         }
     }
     if (node.HasNode("part_resource"))
     {
         part_resources = new List <BuildResource> ();
         foreach (var pr in node.GetNodes("part_resource"))
         {
             var res = new BuildResource();
             res.Load(pr);
             part_resources.Add(res);
         }
     }
     if (node.HasValue("state"))
     {
         var state = fsm.FindState(node.GetValue("state"));
         if (state != null)
         {
             start_state = state;
         }
     }
 }
Ejemplo n.º 6
0
 void onleave_processing_part(KFSMState s)
 {
     Debug.Log(String.Format("[EL RSM] onleave_processing_part"));
     recycle_parts.Remove(active_part.flightID);
     active_part.Die();
     active_part = null;
 }
Ejemplo n.º 7
0
        public static void Freeze(KerbalEVA kerbal)
        {
            // set kerbal to the 'freezed' unescapable state
            // how it works:
            // - kerbal animations and ragdoll state are driven by a finite-state-machine (FSM)
            // - this function is called every frame for all active eva kerbals flagged as dead
            // - if the FSM current state is already 'freezed', we do nothing and this function is a no-op
            // - we create an 'inescapable' state called 'freezed'
            // - we switch the FSM to that state using an ad-hoc event from current state
            // - once the 'freezed' state is set, the FSM cannot switch to any other states
            // - the animator of the object is stopped to stop any left-over animations from previous state

            // do nothing if already freezed
            if (!string.IsNullOrEmpty(kerbal.fsm.currentStateName) && kerbal.fsm.currentStateName != "freezed")
            {
                // create freezed state
                KFSMState freezed = new KFSMState("freezed");

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

                // trigger freeze event
                kerbal.fsm.RunEvent(eva_freeze);

                // stop animations
                kerbal.GetComponent <Animation>().Stop();
            }
        }
Ejemplo n.º 8
0
 void ResetJetpackManualControls(KerbalEVA eva, KFSMState s)
 {
     //When jetpacking, the kerbal may have been in manual axis control.
     //We are now grounded, so that needs to be disabled or we will sidestep-walk
     //rather than turning.
     ReflectedMembers.eva_manualAxisControl.SetValue(eva, false);
     ReflectedMembers.eva_cmdRot.SetValue(eva, Vector3.zero);
 }
Ejemplo n.º 9
0
 void ResetTurningBasisVector(KerbalEVA eva, KFSMState s)
 {
     walk_start_fwd = eva.transform.forward;
     current_turn   = 0f;
     //target_fwd = walk_start_fwd;
     //directionkeypresscount = 0;
     //h_integral = 0f;
     //h_previouserror = 0f;
     ReflectedMembers.eva_integral.SetValue(eva, Vector3.zero);
     ReflectedMembers.eva_prev_error.SetValue(eva, Vector3.zero);
 }
Ejemplo n.º 10
0
 protected override void OnLeaveFromState(KFSMState kfsmState)
 {
     Log.Info("OnLeaveFromState: LaunchState");
     base.OnLeaveFromState(kfsmState);
     if (ConfigInfo.Instance.EngineControl)
     {
         Log.Info("Removing OnFlyByWire");
         FlightGlobals.ActiveVessel.OnFlyByWire = (FlightInputCallback)Delegate.Remove(FlightGlobals.ActiveVessel.OnFlyByWire, (FlightInputCallback)OnFlyByWire);
     }
     GameEvents.onVesselSituationChange.Remove(SituationChanged);
 }
Ejemplo n.º 11
0
        protected virtual void OnLeaveFromState(KFSMState kfsmState)
        {
            if (_dummy == null)
            {
                return;
            }
            Log.Info("OnLeaveFromState: InitialState");
            FlightInputHandler.state.mainThrottle = HighLogic.CurrentGame.Parameters.CustomParams <NC>().defaultThrottle;

            _dummy.StopAllCoroutines();
            _obj.DestroyGameObjectImmediate();
        }
Ejemplo n.º 12
0
 //*********Bound floating RCS toggle*********
 bool Check_Bound_Jetpack(KFSMState currentstate)
 {
     if (!CanControl())
     {
         return(false);
     }
     if (!GameSettings.EVA_TogglePack.GetKeyDown(false))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 13
0
        protected virtual void OnLeaveFromState(KFSMState kfsmState)
        {
            if (_dummy == null)
            {
                return;
            }
            Log.Info("OnLeaveFromState: InitialState");
            FlightInputHandler.state.mainThrottle = ConfigInfo.Instance.VesselOptions[ModuleNASACountdown.CraftName(FlightGlobals.ActiveVessel)].defaultThrottle;

            _dummy.StopAllCoroutines();
            _obj.DestroyGameObjectImmediate();
        }
Ejemplo n.º 14
0
        void ForceArcadeMode(KerbalEVA eva, KFSMState s)
        {
            DEBUG_DeltaHdg(eva, "ForceArcadeMode ");

            if (GameSettings.EVA_back.GetKey(false))
            {
                eva.CharacterFrameModeToggle = true;                    //Force fps mode walking
            }
            else
            {
                eva.CharacterFrameModeToggle = false;                   //Force arcade mode walking
            }
        }
Ejemplo n.º 15
0
        public HookedKerbalFSMState(KFSMState poriginalstate, delHookCondition hookoperationcondition)
            : base(poriginalstate.name)
        {
            originalstate = poriginalstate;

            HookCondition = hookoperationcondition;

            updateMode    = originalstate.updateMode;
            OnEnter       = new KFSMStateChange(H_OnEnter);
            OnLeave       = new KFSMStateChange(H_OnLeave);
            OnUpdate      = new KFSMCallback(H_OnUpdate);
            OnFixedUpdate = new KFSMCallback(H_OnFixedUpdate);
            OnLateUpdate  = new KFSMCallback(H_OnLateUpdate);
        }
Ejemplo n.º 16
0
        bool check_conceive(KFSMState st)
        {
            if (female.location.isWatched())
            {
                return(false);
            }
            if (!female.isInterested())
            {
                return(false);
            }
            var mate = female.SelectMate(female.location.Males());

            return(mate != null?female.Mate(mate) : false);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// This is the eva callback that sends the events to the server
        /// </summary>
        public void LmpOnStateChange(KFSMState prevState, KFSMState newState, KFSMEvent eventToRun)
        {
            var module = GetKerbalEvaModule(FlightGlobals.ActiveVessel) as KerbalEVA;

            if (module != null)
            {
                MessageSender.SendEvaData(FlightGlobals.ActiveVessel, newState.name, eventToRun.name, module.lastBoundStep);
                UpdateFsmStateInProtoVessel(FlightGlobals.ActiveVessel.protoVessel, newState.name, module.lastBoundStep);
            }
            else
            {
                MessageSender.SendEvaData(FlightGlobals.ActiveVessel, newState.name, eventToRun.name);
                UpdateFsmStateInProtoVessel(FlightGlobals.ActiveVessel.protoVessel, newState.name);
            }
        }
Ejemplo n.º 18
0
        //*********Increase bound timeout*********
        bool Replacement_On_bound_fall_OnCheckCondition(KFSMState currentstate)
        {
            if (ReflectedMembers.eva_m_SurfaceOrSplashed(myeva))
            {
                return(false);
            }

            double boundtimeout = (double)myeva.lastBoundStep;

            boundtimeout *= Mathf.Lerp(myeva.boundFallThreshold, myeva.boundFallThreshold * 5f,
                                       (myeva.minWalkingGee - (float)myeva.vessel.mainBody.GeeASL) / myeva.minWalkingGee);

            //KSPLog.print ("Bound fall? " + myeva.fsm.TimeAtCurrentState.ToString() + " / " + boundtimeout.ToString());
            return(myeva.fsm.TimeAtCurrentState > boundtimeout);
        }
Ejemplo n.º 19
0
        private void EnterState(KFSMState kfsmState)
        {
            Log.Info("EnterState: LaunchedState");
            if (ConfigInfo.Instance.CurrentAudio == null)
            {
                return;
            }

            _obj         = new GameObject();
            _audioSource = _obj.AddComponent <AudioSource>();
            _audioSource.spatialBlend = 0;
            _audioSource.volume       = GameSettings.VOICE_VOLUME;


            //_obj.AddComponent<MonoBehaviour>().StartCoroutine(LaunchedSuccess());
            _dummy = _obj.AddComponent <DummyComponent>();
            _dummy.StartCoroutine(LaunchedSuccess());
        }
Ejemplo n.º 20
0
        //*********Fix for "cannot land" on steep surfaces*********
        bool Replacement_On_bound_land_OnCheckCondition(KFSMState currentstate)
        {
            if (myeva.vessel.Splashed)
            {
                return(true);
            }
            if (myeva.fsm.TimeAtCurrentState < 0.1d)
            {
                return(false);
            }

            double boundlandingheight = (double)(float)ReflectedMembers.eva_halfHeight.GetValue(myeva) + (double)myeva.boundThreshold;

            //The standard downward check
            Vector3d downdir = -FlightGlobals.getUpAxis(myeva.vessel.mainBody, myeva.vessel.vesselTransform.position);
            Vector3d hitnormal;
            double   verticalheight = Math.Abs(ProbeSurface(downdir, out hitnormal, true));

            if (verticalheight < boundlandingheight)
            {
                //KSPLog.print ("Replacement_On_bound_land_OnCheckCondition: HIT 1");
                return(true);
            }
            else
            {
                //Give them a little more time to take off on hills
                if (myeva.fsm.TimeAtCurrentState < 0.3d)
                {
                    return(false);
                }

                //Try again in the direction of the previous hit normal, but without updating our Vessel.
                verticalheight = Math.Abs(ProbeSurface(-hitnormal, out hitnormal, false));

                if (verticalheight < boundlandingheight)
                {
                    //KSPLog.print ("Replacement_On_bound_land_OnCheckCondition: HIT 2");
                    return(true);
                }
            }

            //KSPLog.print ("Replacement_On_bound_land_OnCheckCondition: Miss");
            return(false);
        }
Ejemplo n.º 21
0
 void H_OnLeave(KFSMState s)
 {
     if (HookCondition(eva))
     {
         if (PreOnLeave != null)
         {
             PreOnLeave(eva, s);
         }
         originalstate.OnLeave(s);
         if (PostOnLeave != null)
         {
             PostOnLeave(eva, s);
         }
     }
     else
     {
         originalstate.OnLeave(s);
     }
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Forcibly restores the ability to drop parts in the editor
 /// </summary>
 public void RestorePartDropping()
 {
     if (st_place_Backup != null)
     {
         EditorLogic.fetch.GetType().GetField("st_place", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy)?.SetValue(EditorLogic.fetch, st_place_Backup);
         st_place_Backup = null;
         Logging.DebugLog("Restored st_place");
     }
     if (on_partDropped_Backup != null)
     {
         KFSMEvent on_partDropped = EditorLogic.fetch.GetType().GetField("on_partDropped", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy)?.GetValue(EditorLogic.fetch) as KFSMEvent;
         if (on_partDropped != null)
         {
             on_partDropped.OnCheckCondition = on_partDropped_Backup;
             on_partDropped_Backup           = null;
             Logging.DebugLog("Restored on_partDropped");
         }
     }
 }
Ejemplo n.º 23
0
 void H_OnEnter(KFSMState s)
 {
     //KSPLog.print ("ENTER STATE: " + originalstate.name);
     if (HookCondition(eva))
     {
         if (PreOnEnter != null)
         {
             PreOnEnter(eva, s);
         }
         originalstate.OnEnter(s);
         if (PostOnEnter != null)
         {
             PostOnEnter(eva, s);
         }
     }
     else
     {
         originalstate.OnEnter(s);
     }
 }
Ejemplo n.º 24
0
        //adds an FSM state to show that we are animating
        private void AddAnimationState()
        {
            if (States.Find(k => k.name == "KAS_Animation") == null)
            {
                KFSMState state = new KFSMState("KAS_Animation");
                state.updateMode = KFSMUpdateMode.MANUAL_TRIGGER;
                FSM.AddState(state);

                KFSMEvent enterEvent = new KFSMEvent("Enter KAS_Animation");
                enterEvent.GoToStateOnEvent = state;
                enterEvent.updateMode       = KFSMUpdateMode.MANUAL_TRIGGER;
                var idleGrounded = States.Find(k => k.name == "Idle (Grounded)");
                FSM.AddEvent(enterEvent, idleGrounded);

                KFSMEvent exitEvent = new KFSMEvent("Exit KAS_Animation");
                exitEvent.GoToStateOnEvent = idleGrounded;
                exitEvent.updateMode       = KFSMUpdateMode.MANUAL_TRIGGER;
                FSM.AddEvent(exitEvent, state);
            }
        }
Ejemplo n.º 25
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();
  }
Ejemplo n.º 26
0
        //bool initialPos = false;
        protected virtual void OnEnterToState(KFSMState kfsmState)
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return;
            }
            Log.Info("OnEnterToState: InitialState");
            if (FlightGlobals.ActiveVessel.situation != Vessel.Situations.PRELAUNCH)
            {
                Machine.RunEvent("Finish");
            }

            _obj   = new GameObject("Helper");
            _dummy = _obj.AddComponent <DummyComponent>();

            StyleFactory.Scale = ConfigInfo.Instance.Scale;

            StyleFactory.Reload();

            _windowRect = CountDownMain.instance.saveLoadWinPos.initialWindow;
        }
Ejemplo n.º 27
0
        private void InjectEvent(KFSMState state, KFSMEvent injectedEvent)
        {
            state.AddEvent(injectedEvent);
            OnCleanup += () => {
//				((List<KFSMEvent>)Refl.GetValue(state, "stateEvents")).Remove(injectedEvent);
//				List<KFSMState> kfsmstatelist = (List<KFSMState>)Refl.GetValue(state, GET_STATEEVENTS);
#if false
                foreach (var kfsmstate in kfsmstatelist)
                {
                    if (kfsmstate == state)
                    {
                        state.
                        kfsmstatelist.Remove(injectedEvent);
                        Log.Info("Removed event " + injectedEvent.name + " from state " + state.name);
                        return;
                    }
                }
#endif
            };
            Log.Info("Injected event " + injectedEvent.name + " into state " + state.name);
        }
        private void SelectRootInjectEvent(KFSMState state, KFSMEvent injectedEvent)
        {
            state.AddEvent(injectedEvent);
            OnCleanup += () => {
//				((List<KFSMEvent>)Refl.GetValue(state, "stateEvents")).Remove(injectedEvent);
//				List<KFSMState> kfsmstatelist = (List<KFSMState>)Refl.GetValue(state, EditorExtensions.c.GET_STATEEVENTS);
                state.StateEvents.Remove(injectedEvent);
                Log.dbg("Removed event {0} from state {1}", injectedEvent.name, state.name);
#if false
                foreach (var kfsmstate in kfsmstatelist)
                {
                    if (kfsmstate == state)
                    {
                        kfsmstatelist.Remove(kfsmstate);
                        Log.Info("Removed event " + injectedEvent.name + " from state " + state.name);
                        return;
                    }
                }
#endif
            };
            Log.dbg("Injected event {0} into state {1}", injectedEvent.name, state.name);
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Forcibly disables the ability to drop parts in the editor
 /// </summary>
 public void DisablePartDropping()
 {
     if (on_partDropped_Backup == null)
     {
         KFSMEvent on_partDropped = EditorLogic.fetch.GetType().GetField("on_partDropped", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy)?.GetValue(EditorLogic.fetch) as KFSMEvent;
         if (on_partDropped != null)
         {
             on_partDropped_Backup           = on_partDropped.OnCheckCondition;
             on_partDropped.OnCheckCondition = (s) => false;
             Logging.DebugLog("Disabled on_partDropped");
         }
     }
     if (st_place_Backup == null)
     {
         KFSMState st_place = EditorLogic.fetch.GetType().GetField("st_place", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy)?.GetValue(EditorLogic.fetch) as KFSMState;
         if (st_place != null)
         {
             st_place_Backup = st_place;
             EditorLogic.fetch.GetType().GetField("st_place", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy)?.SetValue(EditorLogic.fetch, null);
             Logging.DebugLog("Disabled st_place");
         }
     }
 }
		bool check_part_selected (KFSMState s)
		{
			return active_part != null;
		}
		void onleave_transferring_resources (KFSMState s)
		{
			part_resources = null;
		}
		void onenter_processing_part (KFSMState s)
		{
			part_resources = PartResources (active_part);
		}
		bool check_parts_exhausted (KFSMState s)
		{
			return active_part == null;
		}
		void onenter_off (KFSMState s)
		{
		}
		public RecyclerFSM (ExRecycler recycler)
		{
			this.recycler = recycler;

			state_off = new KFSMState ("Off");
			state_off.OnEnter = onenter_off;

			state_idle = new KFSMState ("Idle");
			state_idle.OnEnter = onenter_idle;
			state_idle.OnLeave = onleave_idle;

			state_captured_idle = new KFSMState ("Captured Idle");
			state_captured_idle.OnEnter = onenter_captured_idle;
			state_captured_idle.OnLeave = onleave_captured_idle;

			state_processing_part = new KFSMState ("Processing Part");
			state_processing_part.OnEnter = onenter_processing_part;
			state_processing_part.OnLeave = onleave_processing_part;

			state_transferring_resources = new KFSMState ("Transferring Resources");
			state_transferring_resources.OnEnter = onenter_transferring_resources;
			state_transferring_resources.OnLeave = onleave_transferring_resources;
			state_transferring_resources.OnFixedUpdate = onupdate_transferring_resources;

			event_enabled = new KFSMEvent ("Enabled");
			event_enabled.GoToStateOnEvent = state_idle;
			event_enabled.OnCheckCondition = check_enabled;
			event_enabled.updateMode = KFSMUpdateMode.FIXEDUPDATE;
			event_enabled.OnEvent = delegate { LogEvent ("Enabled"); };

			event_disabled = new KFSMEvent ("Disabled");
			event_disabled.GoToStateOnEvent = state_off;
			event_disabled.OnCheckCondition = check_disabled;
			event_disabled.updateMode = KFSMUpdateMode.FIXEDUPDATE;
			event_disabled.OnEvent = delegate { LogEvent ("Disabled"); };

			event_enter_field = new KFSMEvent ("Enter Field");
			event_enter_field.GoToStateOnEvent = state_captured_idle;
			event_enter_field.updateMode = KFSMUpdateMode.MANUAL_TRIGGER;
			event_enter_field.OnEvent = delegate { LogEvent ("Enter Field"); };

			event_part_selected = new KFSMEvent ("Part Selected");
			event_part_selected.GoToStateOnEvent = state_processing_part;
			event_part_selected.OnCheckCondition = check_part_selected;
			event_part_selected.updateMode = KFSMUpdateMode.FIXEDUPDATE;
			event_part_selected.OnEvent = delegate { LogEvent ("Part Selected"); };

			event_resources_collected = new KFSMEvent ("Resources Collected");
			event_resources_collected.GoToStateOnEvent = state_transferring_resources;
			event_resources_collected.OnCheckCondition = check_resources_collected;
			event_resources_collected.updateMode = KFSMUpdateMode.FIXEDUPDATE;
			event_resources_collected.OnEvent = delegate { LogEvent ("Resources Collected"); };

			event_resources_transferred = new KFSMEvent ("Resources Transferred");
			event_resources_transferred.GoToStateOnEvent = state_captured_idle;
			event_resources_transferred.OnCheckCondition = check_resources_transferred;
			event_resources_transferred.updateMode = KFSMUpdateMode.FIXEDUPDATE;
			event_resources_transferred.OnEvent = delegate { LogEvent ("Resources Transferred"); };

			event_parts_exhausted = new KFSMEvent ("Parts Exhausted");
			event_parts_exhausted.GoToStateOnEvent = state_idle;
			event_parts_exhausted.OnCheckCondition = check_parts_exhausted;
			event_parts_exhausted.updateMode = KFSMUpdateMode.FIXEDUPDATE;
			event_parts_exhausted.OnEvent = delegate { LogEvent ("Parts Exhausted"); };

			fsm = new RecFSM ();
			fsm.AddState (state_off);
			fsm.AddState (state_idle);
			fsm.AddState (state_captured_idle);
			fsm.AddState (state_processing_part);
			fsm.AddState (state_transferring_resources);

			fsm.AddEvent (event_enabled, new KFSMState [] {state_off});
			fsm.AddEvent (event_disabled, new KFSMState [] {state_idle});
			fsm.AddEvent (event_enter_field, new KFSMState [] {state_idle});
			fsm.AddEvent (event_part_selected, new KFSMState [] {state_captured_idle});
			fsm.AddEvent (event_resources_collected, new KFSMState [] {state_processing_part});
			fsm.AddEvent (event_resources_transferred, new KFSMState [] {state_transferring_resources});
			fsm.AddEvent (event_parts_exhausted, new KFSMState [] {state_captured_idle});

			start_state = state_off;


			recycle_parts = new HashSet<uint> ();
		}
 /// <summary>
 /// Start the state machine in a given initial state.
 /// </summary>
 /// <param name="initialState">The state to start in.</param>
 public extern void StartFSM(KFSMState initialState);
Ejemplo n.º 37
0
 private void OnLeaveFromState(KFSMState kfsmState)
 {
     Log.Info("OnLeaveFromState: LaunchedState");
     _obj.DestroyGameObjectImmediate();
     _dummy.StopAllCoroutines();
 }
		void onleave_captured_idle (KFSMState s) { }
        //adds an FSM state to show that we are animating
        private void AddAnimationState()
        {
            if (States.Find (k => k.name == "KAS_Animation") == null)
            {
                KFSMState state = new KFSMState ("KAS_Animation");
                state.updateMode = KFSMUpdateMode.MANUAL_TRIGGER;
                FSM.AddState (state);

                KFSMEvent enterEvent = new KFSMEvent ("Enter KAS_Animation");
                enterEvent.GoToStateOnEvent = state;
                enterEvent.updateMode = KFSMUpdateMode.MANUAL_TRIGGER;
                var idleGrounded = States.Find (k => k.name == "Idle (Grounded)");
                FSM.AddEvent (enterEvent, idleGrounded);

                KFSMEvent exitEvent = new KFSMEvent ("Exit KAS_Animation");
                exitEvent.GoToStateOnEvent = idleGrounded;
                exitEvent.updateMode = KFSMUpdateMode.MANUAL_TRIGGER;
                FSM.AddEvent (exitEvent, state);
            }
        }
		void onenter_captured_idle (KFSMState s)
		{
			active_part = SelectPart ();
		}
		void onleave_idle (KFSMState s)
		{
			if (RecycleField != null) {
				RecycleField.enabled = false;
			}
		}
		void onenter_idle (KFSMState s)
		{
			if (RecycleField != null) {
				RecycleField.enabled = true;
			}
		}
		bool check_disabled (KFSMState s)
		{
			return !recycler_active;
		}
		bool check_enabled (KFSMState s)
		{
			return recycler_active;
		}
Ejemplo n.º 45
0
        private void GetFSM()
        {
            var evaType = EVA.GetType();
            var fields = evaType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);

            Type kfsmEventType = typeof(KFSMEvent);
            Type kfsmStateType = typeof(KFSMState);

            string fieldNames = "Field Names for " + evaType.ToString() + ":\n";
            foreach (var field in fields)
            {
                try
                {
                    if (field.FieldType == kfsmEventType)
                    {
                        KFSMEvent ke = (KFSMEvent)field.GetValue(EVA);
                        fieldNames += "KFSMEvent: " + field.Name + " (" + ke.name + ")\n";
                        if (ke.name == "Stumble")
                        {
                            _stumble = ke;
                        }
                        else if (ke.name == "Swim Forward")
                        {
                            _swimForward = ke;
                        }
                        else if (ke.name == "Ladder Climb")
                        {
                            _ladderClimb = ke;
                        }
                        else if (ke.name == "Start Run")
                        {
                            _startRun = ke;
                        }
                    }
                    else if (field.FieldType == kfsmStateType)
                    {
                        KFSMState ks = (KFSMState)field.GetValue(EVA);
                        fieldNames += "KFSMState: " + field.Name + " (" + ks.name + ")\n";
                        if (ks.name == "Idle (Floating)")
                        {
                            _floating = ks;
                        }
                    }
                }
                catch (Exception)
                {
                    fieldNames += "???\n";
                }
            }
            //Util.Log(fieldNames);
        }
		void onenter_transferring_resources (KFSMState s) { }
 /// <summary>
 /// Add a new possible state to the machine.
 /// </summary>
 /// <param name="st">The state to add.</param>
 public extern void AddState(KFSMState st);
		bool check_resources_collected (KFSMState s)
		{
			return part_resources != null;
		}
 /// <summary>
 /// Whether this event can be triggered when the state machine is in the given state.
 /// Events must be added to states through KerbalFSM.AddEvent before they can be triggered,
 /// and they can only be triggered when the machine is in one of the states to which they
 /// have been added.
 /// </summary>
 /// <param name="state">The state to check.</param>
 /// <returns>Whether the event can be triggered from the given state.</returns>
 public extern bool IsValid(KFSMState state);
		void onleave_processing_part (KFSMState s)
		{
			Debug.Log (String.Format ("[EL RSM] onleave_processing_part"));
			recycle_parts.Remove (active_part.flightID);
			active_part.Die ();
			active_part = null;
		}
		public void Load (ConfigNode node)
		{
			recycle_parts = new HashSet<uint> ();
			if (node.HasValue ("recycle_parts")) {
				var ids = node.GetValue ("recycle_parts").Split (new char[]{' '});
				uint id;
				for (int i = 0; i < ids.Length; i++) {
					if (uint.TryParse (ids[i], out id)) {
						recycle_parts.Add (id);
					}
				}
			}
			if (node.HasNode ("part_resource")) {
				part_resources = new List<BuildResource> ();
				foreach (var pr in node.GetNodes ("part_resource")) {
					var res = new BuildResource ();
					res.Load (pr);
					part_resources.Add (res);
				}
			}
			if (node.HasValue ("state")) {
				var state = fsm.FindState (node.GetValue ("state"));
				if (state != null) {
					start_state = state;
				}
			}
		}
		bool check_resources_transferred (KFSMState s)
		{
			return part_resources.Count < 1;
		}