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

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,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,
{memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0}
});
}
};
function spawn(spawnPoint, newWaypoints){
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 roleBase = require('role_base');
class roleHarvester extends roleBase{
/** @param {Creep} creep **/
var name = 'harvester';
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) {
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;
module.exports = {name,run};

View file

@ -1,36 +1,33 @@
var energyUtils = require('util_energy');
var roleBase = require('role_base');
class roleRepairer extends roleBase {
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;
}
var name = 'repairer';
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);
}
}
};
function 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;
}
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 {
static name = 'upgrader';
/** @param {Creep} creep **/
function run(creep) {
/** @param {Creep} creep **/
static run(creep) {
if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) {
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) {
creep.memory.upgrading = false;
}
if(!creep.memory.upgrading && creep.store.getFreeCapacity() == 0) {
creep.memory.upgrading = true;
}
if(creep.memory.upgrading) {
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'}});
}
}
}
if(creep.memory.upgrading) {
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;
module.exports = {name,run};