forked from VladThePaler/screeps.behaviour-action-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreep.setup.worker.js
106 lines (106 loc) · 3.89 KB
/
creep.setup.worker.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
let setup = new Creep.Setup('worker');
module.exports = setup;
setup.maxWorker = room => {
// no hauler and no miner => 1
// if there is a miner it should be no problem to spawn a hauler, and vice versa.
// if none of them are present spawn a worker first
if( !setup.hasMinerOrHauler(room))
return 1;
// constructionsites present & no strorage or storage > min
if( room.constructionSites.length > 0 && (!room.storage
|| room.storage.store && room.storage.store.energy > MIN_STORAGE_ENERGY[room.controller.level]))
return 1;
// storage full & base fortifyable
if( room.storage && room.storage.store.energy > MAX_STORAGE_ENERGY[room.controller.level] && room.structures.fortifyable.length > 0 )
return 1;
return 0;
};
// validates if there is a miner or a hauler present
setup.hasMinerOrHauler = room => ( room.population &&
((room.population.typeCount['hauler'] && room.population.typeCount['hauler'] > 0) ||
(room.population.typeCount['miner'] && room.population.typeCount['miner'] > 0 )));
// this assures that the first worker gets spawned immediately, but later workers require more energy, giving preference to miners
setup.byPopulation = function(type, start, perBody, limit) {
return function(room) {
const result = start + (room.population && (room.population.typeCount[type] * perBody) || 0);
if( !limit || result <= limit ) {
return result;
} else {
return limit;
}
};
};
setup.RCL = {
1: {
fixedBody: [],
multiBody: [CARRY, WORK, MOVE],
minAbsEnergyAvailable: 200,
minEnergyAvailable: setup.byPopulation(setup.type, 0, 1, 1),
maxMulti: 8,
maxCount: room => ( room.situation.invasion ) ? 1 : 4,
maxWeight: 4000
},
2: {
fixedBody: [],
multiBody: [CARRY, WORK, MOVE],
minAbsEnergyAvailable: 200,
minEnergyAvailable: setup.byPopulation(setup.type, 0, 0.5, 1),
maxMulti: 8,
maxCount: room => ( room.situation.invasion ) ? 1 : 6,
maxWeight: 14400
},
3: {
fixedBody: [],
multiBody: [CARRY, WORK, MOVE],
minAbsEnergyAvailable: 200,
minEnergyAvailable: room => setup.hasMinerOrHauler(room) ? 0.3 : 0,
maxMulti: 8,
maxCount: room => ( room.situation.invasion ) ? 1 : 4,
maxWeight: 9600
},
4: {
fixedBody: [],
multiBody: [CARRY, WORK, MOVE],
minAbsEnergyAvailable: 200,
minEnergyAvailable: room => setup.hasMinerOrHauler(room) ? 0.3 : 0,
maxMulti: 8,
maxCount: (room) => ( room.situation.invasion || room.storage ) ? setup.maxWorker(room) : 2,
maxWeight: 4800
},
5: {
fixedBody: [],
multiBody: [CARRY, WORK, MOVE],
minAbsEnergyAvailable: 400,
minEnergyAvailable: room => setup.hasMinerOrHauler(room) ? 0.3 : 0,
maxMulti: 8,
maxCount: room => setup.maxWorker(room),
maxWeight: 2000
},
6: {
fixedBody: [],
multiBody: [CARRY, WORK, MOVE],
minAbsEnergyAvailable: 600,
minEnergyAvailable: room => setup.hasMinerOrHauler(room) ? 0.3 : 0,
maxMulti: 8,
maxCount: room => setup.maxWorker(room),
maxWeight: 2000
},
7: {
fixedBody: [],
multiBody: [CARRY, WORK, MOVE],
minAbsEnergyAvailable: 800,
minEnergyAvailable: room => setup.hasMinerOrHauler(room) ? 0.2 : 0,
maxMulti: 10,
maxCount: room => setup.maxWorker(room),
maxWeight: 2000
},
8: {
fixedBody: [],
multiBody: [CARRY, WORK, MOVE],
minAbsEnergyAvailable: 800,
minEnergyAvailable: room => setup.hasMinerOrHauler(room) ? 0.1 : 0,
maxMulti: room => (( !room.storage || room.storage.energy > MAX_STORAGE_ENERGY[8] ) ? 16 : 10),
maxCount: room => setup.maxWorker(room),
maxWeight: 3200
}
};