Added progress and shit idk
This commit is contained in:
parent
d5956ede22
commit
18b293c86b
10
role_base.js
10
role_base.js
|
@ -1,14 +1,14 @@
|
||||||
var body = [ MOVE, WORK, CARRY ];
|
|
||||||
var name = 'Creep';
|
var name = 'Creep';
|
||||||
|
|
||||||
function run(creep) { }
|
function run(creep) { }
|
||||||
|
|
||||||
function spawn(spawnPoint, newBody, newName){
|
function spawn(spawnPoint, newName){
|
||||||
if(typeof newBody === 'undefined') newBody = body;
|
var newBody = spawnPoint.room.memory.creepBodies[newName];
|
||||||
if(typeof newName === 'undefined') newName = name;
|
if(typeof newName === 'undefined') newName = name;
|
||||||
spawnPoint.spawnCreep(newBody, newName + Game.time,
|
|
||||||
|
spawnPoint.spawnCreep(newBody, newName + spawnPoint.room.name + "-" + Game.time,
|
||||||
{memory : {role : newName}
|
{memory : {role : newName}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {body,name,run,spawn};
|
module.exports = {name,run,spawn};
|
||||||
|
|
|
@ -14,7 +14,7 @@ function run(creep) {
|
||||||
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
|
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
|
||||||
if(targets.length) {
|
if(targets.length) {
|
||||||
if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
|
if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
|
creep.moveTo(targets[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,67 @@ const roleMap = {
|
||||||
streltsy: roleGuard
|
streltsy: roleGuard
|
||||||
};
|
};
|
||||||
|
|
||||||
var creepCounts = {
|
function calculateCreepCounts(room){
|
||||||
|
var creepCounts = {
|
||||||
"harvester" : 3,
|
"harvester" : 3,
|
||||||
"builder" : 2,
|
"builder" : 1,
|
||||||
"upgrader" : 2,
|
"upgrader" : 1,
|
||||||
"repairer" : 1,
|
"repairer" : 1,
|
||||||
"streltsy" : 2
|
"streltsy" : 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 2 harvesters per source by default
|
||||||
|
creepCounts.harvester = room.find(FIND_SOURCES).length * 2;
|
||||||
|
|
||||||
|
if(room.memory.containers == 0){
|
||||||
|
|
||||||
|
// -1 harvester until at least a container built in order
|
||||||
|
// to reduce congestion
|
||||||
|
creepCounts.harvester -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// streltsy cost 400 energy, and thus cant be built
|
||||||
|
// you have at least 2 extensions (300+50+50)
|
||||||
|
// i guess there wouldnt be a big difference since
|
||||||
|
// they wouldnt spawn anyways, but whatever
|
||||||
|
if(room.memory.extensions >= 2){
|
||||||
|
creepCounts.streltsy += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(room.memory.extensions >= 3){
|
||||||
|
creepCounts.builder += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
room.memory.creepCounts = creepCounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateCreepBodies(room){
|
||||||
|
var creepBodies = {
|
||||||
|
// 200 base cost
|
||||||
|
"harvester" : [WORK, CARRY, MOVE],
|
||||||
|
"builder" : [WORK, CARRY, MOVE],
|
||||||
|
"upgrader" : [WORK, CARRY, MOVE],
|
||||||
|
"repairer" : [WORK, CARRY, MOVE],
|
||||||
|
|
||||||
|
// 400 base cost
|
||||||
|
"streltsy" : [MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK]
|
||||||
|
};
|
||||||
|
|
||||||
|
// 450 cost
|
||||||
|
if(room.memory.extensions >= 3){
|
||||||
|
creepBodies.harvester = [MOVE, MOVE, WORK, WORK, WORK, CARRY];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 400 cost
|
||||||
|
// but only want the upgrading to scale up when have a bunch
|
||||||
|
// of extra energy
|
||||||
|
if(room.memory.extensions >= 10){
|
||||||
|
creepBodies.upgrader = [MOVE, MOVE, WORK, WORK, CARRY, CARRY];
|
||||||
|
}
|
||||||
|
|
||||||
|
room.memory.creepBodies = creepBodies;
|
||||||
|
}
|
||||||
|
|
||||||
function runRole(creep){
|
function runRole(creep){
|
||||||
const role = roleMap[creep.memory.role];
|
const role = roleMap[creep.memory.role];
|
||||||
|
@ -32,17 +86,19 @@ function runRole(creep){
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawnCreeps(spawn){
|
function spawnCreeps(spawn){
|
||||||
for(const [role, count] of Object.entries(creepCounts)){
|
calculateCreepCounts(spawn.room);
|
||||||
|
for(const [role, count] of Object.entries(spawn.room.memory.creepCounts)){
|
||||||
var roleCreeps = _.filter(Game.creeps, (creep) => creep.memory.role == role);
|
var roleCreeps = _.filter(Game.creeps, (creep) => creep.memory.role == role);
|
||||||
|
|
||||||
if(roleCreeps.length < count && !spawn.spawning) {
|
if(roleCreeps.length < count && !spawn.spawning) {
|
||||||
|
calculateCreepBodies(spawn.room);
|
||||||
if(typeof roleMap[role].spawn === 'function')
|
if(typeof roleMap[role].spawn === 'function')
|
||||||
roleMap[role].spawn(spawn);
|
roleMap[role].spawn(spawn);
|
||||||
else
|
else
|
||||||
roleBase.spawn(spawn, roleMap[role].body, roleMap[role].name);
|
roleBase.spawn(spawn, roleMap[role].name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { runRole, spawnCreeps, creepCounts};
|
module.exports = { runRole, spawnCreeps};
|
||||||
|
|
27
role_equalizer.js
Normal file
27
role_equalizer.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
var energyUtils = require('util_energy');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
|
var name = 'desatilnik';
|
||||||
|
|
||||||
|
function run(creep) {
|
||||||
|
if(creep.room.memory.containers == 0) return;
|
||||||
|
|
||||||
|
if(creep.store.getFreeCapacity() > 0 ){
|
||||||
|
var containers = creep.room.find(FIND_STRUCTURES, {
|
||||||
|
filter : { structureType: STRUCTURE_CONTAINER}
|
||||||
|
});
|
||||||
|
|
||||||
|
var maxContainer = containers[0];
|
||||||
|
|
||||||
|
containers.forEach((container, index) => {
|
||||||
|
if(container.store[RESOURCE_ENERGY] > maxContainer.store[RESOURCE_ENERGY]){
|
||||||
|
maxContainer = container;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {name,run};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
var body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ];
|
|
||||||
var name = 'streltsy'
|
var name = 'streltsy'
|
||||||
|
|
||||||
function run(creep) {
|
function run(creep) {
|
||||||
|
@ -23,12 +22,13 @@ function run(creep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawn(spawnPoint, newWaypoints){
|
function spawn(spawnPoint, newWaypoints){
|
||||||
|
var newBody = spawnPoint.room.memory.creepBodies[name];
|
||||||
if(typeof newWaypoints === 'undefined')
|
if(typeof newWaypoints === 'undefined')
|
||||||
newWaypoints = ['A','B'];
|
newWaypoints = ['A','B'];
|
||||||
|
|
||||||
spawnPoint.spawnCreep(this.body, this.name + Game.time,
|
spawnPoint.spawnCreep(newBody, this.name + spawnPoint.room.name + "-" + Game.time,
|
||||||
{memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0}
|
{memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {body,name,run,spawn};
|
module.exports = {name,run,spawn};
|
||||||
|
|
|
@ -8,7 +8,7 @@ function run(creep) {
|
||||||
var source = Game.getObjectById(creep.memory.assignedSource);
|
var source = Game.getObjectById(creep.memory.assignedSource);
|
||||||
|
|
||||||
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(source, {visualizePathStyle: {stroke: '#ffaa00'}});
|
creep.moveTo(source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
var energyUtils = require('util_energy');
|
||||||
var name = 'upgrader';
|
var name = 'upgrader';
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
/** @param {Creep} creep **/
|
||||||
|
@ -16,10 +17,7 @@ function run(creep) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var sources = creep.room.find(FIND_SOURCES);
|
energyUtils.gatherEnergy(creep);
|
||||||
if(creep.harvest(sources[1]) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(sources[1], {visualizePathStyle: {stroke: '#ffaa00'}});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
var energyUtils = {
|
var energyUtils = {
|
||||||
|
|
||||||
|
// get energy from a container (if available) otherwise just mine for it at
|
||||||
|
// an energy source
|
||||||
gatherEnergy : function(creep) {
|
gatherEnergy : function(creep) {
|
||||||
let storage;
|
let storage;
|
||||||
if(creep.room.memory.hasContainer){
|
if(creep.room.memory.containers > 0){
|
||||||
storage = creep.room.find(FIND_STRUCTURES, {
|
storage = creep.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return (structure.structureType == STRUCTURE_CONTAINER) &&
|
return (structure.structureType == STRUCTURE_CONTAINER) &&
|
||||||
|
@ -13,7 +16,7 @@ var energyUtils = {
|
||||||
if(typeof creep.memory.assignedSource === 'undefined') energyUtils.sourceDelegate(creep);
|
if(typeof creep.memory.assignedSource === 'undefined') energyUtils.sourceDelegate(creep);
|
||||||
let source = Game.getObjectById(creep.memory.assignedSource);
|
let source = Game.getObjectById(creep.memory.assignedSource);
|
||||||
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(source, {visualizePathStyle: {stroke: '#ffaa00'}});
|
creep.moveTo(source);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -21,9 +24,11 @@ var energyUtils = {
|
||||||
if(storage.length == 0) return;
|
if(storage.length == 0) return;
|
||||||
|
|
||||||
if(creep.withdraw(storage[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
if(creep.withdraw(storage[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(storage[0], {visualizePathStyle: {stroke: '#ffaa00'}});
|
creep.moveTo(storage[0]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//assign a creep to source in the room the creep is in
|
||||||
sourceDelegate : function(creep){
|
sourceDelegate : function(creep){
|
||||||
const room = creep.room;
|
const room = creep.room;
|
||||||
|
|
||||||
|
@ -54,28 +59,29 @@ var energyUtils = {
|
||||||
room.memory[minSource].push(creep.name);
|
room.memory[minSource].push(creep.name);
|
||||||
creep.memory.assignedSource = minSource;
|
creep.memory.assignedSource = minSource;
|
||||||
|
|
||||||
}
|
},
|
||||||
,
|
|
||||||
|
// put energy into storage, first if possible into a spawner / extension
|
||||||
|
// otherwise put it into a container
|
||||||
depositEnergy : function(creep) {
|
depositEnergy : function(creep) {
|
||||||
var targets = creep.room.find(FIND_STRUCTURES, {
|
var target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return (structure.structureType == STRUCTURE_SPAWN ||
|
return (structure.structureType == STRUCTURE_SPAWN ||
|
||||||
structure.structureType == STRUCTURE_EXTENSION) &&
|
structure.structureType == STRUCTURE_EXTENSION) &&
|
||||||
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(targets.length == 0){
|
if(target == null){
|
||||||
targets = creep.room.find(FIND_STRUCTURES, {
|
target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return (structure.structureType == STRUCTURE_CONTAINER ||
|
return (structure.structureType == STRUCTURE_CONTAINER) &&
|
||||||
structure.structureType == STRUCTURE_TOWER) &&
|
|
||||||
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(targets.length > 0) {
|
if(target != null) {
|
||||||
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
if(creep.transfer(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
|
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,14 @@ var progressUtils = {
|
||||||
|
|
||||||
for(var roomName in Game.rooms){
|
for(var roomName in Game.rooms){
|
||||||
const room = Game.rooms[roomName];
|
const room = Game.rooms[roomName];
|
||||||
const structures = room.find(FIND_MY_STRUCTURES);
|
const structures = room.find(FIND_STRUCTURES);
|
||||||
room.memory.hasContainer = false;
|
room.memory.spawns = 0;
|
||||||
room.memory.hasSpawn = false;
|
room.memory.containers = 0;
|
||||||
room.memory.extensions = 0;
|
room.memory.extensions = 0;
|
||||||
|
|
||||||
structures.forEach(function (structure){
|
structures.forEach(function (structure){
|
||||||
if(structure.structureType == STRUCTURE_CONTAINER) room.memory.hasContainer = true;
|
if(structure.structureType == STRUCTURE_CONTAINER) room.memory.containers++;
|
||||||
if(structure.structureType == STRUCTURE_SPAWN) room.memory.hasSpawn = true;
|
if(structure.structureType == STRUCTURE_SPAWN) room.memory.spawns++;
|
||||||
|
|
||||||
if(structure.structureType == STRUCTURE_EXTENSION) room.memory.extensions++;
|
if(structure.structureType == STRUCTURE_EXTENSION) room.memory.extensions++;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue