Exemplo n.º 1
0
        /// <summary>
        /// Addon work logic.
        /// </summary>
        public void Update()
        {
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                string message = string.Empty;

                if (Input.GetKeyDown(BoardKey))
                {
                    // Prevent addon on map view, or when kerbal is busy,
                    // or when player is typing text in some text field.
                    if (MapView.MapIsEnabled || !this.CrewCanBoard(FlightGlobals.ActiveVessel.evaController))
                    {
                        return;
                    }

                    this.AllowMessages = true;
                    this.WantsBoard    = !this.WantsBoard;

                    if (this.WantsBoard)
                    {
                        this.KerbalName = FlightGlobals.ActiveVessel.vesselName;
                    }

                    message = this.GetStatusMessage();
                }

                KerbalEVA kerbal = FlightGlobals.ActiveVessel.evaController;

                if (this.WantsBoard && kerbal != null)
                {
                    Part airlockPart = this.GetKerbalAirlock(kerbal);

                    if (this.AirlockPart != airlockPart)
                    {
                        // Keep previous airlock to avoid multiple attemts to board it.
                        this.AirlockPart = airlockPart;

                        if (airlockPart != null && kerbal.vessel.state == Vessel.State.ACTIVE && !kerbal.vessel.packed)
                        {
                            if (airlockPart.protoModuleCrew.Count < airlockPart.CrewCapacity)
                            {
                                // There is enough place for the kerbal,
                                // boarding should be successful. We can reset addon fields.
                                this.AllowMessages = false;
                                this.AddonReset();
                            }

                            // Try board.
                            kerbal.BoardPart(airlockPart);
                            return;
                        }
                    }

                    // Try board nearest seat when no airlock.
                    if (airlockPart == null)
                    {
                        KerbalSeat seat = this.GetNearestSeat(kerbal,
                                                              Input.GetKeyDown(BoardKey) ? OriginalSeatDistance : SeatDistance);

                        if (seat != null)
                        {
                            this.AllowMessages = false;
                            seat.BoardSeat();

                            // Check whether boarding seat was successful.
                            if (((PartModule)seat).Events["BoardSeat"].active)
                            {
                                // Fail case.
                                this.AllowMessages = true;
                            }
                            else
                            {
                                // Success case.
                                this.AddonReset();
                            }
                        }
                    }
                }

                this.DisplayMessage(message);
            }
        }
Exemplo n.º 2
0
 public void BoardWing()
 {
     seat.BoardSeat();
     wingCommander.MakeReference();
     evaKerbal = seat.Occupant.FindModuleImplementing <KerbalEVA>();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        public void Update()
        {
            this.CheckVesselControl();

            if (FlightGlobals.ActiveVessel.isEVA)
            {
                string message = string.Empty;

                KerbalEVA kerbal = FlightGlobals.ActiveVessel.evaController;

                if (kerbal == null)
                {
                    return;
                }

                if (Input.GetKeyUp(this.BoardKey))
                {
                    // Prevent addon on map view, or when kerbal is busy,
                    // or when player is typing text in some text field.
                    if (!this.CanKerbalStartToWant(kerbal))
                    {
                        return;
                    }

                    this.AllowMessages = true;
                    this.WantsToBoard  = !this.WantsToBoard;

                    if (this.WantsToBoard)
                    {
                        this.KerbalName = FlightGlobals.ActiveVessel.vesselName;
                    }

                    message = this.GetStatusMessage(this.WantsToBoard ? WantsToBoardMessage : HesitatingMessage);
                }

                if (Input.GetKeyUp(this.GrabKey) && !kerbal.OnALadder)
                {
                    string pattern    = "[" + this.GrabKey.ToString() + "]:";
                    bool   canGrabNow = false;

                    ScreenMessages screenMessages = GameObject.FindObjectOfType <ScreenMessages>();
                    foreach (var activeMessage in screenMessages.ActiveMessages)
                    {
                        if (activeMessage.message.StartsWith(pattern, StringComparison.InvariantCultureIgnoreCase))
                        {
                            canGrabNow = true;
                            break;
                        }
                    }

                    if (!canGrabNow)
                    {
                        // Prevent addon on map view, or when kerbal is busy,
                        // or when player is typing text in some text field.
                        if (!this.CanKerbalStartToWant(kerbal))
                        {
                            return;
                        }

                        this.AllowMessages = true;
                        this.WantsToGrab   = !this.WantsToGrab;

                        if (this.WantsToGrab)
                        {
                            this.KerbalName = FlightGlobals.ActiveVessel.vesselName;
                        }

                        message = this.GetStatusMessage(this.WantsToGrab ? WantsToGrabMessage : HesitatingMessage);
                    }
                }

                if (this.WantsToBoard)
                {
                    Part airlockPart = this.GetKerbalAirlock(kerbal);

                    if (this.AirlockPart != airlockPart)
                    {
                        // Keep previous airlock to avoid multiple attemts to board it.
                        this.AirlockPart = airlockPart;

                        if (airlockPart != null && kerbal.vessel.state == Vessel.State.ACTIVE && !kerbal.vessel.packed)
                        {
                            if (airlockPart.protoModuleCrew.Count < airlockPart.CrewCapacity)
                            {
                                // There is enough place for the kerbal,
                                // boarding should be successful. We can reset addon fields.
                                this.AllowMessages = false;
                                this.AddonReset();
                            }

                            // Try board.
                            this.LockVesselControl();
                            kerbal.BoardPart(airlockPart);
                            return;
                        }
                    }

                    // Try board nearest seat when no airlock.
                    if (airlockPart == null)
                    {
                        KerbalSeat seat = this.GetNearestSeat(kerbal,
                                                              Input.GetKeyUp(this.BoardKey) ? OriginalSeatDistance : SeatDistance);

                        if (seat != null)
                        {
                            this.AllowMessages = false;
                            this.LockVesselControl();
                            seat.BoardSeat();

                            // Check whether boarding seat was successful.
                            if (((PartModule)seat).Events["BoardSeat"].active)
                            {
                                // Fail case.
                                this.AllowMessages = true;
                            }
                            else
                            {
                                // Success case.
                                this.AddonReset();
                                return;
                            }
                        }
                    }
                }

                if (this.WantsToGrab && !kerbal.OnALadder)
                {
                    ScreenMessages screenMessages = GameObject.FindObjectOfType <ScreenMessages>();
                    foreach (var activeMessage in screenMessages.ActiveMessages)
                    {
                        if (activeMessage.message.EndsWith("]: Grab", StringComparison.InvariantCultureIgnoreCase))
                        {
                            foreach (var stateEvent in kerbal.fsm.CurrentState.StateEvents)
                            {
                                if (stateEvent.name == "Ladder Grab Start")
                                {
                                    this.AllowMessages = false;
                                    this.WantsToGrab   = false;
                                    this.LockVesselControl();
                                    kerbal.fsm.RunEvent(stateEvent);
                                    break;
                                }
                            }

                            break;
                        }
                    }
                }

                this.DisplayMessage(message);
            }
        }