private void CheckForMigration(Civilization civ) { foreach (PlanetData pData in civ.PlanetList) { pData.UpdateMigrationStatus(); } }
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 } }
public static Civilization CreateNewCivilization() { List<String> civNameList = DataManager.civNameList; // populate the color list if needed if (civColorList.Count == 0) PopulateCivColorList(); Civilization newCiv = new Civilization(); int dieRoll = 0; galaxyDataRef = GameObject.Find("GameManager").GetComponent<GalaxyData>(); // access galaxy data gameDataRef = GameObject.Find("GameManager").GetComponent<GlobalGameData>(); // access galaxy data // Step 1: Generate type of civ dieRoll = UnityEngine.Random.Range(1, 7); newCiv.Type = (Civilization.eCivType)dieRoll; // cast to enum // Step 2: Generate ID of civ newCiv.ID = "CIV" + gameDataRef.CivList.Count.ToString("N0"); // Step 2: Generate name of civ string primaryName = ""; string surName = ""; if (civNameList.Count > 0) { var nameIndex = UnityEngine.Random.Range(0, civNameList.Count); primaryName = civNameList[nameIndex]; civNameList.RemoveAt(nameIndex); civNameList.TrimExcess(); } else primaryName = "GenericName"; var surNameIndex = UnityEngine.Random.Range(0, DataManager.civSurNameList.Count); surName = DataManager.civSurNameList[surNameIndex]; newCiv.Name = primaryName + " " + surName; // Step 3: Generate other base stats (treasury, size, etc) // size/range newCiv.Range = 40; // to start with int size = UnityEngine.Random.Range(0, 100); // adjust size/other ratings for civ type switch(newCiv.Type) { case Civilization.eCivType.Confederation : { size += 55; break; } case Civilization.eCivType.MinorEmpire: { size += 40; break; } case Civilization.eCivType.Satrapy: { size += 20; break; } case Civilization.eCivType.BrokenCivilization: { size -= 30; break; } case Civilization.eCivType.Pirates: { size -= 15; break; } } // add a empire type mod here if (size < 40) newCiv.Size = Civilization.eCivSize.SinglePlanet; else if (size < 70) newCiv.Size = Civilization.eCivSize.Local; else if (size < 90) { newCiv.Size = Civilization.eCivSize.Minor; newCiv.Range = UnityEngine.Random.Range(MultiSystemEmpireRange - 200, MultiSystemEmpireRange + 200); } else { newCiv.Size = Civilization.eCivSize.Major; newCiv.Range = UnityEngine.Random.Range(MultiRegionEmpireRange - 400, MultiRegionEmpireRange + 400); } // skill ratings newCiv.FarmingBaseRating = UnityEngine.Random.Range(70, 100) - (int)newCiv.Type * 10; newCiv.MiningBaseRating = UnityEngine.Random.Range(50, 90) - (int)newCiv.Type * 10; newCiv.ScienceBaseRating = UnityEngine.Random.Range(0, 50) + (int)newCiv.Type * 10; newCiv.HighTechBaseRating = UnityEngine.Random.Range(0, 40) + (int)newCiv.Type * 10; newCiv.ManufacturingBaseRating = UnityEngine.Random.Range(5, 50) + (int)newCiv.Type * 10; // tolerance newCiv.PlanetMinTolerance = UnityEngine.Random.Range(40, 60); // sets the base minimum habitable world a civilization is willing to tolerate // province size if (newCiv.Size == Civilization.eCivSize.Major) { newCiv.CivMaxProvinceSize = UnityEngine.Random.Range(1, 6); // sets a province size between 1 and 5 systems newCiv.AdminRating = UnityEngine.Random.Range(5, 21); // generates the civ's base admin rating (how efficient they are in adminstering provinces } else { newCiv.CivMaxProvinceSize = 0; // no provinces can be created; the civ is essentially one province newCiv.AdminRating = 1; } // admin rating // Step 4: Determine planet of origin retryPlanet: // beginning of retry loop PlanetData civPlanet = new PlanetData(); dieRoll = UnityEngine.Random.Range(0, galaxyDataRef.GalaxyPlanetDataList.Count); // find the planets in the quadrant civPlanet = galaxyDataRef.GalaxyPlanetDataList[dieRoll]; if (galaxyDataRef.GalaxyPlanetDataList[dieRoll].AdjustedBio < newCiv.PlanetMinTolerance) // if the bio is too low, throw it out goto retryPlanet; if (gameDataRef.CivList.Count > 0) { foreach (Civilization civ in gameDataRef.CivList) { List<StarData> populatedHomeSystems = new List<StarData>(); populatedHomeSystems = HelperFunctions.DataRetrivalFunctions.GetCivSystemList(civ); if (civPlanet.ID == civ.CapitalPlanetID) // check for capital world goto retryPlanet; if (civ.PlanetIDList.Exists(p => p == civPlanet.ID)) // then all other worlds goto retryPlanet; if (newCiv.ID != civ.ID) if (populatedHomeSystems.Exists(p => p.ID == civPlanet.SystemID)) // check for systems that other civs have claimed goto retryPlanet; } // assign a name for the civ's planet if (DataManager.planetNameList.Count > 0) { var nameIndex = UnityEngine.Random.Range(0, DataManager.planetNameList.Count); civPlanet.Name = DataManager.planetNameList[nameIndex]; DataManager.planetNameList.RemoveAt(nameIndex); DataManager.planetNameList.TrimExcess(); } else civPlanet.Name = "GenericName"; // set as capital and send to assign pops, developments, etc. newCiv.CapitalPlanetID = civPlanet.ID; ClaimCivPlanet(civPlanet, newCiv); civPlanet.Rank = PlanetData.ePlanetRank.ImperialCapital; newCiv.PlanetIDList.Add(civPlanet.ID); // add the planet } // Step 5: Determine additional planets if (newCiv.Size != Civilization.eCivSize.SinglePlanet) ClaimPlanetsForCiv(newCiv); // Step 5: Generate color of civ retryColor: // beginning of retry loop Color civColor = new Color(); civColor = new Color(UnityEngine.Random.Range(.01f, .99f), UnityEngine.Random.Range(.01f, .99f), UnityEngine.Random.Range(.01f, .99f)); // select a random color if (gameDataRef.CivList.Count > 0) { foreach (Civilization civ in gameDataRef.CivList) { if (civColor == civ.Color) goto retryColor; } newCiv.Color = civColor; } return newCiv; }
// this 'flags' planets to seed with pops in the next step public static void ClaimPlanetsForCiv(Civilization newCiv) { gameDataRef = GameObject.Find("GameManager").GetComponent<GlobalGameData>(); galaxyDataRef = GameObject.Find("GameManager").GetComponent<GalaxyData>(); float civMaxDistance = newCiv.Range; PlanetData homePlanet = galaxyDataRef.GalaxyPlanetDataList.Find(p => p.ID == newCiv.CapitalPlanetID); StarData homeStar = galaxyDataRef.GalaxyStarDataList.Find(p => p.ID == homePlanet.SystemID); List<StarData> eligibleSystems = new List<StarData>(); foreach (StarData star in galaxyDataRef.GalaxyStarDataList) { float distance = HelperFunctions.Formulas.MeasureDistanceBetweenSystems(star, homeStar); if ( distance <= civMaxDistance) // must be within range and also include the home system eligibleSystems.Add(star); // add systems that are close to the home star } // // now check planets in those systems to see if they can be owned foreach (StarData potStar in eligibleSystems) { foreach(PlanetData pData in potStar.PlanetList) { if (pData.AdjustedBio >= newCiv.PlanetMinTolerance) { bool planetEligible = true; foreach (Civilization civ in gameDataRef.CivList) // check each civ to make sure they don't own the planet { if (civ.PlanetIDList.Exists (p => p == pData.ID)) planetEligible = false; if (pData.ID == homePlanet.ID) planetEligible = false; if (pData.AdjustedMaxHabitableTiles == 0) // if after traits there are no tiles to put people on, it's not a good planet! planetEligible = false; } if (planetEligible) // if they don't, then claim! ClaimCivPlanet(pData,newCiv); } } } }
void GenerateAICivs() { for (int x = 0; x < gameDataRef.NumberOfAICivs; x++) { Civilization newCiv = new Civilization(); newCiv = GenerateGameObject.CreateNewCivilization(); // may need to add parameters gameDataRef.AddNewCivilization(newCiv); } }
private void UpdatePopularSupport(Civilization civ) { foreach (PlanetData pData in civ.PlanetList) { pData.UpdatePopularSupport(); // update popular support and unrest levels } }
private void UpdateEvents(Civilization civ) { foreach (PlanetData pData in civ.PlanetList) { GameEvents.PlanetEventCreator.GeneratePlanetEvents(pData, civ); // generate the events for each planet } foreach (GameEvents.GameEvent gEvent in civ.LastTurnEvents.ToArray()) { if (!gEvent.EventIsNew) // delete the event if it's already been seen { civ.LastTurnEvents.Remove(gEvent); civ.LastTurnEvents.TrimExcess(); } if (gEvent.EventIsNew) { gEvent.EventIsNew = false; } } }
private void ResetCivBudgets(Civilization civ) { civ.Revenues = 0; civ.Expenses = 0; // reset the budgets at the start of the year }
public static List<StarData> GetCivSystems(Civilization civ) { GalaxyData galaxyDataRef = GameObject.Find("GameManager").GetComponent<GalaxyData>(); PlanetData pData = new PlanetData(); List<PlanetData> pDataList = new List<PlanetData>(); List<StarData> sDataList = new List<StarData>(); foreach (string ID in civ.PlanetIDList) { pData = galaxyDataRef.GalaxyPlanetDataList.Find(p => p.ID == ID); if (!sDataList.Exists(p => p.ID == pData.SystemID)) sDataList.Add(galaxyDataRef.GalaxyStarDataList.Find(p => p.ID == pData.SystemID)); } return sDataList; }
public static List<StarData> GetCivSystemList(Civilization civ) { GlobalGameData gameDataRef = GameObject.Find("GameManager").GetComponent<GlobalGameData>(); GalaxyData galaxyDataRef = GameObject.Find("GameManager").GetComponent<GalaxyData>(); List<StarData> civStarList = new List<StarData>(); foreach (PlanetData planet in galaxyDataRef.GalaxyPlanetDataList) { if (civ.PlanetIDList.Exists(p => p == planet.ID)) { StarData star = galaxyDataRef.GalaxyStarDataList.Find(p => p.ID == planet.SystemID); if (!civStarList.Contains(star)) civStarList.Add(star); } } return civStarList; }
public static List<Province> GetCivProvinceList(Civilization civ) { GlobalGameData gameDataRef = GameObject.Find("GameManager").GetComponent<GlobalGameData>(); GalaxyData galaxyDataRef = GameObject.Find("GameManager").GetComponent<GalaxyData>(); List<Province> civProvinceList = new List<Province>(); foreach (Province prov in galaxyDataRef.ProvinceList) { if (prov.OwningCivID == civ.ID) { civProvinceList.Add(prov); } } return civProvinceList; }
public static List<PlanetData> GetCivPlanetList(Civilization civ) { GlobalGameData gameDataRef = GameObject.Find("GameManager").GetComponent<GlobalGameData>(); GalaxyData galaxyDataRef = GameObject.Find("GameManager").GetComponent<GalaxyData>(); List<PlanetData> civPlanetList = new List<PlanetData>(); foreach (PlanetData planet in galaxyDataRef.GalaxyPlanetDataList) { if (civ.PlanetIDList.Exists(p => p == planet.ID)) { civPlanetList.Add(planet); } } return civPlanetList; }
void GeneratePlanetIntelLevels(Civilization humanCiv) { List<PlanetData> civPlanetList = HelperFunctions.DataRetrivalFunctions.GetCivPlanetList(humanCiv); foreach (StarData star in gData.GalaxyStarDataList) { foreach (PlanetData planet in star.PlanetList) { if (civPlanetList.Exists(p => p.ID == planet.ID)) { planet.IntelLevel = 10; planet.ScanLevel = 1f; } else { planet.IntelLevel = star.IntelValue / 2; planet.ScanLevel = (float)(star.IntelValue / 10f) * UnityEngine.Random.Range(.2f, 1f); } } } }
void GenerateHumanCiv() { Civilization newCiv = new Civilization(); newCiv.Name = gameDataRef.PlayerEmpireName; newCiv.Color = Color.cyan; // the color of the empire's system and planet holdings newCiv.Type = Civilization.eCivType.PlayerEmpire; // default empire newCiv.CivMaxProvinceSize = 5; newCiv.AdminRating = 18; // rating that determines maximum size of governable provinces newCiv.Treasury = Random.Range(1000000f, 5000000f); // starting treasury newCiv.Size = Civilization.eCivSize.Major; newCiv.Range = (int)(gameDataRef.GalaxySizeWidth / 2.3f); newCiv.PlanetMinTolerance = 45; newCiv.AstronomyRating = UnityEngine.Random.Range(6,11) * 1000; newCiv.ID = "CIV0"; // use this to reference the player's civ newCiv.HumanCiv = true; PlanetData pData; List<PlanetData> terranSystemPlanetList = gData.GalaxyStarDataList.Find(p => p.Name == "Neo-Sirius").PlanetList; pData = terranSystemPlanetList[UnityEngine.Random.Range(0, terranSystemPlanetList.Count)]; // create the human homeworld manually; pData.Name = "New Terra"; pData.ID = "PLANEWT001"; pData.PlanetSpriteNumber = 43; // the city type pData.Type = PlanetData.ePlanetType.Terran; pData.Rank = PlanetData.ePlanetRank.ImperialCapital; pData.Size = 60; pData.Bio = 90; pData.Energy = 70; pData.HeavyMaterials = 60; pData.MaxTiles = 30; pData.MaxHabitableTiles = 26; pData.RareMaterials = 30; pData.BasicMaterials = 88; pData.IsTradeHub = true; newCiv.CapitalPlanetID = pData.ID; GenerateGameObject.GeneratePlanetRegions(pData); // rework the tiles newCiv.PlanetIDList.Add(pData.ID); // generate the rest of the planet claims for the player empire gameDataRef.AddNewCivilization(newCiv); GenerateGameObject.ClaimPlanetsForCiv(newCiv); // determine intel level for systems, scan level for planets foreach (StarData star in gData.GalaxyStarDataList) { foreach (StarData civStar in HelperFunctions.DataRetrivalFunctions.GetCivSystemList(newCiv)) { float range = HelperFunctions.Formulas.MeasureDistanceBetweenSystems(civStar, star); if (star.IntelValue < (int)(newCiv.AstronomyRating / (range + 1))) star.IntelValue = (int)(newCiv.AstronomyRating / (range + 1)); } } }
private void LookForTradePartner(Civilization civ, string resource, string planetID) { PlanetData needyPlanet = HelperFunctions.DataRetrivalFunctions.GetPlanet(planetID); SortedList sortedPlanetDistList = new SortedList(); // create the sorted list foreach (PlanetData pData in needyPlanet.System.Province.PlanetList) { if (pData.ID != planetID && pData.IsInhabited) { float dist = HelperFunctions.Formulas.MeasureDistanceBetweenSystems(needyPlanet.System,pData.System); while (sortedPlanetDistList.ContainsKey(dist)) { dist += .001f; } sortedPlanetDistList.Add(dist,pData); } } // now check for general ability to create agreement (distance, starbase, support level of viceroy) foreach (DictionaryEntry de in sortedPlanetDistList) { PlanetData exportPlanet = (PlanetData)de.Value; // cast? if (exportPlanet.IsTradeAgreementValid(needyPlanet, resource)) // check for food agreement (is there enough food to send?) { TradeAgreement newTrade = new TradeAgreement(); newTrade.ExportPlanetID = exportPlanet.ID; newTrade.Status = TradeAgreement.eAgreementStatus.Active; newTrade.ImportPlanetID = needyPlanet.ID; switch (resource) { case "food" : { if (exportPlanet.FoodExportAvailable >= Math.Abs(needyPlanet.FoodDifference)) newTrade.FoodSent = Math.Abs(needyPlanet.FoodDifference); else if (exportPlanet.FoodExportAvailable > 0) newTrade.FoodSent = exportPlanet.FoodExportAvailable; else newTrade.FoodSent = 0; // no food avail, error check if (newTrade.FoodSent >= exportPlanet.StarbaseCapacityRemaining) { newTrade.FoodSent = exportPlanet.StarbaseCapacityRemaining; } break; } case "energy": { if (exportPlanet.EnergyExportAvailable >= Math.Abs(needyPlanet.EnergyDifference)) newTrade.EnergySent = Math.Abs(needyPlanet.EnergyDifference); else if (exportPlanet.EnergyExportAvailable > 0) newTrade.EnergySent = exportPlanet.EnergyExportAvailable; else newTrade.EnergySent = 0; if (newTrade.EnergySent >= exportPlanet.StarbaseCapacityRemaining) { newTrade.EnergySent = exportPlanet.StarbaseCapacityRemaining; } break; } case "alpha": { if (exportPlanet.AlphaExportAvailable >= Math.Abs(needyPlanet.AlphaPreProductionDifference)) newTrade.AlphaSent = Math.Abs(needyPlanet.AlphaPreProductionDifference); else if (exportPlanet.AlphaExportAvailable > 0) newTrade.AlphaSent = exportPlanet.AlphaExportAvailable; else newTrade.AlphaSent = 0; if (newTrade.AlphaSent >= exportPlanet.StarbaseCapacityRemaining) { newTrade.AlphaSent = exportPlanet.StarbaseCapacityRemaining; } break; } case "heavy": { if (exportPlanet.HeavyExportAvailable >= Math.Abs(needyPlanet.HeavyPreProductionDifference)) newTrade.HeavySent = Math.Abs(needyPlanet.HeavyPreProductionDifference); else if (exportPlanet.HeavyExportAvailable > 0) newTrade.HeavySent = exportPlanet.HeavyExportAvailable; else newTrade.HeavySent = 0; if (newTrade.HeavySent >= exportPlanet.StarbaseCapacityRemaining) { newTrade.HeavySent = exportPlanet.StarbaseCapacityRemaining; } break; } case "rare": { if (exportPlanet.RareExportAvailable >= Math.Abs(needyPlanet.RarePreProductionDifference)) newTrade.RareSent = Math.Abs(needyPlanet.RarePreProductionDifference); else if (exportPlanet.RareExportAvailable > 0) newTrade.RareSent = exportPlanet.RareExportAvailable; else newTrade.RareSent = 0; //starbase capacity check if (newTrade.RareSent >= exportPlanet.StarbaseCapacityRemaining) { newTrade.RareSent = exportPlanet.StarbaseCapacityRemaining; } break; } default: break; } if (newTrade.TotalSent >= 0.01) // minimum threshold amount for trades, also check for capacity of the trade { Debug.Log("Trade of " + newTrade.TotalSent.ToString("N2") + " " + resource + " to " + newTrade.ImportPlanet.Name + " from " + newTrade.ExportPlanet.Name + " over " + newTrade.Distance.ToString("N1") + " LY for $" + newTrade.Cost.ToString("N2") + " with a " + newTrade.CostModifier.ToString("N1") + " modifier."); gDataRef.ActiveTradeAgreements.Add(newTrade); // add the new agreement } // update the trade info for each planet UpdatePlanetTradeInfo(needyPlanet); UpdatePlanetTradeInfo(exportPlanet); } } }
private void MigratePopsBetweenPlanets(Civilization civ) { foreach (PlanetData pData in civ.PlanetList) { foreach (Region rData in pData.RegionList) { foreach (Pops pop in rData.PopsInTile.ToArray()) { if (pop.IsMigratingOffPlanet) { DetermineMigrationLocation(pop, civ); } } } } }
public static StarData GetCivHomeSystem(Civilization civ) { GlobalGameData gameDataRef = GameObject.Find("GameManager").GetComponent<GlobalGameData>(); GalaxyData galaxyDataRef = GameObject.Find("GameManager").GetComponent<GalaxyData>(); PlanetData pData = new PlanetData(); StarData sData = new StarData(); pData = galaxyDataRef.GalaxyPlanetDataList.Find(p => p.ID == civ.CapitalPlanetID); sData = galaxyDataRef.GalaxyStarDataList.Find(p => p.ID == pData.SystemID); return sData; }
public static void GenerateNewPop(Civilization civ, Region rData, Boolean isGraduating) { float PopSkillModifier = 0.0f; float HouseFarmingModifier = 1f; float HouseMiningModifier = 1f; float HouseEngineeringModifier = 1f; float HouseScienceModifier = 1f; float HouseMerchantModifier = 1f; float HouseFluxModifier = 1f; float HouseAdminModifier = 1f; Pops newPop = new Pops(); // Step 1: Determine civ of pop and set location newPop.EmpireID = civ.ID; newPop.RegionLocationID = rData.ID; // Step 1a: Determine type/age of pop int popTypeChance = 0; popTypeChance = UnityEngine.Random.Range(0, 100); if (isGraduating) // there must always be fewer child pops then worker pops (for Peter Pan issue) { newPop.Age = 18; PopSkillModifier = YoungAdultSkillModifier; } if (popTypeChance < ChancePopIsYoungAdult && !isGraduating) { newPop.Type = Pops.ePopType.Worker; newPop.Age = UnityEngine.Random.Range(18,25); PopSkillModifier = YoungAdultSkillModifier * ((float)newPop.Age/ 18f); } if (popTypeChance < ChancePopIsWorker && !isGraduating) { newPop.Type = Pops.ePopType.Worker; newPop.Age = UnityEngine.Random.Range(25, 65); PopSkillModifier = WorkerSkillModifier; } if (popTypeChance >= ChancePopIsRetired && !isGraduating) { newPop.Type = Pops.ePopType.Retired; newPop.Age = UnityEngine.Random.Range(66, 85); PopSkillModifier = RetiredSkillModifier; } //} //else //{ // newPop.Type = Pops.ePopType.Worker; // newPop.Age = UnityEngine.Random.Range(18, 65); // PopSkillModifier = WorkerSkillModifier; //} // Step 1A: Get House Skill Modifier; if (rData.PlanetLocated.Viceroy.AssignedHouse != null) { //HouseFarmingModifier += ((rData.PlanetLocated.Viceroy.AssignedHouse.FarmingTradition - 50) * .01f * (rData.PlanetLocated.Viceroy.TimeInPosition / 100f)); //HouseMiningModifier += ((rData.PlanetLocated.Viceroy.AssignedHouse.MiningTradition - 50) * .01f * (rData.PlanetLocated.Viceroy.TimeInPosition / 100f)); //HouseEngineeringModifier += ((rData.PlanetLocated.Viceroy.AssignedHouse.ManufacturingTradition - 50) * .01f * (rData.PlanetLocated.Viceroy.TimeInPosition / 100f)); //HouseFluxModifier += (((rData.PlanetLocated.Viceroy.AssignedHouse.ScienceTradition + rData.PlanetLocated.Viceroy.AssignedHouse.ManufacturingTradition) - 100) * .01f * (rData.PlanetLocated.Viceroy.TimeInPosition / 100f)); //HouseScienceModifier += ((rData.PlanetLocated.Viceroy.AssignedHouse.ScienceTradition - 50) * .01f * (rData.PlanetLocated.Viceroy.TimeInPosition / 100f)); //HouseAdminModifier += ((rData.PlanetLocated.Viceroy.AssignedHouse.GovernmentTradition - 50) * .01f * (rData.PlanetLocated.Viceroy.TimeInPosition / 100f)); //HouseMerchantModifier += ((rData.PlanetLocated.Viceroy.AssignedHouse.TradeTradition - 50) * .01f * (rData.PlanetLocated.Viceroy.TimeInPosition / 100f)); } // Step 2: Generate basic stats (eventually blend for civ speciality/tech level) int farmSkill = 0; int scienceSkill = 0; int miningSkill = 0; int highTechSkill = 0; int manufacturingSkill = 0; int merchantSkill = 0; int fluxSkill = 0; int adminSkill = 0; // determine the need in each region for each type of pop int farmDeficit = rData.FarmingLevel - rData.TotalFarmers; int minerDeficit = rData.MiningLevel - rData.TotalMiners; int fluxmenDeficit = rData.HighTechLevel - rData.TotalFluxmen; int adminDeficit = rData.GovernmentLevel - rData.TotalAdministrators; int engineerDeficit = rData.ManufacturingLevel - rData.TotalEngineers; int scientistDeficit = rData.ScienceLevel - rData.TotalScientists; int merchantDeficit = (rData.PopsInTile.Count / 4) - rData.TotalMerchants; // create the base skills using the house modifiers farmSkill = (int)(UnityEngine.Random.Range(45, 55) * PopSkillModifier * HouseFarmingModifier); scienceSkill = (int)(UnityEngine.Random.Range(45, 55) * PopSkillModifier * HouseScienceModifier); miningSkill = (int)(UnityEngine.Random.Range(45, 55) * PopSkillModifier * HouseMiningModifier); highTechSkill = (int)(UnityEngine.Random.Range(45, 55) * PopSkillModifier * HouseEngineeringModifier); manufacturingSkill = (int)(UnityEngine.Random.Range(45, 55) * PopSkillModifier * HouseEngineeringModifier); fluxSkill = (int)(UnityEngine.Random.Range(45, 55) * PopSkillModifier * HouseFluxModifier); merchantSkill = (int)(UnityEngine.Random.Range(45, 55) * PopSkillModifier * HouseMerchantModifier); adminSkill = (int)(UnityEngine.Random.Range(45, 55) * PopSkillModifier * HouseAdminModifier); // adjust for more 'needed/common' pops based on type of job and current need farmSkill += farmDeficit * skillNeedMultiple; scienceSkill += scientistDeficit * skillNeedMultiple; miningSkill += minerDeficit * skillNeedMultiple; highTechSkill += ((fluxmenDeficit + engineerDeficit) / 2) * skillNeedMultiple; manufacturingSkill += engineerDeficit * skillNeedMultiple; fluxSkill += fluxmenDeficit * skillNeedMultiple; merchantSkill += merchantDeficit * skillNeedMultiple; adminSkill += adminDeficit * skillNeedMultiple; // assign the final skill totals newPop.FarmingSkill = farmSkill; newPop.ScienceSkill = scienceSkill; newPop.MiningSkill = miningSkill; newPop.HighTechSkill = highTechSkill; newPop.ManufacturingSkill = manufacturingSkill; newPop.FluxSkill = fluxSkill; newPop.MerchantSkill = merchantSkill; newPop.AdminSkill = adminSkill; // put the pop into the workforce newPop.Employment = Pops.ePopEmployment.Unemployed; // Step 3: Generate popular support and unrest levels newPop.PopSupport = .5f; // 50% to start newPop.UnrestLevel = UnityEngine.Random.Range(0f, .1f); newPop.PlanetHappinessLevel = UnityEngine.Random.Range(30, 90) - (100-rData.PlanetLocated.AdjustedBio); // Step 4: Add the pop rData.PopsInTile.Add(newPop); }
public static void AddPopsToPlanet(PlanetData pData, Civilization civ) { // add pops to each region on a planet foreach (Region rData in pData.RegionList) { for (int x = 0; x < rData.MaxSafePopulationLevel; x++ ) { float generationChance = 0; int generationTarget = 0; // determine base chance for pop generation generationChance = UnityEngine.Random.Range(0, 135); if (pData.Rank == PlanetData.ePlanetRank.EstablishedColony) generationTarget = ChanceForPopOnStandardColony; if (pData.Rank == PlanetData.ePlanetRank.SystemCapital) generationTarget = ChanceForPopOnSystemCapital; if (pData.Rank == PlanetData.ePlanetRank.ProvinceCapital) generationTarget = ChanceForPopOnProvinceCapital; if (pData.Rank == PlanetData.ePlanetRank.ImperialCapital) generationTarget = ChanceForPopOnCivCapital; generationChance -= (float)(rData.HabitatationInfrastructureLevel / 2f); // adjust for existing infrastructure generationChance += rData.MaxSafePopulationLevel - (rData.MaxSafePopulationLevel - rData.PopsInTile.Count); if (rData.PopsInTile.Count == 0 && rData.TotalDevelopmentLevel > 0) { generationChance = 0; // always add at least one pop! } if (rData.TotalDevelopmentLevel == 0) { break; } if (generationChance <= generationTarget) { GenerateNewPop(civ, rData, false); // add a new pop to the region } } } }
// this is where all planet-update functions go to save time private void UpdatePlanets(Civilization civ) { foreach (PlanetData pData in civ.PlanetList) { pData.UpdateBirthAndDeath(); // update popular support and unrest levels pData.MigratePopsBetweenRegions(); // first check to move pops between regions to regions that might better support their talents pData.UpdateEmployment(); // once pops have moved, check employment status pData.UpdateShortfallConditions(); // update shortfall results (food, power, etc) if (gDataRef.GameMonth == 1) // on the first month of every year, do this { pData.SendTaxUpward(); // determine taxes and send up the chute PlanetDevelopmentAI.AdjustViceroyBuildPlan(pData, true); // look at adjusting the build plan for each planet, force every year or when game starts } else { PlanetDevelopmentAI.AdjustViceroyBuildPlan(pData, false); // look at adjusting the build plan for each planet } pData.ExecuteProductionPlan(); // update production of new infrastructure on the planet //GameEvents.PlanetEventCreator.GeneratePlanetEvents(pData, civ); // generate the events for each planet } }
public static void ClaimCivPlanet(PlanetData pData, Civilization newCiv) { // assign a name for the civ's planet if (DataManager.planetNameList.Count > 0) { var nameIndex = UnityEngine.Random.Range(0, DataManager.planetNameList.Count); pData.Name = DataManager.planetNameList[nameIndex]; DataManager.planetNameList.RemoveAt(nameIndex); DataManager.planetNameList.TrimExcess(); } else pData.Name = "GenericName"; pData.Rank = PlanetData.ePlanetRank.EstablishedColony; newCiv.PlanetIDList.Add(pData.ID); // add the planet }
public bool IsActionValid(Character cData, Civilization civ) { if (AllValid) { return true; } if (cData.Role == Character.eRole.Emperor && !EmperorAction) // if not an Emperor character action, kick return false; if (cData.Role == Character.eRole.Viceroy && !ViceroyValid) { return false; } if (cData.Role == Character.eRole.SystemGovernor && !SysGovValid) { return false; } if (cData.Role == Character.eRole.ProvinceGovernor && !ProvGovValid) { return false; } if (cData.Role == Character.eRole.DomesticPrime && !PrimeValid) { return false; } if (cData.Role == Character.eRole.Inquisitor && !InquisitorValid) { return false; } if (EmperorNearValid) { if (civ.Leader != null) { if (cData.PlanetLocationID != civ.Leader.PlanetLocationID) { return false; } } else { return false; // no leader, so false anyway } } return true; // passed all tests so it's true }
public void AddNewCivilization(Civilization civ) { CivList.Add(civ); }