-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.gd
743 lines (591 loc) · 23.5 KB
/
main.gd
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
extends Control
# Declare member variables here. Examples:
var friendly = preload("res://ships/friendly_ship.tscn")
var starbase = preload("res://ships/starbase.tscn")
var drone = preload("res://ships//friendly_drone.tscn")
var enemy = preload("res://ships/enemy_ship.tscn")
var enemy_starbase = preload("res://ships/enemy_starbase.tscn")
var pirate_starbase = preload("res://ships/pirate_starbase.tscn")
var pirate_ship = preload("res://ships/pirate_ship.tscn")
var neutral = preload("res://ships/neutral_ship.tscn")
var asteroid_processor = preload("res://ships/asteroid_processor.tscn")
var cycler = preload("res://ships/cycler.tscn")
var wormhole = preload("res://bodies/wormhole2D.tscn")
# star system templates
#var handmade_system = preload("res://systems/star system.tscn")
#var proc_system = preload("res://systems//proc star system.tscn")
var system_no_planets = preload("res://systems/star system no planets.tscn")
var system_multiple = preload("res://systems/binary star system.tscn")
var data_system = preload("res://systems/data star system.tscn")
# we can't preload from a dictionary because preload wants const,
# so we need to store entire preload("xxx")
var defined_systems = {
# Sol will need to remain separate even after data is merged, due to sheer size & complexity
"Sol": preload("res://systems/Sol system.tscn"),
"Trappist-1": preload("res://systems/Trappist system.tscn"),
#"Proxima": preload("res://systems/Proxima Centauri system.tscn"),
#"Alpha Centauri": preload("res://systems/Alpha Centauri system.tscn"),
#"Barnards": preload("res://systems/Barnard's star system.tscn"),
"UV Ceti": preload("res://systems/Luyten 726-8 system.tscn"), # outlier: data file uses scientific name
"Luyten 726-8": preload("res://systems/Luyten 726-8 system.tscn"), # special case: atypical naming
"Tau Ceti": preload("res://systems/Tau Ceti system.tscn"),
#"Wolf 359": preload("res://systems/Wolf 359 system.tscn"),
"Gliese 1265": preload("res://systems/Gliese 1265 system.tscn"),
"Teegardens": preload("res://systems/Teegarden's star system.tscn"),
}
# game core
var core = preload("res://game_core.tscn")
# how many higher ranks to assign to (friendly) AI
var rank_list = [1,1]
var curr_system = null
var mmap
func system_name_to_id(nam):
var _name = str(nam)
_name = _name.replace("'", "") # nix any apostrophes if present
_name = _name.trim_suffix("Star") # nix any "Star" (e.g. Barnard's Star, Teegarden's Star...)
_name = _name.strip_edges()
print("ID for name: ", _name)
return _name
# this uses text IDs because that's what the spawning/instancing system uses
func spawn_system(system_id, system, multiple=false):
var sys = system_no_planets
if multiple:
sys = system_multiple
# named/defined systems
if system_id in defined_systems: #alternate to dict.has()
print("Defined system found: ", system_id)
sys = defined_systems[system_id]
else:
var systems = game.player.HUD.get_node("Control4/star map").systems
print("System data: ", systems[system_id])
sys = data_system
#print("Systems:", systems)
# print("System not found: ", system)
var system_inst = sys.instantiate()
# data-driven systems
if sys == data_system:
var systems = game.player.HUD.get_node("Control4/star map").systems
system_inst.data = systems[system_id]
# set name
var nam = system_id #.capitalize()
system_inst.set_name(nam)
# make names match for (template) systems w/o planets
if sys == system_no_planets or sys == system_multiple:
var nam = system_id.capitalize()
system_inst.set_name(nam)
if sys != system_multiple:
system_inst.get_child(0).set_name(nam)
system_inst.get_child(0).get_child(1).set_text(nam)
if sys == system_multiple:
#system_inst.get_child(1).set_name(nam + "B")
system_inst.get_child(1).get_child(1).set_text(nam + " B")
add_child(system_inst)
return [system_inst.get_name(), system_inst]
func spawn_core():
var cor = core.instantiate()
add_child(cor)
# spawn player
get_tree().get_nodes_in_group("player")[0].get_child(0).spawn()
# send position to parallax background
get_node("ParallaxBackground").init_pos = get_tree().get_nodes_in_group("player")[0].get_global_position()
#print("Init pos: ", get_node("ParallaxBackground").init_pos)
# Called when the node enters the scene tree for the first time.
func _ready():
print("Main init")
var syst = "Sol"
if game.start != null:
var lookup_system = {1: "Sol", 2: "Trappist"}
syst = lookup_system[game.start]
var data = spawn_system(syst, null)
# the system is always child #2 (#0 is parallax bg and #1 is a timer)
curr_system = data[0]
spawn_core()
var p_ind = get_tree().get_nodes_in_group("player")[0].get_index()
print("Player index: " + str(p_ind))
#print("Map graph: ", game.player.HUD.get_node("Control4/star map").map_graph)
mmap = get_tree().get_nodes_in_group("minimap")[0]
for i in range(4):
spawn_friendly(i, p_ind, mmap)
for i in range(4):
spawn_friendly_drone(i, p_ind)
var pos = spawn_starbase(curr_system, p_ind, mmap)
for i in range(3):
spawn_friendly_drone_pos(i, p_ind, pos)
pos = spawn_enemy_starbase(curr_system, p_ind, mmap)
# spawn related to enemy starbase
for i in range(3):
spawn_enemy(pos, i, p_ind, mmap)
pos = get_tree().get_nodes_in_group("planets")[1] # TODO: should be one of the Jovian/Saturnian moons
pos = pos.get_global_position()
spawn_neutral(pos, 0, p_ind, mmap)
# wormholes
wormholes_from_graph(p_ind)
# other interesting things
pos = spawn_asteroid_processor(p_ind, curr_system, mmap)
if pos != null:
for i in range(2):
spawn_friendly_drone_pos(i, p_ind, pos)
pos = spawn_cycler(p_ind, curr_system, mmap)
if pos != null:
for i in range(2):
spawn_friendly_drone_pos(i, p_ind, pos)
var pirate = spawn_pirate_base(p_ind, curr_system, mmap)
if pirate != null:
for i in range(3):
spawn_pirate(pirate, p_ind, mmap)
mmap.move_player_sprite()
# update census
var flt1 = "Fleet 1 " + str(game.fleet1[0]) + " " + str(game.fleet1[1]) + " " + str(game.fleet1[2])
var flt2 = "Fleet 2 " + str(game.fleet1[0]) + " " + str(game.fleet2[1]) + " " + str(game.fleet2[2])
game.player.HUD.get_node("Control2/Panel_rightHUD/PanelInfo/CensusInfo/Label1").set_text(flt1)
game.player.HUD.get_node("Control2/Panel_rightHUD/PanelInfo/CensusInfo/Label2").set_text(flt2)
# ------------------------------------
func get_colonized_planet():
var ret
var ps = get_tree().get_nodes_in_group("planets")
for p in ps:
# is it colonized?
var col = p.has_colony()
if col and col == "colony":
ret = p
if ret != null:
return ret
else:
print("No colonized planet found")
return null
# all spawn functions spawn at node at system+1 index
func spawn_friendly(i, p_ind, m_map):
var p = get_colonized_planet()
if p:
var sp = friendly.instantiate()
# random factor
randomize()
var offset = Vector2(randf_range(50, 150), randf_range(50, 150))
sp.set_global_position(p.get_global_position() + offset)
print("Spawning @ : " + str(p.get_global_position() + offset))
sp.get_child(0).set_position(Vector2(0,0))
sp.set_name("friendly"+str(i))
get_child(3).add_child(sp)
get_child(3).move_child(sp, p_ind+1)
# doesn't work for some reason
#add_sibling(get_tree().get_nodes_in_group("player")[0], sp)
# give minimap icon
#var mmap = get_tree().get_nodes_in_group("minimap")[0]
m_map._on_friendly_ship_spawned(sp.get_child(0))
# give higher ranks if any left
if rank_list.size() > 0:
sp.get_child(0).rank = rank_list.pop_front()
#print("Friendly " + sp.get_name() + " received rank " + str(sp.get_child(0).rank))
#print("Spawned friendly")
# add to fleet census
game.fleet1[1] += 1
func spawn_starbase(system, p_ind, m_map):
var p = get_colonized_planet()
if p:
var sb = starbase.instantiate()
randomize()
# max offset
var max_o = 700
if system == "Sol":
max_o = 1000
# random factor
var offset = Vector2(randf_range(500, max_o), randf_range(500, max_o))
# sign
if system == "proc":
# force negative
offset = offset*-1
else:
var sig = randf()
if sig > 0.5:
offset = offset*-1
sb.set_global_position(p.get_global_position() + offset)
sb.set_name("friendly_base")
get_child(3).add_child(sb)
get_child(3).move_child(sb, p_ind+1)
# give minimap icon
#var mmap = get_tree().get_nodes_in_group("minimap")[0]
m_map._on_starbase_spawned(sb.get_child(0))
return sb.get_global_position()
func spawn_friendly_drone(i, p_ind):
var p = get_colonized_planet()
if p:
var sp = drone.instantiate()
# random factor
randomize()
var offset = Vector2(randf_range(50, 150), randf_range(50, 150))
sp.set_global_position(p.get_global_position() + offset)
#print("Spawning @ : " + str(p.get_global_position() + offset))
sp.get_child(0).set_position(Vector2(0,0))
sp.set_name("friend_drone"+str(i))
get_child(3).add_child(sp)
get_child(3).move_child(sp, p_ind+1)
# doesn't work for some reason
#add_sibling(get_tree().get_nodes_in_group("player")[0], sp)
# drones don't have minimap icons
# used to spawn at a starbase
func spawn_friendly_drone_pos(i, p_ind, pos):
var sp = drone.instantiate()
# random factor
randomize()
var offset = Vector2(randf_range(50, 150), randf_range(50, 150))
sp.set_global_position(pos + offset)
#print("Spawning @ : " + str(p.get_global_position() + offset))
sp.get_child(0).set_position(Vector2(0,0))
sp.set_name("friend_drone"+str(i))
get_child(3).add_child(sp)
get_child(3).move_child(sp, p_ind+1)
# drones don't have minimap icons
# flag to set the correct state
sp.get_child(0).add_to_group("station_drone")
func spawn_enemy_starbase(system, p_ind, m_map):
var p
var sb = enemy_starbase.instantiate()
if system == "Sol":
p = get_tree().get_nodes_in_group("planets")[1] # Venus # TODO: should be Saturn instead
elif system == "Proxima":
p = get_tree().get_nodes_in_group("planets")[2]
elif system == "Trappist":
p = get_tree().get_nodes_in_group("planets")[3]
else:
p = get_tree().get_nodes_in_group("planets")[0]
# random factor
randomize()
var offset = Vector2(randf_range(200, 400), randf_range(200, 400))
sb.set_global_position(p.get_global_position() + offset)
sb.set_name("enemy_base")
get_child(3).add_child(sb)
get_child(3).move_child(sb, p_ind+1)
# give minimap icon
#var mmap = get_tree().get_nodes_in_group("minimap")[0]
m_map._on_enemy_starbase_spawned(sb.get_child(0))
return sb.get_global_position()
func spawn_enemy(pos, i, p_ind, m_map):
var sp = enemy.instantiate()
# random factor
randomize()
var offset = Vector2(randf_range(50, 100), randf_range(50, 100))
sp.set_global_position(pos + offset)
#print("Spawning enemy @ : " + str(pos + offset))
sp.get_child(0).set_position(Vector2(0,0))
sp.set_name("enemy"+str(i))
get_child(3).add_child(sp)
get_child(3).move_child(sp, p_ind+1)
# give minimap icon
#var mmap = get_tree().get_nodes_in_group("minimap")[0]
m_map._on_enemy_ship_spawned(sp.get_child(0))
# add to fleet census
game.fleet2[1] += 1
func spawn_neutral(pos, i, p_ind, m_map):
var sp = neutral.instantiate()
# random factor
randomize()
var offset = Vector2(randf_range(50, 100), randf_range(50, 100))
sp.set_global_position(pos + offset)
#print("Spawning enemy @ : " + str(pos + offset))
sp.get_child(0).set_position(Vector2(0,0))
sp.set_name("enemy"+str(i))
get_child(3).add_child(sp)
get_child(3).move_child(sp, p_ind+1)
# give minimap icon
#var mmap = get_tree().get_nodes_in_group("minimap")[0]
m_map._on_neutral_ship_spawned(sp.get_child(0))
# add to fleet census
#game.fleet2[1] += 1
# TODO: should move on an actual cycler orbit
func spawn_cycler(p_ind, system, m_map):
if system != "Sol":
return
var e = get_tree().get_nodes_in_group("planets")[2]
var m = get_tree().get_nodes_in_group("planets")[3]
# B-A = A->B
var offset = m.get_global_position()-e.get_global_position()
var castle = cycler.instantiate()
castle.set_global_position(e.get_global_position()+(offset/2))
castle.set_name("cycler")
get_child(3).add_child(castle)
get_child(3).move_child(castle, p_ind+1)
# give minimap icon
#var mmap = get_tree().get_nodes_in_group("minimap")[0]
m_map._on_starbase_spawned(castle.get_child(0))
return castle.get_global_position()
func spawn_asteroid_processor(p_ind, system, m_map):
if system != "Sol":
return
var p = get_tree().get_nodes_in_group("aster_belt")[0]
var ap = asteroid_processor.instantiate()
# random factor
randomize()
var offset = Vector2(randf_range(200, 400), randf_range(200, 400))
# asteroid belt's position is 0,0 so we have to add radius
ap.set_global_position(p.get_global_position()+Vector2(0,p.radius*game.AU) + offset)
ap.set_name("friendly_processor")
get_child(3).add_child(ap)
get_child(3).move_child(ap, p_ind+1)
# give minimap icon
#var mmap = get_tree().get_nodes_in_group("minimap")[0]
m_map._on_starbase_spawned(ap.get_child(0))
return ap.get_global_position()
func spawn_pirate_base(p_ind, system, m_map):
if system != "Sol":
return
var p = get_tree().get_nodes_in_group("aster_belt")[0]
var ap = pirate_starbase.instantiate()
# random factor
randomize()
var offset = Vector2(randf_range(800, 1600), randf_range(200, 400))
# asteroid belt's position is 0,0 so we have to add radius
var pos = p.get_global_position()+Vector2(0,p.radius*game.AU) + offset
ap.set_global_position(pos)
ap.set_name("pirate_base")
get_child(3).add_child(ap)
get_child(3).move_child(ap, p_ind+1)
# give minimap icon
#var mmap = get_tree().get_nodes_in_group("minimap")[0]
m_map._on_pirate_starbase_spawned(ap.get_child(0))
return pos
func spawn_pirate(pos, p_ind, m_map):
var sp = pirate_ship.instantiate()
# random factor
randomize()
var offset = Vector2(randf_range(50, 100), randf_range(50, 100))
sp.set_global_position(pos + offset)
#print("Spawning pirate @ : " + str(pos + offset))
sp.get_child(0).set_position(Vector2(0,0))
sp.set_name("pirate") #+str(i))
get_child(3).add_child(sp)
get_child(3).move_child(sp, p_ind+1)
# give minimap icon
m_map._on_pirate_ship_spawned(sp.get_child(0))
func spawn_wormhole(p_ind, planet_id, m_map, target_system=null, offset=Vector2(0,0), need_icon=true):
var wh = wormhole.instantiate()
# fix for smaller systems
if planet_id >= get_tree().get_nodes_in_group("planets").size():
return
# handle spawning wormholes not relative to a specific planet
# means our system templates for UV Ceti and no planets don't have to contain a wormhole anymore
var gl = null
if planet_id == -1:
gl = Vector2(0,0)
else:
var p = get_tree().get_nodes_in_group("planets")[planet_id]
gl = p.get_global_position()
# random factor
randomize()
var r_offset = Vector2(randf_range(250, 300), randf_range(250, 300))
wh.set_global_position(gl + offset + r_offset)
wh.set_name("wormhole")
if target_system != null:
wh.target_system = target_system
wh.set_name("wormhole_"+str(target_system))
get_child(2).add_child(wh)
get_child(2).move_child(wh, p_ind+1)
# give minimap icon
#var mmap = get_tree().get_nodes_in_group("minimap")[0]
if need_icon:
m_map._on_wormhole_spawned(wh)
if target_system != null:
print("Spawned a wormhole to " + str(target_system) + " at " + str(wh.get_global_position()))
else:
print("Spawned a wormhole at " + str(wh.get_global_position()))
#return wh.get_global_position()
# --------------------------------------------------------------------
func wormholes_from_graph(p_ind, ref_pos=null):
var starmap = game.player.HUD.get_node("Control4/star map")
# get coords, neighbors and directions from AStar3D
var coords = game.player.HUD.get_node("Control4/star map").find_coords_for_name(curr_system)
var neighbors = game.player.HUD.get_node("Control4/star map").get_neighbors(coords)
#print("Neighboring systems: ", neighbors)
# Sol
print("Planets: ", get_tree().get_nodes_in_group("planets").size())
if get_tree().get_nodes_in_group("planets").size() > 10 and !"rotation_rate" in get_child(3):
for n in neighbors:
print(n, " @ ", game.player.HUD.get_node("Control4/star map").map_astar.get_point_position(n))
# relative direction
var dir = game.player.HUD.get_node("Control4/star map").map_astar.get_point_position(n) - coords
# where to place the w-hole?
var wh_pos = Vector2(0, 0)
if dir.x < 0:
wh_pos.x = -1500
if dir.y < 0:
wh_pos.y = 500
elif dir.y > 0:
wh_pos.y = -750
if dir.z < 0:
wh_pos.y = wh_pos.y - 300
print("Wormhole pos: ", wh_pos, " for dir: ", dir)
spawn_wormhole(p_ind, 11, mmap, n, wh_pos)
elif neighbors.size() > 1:
for n in neighbors:
print(n, " ", starmap.find_name_from_pos(starmap.map_astar.get_point_position(n)), " @ ", starmap.map_astar.get_point_position(n))
# relative direction
var dir = game.player.HUD.get_node("Control4/star map").map_astar.get_point_position(n) - coords
# where to place the w-hole?
var wh_pos = Vector2(0, 2000)
if ref_pos:
wh_pos = ref_pos
var offset_x = 0
var offset_y = 0
if dir.x < 0:
offset_x = -(100*abs(dir.x))
if dir.y < 0:
offset_y = -(100*abs(dir.y))
elif dir.y > 0:
offset_y = 100*abs(dir.y) #-750
if dir.z < 0:
offset_y = offset_y - 300
wh_pos = wh_pos + Vector2(offset_x, offset_y)
print("Offset: ", Vector2(offset_x, offset_y), " for dir: ", dir)
print("Wormhole pos: ", wh_pos, " for dir: ", dir)
spawn_wormhole(p_ind, -1, mmap, n, wh_pos)
else:
var wh_pos = Vector2(0, 2000)
spawn_wormhole(p_ind, -1, mmap, neighbors[0], wh_pos)
# -------------------------------------
func move_player(system, travel=0.0):
var place = null
place = get_tree().get_nodes_in_group("star")[0]
# unlike placing wormholes, we can now rely on star group
if get_tree().get_nodes_in_group("star").size() > 1:
place = get_tree().get_nodes_in_group("star")[1]
print("Place player by the 2nd star")
# var first_star = ["Proxima", "Sol", "Barnards", "Wolf 359", "Tau Ceti"]
# # FIXME: doesn't really place correctly?
# if system in first_star:
# #var place = get_tree().get_nodes_in_group("planets")[1]
# place = get_tree().get_nodes_in_group("star")[0]
# if system == "Alpha Centauri" or system == "Luyten 726-8":
# place = get_tree().get_nodes_in_group("star")[1]
# paranoia
if place == null:
place = get_tree().get_nodes_in_group("star")[0]
print("Place: " + str(place.get_global_position()))
# move player
game.player.get_parent().set_global_position(place.get_global_position())
game.player.set_position(Vector2(0,0))
#call_deferred("update_HUD")
# officer message
# get actual system name
var system_name = get_child(2).get_name()
var travel_months = int(floor(travel))
# for convenience, assume a month has 30 days
var days = (travel-travel_months)*30
var format_travel = "%d months %d days" % [travel_months, days]
# add them to date
game.increment_date(int(floor(days)), travel_months)
#game.date = [game.date[0]+int(floor(days)), game.date[1]+travel_months, game.date[2]]
var format_date = "%02d-%02d-%d" % [game.date[0], game.date[1], game.date[2]]
var msg = str("Welcome to ", system_name, " we arrived: ", format_travel, " after departure. The current date is: ", format_date);
print(str(travel) + " months: " + str(travel_months) + ", " + str(days) + " days ")
game.player.emit_signal("officer_message", msg)
# add to captain's log (using formatted date to ensure we save the correct one)
game.add_event_to_log([system_name, format_date])
func update_HUD():
# force update orrery
var orr = mmap.get_parent().get_node("orrery")
orr.setup()
# show the panel again
orr.get_node("Panel").show()
game.player.HUD.get_node("Control4/map view").setup()
# force update minimap
#mmap._ready()
mmap.get_system_bodies()
mmap.add_system_bodies()
mmap.move_player_sprite()
# force update planet listing
game.player.HUD.planets = get_tree().get_nodes_in_group("planets")
game.player.HUD.get_node("Control2").planets = get_tree().get_nodes_in_group("planets")
game.player.HUD.create_planet_listing()
# force update direction labels
game.player.HUD.create_direction_labels()
# connect planet signals
game.player.HUD.connect_planet_signals(get_tree().get_nodes_in_group("planets"))
# this function is passed the starmap icon, which doubles as a data store
func change_system(system="proxima", time=0.0):
# despawn current system
get_child(2).queue_free()
# close starmap
game.player.HUD.hide_starmap()
# clean minimap
#var mmap = get_tree().get_nodes_in_group("minimap")[0]
for i in range(2, mmap.get_child_count()-1):
if mmap.get_child(i).get_name() == "player":
continue # skip player
mmap.get_child(i).queue_free()
mmap.cleanup()
# clean direction labels
for i in range(game.player.HUD.get_node("Control").get_child_count()):
game.player.HUD.get_node("Control").get_child(i).queue_free()
game.player.HUD.dir_labels = []
# despawn all ships and starbases
var sb = get_tree().get_nodes_in_group("starbase")
for s in sb:
s.get_parent().queue_free()
var f = get_tree().get_nodes_in_group("friendly")
for s in f:
s.get_parent().queue_free()
var e = get_tree().get_nodes_in_group("enemy")
for s in e:
s.get_parent().queue_free()
var p = get_tree().get_nodes_in_group("pirate")
for s in p:
s.get_parent().queue_free()
var n = get_tree().get_nodes_in_group("neutral")
for s in n:
s.get_parent().queue_free()
# clean orrery
var orr = mmap.get_parent().get_node("orrery")
for i in range(1, orr.get_child_count()):
orr.get_child(i).queue_free()
orr.cleanup()
# hide the orrery panel temporarily (preventing drawing of orbits)
orr.get_node("Panel").hide()
# do the same to map view
game.player.HUD.get_node("Control4/map view").hide()
# because the first 4 are GUI elements
for i in range(4, game.player.HUD.get_node("Control4/map view").get_child_count()):
game.player.HUD.get_node("Control4/map view").get_child(i).queue_free()
game.player.HUD.get_node("Control4/map view").cleanup()
# close planet view/listing
if game.player.HUD.get_node("Control2/Panel_rightHUD/PanelInfo/NavInfo").is_visible():
game.player.HUD.get_node("Control2/Panel_rightHUD/PanelInfo/NavInfo").hide()
if game.player.HUD.get_node("Control2/Panel_rightHUD/PanelInfo/PlanetInfo").is_visible():
game.player.HUD.get_node("Control2/Panel_rightHUD/PanelInfo/PlanetInfo").hide()
# clear hud planet listing
game.player.HUD.clear_planet_listing()
var multiple = false
if "multiple" in system:
multiple = system.multiple
# convert from input to textual id since instancing still uses textual ids
#var system_id = system_name_to_id(system.get_name())
# spawn new system
# no need to convert using single/merged data file
var system_id = system.get_name()
var data = spawn_system(system_id, system, multiple)
curr_system = data[0]
move_child(data[1], 2)
print("System after change: ", curr_system)
var p_ind = get_tree().get_nodes_in_group("player")[0].get_index()
#print("Player index: " + str(p_ind))
#print("Map graph: ", game.player.HUD.get_node("Control4/star map").map_graph)
# wormhole
# is it a multi-star system?
# doesn't work because previous system isn't removed yet
#print(get_tree().get_nodes_in_group("star"))
# no point in passing some sort of a flag since we need the star's position anyway
var ref_pos = null
# the system is always child #2
if get_child(2).get_child_count() > 1:
# wormholes are children of system too
if get_child(2).get_child(1).is_in_group("star"):
# the 2nd star's position
ref_pos = get_child(2).get_child(1).get_global_position()
print("Star pos: ", ref_pos)
ref_pos = ref_pos + Vector2(500, 1000)
# force cleanup
mmap.wormholes = []
wormholes_from_graph(p_ind, ref_pos)
# timer
get_node("Timer").start()
call_deferred("move_player", system, time)
func _on_Timer_timeout():
update_HUD()