generalised things so that they would work outside of ingame.world; title screen wip

This commit is contained in:
minjaesong
2017-07-21 19:59:51 +09:00
parent cb8d3fd8b9
commit f1391bea6f
68 changed files with 1141 additions and 328 deletions

View File

@@ -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

View File

@@ -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)]
}