-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathcreep.action.feeding.js
25 lines (25 loc) · 1.07 KB
/
creep.action.feeding.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
var action = new Creep.Action('feeding');
action.maxPerTarget = 1;
action.isValidAction = function(creep){
return ( creep.carry.energy > 0 && creep.room.energyAvailable < creep.room.energyCapacityAvailable );
};
action.isValidTarget = function(target){
return ( (target != null) && (target.energy != null) && (target.energy < target.energyCapacity) );
};
action.isAddableAction = function(creep){
return (!creep.room.activities[this.name] || creep.room.activities[this.name] < (creep.room.maxPerJob * (creep.room.relativeEnergyAvailable < HIVE_ENERGY_URGENT ? 2 : 1)) );
};
action.newTarget = function(creep){
var self = this;
return creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (structure) => {
return ((structure.structureType == STRUCTURE_EXTENSION ||
structure.structureType == STRUCTURE_SPAWN )
&& self.isValidTarget(structure) && self.isAddableTarget(structure));
}
});
};
action.work = function(creep){
return creep.transfer(creep.target, RESOURCE_ENERGY);
};
module.exports = action;