more treegen wip

This commit is contained in:
minjaesong
2023-11-12 00:49:03 +09:00
parent dd2dfed198
commit e41c7fa408
4 changed files with 50 additions and 42 deletions

View File

@@ -28,16 +28,16 @@
"51";"51";"51";"BLOCK_PLANK_ROSEWOOD";"0.1252";"0.1252";"0.1252";"0.1252";"17";"900";"WOOD";"1";"1";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"WOOD,NORANDTILE"
# small punchable trees
"64";"64";"64";"BLOCK_TRUNK_NORMAL";"0.0312";"0.0312";"0.0312";"0.0312";"16";"740";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREESMALL,NATURAL"
"65";"65";"65";"BLOCK_TRUNK_EBONY";"0.0312";"0.0312";"0.0312";"0.0312";"19";"1200";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREESMALL,NATURAL"
"66";"66";"66";"BLOCK_TRUNK_BIRCH";"0.0312";"0.0312";"0.0312";"0.0312";"15";"670";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREESMALL,NATURAL"
"67";"67";"67";"BLOCK_TRUNK_ROSEWOOD";"0.0312";"0.0312";"0.0312";"0.0312";"17";"900";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREESMALL,NATURAL"
"64";"64";"64";"BLOCK_TRUNK_NORMAL";"0.0312";"0.0312";"0.0312";"0.0312";"16";"740";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREETRUNK,TREESMALL,NATURAL"
"65";"65";"65";"BLOCK_TRUNK_EBONY";"0.0312";"0.0312";"0.0312";"0.0312";"19";"1200";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREETRUNK,TREESMALL,NATURAL"
"66";"66";"66";"BLOCK_TRUNK_BIRCH";"0.0312";"0.0312";"0.0312";"0.0312";"15";"670";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREETRUNK,TREESMALL,NATURAL"
"67";"67";"67";"BLOCK_TRUNK_ROSEWOOD";"0.0312";"0.0312";"0.0312";"0.0312";"17";"900";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREETRUNK,TREESMALL,NATURAL"
# large non-punchable trees
"72";"72";"72";"BLOCK_TRUNK_NORMAL";"0.0312";"0.0312";"0.0312";"0.0312";"16";"740";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREELARGE,NATURAL"
"73";"73";"73";"BLOCK_TRUNK_EBONY";"0.0312";"0.0312";"0.0312";"0.0312";"19";"1200";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREELARGE,NATURAL"
"74";"74";"74";"BLOCK_TRUNK_BIRCH";"0.0312";"0.0312";"0.0312";"0.0312";"15";"670";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREELARGE,NATURAL"
"75";"75";"75";"BLOCK_TRUNK_ROSEWOOD";"0.0312";"0.0312";"0.0312";"0.0312";"17";"900";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREELARGE,NATURAL"
"72";"72";"72";"BLOCK_TRUNK_NORMAL";"0.0312";"0.0312";"0.0312";"0.0312";"16";"740";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREETRUNK,TREELARGE,NATURAL"
"73";"73";"73";"BLOCK_TRUNK_EBONY";"0.0312";"0.0312";"0.0312";"0.0312";"19";"1200";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREETRUNK,TREELARGE,NATURAL"
"74";"74";"74";"BLOCK_TRUNK_BIRCH";"0.0312";"0.0312";"0.0312";"0.0312";"15";"670";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREETRUNK,TREELARGE,NATURAL"
"75";"75";"75";"BLOCK_TRUNK_ROSEWOOD";"0.0312";"0.0312";"0.0312";"0.0312";"17";"900";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREETRUNK,TREELARGE,NATURAL"
# sabulous
"80";"80";"80";"BLOCK_SAND";"0.1252";"0.1252";"0.1252";"0.1252";"24";"2400";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.06";"SAND,NATURAL,WARM"
Can't render this file because it contains an unexpected character in line 17 and column 2.

View File

@@ -53,7 +53,9 @@ internal object ExportMap : ConsoleCommand {
val colFore = (App.tileMaker.terrainTileColourMap.get(terr) ?: throw NullPointerException("nullterr $terr")).toByteArray()
val colWall = (App.tileMaker.terrainTileColourMap.get(wall) ?: throw NullPointerException("nullwall $wall")).cpy().mul(WALL_OVERLAY).toByteArray()
val colArray = if (ore != Block.AIR) colOre else if (BlockCodex[terr].isSolid) colFore else colWall
val terrProp = BlockCodex[terr]
val colArray = if (ore != Block.AIR) colOre else if (terrProp.isSolid || terrProp.hasTag("TREE")) colFore else colWall
for (i in 0..2) {

View File

@@ -46,40 +46,27 @@ class Treegen(world: GameWorld, seed: Long, params: TreegenParams, val biomeMap:
private fun makeGrassMap(xs: IntProgression): Array<List<Int>> {
val STRIDE = 4
val r = Array<List<Int>>(xs.last - xs.first + 1) { emptyList() }
for (x in xs) {
val ys = ArrayList<Int>()
var y = 0
var y = 1
var tileUp = world.getTileFromTerrain(x, y - 1)
var tile = world.getTileFromTerrain(x, y)
var tileProp = BlockCodex[tile]
while (y < 800) {
val tile = world.getTileFromTerrain(x, y)
val tileProp = BlockCodex[tile]
if (tileProp.hasAnyTagOf("ROCK", "STONE")) break
if (tile == Block.GRASS) {
if (tile == Block.GRASS && tileUp == Block.AIR) {
ys.add(y)
}
// if dirt was hit, climb back up until a grass is seen
else if (tile == Block.DIRT) {
var yi = 1
var tile0 = world.getTileFromTerrain(x, y - yi)
var found = false
while (tile0 == Block.DIRT || yi < STRIDE) {
tile0 = world.getTileFromTerrain(x, y - yi)
if (tile0 == Block.GRASS) found = true
yi += 1
}
// filter duplicates
if (found && (ys.isEmpty() || ys.last() != y - yi)) {
ys.add(y - yi)
}
}
y += 1
y += STRIDE
tileUp = tile
tile = world.getTileFromTerrain(x, y)
tileProp = BlockCodex[tile]
}
r[x - xs.first] = ys
@@ -98,7 +85,7 @@ class Treegen(world: GameWorld, seed: Long, params: TreegenParams, val biomeMap:
val grad2 = yRight - y
if ((grad1 * grad2).absoluteValue <= 1) {
printdbg(this, "Trying to plant tree at $x, $y")
// printdbg(this, "Trying to plant tree at $x, $y")
val rnd = Math.random()
val biome = biomeMap[LandUtil.getBlockAddr(world, x, y)] ?: 0
@@ -123,10 +110,14 @@ class Treegen(world: GameWorld, seed: Long, params: TreegenParams, val biomeMap:
var growCnt = 1
if (size == 1) {
var heightSum = 5+3+2+1
var heightSum = 5+3+2
// check for minimum height
if ((1..heightSum).any { BlockCodex[world.getTileFromTerrain(x, y - it)].isSolid }) {
printdbg(this, "Ceiling not tall enough, aborting")
val chkM1 = (2..heightSum).any { BlockCodex[world.getTileFromTerrain(x, y - it)].isSolid }
val chk0 = (1..heightSum).any { BlockCodex[world.getTileFromTerrain(x, y - it)].isSolid }
val chkP1 = (2..heightSum).any { BlockCodex[world.getTileFromTerrain(x, y - it)].isSolid }
if (chkM1 || chk0 || chkP1) {
printdbg(this, "Ceiling not tall enough at $x, $y, aborting")
return
}
@@ -141,38 +132,53 @@ class Treegen(world: GameWorld, seed: Long, params: TreegenParams, val biomeMap:
// }
// while ((1..heightSum).none { BlockCodex[world.getTileFromTerrain(x, y - it)].isSolid })
printdbg(this, "Planting tree; params: $stem, $bulb1, $bulb2, $bulb3")
printdbg(this, "Planting tree at $x, $y; params: $stem, $bulb1, $bulb2, $bulb3")
// trunk
for (i in 0 until stem) {
for (xi in -1..+1) {
world.setTileTerrain(x + xi, y - growCnt, if (xi == 0) trunk else Block.AIR, true)
if (xi != 0) {
val tileHere = world.getTileFromTerrain(x + xi, y - growCnt)
if (BlockCodex[tileHere].hasTag("TREETRUNK"))
world.setTileTerrain(x + xi, y - growCnt, Block.AIR, true)
}
else {
world.setTileTerrain(x + xi, y - growCnt, trunk, true)
}
}
growCnt += 1
}
// bulb base
for (x in x-2..x+2) {
world.setTileTerrain(x, y - growCnt, foliage, true)
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
// bulb 1
for (i in 0 until bulb1) {
for (x in x-3..x+3) {
world.setTileTerrain(x, y - growCnt, foliage, true)
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
// bulb 2
for (i in 0 until bulb2) {
for (x in x-2..x+2) {
world.setTileTerrain(x, y - growCnt, foliage, true)
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
// bulb 3
for (i in 0 until bulb3) {
for (x in x-1..x+1) {
world.setTileTerrain(x, y - growCnt, foliage, true)
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}

View File

@@ -906,7 +906,7 @@ internal object BlocksDrawer {
fun isPlatform(b: ItemID) = App.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_WALL_STICKER_CONNECT_SELF
//fun isBlendMul(b: Int) = TILES_BLEND_MUL.contains(b)
fun isTreeFoliage(b: ItemID) = BlockCodex[b].hasAllTagOf("TREE", "LEAVES")
fun isTreeTrunk(b: ItemID) = BlockCodex[b].let { it.hasTag("TREE") && !it.hasTag("LEAVES") }
fun isTreeTrunk(b: ItemID) = BlockCodex[b].hasAllTagOf("TREE", "TREETRUNK")
fun tileInCamera(x: Int, y: Int) =
x >= WorldCamera.x.div(TILE_SIZE) && y >= WorldCamera.y.div(TILE_SIZE) &&