DebugError() публичный статический Метод

public static DebugError ( string format ) : void
format string
Результат void
Пример #1
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            // Do not load ScienceData nodes for this module's host part (a KAS container) as they were only stored in case the vessel was
            // recovered. The original parts still contain the science data. (See OnSave.)

            if (node.HasNode("CONTENT") || node.HasNode("CONTENT_PART"))
            {
                contents.Clear();
            }

            foreach (ConfigNode cn in node.nodes)
            {
                if (cn.name != "CONTENT" && cn.name != "CONTENT_PART")
                {
                    continue;
                }

                string      AvPartName = cn.GetValue("name") ?? "null";
                PartContent item       = PartContent.Get(contents, AvPartName);

                if (item != null)
                {
                    item.Load(cn);
                }
                else
                {
                    KAS_Shared.DebugError("Load(Container) - Cannot retrieve " + AvPartName + " from PartLoader !");
                }
            }
        }
Пример #2
0
        public static Part GetPartByID(string vesselID, string partID)
        {
            Vessel searchVessel = FlightGlobals.Vessels.Find(ves => ves.id.ToString() == vesselID);

            if (searchVessel)
            {
                if (!searchVessel.loaded)
                {
                    KAS_Shared.DebugWarning("GetPartByID - Searched vessel are not loaded, loading it...");
                    searchVessel.Load();
                }
                Part searchedPart = searchVessel.Parts.Find(p => p.flightID.ToString() == partID);
                if (searchedPart)
                {
                    return(searchedPart);
                }
                else
                {
                    KAS_Shared.DebugError("GetPartByID - Searched part not found !");
                }
            }
            else
            {
                KAS_Shared.DebugError("GetPartByID - Searched vessel not found !");
            }
            return(null);
        }
Пример #3
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            if (node.HasNode("CONTENT"))
            {
                contents.Clear();
            }

            foreach (ConfigNode cn in node.GetNodes("CONTENT"))
            {
                if (cn.HasValue("name") && cn.HasValue("qty"))
                {
                    string        AvPartName = cn.GetValue("name").ToString();
                    AvailablePart avPart     = null;
                    avPart = PartLoader.getPartInfoByName(AvPartName);
                    int qty = int.Parse(cn.GetValue("qty"));
                    if (avPart != null)
                    {
                        contents.Add(avPart, qty);
                    }
                    else
                    {
                        KAS_Shared.DebugError("Load(Container) - Cannot retrieve " + AvPartName + " from PartLoader !");
                    }
                }
            }
        }
Пример #4
0
 public static bool createFXSound(Part part, FXGroup group, string sndPath, bool loop,
                                  float maxDistance = 30f)
 {
     group.audio              = part.gameObject.AddComponent <AudioSource>();
     group.audio.volume       = GameSettings.SHIP_VOLUME;
     group.audio.rolloffMode  = AudioRolloffMode.Linear;
     group.audio.dopplerLevel = 0f;
     group.audio.spatialBlend = 1f;
     group.audio.maxDistance  = maxDistance;
     group.audio.loop         = loop;
     group.audio.playOnAwake  = false;
     if (GameDatabase.Instance.ExistsAudioClip(sndPath))
     {
         group.audio.clip = GameDatabase.Instance.GetAudioClip(sndPath);
         return(true);
     }
     else
     {
         KAS_Shared.DebugError("Sound not found in the game database !");
         ScreenMessages.PostScreenMessage(
             string.Format("Sound file : {0} as not been found, please check your KAS installation !",
                           sndPath),
             10, ScreenMessageStyle.UPPER_CENTER);
         return(false);
     }
 }
Пример #5
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            if (node.HasNode("CONTENT") || node.HasNode("CONTENT_PART"))
            {
                contents.Clear();
            }

            foreach (ConfigNode cn in node.nodes)
            {
                if (cn.name != "CONTENT" && cn.name != "CONTENT_PART")
                {
                    continue;
                }

                string      AvPartName = cn.GetValue("name") ?? "null";
                PartContent item       = PartContent.Get(contents, AvPartName);

                if (item != null)
                {
                    item.Load(cn);
                }
                else
                {
                    KAS_Shared.DebugError("Load(Container) - Cannot retrieve " + AvPartName + " from PartLoader !");
                }
            }
        }
Пример #6
0
 public static Vessel GetVesselByName(string name) {
   Vessel searchVessel = FlightGlobals.Vessels.Find(ves => ves.vesselName == name);
   if (searchVessel) {
     return searchVessel;
   }
   KAS_Shared.DebugError("GetVesselByName - Searched vessel not found !");
   return null;
 }
Пример #7
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (state == StartState.Editor || state == StartState.None)
            {
                return;
            }

            if (attachMode.Docked)
            {
                Part dockedPart = KAS_Shared.GetPartByID(this.vessel.id.ToString(), dockedPartID);
                if (dockedPart)
                {
                    KASModuleAttachCore dockedAttachModuleTmp = dockedPart.GetComponent <KASModuleAttachCore>();
                    if (dockedAttachModuleTmp)
                    {
                        KAS_Shared.DebugLog("OnLoad(Core) Re-set docking on " + dockedAttachModuleTmp.part.partInfo.title);
                        AttachDocked(dockedAttachModuleTmp);
                    }
                    else
                    {
                        KAS_Shared.DebugError("OnLoad(Core) Unable to get docked module !");
                        attachMode.Docked = false;
                    }
                }
                else
                {
                    KAS_Shared.DebugError("OnLoad(Core) Unable to get saved docked part !");
                    attachMode.Docked = false;
                }
            }

            if (attachMode.Coupled)
            {
                // Todo
            }

            if (attachMode.FixedJoint)
            {
                Part attachedPart = KAS_Shared.GetPartByID(FixedAttach.savedVesselID, FixedAttach.savedPartID);
                if (attachedPart)
                {
                    KAS_Shared.DebugLog("OnLoad(Core) Re-set fixed joint on " + attachedPart.partInfo.title);
                    AttachFixed(attachedPart, FixedAttach.savedBreakForce);
                }
                else
                {
                    KAS_Shared.DebugError("OnLoad(Core) Unable to get saved connected part of the fixed joint !");
                    attachMode.FixedJoint = false;
                }
            }
            if (attachMode.StaticJoint)
            {
                // Nothing to do (see OnVesselLoaded)
            }
            GameEvents.onVesselGoOffRails.Add(new EventData <Vessel> .OnEvent(this.OnVesselGoOffRails));
        }
Пример #8
0
 public static Part GetPartByID(Vessel searchVessel, string partID) {
   Part searchedPart = searchVessel.Parts.Find(p => p.flightID.ToString() == partID);
   if (searchedPart) {
     return searchedPart;
   } else {
     KAS_Shared.DebugError("GetPartByID - Searched part not found !");
     return null;
   }
 }
Пример #9
0
        private void Take(PartContent avPart)
        {
            if (waitAndGrabRunning)
            {
                KAS_Shared.DebugError("Take(Container) Take action is already running, please wait !");
                return;
            }
            if (!FlightGlobals.ActiveVessel.isEVA)
            {
                KAS_Shared.DebugError("Take(Container) Can only grab from EVA!");
                return;
            }
            KASModuleGrab grabbed = KAS_Shared.GetGrabbedPartModule(FlightGlobals.ActiveVessel);

            if (grabbed && grabbed.part.packed)
            {
                KAS_Shared.DebugError("Take(Container) EVA holding a packed part!");
                return;
            }
            if (avPart.pristine_count <= 0 && avPart.instances.Count > 0)
            {
                if (TakeStoredInstance(avPart.instances[0], FlightGlobals.ActiveVessel))
                {
                    avPart.PopInstance();
                    RefreshTotalSize();
                }
                return;
            }
            KASModuleGrab prefabGrabModule = avPart.grabModule;
            // get grabbed position and rotation
            Vector3    pos = FlightGlobals.ActiveVessel.rootPart.transform.TransformPoint(prefabGrabModule.evaPartPos);
            Quaternion rot = FlightGlobals.ActiveVessel.rootPart.transform.rotation * Quaternion.Euler(prefabGrabModule.evaPartDir);

            //Move away the part at creation
            pos += new Vector3(0f, 0f, 100);

            //Part newPart = KAS_Shared.CreatePart(avPart, pos, rot, this.part);
            Part newPart = KAS_Shared.CreatePart(avPart.name, pos, rot, this.part);

            if (!newPart)
            {
                KAS_Shared.DebugError("Take(Container) failed to create the part !");
                return;
            }

            KASModuleGrab moduleGrab = newPart.GetComponent <KASModuleGrab>();

            if (!moduleGrab)
            {
                KAS_Shared.DebugError("Take(Container) Cannot grab the part taken, no grab module found !");
                return;
            }
            avPart.pristine_count--;
            RefreshTotalSize();
            StartCoroutine(WaitAndGrab(moduleGrab, FlightGlobals.ActiveVessel));
        }
Пример #10
0
  public static Part CreatePart(AvailablePart avPart, Vector3 position, Quaternion rotation,
                                Part flagFromPart) {
    UnityEngine.Object obj = UnityEngine.Object.Instantiate(avPart.partPrefab);
    if (!obj) {
      KAS_Shared.DebugError("CreatePart(Crate) Failed to instantiate " + avPart.partPrefab.name);
      return null;
    }

    Part newPart = (Part)obj;
    newPart.gameObject.SetActive(true);
    newPart.gameObject.name = avPart.name;
    newPart.partInfo = avPart;
    //newPart.highlightRecurse = true;
    newPart.SetMirror(Vector3.one);

    ShipConstruct newShip = new ShipConstruct();
    newShip.Add(newPart);
    newShip.SaveShip();
    newShip.shipName = avPart.title;
    //newShip.ty = 1;

    VesselCrewManifest vessCrewManifest = new VesselCrewManifest();
    Vessel currentVessel = FlightGlobals.ActiveVessel;

    Vessel v = newShip.parts[0].localRoot.gameObject.AddComponent<Vessel>();
    v.id = Guid.NewGuid();
    v.vesselName = newShip.shipName;
    v.Initialize(false);
    v.Landed = true;
    v.rootPart.flightID = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState);
    v.rootPart.missionID = flagFromPart.missionID;
    v.rootPart.flagURL = flagFromPart.flagURL;

    //v.rootPart.collider.isTrigger = true;

    //v.landedAt = "somewhere";
                      
    Staging.beginFlight();
    newShip.parts[0].vessel.ResumeStaging();
    Staging.GenerateStagingSequence(newShip.parts[0].localRoot);
    Staging.RecalculateVesselStaging(newShip.parts[0].vessel);

    FlightGlobals.SetActiveVessel(currentVessel);

    v.SetPosition(position);
    v.SetRotation(rotation);

    // Solar panels from containers don't work otherwise
    for (int i = 0; i < newPart.Modules.Count; i++) {
      ConfigNode node = new ConfigNode();
      node.AddValue("name", newPart.Modules[i].moduleName);
      newPart.LoadModule(node, ref i);
    }

    return newPart;
  }
Пример #11
0
        public static Part CreatePart(AvailablePart avPart, Vector3 position, Quaternion rotation, Part flagFromPart)
        {
            UnityEngine.Object obj = UnityEngine.Object.Instantiate(avPart.partPrefab);
            if (!obj)
            {
                KAS_Shared.DebugError("CreatePart(Crate) Failed to instantiate " + avPart.partPrefab.name);
                return(null);
            }

            Part newPart = (Part)obj;

            newPart.gameObject.SetActive(true);
            newPart.gameObject.name  = "KASCreatedPart";
            newPart.partInfo         = avPart;
            newPart.highlightRecurse = true;

            ShipConstruct newShip = new ShipConstruct();

            newShip.Add(newPart);
            newShip.SaveShip();
            newShip.shipName = avPart.title;
            newShip.shipType = 1;

            VesselCrewManifest vessCrewManifest = new VesselCrewManifest();
            Vessel             currentVessel    = FlightGlobals.ActiveVessel;

            Vessel v = newShip.parts[0].localRoot.gameObject.AddComponent <Vessel>();

            v.id         = Guid.NewGuid();
            v.vesselName = newShip.shipName;
            v.Initialize(false);
            v.Landed             = true;
            v.rootPart.flightID  = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState);
            v.rootPart.missionID = (uint)Guid.NewGuid().GetHashCode();
            v.rootPart.flagURL   = flagFromPart.flagURL;

            //v.rootPart.collider.isTrigger = true;

            v.rootPart.FindModelTransform("model").localScale *= v.rootPart.rescaleFactor;


            //v.landedAt = "somewhere";

            Staging.beginFlight();
            newShip.parts[0].vessel.ResumeStaging();
            Staging.GenerateStagingSequence(newShip.parts[0].localRoot);
            Staging.RecalculateVesselStaging(newShip.parts[0].vessel);

            FlightGlobals.SetActiveVessel(currentVessel);

            v.SetPosition(position);
            v.SetRotation(rotation);
            return(newPart);
        }
Пример #12
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (state == StartState.Editor || state == StartState.None)
            {
                return;
            }

            if (attachMode.Docked)
            {
                Part dockedPart = KAS_Shared.GetPartByID(this.vessel, dockedPartID);
                if (dockedPart && (dockedPart == part.parent || dockedPart.parent == part))
                {
                    KASModuleAttachCore dockedAttachModuleTmp = dockedPart.GetComponent <KASModuleAttachCore>();
                    if (dockedAttachModuleTmp == null)
                    {
                        KAS_Shared.DebugError("OnLoad(Core) Unable to get docked module !");
                        attachMode.Docked = false;
                    }
                    else if (dockedAttachModuleTmp.attachMode.Docked &&
                             dockedAttachModuleTmp.dockedPartID == part.flightID.ToString() &&
                             dockedAttachModuleTmp.vesselInfo != null)
                    {
                        KAS_Shared.DebugLog("OnLoad(Core) Part already docked to " + dockedAttachModuleTmp.part.partInfo.title);
                        this.dockedAttachModule = dockedAttachModuleTmp;
                        dockedAttachModuleTmp.dockedAttachModule = this;
                    }
                    else
                    {
                        KAS_Shared.DebugLog("OnLoad(Core) Re-set docking on " + dockedAttachModuleTmp.part.partInfo.title);
                        AttachDocked(dockedAttachModuleTmp);
                    }
                }
                else
                {
                    KAS_Shared.DebugError("OnLoad(Core) Unable to get saved docked part !");
                    attachMode.Docked = false;
                }
            }

            if (attachMode.Coupled)
            {
                // Todo
            }

            if (attachMode.FixedJoint)
            {
                StartCoroutine(WaitAndInitFixedAttach());
            }
            if (attachMode.StaticJoint)
            {
                // Nothing to do (see OnVesselLoaded)
            }
        }
Пример #13
0
        private float GetPartSize(AvailablePart avPart)
        {
            KASModuleGrab grabModule = avPart.partPrefab.GetComponent <KASModuleGrab>();

            if (grabModule)
            {
                return(grabModule.storedSize);
            }
            else
            {
                KAS_Shared.DebugError("Cannot retrieve part size, grab module not found !");
                return(0);
            }
        }
Пример #14
0
        private bool TakeStoredInstance(ConfigNode node, Vessel vessel)
        {
            Part newPart = KAS_Shared.LoadPartSnapshot(vessel, node, Vector3.zero, Quaternion.identity);

            KASModuleGrab moduleGrab = newPart.GetComponent <KASModuleGrab>();

            if (!moduleGrab || !moduleGrab.GrabPending())
            {
                KAS_Shared.DebugError("Take(Container) Cannot grab the part taken, no grab module found !");
                newPart.Die();
                return(false);
            }

            return(true);
        }
Пример #15
0
        void Awake()
        {
            audioBipWrong          = audioGo.AddComponent <AudioSource>();
            audioBipWrong.volume   = GameSettings.UI_VOLUME;
            audioBipWrong.panLevel = 0;  //set as 2D audiosource

            if (GameDatabase.Instance.ExistsAudioClip(bipWrongSndPath))
            {
                audioBipWrong.clip = GameDatabase.Instance.GetAudioClip(bipWrongSndPath);
            }
            else
            {
                KAS_Shared.DebugError("Awake(AttachPointer) Bip wrong sound not found in the game database !");
                ScreenMessages.PostScreenMessage("Sound file : " + bipWrongSndPath + " as not been found, please check your KAS installation !", 10, ScreenMessageStyle.UPPER_CENTER);
            }
        }
Пример #16
0
 protected virtual void InitFixedAttach()
 {
     if (attachMode.FixedJoint)
     {
         Part attachedPart = KAS_Shared.GetPartByID(FixedAttach.savedVesselID, FixedAttach.savedPartID);
         if (attachedPart)
         {
             KAS_Shared.DebugLog("OnLoad(Core) Re-set fixed joint on " + attachedPart.partInfo.title);
             AttachFixed(attachedPart, FixedAttach.savedBreakForce);
         }
         else
         {
             KAS_Shared.DebugError("OnLoad(Core) Unable to get saved connected part of the fixed joint !");
             attachMode.FixedJoint = false;
         }
     }
 }
Пример #17
0
 public override void OnSave(ConfigNode node)
 {
     base.OnSave(node);
     if (attachMode.FixedJoint)
     {
         KAS_Shared.DebugLog("OnSave(Core) Fixed joint detected, saving info...");
         ConfigNode FxNode = node.AddNode("FIXEDATTACH");
         FxNode.AddValue("srcPartID", FixedAttach.srcPart.flightID.ToString());
         FxNode.AddValue("srcVesselID", FixedAttach.srcPart.vessel.id.ToString());
         FxNode.AddValue("tgtPartID", FixedAttach.tgtPart.flightID.ToString());
         FxNode.AddValue("tgtVesselID", FixedAttach.tgtPart.vessel.id.ToString());
         if (FixedAttach.fixedJoint)
         {
             KAS_Shared.DebugLog(string.Format("OnSave(Core) Saving breakforce from joint config : {0}",
                                               FixedAttach.fixedJoint.breakForce));
             FxNode.AddValue("breakForce", FixedAttach.fixedJoint.breakForce);
         }
         else
         {
             KAS_Shared.DebugLog(string.Format(
                                     "OnSave(Core) Saving breakforce from saved : {0}", FixedAttach.savedBreakForce));
             FxNode.AddValue("breakForce", FixedAttach.savedBreakForce);
         }
     }
     if (attachMode.StaticJoint)
     {
         KAS_Shared.DebugLog("OnSave(Core) Static joint detected, saving info...");
         node.AddValue("StaticJoint", "True");
     }
     if (attachMode.Docked)
     {
         KAS_Shared.DebugLog("OnSave(Core) Docked joint detected, saving info...");
         if (dockedAttachModule)
         {
             node.AddValue("dockedPartID", dockedAttachModule.part.flightID.ToString());
             ConfigNode nodeD = node.AddNode("DOCKEDVESSEL");
             this.vesselInfo.Save(nodeD);
         }
         else
         {
             KAS_Shared.DebugError("OnSave(Core) dockedAttachModule is null!");
         }
     }
 }
Пример #18
0
        private void Move(AvailablePart aPart, int qty, KASModuleContainer destContainer)
        {
            KASModuleGrab moduleGrab = aPart.partPrefab.GetComponent <KASModuleGrab>();

            if (!moduleGrab)
            {
                fxSndBipWrong.audio.Play();
                KAS_Shared.DebugError("Cannot grab the part taken, no grab module found !");
                return;
            }
            if (destContainer.MaxSizeReached(aPart, 1))
            {
                fxSndBipWrong.audio.Play();
                ScreenMessages.PostScreenMessage("Max size of the destination container reached !", 5, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            Remove(aPart, qty);
            destContainer.Add(aPart, qty);
        }
Пример #19
0
        protected override void InitFixedAttach()
        {
            base.InitFixedAttach();

            // Reset link if a fixed joint exist
            if (attachMode.FixedJoint)
            {
                KAS_Shared.DebugLog("OnStart(strut) Docked / fixed joint detected from save, relinking...");
                Part tgtStrutPart = KAS_Shared.GetPartByID(tgtStrutVesselID, tgtStrutPartID);
                if (tgtStrutPart)
                {
                    KASModuleStrut linkedStrutModuleSavedF = tgtStrutPart.GetComponent <KASModuleStrut>();
                    LinkTo(linkedStrutModuleSavedF, false, true);
                }
                else
                {
                    KAS_Shared.DebugError("OnStart(strut) Target strut part not found !");
                }
            }
        }
Пример #20
0
        private void Take(AvailablePart avPart)
        {
            if (waitAndGrabRunning)
            {
                KAS_Shared.DebugError("Take(Container) Take action is already running, please wait !");
                return;
            }
            KASModuleGrab prefabGrabModule = avPart.partPrefab.GetComponent <KASModuleGrab>();

            if (!prefabGrabModule)
            {
                KAS_Shared.DebugError("Take(Container) Can't find the prefab grab module !");
                return;
            }
            // get grabbed position and rotation
            Vector3    pos = FlightGlobals.ActiveVessel.rootPart.transform.TransformPoint(prefabGrabModule.evaPartPos);
            Quaternion rot = FlightGlobals.ActiveVessel.rootPart.transform.rotation * Quaternion.Euler(prefabGrabModule.evaPartDir);

            //Move away the part at creation
            pos += new Vector3(0f, 0f, 100);

            //Part newPart = KAS_Shared.CreatePart(avPart, pos, rot, this.part);
            Part newPart = KAS_Shared.CreatePart(avPart.name, pos, rot, this.part);

            if (!newPart)
            {
                KAS_Shared.DebugError("Take(Container) failed to create the part !");
                return;
            }

            KASModuleGrab moduleGrab = newPart.GetComponent <KASModuleGrab>();

            if (!moduleGrab)
            {
                KAS_Shared.DebugError("Take(Container) Cannot grab the part taken, no grab module found !");
                return;
            }
            Remove(avPart, 1);
            StartCoroutine(WaitAndGrab(moduleGrab, FlightGlobals.ActiveVessel));
        }
Пример #21
0
 protected virtual void InitFixedAttach()
 {
     if (attachMode.FixedJoint)
     {
         Part srcPart = KAS_Shared.GetPartByID(
             FixedAttach.savedSrcVesselID, FixedAttach.savedSrcPartID);
         Part tgtPart = KAS_Shared.GetPartByID(
             FixedAttach.savedTgtVesselID, FixedAttach.savedTgtPartID);
         if (tgtPart)
         {
             KAS_Shared.DebugLog(string.Format(
                                     "OnLoad(Core) Re-set fixed joint on {0}", tgtPart.partInfo.title));
             AttachFixed(srcPart, tgtPart, FixedAttach.savedBreakForce);
         }
         else
         {
             KAS_Shared.DebugError(
                 "OnLoad(Core) Unable to get saved connected part of the fixed joint !");
             attachMode.FixedJoint = false;
         }
     }
 }
Пример #22
0
        private void LoadBays()
        {
            bays.Clear();
            ConfigNode node = KAS_Shared.GetBaseConfigNode(this);

            foreach (ConfigNode bayNode in node.GetNodes("BAY"))
            {
                if (bayNode.HasValue("attachNode") && bayNode.HasValue("type"))
                {
                    string     attachNodeName = bayNode.GetValue("attachNode");
                    AttachNode an             = this.part.findAttachNode(attachNodeName);
                    if (an == null)
                    {
                        KAS_Shared.DebugError("LoadBays(PartBay) - Node : " + attachNodeName + " not found !");
                        continue;
                    }
                    List <string> allTypes = new List <string>(bayNode.GetValues("type"));
                    KAS_Shared.AddNodeTransform(this.part, an);
                    bays.Add(an, allTypes);
                }
            }
        }
Пример #23
0
        private void LoadSections()
        {
            sections.Clear();
            sectionTotalLenght = 0;
            ConfigNode node = KAS_Shared.GetBaseConfigNode(this);
            int        i    = 0;

            foreach (ConfigNode sectionNode in node.GetNodes("SECTION"))
            {
                if (sectionNode.HasValue("transformName") && sectionNode.HasValue("lenght"))
                {
                    SectionInfo section = new SectionInfo();
                    string      sectionTransformName = sectionNode.GetValue("transformName");
                    section.transform = this.part.FindModelTransform(sectionTransformName);
                    if (!section.transform)
                    {
                        KAS_Shared.DebugError("LoadSections(TelescopicArm) Section transform "
                                              + sectionTransformName + " not found in the model !");
                        continue;
                    }
                    if (!float.TryParse(sectionNode.GetValue("lenght"), out section.lenght))
                    {
                        KAS_Shared.DebugError(
                            "LoadSections(TelescopicArm) Unable to parse lenght of the Section : "
                            + sectionTransformName);
                        continue;
                    }
                    section.orgLocalPos = KAS_Shared.GetLocalPosFrom(section.transform, this.part.transform);
                    section.orgLocalRot = KAS_Shared.GetLocalRotFrom(section.transform, this.part.transform);
                    if (savedSectionsLocalPos.Count > 0)
                    {
                        section.savedLocalPos = savedSectionsLocalPos[i];
                    }
                    sections.Add(i, section);
                    sectionTotalLenght += section.lenght;
                    i++;
                }
            }
        }
Пример #24
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (state == StartState.Editor || state == StartState.None)
            {
                return;
            }
            KAS_Shared.createFXSound(this.part, fxSndGrab, grabSndPath, false);
            KAS_Shared.createFXSound(this.part, fxSndAttachPart, attachPartSndPath, false);
            KAS_Shared.createFXSound(this.part, fxSndDetach, detachSndPath, false);
            KAS_Shared.createFXSound(this.part, fxSndAttachStatic, attachStaticSndPath, false);
            RefreshContextMenu();

            //Get attach node
            if (attachNodeName == null || attachNodeName == "")
            {
                if (this.part.srfAttachNode == null)
                {
                    KAS_Shared.DebugError("Grab - surface attach node cannot be found on the part !");
                    return;
                }
                KAS_Shared.AddNodeTransform(this.part, this.part.srfAttachNode);
                partNode = this.part.srfAttachNode;
            }
            else
            {
                AttachNode an = this.part.findAttachNode(attachNodeName);
                if (an == null)
                {
                    KAS_Shared.DebugError("Grab - " + attachNodeName + " node cannot be found on the part !");
                    return;
                }
                KAS_Shared.AddNodeTransform(this.part, an);
                partNode = an;
            }
        }
Пример #25
0
        public void LoadRotor()
        {
            KAS_Shared.DebugLog("LoadRotor(Rotor) - Find rotor transform...");
            rotorTransform = this.part.FindModelTransform(rotorTransformName);

            KAS_Shared.DebugLog("LoadRotor(Rotor) - Create physical object...");
            rotorPhysicModule = this.part.gameObject.GetComponent <KASModulePhysicChild>();
            if (!rotorPhysicModule)
            {
                KAS_Shared.DebugLog("LoadRotor(Rotor) - KASModulePhysicChild do not exist, adding it...");
                rotorPhysicModule = this.part.gameObject.AddComponent <KASModulePhysicChild>();
            }
            rotorPhysicModule.mass      = rotorMass;
            rotorPhysicModule.physicObj = rotorTransform.gameObject;
            rotorPhysicModule.Start();

            orgRotorMass = this.part.mass;
            float newMass = this.part.mass - rotorMass;

            if (newMass > 0)
            {
                this.part.mass = newMass;
            }
            else
            {
                KAS_Shared.DebugWarning("LoadRotor(Rotor) - Mass of the rotor is greater than the part !");
            }

            KAS_Shared.DebugLog("LoadRotor - Save original rotor position...");
            rotorOrgLocalPos = KAS_Shared.GetLocalPosFrom(rotorTransform, this.part.transform);
            rotorOrgLocalRot = KAS_Shared.GetLocalRotFrom(rotorTransform, this.part.transform);

            KAS_Shared.DebugLog("LoadRotor - Disable collision...");
            if (rotorTransform.collider)
            {
                KAS_Shared.DisableVesselCollision(this.part.vessel, rotorTransform.collider);
            }
            else
            {
                KAS_Shared.DebugError("LoadRotor - Rotor transform do not have any collider !");
            }

            KAS_Shared.DebugLog("LoadRotor - Create hinge joint...");
            hingeJnt = this.part.gameObject.AddComponent <HingeJoint>();
            hingeJnt.connectedBody = rotorTransform.rigidbody;
            ResetLimitsConfig();
            ResetMotorConfig();
            ResetSpringConfig();
            ResetJointConfig();

            if (firstLoad)
            {
                firstLoad = false;
            }
            else
            {
                KAS_Shared.DebugLog("LoadRotor - Return rotor to the current position and rotation : " + rotorLocalPos + " | " + rotorLocalRot);
                KAS_Shared.SetPartLocalPosRotFrom(rotorTransform.transform, this.part.transform, rotorLocalPos, rotorLocalRot);
            }

            // Get rotor attach nodes
            attachNodes.Clear();
            ConfigNode    node          = KAS_Shared.GetBaseConfigNode(this);
            List <string> attachNodesSt = new List <string>(node.GetValues("attachNode"));

            foreach (String anString in attachNodesSt)
            {
                AttachNode an = this.part.findAttachNode(anString);
                if (an != null)
                {
                    KAS_Shared.DebugLog("LoadRotor - Rotor attach node added : " + an.id);
                    attachNodes.Add(an);
                    if (an.attachedPart)
                    {
                        KAS_Shared.DebugLog("LoadRotor - Setting rotor joint on : " + an.attachedPart.partInfo.title);
                        KAS_Shared.RemoveFixedJointBetween(this.part, an.attachedPart);
                        KAS_Shared.RemoveHingeJointBetween(this.part, an.attachedPart);
                        FixedJoint fjnt = an.attachedPart.gameObject.AddComponent <FixedJoint>();
                        fjnt.connectedBody = rotorTransform.rigidbody;
                        fixedJnts.Add(fjnt);
                    }
                }
            }
            MotorStop();
            rotorLoaded = true;
        }
Пример #26
0
        public void ContextMenuStore()
        {
            KASModuleGrab moduleEvaGrab = KAS_Shared.GetGrabbedPartModule(FlightGlobals.ActiveVessel);

            if (!moduleEvaGrab || moduleEvaGrab.part.packed)
            {
                ScreenMessages.PostScreenMessage("You need to grab a part before", 2, ScreenMessageStyle.UPPER_CENTER);
                KAS_Shared.DebugWarning("ContextMenuStore - GetGrabbedPartModule return null !");
                return;
            }
            // Select the nearest compatible bay
            float      shorterDist    = Mathf.Infinity;
            AttachNode nearestBayNode = null;

            foreach (KeyValuePair <AttachNode, List <string> > bay in bays)
            {
                if (bay.Value != null)
                {
                    if (!bay.Value.Contains(moduleEvaGrab.bayType))
                    {
                        KAS_Shared.DebugWarning("ContextMenuStore - Part type : " + moduleEvaGrab.bayType + " is not allowed | Attach node : " + bay.Key.id);
                        foreach (string type in bay.Value)
                        {
                            KAS_Shared.DebugWarning("ContextMenuStore - Allowed type : " + type);
                        }
                        continue;
                    }
                }
                if (bay.Key.attachedPart)
                {
                    KAS_Shared.DebugWarning("ContextMenuStore - This node are used");
                    continue;
                }

                float distToBay = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, bay.Key.nodeTransform.position);
                if (distToBay <= shorterDist)
                {
                    shorterDist    = distToBay;
                    nearestBayNode = bay.Key;
                }
            }

            if (nearestBayNode == null)
            {
                ScreenMessages.PostScreenMessage("Part is not compatible or there is no free space", 2, ScreenMessageStyle.UPPER_CENTER);
                KAS_Shared.DebugWarning("ContextMenuStore - Part is not compatible or there is no free space");
                return;
            }

            AttachNode grabbedPartAn = moduleEvaGrab.part.findAttachNode(moduleEvaGrab.bayNode);

            if (grabbedPartAn == null)
            {
                KAS_Shared.DebugError("ContextMenuStore - Grabbed part bay node not found !");
                return;
            }

            KAS_Shared.DebugLog("ContextMenuStore - Drop part...");
            moduleEvaGrab.Drop();

            KAS_Shared.DebugLog("ContextMenuStore - Add node transform if not exist...");
            KAS_Shared.AddNodeTransform(moduleEvaGrab.part, grabbedPartAn);

            KAS_Shared.DebugLog("ContextMenuStore - Move part...");
            KAS_Shared.MoveAlign(moduleEvaGrab.part.transform, grabbedPartAn.nodeTransform, nearestBayNode.nodeTransform);
            moduleEvaGrab.part.transform.rotation *= Quaternion.Euler(moduleEvaGrab.bayRot);

            //Couple part with bay
            KAS_Shared.DebugLog("ContextMenuStore - Couple part with bay...");
            moduleEvaGrab.part.Couple(this.part);
            nearestBayNode.attachedPart = moduleEvaGrab.part;

            fxSndStore.audio.Play();
            moduleEvaGrab.part.SendMessage("OnBayStore", SendMessageOptions.DontRequireReceiver);
        }
Пример #27
0
        private void AddGrabModule(ConfigNode node)
        {
            foreach (ConfigNode grabNode in node.GetNodes("GRAB"))
            {
                // Check if the node has value
                if (!grabNode.HasValue("stockPartName"))
                {
                    KAS_Shared.DebugWarning("AddGrabModule(AddModule) Missing stockPartName node !");
                    continue;
                }
                // Add and Retrieve the module
                string        partName = grabNode.GetValue("stockPartName").Replace('_', '.');
                AvailablePart aPart    = PartLoader.getPartInfoByName(partName);
                if (aPart == null)
                {
                    KAS_Shared.DebugError("AddModule(AddModule) - " + partName + " not found in partloader");
                    continue;
                }

                // get or add grab module
                KASModuleGrab grabModule = aPart.partPrefab.GetComponent <KASModuleGrab>();
                if (grabModule)
                {
                    KAS_Shared.DebugWarning("AddModule(AddModule) - KASModuleGrab already added to " + partName);
                }
                else
                {
                    grabModule = aPart.partPrefab.AddModule("KASModuleGrab") as KASModuleGrab;
                    if (!grabModule)
                    {
                        KAS_Shared.DebugError("AddGrabModule(AddModule) Error when adding module !");
                        continue;
                    }
                }

                // Configure the module
                if (grabNode.HasValue("evaPartPos"))
                {
                    grabModule.evaPartPos = KAS_Shared.ParseCfgVector3(grabNode.GetValue("evaPartPos"));
                }
                if (grabNode.HasValue("evaPartDir"))
                {
                    grabModule.evaPartDir = KAS_Shared.ParseCfgVector3(grabNode.GetValue("evaPartDir"));
                }
                if (grabNode.HasValue("customGroundPos"))
                {
                    grabModule.customGroundPos = bool.Parse(grabNode.GetValue("customGroundPos"));
                }
                if (grabNode.HasValue("dropPartPos"))
                {
                    grabModule.dropPartPos = KAS_Shared.ParseCfgVector3(grabNode.GetValue("dropPartPos"));
                }
                if (grabNode.HasValue("dropPartRot"))
                {
                    grabModule.dropPartRot = KAS_Shared.ParseCfgVector3(grabNode.GetValue("dropPartRot"));
                }
                if (grabNode.HasValue("physicJoint"))
                {
                    grabModule.physicJoint = bool.Parse(grabNode.GetValue("physicJoint"));
                }
                if (grabNode.HasValue("addPartMass"))
                {
                    grabModule.addPartMass = bool.Parse(grabNode.GetValue("addPartMass"));
                }
                if (grabNode.HasValue("storable"))
                {
                    grabModule.storable = bool.Parse(grabNode.GetValue("storable"));
                }
                if (grabNode.HasValue("stateless"))
                {
                    grabModule.stateless = bool.Parse(grabNode.GetValue("stateless"));
                }
                if (grabNode.HasValue("storedSize"))
                {
                    grabModule.storedSize = int.Parse(grabNode.GetValue("storedSize"));
                }
                if (grabNode.HasValue("bayType"))
                {
                    grabModule.bayType = grabNode.GetValue("bayType").ToString();
                }
                if (grabNode.HasValue("bayNode"))
                {
                    grabModule.bayNode = grabNode.GetValue("bayNode").ToString();
                }
                if (grabNode.HasValue("bayRot"))
                {
                    grabModule.bayRot = KAS_Shared.ParseCfgVector3(grabNode.GetValue("bayRot"));
                }
                if (grabNode.HasValue("grabSndPath"))
                {
                    grabModule.grabSndPath = grabNode.GetValue("grabSndPath").ToString();
                }
                if (grabNode.HasValue("attachMaxDist"))
                {
                    grabModule.attachMaxDist = float.Parse(grabNode.GetValue("attachMaxDist"));
                }
                if (grabNode.HasValue("attachOnPart"))
                {
                    grabModule.attachOnPart = bool.Parse(grabNode.GetValue("attachOnPart"));
                }
                if (grabNode.HasValue("attachOnEva"))
                {
                    grabModule.attachOnEva = bool.Parse(grabNode.GetValue("attachOnEva"));
                }
                if (grabNode.HasValue("attachOnStatic"))
                {
                    grabModule.attachOnStatic = bool.Parse(grabNode.GetValue("attachOnStatic"));
                }
                if (grabNode.HasValue("attachSendMsgOnly"))
                {
                    grabModule.attachSendMsgOnly = bool.Parse(grabNode.GetValue("attachSendMsgOnly"));
                }
                if (grabNode.HasValue("attachPartSndPath"))
                {
                    grabModule.attachPartSndPath = grabNode.GetValue("attachPartSndPath").ToString();
                }
                if (grabNode.HasValue("attachStaticSndPath"))
                {
                    grabModule.attachStaticSndPath = grabNode.GetValue("attachStaticSndPath").ToString();
                }
                if (grabNode.HasValue("detachSndPath"))
                {
                    grabModule.detachSndPath = grabNode.GetValue("detachSndPath").ToString();
                }
                KAS_Shared.DebugLog("AddGrabModule(AddModule) Module successfully configured on " + partName);
            }
        }
Пример #28
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (state == StartState.Editor || state == StartState.None)
            {
                return;
            }
            //Loading texture
            texStrut = GameDatabase.Instance.GetTexture(tubeTexPath, false);
            if (!texStrut)
            {
                KAS_Shared.DebugError("tube texture loading error !");
                ScreenMessages.PostScreenMessage(
                    "Texture file : " + tubeTexPath
                    + " as not been found, please check your KAS installation !",
                    10, ScreenMessageStyle.UPPER_CENTER);
            }
            // loading sounds
            KAS_Shared.createFXSound(this.part, fxSndLink, sndLinkPath, false);
            KAS_Shared.createFXSound(this.part, fxSndUnlink, sndUnlinkPath, false);
            KAS_Shared.createFXSound(this.part, fxSndBroke, sndBrokePath, false);

            // loading strut renderer
            strutRenderer = this.part.gameObject.AddComponent <KAS_Tube>();
            strutRenderer.tubeTexTilingOffset = textureTiling;
            strutRenderer.tubeScale           = tubeScale;
            strutRenderer.sphereScale         = jointScale;
            strutRenderer.tubeTexture         = texStrut;
            strutRenderer.sphereTexture       = texStrut;
            strutRenderer.tubeJoinedTexture   = texStrut;
            strutRenderer.srcNode             = strutTransform;

            // loading tube type
            switch (tubeSrcType)
            {
            case "None":
                strutRenderer.srcJointType = KAS_Tube.tubeJointType.None;
                break;

            case "Rounded":
                strutRenderer.srcJointType = KAS_Tube.tubeJointType.Rounded;
                break;

            case "ShiftedAndRounded":
                strutRenderer.srcJointType = KAS_Tube.tubeJointType.ShiftedAndRounded;
                break;

            case "Joined":
                strutRenderer.srcJointType = KAS_Tube.tubeJointType.Joined;
                break;

            default:
                strutRenderer.srcJointType = KAS_Tube.tubeJointType.Joined;
                break;
            }
            switch (tubeTgtType)
            {
            case "None":
                strutRenderer.tgtJointType = KAS_Tube.tubeJointType.None;
                break;

            case "Rounded":
                strutRenderer.tgtJointType = KAS_Tube.tubeJointType.Rounded;
                break;

            case "ShiftedAndRounded":
                strutRenderer.tgtJointType = KAS_Tube.tubeJointType.ShiftedAndRounded;
                break;

            case "Joined":
                strutRenderer.tgtJointType = KAS_Tube.tubeJointType.Joined;
                break;

            default:
                strutRenderer.tgtJointType = KAS_Tube.tubeJointType.Joined;
                break;
            }

            // Reset link if docked
            if (attachMode.Docked && !linked)
            {
                KAS_Shared.DebugLog("OnStart(strut) Docked strut detected from save, relinking...");
                KASModuleStrut linkedStrutModuleSavedD = dockedAttachModule.GetComponent <KASModuleStrut>();
                LinkTo(linkedStrutModuleSavedD, false, true);
            }

            // Loading onVesselWasModified KSP event
            GameEvents.onVesselWasModified.Add(new EventData <Vessel> .OnEvent(this.OnVesselWasModified));
        }