-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototype.room.js
153 lines (119 loc) · 5.5 KB
/
prototype.room.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
var params = require('params');
module.exports = function () {
Room.prototype.creeps;
Room.prototype.sources;
Room.prototype.noOfSources;
Room.prototype.noOfCreeps;
Room.prototype.startUp = function () {
// TODO Clean up hack
var primaryRoom;
if (this.name == Memory.primaryRoom) {
primaryRoom = true;
} else {
primaryRoom = false;
}
// Setup memory objects
if (this.memory.roomInit == null) {
this.newRoow();
}
var spawn = this.find(FIND_MY_SPAWNS)[0];
this.memory.MinWallHitPoint = params.DEFAULT_WALL_HITPOINT;
/* Stats
*/
this.creeps = this.find(FIND_MY_CREEPS);
var noOfHarvesters = _.sum(this.creeps, (c) => c.memory.role == 'harvester');
var noOfMiners = _.sum(this.creeps, (c) => c.memory.role == 'miner');
var noOfBuilder = _.sum(this.creeps, (c) => c.memory.role == 'builder');
var noOfCarrier = _.sum(this.creeps, (c) => c.memory.role == 'carrier');
this.noOfCreeps = this.creeps.length;
var noOfCreepsRenewing = _.sum(this.creeps, (c) => c.memory.renewing == true)
var noOfWorkers = noOfHarvesters + noOfBuilder;
this.sources = this.find(FIND_SOURCES);
this.noOfSources = _.sum(this.sources);
console.log('EnergyAvailable: ' + this.energyAvailable + ' of ' + this.energyCapacityAvailable );
console.log(this.name + ' - Creeps: ' + this.noOfCreeps + ', harvesters: ' + noOfHarvesters
+ ', Miners: ' + noOfMiners + ', Builder ' + noOfBuilder + ', Carrier ' + noOfCarrier + ', Renwing ' + noOfCreepsRenewing);
if (primaryRoom == false) { return };
/* Room Settings
*/
if (noOfMiners >= 1 && this.memory.ALLOW_HAVESTER == true) {
this.memory.ALLOW_HAVESTER = false;
}
if (noOfHarvesters > 0 && this.memory.ALLOW_HAVESTER == false) {
var harvesters = this.creeps = this.find(FIND_MY_CREEPS, {filter: (c) => {
return c.memory.role == 'harvester';
}})
for (var h in harvesters){
harvesters[h].newRole("builder");
}
}
/* spamn creeps
*/
if (this.energyAvailable == this.energyCapacityAvailable) {
MSBSpawnCreep('WORKER',noOfWorkers, this.memory.NumberOf_Min_WORKER, 'harvester', spawn, undefined)
MSBSpawnCreep('MINER',noOfMiners, this.memory.NumberOf_Target_MINER, 'miner', spawn, undefined)
MSBSpawnCreep('CARRIER',noOfCarrier, this.memory.NumberOf_Target_CARRIER, 'carrier', spawn, [CARRY,CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, WORK, MOVE, MOVE])
MSBSpawnCreep('WORKER',noOfWorkers, this.memory.NumberOf_Target_WORKER, 'harvester', spawn, undefined)
}
// Set memory
};
function MSBSpawnCreep(creepNamePrefix, currentNoOf, noOfCreepRequired, roleName, spawn, body) {
if ( currentNoOf < noOfCreepRequired) {
if (creepNamePrefix == 'WORKER') {
var r = spawn.createCreepWorker(creepNamePrefix,roleName);
console.log("Spwaming new worker - " + r);
} else if (creepNamePrefix == 'MINER') {
var r = spawn.createCreepMiner(creepNamePrefix, roleName);
console.log("Spwaming new miner - " + r);
} else if (body !== null) {
console.log(creepNamePrefix)
console.log(body)
var name = spawn.getNameName(creepNamePrefix);
console.log("Spwaming new creep - " + name)
console.log(spawn.spawnCreep(body, name, { memory: { role: roleName } }));
}
}
};
Room.prototype.newRoow = function () {
this.memory.roomInit = true;
this.memory.ALLOW_HAVESTER = true;
this.memory.NumberOf_Target_CARRIER = 0;
this.memory.NumberOf_Target_MINER = 2;
this.memory.NumberOf_Target_WORKER = 10;
this.memory.NumberOf_Min_WORKER = 2;
this.memory.MinWallHitPoint = params.DEFAULT_WALL_HITPOINT;
};
Room.prototype.getEnergyDropTarget = function (controller, pos) {
var target;
if (pos == null) {
var targets = this.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_EXTENSION ||
structure.structureType == STRUCTURE_SPAWN ||
structure.structureType == STRUCTURE_TOWER) && structure.energy < structure.energyCapacity;
}
});
if (targets.length > 0) {
target = targets[0];
}
} else {
target = pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_EXTENSION ||
structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity
||( structure.structureType == STRUCTURE_TOWER && (structure.energyCapacity - structure.energy) > 200 ) ;
}
});
}
if (controller == true && target == null) {
target = this.controller;
}
return target;
}
//_.sum(Game.creeps, (c) => c.memory.role == 'harvester');
/* Clear down any var used
*/
Room.prototype.cleanUp =function () {
this.creeps = undefined;
};
}