-
Notifications
You must be signed in to change notification settings - Fork 0
/
upkeep.js
98 lines (81 loc) · 2.25 KB
/
upkeep.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
const Role = require("constants");
const UI = require("ui.utils");
const PartsValue = {
move: 50,
work: 100,
carry: 50,
attack: 80,
ranged_attack: 150,
heal: 250,
claim: 600,
tough: 10
};
const sortedRoles = [
Role.HARVESTER,
Role.UPGRADER,
Role.FIXER,
Role.BUILDER,
Role.WALLER,
Role.AMMO
];
const getNumberOfBuilders = spawn => {
const numberOfConstructionSites = spawn.room.find(FIND_CONSTRUCTION_SITES).length;
if (numberOfConstructionSites > 15) return 2;
return numberOfConstructionSites > 0 ? 1 : 0;
};
const getNumberOfAmmos = spawn => {
const towers = spawn.room.find(FIND_MY_STRUCTURES, {
filter: structure =>
structure.structureType === STRUCTURE_TOWER &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0
});
return !!towers.length ? 1 : 0;
};
const getParts = (part, number) => new Array(number).fill(part);
const baseParts = [CARRY, ...getParts(WORK, 2), ...getParts(MOVE, 3), ...getParts(TOUGH, 5)];
const RoleValues = spawn => ({
[Role.HARVESTER]: {
parts: [...baseParts, ...getParts(WORK, 6), ...getParts(MOVE, 6), ...getParts(CARRY, 2)],
// parts: [WORK, MOVE, CARRY],
maxUnits: 5
},
[Role.BUILDER]: {
parts: baseParts,
maxUnits: getNumberOfBuilders(spawn)
},
[Role.FIXER]: {
parts: [...baseParts, WORK, MOVE, MOVE],
maxUnits: 1
},
[Role.WALLER]: {
parts: [...baseParts, WORK, MOVE, MOVE],
maxUnits: 1
},
[Role.MOVER]: {
parts: [...baseParts, CARRY, CARRY, MOVE],
maxUnits: 0
},
[Role.UPGRADER]: {
parts: [...baseParts, ...getParts(WORK, 3), ...getParts(CARRY, 3)],
maxUnits: 2
},
[Role.AMMO]: {
parts: baseParts,
maxUnits: getNumberOfAmmos(spawn)
}
});
const getCostForParts = parts => parts.reduce((sum, value) => (sum += PartsValue[value]), 0);
const upkeep = spawn => {
sortedRoles.forEach((role, index) => {
const { parts, maxUnits } = RoleValues(spawn)[role];
UI.displayCreepCost(spawn, role, getCostForParts(parts), index);
const units = _.filter(Game.creeps, creep => creep.memory.role == role);
if (units.length < maxUnits && !spawn.spawning) {
const name = role + Game.time;
spawn.spawnCreep(parts, name, {
memory: { role }
});
}
});
};
module.exports = upkeep;