-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
93 lines (86 loc) · 2.72 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleBuilder = require('role.builder');
var roleRepairer = require('role.repairer');
var structTower = require('struct.tower');
var roleScout = require('role.scout');
var spawner = require('spawn');
module.exports.loop = function () {
for(var name in Memory.creeps) {
if(!Game.creeps[name]) {
delete Memory.creeps[name];
console.log('Clearing non-existing creep memory:', name);
}
}
spawner.run(Game.spawns['Spawn1'])
var towers = Game.spawns['Spawn1'].room.find(FIND_MY_STRUCTURES, {
filter: (s) => {
return s.structureType == STRUCTURE_TOWER;
}});
for(var tower of towers){
structTower.run(tower);
}
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);
}
if(creep.memory.role == 'repairer') {
roleRepairer.run(creep);
}
if(creep.memory.role == 'scout') {
roleScout.run(creep);
}
}
// Add road construction request if there are less than a fixed numbers TODO: than builders in the room?
if(Game.time % 50 == 0)
{
console.log("Let's build cette biatch")
// Find highest requested position
var max = {
value:0
}
if(!Memory.room) Memory.room = {}
for(var key of Object.keys(Memory.room))
{
if(max.value < Memory.room[key])
{
max.value = Memory.room[key]
max.key = key
}
}
if(max.value > 0)
{
console.log("Building " + max.value + " at " + max.key)
var keyArray = max.key.split(' ')
var posArray = keyArray[3].split(',')
var roomToBuild = Game.rooms[keyArray[1]]
if(!roomToBuild)
{
console.log("Room not visible. Let's drop this request");
delete Memory.room[max.key];
}
else if(roomToBuild.find(FIND_MY_CONSTRUCTION_SITES).length < 5)
{
var ret = roomToBuild.createConstructionSite(parseInt(posArray[0]), parseInt(posArray[1]), STRUCTURE_ROAD)
console.log("Result " + ret)
// remove count
delete Memory.room[max.key]
}
else
{
console.log("Too many sites. Let's wait" + roomToBuild.find(FIND_MY_CONSTRUCTION_SITES).length )
}
}
else
{
console.log("Noone wants anything.")
}
}
}