-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroom.define.js
More file actions
101 lines (87 loc) · 3.73 KB
/
Copy pathroom.define.js
File metadata and controls
101 lines (87 loc) · 3.73 KB
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
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports.thing = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('room');
* mod.thing == 'a thing'; // true
*/
module.exports = {
run: function(room) {
//find all sources
var sources = room.find(FIND_SOURCES);
//find all spawns and add them to room's memory
var spawnsInRoom = room.find(FIND_MY_SPAWNS);
room.memory.spawns = {};
for (var i in spawnsInRoom) {
room.memory.spawns[spawnsInRoom[i].id] = spawnsInRoom[i].memory; // link spawn.memory to room.spawns.{id}
}
//find the room controller
var controller = room.find(FIND_MY_STRUCTURES,{filter: (s) => s.structureType == STRUCTURE_CONTROLLER});
controller = controller[0];
room.memory.controller = {};
room.memory.controller[controller.id] = {level:controller.level};
//find all towers
var towers = room.find(FIND_MY_STRUCTURES,{filter: (s) => s.structureType == STRUCTURE_TOWER})
//find all containers
var containers = room.find(FIND_STRUCTURES,{ filter: (s) => s.structureType == STRUCTURE_CONTAINER});
//assign containers to source
for (var i in containers) {
var c = containers[i];
room.visual.text(c.memory.role+":"+c.store[RESOURCE_ENERGY], c.pos.x,c.pos.y+1, {color: 'white', font: 0.4, align:'center'});
for (var s in sources) {
if (c.pos.isNearTo(sources[s])) {
sources[s].memory.container = c.id;
c.memory.role = 'mining';
c.memory.source = sources[s].id;
}
}
if (!c.memory.source) {
c.memory.role = 'storage';
}
}
// Clearing non-existing containers
for(var id in room.memory.containers) {
if(!Game.getObjectById(id)) {
console.log('Clearing non-existing containers memory: '+room.name+" - "+Game.getObjectById(id));
delete Memory.rooms[room.name].containers[id];
}
}
//find all extractors
var extractors = room.find(FIND_MY_STRUCTURES,{ filter: (s) => s.structureType == STRUCTURE_EXTRACTOR});
room.memory.extractors = extractors.length;
//find all storage
var storages = room.find(FIND_STRUCTURES,{ filter: (s) => s.structureType == STRUCTURE_STORAGE});
for (var i in storages) {
room.visual.text(storages[i].store[RESOURCE_ENERGY], storages[i].pos.x,storages[i].pos.y, {color: 'white', font: 0.4, align:'center'});
}
//find all links
var links = room.find(FIND_MY_STRUCTURES,{ filter: (s) => s.structureType == STRUCTURE_LINK});
//console.log(JSON.stringify(links));
for (var l in links) {
if (links[l].pos.inRangeTo(room.controller.pos,3)) {
links[l].memory.role = 'controller';
} else {
links[l].memory.role = 'storage';
}
}
//find all FIND_CONSTRUCTION_SITES
var constructionSites = room.find(FIND_CONSTRUCTION_SITES);
var constructionSitesProgress = 0;
var constructionSitesProgressTotal = 0;
for (var i in constructionSites) {
room.visual.text(constructionSites[i].progress+"/"+constructionSites[i].progressTotal, constructionSites[i].pos.x,constructionSites[i].pos.y, {color: 'white', font: 0.25, align:'center'});
constructionSitesProgress += constructionSites[i].progress
constructionSitesProgressTotal += constructionSites[i].progressTotal;
}
room.memory.constructionSites = {};
room.memory.constructionSites.progress = constructionSitesProgress;
room.memory.constructionSites.progressTotal = constructionSitesProgressTotal;
/* TO DO
* add towers
* add spawns
*
*
*/
}
};