Improved walking system.
This commit is contained in:
25
Screeps/JobMiner.js
Normal file
25
Screeps/JobMiner.js
Normal file
@@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
begin(creep){},
|
||||
|
||||
tick(creep){
|
||||
const source = Game.getObjectById(creep.memory.job.source);
|
||||
if(!creep.pos.isNearTo(source)) { creep.moveTo(source); return; }
|
||||
if(!(Game.time%100)) scanForContainer(creep, source);
|
||||
moveToContainer(creep);
|
||||
creep.harvest(source);
|
||||
}
|
||||
}
|
||||
|
||||
function moveToContainer(creep){
|
||||
const container = Game.getObjectById(creep.memory.container);
|
||||
if(!container) return;
|
||||
if(container.pos.x === creep.pos.x && container.pos.y === creep.pos.y) return;
|
||||
creep.moveTo(container);
|
||||
}
|
||||
|
||||
function scanForContainer(creep, source){
|
||||
const container = source.pos.findInRange(FIND_STRUCTURES, 1, {
|
||||
filter:{structureType:STRUCTURE_CONTAINER}
|
||||
})[0];
|
||||
if(container) creep.memory.container = container.id;
|
||||
}
|
||||
Reference in New Issue
Block a user