Created
April 28, 2017 11:20
-
-
Save Drakim/6d2f8eab55df1dbc5818c0e0d31aca26 to your computer and use it in GitHub Desktop.
Screeps renew bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var roleHarvester = { | |
run: function(creep) { | |
if(creep.carry.energy < creep.carryCapacity) { | |
var sources = creep.room.find(FIND_SOURCES); | |
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { | |
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); | |
} | |
} | |
else { | |
var targets = creep.room.find(FIND_STRUCTURES, { | |
filter: (structure) => { | |
return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && | |
structure.energy < structure.energyCapacity; | |
} | |
}); | |
if(targets.length > 0) { | |
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { | |
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); | |
} | |
} | |
} | |
} | |
}; | |
function renewCreep(creep) { | |
// BUG IS TRIGGERED HERE | |
var output = Game.spawns['Spawn1'].renewCreep(creep); | |
if(output === ERR_NOT_IN_RANGE) { | |
creep.moveTo(Game.spawns['Spawn1'], {visualizePathStyle: {stroke: '#ffffff'}}); | |
} | |
} | |
module.exports.loop = function () { | |
for(var name in Memory.creeps) { | |
if(!Game.creeps[name]) { | |
delete Memory.creeps[name]; | |
console.log('Clearing non-existing creep memory:', name); | |
} | |
} | |
var harvesters = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester'); | |
console.log('Harvesters: ' + harvesters.length); | |
if(harvesters.length < 5) { | |
var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,MOVE], undefined, {role: 'harvester'}); | |
console.log('Spawning new harvester: ' + newName); | |
} | |
if(Game.spawns['Spawn1'].spawning) { | |
var spawningCreep = Game.creeps[Game.spawns['Spawn1'].spawning.name]; | |
Game.spawns['Spawn1'].room.visual.text( | |
'🛠️' + spawningCreep.memory.role, | |
Game.spawns['Spawn1'].pos.x + 1, | |
Game.spawns['Spawn1'].pos.y, | |
{align: 'left', opacity: 0.8}); | |
} | |
for(var name in Game.creeps) { | |
var creep = Game.creeps[name]; | |
if(creep.ticksToLive < 1400) { | |
renewCreep(creep); | |
} else { | |
if(creep.memory.role == 'harvester') { | |
roleHarvester.run(creep); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment