public void set_StructuralIntegrityField(float force)
        {
            UnityEngine.Debug.Log("LCARS_StructuralIntegrityField: set_StructuralIntegrityField  beginn");
            if (backup_Parts == null)
            {
                backup_Parts = new Dictionary <Part, Dictionary <string, float> >()
                {
                };
            }

            foreach (Part p in this.ShipSelected.Parts)
            {
                if (!backup_Parts.ContainsKey(p))
                {
                    backup_values = new Dictionary <string, float>()
                    {
                    };
                    backup_values.Add("crashTolerance", p.crashTolerance);
                    backup_values.Add("breakingForce", p.breakingForce);
                    backup_values.Add("breakingTorque", p.breakingTorque);
                    backup_values.Add("maxTemp", p.maxTemp);
                    backup_values.Add("temperature", p.temperature);
                    backup_Parts.Add(p, backup_values);
                    backup_values = null;
                }

                p.crashTolerance = (force >= 1) ? backup_Parts[p]["crashTolerance"] * force : backup_Parts[p]["crashTolerance"];

                p.breakingForce = (force >= 1) ? backup_Parts[p]["breakingForce"] * force : backup_Parts[p]["breakingForce"];

                p.breakingTorque = (force >= 1) ? backup_Parts[p]["breakingTorque"] * force : backup_Parts[p]["breakingTorque"];

                p.maxTemp = (force >= 1) ? backup_Parts[p]["maxTemp"] * force : backup_Parts[p]["maxTemp"];

                p.temperature = (p.temperature > 20f) ? p.temperature - (0.005f * force) : p.temperature;

                //FromGO(UnityEngine.GameObject obj)

                foreach (AttachNode an in p.attachNodes)
                {
                    //an.attachedPart
                    //an.attachMethod
                    //an.breakingForce
                    //an.breakingTorque
                    //an.nodeType
                    //an.position
                }
                //p.attachNodes
                //AttachNode.attachedPart

                Part parentPart1 = p.localRoot;
                if (parentPart1 != null && p != parentPart1 && p.attachJoint == null)
                {
                    UnityEngine.Debug.Log("LCARS_StructuralIntegrityField: set_StructuralIntegrityField 1 parentPart1=" + parentPart1.name);
                    AttachNode  nodeToParent   = p.findAttachNodeByPart(parentPart1);
                    AttachNode  nodeFromParent = parentPart1.findAttachNodeByPart(p);
                    AttachModes m = (AttachModes)AttachNodeMethod.FIXED_JOINT;
                    p.attachJoint = PartJoint.Create(p, parentPart1, nodeToParent, nodeFromParent, m);
                    p.attachJoint.SetBreakingForces(p.breakingForce * force * 20000, p.breakingTorque * force * 20000);

                    UnityEngine.Debug.Log("LCARS_StructuralIntegrityField: set_StructuralIntegrityField 3 parentPart1=" + parentPart1.name);
                    addForceToAttachNodes(parentPart1, p, nodeToParent, nodeFromParent, force);
                    UnityEngine.Debug.Log("LCARS_StructuralIntegrityField: set_StructuralIntegrityField 3 parentPart1=" + parentPart1.name);
                }
                Part parentPart2 = p.parent;
                if (parentPart2 != null && p != parentPart2 && p.attachJoint == null)
                {
                    UnityEngine.Debug.Log("LCARS_StructuralIntegrityField: set_StructuralIntegrityField 1 parentPart2=" + parentPart2.name);
                    AttachNode  nodeToParent   = p.findAttachNodeByPart(parentPart2);
                    AttachNode  nodeFromParent = parentPart2.findAttachNodeByPart(p);
                    AttachModes m = (AttachModes)AttachNodeMethod.LOCKED_JOINT;
                    p.attachJoint = PartJoint.Create(p, parentPart2, nodeToParent, nodeFromParent, m);
                    p.attachJoint.SetBreakingForces(p.breakingForce * force * 20000, p.breakingTorque * force * 20000);
                    UnityEngine.Debug.Log("LCARS_StructuralIntegrityField: set_StructuralIntegrityField 2 parentPart2=" + parentPart2.name);

                    //addForceToAttachNodes(parentPart2, p, nodeToParent, nodeFromParent, force);
                    UnityEngine.Debug.Log("LCARS_StructuralIntegrityField: set_StructuralIntegrityField 3 parentPart2=" + parentPart2.name);
                }

                /*
                 */


                if (p.children.Count > 0)
                {
                    //addForceToPartChildConnections(p,force);
                }



                /*
                 * if (p.parent != null)
                 * {
                 * }
                 */


                float power = PT.L1_usage + (force / 10 * PT.L2_usage / 10);
                this.PowSys.draw(PT.takerName, power);
            }
        }
示例#2
0
        public PartSim(Part thePart, int id, double atmosphere, LogMsg log)
        {
            part = thePart;
            partId = id;
            name = part.partInfo.name;

            if (log != null)
                log.buf.AppendLine("Create PartSim for " + name);

            parent = null;
            parentAttach = part.attachMode;
            fuelCrossFeed = part.fuelCrossFeed;
            noCrossFeedNodeKey = part.NoCrossFeedNodeKey;
            decoupledInStage = DecoupledInStage(part);
            isFuelLine = part is FuelLine;
            isFuelTank = part is FuelTank;
            isSepratron = IsSepratron();
            inverseStage = part.inverseStage;
            //MonoBehaviour.print("inverseStage = " + inverseStage);

            cost = part.partInfo.cost;
            foreach (PartResource resource in part.Resources)
            {
                cost -= (float)((resource.maxAmount - resource.amount) * resource.info.unitCost);
            }

            // Work out if the part should have no physical significance
            isNoPhysics = part.HasModule<LaunchClamp>() ||
                            part.physicalSignificance == Part.PhysicalSignificance.NONE ||
                            part.PhysicsSignificance == 1;

            if (!isNoPhysics)
                baseMass = part.mass;

            if (SimManager.logOutput)
                MonoBehaviour.print((isNoPhysics ? "Ignoring" : "Using") + " part.mass of " + part.mass);

            foreach (PartResource resource in part.Resources)
            {
                // Make sure it isn't NaN as this messes up the part mass and hence most of the values
                // This can happen if a resource capacity is 0 and tweakable
                if (!Double.IsNaN(resource.amount))
                {
                    if (SimManager.logOutput)
                        MonoBehaviour.print(resource.resourceName + " = " + resource.amount);

                    resources.Add(resource.info.id, resource.amount);
                    resourceFlowStates.Add(resource.info.id, resource.flowState ? 1 : 0);
                }
                else
                {
                    MonoBehaviour.print(resource.resourceName + " is NaN. Skipping.");
                }
            }

            startMass = GetMass();

            hasVessel = (part.vessel != null);
            isLanded = hasVessel && part.vessel.Landed;
            if (hasVessel)
            {
                vesselName = part.vessel.vesselName;
                vesselType = part.vesselType;
            }
            initialVesselName = part.initialVesselName;

            hasMultiModeEngine = part.HasModule<MultiModeEngine>();
            hasModuleEnginesFX = part.HasModule<ModuleEnginesFX>();
            hasModuleEngines = part.HasModule<ModuleEngines>();

            isEngine = hasMultiModeEngine || hasModuleEnginesFX || hasModuleEngines;

            if (SimManager.logOutput)
                MonoBehaviour.print("Created " + name + ". Decoupled in stage " + decoupledInStage);
        }
示例#3
0
        public PartSim(Part thePart, int id, double atmosphere, LogMsg log)
        {
            part   = thePart;
            partId = id;
            name   = part.partInfo.name;

            if (log != null)
            {
                log.buf.AppendLine("Create PartSim for " + name);
            }

            parent             = null;
            parentAttach       = part.attachMode;
            fuelCrossFeed      = part.fuelCrossFeed;
            noCrossFeedNodeKey = part.NoCrossFeedNodeKey;
            decoupledInStage   = DecoupledInStage(part);
            isFuelLine         = part is FuelLine;
            isFuelTank         = part is FuelTank;
            isSepratron        = IsSepratron();
            inverseStage       = part.inverseStage;
            //MonoBehaviour.print("inverseStage = " + inverseStage);

            cost = part.partInfo.cost;
            foreach (PartResource resource in part.Resources)
            {
                cost -= (float)((resource.maxAmount - resource.amount) * resource.info.unitCost);
            }

            // Work out if the part should have no physical significance
            isNoPhysics = part.HasModule <LaunchClamp>() ||
                          part.physicalSignificance == Part.PhysicalSignificance.NONE ||
                          part.PhysicsSignificance == 1;

            if (!isNoPhysics)
            {
                baseMass = part.mass;
            }

            if (SimManager.logOutput)
            {
                MonoBehaviour.print((isNoPhysics ? "Ignoring" : "Using") + " part.mass of " + part.mass);
            }

            foreach (PartResource resource in part.Resources)
            {
                // Make sure it isn't NaN as this messes up the part mass and hence most of the values
                // This can happen if a resource capacity is 0 and tweakable
                if (!Double.IsNaN(resource.amount))
                {
                    if (SimManager.logOutput)
                    {
                        MonoBehaviour.print(resource.resourceName + " = " + resource.amount);
                    }

                    resources.Add(resource.info.id, resource.amount);
                    resourceFlowStates.Add(resource.info.id, resource.flowState ? 1 : 0);
                }
                else
                {
                    MonoBehaviour.print(resource.resourceName + " is NaN. Skipping.");
                }
            }

            startMass = GetMass();

            hasVessel = (part.vessel != null);
            isLanded  = hasVessel && part.vessel.Landed;
            if (hasVessel)
            {
                vesselName = part.vessel.vesselName;
                vesselType = part.vesselType;
            }
            initialVesselName = part.initialVesselName;

            hasMultiModeEngine = part.HasModule <MultiModeEngine>();
            hasModuleEnginesFX = part.HasModule <ModuleEnginesFX>();
            hasModuleEngines   = part.HasModule <ModuleEngines>();

            isEngine = hasMultiModeEngine || hasModuleEnginesFX || hasModuleEngines;

            if (SimManager.logOutput)
            {
                MonoBehaviour.print("Created " + name + ". Decoupled in stage " + decoupledInStage);
            }
        }