-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert.js
110 lines (101 loc) · 3.08 KB
/
convert.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
/*global sprintf*/
(function(global) {
function toEHex(n) {
return '0123456789ABCDEFGHJKLMNPQRSTUVW'.charAt(n);
}
// Hex
function sys2hex(system, e2t) {
var hex = e2t(system.x, system.y);
return sprintf('%02d%02d', hex.x, hex.y);
}
// UWP
function sys2uwp(system) {
var st = system.techlev > 10 ? 'A' : 'B';
var siz = toEHex(Math.round(system.radius / 1600));
var atm =
/vacuum/.test(system.description) ? '0' :
/(unusual|pink) oceans/.test(system.description) ? 'A' :
'7';
var hyd =
/vacuum/.test(system.description) ? '0' :
/vast oceans/.test(system.description) ? 'A' :
/oceans/.test(system.description) ? '7' :
'3';
var pop = toEHex(Math.floor(Math.log10(system.population * 1e8)));
var gov = [
'0', // Anarchy => No Government Structure
'5', // Feudal => Feudal Technocracy
'7', // Multi-gov => Balkanization
'B', // Dictatorship => Non-Charismatic Dictator (or 'A', 'D')
'9', // Communist => Impersonal Bureacracy
'7', // Confederacy => Balkanization
'2', // Democracy => Participating Democracy
'1' // Corporate State => Company/Corporation
][system.govtype];
var law = 'X';
var tl = toEHex(system.techlev + 1);
return st + siz + atm + hyd + pop + gov + law + '-' + tl;
}
// Bases
function sys2base(system) { return ' '; }
// Remarks
function sys2rem(system) {
var rem = [
'In Ri', // Rich Ind
'In', // Average Ind
'In Po', // Poor Ind
'In', // Mainly Ind
'Ag', // Mainly Agri
'Ag Ri', // Rich Agri
'Ag', // Average Agri
'Ag Po' // Poor Agri
][system.economy];
if ((system.population * 1e8) > 1e9)
rem += ' Hi';
if (/vacuum/.test(system.description))
rem += ' Va';
if (/(unusual|pink) oceans/.test(system.description))
rem += ' Fl';
if (/vast oceans/.test(system.description))
rem += ' Wa';
return rem.split(' ').sort().join(' ');
}
var RED_WORDS = new Set([
'war', 'disease'
]);
var AMBER_WORDS = new Set([
'plagued', 'ravaged', 'cursed', 'killer', 'deadly'
]);
// Zone
function sys2zone(system) {
var words = system.description.toLowerCase().replace(/\./, '').split(/\s+/);
if (words.some(function(word) { return RED_WORDS.has(word); }))
return 'R';
if (words.some(function(word) { return AMBER_WORDS.has(word); }))
return 'A';
if (system.govtype === 0) // Anarchy
return 'A';
return ' ';
}
// PBG
function sys2pbg(system) {
var pop = system.population * 1e8;
var exp = Math.floor(Math.log10(pop));
var pmult = Math.floor(pop / Math.pow(10, exp));
return sprintf('%dXX', pmult);
}
function elite2traveller(system, e2t) {
return {
name: system.name,
hex: sys2hex(system, e2t),
uwp: sys2uwp(system),
base: sys2base(system),
remarks: sys2rem(system),
zone: sys2zone(system),
pbg: sys2pbg(system),
alleg: 'Xx',
stellar: ''
};
}
global.elite2traveller = elite2traveller;
}(self));