public static void PopulatePlanetTraitTables() { try { string line = null; string path = Application.dataPath; bool fileEmpty = false; System.IO.TextReader readFile = new StreamReader(path + "/Resources/planetTraitsData.txt"); while (!fileEmpty) // until the line hits a null object { line = readFile.ReadLine(); if (line != null) { if (!line.StartsWith("TYPE")) { PlanetAttributeData pAttributeData = new PlanetAttributeData(); PlanetAttributeTable pAttributeTable = new PlanetAttributeTable(); string[] planetBaseTraitsString = line.Split(new Char[] { ',' }); //pull out each modifier pAttributeData.planetType = (PlanetData.ePlanetType)int.Parse(planetBaseTraitsString[0]); pAttributeTable.size = int.Parse(planetBaseTraitsString[1]); pAttributeTable.sizeVar = int.Parse(planetBaseTraitsString[2]); pAttributeTable.habitability = int.Parse(planetBaseTraitsString[3]); pAttributeTable.habVar = int.Parse(planetBaseTraitsString[4]); pAttributeTable.indMult = float.Parse(planetBaseTraitsString[5]); pAttributeTable.ringChance = int.Parse(planetBaseTraitsString[6]); pAttributeTable.moonChance = int.Parse(planetBaseTraitsString[7]); pAttributeTable.maxMoons = int.Parse(planetBaseTraitsString[8]); pAttributeTable.alpMaterial = int.Parse(planetBaseTraitsString[9]); pAttributeTable.alpVar = int.Parse(planetBaseTraitsString[10]); pAttributeTable.heavyMaterial = int.Parse(planetBaseTraitsString[11]); pAttributeTable.heavVar = int.Parse(planetBaseTraitsString[12]); pAttributeTable.rareMaterial = int.Parse(planetBaseTraitsString[13]); pAttributeTable.rareVar = int.Parse(planetBaseTraitsString[14]); pAttributeTable.energy = int.Parse(planetBaseTraitsString[15]); for (int x = 0; x < 8; x++) { pAttributeTable.validRegions[x] = int.Parse(planetBaseTraitsString[16 + x]); } // add the table to the data object and then add to the attribute data list pAttributeData.planetTraitsTable = pAttributeTable; planetAttributeDataList.Add(pAttributeData); } else { continue; } } else fileEmpty = true; } readFile.Close(); readFile = null; Debug.Log("Planet Attribute Tables successfully read!"); } catch (IOException ex) { Debug.LogError("Could not read Planet Attribute Table file; error:" + ex.ToString()); } }
private static PlanetData GeneratePlanet(PlanetData.ePlanetType planetType, StarData curSys, int systemSpot) { PlanetData cPlan = new PlanetData(); PlanetAttributeTable pTable = new PlanetAttributeTable(); PlanetAttributeData pData = new PlanetAttributeData(); // assign the attribute table for the planet type try { pData = DataManager.planetAttributeDataList.Find(p => p.planetType == planetType); pTable = pData.planetTraitsTable; } catch (Exception ex) { Debug.LogError("Could not lookup " + planetType.ToString() + " table for planet type " + planetType.ToString() + "! Error:" + ex.ToString()); return null; // try again with the next planet } // Step 0: Log spot of planet in system cPlan.PlanetSpot = systemSpot; // Step 1: Determine type of planet cPlan.Type = (StellarObjects.PlanetData.ePlanetType)planetType; // assign the planet type // Step 2: Pick name for planet and assign ID(will change to generic star name) systemSpot = curSys.PlanetList.Count + 1; if (cPlan.Type == PlanetData.ePlanetType.AsteroidBelt) cPlan.Name = curSys.Name + " AB-" + HelperFunctions.StringConversions.ConvertToRomanNumeral(systemSpot); else if (cPlan.Type == PlanetData.ePlanetType.IceBelt) cPlan.Name = curSys.Name + " IB-" + HelperFunctions.StringConversions.ConvertToRomanNumeral(systemSpot); else if (cPlan.Type == PlanetData.ePlanetType.DustRing) cPlan.Name = curSys.Name + " DR-" + HelperFunctions.StringConversions.ConvertToRomanNumeral(systemSpot); else cPlan.Name = curSys.Name + " " + HelperFunctions.StringConversions.ConvertToRomanNumeral(systemSpot); // convert to planet and spot cPlan.ID = curSys.Name.Substring(0,2) + UnityEngine.Random.Range(0,9999); // set ID // Step 3: Determine size/axial tilt of planet try { int sizeVar = UnityEngine.Random.Range(0, pTable.sizeVar); int sizeResult = pTable.size + sizeVar; cPlan.Size = sizeResult; // sizeMod; } catch(Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } cPlan.AxialTilt = UnityEngine.Random.Range(0f, 70f); // tilt between 0-70 // Step 4: Determine habitibility of planet try { int habVar = UnityEngine.Random.Range(0, pTable.habVar); float habResult = pTable.habitability + habVar; float spotVar = 0f; switch (cPlan.PlanetSpot) { case 1: if ((int)curSys.SpectralClass < 5) { spotVar = .6f; break; } else { spotVar = .9f; break; } case 2: spotVar = .9f; break; case 3: spotVar = 1f; break; case 4: spotVar = 1f; break; case 5: spotVar = .9f; break; case 6: spotVar = .7f; break; default: spotVar = 1f; break; } cPlan.Bio = (int)(habResult * spotVar); } catch (Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } // Step 5: Determine industrial modifier of planet cPlan.IndustrialMultiplier = (pTable.indMult / 100); // Step 6: Determine if planet has any rings if (UnityEngine.Random.Range(0, 100) <= pTable.ringChance) cPlan.Rings = true; else cPlan.Rings = false; // Step 7: Determine how many moons the planet has if (UnityEngine.Random.Range(0, 100) <= pTable.moonChance) cPlan.Moons = UnityEngine.Random.Range(1,pTable.maxMoons); // change later to expand on moons // Step 7b: Adjust habitability based on moons if (cPlan.Moons > 0) if (((int)cPlan.Type == 7) || ((int)cPlan.Type == 8)) { cPlan.Bio += (cPlan.Moons * 2); } if (((int)cPlan.Type == 10) || ((int)cPlan.Type == 3) || ((int)cPlan.Type == 2) || ((int)cPlan.Type == 13)) { cPlan.Bio += (cPlan.Moons * 5); } // Step 8: Determine rating of alpha materials try { int alphaVar = UnityEngine.Random.Range(0, pTable.alpVar); cPlan.BasicMaterials = pTable.alpMaterial + alphaVar; } catch (Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } // Step 9: Determine rating of heavy materials try { int heavyVar = UnityEngine.Random.Range(0, pTable.heavVar); cPlan.HeavyMaterials = (int)(pTable.heavyMaterial * (1 + (curSys.pMaterial / 20))); cPlan.HeavyMaterials = cPlan.HeavyMaterials * (1 + ((5 - systemSpot) / 10)); cPlan.HeavyMaterials += heavyVar; } catch (Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } // Step 10: Determine rating of rare materials try { int rareMod = UnityEngine.Random.Range(0, pTable.rareVar); cPlan.RareMaterials = (int)(pTable.rareMaterial * (1 + (curSys.pMaterial / 12))); cPlan.RareMaterials = cPlan.RareMaterials * (1 + ((5 - systemSpot) / 8)); cPlan.RareMaterials += rareMod; } catch (Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } // Step 11: Determine energy rating try { cPlan.Energy = (int)(pTable.energy * (1 + (curSys.pMaterial / 12))); cPlan.Energy = cPlan.Energy * (1 + ((5 - systemSpot) / 10)); cPlan.Energy += UnityEngine.Random.Range(0, 30); } catch (Exception ex) { Debug.LogError("Could not calcuate. Error: " + ex.ToString()); } // Step 12: Generate sprite number (to show type of planet) if ((cPlan.Type != PlanetData.ePlanetType.DustRing) && (cPlan.Type != PlanetData.ePlanetType.IceBelt) && (cPlan.Type != PlanetData.ePlanetType.AsteroidBelt)) cPlan.PlanetSpriteNumber = UnityEngine.Random.Range(0, SpritesPerPlanetType - 1); else cPlan.PlanetSpriteNumber = UnityEngine.Random.Range(0, SpritesPerBeltType - 1); // Step 13: Generate ring sprite number if applicable cPlan.PlanetRingSpriteNumber = UnityEngine.Random.Range(0, SpritesPerRingType - 1); cPlan.PlanetRingTilt = UnityEngine.Random.Range(-10, 10); // Step 13: Determine planetary traits DeterminePlanetTraits(cPlan); // Step 14: Determine total and habitable tiles based on bio level cPlan.MaxTiles = (cPlan.Size / 3); for (int x = 0; x < cPlan.MaxTiles; x++) { if (UnityEngine.Random.Range(0, 100) < cPlan.AdjustedBio) { cPlan.MaxHabitableTiles += 1; } } // Step 15: Create and assign tiles to the planet GeneratePlanetRegions(cPlan); // Step 16: Send the planet data back! return cPlan; }