-
Notifications
You must be signed in to change notification settings - Fork 0
/
prototype.StructureSpawn.js
104 lines (93 loc) · 3.27 KB
/
prototype.StructureSpawn.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
module.exports = function () {
// create a new function for StructureSpawn
StructureSpawn.prototype.createCreepWorker = function (creepNamePrefix, roleName) {
var maxSize = this.room.energyCapacityAvailable;
var noParts = Math.floor(maxSize / 200);
var body = [];
console.log(this.room.energyCapacityAvailable);
console.log(maxSize)
console.log(noParts)
for (let i = 0; i < noParts; i++) {
body.push(WORK);
body.push(CARRY);
body.push(MOVE);
}
var remainder = (maxSize - noParts * 200)
console.log(remainder)
noParts = Math.floor(remainder / 50)
console.log(noParts)
var nextPart = MOVE;
for (let i = 0; i < noParts; i++) {
body.push(nextPart);
if (nextPart == CARRY) {
nextPart = MOVE;
} else {
nextPart = CARRY;
}
}
var name = this.getNameName(creepNamePrefix);
console.log("Spwaming new workder - " + name + ' body: ' + body.toString());
return this.createCreep(body, name, { role: roleName });
};
StructureSpawn.prototype.createCreepMiner = function (creepNamePrefix, roleName) {
var maxSize = this.room.energyCapacityAvailable;
var body = [];
// Add move blix
maxSize = maxSize - 50;
body.push(MOVE);
var noParts = Math.floor(maxSize / 100);
// 3000 E / regen every 30
if (noParts > 10) {
noParts = 10
};
for (let i = 0; i < noParts; i++) {
body.push(WORK);
}
var name = this.getNameName(creepNamePrefix);
console.log("Spwaming new miner - " + name + ' body: ' + body.toString());
return this.createCreep(body, name, { role: roleName });
};
/**
* Summary. create long range harvester
*/
StructureSpawn.prototype.createLongRangeHarvester = function (sourceId, sourceRoom, carryPartForWork) {
var maxSize = this.room.energyCapacityAvailable;
var body = [];
// force one work
body.push(WORK);
maxSize -= 100;
var noParts = Math.floor(maxSize / 100);
var addWork = 1;
for (let i = 0; i < noParts; i++) {
body.push(MOVE);
body.push(CARRY);
if (addWork >= carryPartForWork && i + 2 < noParts) {
body.push(WORK);
addWork = 1;
i += 2;
} else {
addWork += 1;
}
}
var name = this.getNameName('LONG_HARVESTER');
console.log("Spwaming new miner - " + name + ' body: ' + body.toString());
return this.createCreep(body, name
, {
role: "LongRangeHarvester",
sourceId: sourceId,
sourceRoom: sourceRoom
});
};
/**
* Summary. get unused name
*/
StructureSpawn.prototype.getNameName = function (creepNamePrefix) {
/* Get name
*/
do {
var name = Math.floor(Math.random() * 8999) + 1000;
name = creepNamePrefix + '_' + name;
} while (_.sum(this.room.creeps, (c) => c.name == name) !== 0);
return name;
};
};