Skip to content

Instantly share code, notes, and snippets.

@Hernanduer
Last active September 24, 2015 22:38
Show Gist options
  • Save Hernanduer/75acc503c0de5fa56a9c to your computer and use it in GitHub Desktop.
Save Hernanduer/75acc503c0de5fa56a9c to your computer and use it in GitHub Desktop.
"use strict";
module.exports = function(creep) {
let store = Game.getObjectById(creep.memory.store);
let spawn = Game.spawns.Spawn1;
let miner = Game.creeps[creep.memory.miner];
///////////////////////need some way to set the miner here and get its name or id in creep.memory.miner
if (miner == undefined) {
if (!Memory.transporters || Memory.transporters >= Memory.bots.miner.length){
Memory.transporters = 0;
}
let modulo = Memory.transporters;
miner = Memory.bots.miner[modulo];
creep.memory.miner = miner;
miner = Game.creeps[miner];
Memory.transporters++;
}
////////////////////////
//look for a new store if the current one doesn't exist or its storage is full
if (store == undefined || store == null || (store.energy != undefined && store.energy >= store.energyCapacity) || (store.store != undefined && store.store.energy >= store.storeCapacity) {
//room storage is first priority
if (creep.room.storage != undefined)
creep.memory.store = creep.room.storage.id;
//then the spawner (should expand to account for multiple spawners)
else if (spawn.energy < spawn.energyCapacity)
creep.memory.store = spawn.id;
//lastly extensions
else {
let storages = creep.room.find(FIND_MY_STRUCTURES, {
filter: function(s) {
return s.structureType == STRUCTURE_EXTENSION && s.energy < s.energyCapacity;
}
});
if (storages.length > 0)
creep.memory.store = storages[0].id;
}
store = Game.getObjectById(creep.memory.store);
}
//if creep's not full go to the miner and fill up
if (creep.carry.energy < creep.carryCapacity) {
if (!creep.pos.isNearTo(miner))
creep.moveTo(miner);
else {
creep.pickup(miner);
miner.transferEnergy(creep);
}
//otherwise head back to the storage site
} else {
if (!creep.pos.isNearTo(store))
creep.moveTo(store);
else
creep.transferEnergy(store);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment