Screeps - Container Mining Guide

Channel:
Subscribers:
180
Published on ● Video Link: https://www.youtube.com/watch?v=L8V-V-Inwq0



Category:
Guide
Duration: 8:37
6,818 views
61


A little guide for the game Screeps, on how to gather energy more efficiently with the use of containers.

Screeps is a real-time strategy Javascript-programming game.


Code used in the video:

-------------------- Miner --------------------

var roleMiner = {

/** @param {Creep} creep **/
run: function(creep) {

var targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_CONTAINER) && (structure.store[RESOURCE_ENERGY] < structure.storeCapacity);
}
});

if(targets.length > 0) {
if(creep.pos.getRangeTo(targets[0]) == 0) {
var source = creep.pos.findClosestByPath(FIND_SOURCES);
creep.harvest(source);
} else {
creep.moveTo(targets[0]);
}
}
}
};

module.exports = roleMiner;


-------------------- Pickup --------------------

var containers = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_CONTAINER) && (structure.store[RESOURCE_ENERGY] > 0);
}
});
var source = creep.pos.findClosestByPath(containers);
if(creep.withdraw(source, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(source);
}







Tags:
Javascript
real-time strategy
RTS
MMO