-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbackend.py
1292 lines (916 loc) · 59.7 KB
/
backend.py
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
from math import sqrt, degrees, radians, cos, acos, sin, asin, tan ,atan2, copysign, pi
import pyperclip
import time
import datetime
import tkinter as tk
import tkinter.ttk as ttk
import json
import os
import csv
import sys
import requests
import webbrowser
import argparse
os.system("")
with open("settings.json", "r") as f:
settings = json.load(f)
if settings["update_checker"] == True:
Local_version = "2.1.1"
release_request_url = "https://api.github.com/repos/Valalol/Star-Citizen-Navigation/releases"
r = requests.get(release_request_url)
content = r.json()
Status_code = r.status_code
Github_version = content[0]['tag_name']
Download_URL = content[0]['html_url']
Release_content = content[0]['name']
if Status_code == 200 :
if Github_version.replace(".", "") > Local_version.replace(".", ""):
print("New version available")
sys.stdout.flush()
def Go_to_release_func():
webbrowser.open(Download_URL)
root.destroy()
raise SystemExit("Opened the new release page in your browser")
def Next_time_func():
root.destroy()
root = tk.Tk()
root.title("Update Checker")
MainWindow = tk.Frame(root)
MainWindow.configure(borderwidth='0', height='200', relief='flat', width='200')
MainWindow.pack(expand='true', fill='both', side='left')
Update_Text = tk.Label(MainWindow, text=f"A new release is available !\n\nNew content :\n{Release_content}\n\nWould you like to go to the release page ?")
Update_Text.grid(row='0', column='0', padx='40', pady='3')
Button_Frame = tk.Frame(MainWindow)
Button_Frame.configure(borderwidth='0', height='200', relief='flat', width='200')
Button_Frame.grid(row='1', column='0', pady='6')
Go_to_release_Button = tk.Button(Button_Frame, text="Go to release", command=Go_to_release_func)
Next_time_Button = tk.Button(Button_Frame, text="Next time", command=Next_time_func)
Go_to_release_Button.grid(row='0', column='0', padx='10', pady='2')
Next_time_Button.grid(row='0', column='1', padx='10', pady='2')
root.mainloop()
with open('Database.json') as f:
Database = json.load(f)
Container_list = []
for i in Database["Containers"]:
Container_list.append(Database["Containers"][i]["Name"])
Space_POI_list = []
for poi in Database["Space_POI"]:
Space_POI_list.append(poi)
Planetary_POI_list = {}
for container_name in Database["Containers"]:
Planetary_POI_list[container_name] = []
for poi in Database["Containers"][container_name]["POI"]:
Planetary_POI_list[container_name].append(poi)
parser = argparse.ArgumentParser()
parser.add_argument("mode", choices=["planetary_nav", "space_nav", "companion"])
parser.add_argument("--container", type=str)
parser.add_argument("--known", type=str)
parser.add_argument("--target", type=str)
parser.add_argument("--entry_type", type=str, choices=["xyz", "oms", "longlatheight"])
parser.add_argument("--x", type=float)
parser.add_argument("--y", type=float)
parser.add_argument("--z", type=float)
parser.add_argument("--OM1_name", type=str)
parser.add_argument("--OM1_value", type=float)
parser.add_argument("--OM2_name", type=str)
parser.add_argument("--OM2_value", type=float)
parser.add_argument("--OM3_name", type=str)
parser.add_argument("--OM3_value", type=float)
parser.add_argument("--height", type=float)
parser.add_argument("--lat", type=float)
parser.add_argument("--long", type=float)
args = parser.parse_args()
# print(args)
Mode = args.mode
if Mode == "planetary_nav":
arg_container = args.container
arg_known = args.known
if arg_known == "true":
arg_target = args.target
Target = Database["Containers"][arg_container]["POI"][arg_target]
else :
arg_entry_type = args.entry_type
if arg_entry_type == "xyz":
arg_x = args.x
arg_y = args.y
arg_z = args.z
Target = {
'Name': 'Custom POI',
'Container': arg_container,
'X': arg_x,
'Y': arg_y,
'Z': arg_z,
"QTMarker": "FALSE"
}
elif arg_entry_type == "oms":
arg_OM1_name = args.OM1_name
arg_OM1_value = args.OM1_value
arg_OM2_name = args.OM2_name
arg_OM2_value = args.OM2_value
arg_OM3_name = args.OM3_name
arg_OM3_value = args.OM3_value
#
# add some things here
#
else:
arg_lat = args.lat
arg_long = args.long
arg_height = args.height
#
# add some things here
#
elif Mode == "space_nav":
arg_known = args.known
if arg_known == "true":
arg_target = args.target
Target = Database["Space_POI"][arg_target]
else:
arg_x = args.x
arg_y = args.y
arg_z = args.z
Target = {
'Name': 'Custom POI',
'X': arg_x,
'Y': arg_y,
'Z': arg_z,
"QTMarker": "FALSE"
}
elif Mode == "companion":
pass
else:
raise SystemExit("Program mode not selected")
logs_enabled = settings["logs_enabled"]
print("Python script ready to start !")
print("Mode: " + Mode)
try :
import ntplib
c = ntplib.NTPClient()
response = c.request('europe.pool.ntp.org', version=3)
server_time = response.tx_time
time_offset = response.offset
except:
print("Error: Could not get time from NTP server")
sys.stdout.flush()
time_offset = 0
print('Time_offset:', time_offset)
sys.stdout.flush()
def vector_norm(a):
"""Returns the norm of a vector"""
return sqrt(a["X"]**2 + a["Y"]**2 + a["Z"]**2)
def vector_product(a, b):
"""Returns the dot product of two vectors"""
return a["X"]*b["X"] + a["Y"]*b["Y"] + a["Z"]*b["Z"]
def angle_between_vectors(a, b):
"""Function that returns an angle in degrees between 2 vectors"""
try :
angle = degrees(acos(vector_product(a, b) / (vector_norm(a) * vector_norm(b))))
except ZeroDivisionError:
angle = 0.0
return angle
def rotate_point_2D(Unrotated_coordinates, angle):
Rotated_coordinates = {}
Rotated_coordinates["X"] = Unrotated_coordinates["X"] * cos(angle) - Unrotated_coordinates["Y"]*sin(angle)
Rotated_coordinates["Y"] = Unrotated_coordinates["X"] * sin(angle) + Unrotated_coordinates["Y"]*cos(angle)
Rotated_coordinates["Z"] = Unrotated_coordinates["Z"]
return (Rotated_coordinates)
def get_current_container(X : float, Y : float, Z : float):
Actual_Container = {
"Name": "None",
"X": 0,
"Y": 0,
"Z": 0,
"Rotation Speed": 0,
"Rotation Adjust": 0,
"OM Radius": 0,
"Body Radius": 0,
"POI": {}
}
for i in Database["Containers"] :
Container_vector = {"X" : Database["Containers"][i]["X"] - X, "Y" : Database["Containers"][i]["Y"] - Y, "Z" : Database["Containers"][i]["Z"] - Z}
if vector_norm(Container_vector) <= 3 * Database["Containers"][i]["OM Radius"]:
Actual_Container = Database["Containers"][i]
return Actual_Container
def get_local_rotated_coordinates(Time_passed : float, X : float, Y : float, Z : float, Actual_Container : dict):
try:
Rotation_speed_in_degrees_per_second = 0.1 * (1/Actual_Container["Rotation Speed"])
except ZeroDivisionError:
Rotation_speed_in_degrees_per_second = 0
Rotation_state_in_degrees = ((Rotation_speed_in_degrees_per_second * Time_passed) + Actual_Container["Rotation Adjust"]) % 360
local_unrotated_coordinates = {
"X": X - Actual_Container["X"],
"Y": Y - Actual_Container["Y"],
"Z": Z - Actual_Container["Z"]
}
local_rotated_coordinates = rotate_point_2D(local_unrotated_coordinates, radians(-1*Rotation_state_in_degrees))
return local_rotated_coordinates
def get_lat_long_height(X : float, Y : float, Z : float, Container : dict):
Radius = Container["Body Radius"]
Radial_Distance = sqrt(X**2 + Y**2 + Z**2)
Height = Radial_Distance - Radius
#Latitude
try :
Latitude = degrees(asin(Z/Radial_Distance))
except :
Latitude = 0
try :
Longitude = -1*degrees(atan2(X, Y))
except :
Longitude = 0
return [Latitude, Longitude, Height]
def get_closest_POI(X : float, Y : float, Z : float, Container : dict, Quantum_marker : bool = False):
Distances_to_POIs = []
for POI in Container["POI"]:
Vector_POI = {
"X": abs(X - Container["POI"][POI]["X"]),
"Y": abs(Y - Container["POI"][POI]["Y"]),
"Z": abs(Z - Container["POI"][POI]["Z"])
}
Distance_POI = vector_norm(Vector_POI)
if Quantum_marker and Container["POI"][POI]["QTMarker"] == "TRUE" or not Quantum_marker:
Distances_to_POIs.append({"Name" : POI, "Distance" : Distance_POI})
Target_to_POIs_Distances_Sorted = sorted(Distances_to_POIs, key=lambda k: k['Distance'])
return Target_to_POIs_Distances_Sorted
def get_closest_oms(X : float, Y : float, Z : float, Container : dict):
Closest_OM = {}
if X >= 0:
Closest_OM["X"] = {"OM" : Container["POI"]["OM-5"], "Distance" : vector_norm({"X" : X - Container["POI"]["OM-5"]["X"], "Y" : Y - Container["POI"]["OM-5"]["Y"], "Z" : Z - Container["POI"]["OM-5"]["Z"]})}
else:
Closest_OM["X"] = {"OM" : Container["POI"]["OM-6"], "Distance" : vector_norm({"X" : X - Container["POI"]["OM-6"]["X"], "Y" : Y - Container["POI"]["OM-6"]["Y"], "Z" : Z - Container["POI"]["OM-6"]["Z"]})}
if Y >= 0:
Closest_OM["Y"] = {"OM" : Container["POI"]["OM-3"], "Distance" : vector_norm({"X" : X - Container["POI"]["OM-3"]["X"], "Y" : Y - Container["POI"]["OM-3"]["Y"], "Z" : Z - Container["POI"]["OM-3"]["Z"]})}
else:
Closest_OM["Y"] = {"OM" : Container["POI"]["OM-4"], "Distance" : vector_norm({"X" : X - Container["POI"]["OM-4"]["X"], "Y" : Y - Container["POI"]["OM-4"]["Y"], "Z" : Z - Container["POI"]["OM-4"]["Z"]})}
if Z >= 0:
Closest_OM["Z"] = {"OM" : Container["POI"]["OM-1"], "Distance" : vector_norm({"X" : X - Container["POI"]["OM-1"]["X"], "Y" : Y - Container["POI"]["OM-1"]["Y"], "Z" : Z - Container["POI"]["OM-1"]["Z"]})}
else:
Closest_OM["Z"] = {"OM" : Container["POI"]["OM-2"], "Distance" : vector_norm({"X" : X - Container["POI"]["OM-2"]["X"], "Y" : Y - Container["POI"]["OM-2"]["Y"], "Z" : Z - Container["POI"]["OM-2"]["Z"]})}
return Closest_OM
def get_sunset_sunrise_predictions(X : float, Y : float, Z : float, Latitude : float, Longitude : float, Height : float, Container : dict, Star : dict):
try :
# Stanton X Y Z coordinates in refrence of the center of the system
sx, sy, sz = Star["X"], Star["Y"], Star["Z"]
# Container X Y Z coordinates in refrence of the center of the system
bx, by, bz = Container["X"], Container["Y"], Container["Z"]
# Rotation speed of the container
rotation_speed = Container["Rotation Speed"]
# Container qw/qx/qy/qz quaternion rotation
qw, qx, qy, qz = Container["qw"], Container["qx"], Container["qy"], Container["qz"]
# Stanton X Y Z coordinates in refrence of the center of the container
bsx = ((1-(2*qy**2)-(2*qz**2))*(sx-bx))+(((2*qx*qy)-(2*qz*qw))*(sy-by))+(((2*qx*qz)+(2*qy*qw))*(sz-bz))
bsy = (((2*qx*qy)+(2*qz*qw))*(sx-bx))+((1-(2*qx**2)-(2*qz**2))*(sy-by))+(((2*qy*qz)-(2*qx*qw))*(sz-bz))
bsz = (((2*qx*qz)-(2*qy*qw))*(sx-bx))+(((2*qy*qz)+(2*qx*qw))*(sy-by))+((1-(2*qx**2)-(2*qy**2))*(sz-bz))
# Solar Declination of Stanton
Solar_declination = degrees(acos((((sqrt(bsx**2+bsy**2+bsz**2))**2)+((sqrt(bsx**2+bsy**2))**2)-(bsz**2))/(2*(sqrt(bsx**2+bsy**2+bsz**2))*(sqrt(bsx**2+bsy**2)))))*copysign(1,bsz)
# Radius of Stanton
StarRadius = Star["Body Radius"] # OK
# Apparent Radius of Stanton
Apparent_Radius = degrees(asin(StarRadius/(sqrt((bsx)**2+(bsy)**2+(bsz)**2))))
# Length of day is the planet rotation rate expressed as a fraction of a 24 hr day.
LengthOfDay = 3600*rotation_speed/86400
# A Julian Date is simply the number of days and fraction of a day since a specific event. (01/01/2020 00:00:00)
JulianDate = Time_passed_since_reference_in_seconds/(24*60*60) # OK
# Determine the current day/night cycle of the planet.
# The current cycle is expressed as the number of day/night cycles and fraction of the cycle that have occurred
# on that planet since Jan 1, 2020 given the length of day. While the number of sunrises that have occurred on the
# planet since Jan 1, 2020 is interesting, we are really only interested in the fractional part.
try :
CurrentCycle = JulianDate/LengthOfDay
except ZeroDivisionError :
CurrentCycle = 1
# The rotation correction is a value that accounts for the rotation of the planet on Jan 1, 2020 as we don’t know
# exactly when the rotation of the planet started. This value is measured and corrected during a rotation
# alignment that is performed periodically in-game and is retrieved from the navigation database.
RotationCorrection = Container["Rotation Adjust"]
# CurrentRotation is how far the planet has rotated in this current day/night cycle expressed in the number of
# degrees remaining before the planet completes another day/night cycle.
CurrentRotation = (360-(CurrentCycle%1)*360-RotationCorrection)%360
# Meridian determine where the star would be if the planet did not rotate.
# Between the planet and Stanton there is a plane that contains the north pole and south pole
# of the planet and the center of Stanton. Locations on the surface of the planet on this plane
# experience the phenomenon we call noon.
Meridian = degrees( (atan2(bsy,bsx)-(pi/2)) % (2*pi) )
# Because the planet rotates, the location of noon is constantly moving. This equation
# computes the current longitude where noon is occurring on the planet.
SolarLongitude = CurrentRotation-(0-Meridian)%360
if SolarLongitude>180:
SolarLongitude = SolarLongitude-360
elif SolarLongitude<-180:
SolarLongitude = SolarLongitude+360
# The difference between Longitude and Longitude360 is that for Longitude, Positive values
# indicate locations in the Eastern Hemisphere, Negative values indicate locations in the Western
# Hemisphere.
# For Longitude360, locations in longitude 0-180 are in the Eastern Hemisphere, locations in
# longitude 180-359 are in the Western Hemisphere.
Longitude360 = Longitude%360 # OK
# Determine correction for location height
ElevationCorrection = degrees(acos(Container["Body Radius"]/(Container["Body Radius"]))) if Height<0 else degrees(acos(Container["Body Radius"]/(Container["Body Radius"]+Height)))
# Determine Rise/Set Hour Angle
# The star rises at + (positive value) rise/set hour angle and sets at - (negative value) rise/set hour angle
# Solar Declination and Apparent Radius come from the first set of equations when we determined where the star is.
RiseSetHourAngle = degrees(acos(-tan(radians(Latitude))*tan(radians(Solar_declination))))+Apparent_Radius+ElevationCorrection
# Determine the current Hour Angle of the star
# Hour Angles between 180 and the +Rise Hour Angle are before sunrise.
# Between +Rise Hour angle and 0 are after sunrise before noon. 0 noon,
# between 0 and -Set Hour Angle is afternoon,
# between -Set Hour Angle and -180 is after sunset.
# Once the current Hour Angle is determined, we now know the actual angle (in degrees)
# between the position of the star and the +rise hour angle and the -set hour angle.
HourAngle = (CurrentRotation-(Longitude360-Meridian)%360)%360
if HourAngle > 180:
HourAngle = HourAngle - 360
# Determine the planet Angular Rotation Rate.
# Angular Rotation Rate is simply the Planet Rotation Rate converted from Hours into degrees per minute.
# The Planet Rotation Rate is datamined from the game files.
try :
AngularRotationRate = 6/rotation_speed # OK
except ZeroDivisionError :
AngularRotationRate = 0
if AngularRotationRate != 0 :
midnight = (HourAngle + 180) / AngularRotationRate
morning = (HourAngle - (RiseSetHourAngle+12)) / AngularRotationRate
if HourAngle <= RiseSetHourAngle+12:
morning = morning + LengthOfDay*24*60
sunrise = (HourAngle - RiseSetHourAngle) / AngularRotationRate
if HourAngle <= RiseSetHourAngle:
sunrise = sunrise + LengthOfDay*24*60
noon = (HourAngle - 0) / AngularRotationRate
if HourAngle <= 0:
noon = noon + LengthOfDay*24*60
sunset = (HourAngle - -1*RiseSetHourAngle) / AngularRotationRate
if HourAngle <= -1*RiseSetHourAngle:
sunset = sunset + LengthOfDay*24*60
evening = (HourAngle - (-1*RiseSetHourAngle-12)) / AngularRotationRate
if HourAngle <= -1*(RiseSetHourAngle-12):
evening = evening + LengthOfDay*24*60
else :
midnight = 0
morning = 0
sunrise = 0
noon = 0
sunset = 0
evening = 0
if 180 >= HourAngle > RiseSetHourAngle+12:
state_of_the_day = "After midnight"
next_event = "Sunrise"
next_event_time = sunrise
elif RiseSetHourAngle+12 >= HourAngle > RiseSetHourAngle:
state_of_the_day = "Morning Twilight"
next_event = "Sunrise"
next_event_time = sunrise
elif RiseSetHourAngle >= HourAngle > 0:
state_of_the_day = "Morning"
next_event = "Sunset"
next_event_time = sunset
elif 0 >= HourAngle > -1*RiseSetHourAngle:
state_of_the_day = "Afternoon"
next_event = "Sunset"
next_event_time = sunset
elif -1*RiseSetHourAngle >= HourAngle > -1*RiseSetHourAngle-12:
state_of_the_day = "Evening Twilight"
next_event = "Sunrise"
next_event_time = sunrise
elif -1*RiseSetHourAngle-12 >= HourAngle >= -180:
state_of_the_day = "Before midnight"
next_event = "Sunrise"
next_event_time = sunrise
if AngularRotationRate == 0 :
next_event = "N/A"
return [state_of_the_day, next_event, next_event_time]
except Exception as e:
print(f"Error in sunrise/sunset calculations: \n{e}\nValues were:\n-X : {X}\n-Y : {Y}\n-Z : {Z}\n-Latitude : {Latitude}\n-Longitude : {Longitude}\n-Height : {Height}\n-Container : {Container['Name']}\n-Star : {Star['Name']}")
sys.stdout.flush()
return ["Unknown", "Unknown", 0]
#Sets some variables
Reference_time_UTC = datetime.datetime(2020, 1, 1)
Epoch = datetime.datetime(1970, 1, 1)
Reference_time = (Reference_time_UTC - Epoch).total_seconds()
if logs_enabled == True:
if not os.path.isdir('Logs'):
os.mkdir('Logs')
if not os.path.isfile('Logs/Logs.csv'):
field = ['Key', 'System' ,'Global_X', 'Global_Y', 'Global_Z', 'Container', 'Local_X', 'Local_Y', 'Local_Z', 'Longitude', 'Latitude', 'Height', 'Time', 'Readable_Time', 'Player', 'Comment']
with open("Logs/Logs.csv","w+", newline='') as f:
writer = csv.writer(f)
writer.writerow(field)
New_run_field = ['New_Run']
with open(r'Logs/Logs.csv', 'a', newline='') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(New_run_field)
Old_clipboard = ""
Old_player_Global_coordinates = {}
for i in ["X", "Y", "Z"]:
Old_player_Global_coordinates[i] = 0.0
Old_player_local_rotated_coordinates = {}
for i in ["X", "Y", "Z"]:
Old_player_local_rotated_coordinates[i] = 0.0
Old_Distance_to_POI = {}
for i in ["X", "Y", "Z"]:
Old_Distance_to_POI[i] = 0.0
Old_container = {
"Name": "None",
"X": 0,
"Y": 0,
"Z": 0,
"Rotation Speed": 0,
"Rotation Adjust": 0,
"OM Radius": 0,
"Body Radius": 0,
"POI": {}
}
Old_time = time.time()
#Reset the clipboard content
pyperclip.copy("")
while True:
#Get the new clipboard content
new_clipboard = pyperclip.paste()
#If clipboard content hasn't changed
if new_clipboard == Old_clipboard or new_clipboard == "":
#Wait some time
time.sleep(1/5)
#If clipboard content has changed
else :
#update the memory with the new content
Old_clipboard = new_clipboard
New_time = time.time() + time_offset
#If it contains some coordinates
if new_clipboard.startswith("Coordinates:"):
#split the clipboard in sections
new_clipboard_splitted = new_clipboard.replace(":", " ").split(" ")
#get the 3 new XYZ coordinates
New_Player_Global_coordinates = {}
New_Player_Global_coordinates['X'] = float(new_clipboard_splitted[3])/1000
New_Player_Global_coordinates['Y'] = float(new_clipboard_splitted[5])/1000
New_Player_Global_coordinates['Z'] = float(new_clipboard_splitted[7])/1000
#-----------------------------------------------------planetary_nav--------------------------------------------------------------
# If the target is within the attraction of a planet
if Mode == "planetary_nav":
#---------------------------------------------------Actual Container----------------------------------------------------------------
#search in the Databse to see if the player is ina Container
Actual_Container = get_current_container(New_Player_Global_coordinates["X"], New_Player_Global_coordinates["Y"], New_Player_Global_coordinates["Z"])
#---------------------------------------------------New player local coordinates----------------------------------------------------
#Time passed since the start of game simulation
Time_passed_since_reference_in_seconds = New_time - Reference_time
New_player_local_rotated_coordinates = get_local_rotated_coordinates(Time_passed_since_reference_in_seconds, New_Player_Global_coordinates["X"], New_Player_Global_coordinates["Y"], New_Player_Global_coordinates["Z"], Actual_Container)
#---------------------------------------------------New target local coordinates----------------------------------------------------
#Grab the rotation speed of the container in the Database and convert it in degrees/s
target_Rotation_speed_in_hours_per_rotation = Database["Containers"][Target["Container"]]["Rotation Speed"]
try:
target_Rotation_speed_in_degrees_per_second = 0.1 * (1/target_Rotation_speed_in_hours_per_rotation)
except ZeroDivisionError:
target_Rotation_speed_in_degrees_per_second = 0
#Get the actual rotation state in degrees using the rotation speed of the container, the actual time and a rotational adjustment value
target_Rotation_state_in_degrees = ((target_Rotation_speed_in_degrees_per_second * Time_passed_since_reference_in_seconds) + Database["Containers"][Target["Container"]]["Rotation Adjust"]) % 360
#get the new player rotated coordinates
target_rotated_coordinates = rotate_point_2D(Target, radians(target_Rotation_state_in_degrees))
#-------------------------------------------------player local Long Lat Height--------------------------------------------------
if Actual_Container['Name'] != "None":
player_Latitude, player_Longitude, player_Height = get_lat_long_height(New_player_local_rotated_coordinates["X"], New_player_local_rotated_coordinates["Y"], New_player_local_rotated_coordinates["Z"], Actual_Container)
#-------------------------------------------------target local Long Lat Height--------------------------------------------------
target_Latitude, target_Longitude, target_Height = get_lat_long_height(Target["X"], Target["Y"], Target["Z"], Database["Containers"][Target["Container"]])
#---------------------------------------------------Distance to POI-----------------------------------------------------------------
New_Distance_to_POI = {}
if Actual_Container == Target["Container"]:
for i in ["X", "Y", "Z"]:
New_Distance_to_POI[i] = abs(Target[i] - New_player_local_rotated_coordinates[i])
else:
for i in ["X", "Y", "Z"]:
New_Distance_to_POI[i] = abs((target_rotated_coordinates[i] + Database["Containers"][Target["Container"]][i]) - New_Player_Global_coordinates[i])
#get the real new distance between the player and the target
New_Distance_to_POI_Total = vector_norm(New_Distance_to_POI)
if New_Distance_to_POI_Total <= 100:
New_Distance_to_POI_Total_color = "#00ff00"
elif New_Distance_to_POI_Total <= 1000:
New_Distance_to_POI_Total_color = "#ffd000"
else :
New_Distance_to_POI_Total_color = "#ff3700"
#---------------------------------------------------Delta Distance to POI-----------------------------------------------------------
#get the real old distance between the player and the target
Old_Distance_to_POI_Total = vector_norm(Old_Distance_to_POI)
#get the 3 XYZ distance travelled since last update
Delta_Distance_to_POI = {}
for i in ["X", "Y", "Z"]:
Delta_Distance_to_POI[i] = New_Distance_to_POI[i] - Old_Distance_to_POI[i]
#get the real distance travelled since last update
Delta_Distance_to_POI_Total = New_Distance_to_POI_Total - Old_Distance_to_POI_Total
if Delta_Distance_to_POI_Total <= 0:
Delta_distance_to_poi_color = "#00ff00"
else:
Delta_distance_to_poi_color = "#ff3700"
#---------------------------------------------------Estimated time of arrival to POI------------------------------------------------
#get the time between the last update and this update
Delta_time = New_time - Old_time
#get the time it would take to reach destination using the same speed
try :
Estimated_time_of_arrival = (Delta_time*New_Distance_to_POI_Total)/abs(Delta_Distance_to_POI_Total)
except ZeroDivisionError:
Estimated_time_of_arrival = 0.00
#----------------------------------------------------Closest Quantumable POI--------------------------------------------------------
if Target["QTMarker"] == "FALSE":
Target_to_POIs_Distances_Sorted = get_closest_POI(Target["X"], Target["Y"], Target["Z"], Database["Containers"][Target["Container"]], True)
else :
Target_to_POIs_Distances_Sorted = [{
"Name" : "POI itself",
"Distance" : 0
}]
#----------------------------------------------------Player Closest POI--------------------------------------------------------
Player_to_POIs_Distances_Sorted = get_closest_POI(New_player_local_rotated_coordinates["X"], New_player_local_rotated_coordinates["Y"], New_player_local_rotated_coordinates["Z"], Actual_Container, False)
#-------------------------------------------------------3 Closest OMs to player---------------------------------------------------------------
player_Closest_OM = get_closest_oms(New_player_local_rotated_coordinates["X"], New_player_local_rotated_coordinates["Y"], New_player_local_rotated_coordinates["Z"], Actual_Container)
#-------------------------------------------------------3 Closest OMs to target---------------------------------------------------------------
target_Closest_OM = get_closest_oms(Target["X"], Target["Y"], Target["Z"], Database["Containers"][Target["Container"]])
#----------------------------------------------------Course Deviation to POI--------------------------------------------------------
#get the vector between current_pos and previous_pos
Previous_current_pos_vector = {}
for i in ['X', 'Y', 'Z']:
Previous_current_pos_vector[i] = New_player_local_rotated_coordinates[i] - Old_player_local_rotated_coordinates[i]
#get the vector between current_pos and target_pos
Current_target_pos_vector = {}
for i in ['X', 'Y', 'Z']:
Current_target_pos_vector[i] = Target[i] - New_player_local_rotated_coordinates[i]
#get the angle between the current-target_pos vector and the previous-current_pos vector
Total_deviation_from_target = angle_between_vectors(Previous_current_pos_vector, Current_target_pos_vector)
if Total_deviation_from_target <= 10:
Total_deviation_from_target_color = "#00ff00"
elif Total_deviation_from_target <= 20:
Total_deviation_from_target_color = "#ffd000"
else:
Total_deviation_from_target_color = "#ff3700"
#----------------------------------------------------------Flat_angle--------------------------------------------------------------
previous = Old_player_local_rotated_coordinates
current = New_player_local_rotated_coordinates
#Vector AB (Previous -> Current)
previous_to_current = {}
for i in ["X", "Y", "Z"]:
previous_to_current[i] = current[i] - previous[i]
#Vector AC (C = center of the planet, Previous -> Center)
previous_to_center = {}
for i in ["X", "Y", "Z"]:
previous_to_center[i] = 0 - previous[i]
#Vector BD (Current -> Target)
current_to_target = {}
for i in ["X", "Y", "Z"]:
current_to_target[i] = Target[i] - current[i]
#Vector BC (C = center of the planet, Current -> Center)
current_to_center = {}
for i in ["X", "Y", "Z"]:
current_to_center[i] = 0 - current[i]
#Normal vector of a plane:
#abc : Previous/Current/Center
n1 = {}
n1["X"] = previous_to_current["Y"] * previous_to_center["Z"] - previous_to_current["Z"] * previous_to_center["Y"]
n1["Y"] = previous_to_current["Z"] * previous_to_center["X"] - previous_to_current["X"] * previous_to_center["Z"]
n1["Z"] = previous_to_current["X"] * previous_to_center["Y"] - previous_to_current["Y"] * previous_to_center["X"]
#acd : Previous/Center/Target
n2 = {}
n2["X"] = current_to_target["Y"] * current_to_center["Z"] - current_to_target["Z"] * current_to_center["Y"]
n2["Y"] = current_to_target["Z"] * current_to_center["X"] - current_to_target["X"] * current_to_center["Z"]
n2["Z"] = current_to_target["X"] * current_to_center["Y"] - current_to_target["Y"] * current_to_center["X"]
Flat_angle = angle_between_vectors(n1, n2)
if Flat_angle <= 10:
Flat_angle_color = "#00ff00"
elif Flat_angle <= 20:
Flat_angle_color = "#ffd000"
else:
Flat_angle_color = "#ff3700"
#----------------------------------------------------------Heading--------------------------------------------------------------
bearingX = cos(radians(target_Latitude)) * sin(radians(target_Longitude) - radians(player_Longitude))
bearingY = cos(radians(player_Latitude)) * sin(radians(target_Latitude)) - sin(radians(player_Latitude)) * cos(radians(target_Latitude)) * cos(radians(target_Longitude) - radians(player_Longitude))
Bearing = (degrees(atan2(bearingX, bearingY)) + 360) % 360
#-------------------------------------------------Sunrise Sunset Calculation----------------------------------------------------
player_state_of_the_day, player_next_event, player_next_event_time = get_sunset_sunrise_predictions(
New_player_local_rotated_coordinates["X"],
New_player_local_rotated_coordinates["Y"],
New_player_local_rotated_coordinates["Z"],
player_Latitude,
player_Longitude,
player_Height,
Actual_Container,
Database["Containers"]["Stanton"]
)
target_state_of_the_day, target_next_event, target_next_event_time = get_sunset_sunrise_predictions(
Target["X"],
Target["Y"],
Target["Z"],
target_Latitude,
target_Longitude,
target_Height,
Database["Containers"][Target["Container"]],
Database["Containers"]["Stanton"]
)
#------------------------------------------------------------Backend to Frontend------------------------------------------------------------
new_data = {
"updated" : f"{time.strftime('%H:%M:%S', time.localtime(time.time()))}",
"target" : Target['Name'],
"player_actual_container" : Actual_Container['Name'],
"target_container" : Target['Container'],
"player_x" : round(New_player_local_rotated_coordinates['X'], 3),
"player_y" : round(New_player_local_rotated_coordinates['Y'], 3),
"player_z" : round(New_player_local_rotated_coordinates['Z'], 3),
"player_long" : f"{round(player_Longitude, 2)}°",
"player_lat" : f"{round(player_Latitude, 2)}°",
"player_height" : f"{round(player_Height, 1)} km",
"player_OM1" : f"{player_Closest_OM['Z']['OM']['Name']} : {round(player_Closest_OM['Z']['Distance'], 3)} km",
"player_OM2" : f"{player_Closest_OM['Y']['OM']['Name']} : {round(player_Closest_OM['Y']['Distance'], 3)} km",
"player_OM3" : f"{player_Closest_OM['X']['OM']['Name']} : {round(player_Closest_OM['X']['Distance'], 3)} km",
"player_closest_poi" : f"{Player_to_POIs_Distances_Sorted[0]['Name']} : {round(Player_to_POIs_Distances_Sorted[0]['Distance'], 3)} km",
"player_state_of_the_day" : f"{player_state_of_the_day}",
"player_next_event" : f"{player_next_event}",
"player_next_event_time" : f"{time.strftime('%H:%M:%S', time.localtime(New_time + player_next_event_time*60))}",
"target_x" : Target["X"],
"target_y" : Target["Y"],
"target_z" : Target["Z"],
"target_long" : f"{round(target_Longitude, 2)}°",
"target_lat" : f"{round(target_Latitude, 2)}°",
"target_height" : f"{round(target_Height, 1)} km",
"target_OM1" : f"{target_Closest_OM['Z']['OM']['Name']} : {round(target_Closest_OM['Z']['Distance'], 3)} km",
"target_OM2" : f"{target_Closest_OM['Y']['OM']['Name']} : {round(target_Closest_OM['Y']['Distance'], 3)} km",
"target_OM3" : f"{target_Closest_OM['X']['OM']['Name']} : {round(target_Closest_OM['X']['Distance'], 3)} km",
"target_closest_QT_beacon" : f"{Target_to_POIs_Distances_Sorted[0]['Name']} : {round(Target_to_POIs_Distances_Sorted[0]['Distance'], 3)} km",
"target_state_of_the_day" : f"{target_state_of_the_day}",
"target_next_event" : f"{target_next_event}",
"target_next_event_time" : f"{time.strftime('%H:%M:%S', time.localtime(New_time + target_next_event_time*60))}",
"distance_to_poi" : f"{round(New_Distance_to_POI_Total, 3)} km",
"distance_to_poi_color" : New_Distance_to_POI_Total_color,
"delta_distance_to_poi" : f"{round(abs(Delta_Distance_to_POI_Total), 3)} km",
"delta_distance_to_poi_color" : Delta_distance_to_poi_color,
"total_deviation" : f"{round(Total_deviation_from_target, 1)}°",
"total_deviation_color" : Total_deviation_from_target_color,
"horizontal_deviation" : f"{round(Flat_angle, 1)}°",
"horizontal_deviation_color" : Flat_angle_color,
"heading" : f"{round(Bearing, 1)}°",
"ETA" : f"{str(datetime.timedelta(seconds=round(Estimated_time_of_arrival, 0)))}"
}
print("New data :", json.dumps(new_data))
sys.stdout.flush()
#------------------------------------------------------------Logs update------------------------------------------------------------
if logs_enabled == True:
if Actual_Container['Name'] != "None":
fields = [
'None',
'Stanton',
str(New_player_local_rotated_coordinates["X"]*1000),
str(New_player_local_rotated_coordinates["Y"]*1000),
str(New_player_local_rotated_coordinates["Z"]*1000),
str(Actual_Container['Name']),
str(New_player_local_rotated_coordinates['X']),
str(New_player_local_rotated_coordinates['Y']),
str(New_player_local_rotated_coordinates['Z']),
str(player_Longitude),
str(player_Latitude),
str(player_Height*1000),
str(time.time()),
time.strftime('%d %b %Y %H:%M:%S', time.gmtime(time.time())),
"",
""
]
# field = [
# 'Key',
# 'System',
# 'Global_X',
# 'Global_Y',
# 'Global_Z',
# 'Container',
# 'Local_X',
# 'Local_Y',
# 'Local_Z',
# 'Longitude',
# 'Latitude',
# 'Height',
# 'Time',
# 'Readable_Time',',
# 'Player',
# 'Comment'
# ]
with open(r'Logs/Logs.csv', 'a', newline='') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(fields)
#---------------------------------------------------Update coordinates for the next update------------------------------------------
for i in ["X", "Y", "Z"]:
Old_player_Global_coordinates[i] = New_Player_Global_coordinates[i]
for i in ["X", "Y", "Z"]:
Old_player_local_rotated_coordinates[i] = New_player_local_rotated_coordinates[i]
for i in ["X", "Y", "Z"]:
Old_Distance_to_POI[i] = New_Distance_to_POI[i]
Old_time = New_time
#-------------------------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------space_nav------------------------------------------------------------------
#If the target is within the attraction of a planet
if Mode == "space_nav":
#-----------------------------------------------------Distance to POI---------------------------------------------------------------
New_Distance_to_POI = {}
for i in ["X", "Y", "Z"]:
New_Distance_to_POI[i] = abs(Target[i] - New_Player_Global_coordinates[i])
#get the real new distance between the player and the target
New_Distance_to_POI_Total = vector_norm(New_Distance_to_POI)
if New_Distance_to_POI_Total <= 100:
New_Distance_to_POI_Total_color = "#00ff00"
elif New_Distance_to_POI_Total <= 1000:
New_Distance_to_POI_Total_color = "#ffd000"
else :
New_Distance_to_POI_Total_color = "#ff3700"
#---------------------------------------------------Delta Distance to POI-----------------------------------------------------------
Old_Distance_to_POI_Total = vector_norm(Old_Distance_to_POI)
#get the real distance travelled since last update
Delta_Distance_to_POI_Total = New_Distance_to_POI_Total - Old_Distance_to_POI_Total
if Delta_Distance_to_POI_Total <= 0:
Delta_distance_to_poi_color = "#00ff00"
else:
Delta_distance_to_poi_color = "#ff3700"