-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototype.Structure.js
More file actions
96 lines (90 loc) · 2.05 KB
/
prototype.Structure.js
File metadata and controls
96 lines (90 loc) · 2.05 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
Object.defineProperty(Source.prototype, 'memory', {
get: function() {
if(Memory.structures[this.id] === undefined){
Memory.structures[this.id] = {}
}
return Memory.sources[this.id]
},
enumerable: false,
configurable: true
});
Object.defineProperty(Structure.prototype, 'stored', {
get: function() {
if(!this.store){
return 100
}
let used = 0
for(let resource of RESOURCES_ALL){
used += this.store.getUsedCapacity(resource)
}
return used
},
enumerable: false,
configurable: true
});
Object.defineProperty(Structure.prototype, 'capacity', {
get: function() {
if(!this.store){
return 0
}
return this.store.getCapacity(RESOURCE_ENERGY)
},
enumerable: false,
configurable: true
});
Object.defineProperty(Structure.prototype, 'usage', {
get: function() {
if(!this.store){
return 100
}
let struct = this
let withdrawl = 0
let deposit = 0
let net = struct.stored
let capacity = struct.capacity
_.forEach(Memory.taskQueue, function(t){
if(t.dest == struct.id){
let target = genRoom.getObject(t.target)
if(t.type == "deposit"){
deposit += target.stored
}
if(t.type == "withdrawl"){
withdrawl -= target.capacity
}
}
})
net = net + deposit - withdrawl
return (net/capacity) * 100
},
enumerable: false,
configurable: true
});
Object.defineProperty(Structure.prototype, 'netEnergy', {
get: function() {
if(!this.store){
return 0
}
return this.store.getUsedCapacity(RESOURCE_ENERGY)
},
enumerable: false,
configurable: true
});
Object.defineProperty(Structure.prototype, 'energyCapacity', {
get: function() {
if(!this.store){
return 0
}
return this.store.getFreeCapacity(RESOURCE_ENERGY)
},
enumerable: false,
configurable: true
});
Structure.prototype.targeted = function() {
let targetList = []
_.forEach(Memory.creeps, (creep, id) => {
if(creep.target == this.id){
targetList.push(Game.creeps[id])
}
})
return targetList
}