modulecomputers: alsmost working terrain rader

This commit is contained in:
minjaesong
2021-12-03 22:56:53 +09:00
parent 4a4290dc35
commit 9c6b36c8e0
5 changed files with 19 additions and 14 deletions

View File

@@ -43,7 +43,7 @@ class ItemWearableWorldRadar(originalID: String) : GameItem(originalID) {
override var baseToolSize: Double? = baseMass
private val vm = VM(32768, TheRealWorld(), arrayOf(
private val vm = VM(73728, TheRealWorld(), arrayOf(
VMProgramRom(ModMgr.getPath("dwarventech", "bios/pipboot.rom")),
VMProgramRom(ModMgr.getPath("dwarventech", "bios/pipcode.bas"))
))
@@ -59,6 +59,7 @@ class ItemWearableWorldRadar(originalID: String) : GameItem(originalID) {
ExtDisp(vm, 160, 140), 32768, 1, 0
)
// MMIO stops working when somethingStream is not defined
vm.getPrintStream = { System.out }
vm.getErrorStream = { System.err }
vm.getInputStream = { System.`in` }
@@ -100,7 +101,7 @@ class WearableWorldRadarUI(val device: VM) : UICanvas() {
batch.end()
batch.color = Color.WHITE
(device.peripheralTable[1].peripheral as? ExtDisp)?.render(batch, posX.toFloat(), posY.toFloat())
(device.peripheralTable[1].peripheral as? ExtDisp)?.render(batch, posX.toFloat(), posY.toFloat(), true)
batch.begin()
batch.color = Toolkit.Theme.COL_INACTIVE

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulecomputers.tsvmperipheral
import net.torvald.terrarum.IngameInstance
import net.torvald.terrarum.Point2i
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
@@ -15,8 +14,8 @@ import java.io.ByteArrayOutputStream
*/
class WorldRadar : BlockTransferInterface(false, true) {
private val W = 162
private val H = 142
private val W = 160
private val H = 140
private val AIR_OUT = 0.toByte()
private val GRASS_OUT = 2.toByte()
@@ -96,22 +95,26 @@ class WorldRadar : BlockTransferInterface(false, true) {
val px = it.intTilewiseHitbox.canonicalX.toInt()
val py = it.intTilewiseHitbox.canonicalY.toInt()
for (y in 1..H - 2) {
for (x in 1..W - 2) {
val yx = (y - 1).shl(8) or x
val nearby = getNearbyTilesPos(px, py).map { ingame.world.getTileFromTerrain(it.x, it.y) } // up, left, right, down
val block = ingame.world.getTileFromTerrain(px, py)
for (yy in 1..H) {
for (xx in 1..W) {
val tx = px - (W/2) + xx
val ty = py - (H/2) + yy
val yx = (yy - 1).shl(8) or xx
val nearby = getNearbyTilesPos(tx, ty).map { ingame.world.getTileFromTerrain(it.x, it.y) } // up, left, right, down
val block = ingame.world.getTileFromTerrain(tx, ty)
val blockprop = Terrarum.blockCodex[block]
if (blockprop.isSolid) {
// TODO create extension function nearby.contains { predicate :: ItemID -> Boolean }
if (blockprop.material == "GRSS" && nearby.contains(Block.AIR)) {
// for some reason I can't use material?
if (block == Block.GRASS && nearby.contains(Block.AIR)) {
cmdbuf[yx] = GRASS_OUT
}
else if (blockprop.material == "DIRT" && nearby.contains(Block.AIR)) {
else if (block == Block.DIRT && nearby.contains(Block.AIR)) {
cmdbuf[yx] = DIRT_OUT
}
else if (blockprop.material == "ROCK" && (nearby.contains(Block.AIR) || nearby.contains(Block.GRASS) || nearby.contains(Block.DIRT))) {
else if (block == Block.STONE && (nearby.contains(Block.AIR) || nearby.contains(Block.GRASS) || nearby.contains(Block.DIRT))) {
cmdbuf[yx] = STONE_OUT
}
}