Repository navigation
Expand file tree
/
Copy pathTR_CE_Extended.py
More file actions
1958 lines (1314 loc) · 78 KB
/
Copy pathTR_CE_Extended.py
File metadata and controls
1958 lines (1314 loc) · 78 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
#
# Cepheus Engine Extended System Generation
#
# About:
#
# This script generates a CE extended system using Ade Stewart's extended system generation rules
#
#
# Author: Michael Bailey
# Date: 23 October 2020
#
# Usage
#
# No command line usage - this code is intended to be called by other Python scripts with user interfaces
#
import logging
# from ppretty import ppretty
import random
import sys
from tinydb import TinyDB, Query
import TR_CE_SRD_World
import TR_Constants
import TR_Support
# Constants
# # Subsector density
# EMPTY_SUBSECTOR = 12
# SCATTERED_DENSITY = 10
# DISPERSED_DENSITY = 9
# AVERAGE_DENSITY = 8
# CROWDED_SUBSECTOR = 6
# DENSE_SUBSECTOR = 5
# # Subsector Information
# SUBSECLETTERS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P']
# FIXEDHEADER = ''' 1-13: Name
# 15-18: HexNbr
# 20-28: UWP
# 31: Bases
# 33-47: Codes & Comments
# 49: Zone
# 52-54: PBG
# 56-57: Allegiance
# 59-74: Stellar Data
# ....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8'''
# Close Orbit Resonance Sequences
RES_SEQ = []
RES_SEQ.append([[1, 2], [1, 3], [2, 3], [2, 5], [3, 5], [4, 7], [5, 8], [6, 9], [7, 18], [8, 13]])
RES_SEQ.append([[1, 2, 5], [2, 3, 5], [3, 4, 6], [4, 7, 11], [6, 8, 14], [8, 15, 23], [9, 17, 26]])
RES_SEQ.append([[1, 2, 5, 7], [3, 4, 7, 11], [3, 5, 8, 13], [4, 6, 9, 14], [6, 9, 18, 24]])
RES_SEQ.append([[2, 3, 4, 7, 11], [3, 5, 9, 14, 23], [4, 6, 9, 12, 18]])
RES_SEQ.append([[2, 3, 5, 8, 12, 18], [3, 4, 7, 11, 18, 29], [4, 5, 9, 14, 25, 39]])
RES_SEQ.append([[2, 3, 4, 6, 9, 15, 24], [2, 4, 6, 10, 16, 26, 42]])
RES_SEQ.append([[2, 3, 5, 8, 13, 21, 34, 55]])
SEQ_LISTCOUNT = [10, 7, 5, 3, 3, 2, 1]
# Flags
f_debug = True
class System:
# Getters
@property
def starList(self):
return self.__starList
@property
def starDetails(self):
return self.__starDetails
@property
def orbitList(self):
return self.__orbitList
@property
def sysType(self):
return self.__sysType
@property
def p_sMin(self):
return self.__p_sMin
@property
def p_sMax(self):
return self.__p_sMax
@property
def s_sMin(self):
return self.__s_sMin
@property
def s_sMax(self):
return self.__s_sMax
@property
def barycentre(self):
return self.__barycentre
@property
def barycentre_ref(self):
return self.__barycentre_ref
@property
def mainWorld(self):
return self.__mainWorld
@property
def sysUWPString(self):
return self.__sysUWPString
# Setters
@starList.setter
def starList(self, starList):
self.__starList = starList
@starDetails.setter
def starDetails(self, starDetails):
self.__starDetails = starDetails
@orbitList.setter
def orbitList(self, orbitList):
self.__orbitList = orbitList
@sysType.setter
def sysType(self, sysType):
self.__sysType = sysType
@p_sMin.setter
def p_sMin(self, p_sMin):
self.__p_sMin = p_sMin
@p_sMax.setter
def p_sMax(self, p_sMax):
self.__p_sMax = p_sMax
@s_sMin.setter
def s_sMin(self, s_sMin):
self.__s_sMin = s_sMin
@s_sMax.setter
def s_sMax(self, s_sMax):
self.__s_sMax = s_sMax
@barycentre.setter
def barycentre(self, barycentre):
self.__barycentre = barycentre
@barycentre_ref.setter
def barycentre_ref(self, barycentre_ref):
self.__barycentre_ref = barycentre_ref
@mainWorld.setter
def mainWorld(self, mainWorld):
self.__mainWorld = mainWorld
@sysUWPString.setter
def sysUWPString(self, sysUWPString):
self.__sysUWPString = sysUWPString
# Methods
def gen_brownDwarfClass(self):
x = TR_Support.D6Roll()
if x in [1, 2, 3]: bdclass = 'L'
elif x in [4, 5]: bdclass = 'T'
else: bdclass = 'Y'
return bdclass
def gen_systemPresence(self, density):
presence = False
subSectorType = TR_Constants.DENSITY_LOOKUP[density]
if TR_Support.D100Roll() <= subSectorType: presence = True
return presence
def gen_systemObject(self, allowUnusual):
# Default to a star system
object = 'Star System'
# Use the unusual objects allowed table
if allowUnusual:
x = TR_Support.D6Rollx3()
if x in [3, 4, 5]: object = 'Rogue Planet' # * = Rogue Planet
elif x in [6, 7]: object = 'Brown Dwarf' # DB = Brown Dwarf
# elif x == 18:
elif x > 12:
y = TR_Support.D6Rollx2()
if y == 2: object = 'Black Hole' # BH = Black Hole
elif y == 3: object = 'Stellar Nursery' # SN = Stellar Nursery
elif y <= 9: object = 'Nebula' # NB = Nebula
elif y <= 11: object = 'Neutron Star' # NS = Neutron Star / Pulsar
else: object = 'Anomaly' # ? = Anomaly
else: object = 'Star System'
# Otherwise use the 'normal' table
else:
x = TR_Support.D6Rollx2()
if x in [2, 3]: object = 'Rogue Planet'
elif x in [4, 5]: object = 'Brown Dwarf'
else: object = 'Star System'
return object
def gen_stellarClass(self, realismType, seqno):
sClass = ''
# Realistic classification
if realismType == TR_Constants.SC_REAL:
# Make a roll, with the star sequence number as a negative DM
x = TR_Support.D6Rollx2() - seqno + 1
# Look up the stellar class
if x == 1:
sClass = self.gen_brownDwarfClass()
elif x in [2, 3, 4, 5, 6, 7, 8, 9]: sClass = 'M'
elif x in [10, 11]:
y = TR_Support.D6Roll() - seqno
if y <= 3: sClass = 'K'
elif y <= 5: sClass = 'G'
else: sClass = 'F'
else:
y = TR_Support.D6Rollx2() - seqno
if y <= 9: sClass = 'A'
elif y <= 11: sClass = 'B'
else: sClass = 'O'
# Semi-realistic - slightly more orange, yellow and white stars
if realismType == TR_Constants.SC_SEMIREAL:
x = TR_Support.D6Rollx2() - seqno + 1
# Look up the stellar class
if x == 1:
sClass = self.gen_brownDwarfClass()
elif x in [2, 3, 4, 5, 6, 7]: sClass = 'M'
elif x in [8, 9]: sClass = 'K'
elif x == 10: sClass = 'G'
elif x == 11: sClass = 'F'
else:
y = TR_Support.D6Rollx2() - seqno
if y <= 9: sClass = 'A'
elif y <= 11: sClass = 'B'
else: sClass = 'O'
# Fantastic: more sun-like stars
if realismType == TR_Constants.SC_FANTASTIC:
x = TR_Support.D6Rollx2() - seqno + 1
# Look up the stellar class
if x == 1:
sClass = self.gen_brownDwarfClass()
elif x in [2, 3, 4, 5, 6]: sClass = 'M'
elif x in [7, 8]: sClass = 'K'
elif x in [9, 10]: sClass = 'G'
elif x == 11: sClass = 'F'
else:
y = TR_Support.D6Rollx2() - seqno
if y <= 9: sClass = 'A'
elif y <= 11: sClass = 'B'
else: sClass = 'O'
# Assert block to trap problems where a class is not assigned
try:
assert sClass != ''
except AssertionError as AssertionError:
logging.exception(AssertionError)
return sClass
# Determine the spectral class decimal number
def gen_sClassDecimal(self):
x = TR_Support.D6Roll() - TR_Support.D6Roll() + 5
if x == 10: x = 0
return x
# Determine a star luminosity class
def gen_sLum(self, seqno):
lum = ''
x = TR_Support.D6Rollx2() - seqno + 1
if x in [2, 3]: lum = 'D'
elif x in [4, 5, 6, 7, 8, 9, 10]: lum = 'V'
elif x == 11: lum = 'III'
elif x == 12:
y = TR_Support.D6Rollx2()
if y == 2: lum = 'Ia'
elif y in [3, 4, 5]: lum = 'II'
elif y in [6, 7, 8]: lum = 'VI'
elif y in [9, 10, 11]: lum = 'IV'
else: lum = 'Ib'
else: lum = 'V'
# Assert block to catch any errors
try:
assert lum != ''
except AssertionError as AssertionError:
logging.exception(AssertionError)
return lum
def gen_numStars(self, spectralClass):
nStars = 1
a = TR_Support.D6Rollx2()
if spectralClass in ['A', 'B', 'O']:
if a in [2, 3]: nStars = 1
elif a in [4, 5, 6, 7, 8, 9]: nStars = 2
elif a == 10: nStars = 3
else: nStars = 4
elif spectralClass in ['K', 'G', 'F']:
if a in [2, 3, 4, 5, 6, 7]: nStars = 1
elif a in [8, 9, 0, 11]: nStars = 2
else: nStars = 3
elif spectralClass == 'M':
if a in [2, 3, 4, 5, 6, 7, 8]: nStars = 1
elif a in [9, 10, 11]: nStars = 2
else: nStars = 3
elif spectralClass in ['L', 'T', 'Y']:
if TR_Support.D6Rollx2() == 12: nStars = 2
else: nStars = 1
elif spectralClass == 'X':
if TR_Support.D6Rollx2() >= 11: nStars = 2
else: nStars = 1
return nStars
def fix_subDwarfs(self, aclass):
if aclass in ['O', 'B', 'K', 'F']: return 'V'
else: return 'VI'
def fix_subGiants(self, aclass, aclassdec):
if (aclass == 'K' and aclassdec in [2, 3, 4, 5, 6, 7, 8, 9]) or aclass == 'M':
x = TR_Support.D6Roll()
if x <= 5:
rclass = 'K'
rclassdec = 0
else:
rclass = 'K'
rclassdec = 1
else:
rclass = aclass
rclassdec = aclassdec
return rclass, rclassdec
def gen_Primary(self, realismtype):
# Determine the primary stellar class
sClass = self.gen_stellarClass(realismtype, 1)
# Determine the system nature
nStars = self.gen_numStars(sClass)
# Generate the spectral class decimal
sClassDec = self.gen_sClassDecimal()
# Generate the primary luminosity
if sClass not in ['L', 'Y', 'T']: sLum = self.gen_sLum(1)
else: sLum = 'BD'
# Apply restrictions - once companion code is in will need to iterate through all bodies
# Fix subgiants
if sLum == 'IV':
temp = self.fix_subGiants(sClass, sClassDec)
sClass = temp[0]
sClassDec = temp[1]
# Fix subdwarfs
if sLum == 'VI': sLum = self.fix_subDwarfs(sClass)
# Fix yellow supergiants
# Code will go in when rules are clarified
# Fix dwarfs
if sLum == 'D': sClass = ''
# Fix Type O giants
if sClass == 'O' and sLum in ['Ia', 'Ib', 'II'] and sClassDec <= 6: sLum = 'I'
# Format the star string
if sLum != 'D': starString = sClass + str(sClassDec) + ' ' + sLum
else: starString = sLum + str(sClassDec)
return starString, nStars, sClass + str(sClassDec), sLum
def gen_Companion(self, primary, seqno):
# Determine the companion stellar class
if primary in ['Star System', 'Black Hole']: sClass = self.gen_stellarClass(TR_Constants.SC_REAL, seqno)
elif primary == 'Brown Dwarf': sClass = self.gen_brownDwarfClass()
else:
starString = ''
return starString
# Generate the spectral class decimal
sClassDec = self.gen_sClassDecimal()
# Generate the companion luminosity
if sClass not in ['L', 'Y', 'T']: sLum = self.gen_sLum(seqno)
else: sLum = ''
# Apply restrictions
# Fix subgiants
if sLum == 'IV':
temp = self.fix_subGiants(sClass, sClassDec)
sClass = temp[0]
sClassDec = temp[1]
# Fix subdwarfs
if sLum == 'VI': sLum = self.fix_subDwarfs(sClass)
# Fix yellow supergiants
# Code will go in when rules are clarified
# Fix dwarfs
if sLum == 'D': sClass = ''
# Fix Type O giants
if sClass == 'O' and sLum in ['Ia', 'Ib', 'II'] and sClassDec <= 6: sLum = 'I'
# Format the star string
if sLum != 'D': starString = sClass + str(sClassDec) + ' ' + sLum
else: starString = sLum + str(sClassDec)
return starString, sClass + str(sClassDec), sLum
def gen_CompanionOrbit(self, primary, seqno, pd, proche):
# Get the companion orbit band
if primary != 'Black Hole': x = TR_Support.D6Rollx3()
else: x = TR_Support.D6Rollx2() + 6
if seqno == 3: x+= 4
elif seqno == 4: x+= 8
# Get companion zone and 'raw' orbit distance - this may be altered after return
if x in [3, 4]:
orbitzone = 'Contact'
orbitdistance = (TR_Support.D6Roll() - TR_Support.D6Roll() + 5) * pd/2
if orbitdistance < proche: orbitdistance = proche
elif x in [5, 6]:
orbitzone = 'Close'
orbitdistance = (TR_Support.D6Roll() - TR_Support.D6Roll() + 5) * 0.5
if orbitdistance < 0.5: orbitdistance = 0.5
elif x in [7, 8, 9]:
orbitzone = 'Near'
orbitdistance = (TR_Support.D6Roll() - TR_Support.D6Roll() + 5) * 5
if orbitdistance < 5: orbitdistance = 5
elif x in [10, 11, 12, 13, 14]:
orbitzone = 'Far'
orbitdistance = (TR_Support.D6Roll() - TR_Support.D6Roll() + 5) * 50
if orbitdistance < 50: orbitdistance = 50
elif x in [15, 16]:
orbitzone = 'Distant'
orbitdistance = (TR_Support.D6Roll() - TR_Support.D6Roll() + 5) * 500
if orbitdistance < 500: orbitdistance = 500
else:
orbitzone = 'Remote'
orbitdistance = (TR_Support.D6Roll() * 1000) + 4000
if orbitdistance < 5000: orbitdistance = 5000
orbitdistance = round(orbitdistance, 3)
return orbitzone, orbitdistance
def get_starDetails(self, thisclass, thislum):
db = TinyDB('db.json')
starTypeStr = ''
if thisclass[0] in ['L', 'T', 'Y']: starTypeStr = thisclass
if thislum != 'D': starTypeStr = thisclass + ' ' + str(thislum)
else: starTypeStr = str(thislum) + thisclass
try:
q = Query()
result = db.search(q.type == starTypeStr.rstrip())
return result[0]
except RuntimeError as e:
print(repr(e))
sys.exit()
def gen_BinaryArchitecture(self):
# First, lets find the barycentre between the two objects
Mb = self.starDetails[1]['mass']
Ma = self.starDetails[0]['mass']
AU = self.starDetails[1]['orbitdistance']
# print('Ma = ' + str(Ma))
# print('Mb = ' + str(Mb))
# print('AU = ' + str(AU))
if self.starDetails[1]['orbitzone'] in ['Contact Binary', 'Close', 'Near', 'Far']:
barycentre = AU * (Mb / (Ma + Mb))
else:
x = TR_Support.D6Roll()
if x >= 4:
barycentre = AU * (Mb / (Ma + Mb))
else: barycentre = 999999
# print('\tbarycentre = ' + str(barycentre))
# Calculate restrictions on S-Type orbits
# First, if the barycentre lies within 20% of the separation, the mainworld cannot have an S-Type orbit
if barycentre > self.starDetails[1]['orbitdistance'] * 0.8 and barycentre < self.starDetails[1]['orbitdistance'] * 1.2:
primaryStypes = False
self.starDetails[0]['sMin'] = 0
self.starDetails[0]['sMax'] = 0
self.starDetails[1]['sMin'] = self.starDetails[1]['roche limit']
self.starDetails[1]['sMax'] = self.starDetails[1]['orbitdistance'] * 0.2
else:
primaryStypes = True
self.starDetails[0]['sMin'] = self.starDetails[0]['roche limit']
self.starDetails[0]['sMax'] = self.starDetails[1]['orbitdistance'] * 0.2
self.starDetails[1]['sMin'] = self.starDetails[1]['roche limit']
self.starDetails[1]['sMax'] = self.starDetails[1]['orbitdistance'] * 0.2
if primaryStypes:
if self.starDetails[0]['sMin'] >= self.starDetails[0]['sMax']:
self.starDetails[0]['sMin'] = self.starDetails[0]['sMax'] = 0
if self.starDetails[1]['sMin'] >= self.starDetails[1]['sMax']:
self.starDetails[1]['sMin'] = self.starDetails[1]['sMax'] = 0
# If the maximum s_Type orbit is outside the star gravitational limit, reduce it to that limit
if self.starDetails[0]['sMax'] > self.starDetails[0]['Limit']: self.starDetails[0]['sMax'] = self.starDetails[0]['Limit']
if self.starDetails[1]['sMax'] > self.starDetails[1]['Limit']: self.starDetails[1]['sMax'] = self.starDetails[1]['Limit']
# Round all values to 3 decimals
self.starDetails[0]['sMin'] = round(self.starDetails[0]['sMin'], 3)
self.starDetails[0]['sMax'] = round(self.starDetails[0]['sMax'], 3)
self.starDetails[1]['sMin'] = round(self.starDetails[1]['sMin'], 3)
self.starDetails[1]['sMax'] = round(self.starDetails[1]['sMax'], 3)
# print('\tPrimary S-Type Orbit limits: ' + str(self.starDetails[0]['sMin']) + ' - ' + str(self.starDetails[0]['sMax']))
# print('\tSecondary S-Type Orbit limits: ' + str(self.starDetails[1]['sMin']) + ' - ' + str(self.starDetails[1]['sMax']))
# Save the barycentre in case we need it later, this can go in the system object
# and set the barycentre reference to the primary - this may be orverriden for trinary systems
# Calculate the limits for P-Type orbits. For accounting purposes these will be assigned to the primary, but they
# really orbit the primary-secondary barycentre
# First, determine if the minumum possible orbit is outside the primary-secondary outer limit
pmin = (self.starDetails[1]['orbitdistance'] * 2 ) + barycentre
pmax = self.starDetails[0]['Limit'] + self.starDetails[1]['Limit']
if pmin > pmax: primaryPtypes = False
else: primaryPtypes = True
if primaryPtypes:
# Minimum orbit is the twice the primary-secondary separation, measured from the barycentre
self.starDetails[0]['pMin'] = pmin
# Maximum orbit is the sum of the primary and secondary outer limits (for now, may change)
self.starDetails[0]['pMax'] = pmax
# Round it all to 3 decimal places
self.starDetails[0]['pMin'] = round(self.starDetails[0]['pMin'], 3)
self.starDetails[0]['pMax'] = round(self.starDetails[0]['pMax'], 3)
# print('\tPrimary - Secondary P-Type limits: ' + str(self.starDetails[0]['pMin']) + ' - ' + str(self.starDetails[0]['pMax']))
# Finally, add the stable T-Type orbits at the primary-secondary L4 and L5 locations
self.starDetails[0]['tL4'] = self.starDetails[0]['tL5'] = self.starDetails[1]['orbitdistance']
self.barycentre = barycentre
self.barycentre_ref = 0
def gen_TrinaryArchitecture(self, usecase):
# barycentre calculations are going to run into the 3 body problem, so our options are:
#
# 1: The tertiary orbits far enough from the primary-secondary pair to be in a P-Type orbit
# Tertiary must be 2 x primary - secondary distance, measured from the primary-secondary barycentre
if usecase == 'both':
# print('\tTertiary orbits primary/secondary pair. Checking tertiary orbit...')
# Determine the barycentre reference
if self.starDetails[0]['mass'] + self.starDetails[1]['mass'] >= self.starDetails[2]['mass']: self.barycentre_ref = 0
else: self.barycentre_ref = 2
# Don't need to adjust orbit now - sufficient distance from the barycentre is a precondition of this block
self.starDetails[2]['orbitdistance'] += self.barycentre
self.starDetails[2]['orbitdistance'] = round(self.starDetails[2]['orbitdistance'], 3)
# Set the maximum S-Type orbit to 20% of the distance to the secondary orbit
self.starDetails[2]['sMin'] = self.starDetails[2]['roche limit']
self.starDetails[2]['sMax'] = (self.starDetails[2]['orbitdistance'] - self.starDetails[1]['orbitdistance']) * 0.2
if self.starDetails[2]['sMax'] > self.starDetails[2]['Limit']: self.starDetails[2]['sMax'] = self.starDetails[2]['Limit']
if self.starDetails[2]['sMin'] > self.starDetails[2]['sMax']: self.starDetails[2]['sMin'] = self.starDetails[2]['sMax'] = 0
# print('\tTertiary S-Type Orbit limits: ' + str(self.starDetails[2]['sMin']) + ' - ' + str(self.starDetails[2]['sMax']))
# Calculate the limits for P-Type orbits. For accounting purposes these will be assigned to the primary, but they
# really orbit the primary-secondary-tertiary barycentre
# First, determine if the minumum possible orbit is outside the primary-secondary-tertiary outer limit
pmin = (self.starDetails[2]['orbitdistance'] * 2 ) + self.barycentre
pmax = self.starDetails[0]['Limit'] + self.starDetails[1]['Limit'] + self.starDetails[2]['Limit']
# Limit the max P-Type orbit to 20% of the distance to the tertiary
if pmax > (self.starDetails[2]['orbitdistance'] - self.barycentre) * 0.2: pmax = (self.starDetails[2]['orbitdistance'] - self.barycentre) * 0.2
if pmin > pmax: primaryPtypes = False
else: primaryPtypes = True
if primaryPtypes:
# Minimum orbit is the twice the primary-secondary separation, measured from the barycentre
self.starDetails[0]['pMin'] = pmin
# Maximum orbit is the sum of the primary and secondary outer limits (for now, may change)
self.starDetails[0]['pMax'] = pmax
# Round it all to 3 decimal places
self.starDetails[0]['pMin'] = round(self.starDetails[0]['pMin'], 3)
self.starDetails[0]['pMax'] = round(self.starDetails[0]['pMax'], 3)
# print('\tPrimary - Secondary P-Type limits: ' + str(self.starDetails[0]['pMin']) + ' - ' + str(self.starDetails[0]['pMax']))
# 2: if the tertiary is within the minimum distance to orbit the pair, it can:
# a - orbit the primary
# b - orbit the companion
# Finally, add the T-Type orbits at the primary-tertiary L4 and L5 Lagrange points
self.starDetails[0]['tL4b'] = self.starDetails[0]['tL5b'] = self.starDetails[2]['orbitdistance']
elif usecase in ['primary']:
# print('\tTertiary orbits primary. Checking orbits')
# First make sure that the tertiary orbits in an allowed orbit around the primary
# Recalculate if necessary (using a random distance between the primary min and max S-Type orbits)
is_between = self.starDetails[0]['sMin'] <= self.starDetails[2]['orbitdistance'] <=self.starDetails[0]['sMax']
# Also check that the orbit does npto clash with the secondary
is_secondary_blocked = self.starDetails[1]['sMin'] <= self.starDetails[2]['orbitdistance'] <= self.starDetails[1]['sMax']
while not is_between and not is_secondary_blocked:
self.starDetails[2]['orbitdistance'] = random.randint(round(self.starDetails[0]['sMin']), round(self.starDetails[0]['sMax']))
# Recalculate the orbit zone as well
if self.starDetails[2]['orbitdistance'] < 0.5: self.starDetails[2]['orbitzone'] = 'Contact Binary'
elif self.starDetails[2]['orbitdistance'] < 5: self.starDetails[2]['orbitzone'] = 'Close'
elif self.starDetails[2]['orbitdistance'] < 50: self.starDetails[2]['orbitzone'] = 'Near'
elif self.starDetails[2]['orbitdistance'] < 500: self.starDetails[2]['orbitzone'] = 'Far'
elif self.starDetails[2]['orbitdistance'] < 5000: self.starDetails[2]['orbitzone'] = 'Distant'
else: self.starDetails[2]['orbitdistance'] = 'Remote'
# print('Moved tertiary orbit to ' + str(self.starDetails[2]['orbitdistance']) + ' AU (' + self.starDetails[2]['orbitzone'] + ')')
# Calculate the limits for P-Type orbits. For accounting purposes these will be assigned to the primary, but they
# really orbit the primary-secondary-tertiary barycentre
# First, determine if the minumum possible orbit is outside the primary-secondary-tertiary outer limit
pmin = (self.starDetails[2]['orbitdistance'] * 2 ) + self.barycentre
pmax = self.starDetails[0]['Limit'] + self.starDetails[1]['Limit'] + self.starDetails[2]['Limit']
if pmin > pmax: primaryPtypes = False
else: primaryPtypes = True
if primaryPtypes:
# Minimum orbit is the twice the primary-secondary separation, measured from the barycentre
self.starDetails[0]['pMin'] = pmin
# Maximum orbit is the sum of the primary and secondary outer limits (for now, may change)
self.starDetails[0]['pMax'] = pmax
# Round it all to 3 decimal places
self.starDetails[0]['pMin'] = round(self.starDetails[0]['pMin'], 3)
self.starDetails[0]['pMax'] = round(self.starDetails[0]['pMax'], 3)
# print('\tPrimary - Secondary - Tertiary P-Type limits: ' + str(self.starDetails[0]['pMin']) + ' - ' + str(self.starDetails[0]['pMax']))
# Recheck if blocked
is_secondary_blocked = self.starDetails[1]['sMin'] <= self.starDetails[2]['orbitdistance'] <= self.starDetails[1]['sMax']
# Finally, add the T-Type orbits at the primary-tertiary L4 and L5 Lagrange points
self.starDetails[0]['tL4c'] = self.starDetails[0]['tL5c'] = self.starDetails[2]['orbitdistance']
elif usecase in ['secondary']:
# print('\tTertiary orbits secondary. Checking orbits')
# First make sure that the tertiary orbits in an allowed orbit around the secondary
# Recalculate if necessary (using a random distance between the primary min and max S-Type orbits)
is_between = self.starDetails[1]['sMin'] <= self.starDetails[2]['orbitdistance'] <=self.starDetails[1]['sMax']
if not is_between:
self.starDetails[2]['orbitdistance'] = random.randint(round(self.starDetails[1]['sMin']), round(self.starDetails[1]['sMax']))
# Recalculate the orbit zone as well
if self.starDetails[2]['orbitdistance'] < 0.5: self.starDetails[2]['orbitzone'] = 'Contact Binary'
elif self.starDetails[2]['orbitdistance'] < 5: self.starDetails[2]['orbitzone'] = 'Close'
elif self.starDetails[2]['orbitdistance'] < 50: self.starDetails[2]['orbitzone'] = 'Near'
elif self.starDetails[2]['orbitdistance'] < 500: self.starDetails[2]['orbitzone'] = 'Far'
elif self.starDetails[2]['orbitdistance'] < 5000: self.starDetails[2]['orbitzone'] = 'Distant'
else: self.starDetails[2]['orbitdistance'] = 'Remote'
# print('Moved tertiary orbit to ' + str(self.starDetails[2]['orbitdistance'] + ' AU (' + self.starDetails[2]['orbitzone'] + ')'))
# Calculate the limits for P-Type orbits. For accounting purposes these will be assigned to the primary, but they
# really orbit the primary-secondary-tertiary barycentre
# First, determine if the minumum possible orbit is outside the primary-secondary-tertiary outer limit
pmin = (self.starDetails[2]['orbitdistance'] * 2 ) + self.barycentre
pmax = self.starDetails[0]['Limit'] + self.starDetails[1]['Limit'] + self.starDetails[2]['Limit']
if pmin > pmax: secondaryPtypes = False
else: secondaryPtypes = True
if secondaryPtypes:
# Minimum orbit is the twice the secondary-tertiary separation, measured from the barycentre
self.starDetails[1]['pMin'] = pmin
# Maximum orbit is the sum of the secondary and tertiary outer limits (for now, may change)
self.starDetails[1]['pMax'] = pmax
# Round it all to 3 decimal places
self.starDetails[1]['pMin'] = round(self.starDetails[1]['pMin'], 3)
self.starDetails[1]['pMax'] = round(self.starDetails[1]['pMax'], 3)
# print('\tPrimary - Secondary - Tertiary P-Type limits: ' + str(self.starDetails[0]['pMin']) + ' - ' + str(self.starDetails[0]['pMax']))
# Check that the maximum P-Type is inside 20% of the primary-secondary distance and correct if needed
if self.starDetails[1]['pMax'] > self.starDetails[1]['orbitdistance']: self.starDetails[1]['pMax'] = self.starDetails[1]['orbitdistance']
# Finally, add the T-Type orbits at the primary-tertiary L4 and L5 Lagrange points
self.starDetails[0]['tL4d'] = self.starDetails[0]['tL5d'] = self.starDetails[2]['orbitdistance']
# 3: if the tertiary is outside the outer limit for both the primary and secondary then it is unbound
elif usecase == 'unbound':
# Stuff needs to go in here
pass
# Now calculate the primary-tertiary barycentre and recalculate the primaries allowed S-Type orbits
Mb = self.starDetails[2]['mass']
Ma = self.starDetails[0]['mass']
AU = self.starDetails[2]['orbitdistance']
self.barycentre = AU * (Mb / (Ma + Mb))
# print('\tPrimary - tertiary barycentre at ' + str(round(barycentre)) + ' AU')
if self.starDetails[0]['sMax'] > self.starDetails[2]['orbitdistance'] * 0.2:
self.starDetails[0]['sMax'] = self.starDetails[2]['orbitdistance'] * 0.2
if self.starDetails[0]['sMin'] > self.starDetails[0]['sMax']: self.starDetails[0]['sMin'] = self.starDetails[0]['sMax'] = 0
# print('\tPrimary S-Type Orbit limits now ' + str(self.starDetails[0]['sMin'] + ' - ' + str(self.starDetails[0]['sMax'])))
# Calculate the tertiary S-Type orbit limits
self.starDetails[2]['sMin'] = self.starDetails[2]['roche limit']
self.starDetails[2]['sMax'] = self.starDetails[2]['orbitdistance'] * 0.2
if self.starDetails[2]['sMax'] > self.starDetails[2]['Limit']: self.starDetails[2]['sMax'] = self.starDetails[2]['Limit']
if self.starDetails[2]['sMin'] > self.starDetails[2]['sMax']: self.starDetails[2]['sMin'] = self.starDetails[2]['sMax']
# Write out the system contents
def print_System(self):
# print('System Type:\t\t' + self.sysType)
if f_debug: print(f'{"DEBUG: System Type:":<22}{self.sysType}')
if self.sysType in ['Star System']:
if f_debug: print('DEBUG: Mainworld (orbit TBA): ' + self.mainWorld.UWPString)
if self.sysType in ['Star System', 'Brown Dwarf']:
if f_debug: print(f'{"DEBUG: System Primary:":<22}{self.starDetails[0]["type"]}')
if f_debug and 'sMin' in self.starDetails[0]: print('\tS-Orbit inner limit = ' + str(self.starDetails[0]['sMin']))
if f_debug and 'sMax' in self.starDetails[0]: print('\tS-Orbit outer limit = ' + str(self.starDetails[0]['sMax']))
if f_debug and 'pMin' in self.starDetails[0]: print('\tP-Orbit inner limit = ' + str(self.starDetails[0]['pMin']))
if f_debug and 'pMax' in self.starDetails[0]: print('\tP-Orbit outer limit = ' + str(self.starDetails[0]['pMax']))
if f_debug and 'tL4' in self.starDetails[0]: print('\tT-Orbits at L4/L5 points = ' + str(self.starDetails[0]['tL4']))
if f_debug and 'tL4b' in self.starDetails[0]: print('\tT-Orbits at L4/L5 points = ' + str(self.starDetails[0]['tL4b']))
if f_debug and 'tL4c' in self.starDetails[0]: print('\tT-Orbits at L4/L5 points = ' + str(self.starDetails[0]['tL4c']))
if f_debug and 'tL4d' in self.starDetails[0]: print('\tT-Orbits at L4/L5 points = ' + str(self.starDetails[0]['tL4d']))
if len(self.starDetails) >= 2:
if f_debug and 'sMin' in self.starDetails[1]: print('\tS-Orbit inner limit = ' + str(self.starDetails[1]['sMin']))
if f_debug and 'sMax' in self.starDetails[1]: print('\tS-Orbit outer limit = ' + str(self.starDetails[1]['sMax']))
if f_debug and 'pMin' in self.starDetails[1]: print('\tP-Orbit inner limit = ' + str(self.starDetails[1]['pMin']))
if f_debug and 'pMax' in self.starDetails[1]: print('\tP-Orbit outer limit = ' + str(self.starDetails[1]['pMax']))
if len(self.starDetails) > 2:
if f_debug and 'sMin' in self.starDetails[2]: print('\tS-Orbit inner limit = ' + str(self.starDetails[2]['sMin']))
if f_debug and 'sMax' in self.starDetails[2]: print('\tS-Orbit outer limit = ' + str(self.starDetails[2]['sMax']))
if f_debug and 'pMin' in self.starDetails[2]: print('\tP-Orbit inner limit = ' + str(self.starDetails[2]['pMin']))
if f_debug and 'pMax' in self.starDetails[2]: print('\tP-Orbit outer limit = ' + str(self.starDetails[2]['pMax']))
# Some temporary code to dump out system contents
# Note - sort the contents by distance soon
print('System Contents:')
i = 0
for sd in self.starDetails:
if i == 0: print(f'{"System Primary:":<22}{self.starDetails[i]["type"]}')
elif i == 1:
print(f'{"System Companion:":<22}{self.starDetails[i]["type"]}')
print('\tDistance from Primary:\t' + str(self.starDetails[i]['orbitdistance']) + ' (' + self.starDetails[i]['orbitzone'] + ')')
elif i == 2:
print('Tertiary: ' + sd['type'])
print(f'{"System Companion:":<22}{self.starDetails[i]["type"]}')
if self.starDetails[i]['orbitsubject'] == 'primary': print('\tDistance from primary:\t' + str(self.starDetails[i]['orbitdistance']) + ' (' + self.starDetails[i]['orbitzone'] + ')')
elif self.starDetails[i]['orbitsubject'] == 'secondary': print('\tDistance from secondary\t' + str(self.starDetails[i]['orbitdistance']) + ' (' + self.starDetails[i]['orbitzone'] + ')')
elif self.starDetails[i]['orbitsubject'] == 'both': print('\tDistance from barycentre:\t' + str(self.starDetails[i]['orbitdistance']) + ' (' + self.starDetails[i]['orbitzone'] + ')')
elif self.starDetails[i]['orbitsubject'] == 'unbound': print('\tDistance from primary (unbound):\t' + str(self.starDetails[i]['orbitdistance']) + ' (' + self.starDetails[i]['orbitzone'] + ')')
# if f_debug: print('DEBUG: body ' + str(i+1) + ':')
for contents in sd['Contents']:
print('\t' + contents['Type'], end = '')
if 'Orbital Distance' in contents: print('\t' + contents['Zone'] + ' (' + str(contents['Orbital Distance']) + ' AU)')
else: print()
i += 1
# print('##########')
print()
# Format the system extended UWP string
def formatUWPString_text_SEC(self):
# Format a UWP text string for the mainworld
self.mainWorld.formatUWPString_text_SEC()
# Now add a Non-Aligned (default) allegiance code
# and the star details to the mainworld UWP string
self.mainWorld.UWPString += " Na"
for star in self.starList:
self.mainWorld.UWPString += " " + star
pass
# Generate the pool of available worlds
def gen_worldPool(self):
# Check for gas giants
# If the frost line for a star is recorded as -1, then the frost line is outside the stars gravitational limit
# Initialise some local variables to ensure that they are bound
nPB = 0
nGG = 0
nRW = 0
i = 0
hasGG = False
GGOrbitsPresent = False
if self.sysType in ['Star System', 'Brown Dwarf']:
hasGG = True
i += 1
# Systems that aren't normally capable of having a gas giant may have a captured one
if not hasGG:
if TR_Support.D6Rollx2() >= 11: nGG = 1
else:
# Brown dwarfs rarely contain gas giants
if self.sysType == 'Brown Dwarf':
if self.starDetails[0]['type'][0] == 'L':
if TR_Support.D6Rollx2() >= 9:
nGG = TR_Support.D6Roll() - 4
if nGG < 1: nGG = 1
elif self.starDetails[0]['type'][0] == 'T':
if TR_Support.D6Rollx2() >= 11:
nGG = 1
else: nGG = 0
# Now determne the number of gas giansts
else:
if TR_Support.D6Rollx2() >= 5:
nGG = TR_Support.D6Roll() - 2
if nGG < 1: nGG = 1
# Determine each gas giant type
gasGiants = []
if nGG > 0:
j = 1
while j <= nGG:
if TR_Support.D6Roll() < 4: gasGiants.append('LGG')
else: gasGiants.append('SGG')
j += 1
if f_debug: print('DEBUG: Gas Giants: ' + str(nGG) + ' ', end = '')