-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPlanetScanner.py
2013 lines (1339 loc) · 77.4 KB
/
PlanetScanner.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
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 31 13:35:51 2019
Planet Scanner
@author: Nuke Bloodaxe
"""
# This requires rather a lot of things to be working beforehand.
# However, it also is the best way to test the planet related code.
import random, os, buttons, planets, pygame, items
import global_constants as g
import helper_functions as h
# Encapsulate the Anomaly logic, it is really a wrapped item class with a
# location parameter.
class Anomaly(object):
def __init__(self, anomalyItem, boundary):
self.item = anomalyItem
self.alternateName = items.getAlternateName(self.item)
# Set a random location
self.locationX = random.randint(boundary[0], boundary[2])
self.locationY = random.randint(boundary[1], boundary[3])
# To encapsulate most probot logic
# Having launch and retrieve here allows for asynchronous operations.
# Note: We assume the bounding box has already been scaled.
class Probot(object):
def __init__(self, x, y, xEnd, yEnd, landBoundary):
self.probotLaunched = False
self.probotDestroyed = False
self.probotRetrieving = False
self.haveCargo = False
self.anomaly = "placeholder" # For tracking anomaly retrieval.
self.planetPosition = [0, 0] # Red dot position on scanner
self.travelDirection = [0, 0] # Stop movement jitter.
self.dataTarget = [0, 0] # Target point for investigation.
self.landBoundary = landBoundary
self.dataGathered = 0 # 100% = 1000
self.scanType = -1
self.fuel = 50 # 100% = approx 50 seconds, can be set on landing.
# Status, in order from 0:
# Docked, Deployed, Orbiting, Gathering, Analyzing, Returning,
# Refueling.
self.status = 0
# Probot timer for current runtime.
# Use stopwatch, careful, results might be "unrealistic."
self.timer = h.StopWatch()
self.timerLastCheck = 0.0 # Used for minor time checks.
# Time limit for current stage, semi-random.
self.statusTimeLimit = 0.0
# Operation times, basing on real-world seconds elapsed.
# Something seems a bit off, adjusting from original logic.
self.timeLimit = 50.0
self.deployedTimeLimit = 2.0 # 15.0
self.orbitingTimeLimit = 3.0 # 10.0
self.gatheringTimeLimit = 10.0
#self.analyzingTimeLimit = 10.0
self.returningTimeLimit = 5.0 # 25.0
self.refuelingTimeLimit = 5.0
# Probots have 4 acivity monitors on main screen, these are the
# bounding-box positions.
self.BoundingBox = (x, y, xEnd, yEnd)
self.BoundingBoxScaled = (int((g.width/320)*x),
int((g.height/200)*y),
int((g.width/320)*xEnd),
int((g.height/200)*yEnd))
self.textPosition = [int((g.width/320)*x),
int((g.height/200)*(yEnd))]
# Descriptors
self.probotFeedback = ["Docked", "Deployed", "Orbiting", "Gathering",
"Analyzing", "Returning", "Refueling",
"Destroyed"]
# Reset the timer.
def resetTimer(self):
self.timer.resetStopwatch()
# Reset probot to default state.
def resetProbot(self):
self.probotLaunched = False
self.probotDestroyed = False
self.probotRetrieving = False
self.haveCargo = False
self.anomaly = "placeholder"
self.planetPosition = [0, 0] # Red dot position on scanner
self.travelDirection = [0, 0]
self.dataGathered = 0
self.scanType = -1
self.fuel = 50.0
self.status = 0
self.timer.resetStopwatch()
self.statusTimeLimit = 0.0
self.timerLastCheck = 0.0
# Refuel the probot.
def refuelProbot(self):
self.fuel = 50.0 # Approx real-World flight seconds.
# Check to see if the probot needs to be drawn on the planet view.
def shouldDraw(self):
yes = False
if self.status in [3, 4]:
yes = True
return yes
# Set a data target
def setDataTarget(self):
if self.probotRetrieving:
try:
self.dataTarget = [self.anomaly.locationX,
self.anomaly.locationY]
except:
print("Exception:Anomaly:setDataTarget: ", str(self.anomaly))
self.probotRetrieving = False
else:
self.dataTarget = [random.randint(self.landBoundary[0],
self.landBoundary[2]),
random.randint(self.landBoundary[1],
self.landBoundary[3])]
# Set Stage Time Limit according to current stage and set timer.
def setCurrentStageTimeLimit(self):
if self.status == 1:
self.statusTimeLimit = self.deployedTimeLimit
elif self.status == 2:
self.statusTimeLimit = self.orbitingTimeLimit
elif self.status == 3:
self.statusTimeLimit = self.gatheringTimeLimit
elif self.status == 4: # Shouldn't hit unless on target.
self.statusTimeLimit = random.randrange(0, 7)
#80.0 + random.randrange(0, 50) # ridiculous.
elif self.status == 5:
self.statusTimeLimit = self.returningTimeLimit
else:
self.statusTimeLimit = self.refuelingTimeLimit
self.timer.setStopwatch()
# Check if stage time limit has been exceeded or matched.
# Returns True if time exceeded, False otherwise.
def checkTimeLimitReached(self):
exceeded = False
if self.timer.getElapsedStopwatch() >= self.statusTimeLimit:
exceeded = True
return exceeded
# Return the current amount of time elapsed for the Probot, for this
# operation stage. Int return value.
def stageTimeElapsed(self):
return int(self.timer.getElapsedStopwatch())
# Make the red dot for the probot move around.
# Use retrieve check, if True then use retrieval logic.
def move(self):
if self.planetPosition[0] > self.dataTarget[0]:
self.travelDirection[0] = -1
elif self.planetPosition[0] < self.dataTarget[0]:
self.travelDirection[0] = 1
else:
self.travelDirection[0] = 0
if self.planetPosition[1] > self.dataTarget[1]:
self.travelDirection[1] = -1
elif self.planetPosition[1] < self.dataTarget[1]:
self.travelDirection[1] = 1
else:
self.travelDirection[1] = 0
applied = [self.planetPosition[0] + self.travelDirection[0],
self.planetPosition[1] + self.travelDirection[1]]
# We are wrapping from the edges, this is a planet, not a sheet
# with walls.
if applied[0] > self.landBoundary[2]:
applied = [self.landBoundary[0], applied[1]]
elif applied[0] < self.landBoundary[0]:
applied = [self.landBoundary[2], applied[1]]
if applied[1] > self.landBoundary[3]:
applied = [applied[0], self.landBoundary[1]]
elif applied[1] < self.landBoundary[1]:
applied = [applied[0], self.landBoundary[3]]
if self.status == 3:
self.planetPosition = applied
# Don't move when Analysing.
if (applied == self.dataTarget) and (self.status != 4):
self.status = 4
# Analysis time is semi-random
self.setCurrentStageTimeLimit()
if self.timer.getTime() - self.timerLastCheck >= 1.0:
# Use fuel
self.fuel -= 1.0
self.timerLastCheck = self.timer.getTime()
# Launch the probot.
def launch(self):
if self.status == 0:
self.status = 1 # Deployed
self.probotLaunched = True
self.setCurrentStageTimeLimit()
# Perform probot tick related functions.
def tick(self, crewMembers):
if self.fuel <= 0.0 or self.dataGathered >= 500:
if self.status != 5 and self.status != 6:
#print("Set Status 5")
self.status = 5
self.setCurrentStageTimeLimit()
if self.probotLaunched:
if self.checkTimeLimitReached():
if self.status == 6:
#print("Status 6: Refueled")
self.refuelProbot()
self.status = 1
elif self.status == 4:
# Increment data gathered here.
# Note: First time crew member skills + stress actually used in this engine.
# Note: After testing, it's frankly not a good idea.
self.dataGathered += 500 # int((crewMembers.skillRange(crewMembers.science, 5, 10) + 20) * (10 / 100))
self.status = 3
self.setDataTarget()
else:
self.status += 1
self.setCurrentStageTimeLimit()
if self.status == 3 or self.status == 4:
self.move()
else:
self.setDataTarget()
if self.probotRetrieving:
if self.checkTimeLimitReached():
if self.status == 4: # Temp, adjust logic later.
self.haveCargo = True
self.status = 5
elif self.status == 6:
self.status = 0
self.probotRetrieving = False
self.refuelProbot()
else:
self.status += 1
self.setCurrentStageTimeLimit()
if self.status == 3 or self.status == 4:
self.move()
else:
self.setDataTarget()
# We reset our timer every second.
#if self.timer.getTime() - self.timerLastCheck >= 1.0:
# self.timerLastCheck = self.timer.getTime()
# This class is essentially a mini-game called "The planet scanner" ;)
# The original game logic is relatively sophisticated, analysing individual
# pixels the probot is examining, looking to see if they match the "right"
# type of data the probot is seeking + how rich the data is.
# To support the above, the Planet class in planets.py needs to be expanded,
# so that individual pixels can be tested via targetted procedural generation.
# Note: The original code is not too creative with "interference" from the
# "natives", I believe here is a lot of potential there; Roswell? ;)
class PlanetScanner(object):
def __init__(self, playerShip, crewMembers):
self.scannerStage = 0 # what we are doing.
self.ironSeed = playerShip
self.crewMembers = crewMembers
self.probotCount = self.ironSeed.getItemQuantity("Probot")
# atmosphere, hydrosphere, lithosphere, biosphere, anomaly
self.scanning = [False, False, False, False, False]
self.scanned = [0, 0, 0, 0, 0] # Historically 0 to 2
self.dataCollected = [0, 0, 0, 0, 0] # Historically 1000 per point.
self.scanningComplete = False
# Which scan window data is displaying right now?
# Also, state 4 turns off full-panel summary and displays land map
# again, with strobing anomalies.
self.scanDisplay = 5 # 5 is the scan progress screen.
# Which line are we displaying from in the scan data list?
self.scanDisplayLine = 0
# Anomaly items with locations.
self.anomalies = []
# Descriptors
self.probotFeedback = ["Docked", "Deployed", "Orbiting", "Gathering",
"Analyzing", "Returning", "Refueling",
"Destroyed", "Docked"]
self.scanTypes = ["Atmosphere", "Hydrosphere", "Lithosphere",
"Biosphere", "Anomaly"]
self.planetActivity = ["None", "Calm", "Mild", "Moderate", "Heavy",
"Massive"]
self.planetTemperature = ["SubArctic", "Arctic", "Cold", "Cool",
"Moderate", "Warm", "Tropical", "Searing",
"Infernal"]
self.planetState = ["Gaseous", "Active", "Stable", "Early Life",
"Advanced Life", "Dying", "Dead"]
self.starState = ["Red Star", "Yellow Star", "White Star"]
self.lifeformDiet = ["Carnivorous", "Herbivourous", "Omnivorous",
"Cannibalistic", "Photosynthetic"]
self.lifeforms = ["Avian", "Monoped", "Biped", "Triped", "Quadraped",
"Octaped", "Aquatics", "Fungi", "Carniferns",
"Crystalline", "Symbiots", "Floaters"]
self.lifeNumbers = ["No Life", "Uncomputable", "000", " Million",
" Billion", " Trillion"]
self.protoLife = ["Short Chain Proteins", "Long Chain Proteins",
"Simple Protoplasms", "Complex Protoplasms"]
self.primativeLife = ["Single Celled", "Chaosms", "Communes",
"Heirarchies"]
self.lifeIntelligence = ["No Intelligence", "Instinctual", "Hive Mind",
"Inherited", "Societies", "Telepathic",
"Cybernetics", "Transcendent", "Unknowable"]
# Scan Data Text
self.scanDataText = ["Information Gathered", " Atmosphere...",
" Hydrosphere..", " Lithosphere..",
" Biosphere....", " Anomaly......", "0/2", "1/2",
"Completed."]
# Planet data summary text.
self.dataSummary = ["Planet Summary", "Star Summary",
"Seismic Activity", "Atmospheric Activity",
"Atmospheric Pressure", "Relative Gravity",
"Percent Hydro", "Percent Bio", "Life Forms",
"Population", "Technology Level", "Temperature",
"Surface Radiation", "Planet State",
"Star Classification", "Most Common Compounds"]
# Actual planet Data summary
self.planetData = []
self.planetDataDone = False
# Scan data names based on planet scan data.
self.scanElementNameData = [] # Tuples of (name, state)
self.scanElementNameDataState = False
# Element distribution based on scan data.
self.elementDistributionSummary = [] # Tuples of (name, quantity)
self.elementDistributionSummaryState = False
# ScanData sublists.
self.scanDataSubLists = [[], [], [], [], []] # list of lists.
self.scanDataSubListsDone = False
# Planet Scanner related graphics layers.
self.scanInterface = pygame.image.load(os.path.join('Graphics_Assets', 'landform.png'))
self.scanInterfaceScaled = pygame.transform.scale(self.scanInterface, (g.width, g.height))
self.scanInterfaceScaled.set_colorkey(g.BLACK)
# Scanner green text frames.
self.greenTextFrames = []
self.prepareGreenTextFrames()
# Landform bounding area for planet texture
self.mainViewBoundary = (int((g.width/320)*28),
int((g.height/200)*13),
int((g.width/320)*267),
int((g.height/200)*132))
# Blank texture for the view window.
self.mainViewBlank = pygame.Surface((self.mainViewBoundary[2]-self.mainViewBoundary[0],
self.mainViewBoundary[3]-self.mainViewBoundary[1]), 0)
# Planet texture scaled to the Landform Bounding area.
self.planetTextureScaled = "Placeholder"
# Planet sphere scaled to size of probot monitor
self.miniPlanet = "Placeholder"
# Planet sphere animation frames
self.miniPlanetAnimation = []
# Zoomed view bounding area for zoomed planet texture.
self.zoomedViewBoundary = (int((g.width/320)*206),
int((g.height/200)*140),
int((g.width/320)*265),
int((g.height/200)*198))
# Blank texture for the zoom window.
self.zoomedViewBlank = pygame.Surface((self.zoomedViewBoundary[2]-self.zoomedViewBoundary[0],
self.zoomedViewBoundary[3]-self.zoomedViewBoundary[1]), 0)
# Selected zone for zoomedViewBoundary; default = top left corner.
self.zoomedViewSelected = (int((g.width/320)*28),
int((g.height/200)*13),
int((g.width/320)*59),
int((g.height/200)*59))
self.zoomLevel = 1 # The zoom applied to the zoom view. Max 3.
# Zoom texture for showing zoomed area of landmass.
self.zoomTexture = pygame.Surface((int((g.width/320)*59),
int((g.height/200)*59)),
0)
self.zoomTextureScaled = pygame.transform.scale(self.zoomTexture,
(int((g.width/320)*59),
int((g.height/200)*59)))
# bounding for writing graphic = (28, 13, 18, 15)
# Up to 4 probots can be partaking in a scan
self.probot = [Probot(281, 18, 312, 43, self.mainViewBoundary),
Probot(281, 58, 312, 83, self.mainViewBoundary),
Probot(281, 98, 312, 123, self.mainViewBoundary),
Probot(281, 138, 312, 163, self.mainViewBoundary)]
# Probot frames, Frames have following dimensions:
# 20 wide x 22 high.
# Scan text 281, 18:301, 40.
# Docked 281, 58:301, 80.
# Refueling 281, 98:301, 120.
# Launched and in transit. 281, 138:301, 160.
# When no probot present, blank area of unit with black square.
self.probotScanning = pygame.Surface((31, 24), 0)
self.probotScanning.blit(self.scanInterface, (0, 0), self.probot[0].BoundingBox )
self.probotScanningScaled = pygame.transform.scale(self.probotScanning, (int((g.width/320)*31), int((g.height/200)*24)))
self.probotScanningScaled.set_colorkey(g.BLACK)
self.probotDocked = pygame.Surface((31, 24), 0)
self.probotDocked.blit(self.scanInterface, (0, 0), self.probot[1].BoundingBox )
self.probotDockedScaled = pygame.transform.scale(self.probotDocked, (int((g.width/320)*31), int((g.height/200)*24)))
self.probotRefuel = pygame.Surface((31, 24), 0)
self.probotRefuel.blit(self.scanInterface, (0, 0), self.probot[2].BoundingBox )
self.probotRefuelScaled = pygame.transform.scale(self.probotRefuel, (int((g.width/320)*31), int((g.height/200)*24)))
self.probotTransit = pygame.Surface((31, 24), 0)
self.probotTransit.blit(self.scanInterface, (0, 0), self.probot[3].BoundingBox )
self.probotTransitScaled = pygame.transform.scale(self.probotTransit, (int((g.width/320)*31), int((g.height/200)*24)))
self.probotTransitScaled.set_colorkey(g.BLACK)
self.probotEmpty = pygame.Surface((31, 24), 0)
self.probotEmptyScaled = pygame.transform.scale(self.probotEmpty, (int((g.width/320)*31), int((g.height/200)*24)))
# define button positions: Scaling experiment.
# Note: expect this to be very buggy! Placeholder class in effect.
# Button positions and handler objects.
# Positional buttons for the screen options.
# height, width, (x,y) position
self.land = buttons.Button(int((g.height/200)*8),
int((g.width/320)*21),
(int((g.width/320)*1), int((g.height/200)*21)))
self.sea = buttons.Button(int((g.height/200)*8),
int((g.width/320)*21),
(int((g.width/320)*1), int((g.height/200)*30)))
self.air = buttons.Button(int((g.height/200)*8),
int((g.width/320)*21),
(int((g.width/320)*1), int((g.height/200)*39)))
self.life = buttons.Button(int((g.height/200)*8),
int((g.width/320)*21),
(int((g.width/320)*1), int((g.height/200)*48)))
self.anomaly = buttons.Button(int((g.height/200)*8),
int((g.width/320)*21),
(int((g.width/320)*1), int((g.height/200)*57)))
self.exit = buttons.Button(int((g.height/200)*20),
int((g.width/320)*11),
(int((g.width/320)*11), int((g.height/200)*66)))
self.next = buttons.Button(int((g.height/200)*18),
int((g.width/320)*7),
(int((g.width/320)*135), int((g.height/200)*180)))
self.previous = buttons.Button(int((g.height/200)*18),
int((g.width/320)*7),
(int((g.width/320)*135), int((g.height/200)*146)))
self.zoomIn = buttons.Button(int((g.height/200)*9),
int((g.width/320)*9),
(int((g.width/320)*195), int((g.height/200)*177)))
self.zoomOut = buttons.Button(int((g.height/200)*9),
int((g.width/320)*9),
(int((g.width/320)*195), int((g.height/200)*187)))
self.Retrieve = buttons.Button(int((g.height/200)*26),
int((g.width/320)*48),
(int((g.width/320)*270), int((g.height/200)*173)))
# Special
self.planetMap = buttons.Button(int((g.height/200)*119),
int((g.width/320)*239),
(int((g.width/320)*28), int((g.height/200)*13)))
# The planet object.
self.thePlanet = "placeholder"
# Music/Sound handlers.
self.musicState = False
self.systemState = 5
# Reset the planet scanner back to default starting values.
def resetScanner(self):
self.scannerStage = -1 # Forces reset when we return to scanner.
self.scanning = [False, False, False, False, False]
self.scanned = [0, 0, 0, 0, 0] # Historically 0 to 2
self.dataCollected = [0, 0, 0, 0, 0] # Historically 1000 per point.
self.scanningComplete = False
self.anomalies = []
self.planetData = []
self.planetDataDone = False
self.scanElementNameData = []
self.scanElementNameDataState = False
self.elementDistributionSummary = []
self.elementDistributionSummaryState = False
self.scanDataSubLists = [[], [], [], [], []]
self.scanDataSubListsDone = False
self.zoomLevel = 1
self.musicState = False
# Reset all probots to default state; assume they all get back.
for bot in self.probot:
bot.resetProbot()
# Load green text animation frames
def prepareGreenTextFrames(self):
# 7 units Wide.
for icon in range(1, 6):
# Top and bottom border of 1 pixel.
# Right border of 1 pixel.
# Each frame 20 pixels wide.
# Each frame 13 pixels high.
sourceRectangle = ((icon*28),13, 20, 13 )
frame = pygame.Surface((20, 13))
frame.blit(self.scanInterface,(0, 0), sourceRectangle)
# The resizing procedure does introduce innaccuracy, but
# unavoidable right now.
resizeFrame = pygame.transform.scale(frame, (int((g.width/320)*frame.get_width()), int((g.height/200)*frame.get_height())))
resizeFrame.set_colorkey(g.BLACK)
self.greenTextFrames.append(resizeFrame)
# Create the mini planet animation frames from current mini sphere.
# 5 frames.
def prepareMiniPlanetFrames(self):
# Generate the mini planet for probot travel
preMiniPlanet = pygame.Surface((g.planetHeight, g.planetHeight), 0)
preMiniPlanet.set_colorkey(g.BLACK)
self.thePlanet.planetBitmapToSphere(preMiniPlanet, 0, eclipse = True)
specialX = int((g.width/320)*31) # Scaled correct X
specialY = int(((g.height/200)*24)) # Scaled correct Y.
self.miniPlanet = pygame.transform.scale(preMiniPlanet,
(specialX, specialY))
# We want to step the frames backwards, so we go from small to large.
# /1 is max size after all.
for count in range(3, 0, -1):
tempFrame = pygame.transform.scale(self.miniPlanet, (int(specialX/count), int(specialY/count)))
realFrame = pygame.Surface((specialX, specialY), 0)
realFrame.set_colorkey(g.BLACK)
realFrame.blit(tempFrame, ((specialX-tempFrame.get_width()), 0))
self.miniPlanetAnimation.append(realFrame)
tempFrame = pygame.transform.scale(self.miniPlanet, (specialX, specialY))
self.miniPlanetAnimation.append(tempFrame)
# Launch probots for a scan or retrieval.
def launchProbots(self):
for bot in self.probot:
bot.launch()
# Run an update tick of the probot timer logic.
# Important! If there is an artifact, it must ALWAYS fit!
# If we don't take an artifact onboard, then we can end up breaking the
# story progression, and thats going to result in maximum bug Voodoo.
def probotTick(self):
for bot in self.probot:
bot.tick(self.crewMembers)
if bot.status == 6: # Refueling
if bot.probotRetrieving:
if bot.haveCargo:
#print(bot.anomaly.item)
result = self.ironSeed.addCargo(bot.anomaly.item, 1)
if result[1] == 0:
#print("Item removed and in cargo")
self.thePlanet.removeItemFromCache(bot.anomaly.item)
bot.anomaly = "placeholder"
bot.haveCargo = False
bot.probotRetrieving = False
# Cycle through looking for an anomaly that
# will fit ship, and clear list of those which
# won't. They stay in the planet cache.
while len(self.anomalies) >= 1:
bot.anomaly = self.anomalies.pop()
if self.ironSeed.willThisFit(bot.anomaly.item):
bot.probotRetrieving = True
bot.setDataTarget()
break
else:
bot.resetProbot()
# Shouldn't happen!
else: # Cargo full! Put item back in cache.
#print("Cargo Full, Item in Cache.")
# Assume bot returns it.
bot.anomaly = "placeholder"
# As this was popped, it won't try again.
#bot.resetProbot() # ?
else:
self.incrementScanData(bot.scanType, bot.dataGathered)
bot.dataGathered = 0
if self.scanned[bot.scanType] == 2:
self.scanning[bot.scanType] = False
bot.resetProbot()
# Destroy a quantity of Probots.
# TODO: Make more elaborate with big popup box and report on how it was
# destroyed.
def destroyProbot(self, quantity):
self.ironSeed.removeCargo("Probot", quantity)
self.probotCount = self.ironSeed.getItemQuantity("Probot")
if quantity > 1:
self.ironseed.addMessage( str(quantity) + " Probots Destroyed!", 3)
else:
self.ironseed.addMessage( "Probot Destroyed!", 3)
# The planet we will scan for anomalies etc.
def scanPlanet(self):
pass
# When a planet is scanned for the first time, we add enough items for a
# full cache. This is assuming we have scanned the planet fully.
# Call this only once per planet. Also populates planet cache, in case
# we leave and then come back later.
def createAnomalies(self):
if self.thePlanet.anomalyGeneration == True:
return # Exit without doing anyhing.
if self.thePlanet.systemName == "EXOPID" and self.thePlanet.orbit == 0:
if 28 in g.eventFlags:
self.anomalies.append(Anomaly("Temporal Anchor",
self.mainViewBoundary))
self.anomalies.append(Anomaly("Heavy Corse Grenade",
self.mainViewBoundary))
self.anomalies.append(Anomaly("Heavy Corse Grenade",
self.mainViewBoundary))
self.anomalies.append(Anomaly("Sling of David",
self.mainViewBoundary))
self.anomalies.append(Anomaly("Sling of David",
self.mainViewBoundary))
self.anomalies.append(Anomaly("Thynne Vortex",
self.mainViewBoundary))
self.anomalies.append(Anomaly("Thynne Vortex",
self.mainViewBoundary))
else:
# Set random value to planet seed.
random.seed(self.thePlanet.seed)
for count in range(7):
d100 = random.randint(0, 100)
randomItem = "placeholder"
# The item is determined by the planet state.
if self.thePlanet.state == 0:
if d100 < 25:
randomItem = items.getRandomItem("MATERIAL",
g.totalMaterials)
elif self.thePlanet.state == 1 or self.thePlanet.state == 2:
if d100 < 76:
randomItem = items.getRandomItem("ELEMENT",
g.totalElements)
elif self.thePlanet.state == 3:
if d100 < 51:
randomItem = items.getRandomItem("ELEMENT",
g.totalElements)
elif random.choice([True, False]):
randomItem = items.getRandomItem("MATERIAL",
g.totalMaterials)
else:
randomItem = items.getRandomItem("COMPONENT",
g.totalComponents)
elif self.thePlanet.state == 4:
if d100 < 41:
randomItem = items.getRandomItem("ELEMENT",
g.totalElements)
elif d100 < 71:
randomItem = items.getRandomItem("COMPONENT",
g.totalComponents)
elif d100 == 74 or d100 == 75:
d500 = random.randint(1, 500)
if d500 > 400:
randomItem = items.getItemOfType("ARTIFACT",
d500+100)
else:
randomItem = items.getItemofType("ARTIFACT",
d500)
elif self.thePlanet.state == 5:
if d100 < 66:
if random.choice([True, False]):
randomItem = items.getRandomItem("MATERIAL",
g.totalMaterials)
else:
randomItem = items.getRandomItem("COMPONENT",
g.totalComponents)
elif d100 == 73 or d100 == 74 or d100 == 75:
d500 = random.randint(1, 500)
if d500 > 400:
randomItem = items.getItemOfType("ARTIFACT",
d500+100)
else:
randomItem = items.getItemofType("ARTIFACT",
d500)
else: # Must be 6.
if d100 < 6:
d500 = random.randint(1, 500)
if d500 > 400:
randomItem = items.getItemOfType("ARTIFACT",
d500+100)
else:
randomItem = items.getItemofType("ARTIFACT",
d500)
if randomItem != "placeholder":
#print("RandomItem: ", randomItem)
self.anomalies.append(Anomaly(randomItem,
self.mainViewBoundary))
for anomaly in self.anomalies:
# Fill planet cache with generated items.
self.thePlanet.addItemToCache(anomaly.item)
#print(self.anomalies)
# Reset random number seed.
random.seed()
self.thePlanet.anomalyGeneration = True
# populate the data summary with the new data.
self.generateDataSubLists()
# Retrieve anomalies to put into ship cargo.
# Note: probot actually carries object! Make sure you put it into cargo!
def retrieveAnomalies(self):
# Don't do anything if we haven't scanned everything.
if self.scanningComplete == False:
return
count = 0
for bot in self.probot:
if bot.probotDestroyed == False and bot.probotRetrieving == False:
count += 1
if count <= self.probotCount and len(self.anomalies) > 0:
bot.anomaly = self.anomalies.pop() # Much excitement!
bot.probotRetrieving = True
bot.setDataTarget()
# Test scan data to see if we have scanned everything
def testScanData(self):
allTestedComplete = True
for test in self.scanned:
if test != 2:
allTestedComplete = False
break
return allTestedComplete
# Synchronise scan data with planet.
def planetSynchronise(self):
self.thePlanet.atmosphere = self.scanned[0]
self.thePlanet.hydrosphere = self.scanned[1]
self.thePlanet.lithosphere = self.scanned[2]
self.thePlanet.biosphere = self.scanned[3]
self.thePlanet.anomaly = self.scanned[4]
self.thePlanet.fullyScanned = self.scanningComplete
# Increment the scandata arrays according to the amount of data found
# by a probot.
# Datatype refers to the array position for that data type (0 to 5)
# Amount refers to the data collected, in points.
# 1000 points = 50% of total data collected for dataType, +1 to scanned.
def incrementScanData(self, dataType, amount):
self.dataCollected[dataType] += amount
if self.dataCollected[dataType] >= 500:
if self.dataCollected[dataType] >= 1000:
self.scanned[dataType] = 2
# Generate Anomalies only when all anomaly data collected.