mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
some fixtures now require wall or floor to spawn
This commit is contained in:
@@ -18,6 +18,8 @@ import net.torvald.tsvm.peripheral.VMProgramRom
|
||||
*/
|
||||
class FixtureHomeComputer : FixtureBase {
|
||||
|
||||
@Transient override val spawnNeedsFloor = true
|
||||
|
||||
// TODO: write serialiser for TSVM && allow mods to have their own serialiser
|
||||
private val vm = VM(ModMgr.getGdxFile("dwarventech", "bios").path(), 0x200000, TheRealWorld(), arrayOf(
|
||||
VMProgramRom(ModMgr.getGdxFile("dwarventech", "bios/tsvmbios.js").path())
|
||||
|
||||
@@ -137,6 +137,9 @@ open class Electric : FixtureBase {
|
||||
*/
|
||||
open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
|
||||
@Transient open val spawnNeedsWall: Boolean = false
|
||||
@Transient open val spawnNeedsFloor: Boolean = false
|
||||
|
||||
/** Real time, in nanoseconds */
|
||||
@Transient var spawnRequestedTime: Long = 0L
|
||||
protected set
|
||||
@@ -215,6 +218,17 @@ 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>>?
|
||||
get() = worldBlockPos?.let { (posX, posY) ->
|
||||
(posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList())
|
||||
}
|
||||
|
||||
override fun updateForTerrainChange(cue: IngameInstance.BlockChangeQueueItem) {
|
||||
placeActorBlocks()
|
||||
}
|
||||
@@ -237,19 +251,31 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
fun canSpawnHere(posX0: Int, posY0: Int): Boolean {
|
||||
val posX = (posX0 - blockBox.width.minus(1).div(2)) fmod world!!.width // width.minus(1) so that spawning position would be same as the ghost's position
|
||||
val posY = posY0 - blockBox.height + 1
|
||||
return canSpawnHere0(posX, posY)
|
||||
}
|
||||
|
||||
private fun canSpawnHere0(posX: Int, posY: Int): Boolean {
|
||||
val everyBlockboxPos = (posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList())
|
||||
|
||||
// check for existing blocks (and fixtures)
|
||||
var hasCollision = false
|
||||
var cannotSpawn = false
|
||||
worldBlockPos = Point2i(posX, posY)
|
||||
forEachBlockbox { x, y, _, _ ->
|
||||
if (!hasCollision) {
|
||||
val tile = world!!.getTileFromTerrain(x, y)
|
||||
if (!BlockCodex[tile].hasTag("INCONSEQUENTIAL")) {
|
||||
hasCollision = true
|
||||
}
|
||||
}
|
||||
|
||||
cannotSpawn = everyBlockboxPos.any { (x, y) -> !BlockCodex[world!!.getTileFromTerrain(x, y)].hasTag("INCONSEQUENTIAL") }
|
||||
|
||||
// check for walls, if spawnNeedsWall = true
|
||||
if (spawnNeedsWall) {
|
||||
cannotSpawn = cannotSpawn or everyBlockboxPos.any { (x, y) -> !BlockCodex[world!!.getTileFromWall(x, y)].isSolid }
|
||||
}
|
||||
return !hasCollision
|
||||
|
||||
// check for floors, if spawnNeedsFloor == true
|
||||
if (spawnNeedsFloor) {
|
||||
val y = posY + blockBox.height
|
||||
val xs = posX until posX + blockBox.width
|
||||
cannotSpawn = cannotSpawn or xs.any { x -> !BlockCodex[world!!.getTileFromTerrain(x, y)].isSolid }
|
||||
}
|
||||
|
||||
return !cannotSpawn
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,16 +355,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
)
|
||||
|
||||
// check for existing blocks (and fixtures)
|
||||
var hasCollision = false
|
||||
forEachBlockbox { x, y, _, _ ->
|
||||
if (!hasCollision) {
|
||||
val tile = world!!.getTileFromTerrain(x, y)
|
||||
if (!BlockCodex[tile].hasTag("INCONSEQUENTIAL")) {
|
||||
hasCollision = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasCollision) {
|
||||
if (!canSpawnHere0(posX, posY)) {
|
||||
printdbg(this, "cannot spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, has tile collision; xy=($posX,$posY) tDim=(${blockBox.width},${blockBox.height})")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
||||
|
||||
@Transient override val spawnNeedsFloor = true
|
||||
@Transient override val tags = listOf("basicsmelter")
|
||||
|
||||
constructor() : super(
|
||||
|
||||
@@ -13,6 +13,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
internal class FixtureStorageChest : FixtureBase {
|
||||
|
||||
@Transient override val spawnNeedsFloor = true
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1),
|
||||
mainUI = UIStorageChest(),
|
||||
|
||||
@@ -43,6 +43,7 @@ open class FixtureSwingingDoorBase : FixtureBase {
|
||||
private var pixelwiseHitboxHeight = TILE_SIZE * tilewiseHitboxHeight
|
||||
private var tilewiseDistToAxis = tw - twClosed
|
||||
|
||||
@Transient override val spawnNeedsWall = true
|
||||
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), Cvec(0)))
|
||||
// the Cvec will be calculated dynamically on Update
|
||||
@Transient override var shadeBoxList = arrayListOf(Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), Cvec(0)))
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.torvald.terrarum.blockproperties.Block
|
||||
* Created by minjaesong on 2022-07-28.
|
||||
*/
|
||||
class FixtureSwingingDoorOak : FixtureSwingingDoorBase {
|
||||
@Transient override val spawnNeedsWall = true
|
||||
constructor() : super() {
|
||||
_construct(
|
||||
2,
|
||||
@@ -24,6 +25,7 @@ class FixtureSwingingDoorOak : FixtureSwingingDoorBase {
|
||||
}
|
||||
|
||||
class FixtureSwingingDoorEbony : FixtureSwingingDoorBase {
|
||||
@Transient override val spawnNeedsWall = true
|
||||
constructor() : super() {
|
||||
_construct(
|
||||
2,
|
||||
@@ -41,6 +43,7 @@ class FixtureSwingingDoorEbony : FixtureSwingingDoorBase {
|
||||
}
|
||||
|
||||
class FixtureSwingingDoorBirch : FixtureSwingingDoorBase {
|
||||
@Transient override val spawnNeedsWall = true
|
||||
constructor() : super() {
|
||||
_construct(
|
||||
2,
|
||||
@@ -58,6 +61,7 @@ class FixtureSwingingDoorBirch : FixtureSwingingDoorBase {
|
||||
}
|
||||
|
||||
class FixtureSwingingDoorRosewood : FixtureSwingingDoorBase {
|
||||
@Transient override val spawnNeedsWall = true
|
||||
constructor() : super() {
|
||||
_construct(
|
||||
2,
|
||||
|
||||
@@ -18,6 +18,8 @@ import kotlin.properties.Delegates
|
||||
*/
|
||||
internal class FixtureTapestry : FixtureBase {
|
||||
|
||||
@Transient override val spawnNeedsWall = true
|
||||
|
||||
var artName = ""; private set
|
||||
var artAuthor = ""; private set
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
internal class FixtureTikiTorch : FixtureBase {
|
||||
|
||||
@Transient override val spawnNeedsFloor = true
|
||||
|
||||
private val rndHash1 = (Math.random() * 256).toInt()
|
||||
private val rndHash2 = (Math.random() * 256).toInt()
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import kotlin.math.roundToInt
|
||||
*/
|
||||
class FixtureTypewriter : FixtureBase {
|
||||
|
||||
@Transient override val spawnNeedsFloor = true
|
||||
var typewriterKeymapName = "us_qwerty" // used to control the keyboard input behaviour
|
||||
private set
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
class FixtureWallCalendar : FixtureBase {
|
||||
|
||||
@Transient override val spawnNeedsWall = true
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 1, 1),
|
||||
nameFun = { Lang["ITEM_CALENDAR"] },
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
class FixtureWorkbench : FixtureBase, CraftingStation {
|
||||
|
||||
@Transient override val spawnNeedsFloor = true
|
||||
@Transient override val tags = listOf("basiccrafting")
|
||||
|
||||
constructor() : super(
|
||||
|
||||
@@ -19,6 +19,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
class FixtureWorldPortal : Electric {
|
||||
|
||||
@Transient override val spawnNeedsFloor = true
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 5, 2),
|
||||
nameFun = { Lang["ITEM_WORLD_PORTAL"] },
|
||||
|
||||
Reference in New Issue
Block a user