-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
1871 lines (1645 loc) · 74.9 KB
/
main.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
/*
* MFI Metro
* Copyright (C) 2022 Shandra McCollough <[email protected]>
*/
// Initializing game data variables
var gameData = {
version: 0.52,
money: 50000,
ticketPrice: 100,
passengers: 0,
ginza: { line: 0, stations: 0, locomotives: 0, cars: 0 },
marunouchi: { line: 0, stations: 0, locomotives: 0, cars: 0 },
hibiya: { line: 0, stations: 0, locomotives: 0, cars: 0 },
tozai: { line: 0, stations: 0, locomotives: 0, cars: 0 },
chiyoda: { line: 0, stations: 0, locomotives: 0, cars: 0 },
yurakucho: { line: 0, stations: 0, locomotives: 0, cars: 0 },
hanzomon: { line: 0, stations: 0, locomotives: 0, cars: 0 },
namboku: { line: 0, stations: 0, locomotives: 0, cars: 0 },
fukutoshin: { line: 0, stations: 0, locomotives: 0, cars: 0 },
bXP: 0,
highestLine: 0,
prestige: { upgrade1Lvl: 0, upgrade2Lvl: 0, upgrade3Lvl: 0, upgrade4Lvl: 0, upgrade5Lvl: 0, upgrade6Lvl: 0, upgrade7Lvl: 0 }
} // remember to add new variables to load function, even ones in nested objects
// remember to check compatibility with prestige resetting function
// non gameData variables
var pps = 0;
var maxPassengers = 0;
var mps = 0;
var unrealizedPrestige = 0;
var lineCost = 0; // dont forget this exists
// constants for base values
const ticketPriceEqConst = 200;
const ticketPriceMaxConst = 1000;
const ppsPerStatConst = 6;
const locoPerStatConst = 1;
const carPerLocoConst = 6;
const passPerCarConst = 100;
const statPerLine = 5; // for determining balance
// variables than can be changed by upgrades
var ticketPriceEq = ticketPriceEqConst;
var ticketPriceMax = ticketPriceMaxConst;
var ppsPerStat = ppsPerStatConst;
var locoPerStat = locoPerStatConst;
var carPerLoco = carPerLocoConst;
var passPerCar = passPerCarConst;
// Defining save function
function save() {
localStorage.setItem("mfiSave",JSON.stringify(gameData)); // mfiSave is name of locally stored data
console.log('Game Saved!');
}
// Defining load function
function load() {
var saveGame = JSON.parse(localStorage.getItem("mfiSave")); // saveGame is the decoded save
if (saveGame !==null) { // runs if player has a save file
if (saveGame.version !== gameData.version) { // runs if the save is out of date
// removing support for saves before 0.50
if (saveGame.version < 0.5 || isNaN(saveGame.version) ) {
alert('MFI Metro v0.5 is incompatible with previous version saves. Your progress will be reset.');
saveGame = gameData;
}
if (typeof saveGame.version === 'undefined') saveGame.version = gameData.version;
if (typeof saveGame.money === 'undefined') saveGame.money = gameData.money;
if (typeof saveGame.ticketPrice === 'undefined') saveGame.ticketPrice = gameData.ticketPrice;
if (typeof saveGame.passengers === 'undefined') saveGame.passengers = gameData.passengers;
if (typeof saveGame.ginza === 'undefined') saveGame.ginza = gameData.ginza;
if (typeof saveGame.marunouchi === 'undefined') saveGame.marunouchi = gameData.marunouchi;
if (typeof saveGame.hibiya === 'undefined') saveGame.hibiya = gameData.hibiya;
if (typeof saveGame.tozai === 'undefined') saveGame.tozai = gameData.tozai;
if (typeof saveGame.chiyoda === 'undefined') saveGame.chiyoda = gameData.chiyoda;
if (typeof saveGame.yurakucho === 'undefined') saveGame.yurakucho = gameData.yurakucho;
if (typeof saveGame.hanzomon === 'undefined') saveGame.hanzomon = gameData.hanzomon;
if (typeof saveGame.namboku === 'undefined') saveGame.namboku = gameData.namboku;
if (typeof saveGame.fukutoshin === 'undefined') saveGame.fukutoshin = gameData.fukutoshin;
if (typeof saveGame.bXP === 'undefined') saveGame.bXP = gameData.bXP;
if (typeof saveGame.highestLine === 'undefined') saveGame.highestLine = gameData.highestLine;
if (typeof saveGame.prestige === 'undefined') saveGame.prestige = gameData.prestige;
if (typeof saveGame.prestige.upgrade1Lvl === 'undefined') saveGame.prestige.upgrade7Lvl = gameData.prestige.upgrade7Lvl;
saveGame.version = gameData.version;
console.log(`saveGame has been updated to ${gameData.version}`);
}
gameData = saveGame; // loading the player's save data into the game
refresh(); // visually refreshing values
console.log('Game Loaded!');
}
}
// Defining delete save function
function deleteSave() {
clearInterval(autosaveLoop);
if(confirm("This will delete your progress, are you sure?") === true) {
localStorage.removeItem("mfiSave");
console.log('Save Deleted!');
location.reload();
} else {
console.log('Delete Cancelled.')
location.reload();
}
}
// General tools
function update(id, content) {
document.getElementById(id).innerHTML = content;
}
function show(id) {
document.getElementById(id).style.display = "inline-block";
}
function hide(id) {
document.getElementById(id).style.display = "none";
}
function changeAccentColor() {
let accentColor = prompt("Enter a HEX color","#40CFFF");
if(!accentColor.match(/^#[0-9A-F]{6}$/i) ) {
alert("Please enter a valid HEX color."); return;
}
document.documentElement.style.setProperty('--accentColor', accentColor);
}
// navigation tools
function goToTab(tab) {
hide("linesTab");
document.getElementById("linesTabButton").setAttribute("class", "button nav")
hide("prestigeTab");
document.getElementById("prestigeTabButton").setAttribute("class", "button nav")
hide("optionsTab");
document.getElementById("optionsTabButton").setAttribute("class", "button nav")
if(tab === 'linesTab') {
document.getElementById("linesTab").style.display = "block";
document.getElementById("linesTabButton").setAttribute("class", "button nav active");
window.scrollTo(0, 0);
refresh();
}
if(tab === 'prestigeTab') {
document.getElementById("prestigeTab").style.display = "block";
document.getElementById("prestigeTabButton").setAttribute("class", "button nav active");
window.scrollTo(0, 0);
refreshPrestige(); // in theory, prestige should only need to be updated here
}
if(tab === 'optionsTab') {
document.getElementById("optionsTab").style.display = "block";
document.getElementById("optionsTabButton").setAttribute("class", "button nav active");
window.scrollTo(0, 0);
}
}
// line refresh functions
function refreshGinza() {
update("ginStations", format(gameData.ginza.stations) );
ginStationCost = calcStationCost(gameData.ginza.stations);
update("ginStationCost", format(ginStationCost));
update("ginLocomotives", format(gameData.ginza.locomotives) );
update("ginMaxLocomotives", format(gameData.ginza.stations * locoPerStat) );
ginLocomotiveCost = calcLocomotiveCost(gameData.ginza.locomotives);
update("ginLocomotiveCost", format(ginLocomotiveCost));
update("ginCars", format(gameData.ginza.cars) );
update("ginMaxCars", format(gameData.ginza.locomotives * carPerLoco) );
ginCarCost = calcCarCost(gameData.ginza.cars);
update("ginCarCost", format(ginCarCost));
}
function refreshMarunouchi() {
update("maruStations", format(gameData.marunouchi.stations) );
maruStationCost = calcStationCost(gameData.marunouchi.stations);
update("maruStationCost", format(maruStationCost));
update("maruLocomotives", format(gameData.marunouchi.locomotives) );
update("maruMaxLocomotives", format(gameData.marunouchi.stations * locoPerStat) );
maruLocomotiveCost = calcLocomotiveCost(gameData.marunouchi.locomotives);
update("maruLocomotiveCost", format(maruLocomotiveCost));
update("maruCars", format(gameData.marunouchi.cars) );
update("maruMaxCars", format(gameData.marunouchi.locomotives * carPerLoco) );
maruCarCost = calcCarCost(gameData.marunouchi.cars);
update("maruCarCost", format(maruCarCost));
}
function refreshHibiya() {
update("hibiStations", format(gameData.hibiya.stations) );
hibiStationCost = calcStationCost(gameData.hibiya.stations);
update("hibiStationCost", format(hibiStationCost));
update("hibiLocomotives", format(gameData.hibiya.locomotives) );
update("hibiMaxLocomotives", format(gameData.hibiya.stations * locoPerStat) );
hibiLocomotiveCost = calcLocomotiveCost(gameData.hibiya.locomotives);
update("hibiLocomotiveCost", format(hibiLocomotiveCost));
update("hibiCars", format(gameData.hibiya.cars) );
update("hibiMaxCars", format(gameData.hibiya.locomotives * carPerLoco) );
hibiCarCost = calcCarCost(gameData.hibiya.cars);
update("hibiCarCost", format(hibiCarCost));
}
function refreshTozai() {
update("tozaStations", format(gameData.tozai.stations) );
tozaStationCost = calcStationCost(gameData.tozai.stations);
update("tozaStationCost", format(tozaStationCost));
update("tozaLocomotives", format(gameData.tozai.locomotives) );
update("tozaMaxLocomotives", format(gameData.tozai.stations * locoPerStat) );
tozaLocomotiveCost = calcLocomotiveCost(gameData.tozai.locomotives);
update("tozaLocomotiveCost", format(tozaLocomotiveCost));
update("tozaCars", format(gameData.tozai.cars) );
update("tozaMaxCars", format(gameData.tozai.locomotives * carPerLoco) );
tozaCarCost = calcCarCost(gameData.tozai.cars);
update("tozaCarCost", format(tozaCarCost));
}
function refreshChiyoda() {
update("chiyoStations", format(gameData.chiyoda.stations) );
chiyoStationCost = calcStationCost(gameData.chiyoda.stations);
update("chiyoStationCost", format(chiyoStationCost));
update("chiyoLocomotives", format(gameData.chiyoda.locomotives) );
update("chiyoMaxLocomotives", format(gameData.chiyoda.stations * locoPerStat) );
chiyoLocomotiveCost = calcLocomotiveCost(gameData.chiyoda.locomotives);
update("chiyoLocomotiveCost", format(chiyoLocomotiveCost));
update("chiyoCars", format(gameData.chiyoda.cars) );
update("chiyoMaxCars", format(gameData.chiyoda.locomotives * carPerLoco) );
chiyoCarCost = calcCarCost(gameData.chiyoda.cars);
update("chiyoCarCost", format(chiyoCarCost));
}
function refreshYurakucho() {
update("yuraStations", format(gameData.yurakucho.stations) );
yuraStationCost = calcStationCost(gameData.yurakucho.stations);
update("yuraStationCost", format(yuraStationCost));
update("yuraLocomotives", format(gameData.yurakucho.locomotives) );
update("yuraMaxLocomotives", format(gameData.yurakucho.stations * locoPerStat) );
yuraLocomotiveCost = calcLocomotiveCost(gameData.yurakucho.locomotives);
update("yuraLocomotiveCost", format(yuraLocomotiveCost));
update("yuraCars", format(gameData.yurakucho.cars) );
update("yuraMaxCars", format(gameData.yurakucho.locomotives * carPerLoco) );
yuraCarCost = calcCarCost(gameData.yurakucho.cars);
update("yuraCarCost", format(yuraCarCost));
}
function refreshHanzomon() {
update("hanStations", format(gameData.hanzomon.stations) );
hanStationCost = calcStationCost(gameData.hanzomon.stations);
update("hanStationCost", format(hanStationCost));
update("hanLocomotives", format(gameData.hanzomon.locomotives) );
update("hanMaxLocomotives", format(gameData.hanzomon.stations * locoPerStat) );
hanLocomotiveCost = calcLocomotiveCost(gameData.hanzomon.locomotives);
update("hanLocomotiveCost", format(hanLocomotiveCost));
update("hanCars", format(gameData.hanzomon.cars) );
update("hanMaxCars", format(gameData.hanzomon.locomotives * carPerLoco) );
hanCarCost = calcCarCost(gameData.hanzomon.cars);
update("hanCarCost", format(hanCarCost));
}
function refreshNamboku() {
update("namStations", format(gameData.namboku.stations) );
namStationCost = calcStationCost(gameData.namboku.stations);
update("namStationCost", format(namStationCost));
update("namLocomotives", format(gameData.namboku.locomotives) );
update("namMaxLocomotives", format(gameData.namboku.stations * locoPerStat) );
namLocomotiveCost = calcLocomotiveCost(gameData.namboku.locomotives);
update("namLocomotiveCost", format(namLocomotiveCost));
update("namCars", format(gameData.namboku.cars) );
update("namMaxCars", format(gameData.namboku.locomotives * carPerLoco) );
namCarCost = calcCarCost(gameData.namboku.cars);
update("namCarCost", format(namCarCost));
}
function refreshFukutoshin() {
update("fukuStations", format(gameData.fukutoshin.stations) );
fukuStationCost = calcStationCost(gameData.fukutoshin.stations);
update("fukuStationCost", format(fukuStationCost));
update("fukuLocomotives", format(gameData.fukutoshin.locomotives) );
update("fukuMaxLocomotives", format(gameData.fukutoshin.stations * locoPerStat) );
fukuLocomotiveCost = calcLocomotiveCost(gameData.fukutoshin.locomotives);
update("fukuLocomotiveCost", format(fukuLocomotiveCost));
update("fukuCars", format(gameData.fukutoshin.cars) );
update("fukuMaxCars", format(gameData.fukutoshin.locomotives * carPerLoco) );
fukuCarCost = calcCarCost(gameData.fukutoshin.cars);
update("fukuCarCost", format(fukuCarCost));
}
// end line refresh functions
// Defining refresh function to update page after loading game
function refresh() {
// refreshing values from gameData
update("money", format(gameData.money));
update("ticketPrice", format(gameData.ticketPrice) );
update("passengers", gameData.passengers.toLocaleString("en-US"));
// refreshing variables effected by prestige upgrades
ticketPriceEq = ticketPriceEqConst * 2 ** gameData.prestige.upgrade1Lvl;
ticketPriceMax = ticketPriceMaxConst * 2 ** gameData.prestige.upgrade2Lvl;
ppsPerStat = ppsPerStatConst + (2 * gameData.prestige.upgrade3Lvl);
locoPerStat = locoPerStatConst + (1 * gameData.prestige.upgrade4Lvl);
carPerLoco = carPerLocoConst + (2 * gameData.prestige.upgrade5Lvl);
passPerCar = passPerCarConst + (50 * gameData.prestige.upgrade6Lvl);
// refreshing formulas dependent on gameData
updatePps();
updateMps();
updateMaxPassengers();
lineCost = calcLineCost();
// making sure proper elements are displayed per line
if(gameData.bXP < 1 && gameData.tozai.line < 1) {
hide("prestigeTabButton");
} // make sure buyTozaLine makes this button show
if(gameData.ginza.line < 1) {
update("ginLineCost", format(lineCost));
}
if(gameData.ginza.line > 0) {
show("ginzaBody"); hide("ginzaHead");
refreshGinza();
show("marunouchiHead");
update("maruLineCost", format(lineCost));
}
if(gameData.marunouchi.line > 0) {
show("marunouchiBody"); hide("marunouchiHead");
refreshMarunouchi();
show("hibiyaHead");
update("hibiLineCost", format(lineCost));
}
if(gameData.hibiya.line > 0) {
show("hibiyaBody"); hide("hibiyaHead");
refreshHibiya();
show("tozaiHead");
update("tozaLineCost", format(lineCost));
}
if(gameData.tozai.line > 0) {
show("tozaiBody"); hide("tozaiHead");
refreshTozai();
show("chiyodaHead");
update("chiyoLineCost", format(lineCost));
}
if(gameData.chiyoda.line > 0) {
show("chiyodaBody"); hide("chiyodaHead");
refreshChiyoda();
show("yurakuchoHead");
update("yuraLineCost", format(lineCost));
}
if(gameData.yurakucho.line > 0) {
show("yurakuchoBody"); hide("yurakuchoHead");
refreshYurakucho();
show("hanzomonHead");
update("hanLineCost", format(lineCost));
}
if(gameData.hanzomon.line > 0) {
show("hanzomonBody"); hide("hanzomonHead");
refreshHanzomon();
show("nambokuHead");
update("namLineCost", format(lineCost));
}
if(gameData.namboku.line > 0) {
show("nambokuBody"); hide("nambokuHead");
refreshNamboku();
show("fukutoshinHead");
update("fukuLineCost", format(lineCost));
}
if(gameData.fukutoshin.line > 0) {
show("fukutoshinBody"); hide("fukutoshinHead");
refreshFukutoshin();
show("endMessage");
}
}
// INITIAL GAME LOAD
load();
refresh();
update("titleVer", `v${gameData.version}`);
if(window.location.href === "https://smmdesign.github.io/mfiMetro/alpha/") {titleVer.insertAdjacentHTML('afterend', ' <span style="font-size:70%;">ALPHA</span>');}
if(window.location.href !== "https://smmdesign.github.io/mfiMetro/" && window.location.href !== "https://smmdesign.github.io/mfiMetro/alpha/" && window.location.protocol !== "file:") {document.body.insertAdjacentHTML( 'afterbegin', '<div class="titleBar" style="height:auto;background-color:darkred;color:white;text-align:center;font-weight:bold;font-size:80%;"><a href="https://smmdesign.github.io/mfiMetro/" style="color:white;text-decoration: none;">This is a copy, please support the original game at <u>smmdesign.github.io/mfiMetro</u></a></div>');}
goToTab('linesTab');
// goToTab('prestigeTab'); // while editing so i dont have to switch every F5
// goToTab('optionsTab'); // while editing so i dont have to switch every F5
// GAME FUNCTIONS
function makeMoney(number) {
gameData.money += number;
update("money", format(gameData.money));
}
function generatePassengers(number) {
gameData.passengers += number;
// Prevents passengers from exceeding passenger car max
if (gameData.passengers >= calcTotalCars() * passPerCar) {
gameData.passengers = calcTotalCars() * passPerCar;
}
// Prevents passengers from going below zero
if (gameData.passengers < 0) {
gameData.passengers = 0;
}
update("passengers", gameData.passengers.toLocaleString("en-US"));
updateMps();
updatePps();
}
function setTicketPrice() {
let userPrice = prompt(`Set Price ( 1 - ${format(ticketPriceMax)} )`,"100");
if(userPrice === null || isNaN(userPrice)) { return;}
if(userPrice < 1 || userPrice > ticketPriceMax) {
alert(`Please enter a number between 1 and ${format(ticketPriceMax)}.`); return;
}
gameData.ticketPrice = Math.round(userPrice);
update("ticketPrice", format(gameData.ticketPrice) );
updatePps(); // because pps is dependent on ticket price
updateMps(); // because mps is dependent on ticket price
}
function adjustTicketPrice(number) {
if(number === 'min') {gameData.ticketPrice = 1;}
if(number === 'eq') {
if(ticketPriceEq > ticketPriceMax) {
gameData.ticketPrice = ticketPriceMax;
} else {gameData.ticketPrice = ticketPriceEq;}
}
if(number === 'max') {gameData.ticketPrice = ticketPriceMax;}
// percentage based changes
let priceAdjust = gameData.ticketPrice + ticketPriceEq * number;
if(ticketPriceMax > priceAdjust > 0) { gameData.ticketPrice = priceAdjust; }
if(priceAdjust > ticketPriceMax) { gameData.ticketPrice = ticketPriceMax; }
if(priceAdjust < 1) { gameData.ticketPrice = 1; }
update("ticketPrice", format(gameData.ticketPrice) );
updatePps(); // because pps is dependent on ticket price
updateMps(); // because mps is dependent on ticket price
}
// ticket price formula location
function updatePps() {
pps = Math.ceil( (( ticketPriceEq - gameData.ticketPrice ) / ticketPriceEq ) * ( calcTotalStations() * ppsPerStat ) );
// prevents errors from dividing by zero
if(!pps) {
pps = 0;
}
// prevents stalling at 0 passengers once game has started
if(gameData.passengers === 0 && gameData.ginza.line > 0) {
gameData.passengers = 1;
}
update("pps", `(${pps.toLocaleString("en-US")}/s)`)
}
function updateMps() {
if(gameData.prestige.upgrade7Lvl === 0) {
mps = gameData.passengers * gameData.ticketPrice;
}
if(gameData.prestige.upgrade7Lvl > 0) {
mps = (gameData.passengers * gameData.ticketPrice) * (calcTotalLines() ** gameData.prestige.upgrade7Lvl);
}
update("mps", `(¥${format(mps)}/s)`)
}
function updateMaxPassengers() {
maxPassengers = calcTotalCars() * passPerCar;
update("maxPassengers", `/${maxPassengers.toLocaleString("en-US")}`)
}
// calc functions that return values
// remember to adjust max+multi if you adjust the individuals
function calcTotalLines() {
return gameData.ginza.line + gameData.marunouchi.line + gameData.hibiya.line + gameData.tozai.line + gameData.chiyoda.line + gameData.yurakucho.line + gameData.hanzomon.line + gameData.namboku.line + gameData.fukutoshin.line;
}
function calcTotalStations() {
return gameData.ginza.stations + gameData.marunouchi.stations + gameData.hibiya.stations + gameData.tozai.stations + gameData.chiyoda.stations + gameData.yurakucho.stations + gameData.hanzomon.stations + gameData.namboku.stations + gameData.fukutoshin.stations
}
function calcTotalLocomotives() {
return gameData.ginza.locomotives + gameData.marunouchi.locomotives + gameData.hibiya.locomotives + gameData.tozai.locomotives + gameData.chiyoda.locomotives + gameData.yurakucho.locomotives + gameData.hanzomon.locomotives + gameData.namboku.locomotives + gameData.fukutoshin.locomotives
}
function calcTotalCars() {
return gameData.ginza.cars + gameData.marunouchi.cars + gameData.hibiya.cars + gameData.tozai.cars + gameData.chiyoda.cars + gameData.yurakucho.cars + gameData.hanzomon.cars + gameData.namboku.cars + gameData.fukutoshin.cars
}
function calcLineCost() {
return Math.floor(50000 * ( (statPerLine * locoPerStatConst * carPerLocoConst) ** calcTotalLines()));
}
function calcStationCost(stations) {
return Math.floor(10000 * (2 ** stations ));
}
// these functions automatically readjust prices based on ratios from upgrades
function calcLocomotiveCost(locomotives) {
return Math.floor( (7000 * ( (1 + (0.8 * locoPerStatConst / locoPerStat)) ** locomotives )));
}
function calcCarCost(cars) {
return Math.floor( 5000 * ( (1 + (.1 * carPerLocoConst / carPerLoco * locoPerStatConst / locoPerStat)) ** cars ));
}
function calcMaxBuyNumber(type, owned) {
let base;
let increment;
if(type === 'station') {
base = 10000;
increment = 2;
}
if(type === 'locomotive') {
base = 7000;
increment = (1 + (0.8 * locoPerStatConst / locoPerStat));
}
if(type === 'car') {
base = 5000;
increment = (1 + (.1 * carPerLocoConst / carPerLoco * locoPerStatConst / locoPerStat));
}
let y = (increment ** owned) - (gameData.money *( 1 - increment ) / base);
let x = increment;
// returns the logarithm of y with base x
return Math.floor( (Math.log(y) / Math.log(x)) - owned);
}
function calcMultiBuyCost(type, owned, amount) {
let base;
let increment;
if(type === 'station') {
base = 10000;
increment = 2;
}
if(type === 'locomotive') {
base = 7000;
increment = (1 + (0.8 * locoPerStatConst / locoPerStat));
}
if(type === 'car') {
base = 5000;
increment = (1 + (.1 * carPerLocoConst / carPerLoco * locoPerStatConst / locoPerStat));
}
return Math.floor( base *((increment ** (owned) - increment ** (owned + amount))/(1-increment)) );
}
// end of calc functions
// buying functions
// buy all buttons
function buyAll1Station() {
if(gameData.ginza.line === 1) { buyGinStation(1); }
if(gameData.marunouchi.line === 1) { buyMaruStation(1); }
if(gameData.hibiya.line === 1) { buyHibiStation(1); }
if(gameData.tozai.line === 1) { buyTozaStation(1); }
if(gameData.chiyoda.line === 1) { buyChiyoStation(1); }
if(gameData.yurakucho.line === 1) { buyYuraStation(1); }
if(gameData.hanzomon.line === 1) { buyHanStation(1); }
if(gameData.namboku.line === 1) { buyNamStation(1); }
if(gameData.fukutoshin.line === 1) { buyFukuStation(1); }
}
function buyAllLocomotive() {
if(gameData.ginza.line === 1) { buyGinLocomotive('max'); }
if(gameData.marunouchi.line === 1) { buyMaruLocomotive('max'); }
if(gameData.hibiya.line === 1) { buyHibiLocomotive('max'); }
if(gameData.tozai.line === 1) { buyTozaLocomotive('max'); }
if(gameData.chiyoda.line === 1) { buyChiyoLocomotive('max'); }
if(gameData.yurakucho.line === 1) { buyYuraLocomotive('max'); }
if(gameData.hanzomon.line === 1) { buyHanLocomotive('max'); }
if(gameData.namboku.line === 1) { buyNamLocomotive('max'); }
if(gameData.fukutoshin.line === 1) { buyFukuLocomotive('max'); }
}
function buyAllCar() {
if(gameData.ginza.line === 1) { buyGinCar('max'); }
if(gameData.marunouchi.line === 1) { buyMaruCar('max'); }
if(gameData.hibiya.line === 1) { buyHibiCar('max'); }
if(gameData.tozai.line === 1) { buyTozaCar('max'); }
if(gameData.chiyoda.line === 1) { buyChiyoCar('max'); }
if(gameData.yurakucho.line === 1) { buyYuraCar('max'); }
if(gameData.hanzomon.line === 1) { buyHanCar('max'); }
if(gameData.namboku.line === 1) { buyNamCar('max'); }
if(gameData.fukutoshin.line === 1) { buyFukuCar('max'); }
}
// ginza buying functions
function buyGinLine() {
if(gameData.money >= lineCost) {
gameData.ginza.line = 1;
gameData.money -= lineCost;
gameData.ginza.stations += 2;
gameData.ginza.locomotives += 1;
gameData.ginza.cars += 1;
show("ginzaBody");
hide("ginzaHead");
show("marunouchiHead");
update("money", format(gameData.money));
lineCost = calcLineCost();
update("maruLineCost", format(lineCost));
refreshGinza();
updatePps(); // because pps is dependent on station number
updateMaxPassengers(); // because max is dependent on car number
updateMps(); // because mps is dependent on line number
gtag("event", "level_start", {
level_name: "Ginza Line"
});
}}
function buyGinStation(number) {
if(gameData.money >= ginStationCost) {
if(number === 1) {
gameData.ginza.stations += 1;
gameData.money -= ginStationCost;
}
if(number > 1) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('station', gameData.ginza.stations, number);
gameData.ginza.stations += number;
}
if(number === 'max') {
let maxNumber = calcMaxBuyNumber('station', gameData.ginza.stations);
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('station', gameData.ginza.stations, maxNumber);
gameData.ginza.stations += maxNumber;
}
ginStationCost = calcStationCost(gameData.ginza.stations);
update("money", format(gameData.money));
refreshGinza();
updatePps(); // because pps is dependent on station number
}
}
function buyGinLocomotive(number) {
if(gameData.ginza.locomotives < gameData.ginza.stations * locoPerStat && gameData.money >= ginLocomotiveCost) {
if(number === 1) {
gameData.ginza.locomotives += 1;
gameData.money -= ginLocomotiveCost;
}
if(number > 1) {
if(gameData.ginza.locomotives + number <= gameData.ginza.stations * locoPerStat) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('locomotive', gameData.ginza.locomotives, number);
gameData.ginza.locomotives += number;
}
}
if(number === 'max') {
let maxNumber = calcMaxBuyNumber('locomotive', gameData.ginza.locomotives);
if(gameData.ginza.locomotives + maxNumber <= gameData.ginza.stations * locoPerStat) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('locomotive', gameData.ginza.locomotives, maxNumber);
gameData.ginza.locomotives += maxNumber;
} else {
buyGinLocomotive((gameData.ginza.stations * locoPerStat) - gameData.ginza.locomotives); //buys to max capacity
}
}
ginLocomotiveCost = calcLocomotiveCost(gameData.ginza.locomotives);
update("money", format(gameData.money));
refreshGinza();
}
}
function buyGinCar(number) {
if(gameData.ginza.cars < gameData.ginza.locomotives * carPerLoco && gameData.money >= ginCarCost) {
if(number === 1) {
gameData.ginza.cars += 1;
gameData.money -= ginCarCost;
}
if(number > 1) {
if(gameData.ginza.cars + number <= gameData.ginza.locomotives * carPerLoco) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('car', gameData.ginza.cars, number);
gameData.ginza.cars += number;
}
}
if(number === 'max') {
let maxNumber = calcMaxBuyNumber('car', gameData.ginza.cars);
if(gameData.ginza.cars + maxNumber <= gameData.ginza.locomotives * carPerLoco) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('car', gameData.ginza.cars, maxNumber);
gameData.ginza.cars += maxNumber;
} else {
buyGinCar((gameData.ginza.locomotives * carPerLoco) - gameData.ginza.cars); //buys to max capacity
}
}
ginCarCost = calcCarCost(gameData.ginza.cars);
update("money", format(gameData.money));
refreshGinza();
updateMaxPassengers(); // because max is dependent on car number
}
}
// end of ginza buying functions
// marunouchi buying functions
function buyMaruLine() {
if(gameData.money >= lineCost) {
gameData.marunouchi.line = 1;
gameData.money -= lineCost;
gameData.marunouchi.stations += 2;
gameData.marunouchi.locomotives += 1;
gameData.marunouchi.cars += 1;
show("marunouchiBody");
hide("marunouchiHead");
show("hibiyaHead");
update("money", format(gameData.money));
lineCost = calcLineCost();
update("hibiLineCost", format(lineCost));
refreshMarunouchi();
updatePps(); // because pps is dependent on station number
updateMaxPassengers(); // because max is dependent on car number
updateMps(); // because mps is dependent on line number
gtag("event", "level_start", {
level_name: "Marunouchi Line"
});
}}
function buyMaruStation(number) {
if(gameData.money >= maruStationCost) {
if(number === 1) {
gameData.marunouchi.stations += 1;
gameData.money -= maruStationCost;
}
if(number > 1) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('station', gameData.marunouchi.stations, number);
gameData.marunouchi.stations += number;
}
if(number === 'max') {
let maxNumber = calcMaxBuyNumber('station', gameData.marunouchi.stations);
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('station', gameData.marunouchi.stations, maxNumber);
gameData.marunouchi.stations += maxNumber;
}
maruStationCost = calcStationCost(gameData.marunouchi.stations);
update("money", format(gameData.money));
refreshMarunouchi();
updatePps(); // because pps is dependent on station number
}
}
function buyMaruLocomotive(number) {
if(gameData.marunouchi.locomotives < gameData.marunouchi.stations * locoPerStat && gameData.money >= maruLocomotiveCost) {
if(number === 1) {
gameData.marunouchi.locomotives += 1;
gameData.money -= maruLocomotiveCost;
}
if(number > 1) {
if(gameData.marunouchi.locomotives + number <= gameData.marunouchi.stations * locoPerStat) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('locomotive', gameData.marunouchi.locomotives, number);
gameData.marunouchi.locomotives += number;
}
}
if(number === 'max') {
let maxNumber = calcMaxBuyNumber('locomotive', gameData.marunouchi.locomotives);
if(gameData.marunouchi.locomotives + maxNumber <= gameData.marunouchi.stations * locoPerStat) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('locomotive', gameData.marunouchi.locomotives, maxNumber);
gameData.marunouchi.locomotives += maxNumber;
} else {
buyMaruLocomotive((gameData.marunouchi.stations * locoPerStat) - gameData.marunouchi.locomotives); //buys to max capacity
}
}
maruLocomotiveCost = calcLocomotiveCost(gameData.marunouchi.locomotives);
update("money", format(gameData.money));
refreshMarunouchi();
}
}
function buyMaruCar(number) {
if(gameData.marunouchi.cars < gameData.marunouchi.locomotives * carPerLoco && gameData.money >= maruCarCost) {
if(number === 1) {
gameData.marunouchi.cars += 1;
gameData.money -= maruCarCost;
}
if(number > 1) {
if(gameData.marunouchi.cars + number <= gameData.marunouchi.locomotives * carPerLoco) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('car', gameData.marunouchi.cars, number);
gameData.marunouchi.cars += number;
}
}
if(number === 'max') {
let maxNumber = calcMaxBuyNumber('car', gameData.marunouchi.cars);
if(gameData.marunouchi.cars + maxNumber <= gameData.marunouchi.locomotives * carPerLoco) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('car', gameData.marunouchi.cars, maxNumber);
gameData.marunouchi.cars += maxNumber;
} else {
buyMaruCar((gameData.marunouchi.locomotives * carPerLoco) - gameData.marunouchi.cars); //buys to max capacity
}
}
maruCarCost = calcCarCost(gameData.marunouchi.cars);
update("money", format(gameData.money));
refreshMarunouchi();
updateMaxPassengers(); // because max is dependent on car number
}
}
// end of marunouchi buying functions
// hibiya buying functions
function buyHibiLine() {
if(gameData.money >= lineCost) {
gameData.hibiya.line = 1;
gameData.money -= lineCost;
gameData.hibiya.stations += 2;
gameData.hibiya.locomotives += 1;
gameData.hibiya.cars += 1;
show("hibiyaBody");
hide("hibiyaHead");
show("tozaiHead");
update("money", format(gameData.money));
lineCost = calcLineCost();
update("tozaLineCost", format(lineCost));
refreshHibiya();
updatePps(); // because pps is dependent on station number
updateMaxPassengers(); // because max is dependent on car number
updateMps(); // because mps is dependent on line number
gtag("event", "level_start", {
level_name: "Hibiya Line"
});
}}
function buyHibiStation(number) {
if(gameData.money >= hibiStationCost) {
if(number === 1) {
gameData.hibiya.stations += 1;
gameData.money -= hibiStationCost;
}
if(number > 1) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('station', gameData.hibiya.stations, number);
gameData.hibiya.stations += number;
}
if(number === 'max') {
let maxNumber = calcMaxBuyNumber('station', gameData.hibiya.stations);
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('station', gameData.hibiya.stations, maxNumber);
gameData.hibiya.stations += maxNumber;
}
hibiStationCost = calcStationCost(gameData.hibiya.stations);
update("money", format(gameData.money));
refreshHibiya();
updatePps(); // because pps is dependent on station number
}
}
function buyHibiLocomotive(number) {
if(gameData.hibiya.locomotives < gameData.hibiya.stations * locoPerStat && gameData.money >= hibiLocomotiveCost) {
if(number === 1) {
gameData.hibiya.locomotives += 1;
gameData.money -= hibiLocomotiveCost;
}
if(number > 1) {
if(gameData.hibiya.locomotives + number <= gameData.hibiya.stations * locoPerStat) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('locomotive', gameData.hibiya.locomotives, number);
gameData.hibiya.locomotives += number;
}
}
if(number === 'max') {
let maxNumber = calcMaxBuyNumber('locomotive', gameData.hibiya.locomotives);
if(gameData.hibiya.locomotives + maxNumber <= gameData.hibiya.stations * locoPerStat) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('locomotive', gameData.hibiya.locomotives, maxNumber);
gameData.hibiya.locomotives += maxNumber;
} else {
buyHibiLocomotive((gameData.hibiya.stations * locoPerStat) - gameData.hibiya.locomotives); //buys to max capacity
}
}
hibiLocomotiveCost = calcLocomotiveCost(gameData.hibiya.locomotives);
update("money", format(gameData.money));
refreshHibiya();
}
}
function buyHibiCar(number) {
if(gameData.hibiya.cars < gameData.hibiya.locomotives * carPerLoco && gameData.money >= hibiCarCost) {
if(number === 1) {
gameData.hibiya.cars += 1;
gameData.money -= hibiCarCost;
}
if(number > 1) {
if(gameData.hibiya.cars + number <= gameData.hibiya.locomotives * carPerLoco) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('car', gameData.hibiya.cars, number);
gameData.hibiya.cars += number;
}
}
if(number === 'max') {
let maxNumber = calcMaxBuyNumber('car', gameData.hibiya.cars);
if(gameData.hibiya.cars + maxNumber <= gameData.hibiya.locomotives * carPerLoco) {
// calculate cost first because it depends on current number
gameData.money -= calcMultiBuyCost('car', gameData.hibiya.cars, maxNumber);
gameData.hibiya.cars += maxNumber;
} else {
buyHibiCar((gameData.hibiya.locomotives * carPerLoco) - gameData.hibiya.cars); //buys to max capacity
}
}
hibiCarCost = calcCarCost(gameData.hibiya.cars);
update("money", format(gameData.money));
refreshHibiya();
updateMaxPassengers(); // because max is dependent on car number
}
}
// end of hibiya buying functions
// tozai buying functions
function buyTozaLine() {
if(gameData.money >= lineCost) {
gameData.tozai.line = 1;
gameData.money -= lineCost;
gameData.tozai.stations += 2;
gameData.tozai.locomotives += 1;
gameData.tozai.cars += 1;
show("tozaiBody");
hide("tozaiHead");
show("chiyodaHead");
update("money", format(gameData.money));