public static Region GetRegion(string ID)
        {
            GalaxyData galaxyDataRef = GameObject.Find("GameManager").GetComponent<GalaxyData>();
            Region rData = new Region();

            rData = galaxyDataRef.GalaxyRegionDataList.Find(p => p.ID == ID);
            return rData;
        }
        private void AllocateInfraProduction(Region targetRegion)
        {           
            bool alphaBPsReachedForInfra = false;
            bool heavyBPsReachedForInfra = false;
            bool rareBPsReachedForInfra = false;
            int alphaBPMultiplier = 0;
            int heavyBPMultiplier = 0;
            int rareBPMultiplier = 0;
            
            float AlphaMaterialsRequired = Constants.Constants.AlphaMaterialsPerInfraLevel * (100 / AdjustedBio) * Mathf.Pow(targetRegion.HabitatationInfrastructureLevel,3);
            float HeavyMaterialsRequired = Constants.Constants.HeavyMaterialsPerInfraLevel * (100 / AdjustedBio) * Mathf.Pow(targetRegion.HabitatationInfrastructureLevel, 3);
            float RareMaterialsRequired = Constants.Constants.RareMaterialsPerInfraLevel * (100 / AdjustedBio) * Mathf.Pow(targetRegion.HabitatationInfrastructureLevel, 3);

            if (AlphaBPsGeneratedMonthly > 0)
            {
                if (AlphaMaterialsRequired * (100 / AdjustedBio) <= targetRegion.TotalAlphaBPsAllocatedInfra)
                {
                    alphaBPsReachedForInfra = true;
                    alphaBPMultiplier = (int)(targetRegion.TotalAlphaBPsAllocatedInfra / AlphaMaterialsRequired);
                }

                if (HeavyMaterialsRequired <= targetRegion.TotalHeavyBPsAllocatedInfra)
                {
                    heavyBPsReachedForInfra = true;
                    heavyBPMultiplier = (int)(targetRegion.TotalHeavyBPsAllocatedInfra / HeavyMaterialsRequired);
                    if (heavyBPMultiplier == 0)
                        heavyBPMultiplier = 1;
                }

                if (RareMaterialsRequired <= targetRegion.TotalRareBPsAllocatedInfra)
                {
                    rareBPsReachedForInfra = true;
                    rareBPMultiplier = (int)(targetRegion.TotalRareBPsAllocatedInfra / RareMaterialsRequired);
                    if (rareBPMultiplier == 0)
                        rareBPMultiplier = 1;
                }

                if (alphaBPsReachedForInfra && heavyBPsReachedForInfra && rareBPsReachedForInfra)
                {
                    // determine the max amount of levels that can be built at once
                    int totalLevels = alphaBPMultiplier;
                    InfraLevelBuilt = true;
                    if (heavyBPMultiplier < totalLevels)
                        totalLevels = heavyBPMultiplier;
                    if (rareBPMultiplier < totalLevels)
                        totalLevels = rareBPMultiplier;

                    // build those levels
                    AddNewLevels("Infra", totalLevels, targetRegion);

                    // reset the allocations
                    targetRegion.TotalAlphaBPsAllocatedInfra = 0;
                    targetRegion.TotalHeavyBPsAllocatedInfra = 0;
                    targetRegion.TotalRareBPsAllocatedInfra = 0;
                }

                // determine Infras BPs
                if (!alphaBPsReachedForInfra)
                {
                    float previousTotal = TotalHeavyBPsAllocatedInfra;
                    targetRegion.TotalAlphaBPsAllocatedInfra += (float)(AlphaBPsGeneratedMonthly * BuildPlan.InfraAllocation);
                    if (targetRegion.TotalAlphaBPsAllocatedInfra > AlphaMaterialsRequired)
                    {
                        AlphaBPsUsed = AlphaMaterialsRequired - previousTotal;
                        targetRegion.TotalAlphaBPsAllocatedInfra = AlphaMaterialsRequired;
                    }
                    else
                    {
                        AlphaBPsUsed += (float)(AlphaBPsGeneratedMonthly * BuildPlan.InfraAllocation);
                    }

                }

                if (!heavyBPsReachedForInfra)
                {
                    float previousTotal = TotalHeavyBPsAllocatedInfra;
                    targetRegion.TotalHeavyBPsAllocatedInfra += (float)(HeavyBPsGeneratedMonthly * BuildPlan.InfraAllocation);
                    if (targetRegion.TotalHeavyBPsAllocatedInfra > HeavyMaterialsRequired)
                    {
                        HeavyBPsUsed = HeavyMaterialsRequired - previousTotal;
                        targetRegion.TotalHeavyBPsAllocatedInfra = HeavyMaterialsRequired;
                    }
                    else
                    {
                        HeavyBPsUsed += (float)(HeavyBPsGeneratedMonthly * BuildPlan.InfraAllocation);
                    }
                }

                if (!rareBPsReachedForInfra)
                {
                    float previousTotal = targetRegion.TotalRareBPsAllocatedInfra;
                    targetRegion.TotalRareBPsAllocatedInfra += (float)(RareBPsGeneratedMonthly * BuildPlan.InfraAllocation);
                    if (targetRegion.TotalRareBPsAllocatedInfra > RareMaterialsRequired)
                    {

                        RareBPsUsed = RareMaterialsRequired - previousTotal;
                        targetRegion.TotalRareBPsAllocatedInfra = RareMaterialsRequired;
                    }
                    else
                    {
                        RareBPsUsed += (float)(RareBPsGeneratedMonthly * BuildPlan.InfraAllocation);
                    }
                }

                float TotalBPs = targetRegion.TotalAlphaBPsAllocatedInfra + targetRegion.TotalHeavyBPsAllocatedInfra + targetRegion.TotalRareBPsAllocatedInfra;
                float TotalBPsNeeded = AlphaMaterialsRequired + HeavyMaterialsRequired + RareMaterialsRequired;

                if (InfraLevelBuilt)
                {
                    PercentToNewInfraLevel = 1f; // Infra is built, so show 100%
                    InfraLevelBuilt = false; // reset
                }
                else
                {
                    PercentToNewInfraLevel = TotalBPs / TotalBPsNeeded;
                    if (PercentToNewInfraLevel > 1f)
                    {
                        PercentToNewInfraLevel = 1f;
                    }
                }
            }
        }
        private void AddNewLevels(string levType, int levels, Region targetRegion)
        {
            for (int x = 0; x < levels; x++)
            {
                // determine all eligible regions on the planet (not overpopulated)
                List<string> regionsEligible = new List<string>();
                foreach (Region rData in RegionList)
                {
                    if (rData.TotalDevelopmentLevel < rData.MaxDevelopmentLevel && levType != "Infra" && rData.IsHabitable)
                    {
                        regionsEligible.Add(rData.ID);
                    }
                    else
                    {
                        if (rData.IsHabitable)
                            regionsEligible.Add(rData.ID);
                    }
                }
                
                // then choose a region from this list
                int regionChoice = UnityEngine.Random.Range(0, regionsEligible.Count);
                if (levType == "Farm")
                {              
                    HelperFunctions.DataRetrivalFunctions.GetRegion(regionsEligible[regionChoice]).FarmingLevel += 1;
                    FarmsBuiltLastTurn += 1;
                }

                if (levType == "Hightech")
                {
                    HelperFunctions.DataRetrivalFunctions.GetRegion(regionsEligible[regionChoice]).HighTechLevel += 1;
                    HighTechBuiltLastTurn += 1;
                }

                if (levType == "Factory")
                {
                    HelperFunctions.DataRetrivalFunctions.GetRegion(regionsEligible[regionChoice]).ManufacturingLevel += 1;
                    FactoriesBuiltLastTurn += 1;
                }

                if (levType == "Mine")
                {
                    HelperFunctions.DataRetrivalFunctions.GetRegion(regionsEligible[regionChoice]).MiningLevel += 1;
                    MinesBuiltLastTurn += 1;
                }

                if (levType == "Infra")
                {
                    targetRegion.HabitatationInfrastructureLevel += 1;
                    InfraLevelsBuiltLastTurn += 1;
                }
            }
        }
 public bool MovePopBetweenRegions(Pops pop, Region oldRegion, Region newRegion)
 {
     if ((newRegion.MaxSafePopulationLevel * 2) > newRegion.PopsInTile.Count) // only move pops if there is room!
     {
         oldRegion.PopsInTile.Remove(pop);
         newRegion.PopsInTile.Add(pop);
         pop.RegionLocationID = newRegion.ID;
         //Debug.Log("A " + pop.PopClass.ToString().ToLower() + " from region " + oldRegion.ID + " moved to region " + newRegion.ID + ".");
         return true;
     }
     else
         return false;
 }