screeps/bodypartbuilder.js

336 lines
16 KiB
JavaScript
Raw Permalink 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
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 [
2020-11-09 19:31:39 -06:00
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],
[MOVE,WORK,CARRY,MOVE,WORK,CARRY],
[MOVE,WORK,CARRY,CARRY]
2017-06-06 13:17:26 -05:00
]){
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 [
2020-11-09 19:31:39 -06:00
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],
[MOVE,WORK,CARRY,MOVE,WORK,CARRY],
2017-06-06 13:17:26 -05:00
[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 [
2020-11-09 19:31:39 -06:00
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE]
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
[CARRY,CARRY,MOVE],
2017-06-06 13:17:26 -05:00
[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){
2020-11-09 19:31:39 -06:00
for(let totry of [
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE]
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
[CARRY,CARRY,MOVE],
2017-06-06 13:17:26 -05:00
[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 [
2020-11-09 19:31:39 -06:00
[WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE]//RCL3
[WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE],
[WORK,CARRY,MOVE,WORK,CARRY,MOVE],
2017-06-06 13:17:26 -05:00
[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 [
2017-07-13 23:24:42 -05:00
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],//RCL8
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],//RCL7
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],//RCL6
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],//RCL5
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],//RCL4
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],//RCL3
[MOVE,WORK,CARRY,MOVE,WORK,CARRY],//RCL2
[MOVE,WORK,CARRY]//RCL1
2017-06-06 13:17:26 -05:00
]){
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
2020-11-30 03:41:26 -06:00
},
designCreep: function(availableCost,arrParts)
{
var bodyPartArray = [];
var arrCosts = [];
for(var i = 0;i<arrParts.length;i++)
{
arrCosts.push(BODYPART_COST[arrParts[i]]);
}
var partCounter = 0;
var currentCost = 0;
while(true)
{
var nextPartType = partCounter%arrParts.length;
partCounter++;
if(currentCost+arrCosts[nextPartType] <= availableCost && partCounter<=50)
{
bodyPartArray.push(arrParts[nextPartType]);currentCost+=arrCosts[nextPartType];
}
else
{
if(bodyPartArray.length<arrParts.length)
{
console.log("Insufficient funds for functional creep");
return [];
}
return bodyPartArray;
}
}
},
2016-09-28 08:37:28 -05:00
};
module.exports = buildparts;