-
Notifications
You must be signed in to change notification settings - Fork 0
/
mazeConst.py
196 lines (162 loc) · 8.99 KB
/
mazeConst.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
import mazeGen as mg
import mazeFiller as mf
import treasure as trsr
import pickle
import os
from random import randrange
from util import randdiff
from personality import randPersonEcounter
import traps
def spaceInfo(lvl, state, string, player_count):
if(state == 4):
hrd = trsr.getHoard(lvl)
return trsr.cashToString(hrd['cash']) + ' and ' + hrd['loot']
elif(state == 5):
return "stairs down"
elif(state == 6):
return "stairs up"
elif(state == 7):
return trsr.cashToString(trsr.getTreasure(lvl)['cash']) + ', hidden(no monster encounter): {}, Clue to {}: ({}, {})'.format(randdiff(lvl), ['goal', 'treasure1', 'treasure2'][randrange(3)], randdiff(lvl),
['Arcana', 'History', 'Investigation', 'Nature', 'Religion'][randrange(5)])
elif(state == 9):
e = mf.get_encounter(lvl, num = player_count)
return '{} {}'.format(e[1], e[0])
elif(state == 10):
e = mf.get_encounter(lvl, diff = 0, num = player_count)
return '{} {}'.format(e[1], e[0])
elif(state == 11):
e = mf.get_encounter(lvl, diff = 2, num = player_count)
return '{} {}'.format(e[1], e[0])
elif(state == 12):
return randPersonEcounter(lvl)
elif(state == 13):
return traps.randtrap(lvl)
else:
return string
def edgeInfo(lvl, state, string):
if(state == 2):
s = 'door: '
door = mf.randDoor(lvl)
if('lock' in door):
s = s + 'locked: {}, '.format(door['lock'])
s = s + 'strength: {}'.format(door['strength'])
return s
if(state == 3):
s = 'door: '
door = mf.randSDoor(lvl)
if('lock' in door):
s = s + 'locked: {}, '.format(door['lock'])
if('hidden' in door):
s = s + 'hidden: {}, '.format(door['hidden'])
s = s + 'strength: {}'.format(door['strength'])
return s
else:
return string
#need to mark secret doors as spectial
def genInfo(lvl, mp, pc, moninit):
mf.initMonsters(fn = moninit)
s = 'floor lvl ' + str(lvl)
return {'space': [[spaceInfo(lvl, mp['space'][r][c], s, pc) for c in range(mp['c_len'])] for r in range(mp['r_len'])],
'hor': [[edgeInfo(lvl, mp['hor'][r][c], s) for c in range(mp['c_len'])] for r in range(mp['r_len']+1)],
'ver': [[edgeInfo(lvl, mp['ver'][r][c], s) for c in range(mp['c_len']+1)] for r in range(mp['r_len'])]}
def makeDun(strength = [x for x in range(1, 21)], size = [(2, 2)]*4 + [(3, 3)]*7 + [(4, 4)]*5 + [(5,5)]*4, pc = 4, monsterlistfilename = "Ref/monster_list.txt", layoutType = 'maze'):
dun = {'floor': [mg.make_floor(x[0], x[1], layoutType) for x in size]}
dun['desc'] = 'dungeon'
dun['info'] = [genInfo(strength[x], dun['floor'][x], pc, monsterlistfilename) for x in range(len(strength))]
return dun
def save(ob, name = 'temp.psav'):
file = open(name, mode = 'wb')
pickle.dump(ob, file)
file.close()
def load(name = 'temp.psav'):
file = open(name, mode = 'rb')
res = pickle.load(file)
file.close()
return res
ch = [(' ', ' '), ('|', '-'), ('/', '\\'),
('S','S'), 'T', 'G', 'E', 't', ' ', 'm', 'e', 'h', 'P', 'R']
ch2 = [(' ',' '), ('|', '-'), ('/', '\\'), ('|', '-')]
def make_txt(dun, name = './temp'):
d = os.path.dirname(name)
if (not os.path.exists(d)):
print('making dir')
os.makedirs(name)
cwd = os.getcwd()
os.chdir(name)
save(dun, name = "Full.dun")
for floor in range(len(dun['floor'])):
lines = [' ' + ''.join(['+{:0>3X}'.format(c) for c in range(dun['floor'][floor]['c_len'])]) + '+\n']
for r in range(dun['floor'][floor]['r_len']):
lines.append('{:0>3X}'.format(r))
for c in range(dun['floor'][floor]['c_len']):
lines[-1] = lines[-1] + '+ {} '.format(ch[dun['floor'][floor]['hor'][r][c]][1])
lines[-1] = lines[-1] + '+{:0>3X}\n'.format(r)
lines.append('{:0>3X}'.format(r))
for c in range(dun['floor'][floor]['c_len']):
lines[-1] = lines[-1] + '{} {} '.format(ch[dun['floor'][floor]['ver'][r][c]][0], ch[dun['floor'][floor]['space'][r][c]])
lines[-1] = lines[-1] + ch[dun['floor'][floor]['ver'][r][dun['floor'][floor]['c_len']]][0] + '{:0>3X}\n'.format(r)
lines.append('{:0>3X}'.format(dun['floor'][floor]['r_len']))
for c in range(dun['floor'][floor]['c_len']):
lines[-1] = lines[-1] + '+ {} '.format(ch[dun['floor'][floor]['hor'][dun['floor'][floor]['r_len']][c]][1])
lines[-1] = lines[-1] + '+{:0>3X}\n'.format(dun['floor'][floor]['r_len'])
lines.append(' ' + ''.join(['+{:0>3X}'.format(c) for c in range(dun['floor'][floor]['c_len'])]) + '+\n')
dmap = open('Floor{:0>2d}Map.txt'.format(floor+1), 'w')
dmap.writelines(lines)
dmap.close()
lines = []
for r in range(dun['floor'][floor]['r_len']):
for c in range(dun['floor'][floor]['c_len']):
if(dun['floor'][floor]['space'][r][c] != 8):
lines.append('({:2X}, {:2X}) : {}\n'.format(r, c, dun['info'][floor]['space'][r][c]))
mref = open('Floor{:0>2d}MonRef.txt'.format(floor+1), 'w')
mref.writelines(lines)
mref.close()
lines = ['horizontal vertical\n']
for r in range(dun['floor'][floor]['r_len'] + 1):
for c in range(dun['floor'][floor]['c_len']):
if(dun['floor'][floor]['hor'][r][c] > 1):
lines.append('({:2X}, {:2X}) : {}\n'.format(r, c, dun['info'][floor]['hor'][r][c]))
lines2 = []
for r in range(dun['floor'][floor]['r_len']):
for c in range(dun['floor'][floor]['c_len'] + 1):
if(dun['floor'][floor]['ver'][r][c] > 1):
lines2.append('({:2X}, {:2X}) : {}\n'.format(r, c, dun['info'][floor]['ver'][r][c]))
for i in range(1, len(lines)):
if(i >= len(lines2)):
break
spacesize = len(lines[0][:-9]) - len(lines[i])
temp = ' '*spacesize + lines2[i]
lines[i] = '{}{}'.format(lines[i][:-1], temp)
dref = open('Floor{:0>2d}DoorRef.txt'.format(floor+1), 'w')
dref.writelines(lines)
dref.close()
pref = open('Floor{:0>2d}PrintMap.txt'.format(floor+1), 'w')
lines = []
for majorC in range(dun['floor'][floor]['c_len']//30):
for majorR in range(dun['floor'][floor]['r_len']//30):
lines.append(' ' + ''.join(['+{:0>3X}'.format(c) for c in range(majorC*30, (majorC+1)*30)]) + '+\n')
for r in range(majorR*30, (majorR+1)*30):
lines.append('{:0>3X}+'.format(r) + '+'.join([' {} '.format(ch[dun['floor'][floor]['hor'][r][c]][1]) for c in range(majorC*30, (majorC+1)*30)]) + '+{:0>3X}\n'.format(r))
lines.append('{:0>3X}'.format(r) + ''.join(['{} {} '.format(ch[dun['floor'][floor]['ver'][r][c]][0], ch[dun['floor'][floor]['space'][r][c]]) for c in range(majorC*30, (majorC+1)*30)]) + '{}{:0>3X}\n'.format(ch[dun['floor'][floor]['ver'][r][(majorC+1)*30]][0],r))
lines.append('{:0>3X}+'.format((majorR+1)*30) + '+'.join([' {} '.format(ch[dun['floor'][floor]['hor'][(majorR+1)*30][c]][1]) for c in range(majorC*30, (majorC+1)*30)]) + '+{:0>3X}\n'.format((majorR+1)*30))
lines.append(' ' + ''.join(['+{:0>3X}'.format(c) for c in range(majorC*30, (majorC+1)*30)]) + '+\n')
lines.append('\n\n')
pref.writelines(lines)
lines = []
pref.close()
pref = open('Floor{:0>2d}PlayerMap.txt'.format(floor+1), 'w')
lines = []
for majorC in range(dun['floor'][floor]['c_len']//30):
for majorR in range(dun['floor'][floor]['r_len']//30):
lines.append(' ' + ''.join(['+{:0>3X}'.format(c) for c in range(majorC*30, (majorC+1)*30)]) + '+\n')
for r in range(majorR*30, (majorR+1)*30):
lines.append('{:0>3X}+'.format(r) + '+'.join([' {} '.format(ch2[dun['floor'][floor]['hor'][r][c]][1]) for c in range(majorC*30, (majorC+1)*30)]) + '+{:0>3X}\n'.format(r))
lines.append('{:0>3X}'.format(r) + ''.join(['{} '.format(ch2[dun['floor'][floor]['ver'][r][c]][0]) for c in range(majorC*30, (majorC+1)*30)]) + '{}{:0>3X}\n'.format(ch[dun['floor'][floor]['ver'][r][(majorC+1)*30]][0],r))
lines.append('{:0>3X}+'.format((majorR+1)*30) + '+'.join([' {} '.format(ch2[dun['floor'][floor]['hor'][(majorR+1)*30][c]][1]) for c in range(majorC*30, (majorC+1)*30)]) + '+{:0>3X}\n'.format((majorR+1)*30))
lines.append(' ' + ''.join(['+{:0>3X}'.format(c) for c in range(majorC*30, (majorC+1)*30)]) + '+\n')
lines.append('\n\n')
pref.writelines(lines)
lines = []
pref.close()
os.chdir(cwd)
make_txt(makeDun(pc = 4, layoutType = 'cave'), name = './dungeontest')