Removed classes, as nodejs 10 doesn't support them properly (mega bruh)

This commit is contained in:
ObeseTermite 2025-06-05 11:37:55 -07:00
parent e6d90d43a4
commit 032cad4e24
7 changed files with 119 additions and 132 deletions

View file

@ -1,13 +1,15 @@
class roleBase{ var body = [ MOVE, WORK, CARRY ];
static body = [ MOVE, WORK, CARRY ]; var name = 'Creep';
static name = 'Creep';
/** @param {Creep} creep **/
run(creep) { }
static spawn(spawnPoint){
spawnPoint.spawnCreep(this.body, this.name + Game.time,
{memory : {role : this.name}
});
}
};
module.exports = roleBase; function run(creep) { }
function spawn(spawnPoint, newBody, newName){
if(newBody === 'undefined') newBody = body;
if(newName === 'undefined') newName = name;
spawnPoint.spawnCreep(newBody, newName + Game.time,
{memory : {role : newName}
});
}
module.exports = {body,name,run,spawn};

View file

@ -1,30 +1,26 @@
var energyUtils = require('util_energy'); var energyUtils = require('util_energy');
var roleBase = require('role_base');
class roleBuilder extends roleBase{ var name = 'builder';
/** @param {Creep} creep **/
static name = 'builder';
static run(creep) { function 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;
} }
if(!creep.memory.building && creep.store.getFreeCapacity() == 0) { if(!creep.memory.building && creep.store.getFreeCapacity() == 0) {
creep.memory.building = true; creep.memory.building = true;
} }
if(creep.memory.building) { if(creep.memory.building) {
var targets = creep.room.find(FIND_CONSTRUCTION_SITES); var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
if(targets.length) { if(targets.length) {
if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) { if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
} }
} }
} }
else { else {
energyUtils.gatherEnergy(creep); energyUtils.gatherEnergy(creep);
} }
} }
};
module.exports = roleBuilder; module.exports = {name,run};

View file

@ -3,6 +3,7 @@ var roleUpgrader = require('role_upgrader');
var roleBuilder = require('role_builder'); var roleBuilder = require('role_builder');
var roleRepairer = require('role_repairer'); var roleRepairer = require('role_repairer');
var roleGuard = require('role_guard'); var roleGuard = require('role_guard');
var roleBase = require('role_base');
const roleMap = { const roleMap = {
harvester: roleHarvester, harvester: roleHarvester,
@ -23,7 +24,7 @@ var creepCounts = {
function runRole(creep){ function runRole(creep){
const role = roleMap[creep.memory.role]; const role = roleMap[creep.memory.role];
if(role !== 'undefined'){ if(typeof role.run === 'function'){
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);
@ -35,7 +36,10 @@ function spawnCreeps(spawn){
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) {
roleMap[role].spawn(spawn); if(typeof roleMap[role].spawn === 'function')
roleMap[role].spawn(spawn);
else
roleBase.spawn(spawn, roleMap[role].body, roleMap[role].name);
break; break;
} }
} }

View file

@ -1,10 +1,7 @@
var roleBase = require('role_base'); var body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ];
var name = 'streltsy'
class roleGuard extends roleBase{ function run(creep) {
static body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ];
static name = 'streltsy'
/** @param {Creep} creep **/
static 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) {
@ -24,14 +21,14 @@ class roleGuard extends roleBase{
} }
} }
} }
static spawn(spawnPoint, newWaypoints){
if(typeof newWaypoints === 'undefined')
newWaypoints = ['A','B'];
spawnPoint.spawnCreep(this.body, this.name + Game.time, function spawn(spawnPoint, newWaypoints){
{memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0} if(typeof newWaypoints === 'undefined')
}); newWaypoints = ['A','B'];
}
};
module.exports = roleGuard; spawnPoint.spawnCreep(this.body, this.name + Game.time,
{memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0}
});
}
module.exports = {body,name,run,spawn};

View file

@ -1,24 +1,19 @@
var energyUtils = require('util_energy'); var energyUtils = require('util_energy');
var roleBase = require('role_base');
class roleHarvester extends roleBase{ var name = 'harvester';
/** @param {Creep} creep **/
static name = 'harvester'; function run(creep) {
if(creep.store.getFreeCapacity() > 0) {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
else {
if(!energyUtils.depositEnergy(creep)){
creep.moveTo(Game.flags.IdleArea);
}
}
}
static run(creep) { module.exports = {name,run};
if(creep.store.getFreeCapacity() > 0) {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
else {
if(!energyUtils.depositEnergy(creep)){
creep.moveTo(Game.flags.IdleArea);
}
}
}
};
module.exports = roleHarvester;

View file

@ -1,36 +1,33 @@
var energyUtils = require('util_energy'); var energyUtils = require('util_energy');
var roleBase = require('role_base');
class roleRepairer extends roleBase { var name = 'repairer';
static name = 'repairer';
/** @param {Creep} creep **/
static run(creep) {
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.building = false;
}
if(!creep.memory.building && creep.store.getFreeCapacity() == 0) {
creep.memory.building = true;
}
if(creep.memory.building) { function run(creep) {
var targets = creep.room.find(FIND_STRUCTURES, { if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
filter: (structure) => { creep.memory.building = false;
return structure.hitsMax - structure.hits > 0; }
} if(!creep.memory.building && creep.store.getFreeCapacity() == 0) {
}); creep.memory.building = true;
if(targets.length > 0) { }
if(creep.repair(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
}
}
else{
creep.say("IDLE")
}
}
else {
energyUtils.gatherEnergy(creep);
}
}
};
module.exports = roleRepairer; if(creep.memory.building) {
var targets = creep.room.find(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'}});
}
}
else{
creep.say("IDLE")
}
}
else {
energyUtils.gatherEnergy(creep);
}
}
module.exports = {name,run};

View file

@ -1,30 +1,26 @@
var roleBase = require('role_base'); var name = 'upgrader';
class roleUpgrader extends roleBase { /** @param {Creep} creep **/
static name = 'upgrader'; function run(creep) {
/** @param {Creep} creep **/ if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) {
static run(creep) { creep.memory.upgrading = false;
}
if(!creep.memory.upgrading && creep.store.getFreeCapacity() == 0) {
creep.memory.upgrading = true;
}
if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) { if(creep.memory.upgrading) {
creep.memory.upgrading = false; if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
} creep.moveTo(creep.room.controller, {visualizePathStyle: {stroke: '#ffffff'}});
if(!creep.memory.upgrading && creep.store.getFreeCapacity() == 0) { }
creep.memory.upgrading = true; }
} else {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[1]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[1], {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
}
if(creep.memory.upgrading) { module.exports = {name,run};
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller, {visualizePathStyle: {stroke: '#ffffff'}});
}
}
else {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[1]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[1], {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
}
};
module.exports = roleUpgrader;