-
Notifications
You must be signed in to change notification settings - Fork 40
/
factory.js
105 lines (91 loc) · 1.92 KB
/
factory.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
94
95
96
97
98
99
100
101
102
103
104
105
var countType = require('countType');
module.exports ={
init: function()
{
if(Memory.factoryInit != undefined)
return;
Memory.factoryInit = true;
this.memory();
},
run: function()
{
this.spawnRequiredScreeps();
},
memory: function() {
if(Memory.spawnQue == undefined)
Memory.spawnQue = [ ];
if(Memory.sources == undefined)
Memory.sources = { };
if(Memory.requiredScreeps == undefined)
{
Memory.requiredScreeps = [
//Survival
'miner', //1
'archer', //1
'miner', //2
'archer', //2
'healer', //1
'archer', //3
'miner', //3
'builder',
'transporter',
'transporter',
'archer', //4
'healer', //2
'archer', //5
'archer', //6
'miner', //4
'archer', //7
'archer', //8
'archer', //9
'healer', //3
'miner', //5
'builder',
'transporter',
'transporter',
'archer', //10
'archer', //11
'healer' //4
//Tutorial
// 'miner',
// 'miner',
// 'miner',
// 'miner',
// 'miner',
];
}
},
spawnRequiredScreeps: function()
{
var requiredScreeps = Memory.requiredScreeps;
var gatheredScreeps = { };
for(var index in requiredScreeps)
{
var type = requiredScreeps[index];
if(gatheredScreeps[type] == undefined)
gatheredScreeps[type] = 0;
var neededToSkip = gatheredScreeps[type] + 1;
var found = countType(type, true);
if(neededToSkip > countType(type, true))
{
Memory.spawnQue.push(type);
}
gatheredScreeps[type]++;
}
},
buildArmyWhileIdle: function()
{
for(var i in Game.spawns)
{
var spawn = Game.spawns[i];
if(!spawn.spawning && Memory.spawnQue.length == 0 && spawn.energy / spawn.energyCapacity >= .6) {
var archers = countType('archer', true);
var healers = countType('healer', true);
if(healers / archers < .25)
require('spawner').spawn('healer', { }, spawn);
else
require('spawner').spawn('archer', { }, spawn);
}
}
}
};