-
Notifications
You must be signed in to change notification settings - Fork 0
/
prototype.spawn.js
165 lines (160 loc) · 6.74 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
module.exports = function() {
StructureSpawn.prototype.setMinRoles =
function(){
if(this.memory.varsSet == undefined){
var minHarvesters = 2;
var minUpgraders = 2;
var sources = Game.spawns.Spawn1.room.find(FIND_SOURCES);
var minMiners = sources.length;
var minCouriers = minMiners;
var minBuilders = 2;
var minRepairers = 2;
var minLDHarvesterW26N12 = 1;
var minLDHarvesterW25N11 = 1;
this.memory.minHarvesters = minHarvesters;
this.memory.minUpgraders = minUpgraders;
this.memory.sources = sources;
this.memory.minMiners = this.memory.sources.length;
this.memory.minCouriers = this.memory.minMiners;
this.memory.minRepairers = minRepairers;
this.memory.minContainerRepairers = this.memory.minRepairers;
this.memory.varsSet = true;
}
}
// create a new function for StructureSpawn
StructureSpawn.prototype.spawnCustomCreep =
function(energy, roleName) {
// create a balanced body as big as possible with the given energy
var cName = roleName + Game.time;
if (energy > 3200) { energy = 3200}
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
// console.log(body);
return this.spawnCreep(body, cName, { memory: {
role: roleName,
working: false
}});
};
StructureSpawn.prototype.spawnMiner =
function(sourceID, energy, roleName){
var cName = roleName + Game.time;
if(energy >= 800){
return this.spawnCreep([WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,MOVE], cName, {memory:
{ role: 'miner',
working: false,
sourceID: sourceID }});
}
else if(energy < 800){
return this.spawnCreep([WORK,WORK,CARRY,MOVE], cName, {memory:
{ role: 'miner',
working: false,
sourceID: sourceID }});
}
}
StructureSpawn.prototype.spawnCourier =
function(containerID, energy, roleName){
var cName = roleName + Game.time;
if(energy >= 800){
return this.spawnCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,WORK,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE], cName,{memory:
{ role: 'courier',
working: false,
containerID: containerID }});
}
else if(energy < 800){
return this. spawnCreep([CARRY,CARRY,WORK,MOVE,MOVE], cName,{memory: {
role: 'courier',
working: false,
containerID: containerID }});
}
}
StructureSpawn.prototype.spawnLongDistanceHarvester =
function (numberOfWorkParts, home, target, sourceIndex) {
var cName = roleName + Game.time;
var energy = this.room.energyCapacityAvailable;
// create a body with the specified number of WORK parts and one MOVE part per non-MOVE part
var body = [];
for (let i = 0; i < numberOfWorkParts; i++) {
body.push(WORK);
body.push(MOVE);
}
// 150 = 100 (cost of WORK) + 50 (cost of MOVE)
energy -= 150 * numberOfWorkParts;
var numberOfParts = Math.floor(energy / 50);
for (let i = 0; i < numberOfParts; i++) {
body.push(CARRY);
}
// create creep with the created body
return this.spawnCreep(body, cName, {
role: 'ldHarvester',
home: home,
target: target,
sourceIndex: sourceIndex,
working: false
});
};
StructureSpawn.prototype.spawnUpgrader =
function(){
var cName = 'upgrader' + Game.time;
var energy = this.room.energyCapacityAvailable;
if(energy >= 500){
// create creep with the created body and the given role
var body = [CARRY, CARRY, WORK, MOVE, MOVE]
return this.spawnCreep(body, cName, {memory:
{ role: 'upgrader',
working: false }});
}else{
var body = [CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,WORK,MOVE,MOVE]
return this.createCreep(body,cName,{memory:
{ role: 'upgrader',
working: false}})
}
}
StructureSpawn.prototype.spawnContainerRepairer =
function(containerID){
var cName = 'containerRepairer' + Game.time;
var energy = this.room.energyCapacityAvailable;
// 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(CARRY);
body.push(CARRY);
body.push(WORK);
}
energy = energy - numberOfParts * 200
if (energy < 50){
body.splice(body.length-1,1);
}
body.push(MOVE);
// create creep with the created body and the given role
return this.spawnCreep(body, cName, {memory: {
role: 'containerRepairer',
working: false,
containerID: containerID
}});
}
StructureSpawn.prototype.getMinLDHarvesters =
function(){
let spawn = this;
let exits = this.room.find(FIND_EXIT);
if(exits.length > 0){
let exitDirections = [FIND_EXIT_BOTTOM,FIND_EXIT_LEFT,FIND_EXIT_TOP,FIND_EXIT_RIGHT];
for(let directionIndex in exitDirections){
if(spawn.room.find(exitDirections[directionIndex]).length > 0){
minLDHarvester = minLDHarvester+1
}
}
}
this.memory.minLDHarvester = minLDHarvester;
}
};