Some code for allowing multiple worms
This commit is contained in:
parent
274b5c059a
commit
7736762c86
@ -40,29 +40,29 @@ class WormPlacement(
|
|||||||
val maxTravelDown: Int = Int.MAX_VALUE,
|
val maxTravelDown: Int = Int.MAX_VALUE,
|
||||||
val maxTravelUp: Int = Int.MAX_VALUE,
|
val maxTravelUp: Int = Int.MAX_VALUE,
|
||||||
) : AbstractEnormousPlacement(parameters) {
|
) : AbstractEnormousPlacement(parameters) {
|
||||||
override fun getPositions(center: BlockPos, random: RandomSource): Stream<BlockPos> {
|
private inner class Worm(private val random: RandomSource, private var position: Vector) {
|
||||||
var position = Vector.ZERO
|
private var remainingDistance = length.sample(random)
|
||||||
val maxDistance = length.sample(random)
|
private var xzRotation = random.nextDouble(-PI / 2.0, PI / 2.0)
|
||||||
// determine initial worm facing angle
|
private var xyRotation = normalizeAngle(initialAngleXY.sample(random).toDouble())
|
||||||
var xzRotation = random.nextDouble(-PI / 2.0, PI / 2.0)
|
private var xzTargetRotation = random.nextDouble(-PI / 2.0, PI / 2.0)
|
||||||
var xyRotation = normalizeAngle(initialAngleXY.sample(random).toDouble())
|
private var xyTargetRotation = normalizeAngle(initialAngleXY.sample(random).toDouble())
|
||||||
|
|
||||||
// determine initial "turn to" angle
|
private var xzSin = sin(xzRotation)
|
||||||
var xzTargetRotation = random.nextDouble(-PI / 2.0, PI / 2.0)
|
private var xzCos = cos(xzRotation)
|
||||||
var xyTargetRotation = normalizeAngle(initialAngleXY.sample(random).toDouble())
|
private var xySin = sin(xyRotation)
|
||||||
|
|
||||||
var xzSin = sin(xzRotation)
|
private val turnChanceXZ = this@WormPlacement.turnChanceXZ.instance()
|
||||||
var xzCos = cos(xzRotation)
|
private val turnChanceXY = this@WormPlacement.turnChanceXY.instance()
|
||||||
var xySin = sin(xyRotation)
|
|
||||||
|
|
||||||
val positions = ArrayList<BlockPos>()
|
val hasFinished: Boolean
|
||||||
var prevPos = position.toBlockPos()
|
get() = remainingDistance <= 0
|
||||||
positions.add(prevPos)
|
|
||||||
|
|
||||||
val turnChanceXZ = turnChanceXZ.instance()
|
private var prevPos = BlockPos.ZERO
|
||||||
val turnChanceXY = turnChanceXY.instance()
|
|
||||||
|
fun follow(): BlockPos? {
|
||||||
|
if (hasFinished) return null
|
||||||
|
remainingDistance--
|
||||||
|
|
||||||
for (traveledDistance in 0 .. maxDistance) {
|
|
||||||
// wormy turn
|
// wormy turn
|
||||||
if (turnChanceXZ.sample(random)) {
|
if (turnChanceXZ.sample(random)) {
|
||||||
// wormy angle
|
// wormy angle
|
||||||
@ -122,7 +122,24 @@ class WormPlacement(
|
|||||||
if (calc != prevPos) {
|
if (calc != prevPos) {
|
||||||
// if worm made a wurm, add new position to set
|
// if worm made a wurm, add new position to set
|
||||||
prevPos = calc
|
prevPos = calc
|
||||||
positions.add(calc)
|
return calc
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getPositions(center: BlockPos, random: RandomSource): Stream<BlockPos> {
|
||||||
|
val worms = ArrayList<Worm>()
|
||||||
|
worms.add(Worm(random, Vector.ZERO))
|
||||||
|
val positions = ArrayList<BlockPos>()
|
||||||
|
positions.add(BlockPos.ZERO)
|
||||||
|
|
||||||
|
while (worms.isNotEmpty()) {
|
||||||
|
worms.removeIf {
|
||||||
|
val pos = it.follow()
|
||||||
|
if (pos != null) positions.add(pos)
|
||||||
|
it.hasFinished
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user