Finished migration to class based system

This commit is contained in:
ObeseTermite 2025-06-04 12:59:46 -07:00
parent b5dfb44faf
commit 7c22f99bf9
9 changed files with 47 additions and 47 deletions

View file

@ -1,5 +1,4 @@
var roleDispatcher = require('role.dispatcher'); var roleDispatcher = require('role/dispatcher');
module.exports.loop = function () { module.exports.loop = function () {

View file

@ -5,9 +5,9 @@ class roleBase{
} }
/** @param {Creep} creep **/ /** @param {Creep} creep **/
run(creep) { } run(creep) { }
spawn(spawn){ spawn(spawnPoint){
spawn.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

@ -1,15 +1,13 @@
var energyUtils = require('utils.energy'); var energyUtils = require('../utils/energy');
var roleBase = require('base');
const body = [
WORK, CARRY, MOVE
];
var roleBuilder = {
body,
class roleBuilder extends roleBase{
/** @param {Creep} creep **/ /** @param {Creep} creep **/
run: function(creep) { constructor(){
super()
this.name = 'Builder';
}
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,12 +1,12 @@
var energyUtils = require('utils.energy'); var roleBase = require('base');
const body = [ class roleGuard extends roleBase{
MOVE, RANGED_ATTACK
];
var roleGuard = {
/** @param {Creep} creep **/ /** @param {Creep} creep **/
run: function(creep) { constructor(){
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,6 +26,11 @@ var roleGuard = {
} }
} }
} }
spawn(spawnPoint, newWaypoints){
spawnPoint.spawnCreep(this.body, this.name + Game.time,
{memory : {role : this.name, waypoints : newWaypoints}
});
}
}; };
module.exports = roleGuard; module.exports = roleGuard;

View file

@ -1,14 +1,13 @@
var energyUtils = require('utils.energy'); var energyUtils = require('../utils/energy');
var roleBase = require('base');
const body = [
WORK, CARRY, MOVE
];
var roleHarvester = {
body,
class roleHarvester extends roleBase{
/** @param {Creep} creep **/ /** @param {Creep} creep **/
run: function(creep) { constructor(){
super();
this.name = 'Peasant'
}
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

@ -1,15 +1,13 @@
var energyUtils = require('utils.energy'); var energyUtils = require('../utils/energy');
var roleBase = require('base');
const body = [
WORK, CARRY, MOVE
];
var roleRepairer = {
body,
class roleRepairer extends roleBase {
constructor(){
super();
this.name = 'Repairer';
}
/** @param {Creep} creep **/ /** @param {Creep} creep **/
run: function(creep) { 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,12 +1,13 @@
const body = [ var roleBase = require('base');
WORK, CARRY, MOVE
];
var roleUpgrader = { class roleUpgrader extends roleBase {
body, constructor(){
super();
this.name = 'Upgrader';
}
/** @param {Creep} creep **/ /** @param {Creep} creep **/
run: function(creep) { 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;