Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate names for cities #39

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
04b7c10
Add random names to cities
mayant15 Mar 30, 2019
be98fad
Add names at world generation
mayant15 Mar 30, 2019
f858702
Clean up and format code
mayant15 Mar 30, 2019
bfe433e
Split up Settlement and Site components
mayant15 Apr 1, 2019
06dfc74
Allow town theme to be specified in the culture component
mayant15 Apr 1, 2019
289be32
Add custom themes
mayant15 Apr 2, 2019
c60aef5
Code style fixes
mayant15 Apr 3, 2019
186bedd
Restructure SettlementComponent
mayant15 Apr 3, 2019
dec65d3
Add default constructor to SettlementComponent
mayant15 Apr 12, 2019
f4872fd
Refactor code
mayant15 May 1, 2019
b38828f
Add NameGenerator to module dependencies
mayant15 May 1, 2019
9c637a9
Remove sufficient grass condition
mayant15 May 30, 2019
f416e1b
Add city centre icon to minimap
mayant15 Jun 2, 2019
3a3928b
Fix icon scaling with zoom
mayant15 Jun 2, 2019
2c2cde1
Add network constraints to CentreOverlay addition
mayant15 Jun 2, 2019
caa11d5
Make icon persist when city moves out of view
mayant15 Jun 4, 2019
cdd9c43
Add javadocs
mayant15 Jun 9, 2019
0998206
Add location component to building entities
AndyTechGuy Jun 12, 2019
ba15ee7
Setup road construction pipeline
mayant15 Jun 20, 2019
483e818
Calculate and place RoadParcels between settlements
mayant15 Jun 21, 2019
ea8b9c8
Add a rasterizer to place blocks
mayant15 Jun 22, 2019
a789180
Better place and clear out space for roads
mayant15 Jun 23, 2019
db319e2
Add gravel blocks to road
mayant15 Jun 23, 2019
0c0fc25
Add road rasterizer and theme to construction system
mayant15 Jun 27, 2019
c76ed0e
Create roads from the nearest city only
mayant15 Jun 28, 2019
d49fe91
Clean up code
mayant15 Jun 29, 2019
0308f9d
Refactor and add javadocs
mayant15 Jul 1, 2019
8b70162
Add random names to cities
mayant15 Mar 30, 2019
4eadbbd
Add names at world generation
mayant15 Mar 30, 2019
5d33fcd
Clean up and format code
mayant15 Mar 30, 2019
a288c6d
Split up Settlement and Site components
mayant15 Apr 1, 2019
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ This [techdemo](https://www.youtube.com/watch?v=feEMmo1pRSY&feature=youtu.be) pr
![sc2](/images/niceCity5.jpg)

This module originates from the GSOC 2016 Project Citysimulation by [CptCrispyCrunchy](https://github.com/CptCrispyCrunchy) with [Skaldarnar](https://github.com/skaldarnar) and [msteiger](https://github.com/msteiger) as mentors.

### Images
The building icon image was taken from http://www.iconsmind.com (Linkware License)
Binary file added assets/textures/city-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion module.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
{"id" : "Minimap", "minVersion" : "1.0.0"},
{"id" : "Economy", "minVersion" : "0.1.0"},
{"id" : "StructureTemplates", "minVersion" : "0.3.0"},
{"id" : "StructuralResources", "minVersion" : "1.0.0"}
{"id" : "StructuralResources", "minVersion" : "1.0.0"},
{"id" : "NameGenerator", "minVersion" : "0.4.0"}
],
"isGameplay" : "false",
"serverSideOnly" : false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@
import org.terasology.dynamicCities.decoration.DecorationRasterizer;
import org.terasology.dynamicCities.decoration.SingleBlockRasterizer;
import org.terasology.dynamicCities.parcels.DynParcel;
import org.terasology.dynamicCities.parcels.RoadParcel;
import org.terasology.dynamicCities.parcels.RoadStatus;
import org.terasology.dynamicCities.playerTracking.PlayerTracker;
import org.terasology.dynamicCities.population.CultureComponent;
import org.terasology.dynamicCities.rasterizer.AbsDynBuildingRasterizer;
import org.terasology.dynamicCities.rasterizer.BufferRasterTarget;
import org.terasology.dynamicCities.rasterizer.RoadRasterizer;
import org.terasology.dynamicCities.rasterizer.doors.DoorRasterizer;
import org.terasology.dynamicCities.rasterizer.doors.SimpleDoorRasterizer;
import org.terasology.dynamicCities.rasterizer.doors.WingDoorRasterizer;
Expand All @@ -65,6 +68,7 @@
import org.terasology.dynamicCities.rasterizer.window.RectWindowRasterizer;
import org.terasology.dynamicCities.rasterizer.window.SimpleWindowRasterizer;
import org.terasology.dynamicCities.rasterizer.window.WindowRasterizer;
import org.terasology.dynamicCities.roads.RoadSegment;
import org.terasology.economy.components.MultiInvStorageComponent;
import org.terasology.entitySystem.entity.EntityManager;
import org.terasology.entitySystem.entity.EntityRef;
Expand All @@ -79,17 +83,19 @@
import org.terasology.math.Side;
import org.terasology.math.geom.BaseVector2i;
import org.terasology.math.geom.BaseVector3i;
import org.terasology.math.geom.ImmutableVector2i;
import org.terasology.math.geom.Rect2i;
import org.terasology.math.geom.Vector2i;
import org.terasology.math.geom.Vector3f;
import org.terasology.math.geom.Vector3i;
import org.terasology.network.NetworkSystem;
import org.terasology.registry.CoreRegistry;
import org.terasology.registry.In;
import org.terasology.registry.Share;
import org.terasology.structureTemplates.components.SpawnBlockRegionsComponent;
import org.terasology.structureTemplates.interfaces.StructureTemplateProvider;
import org.terasology.structureTemplates.util.BlockRegionUtilities;
import org.terasology.structureTemplates.util.BlockRegionTransform;
import org.terasology.structureTemplates.util.BlockRegionUtilities;
import org.terasology.world.BlockEntityRegistry;
import org.terasology.world.WorldProvider;
import org.terasology.world.block.Block;
Expand Down Expand Up @@ -145,13 +151,15 @@ public class Construction extends BaseComponentSystem {
private InventoryManager inventoryManager;


private BlockTheme theme;
private BlockTheme cityTheme;
private BlockTheme roadTheme;

private Block air;
private Block plant;
private Block water;
private Block defaultBlock;
private int maxMinDeviation = 40;
private RoadRasterizer roadRasterizer;
private final List<AbsDynBuildingRasterizer> stdRasterizers = new ArrayList<>();
private final List<WindowRasterizer> windowRasterizers = new ArrayList<>();
private final List<DoorRasterizer> doorRasterizers = new ArrayList<>();
Expand All @@ -160,8 +168,13 @@ public class Construction extends BaseComponentSystem {
private final List<Block> plantBlocks = new ArrayList<>();
private Logger logger = LoggerFactory.getLogger(Construction.class);

private Map<Integer, Integer> segmentCache = new HashMap<>();

/**
* Initialises the system and rasterizers with default themes
*/
public void initialise() {
theme = BlockTheme.builder(blockManager)
cityTheme = BlockTheme.builder(blockManager)
.register(DefaultBlockType.ROAD_FILL, "core:dirt")
.register(DefaultBlockType.ROAD_SURFACE, "core:Gravel")
.register(DefaultBlockType.LOT_EMPTY, "core:dirt")
Expand Down Expand Up @@ -192,33 +205,40 @@ public void initialise() {

.build();

if (roadRasterizer == null) {
roadRasterizer = new RoadRasterizer();
roadTheme = BlockTheme.builder(blockManager)
.register(DefaultBlockType.ROAD_FILL, "core:dirt")
.register(DefaultBlockType.ROAD_SURFACE, "core:Gravel")
.build();
}

blockManager = CoreRegistry.get(BlockManager.class);
air = blockManager.getBlock("engine:air");
water = blockManager.getBlock("core:water");
plant = blockManager.getBlock("core:plant");
defaultBlock = blockManager.getBlock("core:dirt");

stdRasterizers.add(new HollowBuildingPartRasterizer(theme, worldProvider));
stdRasterizers.add(new RectPartRasterizer(theme, worldProvider));
stdRasterizers.add(new RoundPartRasterizer(theme, worldProvider));
stdRasterizers.add(new StaircaseRasterizer(theme, worldProvider));

stdRasterizers.add(new HollowBuildingPartRasterizer(cityTheme, worldProvider));
stdRasterizers.add(new RectPartRasterizer(cityTheme, worldProvider));
stdRasterizers.add(new RoundPartRasterizer(cityTheme, worldProvider));
stdRasterizers.add(new StaircaseRasterizer(cityTheme, worldProvider));

decorationRasterizers.add(new SingleBlockRasterizer(theme));
decorationRasterizers.add(new ColumnRasterizer(theme));
decorationRasterizers.add(new SingleBlockRasterizer(cityTheme));
decorationRasterizers.add(new ColumnRasterizer(cityTheme));

doorRasterizers.add(new SimpleDoorRasterizer(theme));
doorRasterizers.add(new WingDoorRasterizer(theme));
doorRasterizers.add(new SimpleDoorRasterizer(cityTheme));
doorRasterizers.add(new WingDoorRasterizer(cityTheme));

windowRasterizers.add(new RectWindowRasterizer(theme));
windowRasterizers.add(new SimpleWindowRasterizer(theme));
windowRasterizers.add(new RectWindowRasterizer(cityTheme));
windowRasterizers.add(new SimpleWindowRasterizer(cityTheme));

roofRasterizers.add(new ConicRoofRasterizer(theme));
roofRasterizers.add(new DomeRoofRasterizer(theme));
roofRasterizers.add(new FlatRoofRasterizer(theme));
roofRasterizers.add(new HipRoofRasterizer(theme));
roofRasterizers.add(new PentRoofRasterizer(theme));
roofRasterizers.add(new SaddleRoofRasterizer(theme));
roofRasterizers.add(new ConicRoofRasterizer(cityTheme));
roofRasterizers.add(new DomeRoofRasterizer(cityTheme));
roofRasterizers.add(new FlatRoofRasterizer(cityTheme));
roofRasterizers.add(new HipRoofRasterizer(cityTheme));
roofRasterizers.add(new PentRoofRasterizer(cityTheme));
roofRasterizers.add(new SaddleRoofRasterizer(cityTheme));

//Register plant blocks
plantBlocks.add(blockManager.getBlock("core:GreenLeaf"));
Expand All @@ -230,11 +250,22 @@ public void initialise() {
plantBlocks.add(blockManager.getBlock("core:Cactus"));
}

/**
* Setup external rasterizer to be used for the road and it's block theme
* @param rasterizer to be used for the road
* @param theme theme that the rasterizer will use
*/
public void setRoadRasterizer(RoadRasterizer rasterizer, BlockTheme theme) {
roadRasterizer = rasterizer;
roadTheme = theme;
}

/**
* Maybe return a structured data with (int or false) as return value
* @param area The area which should be flattened
*
* @param area The area which should be flattened
* @param defaultHeight A rough estimation of the mean height of the terrain
* @param filler The blocktype which should be used to fill up terrain under the mean height
* @param filler The blocktype which should be used to fill up terrain under the mean height
* @return The height on which it was flattened to
*/
public int flatten(Rect2i area, int defaultHeight, Block filler) {
Expand Down Expand Up @@ -280,9 +311,9 @@ public int flatten(Rect2i area, int defaultHeight, Block filler) {
public int flatten(Rect2i area, int defaultHeight) {
return flatten(area, defaultHeight, defaultBlock);
}

/**
*
* @param area The area which should be sampled
* @param area The area which should be sampled
* @param height A rough estimation of the mean height of the terrain
* @return
*/
Expand Down Expand Up @@ -338,7 +369,7 @@ public boolean buildParcel(DynParcel dynParcel, EntityRef settlement, CultureCom
//Flatten the parcel area
dynParcel.height = flatten(dynParcel.shape, dynParcel.height);

RasterTarget rasterTarget = new BufferRasterTarget(blockBufferSystem, theme, dynParcel.shape);
RasterTarget rasterTarget = new BufferRasterTarget(blockBufferSystem, cityTheme, dynParcel.shape);
Rect2i shape = dynParcel.shape;
HeightMap hm = HeightMaps.constant(dynParcel.height);

Expand Down Expand Up @@ -369,6 +400,9 @@ public boolean buildParcel(DynParcel dynParcel, EntityRef settlement, CultureCom
Optional<Prefab> entityPrefab = assetManager.getAsset(building.resourceUrn, Prefab.class);
if (entityPrefab.isPresent()) {
dynParcel.buildingEntity = entityManager.create(entityPrefab.get());
dynParcel.buildingEntity.addComponent(new LocationComponent(new Vector3f(
(dynParcel.getShape().minX() + dynParcel.getShape().maxX()) / 2, dynParcel.height,
(dynParcel.getShape().minY() + dynParcel.getShape().maxY()) / 2))); // midpoint of the parcel shape, and the bottom of the building
dynParcel.buildingEntity.addComponent(new SettlementRefComponent(settlement));
dynParcel.buildingEntity.addComponent(new DynParcelRefComponent(dynParcel));
dynParcel.buildingEntity.send(new BuildingEntitySpawnedEvent());
Expand All @@ -382,13 +416,17 @@ public boolean buildParcel(DynParcel dynParcel, EntityRef settlement, CultureCom
boolean needsRotation = buildingManager.needsRotation(dynParcel, building);
if (needsRotation) {
switch (dynParcel.getOrientation()) {
case NORTH: dynParcel.orientation = Orientation.EAST;
case NORTH:
dynParcel.orientation = Orientation.EAST;
break;
case SOUTH: dynParcel.orientation = Orientation.WEST;
case SOUTH:
dynParcel.orientation = Orientation.WEST;
break;
case WEST: dynParcel.orientation = Orientation.NORTH;
case WEST:
dynParcel.orientation = Orientation.NORTH;
break;
case EAST: dynParcel.orientation = Orientation.SOUTH;
case EAST:
dynParcel.orientation = Orientation.SOUTH;
break;
}
}
Expand Down Expand Up @@ -469,8 +507,6 @@ public boolean buildParcel(DynParcel dynParcel, EntityRef settlement, CultureCom
}




/**
* Send block-change event to refresh the minimap
*/
Expand All @@ -483,6 +519,84 @@ public boolean buildParcel(DynParcel dynParcel, EntityRef settlement, CultureCom
return true;
}

public RoadStatus buildRoadParcel(RoadParcel parcel, EntityRef settlement) {
boolean containsRelevantRegion = false;
boolean segmentFailed = false;

final int vertLimit = 255; // To check if region is relevant

final int segmentHeight = 10; // Height to be given to the flatten function
final int failHeight = -9999;

// Factor by which the rect will be expanded while flattening
final int expWidth = 1;
final int expHeight = 1;
final ImmutableVector2i rectExpansionFactor = new ImmutableVector2i(expWidth, expHeight);

for (int i = 0; i < parcel.rects.size(); i++) {
RoadSegment segment = parcel.rects.elementAt(i);

if (segmentCache.containsKey(segment.hashCode()) && segmentCache.get(segment.hashCode()) == parcel.hashCode()) {
continue;
}

// Check if the region is relevant
Region3i region = Region3i.createFromMinMax(
new Vector3i(segment.rect.minX(), vertLimit, segment.rect.minY()),
new Vector3i(segment.rect.maxX(), -1 * vertLimit, segment.rect.maxY())
);
if (!worldProvider.isRegionRelevant(region)) {
continue;
} else {
containsRelevantRegion = true;
}

// Flatten the rect
// TODO: Find a way to store the surface height at that point to the segment here.
segment.height = flatten(segment.rect.expand(rectExpansionFactor), segmentHeight);

// Create raster targets
RasterTarget rasterTarget = new BufferRasterTarget(blockBufferSystem, roadTheme, segment.rect);
HeightMap hm = HeightMaps.constant(segment.height);

if (segment.height == failHeight) {
segmentFailed = true;
continue;
}

// Check for player collision
Map<EntityRef, EntityRef> playerCityMap = playerTracker.getPlayerCityMap();

boolean shouldRaster = true;
for (EntityRef player : playerCityMap.keySet()) {
if (playerCityMap.get(player) == settlement) {
LocationComponent playerLocation = player.getComponent(LocationComponent.class);
if (playerLocation != null && segment.rect.contains(playerLocation.getLocalPosition().x(), playerLocation.getLocalPosition().z())) {
segmentFailed = true;
shouldRaster = false;
break;
}
}
}

// Rasterize the road
if (shouldRaster) {
roadRasterizer.raster(rasterTarget, segment, hm);
segmentCache.put(segment.hashCode(), parcel.hashCode());
}
}

if (!containsRelevantRegion) {
return RoadStatus.NONE;
}

if (segmentFailed) {
return RoadStatus.PARTIAL;
}

return RoadStatus.COMPLETE;
}

/**
* Catches the spawn of a structure template on a parcel and assigns potential chest entities to the parcels entity
*/
Expand Down Expand Up @@ -520,7 +634,7 @@ public void catchOnSpawnDynamicStructure(OnSpawnDynamicStructureEvent event, Ent
public void onSpawnBlockRegions(SpawnStructureBufferedEvent event, EntityRef entity,
SpawnBlockRegionsComponent spawnBlockRegionComponent) {
BlockRegionTransform transformation = event.getTransformation();
for (SpawnBlockRegionsComponent.RegionToFill regionToFill: spawnBlockRegionComponent.regionsToFill) {
for (SpawnBlockRegionsComponent.RegionToFill regionToFill : spawnBlockRegionComponent.regionsToFill) {
Block block = regionToFill.blockType;

Region3i region = regionToFill.region;
Expand Down
Loading