-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnippets
150 lines (137 loc) · 4.38 KB
/
snippets
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
function scrounge(creep) {
// TODO every 5 ticks or so we should check there is still something at the
// stored tile
// Otherwise any time something is dropped you might pull a bunch of
// gatherers without need.
// See if we are already on the move
//
//
// var nrg = creep.pos.findClosestByPath(FIND_DROPPED_RESOURCES);
// if (creep.pos.isNearTo(nrg)){
// creep.pickup(nrg);
// } else {
// creep.moveTo(nrg)}
//
// return
//
if (!util.def(creep.memory.targetUpdated)) {
creep.memory.targetUpdated = 0;
} else if (!util.def(creep.memory.eTarget) && creep.memory.targetUpdated + 90 < Game.time) {
// We already checked not too long ago, there isn't anything here
return false;
}
//
if (!util.def(creep.memory.eTarget) ||
!util.def(Game.getObjectById(creep.memory.eTarget)) ||
(creep.memory.targetUpdated + 90) < Game.time) { // If I
// don't
// have
// a
// target,
// get
// one
var res = findEnergy(creep);
if (!util.def(res) || !res) {
// No energy. Mark it and remember
delete creep.memory.eTarget;
creep.memory.targetUpdated = Game.time;
return false
}
// dlog('assigning new free energy target: ' + creep.name);
creep.memory.eTarget = res;
creep.memory.targetUpdated = Game.time;
}
var target = Game.getObjectById(creep.memory.eTarget);
// util.dumpObject(target)
if (!util.def(target)) {
dlog('zomg')
}
dlog('scrounging')
var res = creep.hitUp(target);
// TODO: possibly reuse path found earlier for more efficiency
switch (res) {
case OK:
case ERR_FULL:
return true;
break;
case ERR_NOT_IN_RANGE:
var move = creep.moveTo(target, {
reusePath: 15,
visualizePathStyle: {
fill: 'green',
stroke: '#00ff00',
strokeWidth: .3,
opacity: .9,
lineStyle: 'dashed'
}
});
// {
// fill: 'transparent',
// stroke: '#fff',
// lineStyle: 'dashed',
// strokeWidth: .15,
// opacity: .1
// }
// width number
// Line width, default is 0.1.
// color string
// Line color in any web format, default is #ffffff (white).
// opacity number
// Opacity value, default is 0.5.
// lineStyle string
// Either undefined (solid line), dashed, or dotted. Default is undefined.
// // if (move == ERR_NO_PATH) {
// delete creep.memory.eTarget;
// dlog('hmm');
// return false;
// }
return true;
break;
case ERR_NOT_ENOUGH_ENERGY:
delete creep.memory.eTarget;
return false;
break;
default:
// delete creep.memory.eTarget;
dlog("Error scrounging: " + util.getError(res) + ' ---- ' + res);
}
dlog('not quote sure how i got here but oh well')
delete creep.memory.eTarget;
return false
}
module.exports.scrounge = scrounge;
// function retask(room, type, role) {
// // special cases stuff. Maybe find a beter way to do this
// if( role == 'builder')
// { var targets = room.find(FIND_MY_CONSTRUCTION_SITES);
// if (targets.length < 1) {return}}
//
// var roomCreeps = room.find(FIND_MY_CREEPS);
// // dlog('was told to retask all ' + type + ' to do ' + role)
// for ( var i in roomCreeps) {
// var youThere = roomCreeps[i];
// var yourJob = youThere.memory.role;
// var taskList = youThere.memory.taskList;
// if (util.def(yourJob) && (yourJob == type)
// && (taskList[taskList.length - 1] != role)) {
// // Check the latest task isn't already set to type
// dlog('preempting creep ' + youThere.name + ' task list to ' + role);
//
// youThere.memory.taskList.push(role)
// }
// }
// }
// module.exports.retask = retask
//
// Room.prototype.getSpawning = function() {
// var babbysForming = {};
// var spawns = this.find(FIND_MY_SPAWNS);
// for ( var n in spawns) {
// var spawn = spawns[n];
// if (util.def(spawn.spawning)) {
// babbysForming[spawn.spawning.name] = true;
// }
// }
//
// return babbysForming;
// }