fix: damaging terrain would not queue the modified chunk for the autosave

This commit is contained in:
minjaesong
2024-02-16 14:29:47 +09:00
parent 902341bd78
commit b11bbf0130
7 changed files with 24 additions and 10 deletions

View File

@@ -295,6 +295,7 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
open fun modified(layer: Int, x: Int, y: Int) { open fun modified(layer: Int, x: Int, y: Int) {
// printdbg(this, "Chunk modified: layer $layer ($x, $y)")
modifiedChunks[layer].add(LandUtil.toChunkNum(world, x, y)) modifiedChunks[layer].add(LandUtil.toChunkNum(world, x, y))
} }

View File

@@ -588,7 +588,7 @@ open class ActorWithBody : Actor {
// printdbg(this, it) // printdbg(this, it)
val dmgPerTile = terrainDamage / it.size val dmgPerTile = terrainDamage / it.size
it.forEach { (x, y) -> it.forEach { (x, y) ->
world?.inflictTerrainDamage(x, y, dmgPerTile) world?.inflictTerrainDamage(x, y, dmgPerTile, false)
} }
} }
} }

View File

@@ -644,7 +644,7 @@ open class GameWorld(
/** /**
* @return ItemID of the broken block AND ore if the block is broken, `null` otherwise * @return ItemID of the broken block AND ore if the block is broken, `null` otherwise
*/ */
fun inflictTerrainDamage(x: Int, y: Int, damage: Double): Pair<ItemID?, ItemID?> { fun inflictTerrainDamage(x: Int, y: Int, damage: Double, bypassEvent: Boolean): Pair<ItemID?, ItemID?> {
if (damage.isNaN()) throw IllegalArgumentException("Cannot inflict NaN amount of damage at($x, $y)") if (damage.isNaN()) throw IllegalArgumentException("Cannot inflict NaN amount of damage at($x, $y)")
val damage = damage.toFloat() val damage = damage.toFloat()
@@ -662,6 +662,10 @@ open class GameWorld(
terrainDamages[addr] = terrainDamages[addr]!! + damage terrainDamages[addr] = terrainDamages[addr]!! + damage
} }
if (!bypassEvent) {
Terrarum.ingame?.modified(LandUtil.LAYER_TERR, x, y)
}
//println("[GameWorld] accumulated damage: ${terrainDamages[addr]}") //println("[GameWorld] accumulated damage: ${terrainDamages[addr]}")
// remove tile from the world // remove tile from the world
@@ -681,7 +685,7 @@ open class GameWorld(
/** /**
* @return true if block is broken * @return true if block is broken
*/ */
fun inflictWallDamage(x: Int, y: Int, damage: Double): ItemID? { fun inflictWallDamage(x: Int, y: Int, damage: Double, bypassEvent: Boolean): ItemID? {
if (damage.isNaN()) throw IllegalArgumentException("Cannot inflict NaN amount of damage at($x, $y)") if (damage.isNaN()) throw IllegalArgumentException("Cannot inflict NaN amount of damage at($x, $y)")
val damage = damage.toFloat() val damage = damage.toFloat()
@@ -697,6 +701,10 @@ open class GameWorld(
wallDamages[addr] = wallDamages[addr]!! + damage wallDamages[addr] = wallDamages[addr]!! + damage
} }
if (!bypassEvent) {
Terrarum.ingame?.modified(LandUtil.LAYER_TERR, x, y)
}
// remove tile from the world // remove tile from the world
if (wallDamages[addr]!! >= BlockCodex[getTileFromWall(x, y)].strength) { if (wallDamages[addr]!! >= BlockCodex[getTileFromWall(x, y)].strength) {
val tileBroke = getTileFromWall(x, y) val tileBroke = getTileFromWall(x, y)

View File

@@ -140,7 +140,7 @@ object ExplosionManager {
private fun memcpyToWorldBreakage(CALC_WIDTH: Int, world: GameWorld, xStart: Int, yStart: Int, yOff: Int, out: UnsafeFloatArray) { private fun memcpyToWorldBreakage(CALC_WIDTH: Int, world: GameWorld, xStart: Int, yStart: Int, yOff: Int, out: UnsafeFloatArray) {
for (x in xStart until xStart + CALC_WIDTH) { for (x in xStart until xStart + CALC_WIDTH) {
world.inflictTerrainDamage(x, yStart + yOff, out[x - xStart, yOff].toDouble()) world.inflictTerrainDamage(x, yStart + yOff, out[x - xStart, yOff].toDouble(), false)
} }
} }
@@ -273,7 +273,7 @@ object ExplosionManager {
for (wx in worldXstart until worldXstart + CALC_WIDTH) { for (wx in worldXstart until worldXstart + CALC_WIDTH) {
val lx = wx - (tx - CALC_RADIUS - 1) val lx = wx - (tx - CALC_RADIUS - 1)
val ly = wy - (ty - CALC_RADIUS - 1) val ly = wy - (ty - CALC_RADIUS - 1)
world.inflictTerrainDamage(wx, wy, mapBoomPow[lx, ly].blastToDmg().toDouble()).let { (tile, ore) -> world.inflictTerrainDamage(wx, wy, mapBoomPow[lx, ly].blastToDmg().toDouble(), false).let { (tile, ore) ->
if (ore != null || tile != null) { if (ore != null || tile != null) {
// drop item // drop item
val prob = if (ore != null) dropProbOre else dropProbNonOre val prob = if (ore != null) dropProbOre else dropProbNonOre

View File

@@ -79,7 +79,8 @@ object AxeCore {
INGAME.world.inflictTerrainDamage( INGAME.world.inflictTerrainDamage(
x, y, x, y,
Calculate.hatchetPower(actor, item?.material) * swingDmgToFrameDmg Calculate.hatchetPower(actor, item?.material) * swingDmgToFrameDmg,
false
).let { tileBroken -> ).let { tileBroken ->
// tile busted // tile busted
if (tileBroken != null) { if (tileBroken != null) {
@@ -100,7 +101,8 @@ object AxeCore {
INGAME.world.inflictTerrainDamage( INGAME.world.inflictTerrainDamage(
x, y, x, y,
Calculate.hatchetPower(actor, item?.material) * swingDmgToFrameDmg Calculate.hatchetPower(actor, item?.material) * swingDmgToFrameDmg,
false
).let { (tileBroken, _) -> ).let { (tileBroken, _) ->
// tile busted // tile busted
if (tileBroken != null) { if (tileBroken != null) {
@@ -125,7 +127,8 @@ object AxeCore {
INGAME.world.inflictTerrainDamage( INGAME.world.inflictTerrainDamage(
x, y, x, y,
Calculate.hatchetPower(actor, item?.material) * swingDmgToFrameDmg Calculate.hatchetPower(actor, item?.material) * swingDmgToFrameDmg,
false
).let { (tileBroken, _) -> ).let { (tileBroken, _) ->
// tile busted // tile busted
if (tileBroken != null) { if (tileBroken != null) {

View File

@@ -93,7 +93,8 @@ object PickaxeCore {
INGAME.world.inflictTerrainDamage( INGAME.world.inflictTerrainDamage(
x, y, x, y,
Calculate.pickaxePower(actor, item?.material) * swingDmgToFrameDmg Calculate.pickaxePower(actor, item?.material) * swingDmgToFrameDmg,
false
).let { (tileBroken, oreBroken) -> ).let { (tileBroken, oreBroken) ->
// drop ore // drop ore

View File

@@ -94,7 +94,8 @@ object SledgehammerCore {
INGAME.world.inflictWallDamage( INGAME.world.inflictWallDamage(
x, y, x, y,
Calculate.pickaxePower(actor, item?.material) * swingDmgToFrameDmg Calculate.pickaxePower(actor, item?.material) * swingDmgToFrameDmg,
false
).let { tileBroken -> ).let { tileBroken ->
// tile busted // tile busted
if (tileBroken != null) { if (tileBroken != null) {