Example #1
0
    run: function(creep, i) {
        creep.memory.role = "harvester";
        if(creep.carry.energy === 0) {

            if (creep.memory.unloading) {
                creep.say("harvest")
            }
            creep.memory.unloading = false;
        } else if(creep.carry.energy === creep.carryCapacity) {
            if (!creep.memory.unloading) {
                creep.say("xfer");
            }
            creep.memory.unloading = true;
        }

        if(creep.memory.unloading) {

            let structure = creep.pos.findClosestByRange(FIND_MY_STRUCTURES, {filter: s => s.energy < s.energyCapacity});

            let x = creep.transfer(structure, RESOURCE_ENERGY);

             if(x == ERR_NOT_IN_RANGE) {
                creep.moveTo(structure);
            }
        }
        else {

            helpers.harvest(creep);

        }
    }
Example #2
0
    run: function(creep) {
        creep.memory.role = "builder";

        if(creep.memory.building && creep.carry.energy == 0) {
            creep.memory.building = false;
            creep.say('harvest');
        }
        if(!creep.memory.building && creep.carry.energy == creep.carryCapacity) {
            creep.memory.building = true;
            creep.say('build');
        }

        if(creep.memory.building) {
            
            let target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
            if(creep.build(target) == ERR_NOT_IN_RANGE) {
                creep.moveTo(target);
            }
        }
        else {

            helpers.harvest(creep);
        }
    }