mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
terrain damage data is now properly removed when the tile is newly placed
This commit is contained in:
@@ -6,7 +6,7 @@ import net.torvald.terrarum.Terrarum
|
|||||||
import net.torvald.terrarum.gameactors.faction.Faction
|
import net.torvald.terrarum.gameactors.faction.Faction
|
||||||
import net.torvald.terrarum.gamecontroller.EnumKeyFunc
|
import net.torvald.terrarum.gamecontroller.EnumKeyFunc
|
||||||
import net.torvald.terrarum.itemproperties.InventoryItem
|
import net.torvald.terrarum.itemproperties.InventoryItem
|
||||||
import net.torvald.terrarum.realestate.RealEstateUtility
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
import org.newdawn.slick.GameContainer
|
import org.newdawn.slick.GameContainer
|
||||||
import org.newdawn.slick.Input
|
import org.newdawn.slick.Input
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -37,11 +37,11 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
|||||||
override var houseDesignation: ArrayList<Long>? = ArrayList()
|
override var houseDesignation: ArrayList<Long>? = ArrayList()
|
||||||
|
|
||||||
override fun addHouseTile(x: Int, y: Int) {
|
override fun addHouseTile(x: Int, y: Int) {
|
||||||
if (houseDesignation != null) houseDesignation!!.add(RealEstateUtility.getAbsoluteTileNumber(x, y))
|
if (houseDesignation != null) houseDesignation!!.add(LandUtil.getTileAddr(x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun removeHouseTile(x: Int, y: Int) {
|
override fun removeHouseTile(x: Int, y: Int) {
|
||||||
if (houseDesignation != null) houseDesignation!!.remove(RealEstateUtility.getAbsoluteTileNumber(x, y))
|
if (houseDesignation != null) houseDesignation!!.remove(LandUtil.getTileAddr(x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun clearHouseDesignation() {
|
override fun clearHouseDesignation() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
package net.torvald.terrarum.gameworld
|
package net.torvald.terrarum.gameworld
|
||||||
|
|
||||||
import net.torvald.terrarum.realestate.RealEstateUtility
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
import net.torvald.terrarum.tileproperties.TileCodex
|
import net.torvald.terrarum.tileproperties.TileCodex
|
||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
import org.newdawn.slick.SlickException
|
import org.newdawn.slick.SlickException
|
||||||
@@ -142,11 +142,13 @@ class GameWorld(val width: Int, val height: Int) {
|
|||||||
fun setTileWall(x: Int, y: Int, tile: Byte, damage: Int) {
|
fun setTileWall(x: Int, y: Int, tile: Byte, damage: Int) {
|
||||||
layerWall.setTile(x fmod width, y, tile)
|
layerWall.setTile(x fmod width, y, tile)
|
||||||
layerWallLowBits.setData(x fmod width, y, damage)
|
layerWallLowBits.setData(x fmod width, y, damage)
|
||||||
|
wallDamages.remove(LandUtil.getTileAddr(x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setTileTerrain(x: Int, y: Int, tile: Byte, damage: Int) {
|
fun setTileTerrain(x: Int, y: Int, tile: Byte, damage: Int) {
|
||||||
layerTerrain.setTile(x fmod width, y, tile)
|
layerTerrain.setTile(x fmod width, y, tile)
|
||||||
layerTerrainLowBits.setData(x fmod width, y, damage)
|
layerTerrainLowBits.setData(x fmod width, y, damage)
|
||||||
|
terrainDamages.remove(LandUtil.getTileAddr(x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setTileWire(x: Int, y: Int, tile: Byte) {
|
fun setTileWire(x: Int, y: Int, tile: Byte) {
|
||||||
@@ -216,7 +218,7 @@ class GameWorld(val width: Int, val height: Int) {
|
|||||||
* @return true if block is broken
|
* @return true if block is broken
|
||||||
*/
|
*/
|
||||||
fun inflctTerrainDamage(x: Int, y: Int, damage: Float): Boolean {
|
fun inflctTerrainDamage(x: Int, y: Int, damage: Float): Boolean {
|
||||||
val addr = RealEstateUtility.getAbsoluteTileNumber(x, y)
|
val addr = LandUtil.getTileAddr(x, y)
|
||||||
|
|
||||||
if (terrainDamages[addr] == null) { // add new
|
if (terrainDamages[addr] == null) { // add new
|
||||||
terrainDamages[addr] = damage
|
terrainDamages[addr] = damage
|
||||||
@@ -239,13 +241,13 @@ class GameWorld(val width: Int, val height: Int) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
fun getTerrainDamage(x: Int, y: Int): Float =
|
fun getTerrainDamage(x: Int, y: Int): Float =
|
||||||
terrainDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0f
|
terrainDamages[LandUtil.getTileAddr(x, y)] ?: 0f
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if block is broken
|
* @return true if block is broken
|
||||||
*/
|
*/
|
||||||
fun inflctWallDamage(x: Int, y: Int, damage: Float): Boolean {
|
fun inflctWallDamage(x: Int, y: Int, damage: Float): Boolean {
|
||||||
val addr = RealEstateUtility.getAbsoluteTileNumber(x, y)
|
val addr = LandUtil.getTileAddr(x, y)
|
||||||
|
|
||||||
if (wallDamages[addr] == null) { // add new
|
if (wallDamages[addr] == null) { // add new
|
||||||
wallDamages[addr] = damage
|
wallDamages[addr] = damage
|
||||||
@@ -266,7 +268,7 @@ class GameWorld(val width: Int, val height: Int) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
fun getWallDamage(x: Int, y: Int): Float =
|
fun getWallDamage(x: Int, y: Int): Float =
|
||||||
wallDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0f
|
wallDamages[LandUtil.getTileAddr(x, y)] ?: 0f
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import net.torvald.terrarum.mapdrawer.MapCamera.x
|
|||||||
import net.torvald.terrarum.mapdrawer.MapCamera.y
|
import net.torvald.terrarum.mapdrawer.MapCamera.y
|
||||||
import net.torvald.terrarum.mapdrawer.MapCamera.height
|
import net.torvald.terrarum.mapdrawer.MapCamera.height
|
||||||
import net.torvald.terrarum.mapdrawer.MapCamera.width
|
import net.torvald.terrarum.mapdrawer.MapCamera.width
|
||||||
import net.torvald.terrarum.realestate.RealEstateUtility
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
import org.lwjgl.opengl.GL11
|
import org.lwjgl.opengl.GL11
|
||||||
import org.newdawn.slick.*
|
import org.newdawn.slick.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import net.torvald.terrarum.gameworld.TileAddress
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-03-27.
|
* Created by minjaesong on 16-03-27.
|
||||||
*/
|
*/
|
||||||
object RealEstateUtility {
|
object LandUtil {
|
||||||
fun getAbsoluteTileNumber(x: Int, y: Int): TileAddress =
|
fun getTileAddr(x: Int, y: Int): TileAddress =
|
||||||
(Terrarum.ingame!!.world.width * y).toLong() + x
|
(Terrarum.ingame!!.world.width * y).toLong() + x
|
||||||
|
|
||||||
fun resolveAbsoluteTileNumber(t: TileAddress): Pair<Int, Int> =
|
fun resolveAbsoluteTileNumber(t: TileAddress): Pair<Int, Int> =
|
||||||
@@ -15,13 +15,13 @@ object RealEstateCodex {
|
|||||||
private var ownershipRegistry: HashMap<Long, Int> = HashMap()
|
private var ownershipRegistry: HashMap<Long, Int> = HashMap()
|
||||||
|
|
||||||
fun setOwner(tileX: Int, tileY: Int, refID: Int) {
|
fun setOwner(tileX: Int, tileY: Int, refID: Int) {
|
||||||
ownershipRegistry[RealEstateUtility.getAbsoluteTileNumber(tileX, tileY)] = refID
|
ownershipRegistry[LandUtil.getTileAddr(tileX, tileY)] = refID
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeOwner(tileX: Int, tileY: Int) {
|
fun removeOwner(tileX: Int, tileY: Int) {
|
||||||
ownershipRegistry.remove(RealEstateUtility.getAbsoluteTileNumber(tileX, tileY))
|
ownershipRegistry.remove(LandUtil.getTileAddr(tileX, tileY))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getOwner(tileX: Int, tileY: Int): Int? =
|
fun getOwner(tileX: Int, tileY: Int): Int? =
|
||||||
ownershipRegistry[RealEstateUtility.getAbsoluteTileNumber(tileX, tileY)]
|
ownershipRegistry[LandUtil.getTileAddr(tileX, tileY)]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user