예제 #1
0
	void Start ()
    {
        SetUpRNG(myNumber);
        
        base.Start();
        // Draw orbit path (same color as planet)
        orbitPath = GetComponent<LineRenderer>();

        homeStar = parentBody.GetComponent<SystemStar>();

        // Set ownership status
        if (PlayerData.instance.CheckPlanetStatus(homeStar.myNumber, planetNum) == 1)
        {
            personalOwnership = true;
            ownershipState = true;
            orbitPath.SetColors(Color.green,Color.green);
        }
        else if (PlayerData.instance.CheckPlanetStatus(homeStar.myNumber, planetNum) == 0)
        {
            personalOwnership = false;
            ownershipState = true;
            this.gameObject.GetComponent<Spacebux>().enabled = false;
            this.gameObject.GetComponent<Population>().enabled = false;
            this.gameObject.GetComponent<Power>().enabled = false;
            orbitPath.SetColors(Color.red,Color.red);
        }
        else 
        {
            personalOwnership = false;
            ownershipState = false;
            this.gameObject.GetComponent<Spacebux>().enabled = false;
            this.gameObject.GetComponent<Population>().enabled = false;
            this.gameObject.GetComponent<Power>().enabled = false;
            orbitPath.SetColors(Color.white,Color.white);
        }

	    lastResourceCollection = PlayerData.instance.GetPlanetLastCollectedTime(homeStar.myNumber, planetNum);
	    population = PlayerData.instance.GetPlanetPopulation(homeStar.myNumber, planetNum);

        // Set Color
        if (planetNum <= 2)  // hot planets generate more power, negative population rate (usually)
        {
            energyModifier = localRNG.NextGaussian(2);
            populationRate = localRNG.NextGaussian(3, 1);
            _layeredSprite.Randomize((uint)localRNG.Next(), ref localRNG, "red");
        }
        else if (planetNum > 2 & planetNum <= 5)
        {
            energyModifier = localRNG.NextGaussian(1);
            populationRate = localRNG.NextGaussian(5, 4);
            _layeredSprite.Randomize((uint) localRNG.Next(), ref localRNG, "green");
        }
        else
        {
            energyModifier = localRNG.NextGaussian(-1);
            populationRate = localRNG.NextGaussian(3, 1);
            _layeredSprite.Randomize((uint)localRNG.Next(), ref localRNG, "blue");
        }

        Debug.Log(string.Format("Created planet: {0}{1}. EnergyProduced: {2}, populationRate: {3}", 
            homeStar.myNumber, System.Convert.ToChar(64 + planetNum), Mathf.RoundToInt((float)energyModifier*homeStar.baseEnergyLevel), Mathf.RoundToInt((float)populationRate)));

        renderer = GetComponent<Renderer>();

        Size = localRNG.Next(MIN_SIZE, MAX_SIZE);


        // Set Planet Size
        transform.localScale = new Vector3(Size, Size, Size);

        // Orbit Speed is a function of distance from orbit parent (whether it be a planet or star)
        orbitSpeed = localRNG.Next(MIN_ORBIT_SPEED, MAX_ORBIT_SPEED);

        // Rotational offset
        initialRotationOffset = localRNG.Next(0, 360);

        // Randomize Location around orbit parent (for illusion of time passing)
        // Consider actually counting the amount of time the user has been away.
        transform.position = (transform.position - parentBody.transform.position).normalized * ORBIT_CONSTANT * planetNum +
                             parentBody.transform.position;
        transform.RotateAround(parentBody.transform.position, Vector3.forward, initialRotationOffset);


        if (personalOwnership) {
            // Adding population based on missing time
            long populationIncrease = (long)(populationRate *
                           (DateTime.Now - PlayerData.instance.GetLastVisitedTime(homeStar.myNumber)).TotalSeconds / (360 / orbitSpeed));
            NetworkManager.instance._controller.UpdatePopulation(homeStar.myNumber, planetNum, (int)populationIncrease);
            population += populationIncrease;
            this.dt = TimeSpan.FromSeconds((DateTime.Now - PlayerData.instance.GetLastVisitedTime(homeStar.myNumber)).TotalSeconds % (360 / orbitSpeed));
            Debug.Log("DT for pop is: " + (DateTime.Now - PlayerData.instance.GetLastVisitedTime(homeStar.myNumber)).TotalSeconds);
        }

        // Adjust for persistent rotation
        System.TimeSpan dt = System.DateTime.Now - DateTime.ParseExact("2016-03-03 14:40:52,531", "yyyy-MM-dd HH:mm:ss,fff",
                                       System.Globalization.CultureInfo.InvariantCulture);// HACK homeStar.discoveryTime;
        Debug.Log("Dt is: " + dt.TotalSeconds);
        transform.RotateAround(parentBody.transform.position, Vector3.forward, (float)(-orbitSpeed * dt.TotalSeconds));
        Debug.Log(homeStar.myNumber + " planet number: " + planetNum + " rot. time = " + 360 / orbitSpeed);

        // Draw the orbit.
        DrawOrbit();

    }
예제 #2
0
    public void Initialize(PlanetaryBody parent, int planetNum)
    {
        base.Start();

        parentBody = parent;

        this.planetNum = planetNum;

        renderer = GetComponent<Renderer>();

        Size = localRNG.Next(MIN_SIZE, MAX_SIZE);

        homeStar = parentBody.GetComponent<SystemStar>();

        //Randomize Rotation Speed
        //rotationSpeed = localRNG.Next(MIN_ROTATION, MAX_ROTATION);

        // Set Planet Size
        transform.localScale = new Vector3(Size, Size, Size);

        // Orbit Speed is a function of distance from orbit parent (whether it be a planet or star)
        orbitSpeed = localRNG.Next(MIN_ORBIT_SPEED, MAX_ORBIT_SPEED);

        // Rotational offset
        initialRotationOffset = localRNG.Next(0, 360);

        // Randomize Location around orbit parent (for illusion of time passing)
        // Consider actually counting the amount of time the user has been away.
        transform.position = (transform.position - parentBody.transform.position).normalized*ORBIT_CONSTANT*planetNum +
                             parentBody.transform.position;
        transform.RotateAround(parentBody.transform.position, Vector3.forward, initialRotationOffset);

        System.TimeSpan dt = System.DateTime.Now - homeStar.discoveryTime;

        transform.RotateAround(parentBody.transform.position, Vector3.forward, -orbitSpeed*(float) dt.TotalSeconds);

        // Set Color
        if (planetNum <= 2)
        {
            _layeredSprite.Randomize((uint) localRNG.Next(), ref localRNG, "red");
        }
        else if (planetNum > 2 & planetNum < 4)
        {
            _layeredSprite.Randomize((uint) localRNG.Next(), ref localRNG, "green");
        }
        else
        {
            _layeredSprite.Randomize((uint) localRNG.Next(), ref localRNG, "blue");
        }

        // Draw orbit path (same color as planet)
        orbitPath = GetComponent<LineRenderer>();
        orbitPath.materials[0].color = Color.gray;

        // Draw the orbit.
        DrawOrbit();

        // Randomize Moons
        /* add moons after
        if (orbitParent.tag == SystemStar.TAG && Random.value <= MOON_CHANCE)
        {
            int numMoons = Random.Range(1, MAX_MOONS + 1);
            BuildMoons(numMoons);
        }
        */
    }