Esempio n. 1
0
 private void AddChildToConstruct(ShipConstruct construct, Part childPart)
 {
     construct.Add(childPart);
     for (int i = 0; i < childPart.FindChildParts <Part>().Count(); i++)
     {
         AddChildToConstruct(construct, childPart.FindChildParts <Part>()[i]);
     }
 }
Esempio n. 2
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;
  }
Esempio n. 3
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);
        }
Esempio n. 4
0
        //creation
        public static Vessel Create(Creature creature, Vector3 positionOffset)
        {
            try
            {
                AvailablePart partInfo      = PartLoader.LoadedPartsList.First(ap => ap.name == creature.part);
                Part          referencePart = FlightGlobals.ActiveVessel.rootPart;

                Part part = (Part)UnityEngine.Object.Instantiate(partInfo.partPrefab);
                part.gameObject.SetActive(true);
                part.gameObject.name = partInfo.name;
                part.partInfo        = partInfo;
                part.SetMirror(Vector3.one);

                ShipConstruct sc = new ShipConstruct();
                sc.Add(part);
                sc.SaveShip();
                sc.shipName = creature.name;

                Vessel vessel = sc.parts[0].localRoot.gameObject.AddComponent <Vessel>();
                vessel.id         = Guid.NewGuid();
                vessel.vesselName = sc.shipName;
                vessel.vesselType = VesselType.Unknown;
                //vessel.DiscoveryInfo.Load(ProtoVessel.CreateDiscoveryNode(DiscoveryLevels.Unowned, UntrackedObjectClass.A, 10000, 10000));
                vessel.ctrlState = new FlightCtrlState();
                vessel.ctrlState.NeutralizeAll();
                vessel.Initialize(false);
                vessel.Landed = false;
                vessel.SetPosition(referencePart.transform.position + positionOffset);
                vessel.SetRotation(Quaternion.identity);

                //manually remove orbit renderer
                UnityEngine.Object.Destroy(vessel.orbitDriver.Renderer);

                CreaturePart cp = (CreaturePart)vessel.rootPart;
                cp.creature  = creature;
                cp.flightID  = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState);
                cp.missionID = referencePart.missionID;
                cp.flagURL   = referencePart.flagURL;

                FlightLogger.eventLog.Add(Utils.FormatTime(referencePart.vessel.missionTime) + "A " + creature.name + " was seen.");

                return(vessel);
            }
            catch (Exception e)
            {
                Utils.LogError("Error encountered while spawning part");
                if (e != null)
                {
                    Debug.LogException(e);
                }
            }

            return(null);
        }
Esempio n. 5
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.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 = 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;
        }
Esempio n. 6
0
        public static ShipConstruct buildConstruct(ConfigNode vessel)
        {
            ShipConstruct ship = new ShipConstruct();
            ConfigNode[] partNodes = vessel.GetNodes("PART");
            List<Part> parts = new List<Part>();
            string[] partNameByIdx = new string[partNodes.Length];
            Dictionary<string, Part> partByName = new Dictionary<string, Part>();

            int part_idx = 0;
            foreach (ConfigNode partNode in partNodes)
            {
                // get part name
                string[] str_part = partNode.GetValue("part").Split('_');
                partNameByIdx[part_idx] = partNode.GetValue("part");

                // get part from loader
                Part part = PartLoader.getPartInfoByName(str_part[0]).partPrefab;
                partByName[partNode.GetValue("part")] = part;

                // add info
                part.orgPos = Utils.StringToVector3(partNode.GetValue("pos"));
                part.attPos = Utils.StringToVector3(partNode.GetValue("attPos"));
                part.attPos0 = Utils.StringToVector3(partNode.GetValue("attPos0"));

                part.orgRot = Utils.StringToQuaternion(partNode.GetValue("rot"));
                part.attRotation = Utils.StringToQuaternion(partNode.GetValue("attRot"));
                part.attRotation0 = Utils.StringToQuaternion(partNode.GetValue("attRot0"));

                part.mirrorVector = Utils.StringToVector3(partNode.GetValue("mir"));

                string symMethod = partNode.GetValue("symMethod");
                if (symMethod == "Radial")
                {
                    part.symMethod = SymmetryMethod.Radial;
                }
                else if (symMethod == "Mirror")
                {
                    part.symMethod = SymmetryMethod.Mirror;
                }

                part.inverseStage = int.Parse(partNode.GetValue("istg"));
                part.defaultInverseStage = int.Parse(partNode.GetValue("istg"));
                part.stageOffset = int.Parse(partNode.GetValue("sidx"));
                //part.manualStageOffset = int.Parse(partNode.GetValue("sqor"));
                part.separationIndex = int.Parse(partNode.GetValue("sepI"));
                string attm = partNode.GetValue("attm");
                if (attm == "0")
                {
                    part.attachMode = AttachModes.STACK;
                }
                else if (attm == "1")
                {
                    part.attachMode = AttachModes.SRF_ATTACH;
                }
                // modCost = 0
                // modMass = 0
                // modSize = (0.0, 0.0, 0.0)

                // add to part list
                parts.Add(part);
                ship.Add(part);
                ++part_idx;
            }

            // add links
            part_idx = 0;
            foreach (Part part in parts)
            {
                string[] links = partNodes[part_idx].GetValues("link");
                foreach (string link in links)
                {
                    Part linkedPart = partByName[link];
                    if (linkedPart != null)
                    {
                        part.editorLinks.Add(linkedPart);
                        part.children.Add(linkedPart);

                        //AttachNode attN = new AttachNode(
                        //part.attachNodes.Add
                        //part.AddAttachNode(partNodes[part_idx]);
                    }
                }
                ++part_idx;
            }

            ship.shipFacility = EditorFacility.VAB;
            return ship;
        }
Esempio n. 7
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;
        }