Compare commits
5 commits
bb03c6d884
...
e6d90d43a4
Author | SHA1 | Date | |
---|---|---|---|
|
e6d90d43a4 | ||
|
4b403bb935 | ||
|
86295d6f0a | ||
|
7c22f99bf9 | ||
|
b5dfb44faf |
3
main.js
3
main.js
|
@ -1,5 +1,4 @@
|
||||||
var roleDispatcher = require('role.dispatcher');
|
var roleDispatcher = require('role_dispatcher');
|
||||||
|
|
||||||
|
|
||||||
module.exports.loop = function () {
|
module.exports.loop = function () {
|
||||||
|
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
var energyUtils = require('utils.energy');
|
|
||||||
|
|
||||||
const body = [
|
|
||||||
MOVE, RANGED_ATTACK
|
|
||||||
];
|
|
||||||
|
|
||||||
var roleGuard = {
|
|
||||||
body,
|
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
|
||||||
run: function(creep) {
|
|
||||||
const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
|
|
||||||
if(target) {
|
|
||||||
if(creep.rangedAttack(target) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
creep.moveTo(Game.flags.IdleArea);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = roleGuard;
|
|
13
role_base.js
Normal file
13
role_base.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
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 = roleBase;
|
|
@ -1,15 +1,11 @@
|
||||||
var energyUtils = require('utils.energy');
|
var energyUtils = require('util_energy');
|
||||||
|
var roleBase = require('role_base');
|
||||||
const body = [
|
|
||||||
WORK, CARRY, MOVE
|
|
||||||
];
|
|
||||||
|
|
||||||
var roleBuilder = {
|
|
||||||
body,
|
|
||||||
|
|
||||||
|
class roleBuilder extends roleBase{
|
||||||
/** @param {Creep} creep **/
|
/** @param {Creep} creep **/
|
||||||
run: function(creep) {
|
static name = 'builder';
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
var roleHarvester = require('role.harvester');
|
var roleHarvester = require('role_harvester');
|
||||||
var roleUpgrader = require('role.upgrader');
|
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');
|
||||||
|
|
||||||
const roleMap = {
|
const roleMap = {
|
||||||
harvester: roleHarvester,
|
harvester: roleHarvester,
|
||||||
|
@ -23,7 +23,7 @@ var creepCounts = {
|
||||||
function runRole(creep){
|
function runRole(creep){
|
||||||
const role = roleMap[creep.memory.role];
|
const role = roleMap[creep.memory.role];
|
||||||
|
|
||||||
if(role && 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);
|
||||||
|
@ -33,12 +33,9 @@ function runRole(creep){
|
||||||
function spawnCreeps(spawn){
|
function spawnCreeps(spawn){
|
||||||
for(const [role, count] of Object.entries(creepCounts)){
|
for(const [role, count] of Object.entries(creepCounts)){
|
||||||
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) {
|
||||||
var newName = role + Game.time;
|
roleMap[role].spawn(spawn);
|
||||||
console.log(spawn.spawnCreep(roleMap[role].body, newName,
|
|
||||||
{memory: {role: role}}));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
37
role_guard.js
Normal file
37
role_guard.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
var roleBase = require('role_base');
|
||||||
|
|
||||||
|
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) {
|
||||||
|
creep.moveTo(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var currentWaypoint = Game.flags[creep.memory.waypoints[creep.memory.currentWaypoint]];
|
||||||
|
if(creep.pos.getRangeTo(currentWaypoint) > 0){
|
||||||
|
creep.moveTo(currentWaypoint);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
creep.memory.currentWaypoint += 1;
|
||||||
|
if(creep.memory.currentWaypoint > creep.memory.waypoints.length){
|
||||||
|
creep.memory.currentWaypoint = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 = roleGuard;
|
|
@ -1,14 +1,12 @@
|
||||||
var energyUtils = require('utils.energy');
|
var energyUtils = require('util_energy');
|
||||||
|
var roleBase = require('role_base');
|
||||||
const body = [
|
|
||||||
WORK, CARRY, MOVE
|
|
||||||
];
|
|
||||||
|
|
||||||
var roleHarvester = {
|
|
||||||
body,
|
|
||||||
|
|
||||||
|
class roleHarvester extends roleBase{
|
||||||
/** @param {Creep} creep **/
|
/** @param {Creep} creep **/
|
||||||
run: function(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) {
|
|
@ -1,15 +1,10 @@
|
||||||
var energyUtils = require('utils.energy');
|
var energyUtils = require('util_energy');
|
||||||
|
var roleBase = require('role_base');
|
||||||
const body = [
|
|
||||||
WORK, CARRY, MOVE
|
|
||||||
];
|
|
||||||
|
|
||||||
var roleRepairer = {
|
|
||||||
body,
|
|
||||||
|
|
||||||
|
class roleRepairer extends roleBase {
|
||||||
|
static name = 'repairer';
|
||||||
/** @param {Creep} creep **/
|
/** @param {Creep} creep **/
|
||||||
run: function(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;
|
||||||
}
|
}
|
|
@ -1,12 +1,10 @@
|
||||||
const body = [
|
var roleBase = require('role_base');
|
||||||
WORK, CARRY, MOVE
|
|
||||||
];
|
|
||||||
|
|
||||||
var roleUpgrader = {
|
class roleUpgrader extends roleBase {
|
||||||
body,
|
static name = 'upgrader';
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
/** @param {Creep} creep **/
|
||||||
run: function(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;
|
|
@ -23,15 +23,15 @@ var energyUtils = {
|
||||||
depositEnergy : function(creep) {
|
depositEnergy : function(creep) {
|
||||||
var targets = creep.room.find(FIND_STRUCTURES, {
|
var targets = creep.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return structure.structureType == STRUCTURE_SPAWN &&
|
return (structure.structureType == STRUCTURE_SPAWN ||
|
||||||
structure.store.getUsedCapacity(RESOURCE_ENERGY) < 250;
|
structure.structureType == STRUCTURE_EXTENSION) &&
|
||||||
|
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(targets.length == 0){
|
if(targets.length == 0){
|
||||||
targets = creep.room.find(FIND_STRUCTURES, {
|
targets = creep.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return (structure.structureType == STRUCTURE_EXTENSION ||
|
return (structure.structureType == STRUCTURE_CONTAINER ||
|
||||||
structure.structureType == STRUCTURE_CONTAINER ||
|
|
||||||
structure.structureType == STRUCTURE_TOWER) &&
|
structure.structureType == STRUCTURE_TOWER) &&
|
||||||
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,10 @@ var energyUtils = {
|
||||||
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
|
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