cleaning up MacroData class

This commit is contained in:
austin 2025-04-16 13:07:42 -04:00
parent 8e2c86397b
commit 68fd87acae

View File

@ -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<Character> initialDieties = new LinkedList<Character>();
List<Race> races = new LinkedList<Race>();
List<Character> characters = new LinkedList<Character>();
List<Character> aliveCharacters = new LinkedList<Character>();
List<Civilization> civilizations = new LinkedList<Civilization>();
List<Town> towns = new LinkedList<Town>();
List<Structure> structures = new LinkedList<Structure>();
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<Character> initialDieties = new LinkedList<Character>();
/**
* List of races
*/
List<Race> races = new LinkedList<Race>();
/**
* List of characters
*/
List<Character> characters = new LinkedList<Character>();
/**
* List of alive characters
*/
List<Character> aliveCharacters = new LinkedList<Character>();
/**
* List of civilizations
*/
List<Civilization> civilizations = new LinkedList<Civilization>();
/**
* List of towns
*/
List<Town> towns = new LinkedList<Town>();
/**
* List of structures
*/
List<Structure> structures = new LinkedList<Structure>();
/**
* 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<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){ //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;
// 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){ //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;
// // }
// }
// }
// 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<Character> getAliveCharacters(){
return aliveCharacters;
}
/**
* Gets the list of civilizations
* @return The list of civilizations
*/
public List<Civilization> 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<Town> 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<Structure> 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("==========================");
}
}