screeps/Empire.js

133 lines
5.4 KiB
JavaScript
Raw Normal View History

2020-11-09 19:31:39 -06:00
//let buildparts=require('bodypartbuilder')
2017-06-06 13:17:26 -05:00
module.exports = {
get getcounts(){
2020-11-09 19:31:39 -06:00
for(let room of _.filter(Game.rooms, 'controller.my')) {
roomcounts = _.countBy(room.find(FIND_MY_CREEPS), c => c.memory.role)
console.log(roomcounts['phase1worker'])
console.log(roomcounts['miner'])
}
2017-06-06 13:17:26 -05:00
},
decrease: function(role,roomname){
let rolename = 'max' + role + 's'
let currentmax = Game.rooms[roomname].memory[rolename]
Game.rooms[roomname].memory[rolename]--
let newmax = Game.rooms[roomname].memory[rolename]
return 'Old Max:'+currentmax+' New Max:'+newmax
},
2017-07-13 23:24:42 -05:00
setmax: function(role,roomname,count){
let rolename = 'max' + role + 's'
let currentmax = Game.rooms[roomname].memory[rolename]
Game.rooms[roomname].memory[rolename] = count
let newmax = Game.rooms[roomname].memory[rolename]
return 'Old Max:'+currentmax+' New Max:'+newmax
},
2017-06-06 13:17:26 -05:00
increase: function(role,roomname){
let rolename = 'max' + role + 's'
let currentmax = Game.rooms[roomname].memory[rolename]
Game.rooms[roomname].memory[rolename]++
let newmax = Game.rooms[roomname].memory[rolename]
return 'Old Max:'+currentmax+' New Max:'+newmax
},
kill: function(creepname){
let me= Game.creeps[creepname].suicide()
return me
},
2020-11-09 19:31:39 -06:00
spawnwarrior: function(){
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name
require('proc.spawning').spawnwarrior(name)
}
return 'Spawning initiated'
},
spawnnrworker: function(){
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name
require('proc.spawning').spawnnrworker(name)
}
return 'Spawning initiated'
},
spawnworker: function(){
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name
require('proc.spawning').spawnworker(name)
}
return 'Spawning initiated'
},
2020-11-14 01:18:05 -06:00
spawnminer: function(){
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name
2022-05-06 16:48:12 -05:00
require('proc.spawning').spawnsourceminer(name)
}
return 'Spawning initiated'
},
spawnmover: function(){
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name
require('proc.spawning').spawnmover(name)
2020-11-14 01:18:05 -06:00
}
return 'Spawning initiated'
},
2020-11-09 19:31:39 -06:00
spawnclaimer: function(){
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name
require('proc.spawning').spawnclaimer(name)
}
2017-06-06 13:17:26 -05:00
return 'Spawning initiated'
},
removeConstruction: function(roomname){
_.invoke(Game.rooms[roomname].find(FIND_MY_CONSTRUCTION_SITES), 'remove')
},
2020-11-09 19:31:39 -06:00
removeAllConstruction: function(){
_.invoke(_.map(Game.constructionSites, (x)=>x), 'remove')
},
2017-06-06 13:17:26 -05:00
removeWalls: function(roomname){
Game.rooms[roomname].find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_WALL}).forEach(s => s.destroy())
2020-11-09 19:31:39 -06:00
},
removeRoads: function(roomname,hitsleft){
Game.rooms[roomname].find(FIND_STRUCTURES, {filter: s => (s.structureType === STRUCTURE_ROAD && s.hits < hitsleft)}).forEach(s => s.destroy())
return "done"
},
sellEnergy: function(roomname){
let myorders = Game.market.getAllOrders(order=>order.resourceType == RESOURCE_ENERGY && order.type == ORDER_SELL)
2020-11-14 02:14:51 -06:00
},
computeSourceAccess: function(){
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name
let minablepositions = 0
let srcs = Game.rooms[name].find(FIND_SOURCES);
for(let i = 0;i<srcs.length;i++)
{
minablepositions = minablepositions + this.computeSourceAccessPoints(Game.rooms[name],srcs[i])
//minablepositions = minablepositions + this.checkminablepositions(srcs[i])
}
Game.rooms[name].memory.minablepositions = minablepositions
}
},
computeMineralAccess: function(){
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name
let mineralminablepositions = 0
let minerals = Game.rooms[name].find(FIND_MINERALS);
for(let i = 0;i<minerals.length;i++)
{
mineralminablepositions = mineralminablepositions + this.computeSourceAccessPoints(Game.rooms[name],minerals[i])
//minablepositions = minablepositions + this.checkminablepositions(srcs[i])
}
//todo - create array of minable positions in the room and assign a screep to them, rather than having them constantly try to find the nearest one.
Game.rooms[name].memory.mineralminablepositions = mineralminablepositions
}
},
2020-11-14 02:14:51 -06:00
computeSourceAccessPoints: function(room, source){
const roomTerrain = room.getTerrain();
var accessPoints = 0;
for(var x = -1;x<=1;x++)
{
for(var y = -1;y<=1;y++)
{
if(x==0 && y==0){continue;}
if(roomTerrain.get(source.pos.x+x,source.pos.y+y)!=1){accessPoints++;}
}
}
return accessPoints;
2017-06-06 13:17:26 -05:00
}
};