-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
84 lines (66 loc) · 2.73 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
require('prototype.spawn')();
require('prototype.creep')();
require('prototype.tower')();
require('prototype.container')();
module.exports.loop = function () {
//Delete Memory from dead creeps
for(var name in Memory.creeps) {
if(!Game.creeps[name]) {
let creep = Memory.creeps[name];
if(creep.role == 'miner'){
Memory.containers[creep.container].hasMiner = false;
}else if(creep.role == 'lorry'){
Memory.containers[creep.container].hasLorry = false;
}
console.log(creep.role + " " + name + " died.");
delete Memory.creeps[name];
}
}
//Default run logic for all towers.
for(let tower of _.filter(Game.structures, (s) => s.structureType == STRUCTURE_TOWER)){
tower.run();
}
//Try to spawn creep, if it's necessary.
for(let spawn in Game.spawns){
let containers = Game.spawns[spawn].room.find(FIND_STRUCTURES, {filter: (s) => s.structureType == STRUCTURE_CONTAINER});
//Register new container
for(let containerName in containers){
let container = containers[containerName];
if(Memory.containers == undefined){
Memory.containers = {};
}
if(Memory.containers[container.id] == undefined){
Memory.containers[container.id] = {hasMiner: false, hasLorry: false};
}
//Check if they need to be closed.
if(container.store[RESOURCE_ENERGY] <= 100){
container.setClosed();
}else if(container.store[RESOURCE_ENERGY] >= 300){
container.setOpened();
}
}
Game.spawns[spawn].tryToSpawnCreep();
//If hostiles are in my room, capable of attack, activate the safe mode (or at least try).
let hostiles = Game.spawns[spawn].room.find(FIND_HOSTILE_CREEPS,
{filter: (c) => Memory.rooms[Game.spawns[spawn].room.name].tripwireTriggered == true
|| c.owner.username != 'jueyanyingyu'});
for(creep in hostiles){
if(hostiles[creep].body.some(function(bodyPart) {
if(bodyPart.type == ATTACK || bodyPart.type == RANGED_ATTACK){
return true;
}
}) == true)
{
console.log('ATTENTION');
if(Game.spawns[spawn].room.controller.activateSafeMode() == OK){
Game.notify('Safe Mode activated in response to hostile creeps from' + hostiles[creep].owner);
}
break;
}
}
}
//Default run logic for all creeps.
for(var name in Game.creeps) {
Game.creeps[name].run();
}
}