-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateMap.py
More file actions
121 lines (111 loc) · 3.11 KB
/
GenerateMap.py
File metadata and controls
121 lines (111 loc) · 3.11 KB
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
#!/usr/bin/python
import os,struct,sys,codecs,time
from stat import *
try:
import psyco
psyco.full()
except: pass
# Settings here
processmaplist=[0,1,30,34,36,43,47,48,70,90,109,129,189,209,229,230,249,269,289,309,
329,369,389,409,429,449,509,530,531,532]
rootpath="./../../"
StrtCoords="StartCoords"
vmaps="demodata/vmaps"
mmaps="mmaps"
waittime=0.8
# Initialization of variables used
gridlist=[]
dones=[]
startCoords=[]
failed=[]
exportmap=0
# Functions
def GetSplit(part1,reverse):
coords=part1.split('_')
imap=int(coords[0])
try:
x=int(coords[1])
y=int(coords[2])
except:
x=0
y=0
if imap==exportmap:
if reverse==1:
grid=(y,x)
else:
grid=(x,y)
return grid
def sortbysize(filelist):
tmplist=[]
for one in filelist:
tmplist.append((os.stat(rootpath+StrtCoords+"/"+one)[ST_SIZE],one))
tmplist.sort(key=lambda x:x[0],reverse=True)
flist=[]
for one in tmplist:
flist.append(one[1])
return flist
def updateList(path,sorting):
ilist=[]
osdones=os.listdir(path)
if sorting:
osdones=sortbysize(osdones)
for one in osdones:
try:
name=one.split(".")[0]
imap=int(name.split("_")[0])
if imap==exportmap:
ilist.append(GetSplit(name,0))
except:
continue
return ilist
def oneleft():
for one in startCoords:
if dones.count(one)==0 and failed.count(one)==0 and gridlist.count(one)>0:
return one
return 0
# Main code
for exportmap in processmaplist:
fulllist = os.listdir(rootpath+vmaps)
for one in fulllist:
f=one.split(".")
ext=f[1]
imap=int(f[0].split("_")[0])
if ext=="vmdir" and imap==exportmap:
gridlist.append(GetSplit(f[0],0))
fulllist = os.listdir(rootpath+StrtCoords)
for one in fulllist:
try:
f=one.split(".")
ext=f[1]
imap=int(f[0].split("_")[0])
if ext=="txt" and imap==exportmap:
gridlist.append(GetSplit(f[0],0))
except:
continue
goon=1
past=0
dones=updateList(rootpath+mmaps,0)
startCoords=updateList(rootpath+StrtCoords,1)
while goon:
gridleft=oneleft()
if gridleft:
if gridleft==past:
failed.append(gridleft)
else:
past=gridleft
print "\nGenerating "+str(exportmap)+" "+str(gridleft[0])+" "+str(gridleft[1])
os.system("Generator "+str(exportmap)+" "+str(gridleft[0])+" "+str(gridleft[1])+" 1")
time.sleep(waittime)
else:
goon=0
dones=updateList(rootpath+mmaps,0)
startCoords=updateList(rootpath+StrtCoords,1)
file=open('failed'+str(exportmap)+'.txt','w')
for one in failed:
if one[0]!=0 and one[1]!=0:
file.write(str(one[0])+","+str(one[1])+'\n')
for one in gridlist:
if dones.count(one)==0:
if one[0]!=0 and one[1]!=0:
file.write(str(one[0])+","+str(one[1])+'\n')
file.close()