exaV / screeps-kotlin-types

Screep's Kotlin type definitions
MIT License
17 stars 18 forks source link

Cannot Harvest Deposit #76

Closed Longtianmu closed 5 months ago

Longtianmu commented 2 years ago

Actually, it's difficult to figure out that why Harvestable is not in Identifible. Besides,there is no way to harvest deposit

exaV commented 2 years ago

Here's an example of how to harvest from a mineral deposit

        val creep = // some creen
        val minerals = creep.room.find(FIND_MINERALS)
        if (creep.harvest(minerals[0]) == ERR_NOT_IN_RANGE) {
            creep.moveTo(minerals[0].pos)
        }

We try to keep things simple and to avoid mixing the interfaces too much. That's why for example Owned is not Identifieable either.

In my playthrough it has not been a problem. I keep a list of Mineral not a list of Harvestable in my code and I use Game.getObjectById<Mineral>(id) to load them by id. That being said, if it you can make a good case for why Harvestable should be Identifieable then I am not opposed to adding it.

Longtianmu commented 2 years ago

If I want to use Task or some a more powerful way, I will stored Source/Deposit/Mineral's ID in memory and Game.getObjectByID(id) And here is the problem-I can't harvest a Identifable so I need to cast it to Source/Deposit/Mineral like

  val target = Game.getObjectById<Identifiable>(targetID).unsafeCast<Source/Mineral/Deposits>(targetID)

However the step can be used for Anything that is harvestable so I can't cast it to any specific type If I can use Harvestale instead,the problem will be much easier like that:

    val target = Game.getObjectById<Harvestable>(targetID) 

    creep.harvest(target)
Longtianmu commented 2 years ago

A off-topic problem: How can I use IR Backend when use this project? It will always throw an error like that image

exaV commented 5 months ago

fixed with https://github.com/exaV/screeps-kotlin-types/commit/ad554d7a65fed92d2d5bb0ba1ad72e41b146b5ac