Skip to content

Commit

Permalink
Merge pull request #1 from maaktweluit/master
Browse files Browse the repository at this point in the history
Good addition
  • Loading branch information
Garethp committed Dec 7, 2014
2 parents f2f23c3 + 028a23f commit 8236596
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion performRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function(creeps)
for(var name in creeps)
{
var creep = creeps[name];
if(creep.memory.role == undefined || (creep.memory.active !== undefined && !creep.memory.active))
if(creep.spawning || creep.memory.role == undefined || (creep.memory.active !== undefined && !creep.memory.active))
continue;

var role = creep.memory.role;
Expand Down
42 changes: 20 additions & 22 deletions spawner.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,40 @@ module.exports =
{
this.initSpawnQue();

if(Memory.spawnQue.length == 0)
if(!Memory.spawnQue.length)
return;

var spawns = Game.getRoom('1-1').find(Game.MY_SPAWNS, {
filter: function(spawn)
{
return spawn.spawning === undefined || spawn.spawning === null;
}
});

if(!spawns.length)
return;

var role = Memory.spawnQue[0];
var spawnCost = this.spawnCost(role);
var me = this;

if(typeof role == "string")
{
role = { type: role, memory: { } };
}

var toSpawnAt = Game.getRoom('1-1').find(Game.MY_SPAWNS, {
filter: function(spawn)
{
return me.canSpawn(spawn, role.type);
}
var me = this;
var toSpawnAt = spawns.filter(function(spawn)
{
return me.canSpawn(spawn, role.type);
});

if(toSpawnAt.length > 0)
toSpawnAt = toSpawnAt[0];
else
toSpawnAt = false;

// console.log(toSpawnAt);
if(! toSpawnAt.length)
return;

if(toSpawnAt)
{
if(!this.canSpawn(toSpawnAt, role.type))
return;
toSpawnAt = toSpawnAt[0];

this.spawn(role.type, role.memory, toSpawnAt);
this.spawn(role.type, role.memory, toSpawnAt);

console.log('Removing ' + role.type);
Memory.spawnQue.shift();
}
Memory.spawnQue.shift();
},

spawn: function(role, memory, spawnPoint)
Expand Down

0 comments on commit 8236596

Please sign in to comment.