-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_wallofranged.js
89 lines (59 loc) · 2.66 KB
/
job_wallofranged.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
/**
* creepFactory
*/
var job_wallofranged = {
increase: function(spawn,job,increase,role) {
job.jobmemory[role+'s']=job.jobmemory[role+'s']+increase;
},
decrease: function(spawn,job,decrease,role) {
job.jobmemory.rangers=job.jobmemory.rangers-decrease;
for (var x = job.jobmemory.rangers; x < 0; x--) {
console.log(x);
job.jobmemory.ranger[x]=null;
var creep = Game.getObjectById(job.jobmemory.ranger[x]);
creep.memory.job_active='false';
creep.memory.job_pos=null;
creep.memory.job=null;
job.jobmemory.ranger.splice(x,1);
}
},
action: function (spawn,job) {
//console.log ("Ranged Job: Rangers=" + job.jobmemory.rangers);
var roles=['ranger','healer'];
for (var i in roles){
var role = roles[i];
// If this is a new JOB, init the job
if(!job.jobmemory[role]){
job.jobmemory.health = 'starting';
job.jobmemory[role] = new Array();
for (var x = 0; x < job.jobmemory[role+'s']; x++) {
// Find or make creeps needed for Job
require('jobManager').initJobCreepAllocator(spawn,job,role,x);
}
// If this job is not new
} else {
var numCreeps = 0;
// Check if we need creeps (creep died, or size changed)
for (var x = 0; x < job.jobmemory[role+'s']; x++) {
// Find or make creeps needed for Job
require('jobManager').initJobCreepAllocator(spawn,job,role,x);
// TODO: put logic in here to free up creeps on this job if job shrinks or gets deleted
//If we are waiting on spawning, look for new creep
if (job.jobmemory[role][x]=='spawning'){
require('jobManager').initJobCreepSpawnChecker(spawn,job,role,x);
//If we have a creep, use the creep
} else {
//TODO: Need to move numCreeps to memory and fix logic in/out functions
var haveCreep=require('jobManager').handleCreepActions(spawn,job,role,x);
numCreeps=numCreeps+haveCreep;
}
} // end for loop
//Check if we have all the desired creeps
if (numCreeps==job.jobmemory[role+'s']){
job.jobmemory.health = 'healthy';
}
} //end else
} //end roles for loop
} //end action
};
module.exports = job_wallofranged;