diff --git a/assets/mods/basegame/items/items.tga b/assets/mods/basegame/items/items.tga index 0f988088e..3a4eeb0ec 100644 --- a/assets/mods/basegame/items/items.tga +++ b/assets/mods/basegame/items/items.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c87d1561269a2de48040d883fe8903afd72f751b89377dd77c59023914e315a5 +oid sha256:09a7e7864ea77f9793ff71601f9e727cbfcc55ffcf921ca74d9b800edb3a8613 size 2408466 diff --git a/assets/mods/basegame/wires/256.tga b/assets/mods/basegame/wires/256.tga new file mode 100644 index 000000000..f45420d35 --- /dev/null +++ b/assets/mods/basegame/wires/256.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59130811ec5bf60eb1820da7afd85b28a25536c881a9a4d827ad1c7cd9361486 +size 32786 diff --git a/assets/mods/basegame/wires/wires.csv b/assets/mods/basegame/wires/wires.csv index 804e4167d..7f2e493e9 100644 --- a/assets/mods/basegame/wires/wires.csv +++ b/assets/mods/basegame/wires/wires.csv @@ -9,6 +9,7 @@ id;drop;name;renderclass;accept;inputcount;inputtype;outputtype;javaclass;invent 2;2;WIRE_POWER_HIGH;power;power_high;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,6,4;1;"POWERWIRE_HIGH" 16;16;WIRE_ETHERNET;network;10base2;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,7,4;1;"ETHERNETWIRE" +256;256;AXLE;axle;axle;1;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceAxle;basegame.items,1,5;0;"AXLE" # accept: which wiretype (defined elsewhere) the wires acceps. Use comma to separate multiple. N/A for electronic components (aka not wires) # inputcount: how many sides are input (outputcount is deduced from the inputcount). N/A for wires diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index 9bb0900ef..96e84657a 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -120,8 +120,8 @@ open class GameWorld( * Single block can have multiple conduits, different types of conduits are stored separately. */ public val wirings = HashedWirings() - private val wiringGraph = HashedWiringGraph() + @Transient private val WIRE_POS_MAP = intArrayOf(1,2,4,8) @Transient private val WIRE_ANTIPOS_MAP = intArrayOf(4,8,1,2) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSwitchManual.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSwitchManual.kt index 4767c600d..9e805b6d4 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSwitchManual.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSwitchManual.kt @@ -144,7 +144,7 @@ class FixtureLogicSignalPressurePlate : Electric { ) @Transient open val minMass = 2.0 // different types of switches can have different minimal mass? - @Transient open val holdTime = 30 // ticks + @Transient open val holdTime = 30 // ingame TIME_T private var triggeredTime: Long? = null // null = off; number: TIME_T that the button was held down diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt index fb813475c..a106ddf0d 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt @@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameitems import com.badlogic.gdx.Gdx import net.torvald.terrarum.* +import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.ItemID @@ -80,10 +81,18 @@ object BlockBase { } private val wireVectorChars = arrayOf( - "· · · ·","· · · →","· · ↓ ·","· · ↓ →","· ← · ·","· ← · →","· ← ↓ ·","· ← ↓ →","↑ · · ·","↑ · · →","↑ · ↓ ·","↑ · ↓ →","↑ ← · ·","↑ ← · →","↑ ← ↓ ·","↑ ← ↓ →", + "· · · ·","· · · →","· · ↓ ·","· · ↓ →", + "· ← · ·","· ← · →","· ← ↓ ·","· ← ↓ →", + "↑ · · ·","↑ · · →","↑ · ↓ ·","↑ · ↓ →", + "↑ ← · ·","↑ ← · →","↑ ← ↓ ·","↑ ← ↓ →", ) fun Int.toWireVectorBitsStr(): String = "[${wireVectorChars[this]}]($this)" - fun Int.wireNodeMirror() = this.shl(4).or(this).ushr(2).and(15) + private val wireMirrorLUT = arrayOf(0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15) +// fun Int.wireNodeMirror() = this.shl(4).or(this).ushr(2).and(15) + fun Int.wireNodeMirror() = wireMirrorLUT[this] + private val wireExtendLUT = arrayOf(0,5,10,15,5,5,15,15,10,15,10,15,15,15,15,15) + fun Int.wireNodeExtend() = wireExtendLUT[this] + fun Int.isOrthogonalTo(other: Int) = (this.wireNodeExtend() and other.wireNodeExtend() == 0) fun wireNodesConnectedEachOther(oldToNewVector: Int, new: Int?, old: Int?): Boolean { return if (new == null || old == null || oldToNewVector == 0) false else { @@ -93,7 +102,7 @@ object BlockBase { val q = newToOldVector and new if (p == 0 && q == 0) false else if (p > 0 && q > 0) true - else throw IllegalStateException("oldToNewVector = ${oldToNewVector.toWireVectorBitsStr()}, new = ${new.toWireVectorBitsStr()}, old = ${old.toWireVectorBitsStr()}") + else throw IllegalStateException("oldToNewVector = ${oldToNewVector.toWireVectorBitsStr()}, newToOldVector = ${newToOldVector.toWireVectorBitsStr()}; old = ${old.toWireVectorBitsStr()}, new = ${new.toWireVectorBitsStr()}") } } @@ -103,16 +112,25 @@ object BlockBase { private var oldTileX = -1 private var oldTileY = -1 - private fun placeWirePieceTo(world: GameWorld, item: ItemID, x: Int, y: Int) { - world.setTileWire(x, y, item, false, 0) + private fun placeWirePieceTo(world: GameWorld, item: ItemID, x: Int, y: Int, cnx: Int = 0) { + world.setTileWire(x, y, item, false, cnx) } /** * This function assumes xy and oxy are neighboured and tiles are correctly placed */ - private fun setConnectivity(world: GameWorld, vec: Int, item: ItemID, x: Int, y: Int, ox: Int, oy: Int) { - world.getWireGraphOf(x, y, item)!!.let { world.setWireGraphOf(x, y, item, vec.wireNodeMirror() or it) } - world.getWireGraphOf(ox, oy, item)!!.let { world.setWireGraphOf(ox, oy, item, vec or it) } + private fun setConnectivity(mode: String, world: GameWorld, vec: Int, item: ItemID, x: Int, y: Int, ox: Int, oy: Int) { + when (mode) { + "axle" -> { + // vec is guaranteed to be 5 or 10 + world.setWireGraphOf(x, y, item, vec) + world.setWireGraphOf(ox, oy, item, vec) + } + else -> { + world.getWireGraphOf(x, y, item)!!.let { world.setWireGraphOf(x, y, item, vec.wireNodeMirror() or it) } + world.getWireGraphOf(ox, oy, item)!!.let { world.setWireGraphOf(ox, oy, item, vec or it) } + } + } } private fun isNeighbouring(ww: Int, x1: Int, y1: Int, x2: Int, y2: Int): Boolean { @@ -125,7 +143,7 @@ object BlockBase { else false } - fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = mouseInInteractableRange(actor) { _, _, mtx, mty -> + fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float, wirePlaceMode: String) = mouseInInteractableRange(actor) { mx, my, mtx, mty -> val itemID = gameItem.originalID val ingame = Terrarum.ingame!! as TerrarumIngame @@ -147,15 +165,34 @@ object BlockBase { val thisTileOccupied = thisTileWires.first?.searchFor(itemID) != null val oldTileOccupied = oldTileWires.first?.searchFor(itemID) != null - val oldToNewVector = if (mtx == ww - 1 && oldTileX == 0) 4 + val oldToNewVector = when (wirePlaceMode) { + "axle" -> { + // determine new vector by dividing the block cell in X-shape + val mxt = mx - mtx * TILE_SIZE + val myt = my - mty * TILE_SIZE + // f(y)=myt + // g(y)=-myt+TILE_SIZE + // check if ( f(y) < x < g(y) OR f(y) > x > g(y) ) + // or, check if mouse is in the hourglass-shaped 🮚 area + if ((myt < mxt && mxt < -myt+TILE_SIZE) || (myt > mxt && mxt > -myt+TILE_SIZE)) + 10 + else + 5 + } + else -> { + if (mtx == ww - 1 && oldTileX == 0) 4 else if (mtx == 0 && oldTileX == ww - 1) 1 else if (mtx - oldTileX == 1) 1 else if (mtx - oldTileX == -1) 4 else if (mty - oldTileY == 1) 2 else if (mty - oldTileY == -1) 8 else 0 // if xy == oxy, the vector will be 0 - - val connectedEachOther = wireNodesConnectedEachOther(oldToNewVector, thisTileWireCnx, oldTileWireCnx) + } + } + val connectedEachOther = when (wirePlaceMode) { + "axle" -> thisTileOccupied && oldTileOccupied + else -> wireNodesConnectedEachOther(oldToNewVector, thisTileWireCnx, oldTileWireCnx) + } val thisTileWasDraggedOn = initialMouseDownTileX != mtx || initialMouseDownTileY != mty var ret = -1L @@ -173,7 +210,7 @@ object BlockBase { if (!thisTileWasDraggedOn) { if (thisTileOccupied) return@mouseInInteractableRange -1 else { - placeWirePieceTo(ingame.world, itemID, mtx, mty) + placeWirePieceTo(ingame.world, itemID, mtx, mty, oldToNewVector) ret = 1 } } @@ -182,12 +219,12 @@ object BlockBase { ret -1 } else if (thisTileOccupied && oldTileOccupied) { - setConnectivity(ingame.world, oldToNewVector, itemID, mtx, mty, oldTileX, oldTileY) + setConnectivity(wirePlaceMode, ingame.world, oldToNewVector, itemID, mtx, mty, oldTileX, oldTileY) ret = 0 } else { placeWirePieceTo(ingame.world, itemID, mtx, mty) - setConnectivity(ingame.world, oldToNewVector, itemID, mtx, mty, oldTileX, oldTileY) + setConnectivity(wirePlaceMode, ingame.world, oldToNewVector, itemID, mtx, mty, oldTileX, oldTileY) ret = 1 } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/WirePieceSignalWire.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/WirePieceSignalWire.kt index 252077471..9f641418a 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/WirePieceSignalWire.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/WirePieceSignalWire.kt @@ -1,13 +1,11 @@ package net.torvald.terrarum.modulebasegame.gameitems -import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.terrarum.CommonResourcePool import net.torvald.terrarum.WireCodex import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameitems.FixtureInteractionBlocked import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.ItemID -import net.torvald.terrarum.itemproperties.Material /** * @param originalID something like `basegame:8192` (the id must exist on wires.csv) @@ -34,7 +32,44 @@ class WirePieceSignalWire(originalID: ItemID, private val atlasID: String, priva } override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long { - return BlockBase.wireStartPrimaryUse(actor,this, delta) + return BlockBase.wireStartPrimaryUse(actor,this, delta, "signal_wire") + } + + override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) { + BlockBase.wireEffectWhenEquipped(this, delta) + } + + override fun effectOnUnequip(actor: ActorWithBody) { + BlockBase.wireEffectWhenUnequipped(this) + } +} + +/** + * @param originalID something like `basegame:8192` (the id must exist on wires.csv) + * + * Created by minjaesong on 2024-10-02. + */ +class WirePieceAxle(originalID: ItemID, private val atlasID: String, private val sheetX: Int, private val sheetY: Int) + : GameItem(originalID), FixtureInteractionBlocked { + + override var dynamicID: ItemID = originalID + override var baseMass = 0.001 + override var baseToolSize: Double? = null + override var inventoryCategory = Category.WIRE + override val canBeDynamic = false + override val materialId = "" + init { + itemImage = CommonResourcePool.getAsItemSheet(atlasID).get(sheetX, sheetY) + } + + init { + equipPosition = GameItem.EquipPosition.HAND_GRIP + originalName = "ITEM_AXLE" + tags.addAll(WireCodex[originalID].tags) + } + + override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long { + return BlockBase.wireStartPrimaryUse(actor,this, delta, "axle") } override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) { diff --git a/work_files/graphics/items/basegame_items.kra b/work_files/graphics/items/basegame_items.kra index 99c8d4c31..c07079bc0 100644 --- a/work_files/graphics/items/basegame_items.kra +++ b/work_files/graphics/items/basegame_items.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:76339f18f3f1ee355d8639181b785f22415ee68601c2a507284d4e064e4bbede -size 1790388 +oid sha256:83e00f10dd8a5f3d0b3058edd6cc0b866d1c8bd3c626c05cb7b3d853716dfdaf +size 1801204 diff --git a/work_files/graphics/sprites/fixtures/axle.kra b/work_files/graphics/sprites/fixtures/axle.kra new file mode 100644 index 000000000..0a8ed0d60 --- /dev/null +++ b/work_files/graphics/sprites/fixtures/axle.kra @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:881fa98595598c44ad9c1e3599c6de63bbaefecc7871c15253d095923b44db24 +size 63474