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

View file

@ -1,8 +1,11 @@
var energyUtils = require('util_energy'); 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) { if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.building = false; creep.memory.building = false;
} }
@ -21,6 +24,7 @@ function run(creep) {
else { else {
energyUtils.gatherEnergy(creep); 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 roleBuilder = require('role_builder');
var roleRepairer = require('role_repairer'); var roleRepairer = require('role_repairer');
var roleGuard = require('role_guard'); var roleGuard = require('role_guard');
var roleBase = require('role_base');
const roleMap = { const roleMap = {
harvester: roleHarvester, harvester: roleHarvester,
@ -24,7 +23,7 @@ var creepCounts = {
function runRole(creep){ function runRole(creep){
const role = roleMap[creep.memory.role]; const role = roleMap[creep.memory.role];
if(typeof role.run === 'function'){ if(role !== 'undefined'){
role.run(creep); role.run(creep);
} else { } else {
console.log('Unknown or undefined role: ' + creep.memory.role); 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); var roleCreeps = _.filter(Game.creeps, (creep) => creep.memory.role == role);
if(roleCreeps.length < count && !spawn.spawning) { if(roleCreeps.length < count && !spawn.spawning) {
if(typeof roleMap[role].spawn === 'function')
roleMap[role].spawn(spawn); roleMap[role].spawn(spawn);
else
roleBase.spawn(spawn, roleMap[role].body, roleMap[role].name);
break; break;
} }
} }

View file

@ -1,7 +1,10 @@
var body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ]; var roleBase = require('role_base');
var name = 'streltsy'
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); 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) {
@ -21,14 +24,14 @@ function run(creep) {
} }
} }
} }
static spawn(spawnPoint, newWaypoints){
function spawn(spawnPoint, newWaypoints){
if(typeof newWaypoints === 'undefined') if(typeof newWaypoints === 'undefined')
newWaypoints = ['A','B']; newWaypoints = ['A','B'];
spawnPoint.spawnCreep(this.body, this.name + Game.time, spawnPoint.spawnCreep(this.body, this.name + Game.time,
{memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0} {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 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) { 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) {
@ -14,6 +18,7 @@ function run(creep) {
creep.moveTo(Game.flags.IdleArea); creep.moveTo(Game.flags.IdleArea);
} }
} }
} }
};
module.exports = {name,run}; module.exports = roleHarvester;

View file

@ -1,8 +1,10 @@
var energyUtils = require('util_energy'); var energyUtils = require('util_energy');
var roleBase = require('role_base');
var name = 'repairer'; class roleRepairer extends roleBase {
static name = 'repairer';
function run(creep) { /** @param {Creep} creep **/
static 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;
} }
@ -28,6 +30,7 @@ function run(creep) {
else { else {
energyUtils.gatherEnergy(creep); 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 **/ class roleUpgrader extends roleBase {
function run(creep) { static name = 'upgrader';
/** @param {Creep} creep **/
static 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;
@ -21,6 +24,7 @@ function run(creep) {
creep.moveTo(sources[1], {visualizePathStyle: {stroke: '#ffaa00'}}); creep.moveTo(sources[1], {visualizePathStyle: {stroke: '#ffaa00'}});
} }
} }
} }
};
module.exports = {name,run}; module.exports = roleUpgrader;