-
Notifications
You must be signed in to change notification settings - Fork 48
/
constants.js
377 lines (368 loc) · 10.9 KB
/
constants.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
const TITLE = "Cyclone Simulator";
const VERSION_NUMBER = "0.4.19";
const SAVE_FORMAT = 7; // Format #7 in use starting in v0.4
const EARLIEST_COMPATIBLE_FORMAT = 0;
const ENVDATA_COMPATIBLE_FORMAT = 0;
const WIDTH = 960; // 16:9 aspect ratio
const HEIGHT = 540;
const DIAMETER = 20; // Storm icon diameter
const PERLIN_ZOOM = 100; // Resolution for perlin noise
const TICK_DURATION = 3600000; // How long in sim time does a tick last in milliseconds (1 hour)
const ADVISORY_TICKS = 6; // Number of ticks per advisory
const YEAR_LENGTH = 365.2425*24; // The length of a year in ticks; used for seasonal activity
const STEP = 30; // Number of milliseconds in real time a simulation step lasts at default speed
const NHEM_DEFAULT_YEAR = moment.utc().year();
const SHEM_DEFAULT_YEAR = moment.utc().month() < 6 ? NHEM_DEFAULT_YEAR : NHEM_DEFAULT_YEAR+1;
const DEPRESSION_LETTER = "H";
const WINDSPEED_ROUNDING = 5;
// const MAP_DEFINITION = 2; // normal scaler for the land map
const EARTH_SB_IDS = {
world: 0,
nhem: 1,
atl: 2,
atlland: 3,
epac: 4,
epacland: 5,
cpac: 6,
wpac: 7,
pagasa: 8,
bob: 9,
arb: 10,
nioland: 11,
medi: 12,
shem: 128,
aus: 129,
jakarta: 130,
pm: 131,
swio: 132,
spac: 133,
satl: 134,
nio: 192
};
const MAP_TYPES = [ // Land generation controls and option presets for different map types
{
label: "Two Continents",
form: "linear",
landBiasFactors: [
5/8, // Where the "center" should be for land/ocean bias (0-1 scale from west to east)
0.15, // Bias factor for the west edge (positive = land more likely, negative = sea more likely)
-0.3, // Bias factor for the "center" (as defined by .landBiasFactors[0])
0.1 // Bias factor for the east edge
],
optionPresets: {
designations: 22
}
},
{
label: "East Continent",
form: "linear",
landBiasFactors: [
5/8,
-0.3,
-0.3,
0.15
],
optionPresets: {
designations: 22
}
},
{
label: "West Continent",
form: "linear",
landBiasFactors: [
1/2,
0.15,
-0.3,
-0.3
],
optionPresets: {
designations: 22
}
},
{
label: "Island Ocean",
form: "linear",
landBiasFactors: [
1/2,
-0.28,
-0.28,
-0.28
],
optionPresets: {
designations: 22
}
},
{
label: "Central Continent",
form: "radial",
landBiasFactors: [
1/2, // Where the east-west center should be (0-1 scale from west to east)
1/2, // Where the north-south center should be (0-1 scale from north to south)
1/2, // First control distance (in terms of the geometric mean of the canvas dimensions)
1, // Second control distance
0.15, // Bias factor for the center
-0.27, // Bias factor for the first control distance
-0.3 // Bias factor for the second control distance and outward
],
optionPresets: {
designations: 22
}
},
{
label: "Central Inland Sea",
form: "radial",
landBiasFactors: [
1/2,
1/2,
3/8,
1,
-0.3,
0.2,
0.3
],
optionPresets: {
designations: 22
}
},
{
label: "Atlantic",
form: 'earth',
west: -102.67,
east: 3,
north: 59.45,
south: 0,
mainSubBasin: EARTH_SB_IDS.atl,
optionPresets: {
hem: 1,
scale: 0,
designations: 0
}
},
{
label: "Eastern Pacific",
form: 'earth',
west: -180,
east: -74.33,
north: 59.45,
south: 0,
mainSubBasin: EARTH_SB_IDS.epac,
optionPresets: {
hem: 1,
scale: 0,
designations: 1
}
},
{
label: "Western Pacific",
form: 'earth',
west: 94.42,
east: -159.91,
north: 59.45,
south: 0,
mainSubBasin: EARTH_SB_IDS.wpac,
optionPresets: {
hem: 1,
scale: 3,
designations: 3
}
},
{
label: "Northern Indian Ocean",
form: 'earth',
west: 25.95,
east: 131.62,
north: 59.45,
south: 0,
mainSubBasin: EARTH_SB_IDS.nio,
optionPresets: {
hem: 1,
scale: 4,
designations: 5
}
},
{
label: "Australian Region",
form: 'earth',
west: 82.03,
east: -172.29,
north: 0,
south: -59.45,
mainSubBasin: EARTH_SB_IDS.aus,
optionPresets: {
hem: 2,
scale: 2,
designations: 6
}
},
{
label: "South Pacific",
form: 'earth',
west: 147.2,
east: -107.13,
north: 0,
south: -59.45,
mainSubBasin: EARTH_SB_IDS.spac,
optionPresets: {
hem: 2,
scale: 2,
designations: 7
}
},
{
label: "South-West Indian Ocean",
form: 'earth',
west: 17.25,
east: 122.93,
north: 0,
south: -59.45,
mainSubBasin: EARTH_SB_IDS.swio,
optionPresets: {
hem: 2,
scale: 5,
designations: 8
}
},
{
label: "South Atlantic",
form: 'earth',
west: -81.48,
east: 24.19,
north: 0,
south: -59.45,
mainSubBasin: EARTH_SB_IDS.satl,
optionPresets: {
hem: 2,
scale: 0,
designations: 9
}
},
{
label: "Mediterranean",
form: 'earth',
west: -10.32,
east: 42.52,
north: 55.38,
south: 25.65,
mainSubBasin: EARTH_SB_IDS.medi,
optionPresets: {
hem: 1,
scale: 0,
designations: 10
}
}
];
const EARTH_MAP_PATH = 'resources/earth.png';
const EXTROP = 0;
const SUBTROP = 1;
const TROP = 2;
const TROPWAVE = 3;
const STORM_TYPES = 4;
const KEY_LEFT_BRACKET = 219;
const KEY_RIGHT_BRACKET = 221;
const KEY_F11 = 122;
const KEY_REPEAT_COOLDOWN = 15;
const KEY_REPEATER = 5;
const MAX_SNOW_LAYERS = 50;
const SNOW_SEASON_OFFSET = 5/6;
const ENV_LAYER_TILE_SIZE = 20;
const NC_OFFSET_RANDOM_FACTOR = 4096;
const ACE_WIND_THRESHOLD = 34;
const ACE_DIVISOR = 10000;
const DAMAGE_DIVISOR = 1000;
const ENVDATA_NOT_FOUND_ERROR = "envdata-not-found";
const LOADED_SEASON_REQUIRED_ERROR = "loaded-season-required";
const LOAD_MENU_BUTTONS_PER_PAGE = 6;
const DEFAULT_MAIN_SUBBASIN = 0;
const DEFAULT_OUTBASIN_SUBBASIN = 255;
const DESIG_CROSSMODE_ALWAYS = 0;
const DESIG_CROSSMODE_STRICT_ALWAYS = 1;
const DESIG_CROSSMODE_REGEN = 2;
const DESIG_CROSSMODE_STRICT_REGEN = 3;
const DESIG_CROSSMODE_KEEP = 4;
const SCALE_MEASURE_ONE_MIN_KNOTS = 0;
const SCALE_MEASURE_TEN_MIN_KNOTS = 1;
const SCALE_MEASURE_MILLIBARS = 2;
const SCALE_MEASURE_INHG = 3;
const SCALE_MEASURE_ONE_MIN_MPH = 4;
const SCALE_MEASURE_TEN_MIN_MPH = 5;
const SCALE_MEASURE_ONE_MIN_KMH = 6;
const SCALE_MEASURE_TEN_MIN_KMH = 7;
const MIN_SPEED = -5;
const MAX_SPEED = 5;
// Saving/loading-related constants
const AUTOSAVE_SAVE_NAME = "Autosave";
const DB_KEY_SETTINGS = "settings";
const LOADED_SEASON_EXPIRATION = 150000; // minimum duration in miliseconds after a season was last accessed before it unloads (2.5 minutes)
const FORMAT_WITH_SAVED_SEASONS = 1;
const FORMAT_WITH_INDEXEDDB = 2;
const FORMAT_WITH_IMPROVED_ENV = 3;
const FORMAT_WITH_SUBBASIN_SEASON_STATS = 4;
const FORMAT_WITH_STORM_SUBBASIN_DATA = 5;
const FORMAT_WITH_SCALES = 6;
const FORMAT_WITH_EARTH_SUBBASINS = 7;
const FORMAT_WITH_LONG_LAT = 7;
// Legacy saving/loading-related constants (backwards-compatibility)
const LEGACY_SAVE_NAME_PREFIX = "Slot ";
const LOCALSTORAGE_KEY_PREFIX = "cyclone-sim-";
const LOCALSTORAGE_KEY_SAVEDBASIN = "savedbasin-";
const LOCALSTORAGE_KEY_BASIN = "basin";
const LOCALSTORAGE_KEY_FORMAT = "format";
const LOCALSTORAGE_KEY_NAMES = "names";
const LOCALSTORAGE_KEY_SEASON = "season-";
const LOCALSTORAGE_KEY_SETTINGS = "settings";
const SAVING_RADIX = 36;
// const ENVDATA_SAVE_FLOAT = -2;
const ENVDATA_SAVE_MULT = 10000;
// const ACTIVESYSTEM_SAVE_FLOAT = -2;
const HELP_TEXT = "Keyboard Controls:\n" +
"\t\tSPACE - Pause/resume simulation\n" +
"\t\tA - Step simulation one hour while paused\n" +
"\t\tE - Cycle through map layers\n" +
"\t\tT - Cycle through track display modes\n" +
"\t\tW - Toggle intensity indicators below storm icons (kts / hPa)\n" +
"\t\tM - Toggle magnifying glass for map layers\n" +
"\t\t[ - Decrease simulation speed (half)\n" +
"\t\t] - Increase simulation speed (double)\n" +
"\t\tLEFT ARROW - Step backwards through analysis\n" +
"\t\tRIGHT ARROW - Step forewards through analysis\n" +
"\t\tCLICK + [special key] - Spawn [corresponding storm system]\n" +
"\t\t\t\tX - Extratropical cyclone\n" +
"\t\t\t\tL - Tropical Low/Wave\n" +
"\t\t\t\tD - Tropical Depression\n" +
"\t\t\t\tS - Tropical Storm\n" +
"\t\t\t\t[number key 1-9] - Category [1-9]* Tropical Cyclone\n" +
'\t\t\t\t0 - Category 10* Tropical Cyclone\n' +
'\t\t\t\tY - Hyperclone*\n' +
'\t\t\t\t\t*must use Extended Saffir-Simpson scale to see C6+ storms';
const COLORS = {}; // For storing all colors used in the graphics
function defineColors(){ // Since p5 color() function doesn't work until setup(), this is called in setup()
COLORS.bg = color(10,55,155);
COLORS.storm = {};
COLORS.storm[EXTROP] = color(220,220,220);
COLORS.storm[TROPWAVE] = color(130,130,240);
COLORS.storm.extL = "red";
COLORS.land = [];
COLORS.land.push([0.85, color(190,190,190)]);
COLORS.land.push([0.8, color(160,160,160)]);
COLORS.land.push([0.75, color(145,115,90)]);
COLORS.land.push([0.7, color(160,125,100)]);
COLORS.land.push([0.65, color(35,145,35)]);
COLORS.land.push([0.6, color(35,160,35)]);
COLORS.land.push([0.55, color(30,175,30)]);
COLORS.land.push([0.53, color(205,205,105)]);
COLORS.land.push([0.5, color(230,230,105)]);
COLORS.snow = color(240);
COLORS.outBasin = color(45,70,120);
COLORS.subBasinOutline = color(255,255,0);
COLORS.UI = {};
COLORS.UI.bar = color(200,100);
COLORS.UI.box = color(200,170);
COLORS.UI.buttonBox = color(200,170);
COLORS.UI.buttonHover = color(200);
COLORS.UI.text = color(0);
COLORS.UI.greyText = color(130);
COLORS.UI.redText = color(240,0,0);
COLORS.UI.nonSelectedInput = color(70);
COLORS.UI.input = color(255);
COLORS.UI.loadingSymbol = color(0,40,85);
}