mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
fix: door spawn required wall be exist on the cells that don't matter
This commit is contained in:
@@ -1013,3 +1013,9 @@ fun distBetween(a: ActorWithBody, bpos: Vector2): Double {
|
|||||||
}
|
}
|
||||||
const val hashStrMap = "YBNDRFG8EJKMCPQXOTLVWIS2A345H769"
|
const val hashStrMap = "YBNDRFG8EJKMCPQXOTLVWIS2A345H769"
|
||||||
fun getHashStr(length: Int = 5) = (0 until length).map { hashStrMap[Math.random().times(32).toInt()] }.joinToString("")
|
fun getHashStr(length: Int = 5) = (0 until length).map { hashStrMap[Math.random().times(32).toInt()] }.joinToString("")
|
||||||
|
|
||||||
|
fun <S, T> List<S>.cartesianProduct(other: List<T>) = this.flatMap { thisIt ->
|
||||||
|
other.map { otherIt ->
|
||||||
|
thisIt to otherIt
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -218,12 +218,6 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <S, T> List<S>.cartesianProduct(other: List<T>) = this.flatMap { thisIt ->
|
|
||||||
other.map { otherIt ->
|
|
||||||
thisIt to otherIt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val everyBlockboxPos: List<Pair<Int, Int>>?
|
val everyBlockboxPos: List<Pair<Int, Int>>?
|
||||||
get() = worldBlockPos?.let { (posX, posY) ->
|
get() = worldBlockPos?.let { (posX, posY) ->
|
||||||
(posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList())
|
(posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList())
|
||||||
@@ -254,7 +248,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
return canSpawnHere0(posX, posY)
|
return canSpawnHere0(posX, posY)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun canSpawnHere0(posX: Int, posY: Int): Boolean {
|
open fun canSpawnHere0(posX: Int, posY: Int): Boolean {
|
||||||
val everyBlockboxPos = (posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList())
|
val everyBlockboxPos = (posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList())
|
||||||
|
|
||||||
// check for existing blocks (and fixtures)
|
// check for existing blocks (and fixtures)
|
||||||
|
|||||||
@@ -145,6 +145,33 @@ open class FixtureSwingingDoorBase : FixtureBase {
|
|||||||
|
|
||||||
override fun spawn(posX: Int, posY: Int, installersUUID: UUID?): Boolean = spawn(posX, posY, installersUUID, tilewiseHitboxWidth, tilewiseHitboxHeight)
|
override fun spawn(posX: Int, posY: Int, installersUUID: UUID?): Boolean = spawn(posX, posY, installersUUID, tilewiseHitboxWidth, tilewiseHitboxHeight)
|
||||||
|
|
||||||
|
override fun canSpawnHere0(posX: Int, posY: Int): Boolean {
|
||||||
|
val everyBlockboxPos = (posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList())
|
||||||
|
|
||||||
|
val xoffToFrame = (tilewiseHitboxWidth - twClosed) / 2
|
||||||
|
val everyDoorframePos = (posX + xoffToFrame until posX + blockBox.width - 1).toList().cartesianProduct((posY until posY + blockBox.height).toList())
|
||||||
|
|
||||||
|
// check for existing blocks (and fixtures)
|
||||||
|
var cannotSpawn = false
|
||||||
|
worldBlockPos = Point2i(posX, posY)
|
||||||
|
|
||||||
|
cannotSpawn = everyBlockboxPos.any { (x, y) -> !BlockCodex[world!!.getTileFromTerrain(x, y)].hasTag("INCONSEQUENTIAL") }
|
||||||
|
|
||||||
|
// check for walls, if spawnNeedsWall = true
|
||||||
|
if (spawnNeedsWall) {
|
||||||
|
cannotSpawn = cannotSpawn or everyDoorframePos.any { (x, y) -> !BlockCodex[world!!.getTileFromWall(x, y)].isSolid }
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for floors, if spawnNeedsFloor == true
|
||||||
|
if (spawnNeedsFloor) {
|
||||||
|
val y = posY + blockBox.height
|
||||||
|
val xs = posX + xoffToFrame until posX + blockBox.width - xoffToFrame
|
||||||
|
cannotSpawn = cannotSpawn or xs.any { x -> !BlockCodex[world!!.getTileFromTerrain(x, y)].isSolid }
|
||||||
|
}
|
||||||
|
|
||||||
|
return !cannotSpawn
|
||||||
|
}
|
||||||
|
|
||||||
override fun reload() {
|
override fun reload() {
|
||||||
super.reload()
|
super.reload()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user