-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprototype.spawn.js
122 lines (121 loc) · 3.72 KB
/
prototype.spawn.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
module.exports = function () {
// create a new function for StructureSpawn that equally divides the body parts
StructureSpawn.prototype.createEqualCreep = function (
energy,
roleName,
status
) {
// create a balanced body as big as possible with the given energy
var numberOfParts = Math.floor(energy / 200);
var body = [];
for (let i = 0; i < numberOfParts; i++) {
body.push(WORK);
}
for (let i = 0; i < numberOfParts; i++) {
body.push(CARRY);
}
for (let i = 0; i < numberOfParts; i++) {
body.push(MOVE);
}
// create creep with the created body and the given role
return this.spawnCreep(body, roleName + Game.time, {
memory: { role: roleName, idle: true, status: status },
});
};
// create a new function for StructureSpawn that creates 2:1 carry/move to work body parts
StructureSpawn.prototype.createFastCreep = function (
energy,
roleName,
status
) {
// create a more speed focused body
var numberOfParts = Math.floor(energy / 300);
var body = [];
for (let i = 0; i < numberOfParts; i++) {
body.push(WORK);
}
for (let i = 0; i < numberOfParts; i++) {
body.push(CARRY);
body.push(CARRY);
}
for (let i = 0; i < numberOfParts; i++) {
body.push(MOVE);
body.push(MOVE);
}
if (body.length === 0) {
return ERR_NOT_ENOUGH_ENERGY;
}
// create creep with the created body and the given role
return this.spawnCreep(body, roleName + Game.time, {
memory: { role: roleName, idle: true, status: status },
});
};
// create a new function for StructureSpawn that creates 3:1:1 carry:move:work body parts
StructureSpawn.prototype.createCarrierCreep = function (
energy,
roleName,
status
) {
// create a carry focused creep
var numberOfParts = Math.floor(energy / 300);
var body = [];
for (let i = 0; i < numberOfParts; i++) {
body.push(WORK);
}
for (let i = 0; i < numberOfParts; i++) {
body.push(CARRY);
body.push(CARRY);
body.push(CARRY);
}
for (let i = 0; i < numberOfParts; i++) {
body.push(MOVE);
}
if (body.length === 0) {
return ERR_NOT_ENOUGH_ENERGY;
}
// create creep with the created body and the given role
return this.spawnCreep(body, roleName + Game.time, {
memory: { role: roleName, idle: true, status: status },
});
};
// create a new function for StructureSpawn that creates 2:1:1 work:carry:move body parts
StructureSpawn.prototype.createHarvesterCreep = function (
energy,
roleName,
status
) {
// create a carry focused creep
var numberOfParts = Math.floor(energy / 400);
var body = [];
for (let i = 0; i < numberOfParts; i++) {
body.push(WORK);
body.push(WORK);
body.push(WORK);
}
for (let i = 0; i < numberOfParts; i++) {
body.push(CARRY);
}
for (let i = 0; i < numberOfParts; i++) {
body.push(MOVE);
}
if (body.length === 0) {
return ERR_NOT_ENOUGH_ENERGY;
}
// create creep with the created body and the given role
return this.spawnCreep(body, roleName + Game.time, {
memory: { role: roleName, idle: true, status: status },
});
};
// create a new function for StructureSpawn that creates a miner that sits on a container
StructureSpawn.prototype.createMinerCreep = function (status) {
// create a miner, it needs no carry part
var body = [WORK, WORK, WORK, WORK, WORK, MOVE];
// create creep with the created body and the given role
if (body.length === 0) {
return ERR_NOT_ENOUGH_ENERGY;
}
return this.spawnCreep(body, `Miner` + Game.time, {
memory: { role: roleName, idle: true, status: status },
});
};
};