public Planet(string name, Random r, StarSystem system)
{
_populationMax = r.Next(0, 150) - 25;
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.AVERAGE;
EnvironmentBonus = PLANET_ENVIRONMENT_BONUS.AVERAGE;
ResearchBonus = PLANET_RESEARCH_BONUS.AVERAGE;
int randomNum = r.Next(100);
var color = system.Color;
string type = string.Empty;
if (color == Color.Red)
{
//TODO: Handle nebula generation
if (randomNum < 5)
{
type = NONE;
}
else if (randomNum < 10)
{
type = RADIATED;
}
else if (randomNum < 15)
{
type = TOXIC;
}
else if (randomNum < 20)
{
type = VOLCANIC;
}
else if (randomNum < 25)
{
type = DEAD;
}
else if (randomNum < 30)
{
type = TUNDRA;
}
else if (randomNum < 35)
{
type = BARREN;
}
else if (randomNum < 40)
{
type = ARCTIC;
}
else if (randomNum < 50)
{
type = DESERT;
}
else if (randomNum < 60)
{
type = STEPPE;
}
else if (randomNum < 75)
{
type = BADLANDS;
}
else if (randomNum < 85)
{
type = OCEANIC;
}
else if (randomNum < 95)
{
type = JUNGLE;
}
else
{
type = TERRAN;
}
}
else if (color == Color.Green)
{
//TODO: Handle nebula generation
if (randomNum < 5)
{
type = NONE;
}
else if (randomNum < 10)
{
type = RADIATED;
}
else if (randomNum < 15)
{
type = TOXIC;
}
else if (randomNum < 20)
{
type = VOLCANIC;
}
else if (randomNum < 25)
{
type = DEAD;
}
else if (randomNum < 30)
{
type = TUNDRA;
}
else if (randomNum < 35)
{
type = BARREN;
}
else if (randomNum < 40)
{
type = ARCTIC;
}
else if (randomNum < 45)
{
type = DESERT;
}
else if (randomNum < 55)
{
type = STEPPE;
}
else if (randomNum < 65)
{
type = BADLANDS;
}
else if (randomNum < 75)
{
type = OCEANIC;
}
else if (randomNum < 85)
{
type = JUNGLE;
}
else
{
type = TERRAN;
}
}
else if (color == Color.Yellow)
{
//TODO: Handle nebula generation
if (randomNum < 5)
{
type = VOLCANIC;
}
else if (randomNum < 10)
{
type = TUNDRA;
}
else if (randomNum < 15)
{
type = BARREN;
}
else if (randomNum < 20)
{
type = ARCTIC;
}
else if (randomNum < 25)
{
type = DESERT;
}
else if (randomNum < 30)
{
type = STEPPE;
}
else if (randomNum < 40)
{
type = BADLANDS;
}
else if (randomNum < 50)
{
type = OCEANIC;
}
else if (randomNum < 60)
{
type = JUNGLE;
}
else
{
type = TERRAN;
}
}
else if (color == Color.Blue)
{
//TODO: Handle nebula generation
if (randomNum < 15)
{
type = NONE;
}
else if (randomNum < 25)
{
type = RADIATED;
}
else if (randomNum < 35)
{
type = TOXIC;
}
else if (randomNum < 45)
{
type = VOLCANIC;
}
else if (randomNum < 55)
{
type = DEAD;
}
else if (randomNum < 65)
{
type = TUNDRA;
}
else if (randomNum < 75)
{
type = BARREN;
}
else if (randomNum < 85)
{
type = ARCTIC;
}
else if (randomNum < 90)
{
type = DESERT;
}
else if (randomNum < 95)
{
type = STEPPE;
}
else
{
type = BADLANDS;
}
}
else if (color == Color.White)
{
//TODO: Handle nebula generation
if (randomNum < 10)
{
type = NONE;
}
else if (randomNum < 20)
{
type = RADIATED;
}
else if (randomNum < 30)
{
type = TOXIC;
}
else if (randomNum < 40)
{
type = VOLCANIC;
}
else if (randomNum < 50)
{
type = DEAD;
}
else if (randomNum < 60)
{
type = TUNDRA;
}
else if (randomNum < 70)
{
type = BARREN;
}
else if (randomNum < 80)
{
type = ARCTIC;
}
else if (randomNum < 85)
{
type = DESERT;
}
else if (randomNum < 90)
{
type = STEPPE;
}
else if (randomNum < 95)
{
type = BADLANDS;
}
else
{
type = OCEANIC;
}
}
else
{
//TODO: Handle nebula generation
if (randomNum < 20)
{
type = NONE;
}
else if (randomNum < 45)
{
type = RADIATED;
}
else if (randomNum < 60)
{
type = TOXIC;
}
else if (randomNum < 75)
{
type = VOLCANIC;
}
else if (randomNum < 85)
{
type = DEAD;
}
else if (randomNum < 90)
{
type = TUNDRA;
}
else if (randomNum < 95)
{
type = BARREN;
}
else
{
type = ARCTIC;
}
}
switch (type)
{
case NONE:
_populationMax = 0;
break;
case RADIATED:
case TOXIC:
case VOLCANIC:
_populationMax = r.Next(2, 9) * 5;
break;
case DEAD:
case TUNDRA:
_populationMax = r.Next(4, 11) * 5;
break;
case BARREN:
case ARCTIC:
_populationMax = r.Next(6, 11) * 5;
break;
case DESERT:
_populationMax = r.Next(7, 11) * 5;
break;
case STEPPE:
_populationMax = r.Next(9, 13) * 5;
break;
case BADLANDS:
_populationMax = r.Next(11, 15) * 5;
break;
case OCEANIC:
_populationMax = r.Next(13, 17) * 5;
break;
case JUNGLE:
_populationMax = r.Next(15, 19) * 5;
break;
case TERRAN:
_populationMax = r.Next(17, 21) * 5;
break;
}
//Add some variety to the population size
while (r.Next(100) < 20)
{
if (r.Next(100) < 50)
{
//decrease the population by 20
_populationMax -= 20;
if (_populationMax < 10)
{
_populationMax = 10;
}
}
else
{
//increase the population by 20
_populationMax += 20;
if (_populationMax > 140)
{
_populationMax = 140;
}
}
}
//Now roll for poor/ultra poor if the planet is steppe, badlands, oceanic, jungle, or terran
if (type == STEPPE || type == BADLANDS || type == OCEANIC || type == JUNGLE || type == TERRAN)
{
randomNum = r.Next(1000);
if (system.Color == Color.Blue || system.Color == Color.White || system.Color == Color.Yellow)
{
if (randomNum < 25) //2.5% chance of ultrapoor
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRAPOOR;
}
else if (randomNum < 100) //7.5% chance of poor
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.POOR;
}
}
else if (system.Color == Color.Red)
{
if (randomNum < 60) //6% chance of ultrapoor
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRAPOOR;
}
else if (randomNum < 200) //14% chance of poor
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.POOR;
}
}
else if (system.Color == Color.Green)
{
if (randomNum < 135) //13.5% chance of ultrapoor
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRAPOOR;
}
else if (randomNum < 300) //16.5% chance of poor
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.POOR;
}
}
}
//roll for rich/ultrarich only if the planet is not poor already
if (ConstructionBonus == PLANET_CONSTRUCTION_BONUS.AVERAGE)
{
//todo: handle nebula generation
randomNum = r.Next(10000);
if (type == RADIATED)
{
if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
{
if (randomNum < 875)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 3500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else if (system.Color == Color.Blue)
{
if (randomNum < 1575)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 4500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else //neutron star
{
if (randomNum < 3000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 6000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
}
else if (type == TOXIC)
{
if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
{
if (randomNum < 750)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 3000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else if (system.Color == Color.Blue)
{
if (randomNum < 1400)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 4000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else //neutron star
{
if (randomNum < 2750)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 5500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
}
else if (type == VOLCANIC)
{
if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
{
if (randomNum < 625)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 2500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else if (system.Color == Color.Blue)
{
if (randomNum < 1225)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 3500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else //neutron star
{
if (randomNum < 2500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 5000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
}
else if (type == DEAD)
{
if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
{
if (randomNum < 500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 2000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else if (system.Color == Color.Blue)
{
if (randomNum < 1050)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 3000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else //neutron star
{
if (randomNum < 2250)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 4500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
}
else if (type == TUNDRA)
{
if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
{
if (randomNum < 375)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 1500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else if (system.Color == Color.Blue)
{
if (randomNum < 875)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 2500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else //neutron star
{
if (randomNum < 2000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 4000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
}
else if (type == BARREN)
{
if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
{
if (randomNum < 250)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 1000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else if (system.Color == Color.Blue)
{
if (randomNum < 700)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 2000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else //neutron star
{
if (randomNum < 1750)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 3500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
}
else if (type == ARCTIC)
{
if (system.Color == Color.Red || system.Color == Color.Yellow || system.Color == Color.Green || system.Color == Color.White)
{
if (randomNum < 125)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else if (system.Color == Color.Blue)
{
if (randomNum < 525)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 1500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else //neutron star
{
if (randomNum < 1500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 3000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
}
else if (type == DESERT && system.Color == Color.Blue)
{
if (randomNum < 350)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 1000)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
else if (type == STEPPE && system.Color == Color.Blue)
{
if (randomNum < 175)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.ULTRARICH;
}
else if (randomNum < 500)
{
ConstructionBonus = PLANET_CONSTRUCTION_BONUS.RICH;
}
}
}
//Now determine asteroid density
randomNum = r.Next(100);
if (randomNum < 25) //Always 25% chance of low density, no matter what type/bonus the planet has
{
AsteroidDensity = PLANET_ASTEROID_DENSITY.LOW;
}
else
{
int extraValue = 0;
switch (type)
{
case RADIATED:
extraValue = 12;
break;
case TOXIC:
extraValue = 11;
break;
case VOLCANIC:
extraValue = 10;
break;
case DEAD:
extraValue = 9;
break;
case TUNDRA:
extraValue = 8;
break;
case BARREN:
extraValue = 7;
break;
case ARCTIC:
extraValue = 6;
break;
case DESERT:
extraValue = 5;
break;
case STEPPE:
extraValue = 4;
break;
case BADLANDS:
extraValue = 3;
break;
case OCEANIC:
extraValue = 2;
break;
case JUNGLE:
extraValue = 1;
break;
}
if (ConstructionBonus == PLANET_CONSTRUCTION_BONUS.ULTRARICH)
{
if (randomNum < 62 + extraValue)
{
AsteroidDensity = PLANET_ASTEROID_DENSITY.HIGH;
}
else
{
AsteroidDensity = PLANET_ASTEROID_DENSITY.NONE;
}
}
else if (ConstructionBonus == PLANET_CONSTRUCTION_BONUS.RICH)
{
if (randomNum < 52 + extraValue)
{
AsteroidDensity = PLANET_ASTEROID_DENSITY.HIGH;
}
else
{
AsteroidDensity = PLANET_ASTEROID_DENSITY.NONE;
}
}
else
{
if (randomNum < 42 + extraValue)
{
AsteroidDensity = PLANET_ASTEROID_DENSITY.HIGH;
}
else
{
AsteroidDensity = PLANET_ASTEROID_DENSITY.NONE;
}
}
}
//Now roll for fertility
if (type == DESERT || type == STEPPE || type == BADLANDS || type == OCEANIC || type == JUNGLE || type == TERRAN)
{
randomNum = r.Next(100);
if (randomNum < 9) //original is 1 / 12th, so this is close enough
{
EnvironmentBonus = PLANET_ENVIRONMENT_BONUS.FERTILE;
float value = _populationMax / 5;
value *= 1.25f;
_populationMax = ((int) value) * 5;
if (_populationMax > 140)
{
_populationMax = 140;
}
}
}
else if (type == RADIATED || type == TOXIC || type == VOLCANIC || type == DEAD || type == TUNDRA || type == BARREN)
{
EnvironmentBonus = PLANET_ENVIRONMENT_BONUS.HOSTILE;
}
//Finally, roll for artifacts
if (ConstructionBonus == PLANET_CONSTRUCTION_BONUS.AVERAGE)
{
randomNum = r.Next(100);
if (randomNum < 10) //10% chance of having artifacts
{
ResearchBonus = PLANET_RESEARCH_BONUS.ARTIFACTS;
}
}
SetValues(name, type, _populationMax, system, null, r);
}