diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index a25c0b2c..f661a6c7 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1711,6 +1711,7 @@ Goal macro data work Shuffle where macro data is stored Structures are stored in character data as IDs into macro data now Item acquisition tree can be triggered by setting macro goal correctly +Macro sim triggers character to try to get mats to build structure diff --git a/src/main/java/electrosphere/server/datacell/Realm.java b/src/main/java/electrosphere/server/datacell/Realm.java index c48f8bef..ce0963ca 100644 --- a/src/main/java/electrosphere/server/datacell/Realm.java +++ b/src/main/java/electrosphere/server/datacell/Realm.java @@ -258,7 +258,7 @@ public class Realm { // //macro data simulation if(this.macroData != null){ - MacroSimulation.simulate(this.macroData); + MacroSimulation.simulate(this); } // diff --git a/src/main/java/electrosphere/server/macro/utils/StructureRepairUtils.java b/src/main/java/electrosphere/server/macro/utils/StructureRepairUtils.java index be5d5ce0..530f3c07 100644 --- a/src/main/java/electrosphere/server/macro/utils/StructureRepairUtils.java +++ b/src/main/java/electrosphere/server/macro/utils/StructureRepairUtils.java @@ -4,7 +4,10 @@ import org.joml.Vector3d; import org.joml.Vector3i; import electrosphere.client.block.BlockChunkData; +import electrosphere.engine.Globals; import electrosphere.game.data.block.BlockFab; +import electrosphere.game.data.block.BlockType; +import electrosphere.game.data.item.Item; import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.ServerWorldData; import electrosphere.server.datacell.gridded.GriddedDataCellManager; @@ -52,6 +55,24 @@ public class StructureRepairUtils { return null; } + /** + * Gets the item id of the material to use for the next repair to perform on a structure + * @param realm The realm + * @param struct The structure + * @return The id of the item to use to repair + */ + public static String getNextRepairMat(Realm realm, Structure struct){ + Vector3i repairPos = StructureRepairUtils.getRepairablePosition(realm, struct); + + //get the id of item entity type for the block we need + BlockFab fab = struct.getFab(); + short blockTypeId = fab.getType(repairPos.x, repairPos.y, repairPos.z); + BlockType blockType = Globals.gameConfigCurrent.getBlockData().getTypeFromId(blockTypeId); + String itemId = Item.getBlockTypeId(blockType); + + return itemId; + } + /** * Solves for whether the structure can be repaired or not * @param realm The realm the structure is within diff --git a/src/main/java/electrosphere/server/simulation/MacroSimulation.java b/src/main/java/electrosphere/server/simulation/MacroSimulation.java index ca42dfb4..e66313ab 100644 --- a/src/main/java/electrosphere/server/simulation/MacroSimulation.java +++ b/src/main/java/electrosphere/server/simulation/MacroSimulation.java @@ -7,6 +7,7 @@ import org.joml.Vector3d; import electrosphere.engine.Globals; import electrosphere.game.data.block.BlockFab; import electrosphere.game.data.struct.StructureData; +import electrosphere.server.datacell.Realm; import electrosphere.server.macro.MacroData; import electrosphere.server.macro.character.Character; import electrosphere.server.macro.character.CharacterUtils; @@ -15,6 +16,7 @@ import electrosphere.server.macro.character.goal.CharacterGoal; import electrosphere.server.macro.character.goal.CharacterGoal.CharacterGoalType; import electrosphere.server.macro.structure.Structure; import electrosphere.server.macro.utils.StructurePlacementUtils; +import electrosphere.server.macro.utils.StructureRepairUtils; import electrosphere.util.FileUtils; /** @@ -30,12 +32,12 @@ public class MacroSimulation { /** * Iterates the macro simulation */ - public static void simulate(MacroData macroData){ + public static void simulate(Realm realm){ List characters = Globals.characterService.getAllCharacters(); if(characters != null && characters.size() > 0){ for(Character character : Globals.characterService.getAllCharacters()){ //do something - MacroSimulation.checkForShelter(macroData, character); + MacroSimulation.checkForShelter(realm, character); MacroSimulation.checkTownMembership(character); } } @@ -62,7 +64,8 @@ public class MacroSimulation { */ static final int MAX_PLACE_ATTEMPTS = 10; - protected static void checkForShelter(MacroData macroData, Character chara){ + protected static void checkForShelter(Realm realm, Character chara){ + MacroData macroData = realm.getMacroData(); // for(Character chara : Globals.macroData.getAliveCharacters()){ /* If doesn’t have shelter, check if in town @@ -74,6 +77,11 @@ public class MacroSimulation { fashion makeshift shelter */ if(CharacterUtils.getShelter(macroData,chara) != null){ + Structure shelter = CharacterUtils.getShelter(macroData,chara); + if(shelter.isRepairable()){ + String repairMat = StructureRepairUtils.getNextRepairMat(realm, shelter); + CharacterGoal.setCharacterGoal(chara, new CharacterGoal(CharacterGoalType.ACQUIRE_ITEM, repairMat)); + } // Vector2i charPos = CharacterUtils.getDiscretePosition(chara); // Town nearbyTown = Town.getTownAtPosition(charPos.x,charPos.y); // if(nearbyTown != null){