Example #1
0
    //Called from GenerateResources. Generates a random assortment of moons to orbit this planet
    private void GenerateMoons()
    {
        //Initialize the new list of moons so that it's empty
        this.moons = new List <GameObject>();

        //Created a scalar that uses the massMoonCoorilation curve to skew the random value
        Interpolator scalar = new Interpolator(this.massMoonCoorilation);

        scalar.AddTime(Random.value);

        //Uses the scalar, min number of moons, and max number of moons to find out how many this planet will have
        int numMoons = Mathf.RoundToInt(scalar.GetProgress() * (this.moonNumberRanges.y - this.moonNumberRanges.x) - this.moonNumberRanges.x);

        //Loop to generate each moon
        for (int i = 0; i < numMoons; ++i)
        {
            //Created a new game object to store the instance of the created moon
            GameObject newMoon = null;

            //Finds the orbit distance of the new moon
            float radius = this.GetMoonRadius();

            //If the radius is invalid, we stop generating moons
            if (radius <= 0)
            {
                break;
            }

            //Random value from 0 to 1
            float rand = Random.value;

            //Loop through each moon prefab probability to check against the random value
            for (int m = 0; m < this.moonProbabilities.Count; ++m)
            {
                //If the current moon probability is higher than our rand, that prefab is created
                if (this.moonProbabilities[m] >= rand)
                {
                    newMoon = GameObject.Instantiate(this.moonTypes[m], this.transform.localPosition, this.transform.rotation) as GameObject;
                    break;
                }
                //If this is the last moon probability in the list, it's spawned by default
                else if ((m + 1) >= this.moonProbabilities.Count)
                {
                    newMoon = GameObject.Instantiate(this.moonTypes[m], this.transform.localPosition, this.transform.rotation) as GameObject;
                }
            }

            //creates a random orbit time
            //NOTE: The values used are for testing
            float orbitTime = Random.Range(45, 300);

            //Adds the moon to this planet's list and parents it at the local center
            this.moons.Add(newMoon);
            newMoon.transform.parent        = this.displayObject.transform;
            newMoon.transform.localPosition = new Vector3(0, 0, 0);

            //Generates the moon's stats
            newMoon.GetComponent <Moon>().GenerateStats(new Vector3(radius, 0, radius), orbitTime, this.spinClockwise);
        }
    }
Example #2
0
    //Function to be called as soon as this object is spawned
    public virtual void GenerateStats(bool spinClockwise_ = true)
    {
        //Sets the direction of the revolution
        this.spinClockwise = spinClockwise_;

        //Temp float used to determine the revolution speed
        float spinValue = 1;

        if (!this.spinClockwise)
        {
            spinValue = -1;
        }

        //Makes this planet rotate with its spin
        this.revolutionSpeed = Random.Range(this.revSpeedRange.x, this.revSpeedRange.y) * spinValue;

        //Creating an interpolator and random value that is used as the baseline for our mass and radius
        float        rand   = Random.value;
        Interpolator scalar = new Interpolator(this.massDistribution);

        scalar.AddTime(rand);

        //Sets the Mass based on the scalar's distribution
        this.mass = Mathf.Round((scalar.GetProgress() * (this.massRange.y - this.massRange.x) + this.massRange.x) * 100) / 100;

        //Sets the mass based on the same random value as the mass
        scalar.ease = this.massRadiusCoorilation;
        this.radius = Mathf.Round((scalar.GetProgress() * (this.radiusRange.y - this.radiusRange.x) + this.radiusRange.x) * 100) / 100;

        //Creates a new random value for the scalar to determine the spin
        rand = Random.value;
        scalar.ResetTime();
        scalar.AddTime(rand);

        this.revolutionSpeed = scalar.GetProgress() * (this.revSpeedRange.y - this.revSpeedRange.x) + this.revSpeedRange.x;
    }
    //Function called from GeneratePlanets. Returns a radius (float) to spawn a new planet at. Returns 0 if a valid radius isn't found.
    private float GetPlanetRadius()
    {
        //The radius that is returned by the end of the function
        float returnRadius = 0;

        //Create a sine-in scalar that will weight more of the planets to spawn closer to the star
        Interpolator scalar = new Interpolator(EaseType.SineIn);

        //Counter to track the number of times we've attempted to generate a valid radius
        int endlessCount = 0;

        for (int i = 0; i < 1; ++i)
        {
            //Gives the scalar a random value between 0 and 1 to give us a percentage that's weighted closer to 0 (closer to the star)
            scalar.ResetTime();
            scalar.AddTime(Random.value);

            //Calculates the radius of the planet using the min/max radii (hot and cold) and the scalar's weighted percentage
            returnRadius = scalar.GetProgress() * (this.iceZoneRadius - this.hotZoneRadius) + this.hotZoneRadius;

            //Loops through each planet to see if its orbit is within collision distance
            for (int p = 0; p < this.planets.Count; ++p)
            {
                float check1 = Mathf.Abs(this.planets[p].GetComponent <Planet>().orbitDimensions.x - returnRadius);

                //If we find a planet within collision distance of the new radius, the loop is reset to try again
                if (check1 <= this.collisionDistance)
                {
                    i             = -1;
                    endlessCount += 1;

                    //If there have been 20 failed attempts to generate a new radius, the loop is broken and 0 is returned
                    if (endlessCount > 20)
                    {
                        i = 1;
                        return(0);
                    }
                    break;
                }
            }
        }

        return(returnRadius);
    }
Example #4
0
    //Function called externally from InventoryButton.cs to make a character learn this skill
    public void CharacterUseTome(Character charToLearn_)
    {
        //Int to hold the character's skill level that we'll improve
        int currentSkillLevel = this.GetCurrentSkillLevel(charToLearn_);

        //Int to hold what the new skill level will be
        int improvedSkillLevel = currentSkillLevel;

        //Looping through each progression curve
        for (int c = 0; c < this.progressionCurves.Count; ++c)
        {
            SkillTomeProgression curve = this.progressionCurves[c];

            //Checking to see if the player's current skill level is between the ranges for the curve
            if (currentSkillLevel >= curve.skillRangeMin && currentSkillLevel <= curve.skillRangeMax)
            {
                //Switch statement to allocate points based on the curve type
                switch (curve.progressionCurve)
                {
                case SkillTomeProgression.progressionCurves.Linear:
                    //Getting the percent that the player is between the curve range min/max
                    float percentL = (1f * (currentSkillLevel - curve.skillRangeMin)) /
                                     (1f * (curve.skillRangeMax - curve.skillRangeMin));
                    //Finding the new value between the new skill min/max
                    float newSkillF = (curve.newSkillMax - curve.newSkillMin) * percentL;
                    improvedSkillLevel = curve.newSkillMin + Mathf.RoundToInt(newSkillF);
                    break;

                case SkillTomeProgression.progressionCurves.SineIn:
                    //Getting the percent that the player is between the curve range min/max
                    float percentSI = (1f * (currentSkillLevel - curve.skillRangeMin)) /
                                      (1f * (curve.skillRangeMax - curve.skillRangeMin));
                    //Creating a new interpolator to get the sine in interp using the percent SI
                    Interpolator siInterp = new Interpolator();
                    siInterp.ease = EaseType.SineIn;
                    siInterp.SetDuration(1);
                    siInterp.AddTime(percentSI);
                    //Finding the new value between the new skill min/max using the interpolated percent
                    float newSkillSI = (curve.newSkillMax - curve.newSkillMin) * siInterp.GetProgress();
                    improvedSkillLevel = curve.newSkillMin + Mathf.RoundToInt(newSkillSI);
                    break;

                case SkillTomeProgression.progressionCurves.SineOut:
                    //Getting the percent that the player is between the curve range min/max
                    float percentSO = (1f * (currentSkillLevel - curve.skillRangeMin)) /
                                      (1f * (curve.skillRangeMax - curve.skillRangeMin));
                    //Creating a new interpolator to get the sine in interp using the percent SO
                    Interpolator soInterp = new Interpolator();
                    soInterp.ease = EaseType.SineOut;
                    soInterp.SetDuration(1);
                    soInterp.AddTime(percentSO);
                    //Finding the new value between the new skill min/max using the interpolated percent
                    float newSkillSO = (curve.newSkillMax - curve.newSkillMin) * soInterp.GetProgress();
                    improvedSkillLevel = curve.newSkillMin + Mathf.RoundToInt(newSkillSO);
                    break;

                case SkillTomeProgression.progressionCurves.UpToMax:
                    //Setting the skill level to the max
                    improvedSkillLevel = curve.newSkillMax;
                    break;
                }

                //Breaking the loop so we don't have to bother with the other curves
                break;
            }
        }

        //Setting the new character skill value
        this.SetImprovedSkillLevel(charToLearn_, improvedSkillLevel - currentSkillLevel);
    }
Example #5
0
    /* Function called from SolarSystem.cs (GenerateStar function)
     * Override of the SolarBody parent class' GenerateStats function since stars will have their own unique stats*/
    public override void GenerateStats(bool spinClockwise_ = true)
    {
        //Calls the GenerateStats base function to set the spin direction
        base.GenerateStats(spinClockwise_);

        //Generating a random value between 0 and 1 to use in our scalar
        float rand = Random.value;

        //The new scalar uses the curve designated with TemperatureDistribution and has a time length of 1
        Interpolator scaler = new Interpolator(this.temperatureDistribution, 1);

        scaler.AddTime(rand);

        //Finds the surface temperature based on the temperature distribution
        this.surfaceTemp = Mathf.RoundToInt((scaler.GetProgress() * (this.tempRange.y - this.tempRange.x) + this.tempRange.x) / 100) * 100;

        /*Finds the luminosity based off the area, the temperature to the 4th power, and the Stefan-Bolzmann constant
         * NOTE: the radius used is a float variable inherited from the SolarBody parent class that's generated in base.GenerateStats */
        float area       = (4 * Mathf.PI * (this.radius * this.radius));
        float SBConstant = 5.670367f * Mathf.Pow(10f, -8);
        float tempQuad   = Mathf.Pow(this.surfaceTemp, 4);

        this.luminosity = area * SBConstant * tempQuad;

        //Determines the display object's color based on the temperature distribution. Uses the Mesh Renderer if there's no Sprite Renderer component
        if (this.displayObject.GetComponent <SpriteRenderer>() != null)
        {
            this.displayObject.GetComponent <SpriteRenderer>().color = this.starColors.Evaluate(scaler.GetProgress());
        }
        else if (this.displayObject.GetComponent <MeshRenderer>() != null)
        {
            this.displayObject.GetComponent <MeshRenderer>().materials[0].color = this.starColors.Evaluate(scaler.GetProgress());
        }


        //If this star is at or below the smallest radius, it's game object is set to the smallest scale in the StarScaleRange
        if (this.radius <= this.starRadiusRange.x)
        {
            this.displayObject.transform.localScale = new Vector3(this.starScaleRange.x, this.starScaleRange.x, this.starScaleRange.x);
        }
        //If it's between the smallest and middle radius, finds the scale to set it at based on the coorilation
        else if (this.radius > this.starRadiusRange.x && this.radius <= this.starRadiusRange.y)
        {
            Interpolator scalar  = new Interpolator(this.lowMidCoorilation);
            float        percent = (this.radius - this.starRadiusRange.x) / (this.starRadiusRange.y - this.starRadiusRange.x);
            scalar.AddTime(percent);

            float newScale = scalar.GetProgress() * (this.starScaleRange.y - this.starScaleRange.x) + this.starScaleRange.x;

            this.displayObject.transform.localScale = new Vector3(newScale, newScale, newScale);
        }
        //If it's between the middle radius and the max radius, we find the scale to set it at based on the coorilation
        else if (this.radius > this.starRadiusRange.y && this.radius <= this.starRadiusRange.z)
        {
            Interpolator scalar  = new Interpolator(this.midMaxCoorilation);
            float        percent = (this.radius - this.starRadiusRange.y) / (this.starRadiusRange.z - this.starRadiusRange.y);
            scalar.AddTime(percent);

            float newScale = scalar.GetProgress() * (this.starScaleRange.z - this.starScaleRange.y) + this.starScaleRange.y;

            this.displayObject.transform.localScale = new Vector3(newScale, newScale, newScale);
        }
        //Otherwise the radius is at or above the max radius, so it's set to the largest scale in the StarScaleRange
        else
        {
            this.displayObject.transform.localScale = new Vector3(this.starScaleRange.z, this.starScaleRange.z, this.starScaleRange.z);
        }
    }