Closed Longtianmu closed 5 months 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.
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
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)
A off-topic problem: How can I use IR Backend when use this project? It will always throw an error like that
Actually, it's difficult to figure out that why Harvestable is not in Identifible. Besides,there is no way to harvest deposit