Added progress and shit idk

This commit is contained in:
ObeseTermite 2025-06-07 13:48:30 -07:00
parent d5956ede22
commit 18b293c86b
9 changed files with 129 additions and 42 deletions

View file

@ -1,14 +1,14 @@
var body = [ MOVE, WORK, CARRY ];
var name = 'Creep';
function run(creep) { }
function spawn(spawnPoint, newBody, newName){
if(typeof newBody === 'undefined') newBody = body;
function spawn(spawnPoint, newName){
var newBody = spawnPoint.room.memory.creepBodies[newName];
if(typeof newName === 'undefined') newName = name;
spawnPoint.spawnCreep(newBody, newName + Game.time,
spawnPoint.spawnCreep(newBody, newName + spawnPoint.room.name + "-" + Game.time,
{memory : {role : newName}
});
}
module.exports = {body,name,run,spawn};
module.exports = {name,run,spawn};

View file

@ -14,7 +14,7 @@ function run(creep) {
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
if(targets.length) {
if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
creep.moveTo(targets[0]);
}
}
}

View file

@ -13,13 +13,67 @@ const roleMap = {
streltsy: roleGuard
};
var creepCounts = {
function calculateCreepCounts(room){
var creepCounts = {
"harvester" : 3,
"builder" : 2,
"upgrader" : 2,
"builder" : 1,
"upgrader" : 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){
const role = roleMap[creep.memory.role];
@ -32,17 +86,19 @@ function runRole(creep){
}
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);
if(roleCreeps.length < count && !spawn.spawning) {
calculateCreepBodies(spawn.room);
if(typeof roleMap[role].spawn === 'function')
roleMap[role].spawn(spawn);
else
roleBase.spawn(spawn, roleMap[role].body, roleMap[role].name);
roleBase.spawn(spawn, roleMap[role].name);
break;
}
}
}
module.exports = { runRole, spawnCreeps, creepCounts};
module.exports = { runRole, spawnCreeps};

27
role_equalizer.js Normal file
View 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};

View file

@ -1,4 +1,3 @@
var body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ];
var name = 'streltsy'
function run(creep) {
@ -23,12 +22,13 @@ function run(creep) {
}
function spawn(spawnPoint, newWaypoints){
var newBody = spawnPoint.room.memory.creepBodies[name];
if(typeof newWaypoints === 'undefined')
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}
});
}
module.exports = {body,name,run,spawn};
module.exports = {name,run,spawn};

View file

@ -8,7 +8,7 @@ function run(creep) {
var source = Game.getObjectById(creep.memory.assignedSource);
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
creep.moveTo(source, {visualizePathStyle: {stroke: '#ffaa00'}});
creep.moveTo(source);
}
}
else {

View file

@ -1,3 +1,4 @@
var energyUtils = require('util_energy');
var name = 'upgrader';
/** @param {Creep} creep **/
@ -16,10 +17,7 @@ function run(creep) {
}
}
else {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[1]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[1], {visualizePathStyle: {stroke: '#ffaa00'}});
}
energyUtils.gatherEnergy(creep);
}
}

View file

@ -1,7 +1,10 @@
var energyUtils = {
// get energy from a container (if available) otherwise just mine for it at
// an energy source
gatherEnergy : function(creep) {
let storage;
if(creep.room.memory.hasContainer){
if(creep.room.memory.containers > 0){
storage = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_CONTAINER) &&
@ -13,7 +16,7 @@ var energyUtils = {
if(typeof creep.memory.assignedSource === 'undefined') energyUtils.sourceDelegate(creep);
let source = Game.getObjectById(creep.memory.assignedSource);
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
creep.moveTo(source, {visualizePathStyle: {stroke: '#ffaa00'}});
creep.moveTo(source);
}
return;
}
@ -21,9 +24,11 @@ var energyUtils = {
if(storage.length == 0) return;
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){
const room = creep.room;
@ -54,28 +59,29 @@ var energyUtils = {
room.memory[minSource].push(creep.name);
creep.memory.assignedSource = minSource;
}
,
},
// put energy into storage, first if possible into a spawner / extension
// otherwise put it into a container
depositEnergy : function(creep) {
var targets = creep.room.find(FIND_STRUCTURES, {
var target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_SPAWN ||
structure.structureType == STRUCTURE_EXTENSION) &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
}
});
if(targets.length == 0){
targets = creep.room.find(FIND_STRUCTURES, {
if(target == null){
target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_CONTAINER ||
structure.structureType == STRUCTURE_TOWER) &&
return (structure.structureType == STRUCTURE_CONTAINER) &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
}
});
}
if(targets.length > 0) {
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
if(target != null) {
if(creep.transfer(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
}
return true;
}

View file

@ -3,14 +3,14 @@ var progressUtils = {
for(var roomName in Game.rooms){
const room = Game.rooms[roomName];
const structures = room.find(FIND_MY_STRUCTURES);
room.memory.hasContainer = false;
room.memory.hasSpawn = false;
const structures = room.find(FIND_STRUCTURES);
room.memory.spawns = 0;
room.memory.containers = 0;
room.memory.extensions = 0;
structures.forEach(function (structure){
if(structure.structureType == STRUCTURE_CONTAINER) room.memory.hasContainer = true;
if(structure.structureType == STRUCTURE_SPAWN) room.memory.hasSpawn = true;
if(structure.structureType == STRUCTURE_CONTAINER) room.memory.containers++;
if(structure.structureType == STRUCTURE_SPAWN) room.memory.spawns++;
if(structure.structureType == STRUCTURE_EXTENSION) room.memory.extensions++;
});