mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 05:24:06 +09:00
generalised things so that they would work outside of ingame.world; title screen wip
This commit is contained in:
@@ -3,16 +3,17 @@ package net.torvald.terrarum.realestate
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.faction.FactionCodex
|
||||
import net.torvald.terrarum.gameworld.BlockAddress
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-27.
|
||||
*/
|
||||
object LandUtil {
|
||||
fun getBlockAddr(x: Int, y: Int): BlockAddress =
|
||||
(Terrarum.ingame!!.world.width * y).toLong() + x
|
||||
fun getBlockAddr(world: GameWorld, x: Int, y: Int): BlockAddress =
|
||||
(world.width * y).toLong() + x
|
||||
|
||||
fun resolveBlockAddr(t: BlockAddress): Pair<Int, Int> =
|
||||
Pair((t % Terrarum.ingame!!.world.width).toInt(), (t / Terrarum.ingame!!.world.width).toInt())
|
||||
fun resolveBlockAddr(world: GameWorld, t: BlockAddress): Pair<Int, Int> =
|
||||
Pair((t % world.width).toInt(), (t / world.width).toInt())
|
||||
|
||||
/**
|
||||
* Get owner ID as an Actor/Faction
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.realestate
|
||||
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -13,14 +14,14 @@ object RealEstateCodex {
|
||||
*/
|
||||
private var ownershipRegistry: HashMap<Long, Int> = HashMap()
|
||||
|
||||
fun setOwner(tileX: Int, tileY: Int, refID: Int) {
|
||||
ownershipRegistry[LandUtil.getBlockAddr(tileX, tileY)] = refID
|
||||
fun setOwner(world: GameWorld, tileX: Int, tileY: Int, refID: Int) {
|
||||
ownershipRegistry[LandUtil.getBlockAddr(world, tileX, tileY)] = refID
|
||||
}
|
||||
|
||||
fun removeOwner(tileX: Int, tileY: Int) {
|
||||
ownershipRegistry.remove(LandUtil.getBlockAddr(tileX, tileY))
|
||||
fun removeOwner(world: GameWorld, tileX: Int, tileY: Int) {
|
||||
ownershipRegistry.remove(LandUtil.getBlockAddr(world, tileX, tileY))
|
||||
}
|
||||
|
||||
fun getOwner(tileX: Int, tileY: Int): Int? =
|
||||
ownershipRegistry[LandUtil.getBlockAddr(tileX, tileY)]
|
||||
fun getOwner(world: GameWorld, tileX: Int, tileY: Int): Int? =
|
||||
ownershipRegistry[LandUtil.getBlockAddr(world, tileX, tileY)]
|
||||
}
|
||||
Reference in New Issue
Block a user