-
Notifications
You must be signed in to change notification settings - Fork 38
/
creep.action.picking.js
30 lines (28 loc) · 1.03 KB
/
creep.action.picking.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
var action = new Creep.Action('picking');
action.isValidAction = function(creep){
return ( _.sum(creep.carry) < creep.carryCapacity );
};
action.isAddableAction = function(creep){
return (!creep.room.activities[this.name] || creep.room.activities[this.name] < creep.room.maxPerJob+1); // TODO: compare amount with carry size of assigned creeps
};
action.isValidTarget = function(target){
return (target != null && target.amount != null && target.amount > 0);
};
action.newTarget = function(creep){
var target = creep.pos.findClosestByPath(FIND_DROPPED_RESOURCES, {
filter: (o) => ( o.resourceType != RESOURCE_ENERGY && this.isAddableTarget(o))
});
if( target == null ) target = creep.pos.findClosestByPath(FIND_DROPPED_ENERGY, {
filter: (o) => this.isAddableTarget(o)
});
return target;
};
action.work = function(creep){
var result = creep.pickup(creep.target);
if( result == OK ){
// unregister
creep.action = null;
}
return result;
};
module.exports = action;