Esempio n. 1
0
 public override void OnStart(StartState startState)
 {
     base.OnStart(startState);
     SpawnManager.Init(part);
     if (!string.IsNullOrEmpty(ConstructionNode))
     {
         construction_node = part.FindAttachNode(ConstructionNode);
         foreach (var port in part.FindModulesImplementing <ModuleDockingNode>())
         {
             if (port.nodeTransformName == ConstructionNode ||
                 port.referenceAttachNode == ConstructionNode)
             {
                 construction_port = port;
                 break;
             }
         }
     }
     if (construction_node == null)
     {
         this.Log("ERROR: unable to find construction AttachNode with id: {}",
                  ConstructionNode);
         this.EnableModule(false);
         return;
     }
     if (kit && ConstructDockingNode >= 0)
     {
         construct_docking_node = kit.DockingNodes[ConstructDockingNode];
     }
     if (vessel != null)
     {
         StartCoroutine(CallbackUtil.DelayedCallback(1, find_connected_workshops));
     }
 }
Esempio n. 2
0
 public void UpdateGUI(ShipConstruct ship)
 {
     if (isActiveAndEnabled)
     {
         StartCoroutine(CallbackUtil.DelayedCallback(1, () => MassDisplay = Utils.formatMass(part.TotalMass())));
     }
 }
Esempio n. 3
0
 public void OnEditorScreenChange(EditorScreen e)
 {
     if (e == EditorScreen.Crew)
     {
         StartCoroutine(CallbackUtil.DelayedCallback(1, BuildCrewAssignmentDialogue));
     }
 }
Esempio n. 4
0
 void OnLevelWasLoaded(GameScenes scene)
 {
     if (scene == GameScenes.MAINMENU)
     {
         StartCoroutine(CallbackUtil.DelayedCallback(15, LoadGame));
     }
 }
        void Rescale()
        {
            if (model == null)
            {
                return;
            }
            Scale _scale = scale;

            //change model scale
            model.localScale = _scale.ScaleVector(orig_local_scale);
//            this.Log("size {}/{}, orig scale: {}, local scale: {}", size, orig_size, orig_local_scale, model.localScale);//debug
            model.hasChanged          = true;
            part.transform.hasChanged = true;
            //recalculate mass and cost
            mass = ((specificMass.x * _scale + specificMass.y) * _scale + specificMass.z) * _scale * _scale.aspect + specificMass.w;
            cost = ((specificCost.x * _scale + specificCost.y) * _scale + specificCost.z) * _scale * _scale.aspect + specificCost.w;
            //update nodes and modules
            updaters.ForEach(u => u.OnRescale(_scale));
            //save size and aspect
            old_size        = size;
            old_aspect      = aspect;
            old_local_scale = model.localScale;
            Utils.UpdateEditorGUI();
            if (HighLogic.LoadedSceneIsFlight)
            {
                StartCoroutine(CallbackUtil.DelayedCallback(1, UpdateDragCube));
            }
            just_loaded = false;
        }
Esempio n. 6
0
 public void onMapEntered()
 {
     if (MapNode.AllMapNodes.Count == 0)
     {
         base.StartCoroutine(CallbackUtil.DelayedCallback(10, new Callback(this.processMapNodes)));
     }
     else
     {
         bool containsCBs = false;
         for (int mnI = 0; mnI < MapNode.AllMapNodes.Count; mnI++)
         {
             if (MapNode.AllMapNodes[mnI].mapObject != null)
             {
                 if (MapNode.AllMapNodes[mnI].mapObject.celestialBody != null)
                 {
                     containsCBs = true;
                     break;
                 }
             }
         }
         if (containsCBs)
         {
             processMapNodes();
         }
         else
         {
             base.StartCoroutine(CallbackUtil.DelayedCallback(10, new Callback(this.processMapNodes)));
         }
     }
 }
Esempio n. 7
0
 void OnLevelWasLoaded(GameScenes scene)
 {
     if (scene == GameScenes.SPACECENTER && Vessel >= 0)
     {
         StartCoroutine(CallbackUtil.DelayedCallback(15, SwitchVessel));
     }
 }
Esempio n. 8
0
        private void OnDestroy()
        {
            if (vessel != null &&
                vessel.gameObject.activeInHierarchy &&
                FlightGlobals.fetch != null &&
                ReferenceEquals(FlightGlobals.fetch.VesselTarget, this))
            {
                vessel.StartCoroutine(CallbackUtil.DelayedCallback(1,
                                                                   FlightGlobals.fetch.SetVesselTarget,
                                                                   vessel,
                                                                   false));
            }
            Fields[nameof(numSegments)].OnValueModified        -= onNumSegmentsChange;
            Fields[nameof(ShowUI)].OnValueModified             -= showUI;
            Fields[nameof(ShowConstructionUI)].OnValueModified -= showConstructionUI;
            GameEvents.onVesselWasModified.Remove(onVesselWasModified);
            GameEvents.onVesselCrewWasModified.Remove(onVesselCrewWasModified);
            axisController?.Disconnect();
            axisController = null;
            UI?.Close();
            cUI?.Close();
#if NIGHTBUILD
            GlobalsReloader.RemoveListener(onGlobalsLoaded);
#endif
        }
Esempio n. 9
0
        bool same_vessel_collision_if_deployed()
        {
            var B = get_deployed_part_bounds(true);

            for (int i = 0, vesselPartsCount = vessel.Parts.Count; i < vesselPartsCount; i++)
            {
                var p = vessel.Parts[i];
                if (p == part)
                {
                    continue;
                }
                if (p.parent == part || part.parent == p)
                {
                    continue;
                }
                var pM = new Metric(p, true, true);
                for (int j = 0, pMhullPointsCount = pM.hull.Points.Count; j < pMhullPointsCount; j++)
                {
                    var c  = pM.hull.Points[j];
                    var lc = model.InverseTransformDirection(c - model.position);
                    if (B.Contains(lc))
                    {
                        p.HighlightAlways(Colors.Danger.color);
                        StartCoroutine(CallbackUtil.DelayedCallback(3f, () => p?.SetHighlightDefault()));
                        ShowDeployHint = true;
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 10
0
 public void CrewTransfer_MoveCrewTo()
 {
     _initialEyePosition = ActiveKerbal.KerbalRef.eyeInitialPos;
     FreeIva.InitialPart.RemoveCrewmember(ActiveKerbal);
     FreeIva.CurrentPart.AddCrewmemberAt(ActiveKerbal, TargetedSeatIndex);
     GameEvents.onCrewTransferred.Fire(new GameEvents.HostedFromToAction <ProtoCrewMember, Part>(ActiveKerbal, FreeIva.InitialPart, FreeIva.CurrentPart));
     FlightGlobals.ActiveVessel.DespawnCrew();
     base.StartCoroutine(CallbackUtil.DelayedCallback(1, new Callback(CrewTransfer_waitAndCompleteTransfer)));
 }
Esempio n. 11
0
        internal Part LoadPart(ProtoPartSnapshot protoPart)
        {
            Part newPart = (Part)GameObject.Instantiate(protoPart.partPrefab, vessel.transform.position, vessel.transform.rotation);

            if (rootPart != null)
            {
                newPart.transform.parent = rootPart.transform;
                newPart.setParent(rootPart);
            }
            else
            {
                newPart.transform.parent = vessel.transform;
            }

            newPart.transform.localPosition = protoPart.position;
            newPart.transform.localRotation = protoPart.rotation;
            newPart.gameObject.SetActive(true);

            newPart.vessel = vessel;

            int index = 0;

            foreach (var module in protoPart.modules)
            {
                //if (!blacklist.Contains(module.moduleName))
                //{
                //Log.Normal("Loaded Module: " + (module.moduleName));
                module.Load(newPart, ref index);
                //}
            }

            PartModule[] partModules = newPart.Modules.Cast <PartModule>().ToArray();

            foreach (var module in partModules)
            {
                if (delayList.Contains(module.moduleName))
                {
                    StartCoroutine(CallbackUtil.DelayedCallback(10, DestroyDelayed, module));
                }
                else
                {
                    if (!blackList.Contains(module.moduleName))
                    {
                        Log.Normal("Loaded Module: " + (module.moduleName));
                        module.OnAwake();
                        module.OnStart(PartModule.StartState.PreLaunch);
                    }
                    newPart.Modules.Remove(module);
                    GameObject.DestroyImmediate(module);
                }
            }

            vessel.parts.Add(newPart);

            allObjects.Add(newPart);
            return(newPart);
        }
Esempio n. 12
0
 private void onLevelWasLoaded(GameScenes scene)
 {
     if (scene != GameScenes.SPACECENTER || activeVessel < 0)
     {
         return;
     }
     AutoLoadGame.Log("SPACECENTER is loaded. Waiting 60 frames and switching to the active vessel.");
     StartCoroutine(CallbackUtil.DelayedCallback(60, switch_to_active_vessel));
 }
Esempio n. 13
0
 private void onLevelWasLoaded(GameScenes scene)
 {
     if (scene != GameScenes.MAINMENU)
     {
         return;
     }
     Log("MAINMENU is loaded. Waiting 60 frames and loading the save.");
     StartCoroutine(CallbackUtil.DelayedCallback(60, LoadGame));
 }
Esempio n. 14
0
 private void OnLevelWasLoaded(GameScenes scene)
 {
     PatchColliders();
     PatchFlightIntegrator();
     FixCameras();
     PatchTimeOfDayAnimation();
     StartCoroutine(CallbackUtil.DelayedCallback(3, FixFlags));
     PatchContracts();
     previousScene = HighLogic.LoadedScene;
 }
Esempio n. 15
0
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     just_started = true;
     StartCoroutine(CallbackUtil.DelayedCallback(1, create_deploy_hint_mesh));
     if (State == DeplyomentState.DEPLOYING)
     {
         StartCoroutine(deploy());
     }
 }
Esempio n. 16
0
 void Start()
 {
     this.Log("Starting WorldSpaceTrace for {}s at {}", Delay, transform.position);
     StartCoroutine(CallbackUtil.DelayedCallback
                        (Delay, () =>
     {
         if (gameObject != null)
         {
             Destroy(gameObject);
         }
     }));
 }
Esempio n. 17
0
        private void OnLevelWasLoaded(GameScenes scene)
        {
            PatchFlightIntegrator();
            FixCameras();
            PatchTimeOfDayAnimation();
            StartCoroutine(CallbackUtil.DelayedCallback(3, FixFlags));

            for (Int32 i = 0; i < PSystemManager.Instance.localBodies.Count; i++)
            {
                PatchStarReferences(PSystemManager.Instance.localBodies[i]);
                PatchContractWeight(PSystemManager.Instance.localBodies[i]);
            }
        }
Esempio n. 18
0
        void fromEVA(GameEvents.FromToAction <Part, Part> data)
        {
            // use Hydrazine instead of MonoPropellant if RealFuel is installed
            string monoprop_name = detected_mods.RealFuels ? "Hydrazine" : "MonoPropellant";

            // get any leftover EVA Fuel from EVA vessel
            double monoprop = data.from.Resources.list[0].amount;

            // add the leftover monoprop back to the pod
            data.to.RequestResource(monoprop_name, -monoprop);

            // manage resources in rules
            foreach (Rule r in rules)
            {
                if (r.resource_name.Length == 0 || r.on_eva <= double.Epsilon)
                {
                    continue;
                }
                double leftover = ResourceCache.Info(data.from.vessel, r.resource_name).amount;
                data.to.RequestResource(r.resource_name, -leftover);
            }

            // merge EVA computer files into vessel
            Computer a = DB.VesselData(data.from.vessel.id).computer;
            Computer b = DB.VesselData(data.to.vessel.id).computer;

            b.merge(a);

            // forget vessel data
            DB.ForgetVessel(data.from.vessel.id);

            // purge vessel from resource cache
            ResourceCache.Purge(data.from.vessel.id);

            // execute script on vessel computer
            if (DB.Ready())
            {
                DB.VesselData(data.to.vessel.id).computer.execute("run", "auto/eva_in", string.Empty, data.to.vessel);
            }

            // mute messages for a couple seconds to avoid warning messages from the vessel resource amounts
            Message.MuteInternal();
            base.StartCoroutine(CallbackUtil.DelayedCallback(2.0f, Message.UnmuteInternal));

            // if vessel info is open, switch to the vessel
            if (Info.IsOpen())
            {
                Info.Open(data.to.vessel);
            }
        }
Esempio n. 19
0
        void onPartJointBreak(PartJoint joint, float force)
        {
            if (state != State.Fixed || !IsDocked)
            {
                return;
            }
            var dockedPart = vessel[dockedPartUId];

            if (joint.Parent == part && joint.Child == dockedPart ||
                joint.Parent == dockedPart && joint.Child == part)
            {
                state = State.Broken;
                StartCoroutine(CallbackUtil.DelayedCallback(3, part.explode));
            }
        }
Esempio n. 20
0
        public static void CreateMissingPartsInCurrentProtoVessel(Vessel vessel, ProtoVessel protoVessel)
        {
            //TODO: This is old code where we created parts dinamically but it's quite buggy. It create parts in the CURRENT vessel so it wont work for other vessels

            //We've run trough all the vessel parts and removed the ones that don't exist in the definition.
            //Now run trough the parts in the definition and add the parts that don't exist in the vessel.
            var partsToInit = new List <ProtoPartSnapshot>();

            foreach (var partSnapshot in protoVessel.protoPartSnapshots)
            {
                if (partSnapshot.FindModule("ModuleDockingNode") != null)
                {
                    //We are in a docking port part so remove it from our own vessel if we have it
                    if (FlightGlobals.FindLoadedPart(partSnapshot.persistentId, out var vesselPart))
                    {
                        vesselPart.Die();
                    }
                }

                //Skip parts that already exists
                if (FlightGlobals.FindLoadedPart(partSnapshot.persistentId, out _))
                {
                    continue;
                }

                var newPart = partSnapshot.Load(vessel, false);
                vessel.parts.Add(newPart);
                partsToInit.Add(partSnapshot);
            }

            //Init new parts. This must be done in another loop as otherwise new parts won't have their correct attachment parts.
            foreach (var partSnapshot in partsToInit)
            {
                partSnapshot.Init(vessel);
            }

            vessel.RebuildCrewList();
            MainSystem.Singleton.StartCoroutine(CallbackUtil.DelayedCallback(0.25f, () => { if (FlightGlobals.ActiveVessel)
                                                                                            {
                                                                                                FlightGlobals.ActiveVessel.SpawnCrew();
                                                                                            }
                                                                             }));
            MainSystem.Singleton.StartCoroutine(CallbackUtil.DelayedCallback(0.5f, () => { if (KerbalPortraitGallery.Instance)
                                                                                           {
                                                                                               KerbalPortraitGallery.Instance.SetActivePortraitsForVessel(FlightGlobals.ActiveVessel);
                                                                                           }
                                                                             }));
        }
        public void ShowGroup()
        {
            var group = GetGroup();

            group.ForEach(m => m.part.HighlightAlways(m.TCA_Active?
                                                      Color.green :
                                                      (m.GroupMaster?
                                                       Color.magenta :
                                                       Color.cyan)));
            StartCoroutine(CallbackUtil.DelayedCallback(3.0f, () => group.ForEach(m =>
            {
                if (m != null && m.part != null)
                {
                    m.part.SetHighlightDefault();
                }
            })));
        }
Esempio n. 22
0
        public void ShowGroup()
        {
            var group = GetGroup();

            group.ForEach(m => m.part.HighlightAlways(m.TCA_Active ?
                                                      Colors.Enabled :
                                                      (m.GroupMaster ?
                                                       Colors.Selected2 :
                                                       Colors.Selected1)));
            StartCoroutine(CallbackUtil.DelayedCallback(3.0f, () => group.ForEach(m =>
            {
                if (m != null && m.part != null)
                {
                    m.part.SetHighlightDefault();
                }
            })));
        }
Esempio n. 23
0
        private void OnLevelWasLoaded(GameScenes scene)
        {
            PatchColliders();
            PatchFlightIntegrator();
            FixCameras();
            PatchTimeOfDayAnimation();
            StartCoroutine(CallbackUtil.DelayedCallback(3, FixFlags));
            //Small Contract fixer to remove Sentinel Contracts
            Type contractTypeToRemove = null;

            try
            {
                foreach (Type contract in Contracts.ContractSystem.ContractTypes)
                {
                    try
                    {
                        if (contract.FullName.Contains("SentinelContract"))
                        {
                            contractTypeToRemove = contract;
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
                if (!(contractTypeToRemove == null))
                {
                    ContractSystem.ContractTypes.Remove(contractTypeToRemove);
                    contractTypeToRemove = null;
                    Debug.Log("[Kopernicus] ScenarioDiscoverableObjects is removed, scrubbing SENTINEL contracts.");
                }
            }
            catch
            {
                contractTypeToRemove = null;
            }
            //Patch weights of contracts
            for (Int32 i = 0; i < PSystemManager.Instance.localBodies.Count; i++)
            {
                PatchStarReferences(PSystemManager.Instance.localBodies[i]);
                PatchContractWeight(PSystemManager.Instance.localBodies[i]);
            }
        }
Esempio n. 24
0
        private void updatePhysicsParams()
        {
            updateCoMOffset();
            delayedUpdateInertiaTensor();
#if DEBUG
            StartCoroutine(CallbackUtil.DelayedCallback(3,
                                                        () =>
            {
                if (vessel != null)
                {
                    VesselMass = vessel.GetTotalMass();
                }
                else if (HighLogic.LoadedSceneIsEditor)
                {
                    VesselMass = EditorLogic.fetch.ship.GetTotalMass();
                }
            }));
#endif
        }
Esempio n. 25
0
        public void UpdateMesh()
        {
            if (body_mesh == null || body_collider == null)
            {
                return;
            }
            update_body();
            update_attach_nodes();
            update_passage();
            var data = new BaseEventDetails(BaseEventDetails.Sender.AUTO);

            data.Set <string>("volName", "Tankage");
            data.Set <double>("newTotalVolume", body.current.V * UsableVolumeRatio);
            part.SendEvent("OnPartVolumeChanged", data);
            old_size   = size;
            old_aspect = aspect;
            Utils.UpdateEditorGUI();
            StartCoroutine(CallbackUtil.DelayedCallback(1, UpdateDragCube));
            just_loaded = false;
        }
Esempio n. 26
0
        public void Decouple()
        {
            var dockedPart = vessel[dockedPartUId];

            if (dockedPart != null)
            {
                restore_docking_info(dockedPart);
                var parent               = part.parent;
                var old_vessel           = vessel;
                var referenceTransformId = vessel.referenceTransformId;
                if (parent != dockedPart)
                {
                    dockedPart.Undock(docked_vessel);
                    dockedPart.attachNodes.Remove(grappleNode);
                }
                else
                {
                    part.Undock(this_vessel);
                    part.attachNodes.Remove(grappleNode);
                }
                grappleNode.attachedPart = null;
                grappleNode.owner        = null;
                part.fuelLookupTargets.Remove(dockedPart);
                dockedPart.fuelLookupTargets.Remove(part);
                GameEvents.onPartFuelLookupStateChange.Fire(new GameEvents.HostedFromToAction <bool, Part>(true, part, dockedPart));
                AddForceAlongGrapples(dockedPart, -GrappleForce);
                if (old_vessel == FlightGlobals.ActiveVessel)
                {
                    if (old_vessel[referenceTransformId] == null)
                    {
                        StartCoroutine(CallbackUtil.DelayedCallback(1, () => FlightGlobals.ForceSetActiveVessel(vessel)));
                    }
                }
            }
            if (armAnimator != null)
            {
                armAnimator.Close();
            }
            state = State.Idle;
            update_part_menu();
        }
        void Rescale()
        {
            if (model == null)
            {
                return;
            }
            var scale = GetScale();

            update_model(scale);
            //update modules
            updaters.ForEach(u => u.OnRescale(scale));
            //save size and aspect
            old_size        = size;
            old_aspect      = aspect;
            old_local_scale = model.localScale;
            Utils.UpdateEditorGUI();
            if (HighLogic.LoadedSceneIsFlight)
            {
                StartCoroutine(CallbackUtil.DelayedCallback(1, UpdateDragCube));
            }
            just_loaded = false;
        }
Esempio n. 28
0
        void toEVA(GameEvents.FromToAction <Part, Part> data)
        {
            // use Hydrazine instead of MonoPropellant if RealFuel is installed
            string monoprop_name = detected_mods.RealFuels ? "Hydrazine" : "MonoPropellant";

            // determine if inside breathable atmosphere
            // note: the user can force the helmet + oxygen by pressing shift when going on eva
            bool breathable = Sim.Breathable(data.from.vessel) && !(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));

            // get total crew in the origin vessel
            double tot_crew = (double)data.from.vessel.GetVesselCrew().Count + 1.0;

            // EVA vessels start with 5 units of eva fuel, remove them
            data.to.RequestResource("EVA Propellant", 5.0);

            // determine how much MonoPropellant to get
            // note: never more that the 'share' of this kerbal
            double monoprop = Math.Min(ResourceCache.Info(data.from.vessel, monoprop_name).amount / tot_crew, Settings.MonoPropellantOnEVA);

            // get monoprop from the vessel
            monoprop = data.from.RequestResource(monoprop_name, monoprop);

            // transfer monoprop to the EVA kerbal
            data.to.RequestResource("EVA Propellant", -monoprop);

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

            // manage resources from rules
            foreach (Rule r in rules)
            {
                if (r.resource_name.Length == 0 || r.on_eva <= double.Epsilon)
                {
                    continue;
                }

                // determine amount to take, never more that his own share
                double amount = Math.Min(ResourceCache.Info(data.from.vessel, r.resource_name).amount / tot_crew, r.on_eva);

                // deal with breathable modifier
                if (breathable && r.modifier.Contains("breathable"))
                {
                    continue;
                }

                // remove resource from the vessel
                amount = data.from.RequestResource(r.resource_name, amount);

                // create new resource in the eva kerbal
                Lib.SetupResource(data.to, r.resource_name, amount, r.on_eva);
            }

            // get KerbalEVA
            KerbalEVA kerbal = data.to.FindModuleImplementing <KerbalEVA>();

            // turn off headlamp light, to avoid stock bug that show the light for a split second when going on eva
            EVA.SetHeadlamp(kerbal, false);
            EVA.SetFlares(kerbal, false);

            // remove the helmet if inside breathable atmosphere
            // note: done in EVA::FixedUpdate(), but also done here avoid 'popping' of the helmet when going on eva
            EVA.SetHelmet(kerbal, !breathable);

            // remember if the kerbal has an helmet
            EVA.KerbalData(data.to.vessel).has_helmet = !breathable;

            // execute script on vessel computer
            if (DB.Ready())
            {
                DB.VesselData(data.from.vessel.id).computer.execute("run", "auto/eva_out", string.Empty, data.from.vessel);
            }

            // mute messages for a couple seconds to avoid warning messages from the vessel resource amounts
            Message.MuteInternal();
            base.StartCoroutine(CallbackUtil.DelayedCallback(2.0f, Message.UnmuteInternal));

            // if vessel info is open, switch to the eva kerbal
            // note: for a single tick, the EVA vessel is not valid (sun_dist is zero)
            // this make IsVessel() return false, that in turn close the vessel info instantly
            // for this reason, we wait a small amount of time before switching the info window
            if (Info.IsOpen())
            {
                Info.Open(data.to.vessel);
            }
        }
Esempio n. 29
0
 public void RebuildCrewAssignmentDialogue(KSP.UI.CrewListItem.ButtonTypes type, KSP.UI.CrewListItem cic)
 {
     StartCoroutine(CallbackUtil.DelayedCallback(1, BuildCrewAssignmentDialogue));
 }
Esempio n. 30
0
 public void RebuildAstronautComplex(KSP.UI.CrewListItem.ButtonTypes type, KSP.UI.CrewListItem cic)
 {
     StartCoroutine(CallbackUtil.DelayedCallback(1, BuildAstronautComplex));
 }