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 **/ function run(creep) { }
run(creep) { }
static spawn(spawnPoint){ function spawn(spawnPoint, newBody, newName){
spawnPoint.spawnCreep(this.body, this.name + Game.time, if(newBody === 'undefined') newBody = body;
{memory : {role : this.name} if(newName === 'undefined') newName = name;
spawnPoint.spawnCreep(newBody, newName + Game.time,
{memory : {role : newName}
}); });
} }
};
module.exports = roleBase; module.exports = {body,name,run,spawn};

View file

@ -1,11 +1,8 @@
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;
} }
@ -25,6 +22,5 @@ class roleBuilder extends roleBase{
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) {
if(typeof roleMap[role].spawn === 'function')
roleMap[role].spawn(spawn); 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,7 +21,8 @@ class roleGuard extends roleBase{
} }
} }
} }
static spawn(spawnPoint, newWaypoints){
function spawn(spawnPoint, newWaypoints){
if(typeof newWaypoints === 'undefined') if(typeof newWaypoints === 'undefined')
newWaypoints = ['A','B']; newWaypoints = ['A','B'];
@ -32,6 +30,5 @@ class roleGuard extends roleBase{
{memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0} {memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0}
}); });
} }
};
module.exports = roleGuard; module.exports = {body,name,run,spawn};

View file

@ -1,12 +1,8 @@
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) {
static 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) {
@ -19,6 +15,5 @@ class roleHarvester extends roleBase{
} }
} }
} }
};
module.exports = roleHarvester; module.exports = {name,run};

View file

@ -1,10 +1,8 @@
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 **/ function 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;
} }
@ -31,6 +29,5 @@ class roleRepairer extends roleBase {
energyUtils.gatherEnergy(creep); energyUtils.gatherEnergy(creep);
} }
} }
};
module.exports = roleRepairer; module.exports = {name,run};

View file

@ -1,10 +1,7 @@
var roleBase = require('role_base'); var name = 'upgrader';
class roleUpgrader extends roleBase {
static name = 'upgrader';
/** @param {Creep} creep **/ /** @param {Creep} creep **/
static run(creep) { function 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;
@ -25,6 +22,5 @@ class roleUpgrader extends roleBase {
} }
} }
} }
};
module.exports = roleUpgrader; module.exports = {name,run};