Created
March 28, 2020 04:51
-
-
Save alice-cash/7aff316f2f35931dfb883ff0832e2925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Web; | |
using System.Drawing; | |
namespace PlanetGen | |
{ | |
public class Planet | |
{ | |
public PointD Parent; | |
public int PlanetID; | |
public PlanetFunction Function; | |
public PlanetType Type; | |
public Starport Starport; | |
public Percentage WorkingRateOfStarport; | |
public Percentage MantanceRateOfStarport; | |
public BigInteger Population; | |
public Percentage RateOfChangeForPopulaton; | |
public string Name; | |
public string ImageName; | |
public int ImageNameRange = new Range(1, 16); | |
public int RawResouce_Water; | |
public int RawResouce_Iron; | |
public int RawResouce_RareMetals; | |
public Percentage ProtectionLevel; | |
public Planet(byte Inhababilited) | |
{ | |
PlanetID = ++Galaxy.PlanetCount; | |
if (Inhababilited == 1) | |
{ | |
Function = fnGetPlanetFunction(); | |
Type = fnGetPlanetType(); | |
/*if (Function != PlanetFunction.Homeworld) | |
Starport = fnGetStarport();*/ | |
if (Function != PlanetFunction.Abandoned_Colony) | |
Population = fnGetPopulation(); | |
if (Function != PlanetFunction.Homeworld) | |
Starport = fnGetStarport(); | |
if (Function == PlanetFunction.Abandoned_Colony) | |
MantanceRateOfStarport = 0; | |
Name = fnGetName(); | |
ImageName = string.Format("{0}.jpg", ImageNameRange); | |
if (Function == PlanetFunction.Abandoned_Colony) | |
ProtectionLevel = 0; | |
else if (Function == PlanetFunction.Homeworld) | |
ProtectionLevel = new Range(70, 100); | |
else | |
ProtectionLevel = new Range(0, 100); | |
} | |
else | |
{ | |
Function = PlanetFunction.Natural_Resources; | |
Starport = Starport.None; | |
MantanceRateOfStarport = 0; | |
WorkingRateOfStarport = 0; | |
Name = fnGetName(); | |
fnAddIncompatibleType(PlanetType.Artificial); | |
RateOfChangeForPopulaton = 0; | |
Type = fnGetPlanetType(); | |
ProtectionLevel = 0; | |
Population = 0; | |
ImageName = string.Format("{0}.jpg", ImageNameRange); | |
} | |
} | |
public static Planet BlankPlanet | |
{ | |
get { return new Planet() { PlanetID = ++Galaxy.PlanetCount }; } | |
} | |
private Planet() | |
{ | |
} | |
#region GenerationStuff | |
List<PlanetType> myIncompatibleTypes = new List<PlanetType>(); | |
List<Starport> myIncompatibleStarport = new List<Starport>(); | |
bool myOptionalModifierFlag = true; | |
int myStarportModifier = 0; | |
int myTechLevelModifier = 0; | |
int myAtmosphereModifier = 0; | |
int myPopulationModifier = 0; | |
int fnGetRandomNumber(int inMin, int inMax) | |
{ | |
return new Range(inMin, inMax); | |
} | |
int fnRollOneDie() | |
{ | |
var myDieRoll = fnGetRandomNumber(1, 6); | |
return myDieRoll; | |
} | |
int fnRollDice(int inDice) | |
{ | |
var myDieValue = 0; | |
var myTotal = 0; | |
for (var i = 0; i < inDice; i++) | |
{ | |
myDieValue = fnRollOneDie(); | |
myTotal += myDieValue; | |
} | |
return myTotal; | |
} | |
int fnRoll6SidedPercentile() | |
{ | |
var myFirstNum = fnRollOneDie(); | |
var mySecondNum = fnRollOneDie(); | |
var myString = (myFirstNum * 10) + mySecondNum; | |
return myString; | |
} | |
void fnAddIncompatibleType(PlanetType inCondition) | |
{ | |
myIncompatibleTypes.Add(inCondition); | |
} | |
void fnAddIncompatibleStarport(Starport inCondition) | |
{ | |
myIncompatibleStarport.Add(inCondition); | |
} | |
PlanetFunction fnGetPlanetFunction() | |
{ | |
// roll six-sided percentile dice | |
var myPercentile = fnRoll6SidedPercentile(); | |
PlanetFunction myPlanetFunction; | |
if (myPercentile == 11) | |
{ | |
myPlanetFunction = PlanetFunction.Abandoned_Colony; | |
WorkingRateOfStarport = new Percentage(getWR(-30, 50)); | |
MantanceRateOfStarport = new Percentage(DRange.Range(0, 0)); | |
Population = 0; | |
RateOfChangeForPopulaton = 0; | |
} | |
else if (myPercentile >= 11 && myPercentile <= 21) | |
{ | |
myPlanetFunction = PlanetFunction.Agriculture; | |
if (myOptionalModifierFlag) | |
{ | |
fnAddIncompatibleStarport(Starport.None); | |
fnAddIncompatibleType(PlanetType.Asteroid_Belt); | |
fnAddIncompatibleType(PlanetType.Artificial); | |
} | |
} | |
else if (myPercentile >= 22 && myPercentile <= 35) | |
{ | |
myPlanetFunction = PlanetFunction.Colony; | |
} | |
else if (myPercentile >= 26 && myPercentile <= 33) | |
{ | |
myPlanetFunction = PlanetFunction.Homeworld; | |
if (myOptionalModifierFlag) | |
{ | |
Starport = Starport.Imperial_class; | |
WorkingRateOfStarport = new Percentage(100); | |
MantanceRateOfStarport = new Percentage(100); | |
fnAddIncompatibleType(PlanetType.Asteroid_Belt); | |
} | |
} | |
else if (myPercentile >= 34 && myPercentile <= 41) | |
{ | |
myPlanetFunction = PlanetFunction.Manufacturing_Processing; | |
// ##### *** ##### | |
// additional modifiers!!! | |
if (myOptionalModifierFlag) | |
{ | |
myStarportModifier += 2; | |
myTechLevelModifier += 2; | |
} | |
} | |
else if (myPercentile == 42) | |
{ | |
myPlanetFunction = PlanetFunction.Military; | |
if (myOptionalModifierFlag) | |
{ | |
fnAddIncompatibleStarport(Starport.None); | |
myStarportModifier += 3; | |
myTechLevelModifier += 2; | |
} | |
} | |
else if (myPercentile >= 43 && myPercentile <= 46) | |
{ | |
myPlanetFunction = PlanetFunction.Mining; | |
if (myOptionalModifierFlag) | |
{ | |
myStarportModifier += 2; | |
myTechLevelModifier++; | |
} | |
} | |
else if (myPercentile >= 51 && myPercentile <= 55) | |
{ | |
myPlanetFunction = PlanetFunction.Natural_Resources; | |
} | |
else if (myPercentile >= 56 && myPercentile <= 63) | |
{ | |
myPlanetFunction = PlanetFunction.Service; | |
if (myOptionalModifierFlag) | |
{ | |
fnAddIncompatibleStarport(Starport.None); | |
fnAddIncompatibleStarport(Starport.Small_Craft); | |
myStarportModifier++; | |
myTechLevelModifier += 2; | |
} | |
} | |
else if (myPercentile >= 64 && myPercentile <= 66) | |
{ | |
myPlanetFunction = PlanetFunction.Trade; | |
if (myOptionalModifierFlag) | |
{ | |
fnAddIncompatibleStarport(Starport.None); | |
fnAddIncompatibleStarport(Starport.Small_Craft); | |
myStarportModifier += 3; | |
myTechLevelModifier += 2; | |
} | |
} | |
else | |
{ | |
myPlanetFunction = PlanetFunction.Natural_Resources; | |
} | |
return myPlanetFunction; | |
} | |
PlanetType fnGetPlanetType() | |
{ | |
// roll 2 six-sided dice | |
var myRoll = fnRollDice(2); | |
PlanetType myPlanetType; | |
if (myRoll >= 2 && myRoll <= 9) | |
{ | |
myPlanetType = PlanetType.Terrestrial; | |
} | |
else if (myRoll == 10) | |
{ | |
myPlanetType = PlanetType.Satellite; | |
} | |
else if (myRoll == 11) | |
{ | |
myPlanetType = PlanetType.Asteroid_Belt; | |
if (myOptionalModifierFlag) | |
{ | |
myPopulationModifier -= 2; | |
} | |
} | |
else | |
{ | |
myPlanetType = PlanetType.Artificial; | |
if (myOptionalModifierFlag) | |
{ | |
myPopulationModifier -= 2; | |
} | |
} | |
// check for incompatible types | |
// myIncompatibleTypes | |
var myLength = myIncompatibleTypes.Count; | |
for (var i = 0; i < myLength; i++) | |
{ | |
if (myPlanetType == myIncompatibleTypes[i]) | |
{ | |
//alert("incompatible planet type = " + myPlanetType); | |
myPlanetType = fnGetPlanetType(); | |
break; | |
} | |
} | |
return myPlanetType; | |
} | |
int fnGetLengthOfDay() | |
{ | |
/* | |
// roll 1 six-sided dice | |
var myRoll = fnRollDice(1); | |
var myRoll2 = 0; | |
var myLengthOfDay = 0; | |
if (myRoll >= 1 && myRoll <= 2) | |
{ | |
myRoll2 = fnRollDice(2); | |
myLengthOfDay = myRoll2 + 10; | |
} | |
else if (myRoll >= 3 && myRoll <= 4) | |
{ | |
myRoll2 = fnRollDice(1); | |
myLengthOfDay = myRoll2 + 20; | |
} | |
else if (myRoll == 5) | |
{ | |
myRoll2 = fnRollDice(1); | |
myLengthOfDay = myRoll2 + 25; | |
} | |
else if (myRoll == 6) | |
{ | |
myRoll2 = fnRollDice(1); | |
myLengthOfDay = myRoll2 + 30; | |
} | |
*/ | |
int Weighted = new Range(1, 6); | |
switch (Weighted) | |
{ | |
case 1: | |
case 2: | |
case 3: | |
return new Range(20, 30); //myNumber; | |
case 4: | |
return new Range(10, 20); //myNumber; | |
case 5: | |
return new Range(25, 35); //myNumber; | |
case 6: | |
return new Range(10, 35); //myNumber; | |
default: | |
return new Range(25, 30); //myNumber; | |
} | |
//return myLengthOfDay; | |
} | |
int fnGetLengthOfYear() | |
{ | |
/* | |
// roll 1 six-sided dice | |
var myRoll = fnRollDice(1); | |
var myRoll2 = fnRollDice(1); | |
var myDays = 0; | |
var myNumber = 0; | |
if (myRoll2 == 1) | |
{ | |
myDays = 75; | |
} | |
else if (myRoll2 == 2) | |
{ | |
myDays = 150; | |
} | |
else if (myRoll2 >= 3 && myRoll <= 4) | |
{ | |
myDays = 225; | |
} | |
else if (myRoll2 == 5) | |
{ | |
myDays = 300; | |
} | |
else if (myRoll2 == 6) | |
{ | |
myDays = 375; | |
} | |
myNumber = (myRoll * 15) + myDays; | |
*/ | |
int Weighted = new Range(1, 6); | |
switch (Weighted) | |
{ | |
case 1: | |
case 2: | |
case 3: | |
case 4: | |
return new Range(250, 450); //myNumber; | |
case 5: | |
return new Range(100, 250); //myNumber; | |
case 6: | |
return new Range(250, 500); //myNumber; | |
default: | |
return new Range(100, 450); //myNumber; | |
} | |
} | |
BigInteger fnGetPopulation() | |
{ | |
var myRoll = fnRollDice(1); | |
var myRoll2 = fnRollDice(1); | |
var myRoll3 = fnGetRandomNumber(1, 9); | |
var myNumber = myRoll + myPopulationModifier; | |
BigInteger myBasicPopulation = 0; | |
BigInteger myPopulationRange = 0; | |
BigInteger myPopulation = 0; | |
// make sure the number is between 1 and 6 | |
if (myNumber > 6) | |
{ | |
myNumber = 6; | |
} | |
else if (myNumber < 1) | |
{ | |
myNumber = 1; | |
} | |
if (myNumber == 1) | |
{ | |
myBasicPopulation = 100; | |
} | |
else if (myNumber == 2) | |
{ | |
myBasicPopulation = 1000; | |
} | |
else if (myNumber >= 3 && myNumber <= 4) | |
{ | |
myBasicPopulation = 1000000; | |
} | |
else if (myNumber >= 5 && myNumber <= 6) | |
{ | |
myBasicPopulation = 1000000000; | |
} | |
if (myRoll2 == 1) | |
{ | |
myPopulationRange = 1; | |
} | |
if (myRoll2 >= 2 && myRoll2 <= 5) | |
{ | |
myPopulationRange = 10; | |
} | |
if (myRoll2 == 6) | |
{ | |
myPopulationRange = 100; | |
} | |
myPopulation = myBasicPopulation * myPopulationRange * myRoll3; | |
if (myPopulation == 0) | |
{ | |
//alert("myPopulation is 0"); | |
} | |
if (myPopulation < 100000) | |
RateOfChangeForPopulaton = new Percentage( DRange.Range(-4, 8)); | |
else if (myPopulation < 1000000000) | |
RateOfChangeForPopulaton = new Percentage( DRange.Range(-1, 3)); | |
else | |
RateOfChangeForPopulaton = new Percentage( DRange.Range(-0.2, 1.5)); | |
return myPopulation; | |
} | |
Starport fnGetStarport() | |
{ | |
// roll 2 six-sided dice | |
var myRoll = new Range(1, 18); | |
var myNumber = myRoll + myStarportModifier; | |
Starport myStarport = Starport.None; | |
// make sure the number is not greater than 12 | |
if (myNumber > 18) | |
{ | |
myNumber = 18; | |
} | |
else if (myNumber < 2) | |
{ | |
myNumber = 2; | |
} | |
if (myNumber >= 2 && myNumber <= 7) | |
{ | |
myStarport = Starport.Small_Craft; | |
} | |
else if (myNumber >= 8 && myNumber <= 12) | |
{ | |
myStarport = Starport.Standard_class; | |
} | |
else if (myNumber >= 13 && myNumber <= 15) | |
{ | |
myStarport = Starport.Stellar_class; | |
} | |
else if (myNumber == 16) | |
{ | |
myStarport = Starport.Imperial_class; | |
} | |
else if (myNumber == 17) | |
{ | |
myStarport = Starport.Galactic_class; | |
} | |
var myLength = myIncompatibleStarport.Count; | |
for (var i = 0; i < myLength; i++) | |
{ | |
if (myStarport == myIncompatibleStarport[i]) | |
{ | |
//alert("incompatible temperature = " + myTemperature); | |
myStarport = fnGetStarport(); | |
break; | |
} | |
} | |
if (myStarport == Starport.None) | |
WorkingRateOfStarport = 0; | |
if (myStarport == Starport.Small_Craft) | |
{ | |
if (Population <= 1000) | |
WorkingRateOfStarport = getWR(70, 110); | |
if (Population > 1000) | |
WorkingRateOfStarport = getWR(90, 130); | |
if (Population > 1000000) | |
WorkingRateOfStarport = getWR(95, 180); | |
} | |
if (myStarport == Starport.Standard_class) | |
{ | |
if (Population <= 1000) | |
WorkingRateOfStarport = getWR(40, 70); | |
if (Population > 1000) | |
WorkingRateOfStarport = getWR(50, 80); | |
if (Population > 100000) | |
WorkingRateOfStarport = getWR(80, 130); | |
if (Population > 1000000) | |
WorkingRateOfStarport = getWR(80, 190); | |
if (Population > 100000000) | |
WorkingRateOfStarport = getWR(100, 100); | |
} | |
if (myStarport == Starport.Stellar_class) | |
{ | |
if (Population <= 1000) | |
WorkingRateOfStarport = getWR(0, 20); | |
if (Population > 1000) | |
WorkingRateOfStarport = getWR(0, 40); | |
if (Population > 100000) | |
WorkingRateOfStarport = getWR(40, 120); | |
if (Population > 10000000) | |
WorkingRateOfStarport = getWR(80, 120); | |
if (Population > 1000000000) | |
WorkingRateOfStarport = getWR(95, 200); | |
} | |
if (myStarport == Starport.Imperial_class) | |
{ | |
if (Population <= 1000) | |
WorkingRateOfStarport = getWR(0, 0); | |
if (Population > 1000) | |
WorkingRateOfStarport = getWR(0, 20); | |
if (Population > 1000000) | |
WorkingRateOfStarport = getWR(60, 130); | |
if (Population > 10000000) | |
WorkingRateOfStarport = getWR(80, 130); | |
if (Population > 1000000000) | |
WorkingRateOfStarport = getWR(95, 200); | |
} | |
if (myStarport == Starport.Galactic_class) | |
{ | |
if (Population <= 1000) | |
WorkingRateOfStarport = getWR(0, 0); | |
if (Population > 1000) | |
WorkingRateOfStarport = getWR(0, 0); | |
if (Population > 10000000) | |
WorkingRateOfStarport = getWR(40, 80); | |
if (Population > 1000000000) | |
WorkingRateOfStarport = getWR(60, 130); | |
if (Population > 10000000000) | |
WorkingRateOfStarport = getWR(95, 2000); | |
} | |
//ports loose .5 to 4% working rate a week | |
//smaller ports = easier to fix | |
if (myStarport == Starport.None) | |
MantanceRateOfStarport = 0; | |
if (myStarport == Starport.Small_Craft) | |
{ | |
if (Population <= 1000) | |
MantanceRateOfStarport = getWR(1, 5); | |
if (Population > 1000) | |
MantanceRateOfStarport = getWR(2, 6); | |
if (Population > 1000000) | |
MantanceRateOfStarport = getWR(3, 10); | |
} | |
if (myStarport == Starport.Standard_class) | |
{ | |
if (Population <= 1000) | |
MantanceRateOfStarport = getWR(0, 3); | |
if (Population > 1000) | |
MantanceRateOfStarport = getWR(1, 3); | |
if (Population > 100000) | |
MantanceRateOfStarport = getWR(2, 3); | |
if (Population > 1000000) | |
MantanceRateOfStarport = getWR(3, 5); | |
if (Population > 100000000) | |
MantanceRateOfStarport = getWR(4, 10); | |
} | |
if (myStarport == Starport.Stellar_class) | |
{ | |
if (Population <= 1000) | |
MantanceRateOfStarport = getWR(0, 0); | |
if (Population > 1000) | |
MantanceRateOfStarport = getWR(0, 1); | |
if (Population > 100000) | |
MantanceRateOfStarport = getWR(1, 3); | |
if (Population > 10000000) | |
MantanceRateOfStarport = getWR(2, 5); | |
if (Population > 1000000000) | |
MantanceRateOfStarport = getWR(3, 5); | |
} | |
if (myStarport == Starport.Imperial_class) | |
{ | |
if (Population <= 1000) | |
MantanceRateOfStarport = getWR(0, 0); | |
if (Population > 1000) | |
MantanceRateOfStarport = getWR(0, 0); | |
if (Population > 1000000) | |
MantanceRateOfStarport = getWR(0, 2); | |
if (Population > 10000000) | |
MantanceRateOfStarport = getWR(1, 3); | |
if (Population > 1000000000) | |
MantanceRateOfStarport = getWR(2, 4); | |
} | |
if (myStarport == Starport.Galactic_class) | |
{ | |
if (Population <= 1000) | |
MantanceRateOfStarport = getWR(0, 0); | |
if (Population > 1000) | |
MantanceRateOfStarport = getWR(0, 0); | |
if (Population > 10000000) | |
MantanceRateOfStarport = getWR(1, 1); | |
if (Population > 1000000000) | |
MantanceRateOfStarport = getWR(1, 3); | |
if (Population > 10000000000) | |
MantanceRateOfStarport = getWR(2, 4); | |
} | |
return myStarport; | |
} | |
private int getWR(int min, int Max) | |
{ | |
int Rate = new Range(min, Max); | |
if (Rate > 100) | |
Rate = 100; | |
if (Rate < 0) | |
Rate = 0; | |
return Rate; | |
} | |
public static string fnGetName() | |
{ | |
string[] name1 = new string[] { "Ad", "Al", "Ash", "Ar", "Bah", "Bes", "Both", "Can", "Cor", "Cuh", "Dan", "Day", "En", "Gam", "Kash", "Mand", "Na", "Ro", "Ry", "Sern", "Sull", "Tant", "Tran", "Tund", "Varl", "Ya" }; | |
string[] name2 = new string[] { "a", "boo", "brill", "brin", "do", "ee", "el", "go", "id", "is", "or", "ou", "pi", "si", "ti", "us", "ust" }; | |
string[] name3 = new string[] { "aan", "aari", "bah", "cant", "dal", "dor", "dra", "ine", "ion", "ious", "lag", "lia", "lore", "loth", "mir", "pin", "sha", "vin", "wui", "yyyk" }; | |
string GenedName; | |
do | |
{ | |
int whichname1 = new Range(0, name1.Length - 1); | |
int whichname2 = new Range(0, name2.Length - 1); ; | |
int whichname3 = new Range(0, name3.Length - 1); ; | |
GenedName = name1[whichname1] + name2[whichname2] + name3[whichname3]; | |
//alert(name1[whichname1]+name2[whichname2]+name3[whichname3]); | |
} while (Generate.UsedNames.Contains(GenedName)); | |
return GenedName; | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment