Compare commits

..

No commits in common. "bd6631781d963491e19294c9fb7c02a5d927ffeb" and "e6d90d43a4d8f3465daec27e0561d6836df57b5f" have entirely different histories.

7 changed files with 132 additions and 118 deletions

View file

@ -1,14 +1,13 @@
var body = [ MOVE, WORK, CARRY ];
var name = 'Creep';
function run(creep) { }
function spawn(spawnPoint, newBody, newName){
if(typeof newBody === 'undefined') newBody = body;
if(typeof newName === 'undefined') newName = name;
spawnPoint.spawnCreep(newBody, newName + Game.time,
{memory : {role : newName}
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}
});
}
}
};
module.exports = {body,name,run,spawn};
module.exports = roleBase;

View file

@ -1,8 +1,11 @@
var energyUtils = require('util_energy');
var roleBase = require('role_base');
var name = 'builder';
class roleBuilder extends roleBase{
/** @param {Creep} creep **/
static name = 'builder';
function run(creep) {
static run(creep) {
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.building = false;
}
@ -21,6 +24,7 @@ function run(creep) {
else {
energyUtils.gatherEnergy(creep);
}
}
}
};
module.exports = {name,run};
module.exports = roleBuilder;

View file

@ -3,7 +3,6 @@ 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,
@ -24,7 +23,7 @@ var creepCounts = {
function runRole(creep){
const role = roleMap[creep.memory.role];
if(typeof role.run === 'function'){
if(role !== 'undefined'){
role.run(creep);
} else {
console.log('Unknown or undefined role: ' + creep.memory.role);
@ -36,10 +35,7 @@ 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,7 +1,10 @@
var body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ];
var name = 'streltsy'
var roleBase = require('role_base');
function run(creep) {
class roleGuard extends roleBase{
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);
if(target) {
if(creep.rangedAttack(target) == ERR_NOT_IN_RANGE) {
@ -21,14 +24,14 @@ function run(creep) {
}
}
}
function 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, currentWaypoint : 0}
});
}
}
};
module.exports = {body,name,run,spawn};
module.exports = roleGuard;

View file

@ -1,8 +1,12 @@
var energyUtils = require('util_energy');
var roleBase = require('role_base');
var name = 'harvester';
class roleHarvester extends roleBase{
/** @param {Creep} creep **/
function 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) {
@ -14,6 +18,7 @@ function run(creep) {
creep.moveTo(Game.flags.IdleArea);
}
}
}
}
};
module.exports = {name,run};
module.exports = roleHarvester;

View file

@ -1,8 +1,10 @@
var energyUtils = require('util_energy');
var roleBase = require('role_base');
var name = 'repairer';
function run(creep) {
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;
}
@ -28,6 +30,7 @@ function run(creep) {
else {
energyUtils.gatherEnergy(creep);
}
}
}
};
module.exports = {name,run};
module.exports = roleRepairer;

View file

@ -1,7 +1,10 @@
var name = 'upgrader';
var roleBase = require('role_base');
/** @param {Creep} creep **/
function run(creep) {
class roleUpgrader extends roleBase {
static name = 'upgrader';
/** @param {Creep} creep **/
static run(creep) {
if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.upgrading = false;
@ -21,6 +24,7 @@ function run(creep) {
creep.moveTo(sources[1], {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
}
}
};
module.exports = {name,run};
module.exports = roleUpgrader;