Example #1
0
    private void DetermineMigrationLocation(Pops pop, Civilization civ)
    {
        float      topPlanetValue = 0f;
        PlanetData topPlanet      = null;

        foreach (PlanetData pData in civ.PlanetList) // determine the top value of each planet and choose the best one
        {
            if (pData != pop.PlanetLocated)
            {
                float currentPlanetValue = MigrationValueOfPlanet(pData, pop);
                if (currentPlanetValue > topPlanetValue)
                {
                    topPlanetValue = currentPlanetValue;
                    topPlanet      = pData;
                }
            }
        }

        if (topPlanetValue > Constants.Constants.StellarMigrationThreshold + UnityEngine.Random.Range(0, 200)) // if the best value is above a certain threshold
        {
            List <Region> eligibleRegionList = new List <Region>();
            foreach (Region rData in topPlanet.RegionList.ToArray())
            {
                if (rData.IsHabitable)
                {
                    eligibleRegionList.Add(rData);
                }
            }

            if (eligibleRegionList.Count > 0)
            {
                int regionChoice = UnityEngine.Random.Range(0, eligibleRegionList.Count); // find an eligible region

                // move the pop from one region on a planet to another planet and a suitable region
                string oldPlanetName = pop.PlanetLocated.Name;
                pop.IsMigratingOffPlanet = false; // reset the flag
                pop.RegionLocated.PopsInTile.Remove(pop);
                pop.RegionLocated.EmigratedLastTurn += 1;
                pop.RegionLocated.PopsInTile.TrimExcess();
                pop.RegionLocationID = eligibleRegionList[regionChoice].ID;
                pop.RegionLocated.PopsInTile.Add(pop);
                pop.RegionLocated.ImmigratedLastTurn += 1;
                pop.PlanetHappinessLevel              = 50; // reset planet happiness since they just moved
                Debug.Log("In " + gDataRef.GameDate.ToString("N1") + ", a " + pop.PopClass.ToString() + " migrated from " + oldPlanetName + " to " + topPlanet.Name + ".");
                topPlanet.MigratePopsBetweenRegions();      // rerun migration to move the pop to a more suitable region
            }
            else
            {
                pop.UnrestLevel += .05f; // can't leave
                pop.PopSupport  -= .05f; // and is pissed
            }
        }

        else
        {
            pop.UnrestLevel += .05f; // can't leave
            pop.PopSupport  -= .05f; // and is pissed
        }
    }