Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,6 +16,7 @@ public class GenerationProcess {
private final BiomeGenerationStep biome;
private final PointsGenerationStep points;
private final StructureGenerationStep structure;
private final ItemGenerationStep item;


/**
Expand All @@ -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<GenerationStep> steps() {
return asList(
biome,
points,
structure
structure,
item
);
}

Expand All @@ -51,4 +56,9 @@ public PointsGenerationStep points() {
public StructureGenerationStep structure() {
return structure;
}

public ItemGenerationStep item() {
return item;
}

}
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
@@ -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<ItemGenerationConfig> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Loading