-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
156 lines (130 loc) · 6.43 KB
/
main.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleBuilder = require('role.builder');
var roleRepair = require('role.repair');
var roleDefender = require('role.defender');
var roleAttacker = require('role.attacker');
var roleNotifier = require('role.notifier');
var roleHarvesterExternal = require('role.harvester_external');
var roleHarvesterMineral = require('role.harvester_mineral');
var roleClaimer = require('role.claimer');
var roleFiller = require('role.filler');
var roleExplorer = require('role.explorer');
var roleLib = require('roleLib');
var mapLib = require('mapLib');
var structureTower = require('structure.tower');
var structureLink = require('structure.link');
var harvester_spawn = 3;
var harvester_external_spawn = 4;
var harvester_mineral_spawn = 1;
var upgrader_spawn = 3;
var builder_spawn = 0;
var repair_spawn = 0;
var defender_spawn = 2;
var claimer_spawn = 0;
var filler_spawn = 0;
if (!mapLib.getRoomList().length) {
mapLib.mapRoomsAroundStart(Game.spawns.Spawn1.room.name);
}
//mapLib.getRoomListClaimable().forEach(el => console.log(el.name));
//console.log(mapLib.getNextClaimableRoom("Next: " + Game.spawns.Spawn1.room.name));
//console.log(mapLib.getUnvisitedRooms().forEach(el => console.log(el.name)));
//console.log(mapLib.getGCLClaimsAvailable());
//console.log(mapLib.getRoomsWithUnbuildSpawn());
//mapLib.getRoomList().forEach(el => el.visited = false)
module.exports.loop = function () {
let mapRooms = mapLib.getRoomListClaimable();
var role_Harvesters = _.filter(Game.creeps, (creep) => creep.memory.role === 'harvester');
var role_Harvesters_External = _.filter(Game.creeps, (creep) => creep.memory.role === 'harvester_external');
var role_Harvesters_Mineral = _.filter(Game.creeps, (creep) => creep.memory.role === 'harvester_mineral');
var role_Builders = _.filter(Game.creeps, (creep) => creep.memory.role === 'builder');
var role_Upgraders = _.filter(Game.creeps, (creep) => creep.memory.role === 'upgrader');
var role_Repairs = _.filter(Game.creeps, (creep) => creep.memory.role === 'repair');
var role_Defenders = _.filter(Game.creeps, (creep) => creep.memory.role === 'defender');
var role_Claimers = _.filter(Game.creeps, (creep) => creep.memory.role === 'claimer');
var role_Fillers = _.filter(Game.creeps, (creep) => creep.memory.role === 'filler');
var role_Explorer = _.filter(Game.creeps, (creep) => creep.memory.role === 'explorer');
for (let spawns in Game.spawns) {
let spawn = Game.spawns[spawns];
let room = spawn.room;
var room_Upgraders = _.filter(role_Upgraders, (creep) => creep.memory.room_dest === room.name);
var room_Harvesters = _.filter(role_Harvesters, (creep) => creep.memory.room_dest === room.name);
var room_Harvesters_Mineral = _.filter(role_Harvesters_Mineral, (creep) => creep.memory.room_dest === room.name);
var room_Builders = _.filter(role_Builders, (creep) => creep.memory.room_dest === room.name);
var room_Repairs = _.filter(role_Repairs, (creep) => creep.memory.room_dest === room.name);
var room_Defenders = _.filter(role_Defenders, (creep) => creep.memory.room_dest === room.name);
var room_Fillers = _.filter(role_Fillers, (creep) => creep.memory.room_dest === room.name);
var room_Explorer = role_Explorer;
//HARVESTER
roleLib.spawnHarvester(spawn, room, room_Harvesters.length, harvester_spawn);
//HARVESTER_MINERAL
//roleLib.spawnHarvesterMinderal();
//UPGRADER
roleLib.spawnUpgrader(spawn, room, room_Upgraders.length, upgrader_spawn, room_Harvesters.length);
//BUILDER
roleLib.spawnBuilder(spawn, room, room_Builders.length, builder_spawn, room_Harvesters.length);
//FILLER
roleLib.spawnFiller(spawn, room, room_Fillers.length, filler_spawn, room_Harvesters.length);
//EXPLORER
if (mapLib.getUnvisitedRooms().length) {
roleLib.spawnExplorer(spawn, null, room_Explorer.length, mapLib.getGCLClaimsAvailable() ? mapLib.getGCLClaimsAvailable() : 5, room_Harvesters.length);
}
for (let x = 0; x < mapRooms.length; x++) {
var room_Harvesters_External = _.filter(role_Harvesters_External, (creep) => creep.memory.room_dest == mapRooms[x].name);
var room_Claimers = _.filter(role_Claimers, (creep) => creep.memory.room_dest === mapRooms[x].name);
//HARVESTER_EXTERNAL
roleLib.spawnHarvesterExternal(spawn, mapLib.getNextClaimableRoom(room.name), room_Harvesters_External.length, harvester_external_spawn);
//CLAIMER
roleLib.spawnClaimer(spawn, mapLib.getNextClaimableRoom(room.name), room_Claimers.length, mapLib.getGCLClaimsAvailable() / 2, room_Harvesters.length);
}
}
for (let name in Memory.creeps) {
if (!Game.creeps[name]) {
delete Memory.creeps[name];
console.log('Clearing non-existing creep memory:', name);
}
}
for (let rooms in Game.rooms) {
let room = Game.rooms[rooms];
structureTower.run(room);
structureLink.run(room);
}
for (let name in Game.creeps) {
let creep = Game.creeps[name];
switch (creep.memory.role) {
case 'harvester':
roleHarvester.run(creep);
break;
case 'harvester_external':
roleHarvesterExternal.run(creep);
break;
case 'harvester_mineral':
roleHarvesterMineral.run(creep);
break;
case 'upgrader':
roleUpgrader.run(creep);
break;
case 'builder':
roleBuilder.run(creep);
break;
case 'repair':
roleRepair.run(creep);
break;
case 'defender':
roleDefender.run(creep);
break;
case 'attacker':
roleAttacker.run(creep);
break;
case 'claimer':
roleClaimer.run(creep);
break;
case 'filler':
roleFiller.run(creep);
break;
case 'explorer':
roleExplorer.run(creep);
break;
}
}
};