-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwork.movement.js
63 lines (60 loc) · 2.17 KB
/
work.movement.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Creep Movement Handling
*/
module.exports.run = function(debug = false) {
if (debug) {
var _cpu = Game.cpu.getUsed();
console.log('Running Creep Movement ');
}
// Loop through all the roles
for (var i in ROLES) {
if (Game.cpu.bucket < CPU_MINIMUM && Game.cpu.getUsed() > Game.cpu.limit - 2) {
console.log('Skipping '+ ROLES[i] + ' To relax CPU use');
} else {
// Get the role name from our global array by index
var role = ROLES[i];
// Som Debug
if (debug) { console.log('Running ' + role + ' Creep Movement'); }
// Grab the correct role file
var _role = require('role.' + role);
// Now for each of the creeps
for(var name in Game.creeps) {
const a = Game.cpu.getUsed();
// Make a creep
var creep = Game.creeps[name];
// If this creep's role is the one we are checking
if(creep.memory.role == _role.role) {
// Run it
_role.run(creep);
const cost = Game.cpu.getUsed() - a;
this.colour(creep, cost);
}
}
if (debug) {
console.log(role + ' Move used ' + (Game.cpu.getUsed() - _cpu).toFixed(3) + ' CPU');
}
}
}
}
module.exports.colour = function (creep, cost) {
creep.room.visual.circle(creep.pos, {
fill: global.roleColour[creep.memory.role],
radius: 0.4,
opacity: 0.1,
stroke: global.roleColour[creep.memory.role],
}).text(/* "<--= [" + creep.memory.level + '] ' + creep.memory.role + ' '*/ + cost.toFixed(2), creep.pos, {
color:global.roleColour[creep.memory.role],
font:0.5,
align:'left',
stroke:'rgba(0,0,0,0.5)',
});
// if (creep.memory._move) {
// _room.visual.circle(creep.memory._move.dest.x, creep.memory._move.dest.y, {
// fill: 'transparent',
// radius: 0.5,
// opacity: 0.3,
// stroke: global.roleColour[creep.memory.role],
// });
// } else {
// }
}