-
Notifications
You must be signed in to change notification settings - Fork 7
/
edsy.js
12505 lines (11187 loc) · 501 KB
/
edsy.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
EDSY was created using assets and imagery from Elite Dangerous, with the permission of Frontier Developments plc, for non-commercial purposes.
It is not endorsed by nor reflects the views or opinions of Frontier Developments and no employee of Frontier Developments was involved in the making of it.
Except where noted otherwise, all design, markup and script code for EDSY is copyright (c) 2015-2024 taleden
and is provided under a Creative Commons Attribution-NonCommercial 4.0 International License (http://creativecommons.org/licenses/by-nc/4.0/).
The Elite Dangerous game logic and data in this file remains the property of Frontier Developments plc, and is used here as authorized by
Frontier Customer Services (https://forums.frontier.co.uk/threads/elite-dangerous-media-usage-rules.510879/).
*/
'use strict';
window.edsy = new (function() {
var VERSIONS = [419009901,419009901,419009901,419009901]; /* HTML,CSS,DB,JS */
var LASTMODIFIED = 20241108;
var EMPTY_OBJ = {};
var EMPTY_ARR = [];
var EXPERIMENTAL_IMPORT = {};
var TIMEOUT_RESIZE = 300;
var TIMEOUT_DBLCLICK = 300;
var TIMEOUT_LONGPRESS = 500;
var TOLERANCE_TOUCH = 10;
var WEAPON_CHARGE = 0.0;
var GROUPS = ['hardpoint','utility','component','military','internal'];
var CORE_SLOT_FDNAME = ['Armour', 'PowerPlant', 'MainEngines', 'FrameShiftDrive', 'LifeSupport', 'PowerDistributor', 'Radar', 'FuelTank'];
var CORE_SLOT_ABBR = ['BH','PP','TH','FD','LS','PD','SS','FT'];
var CORE_ABBR_SLOT = { BH:0,PP:1,TH:2,FD:3,LS:4,PD:5,SS:6,FT:7,
RB:1,TM:2,FH:3,EC:4,PC:5, FS:7 };
var BOOST_MARGIN = 0;
var SHIP_HATCH_ID = 49180;
var MAX_SLOT_CLASS = 8;
var MAX_POWER_DIST = 8;
var TOTAL_POWER_DIST = 12;
var MAX_POWER_PRIORITY = 5;
var MAX_BLUEPRINT_GRADE = 5;
var MAX_DAMAGED_PWRCAP = 0.5;
var MAX_MALFUNCTION_PWRCAP = 0.4;
var MIN_MODIFIER = 0.00005;
var MIN_BPROLL = 0.00025;
// var BPGRADE_PROGRESS = [0.99, 0.99, 0.65, 0.5, 0.35, 0.25];
var BPROLL_UPGRADE = 0.8;
// var BPROLL_LIMIT = 0.95;
var DISCOUNTS = [30,20,15,10,5,2.5];
var HASH_VERSION = 18;
var ICON_MOUNT = { F:'fixed', G:'gimballed', T:'turreted' };
var ICON_MISSILE = { D:'dumbfire', S:'seeker' };
var ICON_TAG = { C:'community', G:'guardian', P:'powerplay', T:'techbroker' };
var CSS_FONTS = ['caps','text','fixed'];
var CSS_COLORS = ['orange','red','blue','green','yellow'];
var BUILTIN_STORED_MODULES = {
872200 : { name:"2B Enzyme Missile, HC+Caustic", modulehash:"FLIqG02G0050ypD4sPc8y00C_00Gu00", tag:'C' }, // CG reward // TODO: get sample to test import
862500 : { name:"2E/FD AX Missile, HC+RF", modulehash:"HL3gG-3G_W90zcQ4sPcAhhXEsPcIupDL000P000UxCpWy00", tag:'T' }, // Sirius tech broker
863300 : { name:"3C/FD AX Missile, HC+RF", modulehash:"HL4wG-3G_W90zcQ4sPcAhhXEsPcIupDL000P000UxCpWy00", tag:'T' }, // Sirius tech broker // TODO: get sample to test import
862570 : { name:"2E/G EAXMC \"Azimuth\", OC, AL", modulehash:"HL3nG-3H0038_00CoPcL600", tag:'T' }, // Azimuth / Rescue Ship tech broker
863370 : { name:"3C/G EAXMC \"Azimuth\", OC, AL", modulehash:"HL51G-3H0038_00CoPcL600", tag:'T' }, // Azimuth / Rescue Ship tech broker
881400 : { name:"1D/F Grd Gauss, RF+HC", modulehash:"HLXCG-2G0092_166_00A_00Ew7ZHD00L800P600T800YsPc", tag:'T' }, // Salvation tech broker
882200 : { name:"2B/F Grd Gauss, RF+HC", modulehash:"HLYSG-2G0092_166_00A_00Ew7ZHD00L800P600T800YsPc", tag:'T' }, // Salvation tech broker
881430 : { name:"1D/F Grd Plasma, OC+Foc", modulehash:"HLXFG-2Gxq60vBh4zHx8y00Cw00H800KvLL", tag:'T' }, // Salvation tech broker
882230 : { name:"2B/F Grd Plasma, OC+Foc", modulehash:"HLYVG-2Gxq60vBh4zHx8y00Cw00H800KvLL", tag:'T' }, // Salvation tech broker // TODO: get sample to test import
881460 : { name:"1D/F Grd Shard, LR+Foc, Pen", modulehash:"HLXIG-2G0090y0051Cp98HkDFm0H058K_7YP4JAV700YpXv", tag:'T' }, // Salvation tech broker
882160 : { name:"2A/F Grd Shard, LR+Foc, Pen", modulehash:"HLYOG-2G0090y0051Cp98HkDFm0H058K_7YP4JAV700YpXv", tag:'T' }, // Salvation tech broker // TODO: get sample to test import
882161 : { name:"2A/F Grd Shard, LR5", modulehash:"GLYOmH7I03G0080y0051Cp993DDFm0H058L800Op77V700", tag:'C' }, // CG reward // TODO: get sample to test import
811410 : { name:"1D/F Abrasion Blaster, LR", modulehash:"FJprG02G0062y006y00Ey00Iy00L800P800", tag:'C' }, // CG reward // TODO: get sample to test import
811400 : { name:"1D/F Mining Laser, LR, Incen", modulehash:"HJpqmF5j3H0072y006y00AkPcEy00I_ezL800PBLL", tag:'T' }, // Torval Mining Ltd tech broker
822230 : { name:"2B Seeker \"V1\", HC+LW, ThermCas", modulehash:"HK4lG-3Q_W42-Cp6ypDAsPcIwPc", tag:'T' }, // human tech broker
822231 : { name:"2B Seeker, HC+RF, Drag", modulehash:"HK4lG-2R00612008u00GwghUsPcX400b400", tag:'C' }, // CG reward // TODO: get sample to test import
722500 : { name:"2E/F Multi-cannon, RF+HC, Phasing", modulehash:"HHewm1WaCS007Uy00Yuaab600f466n600soPcv400", tag:'C' }, // CG reward
842200 : { name:"2B/F Rail, LR+HC, FeedCas", modulehash:"FKZyG03I0080-Cp8zCpT000Yyv4b000f000iu00r900", tag:'C' }, // CG reward // TODO: get sample to test import
510600 : { name:"0F ECM, LW+Shd", modulehash:"FCTqG03G0032_pD50009000", tag:'C' }, // CG reward // TODO: get sample to test import
520900 : { name:"0I Heat Sink \"Sirius\", ACx2", modulehash:"HCjwG-2G002P000S_00", tag:'T' }, // Sirus tech broker
570100 : { name:"0A KWS, FS+LR", modulehash:"FDwoG03G0056y008y00GzCpMupDQ_Pc", tag:'C' }, // CG reward // TODO: get sample to test import
530900 : { name:"0I/T Point Defence, Foc+LW", modulehash:"FCzYG05G0042_pD6y00GkPcL000", tag:'C' }, // CG reward // TODO: get sample to test import
413100 : { name:"3A Power Plant, AR+OC", modulehash:"FA5UG03G0040sPc4-cQ8yAFCqAF", tag:'C' }, // CG reward // TODO: get sample to test import
413101 : { name:"3A Power Plant, OC", modulehash:"HA5UG-7G0036upD8ypDCvcQ", tag:'C' }, // CG reward // TODO: get sample to test import
414101 : { name:"4A Power Plant, OC", modulehash:"HA72G-7G0036upD8ypDCvcQ", tag:'C' }, // CG reward // TODO: get sample to test import
415101 : { name:"5A Power Plant, OC", modulehash:"HA8cG-7G0036upD8ypDCvcQ", tag:'C' }, // CG reward // TODO: get sample to test import
433100 : { name:"3A FSD, IR+FB", modulehash:"HAakG-5G_W60upD6upD8qpDE_PcGzcQKsPc", tag:'C' }, // CG reward // TODO: get sample to test import
434100 : { name:"4A FSD, IR+FB", modulehash:"HAcIG-5G_W60upD6upD8qpDE_PcGzcQKsPc", tag:'C' }, // CG reward // TODO: get sample to test import
435100 : { name:"5A FSD \"V1\", IR+FB", modulehash:"HAdsG-5G_W60upD6upD8qpDE_PcGzcQKsPc", tag:'T' }, // human tech broker
436100 : { name:"6A FSD, IR+FB", modulehash:"HAfQG-5G_W60upD6upD8qpDE_PcGzcQKsPc", tag:'C' }, // CG reward // TODO: get sample to test import
5510 : { name:"5E Anti-Corrosion Cargo (32T)", modulehash:"H08d00", tag:'C' }, // CG reward
6510 : { name:"6E Anti-Corrosion Cargo (64T)", modulehash:"H0AB00", tag:'C' }, // CG reward
303100 : { name:"3A Shield Gen, KR+TR", modulehash:"F7PcG05G0044sPc8wPccupDgvcQ", tag:'C' }, // CG reward // TODO: get sample to test import
111300 : { name:"1I DSS \"V1\", ERx2", modulehash:"H2jwG-9G_W1P000", tag:'T' }, // human tech broker
};
var LANG_NAMES = { // TODO cn? ko? nl? pl?
"cs": "Čeština",
"de": "Deutsch",
"en": "English",
"es": "Español",
"fr": "Français",
"it": "Italiano",
"hu": "Magyar",
// "nl": "Nederlands",
"ja": "日本語",
"pt": "Português, Brasileiro",
"ru": "Русский",
"zh": "简体中文",
};
var LANGS = Object.keys(LANG_NAMES);
var LANG_DEFAULT = 'en';
var UNIT_ABBR_TRANSLATIONS = {
"%": "unit-percent-abbr",
"°": "unit-degrees-abbr",
"°/s": "unit-degrees-per-second-abbr",
"Cr": "unit-credits-abbr",
"Cr/T": "unit-credits-per-ton-abbr",
"KM": "unit-kilometers-abbr",
"LS": "unit-lightseconds-abbr",
"LY": "unit-lightyears-abbr",
"M": "unit-meters-abbr",
"M/s": "unit-meters-per-second-abbr",
"MJ/s": "unit-megajoules-per-second",
"MW": "unit-megawatts-abbr",
"MW/s": "unit-megawatts-per-second-abbr",
"/MW": "unit-per-megawatt-abbr",
"T": "unit-tons-abbr",
"T/s": "unit-tons-per-second-abbr",
"h": "unit-hours-abbr",
"m": "unit-minutes-abbr",
"s": "unit-seconds-abbr",
"/s": "unit-per-second-abbr",
"x": "unit-multiplier-abbr",
};
var cache = {
reEscapeHTML: new RegExp('[&<>"\'/°]', 'g'),
fnEscapeHTML: function(m) { return {'&':'&','<':'<','>':'>','"':'"','\'':''','/':'/','°':'°'}[m] || m; },
attribute: {},
formatNumText: {},
formatPctText: {},
reSpacePercent: new RegExp('[ \u00A0]+(%)'),
parseNumText: null,
feature: {},
ships: [],
shipBuild: {},
shipHash: {},
shipModules: {},
groupMtypes: {},
mtypeModules: {},
mtypeBuiltins: {},
mtypeSizeGaps: {},
mtypeBlueprints: {},
mtypeExpeffects: {},
moduleHash: {},
hashVersionMap: {},
discountMod: {},
discounts: [],
option: {},
template: {},
icon: {},
lang: null,
translation: {},
translationDefault: null,
reTranslationValue: new RegExp('\{([A-Za-z0-9_-]+)\}', 'g'),
};
var current = {
dev: false,
beta: false,
locale: undefined,
lang: LANG_DEFAULT,
hashlock: false,
popup: {
element: null,
trigger: null,
refocus: null,
sticky: null,
onOkay: null,
onCancel: null,
},
importdata: {
imports: null,
buildlist: null,
modules: null,
},
drag: null,
resize: null,
query: null,
pickerClick: {},
pickerTouch: {},
slotsClick: {},
slotsTouch: {},
bprollClick: {},
bprollTouch: {},
importLabel: {},
labelImports: {},
stored: {
shipNamehashStored: { 0:{} },
shipStoreds: { 0:[] },
moduleNamehashStored: { 0:{} },
moduleStoreds: { 0:[] },
modulehashStored: {},
},
pickerNameNamehash: {},
option: {
insurance: 9500,
discounts: 0,
builtin: 'some',
onlybest: 'some',
revsize: false,
revrating: false,
experimental: false,
show1: true,
show2: true,
show3: true,
hidestats: true,
// fonts generated from CSS_FONTS
// colors generated from CSS_COLORS
language: '',
},
page: null,
shipyard_tab: null,
tab: null,
fit: null,
outfitting_onecol: false,
outfitting_focus: null,
outfitting_mode: null,
outfitting_show1: null,
outfitting_show2a: null,
outfitting_show2b: null,
pickerSlot: null,
tempSlot: null,
group: null,
slot: null,
analysis_tab: null,
tableSort: {
shipyard_ships_table: {},
shipyard_storedbuilds_table: {},
},
counter: {},
retrofit: null,
};
var
LN2 = Math.LN2,
LN10 = Math.LN10,
PI = Math.PI,
abs = Math.abs,
atan2 = Math.atan2,
ceil = Math.ceil,
exp = Math.exp,
floor = Math.floor,
log = Math.log,
log2 = Math.log2,
max = Math.max,
min = Math.min,
pow = Math.pow,
random = Math.random,
round = Math.round,
sign = Math.sign,
sqrt = Math.sqrt
;
var
atanh = Math.atanh || function(x) {
return (log((1 + x) / (1 - x)) / 2);
},
tanh = Math.tanh || function(x) {
var a = exp(+x), b = exp(-x);
return ((a == Infinity) ? 1 : ((b == Infinity) ? -1 : ((a - b) / (a + b))));
},
clone = Object.assign || function(tgt, src) {
if (src) {
for (var key in src) {
if (src.hasOwnProperty(key)) {
tgt[key] = src[key];
}
}
}
return tgt;
},
contains = function(lst, itm) {
var i = lst.length;
while (i-- > 0) {
if (lst[i] === itm)
return true;
}
return false;
}
;
/*
* UTILITY FUNCTIONS
*/
var setDOMSelectLength = function(select, length) {
while (select.length < length)
select.options.add(document.createElement('option'));
while (select.length > length)
select.options.remove(select.options.length - 1);
}; // setDOMSelectLength()
var populateDOMSelectStoreds = function(select, storeds, namehash, offset) {
var selectedIndex = (select.selectedIndex ? -1 : 0);
storeds = storeds || EMPTY_ARR;
offset = offset || 0;
setDOMSelectLength(select, offset + storeds.length);
for (var i = 0; i < storeds.length; i++) {
select.options[offset+i].value = storeds[i].namehash;
select.options[offset+i].text = storeds[i].name;
if (storeds[i].namehash === namehash)
selectedIndex = offset+i;
}
select.selectedIndex = selectedIndex;
return true;
}; // populateDOMSelectStoreds()
var setClipboardString = function(string) {
var el = document.createElement('textarea');
el.value = string;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-1000px';
document.body.appendChild(el);
el.focus();
el.select();
var ok = true;
try {
document.execCommand('copy');
} catch (exc) {
ok = false;
}
document.body.removeChild(el);
return ok;
}; // setClipboardString()
var isDropEffectCopy = function(e) {
// Fixes browser bug in Chrome on Windows where dropEffect is always "none".
// The original bug report [1] was merged into another issue [2] but that
// issue was made private or something because I get permission denied when
// trying to view it.
//
// The fix is to wrap the retrieval of the drop effect and use the current
// event to determine what the drop effect is.
//
// [1]: https://bugs.chromium.org/p/chromium/issues/detail?id=501655
// [2]: https://bugs.chromium.org/p/chromium/issues/detail?id=39399
if (e.dataTransfer.dropEffect !== 'none') {
// Bug hasn't been hit because a drop effect was detected.
return e.dataTransfer.dropEffect;
}
if (e.dataTransfer.effectAllowed !== 'copyMove') {
// Should never happen. We should only be using this function when we're
// expecting a copy or move drop event. effectAllowed should have been
// set when the drag started.
console.warn('Using isDropEffectCopy() but effectAllowed is not copyMove! (effectAllowed=' + e.dataTransfer.effectAllowed + ')');
return e.dataTransfer.effectAllowed;
}
// This is the actual fix.
return !!e.ctrlKey;
} // isDropEffectCopy()
var encodeHTML = function(text) {
return text.replaceAll(cache.reEscapeHTML, cache.fnEscapeHTML);
}; // encodeHTML()
var getCookie = function(name, defaultvalue) {
return ((document.cookie.match(new RegExp('(?:^|;)\\s*' + name + '\\s*=\\s*"?([^"\\s;]*)"?\\s*(?:;|$)')) || EMPTY_ARR)[1] || defaultvalue);
}; // getCookie()
var getCookies = function(pattern) {
var cookies = document.cookie;
var c = {};
var re = new RegExp('(?:^|;)\\s*(' + pattern + ')\\s*=\\s*"?([^"\\s;]*)"?', 'g');
var match;
while ((match = re.exec(cookies)) !== null) {
c[match[1]] = match[2];
}
return c;
}; // getCookies()
var createIcon = function(icon) {
return (cache.icon[icon] || cache.icon['unknown'] || document.createTextNode('?')).cloneNode(true);
}; // createIcon()
/* TODO not needed?
var appendTextLines = function(el, text, lines) {
lines = lines || ceil(text.length / 80);
while (lines > 1) {
var i = (text.length / lines) | 0;
for (var j = 0; j <= i; j++) {
if (text[i+j] == ' ') {
el.append(text.slice(0, i+j), document.createElement('br'));
text = text.slice(i+j+1);
break;
} else if (text[i-j] == ' ') {
el.append(text.slice(0, i-j), document.createElement('br'));
text = text.slice(i-j+1);
break;
}
}
lines--;
}
el.append(text);
}; // appendTextLines()
*/
var formatNumText = ((window.Intl && window.Intl.NumberFormat)
? (
function(num, dec) {
return (cache.formatNumText[dec] || (
cache.formatNumText[dec] = (new window.Intl.NumberFormat(current.locale, { style:'decimal', useGrouping:true, minimumIntegerDigits:1, minimumFractionDigits:dec, maximumFractionDigits:dec })).format
))(num);
}
) : (
function(num, dec) {
if (!isFinite(num))
return n.toFixed(dec);
var parts = num.toFixed(dec).split('.');
var o = '';
var s = parts[0];
var i = L = s.length;
while (i-- > 0)
o = ((i && !((L - i) % 3)) ? ',' : '') + s[i] + o;
return o + (dec ? ('.' + parts[1]) : '');
}
)
); // formatNumText()
var parseNumText = function(text) {
if (!cache.parseNumText) {
if (window.Intl && window.Intl.NumberFormat) {
// based on Mike Bostock's solution: https://observablehq.com/@mbostock/localized-number-parsing
var parts = (new window.Intl.NumberFormat(current.locale, {useGrouping:true, minimumIntegerDigits:10, minimumFractionDigits:1})).formatToParts(123456789);
var n = 0, map = {};
for (var p = 0; p < parts.length; p++) {
switch (parts[p].type) {
case 'integer': for (var i = 0; i < parts[p].value.length; i++) map[parts[p].value[i]] = n++; break;
case 'group': map[parts[p].value] = ""; break;
case 'decimal': map[parts[p].value] = "."; break;
}
}
var search = new RegExp('[' + Object.keys(map).join('').replace(/([\.\(\)\[\]\-])/g,'\\$1') + ']', 'g');
cache.parseNumText = function(text) {
return (text = text.trim().replace(search, function(s) { return map[s]; })) ? parseFloat(text) : NaN
};
} else {
var sep = formatNumText(1.2,1).substring(1,2);
var reDecimalSep = new RegExp('\\' + sep);
sep = formatNumText(111111111,0).replace(new RegExp(formatNumText(1,0),'g'),'')[0];
var reThousandSep = sep ? (new RegExp('\\' + sep, 'g')) : null;
cache.parseNumText = function(text) {
if (reThousandSep)
text = text.replace(reThousandSep, '');
return parseFloat(text.replace(reDecimalSep, '.').trim());
}
}
}
return cache.parseNumText(text);
}; // parseNumText()
var formatPctText = ((window.Intl && window.Intl.NumberFormat)
? (
function(num, dec) {
return (cache.formatPctText[dec] || (
cache.formatPctText[dec] = (new window.Intl.NumberFormat(current.locale, { style:'percent', useGrouping:false, minimumIntegerDigits:1, minimumFractionDigits:dec, maximumFractionDigits:dec })).format
))(num).replace(cache.reSpacePercent, '$1');
}
) : (
function(num, dec) {
return (num * 100).toFixed(0) + '%';
}
)
); // formatPctText()
var formatNumHTML = function(num, dec) {
if (num === undefined)
return '';
var vals = {'number':num, 'number#':dec, 'number!':(isNaN(num) ? 0 : (isFinite(num) ? undefined : ((num < 0) ? -1 : 1)))};
var text = ((isFinite(num) || isNaN(num)) ? formatNumText(((num === num) ? num : 0), dec) : '∞');
if (num !== num)
text = text.replace(/0/g,'?');
var html = '<span'
+ ' edsy-vals="' + encodeHTML(JSON.stringify(vals)) + '"'
+ ' edsy-text="interp-number"'
+ '>' + text + '</span>';
if (num !== num)
html = '<abbr class="unknown" edsy-title="unknown" title="Unknown!">' + html + '</abbr>';
return html;
}; // formatNumHTML()
var formatPctHTML = function(num, dec) {
if (num === undefined)
return '';
var vals = {'number':num, 'number#':dec, 'number%':true, 'number!':(isNaN(num) ? 0 : (isFinite(num) ? undefined : ((num < 0) ? -1 : 1)))};
var text = ((isFinite(num) || isNaN(num)) ? formatPctText(((num === num) ? num : 0), dec).replace('%', '<small class="semantic">%</small>') : '∞');
if (num !== num)
text = text.replace(/0/g,'?');
var html = '<span'
+ ' edsy-vals="' + encodeHTML(JSON.stringify(vals)) + '"'
+ ' edsy-text="interp-number"'
+ '>' + text + '</span>';
if (num !== num)
html = '<abbr class="unknown" edsy-title="unknown" title="Unknown!">' + html + '</abbr>';
return html;
}; // formatPctHTML()
var formatTimeHTML = function(sec, brief) {
if (sec !== sec)
return formatNumHTML(NaN, 1);
if (!isFinite(sec))
return formatNumHTML(sec, 0);
var s = (sec % 60);
var m = (sec / 60) | 0;
var h = (m / 60) | 0;
m = (m % 60) | 0;
// return ((sec >= 10) ? ((h ? (h.toFixed(0) + ':') : '') + ((h && m < 10) ? '0' : '') + m.toFixed(0) + ':' + (((h || m) && s < 10) ? '0' : '') + s.toFixed(0)) : s.toFixed(1));
if (brief) {
if (h) return (((h < 10) ? formatNumHTML(h+(m/60), 1) : formatNumHTML(h, 0)) + '<small class="semantic" edsy-text="unit-hours-abbr">h</small>');
if (m) return (((m < 10) ? formatNumHTML(m+(s/60), 1) : formatNumHTML(m, 0)) + '<small class="semantic" edsy-text="unit-minutes-abbr">m</small>');
return (((h && !m) ? '0<small class="semantic">m</small>' : '') + formatNumHTML(s, (sec < 10) ? 1 : 0) + '<small class="semantic" edsy-text="unit-seconds-abbr">s</small>');
}
var html = '';
if (h) html += (formatNumHTML(h, 0) + '<small class="semantic" edsy-text="unit-hours-abbr">h</small>');
if (m) html += (formatNumHTML(m, 0) + '<small class="semantic" edsy-text="unit-minutes-abbr">m</small>');
if (h && !m) html += '0<small class="semantic" edsy-text="unit-minutes-abbr">m</small>';
html += (formatNumHTML(s, (sec < 10) ? 1 : 0) + '<small class="semantic" edsy-text="unit-seconds-abbr">s</small>');
return html;
}; // formatTimeHTML()
var formatPriceHTML = function(num, brief) {
if (num !== num || !isFinite(num))
return formatNumHTML(num, 0);
if (!brief)
return (formatNumHTML(num, 0) + '<small edsy-text="unit-credits-abbr">Cr</small>');
var n = num;
var k = 0;
while (brief && n > 1000 && k < 4) {
n /= 1000;
k++;
}
var d = (n < 10) ? 2 : ((n < 100) ? 1 : 0);
// apparently the KMBT suffixes are pretty universal and don't need to be localized?
var s = (['','K','M','B','T'][k] || '');
return [
'<abbr',
' edsy-vals-title="', encodeHTML(JSON.stringify({'number':num})), '"',
' edsy-title="interp-number-credits-abbr"',
' title="', formatNumText(num, 0), ' Cr"',
' edsy-vals="', encodeHTML(JSON.stringify({'number':n,'number#':d,'suffix':s})), '"',
' edsy-text="interp-number-suffix"',
'>',
formatNumHTML(n, d), ' ', s,
'</abbr>',
'<small edsy-text="unit-credits-abbr">Cr</small>'
].join('');
}; // formatPriceHTML()
var formatAttrLabelHTML = function(attr) {
var attribute = (cache.attribute[attr] || EMPTY_OBJ);
return [
'<abbr class="attribute"',
' edsy-title="attr-', attr, '-desc"',
' title="' + (attribute.desc || '') + '"',
' edsy-text="attr-', attr, '-abbr"',
'>' + (attribute.abbr || attr) + '</abbr>:'
].join('');
}; // formatAttrLabelHTML()
var formatAttrHTML = function(attr, value, dec) {
var attribute = (cache.attribute[attr] || EMPTY_OBJ);
if (dec === undefined)
dec = attribute.scale;
if (value !== value)
return formatNumHTML(NaN, dec);
if (attribute.unit === '%')
return formatPctHTML(value / 100, dec);
if (attribute.time)
return formatTimeHTML(value);
return (((dec !== undefined) ? formatNumHTML(value, dec) : value) + ((attribute.unit && isFinite(value)) ? ('<small edsy-text="' + (UNIT_ABBR_TRANSLATIONS[attribute.unit] || '') + '">' + attribute.unit + '</small>') : ''));
}; // formatAttrHTML()
var HASH_NUM_CHR = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-';
var HASH_CHR_NUM = {};
for (var i = 0; i < HASH_NUM_CHR.length; i++)
HASH_CHR_NUM[HASH_NUM_CHR[i]] = i;
var HASHT_NUM_CHR = ' !"#$%&'+"'"+'()*+,-./:;<=>?@[\\]^_`{|}~';
var HASHT_CHR_NUM = {};
for (var i = 0; i < HASHT_NUM_CHR.length; i++)
HASHT_CHR_NUM[HASHT_NUM_CHR[i]] = i;
var hashEncode = function(n, l) {
var h = '';
while (n) {
h = HASH_NUM_CHR[n & 0x3F] + h;
n = n >> 6;
}
while (h.length < l)
h = HASH_NUM_CHR[0] + h;
return h;
}; // hashEncode()
var hashDecode = function(h) {
var n=0, i=0;
while (i < h.length)
n = (n << 6) | (HASH_CHR_NUM[h[i++]] || 0);
return n;
}; // hashDecode()
var hashEncodeS = function(s) {
var h='', i=0, c;
for (var i = 0; i < s.length; i++) {
c = s.charCodeAt(i);
if (c >= 0x20 && c <= 0xFFF) {
h += HASH_NUM_CHR[c >> 6] + HASH_NUM_CHR[c & 0x3F];
}
}
return h;
}; // hashEncodeS()
var hashDecodeS = function(h) {
var s='', i=1, c1, c2;
for (var i = 1; i < h.length; i += 2) {
c1 = HASH_CHR_NUM[h[i - 1]] || 0;
c2 = HASH_CHR_NUM[h[i]] || 0;
s += String.fromCharCode((c1 << 6) | c2);
}
return s;
}; // hashDecodeS()
var hashEncodeT = function(t) {
var h='', i=0, c;
for (var i = 0; i < t.length; i++) {
if ((c = HASH_CHR_NUM[t[i]]) !== undefined && c < 62) {
h += t[i];
} else if ((c = HASHT_CHR_NUM[t[i]]) !== undefined) {
h += HASH_NUM_CHR[62] + HASH_NUM_CHR[c];
} else if ((c = t.charCodeAt(i) - 0x7F) >= 0 && c <= 0xFFF) {
h += HASH_NUM_CHR[63] + HASH_NUM_CHR[c >> 6] + HASH_NUM_CHR[c & 0x3F];
}
}
return h;
}; // hashEncodeT()
var hashDecodeT = function(h) {
var t='', i=0, c1, c2;
while (i < h.length) {
c1 = HASH_CHR_NUM[h[i++]];
if (c1 !== undefined && c1 < 62) {
t += HASH_NUM_CHR[c1];
} else if (c1 == 62) {
c2 = HASH_CHR_NUM[h[i++]] || 0;
t += HASHT_NUM_CHR[c2];
} else if (c1 == 63) {
c1 = HASH_CHR_NUM[h[i++]] || 0;
c2 = HASH_CHR_NUM[h[i++]] || 0;
t += String.fromCharCode(((c1 << 6) | c2) + 0x7F);
}
}
return t;
}; // hashDecodeT()
var fixed20Encode = function(n) {
return min(max((n * (1 << 17) + 0.5) | 0, 0), 0xFFFFF);
}; // fixed20Encode()
var fixed20Decode = function(n) {
return (1.0 * n / (1 << 17));
}; // fixed20Decode()
var float20Encode = function(f) {
// this is a custom 20-bit floating point format based on the design of IEEE 16- and 32-bit floats
// yes, it's probably a little silly to invent a custom data type just for a fan site,
// but 16 bits just isn't quite enough precision to encode engineer attribute modifiers
// and 32 bits would unnecessarily inflate the length of URL hashes, so here we are --taleden
var s = (f < 0) | 0;
f = (f < 0) ? -f : f;
var m = f | 0;
var e = ((1 << 5) - 1);
if (isNaN(f)) { // NaN
m = 1;
} else if (f > ((1 << 15) - 1)) { // +/- Infinity
m = 0;
} else {
e -= 1;
f -= m;
while (m < (1 << 14) && e > 0) {
m <<= 1;
e -= 1;
f *= 2;
if (f >= 1) {
m |= 1;
f -= 1;
}
}
if (e == 0) {
m = (m >> 1) + (m & 1);
e = (m >= (1 << 15));
} else if (f * 2 >= 1) {
m += 1;
if (m >= (1 << 15)) {
m >>= 1;
e += 1;
}
}
}
s &= 1;
e &= ((1 << 5) - 1);
m &= ((1 << 14) - 1);
return (s << 19) | (e << 14) | m;
}; // float20Encode()
var float20Decode = function(b) {
var s = (b >> 19) & 1;
var e = (b >> 14) & ((1 << 5) - 1);
var m = b & ((1 << 14) - 1);
return (e >= ((1 << 5) - 1)) ? (m ? NaN : (s ? -Infinity : Infinity)) : ((s ? -1 : 1) * pow(2.0, e - ((1 << 5) - 2) + (e == 0)) * ((e ? (1 << 14) : 0) | m));
}; // float20Decode()
var b64Encode = function(t) {
return btoa(t).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
}; // b64Encode()
var b64Decode = function(t) {
return atob((t + '===').slice(0, t.length + ((4 - (t.length % 4)) % 4)).replace(/-/g, '+').replace(/_/g, '/'));
}; // b64Decode()
/*
* GAME FORMULAS
*/
var getJumpFuelCost = function(mass, dist, fsdOpt, fsdMul, fsdExp, jmpBst) {
// https://forums.frontier.co.uk/threads/mass-effect-on-hyperspace-range.32734/#post-643461
return fsdMul * pow(max(0, dist - jmpBst) * mass / fsdOpt, fsdExp);
}; // getJumpFuelCost()
var getJumpDistance = function(mass, fuel, fsdOpt, fsdMul, fsdExp, jmpBst) {
// https://forums.frontier.co.uk/threads/mass-effect-on-hyperspace-range.32734/#post-643461
return pow(fuel / fsdMul, 1 / fsdExp) * fsdOpt / mass + jmpBst;
}; // getJumpDistance()
var getJumpRange = function(fuelcap, mass, fuel, fsdOpt, fsdMul, fsdExp, jmpBst) {
var range = 0;
while (fuelcap > fuel) {
range += getJumpDistance(mass, fuel, fsdOpt, fsdMul, fsdExp, jmpBst);
fuelcap -= fuel;
mass -= fuel;
}
return range + getJumpDistance(mass, fuelcap, fsdOpt, fsdMul, fsdExp, jmpBst);
}; // getJumpRange()
var getMassCurveMultiplier = function(mass, minMass, optMass, maxMass, minMul, optMul, maxMul) {
// https://forums.frontier.co.uk/threads/the-one-formula-to-rule-them-all-the-mechanics-of-shield-and-thruster-mass-curves.300225/
return (minMul + pow(min(1.0, (maxMass - mass) / (maxMass - minMass)), log((optMul - minMul) / (maxMul - minMul)) / log((maxMass - optMass) / (maxMass - minMass))) * (maxMul - minMul));
}; // getMassCurveMultiplier()
var getEffectiveDamageResistance = function(baseres, extrares, exemptres, bestres) {
// https://forums.frontier.co.uk/threads/kinetic-resistance-calculation.266235/post-4230114
// https://forums.frontier.co.uk/threads/shield-booster-mod-calculator.286097/post-4998592
/* old
var threshold = 30;
var rawres = 1 - ((1 - baseres / 100) * (1 - extrares / 100));
var maxres = 1 - ((1 - baseres / 100) * (1 - threshold / 100));
return 100 * (rawres - max(0, pow((rawres - maxres) / 2, curve || 1)));
*/
baseres = baseres || 0;
extrares = extrares || 0;
exemptres = exemptres || 0;
bestres = bestres || 0;
var lo = max(max(30, baseres), bestres || 0);
var hi = 65; // half credit past 30% means 100% -> 30 + (100 - 30) / 2 = 65%
var expected = (1 - ((1 - baseres / 100) * (1 - extrares / 100))) * 100;
var penalized = lo + (expected - lo) / (100 - lo) * (hi - lo); // remap range [lo..100] to [lo..hi]
var actual = ((penalized >= 30) ? penalized : expected);
return (1 - ((1 - exemptres / 100) * (1 - actual / 100))) * 100;
}; // getEffectiveDamageResistance()
var getEffectiveShieldBoostMultiplier = function(shieldbst) {
// https://forums.frontier.co.uk/threads/very-experimental-shield-change.314820/post-4895068
var i = (1 + (shieldbst / 100));
// i = min(i, (1 - exp(-0.7 * i)) * 2.5); // proposed during 2.3 beta, but not implemented
return i;
}; // getEffectiveShieldBoostMultiplier()
var getPipDamageResistance = function(sys) {
// https://forums.frontier.co.uk/threads/2-3-the-commanders-changelog.341916/
return 60 * pow(sys / MAX_POWER_DIST, 0.85);
}; // getPipDamageResistance()
var getEquilibriumHeatLevel = function(heatdismax, thmload) {
// https://forums.frontier.co.uk/threads/research-detailed-heat-mechanics.286628/post-6399855
return sqrt(thmload / heatdismax);
}; // getEquilibriumHeatLevel()
var getTimeUntilHeatLevel = function(heatcap, heatdismax, thmload, heatlevel0, heatlevel) {
// https://forums.frontier.co.uk/threads/research-detailed-heat-mechanics.286628/post-6519883
heatdismax /= heatcap;
if (!thmload) {
var C = -1 / (heatdismax * heatlevel0);
return ((1 / (heatdismax * heatlevel)) + C);
}
thmload /= heatcap;
var sqrtAdivB = sqrt(heatdismax / thmload);
var sqrtAmulB = sqrt(heatdismax * thmload);
var C = -atanh(heatlevel0 * sqrtAdivB) / sqrtAmulB
return ((atanh(heatlevel * sqrtAdivB) / sqrtAmulB) + C);
}; // getTimeUntilHeatLevel()
var getHeatLevelAtTime = function(heatcap, heatdismax, thmload, heatlevel0, seconds) {
// https://forums.frontier.co.uk/threads/research-detailed-heat-mechanics.286628/post-6519883
heatdismax /= heatcap;
if (!thmload) {
var C = -1 / (heatdismax * heatlevel0);
return ((1 / (seconds - C)) / heatdismax);
}
thmload /= heatcap;
var sqrtAdivB = sqrt(heatdismax / thmload);
var sqrtAmulB = sqrt(heatdismax * thmload);
var C = -atanh(heatlevel0 * sqrtAdivB) / sqrtAmulB
return (tanh((seconds - C) * sqrtAmulB) / sqrtAdivB);
}; // getHeatLevelAtTime()
var getEffectiveWeaponThermalLoad = function(thmload, distdraw, wepcap, weplvl) {
// https://forums.frontier.co.uk/threads/research-detailed-heat-mechanics.286628/post-6408594
return (thmload * (1 + 4 * min(max(1 - (wepcap * weplvl - distdraw) / wepcap, 0), 1)));
}; // getEffectiveWeaponThermalLoad()
/*
* SHIP BUILDS
*/
var Slot = function(build, slotgroup, slotnum, modid) {
if (!build || !(build instanceof Build))
throw 'invalid parent build';
this.build = build;
this.slotgroup = null;
this.slotnum = null;
if (slotgroup) {
var ship = eddb.ship[build.getShipID()];
if (!ship || (slotgroup === 'ship' && slotnum !== 'hull' && slotnum !== 'hatch') || (slotgroup !== 'ship' && (!ship.slots[slotgroup] || slotnum < 0 || slotnum > ship.slots[slotgroup].length)))
throw 'invalid ship slot group ' + slotgroup + ' or #' + slotnum;
this.slotgroup = slotgroup;
this.slotnum = slotnum;
}
this.hash = null;
this.modid = 0;
this.module = null;
this.discounts = 0;
this.cost = 0;
this.powered = true;
this.priority = 1;
this.preeng = 0;
this.bpid = 0;
this.bpgrade = 0;
this.bproll = 0;
this.expid = 0;
this.attrModifier = null;
this.attrOverride = null;
if (modid) {
if (!this.setModuleID(modid))
throw 'invalid initial module id #' + modid;
}
}; // Slot
Slot.prototype = {
getSlotGroup: function() {
return this.slotgroup;
}, // getSlotGroup()
getSlotNum: function() {
return this.slotnum;
}, // getSlotNum()
getSlotSize: function() {
var ship = eddb.ship[this.build.getShipID()];
return (ship ? ship.slots[this.slotgroup][this.slotnum] : MAX_SLOT_CLASS);
}, // getSlotSize()
clearHash: function() {
this.hash = null;
if (this.slotgroup) this.build.clearHash();
}, // clearHash()
clearStats: function() {
this.clearHash();
if (this.slotgroup) this.build.clearStats();
}, // clearStats()
isModuleIDValid: function(modid) {
if (this.slotgroup === 'ship') return ((this.slotnum === 'hull' && modid == this.build.getShipID()) || (this.slotnum === 'hatch' && modid == SHIP_HATCH_ID)); // ship pseudogroup can only contain hull or cargo hatch
if (!modid) return (this.slotgroup !== 'component'); // core components cannot be empty
var module = eddb.module[modid];
if (!module) return false; // module does not exist
if (this.slotgroup && !((this.slotgroup === 'component') ? eddb.group.component[this.slotnum] : eddb.group[this.slotgroup]).mtypes[module.mtype]) return false; // group does not allow the module type
return true;
}, // isModuleIDValid()
isModuleIDAllowed: function(modid) {
if (!this.isModuleIDValid(modid)) return false; // module must be valid to be allowed
if (!this.slotgroup || this.slotgroup === 'ship' || !modid) return true; // detached slots, ship pseudogroup slots, and empty slots are always allowed if they're valid
var shipid = this.build.getShipID();
var ship = eddb.ship[shipid];
var slotsize = this.getSlotSize();
var module = eddb.module[modid];
if (module.class > slotsize) return false; // module is too large for the slot
if (module.class < slotsize && this.slotgroup === 'component' && (this.slotnum == CORE_ABBR_SLOT.LS || this.slotnum == CORE_ABBR_SLOT.SS)) return false; // module is too small for the slot (i.e. life support, sensors)
if (module.class < slotsize && module.noundersize) return false; // mtype can normally be undersized, but this module cannot (i.e. SCO FSD)
if (module.reserved && !module.reserved[shipid]) return false; // module does not allow the ship (i.e. fighter hangars, luxury cabins)
var shipreserved = ((ship.reserved || EMPTY_OBJ)[this.slotgroup] || EMPTY_OBJ)[this.slotnum];
if (shipreserved && !shipreserved[module.mtype]) return false; // slot does not allow the module type (i.e. Beluga/Orca/Dolphin cabins-only slots)
return true;
}, // isModuleIDAllowed()
isEnough: function() {
if (!this.slotgroup || this.slotgroup === 'ship' || !this.modid) return true; // detached slots, ship pseudogroup slots, and empty slots are always enough if they're allowed
var ship = eddb.ship[this.build.getShipID()];
if (this.slotgroup === 'component' && this.slotnum == CORE_ABBR_SLOT.TH && ship.mass > this.getEffectiveAttrValue('engmaxmass')) return false; // ship mass exceeds thruster maximum
if (this.slotgroup === 'component' && this.slotnum == CORE_ABBR_SLOT.PD && ship.boostcost + BOOST_MARGIN > this.getEffectiveAttrValue('engcap')) return false; // ship boost cost exceeds distributor capacity
if (this.module.mtype === 'isg' && ship.mass > this.getEffectiveAttrValue('genmaxmass')) return false; // ship mass exceeds shieldgen maximum
return true;
}, // isEnough()
swapWith: function(slot2) {
if (!slot2 || !(slot2 instanceof Slot) || (slot2.build !== this.build) || !this.slotgroup || (this.slotgroup === 'ship') || !slot2.slotgroup || (slot2.slotgroup === 'ship'))
return false;
var modid1 = this.modid;
var modid2 = slot2.modid;
if (!(current.option.experimental ? (this.isModuleIDValid(modid2) && slot2.isModuleIDValid(modid1)) : (this.isModuleIDAllowed(modid2) && slot2.isModuleIDAllowed(modid1))))
return false;
var slotgroup1 = this.slotgroup;
var slotnum1 = this.slotnum;
this.slotgroup = slot2.slotgroup;
this.slotnum = slot2.slotnum;
slot2.slotgroup = slotgroup1;
slot2.slotnum = slotnum1;
return true;
}, // swapWith()
getShipID: function() {
return this.build.getShipID();
}, // getShipID()