-
Notifications
You must be signed in to change notification settings - Fork 1
/
clworldgen.py
146 lines (136 loc) · 6.83 KB
/
clworldgen.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
# alworldgen.py
# Cepheus Light World Generator by Omer Golan-Joel
# This is open source code, feel free to use it for any purpose
# For any questions, contact me at [email protected]
# Import modules
import stellagama
import worldgenlib
import openpyxl
from openpyxl.styles import Font
import json
import csv
# Functions
def sector_generator(maxrow, maxcolumn):
sector_name = stellagama.savefile("sec")
output = open(sector_name, "w")
output.write(f"{'Hex': <{5}}{'Name': <{13}}{'UWP': <{10}}{'Remarks': <{28}}{'{Ix}': <{6}}{'(Ex)': <{8}}{'[Cx]': <{7}}{'N': <{2}}{'B': <{3}}{'Z': <{2}}{'PBG': <{4}}{'W': <{3}}{'A': <{3}}{'Stellar': <{22}}\n")
output.write("---- ------------ --------- --------------------------- ----- ------- ------ - -- - --- -- -- ----------------------\n")
for column in range(1, maxcolumn + 1):
for row in range(1, maxrow + 1):
if stellagama.dice(1, 6) >= 4:
if row <= 9:
row_location = "0%i" % row
elif row >= 10:
row_location = "%i" % row
if column <= 9:
column_location = "0%i" % column
elif column >= 10:
column_location = "%i" % column
world_hex = column_location + row_location
world = worldgenlib.World(world_hex)
world_string = world.get_world_row() + "\r"
output.write(world_string)
else:
pass
output.close()
def sector_generator_excel(maxrow, maxcolumn):
file_name = stellagama.savefile("xlsx")
sector_name = file_name.strip('.xlsx')
workbook = openpyxl.Workbook()
sheet = workbook.active
sheet.title = sector_name
sheet['A1'] = sector_name
sheet['A1'].font = Font(size=16, bold=True)
sheet['A2'] = "Generated by the Cepheus Light World Generator"
for cell in ["A3", "B3", "C3", "D3", "E3", "F3", 'G3', 'H3', 'I3', 'J3', 'K3', 'L3', 'M3']:
sheet[cell].font = Font(bold=True)
sheet['A3'] = "Hex"
sheet['B3'] = "Starport"
sheet['C3'] = "Size"
sheet['D3'] = "Atmosphere"
sheet['E3'] = "Hydrographics"
sheet['F3'] = "Population"
sheet['G3'] = "Government"
sheet['H3'] = "Law"
sheet['I3'] = "TL"
sheet['J3'] = "Zone"
sheet['K3'] = "Bases"
sheet['L3'] = "Gas Giant"
sheet['M3'] = "Trade Codes"
excel_row = 3
for column in range(1, maxcolumn + 1):
for row in range(1, maxrow + 1):
if stellagama.dice(1, 6) >= 4:
excel_row += 1
if row <= 9:
row_location = "0%i" % row
elif row >= 10:
row_location = "%i" % row
if column <= 9:
column_location = "0%i" % column
elif column >= 10:
column_location = "%i" % column
world_hex = column_location + row_location
world = worldgenlib.World()
sheet.cell(row=excel_row, column=1).value = world_hex
sheet.cell(row=excel_row, column=2).value = world.hex_uwp["starport"]
sheet.cell(row=excel_row, column=3).value = world.hex_uwp["size"]
sheet.cell(row=excel_row, column=4).value = world.hex_uwp["atmosphere"]
sheet.cell(row=excel_row, column=5).value = world.hex_uwp["hydrographics"]
sheet.cell(row=excel_row, column=6).value = world.hex_uwp["population"]
sheet.cell(row=excel_row, column=7).value = world.hex_uwp["government"]
sheet.cell(row=excel_row, column=8).value = world.hex_uwp["law"]
sheet.cell(row=excel_row, column=9).value = world.hex_uwp["tl"]
sheet.cell(row=excel_row, column=10).value = world.zone
sheet.cell(row=excel_row, column=11).value = world.base
sheet.cell(row=excel_row, column=12).value = world.gas_giants
sheet.cell(row=excel_row, column=13).value = world.trade_string
else:
pass
workbook.save(file_name)
def sector_generator_json(maxrow, maxcolumn):
sector_name = stellagama.savefile("json")
sector_dict = {}
for column in range(1, maxcolumn + 1):
sector_dict[column] = {}
for row in range(1, maxrow + 1):
if stellagama.dice(1, 6) >= 4:
if row <= 9:
row_location = "0%i" % row
elif row >= 10:
row_location = "%i" % row
if column <= 9:
column_location = "0%i" % column
elif column >= 10:
column_location = "%i" % column
world_hex = column_location + row_location
world = worldgenlib.World(world_hex)
world_dict = {"hex": world_hex, "name": world.name, "starport": world.uwp_dict["starport"], "size": world.uwp_dict["size"], "atmosphere": world.uwp_dict["atmosphere"], "hydrographics": world.uwp_dict["hydrographics"], "population": world.uwp_dict["population"], "government": world.uwp_dict["government"], "law": world.uwp_dict["law"], "tl": world.uwp_dict["tl"], "zone": world.zone, "base": world.base, "gas_giants": world.gas_giant, "trade": world.trade_string}
sector_dict[column][row] = world_dict
else:
pass
with open(sector_name, 'w') as outfile:
json.dump(sector_dict, outfile)
def sector_generator_csv(maxrow, maxcolumn):
sector_name = stellagama.savefile("csv")
with open (sector_name, 'w') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',',lineterminator='\n',)
for column in range(1, maxcolumn + 1):
for row in range(1, maxrow + 1):
if stellagama.dice(1, 6) >= 4:
if row <= 9:
row_location = "0%i" % row
elif row >= 10:
row_location = "%i" % row
if column <= 9:
column_location = "0%i" % column
elif column >= 10:
column_location = "%i" % column
world_hex = column_location + row_location
world = worldgenlib.World(world_hex)
world_list = [column_location, row_location, world.name, world.uwp_dict["starport"], world.uwp_dict["size"], world.uwp_dict["atmosphere"], world.uwp_dict["hydrographics"], world.uwp_dict["population"], world.uwp_dict["government"], world.uwp_dict["law"], world.uwp_dict["tl"], world.zone, world.base, world.gas_giant, world.trade_string]
csvwriter.writerow(world_list)
else:
pass
if __name__ == "__main__":
sector_generator_json(10, 8)