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 java.util.List;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface;
import electrosphere.server.macro.character.Character; import electrosphere.server.macro.character.Character;
import electrosphere.server.macro.character.CharacterDataStrings; import electrosphere.server.macro.character.CharacterDataStrings;
import electrosphere.server.macro.character.CharacterUtils; import electrosphere.server.macro.character.CharacterUtils;
@ -16,36 +17,57 @@ import electrosphere.server.macro.symbolism.model.Symbol;
import electrosphere.server.macro.town.Town; import electrosphere.server.macro.town.Town;
import java.util.Random; import java.util.Random;
import org.joml.Vector2i;
/** /**
* Server macro level data * Server macro level data
*/ */
public class MacroData { 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; 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){ public static MacroData generateWorld(long seed){
Random random = new Random(seed); Random random = new Random(seed);
MacroData rVal = new MacroData(); MacroData rVal = new MacroData();
@ -79,92 +101,139 @@ public class MacroData {
//find initial positions to place characters at per race //find initial positions to place characters at per race
//generate initial characters //generate initial characters
//place them //place them
List<Vector2i> occupiedStartingPositions = new LinkedList<Vector2i>(); // List<Vector2i> occupiedStartingPositions = new LinkedList<Vector2i>();
for(Race race : rVal.races){ // for(Race race : rVal.races){
boolean foundPlacementLocation = false; // boolean foundPlacementLocation = false;
int attempts = 0; // int attempts = 0;
while(!foundPlacementLocation){ // while(!foundPlacementLocation){
// Vector2i start = new Vector2i(random.nextInt(Globals.serverTerrainManager.getWorldDiscreteSize()),random.nextInt(Globals.serverTerrainManager.getWorldDiscreteSize())); // // Vector2i start = new Vector2i(random.nextInt(Globals.serverTerrainManager.getWorldDiscreteSize()),random.nextInt(Globals.serverTerrainManager.getWorldDiscreteSize()));
// //are we above sea level? // // //are we above sea level?
// if(Globals.serverTerrainManager.getDiscreteValue(start.x, start.y) > 25){ //TODO: Set to actual sea level value // // if(Globals.serverTerrainManager.getDiscreteValue(start.x, start.y) > 25){ //TODO: Set to actual sea level value
// //is this position already occupied? // // //is this position already occupied?
// boolean match = false; // // boolean match = false;
// for(Vector2i known : occupiedStartingPositions){ // // for(Vector2i known : occupiedStartingPositions){
// if(known.x == start.x && known.y == start.y){ // // if(known.x == start.x && known.y == start.y){
// match = true; // // match = true;
// break; // // break;
// } // // }
// } // // }
// if(!match){ // // if(!match){
// //occupy position // // //occupy position
// occupiedStartingPositions.add(start); // // occupiedStartingPositions.add(start);
// foundPlacementLocation = true; // // foundPlacementLocation = true;
// //make characters // // //make characters
// int numCharactersToMake = 5 + random.nextInt(20); // // int numCharactersToMake = 5 + random.nextInt(20);
// for(int i = 0; i < numCharactersToMake; i++){ // // for(int i = 0; i < numCharactersToMake; i++){
// Character character = new Character(); // // Character character = new Character();
// CharacterUtils.addDiscretePosition(character, start.x, start.y); // // CharacterUtils.addDiscretePosition(character, start.x, start.y);
// CharacterUtils.addRace(character, race); // // CharacterUtils.addRace(character, race);
// rVal.characters.add(character); // // rVal.characters.add(character);
// rVal.aliveCharacters.add(character); // // rVal.aliveCharacters.add(character);
// } // // }
// } // // }
// } // // }
// attempts++; // // attempts++;
// if(attempts > MAX_PLACEMENT_ATTEMPTS){ // // if(attempts > MAX_PLACEMENT_ATTEMPTS){
// break; // // 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; return rVal;
} }
/**
* Gets all alive characters
* @return The list of all characters
*/
public List<Character> getAliveCharacters(){ public List<Character> getAliveCharacters(){
return aliveCharacters; return aliveCharacters;
} }
/**
* Gets the list of civilizations
* @return The list of civilizations
*/
public List<Civilization> getCivilizations(){ public List<Civilization> getCivilizations(){
return civilizations; return civilizations;
} }
/**
* Adds a civilization
* @param civilization The civilization
*/
public void addCivilization(Civilization civilization){ public void addCivilization(Civilization civilization){
civilizations.add(civilization); civilizations.add(civilization);
} }
/**
* Gets the list of towns
* @return The list of towns
*/
public List<Town> getTowns(){ public List<Town> getTowns(){
return towns; return towns;
} }
/**
* Adds a town
* @param town The town
*/
public void addTown(Town town){ public void addTown(Town town){
towns.add(town); towns.add(town);
} }
/**
* Gets the list of structures
* @return The list of structures
*/
public List<Structure> getStructures(){ public List<Structure> getStructures(){
return structures; return structures;
} }
/**
* Adds a structure
* @param structure The structure
*/
public void addStructure(Structure structure){ public void addStructure(Structure structure){
structures.add(structure); structures.add(structure);
} }
/**
* Describes the world
*/
public void describeWorld(){ public void describeWorld(){
System.out.println("Initial dieties"); LoggerInterface.loggerEngine.WARNING("Initial dieties");
System.out.println("=========================="); LoggerInterface.loggerEngine.WARNING("==========================");
for(Character chara : initialDieties){ for(Character chara : initialDieties){
System.out.println("Diety"); LoggerInterface.loggerEngine.WARNING("Diety");
Diety diety = CharacterUtils.getDiety(chara); Diety diety = CharacterUtils.getDiety(chara);
for(Symbol symbol : diety.getSymbols()){ for(Symbol symbol : diety.getSymbols()){
System.out.print(symbol.getName() + " "); System.out.print(symbol.getName() + " ");
} }
System.out.println("\n"); LoggerInterface.loggerEngine.WARNING("\n");
} }
System.out.println("=========================="); LoggerInterface.loggerEngine.WARNING("==========================");
System.out.println("\n\n"); LoggerInterface.loggerEngine.WARNING("\n\n");
System.out.println("Initial races"); LoggerInterface.loggerEngine.WARNING("Initial races");
System.out.println("=========================="); LoggerInterface.loggerEngine.WARNING("==========================");
for(Race race : races){ for(Race race : races){
System.out.println(race.getName()); LoggerInterface.loggerEngine.WARNING(race.getName());
int numCharsOfRace = 0; int numCharsOfRace = 0;
//n*m complexity - yikes! - as long as we're not making a million chars at start this should be _ok_ //n*m complexity - yikes! - as long as we're not making a million chars at start this should be _ok_
for(Character chara : characters){ for(Character chara : characters){
@ -174,10 +243,10 @@ public class MacroData {
} }
} }
} }
System.out.println(numCharsOfRace + " initial characters"); LoggerInterface.loggerEngine.WARNING(numCharsOfRace + " initial characters");
System.out.println("\n"); LoggerInterface.loggerEngine.WARNING("\n");
} }
System.out.println("=========================="); LoggerInterface.loggerEngine.WARNING("==========================");
} }
} }