Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
304 lines
10 KiB
Java
304 lines
10 KiB
Java
package electrosphere.server.macro;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
import electrosphere.engine.Globals;
|
|
import electrosphere.logger.LoggerInterface;
|
|
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;
|
|
import electrosphere.server.macro.structure.VirtualStructure;
|
|
import electrosphere.server.macro.town.Town;
|
|
import electrosphere.util.FileUtils;
|
|
|
|
import java.util.Random;
|
|
|
|
import org.joml.Vector3d;
|
|
|
|
/**
|
|
* Server macro level data
|
|
*/
|
|
public class MacroData {
|
|
|
|
/**
|
|
* The maximum number of attempts to try placing something
|
|
*/
|
|
static final int MAX_PLACEMENT_ATTEMPTS = 50;
|
|
|
|
/**
|
|
* List of races
|
|
*/
|
|
List<Race> races = new LinkedList<Race>();
|
|
|
|
/**
|
|
* List of civilizations
|
|
*/
|
|
List<Civilization> civilizations = new LinkedList<Civilization>();
|
|
|
|
/**
|
|
* List of towns
|
|
*/
|
|
List<Town> towns = new LinkedList<Town>();
|
|
|
|
/**
|
|
* List of structures
|
|
*/
|
|
List<VirtualStructure> structures = new LinkedList<VirtualStructure>();
|
|
|
|
/**
|
|
* Generates a world
|
|
* @param seed The seed for the world
|
|
* @return The world
|
|
*/
|
|
public static MacroData generateWorld(long seed, ServerWorldData serverWorldData){
|
|
Random random = new Random(seed);
|
|
MacroData rVal = new MacroData();
|
|
|
|
//generate initial dieties
|
|
// int numDieties = 3 + Math.abs(random.nextInt()) % 7;
|
|
// for(int i = 0; i < numDieties; i++){
|
|
// Character diety = generateInitialDiety(random.nextLong());
|
|
// rVal.initialDieties.add(diety);
|
|
// rVal.characters.add(diety);
|
|
// CharacterService.createCharacter(null, i);
|
|
// }
|
|
|
|
|
|
//generate initial races
|
|
if(Globals.gameConfigCurrent.getRaceMap().getRaces().size() < 3){
|
|
for(Race race : Globals.gameConfigCurrent.getRaceMap().getRaces()){
|
|
rVal.races.add(race);
|
|
}
|
|
} else {
|
|
RaceMap raceMap = Globals.gameConfigCurrent.getRaceMap();
|
|
int numRacesToGenerate = 3 + random.nextInt(Math.min(raceMap.getRaces().size() - 3,7));
|
|
for(int i = 0; i < numRacesToGenerate; i++){
|
|
Race raceToAdd = raceMap.getRaces().get(random.nextInt(raceMap.getRaces().size()));
|
|
while(rVal.races.contains(raceToAdd)){
|
|
raceToAdd = raceMap.getRaces().get(random.nextInt(raceMap.getRaces().size()));
|
|
}
|
|
rVal.races.add(raceToAdd);
|
|
}
|
|
}
|
|
|
|
//init civilizations
|
|
CivilizationGenerator.generate(serverWorldData, rVal, Globals.gameConfigCurrent);
|
|
|
|
//add a test character
|
|
// Character testChar = new Character();
|
|
// testChar.setPos(new Vector3d(ServerWorldData.convertChunkToRealSpace(new Vector3i(32774, 3, 32769))));
|
|
// Race.setRace(testChar, Race.create("human", "human"));
|
|
// rVal.characters.add(testChar);
|
|
|
|
//add a test character
|
|
// Vector3d structPos = ServerWorldData.convertChunkToRealSpace(new Vector3i(32774, 0, 32770));
|
|
// double elevationAtStruct = serverWorldData.getServerTerrainManager().getElevation(32774, 32770, 0, 0);
|
|
// structPos.y = elevationAtStruct;
|
|
// Structure struct = Structure.createStructure(Globals.gameConfigCurrent.getStructureData().getType("test1"),structPos);
|
|
// rVal.structures.add(struct);
|
|
|
|
//spawn initial characters in each race
|
|
//find initial positions to place characters at per race
|
|
//generate initial characters
|
|
//place them
|
|
// List<Vector2i> occupiedStartingPositions = new LinkedList<Vector2i>();
|
|
// for(Race race : rVal.races){
|
|
// boolean foundPlacementLocation = false;
|
|
// int attempts = 0;
|
|
// while(!foundPlacementLocation){
|
|
// // Vector2i start = new Vector2i(random.nextInt(Globals.serverTerrainManager.getWorldDiscreteSize()),random.nextInt(Globals.serverTerrainManager.getWorldDiscreteSize()));
|
|
// // //are we above sea level?
|
|
// // if(Globals.serverTerrainManager.getDiscreteValue(start.x, start.y) > 25){
|
|
// // //is this position already occupied?
|
|
// // boolean match = false;
|
|
// // for(Vector2i known : occupiedStartingPositions){
|
|
// // if(known.x == start.x && known.y == start.y){
|
|
// // match = true;
|
|
// // break;
|
|
// // }
|
|
// // }
|
|
// // if(!match){
|
|
// // //occupy position
|
|
// // occupiedStartingPositions.add(start);
|
|
// // foundPlacementLocation = true;
|
|
// // //make characters
|
|
// // int numCharactersToMake = 5 + random.nextInt(20);
|
|
// // for(int i = 0; i < numCharactersToMake; i++){
|
|
// // Character character = new Character();
|
|
// // CharacterUtils.addDiscretePosition(character, start.x, start.y);
|
|
// // CharacterUtils.addRace(character, race);
|
|
// // rVal.characters.add(character);
|
|
// // rVal.aliveCharacters.add(character);
|
|
// // }
|
|
// // }
|
|
// // }
|
|
// // attempts++;
|
|
// // if(attempts > MAX_PLACEMENT_ATTEMPTS){
|
|
// // break;
|
|
// // }
|
|
// }
|
|
// }
|
|
|
|
return rVal;
|
|
}
|
|
|
|
/**
|
|
* Saves this macro data to a save path
|
|
* @param saveName The name of the save
|
|
*/
|
|
public void save(String saveName){
|
|
FileUtils.serializeObjectToSavePath(saveName, "./macro.json", this);
|
|
}
|
|
|
|
// /**
|
|
// * Generates an initial diety
|
|
// * @param seed The seed
|
|
// * @return The character for the diety
|
|
// */
|
|
// static Character generateInitialDiety(long seed){
|
|
// Character rVal = new Character();
|
|
|
|
|
|
// Diety diety = Diety.generateDiety(seed);
|
|
// CharacterUtils.addDiety(rVal, diety);
|
|
|
|
|
|
// return rVal;
|
|
// }
|
|
|
|
/**
|
|
* Gets the list of civilizations
|
|
* @return The list of civilizations
|
|
*/
|
|
public List<Civilization> getCivilizations(){
|
|
return civilizations;
|
|
}
|
|
|
|
/**
|
|
* Adds a civilization
|
|
* @param race the race founding the civilization
|
|
*/
|
|
public Civilization addCivilization(Race race){
|
|
Civilization civ = new Civilization();
|
|
civ.setId(civilizations.size());
|
|
civilizations.add(civ);
|
|
return civ;
|
|
}
|
|
|
|
/**
|
|
* Gets the list of towns
|
|
* @return The list of towns
|
|
*/
|
|
public List<Town> getTowns(){
|
|
return towns;
|
|
}
|
|
|
|
/**
|
|
* Adds a town
|
|
* @param center The center point of the town
|
|
* @param radius The radius of the town
|
|
*/
|
|
public Town addTown(Vector3d center, double radius){
|
|
Town rVal = Town.createTown(center, radius);
|
|
rVal.setId(towns.size());
|
|
towns.add(rVal);
|
|
return rVal;
|
|
}
|
|
|
|
/**
|
|
* Gets a town by its id
|
|
* @param id The id of the town
|
|
* @return The town
|
|
*/
|
|
public Town getTown(int id){
|
|
for(Town town : towns){
|
|
if(town.getId() == id){
|
|
return town;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Gets the list of structures
|
|
* @return The list of structures
|
|
*/
|
|
public List<VirtualStructure> getStructures(){
|
|
return structures;
|
|
}
|
|
|
|
/**
|
|
* Gets a structure by its id
|
|
* @param id The id of the structure
|
|
* @return The structure if it exists, null otherwise
|
|
*/
|
|
public VirtualStructure getStructure(int id){
|
|
for(VirtualStructure struct : structures){
|
|
if(struct.getId() == id){
|
|
return struct;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Adds a structure
|
|
* @param structure The structure
|
|
*/
|
|
public void addStructure(VirtualStructure structure){
|
|
structures.add(structure);
|
|
}
|
|
|
|
/**
|
|
* Describes the world
|
|
*/
|
|
public void describeWorld(){
|
|
LoggerInterface.loggerEngine.WARNING("Initial dieties");
|
|
LoggerInterface.loggerEngine.WARNING("==========================");
|
|
// for(Character chara : initialDieties){
|
|
// LoggerInterface.loggerEngine.WARNING("Diety");
|
|
// Diety diety = CharacterUtils.getDiety(chara);
|
|
// for(Symbol symbol : diety.getSymbols()){
|
|
// LoggerInterface.loggerEngine.WARNING(symbol.getName() + " ");
|
|
// }
|
|
// LoggerInterface.loggerEngine.WARNING("\n");
|
|
// }
|
|
LoggerInterface.loggerEngine.WARNING("==========================");
|
|
LoggerInterface.loggerEngine.WARNING("\n\n");
|
|
LoggerInterface.loggerEngine.WARNING("Initial races");
|
|
LoggerInterface.loggerEngine.WARNING("==========================");
|
|
for(Race race : races){
|
|
LoggerInterface.loggerEngine.WARNING(race.getId());
|
|
int numCharsOfRace = 0;
|
|
//n*m complexity - yikes! - as long as we're not making a million chars at start this should be _ok_
|
|
for(Character chara : Globals.serverState.characterService.getAllCharacters()){
|
|
if(chara.containsKey(CharacterDataStrings.RACE)){
|
|
if(Race.getRace(chara).equals(race)){
|
|
numCharsOfRace++;
|
|
}
|
|
}
|
|
}
|
|
LoggerInterface.loggerEngine.WARNING(numCharsOfRace + " initial characters");
|
|
LoggerInterface.loggerEngine.WARNING("\n");
|
|
}
|
|
LoggerInterface.loggerEngine.WARNING("==========================");
|
|
}
|
|
|
|
/**
|
|
* Gets the list of content-blocking macro objects
|
|
* @return The list
|
|
*/
|
|
public List<MacroAreaObject> getContentBlockers(){
|
|
List<MacroAreaObject> blockers = new LinkedList<MacroAreaObject>();
|
|
blockers.addAll(this.structures);
|
|
return blockers;
|
|
}
|
|
|
|
}
|