-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathbunkerLayoutsHumanReadable.js
167 lines (158 loc) · 3.9 KB
/
bunkerLayoutsHumanReadable.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
157
158
159
160
161
162
163
164
165
166
167
/**
* Posted 19 October 2017 by @sparr
*/
// maps letters in the layout arrays to structures and vice versa
exports.layoutKey = {
'A': STRUCTURE_SPAWN,
'N': STRUCTURE_NUKER,
'K': STRUCTURE_LINK,
'L': STRUCTURE_LAB,
'E': STRUCTURE_EXTENSION,
'S': STRUCTURE_STORAGE,
'T': STRUCTURE_TOWER,
'O': STRUCTURE_OBSERVER,
'M': STRUCTURE_TERMINAL,
'P': STRUCTURE_POWER_SPAWN,
'.': STRUCTURE_ROAD,
'C': STRUCTURE_CONTAINER,
'R': STRUCTURE_RAMPART,
'W': STRUCTURE_WALL,
};
_.merge(exports.layoutKey, _.invert(exports.layoutKey));
// the preferred layout, if there's enough room
exports.bunkerLayout = [
' ..E...E.. ',
' .EE.EEE.EE. ',
'.EE.E.E.E.EE.',
'.E.EEA.EEE.E.',
'E.EEE.T.EEE.E',
'.E.E.T.T.A.E.',
'.EE.NSKMP.E.E',
'.E.E.T.T.E.E.',
'E.EEE.T.OLL..',
'.E.EEA.ELL.L.',
'.EE.E.E.L.LL.',
' .EE.E.E.LL. ',
' ..E.E.... ',
];
exports.bunkerExtensionOrder = [
' 3 7 ',
' 43 447 78 ',
' 43 2 4 7 78 ',
' 3 24 887 7 ',
'3 242 887 7',
' 4 2 7 ',
' 44 8 8',
' 5 5 8 8 ',
'5 566 ',
' 5 56 6 ',
' 65 5 6 ',
' 65 5 6 ',
' 6 6 ',
];
exports.bunkerRoadOrder = [
' .. ... .. ',
' . 2 7 . ',
'. 2 2 7 7 .',
'. 2 2 7 .',
' 2 2 3 7 ',
'. 2 2 3 7 7 .',
'. 2 7 8 ',
'. 5 5 . . 8 .',
' 5 5 . ..',
'. 5 5 . .',
'. 5 5 6 . .',
' . 5 6 . . ',
' .. . .... ',
];
exports.bunkerRampartOrder = [
' 555555555 ',
' 55777777755 ',
'5577777777755',
'57777 77775',
'5777 3 7775',
'577 333 775',
'577 33333 775',
'577 333 775',
'5777 3 7775',
'57777 77775',
'5577777777755',
' 55777777755 ',
' 555555555 ',
];
// just the core of the bunker, plus two spawns
exports.coreLayout = [
' . ',
' AT. ',
' .T.T. ',
'.NSKMP.',
' .T.T. ',
' .TAO ',
' . ',
];
// just the lab block, for placement elsewhere if necessary
exports.labLayout = [
' LL.',
'LL.L',
'L.LL',
'.LL ',
];
// rapid-fill extension block, if there's room
exports.extensionLayout = [
' EEE ',
' EErrEE ',
' EErEErEE ',
' EErEEErrEE',
'EErECECEErE',
' rEEEKEEEr ',
'ErEECECErEE',
'EErrEEErEE ',
' EErEErEE ',
' EErrEE ',
' EEE ',
];
/**
* Get all the positions for a certain structure/letter from a layout
* @param {String[]} layout
* @param {String|String} char letter or structure to return, optional
* @return {{x:Number,y:Number}[]} array of coordinate objects
* @return {Object} map of structure types to arrays of coordinate objects
*/
exports.getPositions = function(layout, char) {
if (typeof(char) === 'string') {
char = [char];
}
const height = layout.length;
const width = layout[0].length;
const top = height / 2 | 0;
const left = width / 2 | 0;
if (char instanceof Array) {
const positions = [];
for (let c of char) {
if (c.length>1) {
if (c in exports.layoutKey) {
c = exports.layoutKey[c];
} else {
continue;
}
}
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
if (layout[y][x] === c) {
positions.push({x: x-left, y: y-top});
}
}
}
}
return positions;
} else {
const positions = {};
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const char = layout[y][x];
positions[exports.layoutKey[char]] = positions[exports.layoutKey[char]] || [];
positions[exports.layoutKey[char]].push({x: x-left, y: y-top});
}
}
}
};