Skip to content

Commit

Permalink
Strata.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarkonnen committed Mar 6, 2012
1 parent 3deaf06 commit 8265b00
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 42 deletions.
16 changes: 9 additions & 7 deletions src/com/zarkonnen/spacegen/Cataclysm.java
@@ -1,16 +1,18 @@
package com.zarkonnen.spacegen;

public enum Cataclysm {
NOVA("The star of $name goes nova, scraping the planet clean of all life!"),
VOLCANIC_ERUPTIONS("Massive volcanic eruptions on $name eradicate all life on the planet!"),
AXIAL_SHIFT("A shift in the orbital axis of $name spells doom for all life on the planet!"),
METEORITE_IMPACT("All life on $name is killed off by a massive asteroid impact!"),
NANOFUNGAL_BLOOM("A nanofungal bloom consumes all other life on $name before itself dying from a lack of nutrients!"),
PSIONIC_SHOCKWAVE("A psionic shockwave of unknown origin passes through $name, instantly stopping all life!");
NOVA("nova", "The star of $name goes nova, scraping the planet clean of all life!"),
VOLCANIC_ERUPTIONS("series of volcanic eruptions", "Massive volcanic eruptions on $name eradicate all life on the planet!"),
AXIAL_SHIFT("shift in the planet's orbital axis", "A shift in the orbital axis of $name spells doom for all life on the planet!"),
METEORITE_IMPACT("massive asteroid impact", "All life on $name is killed off by a massive asteroid impact!"),
NANOFUNGAL_BLOOM("nanofungal bloom", "A nanofungal bloom consumes all other life on $name before itself dying from a lack of nutrients!"),
PSIONIC_SHOCKWAVE("psionic shockwave", "A psionic shockwave of unknown origin passes through $name, instantly stopping all life!");

final String name;
final String desc;

private Cataclysm(String desc) {
private Cataclysm(String name, String desc) {
this.name = name;
this.desc = desc;
}
}
21 changes: 17 additions & 4 deletions src/com/zarkonnen/spacegen/Civ.java
Expand Up @@ -9,16 +9,29 @@ public class Civ {

int resources = 0;
int science = 0;
String name;

public Civ(SentientType st, Planet home, Government govt, int resources) {
public Civ(SentientType st, Planet home, Government govt, int resources, ArrayList<Civ> historicals) {
this.govt = govt;
this.fullMembers.add(st);
this.colonies.add(home);
this.resources = resources;
int nth = 0;
lp: while (true) {
nth++;
String n = genName(nth);
for (Civ c : historicals) {
if (c.name.equals(n)) { continue lp; }
}
name = n;
break;
}
}

public String name() {
String n = govt.name + " of ";

final String genName(int nth) {
String n = "";
if (nth > 1) { n = Names.nth(nth) + " "; }
n += govt.title + " of ";
for (int i = 0; i < fullMembers.size(); i++) {
if (i > 0) {
if (i == fullMembers.size() - 1) {
Expand Down
22 changes: 22 additions & 0 deletions src/com/zarkonnen/spacegen/Fossil.java
@@ -0,0 +1,22 @@
package com.zarkonnen.spacegen;

public class Fossil implements Stratum {
SpecialLifeform fossil;
int fossilisationTime;
Cataclysm cat;

public Fossil(SpecialLifeform fossil, int fossilisationTime, Cataclysm cat) {
this.fossil = fossil;
this.fossilisationTime = fossilisationTime;
this.cat = cat;
}

@Override
public String toString() {
return "Fossils of " + fossil.name.toLowerCase() + " that went extinct in " + fossilisationTime +
(cat == null ? "." : " due to a " + cat.name + ".");
}

@Override
public int time() { return fossilisationTime; }
}
12 changes: 9 additions & 3 deletions src/com/zarkonnen/spacegen/Government.java
Expand Up @@ -5,23 +5,29 @@
public enum Government {
DICTATORSHIP(
"Military Dictatorship",
"Empire",
EXPLORE_PLANET, EXPLORE_PLANET, COLONISE_PLANET, BUILD_SCIENCE_OUTPOST, BUILD_MINING_BASE, BUILD_MILITARY_BASE, BUILD_MILITARY_BASE, BUILD_MILITARY_BASE, DO_RESEARCH, BUILD_WARSHIPS, BUILD_WARSHIPS, BUILD_WARSHIPS, BUILD_CONSTRUCTION),
THEOCRACY(
"Theocracy",
"Church",
EXPLORE_PLANET, COLONISE_PLANET, COLONISE_PLANET, COLONISE_PLANET, BUILD_MINING_BASE, BUILD_MILITARY_BASE, BUILD_MILITARY_BASE, BUILD_WARSHIPS, BUILD_CONSTRUCTION, BUILD_CONSTRUCTION),
FEUDAL_STATE(
"Feudal State",
"Kingdom",
EXPLORE_PLANET, COLONISE_PLANET, COLONISE_PLANET, BUILD_MINING_BASE, BUILD_MILITARY_BASE, DO_RESEARCH, BUILD_WARSHIPS, BUILD_WARSHIPS, BUILD_CONSTRUCTION),
REPUBLIC(
"Republic",
"Republic",
EXPLORE_PLANET, COLONISE_PLANET, BUILD_MINING_BASE, BUILD_MINING_BASE, BUILD_MILITARY_BASE, BUILD_SCIENCE_OUTPOST, DO_RESEARCH, BUILD_WARSHIPS, BUILD_CONSTRUCTION, BUILD_CONSTRUCTION);

final String name;
final String typeName;
final String title;
final CivAction[] behaviour;

private Government(String name, CivAction... behaviour) {
this.name = name;
private Government(String name, String title, CivAction... behaviour) {
this.typeName = name;
this.behaviour = behaviour;
this.title = title;
}


Expand Down
15 changes: 15 additions & 0 deletions src/com/zarkonnen/spacegen/Names.java
@@ -0,0 +1,15 @@
package com.zarkonnen.spacegen;

public class Names {
static final String[] NTHS = {"Zeroth", "First", "Second", "Third", "Fourth", "Fifth", "Sixth",
"Seventh", "Eigth", "Ninth", "Tenth", "Eleventh", "Twelfth", "Thirteenth", "Fourteenth"};

static String nth(int n) {
if (n < NTHS.length) { return NTHS[n]; }
return n + ".";
}

static final String[] COLORS = { "Red", "Green", "Blue", "Orange", "Yellow", "Black", "White",
"Purple", "Grey"
};
}
88 changes: 85 additions & 3 deletions src/com/zarkonnen/spacegen/Planet.java
Expand Up @@ -15,10 +15,47 @@ public class Planet {
Civ owner;
ArrayList<Structure> structures = new ArrayList<Structure>();

ArrayList<Stratum> strata = new ArrayList<Stratum>();

public void dePop(Population pop, int time, Cataclysm cat) {
strata.add(new Remnant(pop, time, cat));
inhabitants.remove(pop);
}

public void deCiv(int time, Cataclysm cat) {
if (owner == null) { return; }
owner.colonies.remove(this);
owner = null;
for (Population p : new ArrayList<Population>(inhabitants)) {
dePop(p, time, cat);
}
for (Structure s : structures) {
strata.add(new Ruin(s, time, cat));
}
structures.clear();
}

public void deLive(int time, Cataclysm cat) {
deCiv(time, cat);
evoPoints = 0;
for (SpecialLifeform slf : lifeforms) {
strata.add(new Fossil(slf, time, cat));
}
lifeforms.clear();
habitable = false;
}

public Planet(Random r) {
this.name = getName(Math.abs(r.nextInt()));
}

public boolean has(StructureType st) {
for (Structure s : structures) {
if (s.type == st) { return true; }
}
return false;
}

static String getName(int p) {
return new String(new char[] {
(char) ('A' + (p + 5) % 7),
Expand All @@ -30,9 +67,9 @@ static String getName(int p) {
}

boolean isOutpost() {
return structures.contains(Structure.MILITARY_BASE) ||
structures.contains(Structure.SCIENCE_LABS) ||
structures.contains(Structure.MINING_BASE);
return has(StructureType.MILITARY_BASE) ||
has(StructureType.SCIENCE_LAB) ||
has(StructureType.MINING_BASE);
}

int population() {
Expand All @@ -42,4 +79,49 @@ int population() {
}
return sum;
}


public String fullDesc() {
StringBuilder sb = new StringBuilder(name.toUpperCase() + "\n");
sb.append("A ").append(habitable ? "life-bearing " : "barren ").append("planet");
if (owner != null) {
sb.append(" of the ").append(owner.name);
}
sb.append(".\n");
if (pollution > 0) {
sb.append("It is ");
switch (pollution) {
case 1: sb.append("a little"); break;
case 2: sb.append("slightly"); break;
case 3: sb.append("somewhat"); break;
case 4: sb.append("heavily"); break;
case 5: sb.append("very heavily"); break;
default: sb.append("incredibly"); break;
}
sb.append(" polluted.\n");
}
if (inhabitants.size() > 0) {
sb.append("It is populated by:\n");
for (Population p : inhabitants) {
sb.append(p).append("\n");
}
}
for (PlanetSpecial ps : specials) {
sb.append(ps.explanation).append("\n");
}
if (!lifeforms.isEmpty()) {
sb.append("Lifeforms of note:\n");
}
for (SpecialLifeform ps : lifeforms) {
sb.append(ps.name).append(": ").append(ps.desc).append("\n");
}
if (!strata.isEmpty()) {
sb.append("Strata:\n");
for (int i = strata.size() - 1; i >= 0; i--) {
sb.append(strata.get(i)).append("\n");
}
}

return sb.toString();
}
}
5 changes: 5 additions & 0 deletions src/com/zarkonnen/spacegen/Population.java
Expand Up @@ -8,4 +8,9 @@ public Population(SentientType type, int size) {
this.type = type;
this.size = size;
}

@Override
public String toString() {
return size + " billion " + type.name;
}
}
22 changes: 22 additions & 0 deletions src/com/zarkonnen/spacegen/Remnant.java
@@ -0,0 +1,22 @@
package com.zarkonnen.spacegen;

public class Remnant implements Stratum {
Population remnant;
int collapseTime;
Cataclysm cat;

public Remnant(Population remnant, int extinctionTime, Cataclysm cat) {
this.remnant = remnant;
this.collapseTime = extinctionTime;
this.cat = cat;
}

@Override
public String toString() {
return "Remnants of a culture of " + remnant.type.name + " that collapsed" +
(cat == null ? "" : " due to a " + cat.name) + " in " + collapseTime + ".";
}

@Override
public int time() { return collapseTime; }
}
22 changes: 22 additions & 0 deletions src/com/zarkonnen/spacegen/Ruin.java
@@ -0,0 +1,22 @@
package com.zarkonnen.spacegen;

public class Ruin implements Stratum {
Structure structure;
int ruinTime;
Cataclysm cat;

public Ruin(Structure structure, int ruinTime, Cataclysm cat) {
this.structure = structure;
this.ruinTime = ruinTime;
this.cat = cat;
}

@Override
public int time() { return ruinTime; }

@Override
public String toString() {
return "The ruins of a " + structure + ", destroyed in " + ruinTime +
(cat == null ? "." : " by a " + cat.name + ".");
}
}

0 comments on commit 8265b00

Please sign in to comment.