public override TerraFlux GetPowerGeneration(int ticks)
        {
            /*  Notes about wind speed:
             *
             *  Main.windSpeed       | The current wind speed.  Always tries to increment/decrement towards Main.windSpeedSet by a
             *                         factor of `0.001f * Main.dayRate` per tick
             *
             *  Main.windSpeedSet    | The target wind speed.  Set to Main.windSpeedTemp when Main.weatherCounter is <= 0.  Value is
             *                         set to `genRand.Next(-100, 101) * 0.01f` on world load/generation.
             *
             *  Main.windSpeedSpeed  | The rate at which Main.windSpeedTemp is changed.  Starts at 0, then is incremented by
             *                         `rand.Next(-10, 11) * 0.0001f` every tick.  Value is clamped to +/- 0.002f
             *
             *  Main.windSpeedTemp   | The next value that Main.windSpeedSet will be set to.  Modified by Main.windSpeedSpeed.
             *                         If it's currently raining, then this variable is modified by Main.windSpeedSpeed * 2 instead.
             *                         Value is clamped to +/- `(0.3f + 0.5f * Main.cloudAlpha)`
             *
             *  Main.weatherCounter  | The timer used for modifying Main.windSpeedSet and also sending net messages for syncing
             *                         world data.  It is decremented by Main.dayRate every tick.  Value is initialized to
             *                         `rand.Next(3600, 18000)` -- when Main.windSpeedSet is set -- or `genRand.Next(3600, 18000)`
             *                         -- during worldgen.
             *
             *  Weathe Radio Display | Displayed wind speed is `Math.Abs(Main.windSpeed) * 100`
             */

            TerraFlux flux = new TerraFlux(0f);

            float realWind = Math.Abs(Main.windSpeed) * 100;

            //Flux = 1TF/t multiplied by a factor of Wind Speed / 28mph
            float tfPerTick = 1f;

            flux += tfPerTick * realWind / 28f;
            flux *= 0.333f;

            //Wind turbine is in a sandstorm/blizzard?
            //Sandstorm: Multiply the generation by 1.15x and add a flat 0.5TF/t increase
            //Blizzard/Raining: Multiply the generation by 1.085x and add a flat 0.2TF/t increase
            if (sandstormBoost)
            {
                flux *= 1.15f;
            }
            if (rainBoost)
            {
                flux *= 1.085f;
            }

            if (sandstormBoost)
            {
                flux += 0.5f;
            }
            if (rainBoost)
            {
                flux += 0.2f;
            }

            flux *= ticks;

            return(flux);
        }
示例#2
0
        public override bool UpdateReaction()
        {
            spinTimer++;

            TerraFlux flux = GetPowerGeneration(1);

            ImportFlux(ref flux);

            //Prevent additional fuel from being used until the flux has been used enough
            if (flux > new TerraFlux(0f))
            {
                return(false);
            }

            //Burn one "fuel" item every 30 seconds
            fuelLeft        -= 1f / 30f / 60f;
            ReactionProgress = (1f - fuelLeft) * 100f;

            if (fuelLeft <= 0)
            {
                ReactionProgress = 100f;
            }

            return(fuelLeft <= 0);
        }
        internal bool CheckFluxRequirement(TerraFlux amount, bool use = true)
        {
            if (StoredFlux < amount)
            {
                return(false);
            }

            if (use)
            {
                StoredFlux -= amount;
            }

            return(true);
        }
 /// <summary>
 /// Adds the incoming <paramref name="flux"/> to this machine's flux pool.  Any excess <paramref name="flux"/> is left in the parameter for the network to collect.
 /// </summary>
 /// <param name="flux">The incoming Terra Flux power</param>
 public void ImportFlux(ref TerraFlux flux)
 {
     if (flux + StoredFlux > FluxCap)
     {
         TerraFlux old = StoredFlux;
         StoredFlux = FluxCap;
         flux      -= StoredFlux - old;
     }
     else
     {
         StoredFlux += flux;
         flux        = new TerraFlux(0f);
     }
 }
示例#5
0
        /// <summary>
        /// Attempts to send the <paramref name="flux"/> to a connected <seealso cref="WireNetwork"/>. The flux is split among all connected networks.
        /// </summary>
        /// <param name="flux"></param>
        public void ExportFlux(WireNetwork network)
        {
            TerraFlux flux = new TerraFlux(Math.Min((float)StoredFlux, (float)ExportRate));

            //Ran out of TF
            if ((float)flux <= 0)
            {
                return;
            }

            TerraFlux send = flux / NetworkCollection.GetWireNetworksConnectedTo(this).Count;

            network.ImportFlux(this, ref send);

            if ((float)send > 0)
            {
                ImportFlux(ref send);
            }
        }
示例#6
0
        public override TerraFlux GetPowerGeneration(int ticks)
        {
            TerraFlux flux;

            if (fuelLeft <= 0)
            {
                return(new TerraFlux(0f));
            }

            Item fuel = cachedFuelItem;

            //The buffs "Well Fed" and "Tipsy" generate power based on the initial buff time
            //The Coal item generates 12 TF/s
            //"Wood"en items generate 8TF/s
            string name = Lang.GetItemNameValue(fuel.type);

            if (fuel.buffType == BuffID.WellFed)
            {
                flux = new TerraFlux(10f * fuel.buffTime / (15 * 3600) / 60f);
            }
            else if (fuel.buffType == BuffID.Tipsy)
            {
                flux = new TerraFlux(5f * fuel.buffTime / (5 * 3600) / 60f);
            }
            else if (fuel.type == ModContent.ItemType <Coal>())
            {
                flux = new TerraFlux(12f / 60f);
            }
            else if (name.Contains("Wood") || name.Contains("wood"))
            {
                flux = new TerraFlux(8f / 60f);
            }
            else
            {
                flux = new TerraFlux(0f);
            }

            return(flux * ticks);
        }
示例#7
0
        public override TerraFlux GetPowerGeneration(int ticks)
        {
            if (!Main.dayTime)
            {
                return(new TerraFlux(0f));
            }

            //Base rate: 40 TF/s
            TerraFlux flux = new TerraFlux(40f / 60f);

            //Power generation is at max when it's noon
            float factor = (fullDay - (float)Math.Abs(fullDay / 2 - Main.time)) / fullDay;

            if (eclipseReduce)
            {
                //Eclipe reduces power gen
                factor *= 0.06f;
            }

            if (rainReduce)
            {
                //Rain blockage is dependent on wind speed
                //Get a factor of (current speed) / 28mph
                float realWind = Math.Abs(Main.windSpeed) * 100;
                float reduce   = 0.12f * realWind / 28f;

                if (reduce > 0.5f)
                {
                    reduce = 0.5f;
                }

                factor *= 1f - reduce;
            }

            return(flux * factor * ticks);
        }
        public override void ReactionComplete()
        {
            TerraFlux flux = GetPowerGeneration(ticks: 1);

            ImportFlux(ref flux);
        }
 public override void ExtraLoad(TagCompound tag)
 {
     StoredFlux = new TerraFlux(tag.GetFloat("flux"));
 }