Everything works now, also changed methods to be static in classes, so I don't have to instance them
This commit is contained in:
parent
86295d6f0a
commit
4b403bb935
|
@ -1,11 +1,9 @@
|
|||
class roleBase{
|
||||
constructor(){
|
||||
this.body = [ MOVE, WORK, CARRY ];
|
||||
this.name = 'Creep';
|
||||
}
|
||||
static body = [ MOVE, WORK, CARRY ];
|
||||
static name = 'Creep';
|
||||
/** @param {Creep} creep **/
|
||||
run(creep) { }
|
||||
spawn(spawnPoint){
|
||||
static spawn(spawnPoint){
|
||||
spawnPoint.spawnCreep(this.body, this.name + Game.time,
|
||||
{memory : {role : this.name}
|
||||
});
|
||||
|
|
|
@ -5,9 +5,9 @@ class roleBuilder extends roleBase{
|
|||
/** @param {Creep} creep **/
|
||||
constructor(){
|
||||
super()
|
||||
this.name = 'Builder';
|
||||
this.name = 'builder';
|
||||
}
|
||||
run(creep) {
|
||||
static run(creep) {
|
||||
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
|
||||
creep.memory.building = false;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ var creepCounts = {
|
|||
function runRole(creep){
|
||||
const role = roleMap[creep.memory.role];
|
||||
|
||||
if(role && typeof role.run === 'function'){
|
||||
if(role !== 'undefined'){
|
||||
role.run(creep);
|
||||
} else {
|
||||
console.log('Unknown or undefined role: ' + creep.memory.role);
|
||||
|
@ -33,10 +33,8 @@ function runRole(creep){
|
|||
function spawnCreeps(spawn){
|
||||
for(const [role, count] of Object.entries(creepCounts)){
|
||||
var roleCreeps = _.filter(Game.creeps, (creep) => creep.memory.role == role);
|
||||
|
||||
|
||||
if(roleCreeps.length < count && !spawn.spawning) {
|
||||
var newName = role + Game.time;
|
||||
roleMap[role].spawn(spawn);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
var roleBase = require('role_base');
|
||||
|
||||
class roleGuard extends roleBase{
|
||||
static body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ];
|
||||
static name = 'streltsy'
|
||||
/** @param {Creep} creep **/
|
||||
constructor(){
|
||||
this.body = [ MOVE, RANGED_ATTACK ];
|
||||
this.name = 'Streltsy'
|
||||
}
|
||||
run(creep) {
|
||||
static run(creep) {
|
||||
const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
|
||||
if(target) {
|
||||
if(creep.rangedAttack(target) == ERR_NOT_IN_RANGE) {
|
||||
|
@ -26,9 +24,12 @@ class roleGuard extends roleBase{
|
|||
}
|
||||
}
|
||||
}
|
||||
spawn(spawnPoint, newWaypoints){
|
||||
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}
|
||||
{memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -3,11 +3,10 @@ var roleBase = require('role_base');
|
|||
|
||||
class roleHarvester extends roleBase{
|
||||
/** @param {Creep} creep **/
|
||||
constructor(){
|
||||
super();
|
||||
this.name = 'Peasant'
|
||||
}
|
||||
run(creep) {
|
||||
|
||||
static name = 'harvester';
|
||||
|
||||
static run(creep) {
|
||||
if(creep.store.getFreeCapacity() > 0) {
|
||||
var sources = creep.room.find(FIND_SOURCES);
|
||||
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
|
||||
|
|
|
@ -2,12 +2,9 @@ var energyUtils = require('util_energy');
|
|||
var roleBase = require('role_base');
|
||||
|
||||
class roleRepairer extends roleBase {
|
||||
constructor(){
|
||||
super();
|
||||
this.name = 'Repairer';
|
||||
}
|
||||
static name = 'repairer';
|
||||
/** @param {Creep} creep **/
|
||||
run(creep) {
|
||||
static run(creep) {
|
||||
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
|
||||
creep.memory.building = false;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
var roleBase = require('role_base');
|
||||
|
||||
class roleUpgrader extends roleBase {
|
||||
constructor(){
|
||||
super();
|
||||
this.name = 'Upgrader';
|
||||
}
|
||||
static name = 'upgrader';
|
||||
|
||||
/** @param {Creep} creep **/
|
||||
run(creep) {
|
||||
static run(creep) {
|
||||
|
||||
if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) {
|
||||
creep.memory.upgrading = false;
|
||||
|
|
|
@ -23,15 +23,15 @@ var energyUtils = {
|
|||
depositEnergy : function(creep) {
|
||||
var targets = creep.room.find(FIND_STRUCTURES, {
|
||||
filter: (structure) => {
|
||||
return structure.structureType == STRUCTURE_SPAWN &&
|
||||
structure.store.getUsedCapacity(RESOURCE_ENERGY) < 250;
|
||||
return (structure.structureType == STRUCTURE_SPAWN ||
|
||||
structure.structureType == STRUCTURE_EXTENSION) &&
|
||||
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
||||
}
|
||||
});
|
||||
if(targets.length == 0){
|
||||
targets = creep.room.find(FIND_STRUCTURES, {
|
||||
filter: (structure) => {
|
||||
return (structure.structureType == STRUCTURE_EXTENSION ||
|
||||
structure.structureType == STRUCTURE_CONTAINER ||
|
||||
return (structure.structureType == STRUCTURE_CONTAINER ||
|
||||
structure.structureType == STRUCTURE_TOWER) &&
|
||||
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
||||
}
|
||||
|
@ -41,9 +41,10 @@ var energyUtils = {
|
|||
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return targets.length > 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = energyUtils;
|
||||
module.exports = energyUtils;
|
||||
|
|
6
util_progress.js
Normal file
6
util_progress.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
var progressUtils = {
|
||||
checkProgress : function() {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = progressUtils;
|
Loading…
Reference in a new issue