From 4b403bb9354fc03661e4a21ca29e7b24e1f7e94b Mon Sep 17 00:00:00 2001 From: ObeseTermite Date: Wed, 4 Jun 2025 17:10:41 -0700 Subject: [PATCH] Everything works now, also changed methods to be static in classes, so I don't have to instance them --- role_base.js | 8 +++----- role_builder.js | 4 ++-- role_dispatcher.js | 4 +--- role_guard.js | 15 ++++++++------- role_harvester.js | 9 ++++----- role_repairer.js | 7 ++----- role_upgrader.js | 7 ++----- util_energy.js | 13 +++++++------ util_progress.js | 6 ++++++ 9 files changed, 35 insertions(+), 38 deletions(-) create mode 100644 util_progress.js diff --git a/role_base.js b/role_base.js index ddde8e2..aef7de5 100644 --- a/role_base.js +++ b/role_base.js @@ -1,11 +1,9 @@ class roleBase{ - constructor(){ - this.body = [ MOVE, WORK, CARRY ]; - this.name = 'Creep'; - } + static body = [ MOVE, WORK, CARRY ]; + static name = 'Creep'; /** @param {Creep} creep **/ run(creep) { } - spawn(spawnPoint){ + static spawn(spawnPoint){ spawnPoint.spawnCreep(this.body, this.name + Game.time, {memory : {role : this.name} }); diff --git a/role_builder.js b/role_builder.js index b520045..cc8e965 100644 --- a/role_builder.js +++ b/role_builder.js @@ -5,9 +5,9 @@ class roleBuilder extends roleBase{ /** @param {Creep} creep **/ constructor(){ super() - this.name = 'Builder'; + this.name = 'builder'; } - run(creep) { + static run(creep) { if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) { creep.memory.building = false; } diff --git a/role_dispatcher.js b/role_dispatcher.js index c0123c3..bb56376 100644 --- a/role_dispatcher.js +++ b/role_dispatcher.js @@ -23,7 +23,7 @@ var creepCounts = { function runRole(creep){ const role = roleMap[creep.memory.role]; - if(role && typeof role.run === 'function'){ + if(role !== 'undefined'){ role.run(creep); } else { console.log('Unknown or undefined role: ' + creep.memory.role); @@ -33,10 +33,8 @@ function runRole(creep){ function spawnCreeps(spawn){ for(const [role, count] of Object.entries(creepCounts)){ var roleCreeps = _.filter(Game.creeps, (creep) => creep.memory.role == role); - if(roleCreeps.length < count && !spawn.spawning) { - var newName = role + Game.time; roleMap[role].spawn(spawn); break; } diff --git a/role_guard.js b/role_guard.js index 23c0fe1..8cf224c 100644 --- a/role_guard.js +++ b/role_guard.js @@ -1,12 +1,10 @@ var roleBase = require('role_base'); class roleGuard extends roleBase{ + static body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ]; + static name = 'streltsy' /** @param {Creep} creep **/ - constructor(){ - this.body = [ MOVE, RANGED_ATTACK ]; - this.name = 'Streltsy' - } - run(creep) { + static run(creep) { const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS); if(target) { if(creep.rangedAttack(target) == ERR_NOT_IN_RANGE) { @@ -26,9 +24,12 @@ class roleGuard extends roleBase{ } } } - spawn(spawnPoint, newWaypoints){ + static spawn(spawnPoint, newWaypoints){ + if(typeof newWaypoints === 'undefined') + newWaypoints = ['A','B']; + spawnPoint.spawnCreep(this.body, this.name + Game.time, - {memory : {role : this.name, waypoints : newWaypoints} + {memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0} }); } }; diff --git a/role_harvester.js b/role_harvester.js index 48899cd..ba6b30a 100644 --- a/role_harvester.js +++ b/role_harvester.js @@ -3,11 +3,10 @@ var roleBase = require('role_base'); class roleHarvester extends roleBase{ /** @param {Creep} creep **/ - constructor(){ - super(); - this.name = 'Peasant' - } - run(creep) { + + static name = 'harvester'; + + static run(creep) { if(creep.store.getFreeCapacity() > 0) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { diff --git a/role_repairer.js b/role_repairer.js index b35a243..d257501 100644 --- a/role_repairer.js +++ b/role_repairer.js @@ -2,12 +2,9 @@ var energyUtils = require('util_energy'); var roleBase = require('role_base'); class roleRepairer extends roleBase { - constructor(){ - super(); - this.name = 'Repairer'; - } + static name = 'repairer'; /** @param {Creep} creep **/ - run(creep) { + static run(creep) { if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) { creep.memory.building = false; } diff --git a/role_upgrader.js b/role_upgrader.js index 6855167..efb53d7 100644 --- a/role_upgrader.js +++ b/role_upgrader.js @@ -1,13 +1,10 @@ var roleBase = require('role_base'); class roleUpgrader extends roleBase { - constructor(){ - super(); - this.name = 'Upgrader'; - } + static name = 'upgrader'; /** @param {Creep} creep **/ - run(creep) { + static run(creep) { if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) { creep.memory.upgrading = false; diff --git a/util_energy.js b/util_energy.js index 6e367ae..32a89c8 100644 --- a/util_energy.js +++ b/util_energy.js @@ -23,15 +23,15 @@ var energyUtils = { depositEnergy : function(creep) { var targets = creep.room.find(FIND_STRUCTURES, { filter: (structure) => { - return structure.structureType == STRUCTURE_SPAWN && - structure.store.getUsedCapacity(RESOURCE_ENERGY) < 250; + 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, { filter: (structure) => { - return (structure.structureType == STRUCTURE_EXTENSION || - structure.structureType == STRUCTURE_CONTAINER || + return (structure.structureType == STRUCTURE_CONTAINER || structure.structureType == STRUCTURE_TOWER) && structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0; } @@ -41,9 +41,10 @@ var energyUtils = { if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); } + return true; } - return targets.length > 0; + return false; } } -module.exports = energyUtils; \ No newline at end of file +module.exports = energyUtils; diff --git a/util_progress.js b/util_progress.js new file mode 100644 index 0000000..87712f0 --- /dev/null +++ b/util_progress.js @@ -0,0 +1,6 @@ +var progressUtils = { + checkProgress : function() { + } +} + +module.exports = progressUtils;