-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller.roles.js
43 lines (43 loc) · 1.75 KB
/
controller.roles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @author Nicolas Durant
* @email [email protected]
* @create date 2019-12-02 18:07:51
* @modify date 2019-12-04 10:10:27
* @desc Controller that executes all the creep roles.
*/
var _HARVESTER = require('role.harvester');
var _UPGRADER = require('role.upgrader');
var _BUILDER = require('role.builder');
var _REPAIRER = require('role.repairer');
var _WALLER = require('role.waller');
var _ROOM = require('controller.room');
module.exports = {
/**
* Function that checks if screeps accidently are in the wrong room.
*/
creepLogic: function (spawn) {
var creepsInSpawnRoom = spawn.room.find(FIND_MY_CREEPS);
// loop that executes the working commands for our creeps per tick
for (const creep of creepsInSpawnRoom) {
// decide the actions of our creep depending on its role memory
let fn;
let roomToBeIn = spawn.room.name;
if (creep.memory.role === 'harvester') {
fn = function() {_HARVESTER.harvest(creep)}
_ROOM.checkRoom(creep, roomToBeIn, fn);
} else if (creep.memory.role === 'upgrader') {
fn = function() {_UPGRADER.run(creep)}
_ROOM.checkRoom(creep, roomToBeIn, fn);
} else if (creep.memory.role === 'builder') {
fn = function() {_BUILDER.run(creep)}
_ROOM.checkRoom(creep, roomToBeIn, fn);
} else if (creep.memory.role === 'repairer') {
fn = function() {_REPAIRER.run(creep)}
_ROOM.checkRoom(creep, roomToBeIn, fn);
} else if (creep.memory.role === 'waller') {
fn = function() {_WALLER.run(creep)}
_ROOM.checkRoom(creep, roomToBeIn, fn);
}
}
},
};