Dubwise56 / Rimatomics

Nuclear power | Energy weapons | Nuclear weapons
41 stars 15 forks source link

Sound rework for turbine & transformer #36

Open kumpuu opened 1 year ago

kumpuu commented 1 year ago

Both were not even audible to me before... They get a bit louder with increasing load, and the turbine also changes in pitch. It sounds really cool if I may say so! turbine.ogg is actually from a real nuclear power plant in sweden if you can believe it.

Some code changes were required, so I figured out how to use dnSpy. I manually copied this, hope I didn't forget anything.

Rimatomics.Turbine
    public void StartWickSustainer()
    {
        SoundInfo info = SoundInfo.InMap(this, MaintenanceType.PerTick);
        this.wickSustainer = SoundDef.Named("Turbine").TrySpawnSustainer(info);
    }

    public override void Tick()
    {
        ...
            this.RPM = Mathf.SmoothDamp(this.RPM, target, ref this.SpinVelocity, 2f, 100f, 0.0166f); //changed smooth time to 2 because it sounds better
            this.powerOutput = this.GenerationCapacity * this.RPM;
            if (this.RPM > 0.01f)
            {
                if (this.wickSustainer == null)
                {
                    this.StartWickSustainer();
                    return;
                }
                if (this.wickSustainer.Ended)
                {
                    this.StartWickSustainer();
                    return;
                }
                this.wickSustainer.info.volumeFactor = Mathf.Lerp(1f, 1.35f, this.RPM);
                this.wickSustainer.info.pitchFactor = Mathf.Lerp(0.6f, 1.3f, this.RPM);
                this.wickSustainer.Maintain();
        }
    }

Rimatomics.Transformer
    public override void Tick()
    {
        ...
        if (this.power.PowerOutput > 5000f)
        {
            if (this.humSustainer == null)
            {
                this.StartHumSustainer();
            }
            else if (this.humSustainer.Ended)
            {
                this.StartHumSustainer();
            }
            else
            {
                this.humSustainer.info.volumeFactor = Mathf.Lerp(0.5f, 1.6f, this.power.PowerOutput / this.MaxCap);
                this.humSustainer.Maintain();
            }
        }
        ...
    }

P.S: Tested in 1.3