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{
static body = [ MOVE, WORK, CARRY ];
static name = 'Creep';
/** @param {Creep} creep **/
run(creep) { }
static spawn(spawnPoint){
spawnPoint.spawnCreep(this.body, this.name + Game.time,
{memory : {role : this.name}
var body = [ MOVE, WORK, CARRY ];
var name = 'Creep';
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 = roleBase;
module.exports = {body,name,run,spawn};

View file

@ -1,11 +1,8 @@
var energyUtils = require('util_energy');
var roleBase = require('role_base');
class roleBuilder extends roleBase{
/** @param {Creep} creep **/
static name = 'builder';
var name = 'builder';
static run(creep) {
function run(creep) {
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.building = false;
}
@ -25,6 +22,5 @@ class roleBuilder extends roleBase{
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 roleRepairer = require('role_repairer');
var roleGuard = require('role_guard');
var roleBase = require('role_base');
const roleMap = {
harvester: roleHarvester,
@ -23,7 +24,7 @@ var creepCounts = {
function runRole(creep){
const role = roleMap[creep.memory.role];
if(role !== 'undefined'){
if(typeof role.run === 'function'){
role.run(creep);
} else {
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);
if(roleCreeps.length < count && !spawn.spawning) {
if(typeof roleMap[role].spawn === 'function')
roleMap[role].spawn(spawn);
else
roleBase.spawn(spawn, roleMap[role].body, roleMap[role].name);
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{
static body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ];
static name = 'streltsy'
/** @param {Creep} creep **/
static run(creep) {
function run(creep) {
const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(target) {
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')
newWaypoints = ['A','B'];
@ -32,6 +30,5 @@ class roleGuard extends roleBase{
{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 roleBase = require('role_base');
class roleHarvester extends roleBase{
/** @param {Creep} creep **/
var name = 'harvester';
static name = 'harvester';
static run(creep) {
function run(creep) {
if(creep.store.getFreeCapacity() > 0) {
var sources = creep.room.find(FIND_SOURCES);
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 roleBase = require('role_base');
class roleRepairer extends roleBase {
static name = 'repairer';
/** @param {Creep} creep **/
static run(creep) {
var name = 'repairer';
function run(creep) {
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.building = false;
}
@ -31,6 +29,5 @@ class roleRepairer extends roleBase {
energyUtils.gatherEnergy(creep);
}
}
};
module.exports = roleRepairer;
module.exports = {name,run};

View file

@ -1,10 +1,7 @@
var roleBase = require('role_base');
class roleUpgrader extends roleBase {
static name = 'upgrader';
var name = 'upgrader';
/** @param {Creep} creep **/
static run(creep) {
function run(creep) {
if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.upgrading = false;
@ -25,6 +22,5 @@ class roleUpgrader extends roleBase {
}
}
}
};
module.exports = roleUpgrader;
module.exports = {name,run};