mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-18 22:44:04 +09:00
Tile -> Block && Map -> World
This commit is contained in:
@@ -2,16 +2,16 @@ package net.torvald.terrarum.realestate
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.faction.FactionCodex
|
||||
import net.torvald.terrarum.gameworld.TileAddress
|
||||
import net.torvald.terrarum.gameworld.BlockAddress
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-27.
|
||||
*/
|
||||
object LandUtil {
|
||||
fun getTileAddr(x: Int, y: Int): TileAddress =
|
||||
fun getBlockAddr(x: Int, y: Int): BlockAddress =
|
||||
(Terrarum.ingame!!.world.width * y).toLong() + x
|
||||
|
||||
fun resolveAbsoluteTileNumber(t: TileAddress): Pair<Int, Int> =
|
||||
fun resolveAbsoluteBlockNumber(t: BlockAddress): Pair<Int, Int> =
|
||||
Pair((t % Terrarum.ingame!!.world.width).toInt(), (t / Terrarum.ingame!!.world.width).toInt())
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.torvald.terrarum.realestate
|
||||
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -8,20 +7,20 @@ import java.util.*
|
||||
*/
|
||||
object RealEstateCodex {
|
||||
/**
|
||||
* HashMap<Absolute tile number, Actor/Faction ID>
|
||||
* HashMap<Absolute block number, Actor/Faction ID>
|
||||
*
|
||||
* Note that a tile can have only ONE owner (as an Actor or Faction ID)
|
||||
* Note that a block can have only ONE owner (as an Actor or Faction ID)
|
||||
*/
|
||||
private var ownershipRegistry: HashMap<Long, Int> = HashMap()
|
||||
|
||||
fun setOwner(tileX: Int, tileY: Int, refID: Int) {
|
||||
ownershipRegistry[LandUtil.getTileAddr(tileX, tileY)] = refID
|
||||
ownershipRegistry[LandUtil.getBlockAddr(tileX, tileY)] = refID
|
||||
}
|
||||
|
||||
fun removeOwner(tileX: Int, tileY: Int) {
|
||||
ownershipRegistry.remove(LandUtil.getTileAddr(tileX, tileY))
|
||||
ownershipRegistry.remove(LandUtil.getBlockAddr(tileX, tileY))
|
||||
}
|
||||
|
||||
fun getOwner(tileX: Int, tileY: Int): Int? =
|
||||
ownershipRegistry[LandUtil.getTileAddr(tileX, tileY)]
|
||||
ownershipRegistry[LandUtil.getBlockAddr(tileX, tileY)]
|
||||
}
|
||||
Reference in New Issue
Block a user