-
-
Notifications
You must be signed in to change notification settings - Fork 362
/
StarSystem.cpp
2709 lines (2439 loc) · 95 KB
/
StarSystem.cpp
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
// Copyright © 2008-2014 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#include "StarSystem.h"
#include "Sector.h"
#include "Galaxy.h"
#include "GalaxyCache.h"
#include "Factions.h"
#include "Serializer.h"
#include "Pi.h"
#include "LuaNameGen.h"
#include "enum_table.h"
#include <map>
#include <string>
#include <algorithm>
#include "utils.h"
#include "Orbit.h"
#include "Lang.h"
#include "StringF.h"
#include <SDL_stdinc.h>
#include "EnumStrings.h"
static const double CELSIUS = 273.15;
//#define DEBUG_DUMP
// minimum moon mass a little under Europa's
static const fixed MIN_MOON_MASS = fixed(1,30000); // earth masses
static const fixed MIN_MOON_DIST = fixed(15,10000); // AUs
static const fixed MAX_MOON_DIST = fixed(2, 100); // AUs
// if binary stars have separation s, planets can have stable
// orbits at (0.5 * s * SAFE_DIST_FROM_BINARY)
static const fixed SAFE_DIST_FROM_BINARY = fixed(5,1);
static const fixed PLANET_MIN_SEPARATION = fixed(135,100);
// very crudely
static const fixed AU_SOL_RADIUS = fixed(305,65536);
static const fixed AU_EARTH_RADIUS = fixed(3, 65536);
static const fixed SUN_MASS_TO_EARTH_MASS = fixed(332998,1);
static const fixed FIXED_PI = fixed(103993,33102);
// indexed by enum type turd
const Uint8 StarSystem::starColors[][3] = {
{ 0, 0, 0 }, // gravpoint
{ 128, 0, 0 }, // brown dwarf
{ 102, 102, 204 }, // white dwarf
{ 255, 51, 0 }, // M
{ 255, 153, 26 }, // K
{ 255, 255, 102 }, // G
{ 255, 255, 204 }, // F
{ 255, 255, 255 }, // A
{ 178, 178, 255 }, // B
{ 255, 178, 255 }, // O
{ 255, 51, 0 }, // M Giant
{ 255, 153, 26 }, // K Giant
{ 255, 255, 102 }, // G Giant
{ 255, 255, 204 }, // F Giant
{ 255, 255, 255 }, // A Giant
{ 178, 178, 255 }, // B Giant
{ 255, 178, 255 }, // O Giant
{ 255, 51, 0 }, // M Super Giant
{ 255, 153, 26 }, // K Super Giant
{ 255, 255, 102 }, // G Super Giant
{ 255, 255, 204 }, // F Super Giant
{ 255, 255, 255 }, // A Super Giant
{ 178, 178, 255 }, // B Super Giant
{ 255, 178, 255 }, // O Super Giant
{ 255, 51, 0 }, // M Hyper Giant
{ 255, 153, 26 }, // K Hyper Giant
{ 255, 255, 102 }, // G Hyper Giant
{ 255, 255, 204 }, // F Hyper Giant
{ 255, 255, 255 }, // A Hyper Giant
{ 178, 178, 255 }, // B Hyper Giant
{ 255, 178, 255 }, // O Hyper Giant
{ 255, 51, 0 }, // Red/M Wolf Rayet Star
{ 178, 178, 255 }, // Blue/B Wolf Rayet Star
{ 255, 178, 255 }, // Purple-Blue/O Wolf Rayet Star
{ 76, 178, 76 }, // Stellar Blackhole
{ 51, 230, 51 }, // Intermediate mass Black-hole
{ 0, 255, 0 }, // Super massive black hole
};
// indexed by enum type turd
const Uint8 StarSystem::starRealColors[][3] = {
{ 0, 0, 0 }, // gravpoint
{ 128, 0, 0 }, // brown dwarf
{ 255, 255, 255 }, // white dwarf
{ 255, 128, 51 }, // M
{ 255, 255, 102 }, // K
{ 255, 255, 242 }, // G
{ 255, 255, 255 }, // F
{ 255, 255, 255 }, // A
{ 204, 204, 255 }, // B
{ 255, 204, 255 }, // O
{ 255, 128, 51 }, // M Giant
{ 255, 255, 102 }, // K Giant
{ 255, 255, 242 }, // G Giant
{ 255, 255, 255 }, // F Giant
{ 255, 255, 255 }, // A Giant
{ 204, 204, 255 }, // B Giant
{ 255, 204, 255 }, // O Giant
{ 255, 128, 51 }, // M Super Giant
{ 255, 255, 102 }, // K Super Giant
{ 255, 255, 242 }, // G Super Giant
{ 255, 255, 255 }, // F Super Giant
{ 255, 255, 255 }, // A Super Giant
{ 204, 204, 255 }, // B Super Giant
{ 255, 204, 255 }, // O Super Giant
{ 255, 128, 51 }, // M Hyper Giant
{ 255, 255, 102 }, // K Hyper Giant
{ 255, 255, 242 }, // G Hyper Giant
{ 255, 255, 255 }, // F Hyper Giant
{ 255, 255, 255 }, // A Hyper Giant
{ 204, 204, 255 }, // B Hyper Giant
{ 255, 204, 255 }, // O Hyper Giant
{ 255, 153, 153 }, // M WF
{ 204, 204, 255 }, // B WF
{ 255, 204, 255 }, // O WF
{ 255, 255, 255 }, // small Black hole
{ 16, 0, 20 }, // med BH
{ 10, 0, 16 }, // massive BH
};
const double StarSystem::starLuminosities[] = {
0,
0.0003, // brown dwarf
0.1, // white dwarf
0.08, // M0
0.38, // K0
1.2, // G0
5.1, // F0
24.0, // A0
100.0, // B0
200.0, // O5
1000.0, // M0 Giant
2000.0, // K0 Giant
4000.0, // G0 Giant
6000.0, // F0 Giant
8000.0, // A0 Giant
9000.0, // B0 Giant
12000.0, // O5 Giant
12000.0, // M0 Super Giant
14000.0, // K0 Super Giant
18000.0, // G0 Super Giant
24000.0, // F0 Super Giant
30000.0, // A0 Super Giant
50000.0, // B0 Super Giant
100000.0, // O5 Super Giant
125000.0, // M0 Hyper Giant
150000.0, // K0 Hyper Giant
175000.0, // G0 Hyper Giant
200000.0, // F0 Hyper Giant
200000.0, // A0 Hyper Giant
200000.0, // B0 Hyper Giant
200000.0, // O5 Hyper Giant
50000.0, // M WF
100000.0, // B WF
200000.0, // O WF
0.0003, // Stellar Black hole
0.00003, // IM Black hole
0.000003, // Supermassive Black hole
};
const float StarSystem::starScale[] = { // Used in sector view
0,
0.6f, // brown dwarf
0.5f, // white dwarf
0.7f, // M
0.8f, // K
0.8f, // G
0.9f, // F
1.0f, // A
1.1f, // B
1.1f, // O
1.3f, // M Giant
1.2f, // K G
1.2f, // G G
1.2f, // F G
1.1f, // A G
1.1f, // B G
1.2f, // O G
1.8f, // M Super Giant
1.6f, // K SG
1.5f, // G SG
1.5f, // F SG
1.4f, // A SG
1.3f, // B SG
1.3f, // O SG
2.5f, // M Hyper Giant
2.2f, // K HG
2.2f, // G HG
2.1f, // F HG
2.1f, // A HG
2.0f, // B HG
1.9f, // O HG
1.1f, // M WF
1.3f, // B WF
1.6f, // O WF
1.0f, // Black hole
2.5f, // Intermediate-mass blackhole
4.0f // Supermassive blackhole
};
const fixed StarSystem::starMetallicities[] = {
fixed(1,1), // GRAVPOINT - for planets that orbit them
fixed(9,10), // brown dwarf
fixed(5,10), // white dwarf
fixed(7,10), // M0
fixed(6,10), // K0
fixed(5,10), // G0
fixed(4,10), // F0
fixed(3,10), // A0
fixed(2,10), // B0
fixed(1,10), // O5
fixed(8,10), // M0 Giant
fixed(65,100), // K0 Giant
fixed(55,100), // G0 Giant
fixed(4,10), // F0 Giant
fixed(3,10), // A0 Giant
fixed(2,10), // B0 Giant
fixed(1,10), // O5 Giant
fixed(9,10), // M0 Super Giant
fixed(7,10), // K0 Super Giant
fixed(6,10), // G0 Super Giant
fixed(4,10), // F0 Super Giant
fixed(3,10), // A0 Super Giant
fixed(2,10), // B0 Super Giant
fixed(1,10), // O5 Super Giant
fixed(1,1), // M0 Hyper Giant
fixed(7,10), // K0 Hyper Giant
fixed(6,10), // G0 Hyper Giant
fixed(4,10), // F0 Hyper Giant
fixed(3,10), // A0 Hyper Giant
fixed(2,10), // B0 Hyper Giant
fixed(1,10), // O5 Hyper Giant
fixed(1,1), // M WF
fixed(8,10), // B WF
fixed(6,10), // O WF
fixed(1,1), // S BH Blackholes, give them high metallicity,
fixed(1,1), // IM BH so any rocks that happen to be there
fixed(1,1) // SM BH may be mining hotspots. FUN :)
};
static const struct StarTypeInfo {
SystemBody::BodySuperType supertype;
int mass[2]; // min,max % sol for stars, unused for planets
int radius[2]; // min,max % sol radii for stars, % earth radii for planets
int tempMin, tempMax;
} starTypeInfo[] = {
{
SystemBody::SUPERTYPE_NONE, {}, {},
0, 0
}, {
SystemBody::SUPERTYPE_STAR, //Brown Dwarf
{2,8}, {10,30},
1000, 2000
}, {
SystemBody::SUPERTYPE_STAR, //white dwarf
{20,100}, {1,2},
4000, 40000
}, {
SystemBody::SUPERTYPE_STAR, //M
{10,47}, {30,60},
2000, 3500
}, {
SystemBody::SUPERTYPE_STAR, //K
{50,78}, {60,100},
3500, 5000
}, {
SystemBody::SUPERTYPE_STAR, //G
{80,110}, {80,120},
5000, 6000
}, {
SystemBody::SUPERTYPE_STAR, //F
{115,170}, {110,150},
6000, 7500
}, {
SystemBody::SUPERTYPE_STAR, //A
{180,320}, {120,220},
7500, 10000
}, {
SystemBody::SUPERTYPE_STAR, //B
{200,300}, {120,290},
10000, 30000
}, {
SystemBody::SUPERTYPE_STAR, //O
{300,400}, {200,310},
30000, 60000
}, {
SystemBody::SUPERTYPE_STAR, //M Giant
{60,357}, {2000,5000},
2500, 3500
}, {
SystemBody::SUPERTYPE_STAR, //K Giant
{125,500}, {1500,3000},
3500, 5000
}, {
SystemBody::SUPERTYPE_STAR, //G Giant
{200,800}, {1000,2000},
5000, 6000
}, {
SystemBody::SUPERTYPE_STAR, //F Giant
{250,900}, {800,1500},
6000, 7500
}, {
SystemBody::SUPERTYPE_STAR, //A Giant
{400,1000}, {600,1000},
7500, 10000
}, {
SystemBody::SUPERTYPE_STAR, //B Giant
{500,1000}, {600,1000},
10000, 30000
}, {
SystemBody::SUPERTYPE_STAR, //O Giant
{600,1200}, {600,1000},
30000, 60000
}, {
SystemBody::SUPERTYPE_STAR, //M Super Giant
{1050,5000}, {7000,15000},
2500, 3500
}, {
SystemBody::SUPERTYPE_STAR, //K Super Giant
{1100,5000}, {5000,9000},
3500, 5000
}, {
SystemBody::SUPERTYPE_STAR, //G Super Giant
{1200,5000}, {4000,8000},
5000, 6000
}, {
SystemBody::SUPERTYPE_STAR, //F Super Giant
{1500,6000}, {3500,7000},
6000, 7500
}, {
SystemBody::SUPERTYPE_STAR, //A Super Giant
{2000,8000}, {3000,6000},
7500, 10000
}, {
SystemBody::SUPERTYPE_STAR, //B Super Giant
{3000,9000}, {2500,5000},
10000, 30000
}, {
SystemBody::SUPERTYPE_STAR, //O Super Giant
{5000,10000}, {2000,4000},
30000, 60000
}, {
SystemBody::SUPERTYPE_STAR, //M Hyper Giant
{5000,15000}, {20000,40000},
2500, 3500
}, {
SystemBody::SUPERTYPE_STAR, //K Hyper Giant
{5000,17000}, {17000,25000},
3500, 5000
}, {
SystemBody::SUPERTYPE_STAR, //G Hyper Giant
{5000,18000}, {14000,20000},
5000, 6000
}, {
SystemBody::SUPERTYPE_STAR, //F Hyper Giant
{5000,19000}, {12000,17500},
6000, 7500
}, {
SystemBody::SUPERTYPE_STAR, //A Hyper Giant
{5000,20000}, {10000,15000},
7500, 10000
}, {
SystemBody::SUPERTYPE_STAR, //B Hyper Giant
{5000,23000}, {6000,10000},
10000, 30000
}, {
SystemBody::SUPERTYPE_STAR, //O Hyper Giant
{10000,30000}, {4000,7000},
30000, 60000
}, {
SystemBody::SUPERTYPE_STAR, // M WF
{2000,5000}, {2500,5000},
25000, 35000
}, {
SystemBody::SUPERTYPE_STAR, // B WF
{2000,7500}, {2500,5000},
35000, 45000
}, {
SystemBody::SUPERTYPE_STAR, // O WF
{2000,10000}, {2500,5000},
45000, 60000
}, {
SystemBody::SUPERTYPE_STAR, // S BH
{20,2000}, {0,0}, // XXX black holes are < 1 Sol radii big; this is clamped to a non-zero value later
10, 24
}, {
SystemBody::SUPERTYPE_STAR, // IM BH
{900000,1000000}, {100,500},
1, 10
}, {
SystemBody::SUPERTYPE_STAR, // SM BH
{2000000,5000000}, {10000,20000},
10, 24
}
/* }, {
SystemBody::SUPERTYPE_GAS_GIANT,
{}, 950, Lang::MEDIUM_GAS_GIANT,
}, {
SystemBody::SUPERTYPE_GAS_GIANT,
{}, 1110, Lang::LARGE_GAS_GIANT,
}, {
SystemBody::SUPERTYPE_GAS_GIANT,
{}, 1500, Lang::VERY_LARGE_GAS_GIANT,
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 1, Lang::ASTEROID,
"icons/object_planet_asteroid.png"
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 2, "Large asteroid",
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 26, "Small, rocky dwarf planet", // moon radius
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 26, "Small, rocky dwarf planet", // dwarf2 for moon-like colours
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 52, "Small, rocky planet with a thin atmosphere", // mars radius
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 100, "Rocky frozen planet with a thin nitrogen atmosphere", // earth radius
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 100, "Dead world that once housed it's own intricate ecosystem.", // earth radius
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 100, "Rocky planet with a carbon dioxide atmosphere",
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 100, "Rocky planet with a methane atmosphere",
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 100, "Water world with vast oceans and a thick nitrogen atmosphere",
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 100, "Rocky planet with a thick carbon dioxide atmosphere",
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 100, "Rocky planet with a thick methane atmosphere",
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 100, "Highly volcanic world",
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 100, "World with indigenous life and an oxygen atmosphere",
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 60, "Marginal terraformed world with minimal plant life",
}, {
SystemBody::SUPERTYPE_ROCKY_PLANET,
{}, 90, "Fully terraformed world with introduced species from numerous successful colonies",
}, {
SystemBody::SUPERTYPE_STARPORT,
{}, 0, Lang::ORBITAL_STARPORT,
}, {
SystemBody::SUPERTYPE_STARPORT,
{}, 0, Lang::STARPORT,
}*/
};
SystemBody::BodySuperType SystemBody::GetSuperType() const
{
PROFILE_SCOPED()
switch (m_type) {
case TYPE_BROWN_DWARF:
case TYPE_WHITE_DWARF:
case TYPE_STAR_M:
case TYPE_STAR_K:
case TYPE_STAR_G:
case TYPE_STAR_F:
case TYPE_STAR_A:
case TYPE_STAR_B:
case TYPE_STAR_O:
case TYPE_STAR_M_GIANT:
case TYPE_STAR_K_GIANT:
case TYPE_STAR_G_GIANT:
case TYPE_STAR_F_GIANT:
case TYPE_STAR_A_GIANT:
case TYPE_STAR_B_GIANT:
case TYPE_STAR_O_GIANT:
case TYPE_STAR_M_SUPER_GIANT:
case TYPE_STAR_K_SUPER_GIANT:
case TYPE_STAR_G_SUPER_GIANT:
case TYPE_STAR_F_SUPER_GIANT:
case TYPE_STAR_A_SUPER_GIANT:
case TYPE_STAR_B_SUPER_GIANT:
case TYPE_STAR_O_SUPER_GIANT:
case TYPE_STAR_M_HYPER_GIANT:
case TYPE_STAR_K_HYPER_GIANT:
case TYPE_STAR_G_HYPER_GIANT:
case TYPE_STAR_F_HYPER_GIANT:
case TYPE_STAR_A_HYPER_GIANT:
case TYPE_STAR_B_HYPER_GIANT:
case TYPE_STAR_O_HYPER_GIANT:
case TYPE_STAR_M_WF:
case TYPE_STAR_B_WF:
case TYPE_STAR_O_WF:
case TYPE_STAR_S_BH:
case TYPE_STAR_IM_BH:
case TYPE_STAR_SM_BH:
return SUPERTYPE_STAR;
case TYPE_PLANET_GAS_GIANT:
return SUPERTYPE_GAS_GIANT;
case TYPE_PLANET_ASTEROID:
case TYPE_PLANET_TERRESTRIAL:
return SUPERTYPE_ROCKY_PLANET;
case TYPE_STARPORT_ORBITAL:
case TYPE_STARPORT_SURFACE:
return SUPERTYPE_STARPORT;
case TYPE_GRAVPOINT:
return SUPERTYPE_NONE;
default:
Output("Warning: Invalid SuperBody Type found.\n");
return SUPERTYPE_NONE;
}
}
std::string SystemBody::GetAstroDescription() const
{
PROFILE_SCOPED()
switch (m_type) {
case TYPE_BROWN_DWARF: return Lang::BROWN_DWARF;
case TYPE_WHITE_DWARF: return Lang::WHITE_DWARF;
case TYPE_STAR_M: return Lang::STAR_M;
case TYPE_STAR_K: return Lang::STAR_K;
case TYPE_STAR_G: return Lang::STAR_G;
case TYPE_STAR_F: return Lang::STAR_F;
case TYPE_STAR_A: return Lang::STAR_A;
case TYPE_STAR_B: return Lang::STAR_B;
case TYPE_STAR_O: return Lang::STAR_O;
case TYPE_STAR_M_GIANT: return Lang::STAR_M_GIANT;
case TYPE_STAR_K_GIANT: return Lang::STAR_K_GIANT;
case TYPE_STAR_G_GIANT: return Lang::STAR_G_GIANT;
case TYPE_STAR_F_GIANT: return Lang::STAR_AF_GIANT;
case TYPE_STAR_A_GIANT: return Lang::STAR_AF_GIANT;
case TYPE_STAR_B_GIANT: return Lang::STAR_B_GIANT;
case TYPE_STAR_O_GIANT: return Lang::STAR_O_GIANT;
case TYPE_STAR_M_SUPER_GIANT: return Lang::STAR_M_SUPER_GIANT;
case TYPE_STAR_K_SUPER_GIANT: return Lang::STAR_K_SUPER_GIANT;
case TYPE_STAR_G_SUPER_GIANT: return Lang::STAR_G_SUPER_GIANT;
case TYPE_STAR_F_SUPER_GIANT: return Lang::STAR_AF_SUPER_GIANT;
case TYPE_STAR_A_SUPER_GIANT: return Lang::STAR_AF_SUPER_GIANT;
case TYPE_STAR_B_SUPER_GIANT: return Lang::STAR_B_SUPER_GIANT;
case TYPE_STAR_O_SUPER_GIANT: return Lang::STAR_O_SUPER_GIANT;
case TYPE_STAR_M_HYPER_GIANT: return Lang::STAR_M_HYPER_GIANT;
case TYPE_STAR_K_HYPER_GIANT: return Lang::STAR_K_HYPER_GIANT;
case TYPE_STAR_G_HYPER_GIANT: return Lang::STAR_G_HYPER_GIANT;
case TYPE_STAR_F_HYPER_GIANT: return Lang::STAR_AF_HYPER_GIANT;
case TYPE_STAR_A_HYPER_GIANT: return Lang::STAR_AF_HYPER_GIANT;
case TYPE_STAR_B_HYPER_GIANT: return Lang::STAR_B_HYPER_GIANT;
case TYPE_STAR_O_HYPER_GIANT: return Lang::STAR_O_HYPER_GIANT;
case TYPE_STAR_M_WF: return Lang::STAR_M_WF;
case TYPE_STAR_B_WF: return Lang::STAR_B_WF;
case TYPE_STAR_O_WF: return Lang::STAR_O_WF;
case TYPE_STAR_S_BH: return Lang::STAR_S_BH;
case TYPE_STAR_IM_BH: return Lang::STAR_IM_BH;
case TYPE_STAR_SM_BH: return Lang::STAR_SM_BH;
case TYPE_PLANET_GAS_GIANT:
if (m_mass > 800) return Lang::VERY_LARGE_GAS_GIANT;
if (m_mass > 300) return Lang::LARGE_GAS_GIANT;
if (m_mass > 80) return Lang::MEDIUM_GAS_GIANT;
else return Lang::SMALL_GAS_GIANT;
case TYPE_PLANET_ASTEROID: return Lang::ASTEROID;
case TYPE_PLANET_TERRESTRIAL: {
std::string s;
if (m_mass > fixed(2,1)) s = Lang::MASSIVE;
else if (m_mass > fixed(3,2)) s = Lang::LARGE;
else if (m_mass < fixed(1,10)) s = Lang::TINY;
else if (m_mass < fixed(1,5)) s = Lang::SMALL;
if (m_volcanicity > fixed(7,10)) {
if (s.size()) s += Lang::COMMA_HIGHLY_VOLCANIC;
else s = Lang::HIGHLY_VOLCANIC;
}
if (m_volatileIces + m_volatileLiquid > fixed(4,5)) {
if (m_volatileIces > m_volatileLiquid) {
if (m_averageTemp < fixed(250)) {
s += Lang::ICE_WORLD;
} else s += Lang::ROCKY_PLANET;
} else {
if (m_averageTemp < fixed(250)) {
s += Lang::ICE_WORLD;
} else {
s += Lang::OCEANICWORLD;
}
}
} else if (m_volatileLiquid > fixed(2,5)){
if (m_averageTemp > fixed(250)) {
s += Lang::PLANET_CONTAINING_LIQUID_WATER;
} else {
s += Lang::PLANET_WITH_SOME_ICE;
}
} else if (m_volatileLiquid > fixed(1,5)){
s += Lang::ROCKY_PLANET_CONTAINING_COME_LIQUIDS;
} else {
s += Lang::ROCKY_PLANET;
}
if (m_volatileGas < fixed(1,100)) {
s += Lang::WITH_NO_SIGNIFICANT_ATMOSPHERE;
} else {
std::string thickness;
if (m_volatileGas < fixed(1,10)) thickness = Lang::TENUOUS;
else if (m_volatileGas < fixed(1,5)) thickness = Lang::THIN;
else if (m_volatileGas < fixed(2,1)) {}
else if (m_volatileGas < fixed(4,1)) thickness = Lang::THICK;
else thickness = Lang::VERY_DENSE;
if (m_atmosOxidizing > fixed(95,100)) {
s += Lang::WITH_A+thickness+Lang::O2_ATMOSPHERE;
} else if (m_atmosOxidizing > fixed(7,10)) {
s += Lang::WITH_A+thickness+Lang::CO2_ATMOSPHERE;
} else if (m_atmosOxidizing > fixed(65,100)) {
s += Lang::WITH_A+thickness+Lang::CO_ATMOSPHERE;
} else if (m_atmosOxidizing > fixed(55,100)) {
s += Lang::WITH_A+thickness+Lang::CH4_ATMOSPHERE;
} else if (m_atmosOxidizing > fixed(3,10)) {
s += Lang::WITH_A+thickness+Lang::H_ATMOSPHERE;
} else if (m_atmosOxidizing > fixed(2,10)) {
s += Lang::WITH_A+thickness+Lang::HE_ATMOSPHERE;
} else if (m_atmosOxidizing > fixed(15,100)) {
s += Lang::WITH_A+thickness+Lang::AR_ATMOSPHERE;
} else if (m_atmosOxidizing > fixed(1,10)) {
s += Lang::WITH_A+thickness+Lang::S_ATMOSPHERE;
} else {
s += Lang::WITH_A+thickness+Lang::N_ATMOSPHERE;
}
}
if (m_life > fixed(1,2)) {
s += Lang::AND_HIGHLY_COMPLEX_ECOSYSTEM;
} else if (m_life > fixed(1,10)) {
s += Lang::AND_INDIGENOUS_PLANT_LIFE;
} else if (m_life > fixed()) {
s += Lang::AND_INDIGENOUS_MICROBIAL_LIFE;
} else {
s += ".";
}
return s;
}
case TYPE_STARPORT_ORBITAL:
return Lang::ORBITAL_STARPORT;
case TYPE_STARPORT_SURFACE:
return Lang::STARPORT;
case TYPE_GRAVPOINT:
default:
Output("Warning: Invalid Astro Body Description found.\n");
return Lang::UNKNOWN;
}
}
const char *SystemBody::GetIcon() const
{
PROFILE_SCOPED()
switch (m_type) {
case TYPE_BROWN_DWARF: return "icons/object_brown_dwarf.png";
case TYPE_WHITE_DWARF: return "icons/object_white_dwarf.png";
case TYPE_STAR_M: return "icons/object_star_m.png";
case TYPE_STAR_K: return "icons/object_star_k.png";
case TYPE_STAR_G: return "icons/object_star_g.png";
case TYPE_STAR_F: return "icons/object_star_f.png";
case TYPE_STAR_A: return "icons/object_star_a.png";
case TYPE_STAR_B: return "icons/object_star_b.png";
case TYPE_STAR_O: return "icons/object_star_b.png"; //shares B graphic for now
case TYPE_STAR_M_GIANT: return "icons/object_star_m_giant.png";
case TYPE_STAR_K_GIANT: return "icons/object_star_k_giant.png";
case TYPE_STAR_G_GIANT: return "icons/object_star_g_giant.png";
case TYPE_STAR_F_GIANT: return "icons/object_star_f_giant.png";
case TYPE_STAR_A_GIANT: return "icons/object_star_a_giant.png";
case TYPE_STAR_B_GIANT: return "icons/object_star_b_giant.png";
case TYPE_STAR_O_GIANT: return "icons/object_star_o.png"; // uses old O type graphic
case TYPE_STAR_M_SUPER_GIANT: return "icons/object_star_m_super_giant.png";
case TYPE_STAR_K_SUPER_GIANT: return "icons/object_star_k_super_giant.png";
case TYPE_STAR_G_SUPER_GIANT: return "icons/object_star_g_super_giant.png";
case TYPE_STAR_F_SUPER_GIANT: return "icons/object_star_g_super_giant.png"; //shares G graphic for now
case TYPE_STAR_A_SUPER_GIANT: return "icons/object_star_a_super_giant.png";
case TYPE_STAR_B_SUPER_GIANT: return "icons/object_star_b_super_giant.png";
case TYPE_STAR_O_SUPER_GIANT: return "icons/object_star_b_super_giant.png";// uses B type graphic for now
case TYPE_STAR_M_HYPER_GIANT: return "icons/object_star_m_hyper_giant.png";
case TYPE_STAR_K_HYPER_GIANT: return "icons/object_star_k_hyper_giant.png";
case TYPE_STAR_G_HYPER_GIANT: return "icons/object_star_g_hyper_giant.png";
case TYPE_STAR_F_HYPER_GIANT: return "icons/object_star_f_hyper_giant.png";
case TYPE_STAR_A_HYPER_GIANT: return "icons/object_star_a_hyper_giant.png";
case TYPE_STAR_B_HYPER_GIANT: return "icons/object_star_b_hyper_giant.png";
case TYPE_STAR_O_HYPER_GIANT: return "icons/object_star_b_hyper_giant.png";// uses B type graphic for now
case TYPE_STAR_M_WF: return "icons/object_star_m_wf.png";
case TYPE_STAR_B_WF: return "icons/object_star_b_wf.png";
case TYPE_STAR_O_WF: return "icons/object_star_o_wf.png";
case TYPE_STAR_S_BH: return "icons/object_star_bh.png";
case TYPE_STAR_IM_BH: return "icons/object_star_smbh.png";
case TYPE_STAR_SM_BH: return "icons/object_star_smbh.png";
case TYPE_PLANET_GAS_GIANT:
if (m_mass > 800) {
if (m_averageTemp > 1000) return "icons/object_planet_large_gas_giant_hot.png";
else return "icons/object_planet_large_gas_giant.png";
}
if (m_mass > 300) {
if (m_averageTemp > 1000) return "icons/object_planet_large_gas_giant_hot.png";
else return "icons/object_planet_large_gas_giant.png";
}
if (m_mass > 80) {
if (m_averageTemp > 1000) return "icons/object_planet_medium_gas_giant_hot.png";
else return "icons/object_planet_medium_gas_giant.png";
}
else {
if (m_averageTemp > 1000) return "icons/object_planet_small_gas_giant_hot.png";
else return "icons/object_planet_small_gas_giant.png";
}
case TYPE_PLANET_ASTEROID:
return "icons/object_planet_asteroid.png";
case TYPE_PLANET_TERRESTRIAL:
if (m_volatileLiquid > fixed(7,10)) {
if (m_averageTemp > 250) return "icons/object_planet_water.png";
else return "icons/object_planet_ice.png";
}
if ((m_life > fixed(9,10)) &&
(m_volatileGas > fixed(6,10))) return "icons/object_planet_life.png";
if ((m_life > fixed(8,10)) &&
(m_volatileGas > fixed(5,10))) return "icons/object_planet_life6.png";
if ((m_life > fixed(7,10)) &&
(m_volatileGas > fixed(45,100))) return "icons/object_planet_life7.png";
if ((m_life > fixed(6,10)) &&
(m_volatileGas > fixed(4,10))) return "icons/object_planet_life8.png";
if ((m_life > fixed(5,10)) &&
(m_volatileGas > fixed(3,10))) return "icons/object_planet_life4.png";
if ((m_life > fixed(4,10)) &&
(m_volatileGas > fixed(2,10))) return "icons/object_planet_life5.png";
if ((m_life > fixed(1,10)) &&
(m_volatileGas > fixed(2,10))) return "icons/object_planet_life2.png";
if (m_life > fixed(1,10)) return "icons/object_planet_life3.png";
if (m_mass < fixed(1,100)) return "icons/object_planet_dwarf.png";
if (m_mass < fixed(1,10)) return "icons/object_planet_small.png";
if ((m_volatileLiquid < fixed(1,10)) &&
(m_volatileGas > fixed(1,5))) return "icons/object_planet_desert.png";
if (m_volatileIces + m_volatileLiquid > fixed(3,5)) {
if (m_volatileIces > m_volatileLiquid) {
if (m_averageTemp < 250) return "icons/object_planet_ice.png";
} else {
if (m_averageTemp > 250) {
return "icons/object_planet_water.png";
} else return "icons/object_planet_ice.png";
}
}
if (m_volatileGas > fixed(1,2)) {
if (m_atmosOxidizing < fixed(1,2)) {
if (m_averageTemp > 300) return "icons/object_planet_methane3.png";
else if (m_averageTemp > 250) return "icons/object_planet_methane2.png";
else return "icons/object_planet_methane.png";
} else {
if (m_averageTemp > 300) return "icons/object_planet_co2_2.png";
else if (m_averageTemp > 250) {
if ((m_volatileLiquid > fixed(3,10)) && (m_volatileGas > fixed(2,10)))
return "icons/object_planet_co2_4.png";
else return "icons/object_planet_co2_3.png";
} else return "icons/object_planet_co2.png";
}
}
if ((m_volatileLiquid > fixed(1,10)) &&
(m_volatileGas < fixed(1,10))) return "icons/object_planet_ice.png";
if (m_volcanicity > fixed(7,10)) return "icons/object_planet_volcanic.png";
return "icons/object_planet_small.png";
/*
"icons/object_planet_water_n1.png"
"icons/object_planet_life3.png"
"icons/object_planet_life2.png"
*/
case TYPE_STARPORT_ORBITAL:
return "icons/object_orbital_starport.png";
case TYPE_GRAVPOINT:
case TYPE_STARPORT_SURFACE:
default:
Output("Warning: Invalid body icon.\n");
return 0;
}
}
/*
* Position a surface starport anywhere. Space.cpp::MakeFrameFor() ensures it
* is on dry land (discarding this position if necessary)
*/
void SystemBody::PositionSettlementOnPlanet()
{
PROFILE_SCOPED()
Random r(m_seed);
// used for orientation on planet surface
double r2 = r.Double(); // function parameter evaluation order is implementation-dependent
double r1 = r.Double(); // can't put two rands in the same expression
m_orbit.SetPlane(matrix3x3d::RotateZ(2*M_PI*r1) * matrix3x3d::RotateY(2*M_PI*r2));
// store latitude and longitude to equivalent orbital parameters to
// be accessible easier
m_inclination = fixed(r1*10000,10000) + FIXED_PI/2; // latitide
m_orbitalOffset = FIXED_PI/2; // longitude
}
double SystemBody::GetMaxChildOrbitalDistance() const
{
PROFILE_SCOPED()
double max = 0;
for (unsigned int i=0; i<m_children.size(); i++) {
if (m_children[i]->m_orbMax.ToDouble() > max) {
max = m_children[i]->m_orbMax.ToDouble();
}
}
return AU * max;
}
bool SystemBody::IsCoOrbitalWith(const SystemBody* other) const
{
if(m_parent && m_parent->GetType()==SystemBody::TYPE_GRAVPOINT
&& ((m_parent->m_children[0] == this && m_parent->m_children[1] == other)
|| (m_parent->m_children[1] == this && m_parent->m_children[0] == other)))
return true;
return false;
}
bool SystemBody::IsCoOrbital() const
{
if(m_parent && m_parent->GetType()==SystemBody::TYPE_GRAVPOINT && (m_parent->m_children[0] == this || m_parent->m_children[1] == this))
return true;
return false;
}
/*
* These are the nice floating point surface temp calculating turds.
*
static const double boltzman_const = 5.6704e-8;
static double calcEnergyPerUnitAreaAtDist(double star_radius, double star_temp, double object_dist)
{
const double total_solar_emission = boltzman_const *
star_temp*star_temp*star_temp*star_temp*
4*M_PI*star_radius*star_radius;
return total_solar_emission / (4*M_PI*object_dist*object_dist);
}
// bond albedo, not geometric
static double CalcSurfaceTemp(double star_radius, double star_temp, double object_dist, double albedo, double greenhouse)
{
const double energy_per_meter2 = calcEnergyPerUnitAreaAtDist(star_radius, star_temp, object_dist);
const double surface_temp = pow(energy_per_meter2*(1-albedo)/(4*(1-greenhouse)*boltzman_const), 0.25);
return surface_temp;
}
*/
/*
* Instead we use these butt-ugly overflow-prone spat of ejaculate:
*/
/*
* star_radius in sol radii
* star_temp in kelvin,
* object_dist in AU
* return energy per unit area in solar constants (1362 W/m^2 )
*/
static fixed calcEnergyPerUnitAreaAtDist(fixed star_radius, int star_temp, fixed object_dist)
{
PROFILE_SCOPED()
fixed temp = star_temp * fixed(1,5778); //normalize to Sun's temperature
const fixed total_solar_emission =
temp*temp*temp*temp*star_radius*star_radius;
return total_solar_emission / (object_dist*object_dist); //return value in solar consts (overflow prevention)
}
//helper function, get branch of system tree from body all the way to the system's root and write it to path
static void getPathToRoot(const SystemBody* body, std::vector<const SystemBody*>& path)
{
while(body)
{
path.push_back(body);
body = body->GetParent();
}
}
//static
int SystemBody::CalcSurfaceTemp(const SystemBody *primary, fixed distToPrimary, fixed albedo, fixed greenhouse)
{
PROFILE_SCOPED()
// accumulator seeded with current primary
fixed energy_per_meter2 = calcEnergyPerUnitAreaAtDist(primary->m_radius, primary->m_averageTemp, distToPrimary);
fixed dist;
// find the other stars which aren't our parent star
IterationProxy<std::vector<SystemBody*> > proxy = primary->GetStarSystem()->GetStars();
for( auto s : proxy )
{
if(s != primary)
{
//get branches from body and star to system root
std::vector<const SystemBody*> first_to_root;
std::vector<const SystemBody*> second_to_root;
getPathToRoot(primary, first_to_root);
getPathToRoot(&(*s), second_to_root);
std::vector<const SystemBody*>::reverse_iterator fit = first_to_root.rbegin();
std::vector<const SystemBody*>::reverse_iterator sit = second_to_root.rbegin();
while(sit!=second_to_root.rend() && fit!=first_to_root.rend() && (*sit)==(*fit)) //keep tracing both branches from system's root
{ //until they diverge
sit++;
fit++;
}
if (sit == second_to_root.rend()) sit--;
if (fit == first_to_root.rend()) fit--; //oops! one of the branches ends at lca, backtrack
if((*fit)->IsCoOrbitalWith(*sit)) //planet is around one part of coorbiting pair, star is another.
{
dist = ((*fit)->GetOrbMaxAsFixed()+(*fit)->GetOrbMinAsFixed()) >> 1; //binaries don't have fully initialized smaxes
}
else if((*sit)->IsCoOrbital()) //star is part of binary around which planet is (possibly indirectly) orbiting
{
bool inverted_ancestry = false;
for(const SystemBody* body = (*sit); body; body = body->GetParent()) if(body == (*fit))
{
inverted_ancestry = true; //ugly hack due to function being static taking planet's primary rather than being called from actual planet
break;
}
if(inverted_ancestry) //primary is star's ancestor! Don't try to take its orbit (could probably be a gravpoint check at this point, but paranoia)
{
dist = distToPrimary;
}
else
{
dist = ((*fit)->GetOrbMaxAsFixed()+(*fit)->GetOrbMinAsFixed()) >> 1; //simplified to planet orbiting stationary star
}
}
else if((*fit)->IsCoOrbital()) //planet is around one part of coorbiting pair, star isn't coorbiting with it
{
dist = ((*sit)->GetOrbMaxAsFixed()+(*sit)->GetOrbMinAsFixed()) >> 1; //simplified to star orbiting stationary planet
}
else //neither is part of any binaries - hooray!
{
dist = (((*sit)->GetSemiMajorAxisAsFixed() - (*fit)->GetSemiMajorAxisAsFixed()).Abs() //avg of conjunction and opposition dist
+ ((*sit)->GetSemiMajorAxisAsFixed() + (*fit)->GetSemiMajorAxisAsFixed())) >> 1;
}
}
energy_per_meter2 += calcEnergyPerUnitAreaAtDist(s->m_radius, s->m_averageTemp, dist);
}
const fixed surface_temp_pow4 = energy_per_meter2 * (1-albedo)/(1-greenhouse);
return (279*int(isqrt(isqrt((surface_temp_pow4.v)))))>>(fixed::FRAC/4); //multiplied by 279 to convert from Earth's temps to Kelvin
}
double SystemBody::CalcSurfaceGravity() const
{
PROFILE_SCOPED()
double r = GetRadius();
if (r > 0.0) {
return G * GetMass() / pow(r, 2);
} else {
return 0.0;
}
}
SystemBody *StarSystem::GetBodyByPath(const SystemPath &path) const
{
PROFILE_SCOPED()
assert(m_path.IsSameSystem(path));
assert(path.IsBodyPath());
assert(path.bodyIndex < m_bodies.size());
return m_bodies[path.bodyIndex].Get();
}
SystemPath StarSystem::GetPathOf(const SystemBody *sbody) const
{
return sbody->GetPath();
}
void StarSystem::CustomGetKidsOf(SystemBody *parent, const std::vector<CustomSystemBody*> &children, int *outHumanInfestedness, Random &rand)
{
PROFILE_SCOPED()
// replaces gravpoint mass by sum of masses of its children
// the code goes here to cover also planetary gravpoints (gravpoints that are not rootBody)
if (parent->GetType() == SystemBody::TYPE_GRAVPOINT) {
fixed mass(0);
for (std::vector<CustomSystemBody*>::const_iterator i = children.begin(); i != children.end(); ++i) {
const CustomSystemBody *csbody = *i;
if (csbody->type >= SystemBody::TYPE_STAR_MIN && csbody->type <= SystemBody::TYPE_STAR_MAX)
mass += csbody->mass;
else
mass += csbody->mass/SUN_MASS_TO_EARTH_MASS;
}
parent->m_mass = mass;
}
for (std::vector<CustomSystemBody*>::const_iterator i = children.begin(); i != children.end(); ++i) {
const CustomSystemBody *csbody = *i;