screeps/bodypartbuilder.js

306 lines
14 KiB
JavaScript
Raw Normal View History

2016-09-28 08:37:28 -05:00
let buildparts = {
tick: function(roomname,role) {
2017-06-06 13:17:26 -05:00
console.log(Game.rooms[roomname].memory.tickssincespawn)
2016-09-28 08:37:28 -05:00
console.log(roomname + ":" + role)
let energyready = Game.rooms[roomname].energyAvailable
let energymax = Game.rooms[roomname].energyCapacityAvailable
2017-06-06 13:17:26 -05:00
Game.rooms[roomname].memory.tickssincespawn=0
2016-09-28 08:37:28 -05:00
let tobuild=[]
2017-06-06 13:17:26 -05:00
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
Game.rooms[roomname].memory.CreepNum++
let CreepName = role + "_" + roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
2016-09-28 08:37:28 -05:00
switch(role){
case 'builder':
2017-06-06 13:17:26 -05:00
2016-09-28 08:37:28 -05:00
for(let spawn of myspawns){
2017-06-06 13:17:26 -05:00
if(!spawn.spawning){
2016-09-28 08:37:28 -05:00
for(let totry of [
2017-06-06 13:17:26 -05:00
[MOVE,MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY],
[MOVE,MOVE,MOVE,WORK,WORK,WORK,CARRY,CARRY,CARRY],
[MOVE,MOVE,WORK,WORK,CARRY,CARRY],
[MOVE,WORK,CARRY]
]){
2016-09-28 08:37:28 -05:00
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
2017-06-06 13:17:26 -05:00
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}
}
break;
case 'nrbuilder':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [
[MOVE,MOVE,WORK,WORK,CARRY,CARRY],
[MOVE,WORK,CARRY]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}
2016-09-28 08:37:28 -05:00
}
break;
case 'hauler':
2017-06-06 13:17:26 -05:00
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [
[CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
[CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE],
[CARRY,CARRY,CARRY,CARRY,MOVE,MOVE],
[CARRY,CARRY,MOVE,MOVE],
[CARRY,MOVE]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}
}
break;
case 'hauler3':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [
[CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
[CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE],
[CARRY,CARRY,CARRY,CARRY,MOVE,MOVE],
[CARRY,CARRY,MOVE,MOVE],
[CARRY,MOVE]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}
}
break;
case 'miner':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [
[WORK,WORK,WORK,WORK,WORK,MOVE],
[WORK,WORK,WORK,WORK,MOVE],
[WORK,WORK,WORK,MOVE],
[WORK,WORK,MOVE],
[WORK,MOVE]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}}
break;
case 'miner2':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE],
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE],
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE],
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE],
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE],
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE],
[WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE],
[WORK,WORK,WORK,WORK,WORK,MOVE],
[WORK,WORK,WORK,WORK,MOVE],
[WORK,WORK,WORK,MOVE],
[WORK,WORK,MOVE],
[WORK,MOVE]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}}
break;
case 'nrminer':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [
[WORK,WORK,WORK,WORK,WORK,MOVE],
[WORK,WORK,WORK,WORK,MOVE],
[WORK,WORK,WORK,MOVE],
[WORK,WORK,MOVE],
[WORK,MOVE]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}}
break;
case 'hauler2':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [[CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
[CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE],
[CARRY,CARRY,CARRY,CARRY,MOVE,MOVE],
[CARRY,CARRY,MOVE,MOVE],
[CARRY,MOVE]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}}
break;
case 'towerrecharger':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [[CARRY,CARRY,CARRY,MOVE,MOVE]]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}}
break;
case 'repairbot':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [
[MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY],//RCL3
[WORK,CARRY,MOVE]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}}
break;
case 'upgrader':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
[WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
[WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
[WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
[WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
[WORK,WORK,WORK,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
[MOVE,MOVE,WORK,WORK,WORK,CARRY,CARRY,CARRY],
[MOVE,MOVE,WORK,WORK,CARRY,CARRY],
[MOVE,WORK,CARRY]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}}
break;
case 'warrior':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [
[ATTACK,ATTACK,RANGED_ATTACK,RANGED_ATTACK,MOVE,MOVE],
[ATTACK,ATTACK,RANGED_ATTACK,MOVE]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}}
break;
case 'claimer':
for(let spawn of myspawns){
if(!spawn.spawning){
for(let totry of [
[CLAIM,CLAIM,CLAIM,CLAIM,CLAIM,MOVE,MOVE],
[CLAIM,MOVE]
]){
let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){
tobuild=totry
break;
}
}
console.log(tobuild)
let newcreep = spawn.createCreep(tobuild,CreepName,{role:role})
console.log('Spawning new ' + role + ': ' + newcreep );
}}
break;
2016-09-28 08:37:28 -05:00
default:
2017-06-06 13:17:26 -05:00
console.log('no match')
2016-09-28 08:37:28 -05:00
}
2017-06-06 13:17:26 -05:00
2016-09-28 08:37:28 -05:00
}
};
module.exports = buildparts;