diff --git a/src/main/java/electrosphere/server/macro/MacroData.java b/src/main/java/electrosphere/server/macro/MacroData.java index 79309a97..2678b0f2 100644 --- a/src/main/java/electrosphere/server/macro/MacroData.java +++ b/src/main/java/electrosphere/server/macro/MacroData.java @@ -9,6 +9,7 @@ import electrosphere.server.datacell.ServerWorldData; import electrosphere.server.macro.character.Character; import electrosphere.server.macro.character.data.CharacterDataStrings; import electrosphere.server.macro.civilization.Civilization; +import electrosphere.server.macro.civilization.CivilizationGenerator; import electrosphere.server.macro.race.Race; import electrosphere.server.macro.race.RaceMap; import electrosphere.server.macro.spatial.MacroAreaObject; @@ -18,6 +19,8 @@ import electrosphere.util.FileUtils; import java.util.Random; +import org.joml.Vector3d; + /** * Server macro level data */ @@ -65,6 +68,7 @@ public class MacroData { // rVal.characters.add(diety); // CharacterService.createCharacter(null, i); // } + //generate initial races if(Globals.gameConfigCurrent.getRaceMap().getRaces().size() < 3){ @@ -82,6 +86,9 @@ public class MacroData { rVal.races.add(raceToAdd); } } + + //init civilizations + CivilizationGenerator.generate(serverWorldData, rVal, Globals.gameConfigCurrent); //add a test character // Character testChar = new Character(); @@ -175,10 +182,13 @@ public class MacroData { /** * Adds a civilization - * @param civilization The civilization + * @param race the race founding the civilization */ - public void addCivilization(Civilization civilization){ - civilizations.add(civilization); + public Civilization addCivilization(Race race){ + Civilization civ = new Civilization(); + civ.setId(civilizations.size()); + civilizations.add(civ); + return civ; } /** @@ -191,10 +201,14 @@ public class MacroData { /** * Adds a town - * @param town The town + * @param center The center point of the town + * @param radius The radius of the town */ - public void addTown(Town town){ - towns.add(town); + public Town addTown(Vector3d center, double radius){ + Town rVal = Town.createTown(center, radius); + rVal.setId(towns.size()); + towns.add(rVal); + return rVal; } /** diff --git a/src/main/java/electrosphere/server/macro/civilization/Civilization.java b/src/main/java/electrosphere/server/macro/civilization/Civilization.java index 8711ce4d..06037386 100644 --- a/src/main/java/electrosphere/server/macro/civilization/Civilization.java +++ b/src/main/java/electrosphere/server/macro/civilization/Civilization.java @@ -1,5 +1,101 @@ package electrosphere.server.macro.civilization; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; + +import electrosphere.engine.Globals; +import electrosphere.server.macro.MacroData; +import electrosphere.server.macro.town.Town; +import electrosphere.server.macro.character.Character; + +/** + * A civilization + */ public class Civilization { + /** + * The id of the civilization + */ + private int id; + + /** + * The name of the civilization + */ + private String name; + + /** + * The towns that are a a part of this civilization + */ + private List towns = new LinkedList(); + + /** + * The citizens of the civilization + */ + private List citizens = new LinkedList(); + + /** + * Gets the id of the civilization + * @return The id + */ + public int getId() { + return id; + } + + /** + * Sets the id of the civilization + * @param id The id + */ + public void setId(int id) { + this.id = id; + } + + /** + * Gets the name of the civilization + * @return The name + */ + public String getName() { + return name; + } + + /** + * Sets the name of the civilization + * @param name The name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets the list of towns that are a part of this civilization + * @return The list of towns + */ + public List getTowns(MacroData macroData){ + return towns.stream().map((Integer id) -> macroData.getTown(id)).filter((Town town) -> town != null).collect(Collectors.toList()); + } + + /** + * Adds a town to the civilization + * @param town The town + */ + public void addTown(Town town){ + this.towns.add(town.getId()); + } + + /** + * Gets the list of citizens of this civilization + * @return The list of citizens + */ + public List getCitizens(MacroData macroData){ + return citizens.stream().map((Integer id) -> Globals.serverState.characterService.getCharacter(id)).filter((Character chara) -> chara != null).collect(Collectors.toList()); + } + + /** + * Adds a citizens of the civilization + * @param chara The character + */ + public void addCitizen(Character chara){ + this.citizens.add(chara.getId()); + } + } diff --git a/src/main/java/electrosphere/server/macro/civilization/CivilizationGenerator.java b/src/main/java/electrosphere/server/macro/civilization/CivilizationGenerator.java new file mode 100644 index 00000000..120d2c31 --- /dev/null +++ b/src/main/java/electrosphere/server/macro/civilization/CivilizationGenerator.java @@ -0,0 +1,38 @@ +package electrosphere.server.macro.civilization; + +import org.joml.Vector3d; + +import electrosphere.data.Config; +import electrosphere.server.datacell.ServerWorldData; +import electrosphere.server.macro.MacroData; +import electrosphere.server.macro.race.Race; +import electrosphere.server.macro.town.Town; +import electrosphere.server.physics.terrain.manager.ServerTerrainChunk; + +/** + * Generates civilizations + */ +public class CivilizationGenerator { + + /** + * Initial radius of the town + */ + static final double INITIAL_TOWN_RADIUS = 100; + + /** + * Generates the civilizations for the macro data + * @param serverWorldData The server world data + * @param macroData The macro data + * @param config The config + */ + public static void generate(ServerWorldData serverWorldData, MacroData macroData, Config config){ + //TODO: spread out and don't just put at global spawn point + Vector3d spawnPoint = new Vector3d(serverWorldData.getWorldSizeDiscrete() * ServerTerrainChunk.CHUNK_PLACEMENT_OFFSET / 2); + for(Race race : config.getRaceMap().getRaces()){ + Civilization newCiv = macroData.addCivilization(race); + Town startingTown = macroData.addTown(spawnPoint, INITIAL_TOWN_RADIUS); + newCiv.addTown(startingTown); + } + } + +} diff --git a/src/main/java/electrosphere/server/macro/civilization/model/CivilizationMap.java b/src/main/java/electrosphere/server/macro/civilization/model/CivilizationMap.java deleted file mode 100644 index 623cd250..00000000 --- a/src/main/java/electrosphere/server/macro/civilization/model/CivilizationMap.java +++ /dev/null @@ -1,5 +0,0 @@ -package electrosphere.server.macro.civilization.model; - -public class CivilizationMap { - -} diff --git a/src/main/java/electrosphere/server/macro/town/Town.java b/src/main/java/electrosphere/server/macro/town/Town.java index 92f269f4..04623a05 100644 --- a/src/main/java/electrosphere/server/macro/town/Town.java +++ b/src/main/java/electrosphere/server/macro/town/Town.java @@ -1,11 +1,14 @@ package electrosphere.server.macro.town; +import electrosphere.engine.Globals; +import electrosphere.server.macro.MacroData; import electrosphere.server.macro.character.Character; import electrosphere.server.macro.spatial.MacroAreaObject; import electrosphere.server.macro.structure.VirtualStructure; import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; import org.joml.AABBd; import org.joml.Vector3d; @@ -38,12 +41,12 @@ public class Town implements MacroAreaObject { /** * The structures inside the town */ - private List structures = new LinkedList(); + private List structures = new LinkedList(); /** * The residents of the town */ - private List residents = new LinkedList(); + private List residents = new LinkedList(); /** * The list of jobs queued in the town @@ -76,15 +79,15 @@ public class Town implements MacroAreaObject { * @param structure The structure */ public void addStructure(VirtualStructure structure){ - structures.add(structure); + structures.add(structure.getId()); } /** * Gets the structures that are a part of the town * @return The list of structures */ - public List getStructures(){ - return structures; + public List getStructures(MacroData macroData){ + return structures.stream().map((Integer id) -> macroData.getStructure(id)).filter((VirtualStructure struct) -> struct != null).collect(Collectors.toList()); } /** @@ -92,15 +95,15 @@ public class Town implements MacroAreaObject { * @param resident The new resident */ public void addResident(Character resident){ - residents.add(resident); + residents.add(resident.getId()); } /** * Gets the list of residents of the town * @return The list of residents */ - public List getResidents(){ - return residents; + public List getResidents(MacroData macroData){ + return residents.stream().map((Integer id) -> Globals.serverState.characterService.getCharacter(id)).filter((Character chara) -> chara != null).collect(Collectors.toList()); } /** @@ -152,6 +155,14 @@ public class Town implements MacroAreaObject { return new AABBd(this.getStartPos(), this.getEndPos()); } + /** + * Sets the id of the town + * @param id The id of the town + */ + public void setId(int id){ + this.id = id; + } + /** * Gets the ID of the town * @return The ID