-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoctrine.html
More file actions
1262 lines (1186 loc) · 60.7 KB
/
Doctrine.html
File metadata and controls
1262 lines (1186 loc) · 60.7 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="theme-color" content="#0c1016">
<title>Doctrine — Geopolitical Strategy Sim 1990–2050 | Board Gaming Hub</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Aerobiz-style geopolitical strategy across 1990–2050. Build alliances, project influence, watch the real world map evolve. Free in-browser, single HTML file.">
<link rel="canonical" href="https://boardgaminghub.com/Doctrine.html">
<meta property="og:type" content="website">
<meta property="og:url" content="https://boardgaminghub.com/Doctrine.html">
<meta property="og:title" content="Doctrine — Geopolitical Sim 1990-2050">
<meta property="og:description" content="Aerobiz-style geopolitical strategy on a real world map, 1990–2050.">
<meta property="og:image" content="https://boardgaminghub.com/og-image.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://boardgaminghub.com/og-image.png">
<script type="application/ld+json">
{ "@context": "https://schema.org", "@type": "VideoGame", "name": "Doctrine",
"description": "Geopolitical strategy simulation spanning 1990 to 2050, with real-world map and alliance dynamics.",
"url": "https://boardgaminghub.com/Doctrine.html", "genre": "Strategy",
"applicationCategory": "Game", "operatingSystem": "Any",
"offers": { "@type": "Offer", "price": "0", "priceCurrency": "USD" } }
</script>
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
<script src="https://cdn.jsdelivr.net/npm/topojson-client@3"></script>
<style>
:root {
--bg: #07090d;
--panel: #0f141c;
--panel-2: #161d28;
--border: #2a3548;
--border-bright: #3d5070;
--text: #c8d4e0;
--dim: #7a8898;
--amber: #ffb000;
--green: #00ff88;
--red: #ff5050;
--us: #4a90ff;
--cn: #ffcc00;
--ru: #ff5050;
--eu: #b070ff;
--neutral: #4a5668;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
font-family: 'Consolas', 'Menlo', 'Courier New', monospace;
background: var(--bg);
color: var(--text);
font-size: 12px;
line-height: 1.4;
user-select: none;
}
.scanline { position: fixed; inset: 0; pointer-events: none; z-index: 9999;
background: repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0 2px, transparent 2px 4px); }
.app { display: grid; grid-template-columns: 240px 1fr 280px; grid-template-rows: 36px 1fr 160px; height: 100vh; gap: 4px; padding: 4px; }
.topbar { grid-column: 1 / -1; background: var(--panel); border: 1px solid var(--border); display: flex; align-items: center; padding: 0 12px; gap: 16px; }
.brand { color: var(--amber); font-weight: bold; letter-spacing: 3px; }
.turn { color: var(--green); }
.topbar .stat { color: var(--dim); }
.topbar .stat b { color: var(--text); margin-left: 4px; }
.left { background: var(--panel); border: 1px solid var(--border); overflow-y: auto; padding: 8px; }
.map-wrap { background: var(--panel); border: 1px solid var(--border); overflow: hidden; position: relative; }
.right { background: var(--panel); border: 1px solid var(--border); overflow-y: auto; padding: 8px; }
.bottom { grid-column: 1 / -1; background: var(--panel); border: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr 220px; gap: 4px; padding: 4px; }
.log, .events, .controls { background: var(--panel-2); border: 1px solid var(--border); padding: 8px; overflow-y: auto; }
.section-title { color: var(--amber); font-size: 10px; letter-spacing: 2px; text-transform: uppercase; border-bottom: 1px solid var(--border); padding-bottom: 4px; margin-bottom: 6px; }
.stat-row { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px dashed rgba(255,255,255,0.03); }
.stat-row span:last-child { color: var(--text); font-weight: bold; }
.bar { height: 6px; background: rgba(255,255,255,0.06); border-radius: 1px; margin: 2px 0 6px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; background: var(--amber); transition: width 0.3s; }
.good { color: var(--green); }
.bad { color: var(--red); }
.warn { color: var(--amber); }
button { background: var(--panel-2); color: var(--text); border: 1px solid var(--border-bright); padding: 6px 10px; cursor: pointer; font-family: inherit; font-size: 11px; letter-spacing: 1px; }
button:hover:not(:disabled) { background: var(--border); color: var(--amber); border-color: var(--amber); }
button:disabled { opacity: 0.35; cursor: not-allowed; }
button.primary { background: var(--amber); color: #000; border-color: var(--amber); font-weight: bold; }
button.primary:hover { background: #ffd040; }
.pill { display: inline-block; padding: 1px 6px; border-radius: 8px; font-size: 10px; letter-spacing: 1px; margin-right: 3px; }
.pill.us { background: rgba(74,144,255,0.2); color: var(--us); }
.pill.cn { background: rgba(255,204,0,0.2); color: var(--cn); }
.pill.ru { background: rgba(255,80,80,0.2); color: var(--ru); }
.pill.eu { background: rgba(176,112,255,0.2); color: var(--eu); }
svg { display: block; }
.country { cursor: pointer; transition: opacity 0.2s; }
.country:hover { opacity: 0.85; stroke: var(--amber) !important; stroke-width: 2 !important; }
.country.selected { stroke: var(--amber) !important; stroke-width: 2.5 !important; filter: drop-shadow(0 0 6px var(--amber)); }
.country-label { fill: rgba(255,255,255,0.55); font-size: 9px; pointer-events: none; text-anchor: middle; font-family: inherit; letter-spacing: 1px; }
.chokepoint { fill: var(--amber); fill-opacity: 0.4; stroke: var(--amber); stroke-dasharray: 2 2; }
.chokepoint.closed { fill: var(--red); stroke: var(--red); fill-opacity: 0.6; }
.log-entry { font-size: 11px; margin-bottom: 3px; padding-left: 8px; border-left: 2px solid var(--border); }
.log-entry.event { border-left-color: var(--amber); color: var(--amber); }
.log-entry.crisis { border-left-color: var(--red); color: var(--red); }
.log-entry.win { border-left-color: var(--green); color: var(--green); }
.event-card { background: rgba(255,176,0,0.06); border: 1px solid var(--amber); padding: 8px; margin-bottom: 6px; }
.event-card .title { color: var(--amber); font-weight: bold; margin-bottom: 4px; }
.event-card .desc { color: var(--text); margin-bottom: 6px; font-size: 11px; }
.event-card .choices button { display: block; width: 100%; text-align: left; margin-top: 3px; padding: 4px 6px; }
.country-detail { padding: 6px 0; }
.alignment-bars { margin-top: 6px; }
.ali-row { display: grid; grid-template-columns: 30px 1fr 30px; align-items: center; gap: 6px; margin-bottom: 2px; font-size: 10px; }
.ali-bar { height: 5px; background: rgba(255,255,255,0.05); }
.ali-bar > div { height: 100%; }
.actions { margin-top: 8px; display: grid; gap: 4px; }
.actions button { text-align: left; font-size: 11px; padding: 5px 8px; }
.actions button .cost { float: right; color: var(--dim); }
.slider-row { display: grid; grid-template-columns: 80px 1fr 50px; gap: 6px; align-items: center; margin: 4px 0; font-size: 11px; }
input[type=range] { -webkit-appearance: none; background: transparent; height: 16px; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: var(--border); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: var(--amber); border-radius: 50%; margin-top: -4px; cursor: pointer; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: var(--panel); border: 2px solid var(--amber); padding: 24px; max-width: 600px; width: 90%; }
.modal h2 { color: var(--amber); letter-spacing: 3px; margin-bottom: 12px; }
.modal h3 { color: var(--text); margin: 12px 0 6px; font-size: 13px; letter-spacing: 2px; }
.modal p { margin-bottom: 8px; font-size: 12px; }
.power-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.power-pick button { padding: 12px; text-align: left; }
.power-pick .nm { color: var(--amber); font-weight: bold; font-size: 14px; }
.power-pick .desc { color: var(--dim); font-size: 11px; margin-top: 4px; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: var(--border-bright); }
</style>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Board Gaming Hub","item":"https://boardgaminghub.com/"},{"@type":"ListItem","position":2,"name":"Simulations","item":"https://boardgaminghub.com/#sims"},{"@type":"ListItem","position":3,"name":"Doctrine","item":"https://boardgaminghub.com/Doctrine.html"}]}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"How accurate is the geopolitics?","acceptedAnswer":{"@type":"Answer","text":"Doctrine's economic and military models are simplified but draw on real datasets (Maddison historical GDP, SIPRI military expenditure). Specific event probabilities are tuned for replayability over historical accuracy."}},{"@type":"Question","name":"Can I play as a minor power?","acceptedAnswer":{"@type":"Answer","text":"Yes. Smaller nations have less budget but more flexibility — alliance-shopping is a viable strategy. Some of the strongest scoring runs come from middle-power coalition-building."}},{"@type":"Question","name":"How long is a campaign?","acceptedAnswer":{"@type":"Answer","text":"60 in-game years = 240 turns ≈ 90–120 minutes of real time. Save and resume across sessions."}},{"@type":"Question","name":"Is multiplayer planned?","acceptedAnswer":{"@type":"Answer","text":"Asymmetric hot-seat (different powers per session) is in design. Real-time multiplayer is not on the near roadmap."}}]}</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2835365593874464"
crossorigin="anonymous"></script>
</head>
<body>
<style id="siteNav-css">
#siteNav { position: sticky; top: 0; z-index: 99999; background: rgba(16,20,28,0.96); border-bottom: 1px solid #2a3540; font-family: Georgia, "Times New Roman", serif; box-shadow: 0 2px 10px rgba(0,0,0,0.6); color: #d8d0c0; }
#siteNav * { box-sizing: border-box; }
#siteNav .nav-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; max-width: 1400px; margin: 0 auto; gap: 12px; }
#siteNav .nav-home { color: #d8d0c0; text-decoration: none; font-size: 0.82em; letter-spacing: 2px; padding: 5px 12px; border: 1px solid #3a5060; border-radius: 3px; white-space: nowrap; }
#siteNav .nav-home:hover { background: #1e2838; color: #f0e0b0; }
#siteNav .nav-title { color: #f0d89c; font-size: 0.95em; letter-spacing: 3px; font-weight: bold; text-align: center; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#siteNav .nav-toggle { background: none; border: 1px solid #3a5060; color: #d8d0c0; font-size: 0.85em; letter-spacing: 2px; padding: 5px 12px; border-radius: 3px; cursor: pointer; font-family: inherit; white-space: nowrap; }
#siteNav .nav-toggle:hover { background: #1e2838; color: #f0e0b0; }
#siteNav .nav-menu { display: none; background: #0f141c; border-top: 1px solid #2a4050; padding: 14px 16px; max-width: 1400px; margin: 0 auto; }
#siteNav .nav-menu.open { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
#siteNav .nav-cat { min-width: 0; }
#siteNav .nav-cat-label { color: #8098a8; font-size: 0.72em; letter-spacing: 4px; padding: 4px 0 8px 0; border-bottom: 1px solid #2a3540; margin-bottom: 6px; }
#siteNav .nav-cat a { display: block; padding: 6px 10px; color: #a8b0c0; text-decoration: none; font-size: 0.88em; border-radius: 3px; }
#siteNav .nav-cat a:hover { background: #1e2838; color: #f0e0b0; }
#siteNav .nav-cat a.current { color: #f0d89c; font-weight: bold; background: #1e2838; }
@media (max-width: 640px) {
#siteNav .nav-menu.open { grid-template-columns: 1fr; gap: 14px; }
#siteNav .nav-title { font-size: 0.82em; letter-spacing: 2px; }
#siteNav .nav-home,
#siteNav .nav-toggle { font-size: 0.74em; padding: 4px 8px; }
}
</style>
<div id="siteNav">
<div class="nav-bar">
<a href="index.html" class="nav-home">HOME</a>
<span class="nav-title">Doctrine</span>
<button class="nav-toggle" onclick="document.querySelector('#siteNav .nav-menu').classList.toggle('open')">GAMES ☰</button>
</div>
<div class="nav-menu">
<div class="nav-cat">
<div class="nav-cat-label">BOARD GAMES</div>
<a href="Agora.html">Agora</a>
<a href="Aresia.html">Aresia</a>
<a href="Backgammon.html">Backgammon</a>
<a href="Bisque.html">Bisque</a>
<a href="Chess.html">Chess</a>
<a href="Convergence.html">Convergence</a>
<a href="Go.html">Go</a>
<a href="Mancala.html">Mancala</a>
<a href="Odyssey.html">Odyssey</a>
<a href="Othello.html">Othello</a>
<a href="PenteGrammai.html">Pente Grammai</a>
<a href="Senet.html">Senet</a>
<a href="Tidelands.html">Tidelands</a>
<a href="Ur.html">Ur</a>
</div>
<div class="nav-cat">
<div class="nav-cat-label">SIMULATIONS</div>
<a href="Apoapsis.html">Apoapsis</a>
<a href="BiosphereBlue.html">Biosphere Blue</a>
<a href="BonnevilleSpillwayOperator.html">Bonneville Spillway</a>
<a href="Cliffwalkers.html">Cliffwalkers</a>
<a href="Doctrine.html" class="current">Doctrine</a>
<a href="EclipsePredictor.html">Eclipse Predictor</a>
<a href="Floodline.html">Floodline</a>
<a href="Metropolis2K.html">Metropolis 2K</a>
<a href="Tower.html">Tower</a>
</div>
</div>
</div>
<div class="scanline"></div>
<div class="app" id="app" style="display:none">
<div class="topbar">
<div class="brand">DOCTRINE</div>
<div class="turn">YEAR <b id="t-year">1990</b></div>
<div class="stat">PLAYING <b id="t-power">USA</b></div>
<div class="stat">GDP <b id="t-gdp">$5963B</b></div>
<div class="stat">DEBT/GDP <b id="t-debt">54%</b></div>
<div class="stat">RATE <b id="t-rate">8.0%</b></div>
<div class="stat">APPROVAL <b id="t-app">60%</b></div>
<div class="stat">TEMPO <b id="t-tempo">3 / 3</b></div>
<div class="stat">SCORE <b id="t-score">0</b></div>
<div style="flex:1"></div>
<button class="primary" id="end-turn">END YEAR ▸</button>
</div>
<div class="left">
<div class="section-title">Domestic — <span id="dom-power">USA</span></div>
<div id="domestic"></div>
<div class="section-title" style="margin-top:14px">Budget % GDP</div>
<div id="budget"></div>
<div class="section-title" style="margin-top:14px">Forces & Posture</div>
<div id="forces"></div>
<div class="section-title" style="margin-top:14px">Rival Powers</div>
<div id="rivals"></div>
</div>
<div class="map-wrap">
<svg id="map" viewBox="0 0 1000 500" preserveAspectRatio="xMidYMid meet" width="100%" height="100%"></svg>
</div>
<div class="right">
<div class="section-title">Selected</div>
<div id="selected">Click a country on the map.</div>
</div>
<div class="bottom">
<div class="log">
<div class="section-title">Situation Log</div>
<div id="log"></div>
</div>
<div class="events">
<div class="section-title">Active Crises</div>
<div id="events">No active crises.</div>
</div>
<div class="controls">
<div class="section-title">Help</div>
<div style="font-size: 10px; color: var(--dim); line-height: 1.6">
Each year you have <b>3 Tempo</b>. Spend on actions toward countries (loans, deals, bases, pacts, intel). Adjust budget & rate any time.<br><br>
Win condition: highest <b>Influence Score</b> at end of 2050, or hold ≥80% weighted alignment for 5 straight years.<br><br>
Lose: debt/GDP > 250% with rate > 12%, or approval < 20% for 3 years.
</div>
</div>
</div>
</div>
<div class="modal-bg" id="start-modal">
<div class="modal">
<h2>DOCTRINE</h2>
<p style="color: var(--dim)">A geopolitical strategy sim. 1990 — 2050. Choose your power.</p>
<p style="color: var(--dim); font-size: 11px">Inspired by <i>Aerobiz Supersonic</i>. Annual turns. Asymmetric kits. AI rivals compete for the same finite alignment slots in 12 contested middle powers. Events shift the board every year.</p>
<div class="power-pick">
<button data-pick="USA"><div class="nm" style="color:var(--us)">UNITED STATES</div><div class="desc">Reserve currency, 11 carriers, NATO+JP+KR alliance web. Easy mode. Hold the unipolar moment.</div></button>
<button data-pick="CHN"><div class="nm" style="color:var(--cn)">CHINA</div><div class="desc">$360B GDP, no allies, manufacturing engine just spooling up. Long climb to peer power.</div></button>
<button data-pick="RUS"><div class="nm" style="color:var(--ru)">RUSSIA</div><div class="desc">Just collapsed, oil/gas leverage, nukes, weak economy. Rebuild the sphere.</div></button>
<button data-pick="EU"><div class="nm" style="color:var(--eu)">EUROPEAN UNION</div><div class="desc">Wealthy, slow, fragmented. Civilian power. Hard to project militarily, easy to write checks.</div></button>
</div>
<p style="margin-top: 16px; color: var(--dim); font-size: 10px; text-align: center">v0.1 — single-file prototype</p>
</div>
</div>
<div class="modal-bg" id="end-modal" style="display:none">
<div class="modal">
<h2 id="end-title">CAMPAIGN COMPLETE</h2>
<div id="end-body"></div>
<button style="margin-top: 16px;" onclick="location.reload()">PLAY AGAIN</button>
</div>
</div>
<script>
// ============================================================
// DOCTRINE v0.1
// ============================================================
const POWERS = ['USA','CHN','RUS','EU'];
const POWER_COLOR = { USA: '#4a90ff', CHN: '#ffcc00', RUS: '#ff5050', EU: '#b070ff' };
const POWER_NAME = { USA: 'United States', CHN: 'China', RUS: 'Russia', EU: 'European Union' };
// ISO 3166-1 numeric code → my internal code. Used to color real country shapes from world-atlas.
const ISO_TO_CODE = {
// Powers
840: 'USA', 156: 'CHN', 643: 'RUS',
// EU member states (EC-12 in 1990; later expansions colored too)
56: 'EU', // Belgium
208: 'EU', // Denmark
250: 'EU', // France
276: 'EU', // Germany
300: 'EU', // Greece
372: 'EU', // Ireland
380: 'EU', // Italy
442: 'EU', // Luxembourg
528: 'EU', // Netherlands
620: 'EU', // Portugal
724: 'EU', // Spain
826: 'EU', // United Kingdom
40: 'EU', // Austria
246: 'EU', // Finland
752: 'EU', // Sweden
// Middle powers
682: 'SAU', 364: 'IRN', 792: 'TUR', 818: 'EGY',
356: 'IND', 586: 'PAK', 360: 'IDN', 704: 'VNM',
76: 'BRA', 484: 'MEX', 566: 'NGA', 710: 'ZAF',
};
// Real lon/lat for chokepoint markers
const CHOKE_LATLON = {
hormuz: { lonlat: [56.3, 26.6], label: 'HORMUZ' },
malacca: { lonlat: [101.4, 2.5], label: 'MALACCA' },
suez: { lonlat: [32.55, 30.0], label: 'SUEZ' },
bosphorus: { lonlat: [29.0, 41.1], label: 'BOSPHORUS' },
panama: { lonlat: [-79.7, 9.1], label: 'PANAMA' },
};
// World map data (loaded async from CDN)
let WORLD_DATA = null;
let PROJECTION = null;
let PATH_GEN = null;
// Cached path strings and centroids — features are immutable, so this avoids
// regenerating SVG path data + centroids on every render.
let FEATURE_PATH_CACHE = null; // Map: feature -> { d, centroid }
let GRATICULE_PATH_CACHE = null; // string
let CODE_TO_FEATURE_CACHE = null; // Map: internal code -> feature
// 1990-ish nominal GDP ($B), debt/GDP, interest rate, approval, military strength index
const POWER_INIT = {
USA: { gdp: 5963, debtGdp: 0.54, rate: 8.0, approval: 60, military: 100, growth: 2.5,
tempoMax: 3, reserveCurrency: true, carriers: 11, bases: 28, allies: ['NATO','JP','KR'],
doctrine: 'Liberal Hegemon' },
CHN: { gdp: 361, debtGdp: 0.16, rate: 9.0, approval: 70, military: 35, growth: 9.0,
tempoMax: 3, reserveCurrency: false, carriers: 0, bases: 2, allies: ['DPRK'],
doctrine: 'Reform & Opening' },
RUS: { gdp: 506, debtGdp: 0.45, rate: 14.0, approval: 35, military: 70, growth: -3.0,
tempoMax: 3, reserveCurrency: false, carriers: 1, bases: 12, allies: ['CSTO'],
doctrine: 'Recovery' },
EU: { gdp: 6800, debtGdp: 0.55, rate: 7.5, approval: 55, military: 65, growth: 2.0,
tempoMax: 2, reserveCurrency: false, carriers: 2, bases: 8, allies: ['internal'],
doctrine: 'Civilian Power' },
};
// Contested middle powers. Initial alignment toward each bloc (0-100). Sum ≤ 100, rest = neutral.
// Coords are on the 1000x500 SVG canvas (rough geographic layout).
const COUNTRIES = {
// MENA
SAU: { name: 'Saudi Arabia', region: 'MENA', gdp: 117, growth: 4, x: 600, y: 280, w: 50, h: 40,
ali: { USA: 65, CHN: 5, RUS: 5, EU: 10 }, traits: ['oil','chokepoint:hormuz'] },
IRN: { name: 'Iran', region: 'MENA', gdp: 120, growth: 2, x: 640, y: 230, w: 55, h: 35,
ali: { USA: 0, CHN: 15, RUS: 30, EU: 5 }, traits: ['oil','chokepoint:hormuz','sanctioned'] },
TUR: { name: 'Turkey', region: 'MENA', gdp: 207, growth: 5, x: 555, y: 220, w: 48, h: 28,
ali: { USA: 60, CHN: 5, RUS: 5, EU: 25 }, traits: ['nato','chokepoint:bosphorus'] },
EGY: { name: 'Egypt', region: 'MENA', gdp: 43, growth: 4, x: 545, y: 270, w: 40, h: 30,
ali: { USA: 50, CHN: 5, RUS: 10, EU: 15 }, traits: ['chokepoint:suez'] },
// Asia
IND: { name: 'India', region: 'Asia', gdp: 326, growth: 6, x: 730, y: 280, w: 65, h: 45,
ali: { USA: 10, CHN: 0, RUS: 30, EU: 10 }, traits: ['nuclear','rising'] },
PAK: { name: 'Pakistan', region: 'Asia', gdp: 40, growth: 4, x: 695, y: 250, w: 35, h: 25,
ali: { USA: 50, CHN: 25, RUS: 0, EU: 5 }, traits: ['nuclear'] },
IDN: { name: 'Indonesia', region: 'Asia', gdp: 106, growth: 7, x: 830, y: 360, w: 70, h: 25,
ali: { USA: 25, CHN: 10, RUS: 5, EU: 10 }, traits: ['chokepoint:malacca'] },
VNM: { name: 'Vietnam', region: 'Asia', gdp: 6, growth: 8, x: 815, y: 305, w: 25, h: 30,
ali: { USA: 0, CHN: 0, RUS: 50, EU: 5 }, traits: ['post-war'] },
// Americas
BRA: { name: 'Brazil', region: 'Americas', gdp: 461, growth: 3, x: 290, y: 360, w: 75, h: 60,
ali: { USA: 30, CHN: 5, RUS: 5, EU: 20 }, traits: ['rising'] },
MEX: { name: 'Mexico', region: 'Americas', gdp: 263, growth: 4, x: 180, y: 270, w: 50, h: 35,
ali: { USA: 70, CHN: 5, RUS: 0, EU: 10 }, traits: [] },
// Africa
NGA: { name: 'Nigeria', region: 'Africa', gdp: 28, growth: 6, x: 510, y: 320, w: 35, h: 35,
ali: { USA: 15, CHN: 5, RUS: 10, EU: 25 }, traits: ['oil'] },
ZAF: { name: 'South Africa', region: 'Africa', gdp: 112, growth: 1, x: 560, y: 410, w: 48, h: 35,
ali: { USA: 25, CHN: 5, RUS: 5, EU: 30 }, traits: [] },
};
// Power "home" rectangles for the map (just for visual presence)
const POWER_GEOM = {
USA: { x: 90, y: 200, w: 140, h: 70, label: 'USA' },
CHN: { x: 760, y: 230, w: 90, h: 60, label: 'CHN' },
RUS: { x: 600, y: 130, w: 280, h: 65, label: 'RUSSIA' },
EU: { x: 470, y: 175, w: 90, h: 50, label: 'EU' },
};
const CHOKEPOINTS = {
hormuz: { x: 645, y: 270, label: 'Hormuz', affects: ['SAU','IRN'] },
malacca: { x: 798, y: 340, label: 'Malacca', affects: ['IDN','VNM','CHN'] },
suez: { x: 555, y: 257, label: 'Suez', affects: ['EGY','EU'] },
bosphorus: { x: 555, y: 213, label: 'Bosphorus', affects: ['TUR','RUS'] },
panama: { x: 200, y: 318, label: 'Panama', affects: ['MEX','USA'] },
};
// Action catalog. cost is { tempo, money } for one-shot; upkeep is per year.
const ACTIONS = {
loan: { name: 'Issue Loan / Aid', tempo: 1, money: 5, upkeep: 0, swing: 18, desc: '$5B grant or concessional loan. Big short-term goodwill.' },
trade: { name: 'Sign Trade Deal', tempo: 1, money: 0, upkeep: 0, swing: 10, desc: 'Permanent +0.5/yr alignment drift while in force. Can be torn up by tariff war.' },
base: { name: 'Build Forward Base', tempo: 2, money: 8, upkeep: 4, swing: 14, desc: 'Permanent presence. +0.4/yr alignment drift. Hard target if war breaks out.' },
carrier: { name: 'Deploy Carrier Group', tempo: 2, money: 0, upkeep: 6, swing: 12, desc: 'Coastal projection. Contests rival access. Requires available carrier.' },
intel: { name: 'Intel Operation', tempo: 1, money: 2, upkeep: 0, swing: 8, desc: 'Covert. 60% chance of swing, 15% chance of blowback (-10).' },
pact: { name: 'Defense Pact', tempo: 2, money: 0, upkeep: 2, swing: 25, desc: 'Locks alignment ≥60. Target enters your security umbrella. Requires alignment ≥55.' },
};
// =============== STATE ===============
let S = null;
function newGame(playerPower) {
S = {
year: 1990,
player: playerPower,
powers: {},
countries: {},
log: [],
activeEvents: [],
chokepointsClosed: {}, // key: { closedUntil: year }
presence: {}, // power -> country -> { trade, base, carrier, pact, loans }
tempo: {}, // power -> remaining tempo this turn
selected: null,
budget: {}, // power -> {mil, soc, infra} (% of GDP)
lowApprovalStreak: 0,
holdStreak: 0,
score: { USA: 0, CHN: 0, RUS: 0, EU: 0 },
over: false,
lastEventYear: 0,
};
for (const p of POWERS) {
S.powers[p] = JSON.parse(JSON.stringify(POWER_INIT[p]));
S.presence[p] = {};
S.tempo[p] = POWER_INIT[p].tempoMax;
// default budget: balanced
S.budget[p] = { mil: p === 'USA' ? 5 : (p === 'RUS' ? 7 : 3),
soc: p === 'EU' ? 22 : 15,
infra: 4 };
}
for (const c of Object.keys(COUNTRIES)) {
S.countries[c] = JSON.parse(JSON.stringify(COUNTRIES[c]));
}
log('event', `${S.year}: Cold War ends. United States enters unipolar moment. You take office as ${POWER_NAME[playerPower]}.`);
render();
}
// =============== UTIL ===============
function clamp(v, lo, hi) { return Math.max(lo, Math.min(hi, v)); }
function fmt$(v) { return '$' + (v >= 1000 ? (v/1000).toFixed(1) + 'T' : v.toFixed(0) + 'B'); }
function fmtPct(v, digits=0) { return (v*100).toFixed(digits) + '%'; }
function rand(a, b) { return a + Math.random() * (b - a); }
function pick(arr) { return arr[Math.floor(Math.random()*arr.length)]; }
function log(kind, msg) {
S.log.unshift({ kind, msg, year: S.year });
if (S.log.length > 200) S.log.pop();
}
// alignment helper
function aliSum(c) { return Object.values(c.ali).reduce((a,b)=>a+b,0); }
function neutral(c) { return Math.max(0, 100 - aliSum(c)); }
function aliShift(country, power, delta) {
const c = S.countries[country];
c.ali[power] = clamp((c.ali[power]||0) + delta, 0, 100);
// Drain neutral first; if no neutral, take from rivals proportionally.
let total = aliSum(c);
if (total > 100) {
const excess = total - 100;
const others = POWERS.filter(p => p !== power);
const rivalSum = others.reduce((a,p) => a + (c.ali[p]||0), 0);
if (rivalSum > 0) {
for (const p of others) {
const share = excess * (c.ali[p]||0) / rivalSum;
c.ali[p] = Math.max(0, c.ali[p] - share);
}
}
}
}
// =============== INFLUENCE SCORE ===============
function computeScore(power) {
// Influence = sum over countries of (alignment * country GDP) + own GDP * 2 + military
let s = 0;
for (const k of Object.keys(S.countries)) {
const c = S.countries[k];
s += (c.ali[power]||0) / 100 * c.gdp;
}
s += S.powers[power].gdp * 0.5;
s += S.powers[power].military * 5;
return Math.round(s);
}
function weightedAlignmentShare(power) {
// Share of (sum of country GDP) aligned to this power
let totalGdp = 0, mineGdp = 0;
for (const k of Object.keys(S.countries)) {
const c = S.countries[k];
totalGdp += c.gdp;
mineGdp += (c.ali[power]||0)/100 * c.gdp;
}
return totalGdp > 0 ? mineGdp / totalGdp : 0;
}
// =============== ACTIONS ===============
function canAct(power, action, target) {
const A = ACTIONS[action];
const P = S.powers[power];
if (S.tempo[power] < A.tempo) return [false, 'No tempo left.'];
if (P.gdp * P.debtGdp > P.gdp * 3) return [false, 'Debt too high.'];
if (action === 'pact') {
if ((S.countries[target].ali[power]||0) < 55) return [false, 'Need alignment ≥55 first.'];
if (S.presence[power][target]?.pact) return [false, 'Already in pact.'];
}
if (action === 'carrier') {
const deployed = Object.values(S.presence[power]).filter(x => x.carrier).length;
if (deployed >= P.carriers) return [false, 'No carriers available.'];
if (!isCoastal(target)) return [false, 'Country not coastal.'];
}
if (action === 'base') {
if (S.presence[power][target]?.base) return [false, 'Already have a base there.'];
}
return [true, ''];
}
function isCoastal(country) {
// most are coastal in our set; landlocked exceptions: none in this list (all have coast)
return true;
}
function doAction(power, action, target) {
const [ok, why] = canAct(power, action, target);
if (!ok) { log('crisis', `Action blocked: ${why}`); return false; }
const A = ACTIONS[action];
const P = S.powers[power];
S.tempo[power] -= A.tempo;
// pay one-shot money via debt issue
if (A.money > 0) {
P.debtGdp += A.money / P.gdp;
}
// record presence
if (!S.presence[power][target]) S.presence[power][target] = { trade:false, base:false, carrier:false, pact:false, loans:0 };
const pres = S.presence[power][target];
if (action === 'trade') pres.trade = true;
if (action === 'base') pres.base = true;
if (action === 'carrier') pres.carrier = true;
if (action === 'pact') pres.pact = true;
if (action === 'loan') pres.loans += 1;
// alignment swing
let swing = A.swing;
if (action === 'intel') {
const r = Math.random();
if (r < 0.6) { aliShift(target, power, swing); log('event', `Intel op in ${S.countries[target].name} succeeds: +${swing} ${power}.`); }
else if (r < 0.75) { aliShift(target, power, -10); log('crisis', `Intel op in ${S.countries[target].name} blown — hostile reaction.`); }
else { log('event', `Intel op in ${S.countries[target].name}: inconclusive.`); }
} else {
aliShift(target, power, swing);
if (power === S.player) log('event', `${A.name} → ${S.countries[target].name}: +${swing} alignment.`);
}
// pact effects
if (action === 'pact') {
aliShift(target, power, 5); // slight bonus
}
return true;
}
// =============== ECONOMY TICK ===============
function annualEconomy() {
for (const p of POWERS) {
const P = S.powers[p];
const B = S.budget[p];
// Base growth modified by infrastructure spend, social spend, military spend, rate, debt
let growth = P.growth;
growth += (B.infra - 4) * 0.5; // infra above 4% boosts growth
growth -= Math.max(0, B.mil - 6) * 0.3; // overspending on military hurts
growth -= Math.max(0, P.rate - 6) * 0.2; // high rates slow growth
growth -= Math.max(0, P.debtGdp - 1.0) * 1.5; // overhang
// big deficits stimulate short-run but not modeled deeply
growth = clamp(growth + rand(-1.0, 1.0), -8, 12);
P.growth = growth;
P.gdp = P.gdp * (1 + growth/100);
// Tax revenue (simplified): 20% of GDP for OECD-ish, 15% for CHN/RUS
const taxRate = (p === 'CHN' || p === 'RUS') ? 0.15 : 0.20;
const revenue = P.gdp * taxRate;
const spend = P.gdp * (B.mil + B.soc + B.infra) / 100;
const interest = P.gdp * P.debtGdp * (P.rate/100);
// upkeep from forces
let upkeep = P.carriers * 0.5 + P.bases * 0.3;
for (const c of Object.keys(S.presence[p])) {
const pr = S.presence[p][c];
if (pr.base) upkeep += ACTIONS.base.upkeep;
if (pr.carrier) upkeep += ACTIONS.carrier.upkeep;
if (pr.pact) upkeep += ACTIONS.pact.upkeep;
}
const totalSpend = spend + interest + upkeep;
const deficit = totalSpend - revenue;
P.debtGdp = clamp(P.debtGdp + deficit / P.gdp, 0, 5);
// Rates: central bank target. Player chooses, but reality nudges toward fundamentals if extreme.
// (No autoshift — player keeps the dial they set.)
// Military: budget mil% drives military index
const milTarget = B.mil * (p === 'USA' ? 18 : p === 'RUS' ? 14 : p === 'CHN' ? 13 : 11);
P.military += (milTarget - P.military) * 0.15;
P.military = clamp(P.military, 5, 200);
// Approval: driven by growth, inflation proxy (rate-related), unemployment proxy (B.soc)
let appDelta = 0;
appDelta += (growth - 2) * 0.6;
appDelta += (B.soc - 15) * 0.3;
appDelta -= Math.max(0, P.rate - 8) * 0.4;
appDelta -= Math.max(0, P.debtGdp - 1.5) * 1.0;
P.approval = clamp(P.approval + appDelta + rand(-2, 2), 0, 100);
}
// Country GDPs grow too
for (const k of Object.keys(S.countries)) {
const c = S.countries[k];
c.gdp *= (1 + (c.growth + rand(-1.5, 1.5)) / 100);
// Trade deals slowly drift alignment
for (const p of POWERS) {
const pr = S.presence[p][k];
if (!pr) continue;
if (pr.trade) aliShift(k, p, 0.5);
if (pr.base) aliShift(k, p, 0.4);
if (pr.carrier) aliShift(k, p, 0.3);
if (pr.pact) aliShift(k, p, 0.6);
}
// Decay neutral countries' alignments slightly toward equilibrium
}
}
// =============== EVENTS ===============
const SCRIPTED_EVENTS = [
{ year: 1991, id: 'gulf_war', title: 'Gulf War', desc: 'Iraq invades Kuwait. Coalition forms. Saudi Arabia begs for protection.',
impact: () => {
aliShift('SAU', 'USA', 15);
S.powers.USA.military += 5;
S.powers.USA.debtGdp += 0.02;
log('event', '1991: Gulf War. Saudi alignment shifts toward US. US debt ticks up.');
} },
{ year: 1992, id: 'ussr_dissolved', title: 'USSR Dissolution Aftermath', desc: 'Russian economy contracts 14%. Central Asian states open.',
impact: () => {
S.powers.RUS.gdp *= 0.86;
S.powers.RUS.military *= 0.85;
log('crisis', '1992: Russian economy contracts 14%, military hollows out.');
} },
{ year: 1997, id: 'asian_crisis', title: 'Asian Financial Crisis', desc: 'Currency runs hit Thailand, Indonesia, Korea. IMF intervenes.',
impact: () => {
S.countries.IDN.gdp *= 0.85;
S.countries.VNM.gdp *= 0.92;
log('crisis', '1997: Asian Financial Crisis. Indonesia GDP -15%.');
// IMF bailout = US influence
aliShift('IDN', 'USA', 8);
} },
{ year: 2001, id: 'terror', title: '9/11-style Attack', desc: 'Mass-casualty terror attack on US soil. War on Terror begins.',
impact: () => {
S.powers.USA.approval += 15;
S.powers.USA.debtGdp += 0.05;
S.powers.USA.military += 10;
log('crisis', '2001: Mass-casualty attack. US rallies, military spending spikes.');
} },
{ year: 2008, id: 'gfc', title: 'Global Financial Crisis', desc: 'Subprime collapse. Global credit freezes.',
impact: () => {
S.powers.USA.gdp *= 0.96; S.powers.USA.debtGdp += 0.15; S.powers.USA.approval -= 12;
S.powers.EU.gdp *= 0.96; S.powers.EU.debtGdp += 0.18;
// China relatively cushioned via stimulus
S.powers.CHN.debtGdp += 0.08;
log('crisis', '2008: Global Financial Crisis. US/EU GDP -4%, debt explodes.');
} },
{ year: 2011, id: 'arab_spring', title: 'Arab Spring', desc: 'Uprisings sweep Egypt, Libya, Syria. Regional alignments wobble.',
impact: () => {
aliShift('EGY', 'USA', -10);
// open neutrality window
log('event', '2011: Arab Spring destabilizes Egypt; alignments fluid.');
} },
{ year: 2014, id: 'crimea', title: 'Crimea-style Annexation Window', desc: 'If Russia is strong enough, it may seize a contested region.',
impact: () => {
if (S.powers.RUS.military > 60) {
S.powers.RUS.military += 5;
S.powers.RUS.approval += 10;
// Sanctions
S.powers.RUS.gdp *= 0.94;
S.powers.RUS.debtGdp += 0.04;
aliShift('VNM', 'RUS', -5);
log('crisis', '2014: Russia annexes contested region. West imposes sanctions. RUS GDP -6%.');
} else {
log('event', '2014: Russia too weak to act on annexation opportunity.');
}
} },
{ year: 2020, id: 'pandemic', title: 'Global Pandemic', desc: 'Respiratory virus emerges. Global GDP contracts.',
impact: () => {
for (const p of POWERS) { S.powers[p].gdp *= 0.95; S.powers[p].debtGdp += 0.10; S.powers[p].approval -= 8; }
for (const k of Object.keys(S.countries)) { S.countries[k].gdp *= 0.94; }
log('crisis', '2020: Pandemic. Global GDP -5%, public debt +10pp across powers.');
} },
];
// Random events
const RANDOM_EVENTS = [
{ id: 'hormuz', title: 'Strait of Hormuz Closure', minYear: 1992, weight: 5,
apply: () => {
S.chokepointsClosed['hormuz'] = { closedUntil: S.year + 1 };
// oil shock: hurts oil importers, helps exporters
for (const p of POWERS) {
S.powers[p].gdp *= 0.97;
S.powers[p].approval -= 5;
}
S.countries.SAU.gdp *= 1.10;
S.countries.IRN.gdp *= 1.10;
log('crisis', `${S.year}: Strait of Hormuz closure. Oil shock. Global GDP -3%.`);
return { offer: 'force_open_hormuz' };
} },
{ id: 'taiwan_crisis', title: 'Taiwan Strait Crisis', minYear: 2020, weight: 4,
apply: () => {
// big alignment churn
const cnMil = S.powers.CHN.military;
const usMil = S.powers.USA.military;
log('crisis', `${S.year}: Taiwan Strait Crisis. CHN mil ${cnMil.toFixed(0)} vs USA mil ${usMil.toFixed(0)}.`);
if (cnMil > usMil * 0.85) {
log('crisis', ` China presses advantage: regional alignment shifts away from US.`);
aliShift('IDN','CHN', 10); aliShift('VNM','CHN', 8); aliShift('IDN','USA',-8);
} else {
log('event', ` US deters; allies rally.`);
aliShift('IDN','USA', 8); aliShift('VNM','USA', 5);
}
S.powers.CHN.gdp *= 0.97;
S.powers.USA.debtGdp += 0.02;
return null;
} },
{ id: 'tech_breakthrough', title: 'Defense Tech Breakthrough', minYear: 2000, weight: 3,
apply: () => {
const winner = pick(POWERS);
S.powers[winner].military += 15;
log('event', `${S.year}: ${winner} achieves military tech breakthrough (stealth/drones/AI). Military +15.`);
return null;
} },
{ id: 'climate_disaster', title: 'Climate Disaster', minYear: 2025, weight: 4,
apply: () => {
const target = pick(Object.keys(S.countries));
S.countries[target].gdp *= 0.92;
log('crisis', `${S.year}: Climate disaster strikes ${S.countries[target].name}. GDP -8%.`);
return null;
} },
{ id: 'coup', title: 'Coup Attempt', minYear: 1992, weight: 3,
apply: () => {
// pick a country with no defense pact
const candidates = Object.keys(S.countries).filter(k => {
return !POWERS.some(p => S.presence[p][k]?.pact);
});
if (!candidates.length) return null;
const target = pick(candidates);
// alignment scrambles
const c = S.countries[target];
const oldTop = POWERS.reduce((a,b) => (c.ali[a]||0) > (c.ali[b]||0) ? a : b, 'USA');
aliShift(target, oldTop, -20);
const beneficiary = pick(POWERS.filter(p => p !== oldTop));
aliShift(target, beneficiary, 15);
log('crisis', `${S.year}: Coup in ${c.name}. Alignment shifts away from ${oldTop} toward ${beneficiary}.`);
return null;
} },
{ id: 'oil_shock', title: 'Oil Price Spike', minYear: 1992, weight: 3,
apply: () => {
S.countries.SAU.gdp *= 1.06; S.countries.IRN.gdp *= 1.06; S.countries.NGA.gdp *= 1.06;
for (const p of POWERS) S.powers[p].gdp *= 0.99;
log('event', `${S.year}: Oil prices spike. Petrostates surge.`);
return null;
} },
];
function tickEvents() {
// Scripted
for (const e of SCRIPTED_EVENTS) {
if (e.year === S.year) e.impact();
}
// Random — at most one per year, with cooldown
if (S.year - S.lastEventYear >= 2 && Math.random() < 0.45) {
const eligible = RANDOM_EVENTS.filter(e => S.year >= e.minYear);
if (eligible.length) {
const total = eligible.reduce((a,e) => a + e.weight, 0);
let r = Math.random() * total;
for (const e of eligible) {
r -= e.weight;
if (r <= 0) { e.apply(); S.lastEventYear = S.year; break; }
}
}
}
// Reopen chokepoints whose timer expired
for (const k of Object.keys(S.chokepointsClosed)) {
if (S.chokepointsClosed[k].closedUntil <= S.year) {
delete S.chokepointsClosed[k];
log('event', `${S.year}: ${k.charAt(0).toUpperCase()+k.slice(1)} chokepoint reopened.`);
}
}
}
// =============== AI ===============
function aiTurn(power) {
// Score countries by potential gain: low alignment + high GDP + region affinity
while (S.tempo[power] > 0) {
const candidates = [];
for (const k of Object.keys(S.countries)) {
const c = S.countries[k];
const myAli = c.ali[power] || 0;
// Look for opportunity: high GDP, room to grow, not already locked by rival pact
const lockedByRival = POWERS.some(p => p !== power && S.presence[p][k]?.pact);
if (lockedByRival) continue;
const score = c.gdp * (1 - myAli/100);
candidates.push({ k, score, myAli });
}
candidates.sort((a,b) => b.score - a.score);
if (!candidates.length) break;
const target = candidates[0].k;
const ali = candidates[0].myAli;
// pick action by alignment level
let action;
if (ali < 30) action = (Math.random() < 0.5 ? 'loan' : 'trade');
else if (ali < 55) action = pick(['trade', 'base', 'intel', 'loan']);
else if (ali < 80) action = (S.tempo[power] >= 2 ? 'pact' : 'trade');
else action = 'trade';
// tempo check
if (ACTIONS[action].tempo > S.tempo[power]) action = 'loan';
const before = S.tempo[power];
doAction(power, action, target);
if (S.tempo[power] === before) break; // couldn't act — bail
}
}
// =============== TURN LOOP ===============
function endYear() {
if (S.over) return;
// AI rivals act
for (const p of POWERS) {
if (p !== S.player) aiTurn(p);
}
// Events
tickEvents();
// Economy
annualEconomy();
// Scoring
for (const p of POWERS) S.score[p] = computeScore(p);
// Win/lose
checkEnd();
// Advance
S.year += 1;
for (const p of POWERS) S.tempo[p] = S.powers[p].tempoMax;
render();
}
function checkEnd() {
const me = S.powers[S.player];
if (me.debtGdp > 2.5 && me.rate > 12) {
endGame(false, `Debt crisis: ${POWER_NAME[S.player]} debt-to-GDP exceeded 250% with rates above 12%. Bond market collapse. Game over.`);
return;
}
if (me.approval < 20) {
S.lowApprovalStreak += 1;
if (S.lowApprovalStreak >= 3) {
endGame(false, `You have lost power. Approval below 20% for 3 consecutive years. Successor takes over.`);
return;
}
} else {
S.lowApprovalStreak = 0;
}
// hegemony
const share = weightedAlignmentShare(S.player);
if (share >= 0.80) {
S.holdStreak += 1;
if (S.holdStreak >= 5) {
endGame(true, `HEGEMONY ACHIEVED. ${POWER_NAME[S.player]} commands ≥80% of weighted global alignment for 5 consecutive years.`);
return;
}
} else {
S.holdStreak = 0;
}
// end of campaign
if (S.year >= 2050) {
const ranking = POWERS.map(p => ({ p, s: S.score[p] })).sort((a,b) => b.s - a.s);
const winner = ranking[0].p;
const won = winner === S.player;
endGame(won, `Campaign complete (2050). Final standings:\n${ranking.map((r,i) => `${i+1}. ${POWER_NAME[r.p]}: ${r.s}`).join('\n')}`);
}
}
function endGame(won, msg) {
S.over = true;
document.getElementById('end-modal').style.display = 'flex';
document.getElementById('end-title').textContent = won ? 'VICTORY' : 'DEFEAT';
document.getElementById('end-title').style.color = won ? 'var(--green)' : 'var(--red)';
document.getElementById('end-body').innerHTML = `<pre style="white-space:pre-wrap;color:var(--text);font-family:inherit;font-size:12px;line-height:1.5">${msg}</pre>`;
log(won ? 'win' : 'crisis', msg.split('\n')[0]);
}
// =============== RENDERING ===============
function dominantPower(c) {
let best = 'NEU', bv = neutral(c);
for (const p of POWERS) {
if ((c.ali[p]||0) > bv) { bv = c.ali[p]||0; best = p; }
}
return best;
}
function colorForCountry(c) {
const dom = dominantPower(c);
if (dom === 'NEU') return 'var(--neutral)';
return POWER_COLOR[dom];
}
function featureForCode(code) {
if (!WORLD_DATA) return null;
if (CODE_TO_FEATURE_CACHE) return CODE_TO_FEATURE_CACHE.get(code) || null;
// For powers/middle powers, find first matching feature (EU has many)
return WORLD_DATA.features.find(f => ISO_TO_CODE[+f.id] === code);
}
function buildMapCaches() {
if (!WORLD_DATA || !PATH_GEN) return;
FEATURE_PATH_CACHE = new Map();
CODE_TO_FEATURE_CACHE = new Map();
for (const f of WORLD_DATA.features) {
const d = PATH_GEN(f);
const c = PATH_GEN.centroid(f);
FEATURE_PATH_CACHE.set(f, { d, centroid: c });
const code = ISO_TO_CODE[+f.id];
// First match wins (EU has many; matches old find() behavior)
if (code && !CODE_TO_FEATURE_CACHE.has(code)) {
CODE_TO_FEATURE_CACHE.set(code, f);
}
}
const graticule = d3.geoGraticule().step([20, 20]);
GRATICULE_PATH_CACHE = PATH_GEN(graticule());
}
function renderMap() {
const svg = document.getElementById('map');
if (!WORLD_DATA) {
svg.innerHTML = '<rect width="1000" height="500" fill="#0a1420"/><text x="500" y="250" text-anchor="middle" fill="#7a8898" font-family="Consolas" font-size="12" letter-spacing="3">LOADING WORLD MAP…</text>';
return;
}
if (!FEATURE_PATH_CACHE) buildMapCaches();
let html = '';
// ocean
html += `<rect width="1000" height="500" fill="#0a1420"/>`;
// graticule (latitude/longitude grid) for that situation-room feel — cached
html += `<path d="${GRATICULE_PATH_CACHE}" fill="none" stroke="#1a2838" stroke-width="0.4" stroke-opacity="0.6"/>`;
// countries
for (const f of WORLD_DATA.features) {
const id = +f.id;
const code = ISO_TO_CODE[id];
const cached = FEATURE_PATH_CACHE.get(f);
const d = cached ? cached.d : null;
if (!d) continue;
let fill, stroke, opa, cls = '', interactive = false;
if (POWERS.includes(code)) {
fill = POWER_COLOR[code];
opa = S.player === code ? 0.55 : 0.32;
stroke = POWER_COLOR[code];
cls = `power power-${code}`;
} else if (S.countries[code]) {
const c = S.countries[code];
const dom = dominantPower(c);
fill = dom === 'NEU' ? '#243040' : POWER_COLOR[dom];
opa = dom === 'NEU' ? 0.7 : 0.30 + ((c.ali[dom]||0)/100) * 0.55;
stroke = dom === 'NEU' ? '#3d5070' : POWER_COLOR[dom];
cls = `country middle${S.selected === code ? ' selected' : ''}`;
interactive = true;
} else {
fill = '#11161e';
opa = 0.85;
stroke = '#2a3548';
}
const dataAttr = interactive ? `data-k="${code}"` : '';
html += `<path class="${cls}" ${dataAttr} d="${d}" fill="${fill}" fill-opacity="${opa}" stroke="${stroke}" stroke-opacity="0.7" stroke-width="0.6"/>`;
}
// power labels — hand-picked anchors so wrap-around features land correctly
const POWER_LABEL_LL = { USA: [-98, 39], CHN: [104, 36], RUS: [85, 62], EU: [10, 50] };
for (const p of POWERS) {
const pt = PROJECTION(POWER_LABEL_LL[p]);
if (pt && !isNaN(pt[0])) {
html += `<text x="${pt[0]}" y="${pt[1] + 4}" class="country-label" style="font-size:14px;font-weight:bold;letter-spacing:3px;fill:rgba(255,255,255,0.92)">${p}</text>`;
}
}
// middle-power labels (3-letter code at centroid)
for (const k of Object.keys(S.countries)) {
const f = featureForCode(k);
if (!f) continue;
const cached = FEATURE_PATH_CACHE.get(f);
const c = cached ? cached.centroid : PATH_GEN.centroid(f);
if (isNaN(c[0])) continue;
html += `<text x="${c[0]}" y="${c[1] + 3}" class="country-label" style="font-size:9px;letter-spacing:1.5px">${k}</text>`;
}
// chokepoints
for (const k of Object.keys(CHOKE_LATLON)) {
const cp = CHOKE_LATLON[k];
const pt = PROJECTION(cp.lonlat);
if (!pt) continue;
const closed = S.chokepointsClosed[k] ? ' closed' : '';
html += `<circle class="chokepoint${closed}" cx="${pt[0]}" cy="${pt[1]}" r="5"/>`;
html += `<text x="${pt[0]}" y="${pt[1] - 8}" class="country-label" style="fill:var(--amber);font-size:8px">${cp.label}</text>`;