Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports.loop = function () {
- for (let name in Game.creeps) {
- let creep = Game.creeps[name];
- if (!creep.memory.sourceId) {
- var source = creep.pos.findClosestByPath(FIND_SOURCES_ACTIVE, {
- filter: (s) => s.pos.findInRange(FIND_MY_CREEPS, 1).length == 0
- });
- if (source) {
- creep.memory.sourceId = source.id;
- }
- }
- if (creep.memory.sourceId) {
- creepHarvestBehavior(creep, Game.getObjectById(creep.memory.sourceId), Game.spawns.Spawn1);
- }
- }
- if (!Game.spawns.Spawn1.spawning && Game.spawns.Spawn1.energy == 300) {
- Game.spawns.Spawn1.createCreep([WORK, CARRY, MOVE, MOVE]);
- }
- }
- function creepHarvestBehavior(creep, source, returnStructure) {
- if (_.sum(creep.carry) == creep.carryCapacity) {
- if (creep.transfer(returnStructure, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
- creep.moveTo(returnStructure);
- }
- }
- else {
- if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
- creep.moveTo(source);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement