civilization generation in macro data
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
ee1058e71d
commit
f3b79bafcf
@ -9,6 +9,7 @@ import electrosphere.server.datacell.ServerWorldData;
|
|||||||
import electrosphere.server.macro.character.Character;
|
import electrosphere.server.macro.character.Character;
|
||||||
import electrosphere.server.macro.character.data.CharacterDataStrings;
|
import electrosphere.server.macro.character.data.CharacterDataStrings;
|
||||||
import electrosphere.server.macro.civilization.Civilization;
|
import electrosphere.server.macro.civilization.Civilization;
|
||||||
|
import electrosphere.server.macro.civilization.CivilizationGenerator;
|
||||||
import electrosphere.server.macro.race.Race;
|
import electrosphere.server.macro.race.Race;
|
||||||
import electrosphere.server.macro.race.RaceMap;
|
import electrosphere.server.macro.race.RaceMap;
|
||||||
import electrosphere.server.macro.spatial.MacroAreaObject;
|
import electrosphere.server.macro.spatial.MacroAreaObject;
|
||||||
@ -18,6 +19,8 @@ import electrosphere.util.FileUtils;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server macro level data
|
* Server macro level data
|
||||||
*/
|
*/
|
||||||
@ -65,6 +68,7 @@ public class MacroData {
|
|||||||
// rVal.characters.add(diety);
|
// rVal.characters.add(diety);
|
||||||
// CharacterService.createCharacter(null, i);
|
// CharacterService.createCharacter(null, i);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
//generate initial races
|
//generate initial races
|
||||||
if(Globals.gameConfigCurrent.getRaceMap().getRaces().size() < 3){
|
if(Globals.gameConfigCurrent.getRaceMap().getRaces().size() < 3){
|
||||||
@ -82,6 +86,9 @@ public class MacroData {
|
|||||||
rVal.races.add(raceToAdd);
|
rVal.races.add(raceToAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//init civilizations
|
||||||
|
CivilizationGenerator.generate(serverWorldData, rVal, Globals.gameConfigCurrent);
|
||||||
|
|
||||||
//add a test character
|
//add a test character
|
||||||
// Character testChar = new Character();
|
// Character testChar = new Character();
|
||||||
@ -175,10 +182,13 @@ public class MacroData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a civilization
|
* Adds a civilization
|
||||||
* @param civilization The civilization
|
* @param race the race founding the civilization
|
||||||
*/
|
*/
|
||||||
public void addCivilization(Civilization civilization){
|
public Civilization addCivilization(Race race){
|
||||||
civilizations.add(civilization);
|
Civilization civ = new Civilization();
|
||||||
|
civ.setId(civilizations.size());
|
||||||
|
civilizations.add(civ);
|
||||||
|
return civ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -191,10 +201,14 @@ public class MacroData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a town
|
* 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){
|
public Town addTown(Vector3d center, double radius){
|
||||||
towns.add(town);
|
Town rVal = Town.createTown(center, radius);
|
||||||
|
rVal.setId(towns.size());
|
||||||
|
towns.add(rVal);
|
||||||
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,5 +1,101 @@
|
|||||||
package electrosphere.server.macro.civilization;
|
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 {
|
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<Integer> towns = new LinkedList<Integer>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The citizens of the civilization
|
||||||
|
*/
|
||||||
|
private List<Integer> citizens = new LinkedList<Integer>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<Town> 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<Character> 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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,5 +0,0 @@
|
|||||||
package electrosphere.server.macro.civilization.model;
|
|
||||||
|
|
||||||
public class CivilizationMap {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,11 +1,14 @@
|
|||||||
package electrosphere.server.macro.town;
|
package electrosphere.server.macro.town;
|
||||||
|
|
||||||
|
import electrosphere.engine.Globals;
|
||||||
|
import electrosphere.server.macro.MacroData;
|
||||||
import electrosphere.server.macro.character.Character;
|
import electrosphere.server.macro.character.Character;
|
||||||
import electrosphere.server.macro.spatial.MacroAreaObject;
|
import electrosphere.server.macro.spatial.MacroAreaObject;
|
||||||
import electrosphere.server.macro.structure.VirtualStructure;
|
import electrosphere.server.macro.structure.VirtualStructure;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.joml.AABBd;
|
import org.joml.AABBd;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
@ -38,12 +41,12 @@ public class Town implements MacroAreaObject {
|
|||||||
/**
|
/**
|
||||||
* The structures inside the town
|
* The structures inside the town
|
||||||
*/
|
*/
|
||||||
private List<VirtualStructure> structures = new LinkedList<VirtualStructure>();
|
private List<Integer> structures = new LinkedList<Integer>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The residents of the town
|
* The residents of the town
|
||||||
*/
|
*/
|
||||||
private List<Character> residents = new LinkedList<Character>();
|
private List<Integer> residents = new LinkedList<Integer>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of jobs queued in the town
|
* The list of jobs queued in the town
|
||||||
@ -76,15 +79,15 @@ public class Town implements MacroAreaObject {
|
|||||||
* @param structure The structure
|
* @param structure The structure
|
||||||
*/
|
*/
|
||||||
public void addStructure(VirtualStructure structure){
|
public void addStructure(VirtualStructure structure){
|
||||||
structures.add(structure);
|
structures.add(structure.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the structures that are a part of the town
|
* Gets the structures that are a part of the town
|
||||||
* @return The list of structures
|
* @return The list of structures
|
||||||
*/
|
*/
|
||||||
public List<VirtualStructure> getStructures(){
|
public List<VirtualStructure> getStructures(MacroData macroData){
|
||||||
return structures;
|
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
|
* @param resident The new resident
|
||||||
*/
|
*/
|
||||||
public void addResident(Character resident){
|
public void addResident(Character resident){
|
||||||
residents.add(resident);
|
residents.add(resident.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the list of residents of the town
|
* Gets the list of residents of the town
|
||||||
* @return The list of residents
|
* @return The list of residents
|
||||||
*/
|
*/
|
||||||
public List<Character> getResidents(){
|
public List<Character> getResidents(MacroData macroData){
|
||||||
return residents;
|
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());
|
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
|
* Gets the ID of the town
|
||||||
* @return The ID
|
* @return The ID
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user