Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/rmgen/painter/CityPainter.js
Context not available. | |||||
let mapCenter = g_Map.getCenter(); | let mapCenter = g_Map.getCenter(); | ||||
let mapSize = g_Map.getSize(); | let mapSize = g_Map.getSize(); | ||||
// TODO: Due to the rounding, this is wasting a lot of space. | |||||
// The city would be much denser if it would test for actual shape intersection or | |||||
// if it would use a custom, more fine-grained obstruction grid | |||||
let tileClass = g_Map.createTileClass(); | let tileClass = g_Map.createTileClass(); | ||||
let processed = new Array(mapSize).fill(0).map(() => new Uint8Array(mapSize)); | for (let point of area.getPoints()) | ||||
{ | |||||
for (let x = 0; x < mapSize; x += 0.5) | for (let template of shuffleArray(templates)) | ||||
for (let y = 0; y < mapSize; y += 0.5) | |||||
{ | { | ||||
let point = new Vector2D(x, y).rotateAround(this.angle, mapCenter).round(); | if (template.constraint && !template.constraint.allows(point)) | ||||
if (!area.contains(point) || processed[point.x][point.y] || !g_Map.validTilePassable(point)) | |||||
continue; | continue; | ||||
processed[point.x][point.y] = 1; | // Randomize building angle while keeping it aligned | ||||
let buildingAngle = this.angle + randIntInclusive(0, 3) * Math.PI / 2; | |||||
for (let template of shuffleArray(templates)) | // Place the entity if all points are within the boundaries and don't collide with the other entities | ||||
{ | let obstructionCorners = template.obstructionCorners.map(obstructionCorner => obstructionCorner.clone().rotate(buildingAngle).add(point)); | ||||
if (template.constraint && !template.constraint.allows(point)) | |||||
continue; | |||||
// Randomize building angle while keeping it aligned | let obstructionPoints = new ConvexPolygonPlacer(obstructionCorners, 0).place( | ||||
let buildingAngle = this.angle + randIntInclusive(0, 3) * Math.PI / 2; | new AndConstraint([new StayAreasConstraint([area]), avoidClasses(tileClass, 0), new PassableMapAreaConstraint()])); | ||||
// Place the entity if all points are within the boundaries and don't collide with the other entities | if (!obstructionPoints) | ||||
let obstructionCorners = template.obstructionCorners.map(obstructionCorner => | continue; | ||||
Vector2D.add(point, obstructionCorner.clone().rotate(buildingAngle))); | |||||
let obstructionPoints = new ConvexPolygonPlacer(obstructionCorners, 0).place( | g_Map.placeEntityPassable(template.templateName, this.playerID, Vector2D.average(obstructionCorners), -buildingAngle); | ||||
new AndConstraint([new StayAreasConstraint([area]), avoidClasses(tileClass, 0), new PassableMapAreaConstraint()])); | |||||
if (!obstructionPoints) | if (template.painter) | ||||
continue; | template.painter.paint(new Area(obstructionPoints)); | ||||
g_Map.placeEntityPassable(template.templateName, this.playerID, Vector2D.average(obstructionCorners), -buildingAngle); | for (let obstructionPoint of obstructionPoints) | ||||
tileClass.add(obstructionPoint); | |||||
if (template.painter) | ++templateCounts[template.templateName]; | ||||
template.painter.paint(new Area(obstructionPoints)); | templates = templates.filter(template => templateCounts[template.templateName] < template.maxCount); | ||||
break; | |||||
for (let obstructionPoint of obstructionPoints) | |||||
tileClass.add(obstructionPoint); | |||||
++templateCounts[template.templateName]; | |||||
templates = templates.filter(template => templateCounts[template.templateName] < template.maxCount); | |||||
break; | |||||
} | |||||
} | } | ||||
}; | } | ||||
}; | |||||
No newline at end of file | |||||
Context not available. |
Wildfire Games · Phabricator