forked from shryme/Screeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sourceHarvester.js
122 lines (95 loc) · 3.05 KB
/
sourceHarvester.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
module.exports = function (creep) {
harvest(creep);
function harvest(creep) {
var sourceKeeper = Game.spawns.Spawn1.memory.sourceKeeperPos;
var pos = Game.spawns.Spawn1.room.getPositionAt(sourceKeeper.x, sourceKeeper.y);
var source = pos.findClosest(Game.SOURCES, {maxOps: 1000, ignoreDestructibleStructures: true, ignoreCreeps: true});
if (Game.spawns.Spawn1.memory.keeper_neutralized === true) {
creep.moveTo(source);
creep.harvest(source);
var carrier = creep.pos.findClosest(Game.MY_CREEPS, {
filter: function(object) {
return object.memory.role === 'source_carrier';
}
});
if(carrier && creep.pos.isNearTo(carrier)) {
creep.transferEnergy(carrier);
}
}
else {
creep.moveTo(46, 20);
}
}
}
// function build(creep) {
// var target = creep.pos.findClosest(Game.MY_STRUCTURES, {filter: function(object) {return object.structureType === Game.STRUCTURE_EXTENSION && object.energy < object.energyCapacity} });
// if (target) {
// creep.moveTo(target);
// creep.transferEnergy(target);
// }
// else {
// var targets = creep.room.find(Game.CONSTRUCTION_SITES);
// if(targets.length) {
// creep.moveTo(targets[0]);
// creep.build(targets[0]);
// }
// else {
// creep.moveTo(Game.spawns.Spawn1);
// creep.transferEnergy(Game.spawns.Spawn1);
// }
// }
// }
// module.exports = function (creep) {
// var isMining = false;
// var targets = creep.pos.findInRange(Game.SOURCES_ACTIVE, 1);
// if (targets.length > 0) {
// isMining = true;
// }
// if(creep.energy < creep.energyCapacity) {
// if (isMining || creep.energy === 0) {
// harvest(creep);
// }
// else {
// build(creep);
// }
// }
// else {
// if (creep.energy > 0)
// build(creep);
// else
// harvest(creep);
// }
// }
// function harvest(creep) {
// var sourceKeeper = Game.spawns.Spawn1.memory.sourceKeeperPos;
// var pos = Game.spawns.Spawn1.room.getPositionAt(sourceKeeper.x, sourceKeeper.y);
// var source = pos.findClosest(Game.SOURCES_ACTIVE, {maxOps: 1000, ignoreDestructibleStructures: true, ignoreCreeps: true});
// var targets = pos.findInRange(Game.HOSTILE_CREEPS, 3);
// var ticks = Game.spawns.Spawn1.pos.findClosest(Game.HOSTILE_STRUCTURES).ticksToSpawn;
// //var lair = Game.flags.SK.pos.findClosest(Game.HOSTILE_STRUCTURES).ticksToSpawn;
// if (Game.spawns.Spawn1.memory.keeper_neutralized === true) {
// creep.moveTo(source);
// creep.harvest(source);
// }
// else {
// creep.moveTo(46, 20);
// }
// }
// function build(creep) {
// var target = creep.pos.findClosest(Game.MY_STRUCTURES, {filter: function(object) {return object.structureType === Game.STRUCTURE_EXTENSION && object.energy < object.energyCapacity} });
// if (target) {
// creep.moveTo(target);
// creep.transferEnergy(target);
// }
// else {
// var targets = creep.room.find(Game.CONSTRUCTION_SITES);
// if(targets.length) {
// creep.moveTo(targets[0]);
// creep.build(targets[0]);
// }
// else {
// creep.moveTo(Game.spawns.Spawn1);
// creep.transferEnergy(Game.spawns.Spawn1);
// }
// }
// }