Improved early game speed, and properly added the equalizer in. Started work on auto build

This commit is contained in:
ObeseTermite 2025-06-10 08:43:01 -07:00
parent 18b293c86b
commit 840fc18041
7 changed files with 80 additions and 16 deletions

View file

@ -11,10 +11,10 @@ function run(creep) {
}
if(creep.memory.building) {
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
if(targets.length) {
if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
var target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
if(target != null) {
if(creep.build(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
}

View file

@ -4,13 +4,15 @@ var roleBuilder = require('role_builder');
var roleRepairer = require('role_repairer');
var roleGuard = require('role_guard');
var roleBase = require('role_base');
var roleEqualizer = require('role_equalizer');
const roleMap = {
harvester: roleHarvester,
upgrader: roleUpgrader,
builder: roleBuilder,
repairer: roleRepairer,
streltsy: roleGuard
streltsy: roleGuard,
desatilnik: roleEqualizer
};
function calculateCreepCounts(room){
@ -19,7 +21,8 @@ function calculateCreepCounts(room){
"builder" : 1,
"upgrader" : 1,
"repairer" : 1,
"streltsy" : 0
"streltsy" : 0,
"desatilnik" : 0
};
// 2 harvesters per source by default
@ -44,6 +47,10 @@ function calculateCreepCounts(room){
creepCounts.builder += 1;
}
if(room.memory.containers >= 2){
creepCounts.desatilnik += 1;
}
room.memory.creepCounts = creepCounts;
}
@ -57,7 +64,8 @@ function calculateCreepBodies(room){
"repairer" : [WORK, CARRY, MOVE],
// 400 base cost
"streltsy" : [MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK]
"streltsy" : [MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK],
"desatilnik" : [CARRY, CARRY, CARRY, MOVE, MOVE, MOVE]
};
// 450 cost

View file

@ -18,8 +18,27 @@ function run(creep) {
maxContainer = container;
}
});
if(creep.withdraw(maxContainer, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(maxContainer);
}
}
else{
var containers = creep.room.find(FIND_STRUCTURES, {
filter : { structureType: STRUCTURE_CONTAINER}
});
var minContainer = containers[0];
containers.forEach((container, index) => {
if(container.store[RESOURCE_ENERGY] < minContainer.store[RESOURCE_ENERGY]){
minContainer = container;
}
});
if(creep.withdraw(minContainer, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(minContainer);
}
}
}

View file

@ -3,7 +3,14 @@ var energyUtils = require('util_energy');
var name = 'harvester';
function run(creep) {
if(creep.store.getFreeCapacity() > 0) {
if(!creep.memory.harvesting && creep.store[RESOURCE_ENERGY] == 0){
creep.memory.harvesting = true;
}
if(creep.memory.harvesting && creep.store.getFreeCapacity() == 0){
creep.memory.harvesting = false;
}
if(creep.memory.harvesting) {
if(typeof creep.memory.assignedSource === 'undefined') energyUtils.sourceDelegate(creep);
var source = Game.getObjectById(creep.memory.assignedSource);

View file

@ -11,14 +11,14 @@ function run(creep) {
}
if(creep.memory.building) {
var targets = creep.room.find(FIND_STRUCTURES, {
var target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => {
return structure.hitsMax - structure.hits > 0;
}
});
if(targets.length > 0) {
if(creep.repair(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
if(target != null) {
if(creep.repair(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
}
}
else{

18
util_autobuild.js Normal file
View file

@ -0,0 +1,18 @@
function determineNextBlueprint(room){
return STRUCTURE_EXTENSION;
}
function addBlueprint(room){
let foundPosition = false;
let spawn = room.find(FIND_MY_SPAWNS);
let position = spawn.pos;
let spiralOffset = 1;
while(!foundPosition){
position.y -= spiralOffset++;
position.x -= spiralOffset++;
position.y += spiralOffset++;
position.x += spiralOffset++;
}
}
module.exports = { addBlueprint }

View file

@ -5,7 +5,7 @@ var energyUtils = {
gatherEnergy : function(creep) {
let storage;
if(creep.room.memory.containers > 0){
storage = creep.room.find(FIND_STRUCTURES, {
storage = creep.room.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_CONTAINER) &&
structure.store.getUsedCapacity(RESOURCE_ENERGY) > 0;
@ -21,10 +21,10 @@ var energyUtils = {
return;
}
if(storage.length == 0) return;
if(storage == null) return;
if(creep.withdraw(storage[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(storage[0]);
if(creep.withdraw(storage, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(storage);
}
},
@ -85,6 +85,18 @@ var energyUtils = {
}
return true;
}
// if no storage anywhere, then just build something
// in order to speed up early game, since no storage
if(creep.room.memory.containers == 0){
target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
if(target != null){
if(creep.build(target) == ERR_NOT_IN_RANGE){
creep.moveTo(target);
}
return true;
}
}
return false;
}
}