diff --git a/src/main/java/nomadrealms/app/context/MainContext.java b/src/main/java/nomadrealms/app/context/MainContext.java index e6f8f38e..6c8a1e49 100644 --- a/src/main/java/nomadrealms/app/context/MainContext.java +++ b/src/main/java/nomadrealms/app/context/MainContext.java @@ -24,7 +24,7 @@ import engine.visuals.lwjgl.render.framebuffer.DefaultFrameBuffer; import nomadrealms.context.game.GameState; import nomadrealms.context.game.event.InputEvent; -import nomadrealms.context.game.world.map.generation.MainWorldGenerationStrategy; +import nomadrealms.context.game.world.map.generation.OverworldGenerationStrategy; import nomadrealms.context.game.zone.Deck; import nomadrealms.render.RenderingEnvironment; import nomadrealms.render.ui.custom.game.GameInterface; @@ -61,7 +61,7 @@ public MainContext() { } public MainContext(Deck deck1, Deck deck2, Deck deck3, Deck deck4) { - gameState = new GameState("New World", stateToUiEventChannel, new MainWorldGenerationStrategy(123456789)); + gameState = new GameState("New World", stateToUiEventChannel, new OverworldGenerationStrategy(123456789)); gameState.world.nomad.deckCollection().importDecks(deck1, deck2, deck3, deck4); } diff --git a/src/main/java/nomadrealms/context/game/GameState.java b/src/main/java/nomadrealms/context/game/GameState.java index 83e81d25..a37f7597 100644 --- a/src/main/java/nomadrealms/context/game/GameState.java +++ b/src/main/java/nomadrealms/context/game/GameState.java @@ -14,8 +14,8 @@ import nomadrealms.context.game.world.World; import nomadrealms.context.game.world.map.area.Tile; import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate; -import nomadrealms.context.game.world.map.generation.MainWorldGenerationStrategy; import nomadrealms.context.game.world.map.generation.MapGenerationStrategy; +import nomadrealms.context.game.world.map.generation.OverworldGenerationStrategy; import nomadrealms.context.game.world.weather.Weather; import nomadrealms.render.RenderingEnvironment; import nomadrealms.render.ui.Camera; @@ -46,7 +46,7 @@ public class GameState { * No-arg constructor for serialization. */ protected GameState() { - this("Default World", new LinkedList<>(), new MainWorldGenerationStrategy(123456789)); + this("Default World", new LinkedList<>(), new OverworldGenerationStrategy(123456789)); } public GameState(String name, Queue uiEventChannel, MapGenerationStrategy mapGenerationStrategy) { diff --git a/src/main/java/nomadrealms/context/game/GameStateSerializer.java b/src/main/java/nomadrealms/context/game/GameStateSerializer.java index 9a9dd9dc..30e8735e 100644 --- a/src/main/java/nomadrealms/context/game/GameStateSerializer.java +++ b/src/main/java/nomadrealms/context/game/GameStateSerializer.java @@ -45,15 +45,16 @@ import nomadrealms.context.game.world.map.area.Zone; import nomadrealms.context.game.world.map.area.coordinate.Coordinate; import nomadrealms.context.game.world.map.generation.MapGenerationStrategy; -import nomadrealms.context.game.world.map.generation.status.GenerationStep; -import nomadrealms.context.game.world.map.generation.status.GenerationStepStatus; -import nomadrealms.context.game.world.map.generation.status.biome.BiomeParameters; -import nomadrealms.context.game.world.map.generation.status.biome.noise.BiomeNoiseGenerator; -import nomadrealms.context.game.world.map.generation.status.biome.noise.BiomeNoiseGeneratorCluster; -import nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory; -import nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType; -import nomadrealms.context.game.world.map.generation.status.biome.nomenclature.ContinentType; -import nomadrealms.context.game.world.map.generation.status.points.point.PointOfInterest; +import nomadrealms.context.game.world.map.generation.overworld.GenerationProcess; +import nomadrealms.context.game.world.map.generation.overworld.GenerationStep; +import nomadrealms.context.game.world.map.generation.overworld.biome.BiomeParameters; +import nomadrealms.context.game.world.map.generation.overworld.biome.noise.BiomeNoiseGenerator; +import nomadrealms.context.game.world.map.generation.overworld.biome.noise.BiomeNoiseGeneratorCluster; +import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory; +import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType; +import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.ContinentType; +import nomadrealms.context.game.world.map.generation.overworld.points.point.PointOfInterest; +import nomadrealms.context.game.world.map.generation.overworld.structure.StructureGenerationConfig; import nomadrealms.context.game.world.map.tile.factory.TileType; import nomadrealms.context.game.world.weather.Weather; import nomadrealms.context.game.zone.CardStack; @@ -134,7 +135,7 @@ private void registerClasses() { kryo.register(TileType[].class); kryo.register(TileType[][].class); kryo.register(Weather.class); - kryo.register(GenerationStepStatus.class); + kryo.register(GenerationProcess.class); kryo.register(BiomeNoiseGenerator.class); kryo.register(BiomeNoiseGeneratorCluster.class); kryo.register(PointOfInterest.class); @@ -155,20 +156,22 @@ private void registerClasses() { kryo.register(DropItemEvent.class); kryo.register(CardZoneEventChannel.class); kryo.register(CardZoneListener.class); + kryo.register(Structure[].class); + kryo.register(Structure[][].class); Reflections reflections = new Reflections(new ConfigurationBuilder().forPackage("nomadrealms")); List> superclasses = Arrays.asList( Event.class, CardExpression.class, Actor.class, - Structure.class, CardPlayerAI.class, Tile.class, Coordinate.class, MapGenerationStrategy.class, + GenerationStep.class, + StructureGenerationConfig.class, Card.class, Action.class, - GenerationStep.class, Constraint.class); for (Class superclass : superclasses) { for (Class clazz : reflections.getSubTypesOf(superclass)) { diff --git a/src/main/java/nomadrealms/context/game/actor/structure/Structure.java b/src/main/java/nomadrealms/context/game/actor/structure/Structure.java index 351d2bb2..2d2bf65e 100644 --- a/src/main/java/nomadrealms/context/game/actor/structure/Structure.java +++ b/src/main/java/nomadrealms/context/game/actor/structure/Structure.java @@ -23,7 +23,7 @@ public class Structure implements Actor { private Inventory inventory; private final String name; - private final String image; + protected final String image; private final int constructionTime; private final int maxHealth; private int health; diff --git a/src/main/java/nomadrealms/context/game/actor/structure/TreeStructure.java b/src/main/java/nomadrealms/context/game/actor/structure/TreeStructure.java index d8b178a0..fbbf7753 100644 --- a/src/main/java/nomadrealms/context/game/actor/structure/TreeStructure.java +++ b/src/main/java/nomadrealms/context/game/actor/structure/TreeStructure.java @@ -2,8 +2,8 @@ public class TreeStructure extends Structure { - public TreeStructure() { - super("tree", "tree_1", 1, 50); - } + public TreeStructure() { + super("tree", "oak_tree", 1, 50); + } } diff --git a/src/main/java/nomadrealms/context/game/world/GameMap.java b/src/main/java/nomadrealms/context/game/world/GameMap.java index 3e9e3e51..2fd28f2d 100644 --- a/src/main/java/nomadrealms/context/game/world/GameMap.java +++ b/src/main/java/nomadrealms/context/game/world/GameMap.java @@ -1,5 +1,7 @@ package nomadrealms.context.game.world; +import static nomadrealms.context.game.world.map.area.coordinate.RegionCoordinate.regionCoordinateOf; + import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -40,7 +42,7 @@ public GameMap(World world, MapGenerationStrategy strategy) { } public void render(RenderingEnvironment re, Vector2f origin) { - RegionCoordinate regionCoord = RegionCoordinate.regionCoordinateOf(origin); + RegionCoordinate regionCoord = regionCoordinateOf(origin); getRegion(regionCoord).render(re, origin); } diff --git a/src/main/java/nomadrealms/context/game/world/World.java b/src/main/java/nomadrealms/context/game/world/World.java index a2a39588..2969b61a 100644 --- a/src/main/java/nomadrealms/context/game/world/World.java +++ b/src/main/java/nomadrealms/context/game/world/World.java @@ -1,8 +1,10 @@ package nomadrealms.context.game.world; +import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static nomadrealms.context.game.item.Item.OAK_LOG; import static nomadrealms.context.game.item.Item.WHEAT_SEED; +import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.chunkCoordinateOf; import java.util.ArrayList; import java.util.List; @@ -66,23 +68,36 @@ public World(GameState state, MapGenerationStrategy mapGenerationStrategy) { Farmer farmer = new Farmer("Fred", getTile(new TileCoordinate(new ChunkCoordinate(new ZoneCoordinate(new RegionCoordinate(0, 0), 0, 0), 0, 1), 0, 0))); - addActor(nomad); - addActor(farmer); + addActor(nomad, true); + addActor(farmer, true); addActor(new FeralMonkey("bob", getTile(new TileCoordinate( - new ChunkCoordinate(new ZoneCoordinate(new RegionCoordinate(0, 0), 0, 0), 0, 0), 6, 6)))); + new ChunkCoordinate(new ZoneCoordinate(new RegionCoordinate(0, 0), 0, 0), 0, 0), 6, 6))), true); } public void renderMap(RenderingEnvironment re) { map.render(re, re.camera.position().vector()); + } public void renderActors(RenderingEnvironment re) { - for (Actor entity : new ArrayList<>(actors)) { - if (entity.isDestroyed()) { - continue; - // TODO: eventually remove destroyed entities after a delay + ChunkCoordinate chunkCoord = chunkCoordinateOf(re.camera.position().vector()); + List chunksToRender = asList( + getChunk(chunkCoord), + getChunk(chunkCoord.up()), + getChunk(chunkCoord.down()), + getChunk(chunkCoord.left()), + getChunk(chunkCoord.right()), + getChunk(chunkCoord.down().right()), + getChunk(chunkCoord.right().right()), + getChunk(chunkCoord.down().down()) + ); + for (Chunk chunk : chunksToRender) { + for (Tile tile : chunk.tiles()) { + // TODO: eventually remove destroyed entities after a delay. not here, but in update() + if (tile.actor() != null && !tile.actor().isDestroyed()) { + tile.actor().render(re); + } } - entity.render(re); } } @@ -90,6 +105,8 @@ public void renderActors(RenderingEnvironment re) { int i = 0; public void update(InputEventFrame inputEventFrame) { + // TODO: this actually does not update actors that werent added using addActor(), i.e. actors loaded from + // zone generation List currentActors = new ArrayList<>(this.actors); // Prevent concurrent modification for added actors i++; if (i % 10 == 0) { @@ -146,10 +163,17 @@ public void addAllProcChains(List chains) { } public void addActor(Actor actor) { + addActor(actor, false); + } + + public void addActor(Actor actor, boolean forced) { actors.add(actor); if (actor instanceof Structure) { structures.add((Structure) actor); } + if (forced) { + actor.tile().clearActor(); + } // TODO: figure out to do when tile is already occupied actor.tile().actor(actor); } diff --git a/src/main/java/nomadrealms/context/game/world/map/area/Chunk.java b/src/main/java/nomadrealms/context/game/world/map/area/Chunk.java index 7e061517..464b8b9a 100644 --- a/src/main/java/nomadrealms/context/game/world/map/area/Chunk.java +++ b/src/main/java/nomadrealms/context/game/world/map/area/Chunk.java @@ -4,6 +4,9 @@ import static nomadrealms.context.game.world.map.area.Tile.TILE_VERTICAL_SPACING; import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.CHUNK_SIZE; +import java.util.ArrayList; +import java.util.List; + import engine.common.math.Vector2f; import engine.visuals.constraint.box.ConstraintPair; import nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate; @@ -82,6 +85,16 @@ public void replace(Tile tile) { tiles[tile.coord().x()][tile.coord().y()] = tile; } + public List tiles() { + List tiles = new ArrayList<>(); + for (int x = 0; x < CHUNK_SIZE; x++) { + for (int y = 0; y < CHUNK_SIZE; y++) { + tiles.add(this.tiles[x][y]); + } + } + return tiles; + } + public void tiles(Tile[][] tiles) { this.tiles = tiles; } diff --git a/src/main/java/nomadrealms/context/game/world/map/area/Tile.java b/src/main/java/nomadrealms/context/game/world/map/area/Tile.java index 6b342339..44c72545 100644 --- a/src/main/java/nomadrealms/context/game/world/map/area/Tile.java +++ b/src/main/java/nomadrealms/context/game/world/map/area/Tile.java @@ -143,6 +143,7 @@ public void actor(Actor actor) { throw new IllegalStateException("Tile " + coord + " is already occupied by " + this.actor); } this.actor = actor; + actor.tile(this); } public void clearActor() { diff --git a/src/main/java/nomadrealms/context/game/world/map/area/Zone.java b/src/main/java/nomadrealms/context/game/world/map/area/Zone.java index cb658e86..01dea444 100644 --- a/src/main/java/nomadrealms/context/game/world/map/area/Zone.java +++ b/src/main/java/nomadrealms/context/game/world/map/area/Zone.java @@ -5,7 +5,6 @@ import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.CHUNK_SIZE; import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.chunkCoordinateOf; import static nomadrealms.context.game.world.map.area.coordinate.ZoneCoordinate.ZONE_SIZE; -import static nomadrealms.context.game.world.map.generation.status.GenerationStepStatus.EMPTY; import java.util.Random; @@ -16,10 +15,11 @@ import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate; import nomadrealms.context.game.world.map.area.coordinate.ZoneCoordinate; import nomadrealms.context.game.world.map.generation.MapGenerationStrategy; -import nomadrealms.context.game.world.map.generation.status.GenerationStepStatus; -import nomadrealms.context.game.world.map.generation.status.biome.BiomeGenerationStep; -import nomadrealms.context.game.world.map.generation.status.points.PointsGenerationStep; -import nomadrealms.context.game.world.map.generation.status.points.point.PointOfInterest; +import nomadrealms.context.game.world.map.generation.overworld.GenerationProcess; +import nomadrealms.context.game.world.map.generation.overworld.biome.BiomeGenerationStep; +import nomadrealms.context.game.world.map.generation.overworld.points.PointsGenerationStep; +import nomadrealms.context.game.world.map.generation.overworld.points.point.PointOfInterest; +import nomadrealms.context.game.world.map.generation.overworld.structure.StructureGenerationStep; import nomadrealms.render.RenderingEnvironment; /** @@ -35,13 +35,11 @@ public class Zone { private transient Region region; - private ZoneCoordinate coord; + private final ZoneCoordinate coord; - private Chunk[][] chunks; + private final Chunk[][] chunks; - private GenerationStepStatus generationStatus = EMPTY; - private BiomeGenerationStep biomeGenerationStep; - private PointsGenerationStep pointsGenerationStep; + private GenerationProcess generationProcess; private transient Random rng; private int rngCounter = 0; @@ -70,11 +68,8 @@ public void initRNG() { public Zone(World world, ZoneCoordinate coord, MapGenerationStrategy strategy) { this.region = world.getRegion(coord.region()); this.coord = coord; - initRNG(); - - biomeGenerationStep = new BiomeGenerationStep(this, world.generation().seed()); - pointsGenerationStep = new PointsGenerationStep(this, world.generation().seed()); + generationProcess = new GenerationProcess(this, strategy); this.chunks = strategy.generateZone(world, this); } @@ -95,7 +90,7 @@ public void render(RenderingEnvironment re, Vector2f origin) { region.world().getChunk(chunkCoord.down().down()).render(re); if (re.showDebugInfo) { - for (PointOfInterest poi : pointsGenerationStep.points()) { + for (PointOfInterest poi : generationProcess.points().points()) { poi.render(this, re); } } @@ -128,11 +123,15 @@ public Zone[][] getSurroundingZones(World world, int range) { } public BiomeGenerationStep biomeGenerationStep() { - return biomeGenerationStep; + return generationProcess.biome(); } public PointsGenerationStep pointsGenerationStep() { - return pointsGenerationStep; + return generationProcess.points(); + } + + public StructureGenerationStep structureGenerationStep() { + return generationProcess.structure(); } private ConstraintPair indexPosition() { diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/FileBasedGenerationStrategy.java b/src/main/java/nomadrealms/context/game/world/map/generation/FileBasedGenerationStrategy.java index 80233bb4..3b4609cd 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/FileBasedGenerationStrategy.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/FileBasedGenerationStrategy.java @@ -31,6 +31,12 @@ public FileBasedGenerationStrategy() { this.worldData = loadWorldData(); } + @Override + public MapGenerationParameters parameters() { + return new MapGenerationParameters() + .seed(0); + } + @Override public Tile[][] generateChunk(Zone zone, Chunk chunk, ChunkCoordinate coord) { TileType[][] chunkTileTypes = new TileType[CHUNK_SIZE][CHUNK_SIZE]; @@ -64,11 +70,6 @@ public Chunk[][] generateZone(World world, Zone zone) { return chunks; } - @Override - public long seed() { - return 0; - } - private List loadWorldData() { List lines = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(new FileReader(getFile()))) { diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/MapGenerationParameters.java b/src/main/java/nomadrealms/context/game/world/map/generation/MapGenerationParameters.java new file mode 100644 index 00000000..72c2646a --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/MapGenerationParameters.java @@ -0,0 +1,32 @@ +package nomadrealms.context.game.world.map.generation; + +import nomadrealms.context.game.world.map.generation.overworld.biome.noise.BiomeNoiseGeneratorCluster; + +public class MapGenerationParameters { + + private long seed; + private BiomeNoiseGeneratorCluster biomeNoise; + + public MapGenerationParameters() { + } + + public MapGenerationParameters seed(long seed) { + this.seed = seed; + return this; + } + + public long seed() { + return seed; + } + + public MapGenerationParameters biomeNoise(BiomeNoiseGeneratorCluster biomeNoise) { + this.biomeNoise = biomeNoise; + return this; + } + + public BiomeNoiseGeneratorCluster biomeNoise() { + return biomeNoise; + } + + +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/MapGenerationStrategy.java b/src/main/java/nomadrealms/context/game/world/map/generation/MapGenerationStrategy.java index 69767950..e952bace 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/MapGenerationStrategy.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/MapGenerationStrategy.java @@ -8,10 +8,10 @@ public interface MapGenerationStrategy { + public MapGenerationParameters parameters(); + public Tile[][] generateChunk(Zone zone, Chunk chunk, ChunkCoordinate coord); public Chunk[][] generateZone(World world, Zone zone); - public long seed(); - } diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/MainWorldGenerationStrategy.java b/src/main/java/nomadrealms/context/game/world/map/generation/OverworldGenerationStrategy.java similarity index 84% rename from src/main/java/nomadrealms/context/game/world/map/generation/MainWorldGenerationStrategy.java rename to src/main/java/nomadrealms/context/game/world/map/generation/OverworldGenerationStrategy.java index 3847e8ed..be22e7dc 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/MainWorldGenerationStrategy.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/OverworldGenerationStrategy.java @@ -5,13 +5,14 @@ import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.CHUNK_SIZE; import static nomadrealms.context.game.world.map.area.coordinate.ZoneCoordinate.ZONE_SIZE; +import nomadrealms.context.game.actor.structure.Structure; import nomadrealms.context.game.world.World; import nomadrealms.context.game.world.map.area.Chunk; import nomadrealms.context.game.world.map.area.Tile; import nomadrealms.context.game.world.map.area.Zone; import nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate; import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate; -import nomadrealms.context.game.world.map.generation.status.biome.noise.BiomeNoiseGeneratorCluster; +import nomadrealms.context.game.world.map.generation.overworld.biome.noise.BiomeNoiseGeneratorCluster; import nomadrealms.context.game.world.map.tile.GrassTile; import nomadrealms.context.game.world.map.tile.GrayscaleTile; import nomadrealms.context.game.world.map.tile.IceTile; @@ -21,25 +22,31 @@ import nomadrealms.context.game.world.map.tile.StoneTile; import nomadrealms.context.game.world.map.tile.WaterTile; -public class MainWorldGenerationStrategy implements MapGenerationStrategy { +public class OverworldGenerationStrategy implements MapGenerationStrategy { private final long worldSeed; - private final BiomeNoiseGeneratorCluster biomeNoise; /** * No-arg constructor for serialization. */ - protected MainWorldGenerationStrategy() { + protected OverworldGenerationStrategy() { worldSeed = 0; biomeNoise = null; } - public MainWorldGenerationStrategy(long worldSeed) { + public OverworldGenerationStrategy(long worldSeed) { this.worldSeed = worldSeed; biomeNoise = new BiomeNoiseGeneratorCluster(worldSeed, 0.01f); } + @Override + public MapGenerationParameters parameters() { + return new MapGenerationParameters() + .seed(worldSeed) + .biomeNoise(biomeNoise); + } + @Override public Tile[][] generateChunk(Zone zone, Chunk chunk, ChunkCoordinate coord) { Tile[][] tiles = new Tile[CHUNK_SIZE][CHUNK_SIZE]; @@ -124,6 +131,12 @@ public Tile[][] generateChunk(Zone zone, Chunk chunk, ChunkCoordinate coord) { default: tile = new GrayscaleTile(chunk, tileCoord, biomeNoise.depth().eval(tileCoord)); } + Structure structure = zone.structureGenerationStep().structures() + [chunk.coord().x() * CHUNK_SIZE + tileCoord.x()] + [chunk.coord().y() * CHUNK_SIZE + tileCoord.y()]; + if (structure != null) { + tile.actor(structure); + } tiles[tileCoord.x()][tileCoord.y()] = tile; } return tiles; @@ -132,8 +145,9 @@ public Tile[][] generateChunk(Zone zone, Chunk chunk, ChunkCoordinate coord) { @Override public Chunk[][] generateZone(World world, Zone zone) { Zone[][] zones = zone.getSurroundingZones(world, 0); - zone.biomeGenerationStep().generate(biomeNoise, zones); - zone.pointsGenerationStep().generate(zones); + zone.biomeGenerationStep().generate(zones, this); + zone.pointsGenerationStep().generate(zones, this); + zone.structureGenerationStep().generate(zones, this); Chunk[][] chunks = new Chunk[ZONE_SIZE][ZONE_SIZE]; for (ChunkCoordinate chunkCoord : flatten(zone.coord().chunkCoordinates())) { @@ -143,10 +157,5 @@ public Chunk[][] generateZone(World world, Zone zone) { } return chunks; } - - @Override - public long seed() { - return worldSeed; - } - + } diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/TemplateGenerationStrategy.java b/src/main/java/nomadrealms/context/game/world/map/generation/TemplateGenerationStrategy.java index 4ab40206..1fc18734 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/TemplateGenerationStrategy.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/TemplateGenerationStrategy.java @@ -14,6 +14,12 @@ public class TemplateGenerationStrategy implements MapGenerationStrategy { + @Override + public MapGenerationParameters parameters() { + return new MapGenerationParameters() + .seed(0); + } + @Override public Tile[][] generateChunk(Zone zone, Chunk chunk, ChunkCoordinate coord) { return TileFactory.createTiles(chunk, new TileType[][]{ @@ -65,9 +71,4 @@ public Chunk[][] generateZone(World world, Zone zone) { return chunks; } - @Override - public long seed() { - return 0; - } - } \ No newline at end of file diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/GenerationProcess.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/GenerationProcess.java new file mode 100644 index 00000000..9fda4705 --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/GenerationProcess.java @@ -0,0 +1,54 @@ +package nomadrealms.context.game.world.map.generation.overworld; + +import static java.util.Arrays.asList; + +import java.util.List; + +import nomadrealms.context.game.world.map.area.Zone; +import nomadrealms.context.game.world.map.generation.MapGenerationStrategy; +import nomadrealms.context.game.world.map.generation.overworld.biome.BiomeGenerationStep; +import nomadrealms.context.game.world.map.generation.overworld.points.PointsGenerationStep; +import nomadrealms.context.game.world.map.generation.overworld.structure.StructureGenerationStep; + +public class GenerationProcess { + + private final BiomeGenerationStep biome; + private final PointsGenerationStep points; + private final StructureGenerationStep structure; + + + /** + * No-arg constructor for serialization. + */ + protected GenerationProcess() { + this.biome = null; + this.points = null; + this.structure = null; + } + + public GenerationProcess(Zone zone, MapGenerationStrategy strategy) { + biome = new BiomeGenerationStep(zone, strategy); + points = new PointsGenerationStep(zone, strategy); + structure = new StructureGenerationStep(zone, strategy); + } + + public List steps() { + return asList( + biome, + points, + structure + ); + } + + public BiomeGenerationStep biome() { + return biome; + } + + public PointsGenerationStep points() { + return points; + } + + public StructureGenerationStep structure() { + return structure; + } +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/GenerationStep.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/GenerationStep.java similarity index 54% rename from src/main/java/nomadrealms/context/game/world/map/generation/status/GenerationStep.java rename to src/main/java/nomadrealms/context/game/world/map/generation/overworld/GenerationStep.java index 0f7c661d..941f9cd6 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/GenerationStep.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/GenerationStep.java @@ -1,6 +1,7 @@ -package nomadrealms.context.game.world.map.generation.status; +package nomadrealms.context.game.world.map.generation.overworld; import nomadrealms.context.game.world.map.area.Zone; +import nomadrealms.context.game.world.map.generation.MapGenerationStrategy; public abstract class GenerationStep { @@ -12,8 +13,6 @@ public GenerationStep(Zone zone, long worldSeed) { this.worldSeed = worldSeed; } - public abstract GenerationStepStatus status(); - - public abstract void generate(Zone[][] surrounding); + public abstract void generate(Zone[][] surrounding, MapGenerationStrategy strategy); } diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/BiomeGenerationStep.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/BiomeGenerationStep.java new file mode 100644 index 00000000..6d76d2d5 --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/BiomeGenerationStep.java @@ -0,0 +1,100 @@ +package nomadrealms.context.game.world.map.generation.overworld.biome; + +import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.CHUNK_SIZE; +import static nomadrealms.context.game.world.map.area.coordinate.ZoneCoordinate.ZONE_SIZE; + +import nomadrealms.context.game.world.map.area.Zone; +import nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate; +import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate; +import nomadrealms.context.game.world.map.generation.MapGenerationStrategy; +import nomadrealms.context.game.world.map.generation.overworld.GenerationStep; +import nomadrealms.context.game.world.map.generation.overworld.biome.noise.BiomeNoiseGeneratorCluster; +import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory; +import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType; +import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.ContinentType; + +/** + * Generates the biomes for the zone. + *

+ * Reference: Minecraft biome generation + * + * @author Lunkle + */ +public class BiomeGenerationStep extends GenerationStep { + + private transient final BiomeParameters[][] parameters = + new BiomeParameters[ZONE_SIZE * CHUNK_SIZE][ZONE_SIZE * CHUNK_SIZE]; + private transient final ContinentType[][] continents = new ContinentType[ZONE_SIZE * CHUNK_SIZE][ZONE_SIZE * CHUNK_SIZE]; + private transient final BiomeCategory[][] categories = new BiomeCategory[ZONE_SIZE * CHUNK_SIZE][ZONE_SIZE * CHUNK_SIZE]; + private final BiomeVariantType[][] biomes = new BiomeVariantType[ZONE_SIZE * CHUNK_SIZE][ZONE_SIZE * CHUNK_SIZE]; + + + /** + * No-arg constructor for serialization. + */ + protected BiomeGenerationStep() { + super(null, 0); + } + + public BiomeGenerationStep(Zone zone, MapGenerationStrategy strategy) { + super(zone, strategy.parameters().seed()); + } + + @Override + public void generate(Zone[][] surrounding, MapGenerationStrategy strategy) { + BiomeNoiseGeneratorCluster noise = strategy.parameters().biomeNoise(); + + for (ChunkCoordinate[] chunkRow : zone.coord().chunkCoordinates()) { + for (ChunkCoordinate chunk : chunkRow) { + for (TileCoordinate[] tileRow : chunk.tileCoordinates()) { + for (TileCoordinate tile : tileRow) { + float temperature = noise.temperature().eval(tile); + float humidity = noise.humidity().eval(tile); + float continentalness = noise.continentalness().eval(tile); + float erosion = noise.erosion().eval(tile); + float weirdness = noise.weirdness().eval(tile); + float depth = noise.depth().eval(tile); + + BiomeParameters parameters = new BiomeParameters(temperature, humidity, continentalness, erosion, weirdness, depth); + + int x = chunk.x() * CHUNK_SIZE + tile.x(); + int y = chunk.y() * CHUNK_SIZE + tile.y(); + this.parameters[x][y] = parameters; + this.continents[x][y] = parameters.calculateContinent(); + this.categories[x][y] = parameters.calculateBiomeCategory(); + biomes[x][y] = parameters.calculateBiomeVariant(); + } + } + } + } + } + + public BiomeVariantType[][] biomes() { + return biomes; + } + + public BiomeVariantType biomeAt(TileCoordinate coord) { + return biomes + [coord.chunk().x() * CHUNK_SIZE + coord.x()] + [coord.chunk().y() * CHUNK_SIZE + coord.y()]; + } + + public BiomeParameters parametersAt(TileCoordinate coord) { + return parameters + [coord.chunk().x() * CHUNK_SIZE + coord.x()] + [coord.chunk().y() * CHUNK_SIZE + coord.y()]; + } + + public BiomeCategory categoryAt(TileCoordinate coord) { + return categories + [coord.chunk().x() * CHUNK_SIZE + coord.x()] + [coord.chunk().y() * CHUNK_SIZE + coord.y()]; + } + + public ContinentType continentAt(TileCoordinate coord) { + return continents + [coord.chunk().x() * CHUNK_SIZE + coord.x()] + [coord.chunk().y() * CHUNK_SIZE + coord.y()]; + } + +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/BiomeParameters.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/BiomeParameters.java new file mode 100644 index 00000000..6d34a146 --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/BiomeParameters.java @@ -0,0 +1,184 @@ +package nomadrealms.context.game.world.map.generation.overworld.biome; + +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory.AQUATIC; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory.HUMIDITY_CEIL; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory.HUMIDITY_FLOOR; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory.TEMPERATURE_CEIL; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory.TEMPERATURE_FLOOR; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory.TEMPERATURE_HUMIDITY_VALUES; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType.BEACH; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType.DEEP_OCEAN; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType.DESERT; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType.FOREST; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType.NORMAL_OCEAN; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType.PLAINS; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType.SNOWY_TUNDRA; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType.TAIGA; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType.TEMPERATE_RAINFOREST; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.ContinentType.HIGHLAND; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.ContinentType.LOWLAND; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.ContinentType.MARINE; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.ContinentType.MIDLAND; + +import java.util.Map; + +import engine.common.math.Vector2i; +import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory; +import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType; +import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.ContinentType; + +/** + * Represents the parameters used to determine a biome. + *

+ * The parameters are: + *
    + *
  • Temperature
  • + *
  • Humidity
  • + *
  • Continentalness
  • + *
  • Erosion
  • + *
  • Weirdness
  • + *
  • Depth
  • + * + * @author Lunkle + */ +public class BiomeParameters { + + private final float temperature; + private final float humidity; + private final float continentalness; + private final float erosion; + private final float weirdness; + private final float depth; + + /** + * No-args constructor for serialization. + */ + public BiomeParameters() { + this.temperature = 0; + this.humidity = 0; + this.continentalness = 0; + this.erosion = 0; + this.weirdness = 0; + this.depth = 0; + } + + public BiomeParameters(float temperature, float humidity, float continentalness, float erosion, float weirdness, float depth) { + this.temperature = temperature; + this.humidity = humidity; + this.continentalness = continentalness; + this.erosion = erosion; + this.weirdness = weirdness; + this.depth = depth; + } + + public float temperature() { + return temperature; + } + + public float humidity() { + return humidity; + } + + public float continentalness() { + return continentalness; + } + + public float erosion() { + return erosion; + } + + public float weirdness() { + return weirdness; + } + + public float depth() { + return depth; + } + + public ContinentType calculateContinent() { + if (continentalness() < 0) { + return MARINE; + } else if (continentalness() < 0.2) { + return LOWLAND; + } else if (continentalness() < 0.6) { + return MIDLAND; + } else { + return HIGHLAND; + } + } + + public BiomeCategory calculateBiomeCategory() { + ContinentType continent = calculateContinent(); + switch (continent) { + case MARINE: + return AQUATIC; + case LOWLAND: + case MIDLAND: + case HIGHLAND: + BiomeCategory category = null; + double closest = Double.MAX_VALUE; + for (Map.Entry entry : TEMPERATURE_HUMIDITY_VALUES.entrySet()) { + Vector2i temperatureHumidity = entry.getValue(); + float adjustedTemperature = (temperature() + 1) * (TEMPERATURE_CEIL - TEMPERATURE_FLOOR) / 2 + TEMPERATURE_FLOOR; + float adjustedHumidity = (humidity() + 1) * (HUMIDITY_CEIL - HUMIDITY_FLOOR) / 2 + HUMIDITY_FLOOR; + double distanceSquared = + Math.pow(temperatureHumidity.x() - adjustedTemperature, 2) + Math.pow(temperatureHumidity.y() - adjustedHumidity, 2); + if (distanceSquared < closest) { + closest = distanceSquared; + category = entry.getKey(); + } + } + return category; + } + throw new IllegalStateException("Could not decide biome category for parameters: " + this); + } + + public BiomeVariantType calculateBiomeVariant() { + ContinentType continent = calculateContinent(); + BiomeCategory category = calculateBiomeCategory(); + + if (continent == MARINE) { + if (depth() < -0.1) { + return DEEP_OCEAN; + } else if (depth() < 0.6) { + return NORMAL_OCEAN; + } else { + return BEACH; + } + } + switch (category) { + case AQUATIC: + // Unreachable code for now, should catch in previous if statement + return NORMAL_OCEAN; + case RAINFOREST: + return TEMPERATE_RAINFOREST; + case GRASSLAND: + return PLAINS; + case CONIFEROUS_FOREST: + return TAIGA; + case TEMPERATE_DECIDUOUS_FOREST: + return FOREST; + case DESERT: + return DESERT; + case TUNDRA: + return SNOWY_TUNDRA; + default: + throw new IllegalStateException("Could not decide biome variant for parameters: " + this + " and " + + "category: " + category + " and continent: " + continent); + } + } + + + @Override + public String toString() { + return "BiomeParameters{" + + "temperature=" + temperature + + ", humidity=" + humidity + + ", continentalness=" + continentalness + + ", erosion=" + erosion + + ", weirdness=" + weirdness + + ", depth=" + depth + + '}'; + } + +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/noise/BiomeNoiseGenerator.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/noise/BiomeNoiseGenerator.java similarity index 82% rename from src/main/java/nomadrealms/context/game/world/map/generation/status/biome/noise/BiomeNoiseGenerator.java rename to src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/noise/BiomeNoiseGenerator.java index 9f1a3a10..9d00a9bd 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/noise/BiomeNoiseGenerator.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/noise/BiomeNoiseGenerator.java @@ -1,4 +1,4 @@ -package nomadrealms.context.game.world.map.generation.status.biome.noise; +package nomadrealms.context.game.world.map.generation.overworld.biome.noise; import static java.lang.Math.abs; import static java.lang.Math.pow; @@ -24,15 +24,14 @@ public class BiomeNoiseGenerator { * No-arg constructor for serialization. */ protected BiomeNoiseGenerator() { - this(0, null, 0); + this(null, 0); } - public BiomeNoiseGenerator(long seed, LayeredNoise noise, float frequency) { - this(seed, noise, frequency, 1); + public BiomeNoiseGenerator(LayeredNoise noise, float frequency) { + this(noise, frequency, 1); } - public BiomeNoiseGenerator(long seed, LayeredNoise noise, float frequency, float power) { - this.seed = seed; + public BiomeNoiseGenerator(LayeredNoise noise, float frequency, float power) { this.noise = noise; this.frequency = frequency; this.power = power; diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/noise/BiomeNoiseGeneratorCluster.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/noise/BiomeNoiseGeneratorCluster.java similarity index 85% rename from src/main/java/nomadrealms/context/game/world/map/generation/status/biome/noise/BiomeNoiseGeneratorCluster.java rename to src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/noise/BiomeNoiseGeneratorCluster.java index 4d916926..1b5232ef 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/noise/BiomeNoiseGeneratorCluster.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/noise/BiomeNoiseGeneratorCluster.java @@ -1,4 +1,4 @@ -package nomadrealms.context.game.world.map.generation.status.biome.noise; +package nomadrealms.context.game.world.map.generation.overworld.biome.noise; import nomadrealms.math.generation.map.LayeredNoise; import nomadrealms.math.generation.map.NoiseOctave; @@ -29,7 +29,7 @@ public BiomeNoiseGeneratorCluster(long seed) { public BiomeNoiseGeneratorCluster(long seed, float frequency) { OpenSimplexNoise base = new OpenSimplexNoise(seed); - this.temperature = new BiomeNoiseGenerator(seed, new LayeredNoise( + this.temperature = new BiomeNoiseGenerator(new LayeredNoise( new NoiseOctave(base, 0.05, 0.4, 0), new NoiseOctave(base, 2, 0.02, 1), new NoiseOctave(base, 1, 0.3, 2), @@ -38,7 +38,7 @@ public BiomeNoiseGeneratorCluster(long seed, float frequency) { new NoiseOctave(base, 0.1, 0.05, 5), new NoiseOctave(base, 0.05, 0.02, 6)), frequency); - this.humidity = new BiomeNoiseGenerator(seed, new LayeredNoise( + this.humidity = new BiomeNoiseGenerator(new LayeredNoise( new NoiseOctave(base, 0.05, 0.4, 0), new NoiseOctave(base, 2, 0.02, 1), new NoiseOctave(base, 1, 0.3, 2), @@ -47,11 +47,11 @@ public BiomeNoiseGeneratorCluster(long seed, float frequency) { new NoiseOctave(base, 0.1, 0.05, 5), new NoiseOctave(base, 0.05, 0.02, 6)), frequency); - this.continentalness = new BiomeNoiseGenerator(seed, new LayeredNoise( + this.continentalness = new BiomeNoiseGenerator(new LayeredNoise( new NoiseOctave(base, 1, 0.025, 0), new NoiseOctave(base, 0.25, 0.975, 6)), frequency, 3); - this.erosion = new BiomeNoiseGenerator(seed, new LayeredNoise( + this.erosion = new BiomeNoiseGenerator(new LayeredNoise( new NoiseOctave(base, 0.05, 0.4, 0), new NoiseOctave(base, 2, 0.02, 1), new NoiseOctave(base, 1, 0.3, 2), @@ -60,7 +60,7 @@ public BiomeNoiseGeneratorCluster(long seed, float frequency) { new NoiseOctave(base, 0.1, 0.05, 5), new NoiseOctave(base, 0.05, 0.02, 6)), frequency); - this.weirdness = new BiomeNoiseGenerator(seed, new LayeredNoise( + this.weirdness = new BiomeNoiseGenerator(new LayeredNoise( new NoiseOctave(base, 0.05, 0.4, 0), new NoiseOctave(base, 2, 0.02, 1), new NoiseOctave(base, 1, 0.3, 2), @@ -69,7 +69,7 @@ public BiomeNoiseGeneratorCluster(long seed, float frequency) { new NoiseOctave(base, 0.1, 0.05, 5), new NoiseOctave(base, 0.05, 0.02, 6)), frequency); - this.depth = new BiomeNoiseGenerator(seed, new LayeredNoise( + this.depth = new BiomeNoiseGenerator(new LayeredNoise( // new NoiseOctave(base, 100, 0.4, 0), // new NoiseOctave(base, 2, 0.02, 1), // new NoiseOctave(base, 1, 0.3, 2), diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/nomenclature/BiomeCategory.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/nomenclature/BiomeCategory.java similarity index 96% rename from src/main/java/nomadrealms/context/game/world/map/generation/status/biome/nomenclature/BiomeCategory.java rename to src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/nomenclature/BiomeCategory.java index 222c45d6..2fcf9b19 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/nomenclature/BiomeCategory.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/nomenclature/BiomeCategory.java @@ -1,4 +1,4 @@ -package nomadrealms.context.game.world.map.generation.status.biome.nomenclature; +package nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/nomenclature/BiomeVariantType.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/nomenclature/BiomeVariantType.java new file mode 100644 index 00000000..3cfac1b9 --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/nomenclature/BiomeVariantType.java @@ -0,0 +1,35 @@ +package nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature; + +public enum BiomeVariantType { + + // Ocean + NORMAL_OCEAN, + DEEP_OCEAN, + CORAL_REEF, + FROZEN_OCEAN, + WARM_OCEAN, + MANGROVE_SWAMP, + + // RAINFOREST + TROPICAL_RAINFOREST, + TEMPERATE_RAINFOREST, + DRY_RAINFOREST, + JUNGLE, + + GRASSLAND, + FOREST, + DESERT, + SNOW, + TUNDRA, + SWAMP, + BEACH, + PLAINS, + HILLS, + MOUNTAINS, + SAVANNA, + TAIGA, + SNOWY_TUNDRA, + SNOWY_MOUNTAINS, + RIVER; + +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/nomenclature/ContinentType.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/nomenclature/ContinentType.java new file mode 100644 index 00000000..c723e96d --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/biome/nomenclature/ContinentType.java @@ -0,0 +1,10 @@ +package nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature; + +public enum ContinentType { + + MARINE, + LOWLAND, + MIDLAND, + HIGHLAND, + +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/points/PointsGenerationStep.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/points/PointsGenerationStep.java similarity index 56% rename from src/main/java/nomadrealms/context/game/world/map/generation/status/points/PointsGenerationStep.java rename to src/main/java/nomadrealms/context/game/world/map/generation/overworld/points/PointsGenerationStep.java index 3d172d52..951d37a0 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/points/PointsGenerationStep.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/points/PointsGenerationStep.java @@ -1,16 +1,15 @@ -package nomadrealms.context.game.world.map.generation.status.points; +package nomadrealms.context.game.world.map.generation.overworld.points; import static java.lang.Math.round; -import static nomadrealms.context.game.world.map.generation.status.GenerationStepStatus.POINTS; import java.util.ArrayList; import java.util.List; import engine.common.math.Vector2f; import nomadrealms.context.game.world.map.area.Zone; -import nomadrealms.context.game.world.map.generation.status.GenerationStep; -import nomadrealms.context.game.world.map.generation.status.GenerationStepStatus; -import nomadrealms.context.game.world.map.generation.status.points.point.PointOfInterest; +import nomadrealms.context.game.world.map.generation.MapGenerationStrategy; +import nomadrealms.context.game.world.map.generation.overworld.GenerationStep; +import nomadrealms.context.game.world.map.generation.overworld.points.point.PointOfInterest; /** * Generates the points of interest for the zone. @@ -26,17 +25,12 @@ public PointsGenerationStep() { super(null, 0); } - public PointsGenerationStep(Zone zone, long worldSeed) { - super(zone, worldSeed); + public PointsGenerationStep(Zone zone, MapGenerationStrategy strategy) { + super(zone, strategy.parameters().seed()); } @Override - public GenerationStepStatus status() { - return POINTS; - } - - @Override - public void generate(Zone[][] surrounding) { + public void generate(Zone[][] surrounding, MapGenerationStrategy strategy) { int numPoints = round(zone.nextRandomFloat() * 5); points = new ArrayList<>(); for (int i = 0; i < numPoints; i++) { diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/points/point/PointOfInterest.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/points/point/PointOfInterest.java similarity index 93% rename from src/main/java/nomadrealms/context/game/world/map/generation/status/points/point/PointOfInterest.java rename to src/main/java/nomadrealms/context/game/world/map/generation/overworld/points/point/PointOfInterest.java index 58b89458..c3825f15 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/points/point/PointOfInterest.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/points/point/PointOfInterest.java @@ -1,4 +1,4 @@ -package nomadrealms.context.game.world.map.generation.status.points.point; +package nomadrealms.context.game.world.map.generation.overworld.points.point; import static engine.common.colour.Colour.rgb; import static engine.common.colour.Colour.toRangedVector; @@ -12,7 +12,7 @@ import engine.visuals.builtin.RectangleVertexArrayObject; import engine.visuals.lwjgl.render.meta.DrawFunction; import nomadrealms.context.game.world.map.area.Zone; -import nomadrealms.context.game.world.map.generation.status.points.PointsGenerationStep; +import nomadrealms.context.game.world.map.generation.overworld.points.PointsGenerationStep; import nomadrealms.render.RenderingEnvironment; /** diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/structure/StructureGenerationConfig.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/structure/StructureGenerationConfig.java new file mode 100644 index 00000000..8d2fdbb6 --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/structure/StructureGenerationConfig.java @@ -0,0 +1,11 @@ +package nomadrealms.context.game.world.map.generation.overworld.structure; + +import nomadrealms.context.game.actor.structure.Structure; +import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate; +import nomadrealms.context.game.world.map.generation.overworld.biome.BiomeParameters; + +public abstract class StructureGenerationConfig { + + public abstract Structure placeStructure(TileCoordinate coord, BiomeParameters biome); + +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/structure/StructureGenerationStep.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/structure/StructureGenerationStep.java new file mode 100644 index 00000000..ef7fcd44 --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/structure/StructureGenerationStep.java @@ -0,0 +1,63 @@ +package nomadrealms.context.game.world.map.generation.overworld.structure; + +import static java.util.Arrays.asList; +import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.CHUNK_SIZE; +import static nomadrealms.context.game.world.map.area.coordinate.ZoneCoordinate.ZONE_SIZE; + +import java.util.ArrayList; +import java.util.List; + +import nomadrealms.context.game.actor.structure.Structure; +import nomadrealms.context.game.world.map.area.Zone; +import nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate; +import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate; +import nomadrealms.context.game.world.map.generation.MapGenerationStrategy; +import nomadrealms.context.game.world.map.generation.overworld.GenerationStep; +import nomadrealms.context.game.world.map.generation.overworld.biome.BiomeParameters; +import nomadrealms.context.game.world.map.generation.overworld.structure.config.TreeGenerationConfig; + +public class StructureGenerationStep extends GenerationStep { + + /** + * List of structure generation parameters for each structure type. + */ + private List structureParameters; + + private final Structure[][] structures = new Structure[ZONE_SIZE * CHUNK_SIZE][ZONE_SIZE * CHUNK_SIZE]; + + /** + * No-arg constructor for serialization. + */ + protected StructureGenerationStep() { + super(null, 0); + } + + public StructureGenerationStep(Zone zone, MapGenerationStrategy strategy) { + super(zone, strategy.parameters().seed()); + structureParameters = new ArrayList<>(asList( + new TreeGenerationConfig(strategy.parameters()) + )); + } + + @Override + public void generate(Zone[][] surrounding, MapGenerationStrategy strategy) { + System.out.println("Generating structures..."); + for (ChunkCoordinate[] chunkRow : zone.coord().chunkCoordinates()) { + for (ChunkCoordinate chunk : chunkRow) { + for (TileCoordinate[] tileRow : chunk.tileCoordinates()) { + for (TileCoordinate tile : tileRow) { + for (StructureGenerationConfig params : structureParameters) { + BiomeParameters biomeParameters = zone.biomeGenerationStep().parametersAt(tile); + Structure structure = params.placeStructure(tile, biomeParameters); + structures[chunk.x() * CHUNK_SIZE + tile.x()][chunk.y() * CHUNK_SIZE + tile.y()] = structure; + } + } + } + } + } + } + + public Structure[][] structures() { + return structures; + } +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/structure/config/TreeGenerationConfig.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/structure/config/TreeGenerationConfig.java new file mode 100644 index 00000000..773a309d --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/structure/config/TreeGenerationConfig.java @@ -0,0 +1,54 @@ +package nomadrealms.context.game.world.map.generation.overworld.structure.config; + +import nomadrealms.context.game.actor.structure.Structure; +import nomadrealms.context.game.actor.structure.TreeStructure; +import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate; +import nomadrealms.context.game.world.map.generation.MapGenerationParameters; +import nomadrealms.context.game.world.map.generation.overworld.biome.BiomeParameters; +import nomadrealms.context.game.world.map.generation.overworld.biome.noise.BiomeNoiseGenerator; +import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType; +import nomadrealms.context.game.world.map.generation.overworld.structure.StructureGenerationConfig; +import nomadrealms.math.generation.map.LayeredNoise; +import nomadrealms.math.generation.map.NoiseOctave; +import nomadrealms.math.generation.map.OpenSimplexNoise; + +/** + * Parameters for generating trees in the overworld. + * + * @author Lunkle + */ +public class TreeGenerationConfig extends StructureGenerationConfig { + + private final BiomeNoiseGenerator noise; + + /** + * No-arg constructor for serialization. + */ + protected TreeGenerationConfig() { + this.noise = null; + } + + public TreeGenerationConfig(MapGenerationParameters mapParameters) { + OpenSimplexNoise base = new OpenSimplexNoise(mapParameters.seed()); + this.noise = new BiomeNoiseGenerator(new LayeredNoise( + new NoiseOctave(base, 0.05, 0.4, 0), + new NoiseOctave(base, 2, 0.02, 1), + new NoiseOctave(base, 1, 0.3, 2), + new NoiseOctave(base, 0.5, 0.18, 3), + new NoiseOctave(base, 0.25, 0.1, 4), + new NoiseOctave(base, 0.1, 0.05, 5), + new NoiseOctave(base, 0.05, 0.02, 6)), + 1); + } + + + public Structure placeStructure(TileCoordinate coord, BiomeParameters biome) { + if (biome.calculateBiomeVariant() == BiomeVariantType.FOREST) { + if (noise.eval(coord) > 0.2f) { + return new TreeStructure(); + } + } + return null; + } + +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/GenerationStepStatus.java b/src/main/java/nomadrealms/context/game/world/map/generation/status/GenerationStepStatus.java deleted file mode 100644 index 65e6bcb9..00000000 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/GenerationStepStatus.java +++ /dev/null @@ -1,29 +0,0 @@ -package nomadrealms.context.game.world.map.generation.status; - -public enum GenerationStepStatus { - - EMPTY, - BIOMES, - POINTS, - PERTURBANCE(true), - TERRAIN, - CARVING(true), - STRUCTURES, - SPAWNS, - AGING(true), - COMPLETE; - - private boolean nextLayer = false; - - GenerationStepStatus() { - } - - GenerationStepStatus(boolean nextLayer) { - this.nextLayer = nextLayer; - } - - public boolean needsNextLayer() { - return nextLayer; - } - -} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/BiomeGenerationStep.java b/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/BiomeGenerationStep.java deleted file mode 100644 index 3416ac4b..00000000 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/BiomeGenerationStep.java +++ /dev/null @@ -1,200 +0,0 @@ -package nomadrealms.context.game.world.map.generation.status.biome; - -import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.CHUNK_SIZE; -import static nomadrealms.context.game.world.map.area.coordinate.ZoneCoordinate.ZONE_SIZE; -import static nomadrealms.context.game.world.map.generation.status.GenerationStepStatus.BIOMES; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory.AQUATIC; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory.HUMIDITY_CEIL; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory.HUMIDITY_FLOOR; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory.TEMPERATURE_CEIL; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory.TEMPERATURE_FLOOR; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory.TEMPERATURE_HUMIDITY_VALUES; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType.BEACH; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType.DEEP_OCEAN; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType.DESERT; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType.FOREST; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType.NORMAL_OCEAN; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType.PLAINS; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType.SNOWY_TUNDRA; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType.TAIGA; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType.TEMPERATE_RAINFOREST; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.ContinentType.HIGHLAND; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.ContinentType.LOWLAND; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.ContinentType.MARINE; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.ContinentType.MIDLAND; - -import java.util.Map; - -import engine.common.math.Vector2i; -import nomadrealms.context.game.world.map.area.Zone; -import nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate; -import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate; -import nomadrealms.context.game.world.map.generation.status.GenerationStep; -import nomadrealms.context.game.world.map.generation.status.GenerationStepStatus; -import nomadrealms.context.game.world.map.generation.status.biome.noise.BiomeNoiseGeneratorCluster; -import nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory; -import nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType; -import nomadrealms.context.game.world.map.generation.status.biome.nomenclature.ContinentType; - -/** - * Generates the biomes for the zone. - *

    - * Reference: Minecraft biome generation - * - * @author Lunkle - */ -public class BiomeGenerationStep extends GenerationStep { - - private transient final BiomeParameters[][] parameters = - new BiomeParameters[ZONE_SIZE * CHUNK_SIZE][ZONE_SIZE * CHUNK_SIZE]; - private transient final ContinentType[][] continents = new ContinentType[ZONE_SIZE * CHUNK_SIZE][ZONE_SIZE * CHUNK_SIZE]; - private transient final BiomeCategory[][] categories = new BiomeCategory[ZONE_SIZE * CHUNK_SIZE][ZONE_SIZE * CHUNK_SIZE]; - private final BiomeVariantType[][] biomes = new BiomeVariantType[ZONE_SIZE * CHUNK_SIZE][ZONE_SIZE * CHUNK_SIZE]; - - /** - * No-arg constructor for serialization. - */ - protected BiomeGenerationStep() { - super(null, 0); - } - - public BiomeGenerationStep(Zone zone, long seed) { - super(zone, seed); - } - - @Override - public GenerationStepStatus status() { - return BIOMES; - } - - @Override - public void generate(Zone[][] surrounding) { - } - - public void generate(BiomeNoiseGeneratorCluster noise, Zone[][] surrounding) { - for (ChunkCoordinate[] chunkRow : zone.coord().chunkCoordinates()) { - for (ChunkCoordinate chunk : chunkRow) { - for (TileCoordinate[] tileRow : chunk.tileCoordinates()) { - for (TileCoordinate tile : tileRow) { - float temperature = noise.temperature().eval(tile); - float humidity = noise.humidity().eval(tile); - float continentalness = noise.continentalness().eval(tile); - float erosion = noise.erosion().eval(tile); - float weirdness = noise.weirdness().eval(tile); - float depth = noise.depth().eval(tile); - - BiomeParameters parameters = new BiomeParameters(temperature, humidity, continentalness, erosion, weirdness, depth); - - this.parameters[chunk.x() * CHUNK_SIZE + tile.x()][chunk.y() * CHUNK_SIZE + tile.y()] = - parameters; - this.continents[chunk.x() * CHUNK_SIZE + tile.x()][chunk.y() * CHUNK_SIZE + tile.y()] = decideContinent(parameters); - this.categories[chunk.x() * CHUNK_SIZE + tile.x()][chunk.y() * CHUNK_SIZE + tile.y()] = decideBiomeCategory(parameters); - biomes[chunk.x() * CHUNK_SIZE + tile.x()][chunk.y() * CHUNK_SIZE + tile.y()] = decideBiomeVariant(parameters); - } - } - } - } - } - - private BiomeVariantType decideBiomeVariant(BiomeParameters p) { - ContinentType continent = decideContinent(p); - BiomeCategory category = decideBiomeCategory(p); - - if (continent == MARINE) { - if (p.depth() < -0.1) { - return DEEP_OCEAN; - } else if (p.depth() < 0.6) { - return NORMAL_OCEAN; - } else { - return BEACH; - } - } - switch (category) { - case AQUATIC: - // Unreachable code for now, should catch in previous if statement - return NORMAL_OCEAN; - case RAINFOREST: - return TEMPERATE_RAINFOREST; - case GRASSLAND: - return PLAINS; - case CONIFEROUS_FOREST: - return TAIGA; - case TEMPERATE_DECIDUOUS_FOREST: - return FOREST; - case DESERT: - return DESERT; - case TUNDRA: - return SNOWY_TUNDRA; - default: - throw new IllegalStateException("Could not decide biome variant for parameters: " + p + " and " + - "category: " + category + " and continent: " + continent); - } - } - - public BiomeCategory decideBiomeCategory(BiomeParameters p) { - ContinentType continent = decideContinent(p); - switch (continent) { - case MARINE: - return AQUATIC; - case LOWLAND: - case MIDLAND: - case HIGHLAND: - BiomeCategory category = null; - double closest = Double.MAX_VALUE; - for (Map.Entry entry : TEMPERATURE_HUMIDITY_VALUES.entrySet()) { - Vector2i temperatureHumidity = entry.getValue(); - float adjustedTemperature = (p.temperature() + 1) * (TEMPERATURE_CEIL - TEMPERATURE_FLOOR) / 2 + TEMPERATURE_FLOOR; - float adjustedHumidity = (p.humidity() + 1) * (HUMIDITY_CEIL - HUMIDITY_FLOOR) / 2 + HUMIDITY_FLOOR; - double distanceSquared = - Math.pow(temperatureHumidity.x() - adjustedTemperature, 2) + Math.pow(temperatureHumidity.y() - adjustedHumidity, 2); - if (distanceSquared < closest) { - closest = distanceSquared; - category = entry.getKey(); - } - } - return category; - } - throw new IllegalStateException("Could not decide biome category for parameters: " + p); - } - - public ContinentType decideContinent(BiomeParameters p) { - if (p.continentalness() < 0) { - return MARINE; - } else if (p.continentalness() < 0.2) { - return LOWLAND; - } else if (p.continentalness() < 0.6) { - return MIDLAND; - } else { - return HIGHLAND; - } - } - - public BiomeVariantType[][] biomes() { - return biomes; - } - - public BiomeVariantType biomeAt(TileCoordinate coord) { - return biomes - [coord.chunk().x() * CHUNK_SIZE + coord.x()] - [coord.chunk().y() * CHUNK_SIZE + coord.y()]; - } - - public BiomeParameters parametersAt(TileCoordinate coord) { - return parameters - [coord.chunk().x() * CHUNK_SIZE + coord.x()] - [coord.chunk().y() * CHUNK_SIZE + coord.y()]; - } - - public BiomeCategory categoryAt(TileCoordinate coord) { - return categories - [coord.chunk().x() * CHUNK_SIZE + coord.x()] - [coord.chunk().y() * CHUNK_SIZE + coord.y()]; - } - - public ContinentType continentAt(TileCoordinate coord) { - return continents - [coord.chunk().x() * CHUNK_SIZE + coord.x()] - [coord.chunk().y() * CHUNK_SIZE + coord.y()]; - } - -} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/BiomeParameters.java b/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/BiomeParameters.java deleted file mode 100644 index c111c22d..00000000 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/BiomeParameters.java +++ /dev/null @@ -1,83 +0,0 @@ -package nomadrealms.context.game.world.map.generation.status.biome; - -/** - * Represents the parameters used to determine a biome. - *

    - * The parameters are: - *
      - *
    • Temperature
    • - *
    • Humidity
    • - *
    • Continentalness
    • - *
    • Erosion
    • - *
    • Weirdness
    • - *
    • Depth
    • - * - * @author Lunkle - */ -public class BiomeParameters { - - private final float temperature; - private final float humidity; - private final float continentalness; - private final float erosion; - private final float weirdness; - private final float depth; - - /** - * No-args constructor for serialization. - */ - public BiomeParameters() { - this.temperature = 0; - this.humidity = 0; - this.continentalness = 0; - this.erosion = 0; - this.weirdness = 0; - this.depth = 0; - } - - public BiomeParameters(float temperature, float humidity, float continentalness, float erosion, float weirdness, float depth) { - this.temperature = temperature; - this.humidity = humidity; - this.continentalness = continentalness; - this.erosion = erosion; - this.weirdness = weirdness; - this.depth = depth; - } - - public float temperature() { - return temperature; - } - - public float humidity() { - return humidity; - } - - public float continentalness() { - return continentalness; - } - - public float erosion() { - return erosion; - } - - public float weirdness() { - return weirdness; - } - - public float depth() { - return depth; - } - - @Override - public String toString() { - return "BiomeParameters{" + - "temperature=" + temperature + - ", humidity=" + humidity + - ", continentalness=" + continentalness + - ", erosion=" + erosion + - ", weirdness=" + weirdness + - ", depth=" + depth + - '}'; - } - -} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/nomenclature/BiomeVariantType.java b/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/nomenclature/BiomeVariantType.java deleted file mode 100644 index bb463e16..00000000 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/nomenclature/BiomeVariantType.java +++ /dev/null @@ -1,35 +0,0 @@ -package nomadrealms.context.game.world.map.generation.status.biome.nomenclature; - -public enum BiomeVariantType { - - // Ocean - NORMAL_OCEAN, - DEEP_OCEAN, - CORAL_REEF, - FROZEN_OCEAN, - WARM_OCEAN, - MANGROVE_SWAMP, - - // RAINFOREST - TROPICAL_RAINFOREST, - TEMPERATE_RAINFOREST, - DRY_RAINFOREST, - JUNGLE, - - GRASSLAND, - FOREST, - DESERT, - SNOW, - TUNDRA, - SWAMP, - BEACH, - PLAINS, - HILLS, - MOUNTAINS, - SAVANNA, - TAIGA, - SNOWY_TUNDRA, - SNOWY_MOUNTAINS, - RIVER; - -} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/nomenclature/ContinentType.java b/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/nomenclature/ContinentType.java deleted file mode 100644 index 185cefaf..00000000 --- a/src/main/java/nomadrealms/context/game/world/map/generation/status/biome/nomenclature/ContinentType.java +++ /dev/null @@ -1,10 +0,0 @@ -package nomadrealms.context.game.world.map.generation.status.biome.nomenclature; - -public enum ContinentType { - - MARINE, - LOWLAND, - MIDLAND, - HIGHLAND, - -} diff --git a/src/main/java/nomadrealms/render/RenderingEnvironment.java b/src/main/java/nomadrealms/render/RenderingEnvironment.java index 42261a6d..b29ebb15 100644 --- a/src/main/java/nomadrealms/render/RenderingEnvironment.java +++ b/src/main/java/nomadrealms/render/RenderingEnvironment.java @@ -125,7 +125,10 @@ private void loadImages() { imageMap.put("rock_1", new Texture().image(loadImage(getFile("/images/rock_1.png"))).load()); imageMap.put("tree_1", new Texture().image(loadImage(getFile("/images/tree_1.png"))).load()); imageMap.put("fence", new Texture().image(loadImage(getFile("/images/fence.png"))).load()); + imageMap.put("oak_tree", new Texture().image(loadImage(getFile("/images/oak_tree.png"))).load()); + imageMap.put("pine_tree", new Texture().image(loadImage(getFile("/images/pine_tree.png"))).load()); imageMap.put("chest", new Texture().image(loadImage(getFile("/images/chest.png"))).load()); + imageMap.put("electrostatic_zapper", new Texture().image(loadImage(getFile("/images/electrostatic_zapper.png"))).load()); imageMap.put("card_front", new Texture().image(loadImage(getFile("/images/card_front.png"))).load()); diff --git a/src/main/java/nomadrealms/render/ui/custom/tooltip/TooltipDeterminer.java b/src/main/java/nomadrealms/render/ui/custom/tooltip/TooltipDeterminer.java index d3dfcf8b..ab92bff1 100644 --- a/src/main/java/nomadrealms/render/ui/custom/tooltip/TooltipDeterminer.java +++ b/src/main/java/nomadrealms/render/ui/custom/tooltip/TooltipDeterminer.java @@ -1,17 +1,17 @@ package nomadrealms.render.ui.custom.tooltip; -import static engine.visuals.constraint.posdim.AbsoluteConstraint.zero; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory.HUMIDITY_CEIL; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory.HUMIDITY_FLOOR; import static engine.common.colour.Colour.rgb; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory.TEMPERATURE_CEIL; -import static nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory.TEMPERATURE_FLOOR; +import static engine.visuals.constraint.posdim.AbsoluteConstraint.zero; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory.HUMIDITY_CEIL; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory.HUMIDITY_FLOOR; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory.TEMPERATURE_CEIL; +import static nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory.TEMPERATURE_FLOOR; import nomadrealms.context.game.actor.Actor; import nomadrealms.context.game.actor.HasTooltip; import nomadrealms.context.game.world.map.area.Tile; import nomadrealms.context.game.world.map.area.Zone; -import nomadrealms.context.game.world.map.generation.status.biome.BiomeParameters; +import nomadrealms.context.game.world.map.generation.overworld.biome.BiomeParameters; import nomadrealms.render.RenderingEnvironment; import nomadrealms.render.ui.content.ContainerContent; import nomadrealms.render.ui.content.TextContent; diff --git a/src/test/java/nomadrealms/context/game/world/GameMapTest.java b/src/test/java/nomadrealms/context/game/world/GameMapTest.java index 521c78d3..1772f48e 100644 --- a/src/test/java/nomadrealms/context/game/world/GameMapTest.java +++ b/src/test/java/nomadrealms/context/game/world/GameMapTest.java @@ -3,59 +3,29 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import java.util.LinkedList; import java.util.List; -import nomadrealms.context.game.world.map.area.Chunk; +import nomadrealms.context.game.GameState; import nomadrealms.context.game.world.map.area.Tile; -import nomadrealms.context.game.world.map.area.Zone; import nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate; import nomadrealms.context.game.world.map.area.coordinate.RegionCoordinate; import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate; import nomadrealms.context.game.world.map.area.coordinate.ZoneCoordinate; -import nomadrealms.context.game.world.map.generation.MainWorldGenerationStrategy; -import nomadrealms.context.game.world.map.generation.MapGenerationStrategy; -import nomadrealms.context.game.world.map.tile.GrassTile; +import nomadrealms.context.game.world.map.generation.OverworldGenerationStrategy; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class GameMapTest { - private GameMap gameMap; + private GameMap map; private World world; @BeforeEach void setUp() { - world = new World(null, new MainWorldGenerationStrategy(123456789)); - MapGenerationStrategy strategy = new MapGenerationStrategy() { - @Override - public Tile[][] generateChunk(Zone zone, Chunk chunk, ChunkCoordinate coord) { - Tile[][] tiles = new Tile[16][16]; - for (int i = 0; i < 16; i++) { - for (int j = 0; j < 16; j++) { - tiles[i][j] = new GrassTile(chunk, new TileCoordinate(coord, i, j)); - } - } - return tiles; - } - - @Override - public Chunk[][] generateZone(World world, Zone zone) { - Chunk[][] chunks = new Chunk[16][16]; - for (int i = 0; i < 16; i++) { - for (int j = 0; j < 16; j++) { - Chunk chunk = new Chunk(zone, new ChunkCoordinate(zone.coord(), i, j)); - chunk.tiles(generateChunk(zone, chunk, new ChunkCoordinate(zone.coord(), i, j))); - chunks[i][j] = chunk; - } - } - return chunks; - } - @Override - public long seed() { - return 0; - } - }; - gameMap = new GameMap(world, strategy); + GameState state = new GameState("Test World", new LinkedList<>(), new OverworldGenerationStrategy(123456789)); + this.world = state.world; + this.map = world.map(); } @Test @@ -63,7 +33,7 @@ void testSimplePathFinding() { Tile source = world.getTile(new TileCoordinate(new ChunkCoordinate(new ZoneCoordinate(new RegionCoordinate(0, 0), 0, 0), 0, 1), 13, 0)); Tile target = world.getTile(new TileCoordinate(new ChunkCoordinate(new ZoneCoordinate(new RegionCoordinate(0, 0), 0, 0), 0, 0), 15, 15)); - List path = gameMap.path(source, target); + List path = map.path(source, target); assertNotNull(path); assertEquals(3, path.size()); @@ -75,8 +45,8 @@ void testSimplePathFinding() { @Test void testSeedConsistency() { long seed = 123456789; - World world1 = new World(null, new MainWorldGenerationStrategy(seed)); - World world2 = new World(null, new MainWorldGenerationStrategy(seed)); + World world1 = new World(null, new OverworldGenerationStrategy(seed)); + World world2 = new World(null, new OverworldGenerationStrategy(seed)); for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) {