-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
70 lines (64 loc) · 2.39 KB
/
main.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
64
65
66
67
68
69
70
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleBuilder = require('role.builder');
module.exports.loop = function () {
//Delete memory of dead Creeps
for(var name in Memory.creeps) {
if(!Game.creeps[name]) {
delete Memory.creeps[name];
}
}
//get all Creeps by Role
var harvesters = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester');
var upgrader = _.filter(Game.creeps, (creep) => creep.memory.role == 'upgrader');
var builder = _.filter(Game.creeps, (creep) => creep.memory.role == 'builder');
//Check amount of living Creeps
if(harvesters.length < 2) {
var newName = 'Harvester' + Game.time;
Game.spawns['Spawn1'].spawnCreep([WORK,CARRY,MOVE], newName,
{memory: {role: 'harvester'}});
}
if(upgrader.length < 2) {
var newName = 'Upgrader' + Game.time;
Game.spawns['Spawn1'].spawnCreep([WORK,CARRY,MOVE], newName,
{memory: {role: 'upgrader'}});
}
if(builder.length < 1) {
var newName = 'Builder' + Game.time;
Game.spawns['Spawn1'].spawnCreep([WORK,CARRY,MOVE], newName,
{memory: {role: 'builder'}});
}
if(Game.spawns['Spawn1'].spawning) {
var spawningCreep = Game.creeps[Game.spawns['Spawn1'].spawning.name];
Game.spawns['Spawn1'].room.visual.text(
'Spawning: ' + spawningCreep.memory.role,
Game.spawns['Spawn1'].pos.x + 1,
Game.spawns['Spawn1'].pos.y,
{align: 'left', opacity: 0.8});
}
for(var name in Game.creeps) {
var creep = Game.creeps[name];
if(creep.memory.role == 'harvester') {
roleHarvester.run(creep);
}
if(creep.memory.role == 'upgrader') {
roleUpgrader.run(creep);
}
if(creep.memory.role == 'builder') {
roleBuilder.run(creep);
}
}
var tower =false;
if(tower) {
var closestDamagedStructure = tower.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => structure.hits < structure.hitsMax
});
if(closestDamagedStructure) {
tower.repair(closestDamagedStructure);
}
var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(closestHostile) {
tower.attack(closestHostile);
}
}
}