-
Notifications
You must be signed in to change notification settings - Fork 0
/
role_mover.js
76 lines (56 loc) · 2.3 KB
/
role_mover.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
var role_mover = {
//TODO
base: function(creep) {
if (creep.memory.job_active!='true'){
if(creep.energy < 1) {
var target = creep.pos.findNearest(Game.DROPPED_ENERGY);
creep.moveTo(target);
creep.pickup(target);
}
else {
creep.moveTo(Game.spawns.Spawn1);
creep.transferEnergy(Game.spawns.Spawn1);
}
}
},
mine_normal: function(creep,job,spot,spawn) {
//creep.moveTo(job.jobmemory.x+spot,job.jobmemory.y);
var source = Game.getObjectById(job.jobmemory.source);
var miner = Game.getObjectById(job.jobmemory.miner[0]);
var target = source.pos.findNearest(Game.DROPPED_ENERGY);
// if miner isn't in danger
if (miner && creep.energy < creep.energyCapacity && job.jobmemory.danger=="false") {
// check if miner is near the source
var targets = miner.pos.findInRange(Game.SOURCES, 1);
// if yes
if(targets.length > 0) {
//if source has energy, move to miner
if (targets[0].energy>1){
creep.moveTo(miner);
//if source has no energy, move to nearest energy on ground
} else {
creep.moveTo(target);
}
} else {
//creep.moveTo(source.pos.x+5,source.pos.y-8);
creep.moveTo(target);
}
creep.pickup(target);
// if miner is in danger, move to safe area
} else if (creep.energy < creep.energyCapacity && job.jobmemory.danger=="true") {
creep.moveTo(source.pos.x+5,source.pos.y-8);
// if miner is dead
} else if (!miner && creep.energy < creep.energyCapacity) {
//creep.moveTo(source.pos.x+5,source.pos.y-8);
creep.moveTo(target);
creep.pickup(target);
// if mover is full, bring back energy
} else {
//creep.moveTo(Game.spawns.Spawn1);
//creep.transferEnergy(Game.spawns.Spawn1);
creep.moveTo(spawn);
creep.transferEnergy(spawn);
}
}
};
module.exports = role_mover;