Example #1
0
 public void SetThrottle(Vessel.Throttle newThrottle)
 {
     this.throttle = newThrottle;
     for (int i = 0; i < this.partsManager.engineModules.Count; i++)
     {
         this.partsManager.engineModules[i].UpdateEngineThrottle(newThrottle);
     }
     if (Ref.mainVessel == this)
     {
         Ref.controller.throttleOnUI.text      = ((!this.throttle.throttleOn) ? "Off" : "On");
         Ref.controller.throttleBar.fillAmount = this.throttle.throttleRaw;
         Ref.controller.throttleColorMove.SetTargetTime((float)((!this.throttle.throttleOn) ? 0 : 1));
         float num = Mathf.Pow(this.throttle.throttleRaw, 1.6f) * 100f;
         if (num > 10f)
         {
             Ref.controller.throttlePercentUI.text = ((int)num).ToString() + "%";
         }
         else if (num >= 0.1f)
         {
             Ref.controller.throttlePercentUI.text = ((int)num).ToString() + "." + ((int)(num % 1f * 10f)).ToString() + "%";
         }
         else
         {
             Ref.controller.throttlePercentUI.text = ((num <= 0f) ? "0%" : "0.1%");
         }
     }
 }
    public void ApplyThrust(ref float totalThrust, Rigidbody2D rb2d, float xAxis, Vessel.Throttle throttle)
    {
        if (!this.engineOn.boolValue)
        {
            return;
        }
        xAxis *= (float)(this.part.orientation.x * this.part.orientation.y);
        this.nozzleMove.SetTargetTime(xAxis);
        if (!throttle.throttleOn)
        {
            return;
        }
        if (throttle.throttle == 0f)
        {
            return;
        }
        if (!this.CheckResourceSource(true))
        {
            this.ToggleEngine(false);
            return;
        }
        this.resourceSource.TakeResource(this.resourceConsuption * throttle.throttle * Time.fixedDeltaTime);
        if (this.fuelIcon.bar != null)
        {
            this.fuelIcon.bar.fillAmount = this.resourceSource.resourcePercent;
        }
        float num = this.thrust * throttle.throttle;

        totalThrust += num;
        Vector2 a     = Quaternion.Euler(0f, 0f, base.transform.rotation.eulerAngles.z) * new Vector2(0f, (float)this.part.orientation.y);
        Vector2 force = a * num;
        Vector2 a2    = (base.transform.localPosition + this.part.centerOfMass * this.part.orientation) * num;

        rb2d.AddForceAtPosition(force, rb2d.GetRelativePoint(a2 / num));
        EngineModule.Flame[] array = this.flamesData;
        for (int i = 0; i < array.Length; i++)
        {
            EngineModule.Flame flame = array[i];
            flame.flame.transform.localScale = new Vector3(UnityEngine.Random.Range(flame.sizeBounds.x, flame.sizeBounds.y), UnityEngine.Random.Range(flame.sizeBounds.z, flame.sizeBounds.w), 1f);
        }
        bool flag = false;

        if (Ref.mainVesselTerrainHeight < 100.0)
        {
            RaycastHit2D hit = Physics2D.Raycast(base.transform.position, -a, this.flameLenght, this.particleCollisionMask);
            if (hit)
            {
                flag = true;
                this.deflectedParticle1.particle.transform.localPosition = new Vector3(0f, -hit.distance / 1.5f + 0.45f, 0f);
                this.deflectedParticle2.particle.transform.localPosition = new Vector3(0f, -hit.distance / 1.5f + 0.45f, 0f);
                this.deflectedParticle1.particleMain.startColor          = new Color(1f, 1f, 1f, throttle.throttleRaw * (1f - hit.distance / this.flameLenght));
                this.deflectedParticle2.particleMain.startColor          = new Color(1f, 1f, 1f, throttle.throttleRaw * (1f - hit.distance / this.flameLenght));
            }
        }
        if (this.deflectedParticle1.particle.gameObject.activeSelf != flag)
        {
            this.deflectedParticle1.particle.gameObject.SetActive(flag);
            this.deflectedParticle2.particle.gameObject.SetActive(flag);
        }
    }
    public void UpdateEngineThrottle(Vessel.Throttle throttle)
    {
        this.audioSource.volume = throttle.throttleRaw * 0.6f;
        bool  flag       = this.engineOn.boolValue && throttle.throttleOn && throttle.throttleRaw > 0f && !Ref.timeWarping;
        float targetTime = (!flag) ? 0f : throttle.throttle;

        this.throttleMove.SetTargetTime(targetTime);
        if (flag != this.audioSource.isPlaying)
        {
            if (this.audioSource.isPlaying)
            {
                this.audioSource.Stop();
            }
            else
            {
                this.audioSource.Play();
                if (Ref.mainVessel != null)
                {
                    for (int i = 0; i < Ref.mainVessel.partsManager.engineModules.Count; i++)
                    {
                        Ref.mainVessel.partsManager.engineModules[i].audioSource.time = 0f;
                    }
                }
            }
        }
    }
Example #4
0
 public VesselSave(Vessel.State state, string adress, Double3 globalPosition, Double3 globalVelocity, float rotation, float angularVelocity, Vessel.Throttle throttle, Part.Save[] parts, Part.Joint.Save[] joints, List <string> vesselArchivments)
 {
     this.globalPosition    = globalPosition;
     this.globalVelocity    = globalVelocity;
     this.rotation          = rotation;
     this.angularVelocity   = angularVelocity;
     this.adress            = adress;
     this.state             = state;
     this.throttle          = throttle;
     this.parts             = parts;
     this.joints            = joints;
     this.vesselArchivments = vesselArchivments;
 }
Example #5
0
    public void ApplyThrust(ref float totalThrust, Rigidbody2D rb2d, float xAxis, Vessel.Throttle throttle, bool mainVessel)
    {
        if (!this.engineOn.boolValue)
        {
            return;
        }
        xAxis *= (float)(this.part.orientation.x * this.part.orientation.y);
        if (this.nozzleMove != null)
        {
            this.nozzleMove.SetTargetTime(xAxis);
        }
        if (!throttle.throttleOn)
        {
            return;
        }
        if (throttle.throttle == 0f)
        {
            return;
        }
        float num = this.thrust * throttle.throttle;

        totalThrust += num;
        Vector2 a     = Quaternion.Euler(0f, 0f, base.transform.rotation.eulerAngles.z) * new Vector2(0f, (float)this.part.orientation.y);
        Vector2 force = a * num;
        Vector2 a2    = (base.transform.localPosition + this.part.centerOfMass * this.part.orientation) * num;

        rb2d.AddForceAtPosition(force, rb2d.GetRelativePoint(a2 / num));
        if (this.deflectedParticleHolder == null)
        {
            return;
        }
        bool flag = false;

        if (Ref.mainVesselTerrainHeight < 100.0)
        {
            RaycastHit2D hit = Physics2D.Raycast(base.transform.position, -a, this.flameLenght, this.particleCollisionMask);
            if (hit)
            {
                flag = true;
                this.deflectedParticle1.particle.transform.localPosition = new Vector3(0f, -hit.distance / this.deflectedParticle1.particle.transform.lossyScale.y * Mathf.Abs(this.deflectedParticle1.particle.transform.localScale.y), 0f);
                this.deflectedParticle2.particle.transform.localPosition = new Vector3(0f, -hit.distance / this.deflectedParticle2.particle.transform.lossyScale.y * Mathf.Abs(this.deflectedParticle2.particle.transform.localScale.y), 0f);
                this.deflectedParticle1.particleMain.startColor          = new Color(1f, 1f, 1f, throttle.throttleRaw * (1f - hit.distance / this.flameLenght));
                this.deflectedParticle2.particleMain.startColor          = new Color(1f, 1f, 1f, throttle.throttleRaw * (1f - hit.distance / this.flameLenght));
            }
        }
        if (this.deflectedParticle1.particle.gameObject.activeSelf != flag)
        {
            this.deflectedParticle1.particle.gameObject.SetActive(flag);
            this.deflectedParticle2.particle.gameObject.SetActive(flag);
        }
    }
Example #6
0
    public void ApplyThrustForce(float engineGimbal, Vessel.Throttle throttle, Vessel vessel)
    {
        if (Ref.mainVessel == vessel && Ref.mainVesselTerrainHeight < 20.0 && (!throttle.throttleOn || throttle.throttleRaw == 0f))
        {
            engineGimbal = 0f;
        }
        float num = 0f;

        for (int i = 0; i < this.engineModules.Count; i++)
        {
            this.engineModules[i].ApplyThrust(ref num, this.rb2d, (!this.engineModules[i].engineOn.boolValue) ? 0f : engineGimbal, throttle);
        }
        if (num == 0f)
        {
            return;
        }
        Ref.controller.cameraOffset = num * 1.5E-05f * UnityEngine.Random.insideUnitCircle;
    }
Example #7
0
    public static Vessel CreateVessel(Part startPart, Vector2 velocity, float angularVelocity, Vessel.Throttle throttle, List <string> vesselArchivments, Transform mapIconHolder)
    {
        Vessel component = UnityEngine.Object.Instantiate <Transform>(Ref.controller.vesselPrefab).GetComponent <Vessel>();

        Ref.controller.vessels.Add(component);
        component.partsManager.GetConnectedParts(startPart, component);
        component.partsManager.rb2d.velocity        = velocity;
        component.partsManager.rb2d.angularVelocity = angularVelocity;
        component.mapIcon = UnityEngine.Object.Instantiate <Transform>(Ref.map.mapVesselIconPrefab, mapIconHolder);
        Ref.map.UpdateVesselsMapIcons();
        component.SetThrottle(throttle);
        component.vesselAchievements = new List <string>(vesselArchivments);
        return(component);
    }
Example #8
0
    public List <Vessel> CreateVesselsFromParts(List <Part> unatendedParts, Vector2 velocity, float angularVecloty, Vessel.Throttle throttle, List <string> inheritedArchivments)
    {
        List <Vessel> list = new List <Vessel>();

        for (int i = 0; i < unatendedParts.Count; i++)
        {
            bool flag = unatendedParts[i] != null && unatendedParts[i].vessel == null && unatendedParts[i].gameObject.activeSelf;
            if (flag)
            {
                Vessel item = Vessel.CreateVessel(unatendedParts[i], velocity, angularVecloty, throttle, inheritedArchivments, Ref.map.mapRefs[this.loadedPlanet].holder);
                list.Add(item);
            }
        }
        return(list);
    }