Example #1
0
    /// <summary>
    /// Calls a random minor event.
    /// </summary>
    private void ExecuteRandomMinorEvent()
    {
        Region_Controller currentRegion;
        string            regionName;

        // Pause the game
        this.GetComponent <World_Controller>().Pause();

        // Randomly select the country in which an event will happen.
        int randomNumber = (int)(Random.Range(0.0f, 25.0f));

        print("random Number is: " + randomNumber);

        // Save info on random country locally.
        currentRegion = this.GetComponent <World_Controller>().region_Controller[randomNumber];
        regionName    = regionNames[randomNumber];

        // Chances of different minor events. // This can be made much much better.
        if (Random.value > 0.3f)
        {
            RandomWar(currentRegion.GetComponent <Region_Controller>(), regionName);
        }
        else
        {
            MurderousCult(currentRegion.GetComponent <Region_Controller>(), regionName);
        }

        // Set populations and give resources.
        devil_Controller.DailyShout();
        god_Controller.DailyShout();
    }
    // Update is called once per frame -- fixed == xseconds .. 0.02seconds is the default .. can change with Time.fixedDeltaTime
    private void FixedUpdate()
    {
        if (!_isTimePaused)
        {
            _timer += Time.deltaTime;

            //update demon banshees text available every frame -- better to only do this whenever player clicks
            SetBaseUnitCountText();    // only after clicking reaserch tree banshee ++ or when an event adds a banshee
            SetSpecialUnitCountText(); // same .. except I could incorporate people dying (saying 1% of population die every year). -- so would need to be called every frame.

            if (devil_Controller.isPlayerControlled)
            {
                SetSkullsSoulsText(); // skulls need to update every frame because of events - better to just update after events click. + at day end.
                SetSinsPrayersText(); //sins becuase of spending in research tree -- better to only do this after clicking research button and whenever people are killed.
            }
            else if (god_Controller.isPlayerControlled)
            {
                // Update
            }

            if (_timer >= DAY_LENGTH)
            {
                if (_timer > (DAY_LENGTH + 0.02f))
                {
                    throw new System.Exception($"The timer ({_timer})has exceeded the length of the day add allowance for minimal allowance ({DAY_LENGTH})");
                }
                // A day has passed.
                _day++;
                Debug.Log("A day has passed.");

                // Reset timer
                _timer = 0.0f;

                // Update the populations in the whole world.
                UpdateAllRegionStatistics();

                // Set the ownership and control level of the continents


                // Call the methods to set resources.
                devil_Controller.DailyShout();
                god_Controller.DailyShout();

                // Possibility of a random minor event.
                this.GetComponent <Minor_Events_Controller>().ChanceToCallRandomMinorEvent();

                SetHUD();
                try{
                    if (_day == _daysInMonth[(_month - 1)])
                    {
                        // New month.
                        _day = 0;
                        if (_month == 12)
                        {
                            // Happy new year.
                            _month = 1;
                            _year++;
                        }
                        else
                        {
                            _month += 1;
                        }
                    }// End month check if statment.
                }
                catch (System.IndexOutOfRangeException E) {
                    Debug.LogError($"The public starting variables for day, month year need to be set in the World_Controller script on the gameobject {gameObject}");
                }
            } // End timer day length if statement.
        }     // End if time is not paused.
    }         // End fixedupdate.