-
Notifications
You must be signed in to change notification settings - Fork 1
/
PyMapGen.py
511 lines (456 loc) · 21.1 KB
/
PyMapGen.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
#
#
# Display a map from Traveller 5.10 sector data
#
#####################################################################
"""
PyMapGen 0.2.7 Beta
-------------------
This program displays Traveller 5 sectors and subsectors.
The Traveller game in all forms is owned by Far Future Enterprises.
Copyright 1977 - 2024 Far Future Enterprises.
Traveller is a registered trademark of Far Future Enterprises.
"""
import pyttsx3
import pygame
from pygame.locals import *
import time
import sys
from mapper import display_map
import os
import logging
from constants import *
from constants import __app__
from constants import __version__
from constants import __py_version_req__
engine = pyttsx3.init()
voice_list = engine.getProperty('voices')
voices = []
voice = {}
rate = -50
volume = 1.0
for i in voice_list:
rec = {}
name_found = i.name[i.name.find(' ')+1:]
name_found = name_found[:name_found.find(' ')]
voices.append(name_found)
rec['Name'] = i.id
rec['Rate'] = rate
rec['Volume'] = volume
voice[name_found] = rec
num_voices = len(voice)
rate = engine.getProperty('rate')
volume = engine.getProperty('volume')
sector = {'Solomani Rim': (0, -3), 'Old Expanses': (1, -2), 'Fornast': (1, 0),
'Delphi': (1, -1), 'Drakken': (3, -4), 'Langere': (2, -4),
'Magyar': (-1, -3), 'Aktifao': (-4, -4), 'Ealiyasiyw': (-3, -2),
'Corridor': (-2, 1), 'Canopus': (-1, -4), 'Riftspan Reaches': (-4, -1),
'Core': (0, 0), 'Spinward Marches': (-4, 1), 'Hinterworlds': (2, -2),
'Aldebaran': (0, -4), 'Leonidae': (3, -2), 'Vland': (-1, 1),
'Gushemege': (-2, 0), 'Lishun': (0, 1), 'Antares': (1, 1),
'Zarushagar': (-1, -1), 'Daibei': (-1, -2), 'Ley': (2, 0),
'Spica': (2, -3), 'Massilia': (0, -1), 'Neworld': (1, -4),
'Glimmerdrift Reaches': (2, -1), 'Crucis Margin': (3, -1),
'Alpha Crucis': (1, -3), "Reaver's Deep": (-2, -2),
"Star's End": (3, 1), 'Iwahfuah': (-3, -3), 'Diaspora': (0, -2),
'Trojan Reach': (-4, 0), 'Ilelish': (-2, -1), 'Empty Quarter': (2, 1),
'Dark Nebula': (-2, -3), 'Ustral Quadrant': (-2, -4), 'Phlask': (3, -3),
'Deneb': (-3, 1), 'Uistilrao': (-3, -4), "Staihaia'yo": (-4, -3),
'Reft': (-3, 0), 'Verge': (-3, -1), 'Dagudashaag': (-1, 0),
'Gateway': (3, 0), 'Hlakhoi': (-4, -2), 'Ziafrplians': (-5, 2),
'Gvurrdon': (-4, 2), 'Foreven': (-5, 1), 'Tuglikki': (-3, 2),
'Stiatlchepr': (-6, 3), 'Provence': (-2, 2), 'Itvikiastaf': (-5, 3),
'Tienspevnekr': (-6, 2), 'Zdiedeiant': (-7,3)
}
XORG_SECTOR, YORG_SECTOR = sector['Core']
__author__ = 'Shawn Driscoll <shawndriscoll@hotmail.com>\nshawndriscoll.blogspot.com'
#clock = pygame.time.Clock()
def main(voice_muted, grid_style, zone_style, trade_code, see_thru, show_loc, show_grid):
xx = XORG_SECTOR
yy = YORG_SECTOR
subxx = 0
subyy = 0
x_zoom_in_level_1_matrix = [-2, -1, -1, 0, 0, 1, 1, 2]
y_zoom_in_level_1_matrix = [-1, 0, 0, 1]
x_zoom_in_level_2_matrix = [-1, 0, 0, 1]
y_zoom_in_level_2_matrix = [0, 1]
x_zoom_out_level_2_matrix = [-1, 0, 0, 1]
y_zoom_out_level_2_matrix = [0, 0]
x_zoom_out_level_4_matrix = [0, 0]
y_zoom_out_level_4_matrix = [0]
zoom = 1
zooming = False
# zoom and draw_style are optional with this call here
# zoom = 1 to 4 (default is 1)
# draw_style = 'HEX_grid_18', 'HEX_grid_20', or 'RECT_grid' (default is 'RECT_grid')
voiced_sector_name = display_map(xx, yy)
if not voice_muted:
# some text to speak
if voiced_sector_name != 'BLANK':
text = 'displaying area near the ' + voiced_sector_name + ' sector'
else:
text = 'this area is unexplored'
engine.say(text)
engine.runAndWait()
still_displaying = True
while still_displaying:
temp_muted = False
event_scanning = True
while event_scanning:
event = pygame.event.wait()
#for event in pygame.event.get():
#print event.type
if event.type == QUIT:
still_displaying = False
event_scanning = False
elif event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
x_mouse_down_pos, y_mouse_down_pos = pos
if event.button == 4:
#Zooming in
zooming = True
if zoom == 1:
x_sector_coord = int(x_mouse_down_pos / (32*X_SPACING*zoom))
y_sector_coord = int(y_mouse_down_pos / (40*Y_SPACING*zoom))
x_location = x_zoom_in_level_1_matrix[x_sector_coord]
y_location = y_zoom_in_level_1_matrix[y_sector_coord]
xx += x_location
yy += -y_location
elif zoom == 2:
x_sector_coord = int(x_mouse_down_pos / (32*X_SPACING*zoom))
y_sector_coord = int(y_mouse_down_pos / (40*Y_SPACING*zoom))
x_location = x_zoom_in_level_2_matrix[x_sector_coord]
y_location = y_zoom_in_level_2_matrix[y_sector_coord]
xx += x_location
yy += -y_location
elif zoom == 4:
x_sector_coord = int(x_mouse_down_pos / (32*X_SPACING*zoom))
y_sector_coord = int(y_mouse_down_pos / (40*Y_SPACING*zoom))
temp_xx = xx
temp_yy = yy
xx += x_sector_coord-1
subxx = 0
subyy = 0
elif zoom == 8:
pass
zoom += 1
if zoom == 3:
zoom = 4
if zoom == 5:
zoom = 8
event_scanning = False
if zoom > 8:
zoom = 8
event_scanning = True
elif event.button == 5:
#zooming out
zooming = True
if zoom == 1:
pass
elif zoom == 2:
x_sector_coord = int(x_mouse_down_pos / (32*X_SPACING*zoom))
y_sector_coord = int(y_mouse_down_pos / (40*Y_SPACING*zoom))
x_location = x_zoom_out_level_2_matrix[x_sector_coord]
y_location = y_zoom_out_level_2_matrix[y_sector_coord]
xx += x_location
yy += -y_location
elif zoom == 4:
x_sector_coord = int(x_mouse_down_pos / (32*X_SPACING*zoom))
y_sector_coord = int(y_mouse_down_pos / (40*Y_SPACING*zoom))
x_location = x_zoom_out_level_4_matrix[x_sector_coord]
y_location = y_zoom_out_level_4_matrix[y_sector_coord]
xx += x_location
yy += -y_location
elif zoom == 8:
xx = temp_xx
yy = temp_yy
zoom += -1
if zoom == 7:
zoom = 4
if zoom == 3:
zoom = 2
event_scanning = False
if zoom < 1:
zoom = 1
event_scanning = True
elif event.type == pygame.MOUSEBUTTONUP:
if not zooming:
pos = pygame.mouse.get_pos()
x_mouse_up_pos, y_mouse_up_pos = pos
if zoom == 1:
if x_mouse_down_pos == x_mouse_up_pos and y_mouse_down_pos == y_mouse_up_pos:
# sector was clicked on
x_sector_distance = int(x_mouse_up_pos / (32*X_SPACING*zoom)) - 4
y_sector_distance = int(y_mouse_up_pos / (40*Y_SPACING*zoom)) - 1
if x_sector_distance != 0 or y_sector_distance != 0:
# origin sector was not clicked on
xx += x_sector_distance
yy += -y_sector_distance
event_scanning = False
else:
# mouse button was dragged
x_mouse_distance = x_mouse_up_pos - x_mouse_down_pos
y_mouse_distance = y_mouse_up_pos - y_mouse_down_pos
columns_moved = int(x_mouse_distance / (32*X_SPACING*zoom+.5))
rows_moved = int(y_mouse_distance / (40*Y_SPACING*zoom+.5))
if columns_moved != 0 or rows_moved != 0:
xx += -columns_moved
yy += rows_moved
event_scanning = False
elif zoom == 2:
if x_mouse_down_pos == x_mouse_up_pos and y_mouse_down_pos == y_mouse_up_pos:
# sector was clicked on
x_sector_distance = int(x_mouse_up_pos / (32*X_SPACING*zoom)) - 2
y_sector_distance = int(y_mouse_up_pos / (40*Y_SPACING*zoom))
if x_sector_distance <= -2:
xx += -1
if x_sector_distance >= 1:
xx += 1
if x_sector_distance >= -1 and x_sector_distance <= 0:
if y_sector_distance == 0:
yy += 1
else:
yy += -1
event_scanning = False
else:
# mouse button was dragged
x_mouse_distance = x_mouse_up_pos - x_mouse_down_pos
y_mouse_distance = y_mouse_up_pos - y_mouse_down_pos
columns_moved = int(x_mouse_distance / (32*X_SPACING*zoom+.5))
rows_moved = int(y_mouse_distance / (40*Y_SPACING*zoom+.5))
if columns_moved != 0 or rows_moved != 0:
xx += -columns_moved
yy += rows_moved
event_scanning = False
elif zoom == 4:
if x_mouse_down_pos == x_mouse_up_pos and y_mouse_down_pos == y_mouse_up_pos:
# sector was clicked on
x_sector_distance = int(x_mouse_up_pos / (32*X_SPACING*zoom)) - 1
y_sector_distance = int(y_mouse_up_pos / (40*Y_SPACING*zoom))
if x_sector_distance == 0:
xx += 1
else:
xx += -1
event_scanning = False
else:
# mouse button was dragged
x_mouse_distance = x_mouse_up_pos - x_mouse_down_pos
y_mouse_distance = y_mouse_up_pos - y_mouse_down_pos
columns_moved = int(x_mouse_distance / (32*X_SPACING*zoom+.5))
rows_moved = int(y_mouse_distance / (40*Y_SPACING*zoom+.5))
if columns_moved != 0 or rows_moved != 0:
xx += -columns_moved
yy += rows_moved
event_scanning = False
else:
zooming = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if zoom == 8:
subxx += -1
if subxx < 0:
subxx = 0
else:
event_scanning = False
else:
xx += -1
event_scanning = False
elif event.key == pygame.K_RIGHT:
if zoom == 8:
subxx += 1
if subxx > 2:
subxx = 2
else:
event_scanning = False
else:
xx += 1
event_scanning = False
elif event.key == pygame.K_UP:
if zoom == 8:
subyy += -1
if subyy < 0:
subyy = 0
else:
event_scanning = False
else:
yy += 1
event_scanning = False
elif event.key == pygame.K_DOWN:
if zoom == 8:
subyy += 1
if subyy > 3:
subyy = 3
else:
event_scanning = False
else:
yy += -1
event_scanning = False
elif event.key == pygame.K_0:
if not voice_muted:
text = 'muting'
voice_muted = True
engine.say(text)
engine.runAndWait()
elif event.key >= 49 and event.key <= num_voices + 48:
speaker = voices[event.key - 49]
voice_muted = False
engine.setProperty('rate', rate + voice[speaker]['Rate'])
engine.setProperty('volume', volume + voice[speaker]['Volume'])
engine.setProperty('voice', voice[speaker]['Name'])
text = 'vocalizations for ' + speaker + ' enabled'
engine.say(text)
engine.runAndWait()
elif event.key == pygame.K_h:
temp_muted = True
if zoom == 8:
grid_style = 'HEX_grid_40'
else:
if grid_style == 'HEX_grid_20':
grid_style = 'HEX_grid_18'
else:
grid_style = 'HEX_grid_20'
event_scanning = False
elif event.key == pygame.K_r:
temp_muted = True
grid_style = 'RECT_grid'
event_scanning = False
elif event.key == pygame.K_c:
temp_muted = True
see_thru = not see_thru
event_scanning = False
elif event.key == pygame.K_z:
temp_muted = True
if zone_style == 'fixed':
zone_style = 'circled'
else:
zone_style = 'fixed'
event_scanning = False
elif event.key == pygame.K_t:
temp_muted = True
trade_code = not trade_code
event_scanning = False
elif event.key == pygame.K_l:
temp_muted = True
show_loc = not show_loc
event_scanning = False
elif event.key == pygame.K_g:
temp_muted = True
show_grid = not show_grid
event_scanning = False
elif event.key == pygame.K_ESCAPE:
still_displaying = False
event_scanning = False
# msElapsed = clock.tick(30)
if not event_scanning and still_displaying:
if zoom == 8:
if grid_style == 'HEX_grid_18' or grid_style == 'HEX_grid_20':
grid_style = 'HEX_grid_40'
voiced_sector_name = display_map(xx, yy, zoom, grid_style, zone_style, trade_code, see_thru, show_loc, show_grid, subxx, subyy)
if zoom == 8:
if grid_style == 'HEX_grid_40':
grid_style = 'HEX_grid_20'
if not voice_muted and not temp_muted:
# some text to speak
if zoom == 1:
if voiced_sector_name != 'BLANK':
text = 'displaying area near the ' + voiced_sector_name + ' sector'
else:
text = 'this area is unexplored'
elif zoom == 4:
if voiced_sector_name == []:
text = 'this area is unexplored'
elif len(voiced_sector_name) == 2:
text = 'displaying both the ' + voiced_sector_name[0] + ' and ' + voiced_sector_name[1] + ' sectors'
else:
text = 'displaying the ' + voiced_sector_name[0] + ' sector'
elif zoom == 8:
if voiced_sector_name == []:
text = 'this area is unexplored'
else:
text = 'displaying both the ' + voiced_sector_name[0] + ' and ' + voiced_sector_name[1] + ' subsectors'
if zoom == 1 or zoom == 4 or zoom == 8:
#print text
engine.say(text)
engine.runAndWait()
print('Exiting ' + __app__)
log.info(__app__ + ' closing...')
log.info('Logging ended.')
if not voice_muted:
# some text to speak
text = 'Exiting ' + __app__
engine.say(text)
engine.runAndWait()
if __name__ == '__main__':
voice_muted = True
grid_style = 'RECT_grid'
zone_style = 'circled'
trade_code = False
see_thru = False
show_loc = True
show_grid = True
if not voice_muted:
# some text to speak
text = 'Starting ' + __app__
engine.say(text)
engine.runAndWait()
log = logging.getLogger('PyMapGen')
log.setLevel(logging.DEBUG)
if not os.path.exists('Logs'):
os.mkdir('Logs')
fh = logging.FileHandler('Logs/pymapgen.log', 'w')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s - %(message)s',
datefmt = '%a, %d %b %Y %H:%M:%S')
fh.setFormatter(formatter)
log.addHandler(fh)
log.info('Logging started.')
log.info(__app__ + ' starting...')
trange = time.localtime()
if trange[0] > 2031 or trange[1] > 12:
log.info(__app__ + ' EXPIRED.')
print()
print(__app__, 'EXPIRED.')
print()
print(__author__)
print()
s = input('Press ENTER: ')
print("OK")
else:
print()
print('Thank you for giving', __app__, 'a try.')
print()
print('This program uses:')
vernum, release = display_map('info')
print(release)
print('Pygame 2.4.0')
print('SDL 2.26.4')
if sys.version_info[0:3] < __py_version_req__:
print('WARNING:', sys.version_info[0:3], 'is an older version of Python installed.')
log.warning('WARNING: ' + str(sys.version_info[0:3]) + ' is an older version of Python installed.')
elif sys.version_info[0:3] > __py_version_req__:
print('WARNING:', sys.version_info[0:3], 'is a newer version of Python installed.')
log.warning('WARNING: ' + str(sys.version_info[0:3]) + ' is a newer version of Python installed.')
if vernum != '2.0':
print('WARNING! Different version of mapper installed:', vernum)
log.warning('WARNING! Different version of mapper installed: ' + vernum)
if pygame.version.vernum != (2, 4, 0):
print('WARNING! Different version of Pygame installed:', pygame.version.ver)
if pygame.get_sdl_version() != (2, 26, 4):
print('WARNING! Different version of SDL installed:', pygame.get_sdl_version())
if not pygame.image.get_extended():
print('No extended image file format support for Pygame.')
else:
print('Extended image file format supported for Pygame.')
print()
print('----------------------------')
print(__author__)
print()
print('The Traveller game in all forms is owned by Far Future Enterprises.')
print('Copyright 1977 - 2024 Far Future Enterprises.')
print('Traveller is a registered trademark of Far Future Enterprises.')
print()
print('Voice List')
print('0 Mute Voice')
for i in range(num_voices):
print(i+1, voices[i])
print()
main(voice_muted, grid_style, zone_style, trade_code, see_thru, show_loc, show_grid)