forked from shryme/Screeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlazy_harvester_factory.js
90 lines (68 loc) · 3.07 KB
/
lazy_harvester_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
var listAllBus = Game.spawns.Spawn1.room.memory.listAllBus;
var listAllHarvester = Game.spawns.Spawn1.room.memory.listAllHarvester;
function getListOfOpenPos(type, currentList) {
var newList = new Array();
var listToFill;
if (type === 'bus')
listToFill = listAllBus;
else
listToFill = listAllHarvester;
for (var i = 0; i < listToFill.length; i++) {
var x = listToFill[i].toGo.x;
var y = listToFill[i].toGo.y;
var isUsed = false;
for (var j = 0; j < currentList.length; j++) {
if (currentList[j].toGo.x === x && currentList[j].toGo.y === y) {
isUsed = true;
break;
}
}
if (!isUsed)
newList.push(listToFill[i]);
}
return newList;
}
module.exports = {
isDone: function(nbHarvester, nbBus, listBus, listHarvester) {
//Calculate the path to take to go to the nearest source
if (listAllBus === undefined) {
listAllBus = new Array();
listAllHarvester = new Array();
var source = Game.spawns.Spawn1.pos.findClosest(Game.SOURCES_ACTIVE, {maxOps: 1000, ignoreDestructibleStructures: true, ignoreCreeps: true});
Game.spawns.Spawn1.memory.path = Game.spawns.Spawn1.room.findPath(Game.spawns.Spawn1.pos, source.pos, {maxOps: 3000, ignoreDestructibleStructures: true, ignoreCreeps: true});
var path = Game.spawns.Spawn1.memory.path;
for (var i = 0; i < path.length - 1; i++) {
if (i === 0) {
listAllHarvester.push({toGo: path[path.length - 2], toDrop: path[path.length - 3]});
listAllHarvester.push({toGo: {x: path[path.length - 2].x, y: path[path.length - 2].y - 1}, toDrop: path[path.length - 2]});
}
else {
var currentPath = {toGo: path[path.length - 2 - i], toDrop: path[path.length - 3 - i]}
listAllBus.push(currentPath);
}
}
Game.spawns.Spawn1.room.memory.listAllBus = listAllBus;
Game.spawns.Spawn1.room.memory.listAllHarvester = listAllHarvester;
}
//Gets the positions that are currently open and that needs to be filled
var listNewPos = getListOfOpenPos('bus', listBus);
var listNewHarvesterPos = getListOfOpenPos('harverster', listHarvester);
//First create the first harvester, then all the transporters, then the rest of the harvester
if (nbHarvester < 1 && listNewHarvesterPos.length > 0) {
Game.spawns.Spawn1.createCreep([Game.WORK, Game.WORK, Game.WORK, Game.CARRY, Game.MOVE], undefined,
{role: 'lazy_harvester', toGo: listNewHarvesterPos[0].toGo, toDrop: listNewHarvesterPos[0].toDrop}); //160
}
else if (listNewPos !== undefined && listNewPos.length > 0) {
Game.spawns.Spawn1.createCreep([Game.CARRY, Game.MOVE], undefined,
{role: 'bus', toGo: listNewPos[0].toGo, toDrop: listNewPos[0].toDrop}); //100
}
else if (listNewHarvesterPos.length > 0) {
Game.spawns.Spawn1.createCreep([Game.WORK, Game.WORK, Game.WORK, Game.CARRY, Game.MOVE], undefined,
{role: 'lazy_harvester', toGo: listNewHarvesterPos[0].toGo, toDrop: listNewHarvesterPos[0].toDrop}); //160
}
else {
return true
}
return false;
}
}