diff --git a/src/net/torvald/terrarum/audio/AudioCodex.kt b/src/net/torvald/terrarum/audio/AudioCodex.kt index dbfca73be..9920db9a6 100644 --- a/src/net/torvald/terrarum/audio/AudioCodex.kt +++ b/src/net/torvald/terrarum/audio/AudioCodex.kt @@ -32,7 +32,7 @@ class AudioCodex { fun getRandomAudio(identifier: String): MusicContainer? { val file = audio[identifier]?.random() return if (file != null) { - MusicContainer(file.nameWithoutExtension(), file.file()) { + MusicContainer(identifier.substringBeforeLast('.') + "." + file.nameWithoutExtension(), file.file()) { it.tryDispose() } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorPrimedBomb.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorLobbed.kt similarity index 90% rename from src/net/torvald/terrarum/modulebasegame/gameactors/ActorPrimedBomb.kt rename to src/net/torvald/terrarum/modulebasegame/gameactors/ActorLobbed.kt index 1b95ee642..d3bcb2d5f 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorPrimedBomb.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorLobbed.kt @@ -1,20 +1,24 @@ package net.torvald.terrarum.modulebasegame.gameactors -import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color -import com.badlogic.gdx.graphics.g2d.SpriteBatch -import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.gdx.graphics.Cvec import net.torvald.spriteanimation.SingleImageSprite import net.torvald.terrarum.* import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED import net.torvald.terrarum.audio.audiobank.MusicContainer -import net.torvald.terrarum.audio.decibelsToFullscale -import net.torvald.terrarum.gameactors.* +import net.torvald.terrarum.gameactors.ActorWithBody +import net.torvald.terrarum.gameactors.Hitbox +import net.torvald.terrarum.gameactors.Lightbox +import net.torvald.terrarum.gameactors.PhysProperties import net.torvald.terrarum.modulebasegame.ExplosionManager -import java.util.ArrayList import kotlin.math.log10 +/** + * Created by minjaesong on 2024-07-12. + */ +open class ActorLobbed : ActorWithBody() + + /** * Created by minjaesong on 2024-02-13. */ @@ -23,7 +27,7 @@ open class ActorPrimedBomb( private var fuse: Second = 1f, @Transient private var dropProbNonOre: Float = 0.25f, @Transient private var dropProbOre: Float = 0.75f -) : ActorWithBody() { +) : ActorLobbed() { init { renderOrder = RenderOrder.MIDTOP @@ -94,10 +98,6 @@ open class ActorPrimedBomb( } } - fun updatePhysOnly(delta: Float) { - super.updateImpl(delta) - } - override fun dispose() { super.dispose() boomSound.dispose() @@ -126,7 +126,7 @@ class ActorCherryBomb : ActorPrimedBomb(14f, 4.5f) { // 14 is the intended value /** * Created by minjaesong on 2024-07-12. */ -class ActorGlowOrb : ActorPrimedBomb(0f, 0f) { // 14 is the intended value; 32 is for testing +class ActorGlowOrb : ActorLobbed() { val spawnTime = INGAME.world.worldTime.TIME_T init { @@ -148,7 +148,7 @@ class ActorGlowOrb : ActorPrimedBomb(0f, 0f) { // 14 is the intended value; 32 i override fun updateImpl(delta: Float) { - updatePhysOnly(delta) + super.updateImpl(delta) val timeDelta0 = INGAME.world.worldTime.TIME_T - spawnTime val timeDelta = timeDelta0.coerceIn(0, 9 * lifePower) @@ -162,7 +162,7 @@ class ActorGlowOrb : ActorPrimedBomb(0f, 0f) { // 14 is the intended value; 32 i lumCol.baseLumColB * charge * lumMult, lumCol.baseLumColA * charge * lumMult, ) - // remove the actor some time AFTER the chemicals are exhausted + // remove the actor some time AFTER the chemicals have exhausted if (timeDelta0 >= 10 * lifePower) { flagDespawn() } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/AxeCore.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/AxeCore.kt index 116cc20cd..0db5a625f 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/AxeCore.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/AxeCore.kt @@ -18,11 +18,17 @@ import kotlin.math.roundToInt * Created by minjaesong on 2023-11-13. */ object AxeCore { + private val tooltipHash = 10003L + private val soundPlayedForThisTick = HashMap() fun startPrimaryUse( actor: ActorWithBody, delta: Float, item: GameItem?, mx: Int, my: Int, mw: Int = 1, mh: Int = 1, additionalCheckTags: List = listOf() ) = mouseInInteractableRangeTools(actor, item) { + if (!soundPlayedForThisTick.containsKey(actor)) { + soundPlayedForThisTick[actor] = 0L + } + val updateTimer = INGAME.WORLD_UPDATE_TIMER val mh = 1 // un-round the mx @@ -69,8 +75,12 @@ object AxeCore { val actionInterval = actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!! val swingDmgToFrameDmg = delta.toDouble() / actionInterval - if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toLong()) { + // prevent double-playing of sound effects + if (soundPlayedForThisTick[actor]!! < updateTimer - 4 && + updateTimer % 11 == (Math.random() * 3).toLong()) { + PickaxeCore.makeNoiseTileTouching(actor, tile) + soundPlayedForThisTick[actor] = updateTimer } INGAME.world.inflictTerrainDamage( @@ -95,8 +105,12 @@ object AxeCore { val actionInterval = actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!! val swingDmgToFrameDmg = delta.toDouble() / actionInterval - if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toLong()) { + // prevent double-playing of sound effects + if (soundPlayedForThisTick[actor]!! < updateTimer - 4 && + updateTimer % 11 == (Math.random() * 3).toLong()) { + PickaxeCore.makeNoiseTileTouching(actor, tile) + soundPlayedForThisTick[actor] = updateTimer } INGAME.world.inflictTerrainDamage( @@ -127,8 +141,12 @@ object AxeCore { val isLargeTree = tileprop.hasTag("TREELARGE") val axePowerMult = if (isLargeTree) 0.5f else 1f - if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toLong()) { + // prevent double-playing of sound effects + if (soundPlayedForThisTick[actor]!! < updateTimer - 4 && + updateTimer % 11 == (Math.random() * 3).toLong()) { + PickaxeCore.makeNoiseTileTouching(actor, tile) + soundPlayedForThisTick[actor] = updateTimer } INGAME.world.inflictTerrainDamage( @@ -211,7 +229,7 @@ object AxeCore { upCtr += 1 } // drop the item under cursor - PickaxeCore.dropItem(BlockCodex[tileBroken].drop, x, y) // todo use log item if applicable + PickaxeCore.dropItem(BlockCodex[tileBroken].drop, x, y) // the drop should be something like "item@basegame:168" PickaxeCore.makeDust(tile, x, y, 9) PickaxeCore.makeNoiseTileBurst(actor, tile) } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt index ae8821161..04dd934f1 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt @@ -1,7 +1,6 @@ package net.torvald.terrarum.modulebasegame.gameitems import com.badlogic.gdx.graphics.Color -import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.terrarum.* import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED @@ -29,7 +28,8 @@ import kotlin.math.roundToInt * Created by minjaesong on 2019-03-10. */ object PickaxeCore { - private val hash = 10002L + private val tooltipHash = 10002L + private val soundPlayedForThisTick = HashMap() /** * @param mx centre position of the digging @@ -41,6 +41,11 @@ object PickaxeCore { actor: ActorWithBody, delta: Float, item: GameItem?, mx: Int, my: Int, dropProbability: Double = 1.0, mw: Int = 1, mh: Int = 1 ) = mouseInInteractableRangeTools(actor, item) { + if (!soundPlayedForThisTick.containsKey(actor)) { + soundPlayedForThisTick[actor] = 0L + } + val updateTimer = INGAME.WORLD_UPDATE_TIMER + // un-round the mx val ww = INGAME.world.width val hpww = ww * TILE_SIZE / 2 @@ -92,8 +97,12 @@ object PickaxeCore { val actionInterval = actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!! val swingDmgToFrameDmg = delta.toDouble() / actionInterval - if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toLong()) { + // prevent double-playing of sound effects + if (soundPlayedForThisTick[actor]!! < updateTimer - 4 && + updateTimer % 11 == (Math.random() * 3).toLong()) { + makeNoiseTileTouching(actor, tile) + soundPlayedForThisTick[actor] = updateTimer } INGAME.world.inflictTerrainDamage( @@ -228,7 +237,7 @@ object PickaxeCore { val overlayUIopen = (INGAME as? TerrarumIngame)?.uiBlur?.isVisible ?: false var tooltipSet = false - val tooltipWasShown = tooltipShowing[hash] ?: false + val tooltipWasShown = tooltipShowing[tooltipHash] ?: false mouseInInteractableRangeTools(actor, tool) { val tileUnderCursor = INGAME.world.getTileFromOre(mx, my).item @@ -241,7 +250,7 @@ object PickaxeCore { else "???" if (App.getConfigBoolean("basegame:showpickaxetooltip")) { INGAME.setTooltipMessage(tileName) - tooltipShowing[hash] = true + tooltipShowing[tooltipHash] = true } tooltipSet = true } @@ -260,7 +269,7 @@ object PickaxeCore { true // just a placeholder } - if (App.getConfigBoolean("basegame:showpickaxetooltip") && !tooltipSet) tooltipShowing[hash] = false + if (App.getConfigBoolean("basegame:showpickaxetooltip") && !tooltipSet) tooltipShowing[tooltipHash] = false } private val soundCue = MusicContainer( diff --git a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt index 0af423bea..a06d7143a 100644 --- a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt +++ b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt @@ -63,17 +63,13 @@ object Worldgen { it.putAll(oreRegistry.map { it.tile to it.tiling }) } - val tagFilter = if (tags.isEmpty()) { { work: Work -> true } } - else { - { work: Work -> - (work.tags union tags).isNotEmpty() - } - } + val tagFilter = if (tags.isEmpty()) { _: Work -> true } + else { work: Work -> (work.tags union tags).isNotEmpty() } + return listOf( - Work(Lang["MENU_IO_WORLDGEN_RETICULATING_SPLINES"], Terragen(world, false, highlandLowlandSelectCache, params.seed, params.terragenParams), listOf("TERRAIN")), + Work(Lang["MENU_IO_WORLDGEN_RETICULATING_SPLINES"], Terragen(world, false, highlandLowlandSelectCache, params.seed, params.terragenParams), listOf("TERRAIN")), // also generates marble veins Work(Lang["MENU_IO_WORLDGEN_GROWING_MINERALS"], Oregen(world, false, caveAttenuateBiasScaledCache, params.seed, oreRegistry), listOf("ORES")), Work(Lang["MENU_IO_WORLDGEN_POSITIONING_ROCKS"], OregenAutotiling(world, false, params.seed, oreTilingModes), listOf("ORES")), - // TODO generate rock veins // TODO generate gemstones Work(Lang["MENU_IO_WORLDGEN_CARVING_EARTH"], Cavegen(world, false, highlandLowlandSelectCache, params.seed, params.terragenParams), listOf("TERRAIN", "CAVE")), Work(Lang["MENU_IO_WORLDGEN_PAINTING_GREEN"], Biomegen(world, false, params.seed, params.biomegenParams, biomeMap), listOf("BIOME")),