structure work with macro data and characters
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
austin 2025-05-10 18:10:34 -04:00
parent 6f72167d68
commit 75ec43a54f
9 changed files with 78 additions and 27 deletions

View File

@ -1709,6 +1709,7 @@ Convert character service to singleton
Start moving character goal logic from behavior trees to macro level simulation
Goal macro data work
Shuffle where macro data is stored
Structures are stored in character data as IDs into macro data now

View File

@ -1,9 +1,11 @@
package electrosphere.server.ai.nodes.checks.macro;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.state.server.ServerCharacterData;
import electrosphere.server.ai.blackboard.Blackboard;
import electrosphere.server.ai.nodes.AITreeNode;
import electrosphere.server.datacell.Realm;
import electrosphere.server.macro.character.Character;
import electrosphere.server.macro.character.CharacterUtils;
import electrosphere.server.macro.structure.Structure;
@ -17,10 +19,11 @@ public class HasShelter implements AITreeNode {
public AITreeNodeResult evaluate(Entity entity, Blackboard blackboard) {
ServerCharacterData serverCharacterData = ServerCharacterData.getServerCharacterData(entity);
Character character = serverCharacterData.getCharacterData();
Realm realm = Globals.realmManager.getEntityRealm(entity);
if(character == null){
throw new Error("Character is null");
}
Structure shelter = CharacterUtils.getShelter(character);
Structure shelter = CharacterUtils.getShelter(realm.getMacroData(),character);
if(shelter == null){
return AITreeNodeResult.FAILURE;
}

View File

@ -204,6 +204,20 @@ public class MacroData {
public List<Structure> 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 Structure getStructure(int id){
for(Structure struct : structures){
if(struct.getId() == id){
return struct;
}
}
return null;
}
/**
* Adds a structure

View File

@ -5,6 +5,8 @@ import org.joml.Vector3d;
import electrosphere.engine.Globals;
import electrosphere.entity.types.creature.CreatureTemplate;
import electrosphere.server.datacell.Realm;
import electrosphere.server.macro.MacroData;
import electrosphere.server.macro.character.data.CharacterAssociatedId;
import electrosphere.server.macro.character.data.CharacterDataStrings;
import electrosphere.server.macro.character.diety.Diety;
import electrosphere.server.macro.race.Race;
@ -46,16 +48,21 @@ public class CharacterUtils {
* @param shelter The shelter
*/
public static void addShelter(Character character, Structure shelter){
character.putData(CharacterDataStrings.SHELTER, shelter);
character.putData(CharacterDataStrings.SHELTER, new CharacterAssociatedId(shelter.getId()));
}
/**
* Gets the shelter of a character
* @param macroData The macro data
* @param character The character
* @return The shelter if it exists, null otherwise
*/
public static Structure getShelter(Character character){
return (Structure)character.getData(CharacterDataStrings.SHELTER);
public static Structure getShelter(MacroData macroData, Character character){
if(!character.containsKey(CharacterDataStrings.SHELTER)){
return null;
}
int structId = ((CharacterAssociatedId)character.getData(CharacterDataStrings.SHELTER)).getId();
return macroData.getStructure(structId);
}
/**

View File

@ -0,0 +1,29 @@
package electrosphere.server.macro.character.data;
/**
* An id of some macro data that is associated with this character
*/
public class CharacterAssociatedId extends CharacterData {
/**
* The id
*/
int id;
/**
* Constructor
*/
public CharacterAssociatedId(int id){
super("AssociatedId");
this.id = id;
}
/**
* Gets the id
* @return The id
*/
public int getId(){
return id;
}
}

View File

@ -11,7 +11,6 @@ import com.google.gson.JsonSerializer;
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;
/**
@ -35,8 +34,8 @@ public class CharacterDataSerializer implements JsonDeserializer<CharacterData>,
}
//a structure
case CharacterDataStrings.STRUCTURE: {
return context.deserialize(json, Structure.class);
case CharacterDataStrings.STRUCTURE_ID: {
return context.deserialize(json, CharacterAssociatedId.class);
}
//a town
@ -65,8 +64,8 @@ public class CharacterDataSerializer implements JsonDeserializer<CharacterData>,
}
//a structure
case CharacterDataStrings.STRUCTURE: {
return context.serialize((Structure)src);
case CharacterDataStrings.STRUCTURE_ID: {
return context.serialize((CharacterAssociatedId)src);
}
//a town

View File

@ -11,7 +11,7 @@ public class CharacterDataStrings {
public static final String PERSONALITY_ADVANCED = "personalityAdvanced";
public static final String RACE = "race";
public static final String SHELTER = "shelter";
public static final String STRUCTURE = "structure";
public static final String STRUCTURE_ID = "structureId";
public static final String HOMETOWN = "hometown";
public static final String TOWN = "town";

View File

@ -5,15 +5,18 @@ import org.joml.Vector3d;
import electrosphere.game.data.block.BlockFab;
import electrosphere.game.data.struct.StructureData;
import electrosphere.server.macro.character.data.CharacterData;
import electrosphere.server.macro.character.data.CharacterDataStrings;
import electrosphere.server.macro.spatial.MacroAreaObject;
import electrosphere.util.annotation.Exclude;
/**
* Server representation of a structure
*/
public class Structure extends CharacterData implements MacroAreaObject {
public class Structure implements MacroAreaObject {
/**
* The id of the structure
*/
int id;
/**
* The position of the structure
@ -46,14 +49,6 @@ public class Structure extends CharacterData implements MacroAreaObject {
*/
boolean repairable = false;
/**
* Constructor
* @param dataType The data type of the structure
*/
private Structure(){
super(CharacterDataStrings.STRUCTURE);
}
/**
* Creates a structure
* @param data The data
@ -77,11 +72,6 @@ public class Structure extends CharacterData implements MacroAreaObject {
return type;
}
@Override
public String getDataType() {
return CharacterDataStrings.HOMETOWN;
}
@Override
public Vector3d getPos() {
return this.position;
@ -146,6 +136,14 @@ public class Structure extends CharacterData implements MacroAreaObject {
public void setRepairable(boolean repairable) {
this.repairable = repairable;
}
/**
* Gets the id of the structure
* @return The id
*/
public int getId(){
return id;
}
}

View File

@ -73,7 +73,7 @@ public class MacroSimulation {
If no town
fashion makeshift shelter
*/
if(CharacterUtils.getShelter(chara) != null){
if(CharacterUtils.getShelter(macroData,chara) != null){
// Vector2i charPos = CharacterUtils.getDiscretePosition(chara);
// Town nearbyTown = Town.getTownAtPosition(charPos.x,charPos.y);
// if(nearbyTown != null){