Exemplo n.º 1
0
    public void ApplyDamage(float amount) // used by InfiniteDice's damage code. 0f is broken, 1f is OK
    {
        partHealth = amount;
        Log.info("=== FSwing damage set to {0} ===", amount);
        ctrlSurfaceRange = originalCtrlSurfaceRange * amount;
        Log.info("=== FSwing range now {0} ===", ctrlSurfaceRange);

        if (amount >= 1f)
        {
            status = "Undamaged";
        }
        else if (amount > 0.5f)
        {
            status = "Damaged";
        }
        else
        {
            status = "Broken";
            jammed = true;
        }

        if (showTweakables)
        {
            Log.info("FSwing - setting fields to {0}", jammed);
            Fields["status"].guiActive        = (amount < 1f);
            Fields["pitchResponse"].guiActive = !jammed;
            Fields["rollResponse"].guiActive  = !jammed;
            Fields["yawResponse"].guiActive   = !jammed;
            Fields["flapResponse"].guiActive  = !jammed;
        }
    }
Exemplo n.º 2
0
    public override void OnStart(PartModule.StartState state)
    {
        FARActive = AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name.Equals("FerramAerospaceResearch", StringComparison.InvariantCultureIgnoreCase));
        // This line breaks the plugin :(
        if (FARActive)
        {
            this.enabled = false;
        }

        if (liftTransformName == string.Empty)
        {
            liftTransform = part.transform;
        }
        else
        {
            liftTransform = part.FindModelTransform(liftTransformName);
        }

        if (liftTransform == null)
        {
            Log.info("FSliftSurface: Can't find lift transform {0}", liftTransformName);
        }
        //if (moduleID == 0)
        //{
        liftSurfaces = part.GetComponents <FSliftSurface>().ToList();
        //liftSurfaces.Add(this); // uhm, what?
        //}
    }
Exemplo n.º 3
0
    private void updateEngineList()
    {
        Log.dbg("updating engine list");
        engines.Clear();
        foreach (Part p in vessel.parts)
        {
            ModuleEngines engine = p.GetComponent <ModuleEngines>();
            if (engine != null)
            {
                engines.Add(engine);
            }
        }
        oldPartCount = vessel.parts.Count;
        if (selectedEngineNumber >= engines.Count)
        {
            selectedEngineNumber = 0;
            engineSelectionDial.updateNumber(0);
        }

        if (engines.Count > 0)
        {
            hasEngines = true;
        }
        else
        {
            hasEngines = false;
        }
    }
Exemplo n.º 4
0
    public void cycleForceAxis()
    {
        switch (forceAxis)
        {
        case "left":
            forceAxis = "right";
            break;

        case "right":
            forceAxis = "up";
            break;

        case "up":
            forceAxis = "down";
            break;

        case "down":
            forceAxis = "forward";
            break;

        case "forward":
            forceAxis = "back";
            break;

        case "back":
            forceAxis = "left";
            break;
        }

        Log.info("FSrudder forceAxis: {0}", forceAxis);
    }
Exemplo n.º 5
0
    public FloatCurve ProcessNodeAsFloatCurve(ConfigNode node)
    {
        FloatCurve resultCurve = new FloatCurve();

        ConfigNode[] moduleNodeArray = node.GetNodes(nodeName);
        debugMessage("ProcessNodeAsFloatCurve: moduleNodeArray.length " + moduleNodeArray.Length);
        for (int k = 0; k < moduleNodeArray.Length; k++)
        {
            debugMessage("found node");
            string[] valueArray = moduleNodeArray[k].GetValues(valueName);
            debugMessage("found " + valueArray.Length + " values");
            for (int l = 0; l < valueArray.Length; l++)
            {
                string[] splitString = valueArray[l].Split(' ');
                try
                {
                    Vector2 v2 = new Vector2(float.Parse(splitString[0]), float.Parse(splitString[1]));
                    resultCurve.Add(v2.x, v2.y, 0, 0);
                }
                catch
                {
                    Log.dbg("Error parsing vector2");
                }
            }
        }
        return(resultCurve);
    }
Exemplo n.º 6
0
 public void decreaseRange()
 {
     range -= 1f;
     if (range < 0f)
     {
         range = 0f;
     }
     Log.info("FSrudder range: {0}", range);
 }
Exemplo n.º 7
0
 public void increaseRange()
 {
     range += 1f;
     if (range > 60f)
     {
         range = 60f;
     }
     Log.info("FSrudder range: {0}", range);
 }
Exemplo n.º 8
0
 public void decreasePower()
 {
     power -= 0.01f;
     if (power < 0f)
     {
         power = 0f;
     }
     Log.info("FSrudder power: {0}", power);
 }
Exemplo n.º 9
0
 private void fireScreechEffect(int wheelNumber, float deltaRPM)
 {
     fxLevel  = Mathf.Clamp((float)vessel.horizontalSrfSpeed, 0f, 40f) / 40f;
     fxLevel *= deltaRPM / 200f;
     part.Effect("touchdown", fxLevel);
     Log.dbg("wheels: {0}, current: {1}", wheelList.wheels.Count, wheelNumber);
     wheelList.wheels[wheelNumber].screechCountdown = 0.5f;
     Log.dbg("Distance {0}", Vector3.Distance(vessel.ReferenceTransform.position, wheelList.wheels[wheelNumber].smokeFX.gameObject.transform.position));
     // TODO play one shot audio
 }
Exemplo n.º 10
0
 public void toggleRequiresWaterContact()
 {
     if (requiresWaterContact == 0)
     {
         requiresWaterContact = 1;
     }
     else
     {
         requiresWaterContact = 0;
     }
     Log.info("FSrudder req. water contact: {0}", requiresWaterContact);
 }
Exemplo n.º 11
0
    public override void OnUpdate()
    {
        if (!HighLogic.LoadedSceneIsFlight)
        {
            return;
        }
        if (!invertSet) //run only the first time the craft is loaded
        {
            //check if the part is on the left or right side of the ship
            if (Vector3.Dot(objectTransform.position.normalized, vessel.ReferenceTransform.right) < 0) // below 0 means the engine is on the left side of the craft
            {
                invertMotion = true;
                Log.dbg("FSanimateManually: Inverting left side Gear");
            }
            invertSet = true;
        }

        if (animationExists && objectExists)
        {
            //check the animation time, normalize
            currentTime = anim[animationName].normalizedTime;
            float useTime = currentTime;
            if (currentTime != 0f)
            {
                animatingForward = (currentTime > oldTime);
            }
            if (animatingForward && currentTime == 0f)
            {
                useTime = 1f;
            }

            //set the rotation if the animation has progressed
            //if (useTime != oldTime)
            //{
            if (invertMotion && allowInvert == 1)
            {
                //add translation when needed
                objectTransform.localRotation = Quaternion.Lerp(endTransformInverted.localRotation, originalTransform.localRotation, useTime);
            }
            else
            {
                //add translation when needed
                objectTransform.localRotation = Quaternion.Slerp(endTransform.localRotation, originalTransform.localRotation, useTime);
            }
            //}

            oldTime = currentTime;
        }
        else
        {
            Log.warn("FSanimateManually: Error, missing object {0}: {1} / missing animation {2}: {3}" + targetObject, objectExists, animationName, animationExists);
        }
    }
Exemplo n.º 12
0
 public void addWheel(string wheelName)
 {
     if (wheelName != string.Empty)
     {
         Transform newWheel = base.internalProp.FindModelTransform(wheelName);
         if (newWheel != null)
         {
             analogCounter.wheels.Add(newWheel);
         }
         else
         {
             Log.info("FSaltimeterCounter: Could not find dial wheel {0}", wheelName);
         }
     }
 }
Exemplo n.º 13
0
    public void Start()
    {
        addWheel(wheel0);
        addWheel(wheel1);
        addWheel(wheel2);
        addWheel(wheel3);
        addWheel(wheel4);
        addWheel(wheel5);
        addWheel(wheel6);
        addWheel(wheel7);
        addWheel(wheel8);
        addWheel(wheel9);

        analogCounter.rotationAxis    = rotationAxis;
        analogCounter.defaultRotation = defaultRotation;
        Log.dbg("altimeter Counter list: {0}", analogCounter.wheels.Count);
    }
Exemplo n.º 14
0
    public void Start()
    {
        newTex = new RenderTexture(256, 256, 24);
        newTex.isPowerOfTwo = true;
        newTex.Create();
        newMat = new Material(Shader.Find("Diffuse"));
        //newMat = new Material(Shader.Find("KSP/Emissive/Diffuse"));
        //newMat = TVplaneObject.GetComponent<Renderer>().material;
        //newMat.CopyPropertiesFromMaterial(TVplaneObject.GetComponent<Renderer>().material);
        newMat.SetTexture("_MainTex", newTex);

        TVplaneObject = base.internalProp.FindModelTransform(TVplaneName).gameObject;
        TVplaneObject.GetComponent <Renderer>().material = newMat;

        foreach (Part part in vessel.Parts)
        {
            Transform partTransform = part.FindModelTransform(TVcamName);
            if (partTransform != null)
            {
                TVcamTransform = partTransform.gameObject;
                Log.dbg("FS: found cam transform");
            }
            //}
        }

        if (TVcamTransform != null)
        {
            TVcam = TVcamTransform.GetComponent <Camera>();
            if (TVcam != null)
            {
                Vector3    originalPosition = TVcam.transform.position;
                Quaternion originalRotation = TVcam.transform.rotation;
                TVcam.targetTexture = newTex;
                TVcam.farClipPlane  = 40000f;
                //TVcam.cullingMask = 32771;
                TVcam.cullingMask = Camera.main.cullingMask;

                TVcam.clearFlags      = CameraClearFlags.Skybox; // CameraClearFlags.SolidColor;
                TVcam.backgroundColor = Color.magenta;
                //TVcam.transparencySortMode = TransparencySortMode.Default;
                Log.dbg("FS: found camera ");
            }
        }

        //repl = Shader.Find("Nightvision");
    }
Exemplo n.º 15
0
 private void nextEngine()
 {
     Log.dbg("next button clicked");
     if (oldPartCount != vessel.parts.Count || engines.Count < 1 || !hasEngines)
     {
         updateEngineList();
     }
     if (hasEngines)
     {
         selectedEngineNumber++;
         if (selectedEngineNumber >= engines.Count)
         {
             selectedEngineNumber = 0;
         }
         engineSelectionDial.updateNumber((float)selectedEngineNumber + 1);
         Log.dbg("selected engine: {0}, engines: {1}", selectedEngineNumber, engines.Count);
     }
 }
Exemplo n.º 16
0
    void Start()
    {
        refTransform          = new GameObject().transform;
        refTransform.parent   = part.transform;
        refTransform.rotation = Quaternion.LookRotation(vessel.ReferenceTransform.up, -vessel.ReferenceTransform.forward);
        shipHeading           = new Firespitter.ShipHeading(refTransform);

        try // overdoing the error protection a bit just because I can't be sure the renderer will be valid
        {
            Transform innerDiscTransform = base.internalProp.FindModelTransform(innerDiscName);
            if (innerDiscTransform != null)
            {
                innerDisc = innerDiscTransform.gameObject;
                discMat   = innerDisc.GetComponent <Renderer>().material;
            }
        }
        catch
        {
            Log.err("FSartificialHorizon: Can't find object, or its material: {0}", innerDiscName);
        }

        if (discMat == null)
        {
            useOffset = false;
            Log.info("FSartificialHorizon: Couldn't find disc material");
        }

        if (useOffset)
        {
            testButton         = base.internalProp.FindModelTransform(testButtonName).gameObject;
            minusButton        = base.internalProp.FindModelTransform(minusButtonName).gameObject;
            plusButton         = base.internalProp.FindModelTransform(plusButtonName).gameObject;
            testButtonHandler  = testButton.AddComponent <FSgenericButtonHandler>();
            minusButtonHandler = minusButton.AddComponent <FSgenericButtonHandler>();
            plusButtonHandler  = plusButton.AddComponent <FSgenericButtonHandler>();
            testButtonHandler.mouseDownFunction  = testCageToggle;
            minusButtonHandler.mouseDownFunction = cageMinus;
            plusButtonHandler.mouseDownFunction  = cagePlus;
        }

        needle = base.internalProp.FindModelTransform(outerRingName);
    }
Exemplo n.º 17
0
    public void Start()
    {
        if (HighLogic.LoadedSceneIsFlight)
        {
            try
            {
                button        = internalProp.FindModelTransform(buttonName).gameObject;
                buttonHandler = button.AddComponent <FSgenericButtonHandler>();
                buttonHandler.mouseDownFunction = nextEngine;
                engineSelectionDialTransform    = internalModel.FindModelTransform(engineSelectionDialName);
                engineSelectionDial             = new Firespitter.cockpit.AnalogCounter(engineSelectionDialTransform, selectionDefaultRotation, selectionRotationAxis);
            }
            catch
            {
                //useEngineSelection = false;
                Log.dbg("FStachometer: No button or dial, disabling engine selection");
            }

            RPMneedle         = internalProp.FindModelTransform(RPMneedleName);
            heatNeedle        = internalProp.FindModelTransform(heatNeedleName);
            thrustLimitNeedle = internalProp.FindModelTransform(thrustLimitNeedleName);
        }
    }
Exemplo n.º 18
0
    private float oldTime = -1; // default to -1 so that the position update is forced the firste time it's run

    public override void OnStart(PartModule.StartState state)
    {
        base.OnStart(state);
        //get the starting rotations
        objectTransform      = part.FindModelTransform(targetObject);
        originalTransform    = new GameObject().transform;
        endTransform         = part.FindModelTransform(targetObject + "End");
        endTransformInverted = part.FindModelTransform(targetObject + "EndInverted");
        if (!objectTransform)
        {
            Log.warn("FSanimateManually: No such object, {0}", targetObject);
            objectExists = false;
        }
        else
        {
            Log.dbg("FSanimateManually: Found object {0}", targetObject);
            originalTransform.localPosition = objectTransform.localPosition;
            originalTransform.localRotation = objectTransform.localRotation;
            //originalTransform = objectTransform;
            objectExists = true;
        }

        Log.dbg("FSanimateManually: looking for anim");
        anim = part.GetComponentInChildren <Animation>();
        if (anim != null)
        {
            Log.dbg("FSanimateManually: Found anim {0} / {1}", animationName, anim.name);
            animationExists = true;
        }
        else
        {
            Log.warn("FSanimateManually: no animation. ");
        }
        //set the rotation based on flip when in the VAB/SPH, or at launch
        // NOPE, can't run the update code in the sph, because there is no vessel object yet, so no finding left/right
        // maybe some world coords?
    }
Exemplo n.º 19
0
 public override void OnUpdate()
 {
     base.OnUpdate();
     if (HighLogic.LoadedSceneIsFlight)
     {
         showPuppet = checkCamMode();
         if (showPuppet && checkSeat)
         {
             seatStatus = checkSeatOccupied();
             showPuppet = seatStatus;
             if (!showOnDate)
             {
                 showPuppet = false;
             }
             if (seatStatus != oldSeatStatus)
             {
                 doUpdate = true;
             }
             oldSeatStatus = seatStatus;
             Log.dbg("seat occupied: ", checkSeatOccupied());
         }
         updatePuppetActive();
     }
 }
 public void refForward(KSPActionParam param)
 {
     Log.info("Setting vessel reference transform");
     vessel.SetReferenceTransform(part);
 }
Exemplo n.º 21
0
    public override void OnStart(PartModule.StartState state)
    {
        try
        {
            deploymentStateEnum = (DeploymentStates)Enum.Parse(typeof(DeploymentStates), deploymentState);
        }
        catch
        {
            Log.dbg("FSwheel: Could not set deployment state {0}", deploymentState);
        }

        #region animation

        anim = part.FindModelAnimators(animationName).FirstOrDefault();
        if (anim != null)
        {
            hasAnimation = true;
            anim[animationName].layer = animationLayer;
            float startAnimTime = 0f;
            if (deploymentStateEnum == DeploymentStates.Retracted)
            {
                startAnimTime = 1f;
                animSpeed     = 1f * customAnimationSpeed;
            }
            else
            {
                animSpeed = -1f * customAnimationSpeed;
            }
            anim[animationName].normalizedTime = startAnimTime;
            anim[animationName].speed          = animSpeed;
            anim.Play(animationName);
        }
        #endregion

        #region In flight
        if (HighLogic.LoadedSceneIsFlight)
        {
            #region create wheel setup
            List <WheelCollider> colliderList   = new List <WheelCollider>();
            List <Transform>     wheelMeshList  = new List <Transform>();
            List <Transform>     suspensionList = new List <Transform>();

            for (int i = 0; i < numberOfWheels; i++)
            {
                string suffix = (i + 1).ToString(); // the names used are e.g. "Wheel", "Wheel2", "Wheel3", to remain compatible with stock wheels
                if (i == 0)
                {
                    suffix = "";
                }
                Transform colliderTransform = part.FindModelTransform(wheelColliderName + suffix);
                if (colliderTransform != null)
                {
                    WheelCollider collider = colliderTransform.GetComponent <WheelCollider>();
                    if (collider != null)
                    {
                        colliderList.Add(collider);

                        Transform wheelMeshTransform = part.FindModelTransform(wheelMeshName + suffix);
                        if (wheelMeshTransform != null)
                        {
                            wheelMeshList.Add(wheelMeshTransform);
                        }
                        else
                        {
                            Log.info("FSwheel: missing wheel mesh {0}{1}", wheelMeshName, suffix);
                        }
                        Transform suspensionTransform = part.FindModelTransform(suspensionParentName + suffix);
                        if (suspensionTransform != null)
                        {
                            suspensionList.Add(suspensionTransform);
                        }
                        else
                        {
                            Log.info("FSwheel: missing suspensionParent {0}{1}", suspensionParentName, suffix);
                        }
                    }
                }
                else
                {
                    Log.info("FSwheel: missing wheel collider {0}{1}", wheelColliderName, suffix);
                }
            }

            wheelList.Create(colliderList, wheelMeshList, suspensionList);
            if (wheelList != null)
            {
                if (!wheelList.enabled)
                {
                    wheelList.enabled = true;
                }
            }

            // set the motor direction based on the first found wheelColliders orientation
            Log.dbg("FSwheel: wheelist count is {0}", wheelList.wheels.Count);
            if (wheelList.wheels.Count > 0)
            {
                Log.info("FSwheel: reversemotorset: {0}", reverseMotorSet);
                if (!reverseMotorSet)                                                                                           //run only the first time the craft is loaded
                {
                    float dot = Vector3.Dot(wheelList.wheels[0].wheelCollider.transform.forward, vessel.ReferenceTransform.up); // up is forward
                    if (dot < 0)                                                                                                // below 0 means the engine is on the left side of the craft
                    {
                        reverseMotor = true;
                        Log.dbg("FSwheel: Reversing motor, dot: {0}", dot);
                    }
                    else
                    {
                        reverseMotor = false;
                        Log.dbg("FSwheel: Motor reversing skipped, dot: {0}", dot);
                    }
                    if (motorStartsReversed)
                    {
                        reverseMotor = !reverseMotor;
                    }
                    reverseMotorSet = true;
                }
            }

            if (disableColliderWhenRetracted)
            {
                if (deploymentStateEnum == DeploymentStates.Retracted)
                {
                    wheelList.enabled = false;
                }
            }

            //friction override
            if (overrideModelFrictionValues)
            {
                wheelList.forwardStiffness       = forwardsStiffness;
                wheelList.forwardsAsymptoteSlip  = forwardsAsymptoteSlip;
                wheelList.forwardsAsymptoteValue = forwardsAsymptoteValue;
                wheelList.forwardsExtremumSlip   = forwardsExtremumSlip;
                wheelList.forwardsExtremumValue  = forwardsExtremumValue;
                wheelList.sidewaysStiffness      = sidewaysStiffness;
                wheelList.sidewaysAsymptoteSlip  = sidewaysAsymptoteSlip;
                wheelList.sidewaysAsymptoteValue = sidewaysAsymptoteValue;
                wheelList.sidewaysExtremumSlip   = sidewaysExtremumSlip;
                wheelList.sidewaysExtremumValue  = sidewaysExtremumValue;
                wheelList.updateWheelFriction();
            }

            //optionally set collider and spring values
            if ((suspensionSpring >= 0f && suspensionDamper >= 0f && suspensionTargetPosition >= 0f) || overrideModelSpringValues)
            {
                wheelList.updateSpring(suspensionSpring, suspensionDamper, suspensionTargetPosition);
            }
            if (wheelColliderRadius >= 0f)
            {
                wheelList.radius = wheelColliderRadius;
            }
            else
            {
                wheelColliderRadius = wheelList.radius;
            }
            if (wheelColliderMass >= 0f)
            {
                wheelList.mass = wheelColliderMass;
            }
            if (wheelColliderSuspensionDistance >= 0f || overrideSuspensionDistance)
            {
                wheelList.suspensionDistance = wheelColliderSuspensionDistance;
            }
            else
            {
                wheelColliderSuspensionDistance = wheelList.suspensionDistance;
            }

            #endregion

            #region GUI popup

            popup                           = new FSGUIPopup(part, "FSwheel", moduleID, FSGUIwindowID.wheel, new Rect(500f, 300f, 250f, 100f), "Wheel settings", new PopupElement("Suspension Settings:"));
            popup.useInFlight               = true;
            wheelRadiusElement              = new PopupElement("Radius", wheelColliderRadius.ToString());
            suspensionDistanceElement       = new PopupElement("Distance", wheelColliderSuspensionDistance.ToString());
            suspensionSpringElement         = new PopupElement("Spring", suspensionSpring.ToString());
            suspensionDamperElement         = new PopupElement("Damper", suspensionDamper.ToString());
            suspensionTargetPositionElement = new PopupElement("Target pos", suspensionTargetPosition.ToString());
            popup.sections[0].elements.Add(wheelRadiusElement);
            popup.sections[0].elements.Add(suspensionDistanceElement);
            popup.sections[0].elements.Add(suspensionSpringElement);
            popup.sections[0].elements.Add(suspensionDamperElement);
            popup.sections[0].elements.Add(suspensionTargetPositionElement);

            suspensionUpdateElement = new PopupElement(new PopupButton("Update", 0f, popupUpdateSuspension));
            popup.sections[0].elements.Add(suspensionUpdateElement);

            #endregion

            if (brakeEmissiveObjectName != string.Empty)
            {
                brakeEmissiveObject = part.FindModelTransform(brakeEmissiveObjectName);
            }
            setBrakeLight(brakesEngaged);

            #region set up fx
            if (useCustomParticleFX)
            {
                smokeFXtexture = GameDatabase.Instance.GetTexture(smokeFXtextureName, false);
                if (smokeFXtexture == null)
                {
                    useCustomParticleFX = false;
                }
                else
                {
                    for (int i = 0; i < wheelList.wheels.Count; i++)
                    {
                        wheelList.wheels[i].smokeFX = new Firespitter.FSparticleFX(wheelList.wheels[i].fxLocation, smokeFXtexture);
                        wheelList.wheels[i].smokeFX.AnimatorColor0 = new Color(1.0f, 1.0f, 1.0f, 0.8f);
                        wheelList.wheels[i].smokeFX.AnimatorColor1 = new Color(1.0f, 1.0f, 1.0f, 0.5f);
                        wheelList.wheels[i].smokeFX.AnimatorColor2 = new Color(1.0f, 1.0f, 1.0f, 0.2f);
                        wheelList.wheels[i].smokeFX.AnimatorColor3 = new Color(1.0f, 1.0f, 1.0f, 0.1f);
                        wheelList.wheels[i].smokeFX.AnimatorColor4 = new Color(1.0f, 1.0f, 1.0f, 0.0f);

                        wheelList.wheels[i].smokeFX.EmitterMinSize     = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMaxSize     = 0.5f;
                        wheelList.wheels[i].smokeFX.EmitterMinEnergy   = 0.1f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEnergy   = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMinEmission = 0f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEmission = 0f;
                        wheelList.wheels[i].smokeFX.AnimatorSizeGrow   = 0.1f;

                        wheelList.wheels[i].smokeFX.setupFXValues();
                    }
                }
            }

            #endregion
        }

        #endregion

        #region GUI element changes
        Events["RaiseGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["RaiseGear"].unfocusedRange     = unfocusedRange;

        Events["LowerGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["LowerGear"].unfocusedRange     = unfocusedRange;

        Events["EnableMotorEvent"].guiActive        = !motorEnabled;
        Events["DisableMotorEvent"].guiActive       = motorEnabled;
        Events["EnableMotorEvent"].guiActiveEditor  = !motorEnabled;
        Events["DisableMotorEvent"].guiActiveEditor = motorEnabled;

        Events["brakesOnEvent"].guiActive        = !brakesEngaged;
        Events["brakesOffEvent"].guiActive       = brakesEngaged;
        Events["brakesOnEvent"].guiActiveEditor  = !brakesEngaged;
        Events["brakesOffEvent"].guiActiveEditor = brakesEngaged;

        Events["EnableReverseMotorEvent"].guiActive        = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActive       = reverseMotor;
        Events["EnableReverseMotorEvent"].guiActiveEditor  = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActiveEditor = reverseMotor;

        Events["brakesOnEvent"].guiActiveUnfocused  = guiActiveUnfocused;
        Events["brakesOffEvent"].guiActiveUnfocused = guiActiveUnfocused;

        if (!hasMotor)
        {
            //Events["EnableMotorEvent"].guiActive = false;
            //Events["DisableMotorEvent"].guiActive = false;
            Events["EnableMotorEvent"].active         = false;
            Events["DisableMotorEvent"].active        = false;
            Events["EnableReverseMotorEvent"].active  = false;
            Events["DisableReverseMotorEvent"].active = false;
        }
        if (!hasAnimation)
        {
            Events["RaiseGear"].active = false;
            Events["LowerGear"].active = false;
        }
        if (debugMode)
        {
            Events["increaseFrictionEvent"].guiActive = true;
            Events["decreaseFrictionEvent"].guiActive = true;
            Events["suspensionGUIEvent"].guiActive    = true;
        }

        if (brakesLockedOn)
        {
            Events["brakesOnEvent"].guiActive           = false;
            Events["brakesOffEvent"].guiActive          = false;
            Events["brakesOnEvent"].guiActiveUnfocused  = false;
            Events["brakesOffEvent"].guiActiveUnfocused = false;
        }

        #endregion
    }
Exemplo n.º 22
0
 public void increasePower()
 {
     power += 0.01f;
     Log.info("FSrudder power: {0}", power);
 }
Exemplo n.º 23
0
    public override void OnStart(PartModule.StartState state)
    {
        debug.debugMode = debugMode;

        FARActive = AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name.Equals("FerramAerospaceResearch", StringComparison.InvariantCultureIgnoreCase));
        // This line breaks the plugin :(
        if (FARActive)
        {
            foreach (BaseField f in Fields)
            {
                f.guiActive = false;
            }
            foreach (BaseEvent e in Events)
            {
                e.active          = false;
                e.guiActive       = false;
                e.guiActiveEditor = false;
            }
            foreach (BaseAction a in Actions)
            {
                a.active = false;
            }
            this.enabled = false;
            return;
        }

        //debug.debugMessage("FSwing OnStart: " + part.name);

        #region fligth mode

        if (HighLogic.LoadedSceneIsFlight)
        {
            findTransforms(true);

            // Check if a stock wing module is present, if not, manipulate FSliftSurface stuff instead.
            if (affectStockWingModule)
            {
                Log.dbg("FSwing: getting stock wing module");
                stockWingModule = part.FindModuleImplementing <ModuleControlSurface>();
                if (stockWingModule != null)
                {
                    Log.dbg("FSwing: success");
                }
                else
                {
                    debug.debugMessage("FSwing: did not Find stock wing module");
                    affectStockWingModule = false;
                }
            }

            // get the main lift surface for the leading edge to manipulate
            if (affectStockWingModule)
            {
                useCtrlSrf = false;
            }
            else
            {
                FSliftSurface[] surfaces = part.GetComponents <FSliftSurface>();
                foreach (FSliftSurface surface in surfaces)
                {
                    if (surface.liftTransformName == leadingEdgeLiftSurface)
                    {
                        mainLift            = surface;
                        mainLiftAreaDefault = surface.wingArea;
                        Log.dbg("FSwing: Slat assigned main lift to: {0}", surface.liftTransformName);
                        break;
                    }
                }
                if (mainLift == null)
                {
                    debug.debugMessage("FSwing: leading edge missing main FSliftSurface: " + leadingEdgeLiftSurface);
                }
            }
        }
        #endregion

        #region help popup

        helpPopup = new Firespitter.info.HelpPopup("Wing setup help", helpTextInternal);

        /*helpSection = new PopupSection();
         * PopupElement helpText = new PopupElement(helpTextnternal, true);
         * helpSection.AddElement(helpText, 300f);
         * if (windowID == 0)
         *  windowID = FSGUIwindowID.getNextID();
         * helpPopup = new FSGUIPopup(part, "FSwing", 0, windowID, windowRect, "Wing setup help");
         * helpPopup.sections.Add(helpSection);
         * helpPopup.useInEditor = true;
         * helpPopup.useInFlight = true;*/

        #endregion

        originalCtrlSurfaceRange = ctrlSurfaceRange;

        if (affectStockWingModule || !showTweakables)
        {
            Fields["pitchResponse"].guiActive       = false;
            Fields["pitchResponse"].guiActiveEditor = false;
            Fields["rollResponse"].guiActive        = false;
            Fields["rollResponse"].guiActiveEditor  = false;
            Fields["yawResponse"].guiActive         = false;
            Fields["yawResponse"].guiActiveEditor   = false;
            Fields["flapResponse"].guiActive        = false;
            Fields["flapResponse"].guiActiveEditor  = false;
        }

        ApplyDamage(partHealth);
    }
Exemplo n.º 24
0
    public override void OnUpdate()
    {
        if (FARActive)
        {
            return;
        }
        #region flight
        if (HighLogic.LoadedSceneIsFlight)
        {
            if (!positionOnVesselSet) //run only the first time the craft is loaded
            {
                // test whether the part is in the front or rear of the craft
                Transform CoMTransform = new GameObject().transform;
                CoMTransform.position = vessel.CoM;
                CoMTransform.rotation = vessel.transform.rotation;
                Vector3 relativePosition = CoMTransform.InverseTransformPoint(part.transform.position);
                if (relativePosition.y < 0)
                {
                    isInFrontOfCoM = false;
                }
                else
                {
                    isInFrontOfCoM = true;
                }

                float dotRight = Vector3.Dot(part.transform.right, vessel.ReferenceTransform.right);
                if (dotRight < -0.01f && allowInvertOnLeft)
                {
                    Log.dbg("FSwing: part is on the left: {0}", relativePosition);
                    wingIsPointingLeft = true;
                }
                else
                {
                    Log.dbg("FSwing: part is on the right: {0}", relativePosition);
                    wingIsPointingLeft = false;
                }

                float dotUp = Vector3.Dot(part.transform.right, vessel.ReferenceTransform.forward); //forward is up! ugh!
                if (dotUp > 0f)
                {
                    Log.dbg("FSwing: part is on the left: {0}", relativePosition);
                    wingIsPointingUp = true;
                }
                else
                {
                    Log.dbg("FSwing: part is on the right: {0}", relativePosition);
                    wingIsPointingUp = false;
                }


                positionOnVesselSet = true;
            }

            FlightCtrlState ctrl = vessel.ctrlState;

            if (useLeadingEdge && !jammed)
            {
                if (autoDeployLeadingEdge)
                {
                    if (vessel.horizontalSrfSpeed < autoLeadingEdgeSpeed || Mathf.Abs(mainLift.AngleOfAttack) > autoLeadingEdgeAoA)
                    {
                        setLeadingEdge(true);
                    }
                    else
                    {
                        setLeadingEdge(false);
                    }
                }

                if (leadingEdgeCurrent < leadingEdgeTarget)
                {
                    leadingEdgeCurrent += leadingEdgeSpeed;
                    if (leadingEdgeCurrent > 1f)
                    {
                        leadingEdgeCurrent = 1f;
                    }
                }
                else if (leadingEdgeCurrent > leadingEdgeTarget)
                {
                    leadingEdgeCurrent -= leadingEdgeSpeed;
                    if (leadingEdgeTarget < 0f)
                    {
                        leadingEdgeCurrent = 0f;
                    }
                }
                updateLeadingEdgePosition();
                if (affectStockWingModule)
                {
                    updateDrag();
                }
            }

            if (useCtrlSrf && !jammed)
            {
                Vector4 input = new Vector4(ctrl.pitch, -ctrl.roll, ctrl.yaw, flapCurrent);
                if (wingIsPointingLeft && allowInvertOnLeft)
                {
                    input.x *= -1;
                    //input.z *= -1;
                    input.w *= -1;
                }
                if (!wingIsPointingUp)
                {
                    input.z *= -1;
                }

                float amount = (limiterMultiplier * ctrlSurfaceRange * ((input.x * pitchResponse) + (input.y * rollResponse) + (input.z * yawResponse))) + (input.w * flapResponse);
                //amount = Mathf.Clamp(ctrlSurfaceRange * ctrlSurfaceClamp.x, ctrlSurfaceRange * ctrlSurfaceClamp.y, amount);
                controlSurface.localRotation = Quaternion.Lerp(controlSurface.localRotation, Quaternion.Euler(ctrllSrfDefRot + (amount * controlSurfaceAxis)), controlRotationSpeed);
            }

            //if (useFlap)
            //{
            updateFlap();
            //}
        }
        #endregion
    }
Exemplo n.º 25
0
    public void toggleEvent()
    {
        Events["toggleEvent"].active = false; //see if this removes the button when clicking
        isAnimating = true;

        //if (startDeployed && reverseAnimation && anim[animationName].normalizedTime == 0f)
        //    anim[animationName].normalizedTime = 0.999f;

        if (reverseAnimation)
        {
            Actions["toggleAction"].guiName = startEventGUIName;
            Events["toggleEvent"].guiName   = startEventGUIName;
            if (toggleActionName != string.Empty)
            {
                Actions["toggleAction"].guiName = toggleActionName;
            }
            // Following two commented out lines (anim[animationName].speed =, and anim.Play) now taken care of in LateUpdate
            //anim[animationName].speed = -1f *  customAnimationSpeed;
            if (anim[animationName].normalizedTime == 0f || anim[animationName].normalizedTime == 1f)
            {
                anim[animationName].normalizedTime = 1f;
            }

            anim.Play(animationName);
            startDeployed = false; // to get the hangar toggle button state right
            if (startRetractEffect != string.Empty)
            {
                part.Effect(startRetractEffect);
                Log.info("start retract effect");
            }
            rampDirection = RampDirection.down;
        }
        else
        {
            Actions["toggleAction"].guiName = endEventGUIName;
            Events["toggleEvent"].guiName   = endEventGUIName;
            if (toggleActionName != string.Empty)
            {
                Actions["toggleAction"].guiName = toggleActionName;
            }
            // Following two commented out lines (anim[animationName].speed =, and anim.Play) now taken care of in LateUpdate
            //anim[animationName].speed = 1f * customAnimationSpeed;
            if (anim[animationName].normalizedTime == 0f || anim[animationName].normalizedTime == 1f)
            {
                anim[animationName].normalizedTime = 0f;
                Log.info("normalizedTime 2 ");
            }

            anim.Play(animationName);
            startDeployed = true; // to get the hangar toggle button state right
            if (startDeployEffect != string.Empty)
            {
                part.Effect(startDeployEffect);
                Log.info("start deploy effect");
            }
            rampDirection = RampDirection.up;
        }

        reverseAnimation = !reverseAnimation;
        oldspeed         = -9999f;

        //if (isOneShot)
        //{
        //    locked = true;
        //    Events["toggleEvent"].active = false;
        //}
    }
Exemplo n.º 26
0
    //
    // Process the ramping in LateUpdate
    //
    public void LateUpdate()
    {
        if (!HighLogic.LoadedSceneIsFlight && !HighLogic.LoadedSceneIsEditor)
        {
            return;
        }

        if (anim != null)
        {
            switch (rampDirection)
            {
            case RampDirection.up:
                if (ramp < 1f)
                {
                    if (ramp < 0)
                    {
                        if (reverseAnimSpeed == 0)
                        {
                            ramp = 0;
                        }
                        else
                        {
                            ramp += animationRampSpeed / reverseAnimSpeed;
                        }
                    }
                    else
                    {
                        ramp += animationRampSpeed;
                    }
                }
                if (ramp > 1f)
                {
                    ramp = 1f;
                }
                break;

            case RampDirection.down:
                if (ramp > -1f)
                {
                    if (ramp < 0)
                    {
                        if (reverseAnimSpeed != 0)
                        {
                            ramp -= animationRampSpeed / reverseAnimSpeed;
                        }
                    }
                    else
                    {
                        ramp -= animationRampSpeed;
                    }
                }
                if (ramp < -1f)
                {
                    ramp = -1f;
                    //rampDirection = RampDirection.up;
                }
                break;
            }
            if (/* reverseAnimation && */ ramp < 0)
            {
                anim[animationName].speed = 1f * customAnimationSpeed * reverseAnimSpeed * ramp;
            }
            else
            {
                anim[animationName].speed = 1f * customAnimationSpeed * ramp;
            }
            if (rampDirection == RampDirection.none)
            {
                if (!animSpeedInited)
                {
                    anim[animationName].speed = animSpeed * startAnimSpeed;
                    animSpeedInited           = true;
                    unstartedSpeed            = anim[animationName].speed;
                    ramp = startAnimSpeed;
                }
                else
                {
                    anim[animationName].speed = unstartedSpeed;
                }
            }
            Log.dbg("rampDirection: {0}   animSpeed: {1}   startAnimSpeed: {2}   anim[animationName].speed: {3}", rampDirection, animSpeed, startAnimSpeed, anim[animationName].speed);
            // I don't think that this causes a problem, to call it every time here even if the speed didn't change.  Also catches any other
            // changes
            //if ((rampDirection == RampDirection.down && anim[animationName].speed > -1) ||  rampDirection == RampDirection.up && anim[animationName].speed < 1 - ramp))
            if (oldspeed != anim[animationName].speed)
            {
                oldspeed = anim[animationName].speed;
                anim.Play(animationName);
            }
        }
    }