-
Notifications
You must be signed in to change notification settings - Fork 3
/
stargen.cpp
2265 lines (2003 loc) · 67.8 KB
/
stargen.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
#include "stargen.h"
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include "accrete.h"
#include "const.h"
#include "display.h"
#include "elements.h"
#include "enviro.h"
#include "planets.h"
#include "utils.h"
using namespace std;
int flags_arg_clone = 0;
sun the_sun_clone;
int flag_verbose = 0;
/* These are the global variables used during accretion: */
planet *innermost_planet;
long double dust_density_coeff = DUST_DENSITY_COEFF;
long flag_seed = 0;
long double min_age = 0;
long double max_age = 10.0E9;
long double max_age_backup = 10.0E9;
bool is_circumbinary = false;
long double compainion_mass_arg = 0;
long double compainion_eccentricity_arg = 0;
long double compainion_distant_arg = 0;
long double compainion_lum_arg = 0;
long double compainion_eff_arg = 0;
string companion_spec_arg = "";
int decimals_arg = 0;
long double temp_arg = 0;
string type_arg = "";
long double max_distance_arg = 0;
int earthlike = 0;
int total_earthlike = 0;
int habitable = 0;
int habitable_jovians = 0;
int habitable_superterrans =0;
int total_habitable = 0;
int potential_habitable = 0;
int total_worlds = 0;
int total_habitable_earthlike = 0;
int total_habitable_conservative = 0;
int total_habitable_optimistic = 0;
int total_potentially_habitable = 0;
int total_potentially_habitable_earthlike = 0;
int total_potentially_habitable_conservative = 0;
int total_potentially_habitable_optimistic = 0;
long double min_breathable_terrestrial_g = 1000.0;
long double min_breathable_g = 1000.0;
long double max_breathable_terrestrial_g = 0.0;
long double max_breathable_g = 0.0;
long double min_breathable_temp = 1000.0;
long double max_breathable_temp = 0.0;
long double min_breathable_p = 100000.0;
long double max_breathable_p = 0.0;
long double min_breathable_terrestrial_l = 1000.0;
long double min_breathable_l = 1000.0;
long double max_breathable_terrestrial_l = 0.0;
long double max_breathable_l = 0.0;
long double max_moon_mass = 0.0;
long double min_breathable_mass = 0;
long double max_breathable_mass = 0;
long double min_potential_terrestrial_g = 1000.0;
long double min_potential_g = 1000.0;
long double max_potential_terrestrial_g = 0.0;
long double max_potential_g = 0.0;
long double min_potential_temp = 1000.0;
long double max_potential_temp = 0.0;
long double min_potential_p = 100000.0;
long double max_potential_p = 0.0;
long double min_potential_terrestrial_l = 1000.0;
long double min_potential_l = 1000.0;
long double max_potential_terrestrial_l = 0.0;
long double max_potential_l = 0.0;
long double min_potential_mass = 0;
long double max_potential_mass = 0;
int type_counts[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //seb
int type_count = 0;
int max_type_count = 0;
bool allow_planet_migration = false;
long system_seed = 0;
string stargen_revision = "$Revision: 2.0 $";
int stargen(actions action, string flag_char, string path, string url_path_arg, string filename_arg, string sys_name_arg, string prognam, long double mass_arg, long double luminosity_arg, long seed_arg, int count_arg, int incr_arg, catalog &cat_arg, int sys_no_arg, long double ratio_arg, long double ecc_coef_arg, long double inner_planet_factor_arg, int flags_arg, int out_format, int graphic_format)
{
sun the_sun;
long double min_mass = 0.4;
long double inc_mass = 0.05;
long double max_mass = 2.35;
long double sys_inc = 0.0; //seb
long double sys_an = 0.0; //seb
int system_count = 1;
int seed_increment = 1;
string default_path = SUBDIR; /* OS specific */
string default_url_path = "../";
string url_path = default_url_path;
string thumbnail_file = "Thumbnails";
string file_name = "StarGen";
string subdir = "";
string csv_file_name = "StarGen.csv";
fstream html_file;
fstream thumbnails;
fstream csv_file;
int index = 0;
bool do_catalog = cat_arg.count() > 0 && sys_no_arg == 0;
int catalog_count = 0;
bool do_gases = (flags_arg & fDoGases) != 0;
bool use_solar_system = (flags_arg & fUseSolarsystem) != 0;
bool reuse_solar_system = (flags_arg & fReuseSolarsystem) != 0;
bool use_known_planets = (flags_arg & fUseKnownPlanets) != 0;
bool no_generate = (flags_arg & fNoGenerate) != 0;
bool do_moons = (flags_arg & fDoMoons) != 0;
bool only_habitable = (flags_arg & fOnlyHabitable) != 0;
bool only_multi_habitable= (flags_arg & fOnlyMultiHabitable) != 0;
bool only_three_habitable= (flags_arg & fOnlyThreeHabitable) != 0;
bool only_jovian_habitable=(flags_arg & fOnlyJovianHabitable) != 0;
bool only_earthlike = (flags_arg & fOnlyEarthlike) != 0;
bool only_superterrans = (flags_arg & fOnlySuperTerans) != 0;
bool only_potential_habitable = (flags_arg & fOnlyPotentialHabitable) != 0;
allow_planet_migration = (flags_arg & fDoMigration) != 0;
is_circumbinary = (flags_arg & fIsCircubinaryStar) != 0;
stringstream ss;
if (do_catalog)
{
catalog_count = cat_arg.count();
}
if (only_habitable && only_multi_habitable)
{
only_habitable = false;
}
if (only_habitable && only_earthlike)
{
only_habitable = false;
}
if (only_three_habitable)
{
only_habitable = false;
only_earthlike = false;
only_multi_habitable = false;
}
if (only_superterrans)
{
only_habitable = false;
only_earthlike = false;
only_multi_habitable = false;
only_three_habitable = false;
}
if (prognam.empty())
{
prognam = "StarGen";
}
//cout << path << endl;
if (path.empty())
{
path = default_path;
}
//cout << path << endl;
if (graphic_format == 0)
{
graphic_format = gfGIF;
}
if (!url_path_arg.empty())
{
url_path = url_path_arg;
}
// Find the last sub-dir in the path
ss << path.substr(path.find_last_of(DIRSEP) + 1) << DIRSEP;
subdir = ss.str();
ss.str("");
//cout << subdir << endl;
if (path.find_last_of(DIRSEP) != path.size())
{
path.append(DIRSEP);
}
//cout << path << endl;
switch (action)
{
case aListGases:
{
long double total = 0.0;
int count = gases.count();
for (int i = 0; i < count; i++)
{
if (gases[i].getWeight() >= AN_N && gases[i].getMaxIpp() < INCREDIBLY_LARGE_NUMBER)
{
total += gases[i].getMaxIpp();
}
//cout << " " << gases[i].getNum() << ": " << gases[i].getSymbol() << " - " << gases[i].getName() << " " << toString(gases[i].getMinIpp()) << " mb - " << toString(gases[i].getMaxIpp()) << " mb" << endl;
}
cout << gases;
cout << "Total Max ipp: " << toString(total) << endl;
cout << "Max pressure: " << toString(MAX_HABITABLE_PRESSURE) << " atm" << endl;
return EXIT_SUCCESS;
}
case aListCatalog:
{
cout << cat_arg;
return EXIT_SUCCESS;
}
case aListCatalogAsHTML:
{
int count = cat_arg.count();
for (int i = 0; i < count; i++)
{
cout << "\t<option value=" << i << ">" << cat_arg[i].getName() << "</option>" << endl;
}
return EXIT_SUCCESS;
}
case aSizeCheck:
{
long double tempE = est_temp(1.0, 1.0, EARTH_ALBEDO);
long double tempJ = est_temp(1.0, 5.2034, GAS_GIANT_ALBEDO);
long double tempS = est_temp(1.0, 9.5371, GAS_GIANT_ALBEDO);
long double tempU = est_temp(1.0, 19.1913, GAS_GIANT_ALBEDO);
long double tempN = est_temp(1.0, 30.0690, GAS_GIANT_ALBEDO);
cout << "Size of float: " << sizeof(float) << endl;
cout << "Size of doubles: " << sizeof(double) << endl;
cout << "Size of long doubles: " << sizeof(long double) << endl;
cout << "Earth Eff Temp: " << toString(tempE) << " K, " << toString(tempE - FREEZING_POINT_OF_WATER) << " C, Earth rel: " << toString(tempE - EARTH_AVERAGE_KELVIN) << " C" << endl;
cout << "Jupiter Eff Temp: " << toString(tempJ) << " K" << endl;
cout << "Saturn Eff Temp: " << toString(tempS) << " K" << endl;
cout << "Uranus Eff Temp: " << toString(tempU) << " K" << endl;
cout << "Neptune Eff Temp: " << toString(tempN) << " K" << endl;
return EXIT_SUCCESS;
}
case aListVerbosity:
{
cout << "Stargen " << stargen_revision << endl;
cout << "Verbosity flags are hexidecimal numbers:" << endl;
cout << "\t0001\tEarthlike count" << endl;
cout << "\t0002\tTrace Min/Max" << endl;
cout << "\t0004\tList Habitable" << endl;
cout << "\t0008\tList Earthlike & Sphinxlike" << endl;
cout << endl;
cout << "\t0010\tList Gases" << endl;
cout << "\t0020\tTrace temp iterations" << endl;
cout << "\t0040\tGas lifetimes" << endl;
cout << "\t0080\tList loss of accreted gas mass" << endl;
cout << endl;
cout << "\t0100\tInjecting, collision" << endl;
cout << "\t0200\tChecking..., Failed..." << endl;
cout << "\t0400\tList binary info" << endl;
cout << "\t0800\tList accreted atmospheres" << endl;
cout << endl;
cout << "\t1000\tMoons (experimental)" << endl;
cout << "\t2000\tOxygen poisoned (experimental)" << endl;
cout << "\t4000\tTrace gas percentages" << endl;
cout << "\t8000\tList Jovians in the ecosphere" << endl;
cout << endl;
cout << "\t10000\tList type diversity" << endl;
cout << "\t20000\tTrace Surface temp interations" << endl;
cout << "\t40000\tDisplay Roche Limits and Hill Sphere distances" << endl;
cout << "\t80000\tDisplay mass-radius maps" << endl;
return EXIT_SUCCESS;
}
case aGenerate:
break;
}
flag_seed = seed_arg;
the_sun.setMass(mass_arg);
the_sun.setLuminosity(luminosity_arg);
if (the_sun.getMass() == 0 && the_sun.getLuminosity() != 0)
{
the_sun.setMass(luminosity_to_mass(the_sun.getLuminosity()));
}
the_sun.setEffTemp(temp_arg);
the_sun.setSpecType(type_arg);
system_count = count_arg;
seed_increment = incr_arg;
if (ratio_arg > 0.0)
{
dust_density_coeff *= ratio_arg;
}
if (reuse_solar_system)
{
system_count = 1 + (int) ((max_mass - min_mass) / inc_mass);
the_sun.setLuminosity(1.0);
the_sun.setMass(1.0);
the_sun.setAge(5E9);
use_solar_system = true;
}
else if (do_catalog)
{
system_count = catalog_count + ((system_count - 1) * (catalog_count - 1));
use_solar_system = true;
}
if (system_count > 1 && out_format != ffCSVdl)
{
if (filename_arg.size() > 0)
{
thumbnail_file = filename_arg;
}
open_html_file("Thumbnails", flag_seed, path, url_path, thumbnail_file, ".html", prognam, thumbnails);
}
if (out_format == ffCSV || out_format == ffCSVdl)
{
string csv_url;
string cleaned_arg = "StarGen";
if (filename_arg.size() > 0)
{
char *ptr;
cleaned_arg = filename_arg;
}
ss.str("");
ss << cleaned_arg << ".csv";
csv_file_name = ss.str();
open_csv_file(path, csv_file_name, csv_file);
}
for (index = 0; index < system_count; index++)
{
//cout << "test " << index << endl;
cout << "";
string system_name;
string designation;
string cp;
long double outer_limit;
long double inner_dust_limit;
int sys_no;
bool has_known_planets = false;
planet *seed_planets = NULL;
bool use_seed_system;
bool in_celestia;
init();
outer_limit = 0;
if (do_catalog || sys_no_arg)
{
if (sys_no_arg)
{
//sys_no = sys_no_arg - 1;
sys_no = sys_no_arg;
}
else
{
if (index >= catalog_count)
{
sys_no = ((index - 1) % (catalog_count - 1)) + 1;
}
else
{
sys_no = index;
}
}
//sys_no += 1;
sys_inc = cat_arg[sys_no].getInc();
sys_an = cat_arg[sys_no].getAn();
if (cat_arg[sys_no].getKnownPlanets() != NULL)
{
has_known_planets = true;
}
else
{
has_known_planets = false;
}
if ((use_known_planets || no_generate) && has_known_planets)
{
seed_planets = cat_arg[sys_no].getKnownPlanets();
use_seed_system = no_generate;
}
else
{
seed_planets = NULL;
use_seed_system = false;
}
in_celestia = cat_arg[sys_no].getInCelestia();
//cout << cat_arg[sys_no].getMass() << " " << cat_arg[sys_no].getLuminosity() << " " << cat_arg[sys_no].getEffTemp() << " " << cat_arg[sys_no].getSpecType() << endl;
the_sun.setMass(cat_arg[sys_no].getMass());
the_sun.setLuminosity(cat_arg[sys_no].getLuminosity());
the_sun.setEffTemp(cat_arg[sys_no].getEffTemp());
the_sun.setSpecType(cat_arg[sys_no].getSpecType());
if (cat_arg[sys_no].getIsCircumbinary())
{
the_sun.setIsCircumbinary(true);
the_sun.setSecondaryMass(cat_arg[sys_no].getMass2());
the_sun.setSecondaryLuminosity(cat_arg[sys_no].getLuminosity2());
the_sun.setSecondaryEffTemp(cat_arg[sys_no].getEffTemp2());
the_sun.setSecondarySpecType(cat_arg[sys_no].getSpecType2());
the_sun.setSeperation(cat_arg[sys_no].getDistance());
the_sun.setEccentricity(cat_arg[sys_no].getEccentricity());
}
else
{
the_sun.setIsCircumbinary(false);
}
if (do_catalog || sys_name_arg.empty())
{
system_name = cat_arg[sys_no].getName();
designation = cat_arg[sys_no].getDesig();
}
else
{
system_name = sys_name_arg;
designation = sys_name_arg;
}
ss.str("");
ss << designation << "-" << flag_seed;
file_name = ss.str();
if (cat_arg[sys_no].getMass2() == 0)
{
inner_dust_limit = cat_arg[sys_no].getDistance();
}
else
{
inner_dust_limit = 0;
}
if (cat_arg[sys_no].getMass2() > .001 && !cat_arg[sys_no].getIsCircumbinary())
{
long double m1 = the_sun.getMass();
long double m2 = cat_arg[sys_no].getMass2();
long double mu = m2 / (m1 + m2);
long double e = cat_arg[sys_no].getEccentricity();
long double a = cat_arg[sys_no].getDistance();
outer_limit = (0.464 + (-0.380 * mu) + (-0.631 * e) + (0.586 * mu * e) + (0.150 * pow2(e)) + (-0.198 * mu * pow2(e))) * a;
}
else
{
outer_limit = 0;
}
}
else if (reuse_solar_system)
{
/*system_name = "Earth-";
system_name.append(float_to_string(earth->getMass() * SUN_MASS_IN_EARTH_MASSES));*/
ss.str("");
ss << "Earth-" << (earth->getMass() * SUN_MASS_IN_EARTH_MASSES);
system_name = ss.str();
file_name = designation = system_name;
outer_limit = 0;
}
else
{
stringstream ss;
if (!sys_name_arg.empty())
{
system_name = sys_name_arg;
designation = sys_name_arg;
}
else
{
ss.str("");
ss << prognam << " " << flag_seed << "-" << the_sun.getMass();
system_name = ss.str();
designation = prognam;
}
ss.str("");
ss << designation << "-" << flag_seed << "-" << the_sun.getMass();
file_name = ss.str();
}
if (compainion_mass_arg > .001)
{
long double m1 = the_sun.getMass();
long double m2 = compainion_mass_arg;
long double mu = m2 / (m1 + m2);
long double e = compainion_eccentricity_arg;
long double a = compainion_distant_arg;
if (is_circumbinary)
{
the_sun.setIsCircumbinary(true);
the_sun.setSecondaryMass(m2);
the_sun.setSecondaryLuminosity(compainion_lum_arg);
the_sun.setSecondaryEffTemp(compainion_eff_arg);
the_sun.setSecondarySpecType(companion_spec_arg);
the_sun.setEccentricity(e);
the_sun.setSeperation(a);
outer_limit = 0;
}
else
{
outer_limit = (0.464 + (-0.380 * mu) + (-0.631 * e) + (0.586 * mu * e) + (0.150 * pow2(e)) + (-0.198 * mu * pow2(e))) * a;
}
}
the_sun.setName(system_name);
if (flag_verbose & 0x0400 && outer_limit > 0.0)
{
cerr << system_name << ", Outer Limit: " << toString(outer_limit) << endl;
}
if (system_count == 1 && filename_arg.size() > 0)
{
file_name = filename_arg;
}
file_name = replaceStrChar(file_name, ' ', '-');
file_name = replaceStrChar(file_name, '\'', '-');
earthlike = habitable = habitable_jovians = habitable_superterrans = potential_habitable = 0;
if (reuse_solar_system)
{
seed_planets = mercury;
use_seed_system = true;
}
else if (use_solar_system)
{
if (index == 0)
{
seed_planets = mercury;
use_seed_system = true;
}
else
{
use_seed_system = false;
if (!use_known_planets)
{
seed_planets = NULL;
}
if (has_known_planets && use_known_planets && no_generate)
{
use_seed_system = true;
}
}
}
for (int i = 0; i < 16; i++)
{
type_counts[i] = 0;
}
type_count = 0;
//cout << index << endl;
the_sun_clone = the_sun;
generate_stellar_system(the_sun, use_seed_system, seed_planets, flag_char, sys_no, system_name, inner_dust_limit, outer_limit, ecc_coef_arg, inner_planet_factor_arg, do_gases, do_moons);
planet *a_planet;
int counter;
int wt_type_count = type_count;
int norm_type_count = 0;
if (type_counts[0] > 0)
{
wt_type_count += 1; // Unknown
}
if (type_counts[1] > 0)
{
wt_type_count += 3; // Rock
}
if (type_counts[2] > 0)
{
wt_type_count += 16; // Venusian
}
if (type_counts[3] > 0)
{
wt_type_count += 20; // Terrestrial
}
if (type_counts[4] > 0)
{
wt_type_count += 12; // Gas Dwarf
}
if (type_counts[5] > 0)
{
wt_type_count += 11; // Neptunian
}
if (type_counts[6] > 0)
{
wt_type_count += 2; // Jovian
}
if (type_counts[7] > 0)
{
wt_type_count += 15; // Martian
}
if (type_counts[8] > 0)
{
wt_type_count += 18; // Water
}
if (type_counts[9] > 0)
{
wt_type_count += 14; // Ice
}
if (type_counts[10] > 0)
{
wt_type_count += 13; // Asteroids
}
if (type_counts[11] > 0)
{
wt_type_count += 10; // 1-Face
}
for (a_planet = innermost_planet, counter = 0; a_planet != NULL; a_planet = a_planet->next_planet, counter++);
norm_type_count = wt_type_count - (counter - type_count);
if (max_type_count < norm_type_count)
{
max_type_count = norm_type_count;
}
if (flag_verbose & 0x10000)
{
cerr << "System " << flag_seed << " - " << system_name << " (-s" << flag_seed << " -" << flag_char << sys_no << ") has " << type_count << " types out of " << counter << " planets. [" << norm_type_count << "]" << endl;
}
total_habitable += habitable;
total_potentially_habitable += potential_habitable;
total_earthlike += earthlike;
if ((!(only_habitable || only_multi_habitable || only_jovian_habitable || only_earthlike || only_three_habitable || only_superterrans || only_potential_habitable)) || (only_habitable && (habitable > 0) && !only_jovian_habitable) || (only_habitable && only_jovian_habitable && habitable > 0 && habitable_jovians > 0) || (only_multi_habitable && (habitable > 1) && !only_jovian_habitable) || (only_multi_habitable && only_jovian_habitable && habitable > 1 && habitable_jovians > 0) || (only_earthlike && (earthlike > 0) && !only_jovian_habitable) || (only_earthlike && only_jovian_habitable && earthlike > 0 && habitable_jovians > 0) || (only_jovian_habitable && (habitable_jovians > 0) && !(only_earthlike || only_multi_habitable || only_habitable || only_three_habitable)) || (only_three_habitable && only_jovian_habitable && habitable > 2 && habitable_jovians > 0) || (only_three_habitable && (habitable > 2)) || (only_superterrans && habitable_superterrans > 0) || (only_potential_habitable && potential_habitable > 0))
{
string system_url, svg_url;
ss.str("");
ss << url_path << subdir << file_name << ".html";
system_url = ss.str();
ss.str("");
ss << url_path << subdir << file_name << ".svg";
svg_url = ss.str();
switch (out_format)
{
case ffSVG:
create_svg_file(innermost_planet, path, file_name, ".svg", prognam, do_moons);
break;
case ffHTML:
//refresh_file_stream(thumbnails, path, thumbnail_file, ".html");
if (graphic_format == gfSVG)
{
create_svg_file(innermost_planet, path, file_name, ".svg", prognam, do_moons);
}
html_thumbnails(innermost_planet, thumbnails, system_name, url_path, system_url, svg_url, file_name, false, true, false, do_moons, graphic_format, do_gases);
open_html_file(system_name, flag_seed, path, url_path, file_name, ".html", prognam, html_file);
html_thumbnails(innermost_planet, html_file, system_name, url_path, system_url, svg_url, file_name, true, false, true, do_moons, graphic_format, do_gases);
html_describe_system(innermost_planet, do_gases, do_moons, url_path, html_file);
close_html_file(html_file);
break;
case ffTEXT:
text_describe_system(innermost_planet, do_gases, flag_seed, do_moons);
break;
case ffCSV:
case ffCSVdl:
csv_describe_system(csv_file, innermost_planet, do_gases, flag_seed, do_moons);
break;
case ffCELESTIA:
celestia_describe_system(innermost_planet, designation, system_name, flag_seed, sys_inc, sys_an, do_moons);
break;
/*case ffMOONGEN:
moongen_describe_system(innermost_planet, designation, system_name, flag_seed);
break;*/
}
if (habitable > 1 && flag_verbose & 0x0001)
{
cerr << "System " << flag_seed << " - " << system_name << " (-s" << flag_seed << " -" << flag_char << sys_no << ") has " << habitable << " planets with breathable atmospheres." << endl;
}
}
if (!(use_solar_system && index == 0))
{
flag_seed += seed_increment;
}
if (reuse_solar_system)
{
earth->setDustMass(earth->getDustMass() + EM(inc_mass));
}
if (!use_seed_system)
{
free_generations();
}
else
{
planet *ptr = NULL;
planet *node = NULL;
planet *next = NULL;
for (ptr = innermost_planet; ptr != NULL; ptr = ptr->next_planet)
{
ptr->setImf(0);
ptr->setRmf(0);
ptr->setCmf(0);
if (do_moons)
{
for (node = ptr->first_moon; node != NULL; node = next)
{
next = node->next_planet;
if (node->getDeletable())
{
delete node;
}
else
{
node->setMoonA(0);
node->setMoonE(0);
node->setImf(0);
node->setRmf(0);
node->setCmf(0);
node->next_planet = node->reconnect_to;
}
//cout << "Deleted World" << endl;
}
ptr->first_moon = ptr->first_moon_backup;
}
}
}
}
if (flag_verbose & 0x0001 || flag_verbose & 0x0002)
{
cerr << "Earthlike planets: " << total_earthlike << endl;
cerr << "Breathable atmospheres: " << total_habitable << endl;
cerr << "Breathable g range: " << toString(min_breathable_g) << " - " << toString(max_breathable_g) << endl;
cerr << "Terrestrial g range: " << toString(min_breathable_terrestrial_g) << " - " << toString(max_breathable_terrestrial_g) << endl;
cerr << "Breathable pressure range: " << toString(min_breathable_p) << " - " << toString(max_breathable_p) << endl;
cerr << "Breathable temp range: " << toString(min_breathable_temp - EARTH_AVERAGE_KELVIN) << " C - " << toString(max_breathable_temp - EARTH_AVERAGE_KELVIN) << " C" << endl;
cerr << "Breathable illumination range: " << toString(min_breathable_l) << " - " << toString(max_breathable_l) << endl;
cerr << "Terrestrial illumination range: " << toString(min_breathable_terrestrial_l) << " - " << toString(max_breathable_terrestrial_l) << endl;
cerr << "Max moon mass: " << toString(max_moon_mass * SUN_MASS_IN_EARTH_MASSES) << " Earth Masses" << endl;
}
if (system_count > 1)
{
if (out_format == ffHTML)
{
if (do_gases)
{
html_thumbnail_totals(thumbnails);
}
close_html_file(thumbnails);
}
}
return EXIT_SUCCESS;
}
void init()
{
if (!flag_seed)
{
time_t temp_time;
unsigned seed = (unsigned)(time(&temp_time));
srand(seed);
flag_seed = rand();
}
srand(flag_seed);
system_seed = flag_seed;
}
int system_counter = 0;
void generate_stellar_system(sun &the_sun, bool use_seed_system, planet *seed_system, string flag_char, int sys_no, string system_name, long double inner_dust_limit, long double outer_planet_limit, long double ecc_coef, long double inner_planet_factor, bool do_gases, bool do_moons)
{
do_gases = (flags_arg_clone & fDoGases) != 0;
do_moons = (flags_arg_clone & fDoMoons) != 0;
system_counter++;
long double outer_dust_limit;
if (!the_sun.getIsCircumbinary())
{
outer_dust_limit = stellar_dust_limit(the_sun.getMass());
}
else
{
outer_dust_limit = stellar_dust_limit(the_sun.getCombinedMass());
}
if (the_sun.getLuminosity() == 0)
{
the_sun.setLuminosity(mass_to_luminosity(the_sun.getMass()));
}
if (the_sun.getMass() == 0)
{
the_sun.setMass(luminosity_to_mass(the_sun.getLuminosity()));
}
if (the_sun.getMass() == 0)
{
//cout << system_name << " " << sys_no << endl;
}
if (the_sun.getEffTemp() == 0)
{
the_sun.setEffTemp(spec_type_to_eff_temp(the_sun.getSpecType()));
}
max_age = max_age_backup;
if (use_seed_system)
{
innermost_planet = seed_system;
long double max_age_of_star = the_sun.getLife();
if (max_age_of_star > 10E9)
{
max_age_of_star = 10E9;
}
if (max_age > max_age_of_star)
{
max_age = max_age_of_star;
}
if (min_age > max_age_of_star)
{
min_age = max_age_of_star;
}
//cout << min_age << " " << max_age << endl;
the_sun.setAge(random_number(min_age, max_age));
}
else
{
long double max_age_of_star = the_sun.getLife();
if (max_age_of_star > 10E9)
{
max_age_of_star = 10E9;
}
if (max_age > max_age_of_star)
{
max_age = max_age_of_star;
}
if (min_age > max_age_of_star)
{
min_age = max_age_of_star;
}
//cout << min_age << " " << max_age << endl;
innermost_planet = dist_planetary_masses(the_sun, inner_dust_limit, outer_dust_limit, outer_planet_limit, dust_density_coeff, ecc_coef, inner_planet_factor, seed_system, do_moons);
the_sun.setAge(random_number(min_age, max_age));
}
//cout << "test" << system_counter << endl;
generate_planets(the_sun, !use_seed_system, flag_char, sys_no, system_name, do_gases, do_moons);
}
void generate_planets(sun &the_sun, bool random_tilt, string flag_char, int sys_no, string system_name, bool do_gases, bool do_moons)
{
do_gases = (flags_arg_clone & fDoGases) != 0;
do_moons = (flags_arg_clone & fDoMoons) != 0;
planet *the_planet;
int planet_no = 0;
planet *moon;
int moons = 0;
for (the_planet = innermost_planet, planet_no = 1; the_planet != NULL; the_planet = the_planet->next_planet, planet_no++)
{
string planet_id;
stringstream ss;
ss.str("");
ss << system_name <<" (-s" << toString(flag_seed) << " -" << flag_char << toString(sys_no) << ") " << toString(planet_no);
planet_id = ss.str();
//cout << planet_id << endl;
if (!(the_planet->getKnownRadius() > 0))
{
the_planet->setImf(0);
the_planet->setRmf(0);
the_planet->setCmf(0);
}
if (!the_sun.getIsCircumbinary())
{
generate_planet(the_planet, planet_no, the_sun, random_tilt, planet_id, do_gases, do_moons, false, the_sun.getMass());
}
else
{
generate_planet(the_planet, planet_no, the_sun, random_tilt, planet_id, do_gases, do_moons, false, the_sun.getCombinedMass());
}
check_planet(the_planet, planet_id, false);
if (do_moons)
{
for (moon = the_planet->first_moon, moons = 1; moon != NULL; moon = moon->next_planet, moons++)
{
string moon_id;
ss.str("");
ss << planet_id << "-" << toString(moons);
moon_id = ss.str();
check_planet(moon, moon_id, true);
}
}
}
}
void generate_planet(planet* the_planet, int planet_no, sun& the_sun, bool random_tilt, string planet_id, bool do_gases, bool do_moons, bool is_moon, long double parent_mass)
{
do_gases = (flags_arg_clone & fDoGases) != 0;
do_moons = (flags_arg_clone & fDoMoons) != 0;
long double tmp;
long double ecc_coef = 0.077;
long double lambda;
long double the_fudged_radius = 0.0;
if (do_moons && !is_moon)
{
srandf(system_seed + (1000 * planet_no));
}
the_planet->setTheSun(the_sun);
the_planet->setOrbitZone(orb_zone(the_sun.getREcosphere(the_planet->getMass() * SUN_MASS_IN_EARTH_MASSES), the_planet->getA()));
the_planet->setHzd(calcHzd(the_planet));
assign_composition(the_planet, the_sun, is_moon);
if (!is_moon)
{
the_planet->setOrbPeriod(period(the_planet->getA(), the_planet->getMass(), parent_mass));
if (random_tilt || the_planet->getAxialTilt() == 0)
{
the_planet->setAxialTilt(inclination(the_planet->getA(), parent_mass));
}
}
else
{
the_planet->setOrbPeriod(period(the_planet->getMoonA(), the_planet->getMass(), parent_mass));
if (random_tilt || the_planet->getAxialTilt() == 0)
{
the_planet->setAxialTilt(inclination(the_planet->getMoonA(), parent_mass));
}
}
the_planet->setInclination(gaussian(1.0));
the_planet->setAscendingNode(random_number(0.0, 360.0));
the_planet->setLongitudeOfPericenter(random_number(0.0, 360.0));
the_planet->setMeanLongitude(random_number(0.0, 360.0));
the_planet->setExosphericTemp(EARTH_EXOSPHERE_TEMP / pow2(the_planet->getA() / the_sun.getREcosphere(the_planet->getMass() * SUN_MASS_IN_EARTH_MASSES)));
the_planet->setRmsVelocity(rms_vel(MOL_NITROGEN, the_planet->getExosphericTemp()));
the_planet->setCoreRadius(radius_improved(the_planet->getDustMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), false, the_planet->getOrbitZone(), the_planet));
the_planet->setDensity(empirical_density(the_planet->getMass(), the_planet->getA(), the_sun.getREcosphere(the_planet->getMass() * SUN_MASS_IN_EARTH_MASSES), true));
the_planet->setRadius(volume_radius(the_planet->getMass(), the_planet->getDensity()));
the_planet->setSurfAccel(acceleration(the_planet->getMass(), the_planet->getRadius()));
the_planet->setSurfGrav(gravity(the_planet->getSurfAccel()));
the_planet->setMolecWeight(min_molec_weight(the_planet));
bool force_gas_giant = false;
if ((the_planet->getGasMass() / the_planet->getMass()) > 0.05 && (the_planet->getMass() * SUN_MASS_IN_EARTH_MASSES) > 10.0)
{
force_gas_giant = true;
}
if (((the_planet->getMass() * SUN_MASS_IN_EARTH_MASSES) > 1.0 && (the_planet->getGasMass() / the_planet->getMass()) > 0.05 && min_molec_weight(the_planet) <= 4.0) || ((the_planet->getGasMass() / the_planet->getMass()) > 0.2 && the_planet->getA() < 0.8) || force_gas_giant) // it's a gas planet
{
if ((the_planet->getMass() * SUN_MASS_IN_EARTH_MASSES) <= 10.0)
{
the_planet->setType(tSubSubGasGiant); // it's a gas dwarf
}
else if ((the_planet->getMass() * SUN_MASS_IN_EARTH_MASSES) <= 50.0)
{
the_planet->setType(tSubGasGiant); // it's a neptunian