mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 21:14:04 +09:00
thermal stuffs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
@@ -24,8 +25,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
||||
|
||||
var fuelCaloriesNow = 0f
|
||||
var fuelCaloriesMax: Float? = null
|
||||
var fuelCaloriesNow = 0.0 // arbitrary number, may as well be watts or joules
|
||||
var fuelCaloriesMax: Double? = null
|
||||
var temperature = 0f // 0f..1f
|
||||
var progress = 0f // 0f..1f
|
||||
|
||||
@@ -83,27 +84,63 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
||||
}
|
||||
}
|
||||
|
||||
private var nextDelay = 0.25f
|
||||
private var nextDelayBase = 0.25f // use smokiness value of the item
|
||||
private var nextDelay = 0.25f // use smokiness value of the item
|
||||
private var spawnTimer = 0f
|
||||
|
||||
@Transient private val FUEL_CONSUMPTION = 1f
|
||||
|
||||
@Transient private val RNG = HQRNG()
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
// consume fuel
|
||||
if (fuelCaloriesNow > 0f) {
|
||||
fuelCaloriesNow -= FUEL_CONSUMPTION
|
||||
|
||||
// emit smokes TODO: only when hot
|
||||
// raise temperature
|
||||
temperature += 1f /2048f
|
||||
}
|
||||
// take fuel from the item slot
|
||||
else if (fuelCaloriesNow <= 0f && fireboxItem != null && fireboxItem!!.qty > 0L) {
|
||||
fuelCaloriesNow = ItemCodex[fireboxItem!!.itm]!!.calories
|
||||
fuelCaloriesMax = ItemCodex[fireboxItem!!.itm]!!.calories
|
||||
nextDelayBase = ItemCodex[fireboxItem!!.itm]!!.smokiness
|
||||
nextDelay = (nextDelayBase * (1.0 + RNG.nextTriangularBal() * 0.1)).toFloat()
|
||||
|
||||
fireboxItem!!.qty -= 1L
|
||||
if (fireboxItem!!.qty == 0L) {
|
||||
fireboxItem = null
|
||||
}
|
||||
}
|
||||
// no item on the slot
|
||||
else if (fuelCaloriesNow <= 0f && fireboxItem == null) {
|
||||
nextDelayBase = Float.POSITIVE_INFINITY
|
||||
nextDelay = Float.POSITIVE_INFINITY
|
||||
}
|
||||
|
||||
// tick a thermal loss
|
||||
temperature -= 1f / 4096f
|
||||
temperature = temperature.coerceIn(0f, 1f)
|
||||
|
||||
|
||||
// emit smokes only when there is something burning
|
||||
if (spawnTimer >= nextDelay) {
|
||||
(Terrarum.ingame as TerrarumIngame).addParticle(
|
||||
ParticleVanishingSprite(
|
||||
CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"),
|
||||
25f, true, hitbox.startX + TILE_SIZED, hitbox.startY + 16, false, (Math.random() * 256).toInt()
|
||||
))
|
||||
CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"),
|
||||
25f, true, hitbox.startX + TILE_SIZED, hitbox.startY + 16, false, (Math.random() * 256).toInt()
|
||||
)
|
||||
)
|
||||
|
||||
spawnTimer -= nextDelay
|
||||
nextDelay = Math.random().toFloat() * 0.25f + 0.25f
|
||||
nextDelay = (nextDelayBase * (1.0 + RNG.nextTriangularBal() * 0.1)).toFloat()
|
||||
|
||||
(sprite as? SheetSpriteAnimation)?.delays?.set(0, Math.random().toFloat() * 0.4f + 0.1f)
|
||||
}
|
||||
|
||||
|
||||
spawnTimer += delta
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user