public void Unload(Vessel vessel, bool delete)
        {
            if (!vessel.isEVA)
            {
                EvaDebug.DebugWarning("Tried unloading a non eva.");
                return;
            }

            EvaDebug.DebugLog("Unload(" + vessel.name + ")");

            foreach (var item in collection)
            {
                if (item.flightID == vessel.id)
                {
                    if (delete)
                    {
                        item.status = Status.Removed;
                    }

                    //unload the vessel here.
                    item.Unload();
                    EvaSettings.SaveEva(item);


                    EvaDebug.DebugLog("Remove EVA: (" + vessel.name + ")");
                    collection.Remove(item);
                    break;
                }
            }
        }
        public void Awake()
        {
            EvaDebug.DebugLog("Loaded AddonAddModule.");

            var parts = new string[]
            {
                "kerbalEVA",
                "kerbalEVAVintage",
                "kerbalEVAfemale",
                "kerbalEVAfemaleVintage",
                "kerbalEVA_RD_Exp",
                "kerbalEVA_female_Exp",
                "kerbalEVA_RD_Future",
                "kerbalEVA_female_Future",
                "kerbalEVAfemaleFuture",
                "maleEVA",
                "femaleEVA",
            };

            foreach (var part in parts)
            {
                var EVA = new ConfigNode("MODULE");
                EVA.AddValue("name", "EvaModule");
                try
                {
                    PartLoader.getPartInfoByName(part).partPrefab.AddModule(EVA);
                }
                catch { }
            }
        }
        /// <summary>
        /// Runs when the EVA is killed.
        /// </summary>
        /// <param name="report"></param>

/*
 *      public void OnCrewKilled(EventReport report)
 *      {
 *          EvaDebug.DebugLog("OnCrewKilled()");
 *              KerbalRoster boboo = new KerbalRoster(Game.Modes.SANDBOX);
 *              print(boboo[report.sender].name);
 *              //MonoBehaviour.print(report.origin);
 *              //MonoBehaviour.print(report.origin.vessel);
 *          //Unload(report.origin.vessel, true);
 *      }
 */
        public void VesselDestroyed(Vessel report)
        {
            EvaDebug.DebugLog("VesselDestroyed()");
            if (report.isEVA)
            {
                Unload(report, true);
            }
        }
 public void onCommandSeatInteraction(KerbalEVA k, bool b)
 {
     EvaDebug.DebugLog("onCommandSeatInteraction()");
     if (!b)
     {
         Load(k.vessel);
     }
 }
        internal bool Contains(Guid id)
        {
            EvaDebug.DebugLog("Contains()");

            for (int i = 0; i < collection.Count; i++)
            {
                if (collection[i].flightID == id)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 6
0
        internal void FromSave(string evaSettings)
        {
            EvaTokenReader reader = new EvaTokenReader(evaSettings);

            try
            {
                string sflightID  = reader.NextTokenEnd(',');
                string sName      = reader.NextTokenEnd(',');
                string mode       = reader.NextTokenEnd(',');
                string status     = reader.NextTokenEnd(',');
                string selected   = reader.NextTokenEnd(',');
                string showHelmet = reader.NextTokenEnd(',');

                string formation = reader.NextToken('(', ')'); reader.Consume();
                string patrol    = reader.NextToken('(', ')'); reader.Consume();
                string order     = reader.NextToken('(', ')'); reader.Consume();
                string wanderer  = reader.NextToken('(', ')');

                this.Name       = sName;
                this.mode       = (Mode)Enum.Parse(typeof(Mode), mode);
                this.status     = (Status)Enum.Parse(typeof(Status), status);
                this.selected   = bool.Parse(selected);
                this.showHelmet = bool.Parse(showHelmet);


                this.formation.FromSave(formation);
                this.patrol.FromSave(patrol);
                this.order.FromSave(order);
                this.wanderer.FromSave(wanderer);

                EvaDebug.DebugLog("Loaded: " + mode);
                EvaDebug.DebugLog("name: " + sName);
                EvaDebug.DebugLog("status: " + status);
                EvaDebug.DebugLog("selected: " + selected);

                if (this.showHelmet == false)
                {
                    eva.ShowHelmet(this.showHelmet);
                }
            }
            catch
            {
                throw new Exception("[EFX] FromSave Failed.");
            }
        }
Esempio n. 7
0
        private static void LoadFile()
        {
            string fileName = String.Format("Evas-{0}.txt", HighLogic.CurrentGame.Title);

            if (FileExcist(fileName))
            {
                KSP.IO.TextReader tr = KSP.IO.TextReader.CreateForType <EvaSettings>(fileName);

                string file = tr.ReadToEnd();
                tr.Close();

                EvaTokenReader reader = new EvaTokenReader(file);

                EvaDebug.DebugLog("Size KeySize: " + collection.Count);

                //read every eva.
                while (!reader.EOF)
                {
                    //Load all the eva's in the list.
                    LoadEva(reader.NextToken('[', ']'));
                }
            }
        }
Esempio n. 8
0
        public void Awake()
        {
            EvaDebug.DebugLog("Loaded AddonAddModule.");

            ConfigNode EVA = new ConfigNode("MODULE");

            EVA.AddValue("name", "EvaModule");

            try
            {
                PartLoader.getPartInfoByName("kerbalEVA").partPrefab.AddModule(EVA);
            }
            catch {
            }

            EVA = new ConfigNode("MODULE");
            EVA.AddValue("name", "EvaModule");

            try {
                PartLoader.getPartInfoByName("kerbalEVAfemale").partPrefab.AddModule(EVA);
            } catch {
            }
        }
 /// <summary>
 /// Load the list
 /// </summary>
 private void onFlightReadyCallback()
 {
     //Load the eva list.
     EvaDebug.DebugLog("onFlightReadyCallback()");
     EvaSettings.Load();
 }
Esempio n. 10
0
 /// <summary>
 /// Runs when the EVA goes onboard a vessel.
 /// </summary>
 /// <param name="e"></param>
 public void OnCrewBoardVessel(GameEvents.FromToAction <Part, Part> e)
 {
     //remove kerbal
     EvaDebug.DebugLog("OnCrewBoardVessel()");
     Unload(e.from.vessel, true);
 }
Esempio n. 11
0
 /// <summary>
 /// Runs when the kerbal goes on EVA.
 /// </summary>
 /// <param name="e"></param>
 public void OnCrewOnEva(GameEvents.FromToAction <Part, Part> e)
 {
     //add new kerbal
     EvaDebug.DebugLog("OnCrewOnEva()");
     Load(e.to.vessel);
 }
Esempio n. 12
0
        public void Update()
        {
            if (!FlightGlobals.ready || PauseMenu.isOpen)
            {
                return;
            }

            try
            {
                angle += 0.1;

                #region Update selected kerbals
                foreach (EvaContainer eva in EvaController.instance.collection)
                {
                    if (!eva.Loaded)
                    {
                        continue;
                    }

                    if (eva.Selected)
                    {
                        UpdateSelectionLine(eva);
                    }
                }
                #endregion


                if (!FlightGlobals.ActiveVessel.Landed && FlightGlobals.ActiveVessel.GetHeightFromSurface() > 25)
                {
                    DisableCursor();
                    return;
                }

                if (HighLogic.LoadedScene != GameScenes.FLIGHT || MapView.MapIsEnabled)
                {
                    return;
                }

                //add here something to change the selection ui in space.


                #region Handle Cursor...
                if (showCursor)
                {
                    if (!_animatedCursor)
                    {
                        //ray every time ?
                        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out _cursorHit))
                        {
                            _cursorPosition = _cursorHit.point;
                            _cursorRotation = FlightGlobals.ActiveVessel.transform.rotation;
                        }
                    }

                    SetCursorProperties();
                }
                #endregion

                #region Select Multiple Kerbals

                if (Input.GetMouseButtonDown(EvaSettings.selectMouseButton) ||
                    Input.GetKeyDown(EvaSettings.selectKeyButton))
                {
                    _startClick = Input.mousePosition;
                }
                else if (Input.GetMouseButtonUp(EvaSettings.selectMouseButton) ||
                         Input.GetKeyUp(EvaSettings.selectKeyButton))
                {
                    if (_selection.width < 0)
                    {
                        _selection.x    += _selection.width;
                        _selection.width = -_selection.width;
                    }
                    if (_selection.height < 0)
                    {
                        _selection.y     += _selection.height;
                        _selection.height = -_selection.height;
                    }

                    _startClick = -Vector3.one;
                }

                if (Input.GetMouseButton(EvaSettings.selectMouseButton) ||
                    Input.GetKey(EvaSettings.selectKeyButton))
                {
                    _selection = new Rect(_startClick.x, InvertY(_startClick.y),
                                          Input.mousePosition.x - _startClick.x, InvertY(Input.mousePosition.y) - InvertY(_startClick.y));
                }

                if (Input.GetMouseButton(EvaSettings.selectMouseButton) ||
                    Input.GetKey(EvaSettings.selectKeyButton))
                {
                    if (_selection.width != 0 && _selection.height != 0)
                    {
                        Rect _temp = new Rect(_selection.x, _selection.y, _selection.width, _selection.height);
                        if (_temp.width < 0)
                        {
                            _temp.x    += _temp.width;
                            _temp.width = -_temp.width;
                        }
                        if (_selection.height < 0)
                        {
                            _temp.y     += _temp.height;
                            _temp.height = -_temp.height;
                        }

                        //get the kerbals in the selection.
                        foreach (EvaContainer container in EvaController.instance.collection)
                        {
                            if (!container.Loaded)
                            {
                                //Can't select what isn't there.
                                continue;
                            }

                            Vector3 camPos = Camera.main.WorldToScreenPoint(container.EVA.transform.position);
                            camPos.y = InvertY(camPos.y);

                            if (_temp.Contains(camPos))
                            {
                                SelectEva(container);
                            }
                            else
                            {
                                if (container.Selected)
                                {
                                    DeselectEva(container);
                                }
                            }
                        }
                    }

                    #region targetVesselBySelection
                    if (EvaSettings.targetVesselBySelection)
                    {
                        if (_selection.width != 0 && _selection.height != 0)
                        {
                            Vessel target  = null;
                            float  longest = 0;
                            //Scan a targetable vessel is avaible.
                            foreach (Vessel vessel in FlightGlobals.Vessels)
                            {
                                if (!vessel.loaded)
                                {
                                    return;
                                }

                                var camera = GetComponent <Camera>();

                                //Calculate distance.
                                var distance = Mathf.Abs(
                                    Vector3.Distance(vessel.GetWorldPos3D(), camera.transform.position));

                                if (target == null)
                                {
                                    longest = distance;
                                    target  = vessel;
                                }
                                else
                                {
                                    if (distance > longest)
                                    {
                                        longest = distance;
                                        target  = vessel;
                                    }
                                }
                            }

                            if (target != null)
                            {
                                Vector3 camPos = Camera.main.WorldToScreenPoint(target.transform.position);
                                camPos.y = InvertY(camPos.y);

                                if (_selection.Contains(camPos))
                                {
                                    //target the vessel.
                                    FlightGlobals.fetch.SetVesselTarget(target);
                                }
                            }
                        }
                    }

                    #endregion
                }
                #endregion



                #region Select Single Kerbal

                bool leftButton  = Input.GetMouseButtonDown(EvaSettings.selectMouseButton) || Input.GetKeyDown(EvaSettings.selectKeyButton);
                bool rightButton = Input.GetMouseButtonDown(EvaSettings.dispatchMouseButton) || Input.GetKeyDown(EvaSettings.dispatchKeyButton);

                if (leftButton == false && rightButton == false)
                {
                    return;
                }

                RaycastHit hitInfo = new RaycastHit();
                bool       hit     = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);

                if (!hit)
                {
                    DisableCursor();
                    return; //nothing to check.
                }

                var evaCollision = hitInfo.transform.gameObject.GetComponent <KerbalEVA>();

                if (leftButton)
                {
                    DeselectAllKerbals();

                    if (evaCollision != null)
                    {
                        EvaContainer eva = EvaController.instance.GetEva(evaCollision.vessel.id);

                        if (!eva.Loaded)
                        {
                            throw new Exception("[EFX] Impossibre!");
                        }

                        SelectEva(eva);
                    }
                    else
                    {
                        DisableCursor();
                    }
                }
                #endregion

                #region Handle Mouse Controls
                if (rightButton) //Middle button.
                {
                    var offset   = (FlightGlobals.ActiveVessel).GetWorldPos3D();
                    var position = (Vector3d)hitInfo.point;

                    foreach (var item in EvaController.instance.collection.ToArray())
                    {
                        if (!item.Loaded)
                        {
                            return;
                        }

                        if (item.Selected)
                        {
                            //Remove current mode.
                            if (item.mode == Mode.Patrol)
                            {
                                item.EndPatrol();
                            }

                            if (EvaSettings.displayDebugLines)
                            {
                                setLine(position, offset);
                            }

                            EvaDebug.DebugLog(string.Format("Target: {0}", position));

                            item.Order(position, offset);
                            item.Selected = false;
                            item.mode     = Mode.Order;

                            _animatedCursor = true;

                            //destroy circle line
                            DestroyLine(item.flightID);
                        }
                    }
                }
                #endregion

                #region Cursor Visible...
                //Show the cursor if more than one kerbal is selected.
                if (selectedKerbals > 0)
                {
                    ShowCursor();
                }
                else
                {
                    DisableCursor();
                }
                #endregion
            }
            catch (Exception exp)
            {
                EvaDebug.DebugWarning("[EFX] EvaOrderController: " + exp.Message);
            }
        }