diff --git a/src/main/java/electrosphere/server/macro/MacroData.java b/src/main/java/electrosphere/server/macro/MacroData.java index 0480c902..32e34878 100644 --- a/src/main/java/electrosphere/server/macro/MacroData.java +++ b/src/main/java/electrosphere/server/macro/MacroData.java @@ -4,6 +4,7 @@ import java.util.LinkedList; import java.util.List; import electrosphere.engine.Globals; +import electrosphere.logger.LoggerInterface; import electrosphere.server.macro.character.Character; import electrosphere.server.macro.character.CharacterDataStrings; import electrosphere.server.macro.character.CharacterUtils; @@ -16,36 +17,57 @@ import electrosphere.server.macro.symbolism.model.Symbol; import electrosphere.server.macro.town.Town; import java.util.Random; -import org.joml.Vector2i; /** * Server macro level data */ public class MacroData { - - List initialDieties = new LinkedList(); - List races = new LinkedList(); - List characters = new LinkedList(); - List aliveCharacters = new LinkedList(); - List civilizations = new LinkedList(); - List towns = new LinkedList(); - List structures = new LinkedList(); - - - static Character generateInitialDiety(long seed){ - Character rVal = new Character(); - - - Diety diety = Diety.generateDiety(seed); - CharacterUtils.addDiety(rVal, diety); - - - return rVal; - } - + /** + * The maximum number of attempts to try placing something + */ static final int MAX_PLACEMENT_ATTEMPTS = 50; + + /** + * List of initial dieties + */ + List initialDieties = new LinkedList(); + /** + * List of races + */ + List races = new LinkedList(); + + /** + * List of characters + */ + List characters = new LinkedList(); + + /** + * List of alive characters + */ + List aliveCharacters = new LinkedList(); + + /** + * List of civilizations + */ + List civilizations = new LinkedList(); + + /** + * List of towns + */ + List towns = new LinkedList(); + + /** + * List of structures + */ + List structures = new LinkedList(); + + /** + * Generates a world + * @param seed The seed for the world + * @return The world + */ public static MacroData generateWorld(long seed){ Random random = new Random(seed); MacroData rVal = new MacroData(); @@ -79,92 +101,139 @@ public class MacroData { //find initial positions to place characters at per race //generate initial characters //place them - List occupiedStartingPositions = new LinkedList(); - 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){ //TODO: Set to actual sea level value - // //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; - // } - } - } + // List occupiedStartingPositions = new LinkedList(); + // 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){ //TODO: Set to actual sea level value + // // //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; + } + + /** + * 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 all alive characters + * @return The list of all characters + */ public List getAliveCharacters(){ return aliveCharacters; } + /** + * Gets the list of civilizations + * @return The list of civilizations + */ public List getCivilizations(){ return civilizations; } + /** + * Adds a civilization + * @param civilization The civilization + */ public void addCivilization(Civilization civilization){ civilizations.add(civilization); } + /** + * Gets the list of towns + * @return The list of towns + */ public List getTowns(){ return towns; } + /** + * Adds a town + * @param town The town + */ public void addTown(Town town){ towns.add(town); } + /** + * Gets the list of structures + * @return The list of structures + */ public List getStructures(){ return structures; } + /** + * Adds a structure + * @param structure The structure + */ public void addStructure(Structure structure){ structures.add(structure); } + /** + * Describes the world + */ public void describeWorld(){ - System.out.println("Initial dieties"); - System.out.println("=========================="); + LoggerInterface.loggerEngine.WARNING("Initial dieties"); + LoggerInterface.loggerEngine.WARNING("=========================="); for(Character chara : initialDieties){ - System.out.println("Diety"); + LoggerInterface.loggerEngine.WARNING("Diety"); Diety diety = CharacterUtils.getDiety(chara); for(Symbol symbol : diety.getSymbols()){ System.out.print(symbol.getName() + " "); } - System.out.println("\n"); + LoggerInterface.loggerEngine.WARNING("\n"); } - System.out.println("=========================="); - System.out.println("\n\n"); - System.out.println("Initial races"); - System.out.println("=========================="); + LoggerInterface.loggerEngine.WARNING("=========================="); + LoggerInterface.loggerEngine.WARNING("\n\n"); + LoggerInterface.loggerEngine.WARNING("Initial races"); + LoggerInterface.loggerEngine.WARNING("=========================="); for(Race race : races){ - System.out.println(race.getName()); + LoggerInterface.loggerEngine.WARNING(race.getName()); 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 : characters){ @@ -174,10 +243,10 @@ public class MacroData { } } } - System.out.println(numCharsOfRace + " initial characters"); - System.out.println("\n"); + LoggerInterface.loggerEngine.WARNING(numCharsOfRace + " initial characters"); + LoggerInterface.loggerEngine.WARNING("\n"); } - System.out.println("=========================="); + LoggerInterface.loggerEngine.WARNING("=========================="); } }