-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.js
More file actions
102 lines (100 loc) · 3.98 KB
/
helper.js
File metadata and controls
102 lines (100 loc) · 3.98 KB
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
module.exports = {
clean: function () {
var toReturn = false;
// Always place this memory cleaning code at the very top of your main loop!
for (var name in Memory.creeps) {
if (!Game.creeps[name]) {
delete Memory.creeps[name];
console.log('Clearing non-existing creep memory:', name);
toReturn = true;
}
}
return toReturn;
},
getTarget: function (creep, type, ressource) {
if (creep === undefined || type == undefined) {
return false;
}
var object=null;
switch (type) {
case 'spawner': {
object = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&structure.energy < structure.energyCapacity;
}
});
if(object===null)
{
return false;
}
creep.memory.path = creep.pos.findPathTo(object.pos);
creep.memory.object =object.id;
creep.memory.lastfind='spawner';
creep.memory.range = creep.memory.path.length;
return true;
break;
}
case 'tower': {
object = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_TOWER) &&structure.energy < structure.energyCapacity;
}
});
if(object===null)
{
return false;
}
creep.memory.path = creep.pos.findPathTo(object.pos);
creep.memory.object =object.id;
creep.memory.lastfind='tower';
creep.memory.range = creep.memory.path.length;
return true;
break;
}
case 'construction': {
object = creep.pos.findClosestByPath(FIND_CONSTRUCTION_SITES);
if(object===null)
{
return false;
}
creep.memory.path = creep.pos.findPathTo(object.pos);
creep.memory.object =object.id;
creep.memory.lastfind='construction';
creep.memory.range = creep.memory.path.length;
return true;
break;
}
case 'repair':{
object = creep.pos.findClosestByRange(FIND_STRUCTURES, {
filter: function (object) {
if (((object.structureType === STRUCTURE_ROAD || object.structureType === STRUCTURE_STORAGE || object.structureType=== STRUCTURE_CONTAINER ) && object.hits < object.hitsMax *0.95) || (object.structureType === STRUCTURE_WALL || object.structureType === STRUCTURE_RAMPART) && object.hits<500000) {
return true;
}
return false;
}
});
if(object===null)
{
return false;
}
creep.memory.path = creep.pos.findPathTo(object.pos);
creep.memory.object =object.id;
creep.memory.lastfind='repair';
creep.memory.range = creep.memory.path.length;
return true;
break;
}
case 'controller':
{
var controller = creep.room.controller;
creep.memory.path = creep.pos.findPathTo(controller);
creep.memory.object =object;
creep.memory.lastfind='controller';
creep.memory.range = creep.memory.path.length;
return true;
break;
}
}
return false;
}
};