Stop objects being placed inside each other
This commit is contained in:
parent
fb9871f45b
commit
0af6646212
@ -35,6 +35,8 @@ import ru.dbotthepony.kstarbound.defs.tile.isEmptyTile
|
|||||||
import ru.dbotthepony.kstarbound.util.AssetPathStack
|
import ru.dbotthepony.kstarbound.util.AssetPathStack
|
||||||
import ru.dbotthepony.kstarbound.world.Direction
|
import ru.dbotthepony.kstarbound.world.Direction
|
||||||
import ru.dbotthepony.kstarbound.world.World
|
import ru.dbotthepony.kstarbound.world.World
|
||||||
|
import ru.dbotthepony.kstarbound.world.entities.tile.WorldObject
|
||||||
|
import java.util.function.Predicate
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
|
|
||||||
data class ObjectOrientation(
|
data class ObjectOrientation(
|
||||||
@ -64,12 +66,18 @@ data class ObjectOrientation(
|
|||||||
if (occupySpaces.isEmpty())
|
if (occupySpaces.isEmpty())
|
||||||
return true
|
return true
|
||||||
|
|
||||||
return occupySpaces.all {
|
var valid = occupySpaces.all {
|
||||||
val cell = world.chunkMap.getCell(it + position)
|
val cell = world.chunkMap.getCell(it + position)
|
||||||
//if (!cell.foreground.material.isEmptyTile) println("not empty tile: ${it + position}, space $it, pos $position")
|
//if (!cell.foreground.material.isEmptyTile) println("not empty tile: ${it + position}, space $it, pos $position")
|
||||||
//if (cell.dungeonId in world.protectedDungeonIDs) println("position is protected: ${it + position}")
|
//if (cell.dungeonId in world.protectedDungeonIDs) println("position is protected: ${it + position}")
|
||||||
cell.foreground.material.isEmptyTile && (ignoreProtectedDungeons || cell.dungeonId !in world.protectedDungeonIDs)
|
cell.foreground.material.isEmptyTile && (ignoreProtectedDungeons || cell.dungeonId !in world.protectedDungeonIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (valid) {
|
||||||
|
valid = !world.entityIndex.any(AABB.ofPoints(occupySpaces), Predicate { it is WorldObject && occupySpaces.any { s -> s in it.occupySpaces } })
|
||||||
|
}
|
||||||
|
|
||||||
|
return valid
|
||||||
}
|
}
|
||||||
|
|
||||||
fun anchorsValid(world: World<*, *>, position: Vector2i, considerNullAsValid: Boolean = false): Boolean {
|
fun anchorsValid(world: World<*, *>, position: Vector2i, considerNullAsValid: Boolean = false): Boolean {
|
||||||
|
Loading…
Reference in New Issue
Block a user