General balances, and made number of harvester dynamic to possible harvesting positions
This commit is contained in:
parent
d282f9321c
commit
fd695a82bc
|
@ -5,6 +5,7 @@ var roleRepairer = require('role_repairer');
|
||||||
var roleGuard = require('role_guard');
|
var roleGuard = require('role_guard');
|
||||||
var roleBase = require('role_base');
|
var roleBase = require('role_base');
|
||||||
var roleEqualizer = require('role_equalizer');
|
var roleEqualizer = require('role_equalizer');
|
||||||
|
var utils = require('util_etc');
|
||||||
|
|
||||||
const roleMap = {
|
const roleMap = {
|
||||||
harvester: roleHarvester,
|
harvester: roleHarvester,
|
||||||
|
@ -15,6 +16,20 @@ const roleMap = {
|
||||||
desatilnik: roleEqualizer
|
desatilnik: roleEqualizer
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// calculates how much space there is for creeps next to
|
||||||
|
// energy sources, in order to have the perfect amount
|
||||||
|
function calculateTotalSourceSpace(room){
|
||||||
|
var sources = room.find(FIND_SOURCES);
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
for(const source of sources){
|
||||||
|
count += utils.calculateSourceSpace(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
function calculateCreepCounts(room){
|
function calculateCreepCounts(room){
|
||||||
var creepCounts = {
|
var creepCounts = {
|
||||||
"harvester" : 3,
|
"harvester" : 3,
|
||||||
|
@ -26,7 +41,7 @@ function calculateCreepCounts(room){
|
||||||
};
|
};
|
||||||
|
|
||||||
// 2 harvesters per source by default
|
// 2 harvesters per source by default
|
||||||
creepCounts.harvester = room.find(FIND_SOURCES).length * 2;
|
creepCounts.harvester = calculateTotalSourceSpace(room);
|
||||||
|
|
||||||
if(room.memory.containers == 0){
|
if(room.memory.containers == 0){
|
||||||
|
|
||||||
|
@ -45,6 +60,7 @@ function calculateCreepCounts(room){
|
||||||
|
|
||||||
if(room.memory.extensions >= 3){
|
if(room.memory.extensions >= 3){
|
||||||
creepCounts.builder += 1;
|
creepCounts.builder += 1;
|
||||||
|
creepCounts.upgrader += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(room.memory.containers >= 2){
|
if(room.memory.containers >= 2){
|
||||||
|
@ -68,18 +84,17 @@ function calculateCreepBodies(room){
|
||||||
"desatilnik" : [CARRY, CARRY, CARRY, MOVE, MOVE, MOVE]
|
"desatilnik" : [CARRY, CARRY, CARRY, MOVE, MOVE, MOVE]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 400 cost
|
||||||
|
if(room.memory.extensions >= 2){
|
||||||
|
creepBodies.upgrader = [MOVE, MOVE, WORK, WORK, CARRY, CARRY];
|
||||||
|
creepBodes.builder = [MOVE, MOVE, WORK, WORK, CARRY, CARRY];
|
||||||
|
}
|
||||||
|
|
||||||
// 450 cost
|
// 450 cost
|
||||||
if(room.memory.extensions >= 3){
|
if(room.memory.extensions >= 3){
|
||||||
creepBodies.harvester = [MOVE, MOVE, WORK, WORK, WORK, CARRY];
|
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;
|
room.memory.creepBodies = creepBodies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,11 @@ function run(creep) {
|
||||||
|
|
||||||
var maxContainer = containers[0];
|
var maxContainer = containers[0];
|
||||||
|
|
||||||
containers.forEach((container, index) => {
|
for(const container of containers){
|
||||||
if(container.store[RESOURCE_ENERGY] > maxContainer.store[RESOURCE_ENERGY]){
|
if(container.store[RESOURCE_ENERGY] > maxContainer.store[RESOURCE_ENERGY]){
|
||||||
maxContainer = container;
|
maxContainer = container;
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
if(creep.withdraw(maxContainer, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
if(creep.withdraw(maxContainer, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(maxContainer);
|
creep.moveTo(maxContainer);
|
||||||
|
@ -30,11 +30,11 @@ function run(creep) {
|
||||||
|
|
||||||
var minContainer = containers[0];
|
var minContainer = containers[0];
|
||||||
|
|
||||||
containers.forEach((container, index) => {
|
for(const container of containers){
|
||||||
if(container.store[RESOURCE_ENERGY] < minContainer.store[RESOURCE_ENERGY]){
|
if(container.store[RESOURCE_ENERGY] < minContainer.store[RESOURCE_ENERGY]){
|
||||||
minContainer = container;
|
minContainer = container;
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
if(creep.transfer(minContainer, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
if(creep.transfer(minContainer, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(minContainer);
|
creep.moveTo(minContainer);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
var utils = require('util_etc');
|
||||||
var energyUtils = {
|
var energyUtils = {
|
||||||
|
|
||||||
// get energy from a container (if available) otherwise just mine for it at
|
// get energy from a container (if available) otherwise just mine for it at
|
||||||
|
@ -40,7 +41,7 @@ var energyUtils = {
|
||||||
if(typeof room.memory[sources[0].id] !== 'undefined')
|
if(typeof room.memory[sources[0].id] !== 'undefined')
|
||||||
minSourceCount = room.memory[sources[0].id].length;
|
minSourceCount = room.memory[sources[0].id].length;
|
||||||
|
|
||||||
sources.forEach(function(source){
|
for(const source of sources){
|
||||||
if(typeof room.memory[source.id] === 'undefined')
|
if(typeof room.memory[source.id] === 'undefined')
|
||||||
room.memory[source.id] = [];
|
room.memory[source.id] = [];
|
||||||
|
|
||||||
|
@ -50,11 +51,13 @@ var energyUtils = {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(room.memory[source.id].length < minSourceCount){
|
if(room.memory[source.id].length < minSourceCount
|
||||||
|
&& room.memory[source.id].length < utils.calculateSourceSpace(source)){
|
||||||
|
|
||||||
minSource = source.id;
|
minSource = source.id;
|
||||||
minSourceCount = room.memory[source.id].length;
|
minSourceCount = room.memory[source.id].length;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
room.memory[minSource].push(creep.name);
|
room.memory[minSource].push(creep.name);
|
||||||
creep.memory.assignedSource = minSource;
|
creep.memory.assignedSource = minSource;
|
||||||
|
|
16
util_etc.js
Normal file
16
util_etc.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
function calculateSourceSpace(source){
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
for(let y = -1; y <= 1; y++){
|
||||||
|
for(let x = -1; x <= 1; x++){
|
||||||
|
if(x == 0 && y == 0) continue;
|
||||||
|
for(var object of source.room.lookAt(source.pos.x + x, source.pos.y + y)){
|
||||||
|
if(object.type != 'terrain') continue;
|
||||||
|
if(object.terrain != 'wall') count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { calculateSourceSpace };
|
|
@ -8,12 +8,12 @@ var progressUtils = {
|
||||||
room.memory.containers = 0;
|
room.memory.containers = 0;
|
||||||
room.memory.extensions = 0;
|
room.memory.extensions = 0;
|
||||||
|
|
||||||
structures.forEach(function (structure){
|
for(const structure of structures){
|
||||||
if(structure.structureType == STRUCTURE_CONTAINER) room.memory.containers++;
|
if(structure.structureType == STRUCTURE_CONTAINER) room.memory.containers++;
|
||||||
if(structure.structureType == STRUCTURE_SPAWN) room.memory.spawns++;
|
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