Everything works now, also changed methods to be static in classes, so I don't have to instance them

This commit is contained in:
ObeseTermite 2025-06-04 17:10:41 -07:00
parent 86295d6f0a
commit 4b403bb935
9 changed files with 35 additions and 38 deletions

View file

@ -1,11 +1,9 @@
class roleBase{ class roleBase{
constructor(){ static body = [ MOVE, WORK, CARRY ];
this.body = [ MOVE, WORK, CARRY ]; static name = 'Creep';
this.name = 'Creep';
}
/** @param {Creep} creep **/ /** @param {Creep} creep **/
run(creep) { } run(creep) { }
spawn(spawnPoint){ static spawn(spawnPoint){
spawnPoint.spawnCreep(this.body, this.name + Game.time, spawnPoint.spawnCreep(this.body, this.name + Game.time,
{memory : {role : this.name} {memory : {role : this.name}
}); });

View file

@ -5,9 +5,9 @@ class roleBuilder extends roleBase{
/** @param {Creep} creep **/ /** @param {Creep} creep **/
constructor(){ constructor(){
super() super()
this.name = 'Builder'; this.name = 'builder';
} }
run(creep) { static run(creep) {
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) { if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.building = false; creep.memory.building = false;
} }

View file

@ -23,7 +23,7 @@ var creepCounts = {
function runRole(creep){ function runRole(creep){
const role = roleMap[creep.memory.role]; const role = roleMap[creep.memory.role];
if(role && typeof role.run === 'function'){ if(role !== 'undefined'){
role.run(creep); role.run(creep);
} else { } else {
console.log('Unknown or undefined role: ' + creep.memory.role); console.log('Unknown or undefined role: ' + creep.memory.role);
@ -34,9 +34,7 @@ function spawnCreeps(spawn){
for(const [role, count] of Object.entries(creepCounts)){ for(const [role, count] of Object.entries(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) {
var newName = role + Game.time;
roleMap[role].spawn(spawn); roleMap[role].spawn(spawn);
break; break;
} }

View file

@ -1,12 +1,10 @@
var roleBase = require('role_base'); var roleBase = require('role_base');
class roleGuard extends roleBase{ class roleGuard extends roleBase{
static body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ];
static name = 'streltsy'
/** @param {Creep} creep **/ /** @param {Creep} creep **/
constructor(){ static run(creep) {
this.body = [ MOVE, RANGED_ATTACK ];
this.name = 'Streltsy'
}
run(creep) {
const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS); const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(target) { if(target) {
if(creep.rangedAttack(target) == ERR_NOT_IN_RANGE) { 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, spawnPoint.spawnCreep(this.body, this.name + Game.time,
{memory : {role : this.name, waypoints : newWaypoints} {memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0}
}); });
} }
}; };

View file

@ -3,11 +3,10 @@ var roleBase = require('role_base');
class roleHarvester extends roleBase{ class roleHarvester extends roleBase{
/** @param {Creep} creep **/ /** @param {Creep} creep **/
constructor(){
super(); static name = 'harvester';
this.name = 'Peasant'
} static run(creep) {
run(creep) {
if(creep.store.getFreeCapacity() > 0) { if(creep.store.getFreeCapacity() > 0) {
var sources = creep.room.find(FIND_SOURCES); var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {

View file

@ -2,12 +2,9 @@ var energyUtils = require('util_energy');
var roleBase = require('role_base'); var roleBase = require('role_base');
class roleRepairer extends roleBase { class roleRepairer extends roleBase {
constructor(){ static name = 'repairer';
super();
this.name = 'Repairer';
}
/** @param {Creep} creep **/ /** @param {Creep} creep **/
run(creep) { static run(creep) {
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) { if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.building = false; creep.memory.building = false;
} }

View file

@ -1,13 +1,10 @@
var roleBase = require('role_base'); var roleBase = require('role_base');
class roleUpgrader extends roleBase { class roleUpgrader extends roleBase {
constructor(){ static name = 'upgrader';
super();
this.name = 'Upgrader';
}
/** @param {Creep} creep **/ /** @param {Creep} creep **/
run(creep) { static run(creep) {
if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) { if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.upgrading = false; creep.memory.upgrading = false;

View file

@ -23,15 +23,15 @@ var energyUtils = {
depositEnergy : function(creep) { depositEnergy : function(creep) {
var targets = creep.room.find(FIND_STRUCTURES, { var targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => { filter: (structure) => {
return structure.structureType == STRUCTURE_SPAWN && return (structure.structureType == STRUCTURE_SPAWN ||
structure.store.getUsedCapacity(RESOURCE_ENERGY) < 250; structure.structureType == STRUCTURE_EXTENSION) &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
} }
}); });
if(targets.length == 0){ if(targets.length == 0){
targets = creep.room.find(FIND_STRUCTURES, { targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => { filter: (structure) => {
return (structure.structureType == STRUCTURE_EXTENSION || return (structure.structureType == STRUCTURE_CONTAINER ||
structure.structureType == STRUCTURE_CONTAINER ||
structure.structureType == STRUCTURE_TOWER) && structure.structureType == STRUCTURE_TOWER) &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0; structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
} }
@ -41,8 +41,9 @@ var energyUtils = {
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
} }
return true;
} }
return targets.length > 0; return false;
} }
} }

6
util_progress.js Normal file
View file

@ -0,0 +1,6 @@
var progressUtils = {
checkProgress : function() {
}
}
module.exports = progressUtils;