Is it even possible to harvest this source?



  • I have a room that you can see in the attached image. Oddly it has 2 sources stacked directly one above the other. My question is, I have tried a number of different approaches. But is the Top energy source in this image even harvestable?

    0_1572725102019_Screen Shot.jpg



  • Sure, just park one of the miners below and to the right of the top source, there is one point of access to it. Of course, in that room you can access both sources from that point, so you have to be sure to get the id of the one you want to mine when you mine it (Store it in the creep's memory.) Then use "Game.getObjectFromId(creep.memory.yourSavedSourceId); to get the source object.

    You can even use just one creep and switch back and forth between the sources.



  • Absolutely, the top source is accessible for mining diagonally from 14,18. I have a similar case in my room over here: https://screeps.com/a/#!/room/shard1/E29N12



  • I figured it was possible... but all my approaches kept ignoring the upper source, and using the bottom source. I have since seen other examples of people succeeding at this. So I will just have to look closer at my code.

    Thanks



  • It's actually pretty easy. Each source has a unique ID, they get assigned when originally created (When Shard 3 was created, in this case.) and are assigned left to right, top to bottom. So the top source has a lower ID number than the one below it, as it was assigned first. These IDs are permanent.

    If you use "let sources = room.find(FIND_SOURCES);" to find the sources, you'll get sources[0] pointing to the top one, and sources[1] pointing to the bottom one. the sources array returned by find will have a length of 2. The ID itself for the top one will be "sources[0].id"

    But if you wander over to the sources and then search for the closest one, you'll just get whichever one is 'closer.' One of them has to be closer, even if they're both 1 away.

    So... the problem is how you're searching for the sources.