-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplanets.py
1881 lines (1231 loc) · 66.6 KB
/
planets.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 Tues Dec 17 22:08:18 2019
Planets: Planet and Planet solar system related code.
These really deserve their own class and file.
@author: Nuke Bloodaxe
"""
# State:
# 0: Gaseous, A:Nebula, B:Gas Giant, C:Heavy Atmosphere
# 1: Active, A: Volcanic, B: Semi-Volcanic, C: Land Formation
# 2: Stable, A: Land and Water, B: Slight Vegitation, C: Medium Vegitation (Tech 0)
# 3: Early Life, A: Heavy Vegitation (tech 0), B: Medium Vegitation (tech 1), C: Medium Vegitation (Tech 2)
# 4: Advanced Life, A: Medium Vegitation (tech 3), B:Slight Vegitation (tech 3), C: No Vegitation (Tech 5)
# 5: Dying, A:Ruins, B:Medium Vegitation, C:Dead Rock
# 6: Dead, A:Radiation, B:Asteroid, C:Null
# 7: Star, A:Yellow, B:Red, C:White
# name, State, variation, Life/Technology level
# Check utils2.pas, it contains most planet related details and old algos.
# Explore.pas contains much of the graphics settings for colours and texturing.
# Investigate how to integrate into the planet class.
# Note: System name and planet names combined = 1000 units.
# Although the planet names appear to never have been used, it should be possible to
# add them and an extra 250 entries. The 250 extra entries won't be cannon, but then
# again I believe they will add more class to the game; quite why channel 7 never
# used that file is a mystery for now.
import io, os, pygame, math, random, items
import helper_functions as h
import global_constants as g
PlanetarySystems = {} # Original code indicates these max out at 250.
Planets = {} # Original code indicates these max out at 1000
PlanetNames = []
ScanData = [] # Holds the scan data definitions from scandata.tab.
# ---> Planet state this way, planet grade down.
SystemData = []
class Planet(object):
def __init__(self):
self.name = "UNKNOWN"
self.systemName = "" # Quicker for reverse lookups.
self.index = 0 # Normally our planet number.
self.state = 0
self.grade = 0 # Appears to be "mode" in original code.
self.size = 1
self.radius = 0
self.water = 0
self.vegitationLevel = (0, 0) # New for this engine.
self.age = 0
self.bots = [0, 0, 0] # Mining, Fabricator, Manufactory.
self.depleted = 0 # Have bots completed mining/building/fabricating?
self.notes = 0
self.seed = 0 # Seed used for procedural generation.
self.cache = [] # Item cache, limit of 7 items.
# Visitation date related info:
self.dateMonth = 0
self.dateYear = 0
self.visits = 0
self.orbit = 0 # set this during system generation.
self.outpost = 0 # Extra feature, is this an outpost?
self.owned = 0 # Extra feature, the owner of the planet.
self.anomalyGeneration = False # Have anomalies been generated?
# Planet bitmap of terrain data.
self.planetTerrain = [[0 for i in range(g.planetWidth)] for j in range(g.planetHeight)]
self.eclipsePhase = random.randint(0, 4) # Area covered by eclipse shadow.
# Planet texture related data
self.planetTexture = pygame.Surface((g.planetWidth, g.planetHeight), 0)
self.planetTexture.set_colorkey(g.BLACK)
self.planetTextureExists = False # Have we generated the planet?
# self.createPlanet()
# Note: If you see a system with a star called 'UNKNOWN',
# then you have a serious problem.
# Probot scan related Data points.
# 1 for each hemesphere. When value is 2, scan is complete.
self.lithosphere = 0
self.hydrosphere = 0
self.atmosphere = 0
self.biosphere = 0
self.anomaly = 0
self.fullyScanned = False
# Per pixel data generated, this affects statistical measurements.
self.biologicalLevel = 0
self.biologicalLevelComputed = False
self.waterCoverage = 0
self.waterCoverageComputed = False
# tl2 as it is known in the original code, represents technology
# after the decimal point.
self.technology2 = 0
# New game initialisation, this occurs during the generation phase.
# Results are ultimately saved to save game file for new game.
def generate(self, index, sun = False):
self.index = index
self.seed = random.randint(1, 64000)
random.seed(self.seed)
self.size = random.randint(1, 5)
self.biologicalLevelComputed = False
self.waterCoverageComputed = False
if self.size == 0 or self.size == 1:
self.radius = 900
elif self.size == 2 or self.size == 3:
self.radius = 1095
else:
self.radius = 3000
if sun:
self.age = random.randint(0, 7)
if self.age <= 3:
self.grade = 1
elif self.age >= 4 and self.age <= 5:
self.grade = 2
else:
self.grade = 3
self.state = 7
return
self.state = random.randint(0, 7)
self.water = random.randint(0, 50)
slightVegitation = (self.water, self.water + 10)
mediumVegitation = (self.water, self.water + 50)
heavyVegitation = (self.water, self.water + 150)# The Triffids are loose!
if self.state == 0:
self.age = random.randint(0, 5)
if self.age <= 3:
self.grade = 1
elif self.age >= 4 and self.age <= 5:
self.grade = 2
else:
self.grade = 3
elif self.state == 1:
if self.age <= 4:
self.grade = 1
elif self.age >= 8 and self.age <= 8:
self.grade = 2
else:
self.grade = 3
elif self.state == 2:
self.age = random.randint(0, 64000)*7812
if self.age <= 200000000:
self.grade = 1
elif self.age <= 350000000 and self.age > 200000000:
self.grade = 2
self.vegitationLevel = slightVegitation
else:
self.grade = 3
self.vegitationLevel = mediumVegitation
elif self.state == 3:
self.age = random.randint(0, 15001)*1000
if self.age <= 150000000:
self.grade = 1
self.vegitationLevel = heavyVegitation
elif self.age <= 150005000 and self.age > 150000000:
self.grade = 2
self.vegitationLevel = mediumVegitation
else:
self.grade = 3
self.vegitationLevel = mediumVegitation
elif self.state == 4:
self.age = random.randint(0, 5000)
if self.age <= 2000:
self.grade = 1
self.vegitationLevel = mediumVegitation
elif self.age <= 3000 and self.age > 2000:
self.grade = 2
self.vegitationLevel = slightVegitation
else:
self.grade = 3
elif self.state == 5:
self.age = random.randint(0, 5000)
if self.age <= 1500:
self.grade = 1
elif self.age <= 5500 and self.age > 1500:
self.grade = 2
self.vegitationLevel = mediumVegitation
else:
self.grade = 3
else: # State 6
self.age = random.randint(0, 100)*1000
if self.age > 100000:
self.grade = 1
else:
if random.randint(0, 2) == 0:
self.grade = 3
else:
self.grade = 1
self.age = random.randint(0, 2000)
# Get the technology level of the planet.
# Note: I'm not 100% sure how those values work.
# It is possible that a bit-shift is intended, but that will
# require more research.
# Note: Expanded to include tl2, the population count.
def getTechLevel(self):
if self.orbit == 0:
return 0 # We are a star... although, what about Dyson spheres?
#if self.name == "mars": # Twilight zone, this check doesn't work?!?
# print("I am Mars")
# return 1500
techLevel = -2
self.technology2 = 0
if self.systemName in ["KODUH","OLEZIAS","IYNK","TEVIX","SEKA","WIOTUN"]:
return 6*256 # Really...
if self.systemName == "EXOPID":
if 27 in g.eventFlags:
return 0
else:
return 6*256
if self.state == 2:
if self.grade == 2:
techLevel == -1
elif self.grade == 3:
self.technology2 = self.age / 15000000
techLevel += self.age / 15000000
elif self.state == 3:
techLevel = (self.state - 1) * 256
if self.grade == 1:
self.technology2 = self.age / 15000000
techLevel += self.age / 15000000
elif self.grade == 2:
self.technology2 = self.age / 1000
techLevel += self.age / 1000
elif self.grade == 3:
self.technology2 = self.age / 800
techLevel += self.age / 800
elif self.state == 4:
techLevel = (self.state + 2) * 256
if self.grade == 1:
self.technology2 = self.age / 400
techLevel += self.age / 400
elif self.grade == 2:
self.technology2 = self.age / 200
techLevel += self.age / 200
elif self.state == 5:
if self.grade == 1:
temp = self.age / 100000000
if temp > 9:
temp = 9
self.technology2 = temp
techLevel += temp
elif self.grade == 2:
techLevel = -1
elif self.state == 6:
if self.grade == 2: # Void Dwellers.
techLevel = 6*256
return techLevel
# This effectively ages the planet based on the time since last visit.
# If the planet state changes then all notes, bots and cache items are lost.
def adjustPlanet(self, timePassed):
if self.bots[0] > 0 or self.bots[1] > 0 or self.bots[2] > 0:
if self.depleted == 0:
self.addItems(7) # Historically limit is 7 items.
self.depleted = 1 # Bots have completed job.
self.age += timePassed
oldState = self.state
if self.state == 0:
if self.grade == 1 or self.grade == 2:
if self.age >= 1000000000:
age = 0
self.grade += 1
elif self.grade == 3:
if self.age > 500000000:
self.age = 0
self.grade = 1
self.state = 1
elif self.state == 1:
if self.grade == 1:
if self.age >= 500000000:
self.age = 0
self.grade = 2
elif self.grade == 2:
if self.age >= 400000000:
self.age = 0
self.grade = 3
elif self.grade == 3:
if self.age >= 300000000:
self.age = 0
self.grade = 1
self.state = 2
elif self.state == 2:
if self.grade == 1:
if self.age >= 200000000:
self.age = 0
self.grade = 2
elif self.grade == 2:
if self.age >= 150000000:
self.age = 0
self.grade = 3
elif self.grade == 3:
if self.age >= 150000000:
self.age = 0
self.grade = 1
self.state = 3
if random.randrange(0, 40) == 0:
self.age = 0
self.state = 5
self.grade = 2
elif self.state == 3:
if self.grade == 1:
if self.age >= 15000000:
self.age = 0
self.grade = 2
if random.randrange(0, 40) == 0:
self.age = 0
self.state = 5
self.grade = 2
elif self.grade == 2:
if self.age >= 10000:
self.age = 0
self.grade = 3
elif self.grade == 3:
if self.age >= 8000:
self.age = 0
self.grade = 1
self.state = 4
elif self.state == 4:
if self.grade == 1:
if self.age >= 4000:
self.age = 0
self.grade = 2
elif self.grade == 2:
if self.age >= 2000:
self.age = 0
self.grade = 3
if random.randrange(0, 40) == 0:
self.age = 0
self.state = 6
if random.randrange(0, 2) == 0:
self.grade = 1
else:
self.grade = 2
elif self.grade == 3:
if self.age >= 4000:
self.age = 0
self.grade = 1
self.state = 5
if random.randrange(0, 40) == 0:
self.age = 0
self.grade = 5
self.state = 6
if random.randrange(0, 2) == 0:
self.mode =1
else:
self.mode = 2
elif self.state == 5:
if self.grade == 1:
if self.age >= 3000:
self.age = 0
self.grade = 2
elif self.grade == 2:
if self.age >= 8000:
self.age = 0
self.grade = 3
if random.randrange(0, 40) == 0:
self.age = 0
self.state = 2
self.grade = 3
#Ignore Grade 3.
elif self.state == 6:
if self.state == 1 and age >= 100000:
self.age = 0
self.grade = 2
# Planet changed, catastrophic loss of equipment and info.
if (oldState != self.state):
self.cache = []
self.bots = [0, 0, 0]
self.notes = 0
self.fullyScanned = False
self.lithosphere = 0
self.hydrosphere = 0
self.atmosphere = 0
self.biosphere = 0
self.anomaly = 0
self.biologicalLevel = 0
self.biologicalLevelComputed = False
self.waterCoverage = 0
self.waterCoverageComputed = False
# This function computes the quantities of elements required to make the
# components of a final product (component, material, weapon, shield etc.)
# If the quantities are sufficient to make the final item, return the
# amount that can be produced.
# Note: Evil function.
def getSubQuantities(self, index, itemType, elements, materials):
totalTech = 99
itemName = items.getItemOfType(itemType, index)
if itemName == "Unknown Component":
return 0
temp = items.itemConstructionDictionary[itemName]
for something in range(1, 4): # each item uses 3 things to make.
if items.itemDictionary[temp[something]][2] == "ELEMENT":
quantity = elements[items.findItemInPseudoArray(temp[something])]
elif items.itemDictionary[temp[something]][2] == "MATERIAL":
quantity = materials[items.findItemInPseudoArray(temp[something])]
# This happens when we receive a final product, like a weapon...
elif items.itemDictionary[temp[something]][2] == "COMPONENT":
subIndex = items.findItemInPseudoArray(temp[something])
quantity = self.getSubQuantities(subIndex, "COMPONENT",
elements, materials)
if quantity < totalTech:
totalTech = quantity
return totalTech
# Ge an entry from the scan data.
def getScanDataEntry(self, index, state):
return ScanData[index][state]
# Scans are predefined, so return quantities accordingly.
# This relies on the predefined scan data file being loaded.
def getItemAmounts(self):
elements = []
materials = []
components = []
for index in range(g.totalElements):
elements.append(ScanData[index][self.state])
for index in range(1, g.totalMaterials):
totalTech = 99 # We don't want to shower the players with gifts.
totalYield = 0
item = items.getItemOfType("MATERIAL", index)
temp = items.itemConstructionDictionary[item]
for element in range(1, 4): # each material uses 3 elements to make.
if item != "Worthless Junk" and item != "Unknown Material":
quantity = elements[items.findItemInPseudoArray(temp[element])]
totalYield += quantity
if quantity < totalTech:
totalTech = quantity
if totalTech > 0:
materials.append(totalYield)
else:
materials.append(0)
materials[0] = 0 # No Unknown Material
materials[19] = 0 # No Worthless Junk
# We use the sub category function in here to determine if we have
# enough materials to actually manufacture the component concerned.
for index in range(1, g.totalComponents+1):
components.append(self.getSubQuantities(index, "COMPONENT",
elements, materials))
components[0] = 0 # No unknown Components.
components[20] = 0 # No Ion Cache.
components[21] = 0 # No Thermoplast.
return elements, materials, components
# Add items to the planet, including results of surface mining/manufacturing.
# These are added by name for ease of use in the dictionaries.
# Note: A planet normally has only one bot type, I'm adding this for
# the possibility of a "factory" planet.
# TODO: Function calls need to be corrected to real versions.
def addItems(self, quantityLimit):
if not self.depleted:
elements, materials, components = self.getItemAmounts()
remaining = quantityLimit
total = 0
if self.bots[0] > 0:
for element in elements:
total += element
for index in range(1, 7):
if len(self.cache) < 7:
self.cache.append(items.getRandomItem("ELEMENT", g.totalElements))
remaining -= 1
if len(self.cache) == total or remaining <= 0:
break
if self.bots[1] > 0:
for material in materials:
total += material
for index in range(1, 7):
if len(self.cache) < 7:
self.cache.append(items.getRandomItem("MATERIAL", g.totalMaterials))
remaining -= 1
if len(self.cache) == total or remaining <= 0:
break
if self.bots[2] > 0:
for component in components:
total += component
for index in range(1, 7):
if len(self.cache) < 7:
self.cache.append(items.getRandomItem("COMPONENT", g.totalComponents))
remaining -= 1
if len(self.cache) == total or remaining <= 0:
break
# Add an item to the planet cache.
def addItemToCache(self, item):
self.cache.append(item)
# Remove an item from the planet cache
def removeItemFromCache(self, item):
self.cache.remove(item)
# Create the planet bitmap, which uses the random pixel height-change
# method to raise and lower terrain.
# Areas where technology is present are represented as a bright pixel.
# Note: Colour adjust later. This function is used to draw the planet
# to screen as well...
def createPlanet(self):
# Prepare texture for per-pixel adjustments.
planetSurface = pygame.PixelArray(self.planetTexture)
#print("I am creating a planet: ", self.name)
currentX, currentY = 0, 0
random.seed(self.seed)
step = 0
technologyLevel = self.getTechLevel()
#print("Technology Level is: ", technologyLevel)
for index in range(600000): # 8 x canon version.
step += 1
currentX = currentX-1+random.randrange(0, 3)
currentY = currentY-1+random.randrange(0, 3)
if currentX > g.planetWidth-1:
currentX = 0
elif currentX < 1:
currentX = g.planetWidth-1
if currentY > g.planetHeight-1:
currentY = 0
elif currentY < 1:
currentY = g.planetHeight-1
if self.planetTerrain[currentY][currentX] < 240:
self.planetTerrain[currentY][currentX] += 7
# Avoid random tech pixels, or non-valid colours.
if self.planetTerrain[currentY][currentX] >= 255:
self.planetTerrain[currentY][currentX] = 254
# Make bright spots representing buildings/tech.
if technologyLevel > 0:
#print("Tech Ahoy!: ", technologyLevel)
technologyLevel = (int(technologyLevel) >> 4) * 10 + (int(technologyLevel) & 0x0F)
technologyLevel = technologyLevel * technologyLevel / 10
#print("Adjusted: ", technologyLevel)
# The above evilness is the nearest approximation I can get at the
# moment for what was happening in pascal.
for index in range(int(technologyLevel)):
currentX = random.randrange(0, g.planetWidth - 1)
currentY = random.randrange(0, g.planetHeight - 1)
if self.planetTerrain[currentY][currentX] > self.water:
self.planetTerrain[currentY][currentX] = 255
# TODO: Convert height bitmap to planet graphic in self.planetTexture
# Create a swirl effect, usually for clouds on a gas giant.
def createSwirl(self, currentX, currentY, size):
currentPixel = 0
if currentY <= g.height: # Southern Hemesphere.
if size == 2:
currentPixel = self.planetTerrain[currentY-1][currentX]
self.planetTerrain[currentY-1][currentX] = self.planetTerrain[currentY][currentX+1] - random.randint(1, 3)
self.planetTerrain[currentY][currentX+1] = currentPixel - random.randint(1, 3)
elif size == 3:
currentPixel = self.planetTerrain[currentY-1][currentX]
self.planetTerrain[currentY-1][currentX] = self.planetTerrain[currentY][currentX+2] - random.randint(1, 3)
self.planetTerrain[currentY][currentX+1] = currentPixel - random.randint(1, 3)
currentPixel = self.planetTerrain[currentY-1][currentX+1]
self.planetTerrain[currentY-1][currentX] = self.planetTerrain[currentY][currentX+1] - random.randint(1, 3)
self.planetTerrain[currentY][currentX+1] = currentPixel - random.randint(1,3)
elif size == 4:
currentPixel = self.planetTerrain[currentY-1][currentX]
self.planetTerrain[currentY-1][currentX] = self.planetTerrain[currentY][currentX+3] - random.randint(1, 3)
self.planetTerrain[currentY][currentX+3] = currentPixel - random.randint(1, 3)
currentPixel = self.planetTerrain[currentY-1][currentX+1]
self.planetTerrain[currentY-1][currentX+1] = self.planetTerrain[currentY][currentX+2] - random.randint(1, 3)
self.planetTerrain[currentY][currentX+2] = currentPixel - random.randint(1, 3)
currentPixel = self.planetTerrain[currentY-2][currentX+2]
self.planetTerrain[currentY-2][currentX+2] = self.planetTerrain[currentY+1][currentX+1] - random.randint(1, 3)
self.planetTerrain[currentY+1][currentX+1] = currentPixel - random.randint(1, 3)
currentPixel = self.planetTerrain[currentY-2][currentX+1]
self.planetTerrain[currentY-2][currentX+1] = self.planetTerrain[currentY+1][currentX+2] - random.randint(1, 3)
self.planetTerrain[currentY+1][currentX+2] = currentPixel - random.randint(1, 3)
else: # Northern Hemesphere.
if size == 2:
currentPixel = self.planetTerrain[currentY-1][currentX+1]
self.planetTerrain[currentY-1][currentX+1] = self.planetTerrain[currentY][currentX] - random.randint(1, 3)
self.planetTerrain[currentY][currentX] = currentPixel - random.randint(1, 3)
elif size == 3:
currentPixel = self.planetTerrain[currentY][currentX]
self.planetTerrain[currentY][currentX] = self.planetTerrain[currentY-1][currentX+2] - random.randint(1, 3)
self.planetTerrain[currentY-1][currentX+2] = currentPixel - random.randint(1, 3)
currentPixel = self.planetTerrain[currentY-1][currentX+1]
self.planetTerrain[currentY-1][currentX+1] = self.planetTerrain[currentY][currentX+1] - random.randint(1, 3)
self.planetTerrain[currentY][currentX+1] = currentPixel - random.randint(1, 3)
elif size == 4:
currentPixel = self.planetTerrain[currentY][currentX]
self.planetTerrain[currentY][currentX] = self.planetTerrain[currentY-1][currentX+3] - random.randint(1, 3)
self.planetTerrain[currentY-1][currentX+3] = currentPixel - random.randint(1, 3)
currentPixel = self.planetTerrain[currentY][currentX+1]
self.planetTerrain[currentY][currentX+1] = self.planetTerrain[currentY-1][currentX+2] - random.randint(1, 3)
self.planetTerrain[currentY-1][currentX+2] = currentPixel - random.randint(1, 3)
currentPixel = self.planetTerrain[currentY-2][currentX+2]
self.planetTerrain[currentY-2][currentX+2] = self.planetTerrain[currentY+1][currentX+1] - random.randint(1, 3)
self.planetTerrain[currentY+1][currentX+1] = currentPixel - random.randint(1, 3)
currentPixel = self.planetTerrain[currentY-2][currentX+1]
self.planetTerrain[currentY-2][currentX+1] = self.planetTerrain[currentY+1][currentX+2] - random.randint(1, 3)
self.planetTerrain[currentY+1][currentX+2] = currentPixel - random.randint(1, 3)
# Create a Gas Planet bitmap.
def createGasPlanet(self):
currentX, currentY = 0
random.seed(self.seed)
#step = 0
colours = [0, 0, 0]
# You never know, there might be blimp people...
#technologyLevel = self.getTechLevel(self.systemName)
# What horrible colours shall we choose?
if random.randint(0, 2) > 0:
colours[0] = 32
colours[1] = 48
colours[2] = 64
else:
colours[0] = 112
colours[1] = 128
colours[2] = 96
# Create the atmospheric bands of "gas". Who knows what the Blimp
# People have been doing...
areas = 1
bandColour = 0
for YPosition in range(int(g.height/2), 0, -1):
areas -= 1
if areas == 0:
areas = (int(g.height/2) - abs(YPosition - int(g.height/2))) / 10
areas = areas + 6 + random.randint(0, areas + 5)
if (areas < YPosition) and ((areas + 5) > YPosition):
areas = YPosition >> 1 # bit shift by 1 right.
bandColour = (bandColour + random.randint(0, 2) + 1) % 3
if bandColour == 0:
bandColour = colours[0] + 8 + random.randint(0, 5)
elif bandColour == 1:
bandColour = colours[1] + 8 + random.randint(0, 5)
else:
bandColour = colours[2] + 8 + random.randint(0, 5)
for XPosition in range(0, int(g.width)):
self.planetTerrain[YPosition][XPosition] = bandColour + random.randint(0, 2)
self.planetTerrain[g.height-YPosition][XPosition] = bandColour + random.randint(0, 2)
# Create areas of turbulance between bands, aka the Jupiter look.
for YPosition in range(3, g.height):
if (self.planetTerrain[YPosition][1] & 0xF0) != (self.planetTerrain[YPosition-1][1] & 0xF0):
XPosition = 1
while XPosition <= g.width:
band = random.randint(0, 4) + 1
if band + XPosition > g.height:
band = g.height - XPosition
self.createSwirl(XPosition,YPosition,band)
XPosition += band
YPosition += 2
# Create Spots: this was pretty dire in the code...
spotCount = 6 + random.randint(0, 5)
spotSize = 0
for spot in range(1, spotCount):
colour = random.randint(0, 2)
if colour == 0:
colour = colours[0] + 2 + random.randint(0, 4)
elif colour == 1:
colour = colours[1] + 2 + random.randint(0, 4)
else:
colour = colours[2] + 2 + random.randint(0, 4)
if spot == 1:
spotSize = 15 + random.randint(1, 5)
else:
spotSize = 2 + random.randint(1, 6)
spotSize2 = spotSize * spotSize
spotSize21 = (spotSize - 1) * (spotSize - 1)
spotSize22 = (spotSize - 2) * (spotSize - 2)
XPosition = random.randint(0, g.width)
YPosition = random.randint(0, (g.height-10)-(2*spotSize)) + 5 + spotSize