reintroduce macro sim scaffolding
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
parent
bc2ecadf64
commit
c893e0568a
@ -23,7 +23,6 @@ import electrosphere.server.ai.nodes.plan.PathfindingNode;
|
||||
import electrosphere.server.datacell.Realm;
|
||||
import electrosphere.server.datacell.gridded.GriddedDataCellManager;
|
||||
import electrosphere.server.datacell.utils.EntityLookupUtils;
|
||||
import electrosphere.server.macro.MacroData;
|
||||
import electrosphere.server.macro.character.Character;
|
||||
import electrosphere.server.macro.character.CharacterUtils;
|
||||
import electrosphere.server.macro.character.goal.CharacterGoal;
|
||||
@ -92,8 +91,7 @@ public class ImGuiAI {
|
||||
if(ImGui.button("Send off map")){
|
||||
Entity entity = ai.getParent();
|
||||
ServerCharacterData serverCharacterData = ServerCharacterData.getServerCharacterData(entity);
|
||||
MacroData macroData = Globals.realmManager.getEntityRealm(entity).getServerContentManager().getMacroData();
|
||||
Character character = macroData.getCharacter(serverCharacterData.getCharacterData().getId());
|
||||
Character character = Globals.characterService.getCharacter(serverCharacterData.getCharacterData().getId());
|
||||
CharacterGoal.setCharacterGoal(character, new CharacterGoal(CharacterGoalType.LEAVE_SIM_RANGE));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package electrosphere.server.entity;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.joml.Vector3i;
|
||||
|
||||
@ -83,7 +84,8 @@ public class ServerContentManager {
|
||||
//ie, if we load an asset-defined (not save-defined) scene that does not have save data
|
||||
//ie, imagine a puzzle room or something like that
|
||||
if(macroData != null){
|
||||
for(Character character : macroData.getCharacters(worldPos)){
|
||||
List<Character> nearbyCharacters = Globals.characterService.getCharacters(worldPos);
|
||||
for(Character character : nearbyCharacters){
|
||||
this.spawnMacroObject(realm, character);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,22 +7,17 @@ import electrosphere.engine.Globals;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.server.datacell.ServerWorldData;
|
||||
import electrosphere.server.macro.character.Character;
|
||||
import electrosphere.server.macro.character.CharacterUtils;
|
||||
import electrosphere.server.macro.character.data.CharacterDataStrings;
|
||||
import electrosphere.server.macro.character.diety.Diety;
|
||||
import electrosphere.server.macro.civilization.Civilization;
|
||||
import electrosphere.server.macro.race.Race;
|
||||
import electrosphere.server.macro.race.RaceMap;
|
||||
import electrosphere.server.macro.spatial.MacroAreaObject;
|
||||
import electrosphere.server.macro.structure.Structure;
|
||||
import electrosphere.server.macro.symbolism.Symbol;
|
||||
import electrosphere.server.macro.town.Town;
|
||||
import electrosphere.util.FileUtils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.joml.Vector3i;
|
||||
|
||||
/**
|
||||
* Server macro level data
|
||||
*/
|
||||
@ -33,11 +28,6 @@ public class MacroData {
|
||||
*/
|
||||
static final int MAX_PLACEMENT_ATTEMPTS = 50;
|
||||
|
||||
/**
|
||||
* List of initial dieties
|
||||
*/
|
||||
List<Character> initialDieties = new LinkedList<Character>();
|
||||
|
||||
/**
|
||||
* List of races
|
||||
*/
|
||||
@ -229,14 +219,14 @@ public class MacroData {
|
||||
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");
|
||||
}
|
||||
// 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");
|
||||
@ -258,22 +248,6 @@ public class MacroData {
|
||||
LoggerInterface.loggerEngine.WARNING("==========================");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the characters at a given world position
|
||||
* @param worldPos The world position
|
||||
* @return The list of characters occupying that world position
|
||||
*/
|
||||
public List<Character> getCharacters(Vector3i worldPos){
|
||||
List<Character> rVal = new LinkedList<Character>();
|
||||
for(Character character : Globals.characterService.getAllCharacters()){
|
||||
if(ServerWorldData.convertRealToChunkSpace(character.getPos()).equals(worldPos.x, worldPos.y, worldPos.z)){
|
||||
rVal.add(character);
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of content-blocking macro objects
|
||||
* @return The list
|
||||
@ -284,18 +258,4 @@ public class MacroData {
|
||||
return blockers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a character by its id
|
||||
* @param id The id
|
||||
* @return The character if it exists, null otherwise
|
||||
*/
|
||||
public Character getCharacter(int id){
|
||||
for(Character character : Globals.characterService.getAllCharacters()){
|
||||
if(character.getId() == id){
|
||||
return character;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import electrosphere.server.macro.character.diety.Diety;
|
||||
import electrosphere.server.macro.race.Race;
|
||||
import electrosphere.server.macro.structure.Structure;
|
||||
import electrosphere.server.macro.town.Town;
|
||||
import electrosphere.server.service.CharacterService;
|
||||
|
||||
/**
|
||||
* Utility functions for dealing with characters
|
||||
@ -55,7 +56,7 @@ public class CharacterUtils {
|
||||
* @return The character
|
||||
*/
|
||||
public static Character spawnCharacter(Realm realm, Vector3d position){
|
||||
Character rVal = Globals.characterService.createCharacter(null, 0);
|
||||
Character rVal = Globals.characterService.createCharacter(null, CharacterService.NO_PLAYER);
|
||||
rVal.setPos(position);
|
||||
Race.setRace(rVal, Race.create("human", "human"));
|
||||
realm.getDataCellManager().evaluateMacroObject(rVal);
|
||||
|
||||
@ -31,7 +31,7 @@ public class PlayerCharacterCreation {
|
||||
|
||||
//
|
||||
//get template
|
||||
Character charaData = Globals.characterService.getCharacter(connectionHandler.getPlayer().getDBID(), connectionHandler.getCharacterId());
|
||||
Character charaData = Globals.characterService.getCharacter(connectionHandler.getCharacterId());
|
||||
CreatureTemplate template = charaData.getCreatureTemplate();
|
||||
if(connectionHandler.getCharacterId() == CharacterProtocol.SPAWN_EXISTING_TEMPLATE){
|
||||
template = connectionHandler.getCurrentCreatureTemplate();
|
||||
@ -90,7 +90,7 @@ public class PlayerCharacterCreation {
|
||||
*/
|
||||
static void addPlayerServerBTrees(Entity entity, ServerConnectionHandler serverConnectionHandler){
|
||||
ServerPlayerViewDirTree.attachServerPlayerViewDirTree(entity);
|
||||
ServerCharacterData.attachServerCharacterData(entity, Globals.characterService.getCharacter(serverConnectionHandler.getPlayer().getDBID(), serverConnectionHandler.getCharacterId()));
|
||||
ServerCharacterData.attachServerCharacterData(entity, Globals.characterService.getCharacter(serverConnectionHandler.getCharacterId()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,7 +100,7 @@ public class PlayerCharacterCreation {
|
||||
* @return The spawn point for the player
|
||||
*/
|
||||
public static Vector3d solveSpawnPoint(Realm realm, ServerConnectionHandler connectionHandler){
|
||||
Vector3d spawnPoint = Globals.characterService.getCharacter(connectionHandler.getPlayer().getDBID(), connectionHandler.getCharacterId()).getPos();
|
||||
Vector3d spawnPoint = Globals.characterService.getCharacter(connectionHandler.getCharacterId()).getPos();
|
||||
if(spawnPoint == null){
|
||||
spawnPoint = realm.getSpawnPoint();
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
@ -17,6 +19,7 @@ import electrosphere.entity.state.server.ServerCharacterData;
|
||||
import electrosphere.entity.types.creature.CreatureTemplate;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.server.datacell.ServerWorldData;
|
||||
import electrosphere.server.db.DatabaseResult;
|
||||
import electrosphere.server.db.DatabaseResultRow;
|
||||
import electrosphere.server.macro.character.Character;
|
||||
@ -27,6 +30,11 @@ import electrosphere.util.SerializationUtils;
|
||||
*/
|
||||
public class CharacterService extends SignalServiceImpl {
|
||||
|
||||
/**
|
||||
* Playerid id for a playerless character
|
||||
*/
|
||||
public static final int NO_PLAYER = 0;
|
||||
|
||||
/**
|
||||
* Map that stores the characters currently loaded into memory
|
||||
*/
|
||||
@ -50,6 +58,9 @@ public class CharacterService extends SignalServiceImpl {
|
||||
* @param playerId The player's id
|
||||
*/
|
||||
public Character createCharacter(CreatureTemplate template, int playerId){
|
||||
if(template == null){
|
||||
throw new Error("Template is null!");
|
||||
}
|
||||
lock.lock();
|
||||
Character toStore = new Character(template);
|
||||
DatabaseResult result = Globals.dbController.executePreparedQuery(
|
||||
@ -70,11 +81,10 @@ public class CharacterService extends SignalServiceImpl {
|
||||
|
||||
/**
|
||||
* Gets the character
|
||||
* @param playerId The player's id
|
||||
* @param characterId The character's id
|
||||
* @return The character if it exists, null otherwise
|
||||
*/
|
||||
public Character getCharacter(int playerId, int characterId){
|
||||
public Character getCharacter(int characterId){
|
||||
lock.lock();
|
||||
if(loadedCharacterMap.containsKey(characterId)){
|
||||
Character rVal = loadedCharacterMap.get(characterId);
|
||||
@ -82,9 +92,9 @@ public class CharacterService extends SignalServiceImpl {
|
||||
return rVal;
|
||||
}
|
||||
Character charData = null;
|
||||
DatabaseResult result = Globals.dbController.executePreparedQuery("SELECT id, dataVal FROM charaData WHERE playerId=? AND id=?;",playerId, characterId);
|
||||
DatabaseResult result = Globals.dbController.executePreparedQuery("SELECT id, dataVal FROM charaData WHERE id=?;", characterId);
|
||||
if(!result.hasResult()){
|
||||
LoggerInterface.loggerDB.WARNING("Failed to locate creature template for playerId=" + playerId + " characterId=" + characterId);
|
||||
LoggerInterface.loggerDB.WARNING("Failed to locate creature template for characterId=" + characterId);
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
@ -176,4 +186,20 @@ public class CharacterService extends SignalServiceImpl {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the characters at a given world position
|
||||
* @param worldPos The world position
|
||||
* @return The list of characters occupying that world position
|
||||
*/
|
||||
public List<Character> getCharacters(Vector3i worldPos){
|
||||
List<Character> rVal = new LinkedList<Character>();
|
||||
List<Character> allCharacters = this.getAllCharacters();
|
||||
for(Character character : allCharacters){
|
||||
if(ServerWorldData.convertRealToChunkSpace(character.getPos()).equals(worldPos.x, worldPos.y, worldPos.z)){
|
||||
rVal.add(character);
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package electrosphere.server.simulation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.server.macro.character.Character;
|
||||
import electrosphere.server.macro.character.data.CharacterDataStrings;
|
||||
|
||||
@ -11,17 +14,20 @@ public class MacroSimulation {
|
||||
/**
|
||||
* Tracks whether the macro simulation is ready or not
|
||||
*/
|
||||
boolean isReady = false;
|
||||
private boolean isReady = false;
|
||||
|
||||
/**
|
||||
* Iterates the macro simulation
|
||||
*/
|
||||
public void simulate(){
|
||||
// for(Character character : Globals.macroData.getAliveCharacters()){
|
||||
// //do something
|
||||
// MacroSimulation.checkForShelter(character);
|
||||
// MacroSimulation.checkTownMembership(character);
|
||||
// }
|
||||
List<Character> characters = Globals.characterService.getAllCharacters();
|
||||
if(characters != null && characters.size() > 0){
|
||||
for(Character character : Globals.characterService.getAllCharacters()){
|
||||
//do something
|
||||
MacroSimulation.checkForShelter(character);
|
||||
MacroSimulation.checkTownMembership(character);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user