mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
partially working conveyor
This commit is contained in:
@@ -134,6 +134,7 @@ id;classname;tags
|
|||||||
# industrial
|
# industrial
|
||||||
2048;net.torvald.terrarum.modulebasegame.gameitems.ItemInductionMotor;FIXTURE,POWER,KINETIC
|
2048;net.torvald.terrarum.modulebasegame.gameitems.ItemInductionMotor;FIXTURE,POWER,KINETIC
|
||||||
2049;net.torvald.terrarum.modulebasegame.gameitems.ItemGearbox;FIXTURE,POWER,KINETIC
|
2049;net.torvald.terrarum.modulebasegame.gameitems.ItemGearbox;FIXTURE,POWER,KINETIC
|
||||||
|
2050;net.torvald.terrarum.modulebasegame.gameitems.ItemConveyorBelt;FIXTURE,KINETIC
|
||||||
|
|
||||||
# data storage (pre-composed discs; 256)
|
# data storage (pre-composed discs; 256)
|
||||||
# 32768 is a reserved number for a BASEOBJECT disc (players can't produce own recordings... yet)
|
# 32768 is a reserved number for a BASEOBJECT disc (players can't produce own recordings... yet)
|
||||||
|
|||||||
|
@@ -1,9 +1,14 @@
|
|||||||
package net.torvald.terrarum.gameactors
|
package net.torvald.terrarum.modulebasegame.gameactors
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
|
import net.torvald.terrarum.INGAME
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
|
import net.torvald.terrarum.inUse
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
|
import java.util.*
|
||||||
import kotlin.math.*
|
import kotlin.math.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,6 +34,7 @@ class ActorConveyors : ActorWithBody {
|
|||||||
cy2 = 0.0
|
cy2 = 0.0
|
||||||
|
|
||||||
r = 0.5 * TILE_SIZED.minus(2)
|
r = 0.5 * TILE_SIZED.minus(2)
|
||||||
|
c = 0
|
||||||
|
|
||||||
btx1 = 0.0
|
btx1 = 0.0
|
||||||
bty1 = 0.0
|
bty1 = 0.0
|
||||||
@@ -47,6 +53,7 @@ class ActorConveyors : ActorWithBody {
|
|||||||
val y2: Int
|
val y2: Int
|
||||||
|
|
||||||
private val s: Double // belt length
|
private val s: Double // belt length
|
||||||
|
private val c: Int // segment counts
|
||||||
|
|
||||||
private val di: Double // inclination deg
|
private val di: Double // inclination deg
|
||||||
private val dd: Double // declination deg
|
private val dd: Double // declination deg
|
||||||
@@ -89,6 +96,7 @@ class ActorConveyors : ActorWithBody {
|
|||||||
cy2 = (this.y2 + 0.5) * TILE_SIZED
|
cy2 = (this.y2 + 0.5) * TILE_SIZED
|
||||||
|
|
||||||
r = 0.5 * TILE_SIZED.minus(2)
|
r = 0.5 * TILE_SIZED.minus(2)
|
||||||
|
c = (s / 8).roundToInt() * 2 // 4px segments rounded towards nearest even number
|
||||||
|
|
||||||
btx1 = cx1 + r * sin(di)
|
btx1 = cx1 + r * sin(di)
|
||||||
bty1 = cy1 + r * cos(di)
|
bty1 = cy1 + r * cos(di)
|
||||||
@@ -107,15 +115,18 @@ class ActorConveyors : ActorWithBody {
|
|||||||
|
|
||||||
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
|
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
|
||||||
|
|
||||||
|
App.shapeRender.inUse {
|
||||||
|
it.color = Color.RED
|
||||||
|
|
||||||
// belt top
|
// belt top
|
||||||
drawLineOnWorld(btx1, bty1, btx2, bty2)
|
drawLineOnWorld(btx1, bty1, btx2, bty2)
|
||||||
// belt bottom
|
// belt bottom
|
||||||
drawLineOnWorld(bbx1, bby1, bbx2, bby2)
|
drawLineOnWorld(bbx1, bby1, bbx2, bby2)
|
||||||
// left arc
|
// left arc
|
||||||
drawArcOnWorld(cx1, cy1, r, dd, Math.PI)
|
drawArcOnWorld(cx1, cy1, r, dd, Math.PI)
|
||||||
// right arc
|
// right arc
|
||||||
drawArcOnWorld(cx2, cy2, r, di, Math.PI)
|
drawArcOnWorld(cx2, cy2, r, di, Math.PI)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawLineOnWorld(x1: Double, y1: Double, x2: Double, y2: Double) {
|
private fun drawLineOnWorld(x1: Double, y1: Double, x2: Double, y2: Double) {
|
||||||
@@ -128,11 +139,11 @@ class ActorConveyors : ActorWithBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun drawArcOnWorld(xc: Double, yc: Double, r: Double, arcStart: Double, arcDeg: Double) {
|
private fun drawArcOnWorld(xc: Double, yc: Double, r: Double, arcStart: Double, arcDeg: Double) {
|
||||||
val w = 2.0f
|
|
||||||
// dissect the circle
|
// dissect the circle
|
||||||
val pathLen = arcDeg * r
|
// val pathLen = arcDeg * r
|
||||||
//// estimated number of segments. pathLen divided by sqrt(2)
|
//// estimated number of segments. pathLen divided by sqrt(2)
|
||||||
val segments = Math.round(pathLen / Double.fromBits(0x3FF6A09E667F3BCDL)).coerceAtLeast(1L).toInt()
|
// val segments = Math.round(pathLen / Double.fromBits(0x3FF6A09E667F3BCDL)).coerceAtLeast(1L).toInt()
|
||||||
|
val segments = 12 * 8
|
||||||
|
|
||||||
for (i in 0 until segments) {
|
for (i in 0 until segments) {
|
||||||
val degStart = (i.toDouble() / segments) * arcDeg + arcStart
|
val degStart = (i.toDouble() / segments) * arcDeg + arcStart
|
||||||
@@ -146,4 +157,40 @@ class ActorConveyors : ActorWithBody {
|
|||||||
drawLineOnWorld(x1, y1, x2, y2)
|
drawLineOnWorld(x1, y1, x2, y2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Real time, in nanoseconds */
|
||||||
|
@Transient var spawnRequestedTime: Long = 0L
|
||||||
|
protected set
|
||||||
|
|
||||||
|
internal var actorThatInstalledThisFixture: UUID? = null
|
||||||
|
|
||||||
|
open fun spawn(installerUUID: UUID?): Boolean {
|
||||||
|
this.isVisible = true
|
||||||
|
|
||||||
|
val posXtl = minOf(x1, x2).toDouble()
|
||||||
|
val posYtl = minOf(y1, y2).toDouble()
|
||||||
|
val posXbr = maxOf(x1, x2).toDouble()
|
||||||
|
val posYbr = maxOf(y1, y2).toDouble()
|
||||||
|
|
||||||
|
this.hitbox.setFromTwoPoints(posXtl * TILE_SIZED, posYtl * TILE_SIZED, (posXbr+1) * TILE_SIZED, (posYbr+1) * TILE_SIZED)
|
||||||
|
this.setHitboxDimension(this.hitbox.width.toInt(), this.hitbox.height.toInt(), 0, 1)
|
||||||
|
this.intTilewiseHitbox.setFromTwoPoints(posXtl, posYtl, posXbr, posYbr)
|
||||||
|
|
||||||
|
// actually add this actor into the world
|
||||||
|
INGAME.queueActorAddition(this)
|
||||||
|
spawnRequestedTime = System.nanoTime()
|
||||||
|
|
||||||
|
actorThatInstalledThisFixture = installerUUID
|
||||||
|
|
||||||
|
//makeNoiseAndDust(posXtl, posYtl)
|
||||||
|
|
||||||
|
onSpawn()
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callend whenever the fixture was spawned successfully.
|
||||||
|
*/
|
||||||
|
open fun onSpawn() {}
|
||||||
}
|
}
|
||||||
@@ -104,10 +104,7 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
|
|||||||
// return true when placed, false when cannot be placed
|
// return true when placed, false when cannot be placed
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startSecondaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
|
override fun startSecondaryUse(actor: ActorWithBody, delta: Float) = fixturePickupFun(actor, delta)
|
||||||
(INGAME as TerrarumIngame).pickupFixtureOrDroppedItem(actor, delta, mwx, mwy, mtx, mty, false)
|
|
||||||
-1
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Also see: [net.torvald.terrarum.modulebasegame.gameactors.FixtureBase.Companion]
|
* Also see: [net.torvald.terrarum.modulebasegame.gameactors.FixtureBase.Companion]
|
||||||
@@ -128,5 +125,10 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
|
|||||||
TextureRegion(Texture(ModMgr.getGdxFile(module, path)))
|
TextureRegion(Texture(ModMgr.getGdxFile(module, path)))
|
||||||
} as TextureRegion
|
} as TextureRegion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun fixturePickupFun(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
|
||||||
|
(INGAME as TerrarumIngame).pickupFixtureOrDroppedItem(actor, delta, mwx, mwy, mtx, mty, false)
|
||||||
|
-1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package net.torvald.terrarum.modulebasegame.gameitems
|
||||||
|
|
||||||
|
import net.torvald.terrarum.INGAME
|
||||||
|
import net.torvald.terrarum.Point2i
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
|
import net.torvald.terrarum.gameitems.GameItem
|
||||||
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
|
import net.torvald.terrarum.gameitems.mouseInInteractableRange
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.ActorConveyors
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2025-03-15.
|
||||||
|
*/
|
||||||
|
open class ItemConveyorBelt(originalID: ItemID) : GameItem(originalID) {
|
||||||
|
override var baseMass = 10.0
|
||||||
|
override var baseToolSize: Double? = null
|
||||||
|
override var inventoryCategory = Category.FIXTURE
|
||||||
|
override val canBeDynamic = false
|
||||||
|
override val materialId = ""
|
||||||
|
override var equipPosition = EquipPosition.HAND_GRIP
|
||||||
|
|
||||||
|
override var originalName = "CONVEYOR_BELT"
|
||||||
|
|
||||||
|
|
||||||
|
protected val AXLE_COUNT = 2
|
||||||
|
|
||||||
|
|
||||||
|
private var currentStatus = 0 // 0: initial, 1+: place n-th axle
|
||||||
|
|
||||||
|
private val occupiedPoints = HashSet<Point2i>()
|
||||||
|
|
||||||
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) { _, _, mtx, mty ->
|
||||||
|
val ret = when (currentStatus) {
|
||||||
|
0 -> placeFirstAxle(mtx, mty)
|
||||||
|
1 -> placeSecondAxleAndFinalise(mtx, mty)
|
||||||
|
else -> {
|
||||||
|
currentStatus = 0
|
||||||
|
-1L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentStatus += 1
|
||||||
|
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun startSecondaryUse(actor: ActorWithBody, delta: Float): Long {
|
||||||
|
return when (currentStatus) {
|
||||||
|
0 -> FixtureItemBase.fixturePickupFun(actor, delta)
|
||||||
|
else -> {
|
||||||
|
currentStatus = -1
|
||||||
|
-1L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun placeFirstAxle(mx: Int, my: Int): Long {
|
||||||
|
occupiedPoints.add(Point2i(mx, my))
|
||||||
|
return 0L
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun placeSecondAxleAndFinalise(mx: Int, my: Int): Long {
|
||||||
|
Point2i(mx, my).let { p2 ->
|
||||||
|
if (!occupiedPoints.contains(p2)) {
|
||||||
|
occupiedPoints.add(p2)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
currentStatus = -1
|
||||||
|
return 0L
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort occupiedPoints by its x value
|
||||||
|
val points = occupiedPoints.toMutableList().also { it.sortBy { it.x } }.also { list ->
|
||||||
|
// check for ROUNDWORLD
|
||||||
|
val xMin = list[0].x
|
||||||
|
val xMax = list[1].x
|
||||||
|
// normalise it by making the x value for left spindle to negative
|
||||||
|
if (xMin >= 0 && xMin < INGAME.world.width / 2 && xMax >= INGAME.world.width / 2) {
|
||||||
|
list[0].x -= INGAME.world.width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val conveyors = ActorConveyors(points[0].x, points[0].y, points[1].x, points[1].y)
|
||||||
|
conveyors.spawn((INGAME.actorNowPlaying as? IngamePlayer)?.uuid)
|
||||||
|
}
|
||||||
|
|
||||||
|
occupiedPoints.clear()
|
||||||
|
currentStatus = -1
|
||||||
|
|
||||||
|
return 1L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user