mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
fixture will drop itself when mined
This commit is contained in:
@@ -126,6 +126,9 @@ open class IngameInstance(val batch: SpriteBatch, val isMultiplayer: Boolean = f
|
|||||||
val actorContainerActive = SortedArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
val actorContainerActive = SortedArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||||
val actorContainerInactive = SortedArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
val actorContainerInactive = SortedArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||||
|
|
||||||
|
val actorAdditionQueue = ArrayList<Actor>()
|
||||||
|
val actorRemovalQueue = ArrayList<Actor>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## BIG NOTE: Calculated actor distance is the **Euclidean distance SQUARED**
|
* ## BIG NOTE: Calculated actor distance is the **Euclidean distance SQUARED**
|
||||||
*
|
*
|
||||||
@@ -158,7 +161,7 @@ open class IngameInstance(val batch: SpriteBatch, val isMultiplayer: Boolean = f
|
|||||||
// add blockmarking_actor into the actorlist
|
// add blockmarking_actor into the actorlist
|
||||||
(CommonResourcePool.get("blockmarking_actor") as BlockMarkerActor).let {
|
(CommonResourcePool.get("blockmarking_actor") as BlockMarkerActor).let {
|
||||||
it.isVisible = false // make sure the actor is invisible on new instance
|
it.isVisible = false // make sure the actor is invisible on new instance
|
||||||
try { addNewActor(it) } catch (e: ReferencedActorAlreadyExistsException) {}
|
if (actorContainerActive.searchFor(it.referenceID) { it.referenceID } != null) actorContainerActive.add(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
gameInitialised = true
|
gameInitialised = true
|
||||||
@@ -300,7 +303,7 @@ open class IngameInstance(val batch: SpriteBatch, val isMultiplayer: Boolean = f
|
|||||||
//fun SortedArrayList<*>.binarySearch(actor: Actor) = this.toArrayList().binarySearch(actor.referenceID)
|
//fun SortedArrayList<*>.binarySearch(actor: Actor) = this.toArrayList().binarySearch(actor.referenceID)
|
||||||
//fun SortedArrayList<*>.binarySearch(ID: Int) = this.toArrayList().binarySearch(ID)
|
//fun SortedArrayList<*>.binarySearch(ID: Int) = this.toArrayList().binarySearch(ID)
|
||||||
|
|
||||||
open fun removeActor(ID: Int) = removeActor(getActorByID(ID))
|
open fun queueActorRemoval(ID: Int) = queueActorRemoval(getActorByID(ID))
|
||||||
/**
|
/**
|
||||||
* get index of the actor and delete by the index.
|
* get index of the actor and delete by the index.
|
||||||
* we can do this as the list is guaranteed to be sorted
|
* we can do this as the list is guaranteed to be sorted
|
||||||
@@ -309,13 +312,12 @@ open class IngameInstance(val batch: SpriteBatch, val isMultiplayer: Boolean = f
|
|||||||
* Any values behind the index will be automatically pushed to front.
|
* Any values behind the index will be automatically pushed to front.
|
||||||
* This is how remove function of [java.util.ArrayList] is defined.
|
* This is how remove function of [java.util.ArrayList] is defined.
|
||||||
*/
|
*/
|
||||||
open fun removeActor(actor: Actor?) {
|
open fun queueActorRemoval(actor: Actor?) {
|
||||||
if (actor == null) return
|
if (actor == null) return
|
||||||
|
actorRemovalQueue.add(actor)
|
||||||
forceRemoveActor(actor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun forceRemoveActor(actor: Actor) {
|
protected open fun forceRemoveActor(actor: Actor) {
|
||||||
arrayOf(actorContainerActive, actorContainerInactive).forEach { actorContainer ->
|
arrayOf(actorContainerActive, actorContainerInactive).forEach { actorContainer ->
|
||||||
val indexToDelete = actorContainer.searchFor(actor.referenceID) { it.referenceID }
|
val indexToDelete = actorContainer.searchFor(actor.referenceID) { it.referenceID }
|
||||||
if (indexToDelete != null) {
|
if (indexToDelete != null) {
|
||||||
@@ -325,20 +327,25 @@ open class IngameInstance(val batch: SpriteBatch, val isMultiplayer: Boolean = f
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected open fun forceAddActor(actor: Actor?) {
|
||||||
* Check for duplicates, append actor and sort the list
|
|
||||||
*/
|
|
||||||
open fun addNewActor(actor: Actor?) {
|
|
||||||
if (actor == null) return
|
if (actor == null) return
|
||||||
|
|
||||||
if (theGameHasActor(actor.referenceID)) {
|
if (theGameHasActor(actor.referenceID)) {
|
||||||
throw ReferencedActorAlreadyExistsException(actor)
|
throw ReferencedActorAlreadyExistsException(actor)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
actorContainerActive.add(actor)
|
actorAdditionQueue.add(actor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for duplicates, append actor and sort the list
|
||||||
|
*/
|
||||||
|
open fun queueActorAddition(actor: Actor?) {
|
||||||
|
if (actor == null) return
|
||||||
|
actorAdditionQueue.add(actor)
|
||||||
|
}
|
||||||
|
|
||||||
fun isActive(ID: Int): Boolean =
|
fun isActive(ID: Int): Boolean =
|
||||||
if (actorContainerActive.size == 0)
|
if (actorContainerActive.size == 0)
|
||||||
false
|
false
|
||||||
|
|||||||
@@ -1736,7 +1736,7 @@ open class ActorWithBody : Actor {
|
|||||||
assertPrinted = true
|
assertPrinted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun flagDespawn() {
|
internal open fun flagDespawn() {
|
||||||
flagDespawn = true
|
flagDespawn = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
internal fun addBlockMarker(x: Int, y: Int) {
|
internal fun addBlockMarker(x: Int, y: Int) {
|
||||||
try {
|
try {
|
||||||
val a = generateNewBlockMarkerVisible(x, y)
|
val a = generateNewBlockMarkerVisible(x, y)
|
||||||
addNewActor(a)
|
queueActorAddition(a)
|
||||||
actorsRenderOverlay.add(a)
|
actorsRenderOverlay.add(a)
|
||||||
selection.add(Point2i(x, y))
|
selection.add(Point2i(x, y))
|
||||||
}
|
}
|
||||||
@@ -233,7 +233,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
internal fun removeBlockMarker(x: Int, y: Int) {
|
internal fun removeBlockMarker(x: Int, y: Int) {
|
||||||
try {
|
try {
|
||||||
val a = getActorByID(blockPosToRefID(x, y))
|
val a = getActorByID(blockPosToRefID(x, y))
|
||||||
removeActor(a)
|
queueActorAddition(a)
|
||||||
actorsRenderOverlay.remove(a)
|
actorsRenderOverlay.remove(a)
|
||||||
selection.remove(Point2i(x, y))
|
selection.remove(Point2i(x, y))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
try {
|
try {
|
||||||
val actor = ReadActor(codices.disk, LoadSavegame.getFileReader(codices.disk, it.toLong()))
|
val actor = ReadActor(codices.disk, LoadSavegame.getFileReader(codices.disk, it.toLong()))
|
||||||
if (actor !is IngamePlayer) { // actor list should not contain IngamePlayers (see WriteWorld.preWrite) but just in case...
|
if (actor !is IngamePlayer) { // actor list should not contain IngamePlayers (see WriteWorld.preWrite) but just in case...
|
||||||
addNewActor(actor)
|
forceAddActor(actor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e: NullPointerException) {
|
catch (e: NullPointerException) {
|
||||||
@@ -329,7 +329,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
// assign new random referenceID for player
|
// assign new random referenceID for player
|
||||||
codices.player.referenceID = Terrarum.generateUniqueReferenceID(Actor.RenderOrder.MIDDLE)
|
codices.player.referenceID = Terrarum.generateUniqueReferenceID(Actor.RenderOrder.MIDDLE)
|
||||||
addNewActor(codices.player)
|
forceAddActor(codices.player)
|
||||||
|
|
||||||
|
|
||||||
// overwrite player's props with world's for multiplayer
|
// overwrite player's props with world's for multiplayer
|
||||||
@@ -460,7 +460,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
actorNowPlaying = player
|
actorNowPlaying = player
|
||||||
actorGamer = player
|
actorGamer = player
|
||||||
addNewActor(player)
|
forceAddActor(player)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -767,12 +767,19 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
///////////////////////////
|
///////////////////////////
|
||||||
repossessActor()
|
repossessActor()
|
||||||
|
|
||||||
|
// process actor addition requests
|
||||||
|
actorAdditionQueue.forEach { forceAddActor(it) }
|
||||||
|
actorAdditionQueue.clear()
|
||||||
// determine whether the inactive actor should be activated
|
// determine whether the inactive actor should be activated
|
||||||
wakeDormantActors()
|
wakeDormantActors()
|
||||||
// update NOW; allow one last update for the actors flagged to despawn
|
// update NOW; allow one last update for the actors flagged to despawn
|
||||||
updateActors(delta)
|
updateActors(delta)
|
||||||
// determine whether the actor should keep being activated or be dormant
|
// determine whether the actor should keep being activated or be dormant
|
||||||
killOrKnockdownActors()
|
killOrKnockdownActors()
|
||||||
|
// process actor removal requests
|
||||||
|
actorRemovalQueue.forEach { forceRemoveActor(it) }
|
||||||
|
actorRemovalQueue.clear()
|
||||||
|
// update particles
|
||||||
particlesContainer.forEach { if (!it.flagDespawn) particlesActive++; it.update(delta) }
|
particlesContainer.forEach { if (!it.flagDespawn) particlesActive++; it.update(delta) }
|
||||||
// TODO thread pool(?)
|
// TODO thread pool(?)
|
||||||
CollisionSolver.process()
|
CollisionSolver.process()
|
||||||
@@ -880,7 +887,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
private val maxRenderableWires = ReferencingRanges.ACTORS_WIRES.endInclusive - ReferencingRanges.ACTORS_WIRES.first + 1
|
private val maxRenderableWires = ReferencingRanges.ACTORS_WIRES.endInclusive - ReferencingRanges.ACTORS_WIRES.first + 1
|
||||||
private val wireActorsContainer = Array(maxRenderableWires) { WireActor(ReferencingRanges.ACTORS_WIRES.first + it).let {
|
private val wireActorsContainer = Array(maxRenderableWires) { WireActor(ReferencingRanges.ACTORS_WIRES.first + it).let {
|
||||||
addNewActor(it)
|
forceAddActor(it)
|
||||||
/*^let*/ it
|
/*^let*/ it
|
||||||
} }
|
} }
|
||||||
|
|
||||||
@@ -949,12 +956,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun changePossession(newActor: ActorHumanoid) {
|
internal fun changePossession(newActor: ActorHumanoid) {
|
||||||
if (!theGameHasActor(actorNowPlaying)) {
|
if (!theGameHasActor(actorNowPlaying)) { throw NoSuchActorWithRefException(newActor) }
|
||||||
throw NoSuchActorWithRefException(newActor)
|
|
||||||
}
|
|
||||||
|
|
||||||
actorNowPlaying = newActor
|
actorNowPlaying = newActor
|
||||||
//WorldSimulator(actorNowPlaying, AppLoader.getSmoothDelta().toFloat())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun changePossession(refid: Int) {
|
internal fun changePossession(refid: Int) {
|
||||||
@@ -994,7 +998,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
val actorIndex = i
|
val actorIndex = i
|
||||||
// kill actors flagged to despawn
|
// kill actors flagged to despawn
|
||||||
if (actor.flagDespawn) {
|
if (actor.flagDespawn) {
|
||||||
removeActor(actor)
|
queueActorRemoval(actor)
|
||||||
actorContainerSize -= 1
|
actorContainerSize -= 1
|
||||||
i-- // array removed 1 elem, so we also decrement counter by 1
|
i-- // array removed 1 elem, so we also decrement counter by 1
|
||||||
}
|
}
|
||||||
@@ -1111,23 +1115,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun removeActor(ID: Int) = removeActor(getActorByID(ID))
|
|
||||||
/**
|
|
||||||
* get index of the actor and delete by the index.
|
|
||||||
* we can do this as the list is guaranteed to be sorted
|
|
||||||
* and only contains unique values.
|
|
||||||
*
|
|
||||||
* Any values behind the index will be automatically pushed to front.
|
|
||||||
* This is how remove function of [java.util.ArrayList] is defined.
|
|
||||||
*/
|
|
||||||
override fun removeActor(actor: Actor?) {
|
|
||||||
if (actor == null) return
|
|
||||||
|
|
||||||
// if (actor.referenceID == actorGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
|
|
||||||
// throw ProtectedActorRemovalException("Player")
|
|
||||||
|
|
||||||
forceRemoveActor(actor)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun forceRemoveActor(actor: Actor) {
|
override fun forceRemoveActor(actor: Actor) {
|
||||||
arrayOf(actorContainerActive, actorContainerInactive).forEach { actorContainer ->
|
arrayOf(actorContainerActive, actorContainerInactive).forEach { actorContainer ->
|
||||||
@@ -1173,18 +1160,13 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
/**
|
/**
|
||||||
* Check for duplicates, append actor and sort the list
|
* Check for duplicates, append actor and sort the list
|
||||||
*/
|
*/
|
||||||
override fun addNewActor(actor: Actor?) {
|
override fun forceAddActor(actor: Actor?) {
|
||||||
if (actor == null) return
|
if (actor == null) return
|
||||||
|
|
||||||
if (theGameHasActor(actor.referenceID)) {
|
if (theGameHasActor(actor.referenceID)) {
|
||||||
throw ReferencedActorAlreadyExistsException(actor)
|
throw ReferencedActorAlreadyExistsException(actor)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (actor.referenceID !in ReferencingRanges.ACTORS_WIRES && actor.referenceID !in ReferencingRanges.ACTORS_WIRES_HELPER) {
|
|
||||||
// printdbg(this, "Adding actor $actor")
|
|
||||||
// printStackTrace(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
actorContainerActive.add(actor)
|
actorContainerActive.add(actor)
|
||||||
if (actor is ActorWithBody) actorToRenderQueue(actor).add(actor)
|
if (actor is ActorWithBody) actorToRenderQueue(actor).add(actor)
|
||||||
}
|
}
|
||||||
@@ -1250,7 +1232,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pickup a fixture
|
// pickup a fixture
|
||||||
if (fixturesUnderHand.size > 0) {
|
if (fixturesUnderHand.size > 0 && fixturesUnderHand[0].canBeDespawned) {
|
||||||
val fixture = fixturesUnderHand[0]
|
val fixture = fixturesUnderHand[0]
|
||||||
val fixtureItem = ItemCodex.fixtureToItemID(fixture)
|
val fixtureItem = ItemCodex.fixtureToItemID(fixture)
|
||||||
printdbg(this, "Fixture pickup: ${fixture.javaClass.canonicalName} -> $fixtureItem")
|
printdbg(this, "Fixture pickup: ${fixture.javaClass.canonicalName} -> $fixtureItem")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ internal object KillActor : ConsoleCommand {
|
|||||||
if (args.size == 2) {
|
if (args.size == 2) {
|
||||||
try {
|
try {
|
||||||
val actorid = args[1].toInt()
|
val actorid = args[1].toInt()
|
||||||
INGAME.removeActor(actorid)
|
INGAME.queueActorRemoval(actorid)
|
||||||
}
|
}
|
||||||
catch (e: NumberFormatException) {
|
catch (e: NumberFormatException) {
|
||||||
EchoError("Wrong number input.")
|
EchoError("Wrong number input.")
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ internal object SpawnPhysTestBall : ConsoleCommand {
|
|||||||
ball.elasticity = elasticity
|
ball.elasticity = elasticity
|
||||||
ball.applyForce(Vector2(xvel, yvel))
|
ball.applyForce(Vector2(xvel, yvel))
|
||||||
|
|
||||||
INGAME.addNewActor(ball)
|
INGAME.queueActorAddition(ball)
|
||||||
}
|
}
|
||||||
else if (args.size == 2) {
|
else if (args.size == 2) {
|
||||||
val elasticity = args[1].toDouble()
|
val elasticity = args[1].toDouble()
|
||||||
@@ -36,7 +36,7 @@ internal object SpawnPhysTestBall : ConsoleCommand {
|
|||||||
ball.setPosition(mouseX, mouseY)
|
ball.setPosition(mouseX, mouseY)
|
||||||
ball.elasticity = elasticity
|
ball.elasticity = elasticity
|
||||||
|
|
||||||
INGAME.addNewActor(ball)
|
INGAME.queueActorAddition(ball)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printUsage()
|
printUsage()
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ internal object SpawnPhysTestLunarLander : ConsoleCommand {
|
|||||||
|
|
||||||
lander.setPosition(mouseX, mouseY)
|
lander.setPosition(mouseX, mouseY)
|
||||||
|
|
||||||
INGAME.addNewActor(lander)
|
INGAME.queueActorAddition(lander)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printUsage() {
|
override fun printUsage() {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ internal object SpawnTapestry : ConsoleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val tapestry = DecodeTapestry(File(args[1]))
|
val tapestry = DecodeTapestry(File(args[1]))
|
||||||
INGAME.addNewActor(tapestry)
|
INGAME.queueActorAddition(tapestry)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printUsage() {
|
override fun printUsage() {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ internal object SpawnTikiTorch : ConsoleCommand {
|
|||||||
val torch = FixtureTikiTorch()
|
val torch = FixtureTikiTorch()
|
||||||
torch.setPosition(Terrarum.mouseX, Terrarum.mouseY)
|
torch.setPosition(Terrarum.mouseX, Terrarum.mouseY)
|
||||||
|
|
||||||
INGAME.addNewActor(torch)
|
INGAME.queueActorAddition(torch)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printUsage() {
|
override fun printUsage() {
|
||||||
|
|||||||
@@ -36,7 +36,11 @@ open class DroppedItem : ActorWithBody {
|
|||||||
|
|
||||||
fun canBePickedUp() = timeSinceSpawned > NO_PICKUP_TIME && !flagDespawn
|
fun canBePickedUp() = timeSinceSpawned > NO_PICKUP_TIME && !flagDespawn
|
||||||
|
|
||||||
constructor(itemID: ItemID, topLeftX: Int, topLeftY: Int) : super(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) {
|
/**
|
||||||
|
* @param topLeftX world-wise coord
|
||||||
|
* @param topLeftY world-wise coord
|
||||||
|
*/
|
||||||
|
constructor(itemID: ItemID, topLeftX: Double, topLeftY: Double) : super(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) {
|
||||||
this.itemID = itemID
|
this.itemID = itemID
|
||||||
|
|
||||||
if (itemID.startsWith("actor@"))
|
if (itemID.startsWith("actor@"))
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
private set
|
private set
|
||||||
|
|
||||||
fun forEachBlockbox(action: (Int, Int) -> Unit) {
|
fun forEachBlockbox(action: (Int, Int) -> Unit) {
|
||||||
worldBlockPos!!.let { (posX, posY) ->
|
worldBlockPos?.let { (posX, posY) ->
|
||||||
for (y in posY until posY + blockBox.height) {
|
for (y in posY until posY + blockBox.height) {
|
||||||
for (x in posX until posX + blockBox.width) {
|
for (x in posX until posX + blockBox.width) {
|
||||||
action(x, y)
|
action(x, y)
|
||||||
@@ -76,20 +76,20 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun updateForTerrainChange(cue: IngameInstance.BlockChangeQueueItem) {
|
override fun updateForTerrainChange(cue: IngameInstance.BlockChangeQueueItem) {
|
||||||
|
fillFillerBlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fillFillerBlock(bypassEvent: Boolean = false) {
|
private fun fillFillerBlock() {
|
||||||
forEachBlockbox { x, y ->
|
forEachBlockbox { x, y ->
|
||||||
//printdbg(this, "fillerblock ${blockBox.collisionType} at ($x, $y)")
|
//printdbg(this, "fillerblock ${blockBox.collisionType} at ($x, $y)")
|
||||||
if (blockBox.collisionType == BlockBox.ALLOW_MOVE_DOWN) {
|
if (blockBox.collisionType == BlockBox.ALLOW_MOVE_DOWN) {
|
||||||
// if the collision type is allow_move_down, only the top surface tile should be "the platform"
|
// if the collision type is allow_move_down, only the top surface tile should be "the platform"
|
||||||
// lower part must not have such property (think of the table!)
|
// lower part must not have such property (think of the table!)
|
||||||
// TODO does this ACTUALLY work ?!
|
// TODO does this ACTUALLY work ?!
|
||||||
world!!.setTileTerrain(x, y, if (y == worldBlockPos!!.y) BlockBox.ALLOW_MOVE_DOWN else BlockBox.NO_COLLISION, bypassEvent)
|
world!!.setTileTerrain(x, y, if (y == worldBlockPos!!.y) BlockBox.ALLOW_MOVE_DOWN else BlockBox.NO_COLLISION, true)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
world!!.setTileTerrain(x, y, blockBox.collisionType, bypassEvent)
|
world!!.setTileTerrain(x, y, blockBox.collisionType, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,38 +144,45 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
this.hitbox.setFromWidthHeight(posX * TILE_SIZED, posY * TILE_SIZED, blockBox.width * TILE_SIZED, blockBox.height * TILE_SIZED)
|
this.hitbox.setFromWidthHeight(posX * TILE_SIZED, posY * TILE_SIZED, blockBox.width * TILE_SIZED, blockBox.height * TILE_SIZED)
|
||||||
|
|
||||||
// actually add this actor into the world
|
// actually add this actor into the world
|
||||||
INGAME.addNewActor(this)
|
INGAME.queueActorAddition(this)
|
||||||
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val canBeDespawned: Boolean get() = inventory?.isEmpty() ?: true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes this instance of the fixture from the world
|
* Removes this instance of the fixture from the world
|
||||||
*/
|
*/
|
||||||
open fun despawn() {
|
open fun despawn() {
|
||||||
printdbg(this, "despawn ${nameFun()}")
|
if (canBeDespawned) {
|
||||||
|
printdbg(this, "despawn ${nameFun()}")
|
||||||
|
|
||||||
// remove filler block
|
// remove filler block
|
||||||
forEachBlockbox { x, y ->
|
forEachBlockbox { x, y ->
|
||||||
world!!.setTileTerrain(x, y, Block.AIR, true)
|
world!!.setTileTerrain(x, y, Block.AIR, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
worldBlockPos = null
|
||||||
|
mainUI?.dispose()
|
||||||
|
|
||||||
|
this.isVisible = false
|
||||||
|
|
||||||
|
if (this is Electric) {
|
||||||
|
wireEmitterTypes.clear()
|
||||||
|
wireEmission.clear()
|
||||||
|
wireConsumption.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
val drop = ItemCodex.fixtureToItemID(this)
|
||||||
|
INGAME.queueActorAddition(DroppedItem(drop, hitbox.startX, hitbox.startY - 1.0))
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
worldBlockPos = null
|
printdbg(this, "cannot despawn a fixture with non-empty inventory")
|
||||||
mainUI?.dispose()
|
|
||||||
|
|
||||||
this.isVisible = false
|
|
||||||
|
|
||||||
if (this is Electric) {
|
|
||||||
wireEmitterTypes.clear()
|
|
||||||
wireEmission.clear()
|
|
||||||
wireConsumption.clear()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO drop self as an item (instance of DroppedItem)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
// if not flagged to despawn and not actually despawned (which sets worldBlockPos as null), always fill up fillerBlock
|
// if not flagged to despawn and not actually despawned (which sets worldBlockPos as null), always fill up fillerBlock
|
||||||
if (!flagDespawn && worldBlockPos != null) {
|
if (!flagDespawn && worldBlockPos != null) {
|
||||||
@@ -187,11 +194,15 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (flagDespawn) despawn()
|
if (!canBeDespawned) flagDespawn = false
|
||||||
|
else if (flagDespawn) despawn()
|
||||||
// actual actor removal is performed by the TerrarumIngame.killOrKnockdownActors
|
// actual actor removal is performed by the TerrarumIngame.killOrKnockdownActors
|
||||||
super.update(delta)
|
super.update(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun flagDespawn() {
|
||||||
|
if (canBeDespawned) flagDespawn = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CuedByTerrainChange {
|
interface CuedByTerrainChange {
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ open class FixtureInventory() {
|
|||||||
*/
|
*/
|
||||||
val itemList = ArrayList<InventoryPair>()
|
val itemList = ArrayList<InventoryPair>()
|
||||||
var wallet = BigInteger("0") // unified currency for whole civs; Dwarf Fortress approach seems too complicated
|
var wallet = BigInteger("0") // unified currency for whole civs; Dwarf Fortress approach seems too complicated
|
||||||
|
|
||||||
|
fun isEmpty() = getTotalCount() == 0
|
||||||
|
fun isNotEmpty() = getTotalCount() > 0
|
||||||
|
|
||||||
open fun add(itemID: ItemID, count: Int = 1) {
|
open fun add(itemID: ItemID, count: Int = 1) {
|
||||||
if (ItemCodex[itemID] == null)
|
if (ItemCodex[itemID] == null)
|
||||||
throw NullPointerException("Item not found: $itemID")
|
throw NullPointerException("Item not found: $itemID")
|
||||||
@@ -136,12 +139,12 @@ open class FixtureInventory() {
|
|||||||
else
|
else
|
||||||
getTotalCount().toDouble()
|
getTotalCount().toDouble()
|
||||||
|
|
||||||
fun getTotalWeight(): Double = itemList.map { ItemCodex[it.itm]!!.mass * it.qty }.sum()
|
fun getTotalWeight(): Double = itemList.sumOf { ItemCodex[it.itm]!!.mass * it.qty }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Real amount
|
* Real amount
|
||||||
*/
|
*/
|
||||||
fun getTotalCount(): Int = itemList.map { it.qty }.sum()
|
fun getTotalCount(): Int = itemList.sumOf { it.qty }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique amount, multiple items are calculated as one
|
* Unique amount, multiple items are calculated as one
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ open class HumanoidNPC : ActorHumanoid, AIControlled, CanBeAnItem {
|
|||||||
try {
|
try {
|
||||||
// place the actor to the world
|
// place the actor to the world
|
||||||
this@HumanoidNPC.setPosition(Terrarum.mouseX, Terrarum.mouseY)
|
this@HumanoidNPC.setPosition(Terrarum.mouseX, Terrarum.mouseY)
|
||||||
INGAME.addNewActor(this@HumanoidNPC)
|
INGAME.queueActorAddition(this@HumanoidNPC)
|
||||||
// successful
|
// successful
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ object PickaxeCore {
|
|||||||
if (Math.random() < dropProbability) {
|
if (Math.random() < dropProbability) {
|
||||||
val drop = BlockCodex[tileBroken].drop
|
val drop = BlockCodex[tileBroken].drop
|
||||||
if (drop.isNotBlank()) {
|
if (drop.isNotBlank()) {
|
||||||
INGAME.addNewActor(DroppedItem(drop, x * TILE_SIZE, y * TILE_SIZE))
|
INGAME.queueActorAddition(DroppedItem(drop, x * TILE_SIZED, y * TILE_SIZED))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import net.torvald.terrarum.CommonResourcePool
|
|||||||
import net.torvald.terrarum.Point2i
|
import net.torvald.terrarum.Point2i
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitems.GameItem
|
import net.torvald.terrarum.gameitems.GameItem
|
||||||
import net.torvald.terrarum.gameitems.ItemID
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
@@ -43,7 +44,7 @@ class WireCutterAll(originalID: ItemID) : GameItem(originalID) {
|
|||||||
|
|
||||||
wires?.forEach {
|
wires?.forEach {
|
||||||
ingame.world.removeTileWire(mouseTile.x, mouseTile.y, it, false)
|
ingame.world.removeTileWire(mouseTile.x, mouseTile.y, it, false)
|
||||||
ingame.addNewActor(DroppedItem(it, mouseTile.x * TILE_SIZE, mouseTile.y * TILE_SIZE))
|
ingame.queueActorAddition(DroppedItem(it, mouseTile.x * TILE_SIZED, mouseTile.y * TILE_SIZED))
|
||||||
} ?: return@mouseInInteractableRange false
|
} ?: return@mouseInInteractableRange false
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|||||||
Reference in New Issue
Block a user