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 01dea444..7b6ada7b 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 @@ -17,6 +17,7 @@ import nomadrealms.context.game.world.map.generation.MapGenerationStrategy; 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.item.ItemGenerationStep; 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; @@ -134,6 +135,10 @@ public StructureGenerationStep structureGenerationStep() { return generationProcess.structure(); } + public ItemGenerationStep itemGenerationStep() { + return generationProcess.item(); + } + private ConstraintPair indexPosition() { return new ConstraintPair(new Vector2f(coord.x() * TILE_HORIZONTAL_SPACING, coord.y() * TILE_VERTICAL_SPACING).scale(ZONE_SIZE * CHUNK_SIZE)); } diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/OverworldGenerationStrategy.java b/src/main/java/nomadrealms/context/game/world/map/generation/OverworldGenerationStrategy.java index be22e7dc..f985a669 100644 --- a/src/main/java/nomadrealms/context/game/world/map/generation/OverworldGenerationStrategy.java +++ b/src/main/java/nomadrealms/context/game/world/map/generation/OverworldGenerationStrategy.java @@ -137,6 +137,12 @@ public Tile[][] generateChunk(Zone zone, Chunk chunk, ChunkCoordinate coord) { if (structure != null) { tile.actor(structure); } + Item item = zone.itemGenerationStep().items() + [chunk.coord().x() * CHUNK_SIZE + tileCoord.x()] + [chunk.coord().y() * CHUNK_SIZE + tileCoord.y()]; + if (item != null) { + tile.addItem(new WorldItem(item)); + } tiles[tileCoord.x()][tileCoord.y()] = tile; } return tiles; @@ -148,6 +154,7 @@ public Chunk[][] generateZone(World world, Zone zone) { zone.biomeGenerationStep().generate(zones, this); zone.pointsGenerationStep().generate(zones, this); zone.structureGenerationStep().generate(zones, this); + zone.itemGenerationStep().generate(zones, this); Chunk[][] chunks = new Chunk[ZONE_SIZE][ZONE_SIZE]; for (ChunkCoordinate chunkCoord : flatten(zone.coord().chunkCoordinates())) { 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 index 9fda4705..e1fae8e6 100644 --- 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 @@ -7,6 +7,7 @@ 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.item.ItemGenerationStep; import nomadrealms.context.game.world.map.generation.overworld.points.PointsGenerationStep; import nomadrealms.context.game.world.map.generation.overworld.structure.StructureGenerationStep; @@ -15,6 +16,7 @@ public class GenerationProcess { private final BiomeGenerationStep biome; private final PointsGenerationStep points; private final StructureGenerationStep structure; + private final ItemGenerationStep item; /** @@ -24,19 +26,22 @@ protected GenerationProcess() { this.biome = null; this.points = null; this.structure = null; + this.item = null; } public GenerationProcess(Zone zone, MapGenerationStrategy strategy) { biome = new BiomeGenerationStep(zone, strategy); points = new PointsGenerationStep(zone, strategy); structure = new StructureGenerationStep(zone, strategy); + item = new ItemGenerationStep(zone, strategy); } public List steps() { return asList( biome, points, - structure + structure, + item ); } @@ -51,4 +56,9 @@ public PointsGenerationStep points() { public StructureGenerationStep structure() { return structure; } + + public ItemGenerationStep item() { + return item; + } + } diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/item/ItemGenerationConfig.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/item/ItemGenerationConfig.java new file mode 100644 index 00000000..1e7c9fcb --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/item/ItemGenerationConfig.java @@ -0,0 +1,11 @@ +package nomadrealms.context.game.world.map.generation.overworld.item; + +import nomadrealms.context.game.item.Item; +import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate; +import nomadrealms.context.game.world.map.generation.overworld.biome.BiomeParameters; + +public abstract class ItemGenerationConfig { + + public abstract Item placeItem(TileCoordinate coord, BiomeParameters biome); + +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/item/ItemGenerationStep.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/item/ItemGenerationStep.java new file mode 100644 index 00000000..0dcf6484 --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/item/ItemGenerationStep.java @@ -0,0 +1,65 @@ +package nomadrealms.context.game.world.map.generation.overworld.item; + +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.item.Item; +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.item.config.LogGenerationConfig; + +public class ItemGenerationStep extends GenerationStep { + + /** + * List of item generation parameters for each item type. + */ + private List itemParameters; + + private final Item[][] items = new Item[ZONE_SIZE * CHUNK_SIZE][ZONE_SIZE * CHUNK_SIZE]; + + /** + * No-arg constructor for serialization. + */ + protected ItemGenerationStep() { + super(null, 0); + } + + public ItemGenerationStep(Zone zone, MapGenerationStrategy strategy) { + super(zone, strategy.parameters().seed()); + itemParameters = new ArrayList<>(asList( + new LogGenerationConfig(strategy.parameters()) + )); + } + + @Override + public void generate(Zone[][] surrounding, MapGenerationStrategy strategy) { + for (ChunkCoordinate[] chunkRow : zone.coord().chunkCoordinates()) { + for (ChunkCoordinate chunk : chunkRow) { + for (TileCoordinate[] tileRow : chunk.tileCoordinates()) { + for (TileCoordinate tile : tileRow) { + BiomeParameters biomeParameters = zone.biomeGenerationStep().parametersAt(tile); + for (ItemGenerationConfig params : itemParameters) { + Item item = params.placeItem(tile, biomeParameters); + if (item != null) { + items[chunk.x() * CHUNK_SIZE + tile.x()][chunk.y() * CHUNK_SIZE + tile.y()] = item; + break; + } + } + } + } + } + } + } + + public Item[][] items() { + return items; + } +} diff --git a/src/main/java/nomadrealms/context/game/world/map/generation/overworld/item/config/LogGenerationConfig.java b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/item/config/LogGenerationConfig.java new file mode 100644 index 00000000..7758d4b5 --- /dev/null +++ b/src/main/java/nomadrealms/context/game/world/map/generation/overworld/item/config/LogGenerationConfig.java @@ -0,0 +1,48 @@ +package nomadrealms.context.game.world.map.generation.overworld.item.config; + +import nomadrealms.context.game.item.Item; +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.item.ItemGenerationConfig; +import nomadrealms.math.generation.map.LayeredNoise; +import nomadrealms.math.generation.map.NoiseOctave; +import nomadrealms.math.generation.map.OpenSimplexNoise; + +public class LogGenerationConfig extends ItemGenerationConfig { + + private final BiomeNoiseGenerator noise; + + /** + * No-arg constructor for serialization. + */ + protected LogGenerationConfig() { + this.noise = null; + } + + public LogGenerationConfig(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); + } + + @Override + public Item placeItem(TileCoordinate coord, BiomeParameters biome) { + if (biome.calculateBiomeVariant() == BiomeVariantType.FOREST) { + if (noise.eval(coord) > 0.2f) { + return Item.OAK_LOG; + } + } + return null; + } + +}